1 /*****************************************************************************
2 * x11_window.cpp: X11 implementation of the Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_window.cpp,v 1.7 2003/05/26 02:09:27 gbazin 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"
51 //---------------------------------------------------------------------------
53 //---------------------------------------------------------------------------
54 X11Window::X11Window( intf_thread_t *p_intf, Window wnd, int x, int y,
55 bool visible, int transition, int normalalpha, int movealpha,
56 bool dragdrop, string name )
57 : SkinWindow( p_intf, x, y, visible, transition, normalalpha, movealpha,
63 display = p_intf->p_sys->display;
64 int screen = DefaultScreen( display );
66 Gc = DefaultGC( display, screen );
73 // Removing fading effect
76 // Set position parameters
77 CursorPos = new POINT;
78 WindowPos = new POINT;
80 // Create Tool Tip Window
81 ToolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
82 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
83 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
84 hWnd, 0, GetModuleHandle( NULL ), 0);
86 // Create Tool Tip infos
87 ToolTipInfo.cbSize = sizeof(TOOLINFO);
88 ToolTipInfo.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
89 ToolTipInfo.hwnd = hWnd;
90 ToolTipInfo.hinst = GetModuleHandle( NULL );
91 ToolTipInfo.uId = (unsigned int)hWnd;
92 ToolTipInfo.lpszText = NULL;
93 ToolTipInfo.rect.left = ToolTipInfo.rect.top = 0;
94 ToolTipInfo.rect.right = ToolTipInfo.rect.bottom = 0;
96 SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
97 (LPARAM)(LPTOOLINFO) &ToolTipInfo );
101 // register the listview as a drop target
102 DropObject = new X11DropObject( p_intf );
103 // gdk_window_register_dnd( gwnd );
106 // Create Tool Tip window
107 /* GdkWindowAttr attr;
108 attr.event_mask = GDK_ALL_EVENTS_MASK;
111 attr.window_type = GDK_WINDOW_CHILD;
112 attr.wclass = GDK_INPUT_OUTPUT;
114 ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
117 //fprintf(stderr, "kludge in x11_window.cpp\n");
120 //---------------------------------------------------------------------------
121 X11Window::~X11Window()
128 DestroyWindow( hWnd );
130 if( ToolTipWindow != NULL )
132 DestroyWindow( ToolTipWindow );
136 // Remove the listview from the list of drop targets
137 RevokeDragDrop( hWnd );
138 DropTarget->Release();
139 // Uninitialize the OLE library
144 gdk_window_destroy( gWnd );
147 //---------------------------------------------------------------------------
148 void X11Window::OSShow( bool show )
152 XMapWindow( display, Wnd );
153 XMoveWindow( display, Wnd, Left, Top );
157 //XWithdrawWindow( display, Wnd, 0 );
158 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();
171 RefreshFromImage( 0, 0, Width, Height );
176 MouseMove( (int)( (XMotionEvent *)p2 )->x,
177 (int)( (XMotionEvent *)p2 )->y, 1 );
178 else if( RButtonDown )
179 MouseMove( (int)( (XMotionEvent *)p2 )->x,
180 (int)( (XMotionEvent *)p2 )->y, 2 );
182 MouseMove( (int)( (XMotionEvent *)p2 )->x,
183 (int)( (XMotionEvent *)p2 )->y, 0 );
188 // Raise all the windows
189 for( list<SkinWindow *>::const_iterator win =
190 p_intf->p_sys->p_theme->WindowList.begin();
191 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
193 XRaiseWindow( display, ( (X11Window *)(*win) )->GetHandle() );
196 switch( ( (XButtonEvent *)p2 )->button )
201 MouseDown( (int)( (XButtonEvent *)p2 )->x,
202 (int)( (XButtonEvent *)p2 )->y, 1 );
208 MouseDown( (int)( (XButtonEvent *)p2 )->x,
209 (int)( (XButtonEvent *)p2 )->y, 2 );
218 switch( ( (XButtonEvent *)p2 )->button )
223 MouseUp( (int)( (XButtonEvent *)p2 )->x,
224 (int)( (XButtonEvent *)p2 )->y, 1 );
230 MouseUp( (int)( (XButtonEvent *)p2 )->x,
231 (int)( (XButtonEvent *)p2 )->y, 2 );
240 OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
243 /* case GDK_2BUTTON_PRESS:
244 MouseDblClick( (int)( (GdkEventButton *)p2 )->x,
245 (int)( (GdkEventButton *)p2 )->y, 1 );
249 DropObject->HandleDropStart( ( (GdkEventDND *)p2 )->context );
253 switch( ( (GdkEventScroll *)p2 )->direction )
256 MouseScroll( ( (GdkEventScroll *)p2 )->x,
257 ( (GdkEventScroll *)p2 )->y,
260 case GDK_SCROLL_DOWN:
261 MouseScroll( ( (GdkEventScroll *)p2 )->x,
262 ( (GdkEventScroll *)p2 )->y,
272 //---------------------------------------------------------------------------
273 void X11Window::SetTransparency( int Value )
277 SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
278 UpdateWindow( hWnd );*/
280 //---------------------------------------------------------------------------
281 void X11Window::RefreshFromImage( int x, int y, int w, int h )
283 Drawable drawable = (( X11Graphics* )Image )->GetImage();
285 XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y );
287 XImage *image = XGetImage( display, drawable, 0, 0, Width, Height,
288 AllPlanes, ZPixmap );
290 // Mask for transparency
291 Region region = XCreateRegion();
292 for( int line = 0; line < Height; line++ )
294 int start = 0, end = 0;
295 while( start < Width )
297 while( start < Width && XGetPixel( image, start, line ) == 0 )
302 while( end < Width && XGetPixel( image, end, line ) != 0)
309 rect.width = end - start + 1;
311 Region newRegion = XCreateRegion();
312 XUnionRectWithRegion( &rect, region, newRegion );
313 XDestroyRegion( region );
318 XShapeCombineRegion( display, Wnd, ShapeBounding, 0, 0, region, ShapeSet );
319 XDestroyRegion( region );
323 //---------------------------------------------------------------------------
324 void X11Window::WindowManualMove()
326 // Get mouse cursor position
328 OSAPI_GetMousePos( x, y );
330 // Move window and chek for magnetism
331 p_intf->p_sys->p_theme->MoveSkinMagnet( this,
332 WindowX + x - CursorX, WindowY + y - CursorY );
335 //---------------------------------------------------------------------------
336 void X11Window::WindowManualMoveInit()
338 OSAPI_GetMousePos( CursorX, CursorY );
342 //---------------------------------------------------------------------------
343 void X11Window::Move( int left, int top )
347 XMoveWindow( display, Wnd, left, top );
349 //---------------------------------------------------------------------------
350 void X11Window::Size( int width, int height )
354 XResizeWindow( display, Wnd, width, height );
356 //---------------------------------------------------------------------------
357 void X11Window::ChangeToolTipText( string text )
359 /* if( text == "none" )
361 if( ToolTipText != "none" )
363 ToolTipText = "none";
364 ToolTipInfo.lpszText = NULL;
365 SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
370 if( text != ToolTipText )
373 ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
374 SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
375 SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
376 (LPARAM)(LPTOOLINFO)&ToolTipInfo );
381 //---------------------------------------------------------------------------