1 /*****************************************************************************
2 * playlist.cpp : WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_interface.h>
41 #define TEXTMAXBUF 512 // at least 500
44 #define LONG2POINT(l, pt) ((pt).x = (SHORT)LOWORD(l), (pt).y = (SHORT)HIWORD(l))
46 #define NUMIMAGES 11 // Number of buttons in the toolbar
47 #define IMAGEWIDTH 16 // Width of the buttons in the toolbar
48 #define IMAGEHEIGHT 16 // Height of the buttons in the toolbar
49 #define BUTTONWIDTH 0 // Width of the button images in the toolbar
50 #define BUTTONHEIGHT 0 // Height of the button images in the toolbar
51 #define ID_TOOLBAR 2000 // Identifier of the main tool bar
68 #define HELP_OPENPL _T("Open playlist")
69 #define HELP_SAVEPL _T("Save playlist")
70 #define HELP_ADDFILE _T("Add File")
71 #define HELP_ADDMRL _T("Add MRL")
72 #define HELP_DELETE _T("Delete selection")
73 #define HELP_INFOS _T("Item info")
74 #define HELP_UP _T("Up")
75 #define HELP_DOWN _T("Down")
76 #define HELP_RANDOM _T("Random")
77 #define HELP_LOOP _T("Repeat all")
78 #define HELP_REPEAT _T("Repeat one")
80 // The TBBUTTON structure contains information the toolbar buttons.
81 static TBBUTTON tbButton2[] =
83 {0, ID_MANAGE_OPENPL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
84 {1, ID_MANAGE_SAVEPL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
85 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
86 {2, ID_MANAGE_ADDFILE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
87 {3, ID_MANAGE_ADDMRL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
88 {4, ID_SEL_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
89 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
90 {5, Infos_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
91 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
92 {6, Up_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
93 {7, Down_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
94 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
95 {8, Random_Event, TBSTATE_ENABLED, TBSTYLE_CHECK},
96 {9, Loop_Event, TBSTATE_ENABLED, TBSTYLE_CHECK},
97 {10, Repeat_Event, TBSTATE_ENABLED, TBSTYLE_CHECK}
101 TCHAR * szToolTips2[] =
116 /*****************************************************************************
118 *****************************************************************************/
120 /*****************************************************************************
122 *****************************************************************************/
123 Playlist::Playlist( intf_thread_t *p_intf, CBaseWindow *p_parent,
125 : CBaseWindow( p_intf, p_parent, h_inst )
127 /* Initializations */
132 b_need_update = true;
135 /***********************************************************************
141 ***********************************************************************/
142 static HWND CreateMenuBar( HWND hwnd, HINSTANCE hInst )
146 memset( &mbi, 0, sizeof(SHMENUBARINFO) );
147 mbi.cbSize = sizeof(SHMENUBARINFO);
148 mbi.hwndParent = hwnd;
149 mbi.hInstRes = hInst;
150 mbi.nToolBarId = IDR_MENUBAR2;
152 if( !SHCreateMenuBar( &mbi ) )
154 MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
159 tbbi.cbSize = sizeof(tbbi);
160 tbbi.dwMask = TBIF_LPARAM;
162 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_MANAGE, (LPARAM)&tbbi );
163 HMENU hmenu_file = (HMENU)tbbi.lParam;
164 RemoveMenu( hmenu_file, 0, MF_BYPOSITION );
165 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_SORT, (LPARAM)&tbbi );
166 HMENU hmenu_sort = (HMENU)tbbi.lParam;
167 RemoveMenu( hmenu_sort, 0, MF_BYPOSITION );
168 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_SEL, (LPARAM)&tbbi );
169 HMENU hmenu_sel = (HMENU)tbbi.lParam;
170 RemoveMenu( hmenu_sel, 0, MF_BYPOSITION );
173 HMENU hmenu_file = CreatePopupMenu();
174 HMENU hmenu_sort = CreatePopupMenu();
175 HMENU hmenu_sel = CreatePopupMenu();
178 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDFILE,
179 _T("&Add File...") );
180 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDDIRECTORY,
181 _T("Add Directory...") );
182 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDMRL,
184 AppendMenu( hmenu_file, MF_SEPARATOR, 0, 0 );
185 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_OPENPL,
186 _T("Open &Playlist") );
187 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_SAVEPL,
188 _T("Save Playlist") );
190 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_TITLE,
191 _T("Sort by &title") );
192 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_RTITLE,
193 _T("&Reverse sort by title") );
194 AppendMenu( hmenu_sort, MF_SEPARATOR, 0, 0 );
195 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_AUTHOR,
196 _T("Sort by &author") );
197 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_RAUTHOR,
198 _T("Reverse sort by &author") );
199 AppendMenu( hmenu_sort, MF_SEPARATOR, 0, 0 );
200 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_SHUFFLE,
201 _T("&Shuffle Playlist") );
203 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_ENABLE,
205 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_DISABLE,
207 AppendMenu( hmenu_sel, MF_SEPARATOR, 0, 0 );
208 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_INVERT,
210 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_DELETE,
212 AppendMenu( hmenu_sel, MF_SEPARATOR, 0, 0 );
213 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_SELECTALL,
221 HMENU hmenu = CreateMenu();
223 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_file, _T("Manage") );
224 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_sort, _T("Sort") );
225 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_sel, _T("Selection") );
227 SetMenu( hwnd, hmenu );
233 /***********************************************************************
238 Processes messages sent to the main window.
239 ***********************************************************************/
240 LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
244 INITCOMMONCONTROLSEX iccex;
249 playlist_t *p_playlist;
254 shidi.dwMask = SHIDIM_FLAGS;
255 shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
256 SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
258 SHInitDialog( &shidi );
260 hwndCB = CreateMenuBar( hwnd, hInst );
262 iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
263 iccex.dwICC = ICC_BAR_CLASSES;
265 // Registers TOOLBAR control classes from the common control dll
266 InitCommonControlsEx (&iccex);
268 // Create the toolbar control.
269 dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS |
270 WS_EX_OVERLAPPEDWINDOW | CCS_NOPARENTALIGN;
272 hwndTB = CreateToolbarEx( hwnd, dwStyle, 0, NUMIMAGES,
273 hInst, IDB_BITMAP3, tbButton2,
274 sizeof (tbButton2) / sizeof (TBBUTTON),
275 BUTTONWIDTH, BUTTONHEIGHT,
276 IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON) );
279 // Add ToolTips to the toolbar.
280 SendMessage( hwndTB, TB_SETTOOLTIPS, (WPARAM) NUMIMAGES,
281 (LPARAM)szToolTips2 );
283 // Reposition the toolbar.
284 GetClientRect( hwnd, &rect );
285 GetWindowRect( hwndTB, &rectTB );
286 MoveWindow( hwndTB, rect.left, rect.top - 2, rect.right - rect.left,
287 MENU_HEIGHT /*rectTB.bottom - rectTB.top */, TRUE);
289 // random, loop, repeat buttons states
291 p_playlist = (playlist_t *)
292 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
293 if( !p_playlist ) break;
295 var_Get( p_playlist , "random", &val );
296 bState = val.b_bool ? TBSTATE_CHECKED : 0;
297 SendMessage( hwndTB, TB_SETSTATE, Random_Event,
298 MAKELONG(bState | TBSTATE_ENABLED, 0) );
299 var_Get( p_playlist , "loop", &val );
300 bState = val.b_bool ? TBSTATE_CHECKED : 0;
301 SendMessage( hwndTB, TB_SETSTATE, Loop_Event,
302 MAKELONG(bState | TBSTATE_ENABLED, 0) );
303 var_Get( p_playlist , "repeat", &val );
304 bState = val.b_bool ? TBSTATE_CHECKED : 0;
305 SendMessage( hwndTB, TB_SETSTATE, Repeat_Event,
306 MAKELONG(bState | TBSTATE_ENABLED, 0) );
307 vlc_object_release( p_playlist );
309 GetClientRect( hwnd, &rect );
310 hListView = CreateWindow( WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD |
311 LVS_REPORT | LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL,
312 rect.left, rect.top + 2*(MENU_HEIGHT+1), rect.right - rect.left,
313 rect.bottom - ( rect.top + 2*MENU_HEIGHT) - MENU_HEIGHT,
314 hwnd, NULL, hInst, NULL );
315 ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
318 lv.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
319 lv.fmt = LVCFMT_LEFT ;
320 GetClientRect( hwnd, &rect );
322 lv.pszText = _T("Name");
324 ListView_InsertColumn( hListView, 0, &lv);
326 lv.pszText = _T("Author");
328 ListView_InsertColumn( hListView, 1, &lv);
329 lv.cx = rect.right - rect.left - 180;
330 lv.pszText = _T("Duration");
332 ListView_InsertColumn( hListView, 2, &lv);
334 SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
342 EndDialog( hwnd, LOWORD( wp ) );
346 SHSipPreference( hwnd, SIP_DOWN );
347 SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
354 EndDialog( hwnd, LOWORD( wp ) );
357 case ID_MANAGE_OPENPL:
359 b_need_update = true;
362 case ID_MANAGE_SAVEPL:
366 case ID_MANAGE_ADDFILE:
367 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE,
369 b_need_update = true;
372 case ID_MANAGE_ADDDIRECTORY:
373 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY,
375 b_need_update = true;
378 case ID_MANAGE_ADDMRL:
379 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
380 b_need_update = true;
385 b_need_update = true;
390 b_need_update = true;
395 b_need_update = true;
400 b_need_update = true;
416 OnSort( ID_SORT_TITLE );
420 OnSort( ID_SORT_RTITLE );
424 OnSort( ID_SORT_AUTHOR );
427 case ID_SORT_RAUTHOR:
428 OnSort( ID_SORT_RAUTHOR );
431 case ID_SORT_SHUFFLE:
432 OnSort( ID_SORT_SHUFFLE );
440 OnDisableSelection();
447 case ID_SEL_SELECTALL:
451 case PopupPlay_Event:
453 b_need_update = true;
458 b_need_update = true;
463 b_need_update = true;
466 case PopupInfo_Event:
468 b_need_update = true;
477 if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
478 ( ((LPNMHDR)lp)->code == NM_CUSTOMDRAW ) )
480 SetWindowLong( hwnd, DWL_MSGRESULT,
481 (LONG)ProcessCustomDraw(lp) );
483 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
484 ( ((LPNMHDR)lp)->code == GN_CONTEXTMENU ) )
486 HandlePopupMenu( hwnd, ((PNMRGINFO)lp)->ptAction );
488 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
489 ( ((LPNMHDR)lp)->code == LVN_COLUMNCLICK ) )
491 OnColSelect( ((LPNMLISTVIEW)lp)->iSubItem );
493 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
494 ( ((LPNMHDR)lp)->code == LVN_ITEMACTIVATE ) )
496 OnActivateItem( ((LPNMLISTVIEW)lp)->iSubItem );
501 // the message was not processed
502 // indicate if the base class handled it
509 LRESULT Playlist::ProcessCustomDraw( LPARAM lParam )
511 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
513 switch( lplvcd->nmcd.dwDrawStage )
515 case CDDS_PREPAINT : //Before the paint cycle begins
516 //request notifications for individual listview items
517 return CDRF_NOTIFYITEMDRAW;
519 case CDDS_ITEMPREPAINT: //Before an item is drawn
520 playlist_t *p_playlist = (playlist_t *)
521 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
522 if( p_playlist == NULL ) return CDRF_DODEFAULT;
523 if( (int)lplvcd->nmcd.dwItemSpec == p_playlist->i_index )
525 lplvcd->clrText = RGB(255,0,0);
526 vlc_object_release(p_playlist);
530 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist,
531 (int)lplvcd->nmcd.dwItemSpec );
534 vlc_object_release(p_playlist);
535 return CDRF_DODEFAULT;
537 if( p_item->b_enabled == false )
539 lplvcd->clrText = RGB(192,192,192);
540 vlc_object_release(p_playlist);
545 return CDRF_DODEFAULT;
548 /**********************************************************************
549 * Handles the display of the "floating" popup
550 **********************************************************************/
551 void Playlist::HandlePopupMenu( HWND hwnd, POINT point )
553 HMENU hMenuTrackPopup;
555 // Create the popup menu.
556 hMenuTrackPopup = CreatePopupMenu();
558 // Append some items.
559 AppendMenu( hMenuTrackPopup, MF_STRING, PopupPlay_Event, _T("Play") );
560 AppendMenu( hMenuTrackPopup, MF_STRING, PopupDel_Event, _T("Delete") );
561 AppendMenu( hMenuTrackPopup, MF_STRING, PopupEna_Event,
562 _T("Toggle enabled") );
563 AppendMenu( hMenuTrackPopup, MF_STRING, PopupInfo_Event, _T("Info") );
565 /* Draw and track the "floating" popup */
566 TrackPopupMenu( hMenuTrackPopup, 0, point.x, point.y, 0, hwnd, NULL );
568 /* Destroy the menu since were are done with it. */
569 DestroyMenu( hMenuTrackPopup );
572 /**********************************************************************
574 **********************************************************************/
575 void Playlist::ShowPlaylist( bool b_show )
577 if( b_show ) Rebuild();
581 /**********************************************************************
582 * Update the playlist
583 **********************************************************************/
584 void Playlist::UpdatePlaylist()
589 b_need_update = false;
592 playlist_t *p_playlist = (playlist_t *)
593 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
594 if( p_playlist == NULL ) return;
596 /* Update the colour of items */
598 vlc_object_lock( p_playlist );
599 if( p_intf->p_sys->i_playing != p_playlist->i_index )
601 // p_playlist->i_index in RED
604 // if exists, p_intf->p_sys->i_playing in BLACK
605 p_intf->p_sys->i_playing = p_playlist->i_index;
607 vlc_object_unlock( p_playlist );
609 vlc_object_release( p_playlist );
612 /**********************************************************************
613 * Rebuild the playlist
614 **********************************************************************/
615 void Playlist::Rebuild()
617 playlist_t *p_playlist = (playlist_t *)
618 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
619 if( p_playlist == NULL ) return;
622 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
624 /* Clear the list... */
625 ListView_DeleteAllItems( hListView );
627 /* ...and rebuild it */
628 vlc_object_lock( p_playlist );
629 for( int i = 0; i < p_playlist->i_size; i++ )
637 ListView_InsertItem( hListView, &lv );
638 ListView_SetItemText( hListView, lv.iItem, 0,
639 _FROMMB(p_playlist->pp_items[i]->input.psz_name) );
642 vlc_object_unlock( p_playlist );
645 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED |
646 LVIS_SELECTED, LVIS_STATEIMAGEMASK )
648 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED,
649 LVIS_STATEIMAGEMASK );
651 vlc_object_release( p_playlist );
654 /**********************************************************************
655 * Update one playlist item
656 **********************************************************************/
657 void Playlist::UpdateItem( int i )
659 playlist_t *p_playlist = (playlist_t *)
660 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
662 if( p_playlist == NULL ) return;
664 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i );
668 vlc_object_release(p_playlist);
672 ListView_SetItemText( hListView, i, 0, _FROMMB(p_item->input.psz_name) );
673 ListView_SetItemText( hListView, i, 1,
674 _FROMMB( input_ItemGetInfo( &p_item->input,
675 _("General") , _("Author") ) ) );
677 char psz_duration[MSTRTIME_MAX_SIZE];
678 mtime_t dur = input_item_GetDuration( p_item );
679 if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
680 else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
682 ListView_SetItemText( hListView, i, 3, _FROMMB(psz_duration) );
684 vlc_object_release(p_playlist);
687 /**********************************************************************
689 **********************************************************************/
690 void Playlist::DeleteItem( int item )
692 playlist_t *p_playlist = (playlist_t *)
693 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
694 if( p_playlist == NULL ) return;
696 playlist_Delete( p_playlist, item );
697 ListView_DeleteItem( hListView, item );
699 vlc_object_release( p_playlist );
702 /**********************************************************************
704 **********************************************************************/
705 static void OnOpenCB( intf_dialog_args_t *p_arg )
707 intf_thread_t *p_intf = (intf_thread_t *)p_arg->p_arg;
709 if( p_arg->i_results && p_arg->psz_results[0] )
711 playlist_t * p_playlist = (playlist_t *)
712 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
716 playlist_Import( p_playlist, p_arg->psz_results[0] );
719 if( p_playlist ) vlc_object_release( p_playlist );
723 void Playlist::OnOpen()
725 char *psz_filters ="All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u";
727 intf_dialog_args_t *p_arg =
728 (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
729 memset( p_arg, 0, sizeof(intf_dialog_args_t) );
731 p_arg->psz_title = strdup( "Open playlist" );
732 p_arg->psz_extensions = strdup( psz_filters );
733 p_arg->p_arg = p_intf;
734 p_arg->pf_callback = OnOpenCB;
736 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC, 0, p_arg);
739 static void OnSaveCB( intf_dialog_args_t *p_arg )
741 intf_thread_t *p_intf = (intf_thread_t *)p_arg->p_arg;
743 if( p_arg->i_results && p_arg->psz_results[0] )
745 playlist_t * p_playlist = (playlist_t *)
746 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
751 char *psz_ext = strrchr( p_arg->psz_results[0], '.' );
753 if( psz_ext && !strcmp( psz_ext, ".pls") )
754 psz_export = "export-pls";
755 else psz_export = "export-m3u";
757 playlist_Export( p_playlist, p_arg->psz_results[0], psz_export );
760 if( p_playlist ) vlc_object_release( p_playlist );
764 void Playlist::OnSave()
766 char *psz_filters ="M3U file|*.m3u|PLS file|*.pls";
768 intf_dialog_args_t *p_arg =
769 (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
770 memset( p_arg, 0, sizeof(intf_dialog_args_t) );
772 p_arg->psz_title = strdup( "Save playlist" );
773 p_arg->psz_extensions = strdup( psz_filters );
774 p_arg->b_save = true;
775 p_arg->p_arg = p_intf;
776 p_arg->pf_callback = OnSaveCB;
778 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC,
782 /**********************************************************************
783 * Selection functions
784 **********************************************************************/
785 void Playlist::OnDeleteSelection()
787 /* Delete from the end to the beginning, to avoid a shift of indices */
788 for( long item = ((int) ListView_GetItemCount( hListView ) - 1);
791 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
798 void Playlist::OnInvertSelection()
802 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
804 iState = ListView_GetItemState( hListView, item, LVIS_STATEIMAGEMASK );
805 ListView_SetItemState( hListView, item, iState ^ LVIS_SELECTED,
806 LVIS_STATEIMAGEMASK );
810 void Playlist::OnEnableSelection()
812 playlist_t *p_playlist = (playlist_t *)
813 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
814 if( p_playlist == NULL ) return;
816 for( long item = ListView_GetItemCount( hListView ) - 1;
819 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
821 playlist_item_t *p_item =
822 playlist_ItemGetByPos( p_playlist, item );
823 playlist_Enable( p_playlist, p_item );
827 vlc_object_release( p_playlist);
830 void Playlist::OnDisableSelection()
832 playlist_t *p_playlist = (playlist_t *)
833 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
834 if( p_playlist == NULL ) return;
836 for( long item = ListView_GetItemCount( hListView ) - 1;
839 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
842 playlist_item_t *p_item =
843 playlist_ItemGetByPos( p_playlist, item );
844 playlist_Disable( p_playlist, p_item );
848 vlc_object_release( p_playlist);
851 void Playlist::OnSelectAll()
853 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
855 ListView_SetItemState( hListView, item, LVIS_FOCUSED | LVIS_SELECTED,
856 LVIS_STATEIMAGEMASK );
860 void Playlist::OnActivateItem( int i_item )
862 playlist_t *p_playlist = (playlist_t *)
863 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
864 if( p_playlist == NULL ) return;
866 playlist_Goto( p_playlist, i_item );
868 vlc_object_release( p_playlist );
871 void Playlist::ShowInfos( HWND hwnd, 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 vlc_object_lock( p_playlist);
878 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
879 vlc_object_unlock( p_playlist );
883 ItemInfoDialog *iteminfo_dialog =
884 new ItemInfoDialog( p_intf, this, hInst, p_item );
885 CreateDialogBox( hwnd, iteminfo_dialog );
886 UpdateItem( i_item );
887 delete iteminfo_dialog;
890 vlc_object_release( p_playlist );
893 /********************************************************************
895 ********************************************************************/
896 void Playlist::OnUp()
898 playlist_t *p_playlist = (playlist_t *)
899 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
900 if( p_playlist == NULL ) return;
902 /* We use the first selected item, so find it */
904 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
906 if( i_item > 0 && i_item < p_playlist->i_size )
908 playlist_Move( p_playlist , i_item, i_item - 1);
911 ListView_SetItemState( hListView, i_item - 1, LVIS_FOCUSED,
912 LVIS_STATEIMAGEMASK );
916 ListView_SetItemState( hListView, 0, LVIS_FOCUSED,
917 LVIS_STATEIMAGEMASK );
920 vlc_object_release( p_playlist );
925 void Playlist::OnDown()
927 playlist_t *p_playlist = (playlist_t *)
928 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
929 if( p_playlist == NULL ) return;
931 /* We use the first selected item, so find it */
933 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
935 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
937 playlist_Move( p_playlist , i_item, i_item + 2 );
938 ListView_SetItemState( hListView, i_item + 1, LVIS_FOCUSED,
939 LVIS_STATEIMAGEMASK );
941 vlc_object_release( p_playlist );
946 /**********************************************************************
947 * Playlist mode functions
948 **********************************************************************/
949 void Playlist::OnRandom()
952 int bState = SendMessage( hwndTB, TB_GETSTATE, Random_Event, 0 );
953 val.b_bool = (bState & TBSTATE_CHECKED) ? true : false;
955 playlist_t *p_playlist = (playlist_t *)
956 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
957 if( p_playlist == NULL ) return;
959 var_Set( p_playlist , "random", val );
960 vlc_object_release( p_playlist );
963 void Playlist::OnLoop ()
966 int bState = SendMessage( hwndTB, TB_GETSTATE, Loop_Event, 0 );
967 val.b_bool = (bState & TBSTATE_CHECKED) ? true : false;
969 playlist_t *p_playlist = (playlist_t *)
970 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
971 if( p_playlist == NULL ) return;
973 var_Set( p_playlist , "loop", val );
974 vlc_object_release( p_playlist );
977 void Playlist::OnRepeat ()
980 int bState = SendMessage( hwndTB, TB_GETSTATE, Repeat_Event, 0 );
981 val.b_bool = (bState & TBSTATE_CHECKED) ? true : false;
983 playlist_t *p_playlist = (playlist_t *)
984 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
985 if( p_playlist == NULL ) return;
987 var_Set( p_playlist , "repeat", val );
988 vlc_object_release( p_playlist );
991 /********************************************************************
993 ********************************************************************/
994 void Playlist::OnSort( UINT event )
996 playlist_t *p_playlist = (playlist_t *)
997 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
998 if( p_playlist == NULL ) return;
1003 playlist_SortTitle( p_playlist , ORDER_NORMAL );
1005 case ID_SORT_RTITLE:
1006 playlist_SortTitle( p_playlist , ORDER_REVERSE );
1008 case ID_SORT_AUTHOR:
1009 playlist_SortAuthor(p_playlist , ORDER_NORMAL );
1011 case ID_SORT_RAUTHOR:
1012 playlist_SortAuthor( p_playlist , ORDER_REVERSE );
1014 case ID_SORT_SHUFFLE:
1015 playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
1019 vlc_object_release( p_playlist );
1021 b_need_update = true;
1026 void Playlist::OnColSelect( int iSubItem )
1028 playlist_t *p_playlist = (playlist_t *)
1029 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1030 if( p_playlist == NULL ) return;
1035 if( i_title_sorted != 1 )
1037 playlist_SortTitle( p_playlist, ORDER_NORMAL );
1042 playlist_SortTitle( p_playlist, ORDER_REVERSE );
1043 i_title_sorted = -1;
1047 if( i_author_sorted != 1 )
1049 playlist_SortAuthor( p_playlist, ORDER_NORMAL );
1050 i_author_sorted = 1;
1054 playlist_SortAuthor( p_playlist, ORDER_REVERSE );
1055 i_author_sorted = -1;
1062 vlc_object_release( p_playlist );
1064 b_need_update = true;
1069 /*****************************************************************************
1070 * Popup management functions
1071 *****************************************************************************/
1072 void Playlist::OnPopupPlay()
1075 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1077 playlist_t *p_playlist = (playlist_t *)
1078 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1079 if( p_playlist == NULL ) return;
1081 if( i_popup_item != -1 )
1083 playlist_Goto( p_playlist, i_popup_item );
1086 vlc_object_release( p_playlist );
1089 void Playlist::OnPopupDel()
1092 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1094 DeleteItem( i_popup_item );
1097 void Playlist::OnPopupEna()
1100 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1102 playlist_t *p_playlist = (playlist_t *)
1103 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1104 if( p_playlist == NULL ) return;
1106 playlist_item_t *p_item =
1107 playlist_ItemGetByPos( p_playlist, i_popup_item );
1109 if( p_playlist->pp_items[i_popup_item]->b_enabled )
1110 //playlist_IsEnabled( p_playlist, i_popup_item ) )
1112 playlist_Disable( p_playlist, p_item );
1116 playlist_Enable( p_playlist, p_item );
1119 vlc_object_release( p_playlist);
1120 UpdateItem( i_popup_item );
1123 void Playlist::OnPopupInfo( HWND hwnd )
1126 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1128 ShowInfos( hwnd, i_popup_item );