* skeleton of X11 skins
[vlc.git] / modules / gui / skins / x11 / x11_window.cpp
1 /*****************************************************************************
2  * x11_window.cpp: X11 implementation of the Window class
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: x11_window.cpp,v 1.1 2003/04/28 14:32:57 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 #ifdef X11_SKINS
26
27 //--- GENERAL ---------------------------------------------------------------
28 //#include <math.h>
29
30 //--- VLC -------------------------------------------------------------------
31 #include <vlc/intf.h>
32
33 //--- X11 -------------------------------------------------------------------
34 #include <X11/Xlib.h>
35
36 //--- SKIN ------------------------------------------------------------------
37 #include "../os_api.h"
38 #include "../src/anchor.h"
39 #include "../controls/generic.h"
40 #include "../src/window.h"
41 #include "../os_window.h"
42 #include "../src/event.h"
43 #include "../os_event.h"
44 #include "../src/graphics.h"
45 #include "../os_graphics.h"
46 #include "../src/skin_common.h"
47 #include "../src/theme.h"
48
49
50 //---------------------------------------------------------------------------
51 // Skinable Window
52 //---------------------------------------------------------------------------
53 X11Window::X11Window( intf_thread_t *p_intf, Window wnd, int x, int y,
54     bool visible, int transition, int normalalpha, int movealpha,
55     bool dragdrop, string name )
56     : SkinWindow( p_intf, x, y, visible, transition, normalalpha, movealpha,
57               dragdrop )
58 {
59     // Set handles
60     Wnd           = wnd;
61 //    gc = gdk_gc_new( gwnd );
62
63     Name        = name;
64
65     LButtonDown = false;
66     RButtonDown = false;
67
68     // Removing fading effect
69     Transition  = 0;
70 /*
71     // Set position parameters
72     CursorPos    = new POINT;
73     WindowPos    = new POINT;
74
75     // Create Tool Tip Window
76     ToolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
77         WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
78         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
79         hWnd, 0, GetModuleHandle( NULL ), 0);
80
81     // Create Tool Tip infos
82     ToolTipInfo.cbSize = sizeof(TOOLINFO);
83     ToolTipInfo.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
84     ToolTipInfo.hwnd = hWnd;
85     ToolTipInfo.hinst = GetModuleHandle( NULL );
86     ToolTipInfo.uId = (unsigned int)hWnd;
87     ToolTipInfo.lpszText = NULL;
88     ToolTipInfo.rect.left = ToolTipInfo.rect.top = 0;
89         ToolTipInfo.rect.right = ToolTipInfo.rect.bottom = 0;
90
91     SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
92                     (LPARAM)(LPTOOLINFO) &ToolTipInfo );
93 */
94     if( DragDrop )
95     {
96         // register the listview as a drop target
97         DropObject = new X11DropObject( p_intf );
98     //    gdk_window_register_dnd( gwnd );
99     }
100
101     // Create Tool Tip window
102 /*    GdkWindowAttr attr;
103     attr.event_mask = GDK_ALL_EVENTS_MASK;
104     attr.width = 100;
105     attr.height = 100;
106     attr.window_type = GDK_WINDOW_CHILD;
107     attr.wclass = GDK_INPUT_OUTPUT;
108     gint mask = 0;
109     ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
110
111 }
112 //---------------------------------------------------------------------------
113 X11Window::~X11Window()
114 {
115 /*    delete CursorPos;
116     delete WindowPos;
117
118     if( hWnd != NULL )
119     {
120         DestroyWindow( hWnd );
121     }
122     if( ToolTipWindow != NULL )
123     {
124         DestroyWindow( ToolTipWindow );
125     }
126     if( DragDrop )
127     {
128         // Remove the listview from the list of drop targets
129         RevokeDragDrop( hWnd );
130         DropTarget->Release();
131         // Uninitialize the OLE library
132         OleUninitialize();
133     }*/
134  /*   if( gWnd )
135     {
136         gdk_window_destroy( gWnd );
137     }*/
138 }
139 //---------------------------------------------------------------------------
140 void X11Window::OSShow( bool show )
141 {
142     if( show )
143     {
144 /*        gdk_window_show( gWnd );
145         gdk_window_move( gWnd, Left, Top );*/
146     }
147     else
148     {
149 /*        gdk_window_hide( gWnd );*/
150     }
151 }
152 //---------------------------------------------------------------------------
153 bool X11Window::ProcessOSEvent( Event *evt )
154 {
155     unsigned int msg = evt->GetMessage();
156     unsigned int p1  = evt->GetParam1();
157     int          p2  = evt->GetParam2();
158 /*
159     switch( msg )
160     {
161         case GDK_EXPOSE:
162             RefreshFromImage( 0, 0, Width, Height );
163             return true;
164  
165         case GDK_MOTION_NOTIFY:
166             if( LButtonDown )
167                 MouseMove( (int)( (GdkEventButton *)p2 )->x,
168                            (int)( (GdkEventButton *)p2 )->y, 1 );
169             else if( RButtonDown )
170                 MouseMove( (int)( (GdkEventButton *)p2 )->x,
171                            (int)( (GdkEventButton *)p2 )->y, 2 );
172             else
173                 MouseMove( (int)( (GdkEventButton *)p2 )->x,
174                            (int)( (GdkEventButton *)p2 )->y, 0 );
175             gdk_window_get_pointer( gWnd, 0, 0, 0 );
176             return true;
177
178
179         case GDK_BUTTON_PRESS:
180             // Raise all the windows
181             for( list<SkinWindow *>::const_iterator win = 
182                     p_intf->p_sys->p_theme->WindowList.begin();
183                     win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
184             {
185                 gdk_window_raise( ( (X11Window *)(*win) )->GetHandle() );
186             }
187           
188             switch( ( (GdkEventButton *)p2 )->button )
189             {
190                 case 1:
191                     // Left button
192                     LButtonDown = true;
193                     MouseDown( (int)( (GdkEventButton *)p2 )->x,
194                                (int)( (GdkEventButton *)p2 )->y, 1 );
195                     break;
196
197                 case 3:
198                     // Right button
199                     RButtonDown = true;
200                     MouseDown( (int)( (GdkEventButton *)p2 )->x,
201                                (int)( (GdkEventButton *)p2 )->y, 2 );
202                     break;
203
204                 default:
205                     break;
206             }
207             return true;
208
209         case GDK_BUTTON_RELEASE:
210             switch( ( (GdkEventButton *)p2 )->button )
211             {
212                 case 1:
213                     // Left button
214                     LButtonDown = false;
215                     MouseUp( (int)( (GdkEventButton *)p2 )->x,
216                              (int)( (GdkEventButton *)p2 )->y, 1 );
217                     break;
218
219                 case 3:
220                     // Right button
221                     RButtonDown = false;
222                     MouseUp( (int)( (GdkEventButton *)p2 )->x,
223                              (int)( (GdkEventButton *)p2 )->y, 2 );
224                     break;
225
226                 default:
227                     break;
228             }
229             return true;
230
231         case GDK_LEAVE_NOTIFY:
232             OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
233             return true;
234
235         case GDK_2BUTTON_PRESS:
236             MouseDblClick( (int)( (GdkEventButton *)p2 )->x,
237                            (int)( (GdkEventButton *)p2 )->y, 1 );
238             return true;
239
240         case GDK_DROP_START:
241             DropObject->HandleDropStart( ( (GdkEventDND *)p2 )->context );
242             return true;
243
244         case GDK_SCROLL:
245             switch( ( (GdkEventScroll *)p2 )->direction )
246             {
247                 case GDK_SCROLL_UP:
248                     MouseScroll( ( (GdkEventScroll *)p2 )->x,
249                                  ( (GdkEventScroll *)p2 )->y,
250                                  MOUSE_SCROLL_UP);
251                     break;
252                 case GDK_SCROLL_DOWN:
253                     MouseScroll( ( (GdkEventScroll *)p2 )->x,
254                                  ( (GdkEventScroll *)p2 )->y,
255                                  MOUSE_SCROLL_DOWN);
256                     break;
257             }
258             return true;
259
260         default:
261             return false;
262     }*/
263 }
264 //---------------------------------------------------------------------------
265 void X11Window::SetTransparency( int Value )
266 {
267 /*    if( Value > -1 )
268         Alpha = Value;
269     SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
270     UpdateWindow( hWnd );*/
271 }
272 //---------------------------------------------------------------------------
273 void X11Window::RefreshFromImage( int x, int y, int w, int h )
274 {
275     // Initialize painting
276 /*    HDC DC = GetWindowDC( hWnd );
277
278     // Draw image on window
279     BitBlt( DC, x, y, w, h, ( (X11Graphics *)Image )->GetImageHandle(),
280             x, y, SRCCOPY );
281
282     // Release window device context
283     ReleaseDC( hWnd, DC );
284
285 */ 
286 /*    GdkDrawable *drawable = (( X11Graphics* )Image )->GetImage();
287     GdkImage *image = gdk_drawable_get_image( drawable, 0, 0, Width, Height );
288     
289     gdk_draw_drawable( gWnd, gc, drawable, x, y, x, y, w, h );
290
291     // Mask for transparency
292     GdkRegion *region = gdk_region_new();
293     for( int line = 0; line < Height; line++ )
294     {
295         int start = 0, end = 0;
296         while( start < Width )
297         {
298             while( start < Width && gdk_image_get_pixel( image, start, line ) == 0 )
299             {
300                 start++;
301             } 
302             end = start;
303             while( end < Width && gdk_image_get_pixel( image, end, line ) != 0)
304             {
305                 end++;
306             }
307             GdkRectangle rect;
308             rect.x = start;
309             rect.y = line;
310             rect.width = end - start + 1;
311             rect.height = 1;
312             GdkRegion *rectReg = gdk_region_rectangle( &rect );
313             gdk_region_union( region, rectReg );
314             gdk_region_destroy( rectReg );
315             start = end + 1;
316         }
317     }
318     gdk_window_shape_combine_region( gWnd, region, 0, 0 );
319     gdk_region_destroy( region );*/
320 }
321 //---------------------------------------------------------------------------
322 void X11Window::WindowManualMove()
323 {
324     // Get mouse cursor position
325     int x, y;
326     OSAPI_GetMousePos( x, y );
327
328     // Move window and chek for magnetism
329     p_intf->p_sys->p_theme->MoveSkinMagnet( this,
330         WindowX + x - CursorX, WindowY + y - CursorY );
331
332 }
333 //---------------------------------------------------------------------------
334 void X11Window::WindowManualMoveInit()
335 {
336 /*    gdk_window_get_pointer( gdk_get_default_root_window(), &CursorX, &CursorY,
337                             NULL );*/
338     WindowX = Left;
339     WindowY = Top;
340 }
341 //---------------------------------------------------------------------------
342 void X11Window::Move( int left, int top )
343 {
344     Left = left;
345     Top  = top;
346 /*   gdk_window_move( gWnd, left, top );*/
347 }
348 //---------------------------------------------------------------------------
349 void X11Window::Size( int width, int height )
350 {
351     Width  = width;
352     Height = height;
353 /*    gdk_window_resize( gWnd, width, height );*/
354 }
355 //---------------------------------------------------------------------------
356 void X11Window::ChangeToolTipText( string text )
357 {
358 /*    if( text == "none" )
359     {
360         if( ToolTipText != "none" )
361         {
362             ToolTipText = "none";
363             ToolTipInfo.lpszText = NULL;
364             SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
365         }
366     }
367     else
368     {
369         if( text != ToolTipText )
370         {
371             ToolTipText = text;
372             ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
373             SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
374             SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
375                              (LPARAM)(LPTOOLINFO)&ToolTipInfo );
376         }
377     }
378 */
379 }
380 //---------------------------------------------------------------------------
381
382 #endif