]> git.sesse.net Git - vlc/blob - modules/gui/skins/gtk2/gtk2_theme.cpp
* something will be visible soon, be patient...
[vlc] / modules / gui / skins / gtk2 / gtk2_theme.cpp
1 /*****************************************************************************
2  * gtk2_theme.cpp: GTK2 implementation of the Theme class
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: gtk2_theme.cpp,v 1.4 2003/04/13 20:07:34 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 #if !defined WIN32
26
27 //--- GTK2 -----------------------------------------------------------------
28 #include <gdk/gdk.h>
29
30 //--- VLC -------------------------------------------------------------------
31 #include <vlc/intf.h>
32
33 //--- SKIN ------------------------------------------------------------------
34 #include "os_api.h"
35 #include "banks.h"
36 #include "window.h"
37 #include "os_window.h"
38 #include "event.h"
39 #include "os_event.h"
40 #include "theme.h"
41 #include "os_theme.h"
42 #include "dialog.h"
43 #include "os_dialog.h"
44 #include "vlcproc.h"
45 #include "skin_common.h"
46
47
48 //---------------------------------------------------------------------------
49 void SkinManage( intf_thread_t *p_intf );
50
51 /*
52
53 //---------------------------------------------------------------------------
54 // GTK2 interface
55 //---------------------------------------------------------------------------
56 LRESULT CALLBACK GTK2Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
57 {
58     // Get pointer to thread info
59     intf_thread_t *p_intf = (intf_thread_t *)GetWindowLongPtr( hwnd,
60         GWLP_USERDATA );
61
62     // If doesn't exist, treat windows message normally
63     if( p_intf == NULL )
64         return DefWindowProc( hwnd, uMsg, wParam, lParam );
65
66     // Create event to dispatch in windows
67     Event *evt = (Event *)new OSEvent( p_intf, hwnd, uMsg, wParam, lParam );
68
69
70     // Find window matching with hwnd
71     list<Window *>::const_iterator win;
72     for( win = p_intf->p_sys->p_theme->WindowList.begin();
73          win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
74     {
75         // If it is the correct window
76         if( hwnd == ( (GTK2Window *)(*win) )->GetHandle() )
77         {
78             // Send event and check if processed
79             if( (*win)->ProcessEvent( evt ) )
80             {
81                 delete (OSEvent *)evt;
82                 return 0;
83             }
84             else
85             {
86                 break;
87             }
88         }
89     }
90     delete (OSEvent *)evt;
91
92
93     // If Window is parent window
94     if( hwnd == ( (GTK2Theme *)p_intf->p_sys->p_theme )->GetParentWindow() )
95     {
96         if( uMsg == WM_SYSCOMMAND )
97         {
98             if( (Event *)wParam != NULL )
99                 ( (Event *)wParam )->SendEvent();
100             return 0;
101         }
102         else if( uMsg == WM_RBUTTONDOWN && wParam == 42 &&
103                  lParam == WM_RBUTTONDOWN )
104         {
105             int x, y;
106             OSAPI_GetMousePos( x, y );
107             TrackPopupMenu(
108                 ( (GTK2Theme *)p_intf->p_sys->p_theme )->GetSysMenu(),
109                 0, x, y, 0, hwnd, NULL );
110         }
111     }
112
113
114     // If closing parent window
115     if( uMsg == WM_CLOSE )
116     {
117         OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
118         return 0;
119     }
120
121     // If hwnd does not match any window or message not processed
122     return DefWindowProc( hwnd, uMsg, wParam, lParam );
123 }
124 //---------------------------------------------------------------------------
125
126
127 */
128
129 //---------------------------------------------------------------------------
130 // THEME
131 //---------------------------------------------------------------------------
132 GTK2Theme::GTK2Theme( intf_thread_t *_p_intf ) : Theme( _p_intf )
133 {
134 /*
135     // Get instance handle
136     hinst = GetModuleHandle( NULL );
137
138     // Create window class
139     WNDCLASS SkinWindow;
140
141     SkinWindow.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
142     SkinWindow.lpfnWndProc = (WNDPROC) GTK2Proc;
143     SkinWindow.lpszClassName = "SkinWindow";
144     SkinWindow.lpszMenuName = NULL;
145     SkinWindow.cbClsExtra = 0;
146     SkinWindow.cbWndExtra = 0;
147     SkinWindow.hbrBackground = HBRUSH (COLOR_WINDOW);
148     SkinWindow.hCursor = LoadCursor( NULL , IDC_ARROW );
149     SkinWindow.hIcon = LoadIcon( hinst, "VLC_ICON" );
150     SkinWindow.hInstance = hinst;
151
152     if( !RegisterClass( &SkinWindow ) )
153     {
154         WNDCLASS wndclass;
155
156         // Check why it failed. If it's because the class already exists
157         // then fine, otherwise return with an error.
158         if( !GetClassInfo( hinst, "SkinWindow", &wndclass ) )
159         {
160             msg_Err( p_intf, "Cannot register window class" );
161             return;
162         }
163     }
164 */
165     //Initialize value
166     ParentWindow = NULL;
167
168 }
169
170 //---------------------------------------------------------------------------
171 GTK2Theme::~GTK2Theme()
172 {/*
173     // Unregister the window class if needed
174     WNDCLASS wndclass;
175     if( GetClassInfo( hinst, "SkinWindow", &wndclass ) )
176     {
177         UnregisterClass( "SkinWindow", hinst );
178     }
179     if( GetClassInfo( hinst, "LogWindow", &wndclass ) )
180     {
181         UnregisterClass( "LogWindow", hinst );
182     }
183     if( GetClassInfo( hinst, "ParentWindow", &wndclass ) )
184     {
185         UnregisterClass( "ParentWindow", hinst );
186     }
187
188     // Delete tray icon if exists
189     if( ShowInTray )
190     {
191         Shell_NotifyIcon( NIM_DELETE, &TrayIcon );
192     }
193
194     // Destroy parent window
195     if( ParentWindow )
196     {
197         DestroyWindow( ParentWindow );
198     }*/
199 }
200 //---------------------------------------------------------------------------
201 void GTK2Theme::OnLoadTheme()
202 {/*
203     // Create window class
204     WNDCLASS ParentClass;
205     ParentClass.style = CS_VREDRAW|CS_HREDRAW|CS_DBLCLKS;
206     ParentClass.lpfnWndProc = (WNDPROC) GTK2Proc;
207     ParentClass.lpszClassName = "ParentWindow";
208     ParentClass.lpszMenuName = NULL;
209     ParentClass.cbClsExtra = 0;
210     ParentClass.cbWndExtra = 0;
211     ParentClass.hbrBackground = HBRUSH (COLOR_WINDOW);
212     ParentClass.hCursor = LoadCursor( NULL , IDC_ARROW );
213     ParentClass.hIcon = LoadIcon( hinst, "VLC_ICON" );
214     ParentClass.hInstance = hinst;
215
216     // register class and check it
217     if( !RegisterClass( &ParentClass ) )
218     {
219         WNDCLASS wndclass;
220
221         // Check why it failed. If it's because the class already exists
222         // then fine, otherwise return with an error.
223         if( !GetClassInfo( hinst, "ParentWindow", &wndclass ) )
224         {
225             msg_Err( p_intf, "Cannot register window class" );
226             return;
227         }
228     }
229
230     // Create Window
231     ParentWindow = CreateWindowEx( WS_EX_LAYERED|WS_EX_TOOLWINDOW,
232         "ParentWindow", "VLC Media Player",
233         WS_SYSMENU,
234         0, 0, 0, 0, 0, 0, hinst, NULL );
235
236     // Store with it a pointer to the interface thread
237     SetWindowLongPtr( ParentWindow, GWLP_USERDATA, (LONG_PTR)p_intf );
238     ShowWindow( ParentWindow, SW_SHOW );
239
240     // System tray icon
241     TrayIcon.cbSize = sizeof( PNOTIFYICONDATA );\r
242     TrayIcon.hWnd = ParentWindow;\r
243     TrayIcon.uID = 42;\r
244     TrayIcon.uFlags = NIF_ICON|NIF_TIP|NIF_MESSAGE;\r
245     TrayIcon.uCallbackMessage = WM_RBUTTONDOWN;\r
246     TrayIcon.hIcon = LoadIcon( hinst, "VLC_ICON" );
247     strcpy( TrayIcon.szTip, "VLC Media Player" );
248
249     // Remove default entries from system menu popup
250     SysMenu = GetSystemMenu( ParentWindow, false );
251     RemoveMenu( SysMenu, SC_RESTORE,  MF_BYCOMMAND );
252     RemoveMenu( SysMenu, SC_MOVE,     MF_BYCOMMAND );
253     RemoveMenu( SysMenu, SC_SIZE,     MF_BYCOMMAND );
254     RemoveMenu( SysMenu, SC_MINIMIZE, MF_BYCOMMAND );
255     RemoveMenu( SysMenu, SC_MAXIMIZE, MF_BYCOMMAND );
256     RemoveMenu( SysMenu, SC_CLOSE,    MF_BYCOMMAND );
257     RemoveMenu( SysMenu, 0,           MF_BYPOSITION );
258
259     // The create menu
260     CreateSystemMenu();
261 */
262     // Set the parent window attributes
263     GdkWindowAttr attr;
264     attr.title = "VLC Media Player";
265     attr.event_mask = GDK_ALL_EVENTS_MASK;
266     attr.x = 100;
267     attr.y = 100;
268     attr.window_type = GDK_WINDOW_TOPLEVEL;
269     attr.width = 400;
270     attr.height = 200;
271     attr.window_type = GDK_WINDOW_TOPLEVEL;
272     attr.wclass = GDK_INPUT_OUTPUT;
273     attr.override_redirect = FALSE;
274     
275     gint mask = GDK_WA_TITLE|GDK_WA_X|GDK_WA_Y|GDK_WA_NOREDIR;
276     
277     // Create the parent window
278     ParentWindow = gdk_window_new( NULL, &attr, mask);
279     gdk_window_show( ParentWindow );
280 }
281 //---------------------------------------------------------------------------
282 void GTK2Theme::AddSystemMenu( string name, Event *event )
283 {/*
284     if( name == "SEPARATOR" )
285     {
286         AppendMenu( SysMenu, MF_SEPARATOR, 0, NULL );
287     }
288     else
289     {
290         AppendMenu( SysMenu, MF_STRING, (unsigned int)event,
291                     (char *)name.c_str() );
292     }*/
293 }
294 //---------------------------------------------------------------------------
295 void GTK2Theme::ChangeClientWindowName( string name )
296 {/*
297     SetWindowText( ParentWindow, name.c_str() );*/
298 }
299 //---------------------------------------------------------------------------
300 void GTK2Theme::AddWindow( string name, int x, int y, bool visible,
301     int fadetime, int alpha, int movealpha, bool dragdrop )
302 {/*
303     HWND hwnd;
304
305     hwnd = CreateWindowEx( WS_EX_LAYERED|WS_EX_TOOLWINDOW,
306         "SkinWindow", name.c_str(), WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
307         0, 0, ParentWindow, 0, hinst, NULL );
308
309     if( !hwnd )
310     {
311         msg_Err( p_intf, "CreateWindow failed" );
312         return;
313     }
314
315     SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_intf );
316
317     WindowList.push_back( (Window *)new OSWindow( p_intf, hwnd, x, y, visible,
318         fadetime, alpha, movealpha, dragdrop ) ) ;*/
319         
320     GdkWindowAttr attr;
321     attr.event_mask = GDK_ALL_EVENTS_MASK;
322     attr.width = 100;
323     attr.height = 100;
324     attr.window_type = GDK_WINDOW_CHILD;
325     attr.wclass = GDK_INPUT_OUTPUT;
326     
327     gint mask =0;
328     
329     // Create the parent window
330     GdkWindow *gwnd = gdk_window_new( ParentWindow, &attr, mask);
331     if( !gwnd )
332     {
333         msg_Err( p_intf, "CreateWindow failed" );
334         return;
335     }
336     
337     gdk_window_show( gwnd );
338     
339     WindowList.push_back( (Window *)new OSWindow( p_intf, gwnd, x, y, visible,
340         fadetime, alpha, movealpha, dragdrop ) ) ;
341
342 }
343 //---------------------------------------------------------------------------
344 /*HWND GTK2Theme::GetLogHandle()
345 {
346     if( Log != NULL )
347         return ( (GTK2LogWindow *)Log )->GetWindow();
348     else
349         return NULL;
350 }*/
351 //---------------------------------------------------------------------------
352 void GTK2Theme::ChangeTray()
353 {/*
354     if( ShowInTray )
355     {
356         Shell_NotifyIcon( NIM_DELETE, &TrayIcon );
357         ShowInTray = false;
358     }
359     else
360     {
361         Shell_NotifyIcon( NIM_ADD, &TrayIcon );
362         ShowInTray = true;
363     }*/
364 }
365 //---------------------------------------------------------------------------
366 void GTK2Theme::ChangeTaskbar()
367 {/*
368     if( ShowInTaskbar )
369     {
370         ShowWindow( ParentWindow, SW_HIDE );
371         SetWindowLongPtr( ParentWindow, GWL_EXSTYLE,
372                           WS_EX_LAYERED|WS_EX_TOOLWINDOW );
373         ShowWindow( ParentWindow, SW_SHOW );
374         ShowInTaskbar = false;
375     }
376     else
377     {
378         ShowWindow( ParentWindow, SW_HIDE );
379         SetWindowLongPtr( ParentWindow, GWL_EXSTYLE,
380                           WS_EX_LAYERED|WS_EX_APPWINDOW );
381         ShowWindow( ParentWindow, SW_SHOW );
382         ShowInTaskbar = true;
383     }*/
384 }
385 //---------------------------------------------------------------------------
386
387 #endif