* events aren't perfect yet, but it is better enough to commit
[vlc.git] / modules / gui / skins / x11 / x11_window.cpp
index 91a822a..23041b5 100644 (file)
@@ -2,7 +2,7 @@
  * x11_window.cpp: X11 implementation of the Window class
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: x11_window.cpp,v 1.3 2003/05/18 11:25:00 asmax Exp $
+ * $Id: x11_window.cpp,v 1.6 2003/05/24 21:28:29 asmax Exp $
  *
  * Authors: Cyril Deguet     <asmax@videolan.org>
  *
@@ -32,6 +32,7 @@
 
 //--- X11 -------------------------------------------------------------------
 #include <X11/Xlib.h>
+#include <X11/extensions/shape.h>
 
 //--- SKIN ------------------------------------------------------------------
 #include "../os_api.h"
@@ -112,6 +113,9 @@ X11Window::X11Window( intf_thread_t *p_intf, Window wnd, int x, int y,
     gint mask = 0;
     ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
 
+    Open();
+    fprintf(stderr, "kludge in x11_window.cpp\n");
+
 }
 //---------------------------------------------------------------------------
 X11Window::~X11Window()
@@ -147,6 +151,7 @@ void X11Window::OSShow( bool show )
     {
 /*        gdk_window_show( gWnd );
         gdk_window_move( gWnd, Left, Top );*/
+        XMoveWindow( display, Wnd, Left, Top );
     }
     else
     {
@@ -159,7 +164,7 @@ bool X11Window::ProcessOSEvent( Event *evt )
     unsigned int msg = evt->GetMessage();
     unsigned int p1  = evt->GetParam1();
     int          p2  = evt->GetParam2();
-    
     switch( msg )
     {
         case Expose:
@@ -167,69 +172,68 @@ bool X11Window::ProcessOSEvent( Event *evt )
             return true;
  
         case MotionNotify:
/*           if( LButtonDown )
-                MouseMove( (int)( (GdkEventButton *)p2 )->x,
-                           (int)( (GdkEventButton *)p2 )->y, 1 );
+            if( LButtonDown )
+                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 ButtonPress:
             // Raise all the windows
-/*            for( list<SkinWindow *>::const_iterator win = 
+            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() );
+                XRaiseWindow( display, ( (X11Window *)(*win) )->GetHandle() );
             }
           
-            switch( ( (GdkEventButton *)p2 )->button )
+            switch( ( (XButtonEvent *)p2 )->button )
             {
                 case 1:
                     // Left button
                     LButtonDown = true;
-                    MouseDown( (int)( (GdkEventButton *)p2 )->x,
-                               (int)( (GdkEventButton *)p2 )->y, 1 );
+                    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:
                     break;
-            }*/
+            }
             return true;
 
         case ButtonRelease:
-/*            switch( ( (GdkEventButton *)p2 )->button )
+            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;
 
                 default:
                     break;
-            }*/
+            }
             return true;
 
         case LeaveNotify:
@@ -276,51 +280,45 @@ 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 );
-
-*/ 
     Drawable drawable = (( X11Graphics* )Image )->GetImage();
     
     XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y );
-    XSync( display, 0);
-/*
+    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);
 }
 //---------------------------------------------------------------------------
 void X11Window::WindowManualMove()
@@ -337,8 +335,7 @@ 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;
 }
@@ -347,14 +344,14 @@ void X11Window::Move( int left, int 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 );
 }
 //---------------------------------------------------------------------------
 void X11Window::ChangeToolTipText( string text )