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 *****************************************************************************/
30 #include <vlc_interface.h>
38 /* Dialogs Provider */
39 class DialogsProvider: public CBaseWindow
43 DialogsProvider( intf_thread_t *, CBaseWindow *, HINSTANCE = 0 );
44 virtual ~DialogsProvider();
47 virtual LRESULT WndProc( HWND, UINT, WPARAM, LPARAM );
53 void OnPlaylist( void );
54 void OnMessages( void );
55 void OnFileInfo( void );
56 void OnPreferences( void );
57 void OnPopupMenu( void );
59 void OnOpen( int, int );
60 void OnOpenFileSimple( int );
61 void OnOpenDirectory( int );
62 void OnOpenFileGeneric( intf_dialog_args_t * );
64 /* GetOpenFileName replacement */
65 BOOL (WINAPI *GetOpenFile)(void *);
66 HMODULE h_gsgetfile_dll;
69 /* Secondary windows */
70 OpenDialog *p_open_dialog;
71 Playlist *p_playlist_dialog;
72 Messages *p_messages_dialog;
73 PrefsDialog *p_prefs_dialog;
74 FileInfo *p_fileinfo_dialog;
77 CBaseWindow *CreateDialogsProvider( intf_thread_t *p_intf,
78 CBaseWindow *p_parent, HINSTANCE h_inst )
80 return new DialogsProvider( p_intf, p_parent, h_inst );
83 /*****************************************************************************
85 *****************************************************************************/
86 DialogsProvider::DialogsProvider( intf_thread_t *p_intf,
87 CBaseWindow *p_parent, HINSTANCE h_inst )
88 : CBaseWindow( p_intf, p_parent, h_inst )
92 p_playlist_dialog = NULL;
93 p_messages_dialog = NULL;
94 p_fileinfo_dialog = NULL;
95 p_prefs_dialog = NULL;
97 /* Create dummy window */
98 hWnd = CreateWindow( _T("VLC WinCE"), _T("DialogsProvider"), 0,
99 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
100 p_parent->GetHandle(), NULL, h_inst, (void *)this );
103 h_gsgetfile_dll = LoadLibrary( _T("gsgetfile") );
104 if( h_gsgetfile_dll )
106 GetOpenFile = (BOOL (WINAPI *)(void *))
107 GetProcAddress( h_gsgetfile_dll, _T("gsGetOpenFileName") );
111 GetOpenFile = (BOOL (WINAPI *)(void *))::GetOpenFileName;
114 DialogsProvider::~DialogsProvider()
117 if( p_open_dialog ) delete p_open_dialog;
118 if( p_playlist_dialog ) delete p_playlist_dialog;
119 if( p_messages_dialog ) delete p_messages_dialog;
120 if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
121 if( p_prefs_dialog ) delete p_prefs_dialog;
123 if( h_gsgetfile_dll ) FreeLibrary( h_gsgetfile_dll );
126 LRESULT DialogsProvider::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
130 case WM_APP + INTF_DIALOG_FILE: OnOpen( FILE_ACCESS, wp ); return TRUE;
131 case WM_APP + INTF_DIALOG_NET: OnOpen( NET_ACCESS, wp ); return TRUE;
132 case WM_APP + INTF_DIALOG_FILE_SIMPLE: OnOpenFileSimple( wp ); return TRUE;
133 case WM_APP + INTF_DIALOG_DIRECTORY: OnOpenDirectory( wp ); return TRUE;
134 case WM_APP + INTF_DIALOG_FILE_GENERIC:
135 OnOpenFileGeneric( (intf_dialog_args_t*)lp ); return TRUE;
136 case WM_APP + INTF_DIALOG_PLAYLIST: OnPlaylist(); return TRUE;
137 case WM_APP + INTF_DIALOG_MESSAGES: OnMessages(); return TRUE;
138 case WM_APP + INTF_DIALOG_FILEINFO: OnFileInfo(); return TRUE;
139 case WM_APP + INTF_DIALOG_PREFS: OnPreferences(); return TRUE;
140 case WM_APP + INTF_DIALOG_POPUPMENU: OnPopupMenu(); return TRUE;
143 return DefWindowProc( hwnd, msg, wp, lp );
146 void DialogsProvider::OnIdle( void )
148 /* Update the log window */
149 if( p_messages_dialog ) p_messages_dialog->UpdateLog();
151 /* Update the playlist */
152 if( p_playlist_dialog ) p_playlist_dialog->UpdatePlaylist();
154 /* Update the fileinfo windows */
155 if( p_fileinfo_dialog ) p_fileinfo_dialog->UpdateFileInfo();
158 void DialogsProvider::OnPopupMenu( void )
161 PopupMenu( p_intf, hWnd, point );
164 void DialogsProvider::OnPlaylist( void )
167 Playlist *playlist = new Playlist( p_intf, this, hInst );
168 CreateDialogBox( hWnd, playlist );
171 /* Show/hide the playlist window */
172 if( !p_playlist_dialog )
173 p_playlist_dialog = new Playlist( p_intf, this, hInst );
175 if( p_playlist_dialog )
177 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
182 void DialogsProvider::OnMessages( void )
184 /* Show/hide the log window */
185 if( !p_messages_dialog )
186 p_messages_dialog = new Messages( p_intf, this, hInst );
188 if( p_messages_dialog )
190 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
194 void DialogsProvider::OnFileInfo( void )
197 FileInfo *fileinfo = new FileInfo( p_intf, this, hInst );
198 CreateDialogBox( hWnd, fileinfo );
201 /* Show/hide the file info window */
202 if( !p_fileinfo_dialog )
203 p_fileinfo_dialog = new FileInfo( p_intf, this, hInst );
205 if( p_fileinfo_dialog )
207 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
212 void DialogsProvider::OnPreferences( void )
215 PrefsDialog *preferences = new PrefsDialog( p_intf, this, hInst );
216 CreateDialogBox( hWnd, preferences );
219 /* Show/hide the open dialog */
220 if( !p_prefs_dialog )
221 p_prefs_dialog = new PrefsDialog( p_intf, this, hInst );
225 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
230 void DialogsProvider::OnOpen( int i_access, int i_arg )
232 /* Show/hide the open dialog */
234 p_open_dialog = new OpenDialog( p_intf, this, hInst, i_access, i_arg );
238 p_open_dialog->Show( !p_open_dialog->IsShown() );
242 void DialogsProvider::OnOpenFileGeneric( intf_dialog_args_t *p_arg )
246 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
250 /* Convert the filter string */
251 TCHAR *psz_filters = (TCHAR *)
252 malloc( (strlen(p_arg->psz_extensions) + 2) * sizeof(TCHAR) );
253 _tcscpy( psz_filters, _FROMMB(p_arg->psz_extensions) );
256 for( i = 0; psz_filters[i]; i++ )
258 if( psz_filters[i] == '|' ) psz_filters[i] = 0;
260 psz_filters[++i] = 0;
263 TCHAR szFile[MAX_PATH] = _T("\0");
265 memset( &ofn, 0, sizeof(OPENFILENAME) );
266 ofn.lStructSize = sizeof(OPENFILENAME);
267 ofn.hwndOwner = hWnd;
268 ofn.hInstance = hInst;
269 ofn.lpstrFilter = psz_filters;
270 ofn.lpstrCustomFilter = NULL;
271 ofn.nMaxCustFilter = 0;
272 ofn.nFilterIndex = 1;
273 ofn.lpstrFile = (LPTSTR)szFile;
274 ofn.nMaxFile = MAX_PATH;
275 ofn.lpstrFileTitle = NULL;
276 ofn.nMaxFileTitle = 40;
277 ofn.lpstrInitialDir = NULL;
278 ofn.lpstrTitle = _FROMMB(p_arg->psz_title);
281 ofn.nFileExtension = 0;
282 ofn.lpstrDefExt = NULL;
285 ofn.lpTemplateName = NULL;
287 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
289 if( p_arg->b_save && GetSaveFileName( &ofn ) )
291 p_arg->i_results = 1;
292 p_arg->psz_results = (char **)malloc( p_arg->i_results *
294 p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
297 if( !p_arg->b_save && GetOpenFile( &ofn ) )
299 p_arg->i_results = 1;
300 p_arg->psz_results = (char **)malloc( p_arg->i_results *
302 p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
306 if( p_arg->pf_callback )
308 p_arg->pf_callback( p_arg );
311 if( p_arg->psz_results )
313 for( int i = 0; i < p_arg->i_results; i++ )
315 free( p_arg->psz_results[i] );
317 free( p_arg->psz_results );
319 if( p_arg->psz_title ) free( p_arg->psz_title );
320 if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
325 void DialogsProvider::OnOpenFileSimple( int i_arg )
328 TCHAR szFile[MAX_PATH] = _T("\0");
329 static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
331 playlist_t *p_playlist = (playlist_t *)
332 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
333 if( p_playlist == NULL ) return;
335 memset( &ofn, 0, sizeof(OPENFILENAME) );
336 ofn.lStructSize = sizeof(OPENFILENAME);
337 ofn.hwndOwner = hWnd;
338 ofn.hInstance = hInst;
339 ofn.lpstrFilter = szFilter;
340 ofn.lpstrCustomFilter = NULL;
341 ofn.nMaxCustFilter = 0;
342 ofn.nFilterIndex = 1;
343 ofn.lpstrFile = (LPTSTR)szFile;
344 ofn.nMaxFile = MAX_PATH;
345 ofn.lpstrFileTitle = NULL;
346 ofn.nMaxFileTitle = 40;
347 ofn.lpstrInitialDir = NULL;
348 ofn.lpstrTitle = _T("Quick Open File");
351 ofn.nFileExtension = 0;
352 ofn.lpstrDefExt = NULL;
355 ofn.lpTemplateName = NULL;
357 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
359 if( GetOpenFile( &ofn ) )
361 char *psz_filename = _TOMB(ofn.lpstrFile);
362 playlist_Add( p_playlist, psz_filename, psz_filename,
363 PLAYLIST_APPEND | (i_arg?PLAYLIST_GO:0), PLAYLIST_END );
366 vlc_object_release( p_playlist );
369 void DialogsProvider::OnOpenDirectory( int i_arg )
371 TCHAR psz_result[MAX_PATH];
372 LPMALLOC p_malloc = 0;
375 playlist_t *p_playlist = 0;
378 # define SHGetMalloc MySHGetMalloc
379 # define SHBrowseForFolder MySHBrowseForFolder
380 # define SHGetPathFromIDList MySHGetPathFromIDList
382 HMODULE ceshell_dll = LoadLibrary( _T("ceshell") );
383 if( !ceshell_dll ) return;
385 HRESULT (WINAPI *SHGetMalloc)(LPMALLOC *) =
386 (HRESULT (WINAPI *)(LPMALLOC *))
387 GetProcAddress( ceshell_dll, _T("SHGetMalloc") );
388 LPITEMIDLIST (WINAPI *SHBrowseForFolder)(LPBROWSEINFO) =
389 (LPITEMIDLIST (WINAPI *)(LPBROWSEINFO))
390 GetProcAddress( ceshell_dll, _T("SHBrowseForFolder") );
391 BOOL (WINAPI *SHGetPathFromIDList)(LPCITEMIDLIST, LPTSTR) =
392 (BOOL (WINAPI *)(LPCITEMIDLIST, LPTSTR))
393 GetProcAddress( ceshell_dll, _T("SHGetPathFromIDList") );
395 if( !SHGetMalloc || !SHBrowseForFolder || !SHGetPathFromIDList )
397 msg_Err( p_intf, "couldn't load SHBrowseForFolder API" );
398 FreeLibrary( ceshell_dll );
403 if( !SUCCEEDED( SHGetMalloc(&p_malloc) ) ) goto error;
405 p_playlist = (playlist_t *)
406 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
407 if( !p_playlist ) goto error;
409 memset( &bi, 0, sizeof(BROWSEINFO) );
411 bi.pszDisplayName = psz_result;
412 bi.ulFlags = BIF_EDITBOX;
414 bi.ulFlags |= BIF_USENEWUI;
417 if( (pidl = SHBrowseForFolder( &bi ) ) )
419 if( SHGetPathFromIDList( pidl, psz_result ) )
421 char *psz_filename = _TOMB(psz_result);
422 playlist_Add( p_playlist, psz_filename, psz_filename,
423 PLAYLIST_APPEND | (i_arg ? PLAYLIST_GO : 0),
426 p_malloc->Free( pidl );
431 if( p_malloc) p_malloc->Release();
432 if( p_playlist ) vlc_object_release( p_playlist );
435 FreeLibrary( ceshell_dll );