Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

dialogs.cpp

00001 /*****************************************************************************
00002  * dialogs.cpp : WinCE plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2000-2005 the VideoLAN team
00005  * $Id: dialogs.cpp 10101 2005-03-02 16:47:31Z robux4 $
00006  *
00007  * Authors: Gildas Bazin <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 
00029 #include <vlc/vlc.h>
00030 #include <vlc/aout.h>
00031 #include <vlc/intf.h>
00032 
00033 #include "wince.h"
00034 
00035 #include <commctrl.h>
00036 #include <commdlg.h>
00037 #include <shlobj.h>
00038 
00039 /* Dialogs Provider */
00040 class DialogsProvider: public CBaseWindow
00041 {
00042 public:
00043     /* Constructor */
00044     DialogsProvider( intf_thread_t *, CBaseWindow *, HINSTANCE = 0 );
00045     virtual ~DialogsProvider();
00046 
00047 protected:
00048     virtual LRESULT WndProc( HWND, UINT, WPARAM, LPARAM );
00049 
00050 private:
00051 
00052     void OnExit( void );
00053     void OnIdle( void );
00054     void OnPlaylist( void );
00055     void OnMessages( void );
00056     void OnFileInfo( void );
00057     void OnPreferences( void );
00058     void OnPopupMenu( void );
00059 
00060     void OnOpen( int, int );
00061     void OnOpenFileSimple( int );
00062     void OnOpenDirectory( int );
00063     void OnOpenFileGeneric( intf_dialog_args_t * );
00064 
00065     /* GetOpenFileName replacement */
00066     BOOL (WINAPI *GetOpenFile)(void *);
00067     HMODULE h_gsgetfile_dll;
00068 
00069 public:
00070     /* Secondary windows */
00071     OpenDialog          *p_open_dialog;
00072     Playlist            *p_playlist_dialog;
00073     Messages            *p_messages_dialog;
00074     PrefsDialog         *p_prefs_dialog;
00075     FileInfo            *p_fileinfo_dialog;
00076 };
00077 
00078 CBaseWindow *CreateDialogsProvider( intf_thread_t *p_intf,
00079                                     CBaseWindow *p_parent, HINSTANCE h_inst )
00080 {
00081     return new DialogsProvider( p_intf, p_parent, h_inst );
00082 }
00083 
00084 /*****************************************************************************
00085  * Constructor.
00086  *****************************************************************************/
00087 DialogsProvider::DialogsProvider( intf_thread_t *p_intf,
00088                                   CBaseWindow *p_parent, HINSTANCE h_inst )
00089   :  CBaseWindow( p_intf, p_parent, h_inst )
00090 {
00091     /* Initializations */
00092     p_open_dialog = NULL;
00093     p_playlist_dialog = NULL;
00094     p_messages_dialog = NULL;
00095     p_fileinfo_dialog = NULL;
00096     p_prefs_dialog = NULL;
00097 
00098     /* Create dummy window */
00099     hWnd = CreateWindow( _T("VLC WinCE"), _T("DialogsProvider"), 0,
00100                          0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
00101                          p_parent->GetHandle(), NULL, h_inst, (void *)this );
00102 
00103     GetOpenFile = 0;
00104     h_gsgetfile_dll = LoadLibrary( _T("gsgetfile") );
00105     if( h_gsgetfile_dll )
00106     {
00107         GetOpenFile = (BOOL (WINAPI *)(void *))
00108             GetProcAddress( h_gsgetfile_dll, _T("gsGetOpenFileName") );
00109     }
00110 
00111     if( !GetOpenFile )
00112         GetOpenFile = (BOOL (WINAPI *)(void *))::GetOpenFileName;
00113 }
00114 
00115 DialogsProvider::~DialogsProvider()
00116 {
00117     /* Clean up */
00118     if( p_open_dialog )     delete p_open_dialog;
00119     if( p_playlist_dialog ) delete p_playlist_dialog;
00120     if( p_messages_dialog ) delete p_messages_dialog;
00121     if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
00122     if( p_prefs_dialog )    delete p_prefs_dialog;
00123 
00124     if( h_gsgetfile_dll ) FreeLibrary( h_gsgetfile_dll );
00125 }
00126 
00127 LRESULT DialogsProvider::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
00128 {
00129     switch( msg )
00130     {
00131     case WM_APP + INTF_DIALOG_FILE: OnOpen( FILE_ACCESS, wp ); return TRUE;
00132     case WM_APP + INTF_DIALOG_NET: OnOpen( NET_ACCESS, wp ); return TRUE;
00133     case WM_APP + INTF_DIALOG_FILE_SIMPLE: OnOpenFileSimple( wp ); return TRUE;
00134     case WM_APP + INTF_DIALOG_DIRECTORY: OnOpenDirectory( wp ); return TRUE;
00135     case WM_APP + INTF_DIALOG_FILE_GENERIC:
00136         OnOpenFileGeneric( (intf_dialog_args_t*)lp ); return TRUE;
00137     case WM_APP + INTF_DIALOG_PLAYLIST: OnPlaylist(); return TRUE;
00138     case WM_APP + INTF_DIALOG_MESSAGES: OnMessages(); return TRUE;
00139     case WM_APP + INTF_DIALOG_FILEINFO: OnFileInfo(); return TRUE;
00140     case WM_APP + INTF_DIALOG_PREFS: OnPreferences(); return TRUE;
00141     case WM_APP + INTF_DIALOG_POPUPMENU: OnPopupMenu(); return TRUE;
00142     }
00143 
00144     return DefWindowProc( hwnd, msg, wp, lp );
00145 }
00146 
00147 void DialogsProvider::OnIdle( void )
00148 {
00149     /* Update the log window */
00150     if( p_messages_dialog ) p_messages_dialog->UpdateLog();
00151 
00152     /* Update the playlist */
00153     if( p_playlist_dialog ) p_playlist_dialog->UpdatePlaylist();
00154 
00155     /* Update the fileinfo windows */
00156     if( p_fileinfo_dialog ) p_fileinfo_dialog->UpdateFileInfo();
00157 }
00158 
00159 void DialogsProvider::OnPopupMenu( void )
00160 {
00161     POINT point = {0};
00162     PopupMenu( p_intf, hWnd, point );
00163 }
00164 
00165 void DialogsProvider::OnPlaylist( void )
00166 {
00167 #if 1
00168     Playlist *playlist = new Playlist( p_intf, this, hInst );
00169     CreateDialogBox( hWnd, playlist );
00170     delete playlist;
00171 #else
00172     /* Show/hide the playlist window */
00173     if( !p_playlist_dialog )
00174         p_playlist_dialog = new Playlist( p_intf, this, hInst );
00175 
00176     if( p_playlist_dialog )
00177     {
00178         p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
00179     }
00180 #endif
00181 }
00182 
00183 void DialogsProvider::OnMessages( void )
00184 {
00185     /* Show/hide the log window */
00186     if( !p_messages_dialog )
00187         p_messages_dialog = new Messages( p_intf, this, hInst );
00188 
00189     if( p_messages_dialog )
00190     {
00191         p_messages_dialog->Show( !p_messages_dialog->IsShown() );
00192     }
00193 }
00194 
00195 void DialogsProvider::OnFileInfo( void )
00196 {
00197 #if 1
00198     FileInfo *fileinfo = new FileInfo( p_intf, this, hInst );
00199     CreateDialogBox( hWnd, fileinfo );
00200     delete fileinfo;
00201 #else
00202     /* Show/hide the file info window */
00203     if( !p_fileinfo_dialog )
00204         p_fileinfo_dialog = new FileInfo( p_intf, this, hInst );
00205 
00206     if( p_fileinfo_dialog )
00207     {
00208         p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
00209     }
00210 #endif
00211 }
00212 
00213 void DialogsProvider::OnPreferences( void )
00214 {
00215 #if 1
00216     PrefsDialog *preferences = new PrefsDialog( p_intf, this, hInst );
00217     CreateDialogBox( hWnd, preferences );
00218     delete preferences;
00219 #else
00220     /* Show/hide the open dialog */
00221     if( !p_prefs_dialog )
00222         p_prefs_dialog = new PrefsDialog( p_intf, this, hInst );
00223 
00224     if( p_prefs_dialog )
00225     {
00226         p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
00227     }
00228 #endif
00229 }
00230 
00231 void DialogsProvider::OnOpen( int i_access, int i_arg )
00232 {
00233     /* Show/hide the open dialog */
00234     if( !p_open_dialog )
00235         p_open_dialog = new OpenDialog( p_intf, this, hInst, i_access, i_arg );
00236 
00237     if( p_open_dialog )
00238     {
00239         p_open_dialog->Show( !p_open_dialog->IsShown() );
00240     }
00241 }
00242 
00243 void DialogsProvider::OnOpenFileGeneric( intf_dialog_args_t *p_arg )
00244 {
00245     if( p_arg == NULL )
00246     {
00247         msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
00248         return;
00249     }
00250 
00251     /* Convert the filter string */
00252     TCHAR *psz_filters = (TCHAR *)
00253         malloc( (strlen(p_arg->psz_extensions) + 2) * sizeof(TCHAR) );
00254     _tcscpy( psz_filters, _FROMMB(p_arg->psz_extensions) );
00255 
00256     int i;
00257     for( i = 0; psz_filters[i]; i++ )
00258     {
00259         if( psz_filters[i] == '|' ) psz_filters[i] = 0;
00260     }
00261     psz_filters[++i] = 0;
00262 
00263     OPENFILENAME ofn;
00264     TCHAR szFile[MAX_PATH] = _T("\0");
00265 
00266     memset( &ofn, 0, sizeof(OPENFILENAME) );
00267     ofn.lStructSize = sizeof(OPENFILENAME);
00268     ofn.hwndOwner = hWnd;
00269     ofn.hInstance = hInst;
00270     ofn.lpstrFilter = psz_filters;
00271     ofn.lpstrCustomFilter = NULL;
00272     ofn.nMaxCustFilter = 0;
00273     ofn.nFilterIndex = 1;
00274     ofn.lpstrFile = (LPTSTR)szFile; 
00275     ofn.nMaxFile = MAX_PATH;
00276     ofn.lpstrFileTitle = NULL; 
00277     ofn.nMaxFileTitle = 40;
00278     ofn.lpstrInitialDir = NULL;
00279     ofn.lpstrTitle = _FROMMB(p_arg->psz_title);
00280     ofn.Flags = 0; 
00281     ofn.nFileOffset = 0;
00282     ofn.nFileExtension = 0;
00283     ofn.lpstrDefExt = NULL;
00284     ofn.lCustData = 0L;
00285     ofn.lpfnHook = NULL;
00286     ofn.lpTemplateName = NULL;
00287 
00288     SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
00289 
00290     if( p_arg->b_save && GetSaveFileName( &ofn ) )
00291     {
00292         p_arg->i_results = 1;
00293         p_arg->psz_results = (char **)malloc( p_arg->i_results *
00294                                               sizeof(char *) );
00295         p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
00296     }
00297 
00298     if( !p_arg->b_save && GetOpenFile( &ofn ) )
00299     {
00300         p_arg->i_results = 1;
00301         p_arg->psz_results = (char **)malloc( p_arg->i_results *
00302                                               sizeof(char *) );
00303         p_arg->psz_results[0] = strdup( _TOMB(ofn.lpstrFile) );
00304     }
00305 
00306     /* Callback */
00307     if( p_arg->pf_callback )
00308     {
00309         p_arg->pf_callback( p_arg );
00310     }
00311 
00312     if( p_arg->psz_results )
00313     {
00314         for( int i = 0; i < p_arg->i_results; i++ )
00315         {
00316             free( p_arg->psz_results[i] );
00317         }
00318         free( p_arg->psz_results );
00319     }
00320     if( p_arg->psz_title ) free( p_arg->psz_title );
00321     if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
00322 
00323     free( p_arg );
00324 }
00325 
00326 void DialogsProvider::OnOpenFileSimple( int i_arg )
00327 {
00328     OPENFILENAME ofn;
00329     TCHAR szFile[MAX_PATH] = _T("\0");
00330     static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
00331 
00332     playlist_t *p_playlist = (playlist_t *)
00333         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00334     if( p_playlist == NULL ) return;
00335 
00336     memset( &ofn, 0, sizeof(OPENFILENAME) );
00337     ofn.lStructSize = sizeof(OPENFILENAME);
00338     ofn.hwndOwner = hWnd;
00339     ofn.hInstance = hInst;
00340     ofn.lpstrFilter = szFilter;
00341     ofn.lpstrCustomFilter = NULL;
00342     ofn.nMaxCustFilter = 0;
00343     ofn.nFilterIndex = 1;     
00344     ofn.lpstrFile = (LPTSTR)szFile; 
00345     ofn.nMaxFile = MAX_PATH;
00346     ofn.lpstrFileTitle = NULL; 
00347     ofn.nMaxFileTitle = 40;
00348     ofn.lpstrInitialDir = NULL;
00349     ofn.lpstrTitle = _T("Quick Open File");
00350     ofn.Flags = 0; 
00351     ofn.nFileOffset = 0;
00352     ofn.nFileExtension = 0;
00353     ofn.lpstrDefExt = NULL;
00354     ofn.lCustData = 0L;
00355     ofn.lpfnHook = NULL;
00356     ofn.lpTemplateName = NULL;
00357 
00358     SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
00359 
00360     if( GetOpenFile( &ofn ) )
00361     {
00362         char *psz_filename = _TOMB(ofn.lpstrFile);
00363         playlist_Add( p_playlist, psz_filename, psz_filename,
00364                       PLAYLIST_APPEND | (i_arg?PLAYLIST_GO:0), PLAYLIST_END );
00365     }
00366 
00367     vlc_object_release( p_playlist );
00368 }
00369 
00370 void DialogsProvider::OnOpenDirectory( int i_arg )
00371 {
00372     TCHAR psz_result[MAX_PATH];
00373     LPMALLOC p_malloc = 0;
00374     LPITEMIDLIST pidl;
00375     BROWSEINFO bi;
00376     playlist_t *p_playlist = 0;
00377 
00378 #ifdef UNDER_CE
00379 #   define SHGetMalloc MySHGetMalloc
00380 #   define SHBrowseForFolder MySHBrowseForFolder
00381 #   define SHGetPathFromIDList MySHGetPathFromIDList
00382 
00383     HMODULE ceshell_dll = LoadLibrary( _T("ceshell") );
00384     if( !ceshell_dll ) return;
00385 
00386     HRESULT (WINAPI *SHGetMalloc)(LPMALLOC *) =
00387         (HRESULT (WINAPI *)(LPMALLOC *))
00388         GetProcAddress( ceshell_dll, _T("SHGetMalloc") );
00389     LPITEMIDLIST (WINAPI *SHBrowseForFolder)(LPBROWSEINFO) =
00390         (LPITEMIDLIST (WINAPI *)(LPBROWSEINFO))
00391         GetProcAddress( ceshell_dll, _T("SHBrowseForFolder") );
00392     BOOL (WINAPI *SHGetPathFromIDList)(LPCITEMIDLIST, LPTSTR) =
00393         (BOOL (WINAPI *)(LPCITEMIDLIST, LPTSTR))
00394         GetProcAddress( ceshell_dll, _T("SHGetPathFromIDList") );
00395 
00396     if( !SHGetMalloc || !SHBrowseForFolder || !SHGetPathFromIDList )
00397     {
00398         msg_Err( p_intf, "couldn't load SHBrowseForFolder API" );
00399         FreeLibrary( ceshell_dll );
00400         return;
00401     }
00402 #endif
00403 
00404     if( !SUCCEEDED( SHGetMalloc(&p_malloc) ) ) goto error;
00405 
00406     p_playlist = (playlist_t *)
00407         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00408     if( !p_playlist ) goto error;
00409 
00410     memset( &bi, 0, sizeof(BROWSEINFO) );
00411     bi.hwndOwner = hWnd;
00412     bi.pszDisplayName = psz_result;
00413     bi.ulFlags = BIF_EDITBOX;
00414 #ifndef UNDER_CE
00415     bi.ulFlags |= BIF_USENEWUI;
00416 #endif
00417 
00418     if( (pidl = SHBrowseForFolder( &bi ) ) )
00419     {
00420         if( SHGetPathFromIDList( pidl, psz_result ) )
00421         {
00422             char *psz_filename = _TOMB(psz_result);
00423             playlist_Add( p_playlist, psz_filename, psz_filename,
00424                           PLAYLIST_APPEND | (i_arg ? PLAYLIST_GO : 0),
00425                           PLAYLIST_END );
00426         }
00427         p_malloc->Free( pidl );
00428     }
00429 
00430  error:
00431 
00432     if( p_malloc) p_malloc->Release();
00433     if( p_playlist ) vlc_object_release( p_playlist );
00434 
00435 #ifdef UNDER_CE
00436     FreeLibrary( ceshell_dll );
00437 #endif
00438 }

Generated on Tue Dec 20 10:14:42 2005 for vlc-0.8.4a by  doxygen 1.4.2