1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: win32_run.cpp,v 1.13 2003/04/30 19:22:27 ipkiss Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
24 *****************************************************************************/
28 //--- GENERAL ---------------------------------------------------------------
34 //--- VLC -------------------------------------------------------------------
37 //--- SKIN ------------------------------------------------------------------
38 #include "../os_api.h"
39 #include "../src/event.h"
40 #include "../os_event.h"
41 #include "../src/banks.h"
42 #include "../src/window.h"
43 #include "../os_window.h"
44 #include "../src/theme.h"
45 #include "../os_theme.h"
46 #include "../src/skin_common.h"
47 #include "../src/vlcproc.h"
50 #include "../src/wxdialogs.h"
51 #include "share/vlc32x32.xpm" // include the graphic icon
54 //---------------------------------------------------------------------------
56 //---------------------------------------------------------------------------
57 bool IsVLCEvent( unsigned int msg );
58 int SkinManage( intf_thread_t *p_intf );
62 //---------------------------------------------------------------------------
63 // Local classes declarations.
64 //---------------------------------------------------------------------------
65 class Instance: public wxApp
69 Instance( intf_thread_t *_p_intf );
76 intf_thread_t *p_intf;
79 class ExitTimer: public wxTimer
82 ExitTimer( intf_thread_t *_p_intf );
87 intf_thread_t *p_intf;
91 //---------------------------------------------------------------------------
92 // Implementation of Instance class
93 //---------------------------------------------------------------------------
98 Instance::Instance( intf_thread_t *_p_intf )
104 IMPLEMENT_APP_NO_MAIN(Instance)
106 bool Instance::OnInit()
108 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
110 // Create all the dialog boxes
111 p_intf->p_sys->OpenDlg = new OpenDialog( p_intf, NULL, FILE_ACCESS );
112 p_intf->p_sys->MessagesDlg = new Messages( p_intf, NULL );
113 p_intf->p_sys->SoutDlg = new SoutDialog( p_intf, NULL );
114 p_intf->p_sys->PrefsDlg = new PrefsDialog( p_intf, NULL );
115 p_intf->p_sys->InfoDlg = new FileInfo( p_intf, NULL );
117 // Start a timer checking if we must exit the main loop
118 p_intf->p_sys->b_wx_die = 0;
119 p_intf->p_sys->p_kludgy_timer = new ExitTimer( p_intf );
120 p_intf->p_sys->p_kludgy_timer->Start( 100 );
122 // OK, initialization is over, now the other thread can go on working...
123 vlc_mutex_lock( &p_intf->p_sys->init_lock );
124 vlc_cond_signal( &p_intf->p_sys->init_cond );
125 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
130 int Instance::OnExit()
132 // Delete evertything
133 delete p_intf->p_sys->p_kludgy_timer;
134 delete p_intf->p_sys->InfoDlg;
135 delete p_intf->p_sys->PrefsDlg;
136 delete p_intf->p_sys->SoutDlg;
137 delete p_intf->p_sys->MessagesDlg;
138 delete p_intf->p_sys->OpenDlg;
139 delete p_intf->p_sys->p_icon;
145 //---------------------------------------------------------------------------
146 // Implementation of ExitTimer class
147 // This timer is only there to call wxApp::ExitMainLoop() from the wxWindows
148 // thread (otherwise we never exit from the wxEntry call).
149 //---------------------------------------------------------------------------
150 ExitTimer::ExitTimer( intf_thread_t *_p_intf ) : wxTimer()
155 void ExitTimer::Notify()
157 if( p_intf->p_sys->b_wx_die )
158 wxTheApp->ExitMainLoop();
162 //---------------------------------------------------------------------------
163 #if !defined(__BUILTIN__) && defined( WIN32 )
164 HINSTANCE hInstance = 0;
165 extern "C" BOOL WINAPI
166 DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
168 hInstance = (HINSTANCE)hModule;
174 //---------------------------------------------------------------------------
176 // We create all wxWindows dialogs in a separate thread because we don't want
177 // any interaction with our own message loop
178 //---------------------------------------------------------------------------
179 void SkinsDialogsThread( intf_thread_t *p_intf )
181 /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
182 wxTheApp = new Instance( p_intf );
185 #if !defined(__BUILTIN__)
186 wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW, TRUE );
188 wxEntry( GetModuleHandle( NULL ), NULL, NULL, SW_SHOW, TRUE );
191 wxEntry( 1, p_args );
199 //---------------------------------------------------------------------------
200 // Refresh Timer Callback
201 //---------------------------------------------------------------------------
202 void CALLBACK RefreshTimer( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
204 intf_thread_t *p_intf = (intf_thread_t *)GetWindowLongPtr( hwnd,
206 SkinManage( p_intf );
208 //---------------------------------------------------------------------------
212 //---------------------------------------------------------------------------
214 //---------------------------------------------------------------------------
215 void OSRun( intf_thread_t *p_intf )
217 VlcProc *Proc = new VlcProc( p_intf );
219 list<SkinWindow *>::const_iterator win;
224 // Create a new thread for wxWindows
225 if( vlc_thread_create( p_intf, "Skins Dialogs Thread", SkinsDialogsThread,
228 msg_Err( p_intf, "cannot create SkinsDialogsThread" );
229 // Don't even enter the main loop
232 vlc_mutex_lock( &p_intf->p_sys->init_lock );
233 vlc_cond_wait( &p_intf->p_sys->init_cond, &p_intf->p_sys->init_lock );
234 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
237 // Create refresh timer
238 SetTimer( ((OSTheme *)p_intf->p_sys->p_theme)->GetParentWindow(), 42, 200,
239 (TIMERPROC)RefreshTimer );
241 // Compute windows message list
242 while( GetMessage( &msg, NULL, 0, 0 ) )
245 for( win = p_intf->p_sys->p_theme->WindowList.begin();
246 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
248 if( msg.hwnd == NULL ||
249 msg.hwnd == ((Win32Window*)(*win))->GetHandle() )
254 if( win == p_intf->p_sys->p_theme->WindowList.end() )
256 // DispatchMessage( &msg );
257 // DefWindowProc( msg.hwnd, msg.message, msg.wParam, msg.lParam );
261 TranslateMessage( &msg );
264 ProcessEvent = (Event *)new OSEvent( p_intf, msg.hwnd, msg.message,
265 msg.wParam, msg.lParam );
267 /*****************************
268 * Process keyboard shortcuts *
269 *****************************/
270 if( msg.message == WM_KEYUP )
272 msg_Err( p_intf, "Key : %i (%i)", msg.wParam, KeyModifier );
274 if( msg.wParam == 17 )
276 else if( KeyModifier == 0 )
278 p_intf->p_sys->p_theme->EvtBank->TestShortcut(
282 else if( msg.message == WM_KEYDOWN )
285 if( msg.wParam == 17 )
287 else if( KeyModifier > 0 )
289 p_intf->p_sys->p_theme->EvtBank->TestShortcut(
290 msg.wParam, KeyModifier );
293 else if( msg.message == WM_SYSKEYDOWN )
296 if( msg.wParam == 18 )
299 else if( msg.message == WM_SYSKEYUP )
301 // If key is a system key
305 /************************
306 * Process timer message *
307 ************************/
308 else if( msg.message == WM_TIMER )
310 DispatchMessage( &msg );
313 /***********************
314 * VLC specific message *
315 ***********************/
316 else if( IsVLCEvent( msg.message ) )
318 if( !Proc->EventProc( ProcessEvent ) )
322 /**********************
323 * Broadcasted message *
324 **********************/
325 else if( msg.hwnd == NULL )
327 for( win = p_intf->p_sys->p_theme->WindowList.begin();
328 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
330 (*win)->ProcessEvent( ProcessEvent );
334 /***********************
335 * Process window event *
336 ***********************/
339 DispatchMessage( &msg );
343 ProcessEvent->DestructParameters();
344 delete (OSEvent *)ProcessEvent;
346 // Check if vlc is closing
351 // Tell wxWindows it's time to exit
352 p_intf->p_sys->b_wx_die = 1;
355 //---------------------------------------------------------------------------
356 bool IsVLCEvent( unsigned int msg )
358 return( msg > VLC_MESSAGE && msg < VLC_WINDOW );
360 //---------------------------------------------------------------------------