1 /*****************************************************************************
2 * wince.cpp: WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Author: 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,
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_interface.h>
35 #include <vlc_input.h>
37 #if defined( UNDER_CE ) && defined(__MINGW32__)
38 /* This is a gross hack for the wince gcc cross-compiler */
46 /*****************************************************************************
48 *****************************************************************************/
49 static int Open ( vlc_object_t * );
50 static void Close ( vlc_object_t * );
51 static void Run ( intf_thread_t * );
53 static int OpenDialogs( vlc_object_t * );
55 static void* MainLoop ( vlc_object_t * );
56 static void ShowDialog( intf_thread_t *, int, int, intf_dialog_args_t * );
58 /*****************************************************************************
60 *****************************************************************************/
61 #define EMBED_TEXT N_("Embed video in interface")
62 #define EMBED_LONGTEXT N_("Embed the video inside the interface instead " \
63 "of having it in a separate window.")
66 set_shortname( "WinCE" );
67 set_description( (char *) _("WinCE interface module") );
68 set_capability( "interface", 100 );
69 set_callbacks( Open, Close );
70 add_shortcut( "wince" );
72 set_category( CAT_INTERFACE );
73 set_subcategory( SUBCAT_INTERFACE_MAIN );
74 add_bool( "wince-embed", 1, NULL,
75 EMBED_TEXT, EMBED_LONGTEXT, false );
78 set_description( N_("WinCE dialogs provider") );
79 set_capability( "dialogs provider", 10 );
80 set_callbacks( OpenDialogs, Close );
83 HINSTANCE hInstance = 0;
85 #if !defined(__BUILTIN__)
86 extern "C" BOOL WINAPI
87 DllMain( HANDLE hModule, DWORD fdwReason, LPVOID lpReserved )
89 hInstance = (HINSTANCE)hModule;
94 /* Global variables used by _TOMB() / _FROMB() */
95 wchar_t pwsz_mbtow_wince[2048];
96 char psz_wtomb_wince[2048];
98 /*****************************************************************************
99 * Open: initialize interface
100 *****************************************************************************/
101 static int Open( vlc_object_t *p_this )
103 intf_thread_t *p_intf = (intf_thread_t *)p_this;
105 // Check if the application is running.
106 // If it's running then focus its window and bail out.
107 HWND hwndMain = FindWindow( _T("VLC WinCE"), _T("VLC media player") );
110 SetForegroundWindow( hwndMain );
114 // Allocate instance and initialize some members
115 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
116 if( p_intf->p_sys == NULL )
119 // Suscribe to messages bank
120 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
123 p_intf->p_sys->p_audio_menu = NULL;
124 p_intf->p_sys->p_video_menu = NULL;
125 p_intf->p_sys->p_navig_menu = NULL;
126 p_intf->p_sys->p_settings_menu = NULL;
128 p_intf->pf_run = Run;
129 p_intf->pf_show_dialog = NULL;
131 p_intf->p_sys->p_input = NULL;
132 p_intf->p_sys->b_playing = 0;
133 p_intf->p_sys->i_playing = -1;
134 p_intf->p_sys->b_slider_free = 1;
135 p_intf->p_sys->i_slider_pos = p_intf->p_sys->i_slider_oldpos = 0;
140 static int OpenDialogs( vlc_object_t *p_this )
142 intf_thread_t *p_intf = (intf_thread_t *)p_this;
143 int i_ret = Open( p_this );
145 p_intf->pf_show_dialog = ShowDialog;
150 /*****************************************************************************
151 * Close: destroy interface
152 *****************************************************************************/
153 static void Close( vlc_object_t *p_this )
155 intf_thread_t *p_intf = (intf_thread_t *)p_this;
156 intf_sys_t *p_sys = p_intf->p_sys;
160 vlc_object_release( p_sys->p_input );
163 MenuItemExt::ClearList( p_intf->p_sys->p_video_menu );
164 delete p_intf->p_sys->p_video_menu;
165 MenuItemExt::ClearList( p_intf->p_sys->p_audio_menu );
166 delete p_intf->p_sys->p_audio_menu;
167 MenuItemExt::ClearList( p_intf->p_sys->p_settings_menu );
168 delete p_intf->p_sys->p_settings_menu;
169 MenuItemExt::ClearList( p_intf->p_sys->p_navig_menu );
170 delete p_intf->p_sys->p_navig_menu;
172 if( p_intf->pf_show_dialog )
174 /* We must destroy the dialogs thread */
176 wxCommandEvent event( wxEVT_DIALOG, INTF_DIALOG_EXIT );
177 p_intf->p_sys->p_wxwindow->AddPendingEvent( event );
179 vlc_thread_join( p_intf );
182 // Unsuscribe to messages bank
183 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
186 free( p_intf->p_sys );
189 /*****************************************************************************
191 *****************************************************************************/
192 static void Run( intf_thread_t *p_intf )
194 if( p_intf->pf_show_dialog )
196 /* The module is used in dialog provider mode */
198 /* Create a new thread for the dialogs provider */
199 if( vlc_thread_create( p_intf, "WinCE Dialogs Thread",
200 MainLoop, 0, true ) )
202 msg_Err( p_intf, "cannot create WinCE Dialogs Thread" );
203 p_intf->pf_show_dialog = NULL;
208 int canc = vlc_savecancel();
209 /* The module is used in interface mode */
210 MainLoop( VLC_OBJECT(p_intf) );
211 vlc_restorecancel( canc );
215 static void* MainLoop( vlc_object_t * p_this )
217 intf_thread_t *p_intf = (intf_thread_t*)p_this;
220 int canc = vlc_savecancel ();
222 if( !hInstance ) hInstance = GetModuleHandle(NULL);
224 // Register window class
226 wc.style = CS_HREDRAW | CS_VREDRAW ;
227 wc.lpfnWndProc = (WNDPROC)CBaseWindow::BaseWndProc;
231 wc.hInstance = hInstance;
233 wc.hbrBackground = (HBRUSH)(COLOR_MENU+1);
234 wc.lpszMenuName = NULL;
235 wc.lpszClassName = _T("VLC WinCE");
236 RegisterClass( &wc );
239 /* Initialize OLE/COM */
243 if( !p_intf->pf_show_dialog )
245 /* The module is used in interface mode */
246 p_intf->p_sys->p_window = intf = new Interface( p_intf, 0, hInstance );
248 /* Create/Show the interface */
249 if( !intf->InitInstance() ) goto end;
252 /* Creates the dialogs provider */
253 p_intf->p_sys->p_window =
254 CreateDialogsProvider( p_intf, p_intf->pf_show_dialog ?
255 NULL : p_intf->p_sys->p_window, hInstance );
257 p_intf->p_sys->pf_show_dialog = ShowDialog;
259 /* OK, initialization is over */
260 vlc_thread_ready( p_intf );
263 while( GetMessage( &msg, NULL, 0, 0 ) > 0 )
265 TranslateMessage( &msg );
266 DispatchMessage( &msg );
273 /* Uninitialize OLE/COM */
276 vlc_restorecancel (canc);
280 /*****************************************************************************
281 * CBaseWindow Implementation
282 *****************************************************************************/
283 LRESULT CALLBACK CBaseWindow::BaseWndProc( HWND hwnd, UINT msg, WPARAM wParam,
288 // check to see if a copy of the 'this' pointer needs to be saved
289 if( msg == WM_CREATE )
291 p_obj = (CBaseWindow *)(((LPCREATESTRUCT)lParam)->lpCreateParams);
292 SetWindowLong( hwnd, GWL_USERDATA,
293 (LONG)((LPCREATESTRUCT)lParam)->lpCreateParams );
298 if( msg == WM_INITDIALOG )
300 p_obj = (CBaseWindow *)lParam;
301 SetWindowLong( hwnd, GWL_USERDATA, lParam );
305 // Retrieve the pointer
306 p_obj = (CBaseWindow *)GetWindowLong( hwnd, GWL_USERDATA );
308 if( !p_obj ) return DefWindowProc( hwnd, msg, wParam, lParam );
310 // Filter message through child classes
311 return p_obj->WndProc( hwnd, msg, wParam, lParam );
314 int CBaseWindow::CreateDialogBox( HWND hwnd, CBaseWindow *p_obj )
316 uint8_t p_buffer[sizeof(DLGTEMPLATE) + sizeof(WORD) * 4];
317 DLGTEMPLATE *p_dlg_template = (DLGTEMPLATE *)p_buffer;
318 memset( p_dlg_template, 0, sizeof(DLGTEMPLATE) + sizeof(WORD) * 4 );
320 // these values are arbitrary, they won't be used normally anyhow
321 p_dlg_template->x = 0; p_dlg_template->y = 0;
322 p_dlg_template->cx = 300; p_dlg_template->cy = 300;
323 p_dlg_template->style =
324 DS_MODALFRAME|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX;
326 return DialogBoxIndirectParam( GetModuleHandle(0), p_dlg_template, hwnd,
327 (DLGPROC)p_obj->BaseWndProc, (LPARAM)p_obj);
330 /*****************************************************************************
332 *****************************************************************************/
333 static void ShowDialog( intf_thread_t *p_intf, int i_dialog_event, int i_arg,
334 intf_dialog_args_t *p_arg )
336 SendMessage( p_intf->p_sys->p_window->GetHandle(), WM_CANCELMODE, 0, 0 );
337 if( i_dialog_event == INTF_DIALOG_POPUPMENU && i_arg == 0 ) return;
339 /* Hack to prevent popup events to be enqueued when
340 * one is already active */
342 if( i_dialog_event != INTF_DIALOG_POPUPMENU ||
343 !p_intf->p_sys->p_popup_menu )
346 SendMessage( p_intf->p_sys->p_window->GetHandle(),
347 WM_APP + i_dialog_event, (WPARAM)i_arg, (LPARAM)p_arg );