7991f325536fedd88f9c6f3e2e0d8367d64be0b5
[vlc.git] / 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.12 2003/04/15 16:47:20 karibu 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 #include <glib.h>
36
37 //--- SKIN ------------------------------------------------------------------
38 #include "os_api.h"
39 #include "anchor.h"
40 #include "generic.h"
41 #include "window.h"
42 #include "os_window.h"
43 #include "event.h"
44 #include "os_event.h"
45 #include "graphics.h"
46 #include "os_graphics.h"
47 #include "skin_common.h"
48 #include "theme.h"
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     gc = gdk_gc_new( gwnd );
74
75     LButtonDown = false;
76     RButtonDown = false;
77 /*
78     // Set position parameters
79     CursorPos    = new POINT;
80     WindowPos    = new POINT;
81
82     // Create Tool Tip Window
83     ToolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
84         WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
85         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
86         hWnd, 0, GetModuleHandle( NULL ), 0);
87
88     // Create Tool Tip infos
89     ToolTipInfo.cbSize = sizeof(TOOLINFO);
90     ToolTipInfo.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
91     ToolTipInfo.hwnd = hWnd;
92     ToolTipInfo.hinst = GetModuleHandle( NULL );
93     ToolTipInfo.uId = (unsigned int)hWnd;
94     ToolTipInfo.lpszText = NULL;
95     ToolTipInfo.rect.left = ToolTipInfo.rect.top = 0;
96         ToolTipInfo.rect.right = ToolTipInfo.rect.bottom = 0;
97
98     SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
99                     (LPARAM)(LPTOOLINFO) &ToolTipInfo );
100
101     // Drag & drop
102     if( DragDrop )
103     {
104         // Initialize the OLE library
105         OleInitialize( NULL );
106         DropTarget = (LPDROPTARGET) new GTK2DropObject();
107         // register the listview as a drop target
108         RegisterDragDrop( hWnd, DropTarget );
109     }
110 */
111     // Create Tool Tip window
112 /*    GdkWindowAttr attr;
113     attr.event_mask = GDK_ALL_EVENTS_MASK;
114     attr.width = 100;
115     attr.height = 100;
116     attr.window_type = GDK_WINDOW_CHILD;
117     attr.wclass = GDK_INPUT_OUTPUT;
118     gint mask = 0;
119     ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
120
121 }
122 //---------------------------------------------------------------------------
123 GTK2Window::~GTK2Window()
124 {
125 /*    delete CursorPos;
126     delete WindowPos;
127
128     if( hWnd != NULL )
129     {
130         DestroyWindow( hWnd );
131     }
132     if( ToolTipWindow != NULL )
133     {
134         DestroyWindow( ToolTipWindow );
135     }
136     if( DragDrop )
137     {
138         // Remove the listview from the list of drop targets
139         RevokeDragDrop( hWnd );
140         DropTarget->Release();
141         // Uninitialize the OLE library
142         OleUninitialize();
143     }
144 */
145 }
146 //---------------------------------------------------------------------------
147 void GTK2Window::OSShow( bool show )
148 {
149     if( show )
150     {
151         gdk_window_show( gWnd );
152     }
153     else
154     {
155         gdk_window_hide( gWnd );
156     }
157 }
158 //---------------------------------------------------------------------------
159 bool GTK2Window::ProcessOSEvent( Event *evt )
160 {
161     unsigned int msg = evt->GetMessage();
162     unsigned int p1  = evt->GetParam1();
163     int          p2  = evt->GetParam2();
164
165     switch( msg )
166     {
167         case GDK_EXPOSE:
168             RefreshFromImage( 0, 0, Width, Height );
169             return true;
170
171
172         case GDK_MOTION_NOTIFY:
173             if( LButtonDown )
174                 MouseMove( (int)( (GdkEventButton *)p2 )->x,
175                            (int)( (GdkEventButton *)p2 )->y, 1 );
176             else if( RButtonDown )
177                 MouseMove( (int)( (GdkEventButton *)p2 )->x,
178                            (int)( (GdkEventButton *)p2 )->y, 2 );
179             else
180                 MouseMove( (int)( (GdkEventButton *)p2 )->x,
181                            (int)( (GdkEventButton *)p2 )->y, 0 );
182             gdk_window_get_pointer( gWnd, 0, 0, 0 );
183             return true;
184
185
186         case GDK_BUTTON_PRESS:
187             switch( ( (GdkEventButton *)p2 )->button )
188             {
189                 case 1:
190                     // Left button
191                     LButtonDown = true;
192                     MouseDown( (int)( (GdkEventButton *)p2 )->x,
193                                (int)( (GdkEventButton *)p2 )->y, 1 );
194                     break;
195
196                 case 3:
197                     // Right button
198                     RButtonDown = true;
199                     MouseDown( (int)( (GdkEventButton *)p2 )->x,
200                                (int)( (GdkEventButton *)p2 )->y, 2 );
201                     break;
202
203                 default:
204                     break;
205             }
206             return true;
207
208         case GDK_BUTTON_RELEASE:
209             switch( ( (GdkEventButton *)p2 )->button )
210             {
211                 case 1:
212                     // Left button
213                     LButtonDown = false;
214                     MouseUp( (int)( (GdkEventButton *)p2 )->x,
215                              (int)( (GdkEventButton *)p2 )->y, 1 );
216                     break;
217
218                 case 3:
219                     // Right button
220                     RButtonDown = false;
221                     MouseUp( (int)( (GdkEventButton *)p2 )->x,
222                              (int)( (GdkEventButton *)p2 )->y, 2 );
223                     break;
224
225                 default:
226                     break;
227             }
228             return true;
229
230         case GDK_LEAVE_NOTIFY:
231             OSAPI_PostMessage( this, WINDOW_LEAVE, -1, -1 );
232             return true;
233 /*
234         case WM_RBUTTONDOWN:
235             MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
236             return true;
237
238         case WM_RBUTTONUP:
239             MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
240             return true;
241
242         case WM_LBUTTONDBLCLK:
243             MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
244             return true;
245
246 */
247         default:
248             return false;
249     }
250 }
251 //---------------------------------------------------------------------------
252 void GTK2Window::SetTransparency( int Value )
253 {
254 /*    if( Value > -1 )
255         Alpha = Value;
256     SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
257     UpdateWindow( hWnd );*/
258 }
259 //---------------------------------------------------------------------------
260 void GTK2Window::RefreshFromImage( int x, int y, int w, int h )
261 {
262     // Initialize painting
263 /*    HDC DC = GetWindowDC( hWnd );
264
265     // Draw image on window
266     BitBlt( DC, x, y, w, h, ( (GTK2Graphics *)Image )->GetImageHandle(),
267             x, y, SRCCOPY );
268
269     // Release window device context
270     ReleaseDC( hWnd, DC );
271
272 */
273
274     gdk_draw_drawable( gWnd, gc, (( GTK2Graphics* )Image )->GetImage(),
275             x, y, x, y, w, h );
276 }
277 //---------------------------------------------------------------------------
278 void GTK2Window::WindowManualMove()
279 {
280     // Get mouse cursor position
281     int x, y;
282     gdk_window_get_pointer( gdk_get_default_root_window(), &x, &y, NULL );
283
284     // Move window and chek for magnetism
285     p_intf->p_sys->p_theme->MoveSkinMagnet( this,
286         WindowX + x - CursorX, WindowY + y - CursorY );
287
288     fprintf( stderr, "---------\n" );
289 }
290 //---------------------------------------------------------------------------
291 void GTK2Window::WindowManualMoveInit()
292 {
293     gdk_window_get_pointer( gdk_get_default_root_window(), &CursorX, &CursorY,
294                             NULL );
295     WindowX = Left;
296     WindowY = Top;
297 }
298 //---------------------------------------------------------------------------
299 void GTK2Window::Move( int left, int top )
300 {
301     Left = left;
302     Top  = top;
303     gdk_window_move( gWnd, left, top );
304 }
305 //---------------------------------------------------------------------------
306 void GTK2Window::Size( int width, int height )
307 {
308     Width  = width;
309     Height = height;
310     gdk_window_resize( gWnd, width, height );
311 }
312 //---------------------------------------------------------------------------
313 void GTK2Window::ChangeToolTipText( string text )
314 {
315 /*    if( text == "none" )
316     {
317         if( ToolTipText != "none" )
318         {
319             ToolTipText = "none";
320             ToolTipInfo.lpszText = NULL;
321             SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
322         }
323     }
324     else
325     {
326         if( text != ToolTipText )
327         {
328             ToolTipText = text;
329             ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
330             SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
331             SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
332                              (LPARAM)(LPTOOLINFO)&ToolTipInfo );
333         }
334     }
335 */
336 }
337 //---------------------------------------------------------------------------
338
339 #endif