]> Pileus Git - ~andy/gtk/blobdiff - gdk/win32/gdkwindow-win32.c
gtk/gtkmain.c Use the new
[~andy/gtk] / gdk / win32 / gdkwindow-win32.c
index fd72bc5fb283e1fd95c1f58ff749e5e50841e8b9..6a7fc6abec1b30dc751d487611b7ca111cd42cd8 100644 (file)
@@ -3,23 +3,23 @@
  * Copyright (C) 1998-1999 Tor Lillqvist
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
 
 /*
- * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
@@ -32,8 +32,7 @@
 #include "gdkwindow.h"
 #include "gdkinternals.h"
 #include "gdkprivate-win32.h"
-#include "gdkwindow-win32.h"
-#include "gdkpixmap-win32.h"
+#include "gdkinput-win32.h"
 
 static gboolean gdk_window_gravity_works (void);
 static void     gdk_window_set_static_win_gravity (GdkWindow *window, 
@@ -45,6 +44,7 @@ static void         gdk_window_impl_win32_set_colormap (GdkDrawable *drawable,
 static void         gdk_window_impl_win32_get_size     (GdkDrawable *drawable,
                                                        gint *width,
                                                        gint *height);
+static GdkRegion*  gdk_window_impl_win32_get_visible_region (GdkDrawable *drawable);
 static void gdk_window_impl_win32_init       (GdkWindowImplWin32      *window);
 static void gdk_window_impl_win32_class_init (GdkWindowImplWin32Class *klass);
 static void gdk_window_impl_win32_finalize   (GObject                 *object);
@@ -73,7 +73,7 @@ gdk_window_impl_win32_get_type (void)
       
       object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_WIN32,
                                             "GdkWindowImplWin32",
-                                            &object_info);
+                                            &object_info, 0);
     }
   
   return object_type;
@@ -113,6 +113,10 @@ gdk_window_impl_win32_class_init (GdkWindowImplWin32Class *klass)
   drawable_class->set_colormap = gdk_window_impl_win32_set_colormap;
   drawable_class->get_colormap = gdk_window_impl_win32_get_colormap;
   drawable_class->get_size = gdk_window_impl_win32_get_size;
+
+  /* Visible and clip regions are the same */
+  drawable_class->get_clip_region = gdk_window_impl_win32_get_visible_region;
+  drawable_class->get_visible_region = gdk_window_impl_win32_get_visible_region;
 }
 
 static void
@@ -136,7 +140,8 @@ gdk_window_impl_win32_finalize (GObject *object)
 
   if (window_impl->hcursor != NULL)
     {
-      DestroyCursor (window_impl->hcursor);
+      if (!DestroyCursor (window_impl->hcursor))
+        WIN32_GDI_FAILED("DestroyCursor");
       window_impl->hcursor = NULL;
     }
 
@@ -157,7 +162,8 @@ gdk_window_impl_win32_get_colormap (GdkDrawable *drawable)
   if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only && 
       drawable_impl->colormap == NULL)
     {
-      g_assert_not_reached ();
+      drawable_impl->colormap = gdk_colormap_get_system ();
+      gdk_colormap_ref (drawable_impl->colormap);
     }
   
   return drawable_impl->colormap;
@@ -179,7 +185,7 @@ gdk_window_impl_win32_set_colormap (GdkDrawable *drawable,
   GDK_DRAWABLE_GET_CLASS (draw_impl)->set_colormap (drawable, cmap);
   
   /* XXX */
-
+  g_print("gdk_window_impl_win32_set_colormap: XXX\n");
 }
 
 static void
@@ -195,6 +201,22 @@ gdk_window_impl_win32_get_size (GdkDrawable *drawable,
     *height = GDK_WINDOW_IMPL_WIN32 (drawable)->height;
 }
 
