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 $
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 //--- GENERAL ---------------------------------------------------------------
30 //--- VLC -------------------------------------------------------------------
33 //--- X11 -------------------------------------------------------------------
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"
50 //---------------------------------------------------------------------------
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,
61 // gc = gdk_gc_new( gwnd );
68 // Removing fading effect
71 // Set position parameters
72 CursorPos = new POINT;
73 WindowPos = new POINT;
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);
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;
91 SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
92 (LPARAM)(LPTOOLINFO) &ToolTipInfo );
96 // register the listview as a drop target
97 DropObject = new X11DropObject( p_intf );
98 // gdk_window_register_dnd( gwnd );
101 // Create Tool Tip window
102 /* GdkWindowAttr attr;
103 attr.event_mask = GDK_ALL_EVENTS_MASK;
106 attr.window_type = GDK_WINDOW_CHILD;
107 attr.wclass = GDK_INPUT_OUTPUT;
109 ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
112 //---------------------------------------------------------------------------
113 X11Window::~X11Window()
120 DestroyWindow( hWnd );
122 if( ToolTipWindow != NULL )
124 DestroyWindow( ToolTipWindow );
128 // Remove the listview from the list of drop targets
129 RevokeDragDrop( hWnd );
130 DropTarget->Release();
131 // Uninitialize the OLE library
136 gdk_window_destroy( gWnd );
139 //---------------------------------------------------------------------------
140 void X11Window::OSShow( bool show )
144 /* gdk_window_show( gWnd );
145 gdk_window_move( gWnd, Left, Top );*/
149 /* gdk_window_hide( gWnd );*/
152 //---------------------------------------------------------------------------
153 bool X11Window::ProcessOSEvent( Event *evt )
155 unsigned int msg = evt->GetMessage();
156 unsigned int p1 = evt->GetParam1();
157 int p2 = evt->GetParam2();
162 RefreshFromImage( 0, 0, Width, Height );
165 case GDK_MOTION_NOTIFY:
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 );
173 MouseMove( (int)( (GdkEventButton *)p2 )->x,
174 (int)( (GdkEventButton *)p2 )->y, 0 );
175 gdk_window_get_pointer( gWnd, 0, 0, 0 );
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++ )
185 gdk_window_raise( ( (X11Window *)(*win) )->GetHandle() );
188 switch( ( (GdkEventButton *)p2 )->button )
193 MouseDown( (int)( (GdkEventButton *)p2 )->x,
194 (int)( (GdkEventButton *)p2 )->y, 1 );
200 MouseDown( (int)( (GdkEventButton *)p2 )->x,
201 (int)( (GdkEventButton *)p2 )->y, 2 );
209 case GDK_BUTTON_RELEASE:
210 switch( ( (GdkEventButton *)p2 )->button )
215 MouseUp( (int)( (GdkEventButton *)p2 )->x,
216 (int)( (GdkEventButton *)p2 )->y, 1 );
222 MouseUp( (int)( (GdkEventButton *)p2 )->x,
223 (int)( (GdkEventButton *)p2 )->y, 2 );
231 case GDK_LEAVE_NOTIFY:
232 OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
235 case GDK_2BUTTON_PRESS:
236 MouseDblClick( (int)( (GdkEventButton *)p2 )->x,
237 (int)( (GdkEventButton *)p2 )->y, 1 );
241 DropObject->HandleDropStart( ( (GdkEventDND *)p2 )->context );
245 switch( ( (GdkEventScroll *)p2 )->direction )
248 MouseScroll( ( (GdkEventScroll *)p2 )->x,
249 ( (GdkEventScroll *)p2 )->y,
252 case GDK_SCROLL_DOWN:
253 MouseScroll( ( (GdkEventScroll *)p2 )->x,
254 ( (GdkEventScroll *)p2 )->y,
264 //---------------------------------------------------------------------------
265 void X11Window::SetTransparency( int Value )
269 SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
270 UpdateWindow( hWnd );*/
272 //---------------------------------------------------------------------------
273 void X11Window::RefreshFromImage( int x, int y, int w, int h )
275 // Initialize painting
276 /* HDC DC = GetWindowDC( hWnd );
278 // Draw image on window
279 BitBlt( DC, x, y, w, h, ( (X11Graphics *)Image )->GetImageHandle(),
282 // Release window device context
283 ReleaseDC( hWnd, DC );
286 /* GdkDrawable *drawable = (( X11Graphics* )Image )->GetImage();
287 GdkImage *image = gdk_drawable_get_image( drawable, 0, 0, Width, Height );
289 gdk_draw_drawable( gWnd, gc, drawable, x, y, x, y, w, h );
291 // Mask for transparency
292 GdkRegion *region = gdk_region_new();
293 for( int line = 0; line < Height; line++ )
295 int start = 0, end = 0;
296 while( start < Width )
298 while( start < Width && gdk_image_get_pixel( image, start, line ) == 0 )
303 while( end < Width && gdk_image_get_pixel( image, end, line ) != 0)
310 rect.width = end - start + 1;
312 GdkRegion *rectReg = gdk_region_rectangle( &rect );
313 gdk_region_union( region, rectReg );
314 gdk_region_destroy( rectReg );
318 gdk_window_shape_combine_region( gWnd, region, 0, 0 );
319 gdk_region_destroy( region );*/
321 //---------------------------------------------------------------------------
322 void X11Window::WindowManualMove()
324 // Get mouse cursor position
326 OSAPI_GetMousePos( x, y );
328 // Move window and chek for magnetism
329 p_intf->p_sys->p_theme->MoveSkinMagnet( this,
330 WindowX + x - CursorX, WindowY + y - CursorY );
333 //---------------------------------------------------------------------------
334 void X11Window::WindowManualMoveInit()
336 /* gdk_window_get_pointer( gdk_get_default_root_window(), &CursorX, &CursorY,
341 //---------------------------------------------------------------------------
342 void X11Window::Move( int left, int top )
346 /* gdk_window_move( gWnd, left, top );*/
348 //---------------------------------------------------------------------------
349 void X11Window::Size( int width, int height )
353 /* gdk_window_resize( gWnd, width, height );*/
355 //---------------------------------------------------------------------------
356 void X11Window::ChangeToolTipText( string text )
358 /* if( text == "none" )
360 if( ToolTipText != "none" )
362 ToolTipText = "none";
363 ToolTipInfo.lpszText = NULL;
364 SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
369 if( text != ToolTipText )
372 ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
373 SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
374 SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
375 (LPARAM)(LPTOOLINFO)&ToolTipInfo );
380 //---------------------------------------------------------------------------