1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_run.cpp,v 1.7 2003/05/24 20:54:27 gbazin Exp $
7 * Authors: Cyril Deguet <asmax@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 *****************************************************************************/
27 //--- X11 -------------------------------------------------------------------
30 //--- WWWINDOWS -------------------------------------------------------------
35 //--- VLC -------------------------------------------------------------------
38 //--- SKIN ------------------------------------------------------------------
39 #include "../os_api.h"
40 #include "../src/event.h"
41 #include "../os_event.h"
42 #include "../src/banks.h"
43 #include "../src/window.h"
44 #include "../os_window.h"
45 #include "../src/theme.h"
46 #include "../os_theme.h"
47 #include "../src/skin_common.h"
48 #include "../src/vlcproc.h"
50 #include "../../wxwindows/wxwindows.h"
53 // include the icon graphic
54 #include "share/vlc32x32.xpm"
59 //---------------------------------------------------------------------------
61 //---------------------------------------------------------------------------
62 bool IsVLCEvent( unsigned int msg );
63 int SkinManage( intf_thread_t *p_intf );
66 //---------------------------------------------------------------------------
67 // Local classes declarations.
68 //---------------------------------------------------------------------------
70 class Instance: public wxApp
74 Instance( intf_thread_t *_p_intf );
80 intf_thread_t *p_intf;
85 //---------------------------------------------------------------------------
87 //---------------------------------------------------------------------------
88 /*void GTK2Proc( GdkEvent *event, gpointer data )
90 // Get objects from data
91 CallBackObjects *obj = (CallBackObjects *)data;
92 VlcProc *proc = obj->Proc;
94 // Get pointer to thread info
95 intf_thread_t *p_intf = proc->GetpIntf();
100 list<SkinWindow *>::const_iterator win;
101 GdkWindow *gwnd = ((GdkEventAny *)event)->window;
103 // Create event to dispatch in windows
105 if( event->type == GDK_CLIENT_EVENT )
107 msg = ( (GdkEventClient *)event )->data.l[0];
108 evt = (Event *)new OSEvent( p_intf,
109 ((GdkEventAny *)event)->window,
111 ( (GdkEventClient *)event )->data.l[1],
112 ( (GdkEventClient *)event )->data.l[2] );
118 evt = (Event *)new OSEvent( p_intf,
119 ((GdkEventAny *)event)->window, msg, 0, (long)event );
122 // Process keyboard shortcuts
123 if( msg == GDK_KEY_PRESS )
127 if( ((GdkEventKey *)event)->state & GDK_MOD1_MASK )
132 else if( ((GdkEventKey *)event)->state & GDK_CONTROL_MASK )
136 int key = ((GdkEventKey *)event)->keyval;
137 // Translate into lower case
138 if( key >= 'a' && key <= 'z' )
142 if( KeyModifier > 0 )
143 p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );
147 else if( IsVLCEvent( msg ) )
149 if( !proc->EventProc( evt ) )
152 return; // Exit VLC !
155 else if( gwnd == NULL )
157 for( win = p_intf->p_sys->p_theme->WindowList.begin();
158 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
160 (*win)->ProcessEvent( evt );
165 // Find window matching with gwnd
166 for( win = p_intf->p_sys->p_theme->WindowList.begin();
167 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
169 // If it is the correct window
170 if( gwnd == ( (GTK2Window *)(*win) )->GetHandle() )
172 // Send event and check if processed
173 if( (*win)->ProcessEvent( evt ) )
175 delete (OSEvent *)evt;
186 evt->DestructParameters();
187 delete (OSEvent *)evt;
189 // Check if vlc is closing
192 gtk_main_do_event( event )
194 //---------------------------------------------------------------------------
197 //---------------------------------------------------------------------------
198 // Implementation of Instance class
199 //---------------------------------------------------------------------------
201 Instance::Instance( )
205 Instance::Instance( intf_thread_t *_p_intf )
211 IMPLEMENT_APP_NO_MAIN(Instance)
213 bool Instance::OnInit()
215 // Set event callback. Yes, it's a big hack ;)
216 // gdk_event_handler_set( GTK2Proc, (gpointer)callbackobj, NULL );
218 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
219 p_intf->p_sys->OpenDlg = new OpenDialog( p_intf, NULL, FILE_ACCESS );
220 p_intf->p_sys->MessagesDlg = new Messages( p_intf, NULL );
221 p_intf->p_sys->SoutDlg = new SoutDialog( p_intf, NULL );
222 p_intf->p_sys->PrefsDlg = new PrefsDialog( p_intf, NULL );
223 p_intf->p_sys->InfoDlg = new FileInfo( p_intf, NULL );
226 // g_timeout_add( 200, (GSourceFunc)RefreshTimer, (gpointer)p_intf );
233 //---------------------------------------------------------------------------
234 // X11 event processing
235 //---------------------------------------------------------------------------
236 void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
239 list<SkinWindow *>::const_iterator win;
243 Window wnd = ((XAnyEvent *)event)->window;
245 // fprintf(stderr,"event %d %x\n", event->type, wnd);
247 // Create event to dispatch in windows
249 if( event->type == ClientMessage )
251 msg = ( (XClientMessageEvent *)event )->data.l[0];
252 evt = (Event *)new OSEvent( p_intf,
253 ((XAnyEvent *)event)->window, msg,
254 ( (XClientMessageEvent *)event )->data.l[1],
255 ( (XClientMessageEvent *)event )->data.l[2] );
261 evt = (Event *)new OSEvent( p_intf,
262 ((XAnyEvent *)event)->window, msg, 0, (long)event );
265 // Process keyboard shortcuts
266 if( msg == KeyPress )
268 /* int KeyModifier = 0;
270 if( ((GdkEventKey *)event)->state & GDK_MOD1_MASK )
275 else if( ((GdkEventKey *)event)->state & GDK_CONTROL_MASK )
279 int key = ((GdkEventKey *)event)->keyval;
280 // Translate into lower case
281 if( key >= 'a' && key <= 'z' )
285 if( KeyModifier > 0 )
286 p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );*/
290 else if( IsVLCEvent( msg ) )
292 if( !proc->EventProc( evt ) )
295 return; // Exit VLC !
298 else if( wnd == NULL )
300 for( win = p_intf->p_sys->p_theme->WindowList.begin();
301 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
303 (*win)->ProcessEvent( evt );
308 // Find window matching with gwnd
309 for( win = p_intf->p_sys->p_theme->WindowList.begin();
310 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
312 // If it is the correct window
313 if( wnd == ( (X11Window *)(*win) )->GetHandle() )
315 // Send event and check if processed
316 if( (*win)->ProcessEvent( evt ) )
318 delete (OSEvent *)evt;
329 evt->DestructParameters();
330 delete (OSEvent *)evt;
332 // Check if vlc is closing
338 //---------------------------------------------------------------------------
340 //---------------------------------------------------------------------------
341 void OSRun( intf_thread_t *p_intf )
343 static char *p_args[] = { "" };
345 VlcProc *proc = new VlcProc( p_intf );
348 wxTheApp = new Instance( p_intf );
349 wxEntry( 1, p_args );
352 Display *display = ((OSTheme *)p_intf->p_sys->p_theme)->GetDisplay();
359 while( XPending( display ) > 0 )
361 XNextEvent( display, &event );
362 ProcessEvent( p_intf, proc, &event );
368 SkinManage( p_intf ); // Call every 100 ms
373 //---------------------------------------------------------------------------
374 bool IsVLCEvent( unsigned int msg )
376 return( msg > VLC_MESSAGE && msg < VLC_WINDOW );
378 //---------------------------------------------------------------------------