+static GdkRegion*
+gdk_window_impl_win32_get_visible_region (GdkDrawable *drawable)
+{
+  GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (drawable);
+  GdkRectangle result_rect;
+
+  result_rect.x = 0;
+  result_rect.y = 0;
+  result_rect.width = impl->width;
+  result_rect.height = impl->height;
+
+  gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
+
+  return gdk_region_rectangle (&result_rect);
+}
+
 void
 _gdk_windowing_window_init (void)
 {
@@ -224,7 +246,7 @@ _gdk_windowing_window_init (void)
   impl->width = width;
   impl->height = height;
 
-  gdk_win32_handle_table_insert (gdk_root_window, gdk_parent_root);
+  gdk_win32_handle_table_insert (&gdk_root_window, gdk_parent_root);
 }
 
 /* The Win API function AdjustWindowRect may return negative values
@@ -394,9 +416,6 @@ gdk_window_new (GdkWindow     *parent,
   int width, height;
   int x, y;
   char *title;
-  gint titlelen;
-  wchar_t *wctitle;
-  gint wlen;
   char *mbtitle;
 
   g_return_val_if_fail (attributes != NULL, NULL);
@@ -406,6 +425,14 @@ gdk_window_new (GdkWindow     *parent,
 
   g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
   
+  GDK_NOTE (MISC,
+           g_print ("gdk_window_new: %s\n",
+                    (attributes->window_type == GDK_WINDOW_TOPLEVEL ? "TOPLEVEL" :
+                     (attributes->window_type == GDK_WINDOW_CHILD ? "CHILD" :
+                      (attributes->window_type == GDK_WINDOW_DIALOG ? "DIALOG" :
+                       (attributes->window_type == GDK_WINDOW_TEMP ? "TEMP" :
+                        "???"))))));
+
   parent_private = (GdkWindowObject*) parent;
   if (GDK_WINDOW_DESTROYED (parent))
     return NULL;
@@ -453,7 +480,7 @@ gdk_window_new (GdkWindow     *parent,
     title = attributes->title;
   else
     title = g_get_prgname ();
-  if (!title)
+  if (!title || !*title)
     title = "GDK client window";
 
   impl->event_mask = GDK_STRUCTURE_MASK | attributes->event_mask;
@@ -479,14 +506,16 @@ gdk_window_new (GdkWindow     *parent,
        {
          if ((((GdkVisualPrivate*)gdk_visual_get_system ())->xvisual) == xvisual)
             {
-              draw_impl->colormap =
-                gdk_colormap_get_system ();
+              draw_impl->colormap = gdk_colormap_get_system ();
               gdk_colormap_ref (draw_impl->colormap);
+             GDK_NOTE (MISC, g_print ("...using system colormap %p\n",
+                                      draw_impl->colormap));
             }
          else
             {
-              draw_impl->colormap =
-                gdk_colormap_new (visual, FALSE);
+              draw_impl->colormap = gdk_colormap_new (visual, FALSE);
+             GDK_NOTE (MISC, g_print ("...using new colormap %p\n",
+                                      draw_impl->colormap));
             }
        }
     }
@@ -496,6 +525,7 @@ gdk_window_new (GdkWindow     *parent,
       private->depth = 0;
       private->input_only = TRUE;
       draw_impl->colormap = NULL;
+      GDK_NOTE (MISC, g_print ("...GDK_INPUT_ONLY, NULL colormap\n"));
     }
 
   if (parent_private)
@@ -564,14 +594,9 @@ gdk_window_new (GdkWindow     *parent,
       height = impl->height;
     }
 
-  titlelen = strlen (title);
-  wctitle = g_new (wchar_t, titlelen + 1);
-  mbtitle = g_new (char, 3*titlelen + 1);
-  wlen = gdk_nmbstowchar_ts (wctitle, title, titlelen, titlelen);
-  wctitle[wlen] = 0;
-  WideCharToMultiByte (GetACP (), 0, wctitle, -1,
-                      mbtitle, 3*titlelen, NULL, NULL);
+  mbtitle = g_locale_from_utf8 (title, -1, NULL, NULL, NULL);
   
+#ifdef WITHOUT_WM_CREATE
   draw_impl->handle = CreateWindowEx (dwExStyle,
                                      MAKEINTRESOURCE(klass),
                                      mbtitle,
@@ -582,24 +607,56 @@ gdk_window_new (GdkWindow     *parent,
                                      NULL,
                                      gdk_app_hmodule,
                                      NULL);
+#else
+  {
+  HWND hwndNew =
+    CreateWindowEx (dwExStyle,
+                   MAKEINTRESOURCE(klass),
+                   mbtitle,
+                   dwStyle,
+                   x, y, 
+                   width, height,
+                   hparent,
+                   NULL,
+                   gdk_app_hmodule,
+                   window);
+  if (GDK_WINDOW_HWND (window) != hwndNew)
+    {
+      g_warning("gdk_window_new: gdk_event_translate::WM_CREATE (%#x, %#x) HWND mismatch.",
+               (guint) GDK_WINDOW_HWND (window),
+               (guint) hwndNew);
+
+      /* HB: IHMO due to a race condition the handle was increased by
+       * one, which causes much trouble. Because I can't find the 
+       * real bug, try to workaround it ...
+       * To reproduce: compile with MSVC 5, DEBUG=1
+       */
+# if 0
+      gdk_win32_handle_table_remove (GDK_WINDOW_HWND (window));
+      GDK_WINDOW_HWND (window) = hwndNew;
+      gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window);
+# else
+      /* the old behaviour, but with warning */
+      GDK_WINDOW_HWND (window) = hwndNew;
+# endif
+
+    }
+  }
+  gdk_drawable_ref (window);
+  gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window);
+#endif
 
   GDK_NOTE (MISC,
-           g_print ("gdk_window_new: %s %s %dx%d@+%d+%d %#x = %#x\n"
-                    "...locale %#x codepage %d\n",
-                    (private->window_type == GDK_WINDOW_TOPLEVEL ? "TOPLEVEL" :
-                     (private->window_type == GDK_WINDOW_CHILD ? "CHILD" :
-                      (private->window_type == GDK_WINDOW_DIALOG ? "DIALOG" :
-                       (private->window_type == GDK_WINDOW_TEMP ? "TEMP" :
-                        "???")))),
+           g_print ("... \"%s\" %dx%d@+%d+%d %#x = %#x\n"
+                    "... locale %#x codepage %d\n",
                     mbtitle,
                     width, height, (x == CW_USEDEFAULT ? -9999 : x), y, 
-                    hparent,
-                    GDK_WINDOW_HWND (window),
-                    impl->input_locale,
-                    impl->charset_info.ciACP));
+                    (guint) hparent,
+                    (guint) GDK_WINDOW_HWND (window),
+                    (guint) impl->input_locale,
+                    (guint) impl->charset_info.ciACP));
 
   g_free (mbtitle);
