* x11_window.cpp: X11 implementation of the Window class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
- * $Id: x11_window.cpp,v 1.1 2003/04/28 14:32:57 asmax Exp $
+ * $Id: x11_window.cpp,v 1.12 2003/06/07 12:19:23 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
//--- X11 -------------------------------------------------------------------
#include <X11/Xlib.h>
+#include <X11/extensions/shape.h>
//--- SKIN ------------------------------------------------------------------
#include "../os_api.h"
#include "../os_graphics.h"
#include "../src/skin_common.h"
#include "../src/theme.h"
+#include "../os_theme.h"
+#include "x11_timer.h"
+
+
+bool ToolTipCallback( void *data );
//---------------------------------------------------------------------------
{
// Set handles
Wnd = wnd;
-// gc = gdk_gc_new( gwnd );
+
+ display = p_intf->p_sys->display;
+ int screen = DefaultScreen( display );
+
+ Gc = DefaultGC( display, screen );
Name = name;
CursorPos = new POINT;
WindowPos = new POINT;
- // Create Tool Tip Window
- ToolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
- WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- hWnd, 0, GetModuleHandle( NULL ), 0);
-
- // Create Tool Tip infos
- ToolTipInfo.cbSize = sizeof(TOOLINFO);
- ToolTipInfo.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
- ToolTipInfo.hwnd = hWnd;
- ToolTipInfo.hinst = GetModuleHandle( NULL );
- ToolTipInfo.uId = (unsigned int)hWnd;
- ToolTipInfo.lpszText = NULL;
- ToolTipInfo.rect.left = ToolTipInfo.rect.top = 0;
- ToolTipInfo.rect.right = ToolTipInfo.rect.bottom = 0;
-
- SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
- (LPARAM)(LPTOOLINFO) &ToolTipInfo );
*/
+
if( DragDrop )
{
// register the listview as a drop target
}
// Create Tool Tip window
-/* GdkWindowAttr attr;
- attr.event_mask = GDK_ALL_EVENTS_MASK;
- attr.width = 100;
- attr.height = 100;
- attr.window_type = GDK_WINDOW_CHILD;
- attr.wclass = GDK_INPUT_OUTPUT;
- gint mask = 0;
- ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
-
+ ToolTipWindow = XCreateSimpleWindow( display, wnd, 0, 0, 1, 1, 0, 0, 0 );
+ X11Timer *timer = new X11Timer( p_intf, 100, ToolTipCallback, &ToolTipInfo );
+ ToolTipInfo.p_intf = p_intf;
+ ToolTipInfo.timer = timer;
+
+ // Double-click handling
+ ClickedX = 0;
+ ClickedY = 0;
+ ClickedTime = 0;
+ // TODO: can be retrieved somewhere ?
+ DblClickDelay = 400;
+
}
//---------------------------------------------------------------------------
X11Window::~X11Window()
if( hWnd != NULL )
{
DestroyWindow( hWnd );
- }
- if( ToolTipWindow != NULL )
- {
- DestroyWindow( ToolTipWindow );
- }
+ }*/
+ XDestroyWindow( display, ToolTipWindow );
+ /*
if( DragDrop )
{
// Remove the listview from the list of drop targets
{
if( show )
{
-/* gdk_window_show( gWnd );
- gdk_window_move( gWnd, Left, Top );*/
+ XLOCK;
+ XMapWindow( display, Wnd );
+ XMoveWindow( display, Wnd, Left, Top );
+ XUNLOCK;
}
else
{
-/* gdk_window_hide( gWnd );*/
+ XLOCK;
+ XUnmapWindow( display, Wnd );
+ XUNLOCK;
}
}
//---------------------------------------------------------------------------
unsigned int msg = evt->GetMessage();
unsigned int p1 = evt->GetParam1();
int p2 = evt->GetParam2();
-/*
+ int time;
+ int posX, posY;
+
switch( msg )
{
- case GDK_EXPOSE:
+ case Expose:
RefreshFromImage( 0, 0, Width, Height );
return true;
-
- case GDK_MOTION_NOTIFY:
+
+ case MotionNotify:
if( LButtonDown )
- MouseMove( (int)( (GdkEventButton *)p2 )->x,
- (int)( (GdkEventButton *)p2 )->y, 1 );
+ MouseMove( (int)( (XMotionEvent *)p2 )->x,
+ (int)( (XMotionEvent *)p2 )->y, 1 );
else if( RButtonDown )
- MouseMove( (int)( (GdkEventButton *)p2 )->x,
- (int)( (GdkEventButton *)p2 )->y, 2 );
+ MouseMove( (int)( (XMotionEvent *)p2 )->x,
+ (int)( (XMotionEvent *)p2 )->y, 2 );
else
- MouseMove( (int)( (GdkEventButton *)p2 )->x,
- (int)( (GdkEventButton *)p2 )->y, 0 );
- gdk_window_get_pointer( gWnd, 0, 0, 0 );
+ MouseMove( (int)( (XMotionEvent *)p2 )->x,
+ (int)( (XMotionEvent *)p2 )->y, 0 );
return true;
- case GDK_BUTTON_PRESS:
+ case ButtonPress:
// Raise all the windows
for( list<SkinWindow *>::const_iterator win =
p_intf->p_sys->p_theme->WindowList.begin();
win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
{
- gdk_window_raise( ( (X11Window *)(*win) )->GetHandle() );
+ XLOCK;
+ XRaiseWindow( display, ( (X11Window *)(*win) )->GetHandle() );
+ XUNLOCK;
}
-
- switch( ( (GdkEventButton *)p2 )->button )
+
+ switch( ( (XButtonEvent *)p2 )->button )
{
case 1:
// Left button
- LButtonDown = true;
- MouseDown( (int)( (GdkEventButton *)p2 )->x,
- (int)( (GdkEventButton *)p2 )->y, 1 );
+ time = OSAPI_GetTime();
+ OSAPI_GetMousePos( posX, posY );
+ if( time - ClickedTime < DblClickDelay &&
+ posX == ClickedX && posY == ClickedY )
+ {
+ // Double-click
+ ClickedTime = 0;
+ MouseDblClick( (int)( (XButtonEvent *)p2 )->x,
+ (int)( (XButtonEvent *)p2 )->y, 1 );
+ }
+ else
+ {
+ ClickedTime = time;
+ ClickedX = posX;
+ ClickedY = posY;
+ LButtonDown = true;
+ MouseDown( (int)( (XButtonEvent *)p2 )->x,
+ (int)( (XButtonEvent *)p2 )->y, 1 );
+ }
break;
case 3:
// Right button
RButtonDown = true;
- MouseDown( (int)( (GdkEventButton *)p2 )->x,
- (int)( (GdkEventButton *)p2 )->y, 2 );
+ MouseDown( (int)( (XButtonEvent *)p2 )->x,
+ (int)( (XButtonEvent *)p2 )->y, 2 );
break;
default:
}
return true;
- case GDK_BUTTON_RELEASE:
- switch( ( (GdkEventButton *)p2 )->button )
+ case ButtonRelease:
+ switch( ( (XButtonEvent *)p2 )->button )
{
case 1:
// Left button
LButtonDown = false;
- MouseUp( (int)( (GdkEventButton *)p2 )->x,
- (int)( (GdkEventButton *)p2 )->y, 1 );
+ MouseUp( (int)( (XButtonEvent *)p2 )->x,
+ (int)( (XButtonEvent *)p2 )->y, 1 );
break;
case 3:
// Right button
RButtonDown = false;
- MouseUp( (int)( (GdkEventButton *)p2 )->x,
- (int)( (GdkEventButton *)p2 )->y, 2 );
+ MouseUp( (int)( (XButtonEvent *)p2 )->x,
+ (int)( (XButtonEvent *)p2 )->y, 2 );
+ break;
+
+ case 4:
+ // Scroll up
+ MouseScroll( (int)( (XButtonEvent *)p2 )->x,
+ (int)( (XButtonEvent *)p2 )->y,
+ MOUSE_SCROLL_UP);
+ break;
+
+ case 5:
+ // Scroll down
+ MouseScroll( (int)( (XButtonEvent *)p2 )->x,
+ (int)( (XButtonEvent *)p2 )->y,
+ MOUSE_SCROLL_DOWN);
break;
default:
}
return true;
- case GDK_LEAVE_NOTIFY:
+ case LeaveNotify:
OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
return true;
- case GDK_2BUTTON_PRESS:
- MouseDblClick( (int)( (GdkEventButton *)p2 )->x,
- (int)( (GdkEventButton *)p2 )->y, 1 );
- return true;
-
- case GDK_DROP_START:
+/* case GDK_DROP_START:
DropObject->HandleDropStart( ( (GdkEventDND *)p2 )->context );
return true;
-
- case GDK_SCROLL:
- switch( ( (GdkEventScroll *)p2 )->direction )
- {
- case GDK_SCROLL_UP:
- MouseScroll( ( (GdkEventScroll *)p2 )->x,
- ( (GdkEventScroll *)p2 )->y,
- MOUSE_SCROLL_UP);
- break;
- case GDK_SCROLL_DOWN:
- MouseScroll( ( (GdkEventScroll *)p2 )->x,
- ( (GdkEventScroll *)p2 )->y,
- MOUSE_SCROLL_DOWN);
- break;
- }
- return true;
-
+*/
default:
return false;
- }*/
+ }
}
//---------------------------------------------------------------------------
void X11Window::SetTransparency( int Value )
//---------------------------------------------------------------------------
void X11Window::RefreshFromImage( int x, int y, int w, int h )
{
- // Initialize painting
-/* HDC DC = GetWindowDC( hWnd );
-
- // Draw image on window
- BitBlt( DC, x, y, w, h, ( (X11Graphics *)Image )->GetImageHandle(),
- x, y, SRCCOPY );
-
- // Release window device context
- ReleaseDC( hWnd, DC );
-
-*/
-/* GdkDrawable *drawable = (( X11Graphics* )Image )->GetImage();
- GdkImage *image = gdk_drawable_get_image( drawable, 0, 0, Width, Height );
+ Drawable drawable = (( X11Graphics* )Image )->GetImage();
- gdk_draw_drawable( gWnd, gc, drawable, x, y, x, y, w, h );
-
+ XLOCK;
+ XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y );
+
+ XImage *image = XGetImage( display, drawable, 0, 0, Width, Height,
+ AllPlanes, ZPixmap );
+
// Mask for transparency
- GdkRegion *region = gdk_region_new();
+ Region region = XCreateRegion();
for( int line = 0; line < Height; line++ )
{
int start = 0, end = 0;
while( start < Width )
{
- while( start < Width && gdk_image_get_pixel( image, start, line ) == 0 )
+ while( start < Width && XGetPixel( image, start, line ) == 0 )
{
start++;
}
end = start;
- while( end < Width && gdk_image_get_pixel( image, end, line ) != 0)
+ while( end < Width && XGetPixel( image, end, line ) != 0)
{
end++;
}
- GdkRectangle rect;
+ XRectangle rect;
rect.x = start;
rect.y = line;
rect.width = end - start + 1;
rect.height = 1;
- GdkRegion *rectReg = gdk_region_rectangle( &rect );
- gdk_region_union( region, rectReg );
- gdk_region_destroy( rectReg );
+ Region newRegion = XCreateRegion();
+ XUnionRectWithRegion( &rect, region, newRegion );
+ XDestroyRegion( region );
+ region = newRegion;
start = end + 1;
}
}
- gdk_window_shape_combine_region( gWnd, region, 0, 0 );
- gdk_region_destroy( region );*/
+ XShapeCombineRegion( display, Wnd, ShapeBounding, 0, 0, region, ShapeSet );
+ XDestroyRegion( region );
+
+ XSync( display, 0);
+ XUNLOCK;
}
//---------------------------------------------------------------------------
void X11Window::WindowManualMove()
//---------------------------------------------------------------------------
void X11Window::WindowManualMoveInit()
{
-/* gdk_window_get_pointer( gdk_get_default_root_window(), &CursorX, &CursorY,
- NULL );*/
+ OSAPI_GetMousePos( CursorX, CursorY );
WindowX = Left;
WindowY = Top;
}
{
Left = left;
Top = top;
-/* gdk_window_move( gWnd, left, top );*/
+ XMoveWindow( display, Wnd, left, top );
}
//---------------------------------------------------------------------------
void X11Window::Size( int width, int height )
{
Width = width;
Height = height;
-/* gdk_window_resize( gWnd, width, height );*/
+ XResizeWindow( display, Wnd, width, height );
}
//---------------------------------------------------------------------------
+
+
+bool ToolTipCallback( void *data )
+{
+ fprintf(stderr," TOOLTIP: %s\n", ((tooltip_t*)data)->text.c_str());
+ return False;
+}
+
+
void X11Window::ChangeToolTipText( string text )
{
-/* if( text == "none" )
+ if( text == "none" )
{
if( ToolTipText != "none" )
{
ToolTipText = "none";
- ToolTipInfo.lpszText = NULL;
- SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
+// ToolTipInfo.lpszText = NULL;
+ // SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
}
}
else
if( text != ToolTipText )
{
ToolTipText = text;
- ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
- SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
- SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
- (LPARAM)(LPTOOLINFO)&ToolTipInfo );
+ ToolTipInfo.text = text;
+ X11TimerManager *timerManager = X11TimerManager::Instance( p_intf );
+ timerManager->addTimer( ToolTipInfo.timer );
+ // ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
}
}
-*/
}
//---------------------------------------------------------------------------