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 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <string.h> /* strerror() */
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))
49 #define NUMIMAGES 11 // Number of buttons in the toolbar
50 #define IMAGEWIDTH 16 // Width of the buttons in the toolbar
51 #define IMAGEHEIGHT 16 // Height of the buttons in the toolbar
52 #define BUTTONWIDTH 0 // Width of the button images in the toolbar
53 #define BUTTONHEIGHT 0 // Height of the button images in the toolbar
54 #define ID_TOOLBAR 2000 // Identifier of the main tool bar
55 #define dwTBFontStyle TBSTYLE_BUTTON | TBSTYLE_CHECK | TBSTYLE_GROUP // style for toolbar buttons
72 #define HELP_OPENPL _T("Open playlist")
73 #define HELP_SAVEPL _T("Save playlist")
74 #define HELP_SIMPLEADD _T("Simple Add")
75 #define HELP_ADDMRL _T("Add MRL")
76 #define HELP_DELETE _T("Delete selection")
77 #define HELP_INFOS _T("Item info")
78 #define HELP_UP _T("Up")
79 #define HELP_DOWN _T("Down")
80 #define HELP_RANDOM _T("Random")
81 #define HELP_LOOP _T("Repeat all")
82 #define HELP_REPEAT _T("Repeat one")
84 // The TBBUTTON structure contains information the toolbar buttons.
85 static TBBUTTON tbButton2[] =
87 {0, ID_MANAGE_OPENPL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
88 {1, ID_MANAGE_SAVEPL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
89 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
90 {2, ID_MANAGE_SIMPLEADD, TBSTATE_ENABLED, TBSTYLE_BUTTON},
91 {3, ID_MANAGE_ADDMRL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
92 {4, ID_SEL_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
93 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
94 {5, Infos_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
95 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
96 {6, Up_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
97 {7, Down_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
98 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
99 {8, Random_Event, TBSTATE_ENABLED, TBSTYLE_CHECK},
100 {9, Loop_Event, TBSTATE_ENABLED, TBSTYLE_CHECK},
101 {10, Repeat_Event, TBSTATE_ENABLED, TBSTYLE_CHECK}
105 TCHAR * szToolTips2[] =
120 /*****************************************************************************
122 *****************************************************************************/
124 /*****************************************************************************
126 *****************************************************************************/
127 Playlist::Playlist( intf_thread_t *_p_intf, HINSTANCE _hInst )
129 /* Initializations */
137 b_need_update = VLC_TRUE;
140 /***********************************************************************
145 Processes messages sent to the main window.
146 ***********************************************************************/
147 LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
151 INITCOMMONCONTROLSEX iccex;
156 playlist_t *p_playlist;
161 shidi.dwMask = SHIDIM_FLAGS;
162 shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
163 SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
165 SHInitDialog( &shidi );
167 //Create the menubar.
168 memset( &mbi, 0, sizeof (SHMENUBARINFO) );
169 mbi.cbSize = sizeof (SHMENUBARINFO);
170 mbi.hwndParent = hwnd;
171 mbi.dwFlags = SHCMBF_HMENU;
172 mbi.nToolBarId = IDR_MENUBAR2;
173 mbi.hInstRes = hInst;
177 if( !SHCreateMenuBar(&mbi) )
179 MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
185 iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
186 iccex.dwICC = ICC_BAR_CLASSES;
188 // Registers TOOLBAR control classes from the common control dll
189 InitCommonControlsEx (&iccex);
191 // Create the toolbar control.
192 dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS |
193 WS_EX_OVERLAPPEDWINDOW | CCS_NOPARENTALIGN;
195 hwndTB = CreateToolbarEx( hwnd, dwStyle, 0, NUMIMAGES,
196 hInst, IDB_BITMAP3, tbButton2,
197 sizeof (tbButton2) / sizeof (TBBUTTON),
198 BUTTONWIDTH, BUTTONHEIGHT,
199 IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON) );
202 // Add ToolTips to the toolbar.
203 SendMessage( hwndTB, TB_SETTOOLTIPS, (WPARAM) NUMIMAGES,
204 (LPARAM)szToolTips2 );
206 // Reposition the toolbar.
207 GetClientRect( hwnd, &rect );
208 GetWindowRect( hwndTB, &rectTB );
209 MoveWindow( hwndTB, rect.left, rect.top - 2, rect.right - rect.left,
210 MENU_HEIGHT /*rectTB.bottom - rectTB.top */, TRUE);
212 // random, loop, repeat buttons states
214 p_playlist = (playlist_t *)
215 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
216 if( !p_playlist ) break;
218 var_Get( p_playlist , "random", &val );
219 bState = val.b_bool ? TBSTATE_CHECKED : 0;
220 SendMessage( hwndTB, TB_SETSTATE, Random_Event,
221 MAKELONG(bState | TBSTATE_ENABLED, 0) );
222 var_Get( p_playlist , "loop", &val );
223 bState = val.b_bool ? TBSTATE_CHECKED : 0;
224 SendMessage( hwndTB, TB_SETSTATE, Loop_Event,
225 MAKELONG(bState | TBSTATE_ENABLED, 0) );
226 var_Get( p_playlist , "repeat", &val );
227 bState = val.b_bool ? TBSTATE_CHECKED : 0;
228 SendMessage( hwndTB, TB_SETSTATE, Repeat_Event,
229 MAKELONG(bState | TBSTATE_ENABLED, 0) );
230 vlc_object_release( p_playlist );
232 GetClientRect( hwnd, &rect );
233 hListView = CreateWindow( WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD |
234 LVS_REPORT | LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL,
235 rect.left, rect.top + 2*(MENU_HEIGHT+1), rect.right - rect.left,
236 rect.bottom - ( rect.top + 2*MENU_HEIGHT) - MENU_HEIGHT,
237 hwnd, NULL, hInst, NULL );
238 ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
241 lv.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
242 lv.fmt = LVCFMT_LEFT ;
243 GetClientRect( hwnd, &rect );
245 lv.pszText = _T("Name");
247 ListView_InsertColumn( hListView, 0, &lv);
249 lv.pszText = _T("Author");
251 ListView_InsertColumn( hListView, 1, &lv);
252 lv.cx = rect.right - rect.left - 180;
253 lv.pszText = _T("Duration");
255 ListView_InsertColumn( hListView, 2, &lv);
257 SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
259 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
267 EndDialog( hwnd, LOWORD( wp ) );
274 EndDialog( hwnd, LOWORD( wp ) );
277 case ID_MANAGE_OPENPL:
279 b_need_update = VLC_TRUE;
282 case ID_MANAGE_SAVEPL:
283 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
285 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
288 case ID_MANAGE_SIMPLEADD:
289 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
291 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
292 b_need_update = VLC_TRUE;
295 case ID_MANAGE_ADDMRL:
296 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
298 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
299 b_need_update = VLC_TRUE;
304 b_need_update = VLC_TRUE;
308 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
310 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
311 b_need_update = VLC_TRUE;
316 b_need_update = VLC_TRUE;
321 b_need_update = VLC_TRUE;
337 OnSort( ID_SORT_TITLE );
341 OnSort( ID_SORT_RTITLE );
345 OnSort( ID_SORT_AUTHOR );
348 case ID_SORT_RAUTHOR:
349 OnSort( ID_SORT_RAUTHOR );
352 case ID_SORT_SHUFFLE:
353 OnSort( ID_SORT_SHUFFLE );
361 OnDisableSelection();
368 case ID_SEL_SELECTALL:
372 case PopupPlay_Event:
374 b_need_update = VLC_TRUE;
379 b_need_update = VLC_TRUE;
384 b_need_update = VLC_TRUE;
387 case PopupInfo_Event:
389 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
390 b_need_update = VLC_TRUE;
398 if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
399 ( ((LPNMHDR)lp)->code == NM_CUSTOMDRAW ) )
401 SetWindowLong( hwnd, DWL_MSGRESULT,
402 (LONG)ProcessCustomDraw(lp) );
404 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
405 ( ((LPNMHDR)lp)->code == GN_CONTEXTMENU ) )
407 HandlePopupMenu( hwnd, ((PNMRGINFO)lp)->ptAction );
409 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
410 ( ((LPNMHDR)lp)->code == LVN_COLUMNCLICK ) )
412 OnColSelect( ((LPNMLISTVIEW)lp)->iSubItem );
414 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
415 ( ((LPNMHDR)lp)->code == LVN_ITEMACTIVATE ) )
417 OnActivateItem( ((LPNMLISTVIEW)lp)->iSubItem );
422 // the message was not processed
423 // indicate if the base class handled it
430 LRESULT Playlist::ProcessCustomDraw( LPARAM lParam )
432 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
434 switch( lplvcd->nmcd.dwDrawStage )
436 case CDDS_PREPAINT : //Before the paint cycle begins
437 //request notifications for individual listview items
438 return CDRF_NOTIFYITEMDRAW;
440 case CDDS_ITEMPREPAINT: //Before an item is drawn
441 playlist_t *p_playlist = (playlist_t *)
442 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
443 if( p_playlist == NULL ) return CDRF_DODEFAULT;
444 if( (int)lplvcd->nmcd.dwItemSpec == p_playlist->i_index )
446 lplvcd->clrText = RGB(255,0,0);
447 vlc_object_release(p_playlist);
451 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist,
452 (int)lplvcd->nmcd.dwItemSpec );
455 vlc_object_release(p_playlist);
456 return CDRF_DODEFAULT;
458 if( p_item->b_enabled == VLC_FALSE )
460 lplvcd->clrText = RGB(192,192,192);
461 vlc_object_release(p_playlist);
466 return CDRF_DODEFAULT;
469 /**********************************************************************
470 * Handles the display of the "floating" popup
471 **********************************************************************/
472 void Playlist::HandlePopupMenu( HWND hwnd, POINT point )
474 HMENU hMenuTrackPopup;
476 // Create the popup menu.
477 hMenuTrackPopup = CreatePopupMenu();
479 // Append some items.
480 AppendMenu( hMenuTrackPopup, MF_STRING, PopupPlay_Event, _T("Play") );
481 AppendMenu( hMenuTrackPopup, MF_STRING, PopupDel_Event, _T("Delete") );
482 AppendMenu( hMenuTrackPopup, MF_STRING, PopupEna_Event,
483 _T("Toggle enabled") );
484 AppendMenu( hMenuTrackPopup, MF_STRING, PopupInfo_Event, _T("Info") );
486 /* Draw and track the "floating" popup */
487 TrackPopupMenu( hMenuTrackPopup, 0, point.x, point.y, 0, hwnd, NULL );
489 /* Destroy the menu since were are done with it. */
490 DestroyMenu( hMenuTrackPopup );
493 /**********************************************************************
494 * Update the playlist
495 **********************************************************************/
496 void Playlist::UpdatePlaylist()
501 b_need_update = VLC_FALSE;
504 playlist_t *p_playlist = (playlist_t *)
505 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
506 if( p_playlist == NULL ) return;
508 /* Update the colour of items */
510 vlc_mutex_lock( &p_playlist->object_lock );
511 if( p_intf->p_sys->i_playing != p_playlist->i_index )
513 // p_playlist->i_index in RED
516 // if exists, p_intf->p_sys->i_playing in BLACK
517 p_intf->p_sys->i_playing = p_playlist->i_index;
519 vlc_mutex_unlock( &p_playlist->object_lock );
521 vlc_object_release( p_playlist );
524 /**********************************************************************
525 * Rebuild the playlist
526 **********************************************************************/
527 void Playlist::Rebuild()
529 playlist_t *p_playlist = (playlist_t *)
530 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
531 if( p_playlist == NULL ) return;
534 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
536 /* Clear the list... */
537 ListView_DeleteAllItems( hListView );
539 /* ...and rebuild it */
540 vlc_mutex_lock( &p_playlist->object_lock );
541 for( int i = 0; i < p_playlist->i_size; i++ )
549 ListView_InsertItem( hListView, &lv );
550 ListView_SetItemText( hListView, lv.iItem, 0,
551 _FROMMB(p_playlist->pp_items[i]->input.psz_name) );
554 vlc_mutex_unlock( &p_playlist->object_lock );
557 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED |
558 LVIS_SELECTED, LVIS_STATEIMAGEMASK )
560 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED,
561 LVIS_STATEIMAGEMASK );
563 vlc_object_release( p_playlist );
566 /**********************************************************************
567 * Update one playlist item
568 **********************************************************************/
569 void Playlist::UpdateItem( int i )
571 playlist_t *p_playlist = (playlist_t *)
572 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
574 if( p_playlist == NULL ) return;
576 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i );
580 vlc_object_release(p_playlist);
584 ListView_SetItemText( hListView, i, 0, _FROMMB(p_item->input.psz_name) );
585 ListView_SetItemText( hListView, i, 1,
586 _FROMMB( vlc_input_item_GetInfo( &p_item->input,
587 _("General") , _("Author") ) ) );
589 char psz_duration[MSTRTIME_MAX_SIZE];
590 mtime_t dur = p_item->input.i_duration;
591 if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
592 else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
594 ListView_SetItemText( hListView, i, 3, _FROMMB(psz_duration) );
596 vlc_object_release(p_playlist);
599 /**********************************************************************
601 **********************************************************************/
602 void Playlist::DeleteItem( int item )
604 playlist_t *p_playlist = (playlist_t *)
605 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
606 if( p_playlist == NULL ) return;
608 playlist_Delete( p_playlist, item );
609 ListView_DeleteItem( hListView, item );
611 vlc_object_release( p_playlist );
614 /**********************************************************************
616 **********************************************************************/
617 void Playlist::OnOpen()
620 TCHAR DateiName[80+1] = _T("\0");
621 static TCHAR szFilter[] = _T("All playlists (*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u)\0*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u\0");
623 playlist_t *p_playlist = (playlist_t *)
624 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
625 if( p_playlist == NULL ) return;
627 memset( &ofn, 0, sizeof(OPENFILENAME) );
628 ofn.lStructSize = sizeof (OPENFILENAME);
629 ofn.hwndOwner = NULL;
630 ofn.hInstance = hInst;
631 ofn.lpstrFilter = szFilter;
632 ofn.lpstrCustomFilter = NULL;
633 ofn.nMaxCustFilter = 0;
634 ofn.nFilterIndex = 1;
635 ofn.lpstrFile = (LPTSTR) DateiName;
637 ofn.lpstrFileTitle = NULL;
638 ofn.nMaxFileTitle = 40;
639 ofn.lpstrInitialDir = NULL;
640 ofn.lpstrTitle = _T("Open playlist");
643 ofn.nFileExtension = 0;
644 ofn.lpstrDefExt = NULL;
647 ofn.lpTemplateName = NULL;
649 if( GetOpenFileName((LPOPENFILENAME)&ofn) )
651 playlist_Import( p_playlist, _TOMB(ofn.lpstrFile) );
654 vlc_object_release( p_playlist );
657 void Playlist::OnSave()
659 TCHAR szFile[NMAXFILE] = _T("\0");
661 TCHAR psz_filters[1000];
670 { { "M3U file", "*.m3u", "export-m3u" },
671 { "PLS file", "*.pls", "export-pls" }
674 for( int i_len = 0, i = 0; i < sizeof(formats)/sizeof(formats[0]); i++ )
676 _tcscpy( psz_filters + i_len, _FROMMB(formats[i].psz_desc) );
677 i_len = i_len + _tcslen( psz_filters + i_len );
678 psz_filters[i_len++] = '\0';
679 _tcscpy( psz_filters + i_len, _FROMMB(formats[i].psz_filter) );
680 i_len = i_len + _tcslen( psz_filters + i_len );
681 psz_filters[i_len++] = '\0';
682 if( i == sizeof(formats)/sizeof(formats[0]) -1 )
683 psz_filters[i_len] = '\0';
686 memset( &(ofn), 0, sizeof(ofn));
687 ofn.lStructSize = sizeof(ofn);
688 ofn.hwndOwner = NULL;
689 ofn.lpstrFile = szFile;
690 ofn.nMaxFile = NMAXFILE;
691 ofn.lpstrFilter = psz_filters;
692 ofn.lpstrTitle = _T("Save playlist");
693 ofn.Flags = OFN_HIDEREADONLY;
695 if( GetSaveFileName( (LPOPENFILENAME)&ofn ) )
697 playlist_t * p_playlist = (playlist_t *)
698 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
700 if( p_playlist && ofn.lpstrFile )
702 playlist_Export( p_playlist, _TOMB(ofn.lpstrFile),
703 formats[ofn.nFilterIndex ?
704 ofn.nFilterIndex - 1 : 0].psz_module );
707 if( p_playlist ) vlc_object_release( p_playlist );
711 void Playlist::OnAddFile()
713 // Same code as in Interface
715 TCHAR DateiName[80+1] = _T("\0");
716 static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
718 playlist_t *p_playlist = (playlist_t *)
719 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
720 if( p_playlist == NULL ) return;
722 memset( &ofn, 0, sizeof(OPENFILENAME) );
723 ofn.lStructSize = sizeof(OPENFILENAME);
724 ofn.hwndOwner = NULL;
725 ofn.hInstance = hInst;
726 ofn.lpstrFilter = szFilter;
727 ofn.lpstrCustomFilter = NULL;
728 ofn.nMaxCustFilter = 0;
729 ofn.nFilterIndex = 1;
730 ofn.lpstrFile = (LPTSTR)DateiName;
732 ofn.lpstrFileTitle = NULL;
733 ofn.nMaxFileTitle = 40;
734 ofn.lpstrInitialDir = NULL;
735 ofn.lpstrTitle = _T("Quick Open File");
738 ofn.nFileExtension = 0;
739 ofn.lpstrDefExt = NULL;
742 ofn.lpTemplateName = NULL;
744 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
746 if( GetOpenFileName( (LPOPENFILENAME)&ofn ) )
748 char *psz_filename = _TOMB(ofn.lpstrFile);
749 playlist_Add( p_playlist, psz_filename, psz_filename,
750 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
753 vlc_object_release( p_playlist );
756 void Playlist::OnAddMRL()
760 /**********************************************************************
761 * Selection functions
762 **********************************************************************/
763 void Playlist::OnDeleteSelection()
765 /* Delete from the end to the beginning, to avoid a shift of indices */
766 for( long item = ((int) ListView_GetItemCount( hListView ) - 1);
769 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
776 void Playlist::OnInvertSelection()
780 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
782 iState = ListView_GetItemState( hListView, item, LVIS_STATEIMAGEMASK );
783 ListView_SetItemState( hListView, item, iState ^ LVIS_SELECTED,
784 LVIS_STATEIMAGEMASK );
788 void Playlist::OnEnableSelection()
790 playlist_t *p_playlist = (playlist_t *)
791 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
792 if( p_playlist == NULL ) return;
794 for( long item = ListView_GetItemCount( hListView ) - 1;
797 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
799 playlist_item_t *p_item =
800 playlist_ItemGetByPos( p_playlist, item );
801 playlist_Enable( p_playlist, p_item );
805 vlc_object_release( p_playlist);
808 void Playlist::OnDisableSelection()
810 playlist_t *p_playlist = (playlist_t *)
811 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
812 if( p_playlist == NULL ) return;
814 for( long item = ListView_GetItemCount( hListView ) - 1;
817 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
820 playlist_item_t *p_item =
821 playlist_ItemGetByPos( p_playlist, item );
822 playlist_Disable( p_playlist, p_item );
826 vlc_object_release( p_playlist);
829 void Playlist::OnSelectAll()
831 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
833 ListView_SetItemState( hListView, item, LVIS_FOCUSED | LVIS_SELECTED,
834 LVIS_STATEIMAGEMASK );
838 void Playlist::OnActivateItem( int i_item )
840 playlist_t *p_playlist = (playlist_t *)
841 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
842 if( p_playlist == NULL ) return;
844 playlist_Goto( p_playlist, i_item );
846 vlc_object_release( p_playlist );
849 void Playlist::ShowInfos( HWND hwnd, int i_item )
851 playlist_t *p_playlist = (playlist_t *)
852 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
853 if( p_playlist == NULL ) return;
855 vlc_mutex_lock( &p_playlist->object_lock);
856 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
857 vlc_mutex_unlock( &p_playlist->object_lock );
861 ItemInfoDialog *iteminfo_dialog =
862 new ItemInfoDialog( p_intf, hInst, p_item );
863 CreateDialogBox( hwnd, iteminfo_dialog );
864 UpdateItem( i_item );
865 delete iteminfo_dialog;
868 vlc_object_release( p_playlist );
871 /********************************************************************
873 ********************************************************************/
874 void Playlist::OnUp()
876 playlist_t *p_playlist = (playlist_t *)
877 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
878 if( p_playlist == NULL ) return;
880 /* We use the first selected item, so find it */
882 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
884 if( i_item > 0 && i_item < p_playlist->i_size )
886 playlist_Move( p_playlist , i_item, i_item - 1);
889 ListView_SetItemState( hListView, i_item - 1, LVIS_FOCUSED,
890 LVIS_STATEIMAGEMASK );
894 ListView_SetItemState( hListView, 0, LVIS_FOCUSED,
895 LVIS_STATEIMAGEMASK );
898 vlc_object_release( p_playlist );
903 void Playlist::OnDown()
905 playlist_t *p_playlist = (playlist_t *)
906 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
907 if( p_playlist == NULL ) return;
909 /* We use the first selected item, so find it */
911 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
913 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
915 playlist_Move( p_playlist , i_item, i_item + 2 );
916 ListView_SetItemState( hListView, i_item + 1, LVIS_FOCUSED,
917 LVIS_STATEIMAGEMASK );
919 vlc_object_release( p_playlist );
924 /**********************************************************************
925 * Playlist mode functions
926 **********************************************************************/
927 void Playlist::OnRandom()
930 int bState = SendMessage( hwndTB, TB_GETSTATE, Random_Event, 0 );
931 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
933 playlist_t *p_playlist = (playlist_t *)
934 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
935 if( p_playlist == NULL ) return;
937 var_Set( p_playlist , "random", val );
938 vlc_object_release( p_playlist );
941 void Playlist::OnLoop ()
944 int bState = SendMessage( hwndTB, TB_GETSTATE, Loop_Event, 0 );
945 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
947 playlist_t *p_playlist = (playlist_t *)
948 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
949 if( p_playlist == NULL ) return;
951 var_Set( p_playlist , "loop", val );
952 vlc_object_release( p_playlist );
955 void Playlist::OnRepeat ()
958 int bState = SendMessage( hwndTB, TB_GETSTATE, Repeat_Event, 0 );
959 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
961 playlist_t *p_playlist = (playlist_t *)
962 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
963 if( p_playlist == NULL ) return;
965 var_Set( p_playlist , "repeat", val );
966 vlc_object_release( p_playlist );
969 /********************************************************************
971 ********************************************************************/
972 void Playlist::OnSort( UINT event )
974 playlist_t *p_playlist = (playlist_t *)
975 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
976 if( p_playlist == NULL ) return;
981 playlist_SortTitle( p_playlist , ORDER_NORMAL );
984 playlist_SortTitle( p_playlist , ORDER_REVERSE );
987 playlist_SortAuthor(p_playlist , ORDER_NORMAL );
989 case ID_SORT_RAUTHOR:
990 playlist_SortAuthor( p_playlist , ORDER_REVERSE );
992 case ID_SORT_SHUFFLE:
993 playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
997 vlc_object_release( p_playlist );
999 b_need_update = VLC_TRUE;
1004 void Playlist::OnColSelect( int iSubItem )
1006 playlist_t *p_playlist = (playlist_t *)
1007 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1008 if( p_playlist == NULL ) return;
1013 if( i_title_sorted != 1 )
1015 playlist_SortTitle( p_playlist, ORDER_NORMAL );
1020 playlist_SortTitle( p_playlist, ORDER_REVERSE );
1021 i_title_sorted = -1;
1025 if( i_author_sorted != 1 )
1027 playlist_SortAuthor( p_playlist, ORDER_NORMAL );
1028 i_author_sorted = 1;
1032 playlist_SortAuthor( p_playlist, ORDER_REVERSE );
1033 i_author_sorted = -1;
1040 vlc_object_release( p_playlist );
1042 b_need_update = VLC_TRUE;
1047 /*****************************************************************************
1048 * Popup management functions
1049 *****************************************************************************/
1050 void Playlist::OnPopupPlay()
1053 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1055 playlist_t *p_playlist = (playlist_t *)
1056 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1057 if( p_playlist == NULL ) return;
1059 if( i_popup_item != -1 )
1061 playlist_Goto( p_playlist, i_popup_item );
1064 vlc_object_release( p_playlist );
1067 void Playlist::OnPopupDel()
1070 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1072 DeleteItem( i_popup_item );
1075 void Playlist::OnPopupEna()
1078 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1080 playlist_t *p_playlist = (playlist_t *)
1081 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
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 vlc_object_release( p_playlist);
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 );