-  g_free (wctitle);
 
   if (draw_impl->handle == NULL)
     {
@@ -608,8 +665,10 @@ gdk_window_new (GdkWindow     *parent,
       return NULL;
     }
 
+#ifdef WITHOUT_WM_CREATE
   gdk_drawable_ref (window);
-  gdk_win32_handle_table_insert (GDK_WINDOW_HWND (window), window);
+  gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window);
+#endif
 
   gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
                                  (attributes->cursor) :
@@ -636,8 +695,9 @@ gdk_window_foreign_new (GdkNativeWindow anid)
   impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
   draw_impl = GDK_DRAWABLE_IMPL_WIN32 (private->impl);
   draw_impl->wrapper = GDK_DRAWABLE (window);
+  parent = GetParent ((HWND)anid);
   
-  private->parent = gdk_win32_handle_table_lookup (parent);
+  private->parent = gdk_win32_handle_table_lookup ((GdkNativeWindow) parent);
   
   parent_private = (GdkWindowObject *)private->parent;
   
@@ -661,7 +721,7 @@ gdk_window_foreign_new (GdkNativeWindow anid)
   private->depth = gdk_visual_get_system ()->depth;
 
   gdk_drawable_ref (window);
-  gdk_win32_handle_table_insert (GDK_WINDOW_HWND (window), window);
+  gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window);
 
   return window;
 }
@@ -676,7 +736,7 @@ _gdk_windowing_window_destroy (GdkWindow *window,
   g_return_if_fail (GDK_IS_WINDOW (window));
   
   GDK_NOTE (MISC, g_print ("_gdk_windowing_window_destroy %#x\n",
-                          GDK_WINDOW_HWND (window)));
+                          (guint) GDK_WINDOW_HWND (window)));
 
   if (private->extension_events != 0)
     gdk_input_window_destroy (window);
@@ -710,17 +770,18 @@ void
 gdk_window_destroy_notify (GdkWindow *window)
 {
   g_return_if_fail (window != NULL);
+  g_return_if_fail (GDK_IS_WINDOW (window));
 
   GDK_NOTE (EVENTS,
            g_print ("gdk_window_destroy_notify: %#x  %s\n",
-                    GDK_WINDOW_HWND (window),
+                    (guint) GDK_WINDOW_HWND (window),
                     (GDK_WINDOW_DESTROYED (window) ? "(destroyed)" : "")));
 
   if (!GDK_WINDOW_DESTROYED (window))
     {
       if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
        g_warning ("window %#x unexpectedly destroyed",
-                  GDK_WINDOW_HWND (window));
+                  (guint) GDK_WINDOW_HWND (window));
 
       _gdk_window_destroy (window, TRUE);
     }
@@ -740,7 +801,7 @@ gdk_window_show (GdkWindow *window)
   if (!private->destroyed)
     {
       GDK_NOTE (MISC, g_print ("gdk_window_show: %#x\n",
-                              GDK_WINDOW_HWND (window)));
+                              (guint) GDK_WINDOW_HWND (window)));
 
       private->mapped = TRUE;
       if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP)
@@ -755,13 +816,24 @@ gdk_window_show (GdkWindow *window)
        }
       else
        {
-         ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNORMAL);
-         ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
-         SetForegroundWindow (GDK_WINDOW_HWND (window));
-         BringWindowToTop (GDK_WINDOW_HWND (window));
+          if (GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE) & WS_EX_TRANSPARENT)
+           {
+             SetWindowPos(GDK_WINDOW_HWND (window), HWND_TOP, 0, 0, 0, 0,
+                          SWP_SHOWWINDOW | SWP_NOREDRAW | SWP_NOMOVE | SWP_NOSIZE);
+           }
+          else
+            {
+             GdkWindow *parent = private->parent;
+
+             ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNORMAL);
+             ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
+              if (parent == gdk_parent_root)
+                SetForegroundWindow (GDK_WINDOW_HWND (window));
+             BringWindowToTop (GDK_WINDOW_HWND (window));
 #if 0
