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
86 * Private function declarations
89 static gboolean gdk_event_translate (MSG *msg,
91 static void handle_wm_paint (MSG *msg,
93 gboolean return_exposes,
96 static gboolean gdk_event_prepare (GSource *source,
98 static gboolean gdk_event_check (GSource *source);
99 static gboolean gdk_event_dispatch (GSource *source,
100 GSourceFunc callback,
103 static gboolean is_modally_blocked (GdkWindow *window);
105 /* Private variable declarations
108 static GList *client_filters; /* Filters for client messages */
109 extern gint _gdk_input_ignore_core;
111 static HCURSOR p_grab_cursor;
113 static GSourceFuncs event_funcs = {
120 GPollFD event_poll_fd;
122 static GdkWindow *mouse_window = NULL;
123 static gint current_x, current_y;
124 static gint current_root_x, current_root_y;
125 static UINT client_message;
127 static UINT got_gdk_events_message;
128 static HWND modal_win32_dialog = NULL;
131 static HKL latin_locale = NULL;
134 static gboolean in_ime_composition = FALSE;
135 static UINT modal_timer;
136 static UINT sync_timer = 0;
138 static int debug_indent = 0;
141 assign_object (gpointer lhsp,
144 if (*(gpointer *)lhsp != rhs)
146 if (*(gpointer *)lhsp != NULL)
147 g_object_unref (*(gpointer *)lhsp);
148 *(gpointer *)lhsp = rhs;
155 track_mouse_event (DWORD dwFlags,
160 tme.cbSize = sizeof(TRACKMOUSEEVENT);
161 tme.dwFlags = dwFlags;
162 tme.hwndTrack = hwnd;
163 tme.dwHoverTime = HOVER_DEFAULT; /* not used */
165 if (!TrackMouseEvent (&tme))
166 WIN32_API_FAILED ("TrackMouseEvent");
167 else if (dwFlags == TME_LEAVE)
168 GDK_NOTE (EVENTS, g_print(" (TrackMouseEvent %p)", hwnd));
169 else if (dwFlags == TME_CANCEL)
170 GDK_NOTE (EVENTS, g_print(" (cancel TrackMouseEvent %p)", hwnd));
174 _gdk_win32_get_next_tick (gulong suggested_tick)
176 static gulong cur_tick = 0;
178 if (suggested_tick == 0)
179 suggested_tick = GetTickCount ();
180 if (suggested_tick <= cur_tick)
183 return cur_tick = suggested_tick;
187 generate_focus_event (GdkDeviceManager *device_manager,
194 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
196 event = gdk_event_new (GDK_FOCUS_CHANGE);
197 event->focus_change.window = window;
198 event->focus_change.in = in;
199 gdk_event_set_device (event, device);
201 _gdk_win32_append_event (event);
205 generate_grab_broken_event (GdkDeviceManager *device_manager,
208 GdkWindow *grab_window)
210 GdkEvent *event = gdk_event_new (GDK_GRAB_BROKEN);
214 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
216 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer;
218 event->grab_broken.window = window;
219 event->grab_broken.send_event = 0;
220 event->grab_broken.keyboard = keyboard;
221 event->grab_broken.implicit = FALSE;
222 event->grab_broken.grab_window = grab_window;
223 gdk_event_set_device (event, device);
225 _gdk_win32_append_event (event);
229 inner_window_procedure (HWND hwnd,
239 msg.message = message;
242 msg.time = _gdk_win32_get_next_tick (0);
243 pos = GetMessagePos ();
244 msg.pt.x = GET_X_LPARAM (pos);
245 msg.pt.y = GET_Y_LPARAM (pos);
247 if (gdk_event_translate (&msg, &ret_val))
249 /* If gdk_event_translate() returns TRUE, we return ret_val from
250 * the window procedure.
252 if (modal_win32_dialog)
253 PostMessageW (modal_win32_dialog, got_gdk_events_message,
259 /* Otherwise call DefWindowProcW(). */
260 GDK_NOTE (EVENTS, g_print (" DefWindowProcW"));
261 return DefWindowProcW (hwnd, message, wparam, lparam);
266 _gdk_win32_window_procedure (HWND hwnd,
273 GDK_NOTE (EVENTS, g_print ("%s%*s%s %p",
274 (debug_indent > 0 ? "\n" : ""),
276 _gdk_win32_message_to_string (message), hwnd));
278 retval = inner_window_procedure (hwnd, message, wparam, lparam);
281 GDK_NOTE (EVENTS, g_print (" => %I64d%s", (gint64) retval, (debug_indent == 0 ? "\n" : "")));
287 _gdk_events_init (void)
294 /* List of languages that use a latin keyboard. Somewhat sorted in
295 * "order of least surprise", in case we have to load one of them if
296 * the user only has arabic loaded, for instance.
298 static int latin_languages[] = {
304 /* Rest in numeric order */
333 client_message = RegisterWindowMessage ("GDK_WIN32_CLIENT_MESSAGE");
334 got_gdk_events_message = RegisterWindowMessage ("GDK_WIN32_GOT_EVENTS");
337 /* Check if we have some input locale identifier loaded that uses a
338 * latin keyboard, to be able to get the virtual-key code for the
339 * latin characters corresponding to ASCII control characters.
341 if ((n = GetKeyboardLayoutList (0, NULL)) == 0)
342 WIN32_API_FAILED ("GetKeyboardLayoutList");
345 HKL *hkl_list = g_new (HKL, n);
346 if (GetKeyboardLayoutList (n, hkl_list) == 0)
347 WIN32_API_FAILED ("GetKeyboardLayoutList");
350 for (i = 0; latin_locale == NULL && i < n; i++)
351 for (j = 0; j < G_N_ELEMENTS (latin_languages); j++)
352 if (PRIMARYLANGID (LOWORD (hkl_list[i])) == latin_languages[j])
354 latin_locale = hkl_list [i];
361 if (latin_locale == NULL)
363 /* Try to load a keyboard layout with latin characters then.
366 while (latin_locale == NULL && i < G_N_ELEMENTS (latin_languages))
369 g_sprintf (id, "%08x", MAKELANGID (latin_languages[i++], SUBLANG_DEFAULT));
370 latin_locale = LoadKeyboardLayout (id, KLF_NOTELLSHELL|KLF_SUBSTITUTE_OK);
374 GDK_NOTE (EVENTS, g_print ("latin_locale = %08x\n", (guint) latin_locale));
377 source = g_source_new (&event_funcs, sizeof (GSource));
378 g_source_set_name (source, "GDK Win32 event source");
379 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
382 event_poll_fd.fd = open ("/dev/windows", O_RDONLY);
383 if (event_poll_fd.fd == -1)
384 g_error ("can't open \"/dev/windows\": %s", g_strerror (errno));
386 event_poll_fd.fd = G_WIN32_MSG_HANDLE;
388 event_poll_fd.events = G_IO_IN;
390 g_source_add_poll (source, &event_poll_fd);
391 g_source_set_can_recurse (source, TRUE);
392 g_source_attach (source, NULL);
396 _gdk_win32_display_has_pending (GdkDisplay *display)
399 return (_gdk_event_queue_find_first (display) ||
400 (modal_win32_dialog == NULL &&
401 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
404 #if 0 /* Unused, but might be useful to re-introduce in some debugging output? */
407 event_mask_string (GdkEventMask mask)
409 static char bfr[500];
414 if (mask & GDK_##x##_MASK) \
415 p += g_sprintf (p, "%s" #x, (p > bfr ? " " : ""))
417 BIT (POINTER_MOTION);
418 BIT (POINTER_MOTION_HINT);
420 BIT (BUTTON1_MOTION);
421 BIT (BUTTON2_MOTION);
422 BIT (BUTTON3_MOTION);
424 BIT (BUTTON_RELEASE);
431 BIT (PROPERTY_CHANGE);
432 BIT (VISIBILITY_NOTIFY);
445 _gdk_windowing_device_grab (GdkDevice *device,
447 GdkWindow *native_window,
448 gboolean owner_events,
449 GdkEventMask event_mask,
450 GdkWindow *confine_to,
455 GdkWin32Cursor *cursor_private;
457 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (native_window->impl);
459 g_return_val_if_fail (window != NULL, 0);
460 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
461 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
463 cursor_private = (GdkWin32Cursor*) cursor;
467 else if ((hcursor = CopyCursor (cursor_private->hcursor)) == NULL)
468 WIN32_API_FAILED ("CopyCursor");
470 return_val = GDK_DEVICE_GET_CLASS (device)->grab (device,
478 /* TODO_CSW: grab brokens, confine window, input_grab */
479 if (p_grab_cursor != NULL)
481 if (GetCursor () == p_grab_cursor)
483 DestroyCursor (p_grab_cursor);
486 p_grab_cursor = hcursor;
488 if (p_grab_cursor != NULL)
489 SetCursor (p_grab_cursor);
490 else if (impl->hcursor != NULL)
491 SetCursor (impl->hcursor);
493 SetCursor (LoadCursor (NULL, IDC_ARROW));
499 find_window_for_mouse_event (GdkWindow* reported_window,
503 GdkDeviceManagerWin32 *device_manager;
504 GdkWindow *event_window;
507 GdkDeviceGrabInfo *grab;
509 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (_gdk_display));
511 grab = _gdk_display_get_last_device_grab (_gdk_display, device_manager->core_pointer);
513 return reported_window;
517 if (!grab->owner_events)
518 event_window = grab->native_window;
522 hwnd = WindowFromPoint (pt);
525 POINT client_pt = pt;
527 ScreenToClient (hwnd, &client_pt);
528 GetClientRect (hwnd, &rect);
529 if (PtInRect (&rect, client_pt))
530 event_window = gdk_win32_handle_table_lookup (hwnd);
532 if (event_window == NULL)
533 event_window = grab->native_window;
536 /* need to also adjust the coordinates to the new window */
537 ScreenToClient (GDK_WINDOW_HWND (event_window), &pt);
539 /* ATTENTION: need to update client coords */
540 msg->lParam = MAKELPARAM (pt.x, pt.y);
546 build_key_event_state (GdkEvent *event,
549 event->key.state = 0;
551 if (key_state[VK_SHIFT] & 0x80)
552 event->key.state |= GDK_SHIFT_MASK;
554 if (key_state[VK_CAPITAL] & 0x01)
555 event->key.state |= GDK_LOCK_MASK;
557 if (key_state[VK_LBUTTON] & 0x80)
558 event->key.state |= GDK_BUTTON1_MASK;
559 if (key_state[VK_MBUTTON] & 0x80)
560 event->key.state |= GDK_BUTTON2_MASK;
561 if (key_state[VK_RBUTTON] & 0x80)
562 event->key.state |= GDK_BUTTON3_MASK;
563 if (key_state[VK_XBUTTON1] & 0x80)
564 event->key.state |= GDK_BUTTON4_MASK;
565 if (key_state[VK_XBUTTON2] & 0x80)
566 event->key.state |= GDK_BUTTON5_MASK;
568 if (_gdk_keyboard_has_altgr &&
569 (key_state[VK_LCONTROL] & 0x80) &&
570 (key_state[VK_RMENU] & 0x80))
572 event->key.group = 1;
573 event->key.state |= GDK_MOD2_MASK;
574 if (key_state[VK_RCONTROL] & 0x80)
575 event->key.state |= GDK_CONTROL_MASK;
576 if (key_state[VK_LMENU] & 0x80)
577 event->key.state |= GDK_MOD1_MASK;
581 event->key.group = 0;
582 if (key_state[VK_CONTROL] & 0x80)
583 event->key.state |= GDK_CONTROL_MASK;
584 if (key_state[VK_MENU] & 0x80)
585 event->key.state |= GDK_MOD1_MASK;
590 build_pointer_event_state (MSG *msg)
596 if (msg->wParam & MK_CONTROL)
597 state |= GDK_CONTROL_MASK;
599 if ((msg->message != WM_LBUTTONDOWN &&
600 (msg->wParam & MK_LBUTTON)) ||
601 msg->message == WM_LBUTTONUP)
602 state |= GDK_BUTTON1_MASK;
604 if ((msg->message != WM_MBUTTONDOWN &&
605 (msg->wParam & MK_MBUTTON)) ||
606 msg->message == WM_MBUTTONUP)
607 state |= GDK_BUTTON2_MASK;
609 if ((msg->message != WM_RBUTTONDOWN &&
610 (msg->wParam & MK_RBUTTON)) ||
611 msg->message == WM_RBUTTONUP)
612 state |= GDK_BUTTON3_MASK;
614 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON1) &&
615 (msg->wParam & MK_XBUTTON1)) ||
616 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON1))
617 state |= GDK_BUTTON4_MASK;
619 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON2) &&
620 (msg->wParam & MK_XBUTTON2)) ||
621 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON2))
622 state |= GDK_BUTTON5_MASK;
624 if (msg->wParam & MK_SHIFT)
625 state |= GDK_SHIFT_MASK;
627 if (GetKeyState (VK_MENU) < 0)
628 state |= GDK_MOD1_MASK;
630 if (GetKeyState (VK_CAPITAL) & 0x1)
631 state |= GDK_LOCK_MASK;
637 build_wm_ime_composition_event (GdkEvent *event,
642 event->key.time = _gdk_win32_get_next_tick (msg->time);
644 build_key_event_state (event, key_state);
646 event->key.hardware_keycode = 0; /* FIXME: What should it be? */
647 event->key.string = NULL;
648 event->key.length = 0;
649 event->key.keyval = gdk_unicode_to_keyval (wc);
652 #ifdef G_ENABLE_DEBUG
655 print_event_state (guint state)
657 #define CASE(bit) if (state & GDK_ ## bit ## _MASK) g_print (#bit " ");
675 _gdk_win32_print_event (const GdkEvent *event)
677 gchar *escaped, *kvname;
678 gchar *selection_name, *target_name, *property_name;
680 g_print ("%s%*s===> ", (debug_indent > 0 ? "\n" : ""), debug_indent, "");
681 switch (event->any.type)
683 #define CASE(x) case x: g_print (#x); break;
688 CASE (GDK_MOTION_NOTIFY);
689 CASE (GDK_BUTTON_PRESS);
690 CASE (GDK_2BUTTON_PRESS);
691 CASE (GDK_3BUTTON_PRESS);
692 CASE (GDK_BUTTON_RELEASE);
693 CASE (GDK_KEY_PRESS);
694 CASE (GDK_KEY_RELEASE);
695 CASE (GDK_ENTER_NOTIFY);
696 CASE (GDK_LEAVE_NOTIFY);
697 CASE (GDK_FOCUS_CHANGE);
698 CASE (GDK_CONFIGURE);
701 CASE (GDK_PROPERTY_NOTIFY);
702 CASE (GDK_SELECTION_CLEAR);
703 CASE (GDK_SELECTION_REQUEST);
704 CASE (GDK_SELECTION_NOTIFY);
705 CASE (GDK_PROXIMITY_IN);
706 CASE (GDK_PROXIMITY_OUT);
707 CASE (GDK_DRAG_ENTER);
708 CASE (GDK_DRAG_LEAVE);
709 CASE (GDK_DRAG_MOTION);
710 CASE (GDK_DRAG_STATUS);
711 CASE (GDK_DROP_START);
712 CASE (GDK_DROP_FINISHED);
713 CASE (GDK_CLIENT_EVENT);
714 CASE (GDK_VISIBILITY_NOTIFY);
716 CASE (GDK_WINDOW_STATE);
718 CASE (GDK_OWNER_CHANGE);
719 CASE (GDK_GRAB_BROKEN);
721 default: g_assert_not_reached ();
724 g_print (" %p ", event->any.window ? GDK_WINDOW_HWND (event->any.window) : NULL);
726 switch (event->any.type)
730 _gdk_win32_gdkrectangle_to_string (&event->expose.area),
731 event->expose.count);
733 case GDK_MOTION_NOTIFY:
734 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s",
735 event->motion.x, event->motion.y,
736 event->motion.x_root, event->motion.y_root,
737 event->motion.is_hint ? "HINT " : "");
738 print_event_state (event->motion.state);
740 case GDK_BUTTON_PRESS:
741 case GDK_2BUTTON_PRESS:
742 case GDK_3BUTTON_PRESS:
743 case GDK_BUTTON_RELEASE:
744 g_print ("%d (%.4g,%.4g) (%.4g,%.4g) ",
745 event->button.button,
746 event->button.x, event->button.y,
747 event->button.x_root, event->button.y_root);
748 print_event_state (event->button.state);
751 case GDK_KEY_RELEASE:
752 if (event->key.length == 0)
753 escaped = g_strdup ("");
755 escaped = g_strescape (event->key.string, NULL);
756 kvname = gdk_keyval_name (event->key.keyval);
757 g_print ("%#.02x group:%d %s %d:\"%s\" ",
758 event->key.hardware_keycode, event->key.group,
759 (kvname ? kvname : "??"),
763 print_event_state (event->key.state);
765 case GDK_ENTER_NOTIFY:
766 case GDK_LEAVE_NOTIFY:
767 g_print ("%p (%.4g,%.4g) (%.4g,%.4g) %s %s%s",
768 event->crossing.subwindow == NULL ? NULL : GDK_WINDOW_HWND (event->crossing.subwindow),
769 event->crossing.x, event->crossing.y,
770 event->crossing.x_root, event->crossing.y_root,
771 (event->crossing.mode == GDK_CROSSING_NORMAL ? "NORMAL" :
772 (event->crossing.mode == GDK_CROSSING_GRAB ? "GRAB" :
773 (event->crossing.mode == GDK_CROSSING_UNGRAB ? "UNGRAB" :
775 (event->crossing.detail == GDK_NOTIFY_ANCESTOR ? "ANCESTOR" :
776 (event->crossing.detail == GDK_NOTIFY_VIRTUAL ? "VIRTUAL" :
777 (event->crossing.detail == GDK_NOTIFY_INFERIOR ? "INFERIOR" :
778 (event->crossing.detail == GDK_NOTIFY_NONLINEAR ? "NONLINEAR" :
779 (event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL ? "NONLINEAR_VIRTUAL" :
780 (event->crossing.detail == GDK_NOTIFY_UNKNOWN ? "UNKNOWN" :
782 event->crossing.focus ? " FOCUS" : "");
783 print_event_state (event->crossing.state);
785 case GDK_FOCUS_CHANGE:
786 g_print ("%s", (event->focus_change.in ? "IN" : "OUT"));
789 g_print ("x:%d y:%d w:%d h:%d",
790 event->configure.x, event->configure.y,
791 event->configure.width, event->configure.height);
793 case GDK_SELECTION_CLEAR:
794 case GDK_SELECTION_REQUEST:
795 case GDK_SELECTION_NOTIFY:
796 selection_name = gdk_atom_name (event->selection.selection);
797 target_name = gdk_atom_name (event->selection.target);
798 property_name = gdk_atom_name (event->selection.property);
799 g_print ("sel:%s tgt:%s prop:%s",
800 selection_name, target_name, property_name);
801 g_free (selection_name);
802 g_free (target_name);
803 g_free (property_name);
807 case GDK_DRAG_MOTION:
808 case GDK_DRAG_STATUS:
810 case GDK_DROP_FINISHED:
811 if (event->dnd.context != NULL)
812 g_print ("ctx:%p: %s %s src:%p dest:%p",
814 _gdk_win32_drag_protocol_to_string (event->dnd.context->protocol),
815 event->dnd.context->is_source ? "SOURCE" : "DEST",
816 event->dnd.context->source_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->source_window),
817 event->dnd.context->dest_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->dest_window));
819 case GDK_CLIENT_EVENT:
820 /* no more GdkEventClient */
823 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",
824 event->scroll.x, event->scroll.y,
825 event->scroll.x_root, event->scroll.y_root,
826 (event->scroll.direction == GDK_SCROLL_UP ? "UP" :
827 (event->scroll.direction == GDK_SCROLL_DOWN ? "DOWN" :
828 (event->scroll.direction == GDK_SCROLL_LEFT ? "LEFT" :
829 (event->scroll.direction == GDK_SCROLL_RIGHT ? "RIGHT" :
831 print_event_state (event->scroll.state);
833 case GDK_WINDOW_STATE:
835 _gdk_win32_window_state_to_string (event->window_state.changed_mask),
836 _gdk_win32_window_state_to_string (event->window_state.new_window_state));
839 (event->setting.action == GDK_SETTING_ACTION_NEW ? "NEW" :
840 (event->setting.action == GDK_SETTING_ACTION_CHANGED ? "CHANGED" :
841 (event->setting.action == GDK_SETTING_ACTION_DELETED ? "DELETED" :
843 (event->setting.name ? event->setting.name : "NULL"));
844 case GDK_GRAB_BROKEN:
846 (event->grab_broken.keyboard ? "KEYBOARD" : "POINTER"),
847 (event->grab_broken.implicit ? "IMPLICIT" : "EXPLICIT"),
848 (event->grab_broken.grab_window ? GDK_WINDOW_HWND (event->grab_broken.grab_window) : 0));
853 g_print ("%s", (debug_indent == 0 ? "\n" : ""));
857 decode_key_lparam (LPARAM lParam)
859 static char buf[100];
862 if (HIWORD (lParam) & KF_UP)
863 p += g_sprintf (p, "KF_UP ");
864 if (HIWORD (lParam) & KF_REPEAT)
865 p += g_sprintf (p, "KF_REPEAT ");
866 if (HIWORD (lParam) & KF_ALTDOWN)
867 p += g_sprintf (p, "KF_ALTDOWN ");
868 if (HIWORD (lParam) & KF_EXTENDED)
869 p += g_sprintf (p, "KF_EXTENDED ");
870 p += g_sprintf (p, "sc:%d rep:%d", LOBYTE (HIWORD (lParam)), LOWORD (lParam));
878 fixup_event (GdkEvent *event)
880 if (event->any.window)
881 g_object_ref (event->any.window);
882 if (((event->any.type == GDK_ENTER_NOTIFY) ||
883 (event->any.type == GDK_LEAVE_NOTIFY)) &&
884 (event->crossing.subwindow != NULL))
885 g_object_ref (event->crossing.subwindow);
886 event->any.send_event = InSendMessage ();
890 _gdk_win32_append_event (GdkEvent *event)
896 link = _gdk_event_queue_append (_gdk_display, event);
897 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
898 /* event morphing, the passed in may not be valid afterwards */
899 _gdk_windowing_got_event (_gdk_display, link, event, 0);
901 _gdk_event_queue_append (_gdk_display, event);
902 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
907 fill_key_event_string (GdkEvent *event)
912 /* Fill in event->string crudely, since various programs
917 if (event->key.keyval != GDK_KEY_VoidSymbol)
918 c = gdk_keyval_to_unicode (event->key.keyval);
925 /* Apply the control key - Taken from Xlib
927 if (event->key.state & GDK_CONTROL_MASK)
929 if ((c >= '@' && c < '\177') || c == ' ')
933 event->key.string = g_memdup ("\0\0", 2);
934 event->key.length = 1;
937 else if (c >= '3' && c <= '7')
945 len = g_unichar_to_utf8 (c, buf);
948 event->key.string = g_locale_from_utf8 (buf, len,
949 NULL, &bytes_written,
951 if (event->key.string)
952 event->key.length = bytes_written;
954 else if (event->key.keyval == GDK_KEY_Escape)
956 event->key.length = 1;
957 event->key.string = g_strdup ("\033");
959 else if (event->key.keyval == GDK_KEY_Return ||
960 event->key.keyval == GDK_KEY_KP_Enter)
962 event->key.length = 1;
963 event->key.string = g_strdup ("\r");
966 if (!event->key.string)
968 event->key.length = 0;
969 event->key.string = g_strdup ("");
973 static GdkFilterReturn
974 apply_event_filters (GdkWindow *window,
978 GdkFilterReturn result = GDK_FILTER_CONTINUE;
983 event = gdk_event_new (GDK_NOTHING);
985 event->any.window = g_object_ref (window);
986 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
988 /* I think GdkFilterFunc semantics require the passed-in event
989 * to already be in the queue. The filter func can generate
990 * more events and append them after it if it likes.
992 node = _gdk_event_queue_append (_gdk_display, event);
997 GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
1000 if ((filter->flags & GDK_EVENT_FILTER_REMOVED) != 0)
1002 tmp_list = tmp_list->next;
1006 filter->ref_count++;
1007 result = filter->function (msg, event, filter->data);
1009 /* get the next node after running the function since the
1010 function may add or remove a next node */
1012 tmp_list = tmp_list->next;
1014 filter->ref_count--;
1015 if (filter->ref_count == 0)
1017 *filters = g_list_remove_link (*filters, node);
1018 g_list_free_1 (node);
1022 if (result != GDK_FILTER_CONTINUE)
1026 if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
1028 _gdk_event_queue_remove_link (_gdk_display, node);
1029 g_list_free_1 (node);
1030 gdk_event_free (event);
1032 else /* GDK_FILTER_TRANSLATE */
1034 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1035 fixup_event (event);
1036 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1042 * On Windows, transient windows will not have their own taskbar entries.
1043 * Because of this, we must hide and restore groups of transients in both
1044 * directions. That is, all transient children must be hidden or restored
1045 * with this window, but if this window's transient owner also has a
1046 * transient owner then this window's transient owner must be hidden/restored
1047 * with this one. And etc, up the chain until we hit an ancestor that has no
1050 * It would be a good idea if applications don't chain transient windows
1051 * together. There's a limit to how much evil GTK can try to shield you
1055 show_window_recurse (GdkWindow *window, gboolean hide_window)
1057 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1058 GSList *children = impl->transient_children;
1059 GdkWindow *child = NULL;
1061 if (!impl->changing_state)
1063 impl->changing_state = TRUE;
1065 if (children != NULL)
1067 while (children != NULL)
1069 child = children->data;
1070 show_window_recurse (child, hide_window);
1072 children = g_slist_next (children);
1076 if (GDK_WINDOW_IS_MAPPED (window))
1080 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_ICONIFIED)
1082 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED)
1084 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
1088 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1094 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
1098 impl->changing_state = FALSE;
1103 do_show_window (GdkWindow *window, gboolean hide_window)
1105 GdkWindow *tmp_window = NULL;
1106 GdkWindowImplWin32 *tmp_impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1108 if (!tmp_impl->changing_state)
1110 /* Find the top-level window in our transient chain. */
1111 while (tmp_impl->transient_owner != NULL)
1113 tmp_window = tmp_impl->transient_owner;
1114 tmp_impl = GDK_WINDOW_IMPL_WIN32 (tmp_window->impl);
1117 /* If we couldn't find one, use the window provided. */
1118 if (tmp_window == NULL)
1120 tmp_window = window;
1123 /* Recursively show/hide every window in the chain. */
1124 if (tmp_window != window)
1126 show_window_recurse (tmp_window, hide_window);
1132 send_crossing_event (GdkDisplay *display,
1135 GdkCrossingMode mode,
1136 GdkNotifyType notify_type,
1137 GdkWindow *subwindow,
1139 GdkModifierType mask,
1143 GdkDeviceGrabInfo *grab;
1144 GdkDeviceManagerWin32 *device_manager;
1147 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (display));
1149 grab = _gdk_display_has_device_grab (display, device_manager->core_pointer, 0);
1152 !grab->owner_events &&
1153 mode != GDK_CROSSING_UNGRAB)
1155 /* !owner_event => only report events wrt grab window, ignore rest */
1156 if ((GdkWindow *)window != grab->native_window)
1161 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1163 event = gdk_event_new (type);
1164 event->crossing.window = window;
1165 event->crossing.subwindow = subwindow;
1166 event->crossing.time = _gdk_win32_get_next_tick (time_);
1167 event->crossing.x = pt.x;
1168 event->crossing.y = pt.y;
1169 event->crossing.x_root = screen_pt->x + _gdk_offset_x;
1170 event->crossing.y_root = screen_pt->y + _gdk_offset_y;
1171 event->crossing.mode = mode;
1172 event->crossing.detail = notify_type;
1173 event->crossing.mode = mode;
1174 event->crossing.detail = notify_type;
1175 event->crossing.focus = FALSE;
1176 event->crossing.state = mask;
1177 gdk_event_set_device (event, _gdk_display->core_pointer);
1179 _gdk_win32_append_event (event);
1181 if (type == GDK_ENTER_NOTIFY &&
1182 window->extension_events != 0)
1183 _gdk_device_wintab_update_window_coords (window);
1187 get_native_parent (GdkWindow *window)
1189 if (window->parent != NULL)
1190 return window->parent->impl_window;
1195 find_common_ancestor (GdkWindow *win1,
1199 GList *path1 = NULL, *path2 = NULL;
1200 GList *list1, *list2;
1203 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
1205 path1 = g_list_prepend (path1, tmp);
1206 tmp = get_native_parent (tmp);
1210 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
1212 path2 = g_list_prepend (path2, tmp);
1213 tmp = get_native_parent (tmp);
1219 while (list1 && list2 && (list1->data == list2->data))
1221 tmp = (GdkWindow *)list1->data;
1222 list1 = g_list_next (list1);
1223 list2 = g_list_next (list2);
1225 g_list_free (path1);
1226 g_list_free (path2);
1232 synthesize_crossing_events (GdkDisplay *display,
1235 GdkCrossingMode mode,
1237 GdkModifierType mask,
1239 gboolean non_linear)
1242 GdkWindow *win, *last, *next;
1246 GdkNotifyType notify_type;
1251 return; /* No crossings generated between src and dest */
1253 c = find_common_ancestor (a, b);
1255 non_linear |= (c != a) && (c != b);
1257 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
1259 /* Traverse up from a to (excluding) c sending leave events */
1261 notify_type = GDK_NOTIFY_NONLINEAR;
1263 notify_type = GDK_NOTIFY_INFERIOR;
1265 notify_type = GDK_NOTIFY_ANCESTOR;
1266 send_crossing_event (display,
1267 a, GDK_LEAVE_NOTIFY,
1277 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1279 notify_type = GDK_NOTIFY_VIRTUAL;
1282 win = get_native_parent (a);
1283 while (win != c && win->window_type != GDK_WINDOW_ROOT)
1285 send_crossing_event (display,
1286 win, GDK_LEAVE_NOTIFY,
1294 win = get_native_parent (win);
1299 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
1301 /* Traverse down from c to b */
1305 win = get_native_parent (b);
1306 while (win != c && win->window_type != GDK_WINDOW_ROOT)
1308 path = g_list_prepend (path, win);
1309 win = get_native_parent (win);
1313 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1315 notify_type = GDK_NOTIFY_VIRTUAL;
1320 win = (GdkWindow *)list->data;
1321 list = g_list_next (list);
1323 next = (GdkWindow *)list->data;
1327 send_crossing_event (display,
1328 win, GDK_ENTER_NOTIFY,
1340 notify_type = GDK_NOTIFY_NONLINEAR;
1342 notify_type = GDK_NOTIFY_ANCESTOR;
1344 notify_type = GDK_NOTIFY_INFERIOR;
1346 send_crossing_event (display,
1347 b, GDK_ENTER_NOTIFY,
1356 /* The check_extended flag controls whether to check if the windows want
1357 * events from extended input devices and if the message should be skipped
1358 * because an extended input device is active
1361 propagate (GdkWindow **window,
1363 GdkWindow *grab_window,
1364 gboolean grab_owner_events,
1366 gboolean (*doesnt_want_it) (gint mask,
1368 gboolean check_extended)
1370 if (grab_window != NULL && !grab_owner_events)
1372 /* Event source is grabbed with owner_events FALSE */
1374 /* See if the event should be ignored because an extended input
1377 if (check_extended &&
1378 grab_window->extension_events != 0 &&
1379 _gdk_input_ignore_core)
1381 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1384 if ((*doesnt_want_it) (grab_mask, msg))
1386 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1391 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1392 assign_object (window, grab_window);
1397 /* If we come here, we know that if grab_window != NULL then
1398 * grab_owner_events is TRUE
1402 if (check_extended &&
1403 (*window)->extension_events != 0 &&
1404 _gdk_input_ignore_core)
1406 GDK_NOTE (EVENTS, g_print (" (ignored)"));
1409 if ((*doesnt_want_it) ((*window)->event_mask, msg))
1411 /* Owner doesn't want it, propagate to parent. */
1412 GdkWindow *parent = gdk_window_get_parent (*window);
1413 if (parent == _gdk_root || parent == NULL)
1415 /* No parent; check if grabbed */
1416 if (grab_window != NULL)
1418 /* Event source is grabbed with owner_events TRUE */
1420 if (check_extended &&
1421 grab_window->extension_events != 0 &&
1422 _gdk_input_ignore_core)
1424 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1427 if ((*doesnt_want_it) (grab_mask, msg))
1429 /* Grabber doesn't want it either */
1430 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1436 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1437 assign_object (window, grab_window);
1443 GDK_NOTE (EVENTS, g_print (" (undelivered)"));
1449 assign_object (window, parent);
1450 /* The only branch where we actually continue the loop */
1459 doesnt_want_key (gint mask,
1462 return (((msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) &&
1463 !(mask & GDK_KEY_RELEASE_MASK)) ||
1464 ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) &&
1465 !(mask & GDK_KEY_PRESS_MASK)));
1469 doesnt_want_char (gint mask,
1472 return !(mask & (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK));
1476 handle_configure_event (MSG *msg,
1482 GetClientRect (msg->hwnd, &client_rect);
1483 point.x = client_rect.left; /* always 0 */
1484 point.y = client_rect.top;
1486 /* top level windows need screen coords */
1487 if (gdk_window_get_parent (window) == _gdk_root)
1489 ClientToScreen (msg->hwnd, &point);
1490 point.x += _gdk_offset_x;
1491 point.y += _gdk_offset_y;
1494 window->width = client_rect.right - client_rect.left;
1495 window->height = client_rect.bottom - client_rect.top;
1497 window->x = point.x;
1498 window->y = point.y;
1500 _gdk_window_update_size (window);
1502 if (window->event_mask & GDK_STRUCTURE_MASK)
1504 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1506 event->configure.window = window;
1508 event->configure.width = client_rect.right - client_rect.left;
1509 event->configure.height = client_rect.bottom - client_rect.top;
1511 event->configure.x = point.x;
1512 event->configure.y = point.y;
1514 _gdk_win32_append_event (event);
1519 _gdk_win32_hrgn_to_region (HRGN hrgn)
1523 cairo_region_t *result;
1527 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1529 WIN32_GDI_FAILED ("GetRegionData");
1533 rgndata = (RGNDATA *) g_malloc (nbytes);
1535 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1537 WIN32_GDI_FAILED ("GetRegionData");
1542 result = cairo_region_create ();
1543 rects = (RECT *) rgndata->Buffer;
1544 for (i = 0; i < rgndata->rdh.nCount; i++)
1548 r.x = rects[i].left;
1550 r.width = rects[i].right - r.x;
1551 r.height = rects[i].bottom - r.y;
1553 cairo_region_union_rectangle (result, &r);
1562 adjust_drag (LONG *drag,
1567 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1569 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1573 handle_wm_paint (MSG *msg,
1575 gboolean return_exposes,
1578 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1580 PAINTSTRUCT paintstruct;
1581 cairo_region_t *update_region;
1583 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1585 WIN32_GDI_FAILED ("GetUpdateRgn");
1586 DeleteObject (hrgn);
1590 hdc = BeginPaint (msg->hwnd, &paintstruct);
1592 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1593 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1594 (paintstruct.fErase ? "erase" : ""),
1596 (return_exposes ? " return_exposes" : "")));
1598 EndPaint (msg->hwnd, &paintstruct);
1600 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1601 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1603 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1604 DeleteObject (hrgn);
1610 if (!GDK_WINDOW_DESTROYED (window))
1612 GList *list = _gdk_display->queued_events;
1614 *event = gdk_event_new (GDK_EXPOSE);
1615 (*event)->expose.window = window;
1616 (*event)->expose.area.x = paintstruct.rcPaint.left;
1617 (*event)->expose.area.y = paintstruct.rcPaint.top;
1618 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1619 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1620 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1621 (*event)->expose.count = 0;
1623 while (list != NULL)
1625 GdkEventPrivate *evp = list->data;
1627 if (evp->event.any.type == GDK_EXPOSE &&
1628 evp->event.any.window == window &&
1629 !(evp->flags & GDK_EVENT_PENDING))
1630 evp->event.expose.count++;
1636 DeleteObject (hrgn);
1640 update_region = _gdk_win32_hrgn_to_region (hrgn);
1641 if (!cairo_region_is_empty (update_region))
1642 _gdk_window_invalidate_for_expose (window, update_region);
1643 cairo_region_destroy (update_region);
1645 DeleteObject (hrgn);
1648 static VOID CALLBACK
1649 modal_timer_proc (HWND hwnd,
1654 int arbitrary_limit = 1;
1656 while (_modal_operation_in_progress &&
1657 g_main_context_pending (NULL) &&
1659 g_main_context_iteration (NULL, FALSE);
1663 _gdk_win32_begin_modal_call (void)
1665 g_assert (!_modal_operation_in_progress);
1667 _modal_operation_in_progress = TRUE;
1669 modal_timer = SetTimer (NULL, 0, 10, modal_timer_proc);
1670 if (modal_timer == 0)
1671 WIN32_API_FAILED ("SetTimer");
1675 _gdk_win32_end_modal_call (void)
1677 g_assert (_modal_operation_in_progress);
1679 _modal_operation_in_progress = FALSE;
1681 if (modal_timer != 0)
1683 API_CALL (KillTimer, (NULL, modal_timer));
1688 static VOID CALLBACK
1689 sync_timer_proc (HWND hwnd,
1695 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1700 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1702 KillTimer (hwnd, sync_timer);
1706 handle_display_change (void)
1708 _gdk_monitor_init ();
1709 _gdk_root_window_size_init ();
1710 g_signal_emit_by_name (_gdk_screen, "size_changed");
1714 generate_button_event (GdkEventType type,
1719 GdkEvent *event = gdk_event_new (type);
1721 event->button.window = window;
1722 event->button.time = _gdk_win32_get_next_tick (msg->time);
1723 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1724 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1725 event->button.x_root = msg->pt.x + _gdk_offset_x;
1726 event->button.y_root = msg->pt.y + _gdk_offset_y;
1727 event->button.axes = NULL;
1728 event->button.state = build_pointer_event_state (msg);
1729 event->button.button = button;
1730 gdk_event_set_device (event, _gdk_display->core_pointer);
1732 _gdk_win32_append_event (event);
1736 ensure_stacking_on_unminimize (MSG *msg)
1739 HWND lowest_transient = NULL;
1742 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1744 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1746 /* Checking window group not implemented yet */
1749 GdkWindowImplWin32 *rover_impl =
1750 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1752 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1753 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1754 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1755 rover_impl->transient_owner != NULL))
1757 lowest_transient = rover;
1761 if (lowest_transient != NULL)
1763 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1764 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1765 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1770 ensure_stacking_on_window_pos_changing (MSG *msg,
1773 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1774 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1776 if (GetActiveWindow () == msg->hwnd &&
1777 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1778 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1779 impl->transient_owner == NULL)
1781 /* Make sure the window stays behind any transient-type windows
1782 * of the same window group.
1784 * If the window is not active and being activated, we let
1785 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1786 * handling to bring any utility windows on top of it.
1789 gboolean restacking;
1791 rover = windowpos->hwndInsertAfter;
1795 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1797 /* Checking window group not implemented yet */
1800 GdkWindowImplWin32 *rover_impl =
1801 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1803 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1804 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1805 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1806 rover_impl->transient_owner != NULL))
1809 windowpos->hwndInsertAfter = rover;
1812 rover = GetNextWindow (rover, GW_HWNDNEXT);
1817 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1825 ensure_stacking_on_activate_app (MSG *msg,
1828 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1830 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1831 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1832 impl->transient_owner != NULL)
1834 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1835 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1839 if (IsWindowVisible (msg->hwnd) &&
1840 msg->hwnd == GetActiveWindow ())
1842 /* This window is not a transient-type window and it is the
1843 * activated window. Make sure this window is as visible as
1844 * possible, just below the lowest transient-type window of this
1850 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
1852 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1854 /* Checking window group not implemented yet */
1857 GdkWindowImplWin32 *rover_impl =
1858 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1860 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1861 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1862 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1863 rover_impl->transient_owner != NULL))
1865 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1866 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1867 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1875 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
1876 GDK_BUTTON2_MASK | \
1877 GDK_BUTTON3_MASK | \
1878 GDK_BUTTON4_MASK | \
1882 gdk_event_translate (MSG *msg,
1885 RECT rect, *drag, orig_drag;
1890 BYTE key_state[256];
1892 WINDOWPOS *windowpos;
1899 GdkWindow *window = NULL;
1900 GdkWindowImplWin32 *impl;
1902 GdkWindow *orig_window, *new_window;
1904 GdkDeviceManager *device_manager;
1906 GdkDeviceGrabInfo *keyboard_grab = NULL;
1907 GdkDeviceGrabInfo *pointer_grab = NULL;
1908 GdkWindow *grab_window = NULL;
1914 gboolean return_val = FALSE;
1918 if (_gdk_default_filters)
1920 /* Apply global filters */
1922 GdkFilterReturn result = apply_event_filters (NULL, msg, &_gdk_default_filters);
1924 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1925 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1926 * we return TRUE, and DefWindowProcW() will not be called.
1928 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1932 window = gdk_win32_handle_table_lookup (msg->hwnd);
1933 orig_window = window;
1937 /* XXX Handle WM_QUIT here ? */
1938 if (msg->message == WM_QUIT)
1940 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1943 else if (msg->message == WM_MOVE ||
1944 msg->message == WM_SIZE)
1946 /* It's quite normal to get these messages before we have
1947 * had time to register the window in our lookup table, or
1948 * when the window is being destroyed and we already have
1949 * removed it. Repost the same message to our queue so that
1950 * we will get it later when we are prepared.
1952 GDK_NOTE (EVENTS, g_print (" (posted)"));
1954 PostMessageW (msg->hwnd, msg->message, msg->wParam, msg->lParam);
1956 else if (msg->message == WM_CREATE)
1958 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1959 GDK_WINDOW_HWND (window) = msg->hwnd;
1963 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1968 device_manager = gdk_display_get_device_manager (_gdk_display);
1970 keyboard_grab = _gdk_display_get_last_device_grab (_gdk_display,
1971 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
1972 pointer_grab = _gdk_display_get_last_device_grab (_gdk_display,
1973 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer);
1975 g_object_ref (window);
1977 /* window's refcount has now been increased, so code below should
1978 * not just return from this function, but instead goto done (or
1979 * break out of the big switch). To protect against forgetting this,
1980 * #define return to a syntax error...
1982 #define return GOTO_DONE_INSTEAD
1984 if (!GDK_WINDOW_DESTROYED (window) && window->filters)
1986 /* Apply per-window filters */
1988 GdkFilterReturn result = apply_event_filters (window, msg, &window->filters);
1990 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1997 if (msg->message == client_message)
2000 GdkFilterReturn result = GDK_FILTER_CONTINUE;
2003 GDK_NOTE (EVENTS, g_print (" client_message"));
2005 event = gdk_event_new (GDK_NOTHING);
2006 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2008 node = _gdk_event_queue_append (_gdk_display, event);
2010 tmp_list = client_filters;
2013 GdkClientFilter *filter = tmp_list->data;
2015 tmp_list = tmp_list->next;
2017 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
2019 GDK_NOTE (EVENTS, g_print (" (match)"));
2021 result = (*filter->function) (msg, event, filter->data);
2023 if (result != GDK_FILTER_CONTINUE)
2030 case GDK_FILTER_REMOVE:
2031 _gdk_event_queue_remove_link (_gdk_display, node);
2032 g_list_free_1 (node);
2033 gdk_event_free (event);
2037 case GDK_FILTER_TRANSLATE:
2038 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2039 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2043 case GDK_FILTER_CONTINUE:
2044 /* No more: Send unknown client messages on to Gtk for it to use */
2045 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2051 switch (msg->message)
2053 case WM_INPUTLANGCHANGE:
2054 _gdk_input_locale = (HKL) msg->lParam;
2055 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
2056 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
2057 LOCALE_IDEFAULTANSICODEPAGE,
2059 _gdk_input_codepage = atoi (buf);
2060 _gdk_keymap_serial++;
2062 g_print (" cs:%lu hkl:%p%s cp:%d",
2063 (gulong) msg->wParam,
2064 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
2065 _gdk_input_codepage));
2071 g_print (" %s ch:%.02x %s",
2072 _gdk_win32_key_to_string (msg->lParam),
2074 decode_key_lparam (msg->lParam)));
2076 /* If posted without us having keyboard focus, ignore */
2077 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
2078 !(HIWORD (msg->lParam) & KF_ALTDOWN))
2081 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
2082 * the keyboard is grabbed.
2084 if (!keyboard_grab &&
2085 (msg->wParam == VK_TAB ||
2086 msg->wParam == VK_SPACE ||
2087 msg->wParam == VK_F4))
2090 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
2096 g_print (" %s ch:%.02x %s",
2097 _gdk_win32_key_to_string (msg->lParam),
2099 decode_key_lparam (msg->lParam)));
2103 /* Ignore key messages intended for the IME */
2104 if (msg->wParam == VK_PROCESSKEY ||
2108 if (keyboard_grab &&
2109 !propagate (&window, msg,
2110 keyboard_grab->window,
2111 keyboard_grab->owner_events,
2112 GDK_ALL_EVENTS_MASK,
2113 doesnt_want_key, FALSE))
2116 if (GDK_WINDOW_DESTROYED (window))
2119 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
2120 msg->message == WM_SYSKEYDOWN) ?
2121 GDK_KEY_PRESS : GDK_KEY_RELEASE);
2122 event->key.window = window;
2123 event->key.time = _gdk_win32_get_next_tick (msg->time);
2124 event->key.keyval = GDK_KEY_VoidSymbol;
2125 event->key.string = NULL;
2126 event->key.length = 0;
2127 event->key.hardware_keycode = msg->wParam;
2128 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2129 if (HIWORD (msg->lParam) & KF_EXTENDED)
2131 switch (msg->wParam)
2134 event->key.hardware_keycode = VK_RCONTROL;
2136 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
2137 * for the right shift key.
2139 event->key.hardware_keycode = VK_RSHIFT;
2142 event->key.hardware_keycode = VK_RMENU;
2146 else if (msg->wParam == VK_SHIFT &&
2147 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
2148 event->key.hardware_keycode = VK_RSHIFT;
2150 API_CALL (GetKeyboardState, (key_state));
2152 /* 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]); */
2154 build_key_event_state (event, key_state);
2156 if (msg->wParam == VK_PACKET &&
2157 ToUnicode (VK_PACKET, HIWORD (msg->lParam), key_state, wbuf, 1, 0) == 1)
2158 event->key.keyval = gdk_unicode_to_keyval (wbuf[0]);
2160 gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (_gdk_display),
2161 event->key.hardware_keycode,
2167 fill_key_event_string (event);
2169 /* Reset MOD1_MASK if it is the Alt key itself */
2170 if (msg->wParam == VK_MENU)
2171 event->key.state &= ~GDK_MOD1_MASK;
2173 _gdk_win32_append_event (event);
2179 if (msg->wParam != VK_SPACE)
2181 /* To prevent beeps, don't let DefWindowProcW() be called */
2187 case WM_IME_STARTCOMPOSITION:
2188 in_ime_composition = TRUE;
2191 case WM_IME_ENDCOMPOSITION:
2192 in_ime_composition = FALSE;
2195 case WM_IME_COMPOSITION:
2196 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2197 * applications. Thus, handle WM_IME_COMPOSITION with
2198 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2199 * with ImmGetCompositionStringW().
2202 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2204 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2205 * for comments by other people that seems to have the same
2206 * experience. WM_IME_CHAR just gives question marks, apparently
2207 * because of going through some conversion to the current code
2210 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2211 * use WM_IME_COMPOSITION there, too, to simplify the code.
2213 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2215 if (!(msg->lParam & GCS_RESULTSTR))
2218 if (keyboard_grab &&
2219 !propagate (&window, msg,
2220 keyboard_grab->window,
2221 keyboard_grab->owner_events,
2222 GDK_ALL_EVENTS_MASK,
2223 doesnt_want_char, FALSE))
2226 if (GDK_WINDOW_DESTROYED (window))
2229 himc = ImmGetContext (msg->hwnd);
2230 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2231 wbuf, sizeof (wbuf));
2232 ImmReleaseContext (msg->hwnd, himc);
2236 API_CALL (GetKeyboardState, (key_state));
2238 for (i = 0; i < ccount; i++)
2240 if (window->event_mask & GDK_KEY_PRESS_MASK)
2242 /* Build a key press event */
2243 event = gdk_event_new (GDK_KEY_PRESS);
2244 event->key.window = window;
2245 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2246 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2248 _gdk_win32_append_event (event);
2251 if (window->event_mask & GDK_KEY_RELEASE_MASK)
2253 /* Build a key release event. */
2254 event = gdk_event_new (GDK_KEY_RELEASE);
2255 event->key.window = window;
2256 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2257 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2259 _gdk_win32_append_event (event);
2265 case WM_LBUTTONDOWN:
2269 case WM_MBUTTONDOWN:
2273 case WM_RBUTTONDOWN:
2277 case WM_XBUTTONDOWN:
2278 if (HIWORD (msg->wParam) == XBUTTON1)
2285 g_print (" (%d,%d)",
2286 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2288 assign_object (&window, find_window_for_mouse_event (window, msg));
2289 /* TODO_CSW?: there used to some synthesize and propagate */
2290 if (GDK_WINDOW_DESTROYED (window))
2293 if (pointer_grab == NULL)
2295 SetCapture (GDK_WINDOW_HWND (window));
2298 generate_button_event (GDK_BUTTON_PRESS, button,
2317 if (HIWORD (msg->wParam) == XBUTTON1)
2324 g_print (" (%d,%d)",
2325 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2327 assign_object (&window, find_window_for_mouse_event (window, msg));
2329 if (window->extension_events != 0 &&
2330 _gdk_input_ignore_core)
2332 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2337 if (pointer_grab != NULL && pointer_grab->implicit)
2339 gint state = build_pointer_event_state (msg);
2341 /* We keep the implicit grab until no buttons at all are held down */
2342 if ((state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (button - 1))) == 0)
2347 hwnd = WindowFromPoint (msg->pt);
2350 POINT client_pt = msg->pt;
2352 ScreenToClient (hwnd, &client_pt);
2353 GetClientRect (hwnd, &rect);
2354 if (PtInRect (&rect, client_pt))
2355 new_window = gdk_win32_handle_table_lookup (hwnd);
2357 synthesize_crossing_events (_gdk_display,
2358 pointer_grab->native_window, new_window,
2359 GDK_CROSSING_UNGRAB,
2361 0, /* TODO: Set right mask */
2364 assign_object (&mouse_window, new_window);
2368 generate_button_event (GDK_BUTTON_RELEASE, button,
2376 g_print (" %p (%d,%d)",
2377 (gpointer) msg->wParam,
2378 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2380 new_window = window;
2382 if (pointer_grab != NULL)
2388 hwnd = WindowFromPoint (pt);
2391 POINT client_pt = pt;
2393 ScreenToClient (hwnd, &client_pt);
2394 GetClientRect (hwnd, &rect);
2395 if (PtInRect (&rect, client_pt))
2396 new_window = gdk_win32_handle_table_lookup (hwnd);
2399 if (!pointer_grab->owner_events &&
2400 new_window != NULL &&
2401 new_window != pointer_grab->native_window)
2405 if (mouse_window != new_window)
2407 GDK_NOTE (EVENTS, g_print (" mouse_sinwod %p -> %p",
2408 mouse_window ? GDK_WINDOW_HWND (mouse_window) : NULL,
2409 new_window ? GDK_WINDOW_HWND (new_window) : NULL));
2410 synthesize_crossing_events (_gdk_display,
2411 mouse_window, new_window,
2412 GDK_CROSSING_NORMAL,
2414 0, /* TODO: Set right mask */
2417 assign_object (&mouse_window, new_window);
2418 if (new_window != NULL)
2419 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (new_window));
2422 assign_object (&window, find_window_for_mouse_event (window, msg));
2424 /* If we haven't moved, don't create any GDK event. Windows
2425 * sends WM_MOUSEMOVE messages after a new window is shows under
2426 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2428 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2429 msg->pt.y + _gdk_offset_y == current_root_y)
2432 current_root_x = msg->pt.x + _gdk_offset_x;
2433 current_root_y = msg->pt.y + _gdk_offset_y;
2435 event = gdk_event_new (GDK_MOTION_NOTIFY);
2436 event->motion.window = window;
2437 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2438 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2439 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2440 event->motion.x_root = current_root_x;
2441 event->motion.y_root = current_root_y;
2442 event->motion.axes = NULL;
2443 event->motion.state = build_pointer_event_state (msg);
2444 event->motion.is_hint = FALSE;
2445 gdk_event_set_device (event, _gdk_display->core_pointer);
2447 _gdk_win32_append_event (event);
2452 case WM_NCMOUSEMOVE:
2454 g_print (" (%d,%d)",
2455 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2459 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2460 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2463 hwnd = WindowFromPoint (msg->pt);
2466 POINT client_pt = msg->pt;
2468 ScreenToClient (hwnd, &client_pt);
2469 GetClientRect (hwnd, &rect);
2470 if (PtInRect (&rect, client_pt))
2471 new_window = gdk_win32_handle_table_lookup (hwnd);
2474 synthesize_crossing_events (_gdk_display,
2475 mouse_window, new_window,
2476 GDK_CROSSING_NORMAL,
2478 0, /* TODO: Set right mask */
2481 assign_object (&mouse_window, new_window);
2487 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2489 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2490 * that. Also, the position is in screen coordinates, not client
2491 * coordinates as with the button messages. I love the
2492 * consistency of Windows.
2494 point.x = GET_X_LPARAM (msg->lParam);
2495 point.y = GET_Y_LPARAM (msg->lParam);
2497 if ((hwnd = WindowFromPoint (point)) == NULL)
2501 if ((new_window = gdk_win32_handle_table_lookup (msg->hwnd)) == NULL)
2504 if (new_window != window)
2506 assign_object (&window, new_window);
2509 ScreenToClient (msg->hwnd, &point);
2511 event = gdk_event_new (GDK_SCROLL);
2512 event->scroll.window = window;
2513 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2514 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2515 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2516 event->scroll.x = (gint16) point.x;
2517 event->scroll.y = (gint16) point.y;
2518 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2519 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2520 event->scroll.state = build_pointer_event_state (msg);
2521 gdk_event_set_device (event, _gdk_display->core_pointer);
2523 _gdk_win32_append_event (event);
2529 /* Just print more debugging information, don't actually handle it. */
2532 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2533 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2534 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2535 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2536 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2537 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2538 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2539 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2540 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2542 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2543 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2544 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2548 /* Just print more debugging information, don't actually handle it. */
2551 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2552 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2553 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2554 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2555 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2556 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2557 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2558 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2559 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2561 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2562 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2563 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2566 case WM_MOUSEACTIVATE:
2570 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2571 || !window->accept_focus)
2573 *ret_valp = MA_NOACTIVATE;
2577 tmp = _gdk_modal_current ();
2581 if (gdk_window_get_toplevel (window) != tmp)
2583 *ret_valp = MA_NOACTIVATEANDEAT;
2592 if (keyboard_grab != NULL &&
2593 !GDK_WINDOW_DESTROYED (keyboard_grab->window))
2595 generate_grab_broken_event (device_manager, keyboard_grab->window, TRUE, NULL);
2600 if (keyboard_grab != NULL &&
2601 !keyboard_grab->owner_events)
2604 if (!(window->event_mask & GDK_FOCUS_CHANGE_MASK))
2607 if (GDK_WINDOW_DESTROYED (window))
2610 generate_focus_event (device_manager, window, (msg->message == WM_SETFOCUS));
2615 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2617 if (GDK_WINDOW_DESTROYED (window))
2625 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2627 200, sync_timer_proc);
2631 handle_wm_paint (msg, window, FALSE, NULL);
2635 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2636 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2638 if (pointer_grab != NULL)
2639 grab_window = pointer_grab->window;
2641 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2644 if (grab_window != NULL && p_grab_cursor != NULL)
2645 hcursor = p_grab_cursor;
2646 else if (!GDK_WINDOW_DESTROYED (window))
2647 hcursor = GDK_WINDOW_IMPL_WIN32 (window->impl)->hcursor;
2651 if (hcursor != NULL)
2653 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2654 SetCursor (hcursor);
2661 GDK_NOTE (EVENTS, g_print (" %s %s",
2662 (msg->wParam ? "YES" : "NO"),
2663 (msg->lParam == 0 ? "ShowWindow" :
2664 (msg->lParam == SW_OTHERUNZOOM ? "OTHERUNZOOM" :
2665 (msg->lParam == SW_OTHERZOOM ? "OTHERZOOM" :
2666 (msg->lParam == SW_PARENTCLOSING ? "PARENTCLOSING" :
2667 (msg->lParam == SW_PARENTOPENING ? "PARENTOPENING" :
2670 if (!(window->event_mask & GDK_STRUCTURE_MASK))
2673 if (msg->lParam == SW_OTHERUNZOOM ||
2674 msg->lParam == SW_OTHERZOOM)
2677 if (GDK_WINDOW_DESTROYED (window))
2680 event = gdk_event_new (msg->wParam ? GDK_MAP : GDK_UNMAP);
2681 event->any.window = window;
2683 _gdk_win32_append_event (event);
2685 if (event->any.type == GDK_UNMAP)
2687 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2689 if (impl->transient_owner && GetForegroundWindow () == GDK_WINDOW_HWND (window))
2691 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2694 if (pointer_grab != NULL)
2696 if (pointer_grab->window == window)
2697 gdk_pointer_ungrab (msg->time);
2700 if (keyboard_grab &&
2701 keyboard_grab->window == window)
2702 gdk_keyboard_ungrab (msg->time);
2709 switch (msg->wParam)
2713 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2721 g_print (" %s %dx%d",
2722 (msg->wParam == SIZE_MAXHIDE ? "MAXHIDE" :
2723 (msg->wParam == SIZE_MAXIMIZED ? "MAXIMIZED" :
2724 (msg->wParam == SIZE_MAXSHOW ? "MAXSHOW" :
2725 (msg->wParam == SIZE_MINIMIZED ? "MINIMIZED" :
2726 (msg->wParam == SIZE_RESTORED ? "RESTORED" : "?"))))),
2727 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2729 if (msg->wParam == SIZE_MINIMIZED)
2731 /* Don't generate any GDK event. This is *not* an UNMAP. */
2732 if (pointer_grab != NULL)
2734 if (pointer_grab->window == window)
2735 gdk_pointer_ungrab (msg->time);
2737 if (keyboard_grab &&
2738 keyboard_grab->window == window)
2739 gdk_keyboard_ungrab (msg->time);
2741 gdk_synthesize_window_state (window,
2742 GDK_WINDOW_STATE_WITHDRAWN,
2743 GDK_WINDOW_STATE_ICONIFIED);
2744 do_show_window (window, TRUE);
2746 else if ((msg->wParam == SIZE_RESTORED ||
2747 msg->wParam == SIZE_MAXIMIZED) &&
2748 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
2750 GdkWindowState withdrawn_bit =
2751 IsWindowVisible (msg->hwnd) ? GDK_WINDOW_STATE_WITHDRAWN : 0;
2753 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
2754 ensure_stacking_on_unminimize (msg);
2756 if (!GDK_WINDOW_DESTROYED (window))
2757 handle_configure_event (msg, window);
2759 if (msg->wParam == SIZE_RESTORED)
2761 gdk_synthesize_window_state (window,
2762 GDK_WINDOW_STATE_ICONIFIED |
2763 GDK_WINDOW_STATE_MAXIMIZED |
2767 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_TEMP && !GDK_WINDOW_IS_MAPPED (window))
2769 do_show_window (window, FALSE);
2772 else if (msg->wParam == SIZE_MAXIMIZED)
2774 gdk_synthesize_window_state (window,
2775 GDK_WINDOW_STATE_ICONIFIED |
2777 GDK_WINDOW_STATE_MAXIMIZED);
2780 if (window->resize_count > 1)
2781 window->resize_count -= 1;
2783 if (window->extension_events != 0)
2784 _gdk_device_wintab_update_window_coords (window);
2790 case WM_ENTERSIZEMOVE:
2791 case WM_ENTERMENULOOP:
2792 _gdk_win32_begin_modal_call ();
2795 case WM_EXITSIZEMOVE:
2796 case WM_EXITMENULOOP:
2797 _gdk_win32_end_modal_call ();
2800 case WM_WINDOWPOSCHANGING:
2801 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2802 g_print (" %s %s %dx%d@%+d%+d now below %p",
2803 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2804 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2805 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2806 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2807 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2808 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2810 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2811 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2813 if (GDK_WINDOW_IS_MAPPED (window))
2814 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2817 case WM_WINDOWPOSCHANGED:
2818 windowpos = (WINDOWPOS *) msg->lParam;
2819 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2820 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2821 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2822 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2823 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2824 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2825 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2827 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2829 /* If position and size haven't changed, don't do anything */
2830 if (_modal_operation_in_progress &&
2831 (windowpos->flags & SWP_NOMOVE) &&
2832 (windowpos->flags & SWP_NOSIZE))
2835 /* Once we've entered the moving or sizing modal loop, we won't
2836 * return to the main loop until we're done sizing or moving.
2838 if (_modal_operation_in_progress &&
2839 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2840 !GDK_WINDOW_DESTROYED (window))
2842 if (window->event_mask & GDK_STRUCTURE_MASK)
2844 GDK_NOTE (EVENTS, g_print (" do magic"));
2845 if (window->resize_count > 1)
2846 window->resize_count -= 1;
2848 handle_configure_event (msg, window);
2849 g_main_context_iteration (NULL, FALSE);
2851 /* Dispatch main loop - to realize resizes... */
2852 modal_timer_proc (msg->hwnd, msg->message, 0, msg->time);
2854 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2862 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2863 drag = (RECT *) msg->lParam;
2864 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2865 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2866 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2867 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2868 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2869 (msg->wParam == WMSZ_TOP ? "TOP" :
2870 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2871 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2873 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2875 _gdk_win32_rect_to_string (&rect),
2876 _gdk_win32_rect_to_string (drag)));
2878 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2880 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2882 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2883 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2885 /* Resize in increments relative to the base size */
2886 rect.left = rect.top = 0;
2887 rect.right = impl->hints.base_width;
2888 rect.bottom = impl->hints.base_height;
2889 _gdk_win32_adjust_client_rect (window, &rect);
2890 point.x = rect.left;
2892 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2893 rect.left = point.x;
2895 point.x = rect.right;
2896 point.y = rect.bottom;
2897 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2898 rect.right = point.x;
2899 rect.bottom = point.y;
2901 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2902 _gdk_win32_rect_to_string (&rect)));
2905 switch (msg->wParam)
2908 if (drag->bottom == rect.bottom)
2910 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2913 case WMSZ_BOTTOMLEFT:
2914 if (drag->bottom == rect.bottom && drag->left == rect.left)
2916 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2917 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2921 if (drag->left == rect.left)
2923 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2927 if (drag->top == rect.top && drag->left == rect.left)
2929 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2930 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2934 if (drag->top == rect.top)
2936 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2940 if (drag->top == rect.top && drag->right == rect.right)
2942 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2943 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2947 if (drag->right == rect.right)
2949 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2952 case WMSZ_BOTTOMRIGHT:
2953 if (drag->bottom == rect.bottom && drag->right == rect.right)
2955 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2956 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2960 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2961 drag->top != orig_drag.top || drag->right != orig_drag.right)
2965 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2966 _gdk_win32_rect_to_string (drag)));
2970 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2972 if (impl->hint_flags & GDK_HINT_ASPECT)
2974 RECT decorated_rect;
2975 RECT undecorated_drag;
2976 int decoration_width, decoration_height;
2977 gdouble drag_aspect;
2978 int drag_width, drag_height, new_width, new_height;
2980 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2981 decorated_rect = rect;
2982 _gdk_win32_adjust_client_rect (window, &decorated_rect);
2984 /* Set undecorated_drag to the client area being dragged
2985 * out, in screen coordinates.
2987 undecorated_drag = *drag;
2988 undecorated_drag.left -= decorated_rect.left - rect.left;
2989 undecorated_drag.right -= decorated_rect.right - rect.right;
2990 undecorated_drag.top -= decorated_rect.top - rect.top;
2991 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
2993 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
2994 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
2996 drag_width = undecorated_drag.right - undecorated_drag.left;
2997 drag_height = undecorated_drag.bottom - undecorated_drag.top;
2999 drag_aspect = (gdouble) drag_width / drag_height;
3001 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
3002 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
3004 if (drag_aspect < impl->hints.min_aspect)
3006 /* Aspect is getting too narrow */
3007 switch (msg->wParam)
3011 /* User drags top or bottom edge outward. Keep height, increase width. */
3012 new_width = impl->hints.min_aspect * drag_height;
3013 drag->left -= (new_width - drag_width) / 2;
3014 drag->right = drag->left + new_width + decoration_width;
3016 case WMSZ_BOTTOMLEFT:
3017 case WMSZ_BOTTOMRIGHT:
3018 /* User drags bottom-left or bottom-right corner down. Adjust height. */
3019 new_height = drag_width / impl->hints.min_aspect;
3020 drag->bottom = drag->top + new_height + decoration_height;
3024 /* User drags left or right edge inward. Decrease height */
3025 new_height = drag_width / impl->hints.min_aspect;
3026 drag->top += (drag_height - new_height) / 2;
3027 drag->bottom = drag->top + new_height + decoration_height;
3031 /* User drags top-left or top-right corner up. Adjust height. */
3032 new_height = drag_width / impl->hints.min_aspect;
3033 drag->top = drag->bottom - new_height - decoration_height;
3036 else if (drag_aspect > impl->hints.max_aspect)
3038 /* Aspect is getting too wide */
3039 switch (msg->wParam)
3043 /* User drags top or bottom edge inward. Decrease width. */
3044 new_width = impl->hints.max_aspect * drag_height;
3045 drag->left += (drag_width - new_width) / 2;
3046 drag->right = drag->left + new_width + decoration_width;
3048 case WMSZ_BOTTOMLEFT:
3050 /* User drags bottom-left or top-left corner left. Adjust width. */
3051 new_width = impl->hints.max_aspect * drag_height;
3052 drag->left = drag->right - new_width - decoration_width;
3054 case WMSZ_BOTTOMRIGHT:
3056 /* User drags bottom-right or top-right corner right. Adjust width. */
3057 new_width = impl->hints.max_aspect * drag_height;
3058 drag->right = drag->left + new_width + decoration_width;
3062 /* User drags left or right edge outward. Increase height. */
3063 new_height = drag_width / impl->hints.max_aspect;
3064 drag->top -= (new_height - drag_height) / 2;
3065 drag->bottom = drag->top + new_height + decoration_height;
3072 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
3073 _gdk_win32_rect_to_string (drag)));
3077 case WM_GETMINMAXINFO:
3078 if (GDK_WINDOW_DESTROYED (window))
3081 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3082 mmi = (MINMAXINFO*) msg->lParam;
3083 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
3084 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3085 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3086 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3087 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3088 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3090 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
3092 rect.left = rect.top = 0;
3093 rect.right = impl->hints.min_width;
3094 rect.bottom = impl->hints.min_height;
3096 _gdk_win32_adjust_client_rect (window, &rect);
3098 mmi->ptMinTrackSize.x = rect.right - rect.left;
3099 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
3102 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
3106 rect.left = rect.top = 0;
3107 rect.right = impl->hints.max_width;
3108 rect.bottom = impl->hints.max_height;
3110 _gdk_win32_adjust_client_rect (window, &rect);
3112 /* at least on win9x we have the 16 bit trouble */
3113 maxw = rect.right - rect.left;
3114 maxh = rect.bottom - rect.top;
3115 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
3116 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
3119 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
3121 /* Don't call DefWindowProcW() */
3122 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
3123 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3124 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3125 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3126 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3127 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3133 GDK_NOTE (EVENTS, g_print (" (%d,%d)",
3134 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
3136 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
3137 !IsIconic (msg->hwnd))
3139 if (!GDK_WINDOW_DESTROYED (window))
3140 handle_configure_event (msg, window);
3147 if (GDK_WINDOW_DESTROYED (window))
3150 event = gdk_event_new (GDK_DELETE);
3151 event->any.window = window;
3153 _gdk_win32_append_event (event);
3155 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3157 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
3159 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3166 if (pointer_grab != NULL)
3168 if (pointer_grab->window == window)
3169 gdk_pointer_ungrab (msg->time);
3172 if (keyboard_grab &&
3173 keyboard_grab->window == window)
3174 gdk_keyboard_ungrab (msg->time);
3176 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
3177 gdk_window_destroy_notify (window);
3179 if (window == NULL || GDK_WINDOW_DESTROYED (window))
3182 event = gdk_event_new (GDK_DESTROY);
3183 event->any.window = window;
3185 _gdk_win32_append_event (event);
3190 case WM_DISPLAYCHANGE:
3191 handle_display_change ();
3194 case WM_DESTROYCLIPBOARD:
3195 if (!_ignore_destroy_clipboard)
3197 event = gdk_event_new (GDK_SELECTION_CLEAR);
3198 event->selection.window = window;
3199 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3200 event->selection.time = _gdk_win32_get_next_tick (msg->time);
3201 _gdk_win32_append_event (event);
3210 case WM_RENDERFORMAT:
3211 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
3213 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
3215 GDK_NOTE (EVENTS, g_print (" (target not found)"));
3220 /* We need to render to clipboard immediately, don't call
3221 * _gdk_win32_append_event()
3223 event = gdk_event_new (GDK_SELECTION_REQUEST);
3224 event->selection.window = window;
3225 event->selection.send_event = FALSE;
3226 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3227 event->selection.target = target;
3228 event->selection.property = _gdk_selection;
3229 event->selection.requestor = gdk_win32_handle_table_lookup (msg->hwnd);
3230 event->selection.time = msg->time;
3232 fixup_event (event);
3233 GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)"));
3234 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
3235 _gdk_event_emit (event);
3236 gdk_event_free (event);
3238 /* Now the clipboard owner should have rendered */
3239 if (!_delayed_rendering_data)
3241 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3245 if (msg->wParam == CF_DIB)
3247 _delayed_rendering_data =
3248 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3250 if (!_delayed_rendering_data)
3252 g_warning ("Cannot convert to DIB from delayed rendered image");
3257 /* The requestor is holding the clipboard, no
3258 * OpenClipboard() is required/possible
3261 g_print (" SetClipboardData(%s,%p)",
3262 _gdk_win32_cf_to_string (msg->wParam),
3263 _delayed_rendering_data));
3265 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3266 _delayed_rendering_data = NULL;
3271 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3272 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3273 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3274 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3275 HIWORD (msg->wParam) ? " minimized" : "",
3276 (HWND) msg->lParam));
3277 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3278 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3281 if (is_modally_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3283 GdkWindow *modal_current = _gdk_modal_current ();
3284 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3290 /* Bring any tablet contexts to the top of the overlap order when
3291 * one of our windows is activated.
3292 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3295 if (LOWORD(msg->wParam) != WA_INACTIVE)
3296 _gdk_input_set_tablet_active ();
3299 case WM_ACTIVATEAPP:
3300 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3301 msg->wParam ? "YES" : "NO",
3302 (gint64) msg->lParam));
3303 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3304 ensure_stacking_on_activate_app (msg, window);
3307 /* Handle WINTAB events here, as we know that gdkinput.c will
3308 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3309 * constants as case labels.
3312 GDK_NOTE (EVENTS, g_print (" %d %p",
3313 (int) msg->wParam, (gpointer) msg->lParam));
3317 GDK_NOTE (EVENTS, g_print (" %d %p",
3318 (int) msg->wParam, (gpointer) msg->lParam));
3322 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3323 (gpointer) msg->wParam,
3324 LOWORD (msg->lParam),
3325 HIWORD (msg->lParam)));
3329 event = gdk_event_new (GDK_NOTHING);
3330 event->any.window = window;
3331 g_object_ref (window);
3333 if (_gdk_input_other_event (event, msg, window))
3334 _gdk_win32_append_event (event);
3336 gdk_event_free (event);
3344 g_object_unref (window);
3351 _gdk_win32_display_queue_events (GdkDisplay *display)
3355 if (modal_win32_dialog != NULL)
3358 while (!_gdk_event_queue_find_first (display) &&
3359 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3361 TranslateMessage (&msg);
3362 DispatchMessageW (&msg);
3367 gdk_event_prepare (GSource *source,
3373 GDK_THREADS_ENTER ();
3377 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3378 (modal_win32_dialog == NULL &&
3379 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3381 GDK_THREADS_LEAVE ();
3387 gdk_event_check (GSource *source)
3392 GDK_THREADS_ENTER ();
3394 if (event_poll_fd.revents & G_IO_IN)
3396 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3397 (modal_win32_dialog == NULL &&
3398 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3405 GDK_THREADS_LEAVE ();
3411 gdk_event_dispatch (GSource *source,
3412 GSourceFunc callback,
3417 GDK_THREADS_ENTER ();
3419 _gdk_win32_display_queue_events (_gdk_display);
3420 event = _gdk_event_unqueue (_gdk_display);
3424 _gdk_event_emit (event);
3426 gdk_event_free (event);
3428 /* Do drag & drop if it is still pending */
3429 if (_dnd_source_state == GDK_WIN32_DND_PENDING)
3431 _dnd_source_state = GDK_WIN32_DND_DRAGGING;
3432 _gdk_win32_dnd_do_dragdrop ();
3433 _dnd_source_state = GDK_WIN32_DND_NONE;
3437 GDK_THREADS_LEAVE ();
3443 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3445 modal_win32_dialog = window;
3449 is_modally_blocked (GdkWindow *window)
3451 GdkWindow *modal_current = _gdk_modal_current ();
3452 return modal_current != NULL ? gdk_window_get_toplevel (window) != modal_current : FALSE;
3456 _gdk_win32_display_sync (GdkDisplay * display)
3460 g_return_if_fail (display == _gdk_display);
3462 /* Process all messages currently available */
3463 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3464 DispatchMessageW (&msg);