📄 playlist.cpp
字号:
/***************************************************************************** * playlist.cpp : WinCE gui plugin for VLC ***************************************************************************** * Copyright (C) 2000-2004 VideoLAN * $Id: playlist.cpp 10485 2005-03-30 23:47:41Z gbazin $ * * Authors: Marodon Cedric <cedric_marodon@yahoo.fr> * Gildas Bazin <gbazin@videolan.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h> /* malloc(), free() */#include <string.h> /* strerror() */#include <stdio.h>#include <vlc/vlc.h>#include <vlc/intf.h>#include "wince.h"#include <commctrl.h>#include <commdlg.h>#ifndef TEXTMAXBUF#define TEXTMAXBUF 512 // at least 500#endif#define LONG2POINT(l, pt) ((pt).x = (SHORT)LOWORD(l), (pt).y = (SHORT)HIWORD(l))#define NUMIMAGES 11 // Number of buttons in the toolbar #define IMAGEWIDTH 16 // Width of the buttons in the toolbar #define IMAGEHEIGHT 16 // Height of the buttons in the toolbar #define BUTTONWIDTH 0 // Width of the button images in the toolbar#define BUTTONHEIGHT 0 // Height of the button images in the toolbar#define ID_TOOLBAR 2000 // Identifier of the main tool barenum { Infos_Event = 1000, Up_Event, Down_Event, Random_Event, Loop_Event, Repeat_Event, PopupPlay_Event, PopupDel_Event, PopupEna_Event, PopupInfo_Event };// Help strings#define HELP_OPENPL _T("Open playlist")#define HELP_SAVEPL _T("Save playlist")#define HELP_ADDFILE _T("Add File")#define HELP_ADDMRL _T("Add MRL")#define HELP_DELETE _T("Delete selection")#define HELP_INFOS _T("Item info")#define HELP_UP _T("Up")#define HELP_DOWN _T("Down")#define HELP_RANDOM _T("Random")#define HELP_LOOP _T("Repeat all")#define HELP_REPEAT _T("Repeat one")// The TBBUTTON structure contains information the toolbar buttons.static TBBUTTON tbButton2[] ={ {0, ID_MANAGE_OPENPL, TBSTATE_ENABLED, TBSTYLE_BUTTON}, {1, ID_MANAGE_SAVEPL, TBSTATE_ENABLED, TBSTYLE_BUTTON}, {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP}, {2, ID_MANAGE_ADDFILE, TBSTATE_ENABLED, TBSTYLE_BUTTON}, {3, ID_MANAGE_ADDMRL, TBSTATE_ENABLED, TBSTYLE_BUTTON}, {4, ID_SEL_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON}, {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP}, {5, Infos_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON}, {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP}, {6, Up_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON}, {7, Down_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON}, {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP}, {8, Random_Event, TBSTATE_ENABLED, TBSTYLE_CHECK}, {9, Loop_Event, TBSTATE_ENABLED, TBSTYLE_CHECK}, {10, Repeat_Event, TBSTATE_ENABLED, TBSTYLE_CHECK}};// Toolbar ToolTipsTCHAR * szToolTips2[] = { HELP_OPENPL, HELP_SAVEPL, HELP_ADDFILE, HELP_ADDMRL, HELP_DELETE, HELP_INFOS, HELP_UP, HELP_DOWN, HELP_RANDOM, HELP_LOOP, HELP_REPEAT};/***************************************************************************** * Event Table. *****************************************************************************//***************************************************************************** * Constructor. *****************************************************************************/Playlist::Playlist( intf_thread_t *p_intf, CBaseWindow *p_parent, HINSTANCE h_inst ) : CBaseWindow( p_intf, p_parent, h_inst ){ /* Initializations */ hListView = NULL; i_title_sorted = 1; i_author_sorted = 1; b_need_update = VLC_TRUE;}/***********************************************************************FUNCTION: CreateMenuBarPURPOSE: Creates a menu bar.***********************************************************************/static HWND CreateMenuBar( HWND hwnd, HINSTANCE hInst ){#ifdef UNDER_CE SHMENUBARINFO mbi; memset( &mbi, 0, sizeof(SHMENUBARINFO) ); mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hwnd; mbi.hInstRes = hInst; mbi.nToolBarId = IDR_MENUBAR2; if( !SHCreateMenuBar( &mbi ) ) { MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK); return 0; } TBBUTTONINFO tbbi; tbbi.cbSize = sizeof(tbbi); tbbi.dwMask = TBIF_LPARAM; SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_MANAGE, (LPARAM)&tbbi ); HMENU hmenu_file = (HMENU)tbbi.lParam; RemoveMenu( hmenu_file, 0, MF_BYPOSITION ); SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_SORT, (LPARAM)&tbbi ); HMENU hmenu_sort = (HMENU)tbbi.lParam; RemoveMenu( hmenu_sort, 0, MF_BYPOSITION ); SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_SEL, (LPARAM)&tbbi ); HMENU hmenu_sel = (HMENU)tbbi.lParam; RemoveMenu( hmenu_sel, 0, MF_BYPOSITION );#else HMENU hmenu_file = CreatePopupMenu(); HMENU hmenu_sort = CreatePopupMenu(); HMENU hmenu_sel = CreatePopupMenu();#endif AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDFILE, _T("&Add File...") ); AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDDIRECTORY, _T("Add Directory...") ); AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDMRL, _T("Add MRL...") ); AppendMenu( hmenu_file, MF_SEPARATOR, 0, 0 ); AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_OPENPL, _T("Open &Playlist") ); AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_SAVEPL, _T("Save Playlist") ); AppendMenu( hmenu_sort, MF_STRING, ID_SORT_TITLE, _T("Sort by &title") ); AppendMenu( hmenu_sort, MF_STRING, ID_SORT_RTITLE, _T("&Reverse sort by title") ); AppendMenu( hmenu_sort, MF_SEPARATOR, 0, 0 ); AppendMenu( hmenu_sort, MF_STRING, ID_SORT_AUTHOR, _T("Sort by &author") ); AppendMenu( hmenu_sort, MF_STRING, ID_SORT_RAUTHOR, _T("Reverse sort by &author") ); AppendMenu( hmenu_sort, MF_SEPARATOR, 0, 0 ); AppendMenu( hmenu_sort, MF_STRING, ID_SORT_SHUFFLE, _T("&Shuffle Playlist") ); AppendMenu( hmenu_sel, MF_STRING, ID_SEL_ENABLE, _T("&Enable") ); AppendMenu( hmenu_sel, MF_STRING, ID_SEL_DISABLE, _T("&Disable") ); AppendMenu( hmenu_sel, MF_SEPARATOR, 0, 0 ); AppendMenu( hmenu_sel, MF_STRING, ID_SEL_INVERT, _T("&Invert") ); AppendMenu( hmenu_sel, MF_STRING, ID_SEL_DELETE, _T("D&elete") ); AppendMenu( hmenu_sel, MF_SEPARATOR, 0, 0 ); AppendMenu( hmenu_sel, MF_STRING, ID_SEL_SELECTALL, _T("&Select All") );#ifdef UNDER_CE return mbi.hwndMB;#else HMENU hmenu = CreateMenu(); AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_file, _T("Manage") ); AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_sort, _T("Sort") ); AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_sel, _T("Selection") ); SetMenu( hwnd, hmenu ); return hwnd;#endif}/***********************************************************************FUNCTION: WndProcPURPOSE: Processes messages sent to the main window.***********************************************************************/LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp ){ SHINITDLGINFO shidi; SHMENUBARINFO mbi; INITCOMMONCONTROLSEX iccex; RECT rect, rectTB; DWORD dwStyle; int bState; playlist_t *p_playlist; switch( msg ) { case WM_INITDIALOG: shidi.dwMask = SHIDIM_FLAGS; shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN; shidi.hDlg = hwnd; SHInitDialog( &shidi ); hwndCB = CreateMenuBar( hwnd, hInst ); iccex.dwSize = sizeof (INITCOMMONCONTROLSEX); iccex.dwICC = ICC_BAR_CLASSES; // Registers TOOLBAR control classes from the common control dll InitCommonControlsEx (&iccex); // Create the toolbar control. dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS | WS_EX_OVERLAPPEDWINDOW | CCS_NOPARENTALIGN; hwndTB = CreateToolbarEx( hwnd, dwStyle, 0, NUMIMAGES, hInst, IDB_BITMAP3, tbButton2, sizeof (tbButton2) / sizeof (TBBUTTON), BUTTONWIDTH, BUTTONHEIGHT, IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON) ); if( !hwndTB ) break; // Add ToolTips to the toolbar. SendMessage( hwndTB, TB_SETTOOLTIPS, (WPARAM) NUMIMAGES, (LPARAM)szToolTips2 ); // Reposition the toolbar. GetClientRect( hwnd, &rect ); GetWindowRect( hwndTB, &rectTB ); MoveWindow( hwndTB, rect.left, rect.top - 2, rect.right - rect.left, MENU_HEIGHT /*rectTB.bottom - rectTB.top */, TRUE); // random, loop, repeat buttons states vlc_value_t val; p_playlist = (playlist_t *) vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( !p_playlist ) break; var_Get( p_playlist , "random", &val ); bState = val.b_bool ? TBSTATE_CHECKED : 0; SendMessage( hwndTB, TB_SETSTATE, Random_Event, MAKELONG(bState | TBSTATE_ENABLED, 0) ); var_Get( p_playlist , "loop", &val ); bState = val.b_bool ? TBSTATE_CHECKED : 0; SendMessage( hwndTB, TB_SETSTATE, Loop_Event, MAKELONG(bState | TBSTATE_ENABLED, 0) ); var_Get( p_playlist , "repeat", &val ); bState = val.b_bool ? TBSTATE_CHECKED : 0; SendMessage( hwndTB, TB_SETSTATE, Repeat_Event, MAKELONG(bState | TBSTATE_ENABLED, 0) ); vlc_object_release( p_playlist ); GetClientRect( hwnd, &rect ); hListView = CreateWindow( WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD | LVS_REPORT | LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL, rect.left, rect.top + 2*(MENU_HEIGHT+1), rect.right - rect.left, rect.bottom - ( rect.top + 2*MENU_HEIGHT) - MENU_HEIGHT, hwnd, NULL, hInst, NULL ); ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT ); LVCOLUMN lv; lv.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT; lv.fmt = LVCFMT_LEFT ; GetClientRect( hwnd, &rect ); lv.cx = 120; lv.pszText = _T("Name"); lv.cchTextMax = 9; ListView_InsertColumn( hListView, 0, &lv); lv.cx = 55; lv.pszText = _T("Author"); lv.cchTextMax = 9; ListView_InsertColumn( hListView, 1, &lv); lv.cx = rect.right - rect.left - 180; lv.pszText = _T("Duration"); lv.cchTextMax = 9; ListView_InsertColumn( hListView, 2, &lv); SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL ); break; case WM_TIMER: UpdatePlaylist(); break; case WM_CLOSE: EndDialog( hwnd, LOWORD( wp ) ); break; case WM_SETFOCUS: SHSipPreference( hwnd, SIP_DOWN ); SHFullScreen( hwnd, SHFS_HIDESIPBUTTON ); break; case WM_COMMAND: switch( LOWORD(wp) ) { case IDOK: EndDialog( hwnd, LOWORD( wp ) ); break; case ID_MANAGE_OPENPL: OnOpen(); b_need_update = VLC_TRUE; break; case ID_MANAGE_SAVEPL: OnSave(); break; case ID_MANAGE_ADDFILE: p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 ); b_need_update = VLC_TRUE; break; case ID_MANAGE_ADDDIRECTORY: p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY, 0, 0 ); b_need_update = VLC_TRUE; break; case ID_MANAGE_ADDMRL:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -