]> Pileus Git - ~andy/gtk/blobdiff - gdk/win32/gdkwindow-win32.c
Large changes to the Win32 backend, partially made necessary by the
[~andy/gtk] / gdk / win32 / gdkwindow-win32.c
index 1f466ae40b3aa27d7a32a9c1ef4c449096d4b7c0..d4c279658cf8ae61239c5150d44e5ca53aa9a514 100644 (file)
@@ -33,6 +33,8 @@
 #include "gdkevents.h"
 #include "gdkpixmap.h"
 #include "gdkwindow.h"
+#include "gdkinternals.h"
+#include "gdkprivate.h"
 #include "gdkprivate-win32.h"
 #include "gdkinputprivate.h"
 #include "gdkwin32.h"
@@ -51,7 +53,10 @@ SafeAdjustWindowRectEx (RECT* lpRect,
                        DWORD dwExStyle)
 {
   if (!AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle))
-    return FALSE;
+    {
+      WIN32_API_FAILED ("AdjustWindowRectEx");
+      return FALSE;
+    }
   if (lpRect->left < 0)
     {
       lpRect->right -= lpRect->left;
@@ -65,6 +70,8 @@ SafeAdjustWindowRectEx (RECT* lpRect,
   return TRUE;
 }
 
+GdkDrawableClass _gdk_windowing_window_class;
+
 static void
 gdk_win32_window_destroy (GdkDrawable *drawable)
 {
@@ -89,28 +96,26 @@ gdk_win32_window_alloc (void)
   GdkWindow *window;
   GdkWindowPrivate *private;
   
-  static GdkDrawableClass klass;
   static gboolean initialized = FALSE;
 
   if (!initialized)
     {
       initialized = TRUE;
       
-      klass = _gdk_win32_drawable_class;
-      klass.destroy = gdk_win32_window_destroy;
+      _gdk_windowing_window_class = _gdk_win32_drawable_class;
+      _gdk_win32_drawable_class.destroy = gdk_win32_window_destroy;
     }
 
   window = _gdk_window_alloc ();
   private = (GdkWindowPrivate *) window;
 
-  private->drawable.klass = &klass;
-  private->drawable.klass_data = g_new (GdkDrawableWin32Data, 1);
+  private->drawable.klass = &_gdk_windowing_window_class;
+  private->drawable.klass_data = g_new (GdkWindowWin32Data, 1);
 
   GDK_WINDOW_WIN32DATA (window)->event_mask = 0;
   GDK_WINDOW_WIN32DATA (window)->bg_type = GDK_WIN32_BG_NORMAL;
   GDK_WINDOW_WIN32DATA (window)->xcursor = NULL;
   GDK_WINDOW_WIN32DATA (window)->hint_flags = 0;
-  GDK_WINDOW_WIN32DATA (window)->extension_events = 0;
   GDK_WINDOW_WIN32DATA (window)->extension_events_selected = FALSE;
   
   GDK_WINDOW_WIN32DATA (window)->input_locale = GetKeyboardLayout (0);
@@ -254,6 +259,11 @@ RegisterGdkClass (GdkDrawableType wtype)
       break;
   }
 
+  if (klass == 0)
+    {
+      WIN32_API_FAILED ("RegisterClassEx");
+      g_error ("That is a fatal error");
+    }
   return klass;
 }
 
