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 = pl_Yield( p_intf );
292 if( !p_playlist ) break;
294 var_Get( p_playlist , "random", &val );
295 bState = val.b_bool ? TBSTATE_CHECKED : 0;
296 SendMessage( hwndTB, TB_SETSTATE, Random_Event,
297 MAKELONG(bState | TBSTATE_ENABLED, 0) );
298 var_Get( p_playlist , "loop", &val );
299 bState = val.b_bool ? TBSTATE_CHECKED : 0;
300 SendMessage( hwndTB, TB_SETSTATE, Loop_Event,
301 MAKELONG(bState | TBSTATE_ENABLED, 0) );
302 var_Get( p_playlist , "repeat", &val );
303 bState = val.b_bool ? TBSTATE_CHECKED : 0;
304 SendMessage( hwndTB, TB_SETSTATE, Repeat_Event,
305 MAKELONG(bState | TBSTATE_ENABLED, 0) );
306 pl_Release( p_intf );
308 GetClientRect( hwnd, &rect );
309 hListView = CreateWindow( WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD |
310 LVS_REPORT | LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL,
311 rect.left, rect.top + 2*(MENU_HEIGHT+1), rect.right - rect.left,
312 rect.bottom - ( rect.top + 2*MENU_HEIGHT) - MENU_HEIGHT,
313 hwnd, NULL, hInst, NULL );
314 ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
317 lv.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
318 lv.fmt = LVCFMT_LEFT ;
319 GetClientRect( hwnd, &rect );
321 lv.pszText = _T("Name");
323 ListView_InsertColumn( hListView, 0, &lv);
325 lv.pszText = _T("Author");
327 ListView_InsertColumn( hListView, 1, &lv);
328 lv.cx = rect.right - rect.left - 180;
329 lv.pszText = _T("Duration");
331 ListView_InsertColumn( hListView, 2, &lv);
333 SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
341 EndDialog( hwnd, LOWORD( wp ) );
345 SHSipPreference( hwnd, SIP_DOWN );
346 SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
353 EndDialog( hwnd, LOWORD( wp ) );
356 case ID_MANAGE_OPENPL:
358 b_need_update = true;
361 case ID_MANAGE_SAVEPL:
365 case ID_MANAGE_ADDFILE:
366 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE,
368 b_need_update = true;
371 case ID_MANAGE_ADDDIRECTORY:
372 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY,
374 b_need_update = true;
377 case ID_MANAGE_ADDMRL:
378 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
379 b_need_update = true;
384 b_need_update = true;
389 b_need_update = true;
394 b_need_update = true;
399 b_need_update = true;
415 OnSort( ID_SORT_TITLE );
419 OnSort( ID_SORT_RTITLE );
423 OnSort( ID_SORT_AUTHOR );
426 case ID_SORT_RAUTHOR:
427 OnSort( ID_SORT_RAUTHOR );
430 case ID_SORT_SHUFFLE:
431 OnSort( ID_SORT_SHUFFLE );
439 OnDisableSelection();
446 case ID_SEL_SELECTALL:
450 case PopupPlay_Event:
452 b_need_update = true;
457 b_need_update = true;
462 b_need_update = true;
465 case PopupInfo_Event:
467 b_need_update = true;
476 if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
477 ( ((LPNMHDR)lp)->code == NM_CUSTOMDRAW ) )
479 SetWindowLong( hwnd, DWL_MSGRESULT,
480 (LONG)ProcessCustomDraw(lp) );
482 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
483 ( ((LPNMHDR)lp)->code == GN_CONTEXTMENU ) )
485 HandlePopupMenu( hwnd, ((PNMRGINFO)lp)->ptAction );
487 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
488 ( ((LPNMHDR)lp)->code == LVN_COLUMNCLICK ) )
490 OnColSelect( ((LPNMLISTVIEW)lp)->iSubItem );
492 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
493 ( ((LPNMHDR)lp)->code == LVN_ITEMACTIVATE ) )
495 OnActivateItem( ((LPNMLISTVIEW)lp)->iSubItem );
500 // the message was not processed
501 // indicate if the base class handled it
508 LRESULT Playlist::ProcessCustomDraw( LPARAM lParam )
510 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
512 switch( lplvcd->nmcd.dwDrawStage )
514 case CDDS_PREPAINT : //Before the paint cycle begins
515 //request notifications for individual listview items
516 return CDRF_NOTIFYITEMDRAW;
518 case CDDS_ITEMPREPAINT: //Before an item is drawn
519 playlist_t *p_playlist = pl_Yield( p_intf );
520 if( p_playlist == NULL ) return CDRF_DODEFAULT;
521 if( (int)lplvcd->nmcd.dwItemSpec == p_playlist->i_index )
523 lplvcd->clrText = RGB(255,0,0);
524 pl_Release( p_intf );
528 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist,
529 (int)lplvcd->nmcd.dwItemSpec );
532 pl_Release( p_intf );
533 return CDRF_DODEFAULT;
535 if( p_item->b_enabled == false )
537 lplvcd->clrText = RGB(192,192,192);
538 pl_Release( p_intf );
541 pl_Release( p_intf );
544 return CDRF_DODEFAULT;
547 /**********************************************************************
548 * Handles the display of the "floating" popup
549 **********************************************************************/
550 void Playlist::HandlePopupMenu( HWND hwnd, POINT point )
552 HMENU hMenuTrackPopup;
554 // Create the popup menu.
555 hMenuTrackPopup = CreatePopupMenu();
557 // Append some items.
558 AppendMenu( hMenuTrackPopup, MF_STRING, PopupPlay_Event, _T("Play") );
559 AppendMenu( hMenuTrackPopup, MF_STRING, PopupDel_Event, _T("Delete") );
560 AppendMenu( hMenuTrackPopup, MF_STRING, PopupEna_Event,
561 _T("Toggle enabled") );
562 AppendMenu( hMenuTrackPopup, MF_STRING, PopupInfo_Event, _T("Info") );
564 /* Draw and track the "floating" popup */
565 TrackPopupMenu( hMenuTrackPopup, 0, point.x, point.y, 0, hwnd, NULL );
567 /* Destroy the menu since were are done with it. */
568 DestroyMenu( hMenuTrackPopup );
571 /**********************************************************************
573 **********************************************************************/
574 void Playlist::ShowPlaylist( bool b_show )
576 if( b_show ) Rebuild();
580 /**********************************************************************
581 * Update the playlist
582 **********************************************************************/
583 void Playlist::UpdatePlaylist()
588 b_need_update = false;
591 playlist_t *p_playlist = pl_Yield( p_intf );
592 if( p_playlist == NULL ) return;
594 /* Update the colour of items */
596 vlc_object_lock( p_playlist );
597 if( p_intf->p_sys->i_playing != p_playlist->i_index )
599 // p_playlist->i_index in RED
602 // if exists, p_intf->p_sys->i_playing in BLACK
603 p_intf->p_sys->i_playing = p_playlist->i_index;
605 vlc_object_unlock( p_playlist );
607 pl_Release( p_intf );
610 /**********************************************************************
611 * Rebuild the playlist
612 **********************************************************************/
613 void Playlist::Rebuild()
615 playlist_t *p_playlist = pl_Yield( p_intf );
616 if( p_playlist == NULL ) return;
619 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
621 /* Clear the list... */
622 ListView_DeleteAllItems( hListView );
624 /* ...and rebuild it */
625 vlc_object_lock( p_playlist );
626 for( int i = 0; i < p_playlist->i_size; i++ )
634 ListView_InsertItem( hListView, &lv );
635 ListView_SetItemText( hListView, lv.iItem, 0,
636 _FROMMB(p_playlist->pp_items[i]->input.psz_name) );
639 vlc_object_unlock( p_playlist );
642 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED |
643 LVIS_SELECTED, LVIS_STATEIMAGEMASK )
645 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED,
646 LVIS_STATEIMAGEMASK );
648 pl_Release( p_intf );
651 /**********************************************************************
652 * Update one playlist item
653 **********************************************************************/
654 void Playlist::UpdateItem( int i )
656 playlist_t *p_playlist = pl_Yield( p_intf );
658 if( p_playlist == NULL ) return;
660 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i );
664 pl_Release( p_intf );
668 ListView_SetItemText( hListView, i, 0, _FROMMB(p_item->input.psz_name) );
669 ListView_SetItemText( hListView, i, 1,
670 _FROMMB( input_ItemGetInfo( &p_item->input,
671 _("General") , _("Author") ) ) );
673 char psz_duration[MSTRTIME_MAX_SIZE];
674 mtime_t dur = input_item_GetDuration( p_item );
675 if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
676 else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
678 ListView_SetItemText( hListView, i, 3, _FROMMB(psz_duration) );
680 pl_Release( p_intf );
683 /**********************************************************************
685 **********************************************************************/
686 void Playlist::DeleteItem( int item )
688 playlist_t *p_playlist = pl_Yield( p_intf );
689 if( p_playlist == NULL ) return;
691 playlist_Delete( p_playlist, item );
692 ListView_DeleteItem( hListView, item );
694 pl_Release( p_intf );
697 /**********************************************************************
699 **********************************************************************/
700 static void OnOpenCB( intf_dialog_args_t *p_arg )
702 intf_thread_t *p_intf = (intf_thread_t *)p_arg->p_arg;
704 if( p_arg->i_results && p_arg->psz_results[0] )
706 playlist_t * p_playlist = pl_Yield( p_intf );
710 playlist_Import( p_playlist, p_arg->psz_results[0] );
711 pl_Release( p_intf );
716 void Playlist::OnOpen()
718 char *psz_filters ="All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u";
720 intf_dialog_args_t *p_arg =
721 (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
722 memset( p_arg, 0, sizeof(intf_dialog_args_t) );
724 p_arg->psz_title = strdup( "Open playlist" );
725 p_arg->psz_extensions = strdup( psz_filters );
726 p_arg->p_arg = p_intf;
727 p_arg->pf_callback = OnOpenCB;
729 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC, 0, p_arg);
732 static void OnSaveCB( intf_dialog_args_t *p_arg )
734 intf_thread_t *p_intf = (intf_thread_t *)p_arg->p_arg;
736 if( p_arg->i_results && p_arg->psz_results[0] )
738 playlist_t * p_playlist = pl_Yield( p_intf );
743 char *psz_ext = strrchr( p_arg->psz_results[0], '.' );
745 if( psz_ext && !strcmp( psz_ext, ".pls") )
746 psz_export = "export-pls";
747 else psz_export = "export-m3u";
749 playlist_Export( p_playlist, p_arg->psz_results[0], psz_export );
750 pl_Release( p_intf );
755 void Playlist::OnSave()
757 char *psz_filters ="M3U file|*.m3u|PLS file|*.pls";
759 intf_dialog_args_t *p_arg =
760 (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
761 memset( p_arg, 0, sizeof(intf_dialog_args_t) );
763 p_arg->psz_title = strdup( "Save playlist" );
764 p_arg->psz_extensions = strdup( psz_filters );
765 p_arg->b_save = true;
766 p_arg->p_arg = p_intf;
767 p_arg->pf_callback = OnSaveCB;
769 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC,
773 /**********************************************************************
774 * Selection functions
775 **********************************************************************/
776 void Playlist::OnDeleteSelection()
778 /* Delete from the end to the beginning, to avoid a shift of indices */
779 for( long item = ((int) ListView_GetItemCount( hListView ) - 1);
782 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
789 void Playlist::OnInvertSelection()
793 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
795 iState = ListView_GetItemState( hListView, item, LVIS_STATEIMAGEMASK );
796 ListView_SetItemState( hListView, item, iState ^ LVIS_SELECTED,
797 LVIS_STATEIMAGEMASK );
801 void Playlist::OnEnableSelection()
803 playlist_t *p_playlist = pl_Yield( p_intf );
804 if( p_playlist == NULL ) return;
806 for( long item = ListView_GetItemCount( hListView ) - 1;
809 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
811 playlist_item_t *p_item =
812 playlist_ItemGetByPos( p_playlist, item );
813 playlist_Enable( p_playlist, p_item );
817 pl_Release( p_intf );
820 void Playlist::OnDisableSelection()
822 playlist_t *p_playlist = pl_Yield( p_intf );
823 if( p_playlist == NULL ) return;
825 for( long item = ListView_GetItemCount( hListView ) - 1;
828 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
831 playlist_item_t *p_item =
832 playlist_ItemGetByPos( p_playlist, item );
833 playlist_Disable( p_playlist, p_item );
837 pl_Release( p_intf );
840 void Playlist::OnSelectAll()
842 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
844 ListView_SetItemState( hListView, item, LVIS_FOCUSED | LVIS_SELECTED,
845 LVIS_STATEIMAGEMASK );
849 void Playlist::OnActivateItem( int i_item )
851 playlist_t *p_playlist = pl_Yield( p_intf );
852 if( p_playlist == NULL ) return;
854 playlist_Goto( p_playlist, i_item );
856 pl_Release( p_intf );
859 void Playlist::ShowInfos( HWND hwnd, int i_item )
861 playlist_t *p_playlist = pl_Yield( p_intf );
862 if( p_playlist == NULL ) return;
864 vlc_object_lock( p_playlist);
865 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
866 vlc_object_unlock( p_playlist );
870 ItemInfoDialog *iteminfo_dialog =
871 new ItemInfoDialog( p_intf, this, hInst, p_item );
872 CreateDialogBox( hwnd, iteminfo_dialog );
873 UpdateItem( i_item );
874 delete iteminfo_dialog;
877 pl_Release( p_intf );
880 /********************************************************************
882 ********************************************************************/
883 void Playlist::OnUp()
885 playlist_t *p_playlist = pl_Yield( p_intf );
886 if( p_playlist == NULL ) return;
888 /* We use the first selected item, so find it */
890 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
892 if( i_item > 0 && i_item < p_playlist->i_size )
894 playlist_Move( p_playlist , i_item, i_item - 1);
897 ListView_SetItemState( hListView, i_item - 1, LVIS_FOCUSED,
898 LVIS_STATEIMAGEMASK );
902 ListView_SetItemState( hListView, 0, LVIS_FOCUSED,
903 LVIS_STATEIMAGEMASK );
906 pl_Release( p_intf );
911 void Playlist::OnDown()
913 playlist_t *p_playlist = pl_Yield( p_intf );
914 if( p_playlist == NULL ) return;
916 /* We use the first selected item, so find it */
918 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
920 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
922 playlist_Move( p_playlist , i_item, i_item + 2 );
923 ListView_SetItemState( hListView, i_item + 1, LVIS_FOCUSED,
924 LVIS_STATEIMAGEMASK );
926 pl_Release( p_intf );
931 /**********************************************************************
932 * Playlist mode functions
933 **********************************************************************/
934 void Playlist::OnRandom()
937 int bState = SendMessage( hwndTB, TB_GETSTATE, Random_Event, 0 );
938 val.b_bool = (bState & TBSTATE_CHECKED) ? true : false;
940 playlist_t *p_playlist = pl_Yield( p_intf );
941 if( p_playlist == NULL ) return;
943 var_Set( p_playlist , "random", val );
944 pl_Release( p_intf );
947 void Playlist::OnLoop ()
950 int bState = SendMessage( hwndTB, TB_GETSTATE, Loop_Event, 0 );
951 val.b_bool = (bState & TBSTATE_CHECKED) ? true : false;
953 playlist_t *p_playlist = pl_Yield( p_intf );
954 if( p_playlist == NULL ) return;
956 var_Set( p_playlist , "loop", val );
957 pl_Release( p_intf );
960 void Playlist::OnRepeat ()
963 int bState = SendMessage( hwndTB, TB_GETSTATE, Repeat_Event, 0 );
964 val.b_bool = (bState & TBSTATE_CHECKED) ? true : false;
966 playlist_t *p_playlist = pl_Yield( p_intf );
967 if( p_playlist == NULL ) return;
969 var_Set( p_playlist , "repeat", val );
970 pl_Release( p_intf );
973 /********************************************************************
975 ********************************************************************/
976 void Playlist::OnSort( UINT event )
978 playlist_t *p_playlist = pl_Yield( p_intf );
979 if( p_playlist == NULL ) return;
984 playlist_SortTitle( p_playlist , ORDER_NORMAL );
987 playlist_SortTitle( p_playlist , ORDER_REVERSE );
990 playlist_SortAuthor(p_playlist , ORDER_NORMAL );
992 case ID_SORT_RAUTHOR:
993 playlist_SortAuthor( p_playlist , ORDER_REVERSE );
995 case ID_SORT_SHUFFLE:
996 playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
1000 pl_Release( p_intf );
1002 b_need_update = true;
1007 void Playlist::OnColSelect( int iSubItem )
1009 playlist_t *p_playlist = pl_Yield( p_intf );
1010 if( p_playlist == NULL ) return;
1015 if( i_title_sorted != 1 )
1017 playlist_SortTitle( p_playlist, ORDER_NORMAL );
1022 playlist_SortTitle( p_playlist, ORDER_REVERSE );
1023 i_title_sorted = -1;
1027 if( i_author_sorted != 1 )
1029 playlist_SortAuthor( p_playlist, ORDER_NORMAL );
1030 i_author_sorted = 1;
1034 playlist_SortAuthor( p_playlist, ORDER_REVERSE );
1035 i_author_sorted = -1;
1042 pl_Release( p_intf );
1044 b_need_update = true;
1049 /*****************************************************************************
1050 * Popup management functions
1051 *****************************************************************************/
1052 void Playlist::OnPopupPlay()
1055 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1057 playlist_t *p_playlist = pl_Yield( p_intf );
1058 if( p_playlist == NULL ) return;
1060 if( i_popup_item != -1 )
1062 playlist_Goto( p_playlist, i_popup_item );
1065 pl_Release( p_intf );
1068 void Playlist::OnPopupDel()
1071 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1073 DeleteItem( i_popup_item );
1076 void Playlist::OnPopupEna()
1079 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1081 playlist_t *p_playlist = pl_Yield( p_intf );
1082 if( p_playlist == NULL ) return;
1084 playlist_item_t *p_item =
1085 playlist_ItemGetByPos( p_playlist, i_popup_item );
1087 if( p_playlist->pp_items[i_popup_item]->b_enabled )
1088 //playlist_IsEnabled( p_playlist, i_popup_item ) )
1090 playlist_Disable( p_playlist, p_item );
1094 playlist_Enable( p_playlist, p_item );
1097 pl_Release( p_intf );
1098 UpdateItem( i_popup_item );
1101 void Playlist::OnPopupInfo( HWND hwnd )
1104 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1106 ShowInfos( hwnd, i_popup_item );