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)
1481 GdkWindowImplWin32 *window_impl;
1486 window_impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1487 if (window_impl->inhibit_configure)
1490 hwnd = GDK_WINDOW_HWND (window);
1492 GetClientRect (hwnd, &client_rect);
1493 point.x = client_rect.left; /* always 0 */
1494 point.y = client_rect.top;
1496 /* top level windows need screen coords */
1497 if (gdk_window_get_parent (window) == _gdk_root)
1499 ClientToScreen (hwnd, &point);
1500 point.x += _gdk_offset_x;
1501 point.y += _gdk_offset_y;
1504 window->width = client_rect.right - client_rect.left;
1505 window->height = client_rect.bottom - client_rect.top;
1507 window->x = point.x;
1508 window->y = point.y;
1510 _gdk_window_update_size (window);
1512 if (window->event_mask & GDK_STRUCTURE_MASK)
1514 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1516 event->configure.window = window;
1518 event->configure.width = client_rect.right - client_rect.left;
1519 event->configure.height = client_rect.bottom - client_rect.top;
1521 event->configure.x = point.x;
1522 event->configure.y = point.y;
1524 _gdk_win32_append_event (event);
1529 _gdk_win32_hrgn_to_region (HRGN hrgn)
1533 cairo_region_t *result;
1537 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1539 WIN32_GDI_FAILED ("GetRegionData");
1543 rgndata = (RGNDATA *) g_malloc (nbytes);
1545 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1547 WIN32_GDI_FAILED ("GetRegionData");
1552 result = cairo_region_create ();
1553 rects = (RECT *) rgndata->Buffer;
1554 for (i = 0; i < rgndata->rdh.nCount; i++)
1558 r.x = rects[i].left;
1560 r.width = rects[i].right - r.x;
1561 r.height = rects[i].bottom - r.y;
1563 cairo_region_union_rectangle (result, &r);
1572 adjust_drag (LONG *drag,
1577 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1579 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1583 handle_wm_paint (MSG *msg,
1585 gboolean return_exposes,
1588 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1590 PAINTSTRUCT paintstruct;
1591 cairo_region_t *update_region;
1593 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1595 WIN32_GDI_FAILED ("GetUpdateRgn");
1596 DeleteObject (hrgn);
1600 hdc = BeginPaint (msg->hwnd, &paintstruct);
1602 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1603 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1604 (paintstruct.fErase ? "erase" : ""),
1606 (return_exposes ? " return_exposes" : "")));
1608 EndPaint (msg->hwnd, &paintstruct);
1610 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1611 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1613 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1614 DeleteObject (hrgn);
1620 if (!GDK_WINDOW_DESTROYED (window))
1622 GList *list = _gdk_display->queued_events;
1624 *event = gdk_event_new (GDK_EXPOSE);
1625 (*event)->expose.window = window;
1626 (*event)->expose.area.x = paintstruct.rcPaint.left;
1627 (*event)->expose.area.y = paintstruct.rcPaint.top;
1628 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1629 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1630 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1631 (*event)->expose.count = 0;
1633 while (list != NULL)
1635 GdkEventPrivate *evp = list->data;
1637 if (evp->event.any.type == GDK_EXPOSE &&
1638 evp->event.any.window == window &&
1639 !(evp->flags & GDK_EVENT_PENDING))
1640 evp->event.expose.count++;
1646 DeleteObject (hrgn);
1650 update_region = _gdk_win32_hrgn_to_region (hrgn);
1651 if (!cairo_region_is_empty (update_region))
1652 _gdk_window_invalidate_for_expose (window, update_region);
1653 cairo_region_destroy (update_region);
1655 DeleteObject (hrgn);
1658 static VOID CALLBACK
1659 modal_timer_proc (HWND hwnd,
1664 int arbitrary_limit = 10;
1666 while (_modal_operation_in_progress &&
1667 g_main_context_pending (NULL) &&
1669 g_main_context_iteration (NULL, FALSE);
1673 _gdk_win32_begin_modal_call (void)
1675 g_assert (!_modal_operation_in_progress);
1677 _modal_operation_in_progress = TRUE;
1679 modal_timer = SetTimer (NULL, 0, 10, modal_timer_proc);
1680 if (modal_timer == 0)
1681 WIN32_API_FAILED ("SetTimer");
1685 _gdk_win32_end_modal_call (void)
1687 g_assert (_modal_operation_in_progress);
1689 _modal_operation_in_progress = FALSE;
1691 if (modal_timer != 0)
1693 API_CALL (KillTimer, (NULL, modal_timer));
1698 static VOID CALLBACK
1699 sync_timer_proc (HWND hwnd,
1705 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1710 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1712 KillTimer (hwnd, sync_timer);
1716 handle_display_change (void)
1718 _gdk_monitor_init ();
1719 _gdk_root_window_size_init ();
1720 g_signal_emit_by_name (_gdk_screen, "size_changed");
1724 generate_button_event (GdkEventType type,
1729 GdkEvent *event = gdk_event_new (type);
1731 event->button.window = window;
1732 event->button.time = _gdk_win32_get_next_tick (msg->time);
1733 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1734 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1735 event->button.x_root = msg->pt.x + _gdk_offset_x;
1736 event->button.y_root = msg->pt.y + _gdk_offset_y;
1737 event->button.axes = NULL;
1738 event->button.state = build_pointer_event_state (msg);
1739 event->button.button = button;
1740 gdk_event_set_device (event, _gdk_display->core_pointer);
1742 _gdk_win32_append_event (event);
1746 ensure_stacking_on_unminimize (MSG *msg)
1749 HWND lowest_transient = NULL;
1752 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1754 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1756 /* Checking window group not implemented yet */
1759 GdkWindowImplWin32 *rover_impl =
1760 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1762 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1763 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1764 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1765 rover_impl->transient_owner != NULL))
1767 lowest_transient = rover;
1771 if (lowest_transient != NULL)
1773 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1774 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1775 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1780 ensure_stacking_on_window_pos_changing (MSG *msg,
1783 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1784 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1786 if (GetActiveWindow () == msg->hwnd &&
1787 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1788 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1789 impl->transient_owner == NULL)
1791 /* Make sure the window stays behind any transient-type windows
1792 * of the same window group.
1794 * If the window is not active and being activated, we let
1795 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1796 * handling to bring any utility windows on top of it.
1799 gboolean restacking;
1801 rover = windowpos->hwndInsertAfter;
1805 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1807 /* Checking window group not implemented yet */
1810 GdkWindowImplWin32 *rover_impl =
1811 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1813 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1814 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1815 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1816 rover_impl->transient_owner != NULL))
1819 windowpos->hwndInsertAfter = rover;
1822 rover = GetNextWindow (rover, GW_HWNDNEXT);
1827 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1835 ensure_stacking_on_activate_app (MSG *msg,
1838 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1840 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1841 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1842 impl->transient_owner != NULL)
1844 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1845 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1849 if (IsWindowVisible (msg->hwnd) &&
1850 msg->hwnd == GetActiveWindow ())
1852 /* This window is not a transient-type window and it is the
1853 * activated window. Make sure this window is as visible as
1854 * possible, just below the lowest transient-type window of this
1860 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
1862 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1864 /* Checking window group not implemented yet */
1867 GdkWindowImplWin32 *rover_impl =
1868 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1870 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1871 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1872 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1873 rover_impl->transient_owner != NULL))
1875 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1876 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1877 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1885 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
1886 GDK_BUTTON2_MASK | \
1887 GDK_BUTTON3_MASK | \
1888 GDK_BUTTON4_MASK | \
1892 gdk_event_translate (MSG *msg,
1895 RECT rect, *drag, orig_drag;
1900 BYTE key_state[256];
1902 WINDOWPOS *windowpos;
1909 GdkWindow *window = NULL;
1910 GdkWindowImplWin32 *impl;
1912 GdkWindow *orig_window, *new_window;
1914 GdkDeviceManager *device_manager;
1916 GdkDeviceGrabInfo *keyboard_grab = NULL;
1917 GdkDeviceGrabInfo *pointer_grab = NULL;
1918 GdkWindow *grab_window = NULL;
1924 gboolean return_val = FALSE;
1928 if (_gdk_default_filters)
1930 /* Apply global filters */
1932 GdkFilterReturn result = apply_event_filters (NULL, msg, &_gdk_default_filters);
1934 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1935 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1936 * we return TRUE, and DefWindowProcW() will not be called.
1938 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1942 window = gdk_win32_handle_table_lookup (msg->hwnd);
1943 orig_window = window;
1947 /* XXX Handle WM_QUIT here ? */
1948 if (msg->message == WM_QUIT)
1950 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1953 else if (msg->message == WM_CREATE)
1955 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1956 GDK_WINDOW_HWND (window) = msg->hwnd;
1960 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1965 device_manager = gdk_display_get_device_manager (_gdk_display);
1967 keyboard_grab = _gdk_display_get_last_device_grab (_gdk_display,
1968 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
1969 pointer_grab = _gdk_display_get_last_device_grab (_gdk_display,
1970 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer);
1972 g_object_ref (window);
1974 /* window's refcount has now been increased, so code below should
1975 * not just return from this function, but instead goto done (or
1976 * break out of the big switch). To protect against forgetting this,
1977 * #define return to a syntax error...
1979 #define return GOTO_DONE_INSTEAD
1981 if (!GDK_WINDOW_DESTROYED (window) && window->filters)
1983 /* Apply per-window filters */
1985 GdkFilterReturn result = apply_event_filters (window, msg, &window->filters);
1987 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1994 if (msg->message == client_message)
1997 GdkFilterReturn result = GDK_FILTER_CONTINUE;
2000 GDK_NOTE (EVENTS, g_print (" client_message"));
2002 event = gdk_event_new (GDK_NOTHING);
2003 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2005 node = _gdk_event_queue_append (_gdk_display, event);
2007 tmp_list = client_filters;
2010 GdkClientFilter *filter = tmp_list->data;
2012 tmp_list = tmp_list->next;
2014 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
2016 GDK_NOTE (EVENTS, g_print (" (match)"));
2018 result = (*filter->function) (msg, event, filter->data);
2020 if (result != GDK_FILTER_CONTINUE)
2027 case GDK_FILTER_REMOVE:
2028 _gdk_event_queue_remove_link (_gdk_display, node);
2029 g_list_free_1 (node);
2030 gdk_event_free (event);
2034 case GDK_FILTER_TRANSLATE:
2035 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2036 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2040 case GDK_FILTER_CONTINUE:
2041 /* No more: Send unknown client messages on to Gtk for it to use */
2042 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2048 switch (msg->message)
2050 case WM_INPUTLANGCHANGE:
2051 _gdk_input_locale = (HKL) msg->lParam;
2052 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
2053 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
2054 LOCALE_IDEFAULTANSICODEPAGE,
2056 _gdk_input_codepage = atoi (buf);
2057 _gdk_keymap_serial++;
2059 g_print (" cs:%lu hkl:%p%s cp:%d",
2060 (gulong) msg->wParam,
2061 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
2062 _gdk_input_codepage));
2068 g_print (" %s ch:%.02x %s",
2069 _gdk_win32_key_to_string (msg->lParam),
2071 decode_key_lparam (msg->lParam)));
2073 /* If posted without us having keyboard focus, ignore */
2074 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
2075 !(HIWORD (msg->lParam) & KF_ALTDOWN))
2078 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
2079 * the keyboard is grabbed.
2081 if (!keyboard_grab &&
2082 (msg->wParam == VK_TAB ||
2083 msg->wParam == VK_SPACE ||
2084 msg->wParam == VK_F4))
2087 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
2093 g_print (" %s ch:%.02x %s",
2094 _gdk_win32_key_to_string (msg->lParam),
2096 decode_key_lparam (msg->lParam)));
2100 /* Ignore key messages intended for the IME */
2101 if (msg->wParam == VK_PROCESSKEY ||
2105 if (keyboard_grab &&
2106 !propagate (&window, msg,
2107 keyboard_grab->window,
2108 keyboard_grab->owner_events,
2109 GDK_ALL_EVENTS_MASK,
2110 doesnt_want_key, FALSE))
2113 if (GDK_WINDOW_DESTROYED (window))
2116 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
2117 msg->message == WM_SYSKEYDOWN) ?
2118 GDK_KEY_PRESS : GDK_KEY_RELEASE);
2119 event->key.window = window;
2120 event->key.time = _gdk_win32_get_next_tick (msg->time);
2121 event->key.keyval = GDK_KEY_VoidSymbol;
2122 event->key.string = NULL;
2123 event->key.length = 0;
2124 event->key.hardware_keycode = msg->wParam;
2125 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2126 if (HIWORD (msg->lParam) & KF_EXTENDED)
2128 switch (msg->wParam)
2131 event->key.hardware_keycode = VK_RCONTROL;
2133 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
2134 * for the right shift key.
2136 event->key.hardware_keycode = VK_RSHIFT;
2139 event->key.hardware_keycode = VK_RMENU;
2143 else if (msg->wParam == VK_SHIFT &&
2144 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
2145 event->key.hardware_keycode = VK_RSHIFT;
2147 API_CALL (GetKeyboardState, (key_state));
2149 /* 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]); */
2151 build_key_event_state (event, key_state);
2153 if (msg->wParam == VK_PACKET &&
2154 ToUnicode (VK_PACKET, HIWORD (msg->lParam), key_state, wbuf, 1, 0) == 1)
2155 event->key.keyval = gdk_unicode_to_keyval (wbuf[0]);
2157 gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (_gdk_display),
2158 event->key.hardware_keycode,
2164 fill_key_event_string (event);
2166 /* Reset MOD1_MASK if it is the Alt key itself */
2167 if (msg->wParam == VK_MENU)
2168 event->key.state &= ~GDK_MOD1_MASK;
2170 _gdk_win32_append_event (event);
2176 if (msg->wParam != VK_SPACE)
2178 /* To prevent beeps, don't let DefWindowProcW() be called */
2184 case WM_IME_STARTCOMPOSITION:
2185 in_ime_composition = TRUE;
2188 case WM_IME_ENDCOMPOSITION:
2189 in_ime_composition = FALSE;
2192 case WM_IME_COMPOSITION:
2193 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2194 * applications. Thus, handle WM_IME_COMPOSITION with
2195 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2196 * with ImmGetCompositionStringW().
2199 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2201 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2202 * for comments by other people that seems to have the same
2203 * experience. WM_IME_CHAR just gives question marks, apparently
2204 * because of going through some conversion to the current code
2207 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2208 * use WM_IME_COMPOSITION there, too, to simplify the code.
2210 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2212 if (!(msg->lParam & GCS_RESULTSTR))
2215 if (keyboard_grab &&
2216 !propagate (&window, msg,
2217 keyboard_grab->window,
2218 keyboard_grab->owner_events,
2219 GDK_ALL_EVENTS_MASK,
2220 doesnt_want_char, FALSE))
2223 if (GDK_WINDOW_DESTROYED (window))
2226 himc = ImmGetContext (msg->hwnd);
2227 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2228 wbuf, sizeof (wbuf));
2229 ImmReleaseContext (msg->hwnd, himc);
2233 API_CALL (GetKeyboardState, (key_state));
2235 for (i = 0; i < ccount; i++)
2237 if (window->event_mask & GDK_KEY_PRESS_MASK)
2239 /* Build a key press event */
2240 event = gdk_event_new (GDK_KEY_PRESS);
2241 event->key.window = window;
2242 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2243 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2245 _gdk_win32_append_event (event);
2248 if (window->event_mask & GDK_KEY_RELEASE_MASK)
2250 /* Build a key release event. */
2251 event = gdk_event_new (GDK_KEY_RELEASE);
2252 event->key.window = window;
2253 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2254 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2256 _gdk_win32_append_event (event);
2262 case WM_LBUTTONDOWN:
2266 case WM_MBUTTONDOWN:
2270 case WM_RBUTTONDOWN:
2274 case WM_XBUTTONDOWN:
2275 if (HIWORD (msg->wParam) == XBUTTON1)
2282 g_print (" (%d,%d)",
2283 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2285 assign_object (&window, find_window_for_mouse_event (window, msg));
2286 /* TODO_CSW?: there used to some synthesize and propagate */
2287 if (GDK_WINDOW_DESTROYED (window))
2290 if (pointer_grab == NULL)
2292 SetCapture (GDK_WINDOW_HWND (window));
2295 generate_button_event (GDK_BUTTON_PRESS, button,
2314 if (HIWORD (msg->wParam) == XBUTTON1)
2321 g_print (" (%d,%d)",
2322 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2324 assign_object (&window, find_window_for_mouse_event (window, msg));
2326 if (window->extension_events != 0 &&
2327 _gdk_input_ignore_core)
2329 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2334 if (pointer_grab != NULL && pointer_grab->implicit)
2336 gint state = build_pointer_event_state (msg);
2338 /* We keep the implicit grab until no buttons at all are held down */
2339 if ((state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (button - 1))) == 0)
2344 hwnd = WindowFromPoint (msg->pt);
2347 POINT client_pt = msg->pt;
2349 ScreenToClient (hwnd, &client_pt);
2350 GetClientRect (hwnd, &rect);
2351 if (PtInRect (&rect, client_pt))
2352 new_window = gdk_win32_handle_table_lookup (hwnd);
2354 synthesize_crossing_events (_gdk_display,
2355 pointer_grab->native_window, new_window,
2356 GDK_CROSSING_UNGRAB,
2358 0, /* TODO: Set right mask */
2361 assign_object (&mouse_window, new_window);
2365 generate_button_event (GDK_BUTTON_RELEASE, button,
2373 g_print (" %p (%d,%d)",
2374 (gpointer) msg->wParam,
2375 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2377 new_window = window;
2379 if (pointer_grab != NULL)
2385 hwnd = WindowFromPoint (pt);
2388 POINT client_pt = pt;
2390 ScreenToClient (hwnd, &client_pt);
2391 GetClientRect (hwnd, &rect);
2392 if (PtInRect (&rect, client_pt))
2393 new_window = gdk_win32_handle_table_lookup (hwnd);
2396 if (!pointer_grab->owner_events &&
2397 new_window != NULL &&
2398 new_window != pointer_grab->native_window)
2402 if (mouse_window != new_window)
2404 GDK_NOTE (EVENTS, g_print (" mouse_sinwod %p -> %p",
2405 mouse_window ? GDK_WINDOW_HWND (mouse_window) : NULL,
2406 new_window ? GDK_WINDOW_HWND (new_window) : NULL));
2407 synthesize_crossing_events (_gdk_display,
2408 mouse_window, new_window,
2409 GDK_CROSSING_NORMAL,
2411 0, /* TODO: Set right mask */
2414 assign_object (&mouse_window, new_window);
2415 if (new_window != NULL)
2416 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (new_window));
2419 assign_object (&window, find_window_for_mouse_event (window, msg));
2421 /* If we haven't moved, don't create any GDK event. Windows
2422 * sends WM_MOUSEMOVE messages after a new window is shows under
2423 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2425 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2426 msg->pt.y + _gdk_offset_y == current_root_y)
2429 current_root_x = msg->pt.x + _gdk_offset_x;
2430 current_root_y = msg->pt.y + _gdk_offset_y;
2432 event = gdk_event_new (GDK_MOTION_NOTIFY);
2433 event->motion.window = window;
2434 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2435 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2436 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2437 event->motion.x_root = current_root_x;
2438 event->motion.y_root = current_root_y;
2439 event->motion.axes = NULL;
2440 event->motion.state = build_pointer_event_state (msg);
2441 event->motion.is_hint = FALSE;
2442 gdk_event_set_device (event, _gdk_display->core_pointer);
2444 _gdk_win32_append_event (event);
2449 case WM_NCMOUSEMOVE:
2451 g_print (" (%d,%d)",
2452 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2456 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2457 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2460 hwnd = WindowFromPoint (msg->pt);
2463 POINT client_pt = msg->pt;
2465 ScreenToClient (hwnd, &client_pt);
2466 GetClientRect (hwnd, &rect);
2467 if (PtInRect (&rect, client_pt))
2468 new_window = gdk_win32_handle_table_lookup (hwnd);
2471 synthesize_crossing_events (_gdk_display,
2472 mouse_window, new_window,
2473 GDK_CROSSING_NORMAL,
2475 0, /* TODO: Set right mask */
2478 assign_object (&mouse_window, new_window);
2484 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2486 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2487 * that. Also, the position is in screen coordinates, not client
2488 * coordinates as with the button messages. I love the
2489 * consistency of Windows.
2491 point.x = GET_X_LPARAM (msg->lParam);
2492 point.y = GET_Y_LPARAM (msg->lParam);
2494 if ((hwnd = WindowFromPoint (point)) == NULL)
2498 if ((new_window = gdk_win32_handle_table_lookup (msg->hwnd)) == NULL)
2501 if (new_window != window)
2503 assign_object (&window, new_window);
2506 ScreenToClient (msg->hwnd, &point);
2508 event = gdk_event_new (GDK_SCROLL);
2509 event->scroll.window = window;
2510 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2511 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2512 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2513 event->scroll.x = (gint16) point.x;
2514 event->scroll.y = (gint16) point.y;
2515 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2516 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2517 event->scroll.state = build_pointer_event_state (msg);
2518 gdk_event_set_device (event, _gdk_display->core_pointer);
2520 _gdk_win32_append_event (event);
2526 /* Just print more debugging information, don't actually handle it. */
2529 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2530 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2531 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2532 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2533 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2534 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2535 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2536 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2537 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2539 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2540 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2541 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2545 /* Just print more debugging information, don't actually handle it. */
2548 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2549 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2550 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2551 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2552 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2553 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2554 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2555 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2556 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2558 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2559 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2560 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2563 case WM_MOUSEACTIVATE:
2567 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2568 || !window->accept_focus)
2570 *ret_valp = MA_NOACTIVATE;
2574 tmp = _gdk_modal_current ();
2578 if (gdk_window_get_toplevel (window) != tmp)
2580 *ret_valp = MA_NOACTIVATEANDEAT;
2589 if (keyboard_grab != NULL &&
2590 !GDK_WINDOW_DESTROYED (keyboard_grab->window))
2592 generate_grab_broken_event (device_manager, keyboard_grab->window, TRUE, NULL);
2597 if (keyboard_grab != NULL &&
2598 !keyboard_grab->owner_events)
2601 if (!(window->event_mask & GDK_FOCUS_CHANGE_MASK))
2604 if (GDK_WINDOW_DESTROYED (window))
2607 generate_focus_event (device_manager, window, (msg->message == WM_SETFOCUS));
2612 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2614 if (GDK_WINDOW_DESTROYED (window))
2622 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2624 200, sync_timer_proc);
2628 handle_wm_paint (msg, window, FALSE, NULL);
2632 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2633 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2635 if (pointer_grab != NULL)
2636 grab_window = pointer_grab->window;
2638 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2641 if (grab_window != NULL && p_grab_cursor != NULL)
2642 hcursor = p_grab_cursor;
2643 else if (!GDK_WINDOW_DESTROYED (window))
2644 hcursor = GDK_WINDOW_IMPL_WIN32 (window->impl)->hcursor;
2648 if (hcursor != NULL)
2650 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2651 SetCursor (hcursor);
2658 switch (msg->wParam)
2662 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2668 case WM_ENTERSIZEMOVE:
2669 case WM_ENTERMENULOOP:
2670 if (msg->message == WM_ENTERSIZEMOVE)
2671 _modal_move_resize_window = msg->hwnd;
2673 _gdk_win32_begin_modal_call ();
2676 case WM_EXITSIZEMOVE:
2677 case WM_EXITMENULOOP:
2678 if (_modal_operation_in_progress)
2680 _modal_move_resize_window = NULL;
2681 _gdk_win32_end_modal_call ();
2685 case WM_CAPTURECHANGED:
2686 /* Sometimes we don't get WM_EXITSIZEMOVE, for instance when you
2687 select move/size in the menu and then click somewhere without
2688 moving/resizing. We work around this using WM_CAPTURECHANGED. */
2689 if (_modal_operation_in_progress)
2691 _modal_move_resize_window = NULL;
2692 _gdk_win32_end_modal_call ();
2696 case WM_WINDOWPOSCHANGING:
2697 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2698 g_print (" %s %s %dx%d@%+d%+d now below %p",
2699 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2700 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2701 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2702 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2703 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2704 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2706 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2707 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2709 if (GDK_WINDOW_IS_MAPPED (window))
2710 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2713 case WM_WINDOWPOSCHANGED:
2714 windowpos = (WINDOWPOS *) msg->lParam;
2715 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2716 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2717 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2718 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2719 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2720 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2721 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2723 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2725 /* Break grabs on unmap or minimize */
2726 if (windowpos->flags & SWP_HIDEWINDOW ||
2727 ((windowpos->flags & SWP_STATECHANGED) && IsIconic (msg->hwnd)))
2729 if (pointer_grab != NULL)
2731 if (pointer_grab->window == window)
2732 gdk_pointer_ungrab (msg->time);
2735 if (keyboard_grab->window == window)
2736 gdk_keyboard_ungrab (msg->time);
2739 /* Send MAP events */
2740 if ((windowpos->flags & SWP_SHOWWINDOW) &&
2741 !GDK_WINDOW_DESTROYED (window))
2743 event = gdk_event_new (GDK_MAP);
2744 event->any.window = window;
2745 _gdk_win32_append_event (event);
2748 /* Update window state */
2749 if (windowpos->flags & (SWP_STATECHANGED | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
2751 GdkWindowState set_bits, unset_bits, old_state, new_state;
2753 old_state = window->state;
2758 if (IsWindowVisible (msg->hwnd))
2759 unset_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2761 set_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2763 if (IsIconic (msg->hwnd))
2764 set_bits |= GDK_WINDOW_STATE_ICONIFIED;
2766 unset_bits |= GDK_WINDOW_STATE_ICONIFIED;
2768 if (IsZoomed (msg->hwnd))
2769 set_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2771 unset_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2773 gdk_synthesize_window_state (window, unset_bits, set_bits);
2775 new_state = window->state;
2777 /* Whenever one window changes iconified state we need to also
2778 * change the iconified state in all transient related windows,
2779 * as windows doesn't give icons for transient childrens.
2781 if ((old_state & GDK_WINDOW_STATE_ICONIFIED) !=
2782 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2783 do_show_window (window, (new_state & GDK_WINDOW_STATE_ICONIFIED));
2786 /* When un-minimizing, make sure we're stacked under any
2787 transient-type windows. */
2788 if (!(old_state & GDK_WINDOW_STATE_ICONIFIED) &&
2789 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2790 ensure_stacking_on_unminimize (msg);
2793 /* Show, New size or position => configure event */
2794 if (!(windowpos->flags & SWP_NOCLIENTMOVE) ||
2795 !(windowpos->flags & SWP_NOCLIENTSIZE) ||
2796 (windowpos->flags & SWP_SHOWWINDOW))
2798 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2799 !IsIconic (msg->hwnd) &&
2800 !GDK_WINDOW_DESTROYED (window))
2801 _gdk_win32_emit_configure_event (window);
2803 if (window->extension_events != 0)
2804 _gdk_device_wintab_update_window_coords (window);
2807 if ((windowpos->flags & SWP_HIDEWINDOW) &&
2808 !GDK_WINDOW_DESTROYED (window))
2810 /* Send UNMAP events */
2811 event = gdk_event_new (GDK_UNMAP);
2812 event->any.window = window;
2813 _gdk_win32_append_event (event);
2815 /* Make transient parent the forground window when window unmaps */
2816 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2818 if (impl->transient_owner &&
2819 GetForegroundWindow () == GDK_WINDOW_HWND (window))
2820 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2823 if (!(windowpos->flags & SWP_NOCLIENTSIZE))
2825 if (window->resize_count > 1)
2826 window->resize_count -= 1;
2829 /* Call modal timer immediate so that we repaint faster after a resize. */
2830 if (_modal_operation_in_progress)
2831 modal_timer_proc (0,0,0,0);
2833 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2839 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2840 drag = (RECT *) msg->lParam;
2841 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2842 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2843 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2844 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2845 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2846 (msg->wParam == WMSZ_TOP ? "TOP" :
2847 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2848 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2850 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2852 _gdk_win32_rect_to_string (&rect),
2853 _gdk_win32_rect_to_string (drag)));
2855 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2857 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2859 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2860 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2862 /* Resize in increments relative to the base size */
2863 rect.left = rect.top = 0;
2864 rect.right = impl->hints.base_width;
2865 rect.bottom = impl->hints.base_height;
2866 _gdk_win32_adjust_client_rect (window, &rect);
2867 point.x = rect.left;
2869 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2870 rect.left = point.x;
2872 point.x = rect.right;
2873 point.y = rect.bottom;
2874 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2875 rect.right = point.x;
2876 rect.bottom = point.y;
2878 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2879 _gdk_win32_rect_to_string (&rect)));
2882 switch (msg->wParam)
2885 if (drag->bottom == rect.bottom)
2887 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2890 case WMSZ_BOTTOMLEFT:
2891 if (drag->bottom == rect.bottom && drag->left == rect.left)
2893 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2894 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2898 if (drag->left == rect.left)
2900 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2904 if (drag->top == rect.top && drag->left == rect.left)
2906 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2907 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2911 if (drag->top == rect.top)
2913 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2917 if (drag->top == rect.top && drag->right == rect.right)
2919 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2920 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2924 if (drag->right == rect.right)
2926 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2929 case WMSZ_BOTTOMRIGHT:
2930 if (drag->bottom == rect.bottom && drag->right == rect.right)
2932 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2933 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2937 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2938 drag->top != orig_drag.top || drag->right != orig_drag.right)
2942 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2943 _gdk_win32_rect_to_string (drag)));
2947 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2949 if (impl->hint_flags & GDK_HINT_ASPECT)
2951 RECT decorated_rect;
2952 RECT undecorated_drag;
2953 int decoration_width, decoration_height;
2954 gdouble drag_aspect;
2955 int drag_width, drag_height, new_width, new_height;
2957 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2958 decorated_rect = rect;
2959 _gdk_win32_adjust_client_rect (window, &decorated_rect);
2961 /* Set undecorated_drag to the client area being dragged
2962 * out, in screen coordinates.
2964 undecorated_drag = *drag;
2965 undecorated_drag.left -= decorated_rect.left - rect.left;
2966 undecorated_drag.right -= decorated_rect.right - rect.right;
2967 undecorated_drag.top -= decorated_rect.top - rect.top;
2968 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
2970 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
2971 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
2973 drag_width = undecorated_drag.right - undecorated_drag.left;
2974 drag_height = undecorated_drag.bottom - undecorated_drag.top;
2976 drag_aspect = (gdouble) drag_width / drag_height;
2978 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
2979 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
2981 if (drag_aspect < impl->hints.min_aspect)
2983 /* Aspect is getting too narrow */
2984 switch (msg->wParam)
2988 /* User drags top or bottom edge outward. Keep height, increase width. */
2989 new_width = impl->hints.min_aspect * drag_height;
2990 drag->left -= (new_width - drag_width) / 2;
2991 drag->right = drag->left + new_width + decoration_width;
2993 case WMSZ_BOTTOMLEFT:
2994 case WMSZ_BOTTOMRIGHT:
2995 /* User drags bottom-left or bottom-right corner down. Adjust height. */
2996 new_height = drag_width / impl->hints.min_aspect;
2997 drag->bottom = drag->top + new_height + decoration_height;
3001 /* User drags left or right edge inward. Decrease height */
3002 new_height = drag_width / impl->hints.min_aspect;
3003 drag->top += (drag_height - new_height) / 2;
3004 drag->bottom = drag->top + new_height + decoration_height;
3008 /* User drags top-left or top-right corner up. Adjust height. */
3009 new_height = drag_width / impl->hints.min_aspect;
3010 drag->top = drag->bottom - new_height - decoration_height;
3013 else if (drag_aspect > impl->hints.max_aspect)
3015 /* Aspect is getting too wide */
3016 switch (msg->wParam)
3020 /* User drags top or bottom edge inward. Decrease width. */
3021 new_width = impl->hints.max_aspect * drag_height;
3022 drag->left += (drag_width - new_width) / 2;
3023 drag->right = drag->left + new_width + decoration_width;
3025 case WMSZ_BOTTOMLEFT:
3027 /* User drags bottom-left or top-left corner left. Adjust width. */
3028 new_width = impl->hints.max_aspect * drag_height;
3029 drag->left = drag->right - new_width - decoration_width;
3031 case WMSZ_BOTTOMRIGHT:
3033 /* User drags bottom-right or top-right corner right. Adjust width. */
3034 new_width = impl->hints.max_aspect * drag_height;
3035 drag->right = drag->left + new_width + decoration_width;
3039 /* User drags left or right edge outward. Increase height. */
3040 new_height = drag_width / impl->hints.max_aspect;
3041 drag->top -= (new_height - drag_height) / 2;
3042 drag->bottom = drag->top + new_height + decoration_height;
3049 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
3050 _gdk_win32_rect_to_string (drag)));
3054 case WM_GETMINMAXINFO:
3055 if (GDK_WINDOW_DESTROYED (window))
3058 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3059 mmi = (MINMAXINFO*) msg->lParam;
3060 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
3061 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3062 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3063 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3064 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3065 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3067 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
3069 rect.left = rect.top = 0;
3070 rect.right = impl->hints.min_width;
3071 rect.bottom = impl->hints.min_height;
3073 _gdk_win32_adjust_client_rect (window, &rect);
3075 mmi->ptMinTrackSize.x = rect.right - rect.left;
3076 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
3079 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
3083 rect.left = rect.top = 0;
3084 rect.right = impl->hints.max_width;
3085 rect.bottom = impl->hints.max_height;
3087 _gdk_win32_adjust_client_rect (window, &rect);
3089 /* at least on win9x we have the 16 bit trouble */
3090 maxw = rect.right - rect.left;
3091 maxh = rect.bottom - rect.top;
3092 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
3093 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
3096 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
3098 /* Don't call DefWindowProcW() */
3099 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
3100 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3101 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3102 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3103 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3104 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3107 mmi->ptMaxTrackSize.x = 30000;
3108 mmi->ptMaxTrackSize.y = 30000;
3113 if (GDK_WINDOW_DESTROYED (window))
3116 event = gdk_event_new (GDK_DELETE);
3117 event->any.window = window;
3119 _gdk_win32_append_event (event);
3121 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3123 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
3125 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3132 if (pointer_grab != NULL)
3134 if (pointer_grab->window == window)
3135 gdk_pointer_ungrab (msg->time);
3138 if (keyboard_grab &&
3139 keyboard_grab->window == window)
3140 gdk_keyboard_ungrab (msg->time);
3142 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
3143 gdk_window_destroy_notify (window);
3145 if (window == NULL || GDK_WINDOW_DESTROYED (window))
3148 event = gdk_event_new (GDK_DESTROY);
3149 event->any.window = window;
3151 _gdk_win32_append_event (event);
3156 case WM_DISPLAYCHANGE:
3157 handle_display_change ();
3160 case WM_DESTROYCLIPBOARD:
3161 if (!_ignore_destroy_clipboard)
3163 event = gdk_event_new (GDK_SELECTION_CLEAR);
3164 event->selection.window = window;
3165 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3166 event->selection.time = _gdk_win32_get_next_tick (msg->time);
3167 _gdk_win32_append_event (event);
3176 case WM_RENDERFORMAT:
3177 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
3179 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
3181 GDK_NOTE (EVENTS, g_print (" (target not found)"));
3186 /* We need to render to clipboard immediately, don't call
3187 * _gdk_win32_append_event()
3189 event = gdk_event_new (GDK_SELECTION_REQUEST);
3190 event->selection.window = window;
3191 event->selection.send_event = FALSE;
3192 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3193 event->selection.target = target;
3194 event->selection.property = _gdk_selection;
3195 event->selection.requestor = gdk_win32_handle_table_lookup (msg->hwnd);
3196 event->selection.time = msg->time;
3198 fixup_event (event);
3199 GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)"));
3200 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
3201 _gdk_event_emit (event);
3202 gdk_event_free (event);
3204 /* Now the clipboard owner should have rendered */
3205 if (!_delayed_rendering_data)
3207 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3211 if (msg->wParam == CF_DIB)
3213 _delayed_rendering_data =
3214 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3216 if (!_delayed_rendering_data)
3218 g_warning ("Cannot convert to DIB from delayed rendered image");
3223 /* The requestor is holding the clipboard, no
3224 * OpenClipboard() is required/possible
3227 g_print (" SetClipboardData(%s,%p)",
3228 _gdk_win32_cf_to_string (msg->wParam),
3229 _delayed_rendering_data));
3231 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3232 _delayed_rendering_data = NULL;
3237 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3238 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3239 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3240 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3241 HIWORD (msg->wParam) ? " minimized" : "",
3242 (HWND) msg->lParam));
3243 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3244 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3247 if (is_modally_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3249 GdkWindow *modal_current = _gdk_modal_current ();
3250 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3256 /* Bring any tablet contexts to the top of the overlap order when
3257 * one of our windows is activated.
3258 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3261 if (LOWORD(msg->wParam) != WA_INACTIVE)
3262 _gdk_input_set_tablet_active ();
3265 case WM_ACTIVATEAPP:
3266 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3267 msg->wParam ? "YES" : "NO",
3268 (gint64) msg->lParam));
3269 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3270 ensure_stacking_on_activate_app (msg, window);
3273 /* Handle WINTAB events here, as we know that gdkinput.c will
3274 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3275 * constants as case labels.
3278 GDK_NOTE (EVENTS, g_print (" %d %p",
3279 (int) msg->wParam, (gpointer) msg->lParam));
3283 GDK_NOTE (EVENTS, g_print (" %d %p",
3284 (int) msg->wParam, (gpointer) msg->lParam));
3288 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3289 (gpointer) msg->wParam,
3290 LOWORD (msg->lParam),
3291 HIWORD (msg->lParam)));
3295 event = gdk_event_new (GDK_NOTHING);
3296 event->any.window = window;
3297 g_object_ref (window);
3299 if (_gdk_input_other_event (event, msg, window))
3300 _gdk_win32_append_event (event);
3302 gdk_event_free (event);
3310 g_object_unref (window);
3317 _gdk_win32_display_queue_events (GdkDisplay *display)
3321 if (modal_win32_dialog != NULL)
3324 while (!_gdk_event_queue_find_first (display) &&
3325 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3327 TranslateMessage (&msg);
3328 DispatchMessageW (&msg);
3333 gdk_event_prepare (GSource *source,
3338 GDK_THREADS_ENTER ();
3342 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3343 (modal_win32_dialog == NULL &&
3344 GetQueueStatus (QS_ALLINPUT) != 0));
3346 GDK_THREADS_LEAVE ();
3352 gdk_event_check (GSource *source)
3356 GDK_THREADS_ENTER ();
3358 if (event_poll_fd.revents & G_IO_IN)
3360 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3361 (modal_win32_dialog == NULL &&
3362 GetQueueStatus (QS_ALLINPUT) != 0));
3369 GDK_THREADS_LEAVE ();
3375 gdk_event_dispatch (GSource *source,
3376 GSourceFunc callback,
3381 GDK_THREADS_ENTER ();
3383 _gdk_win32_display_queue_events (_gdk_display);
3384 event = _gdk_event_unqueue (_gdk_display);
3388 _gdk_event_emit (event);
3390 gdk_event_free (event);
3392 /* Do drag & drop if it is still pending */
3393 if (_dnd_source_state == GDK_WIN32_DND_PENDING)
3395 _dnd_source_state = GDK_WIN32_DND_DRAGGING;
3396 _gdk_win32_dnd_do_dragdrop ();
3397 _dnd_source_state = GDK_WIN32_DND_NONE;
3401 GDK_THREADS_LEAVE ();
3407 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3409 modal_win32_dialog = window;
3413 is_modally_blocked (GdkWindow *window)
3415 GdkWindow *modal_current = _gdk_modal_current ();
3416 return modal_current != NULL ? gdk_window_get_toplevel (window) != modal_current : FALSE;
3420 _gdk_win32_display_sync (GdkDisplay * display)
3424 g_return_if_fail (display == _gdk_display);
3426 /* Process all messages currently available */
3427 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3428 DispatchMessageW (&msg);