1 /*****************************************************************************
2 * x11_window.cpp: X11 implementation of the Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_window.cpp,v 1.2 2003/05/13 20:36:29 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,
62 display = p_intf->p_sys->display;
63 int screen = DefaultScreen( display );
65 Gc = DefaultGC( display, screen );
72 // Removing fading effect
75 // Set position parameters
76 CursorPos = new POINT;
77 WindowPos = new POINT;
79 // Create Tool Tip Window
80 ToolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
81 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
82 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
83 hWnd, 0, GetModuleHandle( NULL ), 0);
85 // Create Tool Tip infos
86 ToolTipInfo.cbSize = sizeof(TOOLINFO);
87 ToolTipInfo.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
88 ToolTipInfo.hwnd = hWnd;
89 ToolTipInfo.hinst = GetModuleHandle( NULL );
90 ToolTipInfo.uId = (unsigned int)hWnd;
91 ToolTipInfo.lpszText = NULL;
92 ToolTipInfo.rect.left = ToolTipInfo.rect.top = 0;
93 ToolTipInfo.rect.right = ToolTipInfo.rect.bottom = 0;
95 SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
96 (LPARAM)(LPTOOLINFO) &ToolTipInfo );
100 // register the listview as a drop target
101 DropObject = new X11DropObject( p_intf );
102 // gdk_window_register_dnd( gwnd );
105 // Create Tool Tip window
106 /* GdkWindowAttr attr;
107 attr.event_mask = GDK_ALL_EVENTS_MASK;
110 attr.window_type = GDK_WINDOW_CHILD;
111 attr.wclass = GDK_INPUT_OUTPUT;
113 ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
116 //---------------------------------------------------------------------------
117 X11Window::~X11Window()
124 DestroyWindow( hWnd );
126 if( ToolTipWindow != NULL )
128 DestroyWindow( ToolTipWindow );
132 // Remove the listview from the list of drop targets
133 RevokeDragDrop( hWnd );
134 DropTarget->Release();
135 // Uninitialize the OLE library
140 gdk_window_destroy( gWnd );
143 //---------------------------------------------------------------------------
144 void X11Window::OSShow( bool show )
148 /* gdk_window_show( gWnd );
149 gdk_window_move( gWnd, Left, Top );*/
153 /* gdk_window_hide( gWnd );*/
156 //---------------------------------------------------------------------------
157 bool X11Window::ProcessOSEvent( Event *evt )
159 unsigned int msg = evt->GetMessage();
160 unsigned int p1 = evt->GetParam1();
161 int p2 = evt->GetParam2();
166 RefreshFromImage( 0, 0, Width, Height );
171 MouseMove( (int)( (GdkEventButton *)p2 )->x,
172 (int)( (GdkEventButton *)p2 )->y, 1 );
173 else if( RButtonDown )
174 MouseMove( (int)( (GdkEventButton *)p2 )->x,
175 (int)( (GdkEventButton *)p2 )->y, 2 );
177 MouseMove( (int)( (GdkEventButton *)p2 )->x,
178 (int)( (GdkEventButton *)p2 )->y, 0 );
179 gdk_window_get_pointer( gWnd, 0, 0, 0 );*/
184 // Raise all the windows
185 /* for( list<SkinWindow *>::const_iterator win =
186 p_intf->p_sys->p_theme->WindowList.begin();
187 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
189 gdk_window_raise( ( (X11Window *)(*win) )->GetHandle() );
192 switch( ( (GdkEventButton *)p2 )->button )
197 MouseDown( (int)( (GdkEventButton *)p2 )->x,
198 (int)( (GdkEventButton *)p2 )->y, 1 );
204 MouseDown( (int)( (GdkEventButton *)p2 )->x,
205 (int)( (GdkEventButton *)p2 )->y, 2 );
214 /* switch( ( (GdkEventButton *)p2 )->button )
219 MouseUp( (int)( (GdkEventButton *)p2 )->x,
220 (int)( (GdkEventButton *)p2 )->y, 1 );
226 MouseUp( (int)( (GdkEventButton *)p2 )->x,
227 (int)( (GdkEventButton *)p2 )->y, 2 );
236 OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
239 /* case GDK_2BUTTON_PRESS:
240 MouseDblClick( (int)( (GdkEventButton *)p2 )->x,
241 (int)( (GdkEventButton *)p2 )->y, 1 );
245 DropObject->HandleDropStart( ( (GdkEventDND *)p2 )->context );
249 switch( ( (GdkEventScroll *)p2 )->direction )
252 MouseScroll( ( (GdkEventScroll *)p2 )->x,
253 ( (GdkEventScroll *)p2 )->y,
256 case GDK_SCROLL_DOWN:
257 MouseScroll( ( (GdkEventScroll *)p2 )->x,
258 ( (GdkEventScroll *)p2 )->y,
268 //---------------------------------------------------------------------------
269 void X11Window::SetTransparency( int Value )
273 SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
274 UpdateWindow( hWnd );*/
276 //---------------------------------------------------------------------------
277 void X11Window::RefreshFromImage( int x, int y, int w, int h )
279 // Initialize painting
280 /* HDC DC = GetWindowDC( hWnd );
282 // Draw image on window
283 BitBlt( DC, x, y, w, h, ( (X11Graphics *)Image )->GetImageHandle(),
286 // Release window device context
287 ReleaseDC( hWnd, DC );
290 Drawable drawable = (( X11Graphics* )Image )->GetImage();
292 fprintf(stderr, "prout\n");
293 XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y );
296 // Mask for transparency
297 GdkRegion *region = gdk_region_new();
298 for( int line = 0; line < Height; line++ )
300 int start = 0, end = 0;
301 while( start < Width )
303 while( start < Width && gdk_image_get_pixel( image, start, line ) == 0 )
308 while( end < Width && gdk_image_get_pixel( image, end, line ) != 0)
315 rect.width = end - start + 1;
317 GdkRegion *rectReg = gdk_region_rectangle( &rect );
318 gdk_region_union( region, rectReg );
319 gdk_region_destroy( rectReg );
323 gdk_window_shape_combine_region( gWnd, region, 0, 0 );
324 gdk_region_destroy( region );*/
326 //---------------------------------------------------------------------------
327 void X11Window::WindowManualMove()
329 // Get mouse cursor position
331 OSAPI_GetMousePos( x, y );
333 // Move window and chek for magnetism
334 p_intf->p_sys->p_theme->MoveSkinMagnet( this,
335 WindowX + x - CursorX, WindowY + y - CursorY );
338 //---------------------------------------------------------------------------
339 void X11Window::WindowManualMoveInit()
341 /* gdk_window_get_pointer( gdk_get_default_root_window(), &CursorX, &CursorY,
346 //---------------------------------------------------------------------------
347 void X11Window::Move( int left, int top )
351 /* gdk_window_move( gWnd, left, top );*/
353 //---------------------------------------------------------------------------
354 void X11Window::Size( int width, int height )
358 /* gdk_window_resize( gWnd, width, height );*/
360 //---------------------------------------------------------------------------
361 void X11Window::ChangeToolTipText( string text )
363 /* if( text == "none" )
365 if( ToolTipText != "none" )
367 ToolTipText = "none";
368 ToolTipInfo.lpszText = NULL;
369 SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
374 if( text != ToolTipText )
377 ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
378 SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
379 SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
380 (LPARAM)(LPTOOLINFO)&ToolTipInfo );
385 //---------------------------------------------------------------------------