1 /*****************************************************************************
2 * gtk2_theme.cpp: GTK2 implementation of the Theme class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: gtk2_theme.cpp,v 1.11 2003/04/15 16:42:02 karibu 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 -----------------------------------------------------------------
29 #include <gdk-pixbuf/gdk-pixbuf.h>
31 //--- VLC -------------------------------------------------------------------
34 //--- SKIN ------------------------------------------------------------------
38 #include "os_window.h"
44 #include "os_dialog.h"
46 #include "skin_common.h"
49 //---------------------------------------------------------------------------
50 void SkinManage( intf_thread_t *p_intf );
53 //---------------------------------------------------------------------------
55 //---------------------------------------------------------------------------
56 GTK2Theme::GTK2Theme( intf_thread_t *_p_intf ) : Theme( _p_intf )
59 // Get instance handle
60 hinst = GetModuleHandle( NULL );
62 // Create window class
65 SkinWindow.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
66 SkinWindow.lpfnWndProc = (WNDPROC) GTK2Proc;
67 SkinWindow.lpszClassName = "SkinWindow";
68 SkinWindow.lpszMenuName = NULL;
69 SkinWindow.cbClsExtra = 0;
70 SkinWindow.cbWndExtra = 0;
71 SkinWindow.hbrBackground = HBRUSH (COLOR_WINDOW);
72 SkinWindow.hCursor = LoadCursor( NULL , IDC_ARROW );
73 SkinWindow.hIcon = LoadIcon( hinst, "VLC_ICON" );
74 SkinWindow.hInstance = hinst;
76 if( !RegisterClass( &SkinWindow ) )
80 // Check why it failed. If it's because the class already exists
81 // then fine, otherwise return with an error.
82 if( !GetClassInfo( hinst, "SkinWindow", &wndclass ) )
84 msg_Err( p_intf, "Cannot register window class" );
94 //---------------------------------------------------------------------------
95 GTK2Theme::~GTK2Theme()
97 // Unregister the window class if needed
99 if( GetClassInfo( hinst, "SkinWindow", &wndclass ) )
101 UnregisterClass( "SkinWindow", hinst );
103 if( GetClassInfo( hinst, "LogWindow", &wndclass ) )
105 UnregisterClass( "LogWindow", hinst );
107 if( GetClassInfo( hinst, "ParentWindow", &wndclass ) )
109 UnregisterClass( "ParentWindow", hinst );
112 // Delete tray icon if exists
115 Shell_NotifyIcon( NIM_DELETE, &TrayIcon );
118 // Destroy parent window
121 DestroyWindow( ParentWindow );
124 //---------------------------------------------------------------------------
125 void GTK2Theme::OnLoadTheme()
127 // Create window class
128 WNDCLASS ParentClass;
129 ParentClass.style = CS_VREDRAW|CS_HREDRAW|CS_DBLCLKS;
130 ParentClass.lpfnWndProc = (WNDPROC) GTK2Proc;
131 ParentClass.lpszClassName = "ParentWindow";
132 ParentClass.lpszMenuName = NULL;
133 ParentClass.cbClsExtra = 0;
134 ParentClass.cbWndExtra = 0;
135 ParentClass.hbrBackground = HBRUSH (COLOR_WINDOW);
136 ParentClass.hCursor = LoadCursor( NULL , IDC_ARROW );
137 ParentClass.hIcon = LoadIcon( hinst, "VLC_ICON" );
138 ParentClass.hInstance = hinst;
140 // register class and check it
141 if( !RegisterClass( &ParentClass ) )
145 // Check why it failed. If it's because the class already exists
146 // then fine, otherwise return with an error.
147 if( !GetClassInfo( hinst, "ParentWindow", &wndclass ) )
149 msg_Err( p_intf, "Cannot register window class" );
155 ParentWindow = CreateWindowEx( WS_EX_LAYERED|WS_EX_TOOLWINDOW,
156 "ParentWindow", "VLC Media Player",
158 0, 0, 0, 0, 0, 0, hinst, NULL );
160 // Store with it a pointer to the interface thread
161 SetWindowLongPtr( ParentWindow, GWLP_USERDATA, (LONG_PTR)p_intf );
162 ShowWindow( ParentWindow, SW_SHOW );
165 TrayIcon.cbSize = sizeof( PNOTIFYICONDATA );
\r
166 TrayIcon.hWnd = ParentWindow;
\r
168 TrayIcon.uFlags = NIF_ICON|NIF_TIP|NIF_MESSAGE;
\r
169 TrayIcon.uCallbackMessage = WM_RBUTTONDOWN;
\r
170 TrayIcon.hIcon = LoadIcon( hinst, "VLC_ICON" );
171 strcpy( TrayIcon.szTip, "VLC Media Player" );
173 // Remove default entries from system menu popup
174 SysMenu = GetSystemMenu( ParentWindow, false );
175 RemoveMenu( SysMenu, SC_RESTORE, MF_BYCOMMAND );
176 RemoveMenu( SysMenu, SC_MOVE, MF_BYCOMMAND );
177 RemoveMenu( SysMenu, SC_SIZE, MF_BYCOMMAND );
178 RemoveMenu( SysMenu, SC_MINIMIZE, MF_BYCOMMAND );
179 RemoveMenu( SysMenu, SC_MAXIMIZE, MF_BYCOMMAND );
180 RemoveMenu( SysMenu, SC_CLOSE, MF_BYCOMMAND );
181 RemoveMenu( SysMenu, 0, MF_BYPOSITION );
186 // Set the parent window attributes
188 attr.title = "VLC Media Player";
189 attr.event_mask = GDK_ALL_EVENTS_MASK;
194 attr.window_type = GDK_WINDOW_TOPLEVEL;
195 attr.wclass = GDK_INPUT_ONLY;
196 attr.override_redirect = FALSE;
198 gint mask = GDK_WA_TITLE|GDK_WA_X|GDK_WA_Y|GDK_WA_NOREDIR;
200 // Create the parent window
201 ParentWindow = gdk_window_new( NULL, &attr, mask);
203 // gdk_window_show( ParentWindow );
205 //---------------------------------------------------------------------------
206 void GTK2Theme::AddSystemMenu( string name, Event *event )
208 if( name == "SEPARATOR" )
210 AppendMenu( SysMenu, MF_SEPARATOR, 0, NULL );
214 AppendMenu( SysMenu, MF_STRING, (unsigned int)event,
215 (char *)name.c_str() );
218 //---------------------------------------------------------------------------
219 void GTK2Theme::ChangeClientWindowName( string name )
221 SetWindowText( ParentWindow, name.c_str() );*/
223 //---------------------------------------------------------------------------
224 void GTK2Theme::AddWindow( string name, int x, int y, bool visible,
225 int fadetime, int alpha, int movealpha, bool dragdrop )
229 hwnd = CreateWindowEx( WS_EX_LAYERED|WS_EX_TOOLWINDOW,
230 "SkinWindow", name.c_str(), WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
231 0, 0, ParentWindow, 0, hinst, NULL );
235 msg_Err( p_intf, "CreateWindow failed" );
239 SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_intf );
241 WindowList.push_back( (Window *)new OSWindow( p_intf, hwnd, x, y, visible,
242 fadetime, alpha, movealpha, dragdrop ) ) ;*/
245 attr.event_mask = GDK_ALL_EVENTS_MASK;
248 attr.window_type = GDK_WINDOW_TOPLEVEL;
249 attr.wclass = GDK_INPUT_OUTPUT;
250 attr.override_redirect = TRUE;
252 gint mask = GDK_WA_NOREDIR;
255 GdkWindow *gwnd = gdk_window_new( NULL, &attr, mask );
258 msg_Err( p_intf, "CreateWindow failed" );
262 gdk_window_show( gwnd );
264 WindowList.push_back( (Window *)new OSWindow( p_intf, gwnd, x, y, visible,
265 fadetime, alpha, movealpha, dragdrop ) ) ;
268 //---------------------------------------------------------------------------
269 /*HWND GTK2Theme::GetLogHandle()
272 return ( (GTK2LogWindow *)Log )->GetWindow();
276 //---------------------------------------------------------------------------
277 void GTK2Theme::ChangeTray()
281 Shell_NotifyIcon( NIM_DELETE, &TrayIcon );
286 Shell_NotifyIcon( NIM_ADD, &TrayIcon );
290 //---------------------------------------------------------------------------
291 void GTK2Theme::ChangeTaskbar()
295 ShowWindow( ParentWindow, SW_HIDE );
296 SetWindowLongPtr( ParentWindow, GWL_EXSTYLE,
297 WS_EX_LAYERED|WS_EX_TOOLWINDOW );
298 ShowWindow( ParentWindow, SW_SHOW );
299 ShowInTaskbar = false;
303 ShowWindow( ParentWindow, SW_HIDE );
304 SetWindowLongPtr( ParentWindow, GWL_EXSTYLE,
305 WS_EX_LAYERED|WS_EX_APPWINDOW );
306 ShowWindow( ParentWindow, SW_SHOW );
307 ShowInTaskbar = true;
310 //---------------------------------------------------------------------------