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>
42 /* Dialogs Provider */
43 class DialogsProvider: public CBaseWindow
47 DialogsProvider( intf_thread_t *, CBaseWindow *, HINSTANCE = 0 );
48 virtual ~DialogsProvider();
51 virtual LRESULT WndProc( HWND, UINT, WPARAM, LPARAM );
57 void OnPlaylist( void );
58 void OnMessages( void );
59 void OnFileInfo( void );
60 void OnPreferences( void );
61 void OnPopupMenu( void );
63 void OnOpen( int, int );
64 void OnOpenFileSimple( int );
65 void OnOpenDirectory( int );
66 void OnOpenFileGeneric( intf_dialog_args_t * );
68 /* GetOpenFileName replacement */
69 BOOL (WINAPI *GetOpenFile)(void *);
70 HMODULE h_gsgetfile_dll;
73 /* Secondary windows */
74 OpenDialog *p_open_dialog;
75 Playlist *p_playlist_dialog;
76 Messages *p_messages_dialog;
77 PrefsDialog *p_prefs_dialog;
78 FileInfo *p_fileinfo_dialog;
81 CBaseWindow *CreateDialogsProvider( intf_thread_t *p_intf,
82 CBaseWindow *p_parent, HINSTANCE h_inst )
84 return new DialogsProvider( p_intf, p_parent, h_inst );
87 /*****************************************************************************
89 *****************************************************************************/
90 DialogsProvider::DialogsProvider( intf_thread_t *p_intf,
91 CBaseWindow *p_parent, HINSTANCE h_inst )
92 : CBaseWindow( p_intf, p_parent, h_inst )
96 p_playlist_dialog = NULL;
97 p_messages_dialog = NULL;
98 p_fileinfo_dialog = NULL;
99 p_prefs_dialog = NULL;
101 /* Create dummy window */
102 hWnd = CreateWindow( _T("VLC WinCE"), _T("DialogsProvider"), 0,
103 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
104 p_parent->GetHandle(), NULL, h_inst, (void *)this );
107 h_gsgetfile_dll = LoadLibrary( _T("gsgetfile") );
108 if( h_gsgetfile_dll )
110 GetOpenFile = (BOOL (WINAPI *)(void *))
111 GetProcAddress( h_gsgetfile_dll, _T("gsGetOpenFileName") );
115 GetOpenFile = (BOOL (WINAPI *)(void *))::GetOpenFileName;
118 DialogsProvider::~DialogsProvider()
121 delete p_open_dialog;
122 delete p_playlist_dialog;
123 delete p_messages_dialog;
124 delete p_fileinfo_dialog;
125 delete p_prefs_dialog;
127 if( h_gsgetfile_dll ) FreeLibrary( h_gsgetfile_dll );
130 LRESULT DialogsProvider::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
134 case WM_APP + INTF_DIALOG_FILE: OnOpen( FILE_ACCESS, wp ); return TRUE;
135 case WM_APP + INTF_DIALOG_NET: OnOpen( NET_ACCESS, wp ); return TRUE;
136 case WM_APP + INTF_DIALOG_FILE_SIMPLE: OnOpenFileSimple( wp ); return TRUE;
137 case WM_APP + INTF_DIALOG_DIRECTORY: OnOpenDirectory( wp ); return TRUE;
138 case WM_APP + INTF_DIALOG_FILE_GENERIC:
139 OnOpenFileGeneric( (intf_dialog_args_t*)lp ); return TRUE;
140 case WM_APP + INTF_DIALOG_PLAYLIST: OnPlaylist(); return TRUE;
141 case WM_APP + INTF_DIALOG_MESSAGES: OnMessages(); return TRUE;
142 case WM_APP + INTF_DIALOG_FILEINFO: OnFileInfo(); return TRUE;
143 case WM_APP + INTF_DIALOG_PREFS: OnPreferences(); return TRUE;
144 case WM_APP + INTF_DIALOG_POPUPMENU: OnPopupMenu(); return TRUE;
147 return DefWindowProc( hwnd, msg, wp, lp );
150 void DialogsProvider::OnIdle( void )
152 /* Update the log window */
153 if( p_messages_dialog ) p_messages_dialog->UpdateLog();
155 /* Update the playlist */
156 if( p_playlist_dialog ) p_playlist_dialog->UpdatePlaylist();
158 /* Update the fileinfo windows */
159 if( p_fileinfo_dialog ) p_fileinfo_dialog->UpdateFileInfo();
162 void DialogsProvider::OnPopupMenu( void )
165 PopupMenu( p_intf, hWnd, point );
168 void DialogsProvider::OnPlaylist( void )
171 Playlist *playlist = new Playlist( p_intf, this, hInst );
172 CreateDialogBox( hWnd, playlist );
175 /* Show/hide the playlist window */
176 if( !p_playlist_dialog )
177 p_playlist_dialog = new Playlist( p_intf, this, hInst );
179 if( p_playlist_dialog )
181 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
186 void DialogsProvider::OnMessages( void )
188 /* Show/hide the log window */
189 if( !p_messages_dialog )
190 p_messages_dialog = new Messages( p_intf, this, hInst );
192 if( p_messages_dialog )
194 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
198 void DialogsProvider::OnFileInfo( void )
201 FileInfo *fileinfo = new FileInfo( p_intf, this, hInst );
202 CreateDialogBox( hWnd, fileinfo );
205 /* Show/hide the file info window */
206 if( !p_fileinfo_dialog )
207 p_fileinfo_dialog = new FileInfo( p_intf, this, hInst );
209 if( p_fileinfo_dialog )
211 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
216 void DialogsProvider::OnPreferences( void )
219 PrefsDialog *preferences = new PrefsDialog( p_intf, this, hInst );
220 CreateDialogBox( hWnd, preferences );
223 /* Show/hide the open dialog */
224 if( !p_prefs_dialog )
225 p_prefs_dialog = new PrefsDialog( p_intf, this, hInst );
229 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
234 void DialogsProvider::OnOpen( int i_access, int i_arg )
236 /* Show/hide the open dialog */
238 p_open_dialog = new OpenDialog( p_intf, this, hInst, i_access, i_arg );
242 p_open_dialog->Show( !p_open_dialog->IsShown() );
246 void DialogsProvider::OnOpenFileGeneric( intf_dialog_args_t *p_arg )
250 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
254 /* Convert the filter string */
255 TCHAR *psz_filters = (TCHAR *)
256 malloc( (strlen(p_arg->psz_extensions) + 2) * sizeof(TCHAR) );
257 _tcscpy( psz_filters, _FROMMB(p_arg->psz_extensions) );
260 for( i = 0; psz_filters[i]; i++ )
262 if( psz_filters[i] == '|' ) psz_filters[i] = 0;
264 psz_filters[++i] = 0;
267 TCHAR szFile[MAX_PATH] = _T("\0");
269 memset( &ofn, 0, sizeof(OPENFILENAME) );
270 ofn.lStructSize = sizeof(OPENFILENAME);
271 ofn.hwndOwner = hWnd;
272 ofn.hInstance = hInst;
273 ofn.lpstrFilter = psz_filters;
274 ofn.lpstrCustomFilter = NULL;
275 ofn.nMaxCustFilter = 0;
276 ofn.nFilterIndex = 1;
277 ofn.lpstrFile = (LPTSTR)szFile;
278 ofn.nMaxFile = MAX_PATH;
279 ofn.lpstrFileTitle = NULL;
280 ofn.nMaxFileTitle = 40;
281 ofn.lpstrInitialDir = NULL;
282 ofn.lpstrTitle = _FROMMB(p_arg->psz_title);
285 ofn.nFileExtension = 0;
286 ofn.lpstrDefExt = NULL;
289 ofn.lpTemplateName = NULL;
291 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
293 if( p_arg->b_save && GetSaveFileName( &ofn ) )
295 p_arg->i_results = 1;
296 p_arg->psz_results = (char **)malloc( p_arg->i_results *
298 p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
301 if( !p_arg->b_save && GetOpenFile( &ofn ) )
303 p_arg->i_results = 1;
304 p_arg->psz_results = (char **)malloc( p_arg->i_results *
306 p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
310 if( p_arg->pf_callback )
312 p_arg->pf_callback( p_arg );
315 if( p_arg->psz_results )
317 for( int i = 0; i < p_arg->i_results; i++ )
319 free( p_arg->psz_results[i] );
321 free( p_arg->psz_results );
323 free( p_arg->psz_title );
324 free( p_arg->psz_extensions );
329 void DialogsProvider::OnOpenFileSimple( int i_arg )
332 TCHAR szFile[MAX_PATH] = _T("\0");
333 static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
335 playlist_t *p_playlist = (playlist_t *)
336 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
337 if( p_playlist == NULL ) return;
339 memset( &ofn, 0, sizeof(OPENFILENAME) );
340 ofn.lStructSize = sizeof(OPENFILENAME);
341 ofn.hwndOwner = hWnd;
342 ofn.hInstance = hInst;
343 ofn.lpstrFilter = szFilter;
344 ofn.lpstrCustomFilter = NULL;
345 ofn.nMaxCustFilter = 0;
346 ofn.nFilterIndex = 1;
347 ofn.lpstrFile = (LPTSTR)szFile;
348 ofn.nMaxFile = MAX_PATH;
349 ofn.lpstrFileTitle = NULL;
350 ofn.nMaxFileTitle = 40;
351 ofn.lpstrInitialDir = NULL;
352 ofn.lpstrTitle = _T("Quick Open File");
355 ofn.nFileExtension = 0;
356 ofn.lpstrDefExt = NULL;
359 ofn.lpTemplateName = NULL;
361 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
363 if( GetOpenFile( &ofn ) )
365 char *psz_filename = _TOMB(ofn.lpstrFile);
366 playlist_Add( p_playlist, psz_filename, psz_filename,
367 PLAYLIST_APPEND | (i_arg?PLAYLIST_GO:0), PLAYLIST_END );
370 vlc_object_release( p_playlist );
373 void DialogsProvider::OnOpenDirectory( int i_arg )
375 TCHAR psz_result[MAX_PATH];
376 LPMALLOC p_malloc = 0;
379 playlist_t *p_playlist = 0;
382 # define SHGetMalloc MySHGetMalloc
383 # define SHBrowseForFolder MySHBrowseForFolder
384 # define SHGetPathFromIDList MySHGetPathFromIDList
386 HMODULE ceshell_dll = LoadLibrary( _T("ceshell") );
387 if( !ceshell_dll ) return;
389 HRESULT (WINAPI *SHGetMalloc)(LPMALLOC *) =
390 (HRESULT (WINAPI *)(LPMALLOC *))
391 GetProcAddress( ceshell_dll, _T("SHGetMalloc") );
392 LPITEMIDLIST (WINAPI *SHBrowseForFolder)(LPBROWSEINFO) =
393 (LPITEMIDLIST (WINAPI *)(LPBROWSEINFO))
394 GetProcAddress( ceshell_dll, _T("SHBrowseForFolder") );
395 BOOL (WINAPI *SHGetPathFromIDList)(LPCITEMIDLIST, LPTSTR) =
396 (BOOL (WINAPI *)(LPCITEMIDLIST, LPTSTR))
397 GetProcAddress( ceshell_dll, _T("SHGetPathFromIDList") );
399 if( !SHGetMalloc || !SHBrowseForFolder || !SHGetPathFromIDList )
401 msg_Err( p_intf, "couldn't load SHBrowseForFolder API" );
402 FreeLibrary( ceshell_dll );
407 if( !SUCCEEDED( SHGetMalloc(&p_malloc) ) ) goto error;
409 p_playlist = (playlist_t *)
410 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
411 if( !p_playlist ) goto error;
413 memset( &bi, 0, sizeof(BROWSEINFO) );
415 bi.pszDisplayName = psz_result;
416 bi.ulFlags = BIF_EDITBOX;
418 bi.ulFlags |= BIF_USENEWUI;
421 if( (pidl = SHBrowseForFolder( &bi ) ) )
423 if( SHGetPathFromIDList( pidl, psz_result ) )
425 char *psz_filename = _TOMB(psz_result);
426 playlist_Add( p_playlist, psz_filename, psz_filename,
427 PLAYLIST_APPEND | (i_arg ? PLAYLIST_GO : 0),
430 p_malloc->Free( pidl );
435 if( p_malloc) p_malloc->Release();
436 if( p_playlist ) vlc_object_release( p_playlist );
439 FreeLibrary( ceshell_dll );