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

wince.cpp

00001 /*****************************************************************************
00002  * wince.cpp: WinCE gui plugin for VLC
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: wince.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Author: 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,
00022  * USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <vlc/vlc.h>
00029 #include <vlc/intf.h>
00030 
00031 #if defined( UNDER_CE ) && defined(__MINGW32__)
00032 /* This is a gross hack for the wince gcc cross-compiler */
00033 #define _off_t long
00034 #endif
00035 
00036 #include "wince.h"
00037 
00038 #include <objbase.h>
00039 
00040 /*****************************************************************************
00041  * Local prototypes.
00042  *****************************************************************************/
00043 static int  Open   ( vlc_object_t * );
00044 static void Close  ( vlc_object_t * );
00045 static void Run    ( intf_thread_t * );
00046 
00047 static int  OpenDialogs( vlc_object_t * );
00048 
00049 static void MainLoop  ( intf_thread_t * );
00050 static void ShowDialog( intf_thread_t *, int, int, intf_dialog_args_t * );
00051 
00052 /*****************************************************************************
00053  * Module descriptor
00054  *****************************************************************************/
00055 #define EMBED_TEXT N_("Embed video in interface")
00056 #define EMBED_LONGTEXT N_("Embed the video inside the interface instead " \
00057     "of having it in a separate window.")
00058 
00059 vlc_module_begin();
00060     set_description( (char *) _("WinCE interface module") );
00061     set_capability( "interface", 100 );
00062     set_callbacks( Open, Close );
00063     add_shortcut( "wince" );
00064     set_program( "wcevlc" );
00065 
00066     add_bool( "wince-embed", 1, NULL,
00067               EMBED_TEXT, EMBED_LONGTEXT, VLC_FALSE );
00068 
00069     add_submodule();
00070     set_description( _("WinCE dialogs provider") );
00071     set_capability( "dialogs provider", 10 );
00072     set_callbacks( OpenDialogs, Close );
00073 vlc_module_end();
00074 
00075 HINSTANCE hInstance = 0;
00076 
00077 #if !defined(__BUILTIN__)
00078 extern "C" BOOL WINAPI
00079 DllMain( HANDLE hModule, DWORD fdwReason, LPVOID lpReserved )
00080 {
00081     hInstance = (HINSTANCE)hModule;
00082     return TRUE;
00083 }
00084 #endif
00085 
00086 /* Global variables used by _TOMB() / _FROMB() */
00087 wchar_t pwsz_mbtow_wince[2048];
00088 char psz_wtomb_wince[2048];
00089 
00090 /*****************************************************************************
00091  * Open: initialize interface
00092  *****************************************************************************/
00093 static int Open( vlc_object_t *p_this )
00094 {
00095     intf_thread_t *p_intf = (intf_thread_t *)p_this;
00096 
00097     // Check if the application is running.
00098     // If it's running then focus its window and bail out.
00099     HWND hwndMain = FindWindow( _T("VLC WinCE"), _T("VLC media player") );  
00100     if( hwndMain )
00101     {
00102         SetForegroundWindow( hwndMain );
00103         return VLC_EGENERIC;
00104     }
00105 
00106     // Allocate instance and initialize some members
00107     p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
00108     if( p_intf->p_sys == NULL )
00109     {
00110         msg_Err( p_intf, "out of memory" );
00111         return VLC_EGENERIC;
00112     }
00113 
00114     // Suscribe to messages bank
00115     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
00116 
00117     // Misc init
00118     p_intf->p_sys->p_audio_menu = NULL;
00119     p_intf->p_sys->p_video_menu = NULL;
00120     p_intf->p_sys->p_navig_menu = NULL;
00121     p_intf->p_sys->p_settings_menu = NULL;
00122 
00123     p_intf->pf_run = Run;
00124     p_intf->pf_show_dialog = NULL;
00125 
00126     p_intf->p_sys->p_input = NULL;
00127     p_intf->p_sys->b_playing = 0;
00128     p_intf->p_sys->i_playing = -1;
00129     p_intf->p_sys->b_slider_free = 1;
00130     p_intf->p_sys->i_slider_pos = p_intf->p_sys->i_slider_oldpos = 0;
00131 
00132     return VLC_SUCCESS;
00133 }
00134 
00135 static int OpenDialogs( vlc_object_t *p_this )
00136 {
00137     intf_thread_t *p_intf = (intf_thread_t *)p_this;
00138     int i_ret = Open( p_this );
00139 
00140     p_intf->pf_show_dialog = ShowDialog;
00141 
00142     return i_ret;
00143 }
00144 
00145 /*****************************************************************************
00146  * Close: destroy interface
00147  *****************************************************************************/
00148 static void Close( vlc_object_t *p_this )
00149 {
00150     intf_thread_t *p_intf = (intf_thread_t *)p_this;
00151 
00152     if( p_intf->p_sys->p_input )
00153     {
00154         vlc_object_release( p_intf->p_sys->p_input );
00155     }
00156 
00157     MenuItemExt::ClearList( p_intf->p_sys->p_video_menu );
00158     delete p_intf->p_sys->p_video_menu;
00159     MenuItemExt::ClearList( p_intf->p_sys->p_audio_menu );
00160     delete p_intf->p_sys->p_audio_menu;
00161     MenuItemExt::ClearList( p_intf->p_sys->p_settings_menu );
00162     delete p_intf->p_sys->p_settings_menu;
00163     MenuItemExt::ClearList( p_intf->p_sys->p_navig_menu );
00164     delete p_intf->p_sys->p_navig_menu;
00165 
00166     if( p_intf->pf_show_dialog )
00167     {
00168         /* We must destroy the dialogs thread */
00169 #if 0
00170         wxCommandEvent event( wxEVT_DIALOG, INTF_DIALOG_EXIT );
00171         p_intf->p_sys->p_wxwindow->AddPendingEvent( event );
00172 #endif
00173         vlc_thread_join( p_intf );
00174     }
00175 
00176     // Unsuscribe to messages bank
00177     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
00178 
00179     // Destroy structure
00180     free( p_intf->p_sys );
00181 }
00182 
00183 /*****************************************************************************
00184  * Run: main loop
00185  *****************************************************************************/
00186 static void Run( intf_thread_t *p_intf )
00187 {
00188     if( p_intf->pf_show_dialog )
00189     {
00190         /* The module is used in dialog provider mode */
00191 
00192         /* Create a new thread for the dialogs provider */
00193         if( vlc_thread_create( p_intf, "Skins Dialogs Thread",
00194                                MainLoop, 0, VLC_TRUE ) )
00195         {
00196             msg_Err( p_intf, "cannot create Skins Dialogs Thread" );
00197             p_intf->pf_show_dialog = NULL;
00198         }
00199     }
00200     else
00201     {
00202         /* The module is used in interface mode */
00203         MainLoop( p_intf );
00204     }
00205 }
00206 
00207 static void MainLoop( intf_thread_t *p_intf )
00208 {
00209     MSG msg;
00210     Interface *intf = 0;
00211 
00212     if( !hInstance ) hInstance = GetModuleHandle(NULL);
00213 
00214     // Register window class
00215     WNDCLASS wc;
00216     wc.style = CS_HREDRAW | CS_VREDRAW ;
00217     wc.lpfnWndProc = (WNDPROC)CBaseWindow::BaseWndProc;
00218     wc.cbClsExtra = 0;
00219     wc.cbWndExtra = 0;
00220     wc.hIcon = NULL;
00221     wc.hInstance = hInstance;
00222     wc.hCursor = NULL;
00223     wc.hbrBackground = (HBRUSH)(COLOR_MENU+1);
00224     wc.lpszMenuName = NULL;
00225     wc.lpszClassName = _T("VLC WinCE");
00226     RegisterClass( &wc );
00227 
00228 #ifndef UNDER_CE
00229     /* Initialize OLE/COM */
00230     CoInitialize( 0 );
00231 #endif
00232 
00233     if( !p_intf->pf_show_dialog )
00234     {
00235         /* The module is used in interface mode */
00236         p_intf->p_sys->p_window = intf = new Interface( p_intf, 0, hInstance );
00237 
00238         /* Create/Show the interface */
00239         if( !intf->InitInstance() ) goto end;
00240     }
00241 
00242     /* Creates the dialogs provider */
00243     p_intf->p_sys->p_window =
00244         CreateDialogsProvider( p_intf, p_intf->pf_show_dialog ?
00245                                NULL : p_intf->p_sys->p_window, hInstance );
00246 
00247     p_intf->p_sys->pf_show_dialog = ShowDialog;
00248 
00249     /* OK, initialization is over */
00250     vlc_thread_ready( p_intf );
00251 
00252     /* Check if we need to start playing */
00253     if( !p_intf->pf_show_dialog && p_intf->b_play )
00254     {
00255         playlist_t *p_playlist =
00256             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00257                                            FIND_ANYWHERE );
00258         if( p_playlist )
00259         {
00260             playlist_Play( p_playlist );
00261             vlc_object_release( p_playlist );
00262         }
00263     }
00264 
00265     // Main message loop
00266     while( GetMessage( &msg, NULL, 0, 0 ) > 0 )
00267     {
00268         TranslateMessage( &msg );
00269         DispatchMessage( &msg );
00270     }
00271 
00272  end:
00273     if( intf ) delete intf;
00274 
00275 #ifndef UNDER_CE
00276     /* Uninitialize OLE/COM */
00277     CoUninitialize();
00278 #endif
00279 }
00280 
00281 /*****************************************************************************
00282  * CBaseWindow Implementation
00283  *****************************************************************************/
00284 LRESULT CALLBACK CBaseWindow::BaseWndProc( HWND hwnd, UINT msg, WPARAM wParam,
00285                                            LPARAM lParam )
00286 {
00287     CBaseWindow *p_obj;
00288 
00289     // check to see if a copy of the 'this' pointer needs to be saved
00290     if( msg == WM_CREATE )
00291     {
00292         p_obj = (CBaseWindow *)(((LPCREATESTRUCT)lParam)->lpCreateParams);
00293         SetWindowLong( hwnd, GWL_USERDATA,
00294                        (LONG)((LPCREATESTRUCT)lParam)->lpCreateParams );
00295 
00296         p_obj->hWnd = hwnd;
00297     }
00298 
00299     if( msg == WM_INITDIALOG )
00300     {
00301         p_obj = (CBaseWindow *)lParam;
00302         SetWindowLong( hwnd, GWL_USERDATA, lParam );
00303         p_obj->hWnd = hwnd;
00304     }
00305 
00306     // Retrieve the pointer
00307     p_obj = (CBaseWindow *)GetWindowLong( hwnd, GWL_USERDATA );
00308 
00309     if( !p_obj ) return DefWindowProc( hwnd, msg, wParam, lParam );
00310 
00311     // Filter message through child classes
00312     return p_obj->WndProc( hwnd, msg, wParam, lParam );
00313 }
00314 
00315 int CBaseWindow::CreateDialogBox( HWND hwnd, CBaseWindow *p_obj )
00316 {
00317     uint8_t p_buffer[sizeof(DLGTEMPLATE) + sizeof(WORD) * 4];
00318     DLGTEMPLATE *p_dlg_template = (DLGTEMPLATE *)p_buffer;
00319     memset( p_dlg_template, 0, sizeof(DLGTEMPLATE) + sizeof(WORD) * 4 );
00320 
00321     // these values are arbitrary, they won't be used normally anyhow
00322     p_dlg_template->x  = 0; p_dlg_template->y  = 0;
00323     p_dlg_template->cx = 300; p_dlg_template->cy = 300;
00324     p_dlg_template->style =
00325         DS_MODALFRAME|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX;
00326 
00327     return DialogBoxIndirectParam( GetModuleHandle(0), p_dlg_template, hwnd,
00328                                    (DLGPROC)p_obj->BaseWndProc, (LPARAM)p_obj);
00329 }
00330 
00331 /*****************************************************************************
00332  * ShowDialog
00333  *****************************************************************************/
00334 static void ShowDialog( intf_thread_t *p_intf, int i_dialog_event, int i_arg,
00335                         intf_dialog_args_t *p_arg )
00336 {
00337     SendMessage( p_intf->p_sys->p_window->GetHandle(), WM_CANCELMODE, 0, 0 );
00338     if( i_dialog_event == INTF_DIALOG_POPUPMENU && i_arg == 0 ) return;
00339 
00340     /* Hack to prevent popup events to be enqueued when
00341      * one is already active */
00342 #if 0
00343     if( i_dialog_event != INTF_DIALOG_POPUPMENU ||
00344         !p_intf->p_sys->p_popup_menu )
00345 #endif
00346     {
00347         SendMessage( p_intf->p_sys->p_window->GetHandle(),
00348                      WM_APP + i_dialog_event, (WPARAM)i_arg, (LPARAM)p_arg );
00349     }
00350 }

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