1 /*****************************************************************************
2 * x11_window.cpp: X11 implementation of the Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_window.cpp,v 1.11 2003/06/07 00:36:28 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 -------------------------------------------------------------------
35 #include <X11/extensions/shape.h>
37 //--- SKIN ------------------------------------------------------------------
38 #include "../os_api.h"
39 #include "../src/anchor.h"
40 #include "../controls/generic.h"
41 #include "../src/window.h"
42 #include "../os_window.h"
43 #include "../src/event.h"
44 #include "../os_event.h"
45 #include "../src/graphics.h"
46 #include "../os_graphics.h"
47 #include "../src/skin_common.h"
48 #include "../src/theme.h"
49 #include "../os_theme.h"
52 //---------------------------------------------------------------------------
54 //---------------------------------------------------------------------------
55 X11Window::X11Window( intf_thread_t *p_intf, Window wnd, int x, int y,
56 bool visible, int transition, int normalalpha, int movealpha,
57 bool dragdrop, string name )
58 : SkinWindow( p_intf, x, y, visible, transition, normalalpha, movealpha,
64 display = p_intf->p_sys->display;
65 int screen = DefaultScreen( display );
67 Gc = DefaultGC( display, screen );
74 // Removing fading effect
77 // Set position parameters
78 CursorPos = new POINT;
79 WindowPos = new POINT;
81 // Create Tool Tip Window
82 ToolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
83 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
84 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
85 hWnd, 0, GetModuleHandle( NULL ), 0);
87 // Create Tool Tip infos
88 ToolTipInfo.cbSize = sizeof(TOOLINFO);
89 ToolTipInfo.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
90 ToolTipInfo.hwnd = hWnd;
91 ToolTipInfo.hinst = GetModuleHandle( NULL );
92 ToolTipInfo.uId = (unsigned int)hWnd;
93 ToolTipInfo.lpszText = NULL;
94 ToolTipInfo.rect.left = ToolTipInfo.rect.top = 0;
95 ToolTipInfo.rect.right = ToolTipInfo.rect.bottom = 0;
97 SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
98 (LPARAM)(LPTOOLINFO) &ToolTipInfo );
103 // register the listview as a drop target
104 DropObject = new X11DropObject( p_intf );
105 // gdk_window_register_dnd( gwnd );
108 // Create Tool Tip window
109 ToolTipWindow = XCreateSimpleWindow( display, wnd, 0, 0, 1, 1, 0, 0, 0 );
111 // Double-click handling
115 // TODO: can be retrieved somewhere ?
119 //---------------------------------------------------------------------------
120 X11Window::~X11Window()
127 DestroyWindow( hWnd );
129 XDestroyWindow( display, ToolTipWindow );
133 // Remove the listview from the list of drop targets
134 RevokeDragDrop( hWnd );
135 DropTarget->Release();
136 // Uninitialize the OLE library
141 gdk_window_destroy( gWnd );
144 //---------------------------------------------------------------------------
145 void X11Window::OSShow( bool show )
150 XMapWindow( display, Wnd );
151 XMoveWindow( display, Wnd, Left, Top );
157 XUnmapWindow( display, Wnd );
161 //---------------------------------------------------------------------------
162 bool X11Window::ProcessOSEvent( Event *evt )
164 unsigned int msg = evt->GetMessage();
165 unsigned int p1 = evt->GetParam1();
166 int p2 = evt->GetParam2();
173 RefreshFromImage( 0, 0, Width, Height );
178 MouseMove( (int)( (XMotionEvent *)p2 )->x,
179 (int)( (XMotionEvent *)p2 )->y, 1 );
180 else if( RButtonDown )
181 MouseMove( (int)( (XMotionEvent *)p2 )->x,
182 (int)( (XMotionEvent *)p2 )->y, 2 );
184 MouseMove( (int)( (XMotionEvent *)p2 )->x,
185 (int)( (XMotionEvent *)p2 )->y, 0 );
190 // Raise all the windows
191 for( list<SkinWindow *>::const_iterator win =
192 p_intf->p_sys->p_theme->WindowList.begin();
193 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
196 XRaiseWindow( display, ( (X11Window *)(*win) )->GetHandle() );
200 switch( ( (XButtonEvent *)p2 )->button )
204 time = OSAPI_GetTime();
205 OSAPI_GetMousePos( posX, posY );
206 if( time - ClickedTime < DblClickDelay &&
207 posX == ClickedX && posY == ClickedY )
211 MouseDblClick( (int)( (XButtonEvent *)p2 )->x,
212 (int)( (XButtonEvent *)p2 )->y, 1 );
220 MouseDown( (int)( (XButtonEvent *)p2 )->x,
221 (int)( (XButtonEvent *)p2 )->y, 1 );
228 MouseDown( (int)( (XButtonEvent *)p2 )->x,
229 (int)( (XButtonEvent *)p2 )->y, 2 );
238 switch( ( (XButtonEvent *)p2 )->button )
243 MouseUp( (int)( (XButtonEvent *)p2 )->x,
244 (int)( (XButtonEvent *)p2 )->y, 1 );
250 MouseUp( (int)( (XButtonEvent *)p2 )->x,
251 (int)( (XButtonEvent *)p2 )->y, 2 );
256 MouseScroll( (int)( (XButtonEvent *)p2 )->x,
257 (int)( (XButtonEvent *)p2 )->y,
263 MouseScroll( (int)( (XButtonEvent *)p2 )->x,
264 (int)( (XButtonEvent *)p2 )->y,
274 OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
277 /* case GDK_DROP_START:
278 DropObject->HandleDropStart( ( (GdkEventDND *)p2 )->context );
285 //---------------------------------------------------------------------------
286 void X11Window::SetTransparency( int Value )
290 SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
291 UpdateWindow( hWnd );*/
293 //---------------------------------------------------------------------------
294 void X11Window::RefreshFromImage( int x, int y, int w, int h )
296 Drawable drawable = (( X11Graphics* )Image )->GetImage();
299 XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y );
301 XImage *image = XGetImage( display, drawable, 0, 0, Width, Height,
302 AllPlanes, ZPixmap );
304 // Mask for transparency
305 Region region = XCreateRegion();
306 for( int line = 0; line < Height; line++ )
308 int start = 0, end = 0;
309 while( start < Width )
311 while( start < Width && XGetPixel( image, start, line ) == 0 )
316 while( end < Width && XGetPixel( image, end, line ) != 0)
323 rect.width = end - start + 1;
325 Region newRegion = XCreateRegion();
326 XUnionRectWithRegion( &rect, region, newRegion );
327 XDestroyRegion( region );
332 XShapeCombineRegion( display, Wnd, ShapeBounding, 0, 0, region, ShapeSet );
333 XDestroyRegion( region );
338 //---------------------------------------------------------------------------
339 void X11Window::WindowManualMove()
341 // Get mouse cursor position
343 OSAPI_GetMousePos( x, y );
345 // Move window and chek for magnetism
346 p_intf->p_sys->p_theme->MoveSkinMagnet( this,
347 WindowX + x - CursorX, WindowY + y - CursorY );
350 //---------------------------------------------------------------------------
351 void X11Window::WindowManualMoveInit()
353 OSAPI_GetMousePos( CursorX, CursorY );
357 //---------------------------------------------------------------------------
358 void X11Window::Move( int left, int top )
362 XMoveWindow( display, Wnd, left, top );
364 //---------------------------------------------------------------------------
365 void X11Window::Size( int width, int height )
369 XResizeWindow( display, Wnd, width, height );
371 //---------------------------------------------------------------------------
372 void X11Window::ChangeToolTipText( string text )
376 if( ToolTipText != "none" )
378 ToolTipText = "none";
379 // ToolTipInfo.lpszText = NULL;
380 // SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
385 if( text != ToolTipText )
388 // ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
389 /* SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
390 SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
391 (LPARAM)(LPTOOLINFO)&ToolTipInfo );*/
395 //---------------------------------------------------------------------------