1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright (C) 1998-2002 Tor Lillqvist
4 * Copyright (C) 2001,2009 Hans Breuer
5 * Copyright (C) 2007-2009 Cody Russell
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.
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.
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.
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/.
30 /* Cannot use TrackMouseEvent, as the stupid WM_MOUSELEAVE message
31 * doesn't tell us where the mouse has gone. Thus we cannot use it to
32 * generate a correct GdkNotifyType. Pity, as using TrackMouseEvent
33 * otherwise would make it possible to reliably generate
34 * GDK_LEAVE_NOTIFY events, which would help get rid of those pesky
35 * tooltips sometimes popping up in the wrong place.
37 * Update: a combination of TrackMouseEvent, GetCursorPos and
38 * GetWindowPos can and is actually used to get rid of those
39 * pesky tooltips. It should be possible to use this for the
40 * whole ENTER/LEAVE NOTIFY handling but some platforms may
41 * not have TrackMouseEvent at all (?) --hb
46 #include <glib/gprintf.h>
49 #include "gdkdisplayprivate.h"
50 #include "gdkprivate-win32.h"
52 #include "gdkkeysyms.h"
53 #include "gdkdevicemanager-win32.h"
54 #include "gdkdeviceprivate.h"
55 #include "gdkdevice-wintab.h"
56 #include "gdkwin32dnd.h"
57 #include "gdkdndprivate.h"
81 #define MK_XBUTTON1 32
82 #define MK_XBUTTON2 64
85 /* Undefined flags: */
86 #define SWP_NOCLIENTSIZE 0x0800
87 #define SWP_NOCLIENTMOVE 0x1000
88 #define SWP_STATECHANGED 0x8000
90 * Private function declarations
93 static gboolean gdk_event_translate (MSG *msg,
95 static void handle_wm_paint (MSG *msg,
97 gboolean return_exposes,
100 static gboolean gdk_event_prepare (GSource *source,
102 static gboolean gdk_event_check (GSource *source);
103 static gboolean gdk_event_dispatch (GSource *source,
104 GSourceFunc callback,
107 static gboolean is_modally_blocked (GdkWindow *window);
109 /* Private variable declarations
112 static GList *client_filters; /* Filters for client messages */
113 extern gint _gdk_input_ignore_core;
115 static HCURSOR p_grab_cursor;
117 static GSourceFuncs event_funcs = {
124 GPollFD event_poll_fd;
126 static GdkWindow *mouse_window = NULL;
127 static gint current_x, current_y;
128 static gint current_root_x, current_root_y;
129 static UINT client_message;
131 static UINT got_gdk_events_message;
132 static HWND modal_win32_dialog = NULL;
135 static HKL latin_locale = NULL;
138 static gboolean in_ime_composition = FALSE;
139 static UINT modal_timer;
140 static UINT sync_timer = 0;
142 static int debug_indent = 0;
145 assign_object (gpointer lhsp,
148 if (*(gpointer *)lhsp != rhs)
150 if (*(gpointer *)lhsp != NULL)
151 g_object_unref (*(gpointer *)lhsp);
152 *(gpointer *)lhsp = rhs;
159 track_mouse_event (DWORD dwFlags,
164 tme.cbSize = sizeof(TRACKMOUSEEVENT);
165 tme.dwFlags = dwFlags;
166 tme.hwndTrack = hwnd;
167 tme.dwHoverTime = HOVER_DEFAULT; /* not used */
169 if (!TrackMouseEvent (&tme))
170 WIN32_API_FAILED ("TrackMouseEvent");
171 else if (dwFlags == TME_LEAVE)
172 GDK_NOTE (EVENTS, g_print(" (TrackMouseEvent %p)", hwnd));
173 else if (dwFlags == TME_CANCEL)
174 GDK_NOTE (EVENTS, g_print(" (cancel TrackMouseEvent %p)", hwnd));
178 _gdk_win32_get_next_tick (gulong suggested_tick)
180 static gulong cur_tick = 0;
182 if (suggested_tick == 0)
183 suggested_tick = GetTickCount ();
184 if (suggested_tick <= cur_tick)
187 return cur_tick = suggested_tick;
191 generate_focus_event (GdkDeviceManager *device_manager,
198 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
200 event = gdk_event_new (GDK_FOCUS_CHANGE);
201 event->focus_change.window = window;
202 event->focus_change.in = in;
203 gdk_event_set_device (event, device);
205 _gdk_win32_append_event (event);
209 generate_grab_broken_event (GdkDeviceManager *device_manager,
212 GdkWindow *grab_window)
214 GdkEvent *event = gdk_event_new (GDK_GRAB_BROKEN);
218 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
220 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer;
222 event->grab_broken.window = window;
223 event->grab_broken.send_event = 0;
224 event->grab_broken.keyboard = keyboard;
225 event->grab_broken.implicit = FALSE;
226 event->grab_broken.grab_window = grab_window;
227 gdk_event_set_device (event, device);
229 _gdk_win32_append_event (event);
233 inner_window_procedure (HWND hwnd,
243 msg.message = message;
246 msg.time = _gdk_win32_get_next_tick (0);
247 pos = GetMessagePos ();
248 msg.pt.x = GET_X_LPARAM (pos);
249 msg.pt.y = GET_Y_LPARAM (pos);
251 if (gdk_event_translate (&msg, &ret_val))
253 /* If gdk_event_translate() returns TRUE, we return ret_val from
254 * the window procedure.
256 if (modal_win32_dialog)
257 PostMessageW (modal_win32_dialog, got_gdk_events_message,
263 /* Otherwise call DefWindowProcW(). */
264 GDK_NOTE (EVENTS, g_print (" DefWindowProcW"));
265 return DefWindowProcW (hwnd, message, wparam, lparam);
270 _gdk_win32_window_procedure (HWND hwnd,
277 GDK_NOTE (EVENTS, g_print ("%s%*s%s %p",
278 (debug_indent > 0 ? "\n" : ""),
280 _gdk_win32_message_to_string (message), hwnd));
282 retval = inner_window_procedure (hwnd, message, wparam, lparam);
285 GDK_NOTE (EVENTS, g_print (" => %I64d%s", (gint64) retval, (debug_indent == 0 ? "\n" : "")));
291 _gdk_events_init (void)
298 /* List of languages that use a latin keyboard. Somewhat sorted in
299 * "order of least surprise", in case we have to load one of them if
300 * the user only has arabic loaded, for instance.
302 static int latin_languages[] = {
308 /* Rest in numeric order */
337 client_message = RegisterWindowMessage ("GDK_WIN32_CLIENT_MESSAGE");
338 got_gdk_events_message = RegisterWindowMessage ("GDK_WIN32_GOT_EVENTS");
341 /* Check if we have some input locale identifier loaded that uses a
342 * latin keyboard, to be able to get the virtual-key code for the
343 * latin characters corresponding to ASCII control characters.
345 if ((n = GetKeyboardLayoutList (0, NULL)) == 0)
346 WIN32_API_FAILED ("GetKeyboardLayoutList");
349 HKL *hkl_list = g_new (HKL, n);
350 if (GetKeyboardLayoutList (n, hkl_list) == 0)
351 WIN32_API_FAILED ("GetKeyboardLayoutList");
354 for (i = 0; latin_locale == NULL && i < n; i++)
355 for (j = 0; j < G_N_ELEMENTS (latin_languages); j++)
356 if (PRIMARYLANGID (LOWORD (hkl_list[i])) == latin_languages[j])
358 latin_locale = hkl_list [i];
365 if (latin_locale == NULL)
367 /* Try to load a keyboard layout with latin characters then.
370 while (latin_locale == NULL && i < G_N_ELEMENTS (latin_languages))
373 g_sprintf (id, "%08x", MAKELANGID (latin_languages[i++], SUBLANG_DEFAULT));
374 latin_locale = LoadKeyboardLayout (id, KLF_NOTELLSHELL|KLF_SUBSTITUTE_OK);
378 GDK_NOTE (EVENTS, g_print ("latin_locale = %08x\n", (guint) latin_locale));
381 source = g_source_new (&event_funcs, sizeof (GSource));
382 g_source_set_name (source, "GDK Win32 event source");
383 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
386 event_poll_fd.fd = open ("/dev/windows", O_RDONLY);
387 if (event_poll_fd.fd == -1)
388 g_error ("can't open \"/dev/windows\": %s", g_strerror (errno));
390 event_poll_fd.fd = G_WIN32_MSG_HANDLE;
392 event_poll_fd.events = G_IO_IN;
394 g_source_add_poll (source, &event_poll_fd);
395 g_source_set_can_recurse (source, TRUE);
396 g_source_attach (source, NULL);
400 _gdk_win32_display_has_pending (GdkDisplay *display)
402 return (_gdk_event_queue_find_first (display) ||
403 (modal_win32_dialog == NULL &&
404 GetQueueStatus (QS_ALLINPUT) != 0));
407 #if 0 /* Unused, but might be useful to re-introduce in some debugging output? */
410 event_mask_string (GdkEventMask mask)
412 static char bfr[500];
417 if (mask & GDK_##x##_MASK) \
418 p += g_sprintf (p, "%s" #x, (p > bfr ? " " : ""))
420 BIT (POINTER_MOTION);
421 BIT (POINTER_MOTION_HINT);
423 BIT (BUTTON1_MOTION);
424 BIT (BUTTON2_MOTION);
425 BIT (BUTTON3_MOTION);
427 BIT (BUTTON_RELEASE);
434 BIT (PROPERTY_CHANGE);
435 BIT (VISIBILITY_NOTIFY);
448 _gdk_windowing_device_grab (GdkDevice *device,
450 GdkWindow *native_window,
451 gboolean owner_events,
452 GdkEventMask event_mask,
453 GdkWindow *confine_to,
458 GdkWin32Cursor *cursor_private;
460 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (native_window->impl);
462 g_return_val_if_fail (window != NULL, 0);
463 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
464 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
466 cursor_private = (GdkWin32Cursor*) cursor;
470 else if ((hcursor = CopyCursor (cursor_private->hcursor)) == NULL)
471 WIN32_API_FAILED ("CopyCursor");
473 return_val = GDK_DEVICE_GET_CLASS (device)->grab (device,
481 /* TODO_CSW: grab brokens, confine window, input_grab */
482 if (p_grab_cursor != NULL)
484 if (GetCursor () == p_grab_cursor)
486 DestroyCursor (p_grab_cursor);
489 p_grab_cursor = hcursor;
491 if (p_grab_cursor != NULL)
492 SetCursor (p_grab_cursor);
493 else if (impl->hcursor != NULL)
494 SetCursor (impl->hcursor);
496 SetCursor (LoadCursor (NULL, IDC_ARROW));
502 find_window_for_mouse_event (GdkWindow* reported_window,
506 GdkDeviceManagerWin32 *device_manager;
507 GdkWindow *event_window;
510 GdkDeviceGrabInfo *grab;
512 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (_gdk_display));
514 grab = _gdk_display_get_last_device_grab (_gdk_display, device_manager->core_pointer);
516 return reported_window;
520 if (!grab->owner_events)
521 event_window = grab->native_window;
525 hwnd = WindowFromPoint (pt);
528 POINT client_pt = pt;
530 ScreenToClient (hwnd, &client_pt);
531 GetClientRect (hwnd, &rect);
532 if (PtInRect (&rect, client_pt))
533 event_window = gdk_win32_handle_table_lookup (hwnd);
535 if (event_window == NULL)
536 event_window = grab->native_window;
539 /* need to also adjust the coordinates to the new window */
540 ScreenToClient (GDK_WINDOW_HWND (event_window), &pt);
542 /* ATTENTION: need to update client coords */
543 msg->lParam = MAKELPARAM (pt.x, pt.y);
549 build_key_event_state (GdkEvent *event,
552 event->key.state = 0;
554 if (key_state[VK_SHIFT] & 0x80)
555 event->key.state |= GDK_SHIFT_MASK;
557 if (key_state[VK_CAPITAL] & 0x01)
558 event->key.state |= GDK_LOCK_MASK;
560 if (key_state[VK_LBUTTON] & 0x80)
561 event->key.state |= GDK_BUTTON1_MASK;
562 if (key_state[VK_MBUTTON] & 0x80)
563 event->key.state |= GDK_BUTTON2_MASK;
564 if (key_state[VK_RBUTTON] & 0x80)
565 event->key.state |= GDK_BUTTON3_MASK;
566 if (key_state[VK_XBUTTON1] & 0x80)
567 event->key.state |= GDK_BUTTON4_MASK;
568 if (key_state[VK_XBUTTON2] & 0x80)
569 event->key.state |= GDK_BUTTON5_MASK;
571 if (_gdk_keyboard_has_altgr &&
572 (key_state[VK_LCONTROL] & 0x80) &&
573 (key_state[VK_RMENU] & 0x80))
575 event->key.group = 1;
576 event->key.state |= GDK_MOD2_MASK;
577 if (key_state[VK_RCONTROL] & 0x80)
578 event->key.state |= GDK_CONTROL_MASK;
579 if (key_state[VK_LMENU] & 0x80)
580 event->key.state |= GDK_MOD1_MASK;
584 event->key.group = 0;
585 if (key_state[VK_CONTROL] & 0x80)
586 event->key.state |= GDK_CONTROL_MASK;
587 if (key_state[VK_MENU] & 0x80)
588 event->key.state |= GDK_MOD1_MASK;
593 build_pointer_event_state (MSG *msg)
599 if (msg->wParam & MK_CONTROL)
600 state |= GDK_CONTROL_MASK;
602 if ((msg->message != WM_LBUTTONDOWN &&
603 (msg->wParam & MK_LBUTTON)) ||
604 msg->message == WM_LBUTTONUP)
605 state |= GDK_BUTTON1_MASK;
607 if ((msg->message != WM_MBUTTONDOWN &&
608 (msg->wParam & MK_MBUTTON)) ||
609 msg->message == WM_MBUTTONUP)
610 state |= GDK_BUTTON2_MASK;
612 if ((msg->message != WM_RBUTTONDOWN &&
613 (msg->wParam & MK_RBUTTON)) ||
614 msg->message == WM_RBUTTONUP)
615 state |= GDK_BUTTON3_MASK;
617 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON1) &&
618 (msg->wParam & MK_XBUTTON1)) ||
619 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON1))
620 state |= GDK_BUTTON4_MASK;
622 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON2) &&
623 (msg->wParam & MK_XBUTTON2)) ||
624 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON2))
625 state |= GDK_BUTTON5_MASK;
627 if (msg->wParam & MK_SHIFT)
628 state |= GDK_SHIFT_MASK;
630 if (GetKeyState (VK_MENU) < 0)
631 state |= GDK_MOD1_MASK;
633 if (GetKeyState (VK_CAPITAL) & 0x1)
634 state |= GDK_LOCK_MASK;
640 build_wm_ime_composition_event (GdkEvent *event,
645 event->key.time = _gdk_win32_get_next_tick (msg->time);
647 build_key_event_state (event, key_state);
649 event->key.hardware_keycode = 0; /* FIXME: What should it be? */
650 event->key.string = NULL;
651 event->key.length = 0;
652 event->key.keyval = gdk_unicode_to_keyval (wc);
655 #ifdef G_ENABLE_DEBUG
658 print_event_state (guint state)
660 #define CASE(bit) if (state & GDK_ ## bit ## _MASK) g_print (#bit " ");
678 _gdk_win32_print_event (const GdkEvent *event)
680 gchar *escaped, *kvname;
681 gchar *selection_name, *target_name, *property_name;
683 g_print ("%s%*s===> ", (debug_indent > 0 ? "\n" : ""), debug_indent, "");
684 switch (event->any.type)
686 #define CASE(x) case x: g_print (#x); break;
691 CASE (GDK_MOTION_NOTIFY);
692 CASE (GDK_BUTTON_PRESS);
693 CASE (GDK_2BUTTON_PRESS);
694 CASE (GDK_3BUTTON_PRESS);
695 CASE (GDK_BUTTON_RELEASE);
696 CASE (GDK_KEY_PRESS);
697 CASE (GDK_KEY_RELEASE);
698 CASE (GDK_ENTER_NOTIFY);
699 CASE (GDK_LEAVE_NOTIFY);
700 CASE (GDK_FOCUS_CHANGE);
701 CASE (GDK_CONFIGURE);
704 CASE (GDK_PROPERTY_NOTIFY);
705 CASE (GDK_SELECTION_CLEAR);
706 CASE (GDK_SELECTION_REQUEST);
707 CASE (GDK_SELECTION_NOTIFY);
708 CASE (GDK_PROXIMITY_IN);
709 CASE (GDK_PROXIMITY_OUT);
710 CASE (GDK_DRAG_ENTER);
711 CASE (GDK_DRAG_LEAVE);
712 CASE (GDK_DRAG_MOTION);
713 CASE (GDK_DRAG_STATUS);
714 CASE (GDK_DROP_START);
715 CASE (GDK_DROP_FINISHED);
716 CASE (GDK_CLIENT_EVENT);
717 CASE (GDK_VISIBILITY_NOTIFY);
719 CASE (GDK_WINDOW_STATE);
721 CASE (GDK_OWNER_CHANGE);
722 CASE (GDK_GRAB_BROKEN);
724 default: g_assert_not_reached ();
727 g_print (" %p ", event->any.window ? GDK_WINDOW_HWND (event->any.window) : NULL);
729 switch (event->any.type)
733 _gdk_win32_gdkrectangle_to_string (&event->expose.area),
734 event->expose.count);
736 case GDK_MOTION_NOTIFY:
737 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s",
738 event->motion.x, event->motion.y,
739 event->motion.x_root, event->motion.y_root,
740 event->motion.is_hint ? "HINT " : "");
741 print_event_state (event->motion.state);
743 case GDK_BUTTON_PRESS:
744 case GDK_2BUTTON_PRESS:
745 case GDK_3BUTTON_PRESS:
746 case GDK_BUTTON_RELEASE:
747 g_print ("%d (%.4g,%.4g) (%.4g,%.4g) ",
748 event->button.button,
749 event->button.x, event->button.y,
750 event->button.x_root, event->button.y_root);
751 print_event_state (event->button.state);
754 case GDK_KEY_RELEASE:
755 if (event->key.length == 0)
756 escaped = g_strdup ("");
758 escaped = g_strescape (event->key.string, NULL);
759 kvname = gdk_keyval_name (event->key.keyval);
760 g_print ("%#.02x group:%d %s %d:\"%s\" ",
761 event->key.hardware_keycode, event->key.group,
762 (kvname ? kvname : "??"),
766 print_event_state (event->key.state);
768 case GDK_ENTER_NOTIFY:
769 case GDK_LEAVE_NOTIFY:
770 g_print ("%p (%.4g,%.4g) (%.4g,%.4g) %s %s%s",
771 event->crossing.subwindow == NULL ? NULL : GDK_WINDOW_HWND (event->crossing.subwindow),
772 event->crossing.x, event->crossing.y,
773 event->crossing.x_root, event->crossing.y_root,
774 (event->crossing.mode == GDK_CROSSING_NORMAL ? "NORMAL" :
775 (event->crossing.mode == GDK_CROSSING_GRAB ? "GRAB" :
776 (event->crossing.mode == GDK_CROSSING_UNGRAB ? "UNGRAB" :
778 (event->crossing.detail == GDK_NOTIFY_ANCESTOR ? "ANCESTOR" :
779 (event->crossing.detail == GDK_NOTIFY_VIRTUAL ? "VIRTUAL" :
780 (event->crossing.detail == GDK_NOTIFY_INFERIOR ? "INFERIOR" :
781 (event->crossing.detail == GDK_NOTIFY_NONLINEAR ? "NONLINEAR" :
782 (event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL ? "NONLINEAR_VIRTUAL" :
783 (event->crossing.detail == GDK_NOTIFY_UNKNOWN ? "UNKNOWN" :
785 event->crossing.focus ? " FOCUS" : "");
786 print_event_state (event->crossing.state);
788 case GDK_FOCUS_CHANGE:
789 g_print ("%s", (event->focus_change.in ? "IN" : "OUT"));
792 g_print ("x:%d y:%d w:%d h:%d",
793 event->configure.x, event->configure.y,
794 event->configure.width, event->configure.height);
796 case GDK_SELECTION_CLEAR:
797 case GDK_SELECTION_REQUEST:
798 case GDK_SELECTION_NOTIFY:
799 selection_name = gdk_atom_name (event->selection.selection);
800 target_name = gdk_atom_name (event->selection.target);
801 property_name = gdk_atom_name (event->selection.property);
802 g_print ("sel:%s tgt:%s prop:%s",
803 selection_name, target_name, property_name);
804 g_free (selection_name);
805 g_free (target_name);
806 g_free (property_name);
810 case GDK_DRAG_MOTION:
811 case GDK_DRAG_STATUS:
813 case GDK_DROP_FINISHED:
814 if (event->dnd.context != NULL)
815 g_print ("ctx:%p: %s %s src:%p dest:%p",
817 _gdk_win32_drag_protocol_to_string (event->dnd.context->protocol),
818 event->dnd.context->is_source ? "SOURCE" : "DEST",
819 event->dnd.context->source_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->source_window),
820 event->dnd.context->dest_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->dest_window));
822 case GDK_CLIENT_EVENT:
823 /* no more GdkEventClient */
826 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",
827 event->scroll.x, event->scroll.y,
828 event->scroll.x_root, event->scroll.y_root,
829 (event->scroll.direction == GDK_SCROLL_UP ? "UP" :
830 (event->scroll.direction == GDK_SCROLL_DOWN ? "DOWN" :
831 (event->scroll.direction == GDK_SCROLL_LEFT ? "LEFT" :
832 (event->scroll.direction == GDK_SCROLL_RIGHT ? "RIGHT" :
834 print_event_state (event->scroll.state);
836 case GDK_WINDOW_STATE:
838 _gdk_win32_window_state_to_string (event->window_state.changed_mask),
839 _gdk_win32_window_state_to_string (event->window_state.new_window_state));
842 (event->setting.action == GDK_SETTING_ACTION_NEW ? "NEW" :
843 (event->setting.action == GDK_SETTING_ACTION_CHANGED ? "CHANGED" :
844 (event->setting.action == GDK_SETTING_ACTION_DELETED ? "DELETED" :
846 (event->setting.name ? event->setting.name : "NULL"));
847 case GDK_GRAB_BROKEN:
849 (event->grab_broken.keyboard ? "KEYBOARD" : "POINTER"),
850 (event->grab_broken.implicit ? "IMPLICIT" : "EXPLICIT"),
851 (event->grab_broken.grab_window ? GDK_WINDOW_HWND (event->grab_broken.grab_window) : 0));
856 g_print ("%s", (debug_indent == 0 ? "\n" : ""));
860 decode_key_lparam (LPARAM lParam)
862 static char buf[100];
865 if (HIWORD (lParam) & KF_UP)
866 p += g_sprintf (p, "KF_UP ");
867 if (HIWORD (lParam) & KF_REPEAT)
868 p += g_sprintf (p, "KF_REPEAT ");
869 if (HIWORD (lParam) & KF_ALTDOWN)
870 p += g_sprintf (p, "KF_ALTDOWN ");
871 if (HIWORD (lParam) & KF_EXTENDED)
872 p += g_sprintf (p, "KF_EXTENDED ");
873 p += g_sprintf (p, "sc:%d rep:%d", LOBYTE (HIWORD (lParam)), LOWORD (lParam));
881 fixup_event (GdkEvent *event)
883 if (event->any.window)
884 g_object_ref (event->any.window);
885 if (((event->any.type == GDK_ENTER_NOTIFY) ||
886 (event->any.type == GDK_LEAVE_NOTIFY)) &&
887 (event->crossing.subwindow != NULL))
888 g_object_ref (event->crossing.subwindow);
889 event->any.send_event = InSendMessage ();
893 _gdk_win32_append_event (GdkEvent *event)
899 link = _gdk_event_queue_append (_gdk_display, event);
900 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
901 /* event morphing, the passed in may not be valid afterwards */
902 _gdk_windowing_got_event (_gdk_display, link, event, 0);
904 _gdk_event_queue_append (_gdk_display, event);
905 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
910 fill_key_event_string (GdkEvent *event)
915 /* Fill in event->string crudely, since various programs
920 if (event->key.keyval != GDK_KEY_VoidSymbol)
921 c = gdk_keyval_to_unicode (event->key.keyval);
928 /* Apply the control key - Taken from Xlib
930 if (event->key.state & GDK_CONTROL_MASK)
932 if ((c >= '@' && c < '\177') || c == ' ')
936 event->key.string = g_memdup ("\0\0", 2);
937 event->key.length = 1;
940 else if (c >= '3' && c <= '7')
948 len = g_unichar_to_utf8 (c, buf);
951 event->key.string = g_locale_from_utf8 (buf, len,
952 NULL, &bytes_written,
954 if (event->key.string)
955 event->key.length = bytes_written;
957 else if (event->key.keyval == GDK_KEY_Escape)
959 event->key.length = 1;
960 event->key.string = g_strdup ("\033");
962 else if (event->key.keyval == GDK_KEY_Return ||
963 event->key.keyval == GDK_KEY_KP_Enter)
965 event->key.length = 1;
966 event->key.string = g_strdup ("\r");
969 if (!event->key.string)
971 event->key.length = 0;
972 event->key.string = g_strdup ("");
976 static GdkFilterReturn
977 apply_event_filters (GdkWindow *window,
981 GdkFilterReturn result = GDK_FILTER_CONTINUE;
986 event = gdk_event_new (GDK_NOTHING);
988 event->any.window = g_object_ref (window);
989 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
991 /* I think GdkFilterFunc semantics require the passed-in event
992 * to already be in the queue. The filter func can generate
993 * more events and append them after it if it likes.
995 node = _gdk_event_queue_append (_gdk_display, event);
1000 GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
1003 if ((filter->flags & GDK_EVENT_FILTER_REMOVED) != 0)
1005 tmp_list = tmp_list->next;
1009 filter->ref_count++;
1010 result = filter->function (msg, event, filter->data);
1012 /* get the next node after running the function since the
1013 function may add or remove a next node */
1015 tmp_list = tmp_list->next;
1017 filter->ref_count--;
1018 if (filter->ref_count == 0)
1020 *filters = g_list_remove_link (*filters, node);
1021 g_list_free_1 (node);
1025 if (result != GDK_FILTER_CONTINUE)
1029 if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
1031 _gdk_event_queue_remove_link (_gdk_display, node);
1032 g_list_free_1 (node);
1033 gdk_event_free (event);
1035 else /* GDK_FILTER_TRANSLATE */
1037 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1038 fixup_event (event);
1039 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1045 * On Windows, transient windows will not have their own taskbar entries.
1046 * Because of this, we must hide and restore groups of transients in both
1047 * directions. That is, all transient children must be hidden or restored
1048 * with this window, but if this window's transient owner also has a
1049 * transient owner then this window's transient owner must be hidden/restored
1050 * with this one. And etc, up the chain until we hit an ancestor that has no
1053 * It would be a good idea if applications don't chain transient windows
1054 * together. There's a limit to how much evil GTK can try to shield you
1058 show_window_recurse (GdkWindow *window, gboolean hide_window)
1060 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1061 GSList *children = impl->transient_children;
1062 GdkWindow *child = NULL;
1064 if (!impl->changing_state)
1066 impl->changing_state = TRUE;
1068 if (children != NULL)
1070 while (children != NULL)
1072 child = children->data;
1073 show_window_recurse (child, hide_window);
1075 children = g_slist_next (children);
1079 if (GDK_WINDOW_IS_MAPPED (window))
1083 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_ICONIFIED)
1085 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED)
1087 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
1091 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1097 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
1101 impl->changing_state = FALSE;
1106 do_show_window (GdkWindow *window, gboolean hide_window)
1108 GdkWindow *tmp_window = NULL;
1109 GdkWindowImplWin32 *tmp_impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1111 if (!tmp_impl->changing_state)
1113 /* Find the top-level window in our transient chain. */
1114 while (tmp_impl->transient_owner != NULL)
1116 tmp_window = tmp_impl->transient_owner;
1117 tmp_impl = GDK_WINDOW_IMPL_WIN32 (tmp_window->impl);
1120 /* If we couldn't find one, use the window provided. */
1121 if (tmp_window == NULL)
1123 tmp_window = window;
1126 /* Recursively show/hide every window in the chain. */
1127 if (tmp_window != window)
1129 show_window_recurse (tmp_window, hide_window);
1135 send_crossing_event (GdkDisplay *display,
1138 GdkCrossingMode mode,
1139 GdkNotifyType notify_type,
1140 GdkWindow *subwindow,
1142 GdkModifierType mask,
1146 GdkDeviceGrabInfo *grab;
1147 GdkDeviceManagerWin32 *device_manager;
1150 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (display));
1152 grab = _gdk_display_has_device_grab (display, device_manager->core_pointer, 0);
1155 !grab->owner_events &&
1156 mode != GDK_CROSSING_UNGRAB)
1158 /* !owner_event => only report events wrt grab window, ignore rest */
1159 if ((GdkWindow *)window != grab->native_window)
1164 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1166 event = gdk_event_new (type);
1167 event->crossing.window = window;
1168 event->crossing.subwindow = subwindow;
1169 event->crossing.time = _gdk_win32_get_next_tick (time_);
1170 event->crossing.x = pt.x;
1171 event->crossing.y = pt.y;
1172 event->crossing.x_root = screen_pt->x + _gdk_offset_x;
1173 event->crossing.y_root = screen_pt->y + _gdk_offset_y;
1174 event->crossing.mode = mode;
1175 event->crossing.detail = notify_type;
1176 event->crossing.mode = mode;
1177 event->crossing.detail = notify_type;
1178 event->crossing.focus = FALSE;
1179 event->crossing.state = mask;
1180 gdk_event_set_device (event, _gdk_display->core_pointer);
1182 _gdk_win32_append_event (event);
1184 if (type == GDK_ENTER_NOTIFY &&
1185 window->extension_events != 0)
1186 _gdk_device_wintab_update_window_coords (window);
1190 get_native_parent (GdkWindow *window)
1192 if (window->parent != NULL)
1193 return window->parent->impl_window;
1198 find_common_ancestor (GdkWindow *win1,
1202 GList *path1 = NULL, *path2 = NULL;
1203 GList *list1, *list2;
1206 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
1208 path1 = g_list_prepend (path1, tmp);
1209 tmp = get_native_parent (tmp);
1213 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
1215 path2 = g_list_prepend (path2, tmp);
1216 tmp = get_native_parent (tmp);
1222 while (list1 && list2 && (list1->data == list2->data))
1224 tmp = (GdkWindow *)list1->data;
1225 list1 = g_list_next (list1);
1226 list2 = g_list_next (list2);
1228 g_list_free (path1);
1229 g_list_free (path2);
1235 synthesize_crossing_events (GdkDisplay *display,
1238 GdkCrossingMode mode,
1240 GdkModifierType mask,
1242 gboolean non_linear)
1245 GdkWindow *win, *last, *next;
1249 GdkNotifyType notify_type;
1254 return; /* No crossings generated between src and dest */
1256 c = find_common_ancestor (a, b);
1258 non_linear |= (c != a) && (c != b);
1260 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
1262 /* Traverse up from a to (excluding) c sending leave events */
1264 notify_type = GDK_NOTIFY_NONLINEAR;
1266 notify_type = GDK_NOTIFY_INFERIOR;
1268 notify_type = GDK_NOTIFY_ANCESTOR;
1269 send_crossing_event (display,
1270 a, GDK_LEAVE_NOTIFY,
1280 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1282 notify_type = GDK_NOTIFY_VIRTUAL;
1285 win = get_native_parent (a);
1286 while (win != c && win->window_type != GDK_WINDOW_ROOT)
1288 send_crossing_event (display,
1289 win, GDK_LEAVE_NOTIFY,
1297 win = get_native_parent (win);
1302 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
1304 /* Traverse down from c to b */
1308 win = get_native_parent (b);
1309 while (win != c && win->window_type != GDK_WINDOW_ROOT)
1311 path = g_list_prepend (path, win);
1312 win = get_native_parent (win);
1316 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1318 notify_type = GDK_NOTIFY_VIRTUAL;
1323 win = (GdkWindow *)list->data;
1324 list = g_list_next (list);
1326 next = (GdkWindow *)list->data;
1330 send_crossing_event (display,
1331 win, GDK_ENTER_NOTIFY,
1343 notify_type = GDK_NOTIFY_NONLINEAR;
1345 notify_type = GDK_NOTIFY_ANCESTOR;
1347 notify_type = GDK_NOTIFY_INFERIOR;
1349 send_crossing_event (display,
1350 b, GDK_ENTER_NOTIFY,
1359 /* The check_extended flag controls whether to check if the windows want
1360 * events from extended input devices and if the message should be skipped
1361 * because an extended input device is active
1364 propagate (GdkWindow **window,
1366 GdkWindow *grab_window,
1367 gboolean grab_owner_events,
1369 gboolean (*doesnt_want_it) (gint mask,
1371 gboolean check_extended)
1373 if (grab_window != NULL && !grab_owner_events)
1375 /* Event source is grabbed with owner_events FALSE */
1377 /* See if the event should be ignored because an extended input
1380 if (check_extended &&
1381 grab_window->extension_events != 0 &&
1382 _gdk_input_ignore_core)
1384 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1387 if ((*doesnt_want_it) (grab_mask, msg))
1389 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1394 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1395 assign_object (window, grab_window);
1400 /* If we come here, we know that if grab_window != NULL then
1401 * grab_owner_events is TRUE
1405 if (check_extended &&
1406 (*window)->extension_events != 0 &&
1407 _gdk_input_ignore_core)
1409 GDK_NOTE (EVENTS, g_print (" (ignored)"));
1412 if ((*doesnt_want_it) ((*window)->event_mask, msg))
1414 /* Owner doesn't want it, propagate to parent. */
1415 GdkWindow *parent = gdk_window_get_parent (*window);
1416 if (parent == _gdk_root || parent == NULL)
1418 /* No parent; check if grabbed */
1419 if (grab_window != NULL)
1421 /* Event source is grabbed with owner_events TRUE */
1423 if (check_extended &&
1424 grab_window->extension_events != 0 &&
1425 _gdk_input_ignore_core)
1427 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1430 if ((*doesnt_want_it) (grab_mask, msg))
1432 /* Grabber doesn't want it either */
1433 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1439 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1440 assign_object (window, grab_window);
1446 GDK_NOTE (EVENTS, g_print (" (undelivered)"));
1452 assign_object (window, parent);
1453 /* The only branch where we actually continue the loop */
1462 doesnt_want_key (gint mask,
1465 return (((msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) &&
1466 !(mask & GDK_KEY_RELEASE_MASK)) ||
1467 ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) &&
1468 !(mask & GDK_KEY_PRESS_MASK)));
1472 doesnt_want_char (gint mask,
1475 return !(mask & (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK));
1479 handle_configure_event (MSG *msg,
1485 GetClientRect (msg->hwnd, &client_rect);
1486 point.x = client_rect.left; /* always 0 */
1487 point.y = client_rect.top;
1489 /* top level windows need screen coords */
1490 if (gdk_window_get_parent (window) == _gdk_root)
1492 ClientToScreen (msg->hwnd, &point);
1493 point.x += _gdk_offset_x;
1494 point.y += _gdk_offset_y;
1497 window->width = client_rect.right - client_rect.left;
1498 window->height = client_rect.bottom - client_rect.top;
1500 window->x = point.x;
1501 window->y = point.y;
1503 _gdk_window_update_size (window);
1505 if (window->event_mask & GDK_STRUCTURE_MASK)
1507 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1509 event->configure.window = window;
1511 event->configure.width = client_rect.right - client_rect.left;
1512 event->configure.height = client_rect.bottom - client_rect.top;
1514 event->configure.x = point.x;
1515 event->configure.y = point.y;
1517 _gdk_win32_append_event (event);
1522 _gdk_win32_hrgn_to_region (HRGN hrgn)
1526 cairo_region_t *result;
1530 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1532 WIN32_GDI_FAILED ("GetRegionData");
1536 rgndata = (RGNDATA *) g_malloc (nbytes);
1538 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1540 WIN32_GDI_FAILED ("GetRegionData");
1545 result = cairo_region_create ();
1546 rects = (RECT *) rgndata->Buffer;
1547 for (i = 0; i < rgndata->rdh.nCount; i++)
1551 r.x = rects[i].left;
1553 r.width = rects[i].right - r.x;
1554 r.height = rects[i].bottom - r.y;
1556 cairo_region_union_rectangle (result, &r);
1565 adjust_drag (LONG *drag,
1570 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1572 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1576 handle_wm_paint (MSG *msg,
1578 gboolean return_exposes,
1581 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1583 PAINTSTRUCT paintstruct;
1584 cairo_region_t *update_region;
1586 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1588 WIN32_GDI_FAILED ("GetUpdateRgn");
1589 DeleteObject (hrgn);
1593 hdc = BeginPaint (msg->hwnd, &paintstruct);
1595 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1596 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1597 (paintstruct.fErase ? "erase" : ""),
1599 (return_exposes ? " return_exposes" : "")));
1601 EndPaint (msg->hwnd, &paintstruct);
1603 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1604 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1606 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1607 DeleteObject (hrgn);
1613 if (!GDK_WINDOW_DESTROYED (window))
1615 GList *list = _gdk_display->queued_events;
1617 *event = gdk_event_new (GDK_EXPOSE);
1618 (*event)->expose.window = window;
1619 (*event)->expose.area.x = paintstruct.rcPaint.left;
1620 (*event)->expose.area.y = paintstruct.rcPaint.top;
1621 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1622 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1623 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1624 (*event)->expose.count = 0;
1626 while (list != NULL)
1628 GdkEventPrivate *evp = list->data;
1630 if (evp->event.any.type == GDK_EXPOSE &&
1631 evp->event.any.window == window &&
1632 !(evp->flags & GDK_EVENT_PENDING))
1633 evp->event.expose.count++;
1639 DeleteObject (hrgn);
1643 update_region = _gdk_win32_hrgn_to_region (hrgn);
1644 if (!cairo_region_is_empty (update_region))
1645 _gdk_window_invalidate_for_expose (window, update_region);
1646 cairo_region_destroy (update_region);
1648 DeleteObject (hrgn);
1651 static VOID CALLBACK
1652 modal_timer_proc (HWND hwnd,
1657 int arbitrary_limit = 10;
1659 while (_modal_operation_in_progress &&
1660 g_main_context_pending (NULL) &&
1662 g_main_context_iteration (NULL, FALSE);
1666 _gdk_win32_begin_modal_call (void)
1668 g_assert (!_modal_operation_in_progress);
1670 _modal_operation_in_progress = TRUE;
1672 modal_timer = SetTimer (NULL, 0, 10, modal_timer_proc);
1673 if (modal_timer == 0)
1674 WIN32_API_FAILED ("SetTimer");
1678 _gdk_win32_end_modal_call (void)
1680 g_assert (_modal_operation_in_progress);
1682 _modal_operation_in_progress = FALSE;
1684 if (modal_timer != 0)
1686 API_CALL (KillTimer, (NULL, modal_timer));
1691 static VOID CALLBACK
1692 sync_timer_proc (HWND hwnd,
1698 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1703 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1705 KillTimer (hwnd, sync_timer);
1709 handle_display_change (void)
1711 _gdk_monitor_init ();
1712 _gdk_root_window_size_init ();
1713 g_signal_emit_by_name (_gdk_screen, "size_changed");
1717 generate_button_event (GdkEventType type,
1722 GdkEvent *event = gdk_event_new (type);
1724 event->button.window = window;
1725 event->button.time = _gdk_win32_get_next_tick (msg->time);
1726 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1727 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1728 event->button.x_root = msg->pt.x + _gdk_offset_x;
1729 event->button.y_root = msg->pt.y + _gdk_offset_y;
1730 event->button.axes = NULL;
1731 event->button.state = build_pointer_event_state (msg);
1732 event->button.button = button;
1733 gdk_event_set_device (event, _gdk_display->core_pointer);
1735 _gdk_win32_append_event (event);
1739 ensure_stacking_on_unminimize (MSG *msg)
1742 HWND lowest_transient = NULL;
1745 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1747 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1749 /* Checking window group not implemented yet */
1752 GdkWindowImplWin32 *rover_impl =
1753 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1755 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1756 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1757 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1758 rover_impl->transient_owner != NULL))
1760 lowest_transient = rover;
1764 if (lowest_transient != NULL)
1766 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1767 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1768 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1773 ensure_stacking_on_window_pos_changing (MSG *msg,
1776 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1777 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1779 if (GetActiveWindow () == msg->hwnd &&
1780 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1781 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1782 impl->transient_owner == NULL)
1784 /* Make sure the window stays behind any transient-type windows
1785 * of the same window group.
1787 * If the window is not active and being activated, we let
1788 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1789 * handling to bring any utility windows on top of it.
1792 gboolean restacking;
1794 rover = windowpos->hwndInsertAfter;
1798 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1800 /* Checking window group not implemented yet */
1803 GdkWindowImplWin32 *rover_impl =
1804 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1806 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1807 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1808 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1809 rover_impl->transient_owner != NULL))
1812 windowpos->hwndInsertAfter = rover;
1815 rover = GetNextWindow (rover, GW_HWNDNEXT);
1820 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1828 ensure_stacking_on_activate_app (MSG *msg,
1831 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1833 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1834 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1835 impl->transient_owner != NULL)
1837 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1838 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1842 if (IsWindowVisible (msg->hwnd) &&
1843 msg->hwnd == GetActiveWindow ())
1845 /* This window is not a transient-type window and it is the
1846 * activated window. Make sure this window is as visible as
1847 * possible, just below the lowest transient-type window of this
1853 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
1855 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1857 /* Checking window group not implemented yet */
1860 GdkWindowImplWin32 *rover_impl =
1861 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1863 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1864 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1865 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1866 rover_impl->transient_owner != NULL))
1868 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1869 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1870 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1878 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
1879 GDK_BUTTON2_MASK | \
1880 GDK_BUTTON3_MASK | \
1881 GDK_BUTTON4_MASK | \
1885 gdk_event_translate (MSG *msg,
1888 RECT rect, *drag, orig_drag;
1893 BYTE key_state[256];
1895 WINDOWPOS *windowpos;
1902 GdkWindow *window = NULL;
1903 GdkWindowImplWin32 *impl;
1905 GdkWindow *orig_window, *new_window;
1907 GdkDeviceManager *device_manager;
1909 GdkDeviceGrabInfo *keyboard_grab = NULL;
1910 GdkDeviceGrabInfo *pointer_grab = NULL;
1911 GdkWindow *grab_window = NULL;
1917 gboolean return_val = FALSE;
1921 if (_gdk_default_filters)
1923 /* Apply global filters */
1925 GdkFilterReturn result = apply_event_filters (NULL, msg, &_gdk_default_filters);
1927 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1928 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1929 * we return TRUE, and DefWindowProcW() will not be called.
1931 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1935 window = gdk_win32_handle_table_lookup (msg->hwnd);
1936 orig_window = window;
1940 /* XXX Handle WM_QUIT here ? */
1941 if (msg->message == WM_QUIT)
1943 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1946 else if (msg->message == WM_CREATE)
1948 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1949 GDK_WINDOW_HWND (window) = msg->hwnd;
1953 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1958 device_manager = gdk_display_get_device_manager (_gdk_display);
1960 keyboard_grab = _gdk_display_get_last_device_grab (_gdk_display,
1961 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
1962 pointer_grab = _gdk_display_get_last_device_grab (_gdk_display,
1963 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer);
1965 g_object_ref (window);
1967 /* window's refcount has now been increased, so code below should
1968 * not just return from this function, but instead goto done (or
1969 * break out of the big switch). To protect against forgetting this,
1970 * #define return to a syntax error...
1972 #define return GOTO_DONE_INSTEAD
1974 if (!GDK_WINDOW_DESTROYED (window) && window->filters)
1976 /* Apply per-window filters */
1978 GdkFilterReturn result = apply_event_filters (window, msg, &window->filters);
1980 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1987 if (msg->message == client_message)
1990 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1993 GDK_NOTE (EVENTS, g_print (" client_message"));
1995 event = gdk_event_new (GDK_NOTHING);
1996 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1998 node = _gdk_event_queue_append (_gdk_display, event);
2000 tmp_list = client_filters;
2003 GdkClientFilter *filter = tmp_list->data;
2005 tmp_list = tmp_list->next;
2007 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
2009 GDK_NOTE (EVENTS, g_print (" (match)"));
2011 result = (*filter->function) (msg, event, filter->data);
2013 if (result != GDK_FILTER_CONTINUE)
2020 case GDK_FILTER_REMOVE:
2021 _gdk_event_queue_remove_link (_gdk_display, node);
2022 g_list_free_1 (node);
2023 gdk_event_free (event);
2027 case GDK_FILTER_TRANSLATE:
2028 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2029 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2033 case GDK_FILTER_CONTINUE:
2034 /* No more: Send unknown client messages on to Gtk for it to use */
2035 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2041 switch (msg->message)
2043 case WM_INPUTLANGCHANGE:
2044 _gdk_input_locale = (HKL) msg->lParam;
2045 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
2046 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
2047 LOCALE_IDEFAULTANSICODEPAGE,
2049 _gdk_input_codepage = atoi (buf);
2050 _gdk_keymap_serial++;
2052 g_print (" cs:%lu hkl:%p%s cp:%d",
2053 (gulong) msg->wParam,
2054 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
2055 _gdk_input_codepage));
2061 g_print (" %s ch:%.02x %s",
2062 _gdk_win32_key_to_string (msg->lParam),
2064 decode_key_lparam (msg->lParam)));
2066 /* If posted without us having keyboard focus, ignore */
2067 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
2068 !(HIWORD (msg->lParam) & KF_ALTDOWN))
2071 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
2072 * the keyboard is grabbed.
2074 if (!keyboard_grab &&
2075 (msg->wParam == VK_TAB ||
2076 msg->wParam == VK_SPACE ||
2077 msg->wParam == VK_F4))
2080 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
2086 g_print (" %s ch:%.02x %s",
2087 _gdk_win32_key_to_string (msg->lParam),
2089 decode_key_lparam (msg->lParam)));
2093 /* Ignore key messages intended for the IME */
2094 if (msg->wParam == VK_PROCESSKEY ||
2098 if (keyboard_grab &&
2099 !propagate (&window, msg,
2100 keyboard_grab->window,
2101 keyboard_grab->owner_events,
2102 GDK_ALL_EVENTS_MASK,
2103 doesnt_want_key, FALSE))
2106 if (GDK_WINDOW_DESTROYED (window))
2109 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
2110 msg->message == WM_SYSKEYDOWN) ?
2111 GDK_KEY_PRESS : GDK_KEY_RELEASE);
2112 event->key.window = window;
2113 event->key.time = _gdk_win32_get_next_tick (msg->time);
2114 event->key.keyval = GDK_KEY_VoidSymbol;
2115 event->key.string = NULL;
2116 event->key.length = 0;
2117 event->key.hardware_keycode = msg->wParam;
2118 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2119 if (HIWORD (msg->lParam) & KF_EXTENDED)
2121 switch (msg->wParam)
2124 event->key.hardware_keycode = VK_RCONTROL;
2126 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
2127 * for the right shift key.
2129 event->key.hardware_keycode = VK_RSHIFT;
2132 event->key.hardware_keycode = VK_RMENU;
2136 else if (msg->wParam == VK_SHIFT &&
2137 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
2138 event->key.hardware_keycode = VK_RSHIFT;
2140 API_CALL (GetKeyboardState, (key_state));
2142 /* g_print ("ctrl:%02x lctrl:%02x rctrl:%02x alt:%02x lalt:%02x ralt:%02x\n", key_state[VK_CONTROL], key_state[VK_LCONTROL], key_state[VK_RCONTROL], key_state[VK_MENU], key_state[VK_LMENU], key_state[VK_RMENU]); */
2144 build_key_event_state (event, key_state);
2146 if (msg->wParam == VK_PACKET &&
2147 ToUnicode (VK_PACKET, HIWORD (msg->lParam), key_state, wbuf, 1, 0) == 1)
2148 event->key.keyval = gdk_unicode_to_keyval (wbuf[0]);
2150 gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (_gdk_display),
2151 event->key.hardware_keycode,
2157 fill_key_event_string (event);
2159 /* Reset MOD1_MASK if it is the Alt key itself */
2160 if (msg->wParam == VK_MENU)
2161 event->key.state &= ~GDK_MOD1_MASK;
2163 _gdk_win32_append_event (event);
2169 if (msg->wParam != VK_SPACE)
2171 /* To prevent beeps, don't let DefWindowProcW() be called */
2177 case WM_IME_STARTCOMPOSITION:
2178 in_ime_composition = TRUE;
2181 case WM_IME_ENDCOMPOSITION:
2182 in_ime_composition = FALSE;
2185 case WM_IME_COMPOSITION:
2186 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2187 * applications. Thus, handle WM_IME_COMPOSITION with
2188 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2189 * with ImmGetCompositionStringW().
2192 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2194 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2195 * for comments by other people that seems to have the same
2196 * experience. WM_IME_CHAR just gives question marks, apparently
2197 * because of going through some conversion to the current code
2200 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2201 * use WM_IME_COMPOSITION there, too, to simplify the code.
2203 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2205 if (!(msg->lParam & GCS_RESULTSTR))
2208 if (keyboard_grab &&
2209 !propagate (&window, msg,
2210 keyboard_grab->window,
2211 keyboard_grab->owner_events,
2212 GDK_ALL_EVENTS_MASK,
2213 doesnt_want_char, FALSE))
2216 if (GDK_WINDOW_DESTROYED (window))
2219 himc = ImmGetContext (msg->hwnd);
2220 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2221 wbuf, sizeof (wbuf));
2222 ImmReleaseContext (msg->hwnd, himc);
2226 API_CALL (GetKeyboardState, (key_state));
2228 for (i = 0; i < ccount; i++)
2230 if (window->event_mask & GDK_KEY_PRESS_MASK)
2232 /* Build a key press event */
2233 event = gdk_event_new (GDK_KEY_PRESS);
2234 event->key.window = window;
2235 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2236 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2238 _gdk_win32_append_event (event);
2241 if (window->event_mask & GDK_KEY_RELEASE_MASK)
2243 /* Build a key release event. */
2244 event = gdk_event_new (GDK_KEY_RELEASE);
2245 event->key.window = window;
2246 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2247 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2249 _gdk_win32_append_event (event);
2255 case WM_LBUTTONDOWN:
2259 case WM_MBUTTONDOWN:
2263 case WM_RBUTTONDOWN:
2267 case WM_XBUTTONDOWN:
2268 if (HIWORD (msg->wParam) == XBUTTON1)
2275 g_print (" (%d,%d)",
2276 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2278 assign_object (&window, find_window_for_mouse_event (window, msg));
2279 /* TODO_CSW?: there used to some synthesize and propagate */
2280 if (GDK_WINDOW_DESTROYED (window))
2283 if (pointer_grab == NULL)
2285 SetCapture (GDK_WINDOW_HWND (window));
2288 generate_button_event (GDK_BUTTON_PRESS, button,
2307 if (HIWORD (msg->wParam) == XBUTTON1)
2314 g_print (" (%d,%d)",
2315 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2317 assign_object (&window, find_window_for_mouse_event (window, msg));
2319 if (window->extension_events != 0 &&
2320 _gdk_input_ignore_core)
2322 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2327 if (pointer_grab != NULL && pointer_grab->implicit)
2329 gint state = build_pointer_event_state (msg);
2331 /* We keep the implicit grab until no buttons at all are held down */
2332 if ((state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (button - 1))) == 0)
2337 hwnd = WindowFromPoint (msg->pt);
2340 POINT client_pt = msg->pt;
2342 ScreenToClient (hwnd, &client_pt);
2343 GetClientRect (hwnd, &rect);
2344 if (PtInRect (&rect, client_pt))
2345 new_window = gdk_win32_handle_table_lookup (hwnd);
2347 synthesize_crossing_events (_gdk_display,
2348 pointer_grab->native_window, new_window,
2349 GDK_CROSSING_UNGRAB,
2351 0, /* TODO: Set right mask */
2354 assign_object (&mouse_window, new_window);
2358 generate_button_event (GDK_BUTTON_RELEASE, button,
2366 g_print (" %p (%d,%d)",
2367 (gpointer) msg->wParam,
2368 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2370 new_window = window;
2372 if (pointer_grab != NULL)
2378 hwnd = WindowFromPoint (pt);
2381 POINT client_pt = pt;
2383 ScreenToClient (hwnd, &client_pt);
2384 GetClientRect (hwnd, &rect);
2385 if (PtInRect (&rect, client_pt))
2386 new_window = gdk_win32_handle_table_lookup (hwnd);
2389 if (!pointer_grab->owner_events &&
2390 new_window != NULL &&
2391 new_window != pointer_grab->native_window)
2395 if (mouse_window != new_window)
2397 GDK_NOTE (EVENTS, g_print (" mouse_sinwod %p -> %p",
2398 mouse_window ? GDK_WINDOW_HWND (mouse_window) : NULL,
2399 new_window ? GDK_WINDOW_HWND (new_window) : NULL));
2400 synthesize_crossing_events (_gdk_display,
2401 mouse_window, new_window,
2402 GDK_CROSSING_NORMAL,
2404 0, /* TODO: Set right mask */
2407 assign_object (&mouse_window, new_window);
2408 if (new_window != NULL)
2409 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (new_window));
2412 assign_object (&window, find_window_for_mouse_event (window, msg));
2414 /* If we haven't moved, don't create any GDK event. Windows
2415 * sends WM_MOUSEMOVE messages after a new window is shows under
2416 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2418 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2419 msg->pt.y + _gdk_offset_y == current_root_y)
2422 current_root_x = msg->pt.x + _gdk_offset_x;
2423 current_root_y = msg->pt.y + _gdk_offset_y;
2425 event = gdk_event_new (GDK_MOTION_NOTIFY);
2426 event->motion.window = window;
2427 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2428 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2429 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2430 event->motion.x_root = current_root_x;
2431 event->motion.y_root = current_root_y;
2432 event->motion.axes = NULL;
2433 event->motion.state = build_pointer_event_state (msg);
2434 event->motion.is_hint = FALSE;
2435 gdk_event_set_device (event, _gdk_display->core_pointer);
2437 _gdk_win32_append_event (event);
2442 case WM_NCMOUSEMOVE:
2444 g_print (" (%d,%d)",
2445 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2449 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2450 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2453 hwnd = WindowFromPoint (msg->pt);
2456 POINT client_pt = msg->pt;
2458 ScreenToClient (hwnd, &client_pt);
2459 GetClientRect (hwnd, &rect);
2460 if (PtInRect (&rect, client_pt))
2461 new_window = gdk_win32_handle_table_lookup (hwnd);
2464 synthesize_crossing_events (_gdk_display,
2465 mouse_window, new_window,
2466 GDK_CROSSING_NORMAL,
2468 0, /* TODO: Set right mask */
2471 assign_object (&mouse_window, new_window);
2477 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2479 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2480 * that. Also, the position is in screen coordinates, not client
2481 * coordinates as with the button messages. I love the
2482 * consistency of Windows.
2484 point.x = GET_X_LPARAM (msg->lParam);
2485 point.y = GET_Y_LPARAM (msg->lParam);
2487 if ((hwnd = WindowFromPoint (point)) == NULL)
2491 if ((new_window = gdk_win32_handle_table_lookup (msg->hwnd)) == NULL)
2494 if (new_window != window)
2496 assign_object (&window, new_window);
2499 ScreenToClient (msg->hwnd, &point);
2501 event = gdk_event_new (GDK_SCROLL);
2502 event->scroll.window = window;
2503 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2504 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2505 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2506 event->scroll.x = (gint16) point.x;
2507 event->scroll.y = (gint16) point.y;
2508 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2509 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2510 event->scroll.state = build_pointer_event_state (msg);
2511 gdk_event_set_device (event, _gdk_display->core_pointer);
2513 _gdk_win32_append_event (event);
2519 /* Just print more debugging information, don't actually handle it. */
2522 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2523 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2524 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2525 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2526 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2527 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2528 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2529 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2530 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2532 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2533 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2534 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2538 /* Just print more debugging information, don't actually handle it. */
2541 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2542 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2543 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2544 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2545 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2546 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2547 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2548 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2549 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2551 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2552 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2553 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2556 case WM_MOUSEACTIVATE:
2560 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2561 || !window->accept_focus)
2563 *ret_valp = MA_NOACTIVATE;
2567 tmp = _gdk_modal_current ();
2571 if (gdk_window_get_toplevel (window) != tmp)
2573 *ret_valp = MA_NOACTIVATEANDEAT;
2582 if (keyboard_grab != NULL &&
2583 !GDK_WINDOW_DESTROYED (keyboard_grab->window))
2585 generate_grab_broken_event (device_manager, keyboard_grab->window, TRUE, NULL);
2590 if (keyboard_grab != NULL &&
2591 !keyboard_grab->owner_events)
2594 if (!(window->event_mask & GDK_FOCUS_CHANGE_MASK))
2597 if (GDK_WINDOW_DESTROYED (window))
2600 generate_focus_event (device_manager, window, (msg->message == WM_SETFOCUS));
2605 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2607 if (GDK_WINDOW_DESTROYED (window))
2615 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2617 200, sync_timer_proc);
2621 handle_wm_paint (msg, window, FALSE, NULL);
2625 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2626 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2628 if (pointer_grab != NULL)
2629 grab_window = pointer_grab->window;
2631 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2634 if (grab_window != NULL && p_grab_cursor != NULL)
2635 hcursor = p_grab_cursor;
2636 else if (!GDK_WINDOW_DESTROYED (window))
2637 hcursor = GDK_WINDOW_IMPL_WIN32 (window->impl)->hcursor;
2641 if (hcursor != NULL)
2643 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2644 SetCursor (hcursor);
2651 switch (msg->wParam)
2655 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2661 case WM_ENTERSIZEMOVE:
2662 case WM_ENTERMENULOOP:
2663 _gdk_win32_begin_modal_call ();
2666 case WM_EXITSIZEMOVE:
2667 case WM_EXITMENULOOP:
2668 if (_modal_operation_in_progress)
2669 _gdk_win32_end_modal_call ();
2672 case WM_CAPTURECHANGED:
2673 /* Sometimes we don't get WM_EXITSIZEMOVE, for instance when you
2674 select move/size in the menu and then click somewhere without
2675 moving/resizing. We work around this using WM_CAPTURECHANGED. */
2676 if (_modal_operation_in_progress)
2677 _gdk_win32_end_modal_call ();
2680 case WM_WINDOWPOSCHANGING:
2681 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2682 g_print (" %s %s %dx%d@%+d%+d now below %p",
2683 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2684 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2685 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2686 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2687 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2688 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2690 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2691 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2693 if (GDK_WINDOW_IS_MAPPED (window))
2694 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2697 case WM_WINDOWPOSCHANGED:
2698 windowpos = (WINDOWPOS *) msg->lParam;
2699 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2700 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2701 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2702 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2703 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2704 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2705 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2707 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2709 /* Break grabs on unmap or minimize */
2710 if (windowpos->flags & SWP_HIDEWINDOW ||
2711 ((windowpos->flags & SWP_STATECHANGED) && IsIconic (msg->hwnd)))
2713 if (pointer_grab != NULL)
2715 if (pointer_grab->window == window)
2716 gdk_pointer_ungrab (msg->time);
2719 if (keyboard_grab->window == window)
2720 gdk_keyboard_ungrab (msg->time);
2723 /* Send MAP events */
2724 if ((windowpos->flags & SWP_SHOWWINDOW) &&
2725 !GDK_WINDOW_DESTROYED (window))
2727 event = gdk_event_new (GDK_MAP);
2728 event->any.window = window;
2729 _gdk_win32_append_event (event);
2732 /* New size or position => configure event */
2733 if (!(windowpos->flags & SWP_NOCLIENTMOVE) ||
2734 !(windowpos->flags & SWP_NOCLIENTSIZE))
2736 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2737 !IsIconic (msg->hwnd) &&
2738 !GDK_WINDOW_DESTROYED (window))
2739 handle_configure_event (msg, window);
2741 if (window->extension_events != 0)
2742 _gdk_device_wintab_update_window_coords (window);
2745 if ((windowpos->flags & SWP_HIDEWINDOW) &&
2746 !GDK_WINDOW_DESTROYED (window))
2748 /* Send UNMAP events */
2749 event = gdk_event_new (GDK_UNMAP);
2750 event->any.window = window;
2751 _gdk_win32_append_event (event);
2753 /* Make transient parent the forground window when window unmaps */
2754 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2756 if (impl->transient_owner &&
2757 GetForegroundWindow () == GDK_WINDOW_HWND (window))
2758 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2761 /* Update window state */
2762 if (windowpos->flags & (SWP_STATECHANGED | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
2764 GdkWindowState set_bits, unset_bits, old_state, new_state;
2766 old_state = window->state;
2771 if (IsWindowVisible (msg->hwnd))
2772 unset_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2774 set_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2776 if (IsIconic (msg->hwnd))
2777 set_bits |= GDK_WINDOW_STATE_ICONIFIED;
2779 unset_bits |= GDK_WINDOW_STATE_ICONIFIED;
2781 if (IsZoomed (msg->hwnd))
2782 set_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2784 unset_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2786 gdk_synthesize_window_state (window, unset_bits, set_bits);
2788 new_state = window->state;
2790 /* Whenever one window changes iconified state we need to also
2791 * change the iconified state in all transient related windows,
2792 * as windows doesn't give icons for transient childrens.
2794 if ((old_state & GDK_WINDOW_STATE_ICONIFIED) !=
2795 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2796 do_show_window (window, (new_state & GDK_WINDOW_STATE_ICONIFIED));
2799 /* When un-minimizing, make sure we're stacked under any
2800 transient-type windows. */
2801 if (!(old_state & GDK_WINDOW_STATE_ICONIFIED) &&
2802 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2803 ensure_stacking_on_unminimize (msg);
2806 if (!(windowpos->flags & SWP_NOCLIENTSIZE))
2808 if (window->resize_count > 1)
2809 window->resize_count -= 1;
2812 /* Call modal timer immediate so that we repaint faster after a resize. */
2813 if (_modal_operation_in_progress)
2814 modal_timer_proc (0,0,0,0);
2816 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2822 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2823 drag = (RECT *) msg->lParam;
2824 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2825 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2826 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2827 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2828 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2829 (msg->wParam == WMSZ_TOP ? "TOP" :
2830 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2831 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2833 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2835 _gdk_win32_rect_to_string (&rect),
2836 _gdk_win32_rect_to_string (drag)));
2838 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2840 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2842 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2843 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2845 /* Resize in increments relative to the base size */
2846 rect.left = rect.top = 0;
2847 rect.right = impl->hints.base_width;
2848 rect.bottom = impl->hints.base_height;
2849 _gdk_win32_adjust_client_rect (window, &rect);
2850 point.x = rect.left;
2852 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2853 rect.left = point.x;
2855 point.x = rect.right;
2856 point.y = rect.bottom;
2857 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2858 rect.right = point.x;
2859 rect.bottom = point.y;
2861 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2862 _gdk_win32_rect_to_string (&rect)));
2865 switch (msg->wParam)
2868 if (drag->bottom == rect.bottom)
2870 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2873 case WMSZ_BOTTOMLEFT:
2874 if (drag->bottom == rect.bottom && drag->left == rect.left)
2876 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2877 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2881 if (drag->left == rect.left)
2883 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2887 if (drag->top == rect.top && drag->left == rect.left)
2889 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2890 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2894 if (drag->top == rect.top)
2896 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2900 if (drag->top == rect.top && drag->right == rect.right)
2902 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2903 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2907 if (drag->right == rect.right)
2909 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2912 case WMSZ_BOTTOMRIGHT:
2913 if (drag->bottom == rect.bottom && drag->right == rect.right)
2915 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2916 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2920 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2921 drag->top != orig_drag.top || drag->right != orig_drag.right)
2925 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2926 _gdk_win32_rect_to_string (drag)));
2930 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2932 if (impl->hint_flags & GDK_HINT_ASPECT)
2934 RECT decorated_rect;
2935 RECT undecorated_drag;
2936 int decoration_width, decoration_height;
2937 gdouble drag_aspect;
2938 int drag_width, drag_height, new_width, new_height;
2940 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2941 decorated_rect = rect;
2942 _gdk_win32_adjust_client_rect (window, &decorated_rect);
2944 /* Set undecorated_drag to the client area being dragged
2945 * out, in screen coordinates.
2947 undecorated_drag = *drag;
2948 undecorated_drag.left -= decorated_rect.left - rect.left;
2949 undecorated_drag.right -= decorated_rect.right - rect.right;
2950 undecorated_drag.top -= decorated_rect.top - rect.top;
2951 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
2953 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
2954 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
2956 drag_width = undecorated_drag.right - undecorated_drag.left;
2957 drag_height = undecorated_drag.bottom - undecorated_drag.top;
2959 drag_aspect = (gdouble) drag_width / drag_height;
2961 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
2962 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
2964 if (drag_aspect < impl->hints.min_aspect)
2966 /* Aspect is getting too narrow */
2967 switch (msg->wParam)
2971 /* User drags top or bottom edge outward. Keep height, increase width. */
2972 new_width = impl->hints.min_aspect * drag_height;
2973 drag->left -= (new_width - drag_width) / 2;
2974 drag->right = drag->left + new_width + decoration_width;
2976 case WMSZ_BOTTOMLEFT:
2977 case WMSZ_BOTTOMRIGHT:
2978 /* User drags bottom-left or bottom-right corner down. Adjust height. */
2979 new_height = drag_width / impl->hints.min_aspect;
2980 drag->bottom = drag->top + new_height + decoration_height;
2984 /* User drags left or right edge inward. Decrease height */
2985 new_height = drag_width / impl->hints.min_aspect;
2986 drag->top += (drag_height - new_height) / 2;
2987 drag->bottom = drag->top + new_height + decoration_height;
2991 /* User drags top-left or top-right corner up. Adjust height. */
2992 new_height = drag_width / impl->hints.min_aspect;
2993 drag->top = drag->bottom - new_height - decoration_height;
2996 else if (drag_aspect > impl->hints.max_aspect)
2998 /* Aspect is getting too wide */
2999 switch (msg->wParam)
3003 /* User drags top or bottom edge inward. Decrease width. */
3004 new_width = impl->hints.max_aspect * drag_height;
3005 drag->left += (drag_width - new_width) / 2;
3006 drag->right = drag->left + new_width + decoration_width;
3008 case WMSZ_BOTTOMLEFT:
3010 /* User drags bottom-left or top-left corner left. Adjust width. */
3011 new_width = impl->hints.max_aspect * drag_height;
3012 drag->left = drag->right - new_width - decoration_width;
3014 case WMSZ_BOTTOMRIGHT:
3016 /* User drags bottom-right or top-right corner right. Adjust width. */
3017 new_width = impl->hints.max_aspect * drag_height;
3018 drag->right = drag->left + new_width + decoration_width;
3022 /* User drags left or right edge outward. Increase height. */
3023 new_height = drag_width / impl->hints.max_aspect;
3024 drag->top -= (new_height - drag_height) / 2;
3025 drag->bottom = drag->top + new_height + decoration_height;
3032 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
3033 _gdk_win32_rect_to_string (drag)));
3037 case WM_GETMINMAXINFO:
3038 if (GDK_WINDOW_DESTROYED (window))
3041 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3042 mmi = (MINMAXINFO*) msg->lParam;
3043 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
3044 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3045 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3046 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3047 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3048 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3050 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
3052 rect.left = rect.top = 0;
3053 rect.right = impl->hints.min_width;
3054 rect.bottom = impl->hints.min_height;
3056 _gdk_win32_adjust_client_rect (window, &rect);
3058 mmi->ptMinTrackSize.x = rect.right - rect.left;
3059 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
3062 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
3066 rect.left = rect.top = 0;
3067 rect.right = impl->hints.max_width;
3068 rect.bottom = impl->hints.max_height;
3070 _gdk_win32_adjust_client_rect (window, &rect);
3072 /* at least on win9x we have the 16 bit trouble */
3073 maxw = rect.right - rect.left;
3074 maxh = rect.bottom - rect.top;
3075 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
3076 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
3079 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
3081 /* Don't call DefWindowProcW() */
3082 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
3083 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3084 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3085 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3086 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3087 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3093 if (GDK_WINDOW_DESTROYED (window))
3096 event = gdk_event_new (GDK_DELETE);
3097 event->any.window = window;
3099 _gdk_win32_append_event (event);
3101 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3103 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
3105 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3112 if (pointer_grab != NULL)
3114 if (pointer_grab->window == window)
3115 gdk_pointer_ungrab (msg->time);
3118 if (keyboard_grab &&
3119 keyboard_grab->window == window)
3120 gdk_keyboard_ungrab (msg->time);
3122 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
3123 gdk_window_destroy_notify (window);
3125 if (window == NULL || GDK_WINDOW_DESTROYED (window))
3128 event = gdk_event_new (GDK_DESTROY);
3129 event->any.window = window;
3131 _gdk_win32_append_event (event);
3136 case WM_DISPLAYCHANGE:
3137 handle_display_change ();
3140 case WM_DESTROYCLIPBOARD:
3141 if (!_ignore_destroy_clipboard)
3143 event = gdk_event_new (GDK_SELECTION_CLEAR);
3144 event->selection.window = window;
3145 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3146 event->selection.time = _gdk_win32_get_next_tick (msg->time);
3147 _gdk_win32_append_event (event);
3156 case WM_RENDERFORMAT:
3157 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
3159 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
3161 GDK_NOTE (EVENTS, g_print (" (target not found)"));
3166 /* We need to render to clipboard immediately, don't call
3167 * _gdk_win32_append_event()
3169 event = gdk_event_new (GDK_SELECTION_REQUEST);
3170 event->selection.window = window;
3171 event->selection.send_event = FALSE;
3172 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3173 event->selection.target = target;
3174 event->selection.property = _gdk_selection;
3175 event->selection.requestor = gdk_win32_handle_table_lookup (msg->hwnd);
3176 event->selection.time = msg->time;
3178 fixup_event (event);
3179 GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)"));
3180 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
3181 _gdk_event_emit (event);
3182 gdk_event_free (event);
3184 /* Now the clipboard owner should have rendered */
3185 if (!_delayed_rendering_data)
3187 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3191 if (msg->wParam == CF_DIB)
3193 _delayed_rendering_data =
3194 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3196 if (!_delayed_rendering_data)
3198 g_warning ("Cannot convert to DIB from delayed rendered image");
3203 /* The requestor is holding the clipboard, no
3204 * OpenClipboard() is required/possible
3207 g_print (" SetClipboardData(%s,%p)",
3208 _gdk_win32_cf_to_string (msg->wParam),
3209 _delayed_rendering_data));
3211 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3212 _delayed_rendering_data = NULL;
3217 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3218 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3219 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3220 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3221 HIWORD (msg->wParam) ? " minimized" : "",
3222 (HWND) msg->lParam));
3223 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3224 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3227 if (is_modally_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3229 GdkWindow *modal_current = _gdk_modal_current ();
3230 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3236 /* Bring any tablet contexts to the top of the overlap order when
3237 * one of our windows is activated.
3238 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3241 if (LOWORD(msg->wParam) != WA_INACTIVE)
3242 _gdk_input_set_tablet_active ();
3245 case WM_ACTIVATEAPP:
3246 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3247 msg->wParam ? "YES" : "NO",
3248 (gint64) msg->lParam));
3249 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3250 ensure_stacking_on_activate_app (msg, window);
3253 /* Handle WINTAB events here, as we know that gdkinput.c will
3254 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3255 * constants as case labels.
3258 GDK_NOTE (EVENTS, g_print (" %d %p",
3259 (int) msg->wParam, (gpointer) msg->lParam));
3263 GDK_NOTE (EVENTS, g_print (" %d %p",
3264 (int) msg->wParam, (gpointer) msg->lParam));
3268 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3269 (gpointer) msg->wParam,
3270 LOWORD (msg->lParam),
3271 HIWORD (msg->lParam)));
3275 event = gdk_event_new (GDK_NOTHING);
3276 event->any.window = window;
3277 g_object_ref (window);
3279 if (_gdk_input_other_event (event, msg, window))
3280 _gdk_win32_append_event (event);
3282 gdk_event_free (event);
3290 g_object_unref (window);
3297 _gdk_win32_display_queue_events (GdkDisplay *display)
3301 if (modal_win32_dialog != NULL)
3304 while (!_gdk_event_queue_find_first (display) &&
3305 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3307 TranslateMessage (&msg);
3308 DispatchMessageW (&msg);
3313 gdk_event_prepare (GSource *source,
3318 GDK_THREADS_ENTER ();
3322 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3323 (modal_win32_dialog == NULL &&
3324 GetQueueStatus (QS_ALLINPUT) != 0));
3326 GDK_THREADS_LEAVE ();
3332 gdk_event_check (GSource *source)
3336 GDK_THREADS_ENTER ();
3338 if (event_poll_fd.revents & G_IO_IN)
3340 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3341 (modal_win32_dialog == NULL &&
3342 GetQueueStatus (QS_ALLINPUT) != 0));
3349 GDK_THREADS_LEAVE ();
3355 gdk_event_dispatch (GSource *source,
3356 GSourceFunc callback,
3361 GDK_THREADS_ENTER ();
3363 _gdk_win32_display_queue_events (_gdk_display);
3364 event = _gdk_event_unqueue (_gdk_display);
3368 _gdk_event_emit (event);
3370 gdk_event_free (event);
3372 /* Do drag & drop if it is still pending */
3373 if (_dnd_source_state == GDK_WIN32_DND_PENDING)
3375 _dnd_source_state = GDK_WIN32_DND_DRAGGING;
3376 _gdk_win32_dnd_do_dragdrop ();
3377 _dnd_source_state = GDK_WIN32_DND_NONE;
3381 GDK_THREADS_LEAVE ();
3387 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3389 modal_win32_dialog = window;
3393 is_modally_blocked (GdkWindow *window)
3395 GdkWindow *modal_current = _gdk_modal_current ();
3396 return modal_current != NULL ? gdk_window_get_toplevel (window) != modal_current : FALSE;
3400 _gdk_win32_display_sync (GdkDisplay * display)
3404 g_return_if_fail (display == _gdk_display);
3406 /* Process all messages currently available */
3407 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3408 DispatchMessageW (&msg);