1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_run.cpp,v 1.4 2003/05/18 11:25:00 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 -------------------------------------------------------------
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"
57 //---------------------------------------------------------------------------
59 //---------------------------------------------------------------------------
60 bool IsVLCEvent( unsigned int msg );
61 int SkinManage( intf_thread_t *p_intf );
64 //---------------------------------------------------------------------------
65 // Local classes declarations.
66 //---------------------------------------------------------------------------
68 class Instance: public wxApp
72 Instance( intf_thread_t *_p_intf );
78 intf_thread_t *p_intf;
83 //---------------------------------------------------------------------------
85 //---------------------------------------------------------------------------
86 /*void GTK2Proc( GdkEvent *event, gpointer data )
88 // Get objects from data
89 CallBackObjects *obj = (CallBackObjects *)data;
90 VlcProc *proc = obj->Proc;
92 // Get pointer to thread info
93 intf_thread_t *p_intf = proc->GetpIntf();
98 list<SkinWindow *>::const_iterator win;
99 GdkWindow *gwnd = ((GdkEventAny *)event)->window;
101 // Create event to dispatch in windows
103 if( event->type == GDK_CLIENT_EVENT )
105 msg = ( (GdkEventClient *)event )->data.l[0];
106 evt = (Event *)new OSEvent( p_intf,
107 ((GdkEventAny *)event)->window,
109 ( (GdkEventClient *)event )->data.l[1],
110 ( (GdkEventClient *)event )->data.l[2] );
116 evt = (Event *)new OSEvent( p_intf,
117 ((GdkEventAny *)event)->window, msg, 0, (long)event );
120 // Process keyboard shortcuts
121 if( msg == GDK_KEY_PRESS )
125 if( ((GdkEventKey *)event)->state & GDK_MOD1_MASK )
130 else if( ((GdkEventKey *)event)->state & GDK_CONTROL_MASK )
134 int key = ((GdkEventKey *)event)->keyval;
135 // Translate into lower case
136 if( key >= 'a' && key <= 'z' )
140 if( KeyModifier > 0 )
141 p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );
145 else if( IsVLCEvent( msg ) )
147 if( !proc->EventProc( evt ) )
150 return; // Exit VLC !
153 else if( gwnd == NULL )
155 for( win = p_intf->p_sys->p_theme->WindowList.begin();
156 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
158 (*win)->ProcessEvent( evt );
163 // Find window matching with gwnd
164 for( win = p_intf->p_sys->p_theme->WindowList.begin();
165 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
167 // If it is the correct window
168 if( gwnd == ( (GTK2Window *)(*win) )->GetHandle() )
170 // Send event and check if processed
171 if( (*win)->ProcessEvent( evt ) )
173 delete (OSEvent *)evt;
184 evt->DestructParameters();
185 delete (OSEvent *)evt;
187 // Check if vlc is closing
190 gtk_main_do_event( event )
192 //---------------------------------------------------------------------------
194 //---------------------------------------------------------------------------
195 // REFRESH TIMER CALLBACK
196 //---------------------------------------------------------------------------
197 /*gboolean RefreshTimer( gpointer data )
199 intf_thread_t *p_intf = (intf_thread_t *)data;
200 SkinManage( p_intf );
203 //---------------------------------------------------------------------------
206 //---------------------------------------------------------------------------
207 // Implementation of Instance class
208 //---------------------------------------------------------------------------
210 Instance::Instance( )
214 Instance::Instance( intf_thread_t *_p_intf )
220 IMPLEMENT_APP_NO_MAIN(Instance)
222 bool Instance::OnInit()
224 // Set event callback. Yes, it's a big hack ;)
225 // gdk_event_handler_set( GTK2Proc, (gpointer)callbackobj, NULL );
227 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
228 p_intf->p_sys->OpenDlg = new OpenDialog( p_intf, NULL, FILE_ACCESS );
229 p_intf->p_sys->MessagesDlg = new Messages( p_intf, NULL );
230 p_intf->p_sys->SoutDlg = new SoutDialog( p_intf, NULL );
231 p_intf->p_sys->PrefsDlg = new PrefsDialog( p_intf, NULL );
232 p_intf->p_sys->InfoDlg = new FileInfo( p_intf, NULL );
235 // g_timeout_add( 200, (GSourceFunc)RefreshTimer, (gpointer)p_intf );
242 //---------------------------------------------------------------------------
243 // X11 event processing
244 //---------------------------------------------------------------------------
245 void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
248 list<SkinWindow *>::const_iterator win;
252 Window wnd = ((XAnyEvent *)event)->window;
254 // fprintf(stderr,"event %d %x\n", event->type, wnd);
256 // Create event to dispatch in windows
258 if( event->type == ClientMessage )
260 /* msg = ( (GdkEventClient *)event )->data.l[0];
261 evt = (Event *)new OSEvent( p_intf,
262 ((GdkEventAny *)event)->window,
264 ( (GdkEventClient *)event )->data.l[1],
265 ( (GdkEventClient *)event )->data.l[2] );*/
271 evt = (Event *)new OSEvent( p_intf,
272 ((XAnyEvent *)event)->window, msg, 0, (long)event );
275 // Process keyboard shortcuts
276 if( msg == KeyPress )
278 /* int KeyModifier = 0;
280 if( ((GdkEventKey *)event)->state & GDK_MOD1_MASK )
285 else if( ((GdkEventKey *)event)->state & GDK_CONTROL_MASK )
289 int key = ((GdkEventKey *)event)->keyval;
290 // Translate into lower case
291 if( key >= 'a' && key <= 'z' )
295 if( KeyModifier > 0 )
296 p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );*/
300 else if( IsVLCEvent( msg ) )
302 if( !proc->EventProc( evt ) )
305 return; // Exit VLC !
308 else if( wnd == NULL )
310 for( win = p_intf->p_sys->p_theme->WindowList.begin();
311 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
313 (*win)->ProcessEvent( evt );
318 // Find window matching with gwnd
319 for( win = p_intf->p_sys->p_theme->WindowList.begin();
320 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
322 // If it is the correct window
323 if( wnd == ( (X11Window *)(*win) )->GetHandle() )
325 // Send event and check if processed
326 if( (*win)->ProcessEvent( evt ) )
328 delete (OSEvent *)evt;
339 evt->DestructParameters();
340 delete (OSEvent *)evt;
342 // Check if vlc is closing
348 //---------------------------------------------------------------------------
350 //---------------------------------------------------------------------------
351 void OSRun( intf_thread_t *p_intf )
353 static char *p_args[] = { "" };
355 VlcProc *proc = new VlcProc( p_intf );
357 /* wxTheApp = new Instance( p_intf, callbackobj );
358 wxEntry( 1, p_args );*/
360 Display *display = ((OSTheme *)p_intf->p_sys->p_theme)->GetDisplay();
366 XNextEvent( display, event );
368 ProcessEvent( p_intf, proc, event );
371 SkinManage( p_intf );
375 //---------------------------------------------------------------------------
376 bool IsVLCEvent( unsigned int msg )
378 return( msg > VLC_MESSAGE && msg < VLC_WINDOW );
380 //---------------------------------------------------------------------------