]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins/gtk2/gtk2_window.cpp
* Events are even better, not yet perfect !
[vlc] / modules / gui / skins / gtk2 / gtk2_window.cpp
index 2c782bcd6dbe1d3bb61cbfe59fa1fba64f17a39a..1bc862f272d8f3e1e8783e8bef0cc2cc85d69ddc 100644 (file)
@@ -2,7 +2,7 @@
  * gtk2_window.cpp: GTK2 implementation of the Window class
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: gtk2_window.cpp,v 1.2 2003/04/12 22:50:42 asmax Exp $
+ * $Id: gtk2_window.cpp,v 1.15 2003/04/15 20:33:58 karibu Exp $
  *
  * Authors: Cyril Deguet     <asmax@videolan.org>
  *
@@ -22,6 +22,7 @@
  * USA.
  *****************************************************************************/
 
+#if !defined WIN32
 
 //--- GENERAL ---------------------------------------------------------------
 //#include <math.h>
@@ -30,7 +31,8 @@
 #include <vlc/intf.h>
 
 //--- GTK2 ------------------------------------------------------------------
-//#include <windows.h>
+#include <gdk/gdk.h>
+#include <glib.h>
 
 //--- SKIN ------------------------------------------------------------------
 #include "os_api.h"
@@ -46,7 +48,6 @@
 #include "theme.h"
 
 
-
 //---------------------------------------------------------------------------
 // Fading API
 //---------------------------------------------------------------------------
@@ -63,13 +64,19 @@ SLWA SetLayeredWindowAttributes =
 //---------------------------------------------------------------------------
 GTK2Window::GTK2Window( intf_thread_t *p_intf, GdkWindow *gwnd, int x, int y,
     bool visible, int transition, int normalalpha, int movealpha,
-    bool dragdrop )
+    bool dragdrop, string name )
     : Window( p_intf, x, y, visible, transition, normalalpha, movealpha,
               dragdrop )
 {
     // Set handles
-/*    hWnd           = hwnd;
+    gWnd           = gwnd;
+    gc = gdk_gc_new( gwnd );
+
+    Name        = name;
 
+    LButtonDown = false;
+    RButtonDown = false;
+/*
     // Set position parameters
     CursorPos    = new POINT;
     WindowPos    = new POINT;
@@ -103,6 +110,16 @@ GTK2Window::GTK2Window( intf_thread_t *p_intf, GdkWindow *gwnd, int x, int y,
         RegisterDragDrop( hWnd, DropTarget );
     }
 */
+    // 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);*/
+
 }
 //---------------------------------------------------------------------------
 GTK2Window::~GTK2Window()
