1 /*****************************************************************************
2 * dialogs.cpp : WinCE plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2005 VideoLAN
5 * $Id: dialogs.cpp 10101 2005-03-02 16:47:31Z robux4 $
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
39 /* Dialogs Provider */
40 class DialogsProvider: public CBaseWindow
44 DialogsProvider( intf_thread_t *, CBaseWindow *, HINSTANCE = 0 );
45 virtual ~DialogsProvider();
48 virtual LRESULT WndProc( HWND, UINT, WPARAM, LPARAM );
54 void OnPlaylist( void );
55 void OnMessages( void );
56 void OnFileInfo( void );
57 void OnPreferences( 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;
142 return DefWindowProc( hwnd, msg, wp, lp );
145 void DialogsProvider::OnIdle( void )
147 /* Update the log window */
148 if( p_messages_dialog ) p_messages_dialog->UpdateLog();
150 /* Update the playlist */
151 if( p_playlist_dialog ) p_playlist_dialog->UpdatePlaylist();
153 /* Update the fileinfo windows */
154 if( p_fileinfo_dialog ) p_fileinfo_dialog->UpdateFileInfo();
157 void DialogsProvider::OnPlaylist( void )
160 Playlist *playlist = new Playlist( p_intf, this, hInst );
161 CreateDialogBox( hWnd, playlist );
164 /* Show/hide the playlist window */
165 if( !p_playlist_dialog )
166 p_playlist_dialog = new Playlist( p_intf, this, hInst );
168 if( p_playlist_dialog )
170 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
175 void DialogsProvider::OnMessages( void )
177 /* Show/hide the log window */
178 if( !p_messages_dialog )
179 p_messages_dialog = new Messages( p_intf, this, hInst );
181 if( p_messages_dialog )
183 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
187 void DialogsProvider::OnFileInfo( void )
190 FileInfo *fileinfo = new FileInfo( p_intf, this, hInst );
191 CreateDialogBox( hWnd, fileinfo );
194 /* Show/hide the file info window */
195 if( !p_fileinfo_dialog )
196 p_fileinfo_dialog = new FileInfo( p_intf, this, hInst );
198 if( p_fileinfo_dialog )
200 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
205 void DialogsProvider::OnPreferences( void )
208 PrefsDialog *preferences = new PrefsDialog( p_intf, this, hInst );
209 CreateDialogBox( hWnd, preferences );
212 /* Show/hide the open dialog */
213 if( !p_prefs_dialog )
214 p_prefs_dialog = new PrefsDialog( p_intf, this, hInst );
218 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
223 void DialogsProvider::OnOpen( int i_access, int i_arg )
225 /* Show/hide the open dialog */
227 p_open_dialog = new OpenDialog( p_intf, this, hInst, i_access, i_arg );
231 p_open_dialog->Show( !p_open_dialog->IsShown() );
235 void DialogsProvider::OnOpenFileGeneric( intf_dialog_args_t *p_arg )
239 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
243 /* Convert the filter string */
244 TCHAR *psz_filters = (TCHAR *)
245 malloc( (strlen(p_arg->psz_extensions) + 2) * sizeof(TCHAR) );
246 _tcscpy( psz_filters, _FROMMB(p_arg->psz_extensions) );
249 for( i = 0; psz_filters[i]; i++ )
251 if( psz_filters[i] == '|' ) psz_filters[i] = 0;
253 psz_filters[++i] = 0;
256 TCHAR szFile[MAX_PATH] = _T("\0");
258 memset( &ofn, 0, sizeof(OPENFILENAME) );
259 ofn.lStructSize = sizeof(OPENFILENAME);
260 ofn.hwndOwner = hWnd;
261 ofn.hInstance = hInst;
262 ofn.lpstrFilter = psz_filters;
263 ofn.lpstrCustomFilter = NULL;
264 ofn.nMaxCustFilter = 0;
265 ofn.nFilterIndex = 1;
266 ofn.lpstrFile = (LPTSTR)szFile;
267 ofn.nMaxFile = MAX_PATH;
268 ofn.lpstrFileTitle = NULL;
269 ofn.nMaxFileTitle = 40;
270 ofn.lpstrInitialDir = NULL;
271 ofn.lpstrTitle = _FROMMB(p_arg->psz_title);
274 ofn.nFileExtension = 0;
275 ofn.lpstrDefExt = NULL;
278 ofn.lpTemplateName = NULL;
280 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
282 if( p_arg->b_save && GetSaveFileName( &ofn ) )
284 p_arg->i_results = 1;
285 p_arg->psz_results = (char **)malloc( p_arg->i_results *
287 p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
290 if( !p_arg->b_save && GetOpenFile( &ofn ) )
292 p_arg->i_results = 1;
293 p_arg->psz_results = (char **)malloc( p_arg->i_results *
295 p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
299 if( p_arg->pf_callback )
301 p_arg->pf_callback( p_arg );
304 if( p_arg->psz_results )
306 for( int i = 0; i < p_arg->i_results; i++ )
308 free( p_arg->psz_results[i] );
310 free( p_arg->psz_results );
312 if( p_arg->psz_title ) free( p_arg->psz_title );
313 if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
318 void DialogsProvider::OnOpenFileSimple( int i_arg )
321 TCHAR szFile[MAX_PATH] = _T("\0");
322 static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
324 playlist_t *p_playlist = (playlist_t *)
325 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
326 if( p_playlist == NULL ) return;
328 memset( &ofn, 0, sizeof(OPENFILENAME) );
329 ofn.lStructSize = sizeof(OPENFILENAME);
330 ofn.hwndOwner = hWnd;
331 ofn.hInstance = hInst;
332 ofn.lpstrFilter = szFilter;
333 ofn.lpstrCustomFilter = NULL;
334 ofn.nMaxCustFilter = 0;
335 ofn.nFilterIndex = 1;
336 ofn.lpstrFile = (LPTSTR)szFile;
337 ofn.nMaxFile = MAX_PATH;
338 ofn.lpstrFileTitle = NULL;
339 ofn.nMaxFileTitle = 40;
340 ofn.lpstrInitialDir = NULL;
341 ofn.lpstrTitle = _T("Quick Open File");
344 ofn.nFileExtension = 0;
345 ofn.lpstrDefExt = NULL;
348 ofn.lpTemplateName = NULL;
350 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
352 if( GetOpenFile( &ofn ) )
354 char *psz_filename = _TOMB(ofn.lpstrFile);
355 playlist_Add( p_playlist, psz_filename, psz_filename,
356 PLAYLIST_APPEND | (i_arg?PLAYLIST_GO:0), PLAYLIST_END );
359 vlc_object_release( p_playlist );
362 void DialogsProvider::OnOpenDirectory( int i_arg )
364 TCHAR psz_result[MAX_PATH];
365 LPMALLOC p_malloc = 0;
368 playlist_t *p_playlist = 0;
371 # define SHGetMalloc MySHGetMalloc
372 # define SHBrowseForFolder MySHBrowseForFolder
373 # define SHGetPathFromIDList MySHGetPathFromIDList
375 HMODULE ceshell_dll = LoadLibrary( _T("ceshell") );
376 if( !ceshell_dll ) return;
378 HRESULT WINAPI (*SHGetMalloc)(LPMALLOC *) =
379 (HRESULT WINAPI (*)(LPMALLOC *))
380 GetProcAddress( ceshell_dll, _T("SHGetMalloc") );
381 LPITEMIDLIST WINAPI (*SHBrowseForFolder)(LPBROWSEINFO) =
382 (LPITEMIDLIST WINAPI (*)(LPBROWSEINFO))
383 GetProcAddress( ceshell_dll, _T("SHBrowseForFolder") );
384 BOOL WINAPI (*SHGetPathFromIDList)(LPCITEMIDLIST, LPTSTR) =
385 (BOOL WINAPI (*)(LPCITEMIDLIST, LPTSTR))
386 GetProcAddress( ceshell_dll, _T("SHGetPathFromIDList") );
388 if( !SHGetMalloc || !SHBrowseForFolder || !SHGetPathFromIDList )
390 msg_Err( p_intf, "couldn't load SHBrowseForFolder API" );
391 FreeLibrary( ceshell_dll );
396 if( !SUCCEEDED( SHGetMalloc(&p_malloc) ) ) goto error;
398 p_playlist = (playlist_t *)
399 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
400 if( !p_playlist ) goto error;
402 memset( &bi, 0, sizeof(BROWSEINFO) );
404 bi.pszDisplayName = psz_result;
405 bi.ulFlags = BIF_EDITBOX;
407 bi.ulFlags |= BIF_USENEWUI;
410 if( (pidl = SHBrowseForFolder( &bi ) ) )
412 if( SHGetPathFromIDList( pidl, psz_result ) )
414 char *psz_filename = _TOMB(psz_result);
415 playlist_Add( p_playlist, psz_filename, psz_filename,
416 PLAYLIST_APPEND | (i_arg ? PLAYLIST_GO : 0),
419 p_malloc->Free( pidl );
424 if( p_malloc) p_malloc->Release();
425 if( p_playlist ) vlc_object_release( p_playlist );
428 FreeLibrary( ceshell_dll );