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 _gdk_win32_emit_configure_event (GdkWindow *window)
1485 hwnd = GDK_WINDOW_HWND (window);
1487 GetClientRect (hwnd, &client_rect);
1488 point.x = client_rect.left; /* always 0 */
1489 point.y = client_rect.top;
1491 /* top level windows need screen coords */
1492 if (gdk_window_get_parent (window) == _gdk_root)
1494 ClientToScreen (hwnd, &point);
1495 point.x += _gdk_offset_x;
1496 point.y += _gdk_offset_y;
1499 window->width = client_rect.right - client_rect.left;
1500 window->height = client_rect.bottom - client_rect.top;
1502 window->x = point.x;
1503 window->y = point.y;
1505 _gdk_window_update_size (window);
1507 if (window->event_mask & GDK_STRUCTURE_MASK)
1509 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1511 event->configure.window = window;
1513 event->configure.width = client_rect.right - client_rect.left;
1514 event->configure.height = client_rect.bottom - client_rect.top;
1516 event->configure.x = point.x;
1517 event->configure.y = point.y;
1519 _gdk_win32_append_event (event);
1524 _gdk_win32_hrgn_to_region (HRGN hrgn)
1528 cairo_region_t *result;
1532 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1534 WIN32_GDI_FAILED ("GetRegionData");
1538 rgndata = (RGNDATA *) g_malloc (nbytes);
1540 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1542 WIN32_GDI_FAILED ("GetRegionData");
1547 result = cairo_region_create ();
1548 rects = (RECT *) rgndata->Buffer;
1549 for (i = 0; i < rgndata->rdh.nCount; i++)
1553 r.x = rects[i].left;
1555 r.width = rects[i].right - r.x;
1556 r.height = rects[i].bottom - r.y;
1558 cairo_region_union_rectangle (result, &r);
1567 adjust_drag (LONG *drag,
1572 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1574 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1578 handle_wm_paint (MSG *msg,
1580 gboolean return_exposes,
1583 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1585 PAINTSTRUCT paintstruct;
1586 cairo_region_t *update_region;
1588 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1590 WIN32_GDI_FAILED ("GetUpdateRgn");
1591 DeleteObject (hrgn);
1595 hdc = BeginPaint (msg->hwnd, &paintstruct);
1597 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1598 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1599 (paintstruct.fErase ? "erase" : ""),
1601 (return_exposes ? " return_exposes" : "")));
1603 EndPaint (msg->hwnd, &paintstruct);
1605 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1606 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1608 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1609 DeleteObject (hrgn);
1615 if (!GDK_WINDOW_DESTROYED (window))
1617 GList *list = _gdk_display->queued_events;
1619 *event = gdk_event_new (GDK_EXPOSE);
1620 (*event)->expose.window = window;
1621 (*event)->expose.area.x = paintstruct.rcPaint.left;
1622 (*event)->expose.area.y = paintstruct.rcPaint.top;
1623 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1624 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1625 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1626 (*event)->expose.count = 0;
1628 while (list != NULL)
1630 GdkEventPrivate *evp = list->data;
1632 if (evp->event.any.type == GDK_EXPOSE &&
1633 evp->event.any.window == window &&
1634 !(evp->flags & GDK_EVENT_PENDING))
1635 evp->event.expose.count++;
1641 DeleteObject (hrgn);
1645 update_region = _gdk_win32_hrgn_to_region (hrgn);
1646 if (!cairo_region_is_empty (update_region))
1647 _gdk_window_invalidate_for_expose (window, update_region);
1648 cairo_region_destroy (update_region);
1650 DeleteObject (hrgn);
1653 static VOID CALLBACK
1654 modal_timer_proc (HWND hwnd,
1659 int arbitrary_limit = 10;
1661 while (_modal_operation_in_progress &&
1662 g_main_context_pending (NULL) &&
1664 g_main_context_iteration (NULL, FALSE);
1668 _gdk_win32_begin_modal_call (void)
1670 g_assert (!_modal_operation_in_progress);
1672 _modal_operation_in_progress = TRUE;
1674 modal_timer = SetTimer (NULL, 0, 10, modal_timer_proc);
1675 if (modal_timer == 0)
1676 WIN32_API_FAILED ("SetTimer");
1680 _gdk_win32_end_modal_call (void)
1682 g_assert (_modal_operation_in_progress);
1684 _modal_operation_in_progress = FALSE;
1686 if (modal_timer != 0)
1688 API_CALL (KillTimer, (NULL, modal_timer));
1693 static VOID CALLBACK
1694 sync_timer_proc (HWND hwnd,
1700 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1705 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1707 KillTimer (hwnd, sync_timer);
1711 handle_display_change (void)
1713 _gdk_monitor_init ();
1714 _gdk_root_window_size_init ();
1715 g_signal_emit_by_name (_gdk_screen, "size_changed");
1719 generate_button_event (GdkEventType type,
1724 GdkEvent *event = gdk_event_new (type);
1726 event->button.window = window;
1727 event->button.time = _gdk_win32_get_next_tick (msg->time);
1728 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1729 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1730 event->button.x_root = msg->pt.x + _gdk_offset_x;
1731 event->button.y_root = msg->pt.y + _gdk_offset_y;
1732 event->button.axes = NULL;
1733 event->button.state = build_pointer_event_state (msg);
1734 event->button.button = button;
1735 gdk_event_set_device (event, _gdk_display->core_pointer);
1737 _gdk_win32_append_event (event);
1741 ensure_stacking_on_unminimize (MSG *msg)
1744 HWND lowest_transient = NULL;
1747 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1749 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1751 /* Checking window group not implemented yet */
1754 GdkWindowImplWin32 *rover_impl =
1755 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1757 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1758 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1759 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1760 rover_impl->transient_owner != NULL))
1762 lowest_transient = rover;
1766 if (lowest_transient != NULL)
1768 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1769 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1770 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1775 ensure_stacking_on_window_pos_changing (MSG *msg,
1778 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1779 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1781 if (GetActiveWindow () == msg->hwnd &&
1782 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1783 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1784 impl->transient_owner == NULL)
1786 /* Make sure the window stays behind any transient-type windows
1787 * of the same window group.
1789 * If the window is not active and being activated, we let
1790 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1791 * handling to bring any utility windows on top of it.
1794 gboolean restacking;
1796 rover = windowpos->hwndInsertAfter;
1800 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1802 /* Checking window group not implemented yet */
1805 GdkWindowImplWin32 *rover_impl =
1806 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1808 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1809 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1810 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1811 rover_impl->transient_owner != NULL))
1814 windowpos->hwndInsertAfter = rover;
1817 rover = GetNextWindow (rover, GW_HWNDNEXT);
1822 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1830 ensure_stacking_on_activate_app (MSG *msg,
1833 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1835 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1836 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1837 impl->transient_owner != NULL)
1839 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1840 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1844 if (IsWindowVisible (msg->hwnd) &&
1845 msg->hwnd == GetActiveWindow ())
1847 /* This window is not a transient-type window and it is the
1848 * activated window. Make sure this window is as visible as
1849 * possible, just below the lowest transient-type window of this
1855 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
1857 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1859 /* Checking window group not implemented yet */
1862 GdkWindowImplWin32 *rover_impl =
1863 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1865 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1866 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1867 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1868 rover_impl->transient_owner != NULL))
1870 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1871 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1872 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1880 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
1881 GDK_BUTTON2_MASK | \
1882 GDK_BUTTON3_MASK | \
1883 GDK_BUTTON4_MASK | \
1887 gdk_event_translate (MSG *msg,
1890 RECT rect, *drag, orig_drag;
1895 BYTE key_state[256];
1897 WINDOWPOS *windowpos;
1904 GdkWindow *window = NULL;
1905 GdkWindowImplWin32 *impl;
1907 GdkWindow *orig_window, *new_window;
1909 GdkDeviceManager *device_manager;
1911 GdkDeviceGrabInfo *keyboard_grab = NULL;
1912 GdkDeviceGrabInfo *pointer_grab = NULL;
1913 GdkWindow *grab_window = NULL;
1919 gboolean return_val = FALSE;
1923 if (_gdk_default_filters)
1925 /* Apply global filters */
1927 GdkFilterReturn result = apply_event_filters (NULL, msg, &_gdk_default_filters);
1929 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1930 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1931 * we return TRUE, and DefWindowProcW() will not be called.
1933 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1937 window = gdk_win32_handle_table_lookup (msg->hwnd);
1938 orig_window = window;
1942 /* XXX Handle WM_QUIT here ? */
1943 if (msg->message == WM_QUIT)
1945 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1948 else if (msg->message == WM_CREATE)
1950 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1951 GDK_WINDOW_HWND (window) = msg->hwnd;
1955 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1960 device_manager = gdk_display_get_device_manager (_gdk_display);
1962 keyboard_grab = _gdk_display_get_last_device_grab (_gdk_display,
1963 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
1964 pointer_grab = _gdk_display_get_last_device_grab (_gdk_display,
1965 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer);
1967 g_object_ref (window);
1969 /* window's refcount has now been increased, so code below should
1970 * not just return from this function, but instead goto done (or
1971 * break out of the big switch). To protect against forgetting this,
1972 * #define return to a syntax error...
1974 #define return GOTO_DONE_INSTEAD
1976 if (!GDK_WINDOW_DESTROYED (window) && window->filters)
1978 /* Apply per-window filters */
1980 GdkFilterReturn result = apply_event_filters (window, msg, &window->filters);
1982 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1989 if (msg->message == client_message)
1992 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1995 GDK_NOTE (EVENTS, g_print (" client_message"));
1997 event = gdk_event_new (GDK_NOTHING);
1998 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2000 node = _gdk_event_queue_append (_gdk_display, event);
2002 tmp_list = client_filters;
2005 GdkClientFilter *filter = tmp_list->data;
2007 tmp_list = tmp_list->next;
2009 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
2011 GDK_NOTE (EVENTS, g_print (" (match)"));
2013 result = (*filter->function) (msg, event, filter->data);
2015 if (result != GDK_FILTER_CONTINUE)
2022 case GDK_FILTER_REMOVE:
2023 _gdk_event_queue_remove_link (_gdk_display, node);
2024 g_list_free_1 (node);
2025 gdk_event_free (event);
2029 case GDK_FILTER_TRANSLATE:
2030 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2031 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2035 case GDK_FILTER_CONTINUE:
2036 /* No more: Send unknown client messages on to Gtk for it to use */
2037 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2043 switch (msg->message)
2045 case WM_INPUTLANGCHANGE:
2046 _gdk_input_locale = (HKL) msg->lParam;
2047 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
2048 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
2049 LOCALE_IDEFAULTANSICODEPAGE,
2051 _gdk_input_codepage = atoi (buf);
2052 _gdk_keymap_serial++;
2054 g_print (" cs:%lu hkl:%p%s cp:%d",
2055 (gulong) msg->wParam,
2056 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
2057 _gdk_input_codepage));
2063 g_print (" %s ch:%.02x %s",
2064 _gdk_win32_key_to_string (msg->lParam),
2066 decode_key_lparam (msg->lParam)));
2068 /* If posted without us having keyboard focus, ignore */
2069 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
2070 !(HIWORD (msg->lParam) & KF_ALTDOWN))
2073 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
2074 * the keyboard is grabbed.
2076 if (!keyboard_grab &&
2077 (msg->wParam == VK_TAB ||
2078 msg->wParam == VK_SPACE ||
2079 msg->wParam == VK_F4))
2082 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
2088 g_print (" %s ch:%.02x %s",
2089 _gdk_win32_key_to_string (msg->lParam),
2091 decode_key_lparam (msg->lParam)));
2095 /* Ignore key messages intended for the IME */
2096 if (msg->wParam == VK_PROCESSKEY ||
2100 if (keyboard_grab &&
2101 !propagate (&window, msg,
2102 keyboard_grab->window,
2103 keyboard_grab->owner_events,
2104 GDK_ALL_EVENTS_MASK,
2105 doesnt_want_key, FALSE))
2108 if (GDK_WINDOW_DESTROYED (window))
2111 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
2112 msg->message == WM_SYSKEYDOWN) ?
2113 GDK_KEY_PRESS : GDK_KEY_RELEASE);
2114 event->key.window = window;
2115 event->key.time = _gdk_win32_get_next_tick (msg->time);
2116 event->key.keyval = GDK_KEY_VoidSymbol;
2117 event->key.string = NULL;
2118 event->key.length = 0;
2119 event->key.hardware_keycode = msg->wParam;
2120 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2121 if (HIWORD (msg->lParam) & KF_EXTENDED)
2123 switch (msg->wParam)
2126 event->key.hardware_keycode = VK_RCONTROL;
2128 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
2129 * for the right shift key.
2131 event->key.hardware_keycode = VK_RSHIFT;
2134 event->key.hardware_keycode = VK_RMENU;
2138 else if (msg->wParam == VK_SHIFT &&
2139 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
2140 event->key.hardware_keycode = VK_RSHIFT;
2142 API_CALL (GetKeyboardState, (key_state));
2144 /* 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]); */
2146 build_key_event_state (event, key_state);
2148 if (msg->wParam == VK_PACKET &&
2149 ToUnicode (VK_PACKET, HIWORD (msg->lParam), key_state, wbuf, 1, 0) == 1)
2150 event->key.keyval = gdk_unicode_to_keyval (wbuf[0]);
2152 gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (_gdk_display),
2153 event->key.hardware_keycode,
2159 fill_key_event_string (event);
2161 /* Reset MOD1_MASK if it is the Alt key itself */
2162 if (msg->wParam == VK_MENU)
2163 event->key.state &= ~GDK_MOD1_MASK;
2165 _gdk_win32_append_event (event);
2171 if (msg->wParam != VK_SPACE)
2173 /* To prevent beeps, don't let DefWindowProcW() be called */
2179 case WM_IME_STARTCOMPOSITION:
2180 in_ime_composition = TRUE;
2183 case WM_IME_ENDCOMPOSITION:
2184 in_ime_composition = FALSE;
2187 case WM_IME_COMPOSITION:
2188 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2189 * applications. Thus, handle WM_IME_COMPOSITION with
2190 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2191 * with ImmGetCompositionStringW().
2194 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2196 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2197 * for comments by other people that seems to have the same
2198 * experience. WM_IME_CHAR just gives question marks, apparently
2199 * because of going through some conversion to the current code
2202 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2203 * use WM_IME_COMPOSITION there, too, to simplify the code.
2205 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2207 if (!(msg->lParam & GCS_RESULTSTR))
2210 if (keyboard_grab &&
2211 !propagate (&window, msg,
2212 keyboard_grab->window,
2213 keyboard_grab->owner_events,
2214 GDK_ALL_EVENTS_MASK,
2215 doesnt_want_char, FALSE))
2218 if (GDK_WINDOW_DESTROYED (window))
2221 himc = ImmGetContext (msg->hwnd);
2222 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2223 wbuf, sizeof (wbuf));
2224 ImmReleaseContext (msg->hwnd, himc);
2228 API_CALL (GetKeyboardState, (key_state));
2230 for (i = 0; i < ccount; i++)
2232 if (window->event_mask & GDK_KEY_PRESS_MASK)
2234 /* Build a key press event */
2235 event = gdk_event_new (GDK_KEY_PRESS);
2236 event->key.window = window;
2237 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2238 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2240 _gdk_win32_append_event (event);
2243 if (window->event_mask & GDK_KEY_RELEASE_MASK)
2245 /* Build a key release event. */
2246 event = gdk_event_new (GDK_KEY_RELEASE);
2247 event->key.window = window;
2248 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2249 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2251 _gdk_win32_append_event (event);
2257 case WM_LBUTTONDOWN:
2261 case WM_MBUTTONDOWN:
2265 case WM_RBUTTONDOWN:
2269 case WM_XBUTTONDOWN:
2270 if (HIWORD (msg->wParam) == XBUTTON1)
2277 g_print (" (%d,%d)",
2278 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2280 assign_object (&window, find_window_for_mouse_event (window, msg));
2281 /* TODO_CSW?: there used to some synthesize and propagate */
2282 if (GDK_WINDOW_DESTROYED (window))
2285 if (pointer_grab == NULL)
2287 SetCapture (GDK_WINDOW_HWND (window));
2290 generate_button_event (GDK_BUTTON_PRESS, button,
2309 if (HIWORD (msg->wParam) == XBUTTON1)
2316 g_print (" (%d,%d)",
2317 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2319 assign_object (&window, find_window_for_mouse_event (window, msg));
2321 if (window->extension_events != 0 &&
2322 _gdk_input_ignore_core)
2324 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2329 if (pointer_grab != NULL && pointer_grab->implicit)
2331 gint state = build_pointer_event_state (msg);
2333 /* We keep the implicit grab until no buttons at all are held down */
2334 if ((state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (button - 1))) == 0)
2339 hwnd = WindowFromPoint (msg->pt);
2342 POINT client_pt = msg->pt;
2344 ScreenToClient (hwnd, &client_pt);
2345 GetClientRect (hwnd, &rect);
2346 if (PtInRect (&rect, client_pt))
2347 new_window = gdk_win32_handle_table_lookup (hwnd);
2349 synthesize_crossing_events (_gdk_display,
2350 pointer_grab->native_window, new_window,
2351 GDK_CROSSING_UNGRAB,
2353 0, /* TODO: Set right mask */
2356 assign_object (&mouse_window, new_window);
2360 generate_button_event (GDK_BUTTON_RELEASE, button,
2368 g_print (" %p (%d,%d)",
2369 (gpointer) msg->wParam,
2370 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2372 new_window = window;
2374 if (pointer_grab != NULL)
2380 hwnd = WindowFromPoint (pt);
2383 POINT client_pt = pt;
2385 ScreenToClient (hwnd, &client_pt);
2386 GetClientRect (hwnd, &rect);
2387 if (PtInRect (&rect, client_pt))
2388 new_window = gdk_win32_handle_table_lookup (hwnd);
2391 if (!pointer_grab->owner_events &&
2392 new_window != NULL &&
2393 new_window != pointer_grab->native_window)
2397 if (mouse_window != new_window)
2399 GDK_NOTE (EVENTS, g_print (" mouse_sinwod %p -> %p",
2400 mouse_window ? GDK_WINDOW_HWND (mouse_window) : NULL,
2401 new_window ? GDK_WINDOW_HWND (new_window) : NULL));
2402 synthesize_crossing_events (_gdk_display,
2403 mouse_window, new_window,
2404 GDK_CROSSING_NORMAL,
2406 0, /* TODO: Set right mask */
2409 assign_object (&mouse_window, new_window);
2410 if (new_window != NULL)
2411 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (new_window));
2414 assign_object (&window, find_window_for_mouse_event (window, msg));
2416 /* If we haven't moved, don't create any GDK event. Windows
2417 * sends WM_MOUSEMOVE messages after a new window is shows under
2418 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2420 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2421 msg->pt.y + _gdk_offset_y == current_root_y)
2424 current_root_x = msg->pt.x + _gdk_offset_x;
2425 current_root_y = msg->pt.y + _gdk_offset_y;
2427 event = gdk_event_new (GDK_MOTION_NOTIFY);
2428 event->motion.window = window;
2429 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2430 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2431 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2432 event->motion.x_root = current_root_x;
2433 event->motion.y_root = current_root_y;
2434 event->motion.axes = NULL;
2435 event->motion.state = build_pointer_event_state (msg);
2436 event->motion.is_hint = FALSE;
2437 gdk_event_set_device (event, _gdk_display->core_pointer);
2439 _gdk_win32_append_event (event);
2444 case WM_NCMOUSEMOVE:
2446 g_print (" (%d,%d)",
2447 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2451 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2452 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2455 hwnd = WindowFromPoint (msg->pt);
2458 POINT client_pt = msg->pt;
2460 ScreenToClient (hwnd, &client_pt);
2461 GetClientRect (hwnd, &rect);
2462 if (PtInRect (&rect, client_pt))
2463 new_window = gdk_win32_handle_table_lookup (hwnd);
2466 synthesize_crossing_events (_gdk_display,
2467 mouse_window, new_window,
2468 GDK_CROSSING_NORMAL,
2470 0, /* TODO: Set right mask */
2473 assign_object (&mouse_window, new_window);
2479 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2481 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2482 * that. Also, the position is in screen coordinates, not client
2483 * coordinates as with the button messages. I love the
2484 * consistency of Windows.
2486 point.x = GET_X_LPARAM (msg->lParam);
2487 point.y = GET_Y_LPARAM (msg->lParam);
2489 if ((hwnd = WindowFromPoint (point)) == NULL)
2493 if ((new_window = gdk_win32_handle_table_lookup (msg->hwnd)) == NULL)
2496 if (new_window != window)
2498 assign_object (&window, new_window);
2501 ScreenToClient (msg->hwnd, &point);
2503 event = gdk_event_new (GDK_SCROLL);
2504 event->scroll.window = window;
2505 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2506 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2507 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2508 event->scroll.x = (gint16) point.x;
2509 event->scroll.y = (gint16) point.y;
2510 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2511 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2512 event->scroll.state = build_pointer_event_state (msg);
2513 gdk_event_set_device (event, _gdk_display->core_pointer);
2515 _gdk_win32_append_event (event);
2521 /* Just print more debugging information, don't actually handle it. */
2524 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2525 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2526 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2527 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2528 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2529 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2530 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2531 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2532 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2534 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2535 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2536 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2540 /* Just print more debugging information, don't actually handle it. */
2543 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2544 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2545 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2546 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2547 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2548 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2549 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2550 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2551 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2553 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2554 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2555 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2558 case WM_MOUSEACTIVATE:
2562 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2563 || !window->accept_focus)
2565 *ret_valp = MA_NOACTIVATE;
2569 tmp = _gdk_modal_current ();
2573 if (gdk_window_get_toplevel (window) != tmp)
2575 *ret_valp = MA_NOACTIVATEANDEAT;
2584 if (keyboard_grab != NULL &&
2585 !GDK_WINDOW_DESTROYED (keyboard_grab->window))
2587 generate_grab_broken_event (device_manager, keyboard_grab->window, TRUE, NULL);
2592 if (keyboard_grab != NULL &&
2593 !keyboard_grab->owner_events)
2596 if (!(window->event_mask & GDK_FOCUS_CHANGE_MASK))
2599 if (GDK_WINDOW_DESTROYED (window))
2602 generate_focus_event (device_manager, window, (msg->message == WM_SETFOCUS));
2607 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2609 if (GDK_WINDOW_DESTROYED (window))
2617 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2619 200, sync_timer_proc);
2623 handle_wm_paint (msg, window, FALSE, NULL);
2627 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2628 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2630 if (pointer_grab != NULL)
2631 grab_window = pointer_grab->window;
2633 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2636 if (grab_window != NULL && p_grab_cursor != NULL)
2637 hcursor = p_grab_cursor;
2638 else if (!GDK_WINDOW_DESTROYED (window))
2639 hcursor = GDK_WINDOW_IMPL_WIN32 (window->impl)->hcursor;
2643 if (hcursor != NULL)
2645 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2646 SetCursor (hcursor);
2653 switch (msg->wParam)
2657 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2663 case WM_ENTERSIZEMOVE:
2664 case WM_ENTERMENULOOP:
2665 if (msg->message == WM_ENTERSIZEMOVE)
2666 _modal_move_resize_window = msg->hwnd;
2668 _gdk_win32_begin_modal_call ();
2671 case WM_EXITSIZEMOVE:
2672 case WM_EXITMENULOOP:
2673 if (_modal_operation_in_progress)
2675 _modal_move_resize_window = NULL;
2676 _gdk_win32_end_modal_call ();
2680 case WM_CAPTURECHANGED:
2681 /* Sometimes we don't get WM_EXITSIZEMOVE, for instance when you
2682 select move/size in the menu and then click somewhere without
2683 moving/resizing. We work around this using WM_CAPTURECHANGED. */
2684 if (_modal_operation_in_progress)
2686 _modal_move_resize_window = NULL;
2687 _gdk_win32_end_modal_call ();
2691 case WM_WINDOWPOSCHANGING:
2692 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2693 g_print (" %s %s %dx%d@%+d%+d now below %p",
2694 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2695 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2696 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2697 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2698 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2699 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2701 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2702 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2704 if (GDK_WINDOW_IS_MAPPED (window))
2705 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2708 case WM_WINDOWPOSCHANGED:
2709 windowpos = (WINDOWPOS *) msg->lParam;
2710 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2711 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2712 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2713 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2714 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2715 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2716 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2718 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2720 /* Break grabs on unmap or minimize */
2721 if (windowpos->flags & SWP_HIDEWINDOW ||
2722 ((windowpos->flags & SWP_STATECHANGED) && IsIconic (msg->hwnd)))
2724 if (pointer_grab != NULL)
2726 if (pointer_grab->window == window)
2727 gdk_pointer_ungrab (msg->time);
2730 if (keyboard_grab->window == window)
2731 gdk_keyboard_ungrab (msg->time);
2734 /* Send MAP events */
2735 if ((windowpos->flags & SWP_SHOWWINDOW) &&
2736 !GDK_WINDOW_DESTROYED (window))
2738 event = gdk_event_new (GDK_MAP);
2739 event->any.window = window;
2740 _gdk_win32_append_event (event);
2743 /* Update window state */
2744 if (windowpos->flags & (SWP_STATECHANGED | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
2746 GdkWindowState set_bits, unset_bits, old_state, new_state;
2748 old_state = window->state;
2753 if (IsWindowVisible (msg->hwnd))
2754 unset_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2756 set_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2758 if (IsIconic (msg->hwnd))
2759 set_bits |= GDK_WINDOW_STATE_ICONIFIED;
2761 unset_bits |= GDK_WINDOW_STATE_ICONIFIED;
2763 if (IsZoomed (msg->hwnd))
2764 set_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2766 unset_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2768 gdk_synthesize_window_state (window, unset_bits, set_bits);
2770 new_state = window->state;
2772 /* Whenever one window changes iconified state we need to also
2773 * change the iconified state in all transient related windows,
2774 * as windows doesn't give icons for transient childrens.
2776 if ((old_state & GDK_WINDOW_STATE_ICONIFIED) !=
2777 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2778 do_show_window (window, (new_state & GDK_WINDOW_STATE_ICONIFIED));
2781 /* When un-minimizing, make sure we're stacked under any
2782 transient-type windows. */
2783 if (!(old_state & GDK_WINDOW_STATE_ICONIFIED) &&
2784 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2785 ensure_stacking_on_unminimize (msg);
2788 /* Show, New size or position => configure event */
2789 if (!(windowpos->flags & SWP_NOCLIENTMOVE) ||
2790 !(windowpos->flags & SWP_NOCLIENTSIZE) ||
2791 (windowpos->flags & SWP_SHOWWINDOW))
2793 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2794 !IsIconic (msg->hwnd) &&
2795 !GDK_WINDOW_DESTROYED (window))
2796 _gdk_win32_emit_configure_event (window);
2798 if (window->extension_events != 0)
2799 _gdk_device_wintab_update_window_coords (window);
2802 if ((windowpos->flags & SWP_HIDEWINDOW) &&
2803 !GDK_WINDOW_DESTROYED (window))
2805 /* Send UNMAP events */
2806 event = gdk_event_new (GDK_UNMAP);
2807 event->any.window = window;
2808 _gdk_win32_append_event (event);
2810 /* Make transient parent the forground window when window unmaps */
2811 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2813 if (impl->transient_owner &&
2814 GetForegroundWindow () == GDK_WINDOW_HWND (window))
2815 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2818 if (!(windowpos->flags & SWP_NOCLIENTSIZE))
2820 if (window->resize_count > 1)
2821 window->resize_count -= 1;
2824 /* Call modal timer immediate so that we repaint faster after a resize. */
2825 if (_modal_operation_in_progress)
2826 modal_timer_proc (0,0,0,0);
2828 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2834 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2835 drag = (RECT *) msg->lParam;
2836 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2837 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2838 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2839 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2840 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2841 (msg->wParam == WMSZ_TOP ? "TOP" :
2842 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2843 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2845 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2847 _gdk_win32_rect_to_string (&rect),
2848 _gdk_win32_rect_to_string (drag)));
2850 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2852 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2854 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2855 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2857 /* Resize in increments relative to the base size */
2858 rect.left = rect.top = 0;
2859 rect.right = impl->hints.base_width;
2860 rect.bottom = impl->hints.base_height;
2861 _gdk_win32_adjust_client_rect (window, &rect);
2862 point.x = rect.left;
2864 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2865 rect.left = point.x;
2867 point.x = rect.right;
2868 point.y = rect.bottom;
2869 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2870 rect.right = point.x;
2871 rect.bottom = point.y;
2873 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2874 _gdk_win32_rect_to_string (&rect)));
2877 switch (msg->wParam)
2880 if (drag->bottom == rect.bottom)
2882 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2885 case WMSZ_BOTTOMLEFT:
2886 if (drag->bottom == rect.bottom && drag->left == rect.left)
2888 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2889 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2893 if (drag->left == rect.left)
2895 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2899 if (drag->top == rect.top && drag->left == rect.left)
2901 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2902 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2906 if (drag->top == rect.top)
2908 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2912 if (drag->top == rect.top && drag->right == rect.right)
2914 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2915 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2919 if (drag->right == rect.right)
2921 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2924 case WMSZ_BOTTOMRIGHT:
2925 if (drag->bottom == rect.bottom && drag->right == rect.right)
2927 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2928 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2932 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2933 drag->top != orig_drag.top || drag->right != orig_drag.right)
2937 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2938 _gdk_win32_rect_to_string (drag)));
2942 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2944 if (impl->hint_flags & GDK_HINT_ASPECT)
2946 RECT decorated_rect;
2947 RECT undecorated_drag;
2948 int decoration_width, decoration_height;
2949 gdouble drag_aspect;
2950 int drag_width, drag_height, new_width, new_height;
2952 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2953 decorated_rect = rect;
2954 _gdk_win32_adjust_client_rect (window, &decorated_rect);
2956 /* Set undecorated_drag to the client area being dragged
2957 * out, in screen coordinates.
2959 undecorated_drag = *drag;
2960 undecorated_drag.left -= decorated_rect.left - rect.left;
2961 undecorated_drag.right -= decorated_rect.right - rect.right;
2962 undecorated_drag.top -= decorated_rect.top - rect.top;
2963 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
2965 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
2966 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
2968 drag_width = undecorated_drag.right - undecorated_drag.left;
2969 drag_height = undecorated_drag.bottom - undecorated_drag.top;
2971 drag_aspect = (gdouble) drag_width / drag_height;
2973 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
2974 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
2976 if (drag_aspect < impl->hints.min_aspect)
2978 /* Aspect is getting too narrow */
2979 switch (msg->wParam)
2983 /* User drags top or bottom edge outward. Keep height, increase width. */
2984 new_width = impl->hints.min_aspect * drag_height;
2985 drag->left -= (new_width - drag_width) / 2;
2986 drag->right = drag->left + new_width + decoration_width;
2988 case WMSZ_BOTTOMLEFT:
2989 case WMSZ_BOTTOMRIGHT:
2990 /* User drags bottom-left or bottom-right corner down. Adjust height. */
2991 new_height = drag_width / impl->hints.min_aspect;
2992 drag->bottom = drag->top + new_height + decoration_height;
2996 /* User drags left or right edge inward. Decrease height */
2997 new_height = drag_width / impl->hints.min_aspect;
2998 drag->top += (drag_height - new_height) / 2;
2999 drag->bottom = drag->top + new_height + decoration_height;
3003 /* User drags top-left or top-right corner up. Adjust height. */
3004 new_height = drag_width / impl->hints.min_aspect;
3005 drag->top = drag->bottom - new_height - decoration_height;
3008 else if (drag_aspect > impl->hints.max_aspect)
3010 /* Aspect is getting too wide */
3011 switch (msg->wParam)
3015 /* User drags top or bottom edge inward. Decrease width. */
3016 new_width = impl->hints.max_aspect * drag_height;
3017 drag->left += (drag_width - new_width) / 2;
3018 drag->right = drag->left + new_width + decoration_width;
3020 case WMSZ_BOTTOMLEFT:
3022 /* User drags bottom-left or top-left corner left. Adjust width. */
3023 new_width = impl->hints.max_aspect * drag_height;
3024 drag->left = drag->right - new_width - decoration_width;
3026 case WMSZ_BOTTOMRIGHT:
3028 /* User drags bottom-right or top-right corner right. Adjust width. */
3029 new_width = impl->hints.max_aspect * drag_height;
3030 drag->right = drag->left + new_width + decoration_width;
3034 /* User drags left or right edge outward. Increase height. */
3035 new_height = drag_width / impl->hints.max_aspect;
3036 drag->top -= (new_height - drag_height) / 2;
3037 drag->bottom = drag->top + new_height + decoration_height;
3044 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
3045 _gdk_win32_rect_to_string (drag)));
3049 case WM_GETMINMAXINFO:
3050 if (GDK_WINDOW_DESTROYED (window))
3053 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3054 mmi = (MINMAXINFO*) msg->lParam;
3055 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
3056 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3057 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3058 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3059 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3060 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3062 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
3064 rect.left = rect.top = 0;
3065 rect.right = impl->hints.min_width;
3066 rect.bottom = impl->hints.min_height;
3068 _gdk_win32_adjust_client_rect (window, &rect);
3070 mmi->ptMinTrackSize.x = rect.right - rect.left;
3071 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
3074 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
3078 rect.left = rect.top = 0;
3079 rect.right = impl->hints.max_width;
3080 rect.bottom = impl->hints.max_height;
3082 _gdk_win32_adjust_client_rect (window, &rect);
3084 /* at least on win9x we have the 16 bit trouble */
3085 maxw = rect.right - rect.left;
3086 maxh = rect.bottom - rect.top;
3087 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
3088 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
3091 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
3093 /* Don't call DefWindowProcW() */
3094 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
3095 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3096 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3097 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3098 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3099 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3102 mmi->ptMaxTrackSize.x = 30000;
3103 mmi->ptMaxTrackSize.y = 30000;
3108 if (GDK_WINDOW_DESTROYED (window))
3111 event = gdk_event_new (GDK_DELETE);
3112 event->any.window = window;
3114 _gdk_win32_append_event (event);
3116 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3118 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
3120 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3127 if (pointer_grab != NULL)
3129 if (pointer_grab->window == window)
3130 gdk_pointer_ungrab (msg->time);
3133 if (keyboard_grab &&
3134 keyboard_grab->window == window)
3135 gdk_keyboard_ungrab (msg->time);
3137 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
3138 gdk_window_destroy_notify (window);
3140 if (window == NULL || GDK_WINDOW_DESTROYED (window))
3143 event = gdk_event_new (GDK_DESTROY);
3144 event->any.window = window;
3146 _gdk_win32_append_event (event);
3151 case WM_DISPLAYCHANGE:
3152 handle_display_change ();
3155 case WM_DESTROYCLIPBOARD:
3156 if (!_ignore_destroy_clipboard)
3158 event = gdk_event_new (GDK_SELECTION_CLEAR);
3159 event->selection.window = window;
3160 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3161 event->selection.time = _gdk_win32_get_next_tick (msg->time);
3162 _gdk_win32_append_event (event);
3171 case WM_RENDERFORMAT:
3172 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
3174 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
3176 GDK_NOTE (EVENTS, g_print (" (target not found)"));
3181 /* We need to render to clipboard immediately, don't call
3182 * _gdk_win32_append_event()
3184 event = gdk_event_new (GDK_SELECTION_REQUEST);
3185 event->selection.window = window;
3186 event->selection.send_event = FALSE;
3187 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3188 event->selection.target = target;
3189 event->selection.property = _gdk_selection;
3190 event->selection.requestor = gdk_win32_handle_table_lookup (msg->hwnd);
3191 event->selection.time = msg->time;
3193 fixup_event (event);
3194 GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)"));
3195 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
3196 _gdk_event_emit (event);
3197 gdk_event_free (event);
3199 /* Now the clipboard owner should have rendered */
3200 if (!_delayed_rendering_data)
3202 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3206 if (msg->wParam == CF_DIB)
3208 _delayed_rendering_data =
3209 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3211 if (!_delayed_rendering_data)
3213 g_warning ("Cannot convert to DIB from delayed rendered image");
3218 /* The requestor is holding the clipboard, no
3219 * OpenClipboard() is required/possible
3222 g_print (" SetClipboardData(%s,%p)",
3223 _gdk_win32_cf_to_string (msg->wParam),
3224 _delayed_rendering_data));
3226 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3227 _delayed_rendering_data = NULL;
3232 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3233 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3234 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3235 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3236 HIWORD (msg->wParam) ? " minimized" : "",
3237 (HWND) msg->lParam));
3238 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3239 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3242 if (is_modally_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3244 GdkWindow *modal_current = _gdk_modal_current ();
3245 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3251 /* Bring any tablet contexts to the top of the overlap order when
3252 * one of our windows is activated.
3253 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3256 if (LOWORD(msg->wParam) != WA_INACTIVE)
3257 _gdk_input_set_tablet_active ();
3260 case WM_ACTIVATEAPP:
3261 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3262 msg->wParam ? "YES" : "NO",
3263 (gint64) msg->lParam));
3264 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3265 ensure_stacking_on_activate_app (msg, window);
3268 /* Handle WINTAB events here, as we know that gdkinput.c will
3269 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3270 * constants as case labels.
3273 GDK_NOTE (EVENTS, g_print (" %d %p",
3274 (int) msg->wParam, (gpointer) msg->lParam));
3278 GDK_NOTE (EVENTS, g_print (" %d %p",
3279 (int) msg->wParam, (gpointer) msg->lParam));
3283 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3284 (gpointer) msg->wParam,
3285 LOWORD (msg->lParam),
3286 HIWORD (msg->lParam)));
3290 event = gdk_event_new (GDK_NOTHING);
3291 event->any.window = window;
3292 g_object_ref (window);
3294 if (_gdk_input_other_event (event, msg, window))
3295 _gdk_win32_append_event (event);
3297 gdk_event_free (event);
3305 g_object_unref (window);
3312 _gdk_win32_display_queue_events (GdkDisplay *display)
3316 if (modal_win32_dialog != NULL)
3319 while (!_gdk_event_queue_find_first (display) &&
3320 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3322 TranslateMessage (&msg);
3323 DispatchMessageW (&msg);
3328 gdk_event_prepare (GSource *source,
3333 GDK_THREADS_ENTER ();
3337 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3338 (modal_win32_dialog == NULL &&
3339 GetQueueStatus (QS_ALLINPUT) != 0));
3341 GDK_THREADS_LEAVE ();
3347 gdk_event_check (GSource *source)
3351 GDK_THREADS_ENTER ();
3353 if (event_poll_fd.revents & G_IO_IN)
3355 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3356 (modal_win32_dialog == NULL &&
3357 GetQueueStatus (QS_ALLINPUT) != 0));
3364 GDK_THREADS_LEAVE ();
3370 gdk_event_dispatch (GSource *source,
3371 GSourceFunc callback,
3376 GDK_THREADS_ENTER ();
3378 _gdk_win32_display_queue_events (_gdk_display);
3379 event = _gdk_event_unqueue (_gdk_display);
3383 _gdk_event_emit (event);
3385 gdk_event_free (event);
3387 /* Do drag & drop if it is still pending */
3388 if (_dnd_source_state == GDK_WIN32_DND_PENDING)
3390 _dnd_source_state = GDK_WIN32_DND_DRAGGING;
3391 _gdk_win32_dnd_do_dragdrop ();
3392 _dnd_source_state = GDK_WIN32_DND_NONE;
3396 GDK_THREADS_LEAVE ();
3402 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3404 modal_win32_dialog = window;
3408 is_modally_blocked (GdkWindow *window)
3410 GdkWindow *modal_current = _gdk_modal_current ();
3411 return modal_current != NULL ? gdk_window_get_toplevel (window) != modal_current : FALSE;
3415 _gdk_win32_display_sync (GdkDisplay * display)
3419 g_return_if_fail (display == _gdk_display);
3421 /* Process all messages currently available */
3422 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3423 DispatchMessageW (&msg);