]> git.sesse.net Git - vlc/blob - modules/gui/skins/x11/x11_run.cpp
* first BMP loader for X11 skins : it can only handle 24bbp uncompressed
[vlc] / modules / gui / skins / x11 / x11_run.cpp
1 /*****************************************************************************
2  * x11_run.cpp:
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: x11_run.cpp,v 1.4 2003/05/18 11:25:00 asmax Exp $
6  *
7  * Authors: Cyril Deguet     <asmax@videolan.org>
8  *
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.
13  *
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.
18  *
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,
22  * USA.
23  *****************************************************************************/
24
25 #ifdef X11_SKINS
26
27 //--- X11 -------------------------------------------------------------------
28 #include <X11/Xlib.h>
29
30 //--- WWWINDOWS -------------------------------------------------------------
31 #ifndef BASIC_SKINS
32 #include <wx/wx.h>
33 #endif
34
35 //--- VLC -------------------------------------------------------------------
36 #include <vlc/intf.h>
37
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"
49 #ifndef BASIC_SKINS
50 #include "../../wxwindows/wxwindows.h"
51 #endif
52
53 // include the icon graphic
54 #include "share/vlc32x32.xpm"
55
56
57 //---------------------------------------------------------------------------
58 // Specific method
59 //---------------------------------------------------------------------------
60 bool IsVLCEvent( unsigned int msg );
61 int  SkinManage( intf_thread_t *p_intf );
62
63
64 //---------------------------------------------------------------------------
65 // Local classes declarations.
66 //---------------------------------------------------------------------------
67 #ifndef BASIC_SKINS
68 class Instance: public wxApp
69 {
70 public:
71     Instance();
72     Instance( intf_thread_t *_p_intf );
73
74     bool OnInit();
75     OpenDialog *open;
76
77 private:
78     intf_thread_t *p_intf;
79 };
80 #endif
81
82
83 //---------------------------------------------------------------------------
84 // GTK2 interface
85 //---------------------------------------------------------------------------
86 /*void GTK2Proc( GdkEvent *event, gpointer data )
87 {
88     // Get objects from data
89     CallBackObjects *obj = (CallBackObjects *)data;
90     VlcProc *proc        = obj->Proc;
91
92     // Get pointer to thread info
93     intf_thread_t *p_intf = proc->GetpIntf();
94
95     // Variables
96     unsigned int msg;
97     Event *evt;
98     list<SkinWindow *>::const_iterator win;
99     GdkWindow *gwnd = ((GdkEventAny *)event)->window;
100
101     // Create event to dispatch in windows
102     // Skin event
103     if( event->type == GDK_CLIENT_EVENT )
104     {
105         msg = ( (GdkEventClient *)event )->data.l[0];
106         evt = (Event *)new OSEvent( p_intf, 
107             ((GdkEventAny *)event)->window,
108             msg,
109             ( (GdkEventClient *)event )->data.l[1],
110             ( (GdkEventClient *)event )->data.l[2] );
111     }
112     // System event
113     else
114     {
115         msg = event->type;
116         evt = (Event *)new OSEvent( p_intf,
117             ((GdkEventAny *)event)->window, msg, 0, (long)event );
118     }
119
120     // Process keyboard shortcuts
121     if( msg == GDK_KEY_PRESS )
122     {
123         int KeyModifier = 0;
124         // If key is ALT
125         if( ((GdkEventKey *)event)->state & GDK_MOD1_MASK )
126         {
127             KeyModifier = 1;
128         }
129         // If key is CTRL
130         else if( ((GdkEventKey *)event)->state & GDK_CONTROL_MASK )
131         {
132             KeyModifier = 2;
133         }
134         int key = ((GdkEventKey *)event)->keyval;
135         // Translate into lower case
136         if( key >= 'a' && key <= 'z' )
137         {
138             key -= ('a' - 'A');
139         }
140         if( KeyModifier > 0 )
141             p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );
142     }
143
144     // Send event
145     else if( IsVLCEvent( msg ) )
146     {
147         if( !proc->EventProc( evt ) )
148         {
149             wxExit();
150             return;      // Exit VLC !
151         }
152     }
153     else if( gwnd == NULL )
154     {
155         for( win = p_intf->p_sys->p_theme->WindowList.begin();
156              win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
157         {
158             (*win)->ProcessEvent( evt );
159         }
160     }
161     else
162     {
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++ )
166         {
167             // If it is the correct window
168             if( gwnd == ( (GTK2Window *)(*win) )->GetHandle() )
169             {
170                 // Send event and check if processed
171                 if( (*win)->ProcessEvent( evt ) )
172                 {
173                     delete (OSEvent *)evt;
174                     return;
175                 }
176                 else
177                 {
178                     break;
179                 }
180             }
181         }
182     }
183
184     evt->DestructParameters();
185     delete (OSEvent *)evt;
186
187     // Check if vlc is closing
188     proc->IsClosing();
189
190     gtk_main_do_event( event )
191 }*/
192 //---------------------------------------------------------------------------
193
194 //---------------------------------------------------------------------------
195 // REFRESH TIMER CALLBACK
196 //---------------------------------------------------------------------------
197 /*gboolean RefreshTimer( gpointer data )
198 {
199     intf_thread_t *p_intf = (intf_thread_t *)data;
200     SkinManage( p_intf );
201     return true;
202 }*/
203 //---------------------------------------------------------------------------
204
205
206 //---------------------------------------------------------------------------
207 // Implementation of Instance class
208 //---------------------------------------------------------------------------
209 #ifndef BASIC_SKINS
210 Instance::Instance( )
211 {
212 }
213
214 Instance::Instance( intf_thread_t *_p_intf )
215 {
216     // Initialization
217     p_intf = _p_intf;
218 }
219
220 IMPLEMENT_APP_NO_MAIN(Instance)
221
222 bool Instance::OnInit()
223 {
224     // Set event callback. Yes, it's a big hack ;)
225 //    gdk_event_handler_set( GTK2Proc, (gpointer)callbackobj, NULL );
226
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 );
233     
234     // Add timer
235 //    g_timeout_add( 200, (GSourceFunc)RefreshTimer, (gpointer)p_intf );
236
237     return TRUE;
238 }
239 #endif
240
241
242 //---------------------------------------------------------------------------
243 // X11 event processing
244 //---------------------------------------------------------------------------
245 void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
246 {
247     // Variables
248     list<SkinWindow *>::const_iterator win;
249     unsigned int msg;
250     Event *evt;
251
252     Window wnd = ((XAnyEvent *)event)->window;
253     
254 //    fprintf(stderr,"event %d %x\n", event->type, wnd);
255
256     // Create event to dispatch in windows
257     // Skin event
258     if( event->type == ClientMessage )
259     {
260 /*        msg = ( (GdkEventClient *)event )->data.l[0];
261         evt = (Event *)new OSEvent( p_intf, 
262             ((GdkEventAny *)event)->window,
263             msg,
264             ( (GdkEventClient *)event )->data.l[1],
265             ( (GdkEventClient *)event )->data.l[2] );*/
266     }
267     // System event
268     else
269     {
270         msg = event->type;
271         evt = (Event *)new OSEvent( p_intf,
272             ((XAnyEvent *)event)->window, msg, 0, (long)event );
273     }
274
275     // Process keyboard shortcuts
276     if( msg == KeyPress )
277     {
278 /*        int KeyModifier = 0;
279         // If key is ALT
280         if( ((GdkEventKey *)event)->state & GDK_MOD1_MASK )
281         {
282             KeyModifier = 1;
283         }
284         // If key is CTRL
285         else if( ((GdkEventKey *)event)->state & GDK_CONTROL_MASK )
286         {
287             KeyModifier = 2;
288         }
289         int key = ((GdkEventKey *)event)->keyval;
290         // Translate into lower case
291         if( key >= 'a' && key <= 'z' )
292         {
293             key -= ('a' - 'A');
294         }
295         if( KeyModifier > 0 )
296             p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );*/
297     }
298
299     // Send event
300     else if( IsVLCEvent( msg ) )
301     {
302         if( !proc->EventProc( evt ) )
303         {
304 //            wxExit();
305             return;      // Exit VLC !
306         }
307     }
308     else if( wnd == NULL )
309     {
310         for( win = p_intf->p_sys->p_theme->WindowList.begin();
311              win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
312         {
313             (*win)->ProcessEvent( evt );
314         }
315     }
316     else
317     {
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++ )
321         {
322             // If it is the correct window
323             if( wnd == ( (X11Window *)(*win) )->GetHandle() )
324             {
325                 // Send event and check if processed
326                 if( (*win)->ProcessEvent( evt ) )
327                 {
328                     delete (OSEvent *)evt;
329                     return;
330                 }
331                 else
332                 {
333                     break;
334                 }
335             }
336         }
337     }
338
339     evt->DestructParameters();
340     delete (OSEvent *)evt;
341
342 // Check if vlc is closing
343     proc->IsClosing();
344
345 }
346
347
348 //---------------------------------------------------------------------------
349 // X11 interface
350 //---------------------------------------------------------------------------
351 void OSRun( intf_thread_t *p_intf )
352 {
353     static char  *p_args[] = { "" };
354
355     VlcProc *proc = new VlcProc( p_intf );
356     
357 /*    wxTheApp = new Instance( p_intf, callbackobj );
358     wxEntry( 1, p_args );*/
359
360     Display *display = ((OSTheme *)p_intf->p_sys->p_theme)->GetDisplay();
361     
362     // Main event loop
363     while( 1 )
364     {
365         XEvent *event;
366         XNextEvent( display, event );
367         
368         ProcessEvent( p_intf, proc, event );
369
370 // kludge: add timer
371         SkinManage( p_intf );
372     }
373     
374 }
375 //---------------------------------------------------------------------------
376 bool IsVLCEvent( unsigned int msg )
377 {
378     return( msg > VLC_MESSAGE && msg < VLC_WINDOW );
379 }
380 //---------------------------------------------------------------------------
381
382 #endif