Debian Codegraph @

gdk/win32/gdkwindow-win32.c

raw
1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright (C) 1998-2004 Tor Lillqvist
4 * Copyright (C) 2001-2009 Hans Breuer
5 * Copyright (C) 2007-2009 Cody Russell
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23 /*
24 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
25 * file for a list of people on the GTK+ Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 */
29
30 #include "config.h"
31 #include <stdlib.h>
32
33 #include "gdk.h"
34 #include "gdkwindowimpl.h"
35 #include "gdkprivate-win32.h"
36 #include "gdkinput-win32.h"
37 #include "gdkenumtypes.h"
38
39 static GdkColormap* gdk_window_impl_win32_get_colormap (GdkDrawable *drawable);
40 static void gdk_window_impl_win32_set_colormap (GdkDrawable *drawable,
41 GdkColormap *cmap);
42
43 static void gdk_window_impl_win32_get_size (GdkDrawable *drawable,
44 gint *width,
45 gint *height);
46 static void gdk_window_impl_win32_init (GdkWindowImplWin32 *window);
47 static void gdk_window_impl_win32_class_init (GdkWindowImplWin32Class *klass);
48 static void gdk_window_impl_win32_finalize (GObject *object);
49
50 static gpointer parent_class = NULL;
51 static GSList *modal_window_stack = NULL;
52
53 typedef struct _FullscreenInfo FullscreenInfo;
54
55 struct _FullscreenInfo
56 {
57 RECT r;
58 guint hint_flags;
59 LONG style;
60 };
61
62 static void update_style_bits (GdkWindow *window);
63 static gboolean _gdk_window_get_functions (GdkWindow *window,
64 GdkWMFunction *functions);
65
66 #define WINDOW_IS_TOPLEVEL(window) \
67 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
68 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \
69 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
70
71 static void gdk_window_impl_iface_init (GdkWindowImplIface *iface);
72
73 GdkScreen *
74 GDK_WINDOW_SCREEN (GObject *win)
75 {
76 return _gdk_screen;
77 }
78
79 GType
80 _gdk_window_impl_win32_get_type (void)
81 {
82 static GType object_type = 0;
83
84 if (!object_type)
85 {
86 const GTypeInfo object_info =
87 {
88 sizeof (GdkWindowImplWin32Class),
89 (GBaseInitFunc) NULL,
90 (GBaseFinalizeFunc) NULL,
91 (GClassInitFunc) gdk_window_impl_win32_class_init,
92 NULL, /* class_finalize */
93 NULL, /* class_data */
94 sizeof (GdkWindowImplWin32),
95 0, /* n_preallocs */
96 (GInstanceInitFunc) gdk_window_impl_win32_init,
97 };
98
99 const GInterfaceInfo window_impl_info =
100 {
101 (GInterfaceInitFunc) gdk_window_impl_iface_init,
102 NULL,
103 NULL
104 };
105
106 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_WIN32,
107 "GdkWindowImplWin32",
108 &object_info, 0);
109 g_type_add_interface_static (object_type,
110 GDK_TYPE_WINDOW_IMPL,
111 &window_impl_info);
112 }
113
114 return object_type;
115 }
116
117 GType
118 _gdk_window_impl_get_type (void)
119 {
120 return _gdk_window_impl_win32_get_type ();
121 }
122
123 static void
124 gdk_window_impl_win32_get_size (GdkDrawable *drawable,
125 gint *width,
126 gint *height)
127 {
128 GdkWindowObject *wrapper;
129 GdkDrawableImplWin32 *draw_impl;
130
131 g_return_if_fail (GDK_IS_WINDOW_IMPL_WIN32 (drawable));
132
133 draw_impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
134 wrapper = (GdkWindowObject*) draw_impl->wrapper;
135
136 if (width)
137 *width = wrapper->width;
138 if (height)
139 *height = wrapper->height;
140 }
141
142 static void
143 gdk_window_impl_win32_init (GdkWindowImplWin32 *impl)
144 {
145 impl->toplevel_window_type = -1;
146 impl->hcursor = NULL;
147 impl->hicon_big = NULL;
148 impl->hicon_small = NULL;
149 impl->hint_flags = 0;
150 impl->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
151 impl->extension_events_mask = 0;
152 impl->transient_owner = NULL;
153 impl->transient_children = NULL;
154 impl->num_transients = 0;
155 impl->changing_state = FALSE;
156 }
157
158 static void
159 gdk_window_impl_win32_class_init (GdkWindowImplWin32Class *klass)
160 {
161 GObjectClass *object_class = G_OBJECT_CLASS (klass);
162 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
163
164 parent_class = g_type_class_peek_parent (klass);
165
166 object_class->finalize = gdk_window_impl_win32_finalize;
167
168 drawable_class->set_colormap = gdk_window_impl_win32_set_colormap;
169 drawable_class->get_colormap = gdk_window_impl_win32_get_colormap;
170 drawable_class->get_size = gdk_window_impl_win32_get_size;
171 }
172
173 static void
174 gdk_window_impl_win32_finalize (GObject *object)
175 {
176 GdkWindowObject *wrapper;
177 GdkDrawableImplWin32 *draw_impl;
178 GdkWindowImplWin32 *window_impl;
179
180 g_return_if_fail (GDK_IS_WINDOW_IMPL_WIN32 (object));
181
182 draw_impl = GDK_DRAWABLE_IMPL_WIN32 (object);
183 window_impl = GDK_WINDOW_IMPL_WIN32 (object);
184
185 wrapper = (GdkWindowObject*) draw_impl->wrapper;
186
187 if (!GDK_WINDOW_DESTROYED (wrapper))
188 {
189 gdk_win32_handle_table_remove (draw_impl->handle);
190 }
191
192 if (window_impl->hcursor != NULL)
193 {
194 if (GetCursor () == window_impl->hcursor)
195 SetCursor (NULL);
196
197 GDI_CALL (DestroyCursor, (window_impl->hcursor));
198 window_impl->hcursor = NULL;
199 }
200
201 if (window_impl->hicon_big != NULL)
202 {
203 GDI_CALL (DestroyIcon, (window_impl->hicon_big));
204 window_impl->hicon_big = NULL;
205 }
206
207 if (window_impl->hicon_small != NULL)
208 {
209 GDI_CALL (DestroyIcon, (window_impl->hicon_small));
210 window_impl->hicon_small = NULL;
211 }
212
213 G_OBJECT_CLASS (parent_class)->finalize (object);
214 }
215
216 void
217 _gdk_win32_adjust_client_rect (GdkWindow *window,
218 RECT *rect)
219 {
220 LONG style, exstyle;
221
222 style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
223 exstyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
224 API_CALL (AdjustWindowRectEx, (rect, style, FALSE, exstyle));
225 }
226
227 static GdkColormap*
228 gdk_window_impl_win32_get_colormap (GdkDrawable *drawable)
229 {
230 GdkDrawableImplWin32 *drawable_impl;
231
232 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_WIN32 (drawable), NULL);
233
234 drawable_impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
235
236 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
237 drawable_impl->colormap == NULL)
238 {
239 drawable_impl->colormap = gdk_screen_get_system_colormap (_gdk_screen);
240 g_object_ref (drawable_impl->colormap);
241 }
242
243 return drawable_impl->colormap;
244 }
245
246 static void
247 gdk_window_impl_win32_set_colormap (GdkDrawable *drawable,
248 GdkColormap *cmap)
249 {
250 GdkWindowImplWin32 *impl;
251 GdkDrawableImplWin32 *draw_impl;
252
253 g_return_if_fail (GDK_IS_WINDOW_IMPL_WIN32 (drawable));
254
255 impl = GDK_WINDOW_IMPL_WIN32 (drawable);
256 draw_impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
257
258 /* chain up */
259 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
260
261 if (cmap)
262 {
263 /* XXX */
264 g_print ("gdk_window_impl_win32_set_colormap: XXX\n");
265 }
266 }
267
268 void
269 _gdk_root_window_size_init (void)
270 {
271 GdkWindowObject *window_object;
272 GdkRectangle rect;
273 int i;
274
275 window_object = GDK_WINDOW_OBJECT (_gdk_root);
276 rect = _gdk_monitors[0].rect;
277 for (i = 1; i < _gdk_num_monitors; i++)
278 gdk_rectangle_union (&rect, &_gdk_monitors[i].rect, &rect);
279
280 window_object->width = rect.width;
281 window_object->height = rect.height;
282 }
283
284 void
285 _gdk_windowing_window_init (GdkScreen *screen)
286 {
287 GdkWindowObject *private;
288 GdkDrawableImplWin32 *draw_impl;
289
290 g_assert (_gdk_root == NULL);
291
292 _gdk_root = g_object_new (GDK_TYPE_WINDOW, NULL);
293 private = (GdkWindowObject *)_gdk_root;
294 private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
295 private->impl_window = private;
296
297 draw_impl = GDK_DRAWABLE_IMPL_WIN32 (private->impl);
298
299 draw_impl->handle = GetDesktopWindow ();
300 draw_impl->wrapper = GDK_DRAWABLE (private);
301 draw_impl->colormap = gdk_screen_get_default_colormap (_gdk_screen);
302 g_object_ref (draw_impl->colormap);
303
304 private->window_type = GDK_WINDOW_ROOT;
305 private->depth = gdk_visual_get_system ()->depth;
306
307 _gdk_root_window_size_init ();
308
309 private->x = 0;
310 private->y = 0;
311 private->abs_x = 0;
312 private->abs_y = 0;
313 /* width and height already initialised in _gdk_root_window_size_init() */
314 private->viewable = TRUE;
315
316 gdk_win32_handle_table_insert ((HANDLE *) &draw_impl->handle, _gdk_root);
317
318 GDK_NOTE (MISC, g_print ("_gdk_root=%p\n", GDK_WINDOW_HWND (_gdk_root)));
319 }
320
321 static const gchar *
322 get_default_title (void)
323 {
324 const char *title;
325 title = g_get_application_name ();
326 if (!title)
327 title = g_get_prgname ();
328
329 return title;
330 }
331
332 /* RegisterGdkClass
333 * is a wrapper function for RegisterWindowClassEx.
334 * It creates at least one unique class for every
335 * GdkWindowType. If support for single window-specific icons
336 * is ever needed (e.g Dialog specific), every such window should
337 * get its own class
338 */
339 static ATOM
340 RegisterGdkClass (GdkWindowType wtype, GdkWindowTypeHint wtype_hint)
341 {
342 static ATOM klassTOPLEVEL = 0;
343 static ATOM klassDIALOG = 0;
344 static ATOM klassCHILD = 0;
345 static ATOM klassTEMP = 0;
346 static ATOM klassTEMPSHADOW = 0;
347 static HICON hAppIcon = NULL;
348 static HICON hAppIconSm = NULL;
349 static WNDCLASSEXW wcl;
350 ATOM klass = 0;
351
352 wcl.cbSize = sizeof (WNDCLASSEX);
353 wcl.style = 0; /* DON'T set CS_<H,V>REDRAW. It causes total redraw
354 * on WM_SIZE and WM_MOVE. Flicker, Performance!
355 */
356 wcl.lpfnWndProc = _gdk_win32_window_procedure;
357 wcl.cbClsExtra = 0;
358 wcl.cbWndExtra = 0;
359 wcl.hInstance = _gdk_app_hmodule;
360 wcl.hIcon = 0;
361 wcl.hIconSm = 0;
362
363 /* initialize once! */
364 if (0 == hAppIcon && 0 == hAppIconSm)
365 {
366 gchar sLoc [MAX_PATH+1];
367
368 if (0 != GetModuleFileName (_gdk_app_hmodule, sLoc, MAX_PATH))
369 {
370 ExtractIconEx (sLoc, 0, &hAppIcon, &hAppIconSm, 1);
371
372 if (0 == hAppIcon && 0 == hAppIconSm)
373 {
374 if (0 != GetModuleFileName (_gdk_dll_hinstance, sLoc, MAX_PATH))
375 {
376 ExtractIconEx (sLoc, 0, &hAppIcon, &hAppIconSm, 1);
377 }
378 }
379 }
380
381 if (0 == hAppIcon && 0 == hAppIconSm)
382 {
383 hAppIcon = LoadImage (NULL, IDI_APPLICATION, IMAGE_ICON,
384 GetSystemMetrics (SM_CXICON),
385 GetSystemMetrics (SM_CYICON), 0);
386 hAppIconSm = LoadImage (NULL, IDI_APPLICATION, IMAGE_ICON,
387 GetSystemMetrics (SM_CXSMICON),
388 GetSystemMetrics (SM_CYSMICON), 0);
389 }
390 }
391
392 if (0 == hAppIcon)
393 hAppIcon = hAppIconSm;
394 else if (0 == hAppIconSm)
395 hAppIconSm = hAppIcon;
396
397 wcl.lpszMenuName = NULL;
398
399 /* initialize once per class */
400 /*
401 * HB: Setting the background brush leads to flicker, because we
402 * don't get asked how to clear the background. This is not what
403 * we want, at least not for input_only windows ...
404 */
405 #define ONCE_PER_CLASS() \
406 wcl.hIcon = CopyIcon (hAppIcon); \
407 wcl.hIconSm = CopyIcon (hAppIconSm); \
408 wcl.hbrBackground = NULL; \
409 wcl.hCursor = LoadCursor (NULL, IDC_ARROW);
410
411 switch (wtype)
412 {
413 case GDK_WINDOW_TOPLEVEL:
414 if (0 == klassTOPLEVEL)
415 {
416 wcl.lpszClassName = L"gdkWindowToplevel";
417
418 ONCE_PER_CLASS ();
419 klassTOPLEVEL = RegisterClassExW (&wcl);
420 }
421 klass = klassTOPLEVEL;
422 break;
423
424 case GDK_WINDOW_CHILD:
425 if (0 == klassCHILD)
426 {
427 wcl.lpszClassName = L"gdkWindowChild";
428
429 wcl.style |= CS_PARENTDC; /* MSDN: ... enhances system performance. */
430 ONCE_PER_CLASS ();
431 klassCHILD = RegisterClassExW (&wcl);
432 }
433 klass = klassCHILD;
434 break;
435
436 case GDK_WINDOW_DIALOG:
437 if (0 == klassDIALOG)
438 {
439 wcl.lpszClassName = L"gdkWindowDialog";
440 wcl.style |= CS_SAVEBITS;
441 ONCE_PER_CLASS ();
442 klassDIALOG = RegisterClassExW (&wcl);
443 }
444 klass = klassDIALOG;
445 break;
446
447 case GDK_WINDOW_TEMP:
448 if ((wtype_hint == GDK_WINDOW_TYPE_HINT_MENU) ||
449 (wtype_hint == GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU) ||
450 (wtype_hint == GDK_WINDOW_TYPE_HINT_POPUP_MENU) ||
451 (wtype_hint == GDK_WINDOW_TYPE_HINT_TOOLTIP))
452 {
453 if (klassTEMPSHADOW == 0)
454 {
455 wcl.lpszClassName = L"gdkWindowTempShadow";
456 wcl.style |= CS_SAVEBITS;
457 if (LOBYTE (g_win32_get_windows_version()) > 0x05 ||
458 LOWORD (g_win32_get_windows_version()) == 0x0105)
459 {
460 /* Windows XP (5.1) or above */
461 wcl.style |= 0x00020000; /* CS_DROPSHADOW */
462 }
463 ONCE_PER_CLASS ();
464 klassTEMPSHADOW = RegisterClassExW (&wcl);
465 }
466
467 klass = klassTEMPSHADOW;
468 }
469 else
470 {
471 if (klassTEMP == 0)
472 {
473 wcl.lpszClassName = L"gdkWindowTemp";
474 wcl.style |= CS_SAVEBITS;
475 ONCE_PER_CLASS ();
476 klassTEMP = RegisterClassExW (&wcl);
477 }
478
479 klass = klassTEMP;
480 }
481 break;
482
483 default:
484 g_assert_not_reached ();
485 break;
486 }
487
488 if (klass == 0)
489 {
490 WIN32_API_FAILED ("RegisterClassExW");
491 g_error ("That is a fatal error");
492 }
493 return klass;
494 }
495
496 /*
497 * Create native windows.
498 *
499 * With the default Gdk the created windows are mostly toplevel windows.
500 * A lot of child windows are only created for GDK_NATIVE_WINDOWS.
501 *
502 * Placement of the window is derived from the passed in window,
503 * except for toplevel window where OS/Window Manager placement
504 * is used.
505 *
506 * The visual parameter, is based on GDK_WA_VISUAL if set already.
507 * From attributes the only things used is: colormap, title,
508 * wmclass and type_hint. [1]. We are checking redundant information
509 * and complain if that changes, which would break this implementation
510 * again.
511 *
512 * [1] http://mail.gnome.org/archives/gtk-devel-list/2010-August/msg00214.html
513 */
514 void
515 _gdk_window_impl_new (GdkWindow *window,
516 GdkWindow *real_parent,
517 GdkScreen *screen,
518 GdkVisual *visual,
519 GdkEventMask event_mask,
520 GdkWindowAttr *attributes,
521 gint attributes_mask)
522 {
523 HWND hwndNew;
524 HANDLE hparent;
525 ATOM klass = 0;
526 DWORD dwStyle = 0, dwExStyle;
527 RECT rect;
528 GdkWindowObject *private;
529 GdkWindowImplWin32 *impl;
530 GdkDrawableImplWin32 *draw_impl;
531 const gchar *title;
532 wchar_t *wtitle;
533 gboolean override_redirect;
534 gint window_width, window_height;
535 gint offset_x = 0, offset_y = 0;
536 gint x, y, real_x = 0, real_y = 0;
537 /* check consistency of redundant information */
538 guint remaining_mask = attributes_mask;
539
540 private = (GdkWindowObject *)window;
541
542 GDK_NOTE (MISC,
543 g_print ("_gdk_window_impl_new: %s %s\n",
544 (private->window_type == GDK_WINDOW_TOPLEVEL ? "TOPLEVEL" :
545 (private->window_type == GDK_WINDOW_CHILD ? "CHILD" :
546 (private->window_type == GDK_WINDOW_DIALOG ? "DIALOG" :
547 (private->window_type == GDK_WINDOW_TEMP ? "TEMP" :
548 "???")))),
549 (attributes->wclass == GDK_INPUT_OUTPUT ? "" : "input-only"))
550 );
551
552 /* to ensure to not miss important information some additional check against
553 * attributes which may silently work on X11 */
554 if ((attributes_mask & GDK_WA_X) != 0)
555 {
556 g_assert (attributes->x == private->x);
557 remaining_mask &= ~GDK_WA_X;
558 }
559 if ((attributes_mask & GDK_WA_Y) != 0)
560 {
561 g_assert (attributes->y == private->y);
562 remaining_mask &= ~GDK_WA_Y;
563 }
564 override_redirect = FALSE;
565 if ((attributes_mask & GDK_WA_NOREDIR) != 0)
566 {
567 override_redirect = !!attributes->override_redirect;
568 remaining_mask &= ~GDK_WA_NOREDIR;
569 }
570
571 if ((remaining_mask & ~(GDK_WA_WMCLASS|GDK_WA_VISUAL|GDK_WA_CURSOR|GDK_WA_COLORMAP|GDK_WA_TITLE|GDK_WA_TYPE_HINT)) != 0)
572 g_warning ("_gdk_window_impl_new: uexpected attribute 0x%X",
573 remaining_mask & ~(GDK_WA_WMCLASS|GDK_WA_VISUAL|GDK_WA_CURSOR|GDK_WA_COLORMAP|GDK_WA_TITLE|GDK_WA_TYPE_HINT));
574
575 hparent = GDK_WINDOW_HWND (real_parent);
576
577 impl = g_object_new (_gdk_window_impl_get_type (), NULL);
578 private->impl = (GdkDrawable *)impl;
579 draw_impl = GDK_DRAWABLE_IMPL_WIN32 (impl);
580 draw_impl->wrapper = GDK_DRAWABLE (window);
581
582 if (attributes_mask & GDK_WA_VISUAL)
583 g_assert (visual == attributes->visual);
584
585 impl->extension_events_mask = 0;
586 impl->override_redirect = override_redirect;
587
588 /* wclass is not any longer set always, but if is ... */
589 if ((attributes_mask & GDK_WA_WMCLASS) == GDK_WA_WMCLASS)
590 g_assert ((attributes->wclass == GDK_INPUT_OUTPUT) == !private->input_only);
591
592 if (!private->input_only)
593 {
594 dwExStyle = 0;
595
596 private->input_only = FALSE;
597 private->depth = visual->depth;
598
599 if (attributes_mask & GDK_WA_COLORMAP)
600 {
601 draw_impl->colormap = attributes->colormap;
602 g_object_ref (attributes->colormap);
603 }
604 else
605 {
606 draw_impl->colormap = gdk_screen_get_system_colormap (_gdk_screen);
607 g_object_ref (draw_impl->colormap);
608 }
609 }
610 else
611 {
612 /* I very much doubt using WS_EX_TRANSPARENT actually
613 * corresponds to how X11 InputOnly windows work, but it appears
614 * to work well enough for the actual use cases in gtk.
615 */
616 dwExStyle = WS_EX_TRANSPARENT;
617 private->depth = 0; /* xxx: was 0 for years */
618 private->input_only = TRUE;
619 draw_impl->colormap = gdk_screen_get_system_colormap (_gdk_screen);
620 g_object_ref (draw_impl->colormap);
621 GDK_NOTE (MISC, g_print ("... GDK_INPUT_ONLY, system colormap\n"));
622 }
623
624 if (attributes_mask & GDK_WA_TITLE)
625 title = attributes->title;
626 else
627 title = get_default_title ();
628 if (!title || !*title)
629 title = "";
630
631 impl->native_event_mask = GDK_STRUCTURE_MASK | event_mask;
632
633 if (attributes_mask & GDK_WA_TYPE_HINT)
634 gdk_window_set_type_hint (window, attributes->type_hint);
635
636 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY)
637 dwExStyle |= WS_EX_TOOLWINDOW;
638
639 switch (private->window_type)
640 {
641 case GDK_WINDOW_TOPLEVEL:
642 case GDK_WINDOW_DIALOG:
643 if (GDK_WINDOW_TYPE (private->parent) != GDK_WINDOW_ROOT)
644 {
645 /* The common code warns for this case. */
646 hparent = GetDesktopWindow ();
647 }
648 /* Children of foreign windows aren't toplevel windows */
649 if (GDK_WINDOW_TYPE (real_parent) == GDK_WINDOW_FOREIGN)
650 {
651 dwStyle = WS_CHILDWINDOW | WS_CLIPCHILDREN;
652 }
653 else
654 {
655 if (private->window_type == GDK_WINDOW_TOPLEVEL)
656 dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN;
657 else
658 dwStyle = WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU | WS_CAPTION | WS_THICKFRAME | WS_CLIPCHILDREN;
659
660 offset_x = _gdk_offset_x;
661 offset_y = _gdk_offset_y;
662 }
663 break;
664
665 case GDK_WINDOW_CHILD:
666 dwStyle = WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
667 break;
668
669 case GDK_WINDOW_TEMP:
670 /* A temp window is not necessarily a top level window */
671 dwStyle = (_gdk_root == real_parent ? WS_POPUP : WS_CHILDWINDOW);
672 dwStyle |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
673 dwExStyle |= WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
674 offset_x = _gdk_offset_x;
675 offset_y = _gdk_offset_y;
676 break;
677
678 default:
679 g_assert_not_reached ();
680 }
681
682 if (private->window_type != GDK_WINDOW_CHILD)
683 {
684 rect.left = private->x;
685 rect.top = private->y;
686 rect.right = private->width + private->x;
687 rect.bottom = private->height + private->y;
688
689 AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
690
691 real_x = private->x - offset_x;
692 real_y = private->y - offset_y;
693
694 if (private->window_type == GDK_WINDOW_TOPLEVEL ||
695 private->window_type == GDK_WINDOW_DIALOG)
696 {
697 /* We initially place it at default so that we can get the
698 default window positioning if we want */
699 x = y = CW_USEDEFAULT;
700 }
701 else
702 {
703 /* TEMP, FOREIGN: Put these where requested */
704 x = real_x;
705 y = real_y;
706 }
707
708 window_width = rect.right - rect.left;
709 window_height = rect.bottom - rect.top;
710 }
711 else
712 {
713 /* adjust position relative to real_parent */
714 window_width = private->width;
715 window_height = private->height;
716 /* use given position for initial placement, native coordinates */
717 x = private->x + private->parent->abs_x - offset_x;
718 y = private->y + private->parent->abs_y - offset_y;
719 }
720
721 klass = RegisterGdkClass (private->window_type, impl->type_hint);
722
723 wtitle = g_utf8_to_utf16 (title, -1, NULL, NULL, NULL);
724
725 hwndNew = CreateWindowExW (dwExStyle,
726 MAKEINTRESOURCEW (klass),
727 wtitle,
728 dwStyle,
729 x,
730 y,
731 window_width, window_height,
732 hparent,
733 NULL,
734 _gdk_app_hmodule,
735 window);
736 if (GDK_WINDOW_HWND (window) != hwndNew)
737 {
738 g_warning ("gdk_window_new: gdk_event_translate::WM_CREATE (%p, %p) HWND mismatch.",
739 GDK_WINDOW_HWND (window),
740 hwndNew);
741
742 /* HB: IHMO due to a race condition the handle was increased by
743 * one, which causes much trouble. Because I can't find the
744 * real bug, try to workaround it ...
745 * To reproduce: compile with MSVC 5, DEBUG=1
746 */
747 # if 0
748 gdk_win32_handle_table_remove (GDK_WINDOW_HWND (window));
749 GDK_WINDOW_HWND (window) = hwndNew;
750 gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window);
751 # else
752 /* the old behaviour, but with warning */
753 draw_impl->handle = hwndNew;
754 # endif
755
756 }
757
758 if (private->window_type != GDK_WINDOW_CHILD)
759 {
760 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
761 impl->initial_x = rect.left;
762 impl->initial_y = rect.top;
763
764 /* Now we know the initial position, move to actually specified position */
765 if (real_x != x || real_y != y)
766 {
767 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL,
768 real_x, real_y, 0, 0,
769 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
770 }
771 }
772
773 g_object_ref (window);
774 gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window);
775
776 GDK_NOTE (MISC, g_print ("... \"%s\" %dx%d@%+d%+d %p = %p\n",
777 title,
778 window_width, window_height,
779 private->x - offset_x,
780 private->y - offset_y,
781 hparent,
782 GDK_WINDOW_HWND (window)));
783
784 /* Add window handle to title */
785 GDK_NOTE (MISC_OR_EVENTS, gdk_window_set_title (window, title));
786
787 g_free (wtitle);
788
789 if (draw_impl->handle == NULL)
790 {
791 WIN32_API_FAILED ("CreateWindowExW");
792 g_object_unref (window);
793 return;
794 }
795
796 // if (!from_set_skip_taskbar_hint && private->window_type == GDK_WINDOW_TEMP)
797 // gdk_window_set_skip_taskbar_hint (window, TRUE);
798
799 if (attributes_mask & GDK_WA_CURSOR)
800 gdk_window_set_cursor (window, attributes->cursor);
801 }
802
803 GdkWindow *
804 gdk_window_foreign_new_for_display (GdkDisplay *display,
805 GdkNativeWindow anid)
806 {
807 return gdk_win32_window_foreign_new_for_display (display, anid);
808 }
809
810 GdkWindow *
811 gdk_win32_window_foreign_new_for_display (GdkDisplay *display,
812 GdkNativeWindow anid)
813 {
814 GdkWindow *window;
815 GdkWindowObject *private;
816 GdkWindowImplWin32 *impl;
817 GdkDrawableImplWin32 *draw_impl;
818
819 HANDLE parent;
820 RECT rect;
821 POINT point;
822
823 g_return_val_if_fail (display == _gdk_display, NULL);
824
825 window = g_object_new (GDK_TYPE_WINDOW, NULL);
826 private = (GdkWindowObject *)window;
827 private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
828 impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
829 draw_impl = GDK_DRAWABLE_IMPL_WIN32 (private->impl);
830 draw_impl->wrapper = GDK_DRAWABLE (window);
831 parent = GetParent ((HWND)anid);
832
833 private->parent = gdk_win32_handle_table_lookup ((GdkNativeWindow) parent);
834 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
835 private->parent = (GdkWindowObject *)_gdk_root;
836
837 private->parent->children = g_list_prepend (private->parent->children, window);
838
839 draw_impl->handle = (HWND) anid;
840 GetClientRect ((HWND) anid, &rect);
841 point.x = rect.left;
842 point.y = rect.right;
843 ClientToScreen ((HWND) anid, &point);
844 if (parent != GetDesktopWindow ())
845 ScreenToClient (parent, &point);
846 private->x = point.x;
847 private->y = point.y;
848 private->width = rect.right - rect.left;
849 private->height = rect.bottom - rect.top;
850 private->window_type = GDK_WINDOW_FOREIGN;
851 private->destroyed = FALSE;
852 private->event_mask = GDK_ALL_EVENTS_MASK; /* XXX */
853 if (IsWindowVisible ((HWND) anid))
854 private->state &= (~GDK_WINDOW_STATE_WITHDRAWN);
855 else
856 private->state |= GDK_WINDOW_STATE_WITHDRAWN;
857 if (GetWindowLong ((HWND)anid, GWL_EXSTYLE) & WS_EX_TOPMOST)
858 private->state |= GDK_WINDOW_STATE_ABOVE;
859 else
860 private->state &= (~GDK_WINDOW_STATE_ABOVE);
861 private->state &= (~GDK_WINDOW_STATE_BELOW);
862 private->viewable = TRUE;
863
864 private->depth = gdk_visual_get_system ()->depth;
865
866 g_object_ref (window);
867 gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window);
868
869 GDK_NOTE (MISC, g_print ("gdk_window_foreign_new_for_display: %p: %s@%+d%+d\n",
870 (HWND) anid,
871 _gdk_win32_drawable_description (window),
872 private->x, private->y));
873
874 return window;
875 }
876
877 GdkWindow*
878 gdk_window_lookup (GdkNativeWindow hwnd)
879 {
880 return (GdkWindow*) gdk_win32_handle_table_lookup (hwnd);
881 }
882
883 void
884 _gdk_win32_window_destroy (GdkWindow *window,
885 gboolean recursing,
886 gboolean foreign_destroy)
887 {
888 GdkWindowObject *private = (GdkWindowObject *)window;
889 GdkWindowImplWin32 *window_impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
890 GSList *tmp;
891
892 g_return_if_fail (GDK_IS_WINDOW (window));
893
894 GDK_NOTE (MISC, g_print ("_gdk_win32_window_destroy: %p\n",
895 GDK_WINDOW_HWND (window)));
896
897 /* Remove ourself from the modal stack */
898 _gdk_remove_modal_window (window);
899
900 /* Remove all our transient children */
901 tmp = window_impl->transient_children;
902 while (tmp != NULL)
903 {
904 GdkWindow *child = tmp->data;
905 GdkWindowImplWin32 *child_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (child)->impl);
906
907 child_impl->transient_owner = NULL;
908 tmp = g_slist_next (tmp);
909 }
910 g_slist_free (window_impl->transient_children);
911 window_impl->transient_children = NULL;
912
913 /* Remove ourself from our transient owner */
914 if (window_impl->transient_owner != NULL)
915 {
916 gdk_window_set_transient_for (window, NULL);
917 }
918
919 if (!recursing && !foreign_destroy)
920 {
921 _gdk_win32_drawable_finish (private->impl);
922
923 private->destroyed = TRUE;
924 DestroyWindow (GDK_WINDOW_HWND (window));
925 }
926 }
927
928 void
929 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
930 {
931 /* It's somebody else's window, but in our hierarchy, so reparent it
932 * to the desktop, and then try to destroy it.
933 */
934 gdk_window_hide (window);
935 gdk_window_reparent (window, NULL, 0, 0);
936
937 PostMessage (GDK_WINDOW_HWND (window), WM_CLOSE, 0, 0);
938 }
939
940 /* This function is called when the window really gone.
941 */
942 void
943 gdk_window_destroy_notify (GdkWindow *window)
944 {
945 g_return_if_fail (GDK_IS_WINDOW (window));
946
947 GDK_NOTE (EVENTS,
948 g_print ("gdk_window_destroy_notify: %p%s\n",
949 GDK_WINDOW_HWND (window),
950 (GDK_WINDOW_DESTROYED (window) ? " (destroyed)" : "")));
951
952 if (!GDK_WINDOW_DESTROYED (window))
953 {
954 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
955 g_warning ("window %p unexpectedly destroyed",
956 GDK_WINDOW_HWND (window));
957
958 _gdk_window_destroy (window, TRUE);
959 }
960
961 gdk_win32_handle_table_remove (GDK_WINDOW_HWND (window));
962 g_object_unref (window);
963 }
964
965 static void
966 get_outer_rect (GdkWindow *window,
967 gint width,
968 gint height,
969 RECT *rect)
970 {
971 rect->left = rect->top = 0;
972 rect->right = width;
973 rect->bottom = height;
974
975 _gdk_win32_adjust_client_rect (window, rect);
976 }
977
978 static void
979 adjust_for_gravity_hints (GdkWindow *window,
980 RECT *outer_rect,
981 gint *x,
982 gint *y)
983 {
984 GdkWindowObject *obj;
985 GdkWindowImplWin32 *impl;
986
987 obj = GDK_WINDOW_OBJECT (window);
988 impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
989
990 if (impl->hint_flags & GDK_HINT_WIN_GRAVITY)
991 {
992 #ifdef G_ENABLE_DEBUG
993 gint orig_x = *x, orig_y = *y;
994 #endif
995
996 switch (impl->hints.win_gravity)
997 {
998 case GDK_GRAVITY_NORTH:
999 case GDK_GRAVITY_CENTER:
1000 case GDK_GRAVITY_SOUTH:
1001 *x -= (outer_rect->right - outer_rect->left) / 2;
1002 *x += obj->width / 2;
1003 break;
1004
1005 case GDK_GRAVITY_SOUTH_EAST:
1006 case GDK_GRAVITY_EAST:
1007 case GDK_GRAVITY_NORTH_EAST:
1008 *x -= outer_rect->right - outer_rect->left;
1009 *x += obj->width;
1010 break;
1011
1012 case GDK_GRAVITY_STATIC:
1013 *x += outer_rect->left;
1014 break;
1015
1016 default:
1017 break;
1018 }
1019
1020 switch (impl->hints.win_gravity)
1021 {
1022 case GDK_GRAVITY_WEST:
1023 case GDK_GRAVITY_CENTER:
1024 case GDK_GRAVITY_EAST:
1025 *y -= (outer_rect->bottom - outer_rect->top) / 2;
1026 *y += obj->height / 2;
1027 break;
1028
1029 case GDK_GRAVITY_SOUTH_WEST:
1030 case GDK_GRAVITY_SOUTH:
1031 case GDK_GRAVITY_SOUTH_EAST:
1032 *y -= outer_rect->bottom - outer_rect->top;
1033 *y += obj->height;
1034 break;
1035
1036 case GDK_GRAVITY_STATIC:
1037 *y += outer_rect->top;
1038 break;
1039
1040 default:
1041 break;
1042 }
1043 GDK_NOTE (MISC,
1044 (orig_x != *x || orig_y != *y) ?
1045 g_print ("adjust_for_gravity_hints: x: %d->%d, y: %d->%d\n",
1046 orig_x, *x, orig_y, *y)
1047 : (void) 0);
1048 }
1049 }
1050
1051 static void
1052 show_window_internal (GdkWindow *window,
1053 gboolean already_mapped,
1054 gboolean deiconify)
1055 {
1056 GdkWindowObject *private;
1057 GdkWindowImplWin32 *window_impl;
1058 gboolean focus_on_map = FALSE;
1059 DWORD exstyle;
1060
1061 private = (GdkWindowObject *) window;
1062
1063 if (private->destroyed)
1064 return;
1065
1066 GDK_NOTE (MISC, g_print ("show_window_internal: %p: %s%s\n",
1067 GDK_WINDOW_HWND (window),
1068 _gdk_win32_window_state_to_string (private->state),
1069 (deiconify ? " deiconify" : "")));
1070
1071 /* If asked to show (not deiconify) an withdrawn and iconified
1072 * window, do that.
1073 */
1074 if (!deiconify &&
1075 !already_mapped &&
1076 (private->state & GDK_WINDOW_STATE_ICONIFIED))
1077 {
1078 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMINNOACTIVE);
1079 return;
1080 }
1081
1082 /* If asked to just show an iconified window, do nothing. */
1083 if (!deiconify && (private->state & GDK_WINDOW_STATE_ICONIFIED))
1084 return;
1085
1086 /* If asked to deiconify an already noniconified window, do
1087 * nothing. (Especially, don't cause the window to rise and
1088 * activate. There are different calls for that.)
1089 */
1090 if (deiconify && !(private->state & GDK_WINDOW_STATE_ICONIFIED))
1091 return;
1092
1093 /* If asked to show (but not raise) a window that is already
1094 * visible, do nothing.
1095 */
1096 if (!deiconify && !already_mapped && IsWindowVisible (GDK_WINDOW_HWND (window)))
1097 return;
1098
1099 /* Other cases */
1100
1101 if (!already_mapped)
1102 focus_on_map = private->focus_on_map;
1103
1104 exstyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
1105
1106 /* Use SetWindowPos to show transparent windows so automatic redraws
1107 * in other windows can be suppressed.
1108 */
1109 if (exstyle & WS_EX_TRANSPARENT)
1110 {
1111 UINT flags = SWP_SHOWWINDOW | SWP_NOREDRAW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER;
1112
1113 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP || !focus_on_map)
1114 flags |= SWP_NOACTIVATE;
1115
1116 SetWindowPos (GDK_WINDOW_HWND (window), HWND_TOP, 0, 0, 0, 0, flags);
1117
1118 return;
1119 }
1120
1121 /* For initial map of "normal" windows we want to emulate WM window
1122 * positioning behaviour, which means:
1123 * + Use user specified position if GDK_HINT_POS or GDK_HINT_USER_POS
1124 * otherwise:
1125 * + default to the initial CW_USEDEFAULT placement,
1126 * no matter if the user moved the window before showing it.
1127 * + Certain window types and hints have more elaborate positioning
1128 * schemes.
1129 */
1130 window_impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
1131 if (!already_mapped &&
1132 (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL ||
1133 GDK_WINDOW_TYPE (window) == GDK_WINDOW_DIALOG) &&
1134 (window_impl->hint_flags & (GDK_HINT_POS | GDK_HINT_USER_POS)) == 0 &&
1135 !window_impl->override_redirect)
1136 {
1137 gboolean center = FALSE;
1138 RECT window_rect, center_on_rect;
1139 int x, y;
1140
1141 x = window_impl->initial_x;
1142 y = window_impl->initial_y;
1143
1144 if (window_impl->type_hint == GDK_WINDOW_TYPE_HINT_SPLASHSCREEN)
1145 {
1146 HMONITOR monitor;
1147 MONITORINFO mi;
1148
1149 monitor = MonitorFromWindow (GDK_WINDOW_HWND (window), MONITOR_DEFAULTTONEAREST);
1150 mi.cbSize = sizeof (mi);
1151 if (monitor && GetMonitorInfo (monitor, &mi))
1152 center_on_rect = mi.rcMonitor;
1153 else
1154 {
1155 center_on_rect.left = 0;
1156 center_on_rect.right = 0;
1157 center_on_rect.right = GetSystemMetrics (SM_CXSCREEN);
1158 center_on_rect.bottom = GetSystemMetrics (SM_CYSCREEN);
1159 }
1160 center = TRUE;
1161 }
1162 else if (window_impl->transient_owner != NULL &&
1163 GDK_WINDOW_IS_MAPPED (window_impl->transient_owner))
1164 {
1165 GdkWindowObject *owner = GDK_WINDOW_OBJECT (window_impl->transient_owner);
1166 /* Center on transient parent */
1167 center_on_rect.left = owner->x;
1168 center_on_rect.top = owner->y;
1169 center_on_rect.right = center_on_rect.left + owner->width;
1170 center_on_rect.bottom = center_on_rect.top + owner->height;
1171 _gdk_win32_adjust_client_rect (GDK_WINDOW (owner), &center_on_rect);
1172 center = TRUE;
1173 }
1174
1175 if (center)
1176 {
1177 window_rect.left = 0;
1178 window_rect.top = 0;
1179 window_rect.right = private->width;
1180 window_rect.bottom = private->height;
1181 _gdk_win32_adjust_client_rect (window, &window_rect);
1182
1183 x = center_on_rect.left + ((center_on_rect.right - center_on_rect.left) - (window_rect.right - window_rect.left)) / 2;
1184 y = center_on_rect.top + ((center_on_rect.bottom - center_on_rect.top) - (window_rect.bottom - window_rect.top)) / 2;
1185 }
1186
1187 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL,
1188 x, y, 0, 0,
1189 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
1190 }
1191
1192 if (!already_mapped &&
1193 (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL ||
1194 GDK_WINDOW_TYPE (window) == GDK_WINDOW_DIALOG) &&
1195 !window_impl->override_redirect)
1196 {
1197 /* Ensure new windows are fully onscreen */
1198 RECT window_rect;
1199 HMONITOR monitor;
1200 MONITORINFO mi;
1201 int x, y;
1202
1203 GetWindowRect (GDK_WINDOW_HWND (window), &window_rect);
1204
1205 monitor = MonitorFromWindow (GDK_WINDOW_HWND (window), MONITOR_DEFAULTTONEAREST);
1206 mi.cbSize = sizeof (mi);
1207 if (monitor && GetMonitorInfo (monitor, &mi))
1208 {
1209 x = window_rect.left;
1210 y = window_rect.top;
1211
1212 if (window_rect.right > mi.rcWork.right)
1213 {
1214 window_rect.left -= (window_rect.right - mi.rcWork.right);
1215 window_rect.right -= (window_rect.right - mi.rcWork.right);
1216 }
1217
1218 if (window_rect.bottom > mi.rcWork.bottom)
1219 {
1220 window_rect.top -= (window_rect.bottom - mi.rcWork.bottom);
1221 window_rect.bottom -= (window_rect.bottom - mi.rcWork.bottom);
1222 }
1223
1224 if (window_rect.left < mi.rcWork.left)
1225 {
1226 window_rect.right += (mi.rcWork.left - window_rect.left);
1227 window_rect.left += (mi.rcWork.left - window_rect.left);
1228 }
1229
1230 if (window_rect.top < mi.rcWork.top)
1231 {
1232 window_rect.bottom += (mi.rcWork.top - window_rect.top);
1233 window_rect.top += (mi.rcWork.top - window_rect.top);
1234 }
1235
1236 if (x != window_rect.left || y != window_rect.top)
1237 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL,
1238 window_rect.left, window_rect.top, 0, 0,
1239 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
1240 }
1241 }
1242
1243
1244 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1245 {
1246 gdk_window_fullscreen (window);
1247 }
1248 else if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
1249 {
1250 ShowWindow (GDK_WINDOW_HWND (window), SW_MAXIMIZE);
1251 }
1252 else if (private->state & GDK_WINDOW_STATE_ICONIFIED)
1253 {
1254 if (focus_on_map)
1255 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1256 else
1257 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNOACTIVATE);
1258 }
1259 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP || !focus_on_map)
1260 {
1261 if (!IsWindowVisible (GDK_WINDOW_HWND (window)))
1262 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNOACTIVATE);
1263 else
1264 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNA);
1265 }
1266 else if (!IsWindowVisible (GDK_WINDOW_HWND (window)))
1267 {
1268 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNORMAL);
1269 }
1270 else
1271 {
1272 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOW);
1273 }
1274
1275 /* Sync STATE_ABOVE to TOPMOST */
1276 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_TEMP &&
1277 (((private->state & GDK_WINDOW_STATE_ABOVE) &&
1278 !(exstyle & WS_EX_TOPMOST)) ||
1279 (!(private->state & GDK_WINDOW_STATE_ABOVE) &&
1280 (exstyle & WS_EX_TOPMOST))))
1281 {
1282 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window),
1283 (private->state & GDK_WINDOW_STATE_ABOVE)?HWND_TOPMOST:HWND_NOTOPMOST,
1284 0, 0, 0, 0,
1285 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE));
1286 }
1287 }
1288
1289 static void
1290 gdk_win32_window_show (GdkWindow *window,
1291 gboolean already_mapped)
1292 {
1293 show_window_internal (window, already_mapped, FALSE);
1294 }
1295
1296 static void
1297 gdk_win32_window_hide (GdkWindow *window)
1298 {
1299 GdkWindowObject *private;
1300
1301 private = (GdkWindowObject*) window;
1302 if (private->destroyed)
1303 return;
1304
1305 GDK_NOTE (MISC, g_print ("gdk_win32_window_hide: %p: %s\n",
1306 GDK_WINDOW_HWND (window),
1307 _gdk_win32_window_state_to_string (private->state)));
1308
1309 if (GDK_WINDOW_IS_MAPPED (window))
1310 gdk_synthesize_window_state (window,
1311 0,
1312 GDK_WINDOW_STATE_WITHDRAWN);
1313
1314 _gdk_window_clear_update_area (window);
1315
1316 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL)
1317 ShowOwnedPopups (GDK_WINDOW_HWND (window), FALSE);
1318
1319 if (GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE) & WS_EX_TRANSPARENT)
1320 {
1321 SetWindowPos (GDK_WINDOW_HWND (window), HWND_BOTTOM,
1322 0, 0, 0, 0,
1323 SWP_HIDEWINDOW | SWP_NOREDRAW | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE);
1324 }
1325 else
1326 {
1327 ShowWindow (GDK_WINDOW_HWND (window), SW_HIDE);
1328 }
1329 }
1330
1331 static void
1332 gdk_win32_window_withdraw (GdkWindow *window)
1333 {
1334 GdkWindowObject *private;
1335
1336 private = (GdkWindowObject*) window;
1337 if (private->destroyed)
1338 return;
1339
1340 GDK_NOTE (MISC, g_print ("gdk_win32_window_withdraw: %p: %s\n",
1341 GDK_WINDOW_HWND (window),
1342 _gdk_win32_window_state_to_string (private->state)));
1343
1344 gdk_window_hide (window); /* ??? */
1345 }
1346
1347 static void
1348 gdk_win32_window_move (GdkWindow *window,
1349 gint x, gint y)
1350 {
1351 GdkWindowObject *private = (GdkWindowObject *)window;
1352 GdkWindowImplWin32 *impl;
1353
1354 g_return_if_fail (GDK_IS_WINDOW (window));
1355
1356 if (GDK_WINDOW_DESTROYED (window))
1357 return;
1358
1359 GDK_NOTE (MISC, g_print ("gdk_win32_window_move: %p: %+d%+d\n",
1360 GDK_WINDOW_HWND (window), x, y));
1361
1362 impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
1363
1364 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1365 return;
1366
1367 /* Don't check GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD.
1368 * Foreign windows (another app's windows) might be children of our
1369 * windows! Especially in the case of gtkplug/socket.
1370 */
1371 if (GetAncestor (GDK_WINDOW_HWND (window), GA_PARENT) != GetDesktopWindow ())
1372 {
1373 _gdk_window_move_resize_child (window, x, y, private->width, private->height);
1374 }
1375 else
1376 {
1377 RECT outer_rect;
1378
1379 get_outer_rect (window, private->width, private->height, &outer_rect);
1380
1381 adjust_for_gravity_hints (window, &outer_rect, &x, &y);
1382
1383 GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,0,0,"
1384 "NOACTIVATE|NOSIZE|NOZORDER)\n",
1385 GDK_WINDOW_HWND (window),
1386 x - _gdk_offset_x, y - _gdk_offset_y));
1387
1388 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL,
1389 x - _gdk_offset_x, y - _gdk_offset_y, 0, 0,
1390 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
1391 }
1392 }
1393
1394 static void
1395 gdk_win32_window_resize (GdkWindow *window,
1396 gint width, gint height)
1397 {
1398 GdkWindowObject *private = (GdkWindowObject*) window;
1399 GdkWindowImplWin32 *impl;
1400
1401 g_return_if_fail (GDK_IS_WINDOW (window));
1402
1403 if (GDK_WINDOW_DESTROYED (window))
1404 return;
1405
1406 if (width < 1)
1407 width = 1;
1408 if (height < 1)
1409 height = 1;
1410
1411 GDK_NOTE (MISC, g_print ("gdk_win32_window_resize: %p: %dx%d\n",
1412 GDK_WINDOW_HWND (window), width, height));
1413
1414 impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
1415
1416 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1417 return;
1418
1419 if (GetAncestor (GDK_WINDOW_HWND (window), GA_PARENT) != GetDesktopWindow ())
1420 {
1421 _gdk_window_move_resize_child (window, private->x, private->y, width, height);
1422 }
1423 else
1424 {
1425 RECT outer_rect;
1426
1427 get_outer_rect (window, width, height, &outer_rect);
1428
1429 GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,0,0,%ld,%ld,"
1430 "NOACTIVATE|NOMOVE|NOZORDER)\n",
1431 GDK_WINDOW_HWND (window),
1432 outer_rect.right - outer_rect.left,
1433 outer_rect.bottom - outer_rect.top));
1434
1435 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL,
1436 0, 0,
1437 outer_rect.right - outer_rect.left,
1438 outer_rect.bottom - outer_rect.top,
1439 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER));
1440 private->resize_count += 1;
1441 }
1442 }
1443
1444 static void
1445 gdk_win32_window_move_resize_internal (GdkWindow *window,
1446 gint x,
1447 gint y,
1448 gint width,
1449 gint height)
1450 {
1451 GdkWindowObject *private;
1452 GdkWindowImplWin32 *impl;
1453
1454 g_return_if_fail (GDK_IS_WINDOW (window));
1455
1456 if (GDK_WINDOW_DESTROYED (window))
1457 return;
1458
1459 if (width < 1)
1460 width = 1;
1461 if (height < 1)
1462 height = 1;
1463
1464 private = GDK_WINDOW_OBJECT (window);
1465 impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
1466
1467 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1468 return;
1469
1470 GDK_NOTE (MISC, g_print ("gdk_win32_window_move_resize: %p: %dx%d@%+d%+d\n",
1471 GDK_WINDOW_HWND (window),
1472 width, height, x, y));
1473
1474 if (GetAncestor (GDK_WINDOW_HWND (window), GA_PARENT) != GetDesktopWindow ())
1475 {
1476 _gdk_window_move_resize_child (window, x, y, width, height);
1477 }
1478 else
1479 {
1480 RECT outer_rect;
1481
1482 get_outer_rect (window, width, height, &outer_rect);
1483
1484 adjust_for_gravity_hints (window, &outer_rect, &x, &y);
1485
1486 GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,%ld,%ld,"
1487 "NOACTIVATE|NOZORDER)\n",
1488 GDK_WINDOW_HWND (window),
1489 x - _gdk_offset_x, y - _gdk_offset_y,
1490 outer_rect.right - outer_rect.left,
1491 outer_rect.bottom - outer_rect.top));
1492
1493 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL,
1494 x - _gdk_offset_x, y - _gdk_offset_y,
1495 outer_rect.right - outer_rect.left,
1496 outer_rect.bottom - outer_rect.top,
1497 SWP_NOACTIVATE | SWP_NOZORDER));
1498 }
1499 }
1500
1501 static void
1502 gdk_win32_window_move_resize (GdkWindow *window,
1503 gboolean with_move,
1504 gint x,
1505 gint y,
1506 gint width,
1507 gint height)
1508 {
1509 GdkWindowObject *private = (GdkWindowObject *)window;
1510 GdkWindowImplWin32 *window_impl;
1511
1512 window_impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
1513 window_impl->inhibit_configure = TRUE;
1514
1515 /* We ignore changes to the window being moved or resized by the
1516 user, as we don't want to fight the user */
1517 if (GDK_WINDOW_HWND (window) == _modal_move_resize_window)
1518 goto out;
1519
1520 if (with_move && (width < 0 && height < 0))
1521 {
1522 gdk_win32_window_move (window, x, y);
1523 }
1524 else
1525 {
1526 if (with_move)
1527 {
1528 gdk_win32_window_move_resize_internal (window, x, y, width, height);
1529 }
1530 else
1531 {
1532 gdk_win32_window_resize (window, width, height);
1533 }
1534 }
1535
1536 out:
1537 window_impl->inhibit_configure = FALSE;
1538
1539 if (WINDOW_IS_TOPLEVEL (window))
1540 _gdk_win32_emit_configure_event (window);
1541 }
1542
1543 static gboolean
1544 gdk_win32_window_reparent (GdkWindow *window,
1545 GdkWindow *new_parent,
1546 gint x,
1547 gint y)
1548 {
1549 GdkWindowObject *window_private;
1550 GdkWindowObject *parent_private;
1551 GdkWindowObject *old_parent_private;
1552 GdkWindowImplWin32 *impl;
1553 gboolean was_toplevel;
1554 LONG style;
1555
1556 if (!new_parent)
1557 new_parent = _gdk_root;
1558
1559 window_private = (GdkWindowObject*) window;
1560 old_parent_private = (GdkWindowObject *) window_private->parent;
1561 parent_private = (GdkWindowObject*) new_parent;
1562 impl = GDK_WINDOW_IMPL_WIN32 (window_private->impl);
1563
1564 GDK_NOTE (MISC, g_print ("gdk_win32_window_reparent: %p: %p\n",
1565 GDK_WINDOW_HWND (window),
1566 GDK_WINDOW_HWND (new_parent)));
1567
1568 style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
1569
1570 was_toplevel = GetAncestor (GDK_WINDOW_HWND (window), GA_PARENT) == GetDesktopWindow ();
1571 if (was_toplevel && new_parent != _gdk_root)
1572 {
1573 /* Reparenting from top-level (child of desktop). Clear out
1574 * decorations.
1575 */
1576 style &= ~(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
1577 style |= WS_CHILD;
1578 SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, style);
1579 }
1580 else if (new_parent == _gdk_root)
1581 {
1582 /* Reparenting to top-level. Add decorations. */
1583 style &= ~(WS_CHILD);
1584 style |= WS_OVERLAPPEDWINDOW;
1585 SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, style);
1586 }
1587
1588 API_CALL (SetParent, (GDK_WINDOW_HWND (window),
1589 GDK_WINDOW_HWND (new_parent)));
1590
1591 API_CALL (MoveWindow, (GDK_WINDOW_HWND (window),
1592 x, y, window_private->width, window_private->height, TRUE));
1593
1594 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1595 * the root window
1596 */
1597 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1598 new_parent = _gdk_root;
1599
1600 window_private->parent = (GdkWindowObject *)new_parent;
1601
1602 /* Switch the window type as appropriate */
1603
1604 switch (GDK_WINDOW_TYPE (new_parent))
1605 {
1606 case GDK_WINDOW_ROOT:
1607 if (impl->toplevel_window_type != -1)
1608 GDK_WINDOW_TYPE (window) = impl->toplevel_window_type;
1609 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1610 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1611 break;
1612
1613 case GDK_WINDOW_TOPLEVEL:
1614 case GDK_WINDOW_CHILD:
1615 case GDK_WINDOW_DIALOG:
1616 case GDK_WINDOW_TEMP:
1617 if (WINDOW_IS_TOPLEVEL (window))
1618 {
1619 /* Save the original window type so we can restore it if the
1620 * window is reparented back to be a toplevel.
1621 */
1622 impl->toplevel_window_type = GDK_WINDOW_TYPE (window);
1623 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1624 }
1625 }
1626
1627 if (old_parent_private)
1628 old_parent_private->children =
1629 g_list_remove (old_parent_private->children, window);
1630
1631 parent_private->children = g_list_prepend (parent_private->children, window);
1632
1633 return FALSE;
1634 }
1635
1636 static void
1637 erase_background (GdkWindow *window,
1638 HDC hdc)
1639 {
1640 HDC bgdc = NULL;
1641 HBRUSH hbr = NULL;
1642 HPALETTE holdpal = NULL;
1643 RECT rect;
1644 COLORREF bg;
1645 GdkColormap *colormap;
1646 GdkColormapPrivateWin32 *colormap_private;
1647 int x, y;
1648 int x_offset, y_offset;
1649
1650 if (((GdkWindowObject *) window)->input_only ||
1651 ((GdkWindowObject *) window)->bg_pixmap == GDK_NO_BG)
1652 {
1653 return;
1654 }
1655
1656 colormap = gdk_drawable_get_colormap (window);
1657
1658 if (colormap &&
1659 (colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR ||
1660 colormap->visual->type == GDK_VISUAL_STATIC_COLOR))
1661 {
1662 int k;
1663
1664 colormap_private = GDK_WIN32_COLORMAP_DATA (colormap);
1665
1666 if (!(holdpal = SelectPalette (hdc, colormap_private->hpal, FALSE)))
1667 WIN32_GDI_FAILED ("SelectPalette");
1668 else if ((k = RealizePalette (hdc)) == GDI_ERROR)
1669 WIN32_GDI_FAILED ("RealizePalette");
1670 else if (k > 0)
1671 GDK_NOTE (COLORMAP, g_print ("erase_background: realized %p: %d colors\n",
1672 colormap_private->hpal, k));
1673 }
1674
1675 x_offset = y_offset = 0;
1676 while (window && ((GdkWindowObject *) window)->bg_pixmap == GDK_PARENT_RELATIVE_BG)
1677 {
1678 /* If this window should have the same background as the parent,
1679 * fetch the parent. (And if the same goes for the parent, fetch
1680 * the grandparent, etc.)
1681 */
1682 x_offset += ((GdkWindowObject *) window)->x;
1683 y_offset += ((GdkWindowObject *) window)->y;
1684 window = GDK_WINDOW (((GdkWindowObject *) window)->parent);
1685 }
1686
1687 GetClipBox (hdc, &rect);
1688
1689 if (((GdkWindowObject *) window)->bg_pixmap == NULL)
1690 {
1691 bg = _gdk_win32_colormap_color (GDK_DRAWABLE_IMPL_WIN32 (((GdkWindowObject *) window)->impl)->colormap,
1692 ((GdkWindowObject *) window)->bg_color.pixel);
1693
1694 if (!(hbr = CreateSolidBrush (bg)))
1695 WIN32_GDI_FAILED ("CreateSolidBrush");
1696 else if (!FillRect (hdc, &rect, hbr))
1697 WIN32_GDI_FAILED ("FillRect");
1698 if (hbr != NULL)
1699 DeleteObject (hbr);
1700 }
1701 else if (((GdkWindowObject *) window)->bg_pixmap != GDK_NO_BG)
1702 {
1703 GdkPixmap *pixmap = ((GdkWindowObject *) window)->bg_pixmap;
1704 GdkPixmapImplWin32 *pixmap_impl = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl);
1705
1706 if (x_offset == 0 && y_offset == 0 &&
1707 pixmap_impl->width <= 8 && pixmap_impl->height <= 8)
1708 {
1709 if (!(hbr = CreatePatternBrush (GDK_PIXMAP_HBITMAP (pixmap))))
1710 WIN32_GDI_FAILED ("CreatePatternBrush");
1711 else if (!FillRect (hdc, &rect, hbr))
1712 WIN32_GDI_FAILED ("FillRect");
1713 if (hbr != NULL)
1714 DeleteObject (hbr);
1715 }
1716 else
1717 {
1718 HGDIOBJ oldbitmap;
1719
1720 if (!(bgdc = CreateCompatibleDC (hdc)))
1721 {
1722 WIN32_GDI_FAILED ("CreateCompatibleDC");
1723 return;
1724 }
1725 if (!(oldbitmap = SelectObject (bgdc, GDK_PIXMAP_HBITMAP (pixmap))))
1726 {
1727 WIN32_GDI_FAILED ("SelectObject");
1728 DeleteDC (bgdc);
1729 return;
1730 }
1731 x = -x_offset;
1732 while (x < rect.right)
1733 {
1734 if (x + pixmap_impl->width >= rect.left)
1735 {
1736 y = -y_offset;
1737 while (y < rect.bottom)
1738 {
1739 if (y + pixmap_impl->height >= rect.top)
1740 {
1741 if (!BitBlt (hdc, x, y,
1742 pixmap_impl->width, pixmap_impl->height,
1743 bgdc, 0, 0, SRCCOPY))
1744 {
1745 WIN32_GDI_FAILED ("BitBlt");
1746 SelectObject (bgdc, oldbitmap);
1747 DeleteDC (bgdc);
1748 return;
1749 }
1750 }
1751 y += pixmap_impl->height;
1752 }
1753 }
1754 x += pixmap_impl->width;
1755 }
1756 SelectObject (bgdc, oldbitmap);
1757 DeleteDC (bgdc);
1758 }
1759 }
1760 }
1761
1762 static void
1763 gdk_win32_window_clear_area (GdkWindow *window,
1764 gint x,
1765 gint y,
1766 gint width,
1767 gint height,
1768 gboolean send_expose)
1769 {
1770 GdkWindowObject *private = (GdkWindowObject *)window;
1771
1772 if (!GDK_WINDOW_DESTROYED (window))
1773 {
1774 HDC hdc;
1775 RECT rect;
1776
1777 hdc = GetDC (GDK_WINDOW_HWND (window));
1778
1779 if (!send_expose)
1780 {
1781 if (width == 0)
1782 width = private->width - x;
1783 if (height == 0)
1784 height = private->height - y;
1785 GDK_NOTE (MISC, g_print ("_gdk_windowing_window_clear_area: %p: "
1786 "%dx%d@%+d%+d\n",
1787 GDK_WINDOW_HWND (window),
1788 width, height, x, y));
1789 IntersectClipRect (hdc, x, y, x + width, y + height);
1790 erase_background (window, hdc);
1791 GDI_CALL (ReleaseDC, (GDK_WINDOW_HWND (window), hdc));
1792 }
1793 else
1794 {
1795 /* The background should be erased before the expose event is
1796 generated */
1797 IntersectClipRect (hdc, x, y, x + width, y + height);
1798 erase_background (window, hdc);
1799 GDI_CALL (ReleaseDC, (GDK_WINDOW_HWND (window), hdc));
1800
1801 rect.left = x;
1802 rect.right = x + width;
1803 rect.top = y;
1804 rect.bottom = y + height;
1805
1806 GDI_CALL (InvalidateRect, (GDK_WINDOW_HWND (window), &rect, TRUE));
1807 UpdateWindow (GDK_WINDOW_HWND (window));
1808 }
1809 }
1810 }
1811
1812 static void
1813 gdk_window_win32_clear_region (GdkWindow *window,
1814 GdkRegion *region,
1815 gboolean send_expose)
1816 {
1817 GdkRectangle *rectangles;
1818 int n_rectangles, i;
1819
1820 gdk_region_get_rectangles (region,
1821 &rectangles,
1822 &n_rectangles);
1823
1824 for (i = 0; i < n_rectangles; i++)
1825 gdk_win32_window_clear_area (window,
1826 rectangles[i].x, rectangles[i].y,
1827 rectangles[i].width, rectangles[i].height,
1828 send_expose);
1829
1830 g_free (rectangles);
1831 }
1832
1833 static void
1834 gdk_win32_window_raise (GdkWindow *window)
1835 {
1836 if (!GDK_WINDOW_DESTROYED (window))
1837 {
1838 GDK_NOTE (MISC, g_print ("gdk_win32_window_raise: %p\n",
1839 GDK_WINDOW_HWND (window)));
1840
1841 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP)
1842 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_TOPMOST,
1843 0, 0, 0, 0,
1844 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE));
1845 else if (((GdkWindowObject *)window)->accept_focus)
1846 /* Do not wrap this in an API_CALL macro as SetForegroundWindow might
1847 * fail when for example dragging a window belonging to a different
1848 * application at the time of a gtk_window_present() call due to focus
1849 * stealing prevention. */
1850 SetForegroundWindow (GDK_WINDOW_HWND (window));
1851 else
1852 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_TOP,
1853 0, 0, 0, 0,
1854 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE));
1855 }
1856 }
1857
1858 static void
1859 gdk_win32_window_lower (GdkWindow *window)
1860 {
1861 if (!GDK_WINDOW_DESTROYED (window))
1862 {
1863 GDK_NOTE (MISC, g_print ("gdk_win32_window_lower: %p\n"
1864 "... SetWindowPos(%p,HWND_BOTTOM,0,0,0,0,"
1865 "NOACTIVATE|NOMOVE|NOSIZE)\n",
1866 GDK_WINDOW_HWND (window),
1867 GDK_WINDOW_HWND (window)));
1868
1869 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_BOTTOM,
1870 0, 0, 0, 0,
1871 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE));
1872 }
1873 }
1874
1875 void
1876 gdk_window_set_hints (GdkWindow *window,
1877 gint x,
1878 gint y,
1879 gint min_width,
1880 gint min_height,
1881 gint max_width,
1882 gint max_height,
1883 gint flags)
1884 {
1885 /* Note that this function is obsolete */
1886
1887 GdkWindowImplWin32 *impl;
1888
1889 g_return_if_fail (GDK_IS_WINDOW (window));
1890
1891 if (GDK_WINDOW_DESTROYED (window))
1892 return;
1893
1894 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1895
1896 GDK_NOTE (MISC, g_print ("gdk_window_set_hints: %p: %dx%d..%dx%d @%+d%+d\n",
1897 GDK_WINDOW_HWND (window),
1898 min_width, min_height, max_width, max_height,
1899 x, y));
1900
1901 if (flags)
1902 {
1903 GdkGeometry geom;
1904 gint geom_mask = 0;
1905
1906 geom.min_width = min_width;
1907 geom.min_height = min_height;
1908 geom.max_width = max_width;
1909 geom.max_height = max_height;
1910
1911 if (flags & GDK_HINT_MIN_SIZE)
1912 geom_mask |= GDK_HINT_MIN_SIZE;
1913
1914 if (flags & GDK_HINT_MAX_SIZE)
1915 geom_mask |= GDK_HINT_MAX_SIZE;
1916
1917 gdk_window_set_geometry_hints (window, &geom, geom_mask);
1918 }
1919 }
1920
1921 void
1922 gdk_window_set_urgency_hint (GdkWindow *window,
1923 gboolean urgent)
1924 {
1925 FLASHWINFO flashwinfo;
1926 typedef BOOL (WINAPI *PFN_FlashWindowEx) (FLASHWINFO*);
1927 PFN_FlashWindowEx flashWindowEx = NULL;
1928
1929 g_return_if_fail (GDK_IS_WINDOW (window));
1930 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1931
1932 if (GDK_WINDOW_DESTROYED (window))
1933 return;
1934
1935 flashWindowEx = (PFN_FlashWindowEx) GetProcAddress (GetModuleHandle ("user32.dll"), "FlashWindowEx");
1936
1937 if (flashWindowEx)
1938 {
1939 flashwinfo.cbSize = sizeof (flashwinfo);
1940 flashwinfo.hwnd = GDK_WINDOW_HWND (window);
1941 if (urgent)
1942 flashwinfo.dwFlags = FLASHW_ALL | FLASHW_TIMER;
1943 else
1944 flashwinfo.dwFlags = FLASHW_STOP;
1945 flashwinfo.uCount = 0;
1946 flashwinfo.dwTimeout = 0;
1947
1948 flashWindowEx (&flashwinfo);
1949 }
1950 else
1951 {
1952 FlashWindow (GDK_WINDOW_HWND (window), urgent);
1953 }
1954 }
1955
1956 static gboolean
1957 get_effective_window_decorations (GdkWindow *window,
1958 GdkWMDecoration *decoration)
1959 {
1960 GdkWindowImplWin32 *impl;
1961
1962 impl = (GdkWindowImplWin32 *)((GdkWindowObject *)window)->impl;
1963
1964 if (gdk_window_get_decorations (window, decoration))
1965 return TRUE;
1966
1967 if (((GdkWindowObject *) window)->window_type != GDK_WINDOW_TOPLEVEL &&
1968 ((GdkWindowObject *) window)->window_type != GDK_WINDOW_DIALOG)
1969 {
1970 return FALSE;
1971 }
1972
1973 if ((impl->hint_flags & GDK_HINT_MIN_SIZE) &&
1974 (impl->hint_flags & GDK_HINT_MAX_SIZE) &&
1975 impl->hints.min_width == impl->hints.max_width &&
1976 impl->hints.min_height == impl->hints.max_height)
1977 {
1978 *decoration = GDK_DECOR_ALL | GDK_DECOR_RESIZEH | GDK_DECOR_MAXIMIZE;
1979
1980 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1981 impl->type_hint == GDK_WINDOW_TYPE_HINT_MENU ||
1982 impl->type_hint == GDK_WINDOW_TYPE_HINT_TOOLBAR)
1983 {
1984 *decoration |= GDK_DECOR_MINIMIZE;
1985 }
1986 else if (impl->type_hint == GDK_WINDOW_TYPE_HINT_SPLASHSCREEN)
1987 {
1988 *decoration |= GDK_DECOR_MENU | GDK_DECOR_MINIMIZE;
1989 }
1990
1991 return TRUE;
1992 }
1993 else if (impl->hint_flags & GDK_HINT_MAX_SIZE)
1994 {
1995 *decoration = GDK_DECOR_ALL | GDK_DECOR_MAXIMIZE;
1996 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1997 impl->type_hint == GDK_WINDOW_TYPE_HINT_MENU ||
1998 impl->type_hint == GDK_WINDOW_TYPE_HINT_TOOLBAR)
1999 {
2000 *decoration |= GDK_DECOR_MINIMIZE;
2001 }
2002
2003 return TRUE;
2004 }
2005 else
2006 {
2007 switch (impl->type_hint)
2008 {
2009 case GDK_WINDOW_TYPE_HINT_DIALOG:
2010 *decoration = (GDK_DECOR_ALL | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE);
2011 return TRUE;
2012
2013 case GDK_WINDOW_TYPE_HINT_MENU:
2014 *decoration = (GDK_DECOR_ALL | GDK_DECOR_RESIZEH | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE);
2015 return TRUE;
2016
2017 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
2018 case GDK_WINDOW_TYPE_HINT_UTILITY:
2019 gdk_window_set_skip_taskbar_hint (window, TRUE);
2020 gdk_window_set_skip_pager_hint (window, TRUE);
2021 *decoration = (GDK_DECOR_ALL | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE);
2022 return TRUE;
2023
2024 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
2025 *decoration = (GDK_DECOR_ALL | GDK_DECOR_RESIZEH | GDK_DECOR_MENU |
2026 GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE);
2027 return TRUE;
2028
2029 case GDK_WINDOW_TYPE_HINT_DOCK:
2030 return FALSE;
2031
2032 case GDK_WINDOW_TYPE_HINT_DESKTOP:
2033 return FALSE;
2034
2035 default:
2036 /* Fall thru */
2037 case GDK_WINDOW_TYPE_HINT_NORMAL:
2038 *decoration = GDK_DECOR_ALL;
2039 return TRUE;
2040 }
2041 }
2042
2043 return FALSE;
2044 }
2045
2046 void
2047 gdk_window_set_geometry_hints (GdkWindow *window,
2048 const GdkGeometry *geometry,
2049 GdkWindowHints geom_mask)
2050 {
2051 GdkWindowImplWin32 *impl;
2052 FullscreenInfo *fi;
2053
2054 g_return_if_fail (GDK_IS_WINDOW (window));
2055
2056 if (GDK_WINDOW_DESTROYED (window))
2057 return;
2058
2059 GDK_NOTE (MISC, g_print ("gdk_window_set_geometry_hints: %p\n",
2060 GDK_WINDOW_HWND (window)));
2061
2062 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
2063
2064 fi = g_object_get_data (G_OBJECT (window), "fullscreen-info");
2065 if (fi)
2066 fi->hint_flags = geom_mask;
2067 else
2068 impl->hint_flags = geom_mask;
2069 impl->hints = *geometry;
2070
2071 if (geom_mask & GDK_HINT_POS)
2072 ; /* even the X11 mplementation doesn't care */
2073
2074 if (geom_mask & GDK_HINT_MIN_SIZE)
2075 {
2076 GDK_NOTE (MISC, g_print ("... MIN_SIZE: %dx%d\n",
2077 geometry->min_width, geometry->min_height));
2078 }
2079
2080 if (geom_mask & GDK_HINT_MAX_SIZE)
2081 {
2082 GDK_NOTE (MISC, g_print ("... MAX_SIZE: %dx%d\n",
2083 geometry->max_width, geometry->max_height));
2084 }
2085
2086 if (geom_mask & GDK_HINT_BASE_SIZE)
2087 {
2088 GDK_NOTE (MISC, g_print ("... BASE_SIZE: %dx%d\n",
2089 geometry->base_width, geometry->base_height));
2090 }
2091
2092 if (geom_mask & GDK_HINT_RESIZE_INC)
2093 {
2094 GDK_NOTE (MISC, g_print ("... RESIZE_INC: (%d,%d)\n",
2095 geometry->width_inc, geometry->height_inc));
2096 }
2097
2098 if (geom_mask & GDK_HINT_ASPECT)
2099 {
2100 GDK_NOTE (MISC, g_print ("... ASPECT: %g--%g\n",
2101 geometry->min_aspect, geometry->max_aspect));
2102 }
2103
2104 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2105 {
2106 GDK_NOTE (MISC, g_print ("... GRAVITY: %d\n", geometry->win_gravity));
2107 }
2108
2109 update_style_bits (window);
2110 }
2111
2112 void
2113 gdk_window_set_title (GdkWindow *window,
2114 const gchar *title)
2115 {
2116 wchar_t *wtitle;
2117
2118 g_return_if_fail (GDK_IS_WINDOW (window));
2119 g_return_if_fail (title != NULL);
2120
2121 if (GDK_WINDOW_DESTROYED (window))
2122 return;
2123
2124 /* Empty window titles not allowed, so set it to just a period. */
2125 if (!title[0])
2126 title = ".";
2127
2128 GDK_NOTE (MISC, g_print ("gdk_window_set_title: %p: %s\n",
2129 GDK_WINDOW_HWND (window), title));
2130
2131 GDK_NOTE (MISC_OR_EVENTS, title = g_strdup_printf ("%p %s", GDK_WINDOW_HWND (window), title));
2132
2133 wtitle = g_utf8_to_utf16 (title, -1, NULL, NULL, NULL);
2134 API_CALL (SetWindowTextW, (GDK_WINDOW_HWND (window), wtitle));
2135 g_free (wtitle);
2136
2137 GDK_NOTE (MISC_OR_EVENTS, g_free ((char *) title));
2138 }
2139
2140 void
2141 gdk_window_set_role (GdkWindow *window,
2142 const gchar *role)
2143 {
2144 g_return_if_fail (GDK_IS_WINDOW (window));
2145
2146 GDK_NOTE (MISC, g_print ("gdk_window_set_role: %p: %s\n",
2147 GDK_WINDOW_HWND (window),
2148 (role ? role : "NULL")));
2149 /* XXX */
2150 }
2151
2152 void
2153 gdk_window_set_transient_for (GdkWindow *window,
2154 GdkWindow *parent)
2155 {
2156 HWND window_id, parent_id;
2157 GdkWindowImplWin32 *window_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
2158 GdkWindowImplWin32 *parent_impl = NULL;
2159 GSList *item;
2160
2161 g_return_if_fail (GDK_IS_WINDOW (window));
2162
2163 window_id = GDK_WINDOW_HWND (window);
2164 parent_id = parent != NULL ? GDK_WINDOW_HWND (parent) : NULL;
2165
2166 GDK_NOTE (MISC, g_print ("gdk_window_set_transient_for: %p: %p\n", window_id, parent_id));
2167
2168 if (GDK_WINDOW_DESTROYED (window) || (parent && GDK_WINDOW_DESTROYED (parent)))
2169 {
2170 if (GDK_WINDOW_DESTROYED (window))
2171 GDK_NOTE (MISC, g_print ("... destroyed!\n"));
2172 else
2173 GDK_NOTE (MISC, g_print ("... owner destroyed!\n"));
2174
2175 return;
2176 }
2177
2178 if (((GdkWindowObject *) window)->window_type == GDK_WINDOW_CHILD)
2179 {
2180 GDK_NOTE (MISC, g_print ("... a child window!\n"));
2181 return;
2182 }
2183
2184 if (parent == NULL)
2185 {
2186 GdkWindowImplWin32 *trans_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window_impl->transient_owner)->impl);
2187 if (trans_impl->transient_children != NULL)
2188 {
2189 item = g_slist_find (trans_impl->transient_children, window);
2190 item->data = NULL;
2191 trans_impl->transient_children = g_slist_delete_link (trans_impl->transient_children, item);
2192 trans_impl->num_transients--;
2193
2194 if (!trans_impl->num_transients)
2195 {
2196 trans_impl->transient_children = NULL;
2197 }
2198 }
2199 g_object_unref (G_OBJECT (window_impl->transient_owner));
2200 g_object_unref (G_OBJECT (window));
2201
2202 window_impl->transient_owner = NULL;
2203 }
2204 else
2205 {
2206 parent_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (parent)->impl);
2207
2208 parent_impl->transient_children = g_slist_append (parent_impl->transient_children, window);
2209 g_object_ref (G_OBJECT (window));
2210 parent_impl->num_transients++;
2211 window_impl->transient_owner = parent;
2212 g_object_ref (G_OBJECT (parent));
2213 }
2214
2215 /* This changes the *owner* of the window, despite the misleading
2216 * name. (Owner and parent are unrelated concepts.) At least that's
2217 * what people who seem to know what they talk about say on
2218 * USENET. Search on Google.
2219 */
2220 SetLastError (0);
2221 if (SetWindowLongPtr (window_id, GWLP_HWNDPARENT, (LONG_PTR) parent_id) == 0 &&
2222 GetLastError () != 0)
2223 WIN32_API_FAILED ("SetWindowLongPtr");
2224 }
2225
2226 void
2227 _gdk_push_modal_window (GdkWindow *window)
2228 {
2229 modal_window_stack = g_slist_prepend (modal_window_stack,
2230 window);
2231 }
2232
2233 void
2234 _gdk_remove_modal_window (GdkWindow *window)
2235 {
2236 GSList *tmp;
2237
2238 g_return_if_fail (window != NULL);
2239
2240 /* It's possible to be NULL here if someone sets the modal hint of the window
2241 * to FALSE before a modal window stack has ever been created. */
2242 if (modal_window_stack == NULL)
2243 return;
2244
2245 /* Find the requested window in the stack and remove it. Yeah, I realize this
2246 * means we're not a 'real stack', strictly speaking. Sue me. :) */
2247 tmp = g_slist_find (modal_window_stack, window);
2248 if (tmp != NULL)
2249 {
2250 modal_window_stack = g_slist_delete_link (modal_window_stack, tmp);
2251 }
2252 }
2253
2254 gboolean
2255 _gdk_modal_blocked (GdkWindow *window)
2256 {
2257 GSList *l;
2258 gboolean found_any = FALSE;
2259
2260 for (l = modal_window_stack; l != NULL; l = l->next)
2261 {
2262 GdkWindow *modal = l->data;
2263
2264 if (modal == window)
2265 return FALSE;
2266
2267 if (GDK_WINDOW_IS_MAPPED (modal))
2268 found_any = TRUE;
2269 }
2270
2271 return found_any;
2272 }
2273
2274 GdkWindow *
2275 _gdk_modal_current (void)
2276 {
2277 GSList *l;
2278
2279 for (l = modal_window_stack; l != NULL; l = l->next)
2280 {
2281 GdkWindow *modal = l->data;
2282
2283 if (GDK_WINDOW_IS_MAPPED (modal))
2284 return modal;
2285 }
2286
2287 return NULL;
2288 }
2289
2290 static void
2291 gdk_win32_window_set_background (GdkWindow *window,
2292 const GdkColor *color)
2293 {
2294 GdkWindowObject *private = (GdkWindowObject *)window;
2295
2296 GDK_NOTE (MISC, g_print ("gdk_win32_window_set_background: %p: %s\n",
2297 GDK_WINDOW_HWND (window),
2298 _gdk_win32_color_to_string (color)));
2299
2300 private->bg_color = *color;
2301
2302 if (private->bg_pixmap &&
2303 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2304 private->bg_pixmap != GDK_NO_BG)
2305 {
2306 g_object_unref (private->bg_pixmap);
2307 private->bg_pixmap = NULL;
2308 }
2309 }
2310
2311 static void
2312 gdk_win32_window_set_back_pixmap (GdkWindow *window,
2313 GdkPixmap *pixmap)
2314 {
2315 GdkWindowObject *private = (GdkWindowObject *)window;
2316
2317 if (pixmap != GDK_PARENT_RELATIVE_BG &&
2318 pixmap != GDK_NO_BG &&
2319 pixmap && !gdk_drawable_get_colormap (pixmap))
2320 {
2321 g_warning ("gdk_window_set_back_pixmap(): pixmap must have a colormap");
2322 return;
2323 }
2324
2325 if (private->bg_pixmap &&
2326 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2327 private->bg_pixmap != GDK_NO_BG)
2328 g_object_unref (private->bg_pixmap);
2329
2330 if (pixmap != GDK_PARENT_RELATIVE_BG &&
2331 pixmap != GDK_NO_BG &&
2332 pixmap)
2333 {
2334 g_object_ref (pixmap);
2335 private->bg_pixmap = pixmap;
2336 }
2337 else
2338 {
2339 private->bg_pixmap = pixmap;
2340 }
2341 }
2342
2343 static void
2344 gdk_win32_window_set_cursor (GdkWindow *window,
2345 GdkCursor *cursor)
2346 {
2347 GdkWindowImplWin32 *impl;
2348 GdkCursorPrivate *cursor_private;
2349 GdkWindowObject *parent_window;
2350 HCURSOR hcursor;
2351 HCURSOR hprevcursor;
2352
2353 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
2354 cursor_private = (GdkCursorPrivate*) cursor;
2355
2356 if (GDK_WINDOW_DESTROYED (window))
2357 return;
2358
2359 if (!cursor)
2360 hcursor = NULL;
2361 else
2362 hcursor = cursor_private->hcursor;
2363
2364 GDK_NOTE (MISC, g_print ("gdk_win32_window_set_cursor: %p: %p\n",
2365 GDK_WINDOW_HWND (window),
2366 hcursor));
2367
2368 /* First get the old cursor, if any (we wait to free the old one
2369 * since it may be the current cursor set in the Win32 API right
2370 * now).
2371 */
2372 hprevcursor = impl->hcursor;
2373
2374 if (hcursor == NULL)
2375 impl->hcursor = NULL;
2376 else
2377 {
2378 /* We must copy the cursor as it is OK to destroy the GdkCursor
2379 * while still in use for some window. See for instance
2380 * gimp_change_win_cursor() which calls gdk_window_set_cursor
2381 * (win, cursor), and immediately afterwards gdk_cursor_destroy
2382 * (cursor).
2383 */
2384 if ((impl->hcursor = CopyCursor (hcursor)) == NULL)
2385 WIN32_API_FAILED ("CopyCursor");
2386 GDK_NOTE (MISC, g_print ("... CopyCursor (%p) = %p\n",
2387 hcursor, impl->hcursor));
2388 }
2389
2390 if (impl->hcursor != NULL)
2391 {
2392 /* If the pointer is over our window, set new cursor */
2393 GdkWindow *curr_window = gdk_window_get_pointer (window, NULL, NULL, NULL);
2394 if (curr_window == window ||
2395 (curr_window && window == gdk_window_get_toplevel (curr_window)))
2396 SetCursor (impl->hcursor);
2397 else
2398 {
2399 /* Climb up the tree and find whether our window is the
2400 * first ancestor that has cursor defined, and if so, set
2401 * new cursor.
2402 */
2403 GdkWindowObject *curr_window_obj = GDK_WINDOW_OBJECT (curr_window);
2404 while (curr_window_obj &&
2405 !GDK_WINDOW_IMPL_WIN32 (curr_window_obj->impl)->hcursor)
2406 {
2407 curr_window_obj = curr_window_obj->parent;
2408 if (curr_window_obj == GDK_WINDOW_OBJECT (window))
2409 {
2410 SetCursor (impl->hcursor);
2411 break;
2412 }
2413 }
2414 }
2415 }
2416
2417 /* Destroy the previous cursor: Need to make sure it's no longer in
2418 * use before we destroy it, in case we're not over our window but
2419 * the cursor is still set to our old one.
2420 */
2421 if (hprevcursor != NULL)
2422 {
2423 if (GetCursor () == hprevcursor)
2424 {
2425 /* Look for a suitable cursor to use instead */
2426 hcursor = NULL;
2427 parent_window = GDK_WINDOW_OBJECT (window)->parent;
2428 while (hcursor == NULL)
2429 {
2430 if (parent_window)
2431 {
2432 impl = GDK_WINDOW_IMPL_WIN32 (parent_window->impl);
2433 hcursor = impl->hcursor;
2434 parent_window = parent_window->parent;
2435 }
2436 else
2437 {
2438 hcursor = LoadCursor (NULL, IDC_ARROW);
2439 }
2440 }
2441 SetCursor (hcursor);
2442 }
2443
2444 GDK_NOTE (MISC, g_print ("... DestroyCursor (%p)\n", hprevcursor));
2445
2446 API_CALL (DestroyCursor, (hprevcursor));
2447 }
2448 }
2449
2450 static void
2451 gdk_win32_window_get_geometry (GdkWindow *window,
2452 gint *x,
2453 gint *y,
2454 gint *width,
2455 gint *height,
2456 gint *depth)
2457 {
2458 if (!window)
2459 window = _gdk_root;
2460
2461 if (!GDK_WINDOW_DESTROYED (window))
2462 {
2463 RECT rect;
2464
2465 API_CALL (GetClientRect, (GDK_WINDOW_HWND (window), &rect));
2466
2467 if (window != _gdk_root)
2468 {
2469 POINT pt;
2470 GdkWindow *parent = gdk_window_get_parent (window);
2471
2472 pt.x = rect.left;
2473 pt.y = rect.top;
2474 ClientToScreen (GDK_WINDOW_HWND (window), &pt);
2475 ScreenToClient (GDK_WINDOW_HWND (parent), &pt);
2476 rect.left = pt.x;
2477 rect.top = pt.y;
2478
2479 pt.x = rect.right;
2480 pt.y = rect.bottom;
2481 ClientToScreen (GDK_WINDOW_HWND (window), &pt);
2482 ScreenToClient (GDK_WINDOW_HWND (parent), &pt);
2483 rect.right = pt.x;
2484 rect.bottom = pt.y;
2485
2486 if (parent == _gdk_root)
2487 {
2488 rect.left += _gdk_offset_x;
2489 rect.top += _gdk_offset_y;
2490 rect.right += _gdk_offset_x;
2491 rect.bottom += _gdk_offset_y;
2492 }
2493 }
2494
2495 if (x)
2496 *x = rect.left;
2497 if (y)
2498 *y = rect.top;
2499 if (width)
2500 *width = rect.right - rect.left;
2501 if (height)
2502 *height = rect.bottom - rect.top;
2503 if (depth)
2504 *depth = gdk_drawable_get_visual (window)->depth;
2505
2506 GDK_NOTE (MISC, g_print ("gdk_win32_window_get_geometry: %p: %ldx%ldx%d@%+ld%+ld\n",
2507 GDK_WINDOW_HWND (window),
2508 rect.right - rect.left, rect.bottom - rect.top,
2509 gdk_drawable_get_visual (window)->depth,
2510 rect.left, rect.top));
2511 }
2512 }
2513
2514 static gint
2515 gdk_win32_window_get_root_coords (GdkWindow *window,
2516 gint x,
2517 gint y,
2518 gint *root_x,
2519 gint *root_y)
2520 {
2521 gint tx;
2522 gint ty;
2523 POINT pt;
2524
2525 pt.x = x;
2526 pt.y = y;
2527 ClientToScreen (GDK_WINDOW_HWND (window), &pt);
2528 tx = pt.x;
2529 ty = pt.y;
2530
2531 if (root_x)
2532 *root_x = tx + _gdk_offset_x;
2533 if (root_y)
2534 *root_y = ty + _gdk_offset_y;
2535
2536 GDK_NOTE (MISC, g_print ("gdk_win32_window_get_root_coords: %p: %+d%+d %+d%+d\n",
2537 GDK_WINDOW_HWND (window),
2538 x, y,
2539 tx + _gdk_offset_x, ty + _gdk_offset_y));
2540 return 1;
2541 }
2542
2543 static gboolean
2544 gdk_win32_window_get_deskrelative_origin (GdkWindow *window,
2545 gint *x,
2546 gint *y)
2547 {
2548 return gdk_win32_window_get_root_coords (window, 0, 0, x, y);
2549 }
2550
2551 static void
2552 gdk_win32_window_restack_under (GdkWindow *window,
2553 GList *native_siblings)
2554 {
2555 GList *list;
2556
2557 /* input order is bottom-most first */
2558 for (list = native_siblings;;)
2559 {
2560 HWND lower = list->data, upper;
2561
2562 list = list->next;
2563 if (!list)
2564 break;
2565 upper = list->data;
2566 API_CALL (SetWindowPos, (upper, lower, 0, 0, 0, 0,
2567 SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW));
2568 }
2569
2570 }
2571
2572 static void
2573 gdk_win32_window_restack_toplevel (GdkWindow *window,
2574 GdkWindow *sibling,
2575 gboolean above)
2576 {
2577 HWND lower = above ? GDK_WINDOW_HWND (sibling) : GDK_WINDOW_HWND (window);
2578 HWND upper = above ? GDK_WINDOW_HWND (window) : GDK_WINDOW_HWND (sibling);
2579
2580 API_CALL (SetWindowPos, (upper, lower, 0, 0, 0, 0,
2581 SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW));
2582 }
2583
2584 void
2585 gdk_window_get_root_origin (GdkWindow *window,
2586 gint *x,
2587 gint *y)
2588 {
2589 GdkRectangle rect;
2590
2591 g_return_if_fail (GDK_IS_WINDOW (window));
2592
2593 gdk_window_get_frame_extents (window, &rect);
2594
2595 if (x)
2596 *x = rect.x;
2597
2598 if (y)
2599 *y = rect.y;
2600
2601 GDK_NOTE (MISC, g_print ("gdk_window_get_root_origin: %p: %+d%+d\n",
2602 GDK_WINDOW_HWND (window), rect.x, rect.y));
2603 }
2604
2605 void
2606 gdk_window_get_frame_extents (GdkWindow *window,
2607 GdkRectangle *rect)
2608 {
2609 GdkWindowObject *private;
2610 HWND hwnd;
2611 RECT r;
2612
2613 g_return_if_fail (GDK_IS_WINDOW (window));
2614 g_return_if_fail (rect != NULL);
2615
2616 private = GDK_WINDOW_OBJECT (window);
2617
2618 rect->x = 0;
2619 rect->y = 0;
2620 rect->width = 1;
2621 rect->height = 1;
2622
2623 if (GDK_WINDOW_DESTROYED (window))
2624 return;
2625
2626 /* FIXME: window is documented to be a toplevel GdkWindow, so is it really
2627 * necessary to walk its parent chain?
2628 */
2629 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2630 private = (GdkWindowObject*) private->parent;
2631
2632 hwnd = GDK_WINDOW_HWND (window);
2633 API_CALL (GetWindowRect, (hwnd, &r));
2634
2635 rect->x = r.left + _gdk_offset_x;
2636 rect->y = r.top + _gdk_offset_y;
2637 rect->width = r.right - r.left;
2638 rect->height = r.bottom - r.top;
2639
2640 GDK_NOTE (MISC, g_print ("gdk_window_get_frame_extents: %p: %ldx%ld@%+ld%+ld\n",
2641 GDK_WINDOW_HWND (window),
2642 r.right - r.left, r.bottom - r.top,
2643 r.left, r.top));
2644 }
2645
2646
2647 static GdkModifierType
2648 get_current_mask (void)
2649 {
2650 GdkModifierType mask;
2651 BYTE kbd[256];
2652
2653 GetKeyboardState (kbd);
2654 mask = 0;
2655 if (kbd[VK_SHIFT] & 0x80)
2656 mask |= GDK_SHIFT_MASK;
2657 if (kbd[VK_CAPITAL] & 0x80)
2658 mask |= GDK_LOCK_MASK;
2659 if (kbd[VK_CONTROL] & 0x80)
2660 mask |= GDK_CONTROL_MASK;
2661 if (kbd[VK_MENU] & 0x80)
2662 mask |= GDK_MOD1_MASK;
2663 if (kbd[VK_LBUTTON] & 0x80)
2664 mask |= GDK_BUTTON1_MASK;
2665 if (kbd[VK_MBUTTON] & 0x80)
2666 mask |= GDK_BUTTON2_MASK;
2667 if (kbd[VK_RBUTTON] & 0x80)
2668 mask |= GDK_BUTTON3_MASK;
2669
2670 return mask;
2671 }
2672
2673 static gboolean
2674 gdk_window_win32_get_pointer (GdkWindow *window,
2675 gint *x,
2676 gint *y,
2677 GdkModifierType *mask)
2678 {
2679 gboolean return_val;
2680 POINT point;
2681 HWND hwnd, hwndc;
2682
2683 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
2684
2685 return_val = TRUE;
2686
2687 hwnd = GDK_WINDOW_HWND (window);
2688 GetCursorPos (&point);
2689 ScreenToClient (hwnd, &point);
2690
2691 *x = point.x;
2692 *y = point.y;
2693
2694 if (window == _gdk_root)
2695 {
2696 *x += _gdk_offset_x;
2697 *y += _gdk_offset_y;
2698 }
2699
2700 hwndc = ChildWindowFromPoint (hwnd, point);
2701 if (hwndc != NULL && hwndc != hwnd &&
2702 !gdk_win32_handle_table_lookup ((GdkNativeWindow) hwndc))
2703 return_val = FALSE; /* Direct child unknown to gdk */
2704
2705 *mask = get_current_mask ();
2706
2707 return return_val;
2708 }
2709
2710 void
2711 _gdk_windowing_get_pointer (GdkDisplay *display,
2712 GdkScreen **screen,
2713 gint *x,
2714 gint *y,
2715 GdkModifierType *mask)
2716 {
2717 POINT point;
2718
2719 g_return_if_fail (display == _gdk_display);
2720
2721 *screen = _gdk_screen;
2722 GetCursorPos (&point);
2723 *x = point.x + _gdk_offset_x;
2724 *y = point.y + _gdk_offset_y;
2725
2726 *mask = get_current_mask ();
2727 }
2728
2729 void
2730 gdk_display_warp_pointer (GdkDisplay *display,
2731 GdkScreen *screen,
2732 gint x,
2733 gint y)
2734 {
2735 g_return_if_fail (display == _gdk_display);
2736 g_return_if_fail (screen == _gdk_screen);
2737
2738 SetCursorPos (x - _gdk_offset_x, y - _gdk_offset_y);
2739 }
2740
2741 static void
2742 screen_to_client (HWND hwnd, POINT screen_pt, POINT *client_pt)
2743 {
2744 *client_pt = screen_pt;
2745 ScreenToClient (hwnd, client_pt);
2746 }
2747
2748 GdkWindow*
2749 _gdk_windowing_window_at_pointer (GdkDisplay *display,
2750 gint *win_x,
2751 gint *win_y,
2752 GdkModifierType *mask,
2753 gboolean get_toplevel)
2754 {
2755 GdkWindow *window = NULL;
2756 POINT screen_pt, client_pt;
2757 HWND hwnd, hwndc;
2758 RECT rect;
2759
2760 GetCursorPos (&screen_pt);
2761
2762 if (get_toplevel)
2763 {
2764 /* Only consider visible children of the desktop to avoid the various
2765 * non-visible windows you often find on a running Windows box. These
2766 * might overlap our windows and cause our walk to fail. As we assume
2767 * WindowFromPoint() can find our windows, we follow similar logic
2768 * here, and ignore invisible and disabled windows.
2769 */
2770 hwnd = GetDesktopWindow ();
2771 do {
2772 window = gdk_win32_handle_table_lookup ((GdkNativeWindow) hwnd);
2773
2774 if (window != NULL &&
2775 GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT &&
2776 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
2777 break;
2778
2779 screen_to_client (hwnd, screen_pt, &client_pt);
2780 hwndc = ChildWindowFromPointEx (hwnd, client_pt, CWP_SKIPDISABLED |
2781 CWP_SKIPINVISIBLE);
2782
2783 /* Verify that we're really inside the client area of the window */
2784 if (hwndc != hwnd)
2785 {
2786 GetClientRect (hwndc, &rect);
2787 screen_to_client (hwndc, screen_pt, &client_pt);
2788 if (!PtInRect (&rect, client_pt))
2789 hwndc = hwnd;
2790 }
2791
2792 } while (hwndc != hwnd && (hwnd = hwndc, 1));
2793
2794 }
2795 else
2796 {
2797 hwnd = WindowFromPoint (screen_pt);
2798
2799 /* Verify that we're really inside the client area of the window */
2800 GetClientRect (hwnd, &rect);
2801 screen_to_client (hwnd, screen_pt, &client_pt);
2802 if (!PtInRect (&rect, client_pt))
2803 hwnd = NULL;
2804
2805 /* If we didn't hit any window at that point, return the desktop */
2806 if (hwnd == NULL)
2807 {
2808 if (win_x)
2809 *win_x = screen_pt.x + _gdk_offset_x;
2810 if (win_y)
2811 *win_y = screen_pt.y + _gdk_offset_y;
2812 return _gdk_root;
2813 }
2814
2815 window = gdk_win32_handle_table_lookup ((GdkNativeWindow) hwnd);
2816 }
2817
2818 if (window && (win_x || win_y))
2819 {
2820 if (win_x)
2821 *win_x = client_pt.x;
2822 if (win_y)
2823 *win_y = client_pt.y;
2824 }
2825
2826 GDK_NOTE (MISC, g_print ("_gdk_windowing_window_at_pointer: %+d%+d %p%s\n",
2827 *win_x, *win_y,
2828 hwnd,
2829 (window == NULL ? " NULL" : "")));
2830
2831 return window;
2832 }
2833
2834 static GdkEventMask
2835 gdk_win32_window_get_events (GdkWindow *window)
2836 {
2837 GdkWindowImplWin32 *impl;
2838
2839 if (GDK_WINDOW_DESTROYED (window))
2840 return 0;
2841
2842 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
2843
2844 return impl->native_event_mask;
2845 }
2846
2847 static void
2848 gdk_win32_window_set_events (GdkWindow *window,
2849 GdkEventMask event_mask)
2850 {
2851 GdkWindowImplWin32 *impl;
2852
2853 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
2854
2855 /* gdk_window_new() always sets the GDK_STRUCTURE_MASK, so better
2856 * set it here, too. Not that I know or remember why it is
2857 * necessary, will have to test some day.
2858 */
2859 impl->native_event_mask = GDK_STRUCTURE_MASK | event_mask;
2860 }
2861
2862 static void
2863 do_shape_combine_region (GdkWindow *window,
2864 HRGN hrgn,
2865 gint x, gint y)
2866 {
2867 RECT rect;
2868
2869 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2870 _gdk_win32_adjust_client_rect (window, &rect);
2871
2872 OffsetRgn (hrgn, -rect.left, -rect.top);
2873 OffsetRgn (hrgn, x, y);
2874
2875 /* If this is a top-level window, add the title bar to the region */
2876 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL)
2877 {
2878 HRGN tmp = CreateRectRgn (0, 0, rect.right - rect.left, -rect.top);
2879 CombineRgn (hrgn, hrgn, tmp, RGN_OR);
2880 DeleteObject (tmp);
2881 }
2882
2883 SetWindowRgn (GDK_WINDOW_HWND (window), hrgn, TRUE);
2884 }
2885
2886 static void
2887 gdk_win32_window_shape_combine_mask (GdkWindow *window,
2888 GdkBitmap *mask,
2889 gint x, gint y)
2890 {
2891 GdkWindowObject *private = (GdkWindowObject *)window;
2892
2893 if (!mask)
2894 {
2895 GDK_NOTE (MISC, g_print ("gdk_window_shape_combine_mask: %p: none\n",
2896 GDK_WINDOW_HWND (window)));
2897 SetWindowRgn (GDK_WINDOW_HWND (window), NULL, TRUE);
2898
2899 private->shaped = FALSE;
2900 }
2901 else
2902 {
2903 HRGN hrgn;
2904
2905 GDK_NOTE (MISC, g_print ("gdk_window_shape_combine_mask: %p: %p\n",
2906 GDK_WINDOW_HWND (window),
2907 GDK_WINDOW_HWND (mask)));
2908
2909 /* Convert mask bitmap to region */
2910 hrgn = _gdk_win32_bitmap_to_hrgn (mask);
2911
2912 do_shape_combine_region (window, hrgn, x, y);
2913
2914 private->shaped = TRUE;
2915 }
2916 }
2917
2918 void
2919 gdk_window_set_override_redirect (GdkWindow *window,
2920 gboolean override_redirect)
2921 {
2922 GdkWindowObject *private;
2923 GdkWindowImplWin32 *window_impl;
2924
2925 g_return_if_fail (GDK_IS_WINDOW (window));
2926
2927 private = (GdkWindowObject *) window;
2928 window_impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
2929
2930 window_impl->override_redirect = !!override_redirect;
2931 }
2932
2933 void
2934 gdk_window_set_accept_focus (GdkWindow *window,
2935 gboolean accept_focus)
2936 {
2937 GdkWindowObject *private;
2938
2939 g_return_if_fail (GDK_IS_WINDOW (window));
2940
2941 private = (GdkWindowObject *)window;
2942
2943 accept_focus = accept_focus != FALSE;
2944
2945 if (private->accept_focus != accept_focus)
2946 private->accept_focus = accept_focus;
2947 }
2948
2949 void
2950 gdk_window_set_focus_on_map (GdkWindow *window,
2951 gboolean focus_on_map)
2952 {
2953 GdkWindowObject *private;
2954
2955 g_return_if_fail (GDK_IS_WINDOW (window));
2956
2957 private = (GdkWindowObject *)window;
2958
2959 focus_on_map = focus_on_map != FALSE;
2960
2961 if (private->focus_on_map != focus_on_map)
2962 private->focus_on_map = focus_on_map;
2963 }
2964
2965 void
2966 gdk_window_set_icon_list (GdkWindow *window,
2967 GList *pixbufs)
2968 {
2969 GdkPixbuf *pixbuf, *big_pixbuf, *small_pixbuf;
2970 gint big_diff, small_diff;
2971 gint big_w, big_h, small_w, small_h;
2972 gint w, h;
2973 gint dw, dh, diff;
2974 HICON small_hicon, big_hicon;
2975 GdkWindowImplWin32 *impl;
2976 gint i, big_i, small_i;
2977
2978 g_return_if_fail (GDK_IS_WINDOW (window));
2979
2980 if (GDK_WINDOW_DESTROYED (window))
2981 return;
2982
2983 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
2984
2985 /* ideal sizes for small and large icons */
2986 big_w = GetSystemMetrics (SM_CXICON);
2987 big_h = GetSystemMetrics (SM_CYICON);
2988 small_w = GetSystemMetrics (SM_CXSMICON);
2989 small_h = GetSystemMetrics (SM_CYSMICON);
2990
2991 /* find closest sized icons in the list */
2992 big_pixbuf = NULL;
2993 small_pixbuf = NULL;
2994 big_diff = 0;
2995 small_diff = 0;
2996 i = 0;
2997 while (pixbufs)
2998 {
2999 pixbuf = (GdkPixbuf*) pixbufs->data;
3000 w = gdk_pixbuf_get_width (pixbuf);
3001 h = gdk_pixbuf_get_height (pixbuf);
3002
3003 dw = ABS (w - big_w);
3004 dh = ABS (h - big_h);
3005 diff = dw*dw + dh*dh;
3006 if (big_pixbuf == NULL || diff < big_diff)
3007 {
3008 big_pixbuf = pixbuf;
3009 big_diff = diff;
3010 big_i = i;
3011 }
3012
3013 dw = ABS (w - small_w);
3014 dh = ABS (h - small_h);
3015 diff = dw*dw + dh*dh;
3016 if (small_pixbuf == NULL || diff < small_diff)
3017 {
3018 small_pixbuf = pixbuf;
3019 small_diff = diff;
3020 small_i = i;
3021 }
3022
3023 pixbufs = g_list_next (pixbufs);
3024 i++;
3025 }
3026
3027 /* Create the icons */
3028 big_hicon = _gdk_win32_pixbuf_to_hicon (big_pixbuf);
3029 small_hicon = _gdk_win32_pixbuf_to_hicon (small_pixbuf);
3030
3031 /* Set the icons */
3032 SendMessageW (GDK_WINDOW_HWND (window), WM_SETICON, ICON_BIG,
3033 (LPARAM)big_hicon);
3034 SendMessageW (GDK_WINDOW_HWND (window), WM_SETICON, ICON_SMALL,
3035 (LPARAM)small_hicon);
3036
3037 /* Store the icons, destroying any previous icons */
3038 if (impl->hicon_big)
3039 GDI_CALL (DestroyIcon, (impl->hicon_big));
3040 impl->hicon_big = big_hicon;
3041 if (impl->hicon_small)
3042 GDI_CALL (DestroyIcon, (impl->hicon_small));
3043 impl->hicon_small = small_hicon;
3044 }
3045
3046 void
3047 gdk_window_set_icon (GdkWindow *window,
3048 GdkWindow *icon_window,
3049 GdkPixmap *pixmap,
3050 GdkBitmap *mask)
3051 {
3052 g_return_if_fail (GDK_IS_WINDOW (window));
3053
3054 /* do nothing, use gdk_window_set_icon_list instead */
3055 }
3056
3057 void
3058 gdk_window_set_icon_name (GdkWindow *window,
3059 const gchar *name)
3060 {
3061 /* In case I manage to confuse this again (or somebody else does):
3062 * Please note that "icon name" here really *does* mean the name or
3063 * title of an window minimized as an icon on the desktop, or in the
3064 * taskbar. It has nothing to do with the freedesktop.org icon
3065 * naming stuff.
3066 */
3067
3068 g_return_if_fail (GDK_IS_WINDOW (window));
3069
3070 if (GDK_WINDOW_DESTROYED (window))
3071 return;
3072
3073 #if 0
3074 /* This is not the correct thing to do. We should keep both the
3075 * "normal" window title, and the icon name. When the window is
3076 * minimized, call SetWindowText() with the icon name, and when the
3077 * window is restored, with the normal window title. Also, the name
3078 * is in UTF-8, so we should do the normal conversion to either wide
3079 * chars or system codepage, and use either the W or A version of
3080 * SetWindowText(), depending on Windows version.
3081 */
3082 API_CALL (SetWindowText, (GDK_WINDOW_HWND (window), name));
3083 #endif
3084 }
3085
3086 GdkWindow *
3087 gdk_window_get_group (GdkWindow *window)
3088 {
3089 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3090 g_return_val_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD, NULL);
3091
3092 if (GDK_WINDOW_DESTROYED (window))
3093 return NULL;
3094
3095 g_warning ("gdk_window_get_group not yet implemented");
3096
3097 return NULL;
3098 }
3099
3100 void
3101 gdk_window_set_group (GdkWindow *window,
3102 GdkWindow *leader)
3103 {
3104 g_return_if_fail (GDK_IS_WINDOW (window));
3105 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
3106 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
3107
3108 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3109 return;
3110
3111 g_warning ("gdk_window_set_group not implemented");
3112 }
3113
3114 static void
3115 update_single_bit (LONG *style,
3116 gboolean all,
3117 int gdk_bit,
3118 int style_bit)
3119 {
3120 /* all controls the interpretation of gdk_bit -- if all is TRUE,
3121 * gdk_bit indicates whether style_bit is off; if all is FALSE, gdk
3122 * bit indicate whether style_bit is on
3123 */
3124 if ((!all && gdk_bit) || (all && !gdk_bit))
3125 *style |= style_bit;
3126 else
3127 *style &= ~style_bit;
3128 }
3129
3130 static void
3131 update_style_bits (GdkWindow *window)
3132 {
3133 GdkWindowObject *private = (GdkWindowObject *)window;
3134 GdkWindowImplWin32 *impl = (GdkWindowImplWin32 *)private->impl;
3135 GdkWMDecoration decorations;
3136 LONG old_style, new_style, old_exstyle, new_exstyle;
3137 gboolean all;
3138 RECT rect, before, after;
3139
3140 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
3141 return;
3142
3143 old_style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
3144 old_exstyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
3145
3146 GetClientRect (GDK_WINDOW_HWND (window), &before);
3147 after = before;
3148 AdjustWindowRectEx (&before, old_style, FALSE, old_exstyle);
3149
3150 new_style = old_style;
3151 new_exstyle = old_exstyle;
3152
3153 if (private->window_type == GDK_WINDOW_TEMP)
3154 new_exstyle |= WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
3155 else if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY)
3156 new_exstyle |= WS_EX_TOOLWINDOW ;
3157 else
3158 new_exstyle &= ~WS_EX_TOOLWINDOW;
3159
3160 if (get_effective_window_decorations (window, &decorations))
3161 {
3162 all = (decorations & GDK_DECOR_ALL);
3163 update_single_bit (&new_style, all, decorations & GDK_DECOR_BORDER, WS_BORDER);
3164 update_single_bit (&new_style, all, decorations & GDK_DECOR_RESIZEH, WS_THICKFRAME);
3165 update_single_bit (&new_style, all, decorations & GDK_DECOR_TITLE, WS_CAPTION);
3166 update_single_bit (&new_style, all, decorations & GDK_DECOR_MENU, WS_SYSMENU);
3167 update_single_bit (&new_style, all, decorations & GDK_DECOR_MINIMIZE, WS_MINIMIZEBOX);
3168 update_single_bit (&new_style, all, decorations & GDK_DECOR_MAXIMIZE, WS_MAXIMIZEBOX);
3169 }
3170
3171 if (old_style == new_style && old_exstyle == new_exstyle )
3172 {
3173 GDK_NOTE (MISC, g_print ("update_style_bits: %p: no change\n",
3174 GDK_WINDOW_HWND (window)));
3175 return;
3176 }
3177
3178 if (old_style != new_style)
3179 {
3180 GDK_NOTE (MISC, g_print ("update_style_bits: %p: STYLE: %s => %s\n",
3181 GDK_WINDOW_HWND (window),
3182 _gdk_win32_window_style_to_string (old_style),
3183 _gdk_win32_window_style_to_string (new_style)));
3184
3185 SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, new_style);
3186 }
3187
3188 if (old_exstyle != new_exstyle)
3189 {
3190 GDK_NOTE (MISC, g_print ("update_style_bits: %p: EXSTYLE: %s => %s\n",
3191 GDK_WINDOW_HWND (window),
3192 _gdk_win32_window_exstyle_to_string (old_exstyle),
3193 _gdk_win32_window_exstyle_to_string (new_exstyle)));
3194
3195 SetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE, new_exstyle);
3196 }
3197
3198 AdjustWindowRectEx (&after, new_style, FALSE, new_exstyle);
3199
3200 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
3201 rect.left += after.left - before.left;
3202 rect.top += after.top - before.top;
3203 rect.right += after.right - before.right;
3204 rect.bottom += after.bottom - before.bottom;
3205
3206 SetWindowPos (GDK_WINDOW_HWND (window), NULL,
3207 rect.left, rect.top,
3208 rect.right - rect.left, rect.bottom - rect.top,
3209 SWP_FRAMECHANGED | SWP_NOACTIVATE |
3210 SWP_NOREPOSITION | SWP_NOZORDER);
3211
3212 }
3213
3214 static void
3215 update_single_system_menu_entry (HMENU hmenu,
3216 gboolean all,
3217 int gdk_bit,
3218 int menu_entry)
3219 {
3220 /* all controls the interpretation of gdk_bit -- if all is TRUE,
3221 * gdk_bit indicates whether menu entry is disabled; if all is
3222 * FALSE, gdk bit indicate whether menu entry is enabled
3223 */
3224 if ((!all && gdk_bit) || (all && !gdk_bit))
3225 EnableMenuItem (hmenu, menu_entry, MF_BYCOMMAND | MF_ENABLED);
3226 else
3227 EnableMenuItem (hmenu, menu_entry, MF_BYCOMMAND | MF_GRAYED);
3228 }
3229
3230 static void
3231 update_system_menu (GdkWindow *window)
3232 {
3233 GdkWMFunction functions;
3234 BOOL all;
3235
3236 if (_gdk_window_get_functions (window, &functions))
3237 {
3238 HMENU hmenu = GetSystemMenu (GDK_WINDOW_HWND (window), FALSE);
3239
3240 all = (functions & GDK_FUNC_ALL);
3241 update_single_system_menu_entry (hmenu, all, functions & GDK_FUNC_RESIZE, SC_SIZE);
3242 update_single_system_menu_entry (hmenu, all, functions & GDK_FUNC_MOVE, SC_MOVE);
3243 update_single_system_menu_entry (hmenu, all, functions & GDK_FUNC_MINIMIZE, SC_MINIMIZE);
3244 update_single_system_menu_entry (hmenu, all, functions & GDK_FUNC_MAXIMIZE, SC_MAXIMIZE);
3245 update_single_system_menu_entry (hmenu, all, functions & GDK_FUNC_CLOSE, SC_CLOSE);
3246 }
3247 }
3248
3249 static GQuark
3250 get_decorations_quark ()
3251 {
3252 static GQuark quark = 0;
3253
3254 if (!quark)
3255 quark = g_quark_from_static_string ("gdk-window-decorations");
3256
3257 return quark;
3258 }
3259
3260 void
3261 gdk_window_set_decorations (GdkWindow *window,
3262 GdkWMDecoration decorations)
3263 {
3264 GdkWMDecoration* decorations_copy;
3265
3266 g_return_if_fail (GDK_IS_WINDOW (window));
3267
3268 GDK_NOTE (MISC, g_print ("gdk_window_set_decorations: %p: %s %s%s%s%s%s%s\n",
3269 GDK_WINDOW_HWND (window),
3270 (decorations & GDK_DECOR_ALL ? "clearing" : "setting"),
3271 (decorations & GDK_DECOR_BORDER ? "BORDER " : ""),
3272 (decorations & GDK_DECOR_RESIZEH ? "RESIZEH " : ""),
3273 (decorations & GDK_DECOR_TITLE ? "TITLE " : ""),
3274 (decorations & GDK_DECOR_MENU ? "MENU " : ""),
3275 (decorations & GDK_DECOR_MINIMIZE ? "MINIMIZE " : ""),
3276 (decorations & GDK_DECOR_MAXIMIZE ? "MAXIMIZE " : "")));
3277
3278 decorations_copy = g_malloc (sizeof (GdkWMDecoration));
3279 *decorations_copy = decorations;
3280 g_object_set_qdata_full (G_OBJECT (window), get_decorations_quark (), decorations_copy, g_free);
3281
3282 update_style_bits (window);
3283 }
3284
3285 gboolean
3286 gdk_window_get_decorations (GdkWindow *window,
3287 GdkWMDecoration *decorations)
3288 {
3289 GdkWMDecoration* decorations_set;
3290
3291 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3292
3293 decorations_set = g_object_get_qdata (G_OBJECT (window), get_decorations_quark ());
3294 if (decorations_set)
3295 *decorations = *decorations_set;
3296
3297 return (decorations_set != NULL);
3298 }
3299
3300 static GQuark
3301 get_functions_quark ()
3302 {
3303 static GQuark quark = 0;
3304
3305 if (!quark)
3306 quark = g_quark_from_static_string ("gdk-window-functions");
3307
3308 return quark;
3309 }
3310
3311 void
3312 gdk_window_set_functions (GdkWindow *window,
3313 GdkWMFunction functions)
3314 {
3315 GdkWMFunction* functions_copy;
3316
3317 g_return_if_fail (GDK_IS_WINDOW (window));
3318
3319 GDK_NOTE (MISC, g_print ("gdk_window_set_functions: %p: %s %s%s%s%s%s\n",
3320 GDK_WINDOW_HWND (window),
3321 (functions & GDK_FUNC_ALL ? "clearing" : "setting"),
3322 (functions & GDK_FUNC_RESIZE ? "RESIZE " : ""),
3323 (functions & GDK_FUNC_MOVE ? "MOVE " : ""),
3324 (functions & GDK_FUNC_MINIMIZE ? "MINIMIZE " : ""),
3325 (functions & GDK_FUNC_MAXIMIZE ? "MAXIMIZE " : ""),
3326 (functions & GDK_FUNC_CLOSE ? "CLOSE " : "")));
3327
3328 functions_copy = g_malloc (sizeof (GdkWMFunction));
3329 *functions_copy = functions;
3330 g_object_set_qdata_full (G_OBJECT (window), get_functions_quark (), functions_copy, g_free);
3331
3332 update_system_menu (window);
3333 }
3334
3335 gboolean
3336 _gdk_window_get_functions (GdkWindow *window,
3337 GdkWMFunction *functions)
3338 {
3339 GdkWMFunction* functions_set;
3340
3341 functions_set = g_object_get_qdata (G_OBJECT (window), get_functions_quark ());
3342 if (functions_set)
3343 *functions = *functions_set;
3344
3345 return (functions_set != NULL);
3346 }
3347
3348 static gboolean
3349 gdk_win32_window_set_static_gravities (GdkWindow *window,
3350 gboolean use_static)
3351 {
3352 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3353
3354 return !use_static;
3355 }
3356
3357 void
3358 gdk_window_begin_resize_drag (GdkWindow *window,
3359 GdkWindowEdge edge,
3360 gint button,
3361 gint root_x,
3362 gint root_y,
3363 guint32 timestamp)
3364 {
3365 WPARAM winedge;
3366
3367 g_return_if_fail (GDK_IS_WINDOW (window));
3368
3369 if (GDK_WINDOW_DESTROYED (window))
3370 return;
3371
3372 /* Tell Windows to start interactively resizing the window by pretending that
3373 * the left pointer button was clicked in the suitable edge or corner. This
3374 * will only work if the button is down when this function is called, and
3375 * will only work with button 1 (left), since Windows only allows window
3376 * dragging using the left mouse button.
3377 */
3378 if (button != 1)
3379 return;
3380
3381 /* Must break the automatic grab that occured when the button was
3382 * pressed, otherwise it won't work.
3383 */
3384 gdk_display_pointer_ungrab (_gdk_display, 0);
3385
3386 switch (edge)
3387 {
3388 case GDK_WINDOW_EDGE_NORTH_WEST:
3389 winedge = HTTOPLEFT;
3390 break;
3391
3392 case GDK_WINDOW_EDGE_NORTH:
3393 winedge = HTTOP;
3394 break;
3395
3396 case GDK_WINDOW_EDGE_NORTH_EAST:
3397 winedge = HTTOPRIGHT;
3398 break;
3399
3400 case GDK_WINDOW_EDGE_WEST:
3401 winedge = HTLEFT;
3402 break;
3403
3404 case GDK_WINDOW_EDGE_EAST:
3405 winedge = HTRIGHT;
3406 break;
3407
3408 case GDK_WINDOW_EDGE_SOUTH_WEST:
3409 winedge = HTBOTTOMLEFT;
3410 break;
3411
3412 case GDK_WINDOW_EDGE_SOUTH:
3413 winedge = HTBOTTOM;
3414 break;
3415
3416 case GDK_WINDOW_EDGE_SOUTH_EAST:
3417 default:
3418 winedge = HTBOTTOMRIGHT;
3419 break;
3420 }
3421
3422 DefWindowProcW (GDK_WINDOW_HWND (window), WM_NCLBUTTONDOWN, winedge,
3423 MAKELPARAM (root_x - _gdk_offset_x, root_y - _gdk_offset_y));
3424 }
3425
3426 void
3427 gdk_window_begin_move_drag (GdkWindow *window,
3428 gint button,
3429 gint root_x,
3430 gint root_y,
3431 guint32 timestamp)
3432 {
3433 g_return_if_fail (GDK_IS_WINDOW (window));
3434
3435 if (GDK_WINDOW_DESTROYED (window))
3436 return;
3437
3438 /* Tell Windows to start interactively moving the window by pretending that
3439 * the left pointer button was clicked in the titlebar. This will only work
3440 * if the button is down when this function is called, and will only work
3441 * with button 1 (left), since Windows only allows window dragging using the
3442 * left mouse button.
3443 */
3444 if (button != 1)
3445 return;
3446
3447 /* Must break the automatic grab that occured when the button was pressed,
3448 * otherwise it won't work.
3449 */
3450 gdk_display_pointer_ungrab (_gdk_display, 0);
3451
3452 DefWindowProcW (GDK_WINDOW_HWND (window), WM_NCLBUTTONDOWN, HTCAPTION,
3453 MAKELPARAM (root_x - _gdk_offset_x, root_y - _gdk_offset_y));
3454 }
3455
3456
3457 /*
3458 * Setting window states
3459 */
3460 void
3461 gdk_window_iconify (GdkWindow *window)
3462 {
3463 HWND old_active_window;
3464
3465 g_return_if_fail (GDK_IS_WINDOW (window));
3466
3467 if (GDK_WINDOW_DESTROYED (window))
3468 return;
3469
3470 GDK_NOTE (MISC, g_print ("gdk_window_iconify: %p: %s\n",
3471 GDK_WINDOW_HWND (window),
3472 _gdk_win32_window_state_to_string (((GdkWindowObject *) window)->state)));
3473
3474 if (GDK_WINDOW_IS_MAPPED (window))
3475 {
3476 old_active_window = GetActiveWindow ();
3477 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
3478 if (old_active_window != GDK_WINDOW_HWND (window))
3479 SetActiveWindow (old_active_window);
3480 }
3481 else
3482 {
3483 gdk_synthesize_window_state (window,
3484 0,
3485 GDK_WINDOW_STATE_ICONIFIED);
3486 }
3487 }
3488
3489 void
3490 gdk_window_deiconify (GdkWindow *window)
3491 {
3492 g_return_if_fail (GDK_IS_WINDOW (window));
3493
3494 if (GDK_WINDOW_DESTROYED (window))
3495 return;
3496
3497 GDK_NOTE (MISC, g_print ("gdk_window_deiconify: %p: %s\n",
3498 GDK_WINDOW_HWND (window),
3499 _gdk_win32_window_state_to_string (((GdkWindowObject *) window)->state)));
3500
3501 if (GDK_WINDOW_IS_MAPPED (window))
3502 {
3503 show_window_internal (window, GDK_WINDOW_IS_MAPPED (window), TRUE);
3504 }
3505 else
3506 {
3507 gdk_synthesize_window_state (window,
3508 GDK_WINDOW_STATE_ICONIFIED,
3509 0);
3510 }
3511 }
3512
3513 void
3514 gdk_window_stick (GdkWindow *window)
3515 {
3516 g_return_if_fail (GDK_IS_WINDOW (window));
3517
3518 if (GDK_WINDOW_DESTROYED (window))
3519 return;
3520
3521 /* FIXME: Do something? */
3522 }
3523
3524 void
3525 gdk_window_unstick (GdkWindow *window)
3526 {
3527 g_return_if_fail (GDK_IS_WINDOW (window));
3528
3529 if (GDK_WINDOW_DESTROYED (window))
3530 return;
3531
3532 /* FIXME: Do something? */
3533 }
3534
3535 void
3536 gdk_window_maximize (GdkWindow *window)
3537 {
3538 g_return_if_fail (GDK_IS_WINDOW (window));
3539
3540 if (GDK_WINDOW_DESTROYED (window))
3541 return;
3542
3543 GDK_NOTE (MISC, g_print ("gdk_window_maximize: %p: %s\n",
3544 GDK_WINDOW_HWND (window),
3545 _gdk_win32_window_state_to_string (((GdkWindowObject *) window)->state)));
3546
3547 if (GDK_WINDOW_IS_MAPPED (window))
3548 ShowWindow (GDK_WINDOW_HWND (window), SW_MAXIMIZE);
3549 else
3550 gdk_synthesize_window_state (window,
3551 0,
3552 GDK_WINDOW_STATE_MAXIMIZED);
3553 }
3554
3555 void
3556 gdk_window_unmaximize (GdkWindow *window)
3557 {
3558 g_return_if_fail (GDK_IS_WINDOW (window));
3559
3560 if (GDK_WINDOW_DESTROYED (window))
3561 return;
3562
3563 GDK_NOTE (MISC, g_print ("gdk_window_unmaximize: %p: %s\n",
3564 GDK_WINDOW_HWND (window),
3565 _gdk_win32_window_state_to_string (((GdkWindowObject *) window)->state)));
3566
3567 if (GDK_WINDOW_IS_MAPPED (window))
3568 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
3569 else
3570 gdk_synthesize_window_state (window,
3571 GDK_WINDOW_STATE_MAXIMIZED,
3572 0);
3573 }
3574
3575 void
3576 gdk_window_fullscreen (GdkWindow *window)
3577 {
3578 gint x, y, width, height;
3579 FullscreenInfo *fi;
3580 GdkWindowObject *private = (GdkWindowObject *) window;
3581 HMONITOR monitor;
3582 MONITORINFO mi;
3583
3584 g_return_if_fail (GDK_IS_WINDOW (window));
3585
3586 fi = g_new (FullscreenInfo, 1);
3587
3588 if (!GetWindowRect (GDK_WINDOW_HWND (window), &(fi->r)))
3589 g_free (fi);
3590 else
3591 {
3592 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
3593
3594 monitor = MonitorFromWindow (GDK_WINDOW_HWND (window), MONITOR_DEFAULTTONEAREST);
3595 mi.cbSize = sizeof (mi);
3596 if (monitor && GetMonitorInfo (monitor, &mi))
3597 {
3598 x = mi.rcMonitor.left;
3599 y = mi.rcMonitor.top;
3600 width = mi.rcMonitor.right - x;
3601 height = mi.rcMonitor.bottom - y;
3602 }
3603 else
3604 {
3605 x = y = 0;
3606 width = GetSystemMetrics (SM_CXSCREEN);
3607 height = GetSystemMetrics (SM_CYSCREEN);
3608 }
3609
3610 /* remember for restoring */
3611 fi->hint_flags = impl->hint_flags;
3612 impl->hint_flags &= ~GDK_HINT_MAX_SIZE;
3613 g_object_set_data (G_OBJECT (window), "fullscreen-info", fi);
3614 fi->style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE);
3615
3616 /* Send state change before configure event */
3617 gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_FULLSCREEN);
3618
3619 SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE,
3620 (fi->style & ~WS_OVERLAPPEDWINDOW) | WS_POPUP);
3621
3622 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_TOP,
3623 x, y, width, height,
3624 SWP_NOCOPYBITS | SWP_SHOWWINDOW));
3625 }
3626 }
3627
3628 void
3629 gdk_window_unfullscreen (GdkWindow *window)
3630 {
3631 FullscreenInfo *fi;
3632 GdkWindowObject *private = (GdkWindowObject *) window;
3633
3634 g_return_if_fail (GDK_IS_WINDOW (window));
3635
3636 fi = g_object_get_data (G_OBJECT (window), "fullscreen-info");
3637 if (fi)
3638 {
3639 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
3640
3641 gdk_synthesize_window_state (window, GDK_WINDOW_STATE_FULLSCREEN, 0);
3642
3643 impl->hint_flags = fi->hint_flags;
3644 SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, fi->style);
3645 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_NOTOPMOST,
3646 fi->r.left, fi->r.top,
3647 fi->r.right - fi->r.left, fi->r.bottom - fi->r.top,
3648 SWP_NOCOPYBITS | SWP_SHOWWINDOW));
3649
3650 g_object_set_data (G_OBJECT (window), "fullscreen-info", NULL);
3651 g_free (fi);
3652 update_style_bits (window);
3653 }
3654 }
3655
3656 void
3657 gdk_window_set_keep_above (GdkWindow *window,
3658 gboolean setting)
3659 {
3660 g_return_if_fail (GDK_IS_WINDOW (window));
3661
3662 if (GDK_WINDOW_DESTROYED (window))
3663 return;
3664
3665 GDK_NOTE (MISC, g_print ("gdk_window_set_keep_above: %p: %s\n",
3666 GDK_WINDOW_HWND (window),
3667 setting ? "YES" : "NO"));
3668
3669 if (GDK_WINDOW_IS_MAPPED (window))
3670 {
3671 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window),
3672 setting ? HWND_TOPMOST : HWND_NOTOPMOST,
3673 0, 0, 0, 0,
3674 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE));
3675 }
3676
3677 gdk_synthesize_window_state (window,
3678 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
3679 setting ? GDK_WINDOW_STATE_ABOVE : 0);
3680 }
3681
3682 void
3683 gdk_window_set_keep_below (GdkWindow *window,
3684 gboolean setting)
3685 {
3686 g_return_if_fail (GDK_IS_WINDOW (window));
3687
3688 if (GDK_WINDOW_DESTROYED (window))
3689 return;
3690
3691 GDK_NOTE (MISC, g_print ("gdk_window_set_keep_below: %p: %s\n",
3692 GDK_WINDOW_HWND (window),
3693 setting ? "YES" : "NO"));
3694
3695 if (GDK_WINDOW_IS_MAPPED (window))
3696 {
3697 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window),
3698 setting ? HWND_BOTTOM : HWND_NOTOPMOST,
3699 0, 0, 0, 0,
3700 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE));
3701 }
3702
3703 gdk_synthesize_window_state (window,
3704 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
3705 setting ? GDK_WINDOW_STATE_BELOW : 0);
3706 }
3707
3708 void
3709 gdk_window_focus (GdkWindow *window,
3710 guint32 timestamp)
3711 {
3712 GdkWindowObject *private;
3713
3714 g_return_if_fail (GDK_IS_WINDOW (window));
3715
3716 if (GDK_WINDOW_DESTROYED (window))
3717 return;
3718
3719 private = (GdkWindowObject *)window;
3720
3721 GDK_NOTE (MISC, g_print ("gdk_window_focus: %p: %s\n",
3722 GDK_WINDOW_HWND (window),
3723 _gdk_win32_window_state_to_string (((GdkWindowObject *) window)->state)));
3724
3725 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
3726 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
3727 else if (private->state & GDK_WINDOW_STATE_ICONIFIED)
3728 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
3729 else if (!IsWindowVisible (GDK_WINDOW_HWND (window)))
3730 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNORMAL);
3731 else
3732 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOW);
3733
3734 SetFocus (GDK_WINDOW_HWND (window));
3735 }
3736
3737 void
3738 gdk_window_set_modal_hint (GdkWindow *window,
3739 gboolean modal)
3740 {
3741 GdkWindowObject *private;
3742
3743 g_return_if_fail (GDK_IS_WINDOW (window));
3744
3745 if (GDK_WINDOW_DESTROYED (window))
3746 return;
3747
3748 GDK_NOTE (MISC, g_print ("gdk_window_set_modal_hint: %p: %s\n",
3749 GDK_WINDOW_HWND (window),
3750 modal ? "YES" : "NO"));
3751
3752 private = (GdkWindowObject*) window;
3753
3754 if (modal == private->modal_hint)
3755 return;
3756
3757 private->modal_hint = modal;
3758
3759 #if 0
3760 /* Not sure about this one.. -- Cody */
3761 if (GDK_WINDOW_IS_MAPPED (window))
3762 API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window),
3763 modal ? HWND_TOPMOST : HWND_NOTOPMOST,
3764 0, 0, 0, 0,
3765 SWP_NOMOVE | SWP_NOSIZE));
3766 #else
3767
3768 if (modal)
3769 {
3770 _gdk_push_modal_window (window);
3771 gdk_window_raise (window);
3772 }
3773 else
3774 {
3775 _gdk_remove_modal_window (window);
3776 }
3777
3778 #endif
3779 }
3780
3781 void
3782 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
3783 gboolean skips_taskbar)
3784 {
3785 static GdkWindow *owner = NULL;
3786 //GdkWindowAttr wa;
3787
3788 g_return_if_fail (GDK_IS_WINDOW (window));
3789
3790 GDK_NOTE (MISC, g_print ("gdk_window_set_skip_taskbar_hint: %p: %s, doing nothing\n",
3791 GDK_WINDOW_HWND (window),
3792 skips_taskbar ? "YES" : "NO"));
3793
3794 // ### TODO: Need to figure out what to do here.
3795 return;
3796
3797 if (skips_taskbar)
3798 {
3799 #if 0
3800 if (owner == NULL)
3801 {
3802 wa.window_type = GDK_WINDOW_TEMP;
3803 wa.wclass = GDK_INPUT_OUTPUT;
3804 wa.width = wa.height = 1;
3805 wa.event_mask = 0;
3806 owner = gdk_window_new_internal (NULL, &wa, 0, TRUE);
3807 }
3808 #endif
3809
3810 SetWindowLongPtr (GDK_WINDOW_HWND (window), GWLP_HWNDPARENT, (LONG_PTR) GDK_WINDOW_HWND (owner));
3811
3812 #if 0 /* Should we also turn off the minimize and maximize buttons? */
3813 SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE,
3814 GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE) & ~(WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU));
3815
3816 SetWindowPos (GDK_WINDOW_HWND (window), NULL,
3817 0, 0, 0, 0,
3818 SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE |
3819 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
3820 #endif
3821 }
3822 else
3823 {
3824 SetWindowLongPtr (GDK_WINDOW_HWND (window), GWLP_HWNDPARENT, 0);
3825 }
3826 }
3827
3828 void
3829 gdk_window_set_skip_pager_hint (GdkWindow *window,
3830 gboolean skips_pager)
3831 {
3832 g_return_if_fail (GDK_IS_WINDOW (window));
3833
3834 GDK_NOTE (MISC, g_print ("gdk_window_set_skip_pager_hint: %p: %s, doing nothing\n",
3835 GDK_WINDOW_HWND (window),
3836 skips_pager ? "YES" : "NO"));
3837 }
3838
3839 void
3840 gdk_window_set_type_hint (GdkWindow *window,
3841 GdkWindowTypeHint hint)
3842 {
3843 g_return_if_fail (GDK_IS_WINDOW (window));
3844
3845 if (GDK_WINDOW_DESTROYED (window))
3846 return;
3847
3848 GDK_NOTE (MISC,
3849 G_STMT_START{
3850 static GEnumClass *class = NULL;
3851 if (!class)
3852 class = g_type_class_ref (GDK_TYPE_WINDOW_TYPE_HINT);
3853 g_print ("gdk_window_set_type_hint: %p: %s\n",
3854 GDK_WINDOW_HWND (window),
3855 g_enum_get_value (class, hint)->value_name);
3856 }G_STMT_END);
3857
3858 ((GdkWindowImplWin32 *)((GdkWindowObject *)window)->impl)->type_hint = hint;
3859
3860 update_style_bits (window);
3861 }
3862
3863 GdkWindowTypeHint
3864 gdk_window_get_type_hint (GdkWindow *window)
3865 {
3866 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
3867
3868 if (GDK_WINDOW_DESTROYED (window))
3869 return GDK_WINDOW_TYPE_HINT_NORMAL;
3870
3871 return GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl)->type_hint;
3872 }
3873
3874 static void
3875 gdk_win32_window_shape_combine_region (GdkWindow *window,
3876 const GdkRegion *shape_region,
3877 gint offset_x,
3878 gint offset_y)
3879 {
3880 if (GDK_WINDOW_DESTROYED (window))
3881 return;
3882
3883 if (!shape_region)
3884 {
3885 GDK_NOTE (MISC, g_print ("gdk_win32_window_shape_combine_region: %p: none\n",
3886 GDK_WINDOW_HWND (window)));
3887 SetWindowRgn (GDK_WINDOW_HWND (window), NULL, TRUE);
3888 }
3889 else
3890 {
3891 HRGN hrgn;
3892
3893 hrgn = _gdk_win32_gdkregion_to_hrgn (shape_region, 0, 0);
3894
3895 GDK_NOTE (MISC, g_print ("gdk_win32_window_shape_combine_region: %p: %p\n",
3896 GDK_WINDOW_HWND (window),
3897 hrgn));
3898
3899 do_shape_combine_region (window, hrgn, offset_x, offset_y);
3900 }
3901 }
3902
3903 GdkWindow *
3904 gdk_window_lookup_for_display (GdkDisplay *display,
3905 GdkNativeWindow anid)
3906 {
3907 return gdk_win32_window_lookup_for_display (display, anid);
3908 }
3909
3910 GdkWindow *
3911 gdk_win32_window_lookup_for_display (GdkDisplay *display,
3912 GdkNativeWindow anid)
3913 {
3914 g_return_val_if_fail (display == _gdk_display, NULL);
3915
3916 return gdk_window_lookup (anid);
3917 }
3918
3919 void
3920 gdk_window_enable_synchronized_configure (GdkWindow *window)
3921 {
3922 g_return_if_fail (GDK_IS_WINDOW (window));
3923 }
3924
3925 void
3926 gdk_window_configure_finished (GdkWindow *window)
3927 {
3928 g_return_if_fail (GDK_IS_WINDOW (window));
3929 }
3930
3931 void
3932 _gdk_windowing_window_beep (GdkWindow *window)
3933 {
3934 gdk_display_beep (_gdk_display);
3935 }
3936
3937 void
3938 gdk_window_set_opacity (GdkWindow *window,
3939 gdouble opacity)
3940 {
3941 LONG exstyle;
3942 typedef BOOL (WINAPI *PFN_SetLayeredWindowAttributes) (HWND, COLORREF, BYTE, DWORD);
3943 PFN_SetLayeredWindowAttributes setLayeredWindowAttributes = NULL;
3944
3945 g_return_if_fail (GDK_IS_WINDOW (window));
3946 g_return_if_fail (WINDOW_IS_TOPLEVEL (window));
3947
3948 if (GDK_WINDOW_DESTROYED (window))
3949 return;
3950
3951 if (opacity < 0)
3952 opacity = 0;
3953 else if (opacity > 1)
3954 opacity = 1;
3955
3956 exstyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE);
3957
3958 if (!(exstyle & WS_EX_LAYERED))
3959 SetWindowLong (GDK_WINDOW_HWND (window),
3960 GWL_EXSTYLE,
3961 exstyle | WS_EX_LAYERED);
3962
3963 setLayeredWindowAttributes =
3964 (PFN_SetLayeredWindowAttributes)GetProcAddress (GetModuleHandle ("user32.dll"), "SetLayeredWindowAttributes");
3965
3966 if (setLayeredWindowAttributes)
3967 {
3968 API_CALL (setLayeredWindowAttributes, (GDK_WINDOW_HWND (window),
3969 0,
3970 opacity * 0xff,
3971 LWA_ALPHA));
3972 }
3973 }
3974
3975 GdkRegion *
3976 _gdk_windowing_get_shape_for_mask (GdkBitmap *mask)
3977 {
3978 GdkRegion *region;
3979 HRGN hrgn = _gdk_win32_bitmap_to_hrgn (mask);
3980
3981 region = _gdk_win32_hrgn_to_region (hrgn);
3982 DeleteObject (hrgn);
3983
3984 return region;
3985 }
3986
3987 void
3988 _gdk_windowing_window_set_composited (GdkWindow *window, gboolean composited)
3989 {
3990 }
3991
3992 GdkRegion *
3993 _gdk_windowing_window_get_shape (GdkWindow *window)
3994 {
3995 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
3996 int type = GetWindowRgn (GDK_WINDOW_HWND (window), hrgn);
3997
3998 if (type == SIMPLEREGION || type == COMPLEXREGION)
3999 {
4000 GdkRegion *region = _gdk_win32_hrgn_to_region (hrgn);
4001
4002 DeleteObject (hrgn);
4003 return region;
4004 }
4005
4006 return NULL;
4007 }
4008
4009 GdkRegion *
4010 _gdk_windowing_window_get_input_shape (GdkWindow *window)
4011 {
4012 /* CHECK: are these really supposed to be the same? */
4013 return _gdk_windowing_window_get_shape (window);
4014 }
4015
4016 static gboolean
4017 _gdk_win32_window_queue_antiexpose (GdkWindow *window,
4018 GdkRegion *area)
4019 {
4020 HRGN hrgn = _gdk_win32_gdkregion_to_hrgn (area, 0, 0);
4021
4022 GDK_NOTE (EVENTS, g_print ("_gdk_windowing_window_queue_antiexpose: ValidateRgn %p %s\n",
4023 GDK_WINDOW_HWND (window),
4024 _gdk_win32_gdkregion_to_string (area)));
4025
4026 ValidateRgn (GDK_WINDOW_HWND (window), hrgn);
4027
4028 DeleteObject (hrgn);
4029
4030 return FALSE;
4031 }
4032
4033 /*
4034 * queue_translation is meant to only move any outstanding invalid area
4035 * in the given area by dx,dy. A typical example of when its needed is an
4036 * app with two toplevels where one (A) overlaps the other (B). If the
4037 * app first moves A so that B is invalidated and then scrolls B before
4038 * handling the expose. The scroll operation will copy the invalid area
4039 * to a new position, but when the invalid area is then exposed it only
4040 * redraws the old areas not the place where the invalid data was copied
4041 * by the scroll.
4042 */
4043 static void
4044 _gdk_win32_window_queue_translation (GdkWindow *window,
4045 GdkGC *gc,
4046 GdkRegion *area,
4047 gint dx,
4048 gint dy)
4049 {
4050 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
4051 int ret = GetUpdateRgn (GDK_WINDOW_HWND (window), hrgn, FALSE);
4052 if (ret == ERROR)
4053 WIN32_API_FAILED ("GetUpdateRgn");
4054 else if (ret != NULLREGION)
4055 {
4056 /* Get current updateregion, move any part of it that intersects area by dx,dy */
4057 HRGN update = _gdk_win32_gdkregion_to_hrgn (area, 0, 0);
4058 ret = CombineRgn (update, hrgn, update, RGN_AND);
4059 if (ret == ERROR)
4060 WIN32_API_FAILED ("CombineRgn");
4061 else if (ret != NULLREGION)
4062 {
4063 OffsetRgn (update, dx, dy);
4064 API_CALL (InvalidateRgn, (GDK_WINDOW_HWND (window), update, TRUE));
4065 }
4066 DeleteObject (update);
4067 }
4068 DeleteObject (hrgn);
4069 }
4070
4071 static void
4072 gdk_win32_input_shape_combine_region (GdkWindow *window,
4073 const GdkRegion *shape_region,
4074 gint offset_x,
4075 gint offset_y)
4076 {
4077 if (GDK_WINDOW_DESTROYED (window))
4078 return;
4079 /* CHECK: are these really supposed to be the same? */
4080 gdk_win32_window_shape_combine_region (window, shape_region, offset_x, offset_y);
4081 }
4082
4083 void
4084 _gdk_windowing_window_process_updates_recurse (GdkWindow *window,
4085 GdkRegion *region)
4086 {
4087 _gdk_window_process_updates_recurse (window, region);
4088 }
4089
4090 void
4091 _gdk_windowing_before_process_all_updates (void)
4092 {
4093 }
4094
4095 void
4096 _gdk_windowing_after_process_all_updates (void)
4097 {
4098 }
4099
4100 static void
4101 gdk_window_impl_iface_init (GdkWindowImplIface *iface)
4102 {
4103 iface->show = gdk_win32_window_show;
4104 iface->hide = gdk_win32_window_hide;
4105 iface->withdraw = gdk_win32_window_withdraw;
4106 iface->set_events = gdk_win32_window_set_events;
4107 iface->get_events = gdk_win32_window_get_events;
4108 iface->raise = gdk_win32_window_raise;
4109 iface->lower = gdk_win32_window_lower;
4110 iface->restack_under = gdk_win32_window_restack_under;
4111 iface->restack_toplevel = gdk_win32_window_restack_toplevel;
4112 iface->move_resize = gdk_win32_window_move_resize;
4113 iface->set_background = gdk_win32_window_set_background;
4114 iface->set_back_pixmap = gdk_win32_window_set_back_pixmap;
4115 iface->reparent = gdk_win32_window_reparent;
4116 iface->clear_region = gdk_window_win32_clear_region;
4117 iface->set_cursor = gdk_win32_window_set_cursor;
4118 iface->get_geometry = gdk_win32_window_get_geometry;
4119 iface->get_root_coords = gdk_win32_window_get_root_coords;
4120 iface->get_pointer = gdk_window_win32_get_pointer;
4121 iface->get_deskrelative_origin = gdk_win32_window_get_deskrelative_origin;
4122 iface->shape_combine_region = gdk_win32_window_shape_combine_region;
4123 iface->input_shape_combine_region = gdk_win32_input_shape_combine_region;
4124 iface->set_static_gravities = gdk_win32_window_set_static_gravities;
4125 iface->queue_antiexpose = _gdk_win32_window_queue_antiexpose;
4126 iface->queue_translation = _gdk_win32_window_queue_translation;
4127 iface->destroy = _gdk_win32_window_destroy;
4128 iface->input_window_destroy = _gdk_input_window_destroy;
4129 iface->input_window_crossing = _gdk_input_crossing_event;
4130 /* CHECK: we may not need set_pixmap anymore if setting FALSE */
4131 iface->supports_native_bg = TRUE;
4132 }
4133
4134 gboolean
4135 gdk_win32_window_is_win32 (GdkWindow *window)
4136 {
4137 return GDK_WINDOW_IS_WIN32 (window);
4138 }
4139
4140 HWND
4141 gdk_win32_window_get_impl_hwnd (GdkWindow *window)
4142 {
4143 if (GDK_WINDOW_IS_WIN32 (window))
4144 return GDK_WINDOW_HWND (window);
4145 return NULL;
4146 }
4147
4148
4149 GdkDrawable *
4150 gdk_win32_begin_direct_draw_libgtk_only (GdkDrawable *drawable,
4151 GdkGC *gc,
4152 gpointer *priv_data,
4153 gint *x_offset_out,
4154 gint *y_offset_out)
4155 {
4156 GdkDrawable *impl;
4157
4158 impl = _gdk_drawable_begin_direct_draw (drawable,
4159 gc,
4160 priv_data,
4161 x_offset_out,
4162 y_offset_out);
4163
4164 return impl;
4165 }
4166
4167 void
4168 gdk_win32_end_direct_draw_libgtk_only (gpointer priv_data)
4169 {
4170 _gdk_drawable_end_direct_draw (priv_data);
4171 }