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, see <http://www.gnu.org/licenses/>.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 /* Cannot use TrackMouseEvent, as the stupid WM_MOUSELEAVE message
29 * doesn't tell us where the mouse has gone. Thus we cannot use it to
30 * generate a correct GdkNotifyType. Pity, as using TrackMouseEvent
31 * otherwise would make it possible to reliably generate
32 * GDK_LEAVE_NOTIFY events, which would help get rid of those pesky
33 * tooltips sometimes popping up in the wrong place.
35 * Update: a combination of TrackMouseEvent, GetCursorPos and
36 * GetWindowPos can and is actually used to get rid of those
37 * pesky tooltips. It should be possible to use this for the
38 * whole ENTER/LEAVE NOTIFY handling but some platforms may
39 * not have TrackMouseEvent at all (?) --hb
44 #include <glib/gprintf.h>
47 #include "gdkdisplayprivate.h"
48 #include "gdkprivate-win32.h"
50 #include "gdkkeysyms.h"
51 #include "gdkdevicemanager-win32.h"
52 #include "gdkdeviceprivate.h"
53 #include "gdkdevice-wintab.h"
54 #include "gdkwin32dnd.h"
55 #include "gdkdndprivate.h"
79 #define MK_XBUTTON1 32
80 #define MK_XBUTTON2 64
83 /* Undefined flags: */
84 #define SWP_NOCLIENTSIZE 0x0800
85 #define SWP_NOCLIENTMOVE 0x1000
86 #define SWP_STATECHANGED 0x8000
88 * Private function declarations
91 #define SYNAPSIS_ICON_WINDOW_CLASS "SynTrackCursorWindowClass"
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 /* Private variable declarations
110 static GList *client_filters; /* Filters for client messages */
111 extern gint _gdk_input_ignore_core;
113 HCURSOR _gdk_win32_grab_cursor;
115 static GSourceFuncs event_funcs = {
122 GPollFD event_poll_fd;
124 static GdkWindow *mouse_window = NULL;
125 static GdkWindow *mouse_window_ignored_leave = NULL;
126 static gint current_x, current_y;
127 static gint current_root_x, current_root_y;
128 static UINT client_message;
130 static UINT got_gdk_events_message;
131 static HWND modal_win32_dialog = NULL;
134 static HKL latin_locale = NULL;
137 static gboolean in_ime_composition = FALSE;
138 static UINT modal_timer;
139 static UINT sync_timer = 0;
141 static int debug_indent = 0;
144 assign_object (gpointer lhsp,
147 if (*(gpointer *)lhsp != rhs)
149 if (*(gpointer *)lhsp != NULL)
150 g_object_unref (*(gpointer *)lhsp);
151 *(gpointer *)lhsp = rhs;
158 track_mouse_event (DWORD dwFlags,
163 tme.cbSize = sizeof(TRACKMOUSEEVENT);
164 tme.dwFlags = dwFlags;
165 tme.hwndTrack = hwnd;
166 tme.dwHoverTime = HOVER_DEFAULT; /* not used */
168 if (!TrackMouseEvent (&tme))
169 WIN32_API_FAILED ("TrackMouseEvent");
170 else if (dwFlags == TME_LEAVE)
171 GDK_NOTE (EVENTS, g_print(" (TrackMouseEvent %p)", hwnd));
172 else if (dwFlags == TME_CANCEL)
173 GDK_NOTE (EVENTS, g_print(" (cancel TrackMouseEvent %p)", hwnd));
177 _gdk_win32_get_next_tick (gulong suggested_tick)
179 static gulong cur_tick = 0;
181 if (suggested_tick == 0)
182 suggested_tick = GetTickCount ();
183 if (suggested_tick <= cur_tick)
186 return cur_tick = suggested_tick;
190 generate_focus_event (GdkDeviceManager *device_manager,
195 GdkDevice *source_device;
198 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
199 source_device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->system_keyboard;
201 event = gdk_event_new (GDK_FOCUS_CHANGE);
202 event->focus_change.window = window;
203 event->focus_change.in = in;
204 gdk_event_set_device (event, device);
205 gdk_event_set_source_device (event, source_device);
207 _gdk_win32_append_event (event);
211 generate_grab_broken_event (GdkDeviceManager *device_manager,
214 GdkWindow *grab_window)
216 GdkEvent *event = gdk_event_new (GDK_GRAB_BROKEN);
218 GdkDevice *source_device;
222 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
223 source_device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->system_keyboard;
227 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer;
228 source_device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->system_pointer;
231 event->grab_broken.window = window;
232 event->grab_broken.send_event = 0;
233 event->grab_broken.keyboard = keyboard;
234 event->grab_broken.implicit = FALSE;
235 event->grab_broken.grab_window = grab_window;
236 gdk_event_set_device (event, device);
237 gdk_event_set_source_device (event, device);
239 _gdk_win32_append_event (event);
243 inner_window_procedure (HWND hwnd,
253 msg.message = message;
256 msg.time = _gdk_win32_get_next_tick (0);
257 pos = GetMessagePos ();
258 msg.pt.x = GET_X_LPARAM (pos);
259 msg.pt.y = GET_Y_LPARAM (pos);
261 if (gdk_event_translate (&msg, &ret_val))
263 /* If gdk_event_translate() returns TRUE, we return ret_val from
264 * the window procedure.
266 if (modal_win32_dialog)
267 PostMessageW (modal_win32_dialog, got_gdk_events_message,
273 /* Otherwise call DefWindowProcW(). */
274 GDK_NOTE (EVENTS, g_print (" DefWindowProcW"));
275 return DefWindowProcW (hwnd, message, wparam, lparam);
280 _gdk_win32_window_procedure (HWND hwnd,
287 GDK_NOTE (EVENTS, g_print ("%s%*s%s %p",
288 (debug_indent > 0 ? "\n" : ""),
290 _gdk_win32_message_to_string (message), hwnd));
292 retval = inner_window_procedure (hwnd, message, wparam, lparam);
295 GDK_NOTE (EVENTS, g_print (" => %I64d%s", (gint64) retval, (debug_indent == 0 ? "\n" : "")));
301 _gdk_events_init (void)
308 /* List of languages that use a latin keyboard. Somewhat sorted in
309 * "order of least surprise", in case we have to load one of them if
310 * the user only has arabic loaded, for instance.
312 static int latin_languages[] = {
318 /* Rest in numeric order */
347 client_message = RegisterWindowMessage ("GDK_WIN32_CLIENT_MESSAGE");
348 got_gdk_events_message = RegisterWindowMessage ("GDK_WIN32_GOT_EVENTS");
351 /* Check if we have some input locale identifier loaded that uses a
352 * latin keyboard, to be able to get the virtual-key code for the
353 * latin characters corresponding to ASCII control characters.
355 if ((n = GetKeyboardLayoutList (0, NULL)) == 0)
356 WIN32_API_FAILED ("GetKeyboardLayoutList");
359 HKL *hkl_list = g_new (HKL, n);
360 if (GetKeyboardLayoutList (n, hkl_list) == 0)
361 WIN32_API_FAILED ("GetKeyboardLayoutList");
364 for (i = 0; latin_locale == NULL && i < n; i++)
365 for (j = 0; j < G_N_ELEMENTS (latin_languages); j++)
366 if (PRIMARYLANGID (LOWORD (hkl_list[i])) == latin_languages[j])
368 latin_locale = hkl_list [i];
375 if (latin_locale == NULL)
377 /* Try to load a keyboard layout with latin characters then.
380 while (latin_locale == NULL && i < G_N_ELEMENTS (latin_languages))
383 g_sprintf (id, "%08x", MAKELANGID (latin_languages[i++], SUBLANG_DEFAULT));
384 latin_locale = LoadKeyboardLayout (id, KLF_NOTELLSHELL|KLF_SUBSTITUTE_OK);
388 GDK_NOTE (EVENTS, g_print ("latin_locale = %08x\n", (guint) latin_locale));
391 source = g_source_new (&event_funcs, sizeof (GSource));
392 g_source_set_name (source, "GDK Win32 event source");
393 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
396 event_poll_fd.fd = open ("/dev/windows", O_RDONLY);
397 if (event_poll_fd.fd == -1)
398 g_error ("can't open \"/dev/windows\": %s", g_strerror (errno));
400 event_poll_fd.fd = G_WIN32_MSG_HANDLE;
402 event_poll_fd.events = G_IO_IN;
404 g_source_add_poll (source, &event_poll_fd);
405 g_source_set_can_recurse (source, TRUE);
406 g_source_attach (source, NULL);
410 _gdk_win32_display_has_pending (GdkDisplay *display)
412 return (_gdk_event_queue_find_first (display) ||
413 (modal_win32_dialog == NULL &&
414 GetQueueStatus (QS_ALLINPUT) != 0));
417 #if 0 /* Unused, but might be useful to re-introduce in some debugging output? */
420 event_mask_string (GdkEventMask mask)
422 static char bfr[500];
427 if (mask & GDK_##x##_MASK) \
428 p += g_sprintf (p, "%s" #x, (p > bfr ? " " : ""))
430 BIT (POINTER_MOTION);
431 BIT (POINTER_MOTION_HINT);
433 BIT (BUTTON1_MOTION);
434 BIT (BUTTON2_MOTION);
435 BIT (BUTTON3_MOTION);
437 BIT (BUTTON_RELEASE);
444 BIT (PROPERTY_CHANGE);
445 BIT (VISIBILITY_NOTIFY);
458 find_window_for_mouse_event (GdkWindow* reported_window,
462 GdkDeviceManagerWin32 *device_manager;
463 GdkWindow *event_window;
466 GdkDeviceGrabInfo *grab;
468 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (_gdk_display));
470 grab = _gdk_display_get_last_device_grab (_gdk_display, device_manager->core_pointer);
472 return reported_window;
476 if (!grab->owner_events)
477 event_window = grab->native_window;
481 hwnd = WindowFromPoint (pt);
484 POINT client_pt = pt;
486 ScreenToClient (hwnd, &client_pt);
487 GetClientRect (hwnd, &rect);
488 if (PtInRect (&rect, client_pt))
489 event_window = gdk_win32_handle_table_lookup (hwnd);
491 if (event_window == NULL)
492 event_window = grab->native_window;
495 /* need to also adjust the coordinates to the new window */
496 ScreenToClient (GDK_WINDOW_HWND (event_window), &pt);
498 /* ATTENTION: need to update client coords */
499 msg->lParam = MAKELPARAM (pt.x, pt.y);
505 build_key_event_state (GdkEvent *event,
508 event->key.state = 0;
510 if (key_state[VK_SHIFT] & 0x80)
511 event->key.state |= GDK_SHIFT_MASK;
513 if (key_state[VK_CAPITAL] & 0x01)
514 event->key.state |= GDK_LOCK_MASK;
516 if (key_state[VK_LBUTTON] & 0x80)
517 event->key.state |= GDK_BUTTON1_MASK;
518 if (key_state[VK_MBUTTON] & 0x80)
519 event->key.state |= GDK_BUTTON2_MASK;
520 if (key_state[VK_RBUTTON] & 0x80)
521 event->key.state |= GDK_BUTTON3_MASK;
522 if (key_state[VK_XBUTTON1] & 0x80)
523 event->key.state |= GDK_BUTTON4_MASK;
524 if (key_state[VK_XBUTTON2] & 0x80)
525 event->key.state |= GDK_BUTTON5_MASK;
527 if (_gdk_keyboard_has_altgr &&
528 (key_state[VK_LCONTROL] & 0x80) &&
529 (key_state[VK_RMENU] & 0x80))
531 event->key.group = 1;
532 event->key.state |= GDK_MOD2_MASK;
533 if (key_state[VK_RCONTROL] & 0x80)
534 event->key.state |= GDK_CONTROL_MASK;
535 if (key_state[VK_LMENU] & 0x80)
536 event->key.state |= GDK_MOD1_MASK;
540 event->key.group = 0;
541 if (key_state[VK_CONTROL] & 0x80)
542 event->key.state |= GDK_CONTROL_MASK;
543 if (key_state[VK_MENU] & 0x80)
544 event->key.state |= GDK_MOD1_MASK;
549 build_pointer_event_state (MSG *msg)
555 if (msg->wParam & MK_CONTROL)
556 state |= GDK_CONTROL_MASK;
558 if ((msg->message != WM_LBUTTONDOWN &&
559 (msg->wParam & MK_LBUTTON)) ||
560 msg->message == WM_LBUTTONUP)
561 state |= GDK_BUTTON1_MASK;
563 if ((msg->message != WM_MBUTTONDOWN &&
564 (msg->wParam & MK_MBUTTON)) ||
565 msg->message == WM_MBUTTONUP)
566 state |= GDK_BUTTON2_MASK;
568 if ((msg->message != WM_RBUTTONDOWN &&
569 (msg->wParam & MK_RBUTTON)) ||
570 msg->message == WM_RBUTTONUP)
571 state |= GDK_BUTTON3_MASK;
573 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON1) &&
574 (msg->wParam & MK_XBUTTON1)) ||
575 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON1))
576 state |= GDK_BUTTON4_MASK;
578 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON2) &&
579 (msg->wParam & MK_XBUTTON2)) ||
580 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON2))
581 state |= GDK_BUTTON5_MASK;
583 if (msg->wParam & MK_SHIFT)
584 state |= GDK_SHIFT_MASK;
586 if (GetKeyState (VK_MENU) < 0)
587 state |= GDK_MOD1_MASK;
589 if (GetKeyState (VK_CAPITAL) & 0x1)
590 state |= GDK_LOCK_MASK;
596 build_wm_ime_composition_event (GdkEvent *event,
601 event->key.time = _gdk_win32_get_next_tick (msg->time);
603 build_key_event_state (event, key_state);
605 event->key.hardware_keycode = 0; /* FIXME: What should it be? */
606 event->key.string = NULL;
607 event->key.length = 0;
608 event->key.keyval = gdk_unicode_to_keyval (wc);
611 #ifdef G_ENABLE_DEBUG
614 print_event_state (guint state)
616 #define CASE(bit) if (state & GDK_ ## bit ## _MASK) g_print (#bit " ");
634 _gdk_win32_print_event (const GdkEvent *event)
636 gchar *escaped, *kvname;
637 gchar *selection_name, *target_name, *property_name;
639 g_print ("%s%*s===> ", (debug_indent > 0 ? "\n" : ""), debug_indent, "");
640 switch (event->any.type)
642 #define CASE(x) case x: g_print (#x); break;
647 CASE (GDK_MOTION_NOTIFY);
648 CASE (GDK_BUTTON_PRESS);
649 CASE (GDK_2BUTTON_PRESS);
650 CASE (GDK_3BUTTON_PRESS);
651 CASE (GDK_BUTTON_RELEASE);
652 CASE (GDK_KEY_PRESS);
653 CASE (GDK_KEY_RELEASE);
654 CASE (GDK_ENTER_NOTIFY);
655 CASE (GDK_LEAVE_NOTIFY);
656 CASE (GDK_FOCUS_CHANGE);
657 CASE (GDK_CONFIGURE);
660 CASE (GDK_PROPERTY_NOTIFY);
661 CASE (GDK_SELECTION_CLEAR);
662 CASE (GDK_SELECTION_REQUEST);
663 CASE (GDK_SELECTION_NOTIFY);
664 CASE (GDK_PROXIMITY_IN);
665 CASE (GDK_PROXIMITY_OUT);
666 CASE (GDK_DRAG_ENTER);
667 CASE (GDK_DRAG_LEAVE);
668 CASE (GDK_DRAG_MOTION);
669 CASE (GDK_DRAG_STATUS);
670 CASE (GDK_DROP_START);
671 CASE (GDK_DROP_FINISHED);
672 CASE (GDK_CLIENT_EVENT);
673 CASE (GDK_VISIBILITY_NOTIFY);
675 CASE (GDK_WINDOW_STATE);
677 CASE (GDK_OWNER_CHANGE);
678 CASE (GDK_GRAB_BROKEN);
680 default: g_assert_not_reached ();
683 g_print (" %p ", event->any.window ? GDK_WINDOW_HWND (event->any.window) : NULL);
685 switch (event->any.type)
689 _gdk_win32_gdkrectangle_to_string (&event->expose.area),
690 event->expose.count);
692 case GDK_MOTION_NOTIFY:
693 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s",
694 event->motion.x, event->motion.y,
695 event->motion.x_root, event->motion.y_root,
696 event->motion.is_hint ? "HINT " : "");
697 print_event_state (event->motion.state);
699 case GDK_BUTTON_PRESS:
700 case GDK_2BUTTON_PRESS:
701 case GDK_3BUTTON_PRESS:
702 case GDK_BUTTON_RELEASE:
703 g_print ("%d (%.4g,%.4g) (%.4g,%.4g) ",
704 event->button.button,
705 event->button.x, event->button.y,
706 event->button.x_root, event->button.y_root);
707 print_event_state (event->button.state);
710 case GDK_KEY_RELEASE:
711 if (event->key.length == 0)
712 escaped = g_strdup ("");
714 escaped = g_strescape (event->key.string, NULL);
715 kvname = gdk_keyval_name (event->key.keyval);
716 g_print ("%#.02x group:%d %s %d:\"%s\" ",
717 event->key.hardware_keycode, event->key.group,
718 (kvname ? kvname : "??"),
722 print_event_state (event->key.state);
724 case GDK_ENTER_NOTIFY:
725 case GDK_LEAVE_NOTIFY:
726 g_print ("%p (%.4g,%.4g) (%.4g,%.4g) %s %s%s",
727 event->crossing.subwindow == NULL ? NULL : GDK_WINDOW_HWND (event->crossing.subwindow),
728 event->crossing.x, event->crossing.y,
729 event->crossing.x_root, event->crossing.y_root,
730 (event->crossing.mode == GDK_CROSSING_NORMAL ? "NORMAL" :
731 (event->crossing.mode == GDK_CROSSING_GRAB ? "GRAB" :
732 (event->crossing.mode == GDK_CROSSING_UNGRAB ? "UNGRAB" :
734 (event->crossing.detail == GDK_NOTIFY_ANCESTOR ? "ANCESTOR" :
735 (event->crossing.detail == GDK_NOTIFY_VIRTUAL ? "VIRTUAL" :
736 (event->crossing.detail == GDK_NOTIFY_INFERIOR ? "INFERIOR" :
737 (event->crossing.detail == GDK_NOTIFY_NONLINEAR ? "NONLINEAR" :
738 (event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL ? "NONLINEAR_VIRTUAL" :
739 (event->crossing.detail == GDK_NOTIFY_UNKNOWN ? "UNKNOWN" :
741 event->crossing.focus ? " FOCUS" : "");
742 print_event_state (event->crossing.state);
744 case GDK_FOCUS_CHANGE:
745 g_print ("%s", (event->focus_change.in ? "IN" : "OUT"));
748 g_print ("x:%d y:%d w:%d h:%d",
749 event->configure.x, event->configure.y,
750 event->configure.width, event->configure.height);
752 case GDK_SELECTION_CLEAR:
753 case GDK_SELECTION_REQUEST:
754 case GDK_SELECTION_NOTIFY:
755 selection_name = gdk_atom_name (event->selection.selection);
756 target_name = gdk_atom_name (event->selection.target);
757 property_name = gdk_atom_name (event->selection.property);
758 g_print ("sel:%s tgt:%s prop:%s",
759 selection_name, target_name, property_name);
760 g_free (selection_name);
761 g_free (target_name);
762 g_free (property_name);
766 case GDK_DRAG_MOTION:
767 case GDK_DRAG_STATUS:
769 case GDK_DROP_FINISHED:
770 if (event->dnd.context != NULL)
771 g_print ("ctx:%p: %s %s src:%p dest:%p",
773 _gdk_win32_drag_protocol_to_string (event->dnd.context->protocol),
774 event->dnd.context->is_source ? "SOURCE" : "DEST",
775 event->dnd.context->source_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->source_window),
776 event->dnd.context->dest_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->dest_window));
778 case GDK_CLIENT_EVENT:
779 /* no more GdkEventClient */
782 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",
783 event->scroll.x, event->scroll.y,
784 event->scroll.x_root, event->scroll.y_root,
785 (event->scroll.direction == GDK_SCROLL_UP ? "UP" :
786 (event->scroll.direction == GDK_SCROLL_DOWN ? "DOWN" :
787 (event->scroll.direction == GDK_SCROLL_LEFT ? "LEFT" :
788 (event->scroll.direction == GDK_SCROLL_RIGHT ? "RIGHT" :
790 print_event_state (event->scroll.state);
792 case GDK_WINDOW_STATE:
794 _gdk_win32_window_state_to_string (event->window_state.changed_mask),
795 _gdk_win32_window_state_to_string (event->window_state.new_window_state));
798 (event->setting.action == GDK_SETTING_ACTION_NEW ? "NEW" :
799 (event->setting.action == GDK_SETTING_ACTION_CHANGED ? "CHANGED" :
800 (event->setting.action == GDK_SETTING_ACTION_DELETED ? "DELETED" :
802 (event->setting.name ? event->setting.name : "NULL"));
803 case GDK_GRAB_BROKEN:
805 (event->grab_broken.keyboard ? "KEYBOARD" : "POINTER"),
806 (event->grab_broken.implicit ? "IMPLICIT" : "EXPLICIT"),
807 (event->grab_broken.grab_window ? GDK_WINDOW_HWND (event->grab_broken.grab_window) : 0));
812 g_print ("%s", (debug_indent == 0 ? "\n" : ""));
816 decode_key_lparam (LPARAM lParam)
818 static char buf[100];
821 if (HIWORD (lParam) & KF_UP)
822 p += g_sprintf (p, "KF_UP ");
823 if (HIWORD (lParam) & KF_REPEAT)
824 p += g_sprintf (p, "KF_REPEAT ");
825 if (HIWORD (lParam) & KF_ALTDOWN)
826 p += g_sprintf (p, "KF_ALTDOWN ");
827 if (HIWORD (lParam) & KF_EXTENDED)
828 p += g_sprintf (p, "KF_EXTENDED ");
829 p += g_sprintf (p, "sc:%d rep:%d", LOBYTE (HIWORD (lParam)), LOWORD (lParam));
837 fixup_event (GdkEvent *event)
839 if (event->any.window)
840 g_object_ref (event->any.window);
841 if (((event->any.type == GDK_ENTER_NOTIFY) ||
842 (event->any.type == GDK_LEAVE_NOTIFY)) &&
843 (event->crossing.subwindow != NULL))
844 g_object_ref (event->crossing.subwindow);
845 if (((event->any.type == GDK_SELECTION_CLEAR) ||
846 (event->any.type == GDK_SELECTION_NOTIFY) ||
847 (event->any.type == GDK_SELECTION_REQUEST)) &&
848 (event->selection.requestor != NULL))
849 g_object_ref (event->selection.requestor);
850 if ((event->any.type == GDK_OWNER_CHANGE) &&
851 (event->owner_change.owner != NULL))
852 g_object_ref (event->owner_change.owner);
853 event->any.send_event = InSendMessage ();
857 _gdk_win32_append_event (GdkEvent *event)
863 link = _gdk_event_queue_append (_gdk_display, event);
864 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
865 /* event morphing, the passed in may not be valid afterwards */
866 _gdk_windowing_got_event (_gdk_display, link, event, 0);
868 _gdk_event_queue_append (_gdk_display, event);
869 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
874 fill_key_event_string (GdkEvent *event)
879 /* Fill in event->string crudely, since various programs
884 if (event->key.keyval != GDK_KEY_VoidSymbol)
885 c = gdk_keyval_to_unicode (event->key.keyval);
892 /* Apply the control key - Taken from Xlib
894 if (event->key.state & GDK_CONTROL_MASK)
896 if ((c >= '@' && c < '\177') || c == ' ')
900 event->key.string = g_memdup ("\0\0", 2);
901 event->key.length = 1;
904 else if (c >= '3' && c <= '7')
912 len = g_unichar_to_utf8 (c, buf);
915 event->key.string = g_locale_from_utf8 (buf, len,
916 NULL, &bytes_written,
918 if (event->key.string)
919 event->key.length = bytes_written;
921 else if (event->key.keyval == GDK_KEY_Escape)
923 event->key.length = 1;
924 event->key.string = g_strdup ("\033");
926 else if (event->key.keyval == GDK_KEY_Return ||
927 event->key.keyval == GDK_KEY_KP_Enter)
929 event->key.length = 1;
930 event->key.string = g_strdup ("\r");
933 if (!event->key.string)
935 event->key.length = 0;
936 event->key.string = g_strdup ("");
940 static GdkFilterReturn
941 apply_event_filters (GdkWindow *window,
945 GdkFilterReturn result = GDK_FILTER_CONTINUE;
950 event = gdk_event_new (GDK_NOTHING);
952 event->any.window = g_object_ref (window);
953 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
955 /* I think GdkFilterFunc semantics require the passed-in event
956 * to already be in the queue. The filter func can generate
957 * more events and append them after it if it likes.
959 node = _gdk_event_queue_append (_gdk_display, event);
964 GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
967 if ((filter->flags & GDK_EVENT_FILTER_REMOVED) != 0)
969 tmp_list = tmp_list->next;
974 result = filter->function (msg, event, filter->data);
976 /* get the next node after running the function since the
977 function may add or remove a next node */
979 tmp_list = tmp_list->next;
982 if (filter->ref_count == 0)
984 *filters = g_list_remove_link (*filters, node);
985 g_list_free_1 (node);
989 if (result != GDK_FILTER_CONTINUE)
993 if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
995 _gdk_event_queue_remove_link (_gdk_display, node);
996 g_list_free_1 (node);
997 gdk_event_free (event);
999 else /* GDK_FILTER_TRANSLATE */
1001 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1002 fixup_event (event);
1003 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1009 * On Windows, transient windows will not have their own taskbar entries.
1010 * Because of this, we must hide and restore groups of transients in both
1011 * directions. That is, all transient children must be hidden or restored
1012 * with this window, but if this window's transient owner also has a
1013 * transient owner then this window's transient owner must be hidden/restored
1014 * with this one. And etc, up the chain until we hit an ancestor that has no
1017 * It would be a good idea if applications don't chain transient windows
1018 * together. There's a limit to how much evil GTK can try to shield you
1022 show_window_recurse (GdkWindow *window, gboolean hide_window)
1024 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1025 GSList *children = impl->transient_children;
1026 GdkWindow *child = NULL;
1028 if (!impl->changing_state)
1030 impl->changing_state = TRUE;
1032 if (children != NULL)
1034 while (children != NULL)
1036 child = children->data;
1037 show_window_recurse (child, hide_window);
1039 children = g_slist_next (children);
1043 if (GDK_WINDOW_IS_MAPPED (window))
1047 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_ICONIFIED)
1049 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED)
1051 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
1055 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1061 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
1065 impl->changing_state = FALSE;
1070 do_show_window (GdkWindow *window, gboolean hide_window)
1072 GdkWindow *tmp_window = NULL;
1073 GdkWindowImplWin32 *tmp_impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1075 if (!tmp_impl->changing_state)
1077 /* Find the top-level window in our transient chain. */
1078 while (tmp_impl->transient_owner != NULL)
1080 tmp_window = tmp_impl->transient_owner;
1081 tmp_impl = GDK_WINDOW_IMPL_WIN32 (tmp_window->impl);
1084 /* If we couldn't find one, use the window provided. */
1085 if (tmp_window == NULL)
1087 tmp_window = window;
1090 /* Recursively show/hide every window in the chain. */
1091 if (tmp_window != window)
1093 show_window_recurse (tmp_window, hide_window);
1099 send_crossing_event (GdkDisplay *display,
1102 GdkCrossingMode mode,
1103 GdkNotifyType notify_type,
1104 GdkWindow *subwindow,
1106 GdkModifierType mask,
1110 GdkDeviceGrabInfo *grab;
1111 GdkDeviceManagerWin32 *device_manager;
1114 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (display));
1116 grab = _gdk_display_has_device_grab (display, device_manager->core_pointer, 0);
1119 !grab->owner_events &&
1120 mode != GDK_CROSSING_UNGRAB)
1122 /* !owner_event => only report events wrt grab window, ignore rest */
1123 if ((GdkWindow *)window != grab->native_window)
1128 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1130 event = gdk_event_new (type);
1131 event->crossing.window = window;
1132 event->crossing.subwindow = subwindow;
1133 event->crossing.time = _gdk_win32_get_next_tick (time_);
1134 event->crossing.x = pt.x;
1135 event->crossing.y = pt.y;
1136 event->crossing.x_root = screen_pt->x + _gdk_offset_x;
1137 event->crossing.y_root = screen_pt->y + _gdk_offset_y;
1138 event->crossing.mode = mode;
1139 event->crossing.detail = notify_type;
1140 event->crossing.mode = mode;
1141 event->crossing.detail = notify_type;
1142 event->crossing.focus = FALSE;
1143 event->crossing.state = mask;
1144 gdk_event_set_device (event, device_manager->core_pointer);
1145 gdk_event_set_source_device (event, device_manager->system_pointer);
1147 _gdk_win32_append_event (event);
1151 get_native_parent (GdkWindow *window)
1153 if (window->parent != NULL)
1154 return window->parent->impl_window;
1159 find_common_ancestor (GdkWindow *win1,
1163 GList *path1 = NULL, *path2 = NULL;
1164 GList *list1, *list2;
1167 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
1169 path1 = g_list_prepend (path1, tmp);
1170 tmp = get_native_parent (tmp);
1174 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
1176 path2 = g_list_prepend (path2, tmp);
1177 tmp = get_native_parent (tmp);
1183 while (list1 && list2 && (list1->data == list2->data))
1185 tmp = (GdkWindow *)list1->data;
1186 list1 = g_list_next (list1);
1187 list2 = g_list_next (list2);
1189 g_list_free (path1);
1190 g_list_free (path2);
1196 synthesize_crossing_events (GdkDisplay *display,
1199 GdkCrossingMode mode,
1201 GdkModifierType mask,
1203 gboolean non_linear)
1206 GdkWindow *win, *last, *next;
1210 GdkNotifyType notify_type;
1215 return; /* No crossings generated between src and dest */
1217 c = find_common_ancestor (a, b);
1219 non_linear |= (c != a) && (c != b);
1221 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
1223 /* Traverse up from a to (excluding) c sending leave events */
1225 notify_type = GDK_NOTIFY_NONLINEAR;
1227 notify_type = GDK_NOTIFY_INFERIOR;
1229 notify_type = GDK_NOTIFY_ANCESTOR;
1230 send_crossing_event (display,
1231 a, GDK_LEAVE_NOTIFY,
1241 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1243 notify_type = GDK_NOTIFY_VIRTUAL;
1246 win = get_native_parent (a);
1247 while (win != c && win->window_type != GDK_WINDOW_ROOT)
1249 send_crossing_event (display,
1250 win, GDK_LEAVE_NOTIFY,
1258 win = get_native_parent (win);
1263 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
1265 /* Traverse down from c to b */
1269 win = get_native_parent (b);
1270 while (win != c && win->window_type != GDK_WINDOW_ROOT)
1272 path = g_list_prepend (path, win);
1273 win = get_native_parent (win);
1277 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1279 notify_type = GDK_NOTIFY_VIRTUAL;
1284 win = (GdkWindow *)list->data;
1285 list = g_list_next (list);
1287 next = (GdkWindow *)list->data;
1291 send_crossing_event (display,
1292 win, GDK_ENTER_NOTIFY,
1304 notify_type = GDK_NOTIFY_NONLINEAR;
1306 notify_type = GDK_NOTIFY_ANCESTOR;
1308 notify_type = GDK_NOTIFY_INFERIOR;
1310 send_crossing_event (display,
1311 b, GDK_ENTER_NOTIFY,
1320 /* The check_extended flag controls whether to check if the windows want
1321 * events from extended input devices and if the message should be skipped
1322 * because an extended input device is active
1325 propagate (GdkWindow **window,
1327 GdkWindow *grab_window,
1328 gboolean grab_owner_events,
1330 gboolean (*doesnt_want_it) (gint mask,
1333 if (grab_window != NULL && !grab_owner_events)
1335 /* Event source is grabbed with owner_events FALSE */
1337 if ((*doesnt_want_it) (grab_mask, msg))
1339 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1344 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1345 assign_object (window, grab_window);
1350 /* If we come here, we know that if grab_window != NULL then
1351 * grab_owner_events is TRUE
1355 if ((*doesnt_want_it) ((*window)->event_mask, msg))
1357 /* Owner doesn't want it, propagate to parent. */
1358 GdkWindow *parent = gdk_window_get_parent (*window);
1359 if (parent == _gdk_root || parent == NULL)
1361 /* No parent; check if grabbed */
1362 if (grab_window != NULL)
1364 /* Event source is grabbed with owner_events TRUE */
1366 if ((*doesnt_want_it) (grab_mask, msg))
1368 /* Grabber doesn't want it either */
1369 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1375 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1376 assign_object (window, grab_window);
1382 GDK_NOTE (EVENTS, g_print (" (undelivered)"));
1388 assign_object (window, parent);
1389 /* The only branch where we actually continue the loop */
1398 doesnt_want_key (gint mask,
1401 return (((msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) &&
1402 !(mask & GDK_KEY_RELEASE_MASK)) ||
1403 ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) &&
1404 !(mask & GDK_KEY_PRESS_MASK)));
1408 doesnt_want_char (gint mask,
1411 return !(mask & (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK));
1415 _gdk_win32_emit_configure_event (GdkWindow *window)
1417 GdkWindowImplWin32 *window_impl;
1422 window_impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1423 if (window_impl->inhibit_configure)
1426 hwnd = GDK_WINDOW_HWND (window);
1428 GetClientRect (hwnd, &client_rect);
1429 point.x = client_rect.left; /* always 0 */
1430 point.y = client_rect.top;
1432 /* top level windows need screen coords */
1433 if (gdk_window_get_parent (window) == _gdk_root)
1435 ClientToScreen (hwnd, &point);
1436 point.x += _gdk_offset_x;
1437 point.y += _gdk_offset_y;
1440 window->width = client_rect.right - client_rect.left;
1441 window->height = client_rect.bottom - client_rect.top;
1443 window->x = point.x;
1444 window->y = point.y;
1446 _gdk_window_update_size (window);
1448 if (window->event_mask & GDK_STRUCTURE_MASK)
1450 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1452 event->configure.window = window;
1454 event->configure.width = client_rect.right - client_rect.left;
1455 event->configure.height = client_rect.bottom - client_rect.top;
1457 event->configure.x = point.x;
1458 event->configure.y = point.y;
1460 _gdk_win32_append_event (event);
1465 _gdk_win32_hrgn_to_region (HRGN hrgn)
1469 cairo_region_t *result;
1473 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1475 WIN32_GDI_FAILED ("GetRegionData");
1479 rgndata = (RGNDATA *) g_malloc (nbytes);
1481 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1483 WIN32_GDI_FAILED ("GetRegionData");
1488 result = cairo_region_create ();
1489 rects = (RECT *) rgndata->Buffer;
1490 for (i = 0; i < rgndata->rdh.nCount; i++)
1494 r.x = rects[i].left;
1496 r.width = rects[i].right - r.x;
1497 r.height = rects[i].bottom - r.y;
1499 cairo_region_union_rectangle (result, &r);
1508 adjust_drag (LONG *drag,
1513 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1515 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1519 handle_wm_paint (MSG *msg,
1521 gboolean return_exposes,
1524 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1526 PAINTSTRUCT paintstruct;
1527 cairo_region_t *update_region;
1529 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1531 WIN32_GDI_FAILED ("GetUpdateRgn");
1532 DeleteObject (hrgn);
1536 hdc = BeginPaint (msg->hwnd, &paintstruct);
1538 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1539 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1540 (paintstruct.fErase ? "erase" : ""),
1542 (return_exposes ? " return_exposes" : "")));
1544 EndPaint (msg->hwnd, &paintstruct);
1546 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1547 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1549 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1550 DeleteObject (hrgn);
1556 if (!GDK_WINDOW_DESTROYED (window))
1558 GList *list = _gdk_display->queued_events;
1560 *event = gdk_event_new (GDK_EXPOSE);
1561 (*event)->expose.window = window;
1562 (*event)->expose.area.x = paintstruct.rcPaint.left;
1563 (*event)->expose.area.y = paintstruct.rcPaint.top;
1564 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1565 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1566 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1567 (*event)->expose.count = 0;
1569 while (list != NULL)
1571 GdkEventPrivate *evp = list->data;
1573 if (evp->event.any.type == GDK_EXPOSE &&
1574 evp->event.any.window == window &&
1575 !(evp->flags & GDK_EVENT_PENDING))
1576 evp->event.expose.count++;
1582 DeleteObject (hrgn);
1586 update_region = _gdk_win32_hrgn_to_region (hrgn);
1587 if (!cairo_region_is_empty (update_region))
1588 _gdk_window_invalidate_for_expose (window, update_region);
1589 cairo_region_destroy (update_region);
1591 DeleteObject (hrgn);
1594 static VOID CALLBACK
1595 modal_timer_proc (HWND hwnd,
1600 int arbitrary_limit = 10;
1602 while (_modal_operation_in_progress &&
1603 g_main_context_pending (NULL) &&
1605 g_main_context_iteration (NULL, FALSE);
1609 _gdk_win32_begin_modal_call (void)
1611 g_assert (!_modal_operation_in_progress);
1613 _modal_operation_in_progress = TRUE;
1615 modal_timer = SetTimer (NULL, 0, 10, modal_timer_proc);
1616 if (modal_timer == 0)
1617 WIN32_API_FAILED ("SetTimer");
1621 _gdk_win32_end_modal_call (void)
1623 g_assert (_modal_operation_in_progress);
1625 _modal_operation_in_progress = FALSE;
1627 if (modal_timer != 0)
1629 API_CALL (KillTimer, (NULL, modal_timer));
1634 static VOID CALLBACK
1635 sync_timer_proc (HWND hwnd,
1641 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1646 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1648 KillTimer (hwnd, sync_timer);
1652 handle_display_change (void)
1654 _gdk_monitor_init ();
1655 _gdk_root_window_size_init ();
1656 g_signal_emit_by_name (_gdk_screen, "size_changed");
1660 generate_button_event (GdkEventType type,
1665 GdkEvent *event = gdk_event_new (type);
1666 GdkDeviceManagerWin32 *device_manager;
1668 if (_gdk_input_ignore_core)
1671 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (_gdk_display));
1673 event->button.window = window;
1674 event->button.time = _gdk_win32_get_next_tick (msg->time);
1675 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1676 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1677 event->button.x_root = msg->pt.x + _gdk_offset_x;
1678 event->button.y_root = msg->pt.y + _gdk_offset_y;
1679 event->button.axes = NULL;
1680 event->button.state = build_pointer_event_state (msg);
1681 event->button.button = button;
1682 gdk_event_set_device (event, device_manager->core_pointer);
1683 gdk_event_set_source_device (event, device_manager->system_pointer);
1685 _gdk_win32_append_event (event);
1689 ensure_stacking_on_unminimize (MSG *msg)
1692 HWND lowest_transient = NULL;
1695 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1697 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1699 /* Checking window group not implemented yet */
1702 GdkWindowImplWin32 *rover_impl =
1703 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1705 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1706 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1707 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1708 rover_impl->transient_owner != NULL))
1710 lowest_transient = rover;
1714 if (lowest_transient != NULL)
1716 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1717 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1718 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1723 ensure_stacking_on_window_pos_changing (MSG *msg,
1726 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1727 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1729 if (GetActiveWindow () == msg->hwnd &&
1730 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1731 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1732 impl->transient_owner == NULL)
1734 /* Make sure the window stays behind any transient-type windows
1735 * of the same window group.
1737 * If the window is not active and being activated, we let
1738 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1739 * handling to bring any utility windows on top of it.
1742 gboolean restacking;
1744 rover = windowpos->hwndInsertAfter;
1748 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1750 /* Checking window group not implemented yet */
1753 GdkWindowImplWin32 *rover_impl =
1754 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1756 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1757 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1758 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1759 rover_impl->transient_owner != NULL))
1762 windowpos->hwndInsertAfter = rover;
1765 rover = GetNextWindow (rover, GW_HWNDNEXT);
1770 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1778 ensure_stacking_on_activate_app (MSG *msg,
1781 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1783 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1784 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1785 impl->transient_owner != NULL)
1787 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1788 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1792 if (IsWindowVisible (msg->hwnd) &&
1793 msg->hwnd == GetActiveWindow ())
1795 /* This window is not a transient-type window and it is the
1796 * activated window. Make sure this window is as visible as
1797 * possible, just below the lowest transient-type window of this
1803 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
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))
1818 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1819 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1820 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1828 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
1829 GDK_BUTTON2_MASK | \
1830 GDK_BUTTON3_MASK | \
1831 GDK_BUTTON4_MASK | \
1835 gdk_event_translate (MSG *msg,
1838 RECT rect, *drag, orig_drag;
1843 BYTE key_state[256];
1845 WINDOWPOS *windowpos;
1846 gboolean ignore_leave;
1853 GdkWindow *window = NULL;
1854 GdkWindowImplWin32 *impl;
1856 GdkWindow *orig_window, *new_window;
1858 GdkDeviceManager *device_manager;
1859 GdkDeviceManagerWin32 *device_manager_win32;
1861 GdkDeviceGrabInfo *keyboard_grab = NULL;
1862 GdkDeviceGrabInfo *pointer_grab = NULL;
1863 GdkWindow *grab_window = NULL;
1869 gboolean return_val = FALSE;
1873 if (_gdk_default_filters)
1875 /* Apply global filters */
1877 GdkFilterReturn result = apply_event_filters (NULL, msg, &_gdk_default_filters);
1879 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1880 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1881 * we return TRUE, and DefWindowProcW() will not be called.
1883 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1887 window = gdk_win32_handle_table_lookup (msg->hwnd);
1888 orig_window = window;
1892 /* XXX Handle WM_QUIT here ? */
1893 if (msg->message == WM_QUIT)
1895 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1898 else if (msg->message == WM_CREATE)
1900 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1901 GDK_WINDOW_HWND (window) = msg->hwnd;
1905 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1910 device_manager = gdk_display_get_device_manager (_gdk_display);
1911 device_manager_win32 = GDK_DEVICE_MANAGER_WIN32 (device_manager);
1913 keyboard_grab = _gdk_display_get_last_device_grab (_gdk_display,
1914 device_manager_win32->core_keyboard);
1915 pointer_grab = _gdk_display_get_last_device_grab (_gdk_display,
1916 device_manager_win32->core_pointer);
1918 g_object_ref (window);
1920 /* window's refcount has now been increased, so code below should
1921 * not just return from this function, but instead goto done (or
1922 * break out of the big switch). To protect against forgetting this,
1923 * #define return to a syntax error...
1925 #define return GOTO_DONE_INSTEAD
1927 if (!GDK_WINDOW_DESTROYED (window) && window->filters)
1929 /* Apply per-window filters */
1931 GdkFilterReturn result = apply_event_filters (window, msg, &window->filters);
1933 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1940 if (msg->message == client_message)
1943 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1946 GDK_NOTE (EVENTS, g_print (" client_message"));
1948 event = gdk_event_new (GDK_NOTHING);
1949 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1951 node = _gdk_event_queue_append (_gdk_display, event);
1953 tmp_list = client_filters;
1956 GdkClientFilter *filter = tmp_list->data;
1958 tmp_list = tmp_list->next;
1960 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
1962 GDK_NOTE (EVENTS, g_print (" (match)"));
1964 result = (*filter->function) (msg, event, filter->data);
1966 if (result != GDK_FILTER_CONTINUE)
1973 case GDK_FILTER_REMOVE:
1974 _gdk_event_queue_remove_link (_gdk_display, node);
1975 g_list_free_1 (node);
1976 gdk_event_free (event);
1980 case GDK_FILTER_TRANSLATE:
1981 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1982 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1986 case GDK_FILTER_CONTINUE:
1987 /* No more: Send unknown client messages on to Gtk for it to use */
1988 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1994 switch (msg->message)
1996 case WM_INPUTLANGCHANGE:
1997 _gdk_input_locale = (HKL) msg->lParam;
1998 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
1999 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
2000 LOCALE_IDEFAULTANSICODEPAGE,
2002 _gdk_input_codepage = atoi (buf);
2003 _gdk_keymap_serial++;
2005 g_print (" cs:%lu hkl:%p%s cp:%d",
2006 (gulong) msg->wParam,
2007 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
2008 _gdk_input_codepage));
2014 g_print (" %s ch:%.02x %s",
2015 _gdk_win32_key_to_string (msg->lParam),
2017 decode_key_lparam (msg->lParam)));
2019 /* If posted without us having keyboard focus, ignore */
2020 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
2021 !(HIWORD (msg->lParam) & KF_ALTDOWN))
2024 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
2025 * the keyboard is grabbed.
2027 if (!keyboard_grab &&
2028 (msg->wParam == VK_TAB ||
2029 msg->wParam == VK_SPACE ||
2030 msg->wParam == VK_F4))
2033 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
2039 g_print (" %s ch:%.02x %s",
2040 _gdk_win32_key_to_string (msg->lParam),
2042 decode_key_lparam (msg->lParam)));
2046 /* Ignore key messages intended for the IME */
2047 if (msg->wParam == VK_PROCESSKEY ||
2051 if (keyboard_grab &&
2052 !propagate (&window, msg,
2053 keyboard_grab->window,
2054 keyboard_grab->owner_events,
2055 GDK_ALL_EVENTS_MASK,
2059 if (GDK_WINDOW_DESTROYED (window))
2062 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
2063 msg->message == WM_SYSKEYDOWN) ?
2064 GDK_KEY_PRESS : GDK_KEY_RELEASE);
2065 event->key.window = window;
2066 event->key.time = _gdk_win32_get_next_tick (msg->time);
2067 event->key.keyval = GDK_KEY_VoidSymbol;
2068 event->key.string = NULL;
2069 event->key.length = 0;
2070 event->key.hardware_keycode = msg->wParam;
2071 gdk_event_set_device (event, device_manager_win32->core_keyboard);
2072 gdk_event_set_source_device (event, device_manager_win32->system_keyboard);
2073 if (HIWORD (msg->lParam) & KF_EXTENDED)
2075 switch (msg->wParam)
2078 event->key.hardware_keycode = VK_RCONTROL;
2080 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
2081 * for the right shift key.
2083 event->key.hardware_keycode = VK_RSHIFT;
2086 event->key.hardware_keycode = VK_RMENU;
2090 else if (msg->wParam == VK_SHIFT &&
2091 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
2092 event->key.hardware_keycode = VK_RSHIFT;
2094 API_CALL (GetKeyboardState, (key_state));
2096 /* 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]); */
2098 build_key_event_state (event, key_state);
2100 if (msg->wParam == VK_PACKET &&
2101 ToUnicode (VK_PACKET, HIWORD (msg->lParam), key_state, wbuf, 1, 0) == 1)
2102 event->key.keyval = gdk_unicode_to_keyval (wbuf[0]);
2104 gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (_gdk_display),
2105 event->key.hardware_keycode,
2111 fill_key_event_string (event);
2113 /* Reset MOD1_MASK if it is the Alt key itself */
2114 if (msg->wParam == VK_MENU)
2115 event->key.state &= ~GDK_MOD1_MASK;
2117 _gdk_win32_append_event (event);
2123 if (msg->wParam != VK_SPACE)
2125 /* To prevent beeps, don't let DefWindowProcW() be called */
2131 case WM_IME_STARTCOMPOSITION:
2132 in_ime_composition = TRUE;
2135 case WM_IME_ENDCOMPOSITION:
2136 in_ime_composition = FALSE;
2139 case WM_IME_COMPOSITION:
2140 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2141 * applications. Thus, handle WM_IME_COMPOSITION with
2142 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2143 * with ImmGetCompositionStringW().
2146 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2148 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2149 * for comments by other people that seems to have the same
2150 * experience. WM_IME_CHAR just gives question marks, apparently
2151 * because of going through some conversion to the current code
2154 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2155 * use WM_IME_COMPOSITION there, too, to simplify the code.
2157 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2159 if (!(msg->lParam & GCS_RESULTSTR))
2162 if (keyboard_grab &&
2163 !propagate (&window, msg,
2164 keyboard_grab->window,
2165 keyboard_grab->owner_events,
2166 GDK_ALL_EVENTS_MASK,
2170 if (GDK_WINDOW_DESTROYED (window))
2173 himc = ImmGetContext (msg->hwnd);
2174 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2175 wbuf, sizeof (wbuf));
2176 ImmReleaseContext (msg->hwnd, himc);
2180 API_CALL (GetKeyboardState, (key_state));
2182 for (i = 0; i < ccount; i++)
2184 if (window->event_mask & GDK_KEY_PRESS_MASK)
2186 /* Build a key press event */
2187 event = gdk_event_new (GDK_KEY_PRESS);
2188 event->key.window = window;
2189 gdk_event_set_device (event, device_manager_win32->core_keyboard);
2190 gdk_event_set_source_device (event, device_manager_win32->system_keyboard);
2191 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2193 _gdk_win32_append_event (event);
2196 if (window->event_mask & GDK_KEY_RELEASE_MASK)
2198 /* Build a key release event. */
2199 event = gdk_event_new (GDK_KEY_RELEASE);
2200 event->key.window = window;
2201 gdk_event_set_device (event, device_manager_win32->core_keyboard);
2202 gdk_event_set_source_device (event, device_manager_win32->system_keyboard);
2203 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2205 _gdk_win32_append_event (event);
2211 case WM_LBUTTONDOWN:
2215 case WM_MBUTTONDOWN:
2219 case WM_RBUTTONDOWN:
2223 case WM_XBUTTONDOWN:
2224 if (HIWORD (msg->wParam) == XBUTTON1)
2231 g_print (" (%d,%d)",
2232 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2234 assign_object (&window, find_window_for_mouse_event (window, msg));
2235 /* TODO_CSW?: there used to some synthesize and propagate */
2236 if (GDK_WINDOW_DESTROYED (window))
2239 if (pointer_grab == NULL)
2241 SetCapture (GDK_WINDOW_HWND (window));
2244 generate_button_event (GDK_BUTTON_PRESS, button,
2263 if (HIWORD (msg->wParam) == XBUTTON1)
2270 g_print (" (%d,%d)",
2271 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2273 assign_object (&window, find_window_for_mouse_event (window, msg));
2275 if (pointer_grab != NULL && pointer_grab->implicit)
2277 gint state = build_pointer_event_state (msg);
2279 /* We keep the implicit grab until no buttons at all are held down */
2280 if ((state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (button - 1))) == 0)
2285 hwnd = WindowFromPoint (msg->pt);
2288 POINT client_pt = msg->pt;
2290 ScreenToClient (hwnd, &client_pt);
2291 GetClientRect (hwnd, &rect);
2292 if (PtInRect (&rect, client_pt))
2293 new_window = gdk_win32_handle_table_lookup (hwnd);
2295 synthesize_crossing_events (_gdk_display,
2296 pointer_grab->native_window, new_window,
2297 GDK_CROSSING_UNGRAB,
2299 0, /* TODO: Set right mask */
2302 assign_object (&mouse_window, new_window);
2303 mouse_window_ignored_leave = NULL;
2307 generate_button_event (GDK_BUTTON_RELEASE, button,
2315 g_print (" %p (%d,%d)",
2316 (gpointer) msg->wParam,
2317 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2319 new_window = window;
2321 if (pointer_grab != NULL)
2327 hwnd = WindowFromPoint (pt);
2330 POINT client_pt = pt;
2332 ScreenToClient (hwnd, &client_pt);
2333 GetClientRect (hwnd, &rect);
2334 if (PtInRect (&rect, client_pt))
2335 new_window = gdk_win32_handle_table_lookup (hwnd);
2338 if (!pointer_grab->owner_events &&
2339 new_window != NULL &&
2340 new_window != pointer_grab->native_window)
2344 if (mouse_window != new_window)
2346 GDK_NOTE (EVENTS, g_print (" mouse_sinwod %p -> %p",
2347 mouse_window ? GDK_WINDOW_HWND (mouse_window) : NULL,
2348 new_window ? GDK_WINDOW_HWND (new_window) : NULL));
2349 synthesize_crossing_events (_gdk_display,
2350 mouse_window, new_window,
2351 GDK_CROSSING_NORMAL,
2353 0, /* TODO: Set right mask */
2356 assign_object (&mouse_window, new_window);
2357 mouse_window_ignored_leave = NULL;
2358 if (new_window != NULL)
2359 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (new_window));
2361 else if (new_window != NULL &&
2362 new_window == mouse_window_ignored_leave)
2364 /* If we ignored a leave event for this window and we're now getting
2365 input again we need to re-arm the mouse tracking, as that was
2366 cancelled by the mouseleave. */
2367 mouse_window_ignored_leave = NULL;
2368 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (new_window));
2371 assign_object (&window, find_window_for_mouse_event (window, msg));
2373 /* If we haven't moved, don't create any GDK event. Windows
2374 * sends WM_MOUSEMOVE messages after a new window is shows under
2375 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2377 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2378 msg->pt.y + _gdk_offset_y == current_root_y)
2381 current_root_x = msg->pt.x + _gdk_offset_x;
2382 current_root_y = msg->pt.y + _gdk_offset_y;
2384 if (!_gdk_input_ignore_core)
2386 event = gdk_event_new (GDK_MOTION_NOTIFY);
2387 event->motion.window = window;
2388 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2389 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2390 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2391 event->motion.x_root = current_root_x;
2392 event->motion.y_root = current_root_y;
2393 event->motion.axes = NULL;
2394 event->motion.state = build_pointer_event_state (msg);
2395 event->motion.is_hint = FALSE;
2396 gdk_event_set_device (event, device_manager_win32->core_pointer);
2397 gdk_event_set_source_device (event, device_manager_win32->system_pointer);
2399 _gdk_win32_append_event (event);
2405 case WM_NCMOUSEMOVE:
2407 g_print (" (%d,%d)",
2408 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2412 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2413 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2416 hwnd = WindowFromPoint (msg->pt);
2417 ignore_leave = FALSE;
2422 POINT client_pt = msg->pt;
2424 /* The synapitics trackpad drivers have this irritating
2425 feature where it pops up a window right under the pointer
2426 when you scroll. We ignore the leave and enter events for
2428 if (GetClassNameA (hwnd, classname, sizeof(classname)) &&
2429 strcmp (classname, SYNAPSIS_ICON_WINDOW_CLASS) == 0)
2430 ignore_leave = TRUE;
2432 ScreenToClient (hwnd, &client_pt);
2433 GetClientRect (hwnd, &rect);
2434 if (PtInRect (&rect, client_pt))
2435 new_window = gdk_win32_handle_table_lookup (hwnd);
2439 synthesize_crossing_events (_gdk_display,
2440 mouse_window, new_window,
2441 GDK_CROSSING_NORMAL,
2443 0, /* TODO: Set right mask */
2446 assign_object (&mouse_window, new_window);
2447 mouse_window_ignored_leave = ignore_leave ? new_window : NULL;
2454 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2456 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2457 * that. Also, the position is in screen coordinates, not client
2458 * coordinates as with the button messages. I love the
2459 * consistency of Windows.
2461 point.x = GET_X_LPARAM (msg->lParam);
2462 point.y = GET_Y_LPARAM (msg->lParam);
2464 if ((hwnd = WindowFromPoint (point)) == NULL)
2470 /* The synapitics trackpad drivers have this irritating
2471 feature where it pops up a window right under the pointer
2472 when you scroll. We backtrack and to the toplevel and
2473 find the innermost child instead. */
2474 if (GetClassNameA (hwnd, classname, sizeof(classname)) &&
2475 strcmp (classname, SYNAPSIS_ICON_WINDOW_CLASS) == 0)
2479 /* Find our toplevel window */
2480 hwnd = GetAncestor (msg->hwnd, GA_ROOT);
2482 /* Walk back up to the outermost child at the desired point */
2484 ScreenToClient (hwnd, &point);
2485 hwndc = ChildWindowFromPoint (hwnd, point);
2486 ClientToScreen (hwnd, &point);
2487 } while (hwndc != hwnd && (hwnd = hwndc, 1));
2492 if ((new_window = gdk_win32_handle_table_lookup (msg->hwnd)) == NULL)
2495 if (new_window != window)
2497 assign_object (&window, new_window);
2500 ScreenToClient (msg->hwnd, &point);
2502 event = gdk_event_new (GDK_SCROLL);
2503 event->scroll.window = window;
2504 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2505 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2506 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2507 event->scroll.x = (gint16) point.x;
2508 event->scroll.y = (gint16) point.y;
2509 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2510 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2511 event->scroll.state = build_pointer_event_state (msg);
2512 gdk_event_set_device (event, device_manager_win32->core_pointer);
2513 gdk_event_set_source_device (event, device_manager_win32->system_pointer);
2515 _gdk_win32_append_event (event);
2521 /* Just print more debugging information, don't actually handle it. */
2524 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2525 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2526 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2527 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2528 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2529 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2530 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2531 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2532 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2534 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2535 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2536 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2540 /* Just print more debugging information, don't actually handle it. */
2543 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2544 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2545 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2546 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2547 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2548 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2549 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2550 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2551 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2553 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2554 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2555 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2558 case WM_MOUSEACTIVATE:
2560 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2561 || !window->accept_focus)
2563 *ret_valp = MA_NOACTIVATE;
2567 if (_gdk_modal_blocked (gdk_window_get_toplevel (window)))
2569 *ret_valp = MA_NOACTIVATEANDEAT;
2577 if (keyboard_grab != NULL &&
2578 !GDK_WINDOW_DESTROYED (keyboard_grab->window))
2580 generate_grab_broken_event (device_manager, keyboard_grab->window, TRUE, NULL);
2585 if (keyboard_grab != NULL &&
2586 !keyboard_grab->owner_events)
2589 if (!(window->event_mask & GDK_FOCUS_CHANGE_MASK))
2592 if (GDK_WINDOW_DESTROYED (window))
2595 generate_focus_event (device_manager, window, (msg->message == WM_SETFOCUS));
2600 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2602 if (GDK_WINDOW_DESTROYED (window))
2610 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2612 200, sync_timer_proc);
2616 handle_wm_paint (msg, window, FALSE, NULL);
2620 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2621 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2623 if (pointer_grab != NULL)
2624 grab_window = pointer_grab->window;
2626 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2629 if (grab_window != NULL && _gdk_win32_grab_cursor != NULL)
2630 hcursor = _gdk_win32_grab_cursor;
2631 else if (!GDK_WINDOW_DESTROYED (window))
2632 hcursor = GDK_WINDOW_IMPL_WIN32 (window->impl)->hcursor;
2636 if (hcursor != NULL)
2638 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2639 SetCursor (hcursor);
2646 switch (msg->wParam)
2650 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2656 case WM_ENTERSIZEMOVE:
2657 case WM_ENTERMENULOOP:
2658 if (msg->message == WM_ENTERSIZEMOVE)
2659 _modal_move_resize_window = msg->hwnd;
2661 _gdk_win32_begin_modal_call ();
2664 case WM_EXITSIZEMOVE:
2665 case WM_EXITMENULOOP:
2666 if (_modal_operation_in_progress)
2668 _modal_move_resize_window = NULL;
2669 _gdk_win32_end_modal_call ();
2673 case WM_CAPTURECHANGED:
2674 /* Sometimes we don't get WM_EXITSIZEMOVE, for instance when you
2675 select move/size in the menu and then click somewhere without
2676 moving/resizing. We work around this using WM_CAPTURECHANGED. */
2677 if (_modal_operation_in_progress)
2679 _modal_move_resize_window = NULL;
2680 _gdk_win32_end_modal_call ();
2684 case WM_WINDOWPOSCHANGING:
2685 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2686 g_print (" %s %s %dx%d@%+d%+d now below %p",
2687 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2688 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2689 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2690 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2691 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2692 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2694 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2695 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2697 if (GDK_WINDOW_IS_MAPPED (window))
2698 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2701 case WM_WINDOWPOSCHANGED:
2702 windowpos = (WINDOWPOS *) msg->lParam;
2703 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2704 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2705 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2706 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2707 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2708 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2709 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2711 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2713 /* Break grabs on unmap or minimize */
2714 if (windowpos->flags & SWP_HIDEWINDOW ||
2715 ((windowpos->flags & SWP_STATECHANGED) && IsIconic (msg->hwnd)))
2717 if (pointer_grab != NULL)
2719 if (pointer_grab->window == window)
2720 gdk_pointer_ungrab (msg->time);
2723 if (keyboard_grab != NULL &&
2724 keyboard_grab->window == window)
2725 gdk_keyboard_ungrab (msg->time);
2728 /* Send MAP events */
2729 if ((windowpos->flags & SWP_SHOWWINDOW) &&
2730 !GDK_WINDOW_DESTROYED (window))
2732 event = gdk_event_new (GDK_MAP);
2733 event->any.window = window;
2734 _gdk_win32_append_event (event);
2737 /* Update window state */
2738 if (windowpos->flags & (SWP_STATECHANGED | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
2740 GdkWindowState set_bits, unset_bits, old_state, new_state;
2742 old_state = window->state;
2747 if (IsWindowVisible (msg->hwnd))
2748 unset_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2750 set_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2752 if (IsIconic (msg->hwnd))
2753 set_bits |= GDK_WINDOW_STATE_ICONIFIED;
2755 unset_bits |= GDK_WINDOW_STATE_ICONIFIED;
2757 if (IsZoomed (msg->hwnd))
2758 set_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2760 unset_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2762 gdk_synthesize_window_state (window, unset_bits, set_bits);
2764 new_state = window->state;
2766 /* Whenever one window changes iconified state we need to also
2767 * change the iconified state in all transient related windows,
2768 * as windows doesn't give icons for transient childrens.
2770 if ((old_state & GDK_WINDOW_STATE_ICONIFIED) !=
2771 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2772 do_show_window (window, (new_state & GDK_WINDOW_STATE_ICONIFIED));
2775 /* When un-minimizing, make sure we're stacked under any
2776 transient-type windows. */
2777 if (!(old_state & GDK_WINDOW_STATE_ICONIFIED) &&
2778 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2779 ensure_stacking_on_unminimize (msg);
2782 /* Show, New size or position => configure event */
2783 if (!(windowpos->flags & SWP_NOCLIENTMOVE) ||
2784 !(windowpos->flags & SWP_NOCLIENTSIZE) ||
2785 (windowpos->flags & SWP_SHOWWINDOW))
2787 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2788 !IsIconic (msg->hwnd) &&
2789 !GDK_WINDOW_DESTROYED (window))
2790 _gdk_win32_emit_configure_event (window);
2793 if ((windowpos->flags & SWP_HIDEWINDOW) &&
2794 !GDK_WINDOW_DESTROYED (window))
2796 /* Send UNMAP events */
2797 event = gdk_event_new (GDK_UNMAP);
2798 event->any.window = window;
2799 _gdk_win32_append_event (event);
2801 /* Make transient parent the forground window when window unmaps */
2802 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2804 if (impl->transient_owner &&
2805 GetForegroundWindow () == GDK_WINDOW_HWND (window))
2806 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2809 if (!(windowpos->flags & SWP_NOCLIENTSIZE))
2811 if (window->resize_count > 1)
2812 window->resize_count -= 1;
2815 /* Call modal timer immediate so that we repaint faster after a resize. */
2816 if (_modal_operation_in_progress)
2817 modal_timer_proc (0,0,0,0);
2819 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2825 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2826 drag = (RECT *) msg->lParam;
2827 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2828 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2829 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2830 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2831 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2832 (msg->wParam == WMSZ_TOP ? "TOP" :
2833 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2834 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2836 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2838 _gdk_win32_rect_to_string (&rect),
2839 _gdk_win32_rect_to_string (drag)));
2841 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2843 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2845 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2846 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2848 /* Resize in increments relative to the base size */
2849 rect.left = rect.top = 0;
2850 rect.right = impl->hints.base_width;
2851 rect.bottom = impl->hints.base_height;
2852 _gdk_win32_adjust_client_rect (window, &rect);
2853 point.x = rect.left;
2855 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2856 rect.left = point.x;
2858 point.x = rect.right;
2859 point.y = rect.bottom;
2860 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2861 rect.right = point.x;
2862 rect.bottom = point.y;
2864 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2865 _gdk_win32_rect_to_string (&rect)));
2868 switch (msg->wParam)
2871 if (drag->bottom == rect.bottom)
2873 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2876 case WMSZ_BOTTOMLEFT:
2877 if (drag->bottom == rect.bottom && drag->left == rect.left)
2879 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2880 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2884 if (drag->left == rect.left)
2886 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2890 if (drag->top == rect.top && drag->left == rect.left)
2892 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2893 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2897 if (drag->top == rect.top)
2899 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2903 if (drag->top == rect.top && drag->right == rect.right)
2905 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2906 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2910 if (drag->right == rect.right)
2912 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2915 case WMSZ_BOTTOMRIGHT:
2916 if (drag->bottom == rect.bottom && drag->right == rect.right)
2918 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2919 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2923 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2924 drag->top != orig_drag.top || drag->right != orig_drag.right)
2928 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2929 _gdk_win32_rect_to_string (drag)));
2933 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2935 if (impl->hint_flags & GDK_HINT_ASPECT)
2937 RECT decorated_rect;
2938 RECT undecorated_drag;
2939 int decoration_width, decoration_height;
2940 gdouble drag_aspect;
2941 int drag_width, drag_height, new_width, new_height;
2943 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2944 decorated_rect = rect;
2945 _gdk_win32_adjust_client_rect (window, &decorated_rect);
2947 /* Set undecorated_drag to the client area being dragged
2948 * out, in screen coordinates.
2950 undecorated_drag = *drag;
2951 undecorated_drag.left -= decorated_rect.left - rect.left;
2952 undecorated_drag.right -= decorated_rect.right - rect.right;
2953 undecorated_drag.top -= decorated_rect.top - rect.top;
2954 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
2956 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
2957 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
2959 drag_width = undecorated_drag.right - undecorated_drag.left;
2960 drag_height = undecorated_drag.bottom - undecorated_drag.top;
2962 drag_aspect = (gdouble) drag_width / drag_height;
2964 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
2965 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
2967 if (drag_aspect < impl->hints.min_aspect)
2969 /* Aspect is getting too narrow */
2970 switch (msg->wParam)
2974 /* User drags top or bottom edge outward. Keep height, increase width. */
2975 new_width = impl->hints.min_aspect * drag_height;
2976 drag->left -= (new_width - drag_width) / 2;
2977 drag->right = drag->left + new_width + decoration_width;
2979 case WMSZ_BOTTOMLEFT:
2980 case WMSZ_BOTTOMRIGHT:
2981 /* User drags bottom-left or bottom-right corner down. Adjust height. */
2982 new_height = drag_width / impl->hints.min_aspect;
2983 drag->bottom = drag->top + new_height + decoration_height;
2987 /* User drags left or right edge inward. Decrease height */
2988 new_height = drag_width / impl->hints.min_aspect;
2989 drag->top += (drag_height - new_height) / 2;
2990 drag->bottom = drag->top + new_height + decoration_height;
2994 /* User drags top-left or top-right corner up. Adjust height. */
2995 new_height = drag_width / impl->hints.min_aspect;
2996 drag->top = drag->bottom - new_height - decoration_height;
2999 else if (drag_aspect > impl->hints.max_aspect)
3001 /* Aspect is getting too wide */
3002 switch (msg->wParam)
3006 /* User drags top or bottom edge inward. Decrease width. */
3007 new_width = impl->hints.max_aspect * drag_height;
3008 drag->left += (drag_width - new_width) / 2;
3009 drag->right = drag->left + new_width + decoration_width;
3011 case WMSZ_BOTTOMLEFT:
3013 /* User drags bottom-left or top-left corner left. Adjust width. */
3014 new_width = impl->hints.max_aspect * drag_height;
3015 drag->left = drag->right - new_width - decoration_width;
3017 case WMSZ_BOTTOMRIGHT:
3019 /* User drags bottom-right or top-right corner right. Adjust width. */
3020 new_width = impl->hints.max_aspect * drag_height;
3021 drag->right = drag->left + new_width + decoration_width;
3025 /* User drags left or right edge outward. Increase height. */
3026 new_height = drag_width / impl->hints.max_aspect;
3027 drag->top -= (new_height - drag_height) / 2;
3028 drag->bottom = drag->top + new_height + decoration_height;
3035 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
3036 _gdk_win32_rect_to_string (drag)));
3040 case WM_GETMINMAXINFO:
3041 if (GDK_WINDOW_DESTROYED (window))
3044 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3045 mmi = (MINMAXINFO*) msg->lParam;
3046 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
3047 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3048 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3049 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3050 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3051 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3053 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
3055 rect.left = rect.top = 0;
3056 rect.right = impl->hints.min_width;
3057 rect.bottom = impl->hints.min_height;
3059 _gdk_win32_adjust_client_rect (window, &rect);
3061 mmi->ptMinTrackSize.x = rect.right - rect.left;
3062 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
3065 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
3069 rect.left = rect.top = 0;
3070 rect.right = impl->hints.max_width;
3071 rect.bottom = impl->hints.max_height;
3073 _gdk_win32_adjust_client_rect (window, &rect);
3075 /* at least on win9x we have the 16 bit trouble */
3076 maxw = rect.right - rect.left;
3077 maxh = rect.bottom - rect.top;
3078 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
3079 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
3082 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
3084 /* Don't call DefWindowProcW() */
3085 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
3086 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3087 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3088 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3089 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3090 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3093 mmi->ptMaxTrackSize.x = 30000;
3094 mmi->ptMaxTrackSize.y = 30000;
3099 if (GDK_WINDOW_DESTROYED (window))
3102 event = gdk_event_new (GDK_DELETE);
3103 event->any.window = window;
3105 _gdk_win32_append_event (event);
3107 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3109 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
3111 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3118 if (pointer_grab != NULL)
3120 if (pointer_grab->window == window)
3121 gdk_pointer_ungrab (msg->time);
3124 if (keyboard_grab &&
3125 keyboard_grab->window == window)
3126 gdk_keyboard_ungrab (msg->time);
3128 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
3129 gdk_window_destroy_notify (window);
3131 if (window == NULL || GDK_WINDOW_DESTROYED (window))
3134 event = gdk_event_new (GDK_DESTROY);
3135 event->any.window = window;
3137 _gdk_win32_append_event (event);
3142 case WM_DISPLAYCHANGE:
3143 handle_display_change ();
3146 case WM_DESTROYCLIPBOARD:
3147 if (!_ignore_destroy_clipboard)
3149 event = gdk_event_new (GDK_SELECTION_CLEAR);
3150 event->selection.window = window;
3151 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3152 event->selection.time = _gdk_win32_get_next_tick (msg->time);
3153 _gdk_win32_append_event (event);
3162 case WM_RENDERFORMAT:
3163 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
3165 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
3167 GDK_NOTE (EVENTS, g_print (" (target not found)"));
3172 /* We need to render to clipboard immediately, don't call
3173 * _gdk_win32_append_event()
3175 event = gdk_event_new (GDK_SELECTION_REQUEST);
3176 event->selection.window = window;
3177 event->selection.send_event = FALSE;
3178 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3179 event->selection.target = target;
3180 event->selection.property = _gdk_selection;
3181 event->selection.requestor = gdk_win32_handle_table_lookup (msg->hwnd);
3182 event->selection.time = msg->time;
3184 fixup_event (event);
3185 GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)"));
3186 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
3187 _gdk_event_emit (event);
3188 gdk_event_free (event);
3190 /* Now the clipboard owner should have rendered */
3191 if (!_delayed_rendering_data)
3193 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3197 if (msg->wParam == CF_DIB)
3199 _delayed_rendering_data =
3200 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3202 if (!_delayed_rendering_data)
3204 g_warning ("Cannot convert to DIB from delayed rendered image");
3209 /* The requestor is holding the clipboard, no
3210 * OpenClipboard() is required/possible
3213 g_print (" SetClipboardData(%s,%p)",
3214 _gdk_win32_cf_to_string (msg->wParam),
3215 _delayed_rendering_data));
3217 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3218 _delayed_rendering_data = NULL;
3223 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3224 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3225 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3226 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3227 HIWORD (msg->wParam) ? " minimized" : "",
3228 (HWND) msg->lParam));
3229 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3230 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3233 if (_gdk_modal_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3235 GdkWindow *modal_current = _gdk_modal_current ();
3236 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3242 if (LOWORD (msg->wParam) == WA_INACTIVE)
3243 gdk_synthesize_window_state (window, GDK_WINDOW_STATE_FOCUSED, 0);
3245 gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_FOCUSED);
3247 /* Bring any tablet contexts to the top of the overlap order when
3248 * one of our windows is activated.
3249 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3252 if (LOWORD(msg->wParam) != WA_INACTIVE)
3253 _gdk_input_set_tablet_active ();
3256 case WM_ACTIVATEAPP:
3257 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3258 msg->wParam ? "YES" : "NO",
3259 (gint64) msg->lParam));
3260 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3261 ensure_stacking_on_activate_app (msg, window);
3264 /* Handle WINTAB events here, as we know that gdkinput.c will
3265 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3266 * constants as case labels.
3269 GDK_NOTE (EVENTS, g_print (" %d %p",
3270 (int) msg->wParam, (gpointer) msg->lParam));
3274 GDK_NOTE (EVENTS, g_print (" %d %p",
3275 (int) msg->wParam, (gpointer) msg->lParam));
3279 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3280 (gpointer) msg->wParam,
3281 LOWORD (msg->lParam),
3282 HIWORD (msg->lParam)));
3286 event = gdk_event_new (GDK_NOTHING);
3287 event->any.window = window;
3288 g_object_ref (window);
3290 if (_gdk_input_other_event (event, msg, window))
3291 _gdk_win32_append_event (event);
3293 gdk_event_free (event);
3301 g_object_unref (window);
3308 _gdk_win32_display_queue_events (GdkDisplay *display)
3312 if (modal_win32_dialog != NULL)
3315 while (!_gdk_event_queue_find_first (display) &&
3316 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3318 TranslateMessage (&msg);
3319 DispatchMessageW (&msg);
3324 gdk_event_prepare (GSource *source,
3329 gdk_threads_enter ();
3333 if (_gdk_display->event_pause_count > 0)
3336 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3337 (modal_win32_dialog == NULL &&
3338 GetQueueStatus (QS_ALLINPUT) != 0));
3340 gdk_threads_leave ();
3346 gdk_event_check (GSource *source)
3350 gdk_threads_enter ();
3352 if (_gdk_display->event_pause_count > 0)
3354 else if (event_poll_fd.revents & G_IO_IN)
3355 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3356 (modal_win32_dialog == NULL &&
3357 GetQueueStatus (QS_ALLINPUT) != 0));
3361 gdk_threads_leave ();
3367 gdk_event_dispatch (GSource *source,
3368 GSourceFunc callback,
3373 gdk_threads_enter ();
3375 _gdk_win32_display_queue_events (_gdk_display);
3376 event = _gdk_event_unqueue (_gdk_display);
3380 _gdk_event_emit (event);
3382 gdk_event_free (event);
3384 /* Do drag & drop if it is still pending */
3385 if (_dnd_source_state == GDK_WIN32_DND_PENDING)
3387 _dnd_source_state = GDK_WIN32_DND_DRAGGING;
3388 _gdk_win32_dnd_do_dragdrop ();
3389 _dnd_source_state = GDK_WIN32_DND_NONE;
3393 gdk_threads_leave ();
3399 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3401 modal_win32_dialog = window;