1 /*****************************************************************************
2 * dialogs.cpp : WinCE plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
34 #include <vlc_interface.h>
35 #include <vlc_playlist.h>
43 /* Dialogs Provider */
44 class DialogsProvider: public CBaseWindow
48 DialogsProvider( intf_thread_t *, CBaseWindow *, HINSTANCE = 0 );
49 virtual ~DialogsProvider();
52 virtual LRESULT WndProc( HWND, UINT, WPARAM, LPARAM );
58 void OnPlaylist( void );
59 void OnMessages( void );
60 void OnFileInfo( void );
61 void OnPreferences( void );
62 void OnPopupMenu( void );
64 void OnOpen( int, int );
65 void OnOpenFileSimple( int );
66 void OnOpenDirectory( int );
67 void OnOpenFileGeneric( intf_dialog_args_t * );
69 /* GetOpenFileName replacement */
70 BOOL (WINAPI *GetOpenFile)(void *);
71 HMODULE h_gsgetfile_dll;
74 /* Secondary windows */
75 OpenDialog *p_open_dialog;
76 Playlist *p_playlist_dialog;
77 Messages *p_messages_dialog;
78 PrefsDialog *p_prefs_dialog;
79 FileInfo *p_fileinfo_dialog;
82 CBaseWindow *CreateDialogsProvider( intf_thread_t *p_intf,
83 CBaseWindow *p_parent, HINSTANCE h_inst )
85 return new DialogsProvider( p_intf, p_parent, h_inst );
88 /*****************************************************************************
90 *****************************************************************************/
91 DialogsProvider::DialogsProvider( intf_thread_t *p_intf,
92 CBaseWindow *p_parent, HINSTANCE h_inst )
93 : CBaseWindow( p_intf, p_parent, h_inst )
97 p_playlist_dialog = NULL;
98 p_messages_dialog = NULL;
99 p_fileinfo_dialog = NULL;
100 p_prefs_dialog = NULL;
102 /* Create dummy window */
103 hWnd = CreateWindow( _T("VLC WinCE"), _T("DialogsProvider"), 0,
104 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
105 p_parent->GetHandle(), NULL, h_inst, (void *)this );
108 h_gsgetfile_dll = LoadLibrary( _T("gsgetfile") );
109 if( h_gsgetfile_dll )
111 GetOpenFile = (BOOL (WINAPI *)(void *))
112 GetProcAddress( h_gsgetfile_dll, _T("gsGetOpenFileName") );
116 GetOpenFile = (BOOL (WINAPI *)(void *))::GetOpenFileName;
119 DialogsProvider::~DialogsProvider()
122 delete p_open_dialog;
123 delete p_playlist_dialog;
124 delete p_messages_dialog;
125 delete p_fileinfo_dialog;
126 delete p_prefs_dialog;
128 if( h_gsgetfile_dll ) FreeLibrary( h_gsgetfile_dll );
131 LRESULT DialogsProvider::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
135 case WM_APP + INTF_DIALOG_FILE: OnOpen( FILE_ACCESS, wp ); return TRUE;
136 case WM_APP + INTF_DIALOG_NET: OnOpen( NET_ACCESS, wp ); return TRUE;
137 case WM_APP + INTF_DIALOG_FILE_SIMPLE: OnOpenFileSimple( wp ); return TRUE;
138 case WM_APP + INTF_DIALOG_DIRECTORY: OnOpenDirectory( wp ); return TRUE;
139 case WM_APP + INTF_DIALOG_FILE_GENERIC:
140 OnOpenFileGeneric( (intf_dialog_args_t*)lp ); return TRUE;
141 case WM_APP + INTF_DIALOG_PLAYLIST: OnPlaylist(); return TRUE;
142 case WM_APP + INTF_DIALOG_MESSAGES: OnMessages(); return TRUE;
143 case WM_APP + INTF_DIALOG_FILEINFO: OnFileInfo(); return TRUE;
144 case WM_APP + INTF_DIALOG_PREFS: OnPreferences(); return TRUE;
145 case WM_APP + INTF_DIALOG_POPUPMENU: OnPopupMenu(); return TRUE;
148 return DefWindowProc( hwnd, msg, wp, lp );
151 void DialogsProvider::OnIdle( void )
153 /* Update the playlist */
154 if( p_playlist_dialog ) p_playlist_dialog->UpdatePlaylist();
156 /* Update the fileinfo windows */
157 if( p_fileinfo_dialog ) p_fileinfo_dialog->UpdateFileInfo();
160 void DialogsProvider::OnPopupMenu( void )
163 PopupMenu( p_intf, hWnd, point );
166 void DialogsProvider::OnPlaylist( void )
169 Playlist *playlist = new Playlist( p_intf, this, hInst );
170 CreateDialogBox( hWnd, playlist );
173 /* Show/hide the playlist window */
174 if( !p_playlist_dialog )
175 p_playlist_dialog = new Playlist( p_intf, this, hInst );
177 if( p_playlist_dialog )
179 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
184 void DialogsProvider::OnMessages( void )
186 /* Show/hide the log window */
187 if( !p_messages_dialog )
188 p_messages_dialog = new Messages( p_intf, this, hInst );
190 if( p_messages_dialog )
192 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
196 void DialogsProvider::OnFileInfo( void )
199 FileInfo *fileinfo = new FileInfo( p_intf, this, hInst );
200 CreateDialogBox( hWnd, fileinfo );
203 /* Show/hide the file info window */
204 if( !p_fileinfo_dialog )
205 p_fileinfo_dialog = new FileInfo( p_intf, this, hInst );
207 if( p_fileinfo_dialog )
209 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
214 void DialogsProvider::OnPreferences( void )
217 PrefsDialog *preferences = new PrefsDialog( p_intf, this, hInst );
218 CreateDialogBox( hWnd, preferences );
221 /* Show/hide the open dialog */
222 if( !p_prefs_dialog )
223 p_prefs_dialog = new PrefsDialog( p_intf, this, hInst );
227 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
232 void DialogsProvider::OnOpen( int i_access, int i_arg )
234 /* Show/hide the open dialog */
236 p_open_dialog = new OpenDialog( p_intf, this, hInst, i_access, i_arg );
240 p_open_dialog->Show( !p_open_dialog->IsShown() );
244 void DialogsProvider::OnOpenFileGeneric( intf_dialog_args_t *p_arg )
248 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
252 /* Convert the filter string */
253 TCHAR *psz_filters = (TCHAR *)
254 malloc( (strlen(p_arg->psz_extensions) + 2) * sizeof(TCHAR) );
255 _tcscpy( psz_filters, _FROMMB(p_arg->psz_extensions) );
258 for( i = 0; psz_filters[i]; i++ )
260 if( psz_filters[i] == '|' ) psz_filters[i] = 0;
262 psz_filters[++i] = 0;
265 TCHAR szFile[MAX_PATH] = _T("\0");
267 memset( &ofn, 0, sizeof(OPENFILENAME) );
268 ofn.lStructSize = sizeof(OPENFILENAME);
269 ofn.hwndOwner = hWnd;
270 ofn.hInstance = hInst;
271 ofn.lpstrFilter = psz_filters;
272 ofn.lpstrCustomFilter = NULL;
273 ofn.nMaxCustFilter = 0;
274 ofn.nFilterIndex = 1;
275 ofn.lpstrFile = (LPTSTR)szFile;
276 ofn.nMaxFile = MAX_PATH;
277 ofn.lpstrFileTitle = NULL;
278 ofn.nMaxFileTitle = 40;
279 ofn.lpstrInitialDir = NULL;
280 ofn.lpstrTitle = _FROMMB(p_arg->psz_title);
283 ofn.nFileExtension = 0;
284 ofn.lpstrDefExt = NULL;
287 ofn.lpTemplateName = NULL;
289 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
291 if( p_arg->b_save && GetSaveFileName( &ofn ) )
293 p_arg->i_results = 1;
294 p_arg->psz_results = (char **)malloc( p_arg->i_results *
296 p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
299 if( !p_arg->b_save && GetOpenFile( &ofn ) )
301 p_arg->i_results = 1;
302 p_arg->psz_results = (char **)malloc( p_arg->i_results *
304 p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
308 if( p_arg->pf_callback )
310 p_arg->pf_callback( p_arg );
313 if( p_arg->psz_results )
315 for( int i = 0; i < p_arg->i_results; i++ )
317 free( p_arg->psz_results[i] );
319 free( p_arg->psz_results );
321 free( p_arg->psz_title );
322 free( p_arg->psz_extensions );
327 void DialogsProvider::OnOpenFileSimple( int i_arg )
330 TCHAR szFile[MAX_PATH] = _T("\0");
331 static TCHAR szFilter[] = _T("wav (*.wav)\0*.wav\0mp3 (*.mp3 *.mpga)\0*.mp3;*.mpga\0All (*.*)\0*.*\0");
333 playlist_t *p_playlist = pl_Hold( p_intf );
334 if( p_playlist == NULL ) return;
336 memset( &ofn, 0, sizeof(OPENFILENAME) );
337 ofn.lStructSize = sizeof(OPENFILENAME);
338 ofn.hwndOwner = hWnd;
339 ofn.hInstance = hInst;
340 ofn.lpstrFilter = szFilter;
341 ofn.lpstrCustomFilter = NULL;
342 ofn.nMaxCustFilter = 0;
343 ofn.nFilterIndex = 1;
344 ofn.lpstrFile = (LPTSTR)szFile;
345 ofn.nMaxFile = MAX_PATH;
346 ofn.lpstrFileTitle = NULL;
347 ofn.nMaxFileTitle = 40;
348 ofn.lpstrInitialDir = NULL;
349 ofn.lpstrTitle = _T("Quick Open File");
352 ofn.nFileExtension = 0;
353 ofn.lpstrDefExt = NULL;
356 ofn.lpTemplateName = NULL;
358 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
360 if( GetOpenFile( &ofn ) )
362 char *psz_filename = _TOMB(ofn.lpstrFile);
363 playlist_Add( p_playlist, psz_filename, psz_filename,
364 PLAYLIST_APPEND | (i_arg?PLAYLIST_GO:0), PLAYLIST_END,
368 pl_Release( p_intf );
371 void DialogsProvider::OnOpenDirectory( int i_arg )
373 TCHAR psz_result[MAX_PATH];
374 LPMALLOC p_malloc = 0;
377 playlist_t *p_playlist = 0;
380 # define SHGetMalloc MySHGetMalloc
381 # define SHBrowseForFolder MySHBrowseForFolder
382 # define SHGetPathFromIDList MySHGetPathFromIDList
384 HMODULE ceshell_dll = LoadLibrary( _T("ceshell") );
385 if( !ceshell_dll ) return;
387 HRESULT (WINAPI *SHGetMalloc)(LPMALLOC *) =
388 (HRESULT (WINAPI *)(LPMALLOC *))
389 GetProcAddress( ceshell_dll, _T("SHGetMalloc") );
390 LPITEMIDLIST (WINAPI *SHBrowseForFolder)(LPBROWSEINFO) =
391 (LPITEMIDLIST (WINAPI *)(LPBROWSEINFO))
392 GetProcAddress( ceshell_dll, _T("SHBrowseForFolder") );
393 BOOL (WINAPI *SHGetPathFromIDList)(LPCITEMIDLIST, LPTSTR) =
394 (BOOL (WINAPI *)(LPCITEMIDLIST, LPTSTR))
395 GetProcAddress( ceshell_dll, _T("SHGetPathFromIDList") );
397 if( !SHGetMalloc || !SHBrowseForFolder || !SHGetPathFromIDList )
399 msg_Err( p_intf, "couldn't load SHBrowseForFolder API" );
400 FreeLibrary( ceshell_dll );
405 if( !SUCCEEDED( SHGetMalloc(&p_malloc) ) ) goto error;
407 p_playlist = pl_Hold( p_intf );
408 if( !p_playlist ) goto error;
410 memset( &bi, 0, sizeof(BROWSEINFO) );
412 bi.pszDisplayName = psz_result;
413 bi.ulFlags = BIF_EDITBOX;
415 bi.ulFlags |= BIF_USENEWUI;
418 if( (pidl = SHBrowseForFolder( &bi ) ) )
420 if( SHGetPathFromIDList( pidl, psz_result ) )
422 char *psz_filename = _TOMB(psz_result);
423 playlist_Add( p_playlist, psz_filename, psz_filename,
424 PLAYLIST_APPEND | (i_arg ? PLAYLIST_GO : 0),
425 PLAYLIST_END, TRUE, FALSE );
427 p_malloc->Free( pidl );
432 if( p_malloc) p_malloc->Release();
433 if( p_playlist ) pl_Release( p_intf );
436 FreeLibrary( ceshell_dll );