]> git.sesse.net Git - vlc/blob - modules/gui/skins/gtk2/gtk2_run.cpp
bc812af251538194616a436b52b8f9316034aadb
[vlc] / modules / gui / skins / gtk2 / gtk2_run.cpp
1 /*****************************************************************************
2  * gtk2_run.cpp:
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: gtk2_run.cpp,v 1.8 2003/04/15 20:42:04 karibu 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 #if !defined WIN32
26
27 //--- GTK2 ------------------------------------------------------------------
28 #include <glib.h>
29 #include <gdk/gdk.h>
30
31 //--- VLC -------------------------------------------------------------------
32 #include <vlc/intf.h>
33
34 //--- SKIN ------------------------------------------------------------------
35 #include "os_api.h"
36 #include "event.h"
37 #include "os_event.h"
38 #include "banks.h"
39 #include "window.h"
40 #include "os_window.h"
41 #include "theme.h"
42 #include "os_theme.h"
43 #include "skin_common.h"
44 #include "vlcproc.h"
45
46
47 //---------------------------------------------------------------------------
48 // Specific method
49 //---------------------------------------------------------------------------
50 bool IsVLCEvent( unsigned int msg );
51 int  SkinManage( intf_thread_t *p_intf );
52
53
54
55 //---------------------------------------------------------------------------
56 // REFRESH TIMER CALLBACK
57 //---------------------------------------------------------------------------
58 /*void CALLBACK RefreshTimer( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
59 {
60     intf_thread_t *p_intf = (intf_thread_t *)GetWindowLongPtr( hwnd,
61         GWLP_USERDATA );
62     SkinManage( p_intf );
63 }*/
64 //---------------------------------------------------------------------------
65
66 //---------------------------------------------------------------------------
67 // GTK2 interface
68 //---------------------------------------------------------------------------
69 void GTK2Proc( GdkEvent *event, gpointer data )
70 {
71     // Get pointer to thread info
72     unsigned int msg;
73     VlcProc *proc = (VlcProc *)data;
74     intf_thread_t *p_intf = proc->GetpIntf();
75     Event *evt;
76     list<Window *>::const_iterator win;
77     GdkWindow *gwnd = ((GdkEventAny *)event)->window;
78
79     // Create event to dispatch in windows
80     // Skin event
81     if( event->type == GDK_CLIENT_EVENT )
82     {
83         msg = ( (GdkEventClient *)event )->data.l[0];
84         evt = (Event *)new OSEvent( p_intf, 
85             ((GdkEventAny *)event)->window,
86             msg,
87             ( (GdkEventClient *)event )->data.l[1],
88             ( (GdkEventClient *)event )->data.l[2] );
89     }
90     // System event
91     else
92     {
93         msg = event->type;
94         evt = (Event *)new OSEvent( p_intf, 
95             ((GdkEventAny *)event)->window, msg, 0, (long)event );
96     }
97
98     if( IsVLCEvent( msg ) )
99     {
100         if( !proc->EventProc( evt ) )
101             return;      // Exit VLC !
102     }
103     else if( gwnd == NULL )
104     {
105         for( win = p_intf->p_sys->p_theme->WindowList.begin();
106              win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
107         {
108             (*win)->ProcessEvent( evt );
109         }
110     }
111     else
112     {
113         // Find window matching with gwnd
114         for( win = p_intf->p_sys->p_theme->WindowList.begin();
115              win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
116         {
117             // If it is the correct window
118             if( gwnd == ( (GTK2Window *)(*win) )->GetHandle() )
119             {
120                 // Send event and check if processed
121                 if( (*win)->ProcessEvent( evt ) )
122                 {
123                     delete (OSEvent *)evt;
124                     return;
125                 }
126                 else
127                 {
128                     break;
129                 }
130             }
131         }
132     }
133
134     delete (OSEvent *)evt;
135
136 #if 0
137     // If Window is parent window
138     if( hwnd == ( (GTK2Theme *)p_intf->p_sys->p_theme )->GetParentWindow() )
139     {
140         if( uMsg == WM_SYSCOMMAND )
141         {
142             if( (Event *)wParam != NULL )
143                 ( (Event *)wParam )->SendEvent();
144             return 0;
145         }
146         else if( uMsg == WM_RBUTTONDOWN && wParam == 42 &&
147                  lParam == WM_RBUTTONDOWN )
148         {
149             int x, y;
150             OSAPI_GetMousePos( x, y );
151             TrackPopupMenu(
152                 ( (GTK2Theme *)p_intf->p_sys->p_theme )->GetSysMenu(),
153                 0, x, y, 0, hwnd, NULL );
154         }
155     }
156
157
158     // If closing parent window
159     if( uMsg == WM_CLOSE )
160     {
161         OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
162         return 0;
163     }
164
165     // If hwnd does not match any window or message not processed
166     return DefWindowProc( hwnd, uMsg, wParam, lParam );
167 #endif
168 }
169 //---------------------------------------------------------------------------
170
171
172
173 //---------------------------------------------------------------------------
174 // GTK2 interface
175 //---------------------------------------------------------------------------
176 void OSRun( intf_thread_t *p_intf )
177 {
178     // Create VLC event object processing
179     VlcProc *proc = new VlcProc( p_intf );
180
181     gdk_event_handler_set( GTK2Proc, (gpointer)proc, NULL );
182
183     // Main event loop
184     GMainLoop *loop = g_main_loop_new( NULL, TRUE );
185     g_main_loop_run( loop );
186 }
187 //---------------------------------------------------------------------------
188 bool IsVLCEvent( unsigned int msg )
189 {
190     return( msg > VLC_MESSAGE && msg < VLC_WINDOW );
191 }
192 //---------------------------------------------------------------------------
193
194 #endif