@@ -301,7 +311,6 @@ gdk_window_new (GdkWindow     *parent,
   private->drawable.width = (attributes->width > 1) ? (attributes->width) : (1);
   private->drawable.height = (attributes->height > 1) ? (attributes->height) : (1);
   private->drawable.window_type = attributes->window_type;
-  GDK_WINDOW_WIN32DATA (window)->extension_events = 0;
   GDK_WINDOW_WIN32DATA (window)->extension_events_selected = FALSE;
 
   if (attributes_mask & GDK_WA_VISUAL)
@@ -314,6 +323,8 @@ gdk_window_new (GdkWindow     *parent,
     title = attributes->title;
   else
     title = g_get_prgname ();
+  if (!title)
+    title = "GDK client window";
 
   GDK_WINDOW_WIN32DATA (window)->event_mask = GDK_STRUCTURE_MASK | attributes->event_mask;
       
@@ -364,7 +375,9 @@ gdk_window_new (GdkWindow     *parent,
       break;
     case GDK_WINDOW_DIALOG:
       dwStyle = WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU | WS_CAPTION | WS_THICKFRAME | WS_CLIPCHILDREN;
+#if 0
       dwExStyle |= WS_EX_TOPMOST; /* //HB: want this? */
+#endif
       xparent = gdk_root_window;
       break;
     case GDK_WINDOW_TEMP:
@@ -380,8 +393,6 @@ gdk_window_new (GdkWindow     *parent,
     }
 
   klass = RegisterGdkClass (private->drawable.window_type);
-  if (!klass)
-    g_error ("RegisterClassEx failed");
 
   if (private->drawable.window_type != GDK_WINDOW_CHILD)
     {
@@ -399,8 +410,7 @@ gdk_window_new (GdkWindow     *parent,
       rect.right = rect.left + private->drawable.width;
       rect.bottom = rect.top + private->drawable.height;
 
-      if (!SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle))
-       g_warning ("gdk_window_new: AdjustWindowRectEx failed");
+      SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
 
       if (x != CW_USEDEFAULT)
        {
@@ -437,7 +447,7 @@ gdk_window_new (GdkWindow     *parent,
                    NULL);
 
   GDK_NOTE (MISC,
-           g_print ("gdk_window_create: %s %s %dx%d@+%d+%d %#x = %#x\n"
+           g_print ("gdk_window_new: %s %s %dx%d@+%d+%d %#x = %#x\n"
                     "...locale %#x codepage %d\n",
                     (private->drawable.window_type == GDK_WINDOW_TOPLEVEL ? "TOPLEVEL" :
                      (private->drawable.window_type == GDK_WINDOW_CHILD ? "CHILD" :
@@ -456,7 +466,7 @@ gdk_window_new (GdkWindow     *parent,
 
   if (GDK_DRAWABLE_XID (window) == NULL)
     {
-      g_warning ("gdk_window_create: CreateWindowEx failed");
+      WIN32_API_FAILED ("CreateWindowEx");
       g_free (GDK_DRAWABLE_WIN32DATA (window));
       g_free (private);
       return NULL;
@@ -780,8 +790,7 @@ gdk_window_move (GdkWindow *window,
 
          dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
          dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
-         if (!SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle))
-           g_warning ("gdk_window_move: AdjustWindowRectEx failed");
+         SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
 
          x = rect.left;
          y = rect.top;
@@ -798,7 +807,7 @@ gdk_window_move (GdkWindow *window,
       if (!MoveWindow (GDK_DRAWABLE_XID (window),
                       x, y, rect.right - rect.left, rect.bottom - rect.top,
                       TRUE))
-       g_warning ("gdk_window_move: MoveWindow failed");
+       WIN32_API_FAILED ("MoveWindow");
     }
 }
 
@@ -846,7 +855,7 @@ gdk_window_resize (GdkWindow *window,
          dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
          dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
          if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle))
-           g_warning ("gdk_window_resize: AdjustWindowRectEx failed");
+           WIN32_API_FAILED ("AdjustWindowRectEx");
 
          x = rect.left;
          y = rect.top;
@@ -869,7 +878,7 @@ gdk_window_resize (GdkWindow *window,
       if (!MoveWindow (GDK_DRAWABLE_XID (window),
                       x, y, width, height,
                       TRUE))
-       g_warning ("gdk_window_resize: MoveWindow failed");
+       WIN32_API_FAILED ("MoveWindow");
     }
 }
 
@@ -907,7 +916,7 @@ gdk_window_move_resize (GdkWindow *window,
       dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
       dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
       if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle))
-       g_warning ("gdk_window_move_resize: AdjustWindowRectEx failed");
+       WIN32_API_FAILED ("AdjustWindowRectEx");
 
       if (private->drawable.window_type == GDK_WINDOW_CHILD)
        {
@@ -924,7 +933,7 @@ gdk_window_move_resize (GdkWindow *window,
                       rect.left, rect.top,
                       rect.right - rect.left, rect.bottom - rect.top,
                       TRUE))
-       g_warning ("gdk_window_move_resize: MoveWindow failed");
+       WIN32_API_FAILED ("MoveWindow");
 
       if (private->guffaw_gravity)
        {
@@ -970,14 +979,14 @@ gdk_window_reparent (GdkWindow *window,
                               GDK_DRAWABLE_XID (new_parent)));
       if (!SetParent (GDK_DRAWABLE_XID (window),
                      GDK_DRAWABLE_XID (new_parent)))
-       g_warning ("gdk_window_reparent: SetParent failed");
+       WIN32_API_FAILED ("SetParent");
 
       if (!MoveWindow (GDK_DRAWABLE_XID (window),
                       x, y,
                       window_private->drawable.width,
                       window_private->drawable.height,
                       TRUE))
-       g_warning ("gdk_window_reparent: MoveWindow failed");
+       WIN32_API_FAILED ("MoveWindow");
     }
   
   window_private->parent = new_parent;
@@ -1001,16 +1010,16 @@ gdk_window_clear (GdkWindow *window)
   g_return_if_fail (GDK_IS_WINDOW (window));
 
   if (!GDK_DRAWABLE_DESTROYED (window))
-    gdk_window_clear_area (window, 0, 0, -1, -1);
+    gdk_window_clear_area (window, 0, 0, 0, 0);
 }
 
 
 void
-gdk_window_clear_area (GdkWindow *window,
-                      gint       x,
-                      gint       y,
-                      gint       width,
-                      gint       height)
+_gdk_windowing_window_clear_area (GdkWindow *window,
+                                 gint       x,
+                                 gint       y,
+                                 gint       width,
+                                 gint       height)
 {
   g_return_if_fail (window != NULL);
   g_return_if_fail (GDK_IS_WINDOW (window));
@@ -1019,25 +1028,26 @@ gdk_window_clear_area (GdkWindow *window,
     {
       HDC hdc;
 
-      if (width == -1)
-       width = G_MAXSHORT/2;           /* Yeah, right */
-      if (height == -1)
-       height = G_MAXSHORT/2;
-      GDK_NOTE (MISC, g_print ("gdk_window_clear_area: %#x %dx%d@+%d+%d\n",
+      if (width == 0)
+       width = ((GdkDrawablePrivate *) window)->width - x;
+      if (height == 0)
+       height = ((GdkDrawablePrivate *) window)->height - y;
+      GDK_NOTE (MISC, g_print ("_gdk_windowing_window_clear_area: "
+                              "%#x %dx%d@+%d+%d\n",
                               GDK_DRAWABLE_XID (window), width, height, x, y));
       hdc = GetDC (GDK_DRAWABLE_XID (window));
-      IntersectClipRect (hdc, x, y, x + width, y + height);
+      IntersectClipRect (hdc, x, y, x + width + 1, y + height + 1);
       SendMessage (GDK_DRAWABLE_XID (window), WM_ERASEBKGND, (WPARAM) hdc, 0);
       ReleaseDC (GDK_DRAWABLE_XID (window), hdc);
     }
 }
 
 void
-gdk_window_clear_area_e (GdkWindow *window,
-                        gint       x,
-                        gint       y,
-                        gint       width,
-                        gint       height)
+_gdk_windowing_window_clear_area_e (GdkWindow *window,
+                                   gint       x,
+                                   gint       y,
+                                   gint       width,
+                                   gint       height)
 {
   g_return_if_fail (window != NULL);
   g_return_if_fail (GDK_IS_WINDOW (window));
@@ -1046,15 +1056,16 @@ gdk_window_clear_area_e (GdkWindow *window,
     {
       RECT rect;
 
-      GDK_NOTE (MISC, g_print ("gdk_window_clear_area_e: %#x %dx%d@+%d+%d\n",
+      GDK_NOTE (MISC, g_print ("_gdk_windowing_window_clear_area_e: "
+                              "%#x %dx%d@+%d+%d\n",
                               GDK_DRAWABLE_XID (window), width, height, x, y));
 
       rect.left = x;
-      rect.right = x + width;
+      rect.right = x + width + 1;
       rect.top = y;
-      rect.bottom = y + height;
+      rect.bottom = y + height + 1;
       if (!InvalidateRect (GDK_DRAWABLE_XID (window), &rect, TRUE))
-       g_warning ("gdk_window_clear_area_e: InvalidateRect failed");
+       WIN32_GDI_FAILED ("InvalidateRect");
       UpdateWindow (GDK_DRAWABLE_XID (window));
     }
 }
@@ -1071,7 +1082,7 @@ gdk_window_raise (GdkWindow *window)
                               GDK_DRAWABLE_XID (window)));
 
       if (!BringWindowToTop (GDK_DRAWABLE_XID (window)))
-       g_warning ("gdk_window_raise: BringWindowToTop failed");
+       WIN32_API_FAILED ("BringWindowToTop");
     }
 }
 
@@ -1088,7 +1099,7 @@ gdk_window_lower (GdkWindow *window)
 
       if (!SetWindowPos (GDK_DRAWABLE_XID (window), HWND_BOTTOM, 0, 0, 0, 0,
                         SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE))
-       g_warning ("gdk_window_lower: SetWindowPos failed");
+       WIN32_API_FAILED ("SetWindowPos");
     }
 }
 
@@ -1126,7 +1137,7 @@ gdk_window_set_hints (GdkWindow *window,
     {
       if (flags & GDK_HINT_POS)
        if (!GetWindowPlacement (GDK_DRAWABLE_XID (window), &size_hints))
-         g_warning ("gdk_window_set_hints: GetWindowPlacement failed");
+         WIN32_API_FAILED ("GetWindowPlacement");
        else
          {
            GDK_NOTE (MISC, g_print ("...rcNormalPosition:"
@@ -1163,7 +1174,7 @@ gdk_window_set_hints (GdkWindow *window,
                                     size_hints.rcNormalPosition.right,
                                     size_hints.rcNormalPosition.bottom));
            if (!SetWindowPlacement (GDK_DRAWABLE_XID (window), &size_hints))
-             g_warning ("gdk_window_set_hints: SetWindowPlacement failed");
+             WIN32_API_FAILED ("SetWindowPlacement");
            GDK_WINDOW_WIN32DATA (window)->hint_x = rect.left;
            GDK_WINDOW_WIN32DATA (window)->hint_y = rect.top;
          }
@@ -1292,7 +1303,7 @@ gdk_window_set_geometry_hints (GdkWindow      *window,
       && geometry->base_width > 0
       && geometry->base_height > 0)
     if (!GetWindowPlacement (GDK_DRAWABLE_XID (window), &size_hints))
-      g_warning ("gdk_window_set_hints: GetWindowPlacement failed");
+      WIN32_API_FAILED ("GetWindowPlacement");
     else
       {
        GDK_NOTE (MISC, g_print ("gdk_window_set_geometry_hints:"
@@ -1311,7 +1322,7 @@ gdk_window_set_geometry_hints (GdkWindow      *window,
                                 size_hints.rcNormalPosition.right,
                                 size_hints.rcNormalPosition.bottom));
        if (!SetWindowPlacement (GDK_DRAWABLE_XID (window), &size_hints))
-         g_warning ("gdk_window_set_hints: SetWindowPlacement failed");
+         WIN32_API_FAILED ("SetWindowPlacement");
       }
   
   if (geom_mask & GDK_HINT_RESIZE_INC)
@@ -1336,12 +1347,14 @@ gdk_window_set_title (GdkWindow   *window,
 
   g_return_if_fail (window != NULL);
   g_return_if_fail (GDK_IS_WINDOW (window));
+  g_return_if_fail (title != NULL);
+  g_return_if_fail (strlen (title) > 0);
   
   GDK_NOTE (MISC, g_print ("gdk_window_set_title: %#x %s\n",
                           GDK_DRAWABLE_XID (window), title));
   if (!GDK_DRAWABLE_DESTROYED (window))
     {
-      /* As the title most is in UTF-8 we must translate it
+      /* As the title is in UTF-8 we must translate it
        * to the system codepage.
        */
       titlelen = strlen (title);
@@ -1353,7 +1366,7 @@ gdk_window_set_title (GdkWindow   *window,
                           mbstr, 3*titlelen, NULL, NULL);
 
       if (!SetWindowText (GDK_DRAWABLE_XID (window), mbstr))
-       g_warning ("gdk_window_set_title: SetWindowText failed");
+       WIN32_API_FAILED ("SetWindowText");
 
       g_free (mbstr);
       g_free (wcstr);
@@ -1408,7 +1421,7 @@ gdk_window_set_background (GdkWindow *window,
          GDK_WINDOW_WIN32DATA (window)->bg_type = GDK_WIN32_BG_NORMAL;
        }
       GDK_WINDOW_WIN32DATA (window)->bg_type = GDK_WIN32_BG_PIXEL;
-      GDK_WINDOW_WIN32DATA (window)->bg_pixel = *color;
+      GDK_WINDOW_WIN32DATA (window)->bg_pixel = color->pixel;
     }
 }
 
@@ -1458,6 +1471,7 @@ gdk_window_set_cursor (GdkWindow *window,
 {
   GdkCursorPrivate *cursor_private;
   HCURSOR xcursor;
+  POINT pt;
   
   g_return_if_fail (window != NULL);
   g_return_if_fail (GDK_IS_WINDOW (window));
@@ -1474,6 +1488,10 @@ gdk_window_set_cursor (GdkWindow *window,
       GDK_NOTE (MISC, g_print ("gdk_window_set_cursor: %#x %#x\n",
                               GDK_DRAWABLE_XID (window), xcursor));
       GDK_WINDOW_WIN32DATA (window)->xcursor = xcursor;
+
+      GetCursorPos (&pt);
+      if (ChildWindowFromPoint (GDK_DRAWABLE_XID (window), pt) == GDK_DRAWABLE_XID (window))
+       SetCursor (xcursor);
     }
 }
 
@@ -1495,7 +1513,7 @@ gdk_window_get_geometry (GdkWindow *window,
       RECT rect;
 
       if (!GetClientRect (GDK_DRAWABLE_XID (window), &rect))
-       g_warning ("gdk_window_get_geometry: GetClientRect failed");
+       WIN32_API_FAILED ("GetClientRect");
 
       if (x)
        *x = rect.left;
@@ -1822,12 +1840,15 @@ gdk_window_set_icon (GdkWindow *window,
   if (GDK_DRAWABLE_DESTROYED (window))
     return;
   
-  g_warning ("gdk_window_set_icon not implemented");
+  /* Nothing to do, really. As we share window classes between windows
+   * we can't have window-specific icons, sorry. Don't print any warning
+   * either.
+   */
 }
 
 void
-gdk_window_set_icon_name (GdkWindow *window, 
-                         gchar     *name)
+gdk_window_set_icon_name (GdkWindow   *window, 
+                         const gchar *name)
 {
   g_return_if_fail (window != NULL);
   g_return_if_fail (GDK_IS_WINDOW (window));
@@ -1836,7 +1857,7 @@ gdk_window_set_icon_name (GdkWindow *window,
     return;
   
   if (!SetWindowText (GDK_DRAWABLE_XID (window), name))
-    g_warning ("gdk_window_set_icon_name: SetWindowText failed");
+    WIN32_API_FAILED ("SetWindowText");
 }
 
 void          
@@ -1985,7 +2006,7 @@ gdk_propagate_shapes (HANDLE   win,
        for (i = 0; i < num; i++)
         {
           GetWindowPlacement (list[i], &placement);
-          if (placement.showCmd = SW_SHOWNORMAL)
+          if (placement.showCmd == SW_SHOWNORMAL)
             {
               childRegion = CreateRectRgnIndirect (&emptyRect);
               GetWindowRgn (list[i], childRegion);