1 /*****************************************************************************
2 * playlist.cpp : WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
7 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8 * Gildas Bazin <gbazin@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
40 #define NMAXFILE 512 // at least 256
44 #define TEXTMAXBUF 512 // at least 500
47 #define LONG2POINT(l, pt) ((pt).x = (SHORT)LOWORD(l), (pt).y = (SHORT)HIWORD(l))
53 #define NUMIMAGES 11 // Number of buttons in the toolbar
54 #define IMAGEWIDTH 16 // Width of the buttons in the toolbar
55 #define IMAGEHEIGHT 16 // Height of the buttons in the toolbar
56 #define BUTTONWIDTH 0 // Width of the button images in the toolbar
57 #define BUTTONHEIGHT 0 // Height of the button images in the toolbar
58 #define ID_TOOLBAR 2000 // Identifier of the main tool bar
59 #define dwTBFontStyle TBSTYLE_BUTTON | TBSTYLE_CHECK | TBSTYLE_GROUP // style for toolbar buttons
76 #define HELP_OPENPL _T("Open playlist")
77 #define HELP_SAVEPL _T("Save playlist")
78 #define HELP_SIMPLEADD _T("Simple Add")
79 #define HELP_ADDMRL _T("Add MRL")
80 #define HELP_DELETE _T("Delete selection")
81 #define HELP_INFOS _T("Item info")
82 #define HELP_UP _T("Up")
83 #define HELP_DOWN _T("Down")
84 #define HELP_RANDOM _T("Random")
85 #define HELP_LOOP _T("Repeat all")
86 #define HELP_REPEAT _T("Repeat one")
88 // The TBBUTTON structure contains information the toolbar buttons.
89 static TBBUTTON tbButton2[] =
91 {0, ID_MANAGE_OPENPL, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
92 {1, ID_MANAGE_SAVEPL, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
93 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, -1},
94 {2, ID_MANAGE_SIMPLEADD, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
95 {3, ID_MANAGE_ADDMRL, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
96 {4, ID_SEL_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
97 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, -1},
98 {5, Infos_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
99 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, -1},
100 {6, Up_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
101 {7, Down_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
102 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, -1},
103 {8, Random_Event, TBSTATE_ENABLED, TBSTYLE_CHECK, 0, -1},
104 {9, Loop_Event, TBSTATE_ENABLED, TBSTYLE_CHECK, 0, -1},
105 {10, Repeat_Event, TBSTATE_ENABLED, TBSTYLE_CHECK, 0, -1}
109 TCHAR * szToolTips2[] =
124 /*****************************************************************************
126 *****************************************************************************/
128 /*****************************************************************************
130 *****************************************************************************/
131 Playlist::Playlist( intf_thread_t *_p_intf, HINSTANCE _hInst )
133 /* Initializations */
141 b_need_update = VLC_TRUE;
144 /***********************************************************************
150 Processes messages sent to the main window.
152 ***********************************************************************/
153 LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
160 playlist_t *p_playlist;
165 INITCOMMONCONTROLSEX iccex;
167 LRESULT lResult = CBaseWindow::WndProc( hwnd, msg, wp, lp, pbProcessed );
168 BOOL bWasProcessed = *pbProcessed;
174 shidi.dwMask = SHIDIM_FLAGS;
175 shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
176 SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
178 SHInitDialog( &shidi );
180 //Create the menubar.
181 memset( &mbi, 0, sizeof (SHMENUBARINFO) );
182 mbi.cbSize = sizeof (SHMENUBARINFO);
183 mbi.hwndParent = hwnd;
184 mbi.dwFlags = SHCMBF_HMENU;
185 mbi.nToolBarId = IDR_MENUBAR2;
186 mbi.hInstRes = hInst;
190 if( !SHCreateMenuBar(&mbi) )
192 MessageBox(hwnd, L"SHCreateMenuBar Failed", L"Error", MB_OK);
198 iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
199 iccex.dwICC = ICC_BAR_CLASSES;
201 // Registers TOOLBAR control classes from the common control dll
202 InitCommonControlsEx (&iccex);
204 // Create the toolbar control.
205 dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS |
206 WS_EX_OVERLAPPEDWINDOW | CCS_NOPARENTALIGN;
208 hwndTB = CreateToolbarEx( hwnd, dwStyle, NULL, NUMIMAGES,
209 hInst, IDB_BITMAP3, tbButton2,
210 sizeof (tbButton2) / sizeof (TBBUTTON),
211 BUTTONWIDTH, BUTTONHEIGHT,
212 IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON) );
215 *pbProcessed = bWasProcessed;
220 // Add ToolTips to the toolbar.
221 SendMessage( hwndTB, TB_SETTOOLTIPS, (WPARAM) NUMIMAGES,
222 (LPARAM)szToolTips2 );
224 // Reposition the toolbar.
225 GetClientRect( hwnd, &rect );
226 GetWindowRect( hwndTB, &rectTB );
227 MoveWindow( hwndTB, rect.left, rect.top - 2, rect.right - rect.left,
228 MENU_HEIGHT /*rectTB.bottom - rectTB.top */, TRUE);
230 // random, loop, repeat buttons states
232 p_playlist = (playlist_t *)
233 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
234 if( p_playlist == NULL )
236 *pbProcessed = bWasProcessed;
240 var_Get( p_playlist , "random", &val );
241 bState = val.b_bool ? TBSTATE_CHECKED : 0;
242 SendMessage( hwndTB, TB_SETSTATE, Random_Event,
243 MAKELONG(bState | TBSTATE_ENABLED, 0) );
244 var_Get( p_playlist , "loop", &val );
245 bState = val.b_bool ? TBSTATE_CHECKED : 0;
246 SendMessage( hwndTB, TB_SETSTATE, Loop_Event,
247 MAKELONG(bState | TBSTATE_ENABLED, 0) );
248 var_Get( p_playlist , "repeat", &val );
249 bState = val.b_bool ? TBSTATE_CHECKED : 0;
250 SendMessage( hwndTB, TB_SETSTATE, Repeat_Event,
251 MAKELONG(bState | TBSTATE_ENABLED, 0) );
252 vlc_object_release( p_playlist );
254 GetClientRect( hwnd, &rect );
255 hListView = CreateWindow( WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD |
256 LVS_REPORT | LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL,
257 rect.left, rect.top + 2*(MENU_HEIGHT+1), rect.right - rect.left,
258 rect.bottom - ( rect.top + 2*MENU_HEIGHT) - MENU_HEIGHT,
259 hwnd, NULL, hInst, NULL );
260 ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
263 lv.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
264 lv.fmt = LVCFMT_LEFT ;
265 GetClientRect( hwnd, &rect );
267 lv.pszText = _T("Name");
269 ListView_InsertColumn( hListView, 0, &lv);
271 lv.pszText = _T("Author");
273 ListView_InsertColumn( hListView, 1, &lv);
274 lv.cx = rect.right - rect.left - 180;
275 lv.pszText = _T("Duration");
277 ListView_InsertColumn( hListView, 2, &lv);
279 SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
281 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
293 EndDialog( hwnd, LOWORD( wp ) );
296 case ID_MANAGE_OPENPL:
298 b_need_update = VLC_TRUE;
301 case ID_MANAGE_SAVEPL:
302 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
304 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
307 case ID_MANAGE_SIMPLEADD:
308 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
310 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
311 b_need_update = VLC_TRUE;
314 case ID_MANAGE_ADDMRL:
315 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
317 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
318 b_need_update = VLC_TRUE;
323 b_need_update = VLC_TRUE;
327 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
329 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
330 b_need_update = VLC_TRUE;
335 b_need_update = VLC_TRUE;
340 b_need_update = VLC_TRUE;
356 OnSort( ID_SORT_TITLE );
360 OnSort( ID_SORT_RTITLE );
364 OnSort( ID_SORT_AUTHOR );
367 case ID_SORT_RAUTHOR:
368 OnSort( ID_SORT_RAUTHOR );
371 case ID_SORT_SHUFFLE:
372 OnSort( ID_SORT_SHUFFLE );
380 OnDisableSelection();
387 case ID_SEL_SELECTALL:
391 case PopupPlay_Event:
393 b_need_update = VLC_TRUE;
398 b_need_update = VLC_TRUE;
403 b_need_update = VLC_TRUE;
406 case PopupInfo_Event:
408 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
409 b_need_update = VLC_TRUE;
413 *pbProcessed = bWasProcessed;
419 if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
420 ( ((LPNMHDR)lp)->code == NM_CUSTOMDRAW ) )
422 SetWindowLong( hwnd, DWL_MSGRESULT,
423 (LONG)ProcessCustomDraw(lp) );
426 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
427 ( ((LPNMHDR)lp)->code == GN_CONTEXTMENU ) )
429 HandlePopupMenu( hwnd, ((PNMRGINFO)lp)->ptAction );
432 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
433 ( ((LPNMHDR)lp)->code == LVN_COLUMNCLICK ) )
435 OnColSelect( ((LPNMLISTVIEW)lp)->iSubItem );
438 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
439 ( ((LPNMHDR)lp)->code == LVN_ITEMACTIVATE ) )
441 OnActivateItem( ((LPNMLISTVIEW)lp)->iSubItem );
445 *pbProcessed = bWasProcessed;
450 // the message was not processed
451 // indicate if the base class handled it
452 *pbProcessed = bWasProcessed;
460 LRESULT Playlist::ProcessCustomDraw( LPARAM lParam )
462 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
464 switch( lplvcd->nmcd.dwDrawStage )
466 case CDDS_PREPAINT : //Before the paint cycle begins
467 //request notifications for individual listview items
468 return CDRF_NOTIFYITEMDRAW;
470 case CDDS_ITEMPREPAINT: //Before an item is drawn
471 playlist_t *p_playlist = (playlist_t *)
472 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
473 if( p_playlist == NULL ) return CDRF_DODEFAULT;
474 if( (int)lplvcd->nmcd.dwItemSpec == p_playlist->i_index )
476 lplvcd->clrText = RGB(255,0,0);
477 vlc_object_release(p_playlist);
481 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist,
482 (int)lplvcd->nmcd.dwItemSpec );
485 vlc_object_release(p_playlist);
486 return CDRF_DODEFAULT;
488 if( p_item->b_enabled == VLC_FALSE )
490 lplvcd->clrText = RGB(192,192,192);
491 vlc_object_release(p_playlist);
496 return CDRF_DODEFAULT;
499 /**********************************************************************
500 * Handles the display of the "floating" popup
501 **********************************************************************/
502 void Playlist::HandlePopupMenu( HWND hwnd, POINT point )
504 HMENU hMenuTrackPopup;
506 // Create the popup menu.
507 hMenuTrackPopup = CreatePopupMenu();
509 // Append some items.
510 AppendMenu( hMenuTrackPopup, MF_STRING, PopupPlay_Event, _T("Play") );
511 AppendMenu( hMenuTrackPopup, MF_STRING, PopupDel_Event, _T("Delete") );
512 AppendMenu( hMenuTrackPopup, MF_STRING, PopupEna_Event,
513 _T("Toggle enabled") );
514 AppendMenu( hMenuTrackPopup, MF_STRING, PopupInfo_Event, _T("Info") );
516 /* Draw and track the "floating" popup */
517 TrackPopupMenu( hMenuTrackPopup, 0, point.x, point.y, 0, hwnd, NULL );
519 /* Destroy the menu since were are done with it. */
520 DestroyMenu( hMenuTrackPopup );
523 /**********************************************************************
524 * Update the playlist
525 **********************************************************************/
526 void Playlist::UpdatePlaylist()
531 b_need_update = VLC_FALSE;
534 playlist_t *p_playlist = (playlist_t *)
535 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
536 if( p_playlist == NULL ) return;
538 /* Update the colour of items */
540 vlc_mutex_lock( &p_playlist->object_lock );
541 if( p_intf->p_sys->i_playing != p_playlist->i_index )
543 // p_playlist->i_index in RED
546 // if exists, p_intf->p_sys->i_playing in BLACK
547 p_intf->p_sys->i_playing = p_playlist->i_index;
549 vlc_mutex_unlock( &p_playlist->object_lock );
551 vlc_object_release( p_playlist );
554 /**********************************************************************
555 * Rebuild the playlist
556 **********************************************************************/
557 void Playlist::Rebuild()
559 playlist_t *p_playlist = (playlist_t *)
560 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
561 if( p_playlist == NULL ) return;
564 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
566 /* Clear the list... */
567 ListView_DeleteAllItems( hListView );
569 /* ...and rebuild it */
570 vlc_mutex_lock( &p_playlist->object_lock );
571 for( int i = 0; i < p_playlist->i_size; i++ )
579 ListView_InsertItem( hListView, &lv );
580 ListView_SetItemText( hListView, lv.iItem, 0,
581 _FROMMB(p_playlist->pp_items[i]->input.psz_name) );
584 vlc_mutex_unlock( &p_playlist->object_lock );
587 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED |
588 LVIS_SELECTED, LVIS_STATEIMAGEMASK )
590 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED,
591 LVIS_STATEIMAGEMASK );
593 vlc_object_release( p_playlist );
596 /**********************************************************************
597 * Update one playlist item
598 **********************************************************************/
599 void Playlist::UpdateItem( int i )
601 playlist_t *p_playlist = (playlist_t *)
602 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
604 if( p_playlist == NULL ) return;
606 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i );
610 vlc_object_release(p_playlist);
614 ListView_SetItemText( hListView, i, 0, _FROMMB(p_item->input.psz_name) );
615 ListView_SetItemText( hListView, i, 1,
616 _FROMMB( vlc_input_item_GetInfo( &p_item->input,
617 _("General") , _("Author") ) ) );
619 char psz_duration[MSTRTIME_MAX_SIZE];
620 mtime_t dur = p_item->input.i_duration;
621 if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
622 else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
624 ListView_SetItemText( hListView, i, 3, _FROMMB(psz_duration) );
626 vlc_object_release(p_playlist);
629 /**********************************************************************
631 **********************************************************************/
632 void Playlist::DeleteItem( int item )
634 playlist_t *p_playlist = (playlist_t *)
635 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
636 if( p_playlist == NULL ) return;
638 playlist_Delete( p_playlist, item );
639 ListView_DeleteItem( hListView, item );
641 vlc_object_release( p_playlist );
644 /**********************************************************************
646 **********************************************************************/
647 void Playlist::OnOpen()
650 TCHAR DateiName[80+1] = _T("\0");
651 static TCHAR szFilter[] = _T("All playlists (*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u)\0*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u\0");
653 playlist_t *p_playlist = (playlist_t *)
654 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
655 if( p_playlist == NULL ) return;
657 memset( &ofn, 0, sizeof(OPENFILENAME) );
658 ofn.lStructSize = sizeof (OPENFILENAME);
659 ofn.hwndOwner = NULL;
660 ofn.hInstance = hInst;
661 ofn.lpstrFilter = szFilter;
662 ofn.lpstrCustomFilter = NULL;
663 ofn.nMaxCustFilter = 0;
664 ofn.nFilterIndex = 1;
665 ofn.lpstrFile = (LPTSTR) DateiName;
667 ofn.lpstrFileTitle = NULL;
668 ofn.nMaxFileTitle = 40;
669 ofn.lpstrInitialDir = NULL;
670 ofn.lpstrTitle = _T("Open playlist");
673 ofn.nFileExtension = 0;
674 ofn.lpstrDefExt = NULL;
677 ofn.lpTemplateName = NULL;
679 if( GetOpenFileName((LPOPENFILENAME)&ofn) )
681 playlist_Import( p_playlist, _TOMB(ofn.lpstrFile) );
684 vlc_object_release( p_playlist );
687 void Playlist::OnSave()
689 TCHAR szFile[NMAXFILE] = _T("\0");
699 } formats[] = {{ _T("M3U file"), _T("*.m3u"), "export-m3u" },
700 { _T("PLS file"), _T("*.pls"), "export-pls" }};
701 wUnicode = new TCHAR[100];
702 wcscpy( wUnicode, _T("") );
705 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
707 wcscpy( &wUnicode[len], formats[i].psz_desc );
708 len = len + wcslen( formats[i].psz_desc );
709 wUnicode[len] = '\0';
711 wcscpy( &wUnicode[len], formats[i].psz_filter );
712 len = len + wcslen( formats[i].psz_filter );
713 wUnicode[len] = '\0';
716 wUnicode[len] = '\0';
718 memset( &(ofn), 0, sizeof(ofn));
719 ofn.lStructSize = sizeof(ofn);
720 ofn.hwndOwner = NULL;
721 ofn.lpstrFile = szFile;
722 ofn.nMaxFile = NMAXFILE;
723 ofn.lpstrFilter = wUnicode;
724 ofn.lpstrTitle = _T("Save playlist");
725 ofn.Flags = OFN_HIDEREADONLY;
728 if( GetSaveFileName((LPOPENFILENAME) &ofn) )
730 playlist_t * p_playlist = (playlist_t *)
731 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
733 if( p_playlist && ofn.lpstrFile )
735 playlist_Export( p_playlist, _TOMB(ofn.lpstrFile),
736 formats[ofn.nFilterIndex ?
737 ofn.nFilterIndex - 1 : 0].psz_module );
740 if( p_playlist ) vlc_object_release( p_playlist );
744 void Playlist::OnAddFile()
746 // Same code as in Interface
748 TCHAR DateiName[80+1] = _T("\0");
749 static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
751 playlist_t *p_playlist = (playlist_t *)
752 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
753 if( p_playlist == NULL ) return;
755 memset( &ofn, 0, sizeof(OPENFILENAME) );
756 ofn.lStructSize = sizeof(OPENFILENAME);
757 ofn.hwndOwner = NULL;
758 ofn.hInstance = hInst;
759 ofn.lpstrFilter = szFilter;
760 ofn.lpstrCustomFilter = NULL;
761 ofn.nMaxCustFilter = 0;
762 ofn.nFilterIndex = 1;
763 ofn.lpstrFile = (LPTSTR)DateiName;
765 ofn.lpstrFileTitle = NULL;
766 ofn.nMaxFileTitle = 40;
767 ofn.lpstrInitialDir = NULL;
768 ofn.lpstrTitle = _T("Quick Open File");
771 ofn.nFileExtension = 0;
772 ofn.lpstrDefExt = NULL;
775 ofn.lpTemplateName = NULL;
777 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
779 if( GetOpenFileName( (LPOPENFILENAME)&ofn ) )
781 char *psz_filename = _TOMB(ofn.lpstrFile);
782 playlist_Add( p_playlist, psz_filename, psz_filename,
783 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
786 vlc_object_release( p_playlist );
789 void Playlist::OnAddMRL()
793 /**********************************************************************
794 * Selection functions
795 **********************************************************************/
796 void Playlist::OnDeleteSelection()
798 /* Delete from the end to the beginning, to avoid a shift of indices */
799 for( long item = ((int) ListView_GetItemCount( hListView ) - 1);
802 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
809 void Playlist::OnInvertSelection()
813 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
815 iState = ListView_GetItemState( hListView, item, LVIS_STATEIMAGEMASK );
816 ListView_SetItemState( hListView, item, iState ^ LVIS_SELECTED,
817 LVIS_STATEIMAGEMASK );
821 void Playlist::OnEnableSelection()
823 playlist_t *p_playlist = (playlist_t *)
824 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
825 if( p_playlist == NULL ) return;
827 for( long item = ListView_GetItemCount( hListView ) - 1;
830 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
832 playlist_item_t *p_item =
833 playlist_ItemGetByPos( p_playlist, item );
834 playlist_Enable( p_playlist, p_item );
838 vlc_object_release( p_playlist);
841 void Playlist::OnDisableSelection()
843 playlist_t *p_playlist = (playlist_t *)
844 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
845 if( p_playlist == NULL ) return;
847 for( long item = ListView_GetItemCount( hListView ) - 1;
850 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
853 playlist_item_t *p_item =
854 playlist_ItemGetByPos( p_playlist, item );
855 playlist_Disable( p_playlist, p_item );
859 vlc_object_release( p_playlist);
862 void Playlist::OnSelectAll()
864 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
866 ListView_SetItemState( hListView, item, LVIS_FOCUSED | LVIS_SELECTED,
867 LVIS_STATEIMAGEMASK );
871 void Playlist::OnActivateItem( int i_item )
873 playlist_t *p_playlist = (playlist_t *)
874 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
875 if( p_playlist == NULL ) return;
877 playlist_Goto( p_playlist, i_item );
879 vlc_object_release( p_playlist );
882 void Playlist::ShowInfos( HWND hwnd, int i_item )
884 playlist_t *p_playlist = (playlist_t *)
885 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
886 if( p_playlist == NULL ) return;
888 vlc_mutex_lock( &p_playlist->object_lock);
889 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
890 vlc_mutex_unlock( &p_playlist->object_lock );
894 ItemInfoDialog *iteminfo_dialog =
895 new ItemInfoDialog( p_intf, hInst, p_item );
896 DialogBoxParam( hInst, (LPCTSTR)IDD_DUMMY, hwnd,
897 (DLGPROC)iteminfo_dialog->BaseWndProc,
898 (long)iteminfo_dialog );
899 UpdateItem( i_item );
900 delete iteminfo_dialog;
903 vlc_object_release( p_playlist );
906 /********************************************************************
908 ********************************************************************/
909 void Playlist::OnUp()
911 playlist_t *p_playlist = (playlist_t *)
912 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
913 if( p_playlist == NULL ) return;
915 /* We use the first selected item, so find it */
917 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
919 if( i_item > 0 && i_item < p_playlist->i_size )
921 playlist_Move( p_playlist , i_item, i_item - 1);
924 ListView_SetItemState( hListView, i_item - 1, LVIS_FOCUSED,
925 LVIS_STATEIMAGEMASK );
929 ListView_SetItemState( hListView, 0, LVIS_FOCUSED,
930 LVIS_STATEIMAGEMASK );
933 vlc_object_release( p_playlist );
938 void Playlist::OnDown()
940 playlist_t *p_playlist = (playlist_t *)
941 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
942 if( p_playlist == NULL ) return;
944 /* We use the first selected item, so find it */
946 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
948 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
950 playlist_Move( p_playlist , i_item, i_item + 2 );
951 ListView_SetItemState( hListView, i_item + 1, LVIS_FOCUSED,
952 LVIS_STATEIMAGEMASK );
954 vlc_object_release( p_playlist );
959 /**********************************************************************
960 * Playlist mode functions
961 **********************************************************************/
962 void Playlist::OnRandom()
965 int bState = SendMessage( hwndTB, TB_GETSTATE, Random_Event, 0 );
966 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
968 playlist_t *p_playlist = (playlist_t *)
969 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
970 if( p_playlist == NULL ) return;
972 var_Set( p_playlist , "random", val );
973 vlc_object_release( p_playlist );
976 void Playlist::OnLoop ()
979 int bState = SendMessage( hwndTB, TB_GETSTATE, Loop_Event, 0 );
980 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
982 playlist_t *p_playlist = (playlist_t *)
983 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
984 if( p_playlist == NULL ) return;
986 var_Set( p_playlist , "loop", val );
987 vlc_object_release( p_playlist );
990 void Playlist::OnRepeat ()
993 int bState = SendMessage( hwndTB, TB_GETSTATE, Repeat_Event, 0 );
994 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
996 playlist_t *p_playlist = (playlist_t *)
997 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
998 if( p_playlist == NULL ) return;
1000 var_Set( p_playlist , "repeat", val );
1001 vlc_object_release( p_playlist );
1004 /********************************************************************
1006 ********************************************************************/
1007 void Playlist::OnSort( UINT event )
1009 playlist_t *p_playlist = (playlist_t *)
1010 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1011 if( p_playlist == NULL ) return;
1016 playlist_SortTitle( p_playlist , ORDER_NORMAL );
1018 case ID_SORT_RTITLE:
1019 playlist_SortTitle( p_playlist , ORDER_REVERSE );
1021 case ID_SORT_AUTHOR:
1022 playlist_SortAuthor(p_playlist , ORDER_NORMAL );
1024 case ID_SORT_RAUTHOR:
1025 playlist_SortAuthor( p_playlist , ORDER_REVERSE );
1027 case ID_SORT_SHUFFLE:
1028 playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
1032 vlc_object_release( p_playlist );
1034 b_need_update = VLC_TRUE;
1039 void Playlist::OnColSelect( int iSubItem )
1041 playlist_t *p_playlist = (playlist_t *)
1042 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1043 if( p_playlist == NULL ) return;
1048 if( i_title_sorted != 1 )
1050 playlist_SortTitle( p_playlist, ORDER_NORMAL );
1055 playlist_SortTitle( p_playlist, ORDER_REVERSE );
1056 i_title_sorted = -1;
1060 if( i_author_sorted != 1 )
1062 playlist_SortAuthor( p_playlist, ORDER_NORMAL );
1063 i_author_sorted = 1;
1067 playlist_SortAuthor( p_playlist, ORDER_REVERSE );
1068 i_author_sorted = -1;
1075 vlc_object_release( p_playlist );
1077 b_need_update = VLC_TRUE;
1082 /*****************************************************************************
1083 * Popup management functions
1084 *****************************************************************************/
1085 void Playlist::OnPopupPlay()
1088 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1090 playlist_t *p_playlist = (playlist_t *)
1091 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1092 if( p_playlist == NULL ) return;
1094 if( i_popup_item != -1 )
1096 playlist_Goto( p_playlist, i_popup_item );
1099 vlc_object_release( p_playlist );
1102 void Playlist::OnPopupDel()
1105 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1107 DeleteItem( i_popup_item );
1110 void Playlist::OnPopupEna()
1113 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1115 playlist_t *p_playlist = (playlist_t *)
1116 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1117 if( p_playlist == NULL ) return;
1119 playlist_item_t *p_item =
1120 playlist_ItemGetByPos( p_playlist, i_popup_item );
1122 if( p_playlist->pp_items[i_popup_item]->b_enabled )
1123 //playlist_IsEnabled( p_playlist, i_popup_item ) )
1125 playlist_Disable( p_playlist, p_item );
1129 playlist_Enable( p_playlist, p_item );
1132 vlc_object_release( p_playlist);
1133 UpdateItem( i_popup_item );
1136 void Playlist::OnPopupInfo( HWND hwnd )
1139 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1141 ShowInfos( hwnd, i_popup_item );