1 /*****************************************************************************
2 * gtk2_theme.cpp: GTK2 implementation of the Theme class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: gtk2_theme.cpp,v 1.19 2003/04/20 16:16: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 -----------------------------------------------------------------
29 #include <gdk-pixbuf/gdk-pixbuf.h>
31 //--- VLC -------------------------------------------------------------------
34 //--- SKIN ------------------------------------------------------------------
35 #include "../os_api.h"
36 #include "../src/banks.h"
37 #include "../src/window.h"
38 #include "../os_window.h"
39 #include "../src/event.h"
40 #include "../os_event.h"
41 #include "../src/theme.h"
42 #include "../os_theme.h"
43 #include "../src/dialog.h"
44 #include "../os_dialog.h"
45 #include "../src/vlcproc.h"
46 #include "../src/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.title = (gchar *)name.c_str();
246 attr.event_mask = GDK_ALL_EVENTS_MASK;
249 attr.window_type = GDK_WINDOW_TOPLEVEL;
250 attr.wclass = GDK_INPUT_OUTPUT;
251 attr.override_redirect = FALSE;
253 gint mask = GDK_WA_NOREDIR;
256 GdkWindow *gwnd = gdk_window_new( NULL, &attr, mask );
259 msg_Err( p_intf, "CreateWindow failed" );
263 gdk_window_set_decorations( gwnd, (GdkWMDecoration)0 );
265 gdk_window_show( gwnd );
267 WindowList.push_back( (Window *)new OSWindow( p_intf, gwnd, x, y, visible,
268 fadetime, alpha, movealpha, dragdrop, name ) ) ;
271 //---------------------------------------------------------------------------
272 /*HWND GTK2Theme::GetLogHandle()
275 return ( (GTK2LogWindow *)Log )->GetWindow();
279 //---------------------------------------------------------------------------
280 void GTK2Theme::ChangeTray()
284 Shell_NotifyIcon( NIM_DELETE, &TrayIcon );
289 Shell_NotifyIcon( NIM_ADD, &TrayIcon );
293 //---------------------------------------------------------------------------
294 void GTK2Theme::ChangeTaskbar()
298 ShowWindow( ParentWindow, SW_HIDE );
299 SetWindowLongPtr( ParentWindow, GWL_EXSTYLE,
300 WS_EX_LAYERED|WS_EX_TOOLWINDOW );
301 ShowWindow( ParentWindow, SW_SHOW );
302 ShowInTaskbar = false;
306 ShowWindow( ParentWindow, SW_HIDE );
307 SetWindowLongPtr( ParentWindow, GWL_EXSTYLE,
308 WS_EX_LAYERED|WS_EX_APPWINDOW );
309 ShowWindow( ParentWindow, SW_SHOW );
310 ShowInTaskbar = true;
313 //---------------------------------------------------------------------------