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 $
7 * Authors: Cyril Deguet <asmax@videolan.org>
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.
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.
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,
23 *****************************************************************************/
27 //--- GTK2 -----------------------------------------------------------------
30 //--- VLC -------------------------------------------------------------------
33 //--- SKIN ------------------------------------------------------------------
37 #include "os_window.h"
43 #include "os_dialog.h"
45 #include "skin_common.h"
48 //---------------------------------------------------------------------------
49 void SkinManage( intf_thread_t *p_intf );
53 //---------------------------------------------------------------------------
55 //---------------------------------------------------------------------------
56 LRESULT CALLBACK GTK2Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
58 // Get pointer to thread info
59 intf_thread_t *p_intf = (intf_thread_t *)GetWindowLongPtr( hwnd,
62 // If doesn't exist, treat windows message normally
64 return DefWindowProc( hwnd, uMsg, wParam, lParam );
66 // Create event to dispatch in windows
67 Event *evt = (Event *)new OSEvent( p_intf, hwnd, uMsg, wParam, lParam );
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++ )
75 // If it is the correct window
76 if( hwnd == ( (GTK2Window *)(*win) )->GetHandle() )
78 // Send event and check if processed
79 if( (*win)->ProcessEvent( evt ) )
81 delete (OSEvent *)evt;
90 delete (OSEvent *)evt;
93 // If Window is parent window
94 if( hwnd == ( (GTK2Theme *)p_intf->p_sys->p_theme )->GetParentWindow() )
96 if( uMsg == WM_SYSCOMMAND )
98 if( (Event *)wParam != NULL )
99 ( (Event *)wParam )->SendEvent();
102 else if( uMsg == WM_RBUTTONDOWN && wParam == 42 &&
103 lParam == WM_RBUTTONDOWN )
106 OSAPI_GetMousePos( x, y );
108 ( (GTK2Theme *)p_intf->p_sys->p_theme )->GetSysMenu(),
109 0, x, y, 0, hwnd, NULL );
114 // If closing parent window
115 if( uMsg == WM_CLOSE )
117 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
121 // If hwnd does not match any window or message not processed
122 return DefWindowProc( hwnd, uMsg, wParam, lParam );
124 //---------------------------------------------------------------------------
129 //---------------------------------------------------------------------------
131 //---------------------------------------------------------------------------
132 GTK2Theme::GTK2Theme( intf_thread_t *_p_intf ) : Theme( _p_intf )
135 // Get instance handle
136 hinst = GetModuleHandle( NULL );
138 // Create window class
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;
152 if( !RegisterClass( &SkinWindow ) )
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 ) )
160 msg_Err( p_intf, "Cannot register window class" );
170 //---------------------------------------------------------------------------
171 GTK2Theme::~GTK2Theme()
173 // Unregister the window class if needed
175 if( GetClassInfo( hinst, "SkinWindow", &wndclass ) )
177 UnregisterClass( "SkinWindow", hinst );
179 if( GetClassInfo( hinst, "LogWindow", &wndclass ) )
181 UnregisterClass( "LogWindow", hinst );
183 if( GetClassInfo( hinst, "ParentWindow", &wndclass ) )
185 UnregisterClass( "ParentWindow", hinst );
188 // Delete tray icon if exists
191 Shell_NotifyIcon( NIM_DELETE, &TrayIcon );
194 // Destroy parent window
197 DestroyWindow( ParentWindow );
200 //---------------------------------------------------------------------------
201 void GTK2Theme::OnLoadTheme()
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;
216 // register class and check it
217 if( !RegisterClass( &ParentClass ) )
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 ) )
225 msg_Err( p_intf, "Cannot register window class" );
231 ParentWindow = CreateWindowEx( WS_EX_LAYERED|WS_EX_TOOLWINDOW,
232 "ParentWindow", "VLC Media Player",
234 0, 0, 0, 0, 0, 0, hinst, NULL );
236 // Store with it a pointer to the interface thread
237 SetWindowLongPtr( ParentWindow, GWLP_USERDATA, (LONG_PTR)p_intf );
238 ShowWindow( ParentWindow, SW_SHOW );
241 TrayIcon.cbSize = sizeof( PNOTIFYICONDATA );
\r
242 TrayIcon.hWnd = ParentWindow;
\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" );
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 );
262 // Set the parent window attributes
264 attr.title = "VLC Media Player";
265 attr.event_mask = GDK_ALL_EVENTS_MASK;
268 attr.window_type = GDK_WINDOW_TOPLEVEL;
271 attr.window_type = GDK_WINDOW_TOPLEVEL;
272 attr.wclass = GDK_INPUT_OUTPUT;
273 attr.override_redirect = FALSE;
275 gint mask = GDK_WA_TITLE|GDK_WA_X|GDK_WA_Y|GDK_WA_NOREDIR;
277 // Create the parent window
278 ParentWindow = gdk_window_new( NULL, &attr, mask);
279 gdk_window_show( ParentWindow );
281 //---------------------------------------------------------------------------
282 void GTK2Theme::AddSystemMenu( string name, Event *event )
284 if( name == "SEPARATOR" )
286 AppendMenu( SysMenu, MF_SEPARATOR, 0, NULL );
290 AppendMenu( SysMenu, MF_STRING, (unsigned int)event,
291 (char *)name.c_str() );
294 //---------------------------------------------------------------------------
295 void GTK2Theme::ChangeClientWindowName( string name )
297 SetWindowText( ParentWindow, name.c_str() );*/
299 //---------------------------------------------------------------------------
300 void GTK2Theme::AddWindow( string name, int x, int y, bool visible,
301 int fadetime, int alpha, int movealpha, bool dragdrop )
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 );
311 msg_Err( p_intf, "CreateWindow failed" );
315 SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_intf );
317 WindowList.push_back( (Window *)new OSWindow( p_intf, hwnd, x, y, visible,
318 fadetime, alpha, movealpha, dragdrop ) ) ;*/
321 attr.event_mask = GDK_ALL_EVENTS_MASK;
324 attr.window_type = GDK_WINDOW_CHILD;
325 attr.wclass = GDK_INPUT_OUTPUT;
329 // Create the parent window
330 GdkWindow *gwnd = gdk_window_new( ParentWindow, &attr, mask);
333 msg_Err( p_intf, "CreateWindow failed" );
337 gdk_window_show( gwnd );
339 WindowList.push_back( (Window *)new OSWindow( p_intf, gwnd, x, y, visible,
340 fadetime, alpha, movealpha, dragdrop ) ) ;
343 //---------------------------------------------------------------------------
344 /*HWND GTK2Theme::GetLogHandle()
347 return ( (GTK2LogWindow *)Log )->GetWindow();
351 //---------------------------------------------------------------------------
352 void GTK2Theme::ChangeTray()
356 Shell_NotifyIcon( NIM_DELETE, &TrayIcon );
361 Shell_NotifyIcon( NIM_ADD, &TrayIcon );
365 //---------------------------------------------------------------------------
366 void GTK2Theme::ChangeTaskbar()
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;
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;
385 //---------------------------------------------------------------------------