49c36f1043f20226ee30488ad9150ba3fbb6b002
[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.10 2003/04/15 11:46:19 ipkiss 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     fprintf( stderr, "salut %li\n", evt->GetMessage() );
166
167     switch( msg )
168     {
169         case GDK_EXPOSE:
170             RefreshFromImage( 0, 0, Width, Height );
171             return true;
172
173
174         case GDK_MOTION_NOTIFY:
175 //            TRACKMOUSEEVENT TrackEvent;
176 //            TrackEvent.cbSize      = sizeof( TRACKMOUSEEVENT );
177 //            TrackEvent.dwFlags     = TME_LEAVE;
178 //            TrackEvent.hwndTrack   = hWnd;
179 //            TrackEvent.dwHoverTime = 1;
180 //            TrackMouseEvent( &TrackEvent );
181             if( LButtonDown )
182                 MouseMove( ((GdkEventButton *)p2)->x_root, ((GdkEventButton *)p2)->y_root,
183                            1 );
184             else if( RButtonDown )
185                 MouseMove( ((GdkEventButton *)p2)->x_root, ((GdkEventButton *)p2)->y_root,
186                            2 );
187             else
188                 MouseMove( ((GdkEventButton *)p2)->x_root, ((GdkEventButton *)p2)->y_root,
189                            0 );
190
191             return true;
192
193
194         case GDK_BUTTON_PRESS:
195             switch( ((GdkEventButton *)p2)->button )
196             {
197                 case 1:
198                     // Left button
199                     LButtonDown = true;
200                     MouseDown( ((GdkEventButton *)p2)->x_root,
201                                ((GdkEventButton *)p2)->y_root, 1 );
202                     break;
203                 case 3:
204                     // Right button
205                     RButtonDown = true;
206                     MouseDown( ((GdkEventButton *)p2)->x_root,
207                                ((GdkEventButton *)p2)->y_root, 2 );
208                     break;
209                 default:
210                     break;
211             }
212             return true;
213
214         case GDK_BUTTON_RELEASE:
215             switch( ((GdkEventButton *)p2)->button )
216             {
217                 case 1:
218                     // Left button
219                     LButtonDown = false;
220                     MouseUp( ((GdkEventButton *)p2)->x_root,
221                              ((GdkEventButton *)p2)->y_root, 1 );
222                     break;
223                 case 3:
224                     // Right button
225                     RButtonDown = false;
226                     MouseUp( ((GdkEventButton *)p2)->x_root,
227                              ((GdkEventButton *)p2)->y_root, 2 );
228                     break;
229                 default:
230                     break;
231             }
232             return true;
233
234 /*
235         case WM_RBUTTONDOWN:
236             MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
237             return true;
238
239         case WM_RBUTTONUP:
240             MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
241             return true;
242
243         case WM_LBUTTONDBLCLK:
244             MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
245             return true;
246
247         case WM_MOUSELEAVE:
248             OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
249             return true;
250 */
251         default:
252             return false;
253     }
254 }
255 //---------------------------------------------------------------------------
256 void GTK2Window::SetTransparency( int Value )
257 {
258 /*    if( Value > -1 )
259         Alpha = Value;
260     SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
261     UpdateWindow( hWnd );*/
262 }
263 //---------------------------------------------------------------------------
264 void GTK2Window::RefreshFromImage( int x, int y, int w, int h )
265 {
266     // Initialize painting
267 /*    HDC DC = GetWindowDC( hWnd );
268
269     // Draw image on window
270     BitBlt( DC, x, y, w, h, ( (GTK2Graphics *)Image )->GetImageHandle(),
271             x, y, SRCCOPY );
272
273     // Release window device context
274     ReleaseDC( hWnd, DC );
275
276 */
277
278  fprintf(stderr, "window %d %d %d %d\n", x, y, w, h);
279     gdk_draw_drawable( gWnd, gc, (( GTK2Graphics* )Image )->GetImage(),
280             x, y, x, y, w, h );
281 }
282 //---------------------------------------------------------------------------
283 void GTK2Window::WindowManualMove()
284 {
285     // Get mouse cursor position
286     int x, y;
287     gdk_window_get_pointer( gdk_get_default_root_window(), &x, &y, NULL );
288
289     // Move window and chek for magnetism
290     p_intf->p_sys->p_theme->MoveSkinMagnet( this,
291         WindowX + x - CursorX, WindowY + y - CursorY );
292
293     fprintf( stderr, "---------\n" );
294 }
295 //---------------------------------------------------------------------------
296 void GTK2Window::WindowManualMoveInit()
297 {
298     gdk_window_get_pointer( gdk_get_default_root_window(), &CursorX, &CursorY,
299                             NULL );
300     WindowX = Left;
301     WindowY = Top;
302 }
303 //---------------------------------------------------------------------------
304 void GTK2Window::Move( int left, int top )
305 {
306     Left = left;
307     Top  = top;
308     gdk_window_move( gWnd, left, top );
309 }
310 //---------------------------------------------------------------------------
311 void GTK2Window::Size( int width, int height )
312 {
313     Width  = width;
314     Height = height;
315     gdk_window_resize( gWnd, width, height );
316 }
317 //---------------------------------------------------------------------------
318 void GTK2Window::ChangeToolTipText( string text )
319 {
320 /*    if( text == "none" )
321     {
322         if( ToolTipText != "none" )
323         {
324             ToolTipText = "none";
325             ToolTipInfo.lpszText = NULL;
326             SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
327         }
328     }
329     else
330     {
331         if( text != ToolTipText )
332         {
333             ToolTipText = text;
334             ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
335             SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
336             SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
337                              (LPARAM)(LPTOOLINFO)&ToolTipInfo );
338         }
339     }
340 */
341 }
342 //---------------------------------------------------------------------------
343
344 #endif