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 log window */
154 if( p_messages_dialog ) p_messages_dialog->UpdateLog();
156 /* Update the playlist */
157 if( p_playlist_dialog ) p_playlist_dialog->UpdatePlaylist();
159 /* Update the fileinfo windows */
160 if( p_fileinfo_dialog ) p_fileinfo_dialog->UpdateFileInfo();
163 void DialogsProvider::OnPopupMenu( void )
166 PopupMenu( p_intf, hWnd, point );
169 void DialogsProvider::OnPlaylist( void )
172 Playlist *playlist = new Playlist( p_intf, this, hInst );
173 CreateDialogBox( hWnd, playlist );
176 /* Show/hide the playlist window */
177 if( !p_playlist_dialog )
178 p_playlist_dialog = new Playlist( p_intf, this, hInst );
180 if( p_playlist_dialog )
182 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
187 void DialogsProvider::OnMessages( void )
189 /* Show/hide the log window */
190 if( !p_messages_dialog )
191 p_messages_dialog = new Messages( p_intf, this, hInst );
193 if( p_messages_dialog )
195 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
199 void DialogsProvider::OnFileInfo( void )
202 FileInfo *fileinfo = new FileInfo( p_intf, this, hInst );
203 CreateDialogBox( hWnd, fileinfo );
206 /* Show/hide the file info window */
207 if( !p_fileinfo_dialog )
208 p_fileinfo_dialog = new FileInfo( p_intf, this, hInst );
210 if( p_fileinfo_dialog )
212 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
217 void DialogsProvider::OnPreferences( void )
220 PrefsDialog *preferences = new PrefsDialog( p_intf, this, hInst );
221 CreateDialogBox( hWnd, preferences );
224 /* Show/hide the open dialog */
225 if( !p_prefs_dialog )
226 p_prefs_dialog = new PrefsDialog( p_intf, this, hInst );
230 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
235 void DialogsProvider::OnOpen( int i_access, int i_arg )
237 /* Show/hide the open dialog */
239 p_open_dialog = new OpenDialog( p_intf, this, hInst, i_access, i_arg );
243 p_open_dialog->Show( !p_open_dialog->IsShown() );
247 void DialogsProvider::OnOpenFileGeneric( intf_dialog_args_t *p_arg )
251 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
255 /* Convert the filter string */
256 TCHAR *psz_filters = (TCHAR *)
257 malloc( (strlen(p_arg->psz_extensions) + 2) * sizeof(TCHAR) );
258 _tcscpy( psz_filters, _FROMMB(p_arg->psz_extensions) );
261 for( i = 0; psz_filters[i]; i++ )
263 if( psz_filters[i] == '|' ) psz_filters[i] = 0;
265 psz_filters[++i] = 0;
268 TCHAR szFile[MAX_PATH] = _T("\0");
270 memset( &ofn, 0, sizeof(OPENFILENAME) );
271 ofn.lStructSize = sizeof(OPENFILENAME);
272 ofn.hwndOwner = hWnd;
273 ofn.hInstance = hInst;
274 ofn.lpstrFilter = psz_filters;
275 ofn.lpstrCustomFilter = NULL;
276 ofn.nMaxCustFilter = 0;
277 ofn.nFilterIndex = 1;
278 ofn.lpstrFile = (LPTSTR)szFile;
279 ofn.nMaxFile = MAX_PATH;
280 ofn.lpstrFileTitle = NULL;
281 ofn.nMaxFileTitle = 40;
282 ofn.lpstrInitialDir = NULL;
283 ofn.lpstrTitle = _FROMMB(p_arg->psz_title);
286 ofn.nFileExtension = 0;
287 ofn.lpstrDefExt = NULL;
290 ofn.lpTemplateName = NULL;
292 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
294 if( p_arg->b_save && GetSaveFileName( &ofn ) )
296 p_arg->i_results = 1;
297 p_arg->psz_results = (char **)malloc( p_arg->i_results *
299 p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
302 if( !p_arg->b_save && GetOpenFile( &ofn ) )
304 p_arg->i_results = 1;
305 p_arg->psz_results = (char **)malloc( p_arg->i_results *
307 p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
311 if( p_arg->pf_callback )
313 p_arg->pf_callback( p_arg );
316 if( p_arg->psz_results )
318 for( int i = 0; i < p_arg->i_results; i++ )
320 free( p_arg->psz_results[i] );
322 free( p_arg->psz_results );
324 free( p_arg->psz_title );
325 free( p_arg->psz_extensions );
330 void DialogsProvider::OnOpenFileSimple( int i_arg )
333 TCHAR szFile[MAX_PATH] = _T("\0");
334 static TCHAR szFilter[] = _T("wav (*.wav)\0*.wav\0mp3 (*.mp3 *.mpga)\0*.mp3;*.mpga\0All (*.*)\0*.*\0");
336 playlist_t *p_playlist = pl_Hold( p_intf );
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,
371 pl_Release( p_intf );
374 void DialogsProvider::OnOpenDirectory( int i_arg )
376 TCHAR psz_result[MAX_PATH];
377 LPMALLOC p_malloc = 0;
380 playlist_t *p_playlist = 0;
383 # define SHGetMalloc MySHGetMalloc
384 # define SHBrowseForFolder MySHBrowseForFolder
385 # define SHGetPathFromIDList MySHGetPathFromIDList
387 HMODULE ceshell_dll = LoadLibrary( _T("ceshell") );
388 if( !ceshell_dll ) return;
390 HRESULT (WINAPI *SHGetMalloc)(LPMALLOC *) =
391 (HRESULT (WINAPI *)(LPMALLOC *))
392 GetProcAddress( ceshell_dll, _T("SHGetMalloc") );
393 LPITEMIDLIST (WINAPI *SHBrowseForFolder)(LPBROWSEINFO) =
394 (LPITEMIDLIST (WINAPI *)(LPBROWSEINFO))
395 GetProcAddress( ceshell_dll, _T("SHBrowseForFolder") );
396 BOOL (WINAPI *SHGetPathFromIDList)(LPCITEMIDLIST, LPTSTR) =
397 (BOOL (WINAPI *)(LPCITEMIDLIST, LPTSTR))
398 GetProcAddress( ceshell_dll, _T("SHGetPathFromIDList") );
400 if( !SHGetMalloc || !SHBrowseForFolder || !SHGetPathFromIDList )
402 msg_Err( p_intf, "couldn't load SHBrowseForFolder API" );
403 FreeLibrary( ceshell_dll );
408 if( !SUCCEEDED( SHGetMalloc(&p_malloc) ) ) goto error;
410 p_playlist = pl_Hold( p_intf );
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),
428 PLAYLIST_END, TRUE, FALSE );
430 p_malloc->Free( pidl );
435 if( p_malloc) p_malloc->Release();
436 if( p_playlist ) pl_Release( p_intf );
439 FreeLibrary( ceshell_dll );