-         ShowOwnedPopups (GDK_WINDOW_HWND (window), TRUE);
+             ShowOwnedPopups (GDK_WINDOW_HWND (window), TRUE);
 #endif
+           }
        }
     }
 }
@@ -777,13 +849,21 @@ gdk_window_hide (GdkWindow *window)
   if (!private->destroyed)
     {
       GDK_NOTE (MISC, g_print ("gdk_window_hide: %#x\n",
-                              GDK_WINDOW_HWND (window)));
+                              (guint) GDK_WINDOW_HWND (window)));
 
       private->mapped = FALSE;
       if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL)
        ShowOwnedPopups (GDK_WINDOW_HWND (window), FALSE);
 
-      ShowWindow (GDK_WINDOW_HWND (window), SW_HIDE);
+      if (GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE) & WS_EX_TRANSPARENT)
+       {
+         SetWindowPos(GDK_WINDOW_HWND (window), HWND_BOTTOM, 0, 0, 0, 0,
+                      SWP_HIDEWINDOW | SWP_NOREDRAW | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE);
+       }
+      else
+       {
+         ShowWindow (GDK_WINDOW_HWND (window), SW_HIDE);
+       }
     }
 }
 
@@ -798,7 +878,7 @@ gdk_window_withdraw (GdkWindow *window)
   if (!private->destroyed)
     {
       GDK_NOTE (MISC, g_print ("gdk_window_withdraw: %#x\n",
-                              GDK_WINDOW_HWND (window)));
+                              (guint) GDK_WINDOW_HWND (window)));
 
       gdk_window_hide (window);        /* ??? */
     }
@@ -842,7 +922,8 @@ gdk_window_resize (GdkWindow *window,
   if (!private->destroyed)
     {
       GDK_NOTE (MISC, g_print ("gdk_window_resize: %#x %dx%d\n",
-                              GDK_WINDOW_HWND (window), width, height));
+                              (guint) GDK_WINDOW_HWND (window),
+                              width, height));
       
       if (GDK_WINDOW_TYPE (private) != GDK_WINDOW_CHILD)
        {
@@ -879,9 +960,9 @@ gdk_window_resize (GdkWindow *window,
 
       private->resize_count += 1;
 
-      GDK_NOTE (MISC,
-               g_print ("...MoveWindow(%#x,%dx%d@+%d+%d)\n",
-                        GDK_WINDOW_HWND (window), width, height, x, y));
+      GDK_NOTE (MISC, g_print ("...MoveWindow(%#x,%dx%d@+%d+%d)\n",
+                              (guint) GDK_WINDOW_HWND (window),
+                              width, height, x, y));
       if (!MoveWindow (GDK_WINDOW_HWND (window), x, y, width, height, TRUE))
        WIN32_API_FAILED ("MoveWindow");
     }
@@ -914,7 +995,8 @@ gdk_window_move_resize (GdkWindow *window,
       DWORD dwExStyle;
 
       GDK_NOTE (MISC, g_print ("gdk_window_move_resize: %#x %dx%d@+%d+%d\n",
-                              GDK_WINDOW_HWND (window), width, height, x, y));
+                              (guint) GDK_WINDOW_HWND (window),
+                              width, height, x, y));
       
       if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
        _gdk_window_move_resize_child (window, x, y, width, height);
@@ -930,8 +1012,8 @@ gdk_window_move_resize (GdkWindow *window,
          if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle))
            WIN32_API_FAILED ("AdjustWindowRectEx");
 
