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 $
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 *****************************************************************************/
26 //--- GTK2 -----------------------------------------------------------------
29 //--- VLC -------------------------------------------------------------------
32 //--- SKIN ------------------------------------------------------------------
36 #include "os_window.h"
42 #include "os_dialog.h"
44 #include "skin_common.h"
47 //---------------------------------------------------------------------------
48 void SkinManage( intf_thread_t *p_intf );
52 //---------------------------------------------------------------------------
54 //---------------------------------------------------------------------------
55 LRESULT CALLBACK GTK2Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
57 // Get pointer to thread info
58 intf_thread_t *p_intf = (intf_thread_t *)GetWindowLongPtr( hwnd,
61 // If doesn't exist, treat windows message normally
63 return DefWindowProc( hwnd, uMsg, wParam, lParam );
65 // Create event to dispatch in windows
66 Event *evt = (Event *)new OSEvent( p_intf, hwnd, uMsg, wParam, lParam );
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++ )
74 // If it is the correct window
75 if( hwnd == ( (GTK2Window *)(*win) )->GetHandle() )
77 // Send event and check if processed
78 if( (*win)->ProcessEvent( evt ) )
80 delete (OSEvent *)evt;
89 delete (OSEvent *)evt;
92 // If Window is parent window
93 if( hwnd == ( (GTK2Theme *)p_intf->p_sys->p_theme )->GetParentWindow() )
95 if( uMsg == WM_SYSCOMMAND )
97 if( (Event *)wParam != NULL )
98 ( (Event *)wParam )->SendEvent();
101 else if( uMsg == WM_RBUTTONDOWN && wParam == 42 &&
102 lParam == WM_RBUTTONDOWN )
105 OSAPI_GetMousePos( x, y );
107 ( (GTK2Theme *)p_intf->p_sys->p_theme )->GetSysMenu(),
108 0, x, y, 0, hwnd, NULL );
113 // If closing parent window
114 if( uMsg == WM_CLOSE )
116 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
120 // If hwnd does not match any window or message not processed
121 return DefWindowProc( hwnd, uMsg, wParam, lParam );
123 //---------------------------------------------------------------------------
128 //---------------------------------------------------------------------------
130 //---------------------------------------------------------------------------
131 GTK2Theme::GTK2Theme( intf_thread_t *_p_intf ) : Theme( _p_intf )
134 // Get instance handle
135 hinst = GetModuleHandle( NULL );
137 // Create window class
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;
151 if( !RegisterClass( &SkinWindow ) )
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 ) )
159 msg_Err( p_intf, "Cannot register window class" );
169 //---------------------------------------------------------------------------
170 GTK2Theme::~GTK2Theme()
172 // Unregister the window class if needed
174 if( GetClassInfo( hinst, "SkinWindow", &wndclass ) )
176 UnregisterClass( "SkinWindow", hinst );
178 if( GetClassInfo( hinst, "LogWindow", &wndclass ) )
180 UnregisterClass( "LogWindow", hinst );
182 if( GetClassInfo( hinst, "ParentWindow", &wndclass ) )
184 UnregisterClass( "ParentWindow", hinst );
187 // Delete tray icon if exists
190 Shell_NotifyIcon( NIM_DELETE, &TrayIcon );
193 // Destroy parent window
196 DestroyWindow( ParentWindow );
199 //---------------------------------------------------------------------------
200 void GTK2Theme::OnLoadTheme()
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;
215 // register class and check it
216 if( !RegisterClass( &ParentClass ) )
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 ) )
224 msg_Err( p_intf, "Cannot register window class" );
230 ParentWindow = CreateWindowEx( WS_EX_LAYERED|WS_EX_TOOLWINDOW,
231 "ParentWindow", "VLC Media Player",
233 0, 0, 0, 0, 0, 0, hinst, NULL );
235 // Store with it a pointer to the interface thread
236 SetWindowLongPtr( ParentWindow, GWLP_USERDATA, (LONG_PTR)p_intf );
237 ShowWindow( ParentWindow, SW_SHOW );
240 TrayIcon.cbSize = sizeof( PNOTIFYICONDATA );
\r
241 TrayIcon.hWnd = ParentWindow;
\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" );
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 );
262 //---------------------------------------------------------------------------
263 void GTK2Theme::AddSystemMenu( string name, Event *event )
265 if( name == "SEPARATOR" )
267 AppendMenu( SysMenu, MF_SEPARATOR, 0, NULL );
271 AppendMenu( SysMenu, MF_STRING, (unsigned int)event,
272 (char *)name.c_str() );
275 //---------------------------------------------------------------------------
276 void GTK2Theme::ChangeClientWindowName( string name )
278 SetWindowText( ParentWindow, name.c_str() );*/
280 //---------------------------------------------------------------------------
281 void GTK2Theme::AddWindow( string name, int x, int y, bool visible,
282 int fadetime, int alpha, int movealpha, bool dragdrop )
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 );
292 msg_Err( p_intf, "CreateWindow failed" );
296 SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_intf );
298 WindowList.push_back( (Window *)new OSWindow( p_intf, hwnd, x, y, visible,
299 fadetime, alpha, movealpha, dragdrop ) ) ;*/
301 //---------------------------------------------------------------------------
302 /*HWND GTK2Theme::GetLogHandle()
305 return ( (GTK2LogWindow *)Log )->GetWindow();
309 //---------------------------------------------------------------------------
310 void GTK2Theme::ChangeTray()
314 Shell_NotifyIcon( NIM_DELETE, &TrayIcon );
319 Shell_NotifyIcon( NIM_ADD, &TrayIcon );
323 //---------------------------------------------------------------------------
324 void GTK2Theme::ChangeTaskbar()
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;
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;
343 //---------------------------------------------------------------------------