1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_run.cpp,v 1.3 2003/05/13 20:36:29 asmax 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 -------------------------------------------------------------
33 //--- VLC -------------------------------------------------------------------
36 //--- SKIN ------------------------------------------------------------------
37 #include "../os_api.h"
38 #include "../src/event.h"
39 #include "../os_event.h"
40 #include "../src/banks.h"
41 #include "../src/window.h"
42 #include "../os_window.h"
43 #include "../src/theme.h"
44 #include "../os_theme.h"
45 #include "../src/skin_common.h"
46 #include "../src/vlcproc.h"
47 #include "../../wxwindows/wxwindows.h"
49 // include the icon graphic
50 #include "share/vlc32x32.xpm"
53 //---------------------------------------------------------------------------
55 //---------------------------------------------------------------------------
56 bool IsVLCEvent( unsigned int msg );
57 int SkinManage( intf_thread_t *p_intf );
60 //---------------------------------------------------------------------------
61 // Local classes declarations.
62 //---------------------------------------------------------------------------
63 class Instance: public wxApp
67 Instance( intf_thread_t *_p_intf );
73 intf_thread_t *p_intf;
77 //---------------------------------------------------------------------------
79 //---------------------------------------------------------------------------
80 /*void GTK2Proc( GdkEvent *event, gpointer data )
82 // Get objects from data
83 CallBackObjects *obj = (CallBackObjects *)data;
84 VlcProc *proc = obj->Proc;
86 // Get pointer to thread info
87 intf_thread_t *p_intf = proc->GetpIntf();
92 list<SkinWindow *>::const_iterator win;
93 GdkWindow *gwnd = ((GdkEventAny *)event)->window;
95 // Create event to dispatch in windows
97 if( event->type == GDK_CLIENT_EVENT )
99 msg = ( (GdkEventClient *)event )->data.l[0];
100 evt = (Event *)new OSEvent( p_intf,
101 ((GdkEventAny *)event)->window,
103 ( (GdkEventClient *)event )->data.l[1],
104 ( (GdkEventClient *)event )->data.l[2] );
110 evt = (Event *)new OSEvent( p_intf,
111 ((GdkEventAny *)event)->window, msg, 0, (long)event );
114 // Process keyboard shortcuts
115 if( msg == GDK_KEY_PRESS )
119 if( ((GdkEventKey *)event)->state & GDK_MOD1_MASK )
124 else if( ((GdkEventKey *)event)->state & GDK_CONTROL_MASK )
128 int key = ((GdkEventKey *)event)->keyval;
129 // Translate into lower case
130 if( key >= 'a' && key <= 'z' )
134 if( KeyModifier > 0 )
135 p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );
139 else if( IsVLCEvent( msg ) )
141 if( !proc->EventProc( evt ) )
144 return; // Exit VLC !
147 else if( gwnd == NULL )
149 for( win = p_intf->p_sys->p_theme->WindowList.begin();
150 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
152 (*win)->ProcessEvent( evt );
157 // Find window matching with gwnd
158 for( win = p_intf->p_sys->p_theme->WindowList.begin();
159 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
161 // If it is the correct window
162 if( gwnd == ( (GTK2Window *)(*win) )->GetHandle() )
164 // Send event and check if processed
165 if( (*win)->ProcessEvent( evt ) )
167 delete (OSEvent *)evt;
178 evt->DestructParameters();
179 delete (OSEvent *)evt;
181 // Check if vlc is closing
184 gtk_main_do_event( event )
186 //---------------------------------------------------------------------------
188 //---------------------------------------------------------------------------
189 // REFRESH TIMER CALLBACK
190 //---------------------------------------------------------------------------
191 /*gboolean RefreshTimer( gpointer data )
193 intf_thread_t *p_intf = (intf_thread_t *)data;
194 SkinManage( p_intf );
197 //---------------------------------------------------------------------------
200 //---------------------------------------------------------------------------
201 // Implementation of Instance class
202 //---------------------------------------------------------------------------
203 Instance::Instance( )
207 Instance::Instance( intf_thread_t *_p_intf )
213 IMPLEMENT_APP_NO_MAIN(Instance)
215 bool Instance::OnInit()
217 // Set event callback. Yes, it's a big hack ;)
218 // gdk_event_handler_set( GTK2Proc, (gpointer)callbackobj, NULL );
220 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
221 p_intf->p_sys->OpenDlg = new OpenDialog( p_intf, NULL, FILE_ACCESS );
222 p_intf->p_sys->MessagesDlg = new Messages( p_intf, NULL );
223 p_intf->p_sys->SoutDlg = new SoutDialog( p_intf, NULL );
224 p_intf->p_sys->PrefsDlg = new PrefsDialog( p_intf, NULL );
225 p_intf->p_sys->InfoDlg = new FileInfo( p_intf, NULL );
228 // g_timeout_add( 200, (GSourceFunc)RefreshTimer, (gpointer)p_intf );
235 //---------------------------------------------------------------------------
236 // X11 event processing
237 //---------------------------------------------------------------------------
238 void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
241 list<SkinWindow *>::const_iterator win;
245 Window wnd = ((XAnyEvent *)event)->window;
247 fprintf(stderr,"event %d %x\n", event->type, wnd);
249 // Create event to dispatch in windows
251 if( event->type == ClientMessage )
253 /* msg = ( (GdkEventClient *)event )->data.l[0];
254 evt = (Event *)new OSEvent( p_intf,
255 ((GdkEventAny *)event)->window,
257 ( (GdkEventClient *)event )->data.l[1],
258 ( (GdkEventClient *)event )->data.l[2] );*/
264 evt = (Event *)new OSEvent( p_intf,
265 ((XAnyEvent *)event)->window, msg, 0, (long)event );
268 // Process keyboard shortcuts
269 if( msg == KeyPress )
271 /* int KeyModifier = 0;
273 if( ((GdkEventKey *)event)->state & GDK_MOD1_MASK )
278 else if( ((GdkEventKey *)event)->state & GDK_CONTROL_MASK )
282 int key = ((GdkEventKey *)event)->keyval;
283 // Translate into lower case
284 if( key >= 'a' && key <= 'z' )
288 if( KeyModifier > 0 )
289 p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );*/
293 else if( IsVLCEvent( msg ) )
295 if( !proc->EventProc( evt ) )
298 return; // Exit VLC !
301 else if( wnd == NULL )
303 for( win = p_intf->p_sys->p_theme->WindowList.begin();
304 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
306 (*win)->ProcessEvent( evt );
311 // Find window matching with gwnd
312 for( win = p_intf->p_sys->p_theme->WindowList.begin();
313 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
315 // If it is the correct window
316 if( wnd == ( (X11Window *)(*win) )->GetHandle() )
318 // Send event and check if processed
319 if( (*win)->ProcessEvent( evt ) )
321 delete (OSEvent *)evt;
332 evt->DestructParameters();
333 delete (OSEvent *)evt;
335 // Check if vlc is closing
341 //---------------------------------------------------------------------------
343 //---------------------------------------------------------------------------
344 void OSRun( intf_thread_t *p_intf )
346 static char *p_args[] = { "" };
348 VlcProc *proc = new VlcProc( p_intf );
350 /* wxTheApp = new Instance( p_intf, callbackobj );
351 wxEntry( 1, p_args );*/
353 Display *display = ((OSTheme *)p_intf->p_sys->p_theme)->GetDisplay();
359 XNextEvent( display, event );
361 ProcessEvent( p_intf, proc, event );
365 //---------------------------------------------------------------------------
366 bool IsVLCEvent( unsigned int msg )
368 return( msg > VLC_MESSAGE && msg < VLC_WINDOW );
370 //---------------------------------------------------------------------------