-         GDK_NOTE (MISC, g_print ("...MoveWindow(%#x,%dx%d@+%d+%d)\n",
-                                  GDK_WINDOW_HWND (window),
+         GDK_NOTE (MISC, g_print ("...MoveWindow(%#x,%ldx%ld@+%ld+%ld)\n",
+                                  (guint) GDK_WINDOW_HWND (window),
                                   rect.right - rect.left, rect.bottom - rect.top,
                                   rect.left, rect.top));
          if (!MoveWindow (GDK_WINDOW_HWND (window),
@@ -967,8 +1049,8 @@ gdk_window_reparent (GdkWindow *window,
   if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
     {
       GDK_NOTE (MISC, g_print ("gdk_window_reparent: %#x %#x\n",
-                              GDK_WINDOW_HWND (window),
-                              GDK_WINDOW_HWND (new_parent)));
+                              (guint) GDK_WINDOW_HWND (window),
+                              (guint) GDK_WINDOW_HWND (new_parent)));
       if (!SetParent (GDK_WINDOW_HWND (window),
                      GDK_WINDOW_HWND (new_parent)))
        WIN32_API_FAILED ("SetParent");
@@ -1016,7 +1098,8 @@ _gdk_windowing_window_clear_area (GdkWindow *window,
        height = impl->height - y;
       GDK_NOTE (MISC, g_print ("_gdk_windowing_window_clear_area: "
                               "%#x %dx%d@+%d+%d\n",
-                              GDK_WINDOW_HWND (window), width, height, x, y));
+                              (guint) GDK_WINDOW_HWND (window),
+                              width, height, x, y));
       hdc = GetDC (GDK_WINDOW_HWND (window));
       IntersectClipRect (hdc, x, y, x + width + 1, y + height + 1);
       SendMessage (GDK_WINDOW_HWND (window), WM_ERASEBKGND, (WPARAM) hdc, 0);
@@ -1040,7 +1123,8 @@ _gdk_windowing_window_clear_area_e (GdkWindow *window,
 
       GDK_NOTE (MISC, g_print ("_gdk_windowing_window_clear_area_e: "
                               "%#x %dx%d@+%d+%d\n",
-                              GDK_WINDOW_HWND (window), width, height, x, y));
+                              (guint) GDK_WINDOW_HWND (window),
+                              width, height, x, y));
 
       rect.left = x;
       rect.right = x + width + 1;
@@ -1061,7 +1145,7 @@ gdk_window_raise (GdkWindow *window)
   if (!GDK_WINDOW_DESTROYED (window))
     {
       GDK_NOTE (MISC, g_print ("gdk_window_raise: %#x\n",
-                              GDK_WINDOW_HWND (window)));
+                              (guint) GDK_WINDOW_HWND (window)));
 
       if (!BringWindowToTop (GDK_WINDOW_HWND (window)))
        WIN32_API_FAILED ("BringWindowToTop");
@@ -1077,7 +1161,7 @@ gdk_window_lower (GdkWindow *window)
   if (!GDK_WINDOW_DESTROYED (window))
     {
       GDK_NOTE (MISC, g_print ("gdk_window_lower: %#x\n",
-                              GDK_WINDOW_HWND (window)));
+                              (guint) GDK_WINDOW_HWND (window)));
 
       if (!SetWindowPos (GDK_WINDOW_HWND (window), HWND_BOTTOM, 0, 0, 0, 0,
                         SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE))
