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, 0, -1},
88 {1, ID_MANAGE_SAVEPL, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
89 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, -1},
90 {2, ID_MANAGE_SIMPLEADD, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
91 {3, ID_MANAGE_ADDMRL, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
92 {4, ID_SEL_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
93 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, -1},
94 {5, Infos_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
95 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, -1},
96 {6, Up_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
97 {7, Down_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, -1},
98 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, -1},
99 {8, Random_Event, TBSTATE_ENABLED, TBSTYLE_CHECK, 0, -1},
100 {9, Loop_Event, TBSTATE_ENABLED, TBSTYLE_CHECK, 0, -1},
101 {10, Repeat_Event, TBSTATE_ENABLED, TBSTYLE_CHECK, 0, -1}
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, L"SHCreateMenuBar Failed", L"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, NULL, 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");
695 } formats[] = {{ _T("M3U file"), _T("*.m3u"), "export-m3u" },
696 { _T("PLS file"), _T("*.pls"), "export-pls" }};
697 wUnicode = new TCHAR[100];
698 wcscpy( wUnicode, _T("") );
701 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
703 wcscpy( &wUnicode[len], formats[i].psz_desc );
704 len = len + wcslen( formats[i].psz_desc );
705 wUnicode[len] = '\0';
707 wcscpy( &wUnicode[len], formats[i].psz_filter );
708 len = len + wcslen( formats[i].psz_filter );
709 wUnicode[len] = '\0';
712 wUnicode[len] = '\0';
714 memset( &(ofn), 0, sizeof(ofn));
715 ofn.lStructSize = sizeof(ofn);
716 ofn.hwndOwner = NULL;
717 ofn.lpstrFile = szFile;
718 ofn.nMaxFile = NMAXFILE;
719 ofn.lpstrFilter = wUnicode;
720 ofn.lpstrTitle = _T("Save playlist");
721 ofn.Flags = OFN_HIDEREADONLY;
724 if( GetSaveFileName((LPOPENFILENAME) &ofn) )
726 playlist_t * p_playlist = (playlist_t *)
727 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
729 if( p_playlist && ofn.lpstrFile )
731 playlist_Export( p_playlist, _TOMB(ofn.lpstrFile),
732 formats[ofn.nFilterIndex ?
733 ofn.nFilterIndex - 1 : 0].psz_module );
736 if( p_playlist ) vlc_object_release( p_playlist );
740 void Playlist::OnAddFile()
742 // Same code as in Interface
744 TCHAR DateiName[80+1] = _T("\0");
745 static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
747 playlist_t *p_playlist = (playlist_t *)
748 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
749 if( p_playlist == NULL ) return;
751 memset( &ofn, 0, sizeof(OPENFILENAME) );
752 ofn.lStructSize = sizeof(OPENFILENAME);
753 ofn.hwndOwner = NULL;
754 ofn.hInstance = hInst;
755 ofn.lpstrFilter = szFilter;
756 ofn.lpstrCustomFilter = NULL;
757 ofn.nMaxCustFilter = 0;
758 ofn.nFilterIndex = 1;
759 ofn.lpstrFile = (LPTSTR)DateiName;
761 ofn.lpstrFileTitle = NULL;
762 ofn.nMaxFileTitle = 40;
763 ofn.lpstrInitialDir = NULL;
764 ofn.lpstrTitle = _T("Quick Open File");
767 ofn.nFileExtension = 0;
768 ofn.lpstrDefExt = NULL;
771 ofn.lpTemplateName = NULL;
773 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
775 if( GetOpenFileName( (LPOPENFILENAME)&ofn ) )
777 char *psz_filename = _TOMB(ofn.lpstrFile);
778 playlist_Add( p_playlist, psz_filename, psz_filename,
779 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
782 vlc_object_release( p_playlist );
785 void Playlist::OnAddMRL()
789 /**********************************************************************
790 * Selection functions
791 **********************************************************************/
792 void Playlist::OnDeleteSelection()
794 /* Delete from the end to the beginning, to avoid a shift of indices */
795 for( long item = ((int) ListView_GetItemCount( hListView ) - 1);
798 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
805 void Playlist::OnInvertSelection()
809 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
811 iState = ListView_GetItemState( hListView, item, LVIS_STATEIMAGEMASK );
812 ListView_SetItemState( hListView, item, iState ^ LVIS_SELECTED,
813 LVIS_STATEIMAGEMASK );
817 void Playlist::OnEnableSelection()
819 playlist_t *p_playlist = (playlist_t *)
820 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
821 if( p_playlist == NULL ) return;
823 for( long item = ListView_GetItemCount( hListView ) - 1;
826 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
828 playlist_item_t *p_item =
829 playlist_ItemGetByPos( p_playlist, item );
830 playlist_Enable( p_playlist, p_item );
834 vlc_object_release( p_playlist);
837 void Playlist::OnDisableSelection()
839 playlist_t *p_playlist = (playlist_t *)
840 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
841 if( p_playlist == NULL ) return;
843 for( long item = ListView_GetItemCount( hListView ) - 1;
846 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
849 playlist_item_t *p_item =
850 playlist_ItemGetByPos( p_playlist, item );
851 playlist_Disable( p_playlist, p_item );
855 vlc_object_release( p_playlist);
858 void Playlist::OnSelectAll()
860 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
862 ListView_SetItemState( hListView, item, LVIS_FOCUSED | LVIS_SELECTED,
863 LVIS_STATEIMAGEMASK );
867 void Playlist::OnActivateItem( int i_item )
869 playlist_t *p_playlist = (playlist_t *)
870 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
871 if( p_playlist == NULL ) return;
873 playlist_Goto( p_playlist, i_item );
875 vlc_object_release( p_playlist );
878 void Playlist::ShowInfos( HWND hwnd, int i_item )
880 playlist_t *p_playlist = (playlist_t *)
881 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
882 if( p_playlist == NULL ) return;
884 vlc_mutex_lock( &p_playlist->object_lock);
885 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
886 vlc_mutex_unlock( &p_playlist->object_lock );
890 ItemInfoDialog *iteminfo_dialog =
891 new ItemInfoDialog( p_intf, hInst, p_item );
892 DialogBoxParam( hInst, (LPCTSTR)IDD_DUMMY, hwnd,
893 (DLGPROC)iteminfo_dialog->BaseWndProc,
894 (long)iteminfo_dialog );
895 UpdateItem( i_item );
896 delete iteminfo_dialog;
899 vlc_object_release( p_playlist );
902 /********************************************************************
904 ********************************************************************/
905 void Playlist::OnUp()
907 playlist_t *p_playlist = (playlist_t *)
908 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
909 if( p_playlist == NULL ) return;
911 /* We use the first selected item, so find it */
913 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
915 if( i_item > 0 && i_item < p_playlist->i_size )
917 playlist_Move( p_playlist , i_item, i_item - 1);
920 ListView_SetItemState( hListView, i_item - 1, LVIS_FOCUSED,
921 LVIS_STATEIMAGEMASK );
925 ListView_SetItemState( hListView, 0, LVIS_FOCUSED,
926 LVIS_STATEIMAGEMASK );
929 vlc_object_release( p_playlist );
934 void Playlist::OnDown()
936 playlist_t *p_playlist = (playlist_t *)
937 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
938 if( p_playlist == NULL ) return;
940 /* We use the first selected item, so find it */
942 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
944 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
946 playlist_Move( p_playlist , i_item, i_item + 2 );
947 ListView_SetItemState( hListView, i_item + 1, LVIS_FOCUSED,
948 LVIS_STATEIMAGEMASK );
950 vlc_object_release( p_playlist );
955 /**********************************************************************
956 * Playlist mode functions
957 **********************************************************************/
958 void Playlist::OnRandom()
961 int bState = SendMessage( hwndTB, TB_GETSTATE, Random_Event, 0 );
962 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
964 playlist_t *p_playlist = (playlist_t *)
965 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
966 if( p_playlist == NULL ) return;
968 var_Set( p_playlist , "random", val );
969 vlc_object_release( p_playlist );
972 void Playlist::OnLoop ()
975 int bState = SendMessage( hwndTB, TB_GETSTATE, Loop_Event, 0 );
976 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
978 playlist_t *p_playlist = (playlist_t *)
979 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
980 if( p_playlist == NULL ) return;
982 var_Set( p_playlist , "loop", val );
983 vlc_object_release( p_playlist );
986 void Playlist::OnRepeat ()
989 int bState = SendMessage( hwndTB, TB_GETSTATE, Repeat_Event, 0 );
990 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
992 playlist_t *p_playlist = (playlist_t *)
993 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
994 if( p_playlist == NULL ) return;
996 var_Set( p_playlist , "repeat", val );
997 vlc_object_release( p_playlist );
1000 /********************************************************************
1002 ********************************************************************/
1003 void Playlist::OnSort( UINT event )
1005 playlist_t *p_playlist = (playlist_t *)
1006 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1007 if( p_playlist == NULL ) return;
1012 playlist_SortTitle( p_playlist , ORDER_NORMAL );
1014 case ID_SORT_RTITLE:
1015 playlist_SortTitle( p_playlist , ORDER_REVERSE );
1017 case ID_SORT_AUTHOR:
1018 playlist_SortAuthor(p_playlist , ORDER_NORMAL );
1020 case ID_SORT_RAUTHOR:
1021 playlist_SortAuthor( p_playlist , ORDER_REVERSE );
1023 case ID_SORT_SHUFFLE:
1024 playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
1028 vlc_object_release( p_playlist );
1030 b_need_update = VLC_TRUE;
1035 void Playlist::OnColSelect( int iSubItem )
1037 playlist_t *p_playlist = (playlist_t *)
1038 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1039 if( p_playlist == NULL ) return;
1044 if( i_title_sorted != 1 )
1046 playlist_SortTitle( p_playlist, ORDER_NORMAL );
1051 playlist_SortTitle( p_playlist, ORDER_REVERSE );
1052 i_title_sorted = -1;
1056 if( i_author_sorted != 1 )
1058 playlist_SortAuthor( p_playlist, ORDER_NORMAL );
1059 i_author_sorted = 1;
1063 playlist_SortAuthor( p_playlist, ORDER_REVERSE );
1064 i_author_sorted = -1;
1071 vlc_object_release( p_playlist );
1073 b_need_update = VLC_TRUE;
1078 /*****************************************************************************
1079 * Popup management functions
1080 *****************************************************************************/
1081 void Playlist::OnPopupPlay()
1084 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1086 playlist_t *p_playlist = (playlist_t *)
1087 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1088 if( p_playlist == NULL ) return;
1090 if( i_popup_item != -1 )
1092 playlist_Goto( p_playlist, i_popup_item );
1095 vlc_object_release( p_playlist );
1098 void Playlist::OnPopupDel()
1101 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1103 DeleteItem( i_popup_item );
1106 void Playlist::OnPopupEna()
1109 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1111 playlist_t *p_playlist = (playlist_t *)
1112 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1113 if( p_playlist == NULL ) return;
1115 playlist_item_t *p_item =
1116 playlist_ItemGetByPos( p_playlist, i_popup_item );
1118 if( p_playlist->pp_items[i_popup_item]->b_enabled )
1119 //playlist_IsEnabled( p_playlist, i_popup_item ) )
1121 playlist_Disable( p_playlist, p_item );
1125 playlist_Enable( p_playlist, p_item );
1128 vlc_object_release( p_playlist);
1129 UpdateItem( i_popup_item );
1132 void Playlist::OnPopupInfo( HWND hwnd )
1135 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1137 ShowInfos( hwnd, i_popup_item );