@@ -131,77 +148,98 @@ GTK2Window::~GTK2Window()
 //---------------------------------------------------------------------------
 void GTK2Window::OSShow( bool show )
 {
-/*    if( show )
+    if( show )
     {
-        ShowWindow( hWnd, SW_SHOW );
+        gdk_window_show( gWnd );
     }
     else
     {
-        ShowWindow( hWnd, SW_HIDE );
-    }*/
+        gdk_window_hide( gWnd );
+    }
 }
 //---------------------------------------------------------------------------
 bool GTK2Window::ProcessOSEvent( Event *evt )
 {
-/*    unsigned int msg = evt->GetMessage();
+    unsigned int msg = evt->GetMessage();
     unsigned int p1  = evt->GetParam1();
     int          p2  = evt->GetParam2();
 
     switch( msg )
     {
-        case WM_PAINT:
-            HDC DC;
-            PAINTSTRUCT Infos;
-            DC = BeginPaint( hWnd , &Infos );
-            EndPaint( hWnd , &Infos );
+        case GDK_EXPOSE:
             RefreshFromImage( 0, 0, Width, Height );
             return true;
 
-        case WM_MOUSEMOVE:
-            TRACKMOUSEEVENT TrackEvent;
-            TrackEvent.cbSize      = sizeof( TRACKMOUSEEVENT );\r
-            TrackEvent.dwFlags     = TME_LEAVE;\r
-            TrackEvent.hwndTrack   = hWnd;\r
-            TrackEvent.dwHoverTime = 1;
-            TrackMouseEvent( &TrackEvent );
-            if( p1 == MK_LBUTTON )
-                MouseMove( LOWORD( p2 ), HIWORD( p2 ), 1 );
-            else if( p1 == MK_RBUTTON )
-                MouseMove( LOWORD( p2 ), HIWORD( p2 ), 2 );
+        case GDK_MOTION_NOTIFY:
+            if( LButtonDown )
+                MouseMove( (int)( (GdkEventButton *)p2 )->x,
+                           (int)( (GdkEventButton *)p2 )->y, 1 );
+            else if( RButtonDown )
+                MouseMove( (int)( (GdkEventButton *)p2 )->x,
+                           (int)( (GdkEventButton *)p2 )->y, 2 );
             else
-                MouseMove( LOWORD( p2 ), HIWORD( p2 ), 0 );
-
+                MouseMove( (int)( (GdkEventButton *)p2 )->x,
+                           (int)( (GdkEventButton *)p2 )->y, 0 );
+            gdk_window_get_pointer( gWnd, 0, 0, 0 );
             return true;
 
-        case WM_LBUTTONDOWN:
-            SetCapture( hWnd );
-            MouseDown( LOWORD( p2 ), HIWORD( p2 ), 1 );
-            return true;
 
-        case WM_LBUTTONUP:
-            ReleaseCapture();
-            MouseUp( LOWORD( p2 ), HIWORD( p2 ), 1 );
-            return true;
+        case GDK_BUTTON_PRESS:
+            switch( ( (GdkEventButton *)p2 )->button )
+            {
+                case 1:
+                    // Left button
+                    LButtonDown = true;
+                    MouseDown( (int)( (GdkEventButton *)p2 )->x,
+                               (int)( (GdkEventButton *)p2 )->y, 1 );
+                    break;
 
-        case WM_RBUTTONDOWN:
-            MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
-            return true;
+                case 3:
+                    // Right button
+                    RButtonDown = true;
+                    MouseDown( (int)( (GdkEventButton *)p2 )->x,
+                               (int)( (GdkEventButton *)p2 )->y, 2 );
+                    break;
 
-        case WM_RBUTTONUP:
-            MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
+                default:
+                    break;
+            }
             return true;
 
-        case WM_LBUTTONDBLCLK:
-            MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
+        case GDK_BUTTON_RELEASE:
+            switch( ( (GdkEventButton *)p2 )->button )
+            {
+                case 1:
+                    // Left button
+                    LButtonDown = false;
+                    MouseUp( (int)( (GdkEventButton *)p2 )->x,
+                             (int)( (GdkEventButton *)p2 )->y, 1 );
+                    break;
+
+                case 3:
+                    // Right button
+                    RButtonDown = false;
+                    MouseUp( (int)( (GdkEventButton *)p2 )->x,
+                             (int)( (GdkEventButton *)p2 )->y, 2 );
+                    break;
+
+                default:
+                    break;
+            }
             return true;
 
-        case WM_MOUSELEAVE:
+        case GDK_LEAVE_NOTIFY:
             OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
             return true;
+/*
+        case WM_LBUTTONDBLCLK:
+            MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
+            return true;
 
+*/
         default:
             return false;
-    }*/
+    }
 }
 //---------------------------------------------------------------------------
 void GTK2Window::SetTransparency( int Value )
@@ -223,47 +261,45 @@ void GTK2Window::RefreshFromImage( int x, int y, int w, int h )
 
     // Release window device context
     ReleaseDC( hWnd, DC );
+
 */
+
+    gdk_draw_drawable( gWnd, gc, (( GTK2Graphics* )Image )->GetImage(),
+            x, y, x, y, w, h );
 }
 //---------------------------------------------------------------------------
 void GTK2Window::WindowManualMove()
 {
-/*    // Get mouse cursor position
-    LPPOINT NewPos = new POINT;
-    GetCursorPos( NewPos );
+    // Get mouse cursor position
+    int x, y;
+    gdk_window_get_pointer( gdk_get_default_root_window(), &x, &y, NULL );
 
     // Move window and chek for magnetism
     p_intf->p_sys->p_theme->MoveSkinMagnet( this,
-        WindowPos->x + NewPos->x - CursorPos->x,
-        WindowPos->y + NewPos->y - CursorPos->y );
+        WindowX + x - CursorX, WindowY + y - CursorY );
 
-    // Free memory
-    delete[] NewPos;
-*/
 }
 //---------------------------------------------------------------------------
 void GTK2Window::WindowManualMoveInit()
 {
-/*    GetCursorPos( CursorPos );
-    WindowPos->x = Left;
-    WindowPos->y = Top;*/
+    gdk_window_get_pointer( gdk_get_default_root_window(), &CursorX, &CursorY,
+                            NULL );
+    WindowX = Left;
+    WindowY = Top;
 }
 //---------------------------------------------------------------------------
 void GTK2Window::Move( int left, int top )
 {
-/*    Left = left;
+    Left = left;
     Top  = top;
-    //SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
-    //              SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER );
-    MoveWindow( hWnd, Left, Top, Width, Height, false );*/
+    gdk_window_move( gWnd, left, top );
 }
 //---------------------------------------------------------------------------
 void GTK2Window::Size( int width, int height )
 {
-/*    Width  = width;
+    Width  = width;
     Height = height;
-    SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
-                  SWP_NOMOVE|SWP_NOREDRAW|SWP_NOZORDER );*/
+    gdk_window_resize( gWnd, width, height );
 }
 //---------------------------------------------------------------------------
 void GTK2Window::ChangeToolTipText( string text )
@@ -292,3 +328,4 @@ void GTK2Window::ChangeToolTipText( string text )
 }
 //---------------------------------------------------------------------------
 
+#endif