@@ -1111,7 +1195,7 @@ gdk_window_set_hints (GdkWindow *window,
   impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
 
   GDK_NOTE (MISC, g_print ("gdk_window_set_hints: %#x %dx%d..%dx%d @+%d+%d\n",
-                          GDK_WINDOW_HWND (window),
+                          (guint) GDK_WINDOW_HWND (window),
                           min_width, min_height, max_width, max_height,
                           x, y));
 
@@ -1121,48 +1205,50 @@ gdk_window_set_hints (GdkWindow *window,
   if (flags)
     {
       if (flags & GDK_HINT_POS)
-       if (!GetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
-         WIN32_API_FAILED ("GetWindowPlacement");
-       else
-         {
-           GDK_NOTE (MISC, g_print ("...rcNormalPosition:"
-                                    " (%d,%d)--(%d,%d)\n",
-                                    size_hints.rcNormalPosition.left,
-                                    size_hints.rcNormalPosition.top,
-                                    size_hints.rcNormalPosition.right,
-                                    size_hints.rcNormalPosition.bottom));
-           /* What are the corresponding window coordinates for client
-            * area coordinates x, y
-            */
-           rect.left = x;
-           rect.top = y;
-           rect.right = rect.left + 200;       /* dummy */
-           rect.bottom = rect.top + 200;
-           dwStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
-           dwExStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
-           AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
-           size_hints.flags = 0;
-           size_hints.showCmd = SW_SHOWNA;
-
-           /* Set the normal position hint to that location, with unchanged
-            * width and height.
-            */
-           diff = size_hints.rcNormalPosition.left - rect.left;
-           size_hints.rcNormalPosition.left = rect.left;
-           size_hints.rcNormalPosition.right -= diff;
-           diff = size_hints.rcNormalPosition.top - rect.top;
-           size_hints.rcNormalPosition.top = rect.top;
-           size_hints.rcNormalPosition.bottom -= diff;
-           GDK_NOTE (MISC, g_print ("...setting: (%d,%d)--(%d,%d)\n",
-                                    size_hints.rcNormalPosition.left,
-                                    size_hints.rcNormalPosition.top,
-                                    size_hints.rcNormalPosition.right,
-                                    size_hints.rcNormalPosition.bottom));
-           if (!SetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
-             WIN32_API_FAILED ("SetWindowPlacement");
-           impl->hint_x = rect.left;
-           impl->hint_y = rect.top;
-         }
+       {
+         if (!GetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
+           WIN32_API_FAILED ("GetWindowPlacement");
+         else
+           {
+             GDK_NOTE (MISC, g_print ("...rcNormalPosition:"
+                                      " (%ld,%ld)--(%ld,%ld)\n",
+                                      size_hints.rcNormalPosition.left,
+                                      size_hints.rcNormalPosition.top,
+                                      size_hints.rcNormalPosition.right,
+                                      size_hints.rcNormalPosition.bottom));
+             /* What are the corresponding window coordinates for client
+              * area coordinates x, y
+              */
+             rect.left = x;
+             rect.top = y;
+             rect.right = rect.left + 200;     /* dummy */
+             rect.bottom = rect.top + 200;
+             dwStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
+             dwExStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
+             AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
+             size_hints.flags = 0;
+             size_hints.showCmd = SW_SHOWNA;
+             
+             /* Set the normal position hint to that location, with unchanged
+              * width and height.
+              */
+             diff = size_hints.rcNormalPosition.left - rect.left;
+             size_hints.rcNormalPosition.left = rect.left;
+             size_hints.rcNormalPosition.right -= diff;
+             diff = size_hints.rcNormalPosition.top - rect.top;
+             size_hints.rcNormalPosition.top = rect.top;
+             size_hints.rcNormalPosition.bottom -= diff;
+             GDK_NOTE (MISC, g_print ("...setting: (%ld,%ld)--(%ld,%ld)\n",
+                                      size_hints.rcNormalPosition.left,
+                                      size_hints.rcNormalPosition.top,
+                                      size_hints.rcNormalPosition.right,
+                                      size_hints.rcNormalPosition.bottom));
+             if (!SetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
+               WIN32_API_FAILED ("SetWindowPlacement");
+             impl->hint_x = rect.left;
+             impl->hint_y = rect.top;
+           }
+       }
 
       if (flags & GDK_HINT_MIN_SIZE)
        {
@@ -1219,7 +1305,6 @@ gdk_window_set_geometry_hints (GdkWindow      *window,
   RECT rect;
   DWORD dwStyle;
   DWORD dwExStyle;
-  int diff;
   
   g_return_if_fail (window != NULL);
   g_return_if_fail (GDK_IS_WINDOW (window));
@@ -1266,9 +1351,13 @@ gdk_window_set_geometry_hints (GdkWindow      *window,
       rect.bottom = geometry->max_height;
       dwStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
       dwExStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
-      AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
+      /* HB: dont' know why AdjustWindowRectEx is called here, ... */
+      SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
       impl->hint_max_width = rect.right - rect.left;
       impl->hint_max_height = rect.bottom - rect.top;
+      /* ... but negative sizes are always wrong */
+      if (impl->hint_max_width < 0) impl->hint_max_width = G_MAXSHORT;
+      if (impl->hint_max_height < 0) impl->hint_max_height = G_MAXSHORT;
 
       /* Again, check if the window is too large currently. */
       GetClientRect (GDK_WINDOW_HWND (window), &rect);
@@ -1285,28 +1374,30 @@ gdk_window_set_geometry_hints (GdkWindow      *window,
   if (geom_mask & GDK_HINT_BASE_SIZE
       && geometry->base_width > 0
       && geometry->base_height > 0)
-    if (!GetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
-      WIN32_API_FAILED ("GetWindowPlacement");
-    else
-      {
-       GDK_NOTE (MISC, g_print ("gdk_window_set_geometry_hints:"
-                                " rcNormalPosition: (%d,%d)--(%d,%d)\n",
-                                size_hints.rcNormalPosition.left,
-                                size_hints.rcNormalPosition.top,
-                                size_hints.rcNormalPosition.right,
-                                size_hints.rcNormalPosition.bottom));
-       size_hints.rcNormalPosition.right =
-         size_hints.rcNormalPosition.left + geometry->base_width;
-       size_hints.rcNormalPosition.bottom =
-         size_hints.rcNormalPosition.top + geometry->base_height;
-       GDK_NOTE (MISC, g_print ("...setting: rcNormal: (%d,%d)--(%d,%d)\n",
-                                size_hints.rcNormalPosition.left,
-                                size_hints.rcNormalPosition.top,
-                                size_hints.rcNormalPosition.right,
-                                size_hints.rcNormalPosition.bottom));
-       if (!SetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
-         WIN32_API_FAILED ("SetWindowPlacement");
-      }
+    {
+      if (!GetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
+       WIN32_API_FAILED ("GetWindowPlacement");
+      else
+       {
+         GDK_NOTE (MISC, g_print ("gdk_window_set_geometry_hints:"
+                                  " rcNormalPosition: (%ld,%ld)--(%ld,%ld)\n",
+                                  size_hints.rcNormalPosition.left,
+                                  size_hints.rcNormalPosition.top,
+                                  size_hints.rcNormalPosition.right,
+                                  size_hints.rcNormalPosition.bottom));
+         size_hints.rcNormalPosition.right =
+           size_hints.rcNormalPosition.left + geometry->base_width;
+         size_hints.rcNormalPosition.bottom =
+           size_hints.rcNormalPosition.top + geometry->base_height;
+         GDK_NOTE (MISC, g_print ("...setting: rcNormal: (%ld,%ld)--(%ld,%ld)\n",
+                                  size_hints.rcNormalPosition.left,
+                                  size_hints.rcNormalPosition.top,
+                                  size_hints.rcNormalPosition.right,
+                                  size_hints.rcNormalPosition.bottom));
+         if (!SetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
+           WIN32_API_FAILED ("SetWindowPlacement");
+       }
+    }
   
   if (geom_mask & GDK_HINT_RESIZE_INC)
     {
@@ -1323,36 +1414,29 @@ void
 gdk_window_set_title (GdkWindow   *window,
                      const gchar *title)
 {
-  gint titlelen;
-  wchar_t *wcstr;
-  gint wlen;
-  char *mbstr;
+  char *mbtitle;
 
   g_return_if_fail (window != NULL);
   g_return_if_fail (GDK_IS_WINDOW (window));
   g_return_if_fail (title != NULL);
+
+  /* Empty window titles not allowed, so set it to just a period. */
+  if (!title[0])
+    title = ".";
   
   GDK_NOTE (MISC, g_print ("gdk_window_set_title: %#x %s\n",
-                          GDK_WINDOW_HWND (window), title));
+                          (guint) GDK_WINDOW_HWND (window), title));
   
   if (!GDK_WINDOW_DESTROYED (window))
     {
       /* As the title is in UTF-8 we must translate it
        * to the system codepage.
        */
-      titlelen = strlen (title);
-      wcstr = g_new (wchar_t, titlelen + 1);
-      mbstr = g_new (char, 3*titlelen + 1);
-      wlen = gdk_nmbstowchar_ts (wcstr, title, titlelen, titlelen);
-      wcstr[wlen] = 0;
-      WideCharToMultiByte (GetACP (), 0, wcstr, -1,
-                          mbstr, 3*titlelen, NULL, NULL);
-
-      if (!SetWindowText (GDK_WINDOW_HWND (window), mbstr))
+      mbtitle = g_locale_from_utf8 (title, -1, NULL, NULL, NULL);
+      if (!SetWindowText (GDK_WINDOW_HWND (window), mbtitle))
        WIN32_API_FAILED ("SetWindowText");
 
-      g_free (mbstr);
-      g_free (wcstr);
+      g_free (mbtitle);
     }
 }
 
@@ -1364,7 +1448,8 @@ gdk_window_set_role (GdkWindow   *window,
   g_return_if_fail (GDK_IS_WINDOW (window));
   
   GDK_NOTE (MISC, g_print ("gdk_window_set_role: %#x %s\n",
-                          GDK_WINDOW_HWND (window), (role ? role : "NULL")));
+                          (guint) GDK_WINDOW_HWND (window),
+                          (role ? role : "NULL")));
   /* XXX */
 }
 
@@ -1376,8 +1461,8 @@ gdk_window_set_transient_for (GdkWindow *window,
   g_return_if_fail (GDK_IS_WINDOW (window));
   
   GDK_NOTE (MISC, g_print ("gdk_window_set_transient_for: %#x %#x\n",
-                          GDK_WINDOW_HWND (window),
-                          GDK_WINDOW_HWND (parent)));
+                          (guint) GDK_WINDOW_HWND (window),
+                          (guint) GDK_WINDOW_HWND (parent)));
   /* XXX */
 }
 
@@ -1391,7 +1476,7 @@ gdk_window_set_background (GdkWindow *window,
   g_return_if_fail (GDK_IS_WINDOW (window));
   
   GDK_NOTE (MISC, g_print ("gdk_window_set_background: %#x %s\n",
-                          GDK_WINDOW_HWND (window), 
+                          (guint) GDK_WINDOW_HWND (window), 
                           gdk_win32_color_to_string (color)));
 
   private->bg_color = *color;
@@ -1462,10 +1547,12 @@ gdk_window_set_cursor (GdkWindow *window,
        hcursor = cursor_private->hcursor;
 
       GDK_NOTE (MISC, g_print ("gdk_window_set_cursor: %#x %#x\n",
-                              GDK_WINDOW_HWND (window), hcursor));
+                              (guint) GDK_WINDOW_HWND (window),
+                              (guint) hcursor));
       if (impl->hcursor != NULL)
        {
-         GDK_NOTE (MISC, g_print ("...DestroyCursor (%#x)\n", impl->hcursor));
+         GDK_NOTE (MISC, g_print ("...DestroyCursor (%#x)\n",
+                                  (guint) impl->hcursor));
          
          DestroyCursor (impl->hcursor);
          impl->hcursor = NULL;
@@ -1480,7 +1567,7 @@ gdk_window_set_cursor (GdkWindow *window,
           */
          impl->hcursor = CopyCursor (hcursor);
          GDK_NOTE (MISC, g_print ("...CopyCursor (%#x) = %#x\n",
-                                  hcursor, impl->hcursor));
+                                  (guint) hcursor, (guint) impl->hcursor));
 
          GetCursorPos (&pt);
          if (ChildWindowFromPoint (GDK_WINDOW_HWND (window), pt) == GDK_WINDOW_HWND (window))
@@ -1553,7 +1640,8 @@ gdk_window_get_origin (GdkWindow *window,
     *y = ty;
 
   GDK_NOTE (MISC, g_print ("gdk_window_get_origin: %#x: +%d+%d\n",
-                          GDK_WINDOW_HWND (window), tx, ty));
+                          (guint) GDK_WINDOW_HWND (window),
+                          tx, ty));
   return return_val;
 }
 
@@ -1598,9 +1686,10 @@ gdk_window_get_root_origin (GdkWindow *window,
   if (y)
     *y = pt.y;
 
-  GDK_NOTE (MISC, g_print ("gdk_window_get_root_origin: %#x: (%#x) +%d+%d\n",
-                          GDK_WINDOW_HWND (window),
-                          GDK_WINDOW_HWND (rover), pt.x, pt.y));
+  GDK_NOTE (MISC, g_print ("gdk_window_get_root_origin: %#x: (%#x) +%ld+%ld\n",
+                          (guint) GDK_WINDOW_HWND (window),
+                          (guint) GDK_WINDOW_HWND (rover),
+                          pt.x, pt.y));
 }
 
 GdkWindow*
@@ -1638,7 +1727,7 @@ gdk_window_get_pointer (GdkWindow       *window,
     ScreenToClient (hwndc, &point);
   } while (hwndc != hwnd && (hwnd = hwndc, 1));        /* Ouch! */
 
-  return_val = gdk_win32_handle_table_lookup (hwnd);
+  return_val = gdk_win32_handle_table_lookup ((GdkNativeWindow) hwnd);
 
   if (mask)
     {
@@ -1696,7 +1785,7 @@ gdk_window_at_pointer (gint *win_x,
     ScreenToClient (hwndc, &point);
   } while (hwndc != hwnd && (hwnd = hwndc, 1));
 
-  window = gdk_win32_handle_table_lookup (hwnd);
+  window = gdk_win32_handle_table_lookup ((GdkNativeWindow) hwnd);
 
   if (window && (win_x || win_y))
     {
@@ -1707,8 +1796,9 @@ gdk_window_at_pointer (gint *win_x,
        *win_y = point.y - rect.top;
     }
 
-  GDK_NOTE (MISC, g_print ("gdk_window_at_pointer: +%d+%d %#x%s\n",
-                          point.x, point.y, hwnd,
+  GDK_NOTE (MISC, g_print ("gdk_window_at_pointer: +%ld+%ld %#x%s\n",
+                          point.x, point.y,
+                          (guint) hwnd,
                           (window == NULL ? " NULL" : "")));
 
   return window;
@@ -1750,7 +1840,7 @@ gdk_window_shape_combine_mask (GdkWindow *window,
   if (!mask)
     {
       GDK_NOTE (MISC, g_print ("gdk_window_shape_combine_mask: %#x none\n",
-                              GDK_WINDOW_HWND (window)));
+                              (guint) GDK_WINDOW_HWND (window)));
       SetWindowRgn (GDK_WINDOW_HWND (window), NULL, TRUE);
     }
   else
@@ -1764,8 +1854,8 @@ gdk_window_shape_combine_mask (GdkWindow *window,
       hrgn = BitmapToRegion (GDK_WINDOW_HWND (mask));
 
       GDK_NOTE (MISC, g_print ("gdk_window_shape_combine_mask: %#x %#x\n",
-                              GDK_WINDOW_HWND (window),
-                              GDK_WINDOW_HWND (mask)));
+                              (guint) GDK_WINDOW_HWND (window),
+                              (guint) GDK_WINDOW_HWND (mask)));
 
       /* SetWindowRgn wants window (not client) coordinates */ 
       dwStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
@@ -1957,7 +2047,6 @@ gdk_propagate_shapes (HANDLE   win,
 {
    RECT emptyRect;
    HRGN region, childRegion;
-   RECT rect;
    HWND *list = NULL;
    gint i, num;