1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright (C) 1998-1999 Tor Lillqvist
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include "gdkevents.h"
34 #include "gdkpixmap.h"
35 #include "gdkwindow.h"
36 #include "gdkprivate-win32.h"
37 #include "gdkinputprivate.h"
40 static gboolean gdk_window_gravity_works (void);
41 static void gdk_window_set_static_win_gravity (GdkWindow *window,
44 /* The Win API function AdjustWindowRect may return negative values
45 * resulting in obscured title bars. This helper function is coreccting it.
48 SafeAdjustWindowRectEx (RECT* lpRect,
53 if (!AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle))
57 lpRect->right -= lpRect->left;
62 lpRect->bottom -= lpRect->top;
69 gdk_win32_window_destroy (GdkDrawable *drawable)
71 if (!GDK_DRAWABLE_DESTROYED (drawable))
73 if (GDK_DRAWABLE_TYPE (drawable) == GDK_WINDOW_FOREIGN)
74 gdk_xid_table_remove (GDK_DRAWABLE_XID (drawable));
76 g_warning ("losing last reference to undestroyed window\n");
79 if (GDK_WINDOW_WIN32DATA (drawable)->bg_type == GDK_WIN32_BG_PIXMAP
80 && GDK_WINDOW_WIN32DATA (drawable)->bg_pixmap != NULL)
81 gdk_drawable_unref (GDK_WINDOW_WIN32DATA (drawable)->bg_pixmap);
83 g_free (GDK_DRAWABLE_WIN32DATA (drawable));
87 gdk_win32_window_alloc (void)
90 GdkWindowPrivate *private;
92 static GdkDrawableClass klass;
93 static gboolean initialized = FALSE;
99 klass = _gdk_win32_drawable_class;
100 klass.destroy = gdk_win32_window_destroy;
103 window = _gdk_window_alloc ();
104 private = (GdkWindowPrivate *) window;
106 private->drawable.klass = &klass;
107 private->drawable.klass_data = g_new (GdkDrawableWin32Data, 1);
109 GDK_WINDOW_WIN32DATA (window)->event_mask = 0;
110 GDK_WINDOW_WIN32DATA (window)->bg_type = GDK_WIN32_BG_NORMAL;
111 GDK_WINDOW_WIN32DATA (window)->xcursor = NULL;
112 GDK_WINDOW_WIN32DATA (window)->hint_flags = 0;
113 GDK_WINDOW_WIN32DATA (window)->extension_events = 0;
114 GDK_WINDOW_WIN32DATA (window)->extension_events_selected = FALSE;
116 GDK_WINDOW_WIN32DATA (window)->input_locale = GetKeyboardLayout (0);
117 TranslateCharsetInfo ((DWORD FAR *) GetACP (),
118 &GDK_WINDOW_WIN32DATA (window)->charset_info,
125 gdk_window_init (void)
127 GdkWindowPrivate *private;
132 SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
133 width = r.right - r.left;
134 height = r.bottom - r.top;
136 gdk_parent_root = gdk_win32_window_alloc ();
137 private = (GdkWindowPrivate *) gdk_parent_root;
139 GDK_DRAWABLE_WIN32DATA (gdk_parent_root)->xid = gdk_root_window;
140 private->drawable.window_type = GDK_WINDOW_ROOT;
141 private->drawable.width = width;
142 private->drawable.height = height;
144 gdk_xid_table_insert (&gdk_root_window, gdk_parent_root);
148 * is a wrapper function for RegisterWindowClassEx.
149 * It creates at least one unique class for every
150 * GdkWindowType. If support for single window-specific icons
151 * is ever needed (e.g Dialog specific), every such window should
155 RegisterGdkClass (GdkDrawableType wtype)
157 static ATOM klassTOPLEVEL = 0;
158 static ATOM klassDIALOG = 0;
159 static ATOM klassCHILD = 0;
160 static ATOM klassTEMP = 0;
161 static HICON hAppIcon = NULL;
162 static WNDCLASSEX wcl;
165 wcl.cbSize = sizeof(WNDCLASSEX);
166 wcl.style = 0; /* DON'T set CS_<H,V>REDRAW. It causes total redraw
167 * on WM_SIZE and WM_MOVE. Flicker, Performance!
169 wcl.lpfnWndProc = gdk_WindowProc;
172 wcl.hInstance = gdk_ProgInstance;
174 /* initialize once! */
177 gchar sLoc [_MAX_PATH+1];
178 HINSTANCE hInst = GetModuleHandle(NULL);
180 if (0 != GetModuleFileName(hInst, sLoc, _MAX_PATH))
182 hAppIcon = ExtractIcon(hInst, sLoc, 0);
185 char *gdklibname = g_strdup_printf ("gdk-%s.dll", GDK_VERSION);
187 hAppIcon = ExtractIcon(hInst, gdklibname, 0);
192 hAppIcon = LoadIcon (NULL, IDI_APPLICATION);
196 wcl.lpszMenuName = NULL;
199 /* initialize once per class */
200 #define ONCE_PER_CLASS() \
201 wcl.hIcon = CopyIcon (hAppIcon); \
202 wcl.hIconSm = CopyIcon (hAppIcon); \
203 wcl.hbrBackground = CreateSolidBrush( RGB(0,0,0)); \
204 wcl.hCursor = LoadCursor (NULL, IDC_ARROW);
208 case GDK_WINDOW_TOPLEVEL:
209 if (0 == klassTOPLEVEL)
211 wcl.lpszClassName = "gdkWindowToplevel";
214 klassTOPLEVEL = RegisterClassEx(&wcl);
216 klass = klassTOPLEVEL;
218 case GDK_WINDOW_CHILD:
221 wcl.lpszClassName = "gdkWindowChild";
223 wcl.style |= CS_PARENTDC; /* MSDN: ... enhances system performance. */
225 klassCHILD = RegisterClassEx(&wcl);
229 case GDK_WINDOW_DIALOG:
230 if (0 == klassDIALOG)
232 wcl.lpszClassName = "gdkWindowDialog";
233 wcl.style |= CS_SAVEBITS;
235 klassDIALOG = RegisterClassEx(&wcl);
239 case GDK_WINDOW_TEMP:
242 wcl.lpszClassName = "gdkWindowTemp";
243 wcl.style |= CS_SAVEBITS;
245 klassTEMP = RegisterClassEx(&wcl);
249 case GDK_WINDOW_ROOT:
250 g_error ("cannot make windows of type GDK_WINDOW_ROOT");
252 case GDK_DRAWABLE_PIXMAP:
253 g_error ("cannot make windows of type GDK_DRAWABLE_PIXMAP (use gdk_pixmap_new)");
261 gdk_window_new (GdkWindow *parent,
262 GdkWindowAttr *attributes,
263 gint attributes_mask)
266 GdkWindowPrivate *private;
267 GdkWindowPrivate *parent_private;
272 DWORD dwStyle, dwExStyle;
282 g_return_val_if_fail (attributes != NULL, NULL);
285 parent = gdk_parent_root;
287 parent_private = (GdkWindowPrivate*) parent;
288 if (GDK_DRAWABLE_DESTROYED (parent))
291 xparent = GDK_DRAWABLE_XID (parent);
293 window = gdk_win32_window_alloc ();
294 private = (GdkWindowPrivate *)window;
296 private->parent = parent;
298 private->x = (attributes_mask & GDK_WA_X) ? attributes->x : 0;
299 private->y = (attributes_mask & GDK_WA_Y) ? attributes->y : 0;
301 private->drawable.width = (attributes->width > 1) ? (attributes->width) : (1);
302 private->drawable.height = (attributes->height > 1) ? (attributes->height) : (1);
303 private->drawable.window_type = attributes->window_type;
304 GDK_WINDOW_WIN32DATA (window)->extension_events = 0;
305 GDK_WINDOW_WIN32DATA (window)->extension_events_selected = FALSE;
307 if (attributes_mask & GDK_WA_VISUAL)
308 visual = attributes->visual;
310 visual = gdk_visual_get_system ();
311 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
313 if (attributes_mask & GDK_WA_TITLE)
314 title = attributes->title;
316 title = g_get_prgname ();
318 GDK_WINDOW_WIN32DATA (window)->event_mask = GDK_STRUCTURE_MASK | attributes->event_mask;
320 if (parent_private && parent_private->guffaw_gravity)
325 if (attributes->wclass == GDK_INPUT_OUTPUT)
328 if (attributes_mask & GDK_WA_COLORMAP)
329 private->drawable.colormap = attributes->colormap;
331 private->drawable.colormap = gdk_colormap_get_system ();
335 dwExStyle = WS_EX_TRANSPARENT;
336 private->drawable.colormap = NULL;
337 GDK_WINDOW_WIN32DATA (window)->bg_type = GDK_WIN32_BG_TRANSPARENT;
338 GDK_WINDOW_WIN32DATA (window)->bg_pixmap = NULL;
341 if (attributes_mask & GDK_WA_X)
346 if (attributes_mask & GDK_WA_Y)
348 else if (attributes_mask & GDK_WA_X)
349 y = 100; /* ??? We must put it somewhere... */
351 y = 500; /* x is CW_USEDEFAULT, y doesn't matter then */
354 parent_private->children = g_list_prepend (parent_private->children, window);
356 switch (private->drawable.window_type)
358 case GDK_WINDOW_TOPLEVEL:
359 dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN;
360 xparent = gdk_root_window;
362 case GDK_WINDOW_CHILD:
363 dwStyle = WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
365 case GDK_WINDOW_DIALOG:
366 dwStyle = WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU | WS_CAPTION | WS_THICKFRAME | WS_CLIPCHILDREN;
367 dwExStyle |= WS_EX_TOPMOST; /* //HB: want this? */
368 xparent = gdk_root_window;
370 case GDK_WINDOW_TEMP:
371 dwStyle = WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
372 dwExStyle |= WS_EX_TOOLWINDOW;
374 case GDK_WINDOW_ROOT:
375 g_error ("cannot make windows of type GDK_WINDOW_ROOT");
377 case GDK_DRAWABLE_PIXMAP:
378 g_error ("cannot make windows of type GDK_DRAWABLE_PIXMAP (use gdk_pixmap_new)");
382 klass = RegisterGdkClass (private->drawable.window_type);
384 g_error ("RegisterClassEx failed");
386 if (private->drawable.window_type != GDK_WINDOW_CHILD)
388 if (x == CW_USEDEFAULT)
399 rect.right = rect.left + private->drawable.width;
400 rect.bottom = rect.top + private->drawable.height;
402 if (!SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle))
403 g_warning ("gdk_window_new: AdjustWindowRectEx failed");
405 if (x != CW_USEDEFAULT)
410 width = rect.right - rect.left;
411 height = rect.bottom - rect.top;
415 width = private->drawable.width;
416 height = private->drawable.height;
419 titlelen = strlen (title);
420 wctitle = g_new (wchar_t, titlelen + 1);
421 mbtitle = g_new (char, 3*titlelen + 1);
422 wlen = gdk_nmbstowchar_ts (wctitle, title, titlelen, titlelen);
424 WideCharToMultiByte (GetACP (), 0, wctitle, -1,
425 mbtitle, 3*titlelen, NULL, NULL);
427 GDK_DRAWABLE_WIN32DATA (window)->xid =
428 CreateWindowEx (dwExStyle,
429 MAKEINTRESOURCE(klass),
440 g_print ("gdk_window_create: %s %s %dx%d@+%d+%d %#x = %#x\n"
441 "...locale %#x codepage %d\n",
442 (private->drawable.window_type == GDK_WINDOW_TOPLEVEL ? "TOPLEVEL" :
443 (private->drawable.window_type == GDK_WINDOW_CHILD ? "CHILD" :
444 (private->drawable.window_type == GDK_WINDOW_DIALOG ? "DIALOG" :
445 (private->drawable.window_type == GDK_WINDOW_TEMP ? "TEMP" :
448 width, height, (x == CW_USEDEFAULT ? -9999 : x), y,
450 GDK_DRAWABLE_XID (window),
451 GDK_WINDOW_WIN32DATA (window)->input_locale,
452 GDK_WINDOW_WIN32DATA (window)->charset_info.ciACP));
457 if (GDK_DRAWABLE_XID (window) == NULL)
459 g_warning ("gdk_window_create: CreateWindowEx failed");
460 g_free (GDK_DRAWABLE_WIN32DATA (window));
465 gdk_drawable_ref (window);
466 gdk_xid_table_insert (&GDK_DRAWABLE_XID (window), window);
468 if (private->drawable.colormap)
469 gdk_colormap_ref (private->drawable.colormap);
471 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
472 (attributes->cursor) :
479 gdk_window_foreign_new (guint32 anid)
482 GdkWindowPrivate *private;
483 GdkWindowPrivate *parent_private;
488 window = gdk_win32_window_alloc ();
489 private = (GdkWindowPrivate *)window;
491 parent = GetParent ((HWND) anid);
492 private->parent = gdk_xid_table_lookup (parent);
494 parent_private = (GdkWindowPrivate *)private->parent;
497 parent_private->children = g_list_prepend (parent_private->children, window);
499 GDK_DRAWABLE_WIN32DATA (window)->xid = (HWND) anid;
500 GetClientRect ((HWND) anid, &rect);
502 point.y = rect.right;
503 ClientToScreen ((HWND) anid, &point);
504 if (parent != GetDesktopWindow ())
505 ScreenToClient (parent, &point);
506 private->x = point.x;
507 private->y = point.y;
508 private->drawable.width = rect.right - rect.left;
509 private->drawable.height = rect.bottom - rect.top;
510 private->drawable.window_type = GDK_WINDOW_FOREIGN;
511 private->drawable.destroyed = FALSE;
512 private->mapped = IsWindowVisible (GDK_DRAWABLE_XID (window));
514 private->drawable.colormap = NULL;
516 gdk_drawable_ref (window);
517 gdk_xid_table_insert (&GDK_DRAWABLE_XID (window), window);
522 /* Call this function when you want a window and all its children to
523 * disappear. When xdestroy is true, a request to destroy the window
524 * is sent out. When it is false, it is assumed that the window has
525 * been or will be destroyed by destroying some ancestor of this
529 gdk_window_internal_destroy (GdkWindow *window,
531 gboolean our_destroy)
533 GdkWindowPrivate *private;
534 GdkWindowPrivate *temp_private;
535 GdkWindow *temp_window;
539 g_return_if_fail (window != NULL);
541 private = (GdkWindowPrivate *) window;
543 GDK_NOTE (MISC, g_print ("gdk_window_internal_destroy %#x\n",
544 GDK_DRAWABLE_XID (window)));
546 switch (GDK_DRAWABLE_TYPE (window))
548 case GDK_WINDOW_TOPLEVEL:
549 case GDK_WINDOW_CHILD:
550 case GDK_WINDOW_DIALOG:
551 case GDK_WINDOW_TEMP:
552 case GDK_WINDOW_FOREIGN:
553 if (!private->drawable.destroyed)
557 GdkWindowPrivate *parent_private = (GdkWindowPrivate *)private->parent;
558 if (parent_private->children)
559 parent_private->children = g_list_remove (parent_private->children, window);
562 if (GDK_DRAWABLE_TYPE (window) != GDK_WINDOW_FOREIGN)
564 children = tmp = private->children;
565 private->children = NULL;
569 temp_window = tmp->data;
572 temp_private = (GdkWindowPrivate*) temp_window;
574 gdk_window_internal_destroy (temp_window, FALSE,
578 g_list_free (children);
581 if (private->extension_events != 0)
582 gdk_input_window_destroy (window);
584 if (private->filters)
586 tmp = private->filters;
594 g_list_free (private->filters);
595 private->filters = NULL;
598 if (private->drawable.window_type == GDK_WINDOW_FOREIGN)
600 if (our_destroy && (private->parent != NULL))
602 /* It's somebody elses window, but in our hierarchy,
603 * so reparent it to the root window, and then send
604 * it a delete event, as if we were a WM
606 gdk_window_hide (window);
607 gdk_window_reparent (window, NULL, 0, 0);
609 /* Is this too drastic? Many (most?) applications
610 * quit if any window receives WM_QUIT I think.
611 * OTOH, I don't think foreign windows are much
612 * used, so the question is maybe academic.
614 PostMessage (GDK_DRAWABLE_XID (window), WM_QUIT, 0, 0);
618 DestroyWindow (GDK_DRAWABLE_XID (window));
620 if (private->drawable.colormap)
621 gdk_colormap_unref (private->drawable.colormap);
623 private->mapped = FALSE;
624 private->drawable.destroyed = TRUE;
628 case GDK_WINDOW_ROOT:
629 g_error ("attempted to destroy root window");
632 case GDK_DRAWABLE_PIXMAP:
633 g_error ("called gdk_window_destroy on a pixmap (use gdk_drawable_unref)");
638 /* Like internal_destroy, but also destroys the reference created by
642 gdk_window_destroy (GdkWindow *window)
644 gdk_window_internal_destroy (window, TRUE, TRUE);
645 gdk_drawable_unref (window);
648 /* This function is called when the window really gone. */
651 gdk_window_destroy_notify (GdkWindow *window)
653 g_return_if_fail (window != NULL);
656 g_print ("gdk_window_destroy_notify: %#x %s\n",
657 GDK_DRAWABLE_XID (window),
658 (GDK_DRAWABLE_DESTROYED (window) ? "yes" : "no")));
660 if (!GDK_DRAWABLE_DESTROYED (window))
662 if (GDK_DRAWABLE_TYPE(window) != GDK_WINDOW_FOREIGN)
663 g_warning ("window %#x unexpectedly destroyed",
664 GDK_DRAWABLE_XID (window));
666 gdk_window_internal_destroy (window, FALSE, FALSE);
669 gdk_xid_table_remove (GDK_DRAWABLE_XID (window));
670 gdk_drawable_unref (window);
674 gdk_window_show (GdkWindow *window)
676 g_return_if_fail (window != NULL);
678 if (!GDK_DRAWABLE_DESTROYED (window))
680 GDK_NOTE (MISC, g_print ("gdk_window_show: %#x\n",
681 GDK_DRAWABLE_XID (window)));
683 ((GdkWindowPrivate *) window)->mapped = TRUE;
684 if (GDK_DRAWABLE_TYPE (window) == GDK_WINDOW_TEMP)
686 ShowWindow (GDK_DRAWABLE_XID (window), SW_SHOWNOACTIVATE);
687 SetWindowPos (GDK_DRAWABLE_XID (window), HWND_TOPMOST, 0, 0, 0, 0,
688 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
690 /* Don't put on toolbar */
691 ShowWindow (GDK_DRAWABLE_XID (window), SW_HIDE);
696 ShowWindow (GDK_DRAWABLE_XID (window), SW_SHOWNORMAL);
697 ShowWindow (GDK_DRAWABLE_XID (window), SW_RESTORE);
698 SetForegroundWindow (GDK_DRAWABLE_XID (window));
699 BringWindowToTop (GDK_DRAWABLE_XID (window));
701 ShowOwnedPopups (GDK_DRAWABLE_XID (window), TRUE);
708 gdk_window_hide (GdkWindow *window)
710 g_return_if_fail (window != NULL);
712 if (!GDK_DRAWABLE_DESTROYED (window))
714 GDK_NOTE (MISC, g_print ("gdk_window_hide: %#x\n",
715 GDK_DRAWABLE_XID (window)));
717 ((GdkWindowPrivate *) window)->mapped = FALSE;
718 if (GDK_DRAWABLE_TYPE (window) == GDK_WINDOW_TOPLEVEL)
719 ShowOwnedPopups (GDK_DRAWABLE_XID (window), FALSE);
721 ShowWindow (GDK_DRAWABLE_XID (window), SW_HIDE);
723 ShowWindow (GDK_DRAWABLE_XID (window), SW_MINIMIZE);
725 CloseWindow (GDK_DRAWABLE_XID (window));
731 gdk_window_withdraw (GdkWindow *window)
733 g_return_if_fail (window != NULL);
735 if (!GDK_DRAWABLE_DESTROYED (window))
737 GDK_NOTE (MISC, g_print ("gdk_window_withdraw: %#x\n",
738 GDK_DRAWABLE_XID (window)));
740 gdk_window_hide (window); /* XXX */
745 gdk_window_move (GdkWindow *window,
749 GdkWindowPrivate *private;
751 g_return_if_fail (window != NULL);
753 if (!GDK_DRAWABLE_DESTROYED (window))
757 GDK_NOTE (MISC, g_print ("gdk_window_move: %#x +%d+%d\n",
758 GDK_DRAWABLE_XID (window), x, y));
760 private = (GdkWindowPrivate *) window;
761 GetClientRect (GDK_DRAWABLE_XID (window), &rect);
763 if (GDK_DRAWABLE_TYPE (window) != GDK_WINDOW_CHILD)
771 ClientToScreen (GDK_DRAWABLE_XID (window), &ptTL);
776 ptBR.y = rect.bottom;
777 ClientToScreen (GDK_DRAWABLE_XID (window), &ptBR);
778 rect.right = x + ptBR.x - ptTL.x;
779 rect.bottom = y + ptBR.y - ptTL.y;
781 dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
782 dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
783 if (!SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle))
784 g_warning ("gdk_window_move: AdjustWindowRectEx failed");
794 GDK_NOTE (MISC, g_print ("...MoveWindow(%#x,%dx%d@+%d+%d)\n",
795 GDK_DRAWABLE_XID (window),
796 rect.right - rect.left, rect.bottom - rect.top,
798 if (!MoveWindow (GDK_DRAWABLE_XID (window),
799 x, y, rect.right - rect.left, rect.bottom - rect.top,
801 g_warning ("gdk_window_move: MoveWindow failed");
806 gdk_window_resize (GdkWindow *window,
810 GdkWindowPrivate *private;
812 g_return_if_fail (window != NULL);
814 if ((gint16) width < 1)
816 if ((gint16) height < 1)
819 private = (GdkWindowPrivate*) window;
821 if (!private->drawable.destroyed &&
822 ((private->resize_count > 0) ||
823 (private->drawable.width != (guint16) width) ||
824 (private->drawable.height != (guint16) height)))
828 GDK_NOTE (MISC, g_print ("gdk_window_resize: %#x %dx%d\n",
829 GDK_DRAWABLE_XID (window), width, height));
831 if (private->drawable.window_type != GDK_WINDOW_CHILD)
840 ClientToScreen (GDK_DRAWABLE_XID (window), &pt);
843 rect.right = pt.x + width;
844 rect.bottom = pt.y + height;
846 dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
847 dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
848 if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle))
849 g_warning ("gdk_window_resize: AdjustWindowRectEx failed");
853 width = rect.right - rect.left;
854 height = rect.bottom - rect.top;
860 private->drawable.width = width;
861 private->drawable.height = height;
864 private->resize_count += 1;
867 g_print ("...MoveWindow(%#x,%dx%d@+%d+%d)\n",
868 GDK_DRAWABLE_XID (window), width, height, x, y));
869 if (!MoveWindow (GDK_DRAWABLE_XID (window),
872 g_warning ("gdk_window_resize: MoveWindow failed");
877 gdk_window_move_resize (GdkWindow *window,
883 GdkWindowPrivate *private;
885 g_return_if_fail (window != NULL);
887 if ((gint16) width < 1)
889 if ((gint16) height < 1)
892 if (!GDK_DRAWABLE_DESTROYED (window))
898 GDK_NOTE (MISC, g_print ("gdk_window_move_resize: %#x %dx%d@+%d+%d\n",
899 GDK_DRAWABLE_XID (window), width, height, x, y));
901 private = (GdkWindowPrivate*) window;
904 rect.right = x + width;
905 rect.bottom = y + height;
907 dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
908 dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
909 if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle))
910 g_warning ("gdk_window_move_resize: AdjustWindowRectEx failed");
912 if (private->drawable.window_type == GDK_WINDOW_CHILD)
916 private->drawable.width = width;
917 private->drawable.height = height;
919 GDK_NOTE (MISC, g_print ("...MoveWindow(%#x,%dx%d@+%d+%d)\n",
920 GDK_DRAWABLE_XID (window),
921 rect.right - rect.left, rect.bottom - rect.top,
922 rect.left, rect.top));
923 if (!MoveWindow (GDK_DRAWABLE_XID (window),
925 rect.right - rect.left, rect.bottom - rect.top,
927 g_warning ("gdk_window_move_resize: MoveWindow failed");
929 if (private->guffaw_gravity)
931 GList *tmp_list = private->children;
934 GdkWindowPrivate *child_private = tmp_list->data;
936 child_private->x -= x - private->x;
937 child_private->y -= y - private->y;
939 tmp_list = tmp_list->next;
947 gdk_window_reparent (GdkWindow *window,
948 GdkWindow *new_parent,
952 GdkWindowPrivate *window_private;
953 GdkWindowPrivate *parent_private;
954 GdkWindowPrivate *old_parent_private;
956 g_return_if_fail (window != NULL);
959 new_parent = gdk_parent_root;
961 window_private = (GdkWindowPrivate*) window;
962 old_parent_private = (GdkWindowPrivate *) window_private->parent;
963 parent_private = (GdkWindowPrivate*) new_parent;
965 if (!GDK_DRAWABLE_DESTROYED (window)
966 && !GDK_DRAWABLE_DESTROYED (new_parent))
968 GDK_NOTE (MISC, g_print ("gdk_window_reparent: %#x %#x\n",
969 GDK_DRAWABLE_XID (window),
970 GDK_DRAWABLE_XID (new_parent)));
971 if (!SetParent (GDK_DRAWABLE_XID (window),
972 GDK_DRAWABLE_XID (new_parent)))
973 g_warning ("gdk_window_reparent: SetParent failed");
975 if (!MoveWindow (GDK_DRAWABLE_XID (window),
977 window_private->drawable.width,
978 window_private->drawable.height,
980 g_warning ("gdk_window_reparent: MoveWindow failed");
983 window_private->parent = new_parent;
985 if (old_parent_private)
986 old_parent_private->children =
987 g_list_remove (old_parent_private->children, window);
989 if ((old_parent_private &&
990 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
991 (!old_parent_private && parent_private->guffaw_gravity))
992 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
994 parent_private->children = g_list_prepend (parent_private->children, window);
998 gdk_window_clear (GdkWindow *window)
1000 g_return_if_fail (window != NULL);
1001 g_return_if_fail (GDK_IS_WINDOW (window));
1003 if (!GDK_DRAWABLE_DESTROYED (window))
1004 gdk_window_clear_area (window, 0, 0, -1, -1);
1009 gdk_window_clear_area (GdkWindow *window,
1015 g_return_if_fail (window != NULL);
1016 g_return_if_fail (GDK_IS_WINDOW (window));
1018 if (!GDK_DRAWABLE_DESTROYED (window))
1023 width = G_MAXSHORT/2; /* Yeah, right */
1025 height = G_MAXSHORT/2;
1026 GDK_NOTE (MISC, g_print ("gdk_window_clear_area: %#x %dx%d@+%d+%d\n",
1027 GDK_DRAWABLE_XID (window), width, height, x, y));
1028 hdc = GetDC (GDK_DRAWABLE_XID (window));
1029 IntersectClipRect (hdc, x, y, x + width, y + height);
1030 SendMessage (GDK_DRAWABLE_XID (window), WM_ERASEBKGND, (WPARAM) hdc, 0);
1031 ReleaseDC (GDK_DRAWABLE_XID (window), hdc);
1036 gdk_window_clear_area_e (GdkWindow *window,
1042 g_return_if_fail (window != NULL);
1043 g_return_if_fail (GDK_IS_WINDOW (window));
1045 if (!GDK_DRAWABLE_DESTROYED (window))
1049 GDK_NOTE (MISC, g_print ("gdk_window_clear_area_e: %#x %dx%d@+%d+%d\n",
1050 GDK_DRAWABLE_XID (window), width, height, x, y));
1053 rect.right = x + width;
1055 rect.bottom = y + height;
1056 if (!InvalidateRect (GDK_DRAWABLE_XID (window), &rect, TRUE))
1057 g_warning ("gdk_window_clear_area_e: InvalidateRect failed");
1058 UpdateWindow (GDK_DRAWABLE_XID (window));
1063 gdk_window_raise (GdkWindow *window)
1065 g_return_if_fail (window != NULL);
1066 g_return_if_fail (GDK_IS_WINDOW (window));
1068 if (!GDK_DRAWABLE_DESTROYED (window))
1070 GDK_NOTE (MISC, g_print ("gdk_window_raise: %#x\n",
1071 GDK_DRAWABLE_XID (window)));
1073 if (!BringWindowToTop (GDK_DRAWABLE_XID (window)))
1074 g_warning ("gdk_window_raise: BringWindowToTop failed");
1079 gdk_window_lower (GdkWindow *window)
1081 g_return_if_fail (window != NULL);
1082 g_return_if_fail (GDK_IS_WINDOW (window));
1084 if (!GDK_DRAWABLE_DESTROYED (window))
1086 GDK_NOTE (MISC, g_print ("gdk_window_lower: %#x\n",
1087 GDK_DRAWABLE_XID (window)));
1089 if (!SetWindowPos (GDK_DRAWABLE_XID (window), HWND_BOTTOM, 0, 0, 0, 0,
1090 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE))
1091 g_warning ("gdk_window_lower: SetWindowPos failed");
1096 gdk_window_set_hints (GdkWindow *window,
1105 WINDOWPLACEMENT size_hints;
1111 g_return_if_fail (window != NULL);
1112 g_return_if_fail (GDK_IS_WINDOW (window));
1114 if (GDK_DRAWABLE_DESTROYED (window))
1117 GDK_NOTE (MISC, g_print ("gdk_window_set_hints: %#x %dx%d..%dx%d @+%d+%d\n",
1118 GDK_DRAWABLE_XID (window),
1119 min_width, min_height, max_width, max_height,
1122 GDK_WINDOW_WIN32DATA (window)->hint_flags = flags;
1123 size_hints.length = sizeof (size_hints);
1127 if (flags & GDK_HINT_POS)
1128 if (!GetWindowPlacement (GDK_DRAWABLE_XID (window), &size_hints))
1129 g_warning ("gdk_window_set_hints: GetWindowPlacement failed");
1132 GDK_NOTE (MISC, g_print ("...rcNormalPosition:"
1133 " (%d,%d)--(%d,%d)\n",
1134 size_hints.rcNormalPosition.left,
1135 size_hints.rcNormalPosition.top,
1136 size_hints.rcNormalPosition.right,
1137 size_hints.rcNormalPosition.bottom));
1138 /* What are the corresponding window coordinates for client
1139 * area coordinates x, y
1143 rect.right = rect.left + 200; /* dummy */
1144 rect.bottom = rect.top + 200;
1145 dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
1146 dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
1147 AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
1148 size_hints.flags = 0;
1149 size_hints.showCmd = SW_SHOWNA;
1151 /* Set the normal position hint to that location, with unchanged
1154 diff = size_hints.rcNormalPosition.left - rect.left;
1155 size_hints.rcNormalPosition.left = rect.left;
1156 size_hints.rcNormalPosition.right -= diff;
1157 diff = size_hints.rcNormalPosition.top - rect.top;
1158 size_hints.rcNormalPosition.top = rect.top;
1159 size_hints.rcNormalPosition.bottom -= diff;
1160 GDK_NOTE (MISC, g_print ("...setting: (%d,%d)--(%d,%d)\n",
1161 size_hints.rcNormalPosition.left,
1162 size_hints.rcNormalPosition.top,
1163 size_hints.rcNormalPosition.right,
1164 size_hints.rcNormalPosition.bottom));
1165 if (!SetWindowPlacement (GDK_DRAWABLE_XID (window), &size_hints))
1166 g_warning ("gdk_window_set_hints: SetWindowPlacement failed");
1167 GDK_WINDOW_WIN32DATA (window)->hint_x = rect.left;
1168 GDK_WINDOW_WIN32DATA (window)->hint_y = rect.top;
1171 if (flags & GDK_HINT_MIN_SIZE)
1175 rect.right = min_width;
1176 rect.bottom = min_height;
1177 dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
1178 dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
1179 AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
1180 GDK_WINDOW_WIN32DATA (window)->hint_min_width =
1181 rect.right - rect.left;
1182 GDK_WINDOW_WIN32DATA (window)->hint_min_height =
1183 rect.bottom - rect.top;
1185 /* Also chek if he current size of the window is in bounds. */
1186 GetClientRect (GDK_DRAWABLE_XID (window), &rect);
1187 if (rect.right < min_width && rect.bottom < min_height)
1188 gdk_window_resize (window, min_width, min_height);
1189 else if (rect.right < min_width)
1190 gdk_window_resize (window, min_width, rect.bottom);
1191 else if (rect.bottom < min_height)
1192 gdk_window_resize (window, rect.right, min_height);
1195 if (flags & GDK_HINT_MAX_SIZE)
1199 rect.right = max_width;
1200 rect.bottom = max_height;
1201 dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
1202 dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
1203 AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
1204 GDK_WINDOW_WIN32DATA (window)->hint_max_width =
1205 rect.right - rect.left;
1206 GDK_WINDOW_WIN32DATA (window)->hint_max_height =
1207 rect.bottom - rect.top;
1208 /* Again, check if the window is too large currently. */
1209 GetClientRect (GDK_DRAWABLE_XID (window), &rect);
1210 if (rect.right > max_width && rect.bottom > max_height)
1211 gdk_window_resize (window, max_width, max_height);
1212 else if (rect.right > max_width)
1213 gdk_window_resize (window, max_width, rect.bottom);
1214 else if (rect.bottom > max_height)
1215 gdk_window_resize (window, rect.right, max_height);
1221 gdk_window_set_geometry_hints (GdkWindow *window,
1222 GdkGeometry *geometry,
1223 GdkWindowHints geom_mask)
1225 WINDOWPLACEMENT size_hints;
1231 g_return_if_fail (window != NULL);
1232 g_return_if_fail (GDK_IS_WINDOW (window));
1234 if (GDK_DRAWABLE_DESTROYED (window))
1237 size_hints.length = sizeof (size_hints);
1239 GDK_WINDOW_WIN32DATA (window)->hint_flags = geom_mask;
1241 if (geom_mask & GDK_HINT_POS)
1244 if (geom_mask & GDK_HINT_MIN_SIZE)
1248 rect.right = geometry->min_width;
1249 rect.bottom = geometry->min_height;
1250 dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
1251 dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
1252 AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
1253 GDK_WINDOW_WIN32DATA (window)->hint_min_width = rect.right - rect.left;
1254 GDK_WINDOW_WIN32DATA (window)->hint_min_height = rect.bottom - rect.top;
1256 /* Also check if he current size of the window is in bounds */
1257 GetClientRect (GDK_DRAWABLE_XID (window), &rect);
1258 if (rect.right < geometry->min_width
1259 && rect.bottom < geometry->min_height)
1260 gdk_window_resize (window, geometry->min_width, geometry->min_height);
1261 else if (rect.right < geometry->min_width)
1262 gdk_window_resize (window, geometry->min_width, rect.bottom);
1263 else if (rect.bottom < geometry->min_height)
1264 gdk_window_resize (window, rect.right, geometry->min_height);
1267 if (geom_mask & GDK_HINT_MAX_SIZE)
1271 rect.right = geometry->max_width;
1272 rect.bottom = geometry->max_height;
1273 dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
1274 dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
1275 AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
1276 GDK_WINDOW_WIN32DATA (window)->hint_max_width = rect.right - rect.left;
1277 GDK_WINDOW_WIN32DATA (window)->hint_max_height = rect.bottom - rect.top;
1279 /* Again, check if the window is too large currently. */
1280 GetClientRect (GDK_DRAWABLE_XID (window), &rect);
1281 if (rect.right > geometry->max_width
1282 && rect.bottom > geometry->max_height)
1283 gdk_window_resize (window, geometry->max_width, geometry->max_height);
1284 else if (rect.right > geometry->max_width)
1285 gdk_window_resize (window, geometry->max_width, rect.bottom);
1286 else if (rect.bottom > geometry->max_height)
1287 gdk_window_resize (window, rect.right, geometry->max_height);
1290 /* I don't know what to do when called with zero base_width and height. */
1291 if (geom_mask & GDK_HINT_BASE_SIZE
1292 && geometry->base_width > 0
1293 && geometry->base_height > 0)
1294 if (!GetWindowPlacement (GDK_DRAWABLE_XID (window), &size_hints))
1295 g_warning ("gdk_window_set_hints: GetWindowPlacement failed");
1298 GDK_NOTE (MISC, g_print ("gdk_window_set_geometry_hints:"
1299 " rcNormalPosition: (%d,%d)--(%d,%d)\n",
1300 size_hints.rcNormalPosition.left,
1301 size_hints.rcNormalPosition.top,
1302 size_hints.rcNormalPosition.right,
1303 size_hints.rcNormalPosition.bottom));
1304 size_hints.rcNormalPosition.right =
1305 size_hints.rcNormalPosition.left + geometry->base_width;
1306 size_hints.rcNormalPosition.bottom =
1307 size_hints.rcNormalPosition.top + geometry->base_height;
1308 GDK_NOTE (MISC, g_print ("...setting: rcNormal: (%d,%d)--(%d,%d)\n",
1309 size_hints.rcNormalPosition.left,
1310 size_hints.rcNormalPosition.top,
1311 size_hints.rcNormalPosition.right,
1312 size_hints.rcNormalPosition.bottom));
1313 if (!SetWindowPlacement (GDK_DRAWABLE_XID (window), &size_hints))
1314 g_warning ("gdk_window_set_hints: SetWindowPlacement failed");
1317 if (geom_mask & GDK_HINT_RESIZE_INC)
1322 if (geom_mask & GDK_HINT_ASPECT)
1329 gdk_window_set_title (GdkWindow *window,
1337 g_return_if_fail (window != NULL);
1338 g_return_if_fail (GDK_IS_WINDOW (window));
1340 GDK_NOTE (MISC, g_print ("gdk_window_set_title: %#x %s\n",
1341 GDK_DRAWABLE_XID (window), title));
1342 if (!GDK_DRAWABLE_DESTROYED (window))
1344 /* As the title most is in UTF-8 we must translate it
1345 * to the system codepage.
1347 titlelen = strlen (title);
1348 wcstr = g_new (wchar_t, titlelen + 1);
1349 mbstr = g_new (char, 3*titlelen + 1);
1350 wlen = gdk_nmbstowchar_ts (wcstr, title, titlelen, titlelen);
1352 WideCharToMultiByte (GetACP (), 0, wcstr, -1,
1353 mbstr, 3*titlelen, NULL, NULL);
1355 if (!SetWindowText (GDK_DRAWABLE_XID (window), mbstr))
1356 g_warning ("gdk_window_set_title: SetWindowText failed");
1364 gdk_window_set_role (GdkWindow *window,
1367 g_return_if_fail (window != NULL);
1368 g_return_if_fail (GDK_IS_WINDOW (window));
1370 GDK_NOTE (MISC, g_print ("gdk_window_set_role: %#x %s\n",
1371 GDK_DRAWABLE_XID (window), (role ? role : "NULL")));
1376 gdk_window_set_transient_for (GdkWindow *window,
1379 g_return_if_fail (window != NULL);
1380 g_return_if_fail (GDK_IS_WINDOW (window));
1382 GDK_NOTE (MISC, g_print ("gdk_window_set_transient_for: %#x %#x\n",
1383 GDK_DRAWABLE_XID (window),
1384 GDK_DRAWABLE_XID (parent)));
1389 gdk_window_set_background (GdkWindow *window,
1392 g_return_if_fail (window != NULL);
1393 g_return_if_fail (GDK_IS_WINDOW (window));
1395 if (!GDK_DRAWABLE_DESTROYED (window))
1397 GDK_NOTE (MISC, g_print ("gdk_window_set_background: %#x %s\n",
1398 GDK_DRAWABLE_XID (window),
1399 gdk_color_to_string (color)));
1401 if (GDK_WINDOW_WIN32DATA (window)->bg_type == GDK_WIN32_BG_PIXMAP)
1403 if (GDK_WINDOW_WIN32DATA (window)->bg_pixmap != NULL)
1405 gdk_drawable_unref (GDK_WINDOW_WIN32DATA (window)->bg_pixmap);
1406 GDK_WINDOW_WIN32DATA (window)->bg_pixmap = NULL;
1408 GDK_WINDOW_WIN32DATA (window)->bg_type = GDK_WIN32_BG_NORMAL;
1410 GDK_WINDOW_WIN32DATA (window)->bg_type = GDK_WIN32_BG_PIXEL;
1411 GDK_WINDOW_WIN32DATA (window)->bg_pixel = *color;
1416 gdk_window_set_back_pixmap (GdkWindow *window,
1418 gint parent_relative)
1420 g_return_if_fail (window != NULL);
1421 g_return_if_fail (GDK_IS_WINDOW (window));
1423 if (!GDK_DRAWABLE_DESTROYED (window))
1425 if (GDK_WINDOW_WIN32DATA (window)->bg_type == GDK_WIN32_BG_PIXMAP)
1427 if (GDK_WINDOW_WIN32DATA (window)->bg_pixmap != NULL)
1429 gdk_drawable_unref (GDK_WINDOW_WIN32DATA (window)->bg_pixmap);
1430 GDK_WINDOW_WIN32DATA (window)->bg_pixmap = NULL;
1432 GDK_WINDOW_WIN32DATA (window)->bg_type = GDK_WIN32_BG_NORMAL;
1434 if (parent_relative)
1436 GDK_WINDOW_WIN32DATA (window)->bg_type =
1437 GDK_WIN32_BG_PARENT_RELATIVE;
1445 /* We must cache the pixmap in the GdkWindowWin32Data and
1446 * paint it each time we get WM_ERASEBKGND
1448 GDK_WINDOW_WIN32DATA (window)->bg_type = GDK_WIN32_BG_PIXMAP;
1449 GDK_WINDOW_WIN32DATA (window)->bg_pixmap = pixmap;
1450 gdk_drawable_ref (pixmap);
1456 gdk_window_set_cursor (GdkWindow *window,
1459 GdkCursorPrivate *cursor_private;
1462 g_return_if_fail (window != NULL);
1463 g_return_if_fail (GDK_IS_WINDOW (window));
1465 cursor_private = (GdkCursorPrivate*) cursor;
1467 if (!GDK_DRAWABLE_DESTROYED (window))
1470 xcursor = LoadCursor (NULL, IDC_ARROW);
1472 xcursor = cursor_private->xcursor;
1474 GDK_NOTE (MISC, g_print ("gdk_window_set_cursor: %#x %#x\n",
1475 GDK_DRAWABLE_XID (window), xcursor));
1476 GDK_WINDOW_WIN32DATA (window)->xcursor = xcursor;
1481 gdk_window_get_geometry (GdkWindow *window,
1488 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
1491 window = gdk_parent_root;
1493 if (!GDK_DRAWABLE_DESTROYED (window))
1497 if (!GetClientRect (GDK_DRAWABLE_XID (window), &rect))
1498 g_warning ("gdk_window_get_geometry: GetClientRect failed");
1505 *width = rect.right - rect.left;
1507 *height = rect.bottom - rect.top;
1509 *depth = gdk_drawable_get_visual (window)->depth;
1514 gdk_window_get_origin (GdkWindow *window,
1522 g_return_val_if_fail (window != NULL, 0);
1524 if (!GDK_DRAWABLE_DESTROYED (window))
1530 ClientToScreen (GDK_DRAWABLE_XID (window), &pt);
1543 GDK_NOTE (MISC, g_print ("gdk_window_get_origin: %#x: +%d+%d\n",
1544 GDK_DRAWABLE_XID (window), tx, ty));
1549 gdk_window_get_deskrelative_origin (GdkWindow *window,
1553 return gdk_window_get_origin (window, x, y);
1557 gdk_window_get_root_origin (GdkWindow *window,
1561 GdkWindowPrivate *rover;
1564 g_return_if_fail (window != NULL);
1565 g_return_if_fail (GDK_IS_WINDOW (window));
1567 rover = (GdkWindowPrivate*) window;
1572 if (GDK_DRAWABLE_DESTROYED (window))
1575 while (rover->parent && ((GdkWindowPrivate*) rover->parent)->parent)
1576 rover = (GdkWindowPrivate *) rover->parent;
1577 if (rover->drawable.destroyed)
1582 ClientToScreen (GDK_DRAWABLE_XID (rover), &pt);
1588 GDK_NOTE (MISC, g_print ("gdk_window_get_root_origin: %#x: (%#x) +%d+%d\n",
1589 GDK_DRAWABLE_XID (window),
1590 GDK_DRAWABLE_XID (rover), pt.x, pt.y));
1594 gdk_window_get_pointer (GdkWindow *window,
1597 GdkModifierType *mask)
1599 GdkWindow *return_val;
1600 POINT pointc, point;
1603 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
1606 window = gdk_parent_root;
1609 GetCursorPos (&pointc);
1611 ScreenToClient (GDK_DRAWABLE_XID (window), &point);
1618 hwnd = WindowFromPoint (point);
1620 ScreenToClient (hwnd, &point);
1623 hwndc = ChildWindowFromPoint (hwnd, point);
1624 ClientToScreen (hwnd, &point);
1625 ScreenToClient (hwndc, &point);
1626 } while (hwndc != hwnd && (hwnd = hwndc, 1)); /* Ouch! */
1628 return_val = gdk_window_lookup (hwnd);
1634 GetKeyboardState (kbd);
1636 if (kbd[VK_SHIFT] & 0x80)
1637 *mask |= GDK_SHIFT_MASK;
1638 if (kbd[VK_CAPITAL] & 0x80)
1639 *mask |= GDK_LOCK_MASK;
1640 if (kbd[VK_CONTROL] & 0x80)
1641 *mask |= GDK_CONTROL_MASK;
1642 if (kbd[VK_MENU] & 0x80)
1643 *mask |= GDK_MOD1_MASK;
1644 if (kbd[VK_LBUTTON] & 0x80)
1645 *mask |= GDK_BUTTON1_MASK;
1646 if (kbd[VK_MBUTTON] & 0x80)
1647 *mask |= GDK_BUTTON2_MASK;
1648 if (kbd[VK_RBUTTON] & 0x80)
1649 *mask |= GDK_BUTTON3_MASK;
1656 gdk_window_at_pointer (gint *win_x,
1660 POINT point, pointc;
1664 GetCursorPos (&pointc);
1666 hwnd = WindowFromPoint (point);
1670 window = gdk_parent_root;
1678 ScreenToClient (hwnd, &point);
1681 hwndc = ChildWindowFromPoint (hwnd, point);
1682 ClientToScreen (hwnd, &point);
1683 ScreenToClient (hwndc, &point);
1684 } while (hwndc != hwnd && (hwnd = hwndc, 1));
1686 window = gdk_window_lookup (hwnd);
1688 if (window && (win_x || win_y))
1690 GetClientRect (hwnd, &rect);
1692 *win_x = point.x - rect.left;
1694 *win_y = point.y - rect.top;
1697 GDK_NOTE (MISC, g_print ("gdk_window_at_pointer: +%d+%d %#x%s\n",
1698 point.x, point.y, hwnd,
1699 (window == NULL ? " NULL" : "")));
1705 gdk_window_get_children (GdkWindow *window)
1707 GdkWindowPrivate *private;
1710 g_return_val_if_fail (window != NULL, NULL);
1711 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
1713 if (GDK_DRAWABLE_DESTROYED (window))
1717 g_warning ("gdk_window_get_children not implemented");
1724 gdk_window_get_events (GdkWindow *window)
1726 g_return_val_if_fail (window != NULL, 0);
1727 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
1729 if (GDK_DRAWABLE_DESTROYED (window))
1732 return GDK_WINDOW_WIN32DATA (window)->event_mask;
1736 gdk_window_set_events (GdkWindow *window,
1737 GdkEventMask event_mask)
1739 g_return_if_fail (window != NULL);
1740 g_return_if_fail (GDK_IS_WINDOW (window));
1742 if (GDK_DRAWABLE_DESTROYED (window))
1745 GDK_WINDOW_WIN32DATA (window)->event_mask = event_mask;
1749 gdk_window_add_colormap_windows (GdkWindow *window)
1751 g_warning ("gdk_window_add_colormap_windows not implemented");
1755 gdk_window_shape_combine_mask (GdkWindow *window,
1759 g_return_if_fail (window != NULL);
1760 g_return_if_fail (GDK_IS_WINDOW (window));
1764 GDK_NOTE (MISC, g_print ("gdk_window_shape_combine_mask: %#x none\n",
1765 GDK_DRAWABLE_XID (window)));
1766 SetWindowRgn (GDK_DRAWABLE_XID (window), NULL, TRUE);
1775 /* Convert mask bitmap to region */
1776 hrgn = BitmapToRegion (GDK_DRAWABLE_XID (mask));
1778 GDK_NOTE (MISC, g_print ("gdk_window_shape_combine_mask: %#x %#x\n",
1779 GDK_DRAWABLE_XID (window),
1780 GDK_DRAWABLE_XID (mask)));
1782 /* SetWindowRgn wants window (not client) coordinates */
1783 dwStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
1784 dwExStyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
1785 GetClientRect (GDK_DRAWABLE_XID (window), &rect);
1786 AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
1787 OffsetRgn (hrgn, -rect.left, -rect.top);
1789 OffsetRgn (hrgn, x, y);
1791 /* If this is a top-level window, add the title bar to the region */
1792 if (GDK_DRAWABLE_TYPE (window) == GDK_WINDOW_TOPLEVEL)
1794 CombineRgn (hrgn, hrgn,
1795 CreateRectRgn (0, 0, rect.right - rect.left, -rect.top),
1799 SetWindowRgn (GDK_DRAWABLE_XID (window), hrgn, TRUE);
1804 gdk_window_set_override_redirect (GdkWindow *window,
1805 gboolean override_redirect)
1807 g_return_if_fail (window != NULL);
1808 g_return_if_fail (GDK_IS_WINDOW (window));
1810 g_warning ("gdk_window_set_override_redirect not implemented");
1814 gdk_window_set_icon (GdkWindow *window,
1815 GdkWindow *icon_window,
1819 g_return_if_fail (window != NULL);
1820 g_return_if_fail (GDK_IS_WINDOW (window));
1822 if (GDK_DRAWABLE_DESTROYED (window))
1825 g_warning ("gdk_window_set_icon not implemented");
1829 gdk_window_set_icon_name (GdkWindow *window,
1832 g_return_if_fail (window != NULL);
1833 g_return_if_fail (GDK_IS_WINDOW (window));
1835 if (GDK_DRAWABLE_DESTROYED (window))
1838 if (!SetWindowText (GDK_DRAWABLE_XID (window), name))
1839 g_warning ("gdk_window_set_icon_name: SetWindowText failed");
1843 gdk_window_set_group (GdkWindow *window,
1846 g_return_if_fail (window != NULL);
1847 g_return_if_fail (GDK_IS_WINDOW (window));
1848 g_return_if_fail (leader != NULL);
1849 g_return_if_fail (GDK_IS_WINDOW (leader));
1851 if (GDK_DRAWABLE_DESTROYED (window) || GDK_DRAWABLE_DESTROYED (leader))
1854 g_warning ("gdk_window_set_group not implemented");
1858 gdk_window_set_decorations (GdkWindow *window,
1859 GdkWMDecoration decorations)
1861 LONG style, exstyle;
1863 g_return_if_fail (window != NULL);
1864 g_return_if_fail (GDK_IS_WINDOW (window));
1866 style = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
1867 exstyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
1869 style &= (WS_OVERLAPPED|WS_POPUP|WS_CHILD|WS_MINIMIZE|WS_VISIBLE|WS_DISABLED
1870 |WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_MAXIMIZE);
1872 exstyle &= (WS_EX_TOPMOST|WS_EX_TRANSPARENT);
1874 if (decorations & GDK_DECOR_ALL)
1875 style |= (WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX);
1876 if (decorations & GDK_DECOR_BORDER)
1877 style |= (WS_BORDER);
1878 if (decorations & GDK_DECOR_RESIZEH)
1879 style |= (WS_THICKFRAME);
1880 if (decorations & GDK_DECOR_TITLE)
1881 style |= (WS_CAPTION);
1882 if (decorations & GDK_DECOR_MENU)
1883 style |= (WS_SYSMENU);
1884 if (decorations & GDK_DECOR_MINIMIZE)
1885 style |= (WS_MINIMIZEBOX);
1886 if (decorations & GDK_DECOR_MAXIMIZE)
1887 style |= (WS_MAXIMIZEBOX);
1889 SetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE, style);
1893 gdk_window_set_functions (GdkWindow *window,
1894 GdkWMFunction functions)
1896 LONG style, exstyle;
1898 g_return_if_fail (window != NULL);
1899 g_return_if_fail (GDK_IS_WINDOW (window));
1901 style = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE);
1902 exstyle = GetWindowLong (GDK_DRAWABLE_XID (window), GWL_EXSTYLE);
1904 style &= (WS_OVERLAPPED|WS_POPUP|WS_CHILD|WS_MINIMIZE|WS_VISIBLE|WS_DISABLED
1905 |WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_MAXIMIZE|WS_CAPTION|WS_BORDER
1908 exstyle &= (WS_EX_TOPMOST|WS_EX_TRANSPARENT);
1910 if (functions & GDK_FUNC_ALL)
1911 style |= (WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX);
1912 if (functions & GDK_FUNC_RESIZE)
1913 style |= (WS_THICKFRAME);
1914 if (functions & GDK_FUNC_MOVE)
1915 style |= (WS_THICKFRAME);
1916 if (functions & GDK_FUNC_MINIMIZE)
1917 style |= (WS_MINIMIZEBOX);
1918 if (functions & GDK_FUNC_MAXIMIZE)
1919 style |= (WS_MAXIMIZEBOX);
1921 SetWindowLong (GDK_DRAWABLE_XID (window), GWL_STYLE, style);
1925 * propagate the shapes from all child windows of a GDK window to the parent
1926 * window. Shamelessly ripped from Enlightenment's code
1932 QueryTree (HWND hwnd,
1942 child = GetWindow (hwnd, GW_CHILD);
1944 child = GetWindow (child, GW_HWNDNEXT);
1947 } while (child != NULL);
1951 *children = g_new (HWND, n);
1952 for (i = 0; i < n; i++)
1955 child = GetWindow (hwnd, GW_CHILD);
1957 child = GetWindow (child, GW_HWNDNEXT);
1958 *children[i] = child;
1964 gdk_propagate_shapes (HANDLE win,
1968 HRGN region, childRegion;
1973 SetRectEmpty (&emptyRect);
1974 region = CreateRectRgnIndirect (&emptyRect);
1976 GetWindowRgn (win, region);
1978 QueryTree (win, &list, &num);
1981 WINDOWPLACEMENT placement;
1983 placement.length = sizeof (WINDOWPLACEMENT);
1984 /* go through all child windows and combine regions */
1985 for (i = 0; i < num; i++)
1987 GetWindowPlacement (list[i], &placement);
1988 if (placement.showCmd = SW_SHOWNORMAL)
1990 childRegion = CreateRectRgnIndirect (&emptyRect);
1991 GetWindowRgn (list[i], childRegion);
1992 CombineRgn (region, region, childRegion, RGN_OR);
1993 DeleteObject (childRegion);
1996 SetWindowRgn (win, region, TRUE);
1999 DeleteObject (region);
2003 gdk_window_set_child_shapes (GdkWindow *window)
2005 g_return_if_fail (window != NULL);
2006 g_return_if_fail (GDK_IS_WINDOW (window));
2008 if (GDK_DRAWABLE_DESTROYED (window))
2011 gdk_propagate_shapes (GDK_DRAWABLE_XID (window), FALSE);
2015 gdk_window_merge_child_shapes (GdkWindow *window)
2017 g_return_if_fail (window != NULL);
2018 g_return_if_fail (GDK_IS_WINDOW (window));
2020 if (GDK_DRAWABLE_DESTROYED (window))
2023 gdk_propagate_shapes (GDK_DRAWABLE_XID (window), TRUE);
2026 /* Support for windows that can be guffaw-scrolled
2027 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
2031 gdk_window_gravity_works (void)
2033 enum { UNKNOWN, NO, YES };
2034 static gint gravity_works = UNKNOWN;
2036 if (gravity_works == UNKNOWN)
2043 attr.window_type = GDK_WINDOW_TEMP;
2044 attr.wclass = GDK_INPUT_OUTPUT;
2049 attr.event_mask = 0;
2051 parent = gdk_window_new (NULL, &attr, GDK_WA_X | GDK_WA_Y);
2053 attr.window_type = GDK_WINDOW_CHILD;
2054 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
2056 gdk_window_set_static_win_gravity (child, TRUE);
2058 gdk_window_resize (parent, 100, 110);
2059 gdk_window_move (parent, 0, -10);
2060 gdk_window_move_resize (parent, 0, 0, 100, 100);
2062 gdk_window_resize (parent, 100, 110);
2063 gdk_window_move (parent, 0, -10);
2064 gdk_window_move_resize (parent, 0, 0, 100, 100);
2066 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
2068 gdk_window_destroy (parent);
2069 gdk_window_destroy (child);
2071 gravity_works = ((y == -20) ? YES : NO);
2074 return (gravity_works == YES);
2078 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
2080 g_return_if_fail (window != NULL);
2082 GDK_NOTE (MISC, g_print ("gdk_window_set_static_bit_gravity: Not implemented\n"));
2086 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
2088 g_return_if_fail (window != NULL);
2091 g_print ("gdk_window_set_static_win_gravity: Not implemented\n"));
2094 /*************************************************************
2095 * gdk_window_set_static_gravities:
2096 * Set the bit gravity of the given window to static,
2097 * and flag it so all children get static subwindow
2100 * window: window for which to set static gravity
2101 * use_static: Whether to turn static gravity on or off.
2103 * Does the XServer support static gravity?
2104 *************************************************************/
2107 gdk_window_set_static_gravities (GdkWindow *window,
2108 gboolean use_static)
2110 GdkWindowPrivate *private = (GdkWindowPrivate *)window;
2113 g_return_val_if_fail (window != NULL, FALSE);
2114 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2116 if (!use_static == !private->guffaw_gravity)
2119 if (use_static && !gdk_window_gravity_works ())
2122 private->guffaw_gravity = use_static;
2124 if (!GDK_DRAWABLE_DESTROYED (window))
2126 gdk_window_set_static_bit_gravity (window, use_static);
2128 tmp_list = private->children;
2131 gdk_window_set_static_win_gravity (window, use_static);
2133 tmp_list = tmp_list->next;