1 /*****************************************************************************
2 * x11_window.cpp: X11 implementation of the Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_window.cpp,v 1.5 2003/05/19 21:39:34 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"
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 //---------------------------------------------------------------------------
118 X11Window::~X11Window()
125 DestroyWindow( hWnd );
127 if( ToolTipWindow != NULL )
129 DestroyWindow( 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 )
149 /* gdk_window_show( gWnd );
150 gdk_window_move( gWnd, Left, Top );*/
151 XMoveWindow( display, Wnd, Left, Top );
155 /* gdk_window_hide( gWnd );*/
158 //---------------------------------------------------------------------------
159 bool X11Window::ProcessOSEvent( Event *evt )
161 unsigned int msg = evt->GetMessage();
162 unsigned int p1 = evt->GetParam1();
163 int p2 = evt->GetParam2();
168 RefreshFromImage( 0, 0, Width, Height );
173 MouseMove( (int)( (XMotionEvent *)p2 )->x,
174 (int)( (XMotionEvent *)p2 )->y, 1 );
175 else if( RButtonDown )
176 MouseMove( (int)( (XMotionEvent *)p2 )->x,
177 (int)( (XMotionEvent *)p2 )->y, 2 );
179 MouseMove( (int)( (XMotionEvent *)p2 )->x,
180 (int)( (XMotionEvent *)p2 )->y, 0 );
185 // Raise all the windows
186 for( list<SkinWindow *>::const_iterator win =
187 p_intf->p_sys->p_theme->WindowList.begin();
188 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
190 XRaiseWindow( display, ( (X11Window *)(*win) )->GetHandle() );
193 switch( ( (XButtonEvent *)p2 )->button )
198 MouseDown( (int)( (XButtonEvent *)p2 )->x,
199 (int)( (XButtonEvent *)p2 )->y, 1 );
205 MouseDown( (int)( (XButtonEvent *)p2 )->x,
206 (int)( (XButtonEvent *)p2 )->y, 2 );
215 switch( ( (XButtonEvent *)p2 )->button )
220 MouseUp( (int)( (XButtonEvent *)p2 )->x,
221 (int)( (XButtonEvent *)p2 )->y, 1 );
227 MouseUp( (int)( (XButtonEvent *)p2 )->x,
228 (int)( (XButtonEvent *)p2 )->y, 2 );
237 OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
240 /* case GDK_2BUTTON_PRESS:
241 MouseDblClick( (int)( (GdkEventButton *)p2 )->x,
242 (int)( (GdkEventButton *)p2 )->y, 1 );
246 DropObject->HandleDropStart( ( (GdkEventDND *)p2 )->context );
250 switch( ( (GdkEventScroll *)p2 )->direction )
253 MouseScroll( ( (GdkEventScroll *)p2 )->x,
254 ( (GdkEventScroll *)p2 )->y,
257 case GDK_SCROLL_DOWN:
258 MouseScroll( ( (GdkEventScroll *)p2 )->x,
259 ( (GdkEventScroll *)p2 )->y,
269 //---------------------------------------------------------------------------
270 void X11Window::SetTransparency( int Value )
274 SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
275 UpdateWindow( hWnd );*/
277 //---------------------------------------------------------------------------
278 void X11Window::RefreshFromImage( int x, int y, int w, int h )
280 Drawable drawable = (( X11Graphics* )Image )->GetImage();
282 XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y );
284 XImage *image = XGetImage( display, drawable, 0, 0, Width, Height,
285 AllPlanes, ZPixmap );
287 // Mask for transparency
288 Region region = XCreateRegion();
289 for( int line = 0; line < Height; line++ )
291 int start = 0, end = 0;
292 while( start < Width )
294 while( start < Width && XGetPixel( image, start, line ) == 0 )
299 while( end < Width && XGetPixel( image, end, line ) != 0)
306 rect.width = end - start + 1;
308 Region newRegion = XCreateRegion();
309 XUnionRectWithRegion( &rect, region, newRegion );
310 XDestroyRegion( region );
315 XShapeCombineRegion( display, Wnd, ShapeBounding, 0, 0, region, ShapeSet );
316 XDestroyRegion( region );
320 //---------------------------------------------------------------------------
321 void X11Window::WindowManualMove()
323 // Get mouse cursor position
325 OSAPI_GetMousePos( x, y );
327 // Move window and chek for magnetism
328 p_intf->p_sys->p_theme->MoveSkinMagnet( this,
329 WindowX + x - CursorX, WindowY + y - CursorY );
332 //---------------------------------------------------------------------------
333 void X11Window::WindowManualMoveInit()
335 OSAPI_GetMousePos( CursorX, CursorY );
339 //---------------------------------------------------------------------------
340 void X11Window::Move( int left, int top )
344 XMoveWindow( display, Wnd, left, top );
346 //---------------------------------------------------------------------------
347 void X11Window::Size( int width, int height )
351 XResizeWindow( display, Wnd, width, height );
353 //---------------------------------------------------------------------------
354 void X11Window::ChangeToolTipText( string text )
356 /* if( text == "none" )
358 if( ToolTipText != "none" )
360 ToolTipText = "none";
361 ToolTipInfo.lpszText = NULL;
362 SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
367 if( text != ToolTipText )
370 ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
371 SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
372 SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
373 (LPARAM)(LPTOOLINFO)&ToolTipInfo );
378 //---------------------------------------------------------------------------