]> git.sesse.net Git - vlc/blob - modules/gui/skins/gtk2/gtk2_window.cpp
* get the size of a bitmap
[vlc] / modules / gui / skins / gtk2 / gtk2_window.cpp
1 /*****************************************************************************
2  * gtk2_window.cpp: GTK2 implementation of the Window class
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: gtk2_window.cpp,v 1.6 2003/04/14 17:03:42 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 #if !defined WIN32
26
27 //--- GENERAL ---------------------------------------------------------------
28 //#include <math.h>
29
30 //--- VLC -------------------------------------------------------------------
31 #include <vlc/intf.h>
32
33 //--- GTK2 ------------------------------------------------------------------
34 #include <gdk/gdk.h>
35
36 //--- SKIN ------------------------------------------------------------------
37 #include "os_api.h"
38 #include "anchor.h"
39 #include "generic.h"
40 #include "window.h"
41 #include "os_window.h"
42 #include "event.h"
43 #include "os_event.h"
44 #include "graphics.h"
45 #include "os_graphics.h"
46 #include "skin_common.h"
47 #include "theme.h"
48
49
50
51 //---------------------------------------------------------------------------
52 // Fading API
53 //---------------------------------------------------------------------------
54 /*#define LWA_COLORKEY  0x00000001
55 #define LWA_ALPHA     0x00000002
56 typedef BOOL (WINAPI *SLWA)(HWND, COLORREF, BYTE, DWORD);
57 HMODULE hModule = LoadLibrary( "user32.dll" );
58 SLWA SetLayeredWindowAttributes =
59     (SLWA)GetProcAddress( hModule, "SetLayeredWindowAttributes" );
60 */
61
62 //---------------------------------------------------------------------------
63 // Skinable Window
64 //---------------------------------------------------------------------------
65 GTK2Window::GTK2Window( intf_thread_t *p_intf, GdkWindow *gwnd, int x, int y,
66     bool visible, int transition, int normalalpha, int movealpha,
67     bool dragdrop )
68     : Window( p_intf, x, y, visible, transition, normalalpha, movealpha,
69               dragdrop )
70 {
71     // Set handles
72     gWnd           = gwnd;
73 /*
74     // Set position parameters
75     CursorPos    = new POINT;
76     WindowPos    = new POINT;
77
78     // Create Tool Tip Window
79     ToolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
80         WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
81         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
82         hWnd, 0, GetModuleHandle( NULL ), 0);
83
84     // Create Tool Tip infos
85     ToolTipInfo.cbSize = sizeof(TOOLINFO);
86     ToolTipInfo.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
87     ToolTipInfo.hwnd = hWnd;
88     ToolTipInfo.hinst = GetModuleHandle( NULL );
89     ToolTipInfo.uId = (unsigned int)hWnd;
90     ToolTipInfo.lpszText = NULL;
91     ToolTipInfo.rect.left = ToolTipInfo.rect.top = 0;
92         ToolTipInfo.rect.right = ToolTipInfo.rect.bottom = 0;
93
94     SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
95                     (LPARAM)(LPTOOLINFO) &ToolTipInfo );
96
97     // Drag & drop
98     if( DragDrop )
99     {
100         // Initialize the OLE library
101         OleInitialize( NULL );
102         DropTarget = (LPDROPTARGET) new GTK2DropObject();
103         // register the listview as a drop target
104         RegisterDragDrop( hWnd, DropTarget );
105     }
106 */
107     // Create Tool Tip window
108 /*    GdkWindowAttr attr;
109     attr.event_mask = GDK_ALL_EVENTS_MASK;
110     attr.width = 100;
111     attr.height = 100;
112     attr.window_type = GDK_WINDOW_CHILD;
113     attr.wclass = GDK_INPUT_OUTPUT;
114     gint mask = 0;
115     ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
116
117 }
118 //---------------------------------------------------------------------------
119 GTK2Window::~GTK2Window()
120 {
121 /*    delete CursorPos;
122     delete WindowPos;
123
124     if( hWnd != NULL )
125     {
126         DestroyWindow( hWnd );
127     }
128     if( ToolTipWindow != NULL )
129     {
130         DestroyWindow( ToolTipWindow );
131     }
132     if( DragDrop )
133     {
134         // Remove the listview from the list of drop targets
135         RevokeDragDrop( hWnd );
136         DropTarget->Release();
137         // Uninitialize the OLE library
138         OleUninitialize();
139     }
140 */
141 }
142 //---------------------------------------------------------------------------
143 void GTK2Window::OSShow( bool show )
144 {
145     if( show )
146     {
147         gdk_window_show( gWnd );
148     }
149     else
150     {
151         gdk_window_hide( gWnd );
152     }
153 }
154 //---------------------------------------------------------------------------
155 bool GTK2Window::ProcessOSEvent( Event *evt )
156 {
157 /*    unsigned int msg = evt->GetMessage();
158     unsigned int p1  = evt->GetParam1();
159     int          p2  = evt->GetParam2();
160
161     switch( msg )
162     {
163         case WM_PAINT:
164             HDC DC;
165             PAINTSTRUCT Infos;
166             DC = BeginPaint( hWnd , &Infos );
167             EndPaint( hWnd , &Infos );
168             RefreshFromImage( 0, 0, Width, Height );
169             return true;
170
171         case WM_MOUSEMOVE:
172             TRACKMOUSEEVENT TrackEvent;
173             TrackEvent.cbSize      = sizeof( TRACKMOUSEEVENT );\r
174             TrackEvent.dwFlags     = TME_LEAVE;\r
175             TrackEvent.hwndTrack   = hWnd;\r
176             TrackEvent.dwHoverTime = 1;
177             TrackMouseEvent( &TrackEvent );
178             if( p1 == MK_LBUTTON )
179                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 1 );
180             else if( p1 == MK_RBUTTON )
181                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 2 );
182             else
183                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 0 );
184
185             return true;
186
187         case WM_LBUTTONDOWN:
188             SetCapture( hWnd );
189             MouseDown( LOWORD( p2 ), HIWORD( p2 ), 1 );
190             return true;
191
192         case WM_LBUTTONUP:
193             ReleaseCapture();
194             MouseUp( LOWORD( p2 ), HIWORD( p2 ), 1 );
195             return true;
196
197         case WM_RBUTTONDOWN:
198             MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
199             return true;
200
201         case WM_RBUTTONUP:
202             MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
203             return true;
204
205         case WM_LBUTTONDBLCLK:
206             MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
207             return true;
208
209         case WM_MOUSELEAVE:
210             OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
211             return true;
212
213         default:
214             return false;
215     }*/
216 }
217 //---------------------------------------------------------------------------
218 void GTK2Window::SetTransparency( int Value )
219 {
220 /*    if( Value > -1 )
221         Alpha = Value;
222     SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
223     UpdateWindow( hWnd );*/
224 }
225 //---------------------------------------------------------------------------
226 void GTK2Window::RefreshFromImage( int x, int y, int w, int h )
227 {
228     // Initialize painting
229 /*    HDC DC = GetWindowDC( hWnd );
230
231     // Draw image on window
232     BitBlt( DC, x, y, w, h, ( (GTK2Graphics *)Image )->GetImageHandle(),
233             x, y, SRCCOPY );
234
235     // Release window device context
236     ReleaseDC( hWnd, DC );
237 */
238 }
239 //---------------------------------------------------------------------------
240 void GTK2Window::WindowManualMove()
241 {
242 /*    // Get mouse cursor position
243     LPPOINT NewPos = new POINT;
244     GetCursorPos( NewPos );
245
246     // Move window and chek for magnetism
247     p_intf->p_sys->p_theme->MoveSkinMagnet( this,
248         WindowPos->x + NewPos->x - CursorPos->x,
249         WindowPos->y + NewPos->y - CursorPos->y );
250
251     // Free memory
252     delete[] NewPos;
253 */
254 }
255 //---------------------------------------------------------------------------
256 void GTK2Window::WindowManualMoveInit()
257 {
258 /*    GetCursorPos( CursorPos );
259     WindowPos->x = Left;
260     WindowPos->y = Top;*/
261 }
262 //---------------------------------------------------------------------------
263 void GTK2Window::Move( int left, int top )
264 {
265 /*    Left = left;
266     Top  = top;
267     //SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
268     //              SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER );
269     MoveWindow( hWnd, Left, Top, Width, Height, false );*/
270 }
271 //---------------------------------------------------------------------------
272 void GTK2Window::Size( int width, int height )
273 {
274 fprintf(stderr, "size %d %d\n", width, height);
275     Width  = width;
276     Height = height;
277     gdk_window_resize( gWnd, width, height );
278 }
279 //---------------------------------------------------------------------------
280 void GTK2Window::ChangeToolTipText( string text )
281 {
282 /*    if( text == "none" )
283     {
284         if( ToolTipText != "none" )
285         {
286             ToolTipText = "none";
287             ToolTipInfo.lpszText = NULL;
288             SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
289         }
290     }
291     else
292     {
293         if( text != ToolTipText )
294         {
295             ToolTipText = text;
296             ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
297             SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
298             SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
299                              (LPARAM)(LPTOOLINFO)&ToolTipInfo );
300         }
301     }
302 */
303 }
304 //---------------------------------------------------------------------------
305
306 #endif