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