]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkwindow-win32.c
ba803baa5661c94f4d200bc4264eee280c241c2d
[~andy/gtk] / gdk / win32 / gdkwindow-win32.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  * Copyright (C) 1998-2002 Tor Lillqvist
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
23  * file for a list of people on the GTK+ Team.  See the ChangeLog
24  * files for a list of changes.  These files are distributed with
25  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
26  */
27
28 #include <stdlib.h>
29
30 #include "gdk.h" /* gdk_rectangle_intersect */
31 #include "gdkevents.h"
32 #include "gdkpixmap.h"
33 #include "gdkwindow.h"
34 #include "gdkdisplay.h"
35 #include "gdkprivate-win32.h"
36 #include "gdkinput-win32.h"
37
38 static GdkColormap* gdk_window_impl_win32_get_colormap (GdkDrawable *drawable);
39 static void         gdk_window_impl_win32_set_colormap (GdkDrawable *drawable,
40                                                         GdkColormap *cmap);
41 static void         gdk_window_impl_win32_get_size     (GdkDrawable *drawable,
42                                                         gint *width,
43                                                         gint *height);
44 static GdkRegion*   gdk_window_impl_win32_get_visible_region (GdkDrawable *drawable);
45 static void gdk_window_impl_win32_init       (GdkWindowImplWin32      *window);
46 static void gdk_window_impl_win32_class_init (GdkWindowImplWin32Class *klass);
47 static void gdk_window_impl_win32_finalize   (GObject                 *object);
48
49 static gpointer parent_class = NULL;
50
51 GType
52 _gdk_window_impl_win32_get_type (void)
53 {
54   static GType object_type = 0;
55
56   if (!object_type)
57     {
58       static const GTypeInfo object_info =
59       {
60         sizeof (GdkWindowImplWin32Class),
61         (GBaseInitFunc) NULL,
62         (GBaseFinalizeFunc) NULL,
63         (GClassInitFunc) gdk_window_impl_win32_class_init,
64         NULL,           /* class_finalize */
65         NULL,           /* class_data */
66         sizeof (GdkWindowImplWin32),
67         0,              /* n_preallocs */
68         (GInstanceInitFunc) gdk_window_impl_win32_init,
69       };
70       
71       object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_WIN32,
72                                             "GdkWindowImplWin32",
73                                             &object_info, 0);
74     }
75   
76   return object_type;
77 }
78
79 GType
80 _gdk_window_impl_get_type (void)
81 {
82   return _gdk_window_impl_win32_get_type ();
83 }
84
85 static void
86 gdk_window_impl_win32_init (GdkWindowImplWin32 *impl)
87 {
88   impl->width = 1;
89   impl->height = 1;
90
91   impl->hcursor = NULL;
92   impl->hint_flags = 0;
93   impl->extension_events_selected = FALSE;
94 }
95
96 static void
97 gdk_window_impl_win32_class_init (GdkWindowImplWin32Class *klass)
98 {
99   GObjectClass *object_class = G_OBJECT_CLASS (klass);
100   GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
101   
102   parent_class = g_type_class_peek_parent (klass);
103
104   object_class->finalize = gdk_window_impl_win32_finalize;
105
106   drawable_class->set_colormap = gdk_window_impl_win32_set_colormap;
107   drawable_class->get_colormap = gdk_window_impl_win32_get_colormap;
108   drawable_class->get_size = gdk_window_impl_win32_get_size;
109
110   /* Visible and clip regions are the same */
111   drawable_class->get_clip_region = gdk_window_impl_win32_get_visible_region;
112   drawable_class->get_visible_region = gdk_window_impl_win32_get_visible_region;
113 }
114
115 static void
116 gdk_window_impl_win32_finalize (GObject *object)
117 {
118   GdkWindowObject *wrapper;
119   GdkDrawableImplWin32 *draw_impl;
120   GdkWindowImplWin32 *window_impl;
121   
122   g_return_if_fail (GDK_IS_WINDOW_IMPL_WIN32 (object));
123
124   draw_impl = GDK_DRAWABLE_IMPL_WIN32 (object);
125   window_impl = GDK_WINDOW_IMPL_WIN32 (object);
126   
127   wrapper = (GdkWindowObject*) draw_impl->wrapper;
128
129   if (!GDK_WINDOW_DESTROYED (wrapper))
130     {
131       gdk_win32_handle_table_remove (draw_impl->handle);
132     }
133
134   if (window_impl->hcursor != NULL)
135     {
136       if (GetCursor () == window_impl->hcursor)
137         SetCursor (NULL);
138       if (!DestroyCursor (window_impl->hcursor))
139         WIN32_GDI_FAILED("DestroyCursor");
140       window_impl->hcursor = NULL;
141     }
142
143   G_OBJECT_CLASS (parent_class)->finalize (object);
144 }
145
146 static GdkColormap*
147 gdk_window_impl_win32_get_colormap (GdkDrawable *drawable)
148 {
149   GdkDrawableImplWin32 *drawable_impl;
150   
151   g_return_val_if_fail (GDK_IS_WINDOW_IMPL_WIN32 (drawable), NULL);
152
153   drawable_impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
154
155   if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only && 
156       drawable_impl->colormap == NULL)
157     {
158       drawable_impl->colormap = gdk_colormap_get_system ();
159       gdk_colormap_ref (drawable_impl->colormap);
160     }
161   
162   return drawable_impl->colormap;
163 }
164
165 static void
166 gdk_window_impl_win32_set_colormap (GdkDrawable *drawable,
167                                     GdkColormap *cmap)
168 {
169   GdkWindowImplWin32 *impl;
170   GdkDrawableImplWin32 *draw_impl;
171   
172   g_return_if_fail (GDK_IS_WINDOW_IMPL_WIN32 (drawable));
173
174   impl = GDK_WINDOW_IMPL_WIN32 (drawable);
175   draw_impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
176
177   /* chain up */
178   GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
179   
180   if (cmap)
181     {
182       /* XXX */
183       g_print("gdk_window_impl_win32_set_colormap: XXX\n");
184     }
185 }
186
187 static void
188 gdk_window_impl_win32_get_size (GdkDrawable *drawable,
189                                 gint        *width,
190                                 gint        *height)
191 {
192   g_return_if_fail (GDK_IS_WINDOW_IMPL_WIN32 (drawable));
193
194   if (width)
195     *width = GDK_WINDOW_IMPL_WIN32 (drawable)->width;
196   if (height)
197     *height = GDK_WINDOW_IMPL_WIN32 (drawable)->height;
198 }
199
200 static GdkRegion*
201 gdk_window_impl_win32_get_visible_region (GdkDrawable *drawable)
202 {
203   GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (drawable);
204   GdkRectangle result_rect;
205
206   result_rect.x = 0;
207   result_rect.y = 0;
208   result_rect.width = impl->width;
209   result_rect.height = impl->height;
210
211   gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
212
213   return gdk_region_rectangle (&result_rect);
214 }
215
216 void
217 _gdk_windowing_window_init (void)
218 {
219   GdkWindowObject *private;
220   GdkWindowImplWin32 *impl;
221   GdkDrawableImplWin32 *draw_impl;
222   RECT rect;
223   guint width;
224   guint height;
225
226   g_assert (_gdk_parent_root == NULL);
227   
228   SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
229   width  = rect.right - rect.left;
230   height = rect.bottom - rect.top;
231
232   _gdk_parent_root = g_object_new (GDK_TYPE_WINDOW, NULL);
233   private = (GdkWindowObject *)_gdk_parent_root;
234   impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
235   draw_impl = GDK_DRAWABLE_IMPL_WIN32 (private->impl);
236   
237   draw_impl->handle = _gdk_root_window;
238   draw_impl->wrapper = GDK_DRAWABLE (private);
239   draw_impl->colormap = gdk_colormap_get_system ();
240   gdk_colormap_ref (draw_impl->colormap);
241   
242   private->window_type = GDK_WINDOW_ROOT;
243   private->depth = gdk_visual_get_system ()->depth;
244   impl->width = width;
245   impl->height = height;
246
247   _gdk_window_init_position (GDK_WINDOW (private));
248
249   gdk_win32_handle_table_insert (&_gdk_root_window, _gdk_parent_root);
250 }
251
252 static const gchar *
253 get_default_title (void)
254 {
255   const char *title;
256   title = g_get_application_name ();
257   if (!title)
258     title = g_get_prgname ();
259
260   return title;
261 }
262
263 /* The Win API function AdjustWindowRect may return negative values
264  * resulting in obscured title bars. This helper function is coreccting it.
265  */
266 static BOOL
267 SafeAdjustWindowRectEx (RECT* lpRect,
268                         DWORD dwStyle, 
269                         BOOL  bMenu, 
270                         DWORD dwExStyle)
271 {
272   if (!AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle))
273     {
274       WIN32_API_FAILED ("AdjustWindowRectEx");
275       return FALSE;
276     }
277   if (lpRect->left < 0)
278     {
279       lpRect->right -= lpRect->left;
280       lpRect->left = 0;
281     }
282   if (lpRect->top < 0)
283     {
284       lpRect->bottom -= lpRect->top;
285       lpRect->top = 0;
286     }
287   return TRUE;
288 }
289
290 /* RegisterGdkClass
291  *   is a wrapper function for RegisterWindowClassEx.
292  *   It creates at least one unique class for every 
293  *   GdkWindowType. If support for single window-specific icons
294  *   is ever needed (e.g Dialog specific), every such window should
295  *   get its own class
296  */
297 static ATOM
298 RegisterGdkClass (GdkWindowType wtype)
299 {
300   static ATOM klassTOPLEVEL = 0;
301   static ATOM klassDIALOG   = 0;
302   static ATOM klassCHILD    = 0;
303   static ATOM klassTEMP     = 0;
304   static HICON hAppIcon = NULL;
305   static WNDCLASSEX wcl; 
306   ATOM klass = 0;
307
308   wcl.cbSize = sizeof (WNDCLASSEX);
309   wcl.style = 0; /* DON'T set CS_<H,V>REDRAW. It causes total redraw
310                   * on WM_SIZE and WM_MOVE. Flicker, Performance!
311                   */
312   wcl.lpfnWndProc = _gdk_win32_window_procedure;
313   wcl.cbClsExtra = 0;
314   wcl.cbWndExtra = 0;
315   wcl.hInstance = _gdk_app_hmodule;
316   wcl.hIcon = 0;
317   /* initialize once! */
318   if (0 == hAppIcon)
319     {
320       gchar sLoc [MAX_PATH+1];
321
322       if (0 != GetModuleFileName (_gdk_app_hmodule, sLoc, MAX_PATH))
323         {
324           hAppIcon = ExtractIcon (_gdk_app_hmodule, sLoc, 0);
325           if (0 == hAppIcon)
326             {
327               if (0 != GetModuleFileName (_gdk_dll_hinstance, sLoc, MAX_PATH))
328                 hAppIcon = ExtractIcon (_gdk_dll_hinstance, sLoc, 0);
329             }
330         }
331       if (0 == hAppIcon) 
332         hAppIcon = LoadIcon (NULL, IDI_APPLICATION);
333     }
334
335   wcl.lpszMenuName = NULL;
336   wcl.hIconSm = 0;
337
338   /* initialize once per class */
339   /*
340    * HB: Setting the background brush leads to flicker, because we
341    * don't get asked how to clear the background. This is not what
342    * we want, at least not for input_only windows ...
343    */
344 #define ONCE_PER_CLASS() \
345   wcl.hIcon = CopyIcon (hAppIcon); \
346   wcl.hIconSm = CopyIcon (hAppIcon); \
347   wcl.hbrBackground = NULL; \
348   wcl.hCursor = LoadCursor (NULL, IDC_ARROW); 
349   
350   switch (wtype)
351     {
352     case GDK_WINDOW_TOPLEVEL:
353       if (0 == klassTOPLEVEL)
354         {
355           wcl.lpszClassName = "gdkWindowToplevel";
356           
357           ONCE_PER_CLASS();
358           klassTOPLEVEL = RegisterClassEx (&wcl);
359         }
360       klass = klassTOPLEVEL;
361       break;
362       
363     case GDK_WINDOW_CHILD:
364       if (0 == klassCHILD)
365         {
366           wcl.lpszClassName = "gdkWindowChild";
367           
368           wcl.style |= CS_PARENTDC; /* MSDN: ... enhances system performance. */
369           ONCE_PER_CLASS();
370           klassCHILD = RegisterClassEx (&wcl);
371         }
372       klass = klassCHILD;
373       break;
374       
375     case GDK_WINDOW_DIALOG:
376       if (0 == klassDIALOG)
377         {
378           wcl.lpszClassName = "gdkWindowDialog";
379           wcl.style |= CS_SAVEBITS;
380           ONCE_PER_CLASS();
381           klassDIALOG = RegisterClassEx (&wcl);
382         }
383       klass = klassDIALOG;
384       break;
385       
386     case GDK_WINDOW_TEMP:
387       if (0 == klassTEMP)
388         {
389           wcl.lpszClassName = "gdkWindowTemp";
390           wcl.style |= CS_SAVEBITS;
391           ONCE_PER_CLASS();
392           klassTEMP = RegisterClassEx (&wcl);
393         }
394       klass = klassTEMP;
395       break;
396       
397     default:
398       g_assert_not_reached ();
399       break;
400     }
401   
402   if (klass == 0)
403     {
404       WIN32_API_FAILED ("RegisterClassEx");
405       g_error ("That is a fatal error");
406     }
407   return klass;
408 }
409
410 GdkWindow*
411 gdk_window_new (GdkWindow     *parent,
412                 GdkWindowAttr *attributes,
413                 gint           attributes_mask)
414 {
415   HANDLE hparent;
416   ATOM klass = 0;
417   DWORD dwStyle = 0, dwExStyle;
418   RECT rect;
419   GdkWindow *window;
420   GdkWindowObject *private;
421   GdkWindowImplWin32 *impl;
422   GdkDrawableImplWin32 *draw_impl;
423   GdkVisual *visual;
424   const gchar *title;
425   char *mbtitle;
426
427   g_return_val_if_fail (attributes != NULL, NULL);
428
429   if (!parent)
430     parent = _gdk_parent_root;
431
432   g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
433   
434   GDK_NOTE (MISC,
435             g_print ("gdk_window_new: %s\n",
436                      (attributes->window_type == GDK_WINDOW_TOPLEVEL ? "TOPLEVEL" :
437                       (attributes->window_type == GDK_WINDOW_CHILD ? "CHILD" :
438                        (attributes->window_type == GDK_WINDOW_DIALOG ? "DIALOG" :
439                         (attributes->window_type == GDK_WINDOW_TEMP ? "TEMP" :
440                          "???"))))));
441
442   if (GDK_WINDOW_DESTROYED (parent))
443     return NULL;
444   
445   hparent = GDK_WINDOW_HWND (parent);
446
447   window = g_object_new (GDK_TYPE_WINDOW, NULL);
448   private = (GdkWindowObject *)window;
449   impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
450   draw_impl = GDK_DRAWABLE_IMPL_WIN32 (private->impl);
451   draw_impl->wrapper = GDK_DRAWABLE (window);
452
453   /* Windows with a foreign parent are treated as if they are children
454    * of the root window, except for actual creation.
455    */
456   if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
457     parent = _gdk_parent_root;
458   
459   private->parent = (GdkWindowObject *)parent;
460
461   if (attributes_mask & GDK_WA_X)
462     private->x = attributes->x;
463   else
464     private->x = 0;
465   
466   if (attributes_mask & GDK_WA_Y)
467     private->y = attributes->y;
468   else if (attributes_mask & GDK_WA_X)
469     private->y = 100;           /* ??? We must put it somewhere... */
470   else
471     private->y = 0;
472   
473   if (attributes_mask & GDK_WA_VISUAL)
474     visual = attributes->visual;
475   else
476     visual = gdk_visual_get_system ();
477
478   impl->width = (attributes->width > 1) ? (attributes->width) : (1);
479   impl->height = (attributes->height > 1) ? (attributes->height) : (1);
480   impl->extension_events_selected = FALSE;
481   private->window_type = attributes->window_type;
482
483   if (attributes->wclass == GDK_INPUT_OUTPUT)
484     {
485       dwExStyle = 0;
486
487       private->input_only = FALSE;
488       private->depth = visual->depth;
489       
490       if (attributes_mask & GDK_WA_COLORMAP)
491         {
492           draw_impl->colormap = attributes->colormap;
493           gdk_colormap_ref (attributes->colormap);
494         }
495       else
496         {
497           draw_impl->colormap = gdk_colormap_get_system ();
498         }
499     }
500   else
501     {
502       dwExStyle = WS_EX_TRANSPARENT;
503       private->depth = 0;
504       private->input_only = TRUE;
505       draw_impl->colormap = gdk_colormap_get_system ();
506       gdk_colormap_ref (draw_impl->colormap);
507       GDK_NOTE (MISC, g_print ("...GDK_INPUT_ONLY, system colormap\n"));
508     }
509
510   switch (private->window_type)
511     {
512     case GDK_WINDOW_TOPLEVEL:
513       dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN;
514       hparent = _gdk_root_window;
515       break;
516
517     case GDK_WINDOW_CHILD:
518       dwStyle = WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
519       break;
520
521     case GDK_WINDOW_DIALOG:
522       dwStyle = WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU | WS_CAPTION | WS_THICKFRAME | WS_CLIPCHILDREN;
523 #if 0
524       dwExStyle |= WS_EX_TOPMOST; /* //HB: want this? */
525 #endif
526       hparent = _gdk_root_window;
527       break;
528
529     case GDK_WINDOW_TEMP:
530       dwStyle = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
531       /* a temp window is not necessarily a top level window */
532       dwStyle |= (_gdk_parent_root == parent ? WS_POPUP : WS_CHILDWINDOW);
533       dwExStyle |= WS_EX_TOOLWINDOW;
534       break;
535
536     case GDK_WINDOW_ROOT:
537       g_error ("cannot make windows of type GDK_WINDOW_ROOT");
538       break;
539
540     default:
541       g_assert_not_reached ();
542     }
543
544   if (private->window_type != GDK_WINDOW_CHILD)
545     {
546       rect.left = private->x;
547       rect.top = private->y;
548       rect.right = rect.left + impl->width;
549       rect.bottom = rect.top + impl->height;
550
551       SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
552
553       private->x = rect.left;
554       private->y = rect.top;
555       impl->width = rect.right - rect.left;
556       impl->height = rect.bottom - rect.top;
557     }
558
559   _gdk_window_init_position (GDK_WINDOW (private));
560
561   if (impl->position_info.big)
562     private->guffaw_gravity = TRUE;
563
564   if (attributes_mask & GDK_WA_TITLE)
565     title = attributes->title;
566   else
567     title = get_default_title ();
568   if (!title || !*title)
569     title = "GDK client window";
570
571   private->event_mask = GDK_STRUCTURE_MASK | attributes->event_mask;
572       
573   if (private->parent && private->parent->guffaw_gravity)
574     {
575       /* XXX ??? */
576     }
577
578   if (private->parent)
579     private->parent->children = g_list_prepend (private->parent->children, window);
580
581   klass = RegisterGdkClass (private->window_type);
582
583   mbtitle = g_locale_from_utf8 (title, -1, NULL, NULL, NULL);
584   
585 #ifdef WITHOUT_WM_CREATE
586   draw_impl->handle =
587     CreateWindowEx (dwExStyle,
588                     MAKEINTRESOURCE(klass),
589                     mbtitle,
590                     dwStyle,
591                     ((attributes_mask & GDK_WA_X) ?
592                      impl->position_info.x : CW_USEDEFAULT),
593                     impl->position_info.y, 
594                     impl->position_info.width, impl->position_info.height,
595                     hparent,
596                     NULL,
597                     _gdk_app_hmodule,
598                     NULL);
599 #else
600   {
601   HWND hwndNew =
602     CreateWindowEx (dwExStyle,
603                     MAKEINTRESOURCE(klass),
604                     mbtitle,
605                     dwStyle,
606                     ((attributes_mask & GDK_WA_X) ?
607                      impl->position_info.x : CW_USEDEFAULT),
608                     impl->position_info.y, 
609                     impl->position_info.width, impl->position_info.height,
610                     hparent,
611                     NULL,
612                     _gdk_app_hmodule,
613                     window);
614   if (GDK_WINDOW_HWND (window) != hwndNew)
615     {
616       g_warning("gdk_window_new: gdk_event_translate::WM_CREATE (%p, %p) HWND mismatch.",
617                 GDK_WINDOW_HWND (window),
618                 hwndNew);
619
620       /* HB: IHMO due to a race condition the handle was increased by
621        * one, which causes much trouble. Because I can't find the 
622        * real bug, try to workaround it ...
623        * To reproduce: compile with MSVC 5, DEBUG=1
624        */
625 # if 0
626       gdk_win32_handle_table_remove (GDK_WINDOW_HWND (window));
627       GDK_WINDOW_HWND (window) = hwndNew;
628       gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window);
629 # else
630       /* the old behaviour, but with warning */
631       GDK_WINDOW_HWND (window) = hwndNew;
632 # endif
633
634     }
635   }
636   gdk_drawable_ref (window);
637   gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window);
638 #endif
639
640   GDK_NOTE (MISC,
641             g_print ("... \"%s\" %dx%d@+%d+%d %p = %p\n",
642                      mbtitle,
643                      impl->position_info.width, impl->position_info.height,
644                      ((attributes_mask & GDK_WA_X) ?
645                       impl->position_info.x : CW_USEDEFAULT),
646                      impl->position_info.y, 
647                      hparent,
648                      GDK_WINDOW_HWND (window)));
649
650   g_free (mbtitle);
651
652   if (draw_impl->handle == NULL)
653     {
654       WIN32_API_FAILED ("CreateWindowEx");
655       g_object_unref ((GObject *) window);
656       return NULL;
657     }
658
659 #ifdef WITHOUT_WM_CREATE
660   gdk_drawable_ref (window);
661   gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window);
662 #endif
663
664   gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
665                                   (attributes->cursor) :
666                                   NULL));
667
668   return window;
669 }
670
671 GdkWindow *
672 gdk_window_foreign_new_for_display (GdkDisplay      *display,
673                                     GdkNativeWindow  anid)
674 {
675   GdkWindow *window;
676   GdkWindowObject *private;
677   GdkWindowImplWin32 *impl;
678   GdkDrawableImplWin32 *draw_impl;
679
680   HANDLE parent;
681   RECT rect;
682   POINT point;
683
684   g_return_val_if_fail (display == gdk_display_get_default (), NULL);
685
686   window = g_object_new (GDK_TYPE_WINDOW, NULL);
687   private = (GdkWindowObject *)window;
688   impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
689   draw_impl = GDK_DRAWABLE_IMPL_WIN32 (private->impl);
690   draw_impl->wrapper = GDK_DRAWABLE (window);
691   parent = GetParent ((HWND)anid);
692   
693   private->parent = gdk_win32_handle_table_lookup ((GdkNativeWindow) parent);
694   if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
695     private->parent = (GdkWindowObject *)_gdk_parent_root;
696   
697   private->parent->children = g_list_prepend (private->parent->children, window);
698
699   draw_impl->handle = (HWND) anid;
700   GetClientRect ((HWND) anid, &rect);
701   point.x = rect.left;
702   point.y = rect.right;
703   ClientToScreen ((HWND) anid, &point);
704   if (parent != _gdk_root_window)
705     ScreenToClient (parent, &point);
706   private->x = point.x;
707   private->y = point.y;
708   impl->width = rect.right - rect.left;
709   impl->height = rect.bottom - rect.top;
710   private->window_type = GDK_WINDOW_FOREIGN;
711   private->destroyed = FALSE;
712   private->event_mask = GDK_ALL_EVENTS_MASK; /* XXX */
713   if (IsWindowVisible ((HWND) anid))
714     private->state &= (~GDK_WINDOW_STATE_WITHDRAWN);
715   else
716     private->state |= GDK_WINDOW_STATE_WITHDRAWN;
717   private->depth = gdk_visual_get_system ()->depth;
718
719   _gdk_window_init_position (GDK_WINDOW (private));
720
721   gdk_drawable_ref (window);
722   gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window);
723
724   return window;
725 }
726
727 GdkWindow*
728 gdk_window_lookup (GdkNativeWindow hwnd)
729 {
730   return (GdkWindow*) gdk_win32_handle_table_lookup (hwnd); 
731 }
732
733 void
734 _gdk_windowing_window_destroy (GdkWindow *window,
735                                gboolean   recursing,
736                                gboolean   foreign_destroy)
737 {
738   GdkWindowObject *private = (GdkWindowObject *)window;
739
740   g_return_if_fail (GDK_IS_WINDOW (window));
741   
742   GDK_NOTE (MISC, g_print ("_gdk_windowing_window_destroy %p\n",
743                            GDK_WINDOW_HWND (window)));
744
745   if (private->extension_events != 0)
746     _gdk_input_window_destroy (window);
747
748   if (private->window_type == GDK_WINDOW_FOREIGN)
749     {
750       if (!foreign_destroy && (private->parent != NULL))
751         {
752           /* It's somebody else's window, but in our hierarchy,
753            * so reparent it to the root window, and then call
754            * DestroyWindow() on it.
755            */
756           gdk_window_hide (window);
757           gdk_window_reparent (window, NULL, 0, 0);
758           
759           /* Is this too drastic? Many (most?) applications
760            * quit if any window receives WM_QUIT I think.
761            * OTOH, I don't think foreign windows are much
762            * used, so the question is maybe academic.
763            */
764           PostMessage (GDK_WINDOW_HWND (window), WM_QUIT, 0, 0);
765         }
766     }
767   else if (!recursing && !foreign_destroy)
768     {
769       private->destroyed = TRUE;
770       DestroyWindow (GDK_WINDOW_HWND (window));
771     }
772 }
773
774 /* This function is called when the window really gone.
775  */
776 void
777 gdk_window_destroy_notify (GdkWindow *window)
778 {
779   g_return_if_fail (window != NULL);
780   g_return_if_fail (GDK_IS_WINDOW (window));
781
782   GDK_NOTE (EVENTS,
783             g_print ("gdk_window_destroy_notify: %p  %s\n",
784                      GDK_WINDOW_HWND (window),
785                      (GDK_WINDOW_DESTROYED (window) ? "(destroyed)" : "")));
786
787   if (!GDK_WINDOW_DESTROYED (window))
788     {
789       if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
790         g_warning ("window %p unexpectedly destroyed",
791                    GDK_WINDOW_HWND (window));
792
793       _gdk_window_destroy (window, TRUE);
794     }
795   
796   gdk_win32_handle_table_remove (GDK_WINDOW_HWND (window));
797   gdk_drawable_unref (window);
798 }
799
800 static void
801 show_window_internal (GdkWindow *window,
802                       gboolean   raise,
803                       gboolean   deiconify)
804 {
805   GdkWindowObject *private;
806   HWND old_active_window;
807   
808   private = GDK_WINDOW_OBJECT (window);
809
810   if (private->destroyed)
811     return;
812
813   GDK_NOTE (MISC, g_print ("show_window_internal: %p %s%s%s\n",
814                            GDK_WINDOW_HWND (window),
815                            _gdk_win32_window_state_to_string (private->state),
816                            (raise ? " raise" : ""),
817                            (deiconify ? " deiconify" : "")));
818   
819   /* If asked to show (not deiconify) an withdrawn and iconified
820    * window, do that.
821    */
822   if (!deiconify &&
823       !GDK_WINDOW_IS_MAPPED (window) &&
824       (private->state & GDK_WINDOW_STATE_ICONIFIED))
825     {   
826       ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
827       return;
828     }
829   
830   /* If asked to just show an iconified window, do nothing. */
831   if (!deiconify && (private->state & GDK_WINDOW_STATE_ICONIFIED))
832     return;
833   
834   /* If asked to deiconify an already noniconified window, do
835    * nothing. (Especially, don't cause the window to rise and
836    * activate. There are different calls for that.)
837    */
838   if (deiconify && !(private->state & GDK_WINDOW_STATE_ICONIFIED))
839     return;
840   
841   /* If asked to show (but not raise) a window that is already
842    * visible, do nothing.
843    */
844   if (!deiconify && !raise && IsWindowVisible (GDK_WINDOW_HWND (window)))
845     return;
846
847   /* Other cases */
848   
849   if (!GDK_WINDOW_IS_MAPPED (window))
850     gdk_synthesize_window_state (window,
851                                  GDK_WINDOW_STATE_WITHDRAWN,
852                                  0);
853   if (GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE) & WS_EX_TRANSPARENT)
854     {
855       /* Don't really know if this makes sense, can't remember whether
856        * this case is handled like this because it is necessary, or
857        * if this is just old crap.
858        */
859       SetWindowPos(GDK_WINDOW_HWND (window), HWND_TOP, 0, 0, 0, 0,
860                    SWP_SHOWWINDOW | SWP_NOREDRAW | SWP_NOMOVE | SWP_NOSIZE);
861       return;
862     }
863
864   old_active_window = GetActiveWindow ();
865
866   if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
867     ShowWindow (GDK_WINDOW_HWND (window), SW_MAXIMIZE);
868   else if (private->state & GDK_WINDOW_STATE_ICONIFIED)
869     ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
870   else
871     ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNORMAL);
872
873   if (raise)
874     BringWindowToTop (GDK_WINDOW_HWND (window));
875   else if (old_active_window != GDK_WINDOW_HWND (window))
876     SetActiveWindow (old_active_window);
877 }
878
879 void
880 gdk_window_show_unraised (GdkWindow *window)
881 {
882   g_return_if_fail (GDK_IS_WINDOW (window));
883   
884   show_window_internal (window, FALSE, FALSE);
885 }
886
887 void
888 gdk_window_show (GdkWindow *window)
889 {
890   g_return_if_fail (GDK_IS_WINDOW (window));
891
892   show_window_internal (window, TRUE, FALSE);
893 }
894
895 void
896 gdk_window_hide (GdkWindow *window)
897 {
898   GdkWindowObject *private;
899   
900   g_return_if_fail (window != NULL);
901
902   private = (GdkWindowObject*) window;
903   if (!private->destroyed)
904     {
905       GDK_NOTE (MISC, g_print ("gdk_window_hide: %p %s\n",
906                                GDK_WINDOW_HWND (window),
907                                _gdk_win32_window_state_to_string (private->state)));
908
909       if (GDK_WINDOW_IS_MAPPED (window))
910         gdk_synthesize_window_state (window,
911                                      0,
912                                      GDK_WINDOW_STATE_WITHDRAWN);
913
914       _gdk_window_clear_update_area (window);
915
916       if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL)
917         ShowOwnedPopups (GDK_WINDOW_HWND (window), FALSE);
918
919       if (GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE) & WS_EX_TRANSPARENT)
920         {
921           SetWindowPos(GDK_WINDOW_HWND (window), HWND_BOTTOM, 0, 0, 0, 0,
922                        SWP_HIDEWINDOW | SWP_NOREDRAW | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE);
923         }
924       else
925         {
926           ShowWindow (GDK_WINDOW_HWND (window), SW_HIDE);
927         }
928     }
929 }
930
931 void
932 gdk_window_withdraw (GdkWindow *window)
933 {
934   GdkWindowObject *private;
935   
936   g_return_if_fail (window != NULL);
937   
938   private = (GdkWindowObject*) window;
939   if (!private->destroyed)
940     {
941       GDK_NOTE (MISC, g_print ("gdk_window_withdraw: %p %s\n",
942                                GDK_WINDOW_HWND (window),
943                                _gdk_win32_window_state_to_string (private->state)));
944
945       gdk_window_hide (window); /* ??? */
946     }
947 }
948
949 void
950 gdk_window_move (GdkWindow *window,
951                  gint       x,
952                  gint       y)
953 {
954   GdkWindowObject *private = (GdkWindowObject *)window;
955   GdkWindowImplWin32 *impl;
956   RECT rect;
957   LONG style, extended_style;
958
959   g_return_if_fail (window != NULL);
960   g_return_if_fail (GDK_IS_WINDOW (window));
961
962   impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
963   
964   if (!GDK_WINDOW_DESTROYED (window))
965     {
966       if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
967         _gdk_window_move_resize_child (window, x, y,
968                                        impl->width, impl->height);
969       else
970         {
971           /* SetWindowPos uses non-client coordinates, we have client
972            * coordinates. Thus offset them.
973            */
974           style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
975           extended_style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
976           GetClientRect (GDK_WINDOW_HWND (window), &rect);
977           AdjustWindowRectEx (&rect, style, FALSE, extended_style);
978
979           if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
980                              x + rect.left, y + rect.top, 0, 0,
981                              SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER))
982             WIN32_API_FAILED ("SetWindowPos");
983         }
984     }
985 }
986
987 void
988 gdk_window_resize (GdkWindow *window,
989                    gint       width,
990                    gint       height)
991 {
992   GdkWindowObject *private = (GdkWindowObject*) window;
993   GdkWindowImplWin32 *impl;
994   int x, y;
995
996   g_return_if_fail (window != NULL);
997   g_return_if_fail (GDK_IS_WINDOW (window));
998
999   if (width < 1)
1000     width = 1;
1001   if (height < 1)
1002     height = 1;
1003
1004   impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
1005   
1006   if (!GDK_WINDOW_DESTROYED (window))
1007     {
1008       if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1009         _gdk_window_move_resize_child (window, private->x, private->y,
1010                                        width, height);
1011       else
1012         {
1013           POINT pt;
1014           RECT rect;
1015           DWORD dwStyle;
1016           DWORD dwExStyle;
1017
1018           pt.x = 0;
1019           pt.y = 0; 
1020           ClientToScreen (GDK_WINDOW_HWND (window), &pt);
1021           rect.left = pt.x;
1022           rect.top = pt.y;
1023           rect.right = pt.x + width;
1024           rect.bottom = pt.y + height;
1025
1026           dwStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
1027           dwExStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
1028           if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle))
1029             WIN32_API_FAILED ("AdjustWindowRectEx");
1030
1031           x = rect.left;
1032           y = rect.top;
1033           width = rect.right - rect.left;
1034           height = rect.bottom - rect.top;
1035           if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
1036                              x, y, width, height,
1037                              SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER))
1038             WIN32_API_FAILED ("SetWindowPos");
1039         }
1040       private->resize_count += 1;
1041     }
1042 }
1043
1044 void
1045 gdk_window_move_resize (GdkWindow *window,
1046                         gint       x,
1047                         gint       y,
1048                         gint       width,
1049                         gint       height)
1050 {
1051   GdkWindowObject *private = (GdkWindowObject*) window;
1052   GdkWindowImplWin32 *impl;
1053
1054   g_return_if_fail (window != NULL);
1055   g_return_if_fail (GDK_IS_WINDOW (window));
1056
1057   if (width < 1)
1058     width = 1;
1059   if (height < 1)
1060     height = 1;
1061   
1062   impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
1063
1064   if (!private->destroyed)
1065     {
1066       RECT rect;
1067       DWORD dwStyle;
1068       DWORD dwExStyle;
1069
1070       GDK_NOTE (MISC, g_print ("gdk_window_move_resize: %p %dx%d@+%d+%d\n",
1071                                GDK_WINDOW_HWND (window),
1072                                width, height, x, y));
1073       
1074       if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1075         _gdk_window_move_resize_child (window, x, y, width, height);
1076       else
1077         {
1078           rect.left = x;
1079           rect.top = y;
1080           rect.right = x + width;
1081           rect.bottom = y + height;
1082
1083           dwStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
1084           dwExStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
1085           if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle))
1086             WIN32_API_FAILED ("AdjustWindowRectEx");
1087
1088           GDK_NOTE (MISC, g_print ("...SetWindowPos(%p,%ldx%ld@+%ld+%ld)\n",
1089                                    GDK_WINDOW_HWND (window),
1090                                    rect.right - rect.left, rect.bottom - rect.top,
1091                                    rect.left, rect.top));
1092           if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
1093                              rect.left, rect.top,
1094                              rect.right - rect.left, rect.bottom - rect.top,
1095                              SWP_NOACTIVATE | SWP_NOZORDER))
1096             WIN32_API_FAILED ("SetWindowPos");
1097         }
1098     }
1099 }
1100
1101 void
1102 gdk_window_reparent (GdkWindow *window,
1103                      GdkWindow *new_parent,
1104                      gint       x,
1105                      gint       y)
1106 {
1107   GdkWindowObject *window_private;
1108   GdkWindowObject *parent_private;
1109   GdkWindowObject *old_parent_private;
1110   GdkWindowImplWin32 *impl;
1111
1112   g_return_if_fail (window != NULL);
1113   g_return_if_fail (GDK_IS_WINDOW (window));
1114   g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1115   g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1116
1117   if (!new_parent)
1118     new_parent = _gdk_parent_root;
1119
1120   window_private = (GdkWindowObject*) window;
1121   old_parent_private = (GdkWindowObject *) window_private->parent;
1122   parent_private = (GdkWindowObject*) new_parent;
1123   impl = GDK_WINDOW_IMPL_WIN32 (window_private->impl);
1124
1125   if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1126     {
1127       GDK_NOTE (MISC, g_print ("gdk_window_reparent: %p %p\n",
1128                                GDK_WINDOW_HWND (window),
1129                                GDK_WINDOW_HWND (new_parent)));
1130       if (!SetParent (GDK_WINDOW_HWND (window),
1131                       GDK_WINDOW_HWND (new_parent)))
1132         WIN32_API_FAILED ("SetParent");
1133
1134       if (!MoveWindow (GDK_WINDOW_HWND (window),
1135                        x, y, impl->width, impl->height, TRUE))
1136         WIN32_API_FAILED ("MoveWindow");
1137     }
1138
1139   /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1140    * the root window
1141    */
1142   if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1143     new_parent = _gdk_parent_root;
1144   
1145   window_private->parent = (GdkWindowObject *)new_parent;
1146
1147   if (old_parent_private)
1148     old_parent_private->children =
1149       g_list_remove (old_parent_private->children, window);
1150
1151 #if 0
1152   if ((old_parent_private &&
1153        (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1154       (!old_parent_private && parent_private->guffaw_gravity))
1155     gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1156 #endif
1157
1158   parent_private->children = g_list_prepend (parent_private->children, window);
1159   _gdk_window_init_position (GDK_WINDOW (window_private));
1160 }
1161
1162 void
1163 _gdk_windowing_window_clear_area (GdkWindow *window,
1164                                   gint       x,
1165                                   gint       y,
1166                                   gint       width,
1167                                   gint       height)
1168 {
1169   GdkWindowImplWin32 *impl;
1170
1171   g_return_if_fail (window != NULL);
1172   g_return_if_fail (GDK_IS_WINDOW (window));
1173   
1174   impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1175
1176   if (!GDK_WINDOW_DESTROYED (window))
1177     {
1178       HDC hdc;
1179
1180       if (width == 0)
1181         width = impl->width - x;
1182       if (height == 0)
1183         height = impl->height - y;
1184       GDK_NOTE (MISC, g_print ("_gdk_windowing_window_clear_area: "
1185                                "%p %dx%d@+%d+%d\n",
1186                                GDK_WINDOW_HWND (window),
1187                                width, height, x, y));
1188       hdc = GetDC (GDK_WINDOW_HWND (window));
1189       IntersectClipRect (hdc, x, y, x + width + 1, y + height + 1);
1190       SendMessage (GDK_WINDOW_HWND (window), WM_ERASEBKGND, (WPARAM) hdc, 0);
1191       if (!ReleaseDC (GDK_WINDOW_HWND (window), hdc))
1192         WIN32_GDI_FAILED ("ReleaseDC");
1193     }
1194 }
1195
1196 void
1197 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1198                                     gint       x,
1199                                     gint       y,
1200                                     gint       width,
1201                                     gint       height)
1202 {
1203   g_return_if_fail (window != NULL);
1204   g_return_if_fail (GDK_IS_WINDOW (window));
1205   
1206   if (!GDK_WINDOW_DESTROYED (window))
1207     {
1208       RECT rect;
1209
1210       GDK_NOTE (MISC, g_print ("_gdk_windowing_window_clear_area_e: "
1211                                "%p %dx%d@+%d+%d\n",
1212                                GDK_WINDOW_HWND (window),
1213                                width, height, x, y));
1214
1215       rect.left = x;
1216       rect.right = x + width + 1;
1217       rect.top = y;
1218       rect.bottom = y + height + 1;
1219       if (!InvalidateRect (GDK_WINDOW_HWND (window), &rect, TRUE))
1220         WIN32_GDI_FAILED ("InvalidateRect");
1221       UpdateWindow (GDK_WINDOW_HWND (window));
1222     }
1223 }
1224
1225 void
1226 gdk_window_raise (GdkWindow *window)
1227 {
1228   g_return_if_fail (window != NULL);
1229   g_return_if_fail (GDK_IS_WINDOW (window));
1230   
1231   if (!GDK_WINDOW_DESTROYED (window))
1232     {
1233       GDK_NOTE (MISC, g_print ("gdk_window_raise: %p\n",
1234                                GDK_WINDOW_HWND (window)));
1235
1236       if (!BringWindowToTop (GDK_WINDOW_HWND (window)))
1237         WIN32_API_FAILED ("BringWindowToTop");
1238     }
1239 }
1240
1241 void
1242 gdk_window_lower (GdkWindow *window)
1243 {
1244   g_return_if_fail (window != NULL);
1245   g_return_if_fail (GDK_IS_WINDOW (window));
1246   
1247   if (!GDK_WINDOW_DESTROYED (window))
1248     {
1249       GDK_NOTE (MISC, g_print ("gdk_window_lower: %p\n",
1250                                GDK_WINDOW_HWND (window)));
1251
1252       if (!SetWindowPos (GDK_WINDOW_HWND (window), HWND_BOTTOM, 0, 0, 0, 0,
1253                          SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE))
1254         WIN32_API_FAILED ("SetWindowPos");
1255     }
1256 }
1257
1258 void
1259 gdk_window_set_hints (GdkWindow *window,
1260                       gint       x,
1261                       gint       y,
1262                       gint       min_width,
1263                       gint       min_height,
1264                       gint       max_width,
1265                       gint       max_height,
1266                       gint       flags)
1267 {
1268   GdkWindowImplWin32 *impl;
1269   WINDOWPLACEMENT size_hints;
1270   RECT rect;
1271   DWORD dwStyle;
1272   DWORD dwExStyle;
1273   int diff;
1274   
1275   g_return_if_fail (window != NULL);
1276   g_return_if_fail (GDK_IS_WINDOW (window));
1277   
1278   if (GDK_WINDOW_DESTROYED (window))
1279     return;
1280   
1281   impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1282
1283   GDK_NOTE (MISC, g_print ("gdk_window_set_hints: %p %dx%d..%dx%d @+%d+%d\n",
1284                            GDK_WINDOW_HWND (window),
1285                            min_width, min_height, max_width, max_height,
1286                            x, y));
1287
1288   impl->hint_flags = flags;
1289   size_hints.length = sizeof (size_hints);
1290
1291   if (flags)
1292     {
1293       GdkGeometry geom;
1294       gint        geom_mask = 0;
1295
1296       geom.min_width  = min_width;
1297       geom.min_height = min_height;
1298       geom.max_width  = max_width;
1299       geom.max_height = max_height;
1300
1301       if (flags & GDK_HINT_POS)
1302         {
1303           if (!GetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
1304             WIN32_API_FAILED ("GetWindowPlacement");
1305           else
1306             {
1307               GDK_NOTE (MISC, g_print ("...rcNormalPosition:"
1308                                        " (%ld,%ld)--(%ld,%ld)\n",
1309                                        size_hints.rcNormalPosition.left,
1310                                        size_hints.rcNormalPosition.top,
1311                                        size_hints.rcNormalPosition.right,
1312                                        size_hints.rcNormalPosition.bottom));
1313               /* What are the corresponding window coordinates for client
1314                * area coordinates x, y
1315                */
1316               rect.left = x;
1317               rect.top = y;
1318               rect.right = rect.left + 200;     /* dummy */
1319               rect.bottom = rect.top + 200;
1320               dwStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
1321               dwExStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
1322               AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
1323               size_hints.flags = 0;
1324               size_hints.showCmd = SW_SHOWNA;
1325               
1326               /* Set the normal position hint to that location, with unchanged
1327                * width and height.
1328                */
1329               diff = size_hints.rcNormalPosition.left - rect.left;
1330               size_hints.rcNormalPosition.left = rect.left;
1331               size_hints.rcNormalPosition.right -= diff;
1332               diff = size_hints.rcNormalPosition.top - rect.top;
1333               size_hints.rcNormalPosition.top = rect.top;
1334               size_hints.rcNormalPosition.bottom -= diff;
1335               GDK_NOTE (MISC, g_print ("...setting: (%ld,%ld)--(%ld,%ld)\n",
1336                                        size_hints.rcNormalPosition.left,
1337                                        size_hints.rcNormalPosition.top,
1338                                        size_hints.rcNormalPosition.right,
1339                                        size_hints.rcNormalPosition.bottom));
1340               if (!SetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
1341                 WIN32_API_FAILED ("SetWindowPlacement");
1342               impl->hint_x = rect.left;
1343               impl->hint_y = rect.top;
1344             }
1345         }
1346
1347       if (flags & GDK_HINT_MIN_SIZE)
1348         geom_mask |= GDK_HINT_MIN_SIZE;
1349
1350       if (flags & GDK_HINT_MAX_SIZE)
1351         geom_mask |= GDK_HINT_MAX_SIZE;
1352
1353       gdk_window_set_geometry_hints (window, &geom, geom_mask);
1354     }
1355 }
1356
1357 void 
1358 gdk_window_set_geometry_hints (GdkWindow      *window,
1359                                GdkGeometry    *geometry,
1360                                GdkWindowHints  geom_mask)
1361 {
1362   GdkWindowImplWin32 *impl;
1363   WINDOWPLACEMENT size_hints;
1364   RECT rect;
1365   DWORD dwStyle;
1366   DWORD dwExStyle;
1367   gint new_width = 0, new_height = 0;
1368   
1369   g_return_if_fail (window != NULL);
1370   g_return_if_fail (GDK_IS_WINDOW (window));
1371   
1372   if (GDK_WINDOW_DESTROYED (window))
1373     return;
1374
1375   impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1376   size_hints.length = sizeof (size_hints);
1377
1378   impl->hint_flags = geom_mask;
1379
1380   if (geom_mask & GDK_HINT_POS)
1381     ; /* even the X11 mplementation doesn't care */
1382
1383   if (geom_mask & GDK_HINT_MIN_SIZE)
1384     {
1385       rect.left = 0;
1386       rect.top = 0;
1387       rect.right = geometry->min_width;
1388       rect.bottom = geometry->min_height;
1389       dwStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
1390       dwExStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
1391       AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
1392       impl->hint_min_width = rect.right - rect.left;
1393       impl->hint_min_height = rect.bottom - rect.top;
1394
1395       /* Also check if he current size of the window is in bounds */
1396       GetClientRect (GDK_WINDOW_HWND (window), &rect);
1397
1398       if (rect.right < geometry->min_width
1399           && rect.bottom < geometry->min_height)
1400         {
1401           new_width = geometry->min_width; new_height = geometry->min_height;
1402         }
1403       else if (rect.right < geometry->min_width)
1404         {
1405           new_width = geometry->min_width; new_height = rect.bottom;
1406         }
1407       else if (rect.bottom < geometry->min_height)
1408         {
1409           new_width = rect.right; new_height = geometry->min_height;
1410         }
1411     }
1412   
1413   if (geom_mask & GDK_HINT_MAX_SIZE)
1414     {
1415       rect.left = 0;
1416       rect.top = 0;
1417       rect.right = geometry->max_width;
1418       rect.bottom = geometry->max_height;
1419       dwStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
1420       dwExStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
1421       /* HB: dont' know why AdjustWindowRectEx is called here, ... */
1422       SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
1423       impl->hint_max_width = rect.right - rect.left;
1424       impl->hint_max_height = rect.bottom - rect.top;
1425       /* ... but negative sizes are always wrong */
1426       if (impl->hint_max_width < 0) impl->hint_max_width = G_MAXSHORT;
1427       if (impl->hint_max_height < 0) impl->hint_max_height = G_MAXSHORT;
1428
1429       /* Again, check if the window is too large currently. */
1430       GetClientRect (GDK_WINDOW_HWND (window), &rect);
1431       if (rect.right > geometry->max_width
1432           && rect.bottom > geometry->max_height)
1433         {
1434           new_width = geometry->max_width; new_height = geometry->max_height;
1435         }
1436       else if (rect.right > geometry->max_width)
1437         {
1438           new_width = geometry->max_width; new_height = rect.bottom;
1439         }
1440       else if (rect.bottom > geometry->max_height)
1441         {
1442           new_width = rect.right; new_height = geometry->max_height;
1443         }
1444     }
1445
1446   /* finally apply new size constraints */
1447   if (new_width != 0 && new_height != 0)
1448     gdk_window_resize (window, new_width, new_height);
1449   
1450   /* I don't know what to do when called with zero base_width and height. */
1451   if (geom_mask & GDK_HINT_BASE_SIZE
1452       && geometry->base_width > 0
1453       && geometry->base_height > 0)
1454     {
1455       if (!GetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
1456         WIN32_API_FAILED ("GetWindowPlacement");
1457       else
1458         {
1459           GDK_NOTE (MISC, g_print ("gdk_window_set_geometry_hints:"
1460                                    " rcNormalPosition: (%ld,%ld)--(%ld,%ld)\n",
1461                                    size_hints.rcNormalPosition.left,
1462                                    size_hints.rcNormalPosition.top,
1463                                    size_hints.rcNormalPosition.right,
1464                                    size_hints.rcNormalPosition.bottom));
1465           size_hints.rcNormalPosition.right =
1466             size_hints.rcNormalPosition.left + geometry->base_width;
1467           size_hints.rcNormalPosition.bottom =
1468             size_hints.rcNormalPosition.top + geometry->base_height;
1469           GDK_NOTE (MISC, g_print ("...setting: rcNormal: (%ld,%ld)--(%ld,%ld)\n",
1470                                    size_hints.rcNormalPosition.left,
1471                                    size_hints.rcNormalPosition.top,
1472                                    size_hints.rcNormalPosition.right,
1473                                    size_hints.rcNormalPosition.bottom));
1474           if (!SetWindowPlacement (GDK_WINDOW_HWND (window), &size_hints))
1475             WIN32_API_FAILED ("SetWindowPlacement");
1476         }
1477     }
1478   
1479   if (geom_mask & GDK_HINT_RESIZE_INC)
1480     {
1481       /* XXX */
1482     }
1483   
1484   if (geom_mask & GDK_HINT_ASPECT)
1485     {
1486       /* XXX */
1487     }
1488 }
1489
1490 void
1491 gdk_window_set_title (GdkWindow   *window,
1492                       const gchar *title)
1493 {
1494   char *mbtitle;
1495
1496   g_return_if_fail (window != NULL);
1497   g_return_if_fail (GDK_IS_WINDOW (window));
1498   g_return_if_fail (title != NULL);
1499
1500   /* Empty window titles not allowed, so set it to just a period. */
1501   if (!title[0])
1502     title = ".";
1503   
1504   GDK_NOTE (MISC, g_print ("gdk_window_set_title: %p %s\n",
1505                            GDK_WINDOW_HWND (window), title));
1506   
1507   if (!GDK_WINDOW_DESTROYED (window))
1508     {
1509       /* As the title is in UTF-8 we must translate it
1510        * to the system codepage.
1511        */
1512       mbtitle = g_locale_from_utf8 (title, -1, NULL, NULL, NULL);
1513       if (!SetWindowText (GDK_WINDOW_HWND (window), mbtitle))
1514         WIN32_API_FAILED ("SetWindowText");
1515
1516       g_free (mbtitle);
1517     }
1518 }
1519
1520 void          
1521 gdk_window_set_role (GdkWindow   *window,
1522                      const gchar *role)
1523 {
1524   g_return_if_fail (window != NULL);
1525   g_return_if_fail (GDK_IS_WINDOW (window));
1526   
1527   GDK_NOTE (MISC, g_print ("gdk_window_set_role: %p %s\n",
1528                            GDK_WINDOW_HWND (window),
1529                            (role ? role : "NULL")));
1530   /* XXX */
1531 }
1532
1533 void          
1534 gdk_window_set_transient_for (GdkWindow *window, 
1535                               GdkWindow *parent)
1536 {
1537   HWND window_id, parent_id;
1538
1539   g_return_if_fail (window != NULL);
1540   g_return_if_fail (GDK_IS_WINDOW (window));
1541   
1542   GDK_NOTE (MISC, g_print ("gdk_window_set_transient_for: %p %p\n",
1543                            GDK_WINDOW_HWND (window),
1544                            GDK_WINDOW_HWND (parent)));
1545
1546   if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (parent))
1547     return;
1548
1549   if (((GdkWindowObject *) window)->window_type == GDK_WINDOW_CHILD)
1550     {
1551       GDK_NOTE (MISC, g_print ("...a child window!\n"));
1552       return;
1553     }
1554   
1555   window_id = GDK_WINDOW_HWND (window);
1556   parent_id = GDK_WINDOW_HWND (parent);
1557
1558   /* This changes the *owner* of the window, despite the misleading
1559    * name. (Owner and parent are unrelated concepts.) At least that's
1560    * what people who seem to know what they talk about say on
1561    * USENET. Search on Google.
1562    */
1563   SetLastError (0);
1564   if (SetWindowLong (window_id, GWL_HWNDPARENT, (long) parent_id) == 0 &&
1565       GetLastError () != 0)
1566     WIN32_API_FAILED ("SetWindowLong");
1567 }
1568
1569 void
1570 gdk_window_set_background (GdkWindow *window,
1571                            GdkColor  *color)
1572 {
1573   GdkWindowObject *private = (GdkWindowObject *)window;
1574   
1575   g_return_if_fail (window != NULL);
1576   g_return_if_fail (GDK_IS_WINDOW (window));
1577   
1578   GDK_NOTE (MISC, g_print ("gdk_window_set_background: %p %s\n",
1579                            GDK_WINDOW_HWND (window), 
1580                            _gdk_win32_color_to_string (color)));
1581
1582   private->bg_color = *color;
1583
1584   if (private->bg_pixmap &&
1585       private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1586       private->bg_pixmap != GDK_NO_BG)
1587     {
1588       gdk_drawable_unref (private->bg_pixmap);
1589       private->bg_pixmap = NULL;
1590     }
1591 }
1592
1593 void
1594 gdk_window_set_back_pixmap (GdkWindow *window,
1595                             GdkPixmap *pixmap,
1596                             gint       parent_relative)
1597 {
1598   GdkWindowObject *private = (GdkWindowObject *)window;
1599
1600   g_return_if_fail (window != NULL);
1601   g_return_if_fail (GDK_IS_WINDOW (window));
1602   g_return_if_fail (pixmap == NULL || !parent_relative);
1603   g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
1604   
1605   if (private->bg_pixmap &&
1606       private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1607       private->bg_pixmap != GDK_NO_BG)
1608     gdk_drawable_unref (private->bg_pixmap);
1609
1610   if (parent_relative)
1611     {
1612       private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
1613       GDK_NOTE (MISC, g_print (G_STRLOC ": setting background pixmap to parent_relative\n"));
1614     }
1615   else
1616     {
1617       if (pixmap)
1618         {
1619           gdk_drawable_ref (pixmap);
1620           private->bg_pixmap = pixmap;
1621         }
1622       else
1623         {
1624           private->bg_pixmap = GDK_NO_BG;
1625         }
1626     }
1627 }
1628
1629 void
1630 gdk_window_set_cursor (GdkWindow *window,
1631                        GdkCursor *cursor)
1632 {
1633   GdkWindowImplWin32 *impl;
1634   GdkCursorPrivate *cursor_private;
1635   GdkWindowObject *parent_window;
1636   HCURSOR hcursor;
1637   HCURSOR hprevcursor;
1638   
1639   g_return_if_fail (window != NULL);
1640   g_return_if_fail (GDK_IS_WINDOW (window));
1641   
1642   impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1643   cursor_private = (GdkCursorPrivate*) cursor;
1644   
1645   if (GDK_WINDOW_DESTROYED (window))
1646     return;
1647
1648   if (!cursor)
1649     hcursor = NULL;
1650   else
1651     hcursor = cursor_private->hcursor;
1652   
1653   GDK_NOTE (MISC, g_print ("gdk_window_set_cursor: %p %p\n",
1654                            GDK_WINDOW_HWND (window),
1655                            hcursor));
1656
1657   /* First get the old cursor, if any (we wait to free the old one
1658    * since it may be the current cursor set in the Win32 API right
1659    * now).
1660    */
1661   hprevcursor = impl->hcursor;
1662
1663   if (hcursor == NULL)
1664     impl->hcursor = NULL;
1665   else
1666     {
1667       /* We must copy the cursor as it is OK to destroy the GdkCursor
1668        * while still in use for some window. See for instance
1669        * gimp_change_win_cursor() which calls gdk_window_set_cursor
1670        * (win, cursor), and immediately afterwards gdk_cursor_destroy
1671        * (cursor).
1672        */
1673       if ((impl->hcursor = CopyCursor (hcursor)) == NULL)
1674         WIN32_API_FAILED ("CopyCursor");
1675       GDK_NOTE (MISC, g_print ("...CopyCursor (%p) = %p\n",
1676                                hcursor, impl->hcursor));
1677     }
1678
1679   /* If the pointer is over our window, set new cursor if given */
1680   if (gdk_window_get_pointer(window, NULL, NULL, NULL) == window)
1681     if (impl->hcursor != NULL)
1682       SetCursor (impl->hcursor);
1683
1684   /* Destroy the previous cursor: Need to make sure it's no longer in
1685    * use before we destroy it, in case we're not over our window but
1686    * the cursor is still set to our old one.
1687    */
1688   if (hprevcursor != NULL)
1689     {
1690       if (GetCursor() == hprevcursor)
1691         {
1692           /* Look for a suitable cursor to use instead */
1693           hcursor = NULL;
1694           parent_window = GDK_WINDOW_OBJECT (window)->parent;
1695           while (hcursor == NULL)
1696             {
1697               if (parent_window)
1698                 {
1699                   impl = GDK_WINDOW_IMPL_WIN32 (parent_window->impl);
1700                   hcursor = impl->hcursor;
1701                   parent_window = parent_window->parent;
1702                 }
1703               else
1704                 {
1705                   hcursor = LoadCursor (NULL, IDC_ARROW);
1706                 }
1707             }
1708           SetCursor (hcursor);
1709         }
1710
1711       GDK_NOTE (MISC, g_print ("...DestroyCursor (%p)\n",
1712                                hprevcursor));
1713       
1714       if (!DestroyCursor (hprevcursor))
1715         WIN32_API_FAILED ("DestroyCursor");
1716     }
1717 }
1718
1719 void
1720 gdk_window_get_geometry (GdkWindow *window,
1721                          gint      *x,
1722                          gint      *y,
1723                          gint      *width,
1724                          gint      *height,
1725                          gint      *depth)
1726 {
1727   g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
1728   
1729   if (!window)
1730     window = _gdk_parent_root;
1731   
1732   if (!GDK_WINDOW_DESTROYED (window))
1733     {
1734       RECT rect;
1735
1736       if (!GetClientRect (GDK_WINDOW_HWND (window), &rect))
1737         WIN32_API_FAILED ("GetClientRect");
1738
1739       if (window != _gdk_parent_root)
1740         {
1741           POINT pt;
1742           GdkWindow *parent = gdk_window_get_parent (window);
1743
1744           pt.x = rect.left;
1745           pt.y = rect.top;
1746           ClientToScreen (GDK_WINDOW_HWND (window), &pt);
1747           ScreenToClient (GDK_WINDOW_HWND (parent), &pt);
1748           rect.left = pt.x;
1749           rect.top = pt.y;
1750
1751           pt.x = rect.right;
1752           pt.y = rect.bottom;
1753           ClientToScreen (GDK_WINDOW_HWND (window), &pt);
1754           ScreenToClient (GDK_WINDOW_HWND (parent), &pt);
1755           rect.right = pt.x;
1756           rect.bottom = pt.y;
1757         }
1758
1759       if (x)
1760         *x = rect.left;
1761       if (y)
1762         *y = rect.top;
1763       if (width)
1764         *width = rect.right - rect.left;
1765       if (height)
1766         *height = rect.bottom - rect.top;
1767       if (depth)
1768         *depth = gdk_drawable_get_visual (window)->depth;
1769     }
1770 }
1771
1772 gint
1773 gdk_window_get_origin (GdkWindow *window,
1774                        gint      *x,
1775                        gint      *y)
1776 {
1777   gint return_val;
1778   gint tx = 0;
1779   gint ty = 0;
1780
1781   g_return_val_if_fail (window != NULL, 0);
1782
1783   if (!GDK_WINDOW_DESTROYED (window))
1784     {
1785       POINT pt;
1786
1787       pt.x = 0;
1788       pt.y = 0;
1789       ClientToScreen (GDK_WINDOW_HWND (window), &pt);
1790       tx = pt.x;
1791       ty = pt.y;
1792       return_val = 1;
1793     }
1794   else
1795     return_val = 0;
1796   
1797   if (x)
1798     *x = tx;
1799   if (y)
1800     *y = ty;
1801
1802   GDK_NOTE (MISC, g_print ("gdk_window_get_origin: %p: +%d+%d\n",
1803                            GDK_WINDOW_HWND (window),
1804                            tx, ty));
1805   return return_val;
1806 }
1807
1808 gboolean
1809 gdk_window_get_deskrelative_origin (GdkWindow *window,
1810                                     gint      *x,
1811                                     gint      *y)
1812 {
1813   return gdk_window_get_origin (window, x, y);
1814 }
1815
1816 void
1817 gdk_window_get_root_origin (GdkWindow *window,
1818                             gint      *x,
1819                             gint      *y)
1820 {
1821   GdkRectangle rect;
1822
1823   g_return_if_fail (GDK_IS_WINDOW (window));
1824
1825   gdk_window_get_frame_extents (window, &rect);
1826
1827   if (x)
1828     *x = rect.x;
1829
1830   if (y)
1831     *y = rect.y;
1832 }
1833
1834 void
1835 gdk_window_get_frame_extents (GdkWindow    *window,
1836                               GdkRectangle *rect)
1837 {
1838   GdkWindowObject *private;
1839   HWND hwnd;
1840   RECT r;
1841
1842   g_return_if_fail (GDK_IS_WINDOW (window));
1843   g_return_if_fail (rect != NULL);
1844
1845   private = GDK_WINDOW_OBJECT (window);
1846
1847   rect->x = 0;
1848   rect->y = 0;
1849   rect->width = 1;
1850   rect->height = 1;
1851   
1852   if (GDK_WINDOW_DESTROYED (window))
1853     return;
1854
1855   while (private->parent && ((GdkWindowObject*) private->parent)->parent)
1856     private = (GdkWindowObject*) private->parent;
1857
1858   hwnd = GDK_WINDOW_HWND (window);
1859
1860   /* find the frame window */
1861   while (HWND_DESKTOP != GetParent (hwnd))
1862     {
1863       hwnd = GetParent (hwnd);
1864       g_return_if_fail (NULL != hwnd);
1865     }
1866
1867   if (!GetWindowRect (hwnd, &r))
1868     WIN32_API_FAILED ("GetWindowRect");
1869
1870   rect->x = r.left;
1871   rect->y = r.top;
1872   rect->width = r.right - r.left;
1873   rect->height = r.bottom - r.top;
1874 }
1875
1876 GdkWindow*
1877 _gdk_windowing_window_get_pointer (GdkDisplay      *display,
1878                                    GdkWindow       *window,
1879                                    gint            *x,
1880                                    gint            *y,
1881                                    GdkModifierType *mask)
1882 {
1883   GdkWindow *return_val;
1884   POINT screen_point, point;
1885   HWND hwnd, hwndc;
1886   BYTE kbd[256];
1887
1888   g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
1889   
1890   return_val = NULL;
1891   GetCursorPos (&screen_point);
1892   point = screen_point;
1893   ScreenToClient (GDK_WINDOW_HWND (window), &point);
1894
1895   *x = point.x;
1896   *y = point.y;
1897
1898   hwnd = WindowFromPoint (point);
1899   if (hwnd != NULL)
1900     {
1901       gboolean done = FALSE;
1902       
1903       while (!done)
1904         {
1905           point = screen_point;
1906           ScreenToClient (hwnd, &point);
1907           hwndc = ChildWindowFromPoint (hwnd, point);
1908           if (hwndc == NULL)
1909             done = TRUE;
1910           else if (hwndc == hwnd)
1911             done = TRUE;
1912           else
1913             hwnd = hwndc;
1914         }
1915       
1916       return_val = gdk_window_lookup ((GdkNativeWindow) hwnd);
1917     }
1918   else
1919     return_val = NULL;
1920       
1921   GetKeyboardState (kbd);
1922   *mask = 0;
1923   if (kbd[VK_SHIFT] & 0x80)
1924     *mask |= GDK_SHIFT_MASK;
1925   if (kbd[VK_CAPITAL] & 0x80)
1926     *mask |= GDK_LOCK_MASK;
1927   if (kbd[VK_CONTROL] & 0x80)
1928     *mask |= GDK_CONTROL_MASK;
1929   if (kbd[VK_MENU] & 0x80)
1930     *mask |= GDK_MOD1_MASK;
1931   if (kbd[VK_LBUTTON] & 0x80)
1932     *mask |= GDK_BUTTON1_MASK;
1933   if (kbd[VK_MBUTTON] & 0x80)
1934     *mask |= GDK_BUTTON2_MASK;
1935   if (kbd[VK_RBUTTON] & 0x80)
1936     *mask |= GDK_BUTTON3_MASK;
1937   
1938   return return_val;
1939 }
1940
1941 void
1942 _gdk_windowing_get_pointer (GdkDisplay       *display,
1943                             GdkScreen       **screen,
1944                             gint             *x,
1945                             gint             *y,
1946                             GdkModifierType  *mask)
1947 {
1948   GdkScreen *default_screen = gdk_display_get_default_screen (display);
1949   GdkWindow *root_window = gdk_screen_get_root_window (default_screen);
1950   
1951   *screen = default_screen;
1952   _gdk_windowing_window_get_pointer (display, root_window, x, y, mask);
1953 }
1954
1955 GdkWindow*
1956 _gdk_windowing_window_at_pointer (GdkDisplay *display,
1957                                   gint       *win_x,
1958                                   gint       *win_y)
1959 {
1960   GdkWindow *window;
1961   POINT point, pointc;
1962   HWND hwnd, hwndc;
1963   RECT rect;
1964
1965   GetCursorPos (&pointc);
1966   point = pointc;
1967   hwnd = WindowFromPoint (point);
1968
1969   if (hwnd == NULL)
1970     {
1971       window = _gdk_parent_root;
1972       *win_x = pointc.x;
1973       *win_y = pointc.y;
1974       return window;
1975     }
1976       
1977   ScreenToClient (hwnd, &point);
1978
1979   do {
1980     hwndc = ChildWindowFromPoint (hwnd, point);
1981     ClientToScreen (hwnd, &point);
1982     ScreenToClient (hwndc, &point);
1983   } while (hwndc != hwnd && (hwnd = hwndc, 1));
1984
1985   window = gdk_win32_handle_table_lookup ((GdkNativeWindow) hwnd);
1986
1987   if (window && (win_x || win_y))
1988     {
1989       GetClientRect (hwnd, &rect);
1990       *win_x = point.x - rect.left;
1991       *win_y = point.y - rect.top;
1992     }
1993
1994   GDK_NOTE (MISC, g_print ("gdk_window_at_pointer: +%ld+%ld %p%s\n",
1995                            point.x, point.y,
1996                            hwnd,
1997                            (window == NULL ? " NULL" : "")));
1998
1999   return window;
2000 }
2001
2002 GdkEventMask  
2003 gdk_window_get_events (GdkWindow *window)
2004 {
2005   g_return_val_if_fail (window != NULL, 0);
2006   g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2007
2008   if (GDK_WINDOW_DESTROYED (window))
2009     return 0;
2010
2011   return GDK_WINDOW_OBJECT (window)->event_mask;
2012 }
2013
2014 void          
2015 gdk_window_set_events (GdkWindow   *window,
2016                        GdkEventMask event_mask)
2017 {
2018   g_return_if_fail (window != NULL);
2019   g_return_if_fail (GDK_IS_WINDOW (window));
2020
2021   if (GDK_WINDOW_DESTROYED (window))
2022     return;
2023
2024   /* gdk_window_new() always sets the GDK_STRUCTURE_MASK, so better
2025    * set it here, too. Not that I know or remember why it is
2026    * necessary, will have to test some day.
2027    */
2028   GDK_WINDOW_OBJECT (window)->event_mask = GDK_STRUCTURE_MASK | event_mask;
2029 }
2030
2031 void
2032 gdk_window_shape_combine_mask (GdkWindow *window,
2033                                GdkBitmap *mask,
2034                                gint x, gint y)
2035 {
2036   g_return_if_fail (window != NULL);
2037   g_return_if_fail (GDK_IS_WINDOW (window));
2038
2039   if (!mask)
2040     {
2041       GDK_NOTE (MISC, g_print ("gdk_window_shape_combine_mask: %p none\n",
2042                                GDK_WINDOW_HWND (window)));
2043       SetWindowRgn (GDK_WINDOW_HWND (window), NULL, TRUE);
2044     }
2045   else
2046     {
2047       HRGN hrgn;
2048       DWORD dwStyle;
2049       DWORD dwExStyle;
2050       RECT rect;
2051
2052       /* Convert mask bitmap to region */
2053       hrgn = _gdk_win32_bitmap_to_hrgn (mask);
2054
2055       GDK_NOTE (MISC, g_print ("gdk_window_shape_combine_mask: %p %p\n",
2056                                GDK_WINDOW_HWND (window),
2057                                GDK_WINDOW_HWND (mask)));
2058
2059       /* SetWindowRgn wants window (not client) coordinates */ 
2060       dwStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
2061       dwExStyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
2062       GetClientRect (GDK_WINDOW_HWND (window), &rect);
2063       AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
2064       OffsetRgn (hrgn, -rect.left, -rect.top);
2065
2066       OffsetRgn (hrgn, x, y);
2067
2068       /* If this is a top-level window, add the title bar to the region */
2069       if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL)
2070         {
2071           HRGN tmp = CreateRectRgn (0, 0, rect.right - rect.left, -rect.top);
2072           CombineRgn (hrgn, hrgn, tmp, RGN_OR);
2073           DeleteObject (tmp);
2074         }
2075       
2076       SetWindowRgn (GDK_WINDOW_HWND (window), hrgn, TRUE);
2077     }
2078 }
2079
2080 void
2081 gdk_window_set_override_redirect (GdkWindow *window,
2082                                   gboolean   override_redirect)
2083 {
2084   g_return_if_fail (window != NULL);
2085   g_return_if_fail (GDK_IS_WINDOW (window));
2086
2087   g_warning ("gdk_window_set_override_redirect not implemented");
2088 }
2089
2090 void          
2091 gdk_window_set_icon_list (GdkWindow *window,
2092                           GList     *pixbufs)
2093 {
2094   g_return_if_fail (GDK_IS_WINDOW (window));
2095
2096   if (GDK_WINDOW_DESTROYED (window))
2097     return;
2098
2099   /* We could convert it to a hIcon and DrawIcon () it when getting
2100    * a WM_PAINT with IsIconic, but is it worth it ? Same probably
2101    * goes for gdk_window_set_icon (). Patches accepted :-)  --hb
2102    * Or do we only need to deliver the Icon on WM_GETICON ?
2103    */
2104 }
2105
2106 void          
2107 gdk_window_set_icon (GdkWindow *window, 
2108                      GdkWindow *icon_window,
2109                      GdkPixmap *pixmap,
2110                      GdkBitmap *mask)
2111 {
2112   g_return_if_fail (window != NULL);
2113   g_return_if_fail (GDK_IS_WINDOW (window));
2114
2115   if (GDK_WINDOW_DESTROYED (window))
2116     return;
2117   
2118   /* Nothing to do, really. As we share window classes between windows
2119    * we can't have window-specific icons, sorry. Don't print any warning
2120    * either.
2121    */
2122 }
2123
2124 void
2125 gdk_window_set_icon_name (GdkWindow   *window, 
2126                           const gchar *name)
2127 {
2128   g_return_if_fail (window != NULL);
2129   g_return_if_fail (GDK_IS_WINDOW (window));
2130
2131   if (GDK_WINDOW_DESTROYED (window))
2132     return;
2133   
2134   if (!SetWindowText (GDK_WINDOW_HWND (window), name))
2135     WIN32_API_FAILED ("SetWindowText");
2136 }
2137
2138 void          
2139 gdk_window_set_group (GdkWindow *window, 
2140                       GdkWindow *leader)
2141 {
2142   g_return_if_fail (window != NULL);
2143   g_return_if_fail (GDK_IS_WINDOW (window));
2144   g_return_if_fail (leader != NULL);
2145   g_return_if_fail (GDK_IS_WINDOW (leader));
2146
2147   if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
2148     return;
2149   
2150   g_warning ("gdk_window_set_group not implemented");
2151 }
2152
2153 void
2154 gdk_window_set_decorations (GdkWindow      *window,
2155                             GdkWMDecoration decorations)
2156 {
2157   LONG style, bits;
2158   const LONG settable_bits = WS_BORDER|WS_THICKFRAME|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX;
2159
2160   g_return_if_fail (window != NULL);
2161   g_return_if_fail (GDK_IS_WINDOW (window));
2162   
2163   GDK_NOTE (MISC, g_print ("gdk_window_set_decorations: %p %s%s%s%s%s%s%s\n",
2164                            GDK_WINDOW_HWND (window),
2165                            (decorations & GDK_DECOR_ALL ? "ALL " : ""),
2166                            (decorations & GDK_DECOR_BORDER ? "BORDER " : ""),
2167                            (decorations & GDK_DECOR_RESIZEH ? "RESIZEH " : ""),
2168                            (decorations & GDK_DECOR_TITLE ? "TITLE " : ""),
2169                            (decorations & GDK_DECOR_MENU ? "MENU " : ""),
2170                            (decorations & GDK_DECOR_MINIMIZE ? "MINIMIZE " : ""),
2171                            (decorations & GDK_DECOR_MAXIMIZE ? "MAXIMIZE " : "")));
2172
2173   style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
2174
2175   bits = 0;
2176
2177   if (decorations & GDK_DECOR_BORDER)
2178     bits |= WS_BORDER;
2179   if (decorations & GDK_DECOR_RESIZEH)
2180     bits |= WS_THICKFRAME;
2181   if (decorations & GDK_DECOR_TITLE)
2182     bits |= WS_CAPTION;
2183   if (decorations & GDK_DECOR_MENU)
2184     bits |= WS_SYSMENU;
2185   if (decorations & GDK_DECOR_MINIMIZE)
2186     bits |= WS_MINIMIZEBOX;
2187   if (decorations & GDK_DECOR_MAXIMIZE)
2188     bits |= WS_MAXIMIZEBOX;
2189
2190   if (decorations & GDK_DECOR_ALL)
2191     style |= settable_bits, style &= ~bits;
2192   else
2193     style &= ~settable_bits, style |= bits;
2194   
2195   SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, style);
2196   SetWindowPos (GDK_WINDOW_HWND (window), NULL, 0, 0, 0, 0,
2197                 SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE |
2198                 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
2199 }
2200
2201 gboolean
2202 gdk_window_get_decorations(GdkWindow       *window,
2203                            GdkWMDecoration *decorations)
2204 {
2205   LONG style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
2206
2207   *decorations = 0;
2208
2209   if (style & WS_BORDER)
2210     *decorations |= GDK_DECOR_BORDER;
2211   if (style & WS_THICKFRAME)
2212     *decorations |= GDK_DECOR_RESIZEH;
2213   if (style & WS_CAPTION)
2214     *decorations |= GDK_DECOR_TITLE;
2215   if (style & WS_SYSMENU)
2216     *decorations |= GDK_DECOR_MENU;
2217   if (style & WS_MINIMIZEBOX)
2218     *decorations |= GDK_DECOR_MINIMIZE;
2219   if (style & WS_MAXIMIZEBOX)
2220     *decorations |= GDK_DECOR_MAXIMIZE;
2221
2222   return *decorations != 0;
2223 }
2224
2225 void
2226 gdk_window_set_functions (GdkWindow    *window,
2227                           GdkWMFunction functions)
2228 {
2229   LONG style, bits;
2230   const LONG settable_bits = (WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU);
2231
2232   g_return_if_fail (window != NULL);
2233   g_return_if_fail (GDK_IS_WINDOW (window));
2234   
2235   GDK_NOTE (MISC, g_print ("gdk_window_set_functions: %p %s%s%s%s%s%s\n",
2236                            GDK_WINDOW_HWND (window),
2237                            (functions & GDK_FUNC_ALL ? "ALL " : ""),
2238                            (functions & GDK_FUNC_RESIZE ? "RESIZE " : ""),
2239                            (functions & GDK_FUNC_MOVE ? "MOVE " : ""),
2240                            (functions & GDK_FUNC_MINIMIZE ? "MINIMIZE " : ""),
2241                            (functions & GDK_FUNC_MAXIMIZE ? "MAXIMIZE " : ""),
2242                            (functions & GDK_FUNC_CLOSE ? "CLOSE " : "")));
2243
2244   style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
2245
2246   bits = 0;
2247
2248   if (functions & GDK_FUNC_RESIZE)
2249     bits |= WS_THICKFRAME;
2250   if (functions & GDK_FUNC_MOVE)
2251     bits |= (WS_THICKFRAME|WS_SYSMENU);
2252   if (functions & GDK_FUNC_MINIMIZE)
2253     bits |= WS_MINIMIZEBOX;
2254   if (functions & GDK_FUNC_MAXIMIZE)
2255     bits |= WS_MAXIMIZEBOX;
2256   if (functions & GDK_FUNC_CLOSE)
2257     bits |= WS_SYSMENU;
2258   
2259   if (functions & GDK_FUNC_ALL)
2260     style |= settable_bits, style &= ~bits;
2261   else
2262     style &= ~settable_bits, style |= bits;
2263   
2264   SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, style);
2265   SetWindowPos (GDK_WINDOW_HWND (window), NULL, 0, 0, 0, 0,
2266                 SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE |
2267                 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
2268 }
2269
2270 static void
2271 QueryTree (HWND   hwnd,
2272            HWND **children,
2273            gint  *nchildren)
2274 {
2275   guint i, n;
2276   HWND child;
2277
2278   n = 0;
2279   do {
2280     if (n == 0)
2281       child = GetWindow (hwnd, GW_CHILD);
2282     else
2283       child = GetWindow (child, GW_HWNDNEXT);
2284     if (child != NULL)
2285       n++;
2286   } while (child != NULL);
2287
2288   if (n > 0)
2289     {
2290       *children = g_new (HWND, n);
2291       for (i = 0; i < n; i++)
2292         {
2293           if (i == 0)
2294             child = GetWindow (hwnd, GW_CHILD);
2295           else
2296             child = GetWindow (child, GW_HWNDNEXT);
2297           *children[i] = child;
2298         }
2299     }
2300 }
2301
2302 static void
2303 gdk_propagate_shapes (HANDLE   win,
2304                       gboolean merge)
2305 {
2306    RECT emptyRect;
2307    HRGN region, childRegion;
2308    HWND *list = NULL;
2309    gint i, num;
2310
2311    SetRectEmpty (&emptyRect);
2312    region = CreateRectRgnIndirect (&emptyRect);
2313    if (merge)
2314      GetWindowRgn (win, region);
2315    
2316    QueryTree (win, &list, &num);
2317    if (list != NULL)
2318      {
2319        WINDOWPLACEMENT placement;
2320
2321        placement.length = sizeof (WINDOWPLACEMENT);
2322        /* go through all child windows and combine regions */
2323        for (i = 0; i < num; i++)
2324          {
2325            GetWindowPlacement (list[i], &placement);
2326            if (placement.showCmd == SW_SHOWNORMAL)
2327              {
2328                childRegion = CreateRectRgnIndirect (&emptyRect);
2329                GetWindowRgn (list[i], childRegion);
2330                CombineRgn (region, region, childRegion, RGN_OR);
2331                DeleteObject (childRegion);
2332              }
2333           }
2334        SetWindowRgn (win, region, TRUE);
2335        g_free (list);
2336      }
2337    else
2338      DeleteObject (region);
2339 }
2340
2341 void
2342 gdk_window_set_child_shapes (GdkWindow *window)
2343 {
2344   g_return_if_fail (window != NULL);
2345   g_return_if_fail (GDK_IS_WINDOW (window));
2346    
2347   if (GDK_WINDOW_DESTROYED (window))
2348     return;
2349
2350   gdk_propagate_shapes (GDK_WINDOW_HWND (window), FALSE);
2351 }
2352
2353 void
2354 gdk_window_merge_child_shapes (GdkWindow *window)
2355 {
2356   g_return_if_fail (window != NULL);
2357   g_return_if_fail (GDK_IS_WINDOW (window));
2358   
2359   if (GDK_WINDOW_DESTROYED (window))
2360     return;
2361
2362   gdk_propagate_shapes (GDK_WINDOW_HWND (window), TRUE);
2363 }
2364
2365 gboolean 
2366 gdk_window_set_static_gravities (GdkWindow *window,
2367                                  gboolean   use_static)
2368 {
2369   GdkWindowObject *private = (GdkWindowObject *)window;
2370   
2371   g_return_val_if_fail (window != NULL, FALSE);
2372   g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2373
2374   if (!use_static == !private->guffaw_gravity)
2375     return TRUE;
2376   
2377   if (use_static)
2378     return FALSE;
2379   
2380   private->guffaw_gravity = use_static;
2381   
2382   return TRUE;
2383 }
2384
2385 /*
2386  * Setting window states
2387  */
2388 void
2389 gdk_window_iconify (GdkWindow *window)
2390 {
2391   HWND old_active_window;
2392
2393   g_return_if_fail (window != NULL);
2394   g_return_if_fail (GDK_IS_WINDOW (window));
2395
2396   if (GDK_WINDOW_DESTROYED (window))
2397     return;
2398
2399   GDK_NOTE (MISC, g_print ("gdk_window_iconify: %p %s\n",
2400                            GDK_WINDOW_HWND (window),
2401                            _gdk_win32_window_state_to_string (((GdkWindowObject *) window)->state)));
2402
2403   if (GDK_WINDOW_IS_MAPPED (window))
2404     {
2405       old_active_window = GetActiveWindow ();
2406       ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
2407       if (old_active_window != GDK_WINDOW_HWND (window))
2408         SetActiveWindow (old_active_window);
2409     }
2410   else
2411     {
2412       gdk_synthesize_window_state (window,
2413                                    0,
2414                                    GDK_WINDOW_STATE_ICONIFIED);
2415     }
2416 }
2417
2418 void
2419 gdk_window_deiconify (GdkWindow *window)
2420 {
2421   g_return_if_fail (window != NULL);
2422   g_return_if_fail (GDK_IS_WINDOW (window));
2423
2424   if (GDK_WINDOW_DESTROYED (window))
2425     return;
2426
2427   GDK_NOTE (MISC, g_print ("gdk_window_deiconify: %p %s\n",
2428                            GDK_WINDOW_HWND (window),
2429                            _gdk_win32_window_state_to_string (((GdkWindowObject *) window)->state)));
2430
2431   if (GDK_WINDOW_IS_MAPPED (window))
2432     {  
2433       show_window_internal (window, FALSE, TRUE);
2434     }
2435   else
2436     {
2437       gdk_synthesize_window_state (window,
2438                                    GDK_WINDOW_STATE_ICONIFIED,
2439                                    0);
2440     }
2441 }
2442
2443 void
2444 gdk_window_stick (GdkWindow *window)
2445 {
2446   g_return_if_fail (GDK_IS_WINDOW (window));
2447
2448   if (GDK_WINDOW_DESTROYED (window))
2449     return;
2450
2451   /* FIXME: Do something? */
2452 }
2453
2454 void
2455 gdk_window_unstick (GdkWindow *window)
2456 {
2457   g_return_if_fail (GDK_IS_WINDOW (window));
2458
2459   if (GDK_WINDOW_DESTROYED (window))
2460     return;
2461
2462   /* FIXME: Do something? */
2463 }
2464
2465 void
2466 gdk_window_maximize (GdkWindow *window)
2467 {
2468   g_return_if_fail (GDK_IS_WINDOW (window));
2469
2470   if (GDK_WINDOW_DESTROYED (window))
2471     return;
2472
2473   GDK_NOTE (MISC, g_print ("gdk_window_maximize: %p %s\n",
2474                            GDK_WINDOW_HWND (window),
2475                            _gdk_win32_window_state_to_string (((GdkWindowObject *) window)->state)));
2476
2477   if (GDK_WINDOW_IS_MAPPED (window))
2478     ShowWindow (GDK_WINDOW_HWND (window), SW_MAXIMIZE);
2479   else
2480     gdk_synthesize_window_state (window,
2481                                  0,
2482                                  GDK_WINDOW_STATE_MAXIMIZED);
2483 }
2484
2485 void
2486 gdk_window_unmaximize (GdkWindow *window)
2487 {
2488   g_return_if_fail (GDK_IS_WINDOW (window));
2489
2490   if (GDK_WINDOW_DESTROYED (window))
2491     return;
2492
2493   GDK_NOTE (MISC, g_print ("gdk_window_unmaximize: %p %s\n",
2494                            GDK_WINDOW_HWND (window),
2495                            _gdk_win32_window_state_to_string (((GdkWindowObject *) window)->state)));
2496
2497   if (GDK_WINDOW_IS_MAPPED (window))
2498     ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
2499   else
2500     gdk_synthesize_window_state (window,
2501                                  GDK_WINDOW_STATE_MAXIMIZED,
2502                                  0);
2503 }
2504
2505 void
2506 gdk_window_fullscreen (GdkWindow *window)
2507 {
2508   g_return_if_fail (GDK_IS_WINDOW (window));
2509
2510   g_warning ("gdk_window_fullscreen() not implemented.\n");
2511 }
2512
2513 void
2514 gdk_window_unfullscreen (GdkWindow *window)
2515 {
2516   g_return_if_fail (GDK_IS_WINDOW (window));
2517 }
2518
2519 void
2520 gdk_window_focus (GdkWindow *window,
2521                   guint32    timestamp)
2522 {
2523   g_return_if_fail (GDK_IS_WINDOW (window));
2524
2525   if (GDK_WINDOW_DESTROYED (window))
2526     return;
2527   
2528   GDK_NOTE (MISC, g_print ("gdk_window_focus: %p %s\n",
2529                            GDK_WINDOW_HWND (window),
2530                            _gdk_win32_window_state_to_string (((GdkWindowObject *) window)->state)));
2531
2532   ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNORMAL);
2533   SetFocus (GDK_WINDOW_HWND (window));
2534 }
2535
2536 void
2537 gdk_window_set_modal_hint (GdkWindow *window,
2538                            gboolean   modal)
2539 {
2540   GdkWindowObject *private;
2541
2542   g_return_if_fail (window != NULL);
2543   g_return_if_fail (GDK_IS_WINDOW (window));
2544   
2545   if (GDK_WINDOW_DESTROYED (window))
2546     return;
2547
2548   private = (GdkWindowObject*) window;
2549
2550   private->modal_hint = modal;
2551
2552   if (GDK_WINDOW_IS_MAPPED (window))
2553     if (!SetWindowPos (GDK_WINDOW_HWND (window), HWND_TOPMOST,
2554                        0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE))
2555       WIN32_API_FAILED ("SetWindowPos");
2556 }
2557
2558 void
2559 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2560                                   gboolean   skips_taskbar)
2561 {
2562   g_return_if_fail (GDK_IS_WINDOW (window));
2563 }
2564
2565 void
2566 gdk_window_set_skip_pager_hint (GdkWindow *window,
2567                                 gboolean   skips_pager)
2568 {
2569   g_return_if_fail (GDK_IS_WINDOW (window));
2570 }
2571
2572 void
2573 gdk_window_set_type_hint (GdkWindow        *window,
2574                           GdkWindowTypeHint hint)
2575 {
2576   g_return_if_fail (window != NULL);
2577   g_return_if_fail (GDK_IS_WINDOW (window));
2578   
2579   if (GDK_WINDOW_DESTROYED (window))
2580     return;
2581
2582   switch (hint)
2583     {
2584     case GDK_WINDOW_TYPE_HINT_DIALOG:
2585       break;
2586     case GDK_WINDOW_TYPE_HINT_MENU:
2587       gdk_window_set_decorations (window,
2588                                   GDK_DECOR_ALL |
2589                                   GDK_DECOR_RESIZEH |
2590                                   GDK_DECOR_MINIMIZE |
2591                                   GDK_DECOR_MAXIMIZE);
2592       break;
2593     case GDK_WINDOW_TYPE_HINT_TOOLBAR:
2594       break;
2595     default:
2596       g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
2597       /* Fall thru */
2598     case GDK_WINDOW_TYPE_HINT_NORMAL:
2599       break;
2600     }
2601   /*
2602    * XXX ???
2603    */
2604   GDK_NOTE (MISC, g_print ("gdk_window_set_type_hint: %p\n",
2605                            GDK_WINDOW_HWND (window)));
2606 }
2607
2608 void
2609 gdk_window_shape_combine_region (GdkWindow *window,
2610                                  GdkRegion *shape_region,
2611                                  gint       offset_x,
2612                                  gint       offset_y)
2613 {
2614   g_return_if_fail (GDK_IS_WINDOW (window));
2615
2616   if (GDK_WINDOW_DESTROYED (window))
2617     return;
2618
2619   /* XXX: even on X implemented conditional ... */  
2620 }
2621
2622 void
2623 gdk_window_begin_resize_drag (GdkWindow     *window,
2624                               GdkWindowEdge  edge,
2625                               gint           button,
2626                               gint           root_x,
2627                               gint           root_y,
2628                               guint32        timestamp)
2629 {
2630   g_return_if_fail (GDK_IS_WINDOW (window));
2631   
2632   if (GDK_WINDOW_DESTROYED (window))
2633     return;
2634
2635   /* XXX: isn't all this default on win32 ... */  
2636 }
2637
2638 void
2639 gdk_window_begin_move_drag (GdkWindow *window,
2640                             gint       button,
2641                             gint       root_x,
2642                             gint       root_y,
2643                             guint32    timestamp)
2644 {
2645   g_return_if_fail (GDK_IS_WINDOW (window));
2646   
2647   if (GDK_WINDOW_DESTROYED (window))
2648     return;
2649
2650   /* XXX: isn't all this default on win32 ... */  
2651 }
2652
2653 GdkWindow *
2654 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
2655 {
2656   g_return_val_if_fail (display == gdk_display_get_default(), NULL);
2657
2658   return gdk_window_lookup (anid);
2659 }