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 /***********************************************************************
146 Processes messages sent to the main window.
148 ***********************************************************************/
149 LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
156 playlist_t *p_playlist;
161 INITCOMMONCONTROLSEX iccex;
163 LRESULT lResult = CBaseWindow::WndProc( hwnd, msg, wp, lp, pbProcessed );
164 BOOL bWasProcessed = *pbProcessed;
170 shidi.dwMask = SHIDIM_FLAGS;
171 shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
172 SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
174 SHInitDialog( &shidi );
176 //Create the menubar.
177 memset( &mbi, 0, sizeof (SHMENUBARINFO) );
178 mbi.cbSize = sizeof (SHMENUBARINFO);
179 mbi.hwndParent = hwnd;
180 mbi.dwFlags = SHCMBF_HMENU;
181 mbi.nToolBarId = IDR_MENUBAR2;
182 mbi.hInstRes = hInst;
186 if( !SHCreateMenuBar(&mbi) )
188 MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
194 iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
195 iccex.dwICC = ICC_BAR_CLASSES;
197 // Registers TOOLBAR control classes from the common control dll
198 InitCommonControlsEx (&iccex);
200 // Create the toolbar control.
201 dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS |
202 WS_EX_OVERLAPPEDWINDOW | CCS_NOPARENTALIGN;
204 hwndTB = CreateToolbarEx( hwnd, dwStyle, 0, NUMIMAGES,
205 hInst, IDB_BITMAP3, tbButton2,
206 sizeof (tbButton2) / sizeof (TBBUTTON),
207 BUTTONWIDTH, BUTTONHEIGHT,
208 IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON) );
211 *pbProcessed = bWasProcessed;
216 // Add ToolTips to the toolbar.
217 SendMessage( hwndTB, TB_SETTOOLTIPS, (WPARAM) NUMIMAGES,
218 (LPARAM)szToolTips2 );
220 // Reposition the toolbar.
221 GetClientRect( hwnd, &rect );
222 GetWindowRect( hwndTB, &rectTB );
223 MoveWindow( hwndTB, rect.left, rect.top - 2, rect.right - rect.left,
224 MENU_HEIGHT /*rectTB.bottom - rectTB.top */, TRUE);
226 // random, loop, repeat buttons states
228 p_playlist = (playlist_t *)
229 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
230 if( p_playlist == NULL )
232 *pbProcessed = bWasProcessed;
236 var_Get( p_playlist , "random", &val );
237 bState = val.b_bool ? TBSTATE_CHECKED : 0;
238 SendMessage( hwndTB, TB_SETSTATE, Random_Event,
239 MAKELONG(bState | TBSTATE_ENABLED, 0) );
240 var_Get( p_playlist , "loop", &val );
241 bState = val.b_bool ? TBSTATE_CHECKED : 0;
242 SendMessage( hwndTB, TB_SETSTATE, Loop_Event,
243 MAKELONG(bState | TBSTATE_ENABLED, 0) );
244 var_Get( p_playlist , "repeat", &val );
245 bState = val.b_bool ? TBSTATE_CHECKED : 0;
246 SendMessage( hwndTB, TB_SETSTATE, Repeat_Event,
247 MAKELONG(bState | TBSTATE_ENABLED, 0) );
248 vlc_object_release( p_playlist );
250 GetClientRect( hwnd, &rect );
251 hListView = CreateWindow( WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD |
252 LVS_REPORT | LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL,
253 rect.left, rect.top + 2*(MENU_HEIGHT+1), rect.right - rect.left,
254 rect.bottom - ( rect.top + 2*MENU_HEIGHT) - MENU_HEIGHT,
255 hwnd, NULL, hInst, NULL );
256 ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
259 lv.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
260 lv.fmt = LVCFMT_LEFT ;
261 GetClientRect( hwnd, &rect );
263 lv.pszText = _T("Name");
265 ListView_InsertColumn( hListView, 0, &lv);
267 lv.pszText = _T("Author");
269 ListView_InsertColumn( hListView, 1, &lv);
270 lv.cx = rect.right - rect.left - 180;
271 lv.pszText = _T("Duration");
273 ListView_InsertColumn( hListView, 2, &lv);
275 SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
277 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
289 EndDialog( hwnd, LOWORD( wp ) );
292 case ID_MANAGE_OPENPL:
294 b_need_update = VLC_TRUE;
297 case ID_MANAGE_SAVEPL:
298 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
300 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
303 case ID_MANAGE_SIMPLEADD:
304 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
306 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
307 b_need_update = VLC_TRUE;
310 case ID_MANAGE_ADDMRL:
311 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
313 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
314 b_need_update = VLC_TRUE;
319 b_need_update = VLC_TRUE;
323 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
325 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
326 b_need_update = VLC_TRUE;
331 b_need_update = VLC_TRUE;
336 b_need_update = VLC_TRUE;
352 OnSort( ID_SORT_TITLE );
356 OnSort( ID_SORT_RTITLE );
360 OnSort( ID_SORT_AUTHOR );
363 case ID_SORT_RAUTHOR:
364 OnSort( ID_SORT_RAUTHOR );
367 case ID_SORT_SHUFFLE:
368 OnSort( ID_SORT_SHUFFLE );
376 OnDisableSelection();
383 case ID_SEL_SELECTALL:
387 case PopupPlay_Event:
389 b_need_update = VLC_TRUE;
394 b_need_update = VLC_TRUE;
399 b_need_update = VLC_TRUE;
402 case PopupInfo_Event:
404 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
405 b_need_update = VLC_TRUE;
409 *pbProcessed = bWasProcessed;
415 if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
416 ( ((LPNMHDR)lp)->code == NM_CUSTOMDRAW ) )
418 SetWindowLong( hwnd, DWL_MSGRESULT,
419 (LONG)ProcessCustomDraw(lp) );
422 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
423 ( ((LPNMHDR)lp)->code == GN_CONTEXTMENU ) )
425 HandlePopupMenu( hwnd, ((PNMRGINFO)lp)->ptAction );
428 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
429 ( ((LPNMHDR)lp)->code == LVN_COLUMNCLICK ) )
431 OnColSelect( ((LPNMLISTVIEW)lp)->iSubItem );
434 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
435 ( ((LPNMHDR)lp)->code == LVN_ITEMACTIVATE ) )
437 OnActivateItem( ((LPNMLISTVIEW)lp)->iSubItem );
441 *pbProcessed = bWasProcessed;
446 // the message was not processed
447 // indicate if the base class handled it
448 *pbProcessed = bWasProcessed;
456 LRESULT Playlist::ProcessCustomDraw( LPARAM lParam )
458 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
460 switch( lplvcd->nmcd.dwDrawStage )
462 case CDDS_PREPAINT : //Before the paint cycle begins
463 //request notifications for individual listview items
464 return CDRF_NOTIFYITEMDRAW;
466 case CDDS_ITEMPREPAINT: //Before an item is drawn
467 playlist_t *p_playlist = (playlist_t *)
468 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
469 if( p_playlist == NULL ) return CDRF_DODEFAULT;
470 if( (int)lplvcd->nmcd.dwItemSpec == p_playlist->i_index )
472 lplvcd->clrText = RGB(255,0,0);
473 vlc_object_release(p_playlist);
477 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist,
478 (int)lplvcd->nmcd.dwItemSpec );
481 vlc_object_release(p_playlist);
482 return CDRF_DODEFAULT;
484 if( p_item->b_enabled == VLC_FALSE )
486 lplvcd->clrText = RGB(192,192,192);
487 vlc_object_release(p_playlist);
492 return CDRF_DODEFAULT;
495 /**********************************************************************
496 * Handles the display of the "floating" popup
497 **********************************************************************/
498 void Playlist::HandlePopupMenu( HWND hwnd, POINT point )
500 HMENU hMenuTrackPopup;
502 // Create the popup menu.
503 hMenuTrackPopup = CreatePopupMenu();
505 // Append some items.
506 AppendMenu( hMenuTrackPopup, MF_STRING, PopupPlay_Event, _T("Play") );
507 AppendMenu( hMenuTrackPopup, MF_STRING, PopupDel_Event, _T("Delete") );
508 AppendMenu( hMenuTrackPopup, MF_STRING, PopupEna_Event,
509 _T("Toggle enabled") );
510 AppendMenu( hMenuTrackPopup, MF_STRING, PopupInfo_Event, _T("Info") );
512 /* Draw and track the "floating" popup */
513 TrackPopupMenu( hMenuTrackPopup, 0, point.x, point.y, 0, hwnd, NULL );
515 /* Destroy the menu since were are done with it. */
516 DestroyMenu( hMenuTrackPopup );
519 /**********************************************************************
520 * Update the playlist
521 **********************************************************************/
522 void Playlist::UpdatePlaylist()
527 b_need_update = VLC_FALSE;
530 playlist_t *p_playlist = (playlist_t *)
531 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
532 if( p_playlist == NULL ) return;
534 /* Update the colour of items */
536 vlc_mutex_lock( &p_playlist->object_lock );
537 if( p_intf->p_sys->i_playing != p_playlist->i_index )
539 // p_playlist->i_index in RED
542 // if exists, p_intf->p_sys->i_playing in BLACK
543 p_intf->p_sys->i_playing = p_playlist->i_index;
545 vlc_mutex_unlock( &p_playlist->object_lock );
547 vlc_object_release( p_playlist );
550 /**********************************************************************
551 * Rebuild the playlist
552 **********************************************************************/
553 void Playlist::Rebuild()
555 playlist_t *p_playlist = (playlist_t *)
556 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
557 if( p_playlist == NULL ) return;
560 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
562 /* Clear the list... */
563 ListView_DeleteAllItems( hListView );
565 /* ...and rebuild it */
566 vlc_mutex_lock( &p_playlist->object_lock );
567 for( int i = 0; i < p_playlist->i_size; i++ )
575 ListView_InsertItem( hListView, &lv );
576 ListView_SetItemText( hListView, lv.iItem, 0,
577 _FROMMB(p_playlist->pp_items[i]->input.psz_name) );
580 vlc_mutex_unlock( &p_playlist->object_lock );
583 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED |
584 LVIS_SELECTED, LVIS_STATEIMAGEMASK )
586 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED,
587 LVIS_STATEIMAGEMASK );
589 vlc_object_release( p_playlist );
592 /**********************************************************************
593 * Update one playlist item
594 **********************************************************************/
595 void Playlist::UpdateItem( int i )
597 playlist_t *p_playlist = (playlist_t *)
598 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
600 if( p_playlist == NULL ) return;
602 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i );
606 vlc_object_release(p_playlist);
610 ListView_SetItemText( hListView, i, 0, _FROMMB(p_item->input.psz_name) );
611 ListView_SetItemText( hListView, i, 1,
612 _FROMMB( vlc_input_item_GetInfo( &p_item->input,
613 _("General") , _("Author") ) ) );
615 char psz_duration[MSTRTIME_MAX_SIZE];
616 mtime_t dur = p_item->input.i_duration;
617 if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
618 else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
620 ListView_SetItemText( hListView, i, 3, _FROMMB(psz_duration) );
622 vlc_object_release(p_playlist);
625 /**********************************************************************
627 **********************************************************************/
628 void Playlist::DeleteItem( int item )
630 playlist_t *p_playlist = (playlist_t *)
631 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
632 if( p_playlist == NULL ) return;
634 playlist_Delete( p_playlist, item );
635 ListView_DeleteItem( hListView, item );
637 vlc_object_release( p_playlist );
640 /**********************************************************************
642 **********************************************************************/
643 void Playlist::OnOpen()
646 TCHAR DateiName[80+1] = _T("\0");
647 static TCHAR szFilter[] = _T("All playlists (*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u)\0*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u\0");
649 playlist_t *p_playlist = (playlist_t *)
650 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
651 if( p_playlist == NULL ) return;
653 memset( &ofn, 0, sizeof(OPENFILENAME) );
654 ofn.lStructSize = sizeof (OPENFILENAME);
655 ofn.hwndOwner = NULL;
656 ofn.hInstance = hInst;
657 ofn.lpstrFilter = szFilter;
658 ofn.lpstrCustomFilter = NULL;
659 ofn.nMaxCustFilter = 0;
660 ofn.nFilterIndex = 1;
661 ofn.lpstrFile = (LPTSTR) DateiName;
663 ofn.lpstrFileTitle = NULL;
664 ofn.nMaxFileTitle = 40;
665 ofn.lpstrInitialDir = NULL;
666 ofn.lpstrTitle = _T("Open playlist");
669 ofn.nFileExtension = 0;
670 ofn.lpstrDefExt = NULL;
673 ofn.lpTemplateName = NULL;
675 if( GetOpenFileName((LPOPENFILENAME)&ofn) )
677 playlist_Import( p_playlist, _TOMB(ofn.lpstrFile) );
680 vlc_object_release( p_playlist );
683 void Playlist::OnSave()
685 TCHAR szFile[NMAXFILE] = _T("\0");
687 TCHAR psz_filters[1000];
696 { { "M3U file", "*.m3u", "export-m3u" },
697 { "PLS file", "*.pls", "export-pls" }
700 for( int i_len = 0, i = 0; i < sizeof(formats)/sizeof(formats[0]); i++ )
702 _tcscpy( psz_filters + i_len, _FROMMB(formats[i].psz_desc) );
703 i_len = i_len + _tcslen( psz_filters + i_len );
704 psz_filters[i_len++] = '\0';
705 _tcscpy( psz_filters + i_len, _FROMMB(formats[i].psz_filter) );
706 i_len = i_len + _tcslen( psz_filters + i_len );
707 psz_filters[i_len++] = '\0';
708 if( i == sizeof(formats)/sizeof(formats[0]) -1 )
709 psz_filters[i_len] = '\0';
712 memset( &(ofn), 0, sizeof(ofn));
713 ofn.lStructSize = sizeof(ofn);
714 ofn.hwndOwner = NULL;
715 ofn.lpstrFile = szFile;
716 ofn.nMaxFile = NMAXFILE;
717 ofn.lpstrFilter = psz_filters;
718 ofn.lpstrTitle = _T("Save playlist");
719 ofn.Flags = OFN_HIDEREADONLY;
721 if( GetSaveFileName( (LPOPENFILENAME)&ofn ) )
723 playlist_t * p_playlist = (playlist_t *)
724 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
726 if( p_playlist && ofn.lpstrFile )
728 playlist_Export( p_playlist, _TOMB(ofn.lpstrFile),
729 formats[ofn.nFilterIndex ?
730 ofn.nFilterIndex - 1 : 0].psz_module );
733 if( p_playlist ) vlc_object_release( p_playlist );
737 void Playlist::OnAddFile()
739 // Same code as in Interface
741 TCHAR DateiName[80+1] = _T("\0");
742 static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
744 playlist_t *p_playlist = (playlist_t *)
745 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
746 if( p_playlist == NULL ) return;
748 memset( &ofn, 0, sizeof(OPENFILENAME) );
749 ofn.lStructSize = sizeof(OPENFILENAME);
750 ofn.hwndOwner = NULL;
751 ofn.hInstance = hInst;
752 ofn.lpstrFilter = szFilter;
753 ofn.lpstrCustomFilter = NULL;
754 ofn.nMaxCustFilter = 0;
755 ofn.nFilterIndex = 1;
756 ofn.lpstrFile = (LPTSTR)DateiName;
758 ofn.lpstrFileTitle = NULL;
759 ofn.nMaxFileTitle = 40;
760 ofn.lpstrInitialDir = NULL;
761 ofn.lpstrTitle = _T("Quick Open File");
764 ofn.nFileExtension = 0;
765 ofn.lpstrDefExt = NULL;
768 ofn.lpTemplateName = NULL;
770 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
772 if( GetOpenFileName( (LPOPENFILENAME)&ofn ) )
774 char *psz_filename = _TOMB(ofn.lpstrFile);
775 playlist_Add( p_playlist, psz_filename, psz_filename,
776 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
779 vlc_object_release( p_playlist );
782 void Playlist::OnAddMRL()
786 /**********************************************************************
787 * Selection functions
788 **********************************************************************/
789 void Playlist::OnDeleteSelection()
791 /* Delete from the end to the beginning, to avoid a shift of indices */
792 for( long item = ((int) ListView_GetItemCount( hListView ) - 1);
795 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
802 void Playlist::OnInvertSelection()
806 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
808 iState = ListView_GetItemState( hListView, item, LVIS_STATEIMAGEMASK );
809 ListView_SetItemState( hListView, item, iState ^ LVIS_SELECTED,
810 LVIS_STATEIMAGEMASK );
814 void Playlist::OnEnableSelection()
816 playlist_t *p_playlist = (playlist_t *)
817 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
818 if( p_playlist == NULL ) return;
820 for( long item = ListView_GetItemCount( hListView ) - 1;
823 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
825 playlist_item_t *p_item =
826 playlist_ItemGetByPos( p_playlist, item );
827 playlist_Enable( p_playlist, p_item );
831 vlc_object_release( p_playlist);
834 void Playlist::OnDisableSelection()
836 playlist_t *p_playlist = (playlist_t *)
837 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
838 if( p_playlist == NULL ) return;
840 for( long item = ListView_GetItemCount( hListView ) - 1;
843 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
846 playlist_item_t *p_item =
847 playlist_ItemGetByPos( p_playlist, item );
848 playlist_Disable( p_playlist, p_item );
852 vlc_object_release( p_playlist);
855 void Playlist::OnSelectAll()
857 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
859 ListView_SetItemState( hListView, item, LVIS_FOCUSED | LVIS_SELECTED,
860 LVIS_STATEIMAGEMASK );
864 void Playlist::OnActivateItem( int i_item )
866 playlist_t *p_playlist = (playlist_t *)
867 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
868 if( p_playlist == NULL ) return;
870 playlist_Goto( p_playlist, i_item );
872 vlc_object_release( p_playlist );
875 void Playlist::ShowInfos( HWND hwnd, int i_item )
877 playlist_t *p_playlist = (playlist_t *)
878 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
879 if( p_playlist == NULL ) return;
881 vlc_mutex_lock( &p_playlist->object_lock);
882 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
883 vlc_mutex_unlock( &p_playlist->object_lock );
887 ItemInfoDialog *iteminfo_dialog =
888 new ItemInfoDialog( p_intf, hInst, p_item );
889 DialogBoxParam( hInst, (LPCTSTR)IDD_DUMMY, hwnd,
890 (DLGPROC)iteminfo_dialog->BaseWndProc,
891 (long)iteminfo_dialog );
892 UpdateItem( i_item );
893 delete iteminfo_dialog;
896 vlc_object_release( p_playlist );
899 /********************************************************************
901 ********************************************************************/
902 void Playlist::OnUp()
904 playlist_t *p_playlist = (playlist_t *)
905 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
906 if( p_playlist == NULL ) return;
908 /* We use the first selected item, so find it */
910 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
912 if( i_item > 0 && i_item < p_playlist->i_size )
914 playlist_Move( p_playlist , i_item, i_item - 1);
917 ListView_SetItemState( hListView, i_item - 1, LVIS_FOCUSED,
918 LVIS_STATEIMAGEMASK );
922 ListView_SetItemState( hListView, 0, LVIS_FOCUSED,
923 LVIS_STATEIMAGEMASK );
926 vlc_object_release( p_playlist );
931 void Playlist::OnDown()
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 /* We use the first selected item, so find it */
939 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
941 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
943 playlist_Move( p_playlist , i_item, i_item + 2 );
944 ListView_SetItemState( hListView, i_item + 1, LVIS_FOCUSED,
945 LVIS_STATEIMAGEMASK );
947 vlc_object_release( p_playlist );
952 /**********************************************************************
953 * Playlist mode functions
954 **********************************************************************/
955 void Playlist::OnRandom()
958 int bState = SendMessage( hwndTB, TB_GETSTATE, Random_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 , "random", val );
966 vlc_object_release( p_playlist );
969 void Playlist::OnLoop ()
972 int bState = SendMessage( hwndTB, TB_GETSTATE, Loop_Event, 0 );
973 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
975 playlist_t *p_playlist = (playlist_t *)
976 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
977 if( p_playlist == NULL ) return;
979 var_Set( p_playlist , "loop", val );
980 vlc_object_release( p_playlist );
983 void Playlist::OnRepeat ()
986 int bState = SendMessage( hwndTB, TB_GETSTATE, Repeat_Event, 0 );
987 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
989 playlist_t *p_playlist = (playlist_t *)
990 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
991 if( p_playlist == NULL ) return;
993 var_Set( p_playlist , "repeat", val );
994 vlc_object_release( p_playlist );
997 /********************************************************************
999 ********************************************************************/
1000 void Playlist::OnSort( UINT event )
1002 playlist_t *p_playlist = (playlist_t *)
1003 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1004 if( p_playlist == NULL ) return;
1009 playlist_SortTitle( p_playlist , ORDER_NORMAL );
1011 case ID_SORT_RTITLE:
1012 playlist_SortTitle( p_playlist , ORDER_REVERSE );
1014 case ID_SORT_AUTHOR:
1015 playlist_SortAuthor(p_playlist , ORDER_NORMAL );
1017 case ID_SORT_RAUTHOR:
1018 playlist_SortAuthor( p_playlist , ORDER_REVERSE );
1020 case ID_SORT_SHUFFLE:
1021 playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
1025 vlc_object_release( p_playlist );
1027 b_need_update = VLC_TRUE;
1032 void Playlist::OnColSelect( int iSubItem )
1034 playlist_t *p_playlist = (playlist_t *)
1035 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1036 if( p_playlist == NULL ) return;
1041 if( i_title_sorted != 1 )
1043 playlist_SortTitle( p_playlist, ORDER_NORMAL );
1048 playlist_SortTitle( p_playlist, ORDER_REVERSE );
1049 i_title_sorted = -1;
1053 if( i_author_sorted != 1 )
1055 playlist_SortAuthor( p_playlist, ORDER_NORMAL );
1056 i_author_sorted = 1;
1060 playlist_SortAuthor( p_playlist, ORDER_REVERSE );
1061 i_author_sorted = -1;
1068 vlc_object_release( p_playlist );
1070 b_need_update = VLC_TRUE;
1075 /*****************************************************************************
1076 * Popup management functions
1077 *****************************************************************************/
1078 void Playlist::OnPopupPlay()
1081 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1083 playlist_t *p_playlist = (playlist_t *)
1084 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1085 if( p_playlist == NULL ) return;
1087 if( i_popup_item != -1 )
1089 playlist_Goto( p_playlist, i_popup_item );
1092 vlc_object_release( p_playlist );
1095 void Playlist::OnPopupDel()
1098 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1100 DeleteItem( i_popup_item );
1103 void Playlist::OnPopupEna()
1106 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1108 playlist_t *p_playlist = (playlist_t *)
1109 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1110 if( p_playlist == NULL ) return;
1112 playlist_item_t *p_item =
1113 playlist_ItemGetByPos( p_playlist, i_popup_item );
1115 if( p_playlist->pp_items[i_popup_item]->b_enabled )
1116 //playlist_IsEnabled( p_playlist, i_popup_item ) )
1118 playlist_Disable( p_playlist, p_item );
1122 playlist_Enable( p_playlist, p_item );
1125 vlc_object_release( p_playlist);
1126 UpdateItem( i_popup_item );
1129 void Playlist::OnPopupInfo( HWND hwnd )
1132 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1134 ShowInfos( hwnd, i_popup_item );