* added preferences, file info and stream output dialogs to the skins
[vlc.git] / 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.15 2003/04/21 00:54:26 ipkiss 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 #include <gtk/gtk.h>
31
32 //--- WWWINDOWS -------------------------------------------------------------
33 #include <wx/wx.h>
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 #include "../src/wxdialogs.h"
50
51 // include the icon graphic
52 #include "share/vlc32x32.xpm"
53
54 //---------------------------------------------------------------------------
55 class CallBackObjects
56 {
57     public:
58         VlcProc *Proc;
59         GMainLoop *Loop;
60 };
61
62 //---------------------------------------------------------------------------
63 // Specific method
64 //---------------------------------------------------------------------------
65 bool IsVLCEvent( unsigned int msg );
66 int  SkinManage( intf_thread_t *p_intf );
67
68
69 //---------------------------------------------------------------------------
70 // Local classes declarations.
71 //---------------------------------------------------------------------------
72 class Instance: public wxApp
73 {
74 public:
75     Instance();
76     Instance( intf_thread_t *_p_intf, CallBackObjects *callback );
77
78     bool OnInit();
79     OpenDialog *open;
80
81 private:
82     intf_thread_t *p_intf;
83     CallBackObjects *callbackobj;
84 };
85
86
87 //---------------------------------------------------------------------------
88 // GTK2 interface
89 //---------------------------------------------------------------------------
90 void GTK2Proc( GdkEvent *event, gpointer data )
91 {
92     // Get objects from data
93     CallBackObjects *obj = (CallBackObjects *)data;
94     VlcProc *proc        = obj->Proc;
95
96     // Get pointer to thread info
97     intf_thread_t *p_intf = proc->GetpIntf();
98
99     // Variables
100     unsigned int msg;
101     Event *evt;
102     list<Window *>::const_iterator win;
103     GdkWindow *gwnd = ((GdkEventAny *)event)->window;
104
105     // Create event to dispatch in windows
106     // Skin event
107     if( event->type == GDK_CLIENT_EVENT )
108     {
109         msg = ( (GdkEventClient *)event )->data.l[0];
110         evt = (Event *)new OSEvent( p_intf, 
111             ((GdkEventAny *)event)->window,
112             msg,
113             ( (GdkEventClient *)event )->data.l[1],
114             ( (GdkEventClient *)event )->data.l[2] );
115     }
116     // System event
117     else
118     {
119         msg = event->type;
120         evt = (Event *)new OSEvent( p_intf,
121             ((GdkEventAny *)event)->window, msg, 0, (long)event );
122     }
123
124     // Send event
125     if( IsVLCEvent( msg ) )
126     {
127         if( !proc->EventProc( evt ) )
128         {
129             fprintf( stderr, "Quit\n" );
130             wxExit();
131             return;      // Exit VLC !
132         }
133     }
134     else if( gwnd == NULL )
135     {
136         for( win = p_intf->p_sys->p_theme->WindowList.begin();
137              win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
138         {
139             (*win)->ProcessEvent( evt );
140         }
141     }
142     else
143     {
144         // Find window matching with gwnd
145         for( win = p_intf->p_sys->p_theme->WindowList.begin();
146              win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
147         {
148             // If it is the correct window
149             if( gwnd == ( (GTK2Window *)(*win) )->GetHandle() )
150             {
151                 // Send event and check if processed
152                 if( (*win)->ProcessEvent( evt ) )
153                 {
154                     delete (OSEvent *)evt;
155                     return;
156                 }
157                 else
158                 {
159                     break;
160                 }
161             }
162         }
163     }
164
165     evt->DestructParameters();
166     delete (OSEvent *)evt;
167
168     // Check if vlc is closing
169     proc->IsClosing();
170
171 #if 0
172     // If Window is parent window
173     if( hwnd == ( (GTK2Theme *)p_intf->p_sys->p_theme )->GetParentWindow() )
174     {
175         if( uMsg == WM_SYSCOMMAND )
176         {
177             if( (Event *)wParam != NULL )
178                 ( (Event *)wParam )->SendEvent();
179             return 0;
180         }
181         else if( uMsg == WM_RBUTTONDOWN && wParam == 42 &&
182                  lParam == WM_RBUTTONDOWN )
183         {
184             int x, y;
185             OSAPI_GetMousePos( x, y );
186             TrackPopupMenu(
187                 ( (GTK2Theme *)p_intf->p_sys->p_theme )->GetSysMenu(),
188                 0, x, y, 0, hwnd, NULL );
189         }
190     }
191
192
193     // If closing parent window
194     if( uMsg == WM_CLOSE )
195     {
196         OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
197         return 0;
198     }
199
200     // If hwnd does not match any window or message not processed
201     return DefWindowProc( hwnd, uMsg, wParam, lParam );
202 #endif
203     gtk_main_do_event( event );
204
205 }
206 //---------------------------------------------------------------------------
207
208
209 //---------------------------------------------------------------------------
210 // Implementation of Instance class
211 //---------------------------------------------------------------------------
212 Instance::Instance( )
213 {
214 }
215
216 Instance::Instance( intf_thread_t *_p_intf, CallBackObjects *callback )
217 {
218     // Initialization
219     p_intf = _p_intf;
220     callbackobj = callback;
221 }
222
223 IMPLEMENT_APP_NO_MAIN(Instance)
224
225 bool Instance::OnInit()
226 {
227     // Set event callback. Yes, it's a big hack ;)
228     gdk_event_handler_set( GTK2Proc, (gpointer)callbackobj, NULL );
229
230     p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
231     p_intf->p_sys->OpenDlg = new OpenDialog( p_intf, NULL, FILE_ACCESS );
232     p_intf->p_sys->MessagesDlg = new Messages( p_intf, NULL );
233     p_intf->p_sys->SoutDlg = new SoutDialog( p_intf, NULL );
234     p_intf->p_sys->PrefsDlg = new PrefsDialog( p_intf, NULL );
235     p_intf->p_sys->InfoDlg = new FileInfo( p_intf, NULL );
236     return TRUE;
237 }
238
239
240
241 //---------------------------------------------------------------------------
242 // REFRESH TIMER CALLBACK
243 //---------------------------------------------------------------------------
244 gboolean RefreshTimer( gpointer data )
245 {
246     intf_thread_t *p_intf = (intf_thread_t *)data;
247     SkinManage( p_intf );
248     return true;
249 }
250 //---------------------------------------------------------------------------
251
252
253 //---------------------------------------------------------------------------
254 // GTK2 interface
255 //---------------------------------------------------------------------------
256 void OSRun( intf_thread_t *p_intf )
257 {
258     static char  *p_args[] = { "" };
259
260     // Create VLC event object processing
261     CallBackObjects *callbackobj = new CallBackObjects();
262     callbackobj->Proc = new VlcProc( p_intf );
263
264     wxTheApp = new Instance( p_intf, callbackobj );
265
266     // Add timer
267     g_timeout_add( 200, (GSourceFunc)RefreshTimer, (gpointer)p_intf );
268     
269     wxEntry( 1, p_args );
270     
271     delete callbackobj;
272 }
273 //---------------------------------------------------------------------------
274 bool IsVLCEvent( unsigned int msg )
275 {
276     return( msg > VLC_MESSAGE && msg < VLC_WINDOW );
277 }
278 //---------------------------------------------------------------------------
279
280 #endif