1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright (C) 1998-2002 Tor Lillqvist
4 * Copyright (C) 2001,2009 Hans Breuer
5 * Copyright (C) 2007-2009 Cody Russell
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
25 * file for a list of people on the GTK+ Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 /* Cannot use TrackMouseEvent, as the stupid WM_MOUSELEAVE message
31 * doesn't tell us where the mouse has gone. Thus we cannot use it to
32 * generate a correct GdkNotifyType. Pity, as using TrackMouseEvent
33 * otherwise would make it possible to reliably generate
34 * GDK_LEAVE_NOTIFY events, which would help get rid of those pesky
35 * tooltips sometimes popping up in the wrong place.
37 * Update: a combination of TrackMouseEvent, GetCursorPos and
38 * GetWindowPos can and is actually used to get rid of those
39 * pesky tooltips. It should be possible to use this for the
40 * whole ENTER/LEAVE NOTIFY handling but some platforms may
41 * not have TrackMouseEvent at all (?) --hb
46 #include <glib/gprintf.h>
49 #include "gdkdisplayprivate.h"
50 #include "gdkprivate-win32.h"
52 #include "gdkkeysyms.h"
53 #include "gdkdevicemanager-win32.h"
54 #include "gdkdeviceprivate.h"
55 #include "gdkdevice-wintab.h"
56 #include "gdkwin32dnd.h"
57 #include "gdkdndprivate.h"
81 #define MK_XBUTTON1 32
82 #define MK_XBUTTON2 64
85 /* Undefined flags: */
86 #define SWP_NOCLIENTSIZE 0x0800
87 #define SWP_NOCLIENTMOVE 0x1000
88 #define SWP_STATECHANGED 0x8000
90 * Private function declarations
93 #define SYNAPSIS_ICON_WINDOW_CLASS "SynTrackCursorWindowClass"
95 static gboolean gdk_event_translate (MSG *msg,
97 static void handle_wm_paint (MSG *msg,
99 gboolean return_exposes,
102 static gboolean gdk_event_prepare (GSource *source,
104 static gboolean gdk_event_check (GSource *source);
105 static gboolean gdk_event_dispatch (GSource *source,
106 GSourceFunc callback,
109 /* Private variable declarations
112 static GList *client_filters; /* Filters for client messages */
113 extern gint _gdk_input_ignore_core;
115 static HCURSOR p_grab_cursor;
117 static GSourceFuncs event_funcs = {
124 GPollFD event_poll_fd;
126 static GdkWindow *mouse_window = NULL;
127 static GdkWindow *mouse_window_ignored_leave = NULL;
128 static gint current_x, current_y;
129 static gint current_root_x, current_root_y;
130 static UINT client_message;
132 static UINT got_gdk_events_message;
133 static HWND modal_win32_dialog = NULL;
136 static HKL latin_locale = NULL;
139 static gboolean in_ime_composition = FALSE;
140 static UINT modal_timer;
141 static UINT sync_timer = 0;
143 static int debug_indent = 0;
146 assign_object (gpointer lhsp,
149 if (*(gpointer *)lhsp != rhs)
151 if (*(gpointer *)lhsp != NULL)
152 g_object_unref (*(gpointer *)lhsp);
153 *(gpointer *)lhsp = rhs;
160 track_mouse_event (DWORD dwFlags,
165 tme.cbSize = sizeof(TRACKMOUSEEVENT);
166 tme.dwFlags = dwFlags;
167 tme.hwndTrack = hwnd;
168 tme.dwHoverTime = HOVER_DEFAULT; /* not used */
170 if (!TrackMouseEvent (&tme))
171 WIN32_API_FAILED ("TrackMouseEvent");
172 else if (dwFlags == TME_LEAVE)
173 GDK_NOTE (EVENTS, g_print(" (TrackMouseEvent %p)", hwnd));
174 else if (dwFlags == TME_CANCEL)
175 GDK_NOTE (EVENTS, g_print(" (cancel TrackMouseEvent %p)", hwnd));
179 _gdk_win32_get_next_tick (gulong suggested_tick)
181 static gulong cur_tick = 0;
183 if (suggested_tick == 0)
184 suggested_tick = GetTickCount ();
185 if (suggested_tick <= cur_tick)
188 return cur_tick = suggested_tick;
192 generate_focus_event (GdkDeviceManager *device_manager,
199 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_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);
206 _gdk_win32_append_event (event);
210 generate_grab_broken_event (GdkDeviceManager *device_manager,
213 GdkWindow *grab_window)
215 GdkEvent *event = gdk_event_new (GDK_GRAB_BROKEN);
219 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
221 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer;
223 event->grab_broken.window = window;
224 event->grab_broken.send_event = 0;
225 event->grab_broken.keyboard = keyboard;
226 event->grab_broken.implicit = FALSE;
227 event->grab_broken.grab_window = grab_window;
228 gdk_event_set_device (event, device);
230 _gdk_win32_append_event (event);
234 inner_window_procedure (HWND hwnd,
244 msg.message = message;
247 msg.time = _gdk_win32_get_next_tick (0);
248 pos = GetMessagePos ();
249 msg.pt.x = GET_X_LPARAM (pos);
250 msg.pt.y = GET_Y_LPARAM (pos);
252 if (gdk_event_translate (&msg, &ret_val))
254 /* If gdk_event_translate() returns TRUE, we return ret_val from
255 * the window procedure.
257 if (modal_win32_dialog)
258 PostMessageW (modal_win32_dialog, got_gdk_events_message,
264 /* Otherwise call DefWindowProcW(). */
265 GDK_NOTE (EVENTS, g_print (" DefWindowProcW"));
266 return DefWindowProcW (hwnd, message, wparam, lparam);
271 _gdk_win32_window_procedure (HWND hwnd,
278 GDK_NOTE (EVENTS, g_print ("%s%*s%s %p",
279 (debug_indent > 0 ? "\n" : ""),
281 _gdk_win32_message_to_string (message), hwnd));
283 retval = inner_window_procedure (hwnd, message, wparam, lparam);
286 GDK_NOTE (EVENTS, g_print (" => %I64d%s", (gint64) retval, (debug_indent == 0 ? "\n" : "")));
292 _gdk_events_init (void)
299 /* List of languages that use a latin keyboard. Somewhat sorted in
300 * "order of least surprise", in case we have to load one of them if
301 * the user only has arabic loaded, for instance.
303 static int latin_languages[] = {
309 /* Rest in numeric order */
338 client_message = RegisterWindowMessage ("GDK_WIN32_CLIENT_MESSAGE");
339 got_gdk_events_message = RegisterWindowMessage ("GDK_WIN32_GOT_EVENTS");
342 /* Check if we have some input locale identifier loaded that uses a
343 * latin keyboard, to be able to get the virtual-key code for the
344 * latin characters corresponding to ASCII control characters.
346 if ((n = GetKeyboardLayoutList (0, NULL)) == 0)
347 WIN32_API_FAILED ("GetKeyboardLayoutList");
350 HKL *hkl_list = g_new (HKL, n);
351 if (GetKeyboardLayoutList (n, hkl_list) == 0)
352 WIN32_API_FAILED ("GetKeyboardLayoutList");
355 for (i = 0; latin_locale == NULL && i < n; i++)
356 for (j = 0; j < G_N_ELEMENTS (latin_languages); j++)
357 if (PRIMARYLANGID (LOWORD (hkl_list[i])) == latin_languages[j])
359 latin_locale = hkl_list [i];
366 if (latin_locale == NULL)
368 /* Try to load a keyboard layout with latin characters then.
371 while (latin_locale == NULL && i < G_N_ELEMENTS (latin_languages))
374 g_sprintf (id, "%08x", MAKELANGID (latin_languages[i++], SUBLANG_DEFAULT));
375 latin_locale = LoadKeyboardLayout (id, KLF_NOTELLSHELL|KLF_SUBSTITUTE_OK);
379 GDK_NOTE (EVENTS, g_print ("latin_locale = %08x\n", (guint) latin_locale));
382 source = g_source_new (&event_funcs, sizeof (GSource));
383 g_source_set_name (source, "GDK Win32 event source");
384 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
387 event_poll_fd.fd = open ("/dev/windows", O_RDONLY);
388 if (event_poll_fd.fd == -1)
389 g_error ("can't open \"/dev/windows\": %s", g_strerror (errno));
391 event_poll_fd.fd = G_WIN32_MSG_HANDLE;
393 event_poll_fd.events = G_IO_IN;
395 g_source_add_poll (source, &event_poll_fd);
396 g_source_set_can_recurse (source, TRUE);
397 g_source_attach (source, NULL);
401 _gdk_win32_display_has_pending (GdkDisplay *display)
403 return (_gdk_event_queue_find_first (display) ||
404 (modal_win32_dialog == NULL &&
405 GetQueueStatus (QS_ALLINPUT) != 0));
408 #if 0 /* Unused, but might be useful to re-introduce in some debugging output? */
411 event_mask_string (GdkEventMask mask)
413 static char bfr[500];
418 if (mask & GDK_##x##_MASK) \
419 p += g_sprintf (p, "%s" #x, (p > bfr ? " " : ""))
421 BIT (POINTER_MOTION);
422 BIT (POINTER_MOTION_HINT);
424 BIT (BUTTON1_MOTION);
425 BIT (BUTTON2_MOTION);
426 BIT (BUTTON3_MOTION);
428 BIT (BUTTON_RELEASE);
435 BIT (PROPERTY_CHANGE);
436 BIT (VISIBILITY_NOTIFY);
449 _gdk_windowing_device_grab (GdkDevice *device,
451 GdkWindow *native_window,
452 gboolean owner_events,
453 GdkEventMask event_mask,
454 GdkWindow *confine_to,
459 GdkWin32Cursor *cursor_private;
461 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (native_window->impl);
463 g_return_val_if_fail (window != NULL, 0);
464 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
465 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
467 cursor_private = (GdkWin32Cursor*) cursor;
471 else if ((hcursor = CopyCursor (cursor_private->hcursor)) == NULL)
472 WIN32_API_FAILED ("CopyCursor");
474 return_val = GDK_DEVICE_GET_CLASS (device)->grab (device,
482 /* TODO_CSW: grab brokens, confine window, input_grab */
483 if (p_grab_cursor != NULL)
485 if (GetCursor () == p_grab_cursor)
487 DestroyCursor (p_grab_cursor);
490 p_grab_cursor = hcursor;
492 if (p_grab_cursor != NULL)
493 SetCursor (p_grab_cursor);
494 else if (impl->hcursor != NULL)
495 SetCursor (impl->hcursor);
497 SetCursor (LoadCursor (NULL, IDC_ARROW));
503 find_window_for_mouse_event (GdkWindow* reported_window,
507 GdkDeviceManagerWin32 *device_manager;
508 GdkWindow *event_window;
511 GdkDeviceGrabInfo *grab;
513 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (_gdk_display));
515 grab = _gdk_display_get_last_device_grab (_gdk_display, device_manager->core_pointer);
517 return reported_window;
521 if (!grab->owner_events)
522 event_window = grab->native_window;
526 hwnd = WindowFromPoint (pt);
529 POINT client_pt = pt;
531 ScreenToClient (hwnd, &client_pt);
532 GetClientRect (hwnd, &rect);
533 if (PtInRect (&rect, client_pt))
534 event_window = gdk_win32_handle_table_lookup (hwnd);
536 if (event_window == NULL)
537 event_window = grab->native_window;
540 /* need to also adjust the coordinates to the new window */
541 ScreenToClient (GDK_WINDOW_HWND (event_window), &pt);
543 /* ATTENTION: need to update client coords */
544 msg->lParam = MAKELPARAM (pt.x, pt.y);
550 build_key_event_state (GdkEvent *event,
553 event->key.state = 0;
555 if (key_state[VK_SHIFT] & 0x80)
556 event->key.state |= GDK_SHIFT_MASK;
558 if (key_state[VK_CAPITAL] & 0x01)
559 event->key.state |= GDK_LOCK_MASK;
561 if (key_state[VK_LBUTTON] & 0x80)
562 event->key.state |= GDK_BUTTON1_MASK;
563 if (key_state[VK_MBUTTON] & 0x80)
564 event->key.state |= GDK_BUTTON2_MASK;
565 if (key_state[VK_RBUTTON] & 0x80)
566 event->key.state |= GDK_BUTTON3_MASK;
567 if (key_state[VK_XBUTTON1] & 0x80)
568 event->key.state |= GDK_BUTTON4_MASK;
569 if (key_state[VK_XBUTTON2] & 0x80)
570 event->key.state |= GDK_BUTTON5_MASK;
572 if (_gdk_keyboard_has_altgr &&
573 (key_state[VK_LCONTROL] & 0x80) &&
574 (key_state[VK_RMENU] & 0x80))
576 event->key.group = 1;
577 event->key.state |= GDK_MOD2_MASK;
578 if (key_state[VK_RCONTROL] & 0x80)
579 event->key.state |= GDK_CONTROL_MASK;
580 if (key_state[VK_LMENU] & 0x80)
581 event->key.state |= GDK_MOD1_MASK;
585 event->key.group = 0;
586 if (key_state[VK_CONTROL] & 0x80)
587 event->key.state |= GDK_CONTROL_MASK;
588 if (key_state[VK_MENU] & 0x80)
589 event->key.state |= GDK_MOD1_MASK;
594 build_pointer_event_state (MSG *msg)
600 if (msg->wParam & MK_CONTROL)
601 state |= GDK_CONTROL_MASK;
603 if ((msg->message != WM_LBUTTONDOWN &&
604 (msg->wParam & MK_LBUTTON)) ||
605 msg->message == WM_LBUTTONUP)
606 state |= GDK_BUTTON1_MASK;
608 if ((msg->message != WM_MBUTTONDOWN &&
609 (msg->wParam & MK_MBUTTON)) ||
610 msg->message == WM_MBUTTONUP)
611 state |= GDK_BUTTON2_MASK;
613 if ((msg->message != WM_RBUTTONDOWN &&
614 (msg->wParam & MK_RBUTTON)) ||
615 msg->message == WM_RBUTTONUP)
616 state |= GDK_BUTTON3_MASK;
618 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON1) &&
619 (msg->wParam & MK_XBUTTON1)) ||
620 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON1))
621 state |= GDK_BUTTON4_MASK;
623 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON2) &&
624 (msg->wParam & MK_XBUTTON2)) ||
625 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON2))
626 state |= GDK_BUTTON5_MASK;
628 if (msg->wParam & MK_SHIFT)
629 state |= GDK_SHIFT_MASK;
631 if (GetKeyState (VK_MENU) < 0)
632 state |= GDK_MOD1_MASK;
634 if (GetKeyState (VK_CAPITAL) & 0x1)
635 state |= GDK_LOCK_MASK;
641 build_wm_ime_composition_event (GdkEvent *event,
646 event->key.time = _gdk_win32_get_next_tick (msg->time);
648 build_key_event_state (event, key_state);
650 event->key.hardware_keycode = 0; /* FIXME: What should it be? */
651 event->key.string = NULL;
652 event->key.length = 0;
653 event->key.keyval = gdk_unicode_to_keyval (wc);
656 #ifdef G_ENABLE_DEBUG
659 print_event_state (guint state)
661 #define CASE(bit) if (state & GDK_ ## bit ## _MASK) g_print (#bit " ");
679 _gdk_win32_print_event (const GdkEvent *event)
681 gchar *escaped, *kvname;
682 gchar *selection_name, *target_name, *property_name;
684 g_print ("%s%*s===> ", (debug_indent > 0 ? "\n" : ""), debug_indent, "");
685 switch (event->any.type)
687 #define CASE(x) case x: g_print (#x); break;
692 CASE (GDK_MOTION_NOTIFY);
693 CASE (GDK_BUTTON_PRESS);
694 CASE (GDK_2BUTTON_PRESS);
695 CASE (GDK_3BUTTON_PRESS);
696 CASE (GDK_BUTTON_RELEASE);
697 CASE (GDK_KEY_PRESS);
698 CASE (GDK_KEY_RELEASE);
699 CASE (GDK_ENTER_NOTIFY);
700 CASE (GDK_LEAVE_NOTIFY);
701 CASE (GDK_FOCUS_CHANGE);
702 CASE (GDK_CONFIGURE);
705 CASE (GDK_PROPERTY_NOTIFY);
706 CASE (GDK_SELECTION_CLEAR);
707 CASE (GDK_SELECTION_REQUEST);
708 CASE (GDK_SELECTION_NOTIFY);
709 CASE (GDK_PROXIMITY_IN);
710 CASE (GDK_PROXIMITY_OUT);
711 CASE (GDK_DRAG_ENTER);
712 CASE (GDK_DRAG_LEAVE);
713 CASE (GDK_DRAG_MOTION);
714 CASE (GDK_DRAG_STATUS);
715 CASE (GDK_DROP_START);
716 CASE (GDK_DROP_FINISHED);
717 CASE (GDK_CLIENT_EVENT);
718 CASE (GDK_VISIBILITY_NOTIFY);
720 CASE (GDK_WINDOW_STATE);
722 CASE (GDK_OWNER_CHANGE);
723 CASE (GDK_GRAB_BROKEN);
725 default: g_assert_not_reached ();
728 g_print (" %p ", event->any.window ? GDK_WINDOW_HWND (event->any.window) : NULL);
730 switch (event->any.type)
734 _gdk_win32_gdkrectangle_to_string (&event->expose.area),
735 event->expose.count);
737 case GDK_MOTION_NOTIFY:
738 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s",
739 event->motion.x, event->motion.y,
740 event->motion.x_root, event->motion.y_root,
741 event->motion.is_hint ? "HINT " : "");
742 print_event_state (event->motion.state);
744 case GDK_BUTTON_PRESS:
745 case GDK_2BUTTON_PRESS:
746 case GDK_3BUTTON_PRESS:
747 case GDK_BUTTON_RELEASE:
748 g_print ("%d (%.4g,%.4g) (%.4g,%.4g) ",
749 event->button.button,
750 event->button.x, event->button.y,
751 event->button.x_root, event->button.y_root);
752 print_event_state (event->button.state);
755 case GDK_KEY_RELEASE:
756 if (event->key.length == 0)
757 escaped = g_strdup ("");
759 escaped = g_strescape (event->key.string, NULL);
760 kvname = gdk_keyval_name (event->key.keyval);
761 g_print ("%#.02x group:%d %s %d:\"%s\" ",
762 event->key.hardware_keycode, event->key.group,
763 (kvname ? kvname : "??"),
767 print_event_state (event->key.state);
769 case GDK_ENTER_NOTIFY:
770 case GDK_LEAVE_NOTIFY:
771 g_print ("%p (%.4g,%.4g) (%.4g,%.4g) %s %s%s",
772 event->crossing.subwindow == NULL ? NULL : GDK_WINDOW_HWND (event->crossing.subwindow),
773 event->crossing.x, event->crossing.y,
774 event->crossing.x_root, event->crossing.y_root,
775 (event->crossing.mode == GDK_CROSSING_NORMAL ? "NORMAL" :
776 (event->crossing.mode == GDK_CROSSING_GRAB ? "GRAB" :
777 (event->crossing.mode == GDK_CROSSING_UNGRAB ? "UNGRAB" :
779 (event->crossing.detail == GDK_NOTIFY_ANCESTOR ? "ANCESTOR" :
780 (event->crossing.detail == GDK_NOTIFY_VIRTUAL ? "VIRTUAL" :
781 (event->crossing.detail == GDK_NOTIFY_INFERIOR ? "INFERIOR" :
782 (event->crossing.detail == GDK_NOTIFY_NONLINEAR ? "NONLINEAR" :
783 (event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL ? "NONLINEAR_VIRTUAL" :
784 (event->crossing.detail == GDK_NOTIFY_UNKNOWN ? "UNKNOWN" :
786 event->crossing.focus ? " FOCUS" : "");
787 print_event_state (event->crossing.state);
789 case GDK_FOCUS_CHANGE:
790 g_print ("%s", (event->focus_change.in ? "IN" : "OUT"));
793 g_print ("x:%d y:%d w:%d h:%d",
794 event->configure.x, event->configure.y,
795 event->configure.width, event->configure.height);
797 case GDK_SELECTION_CLEAR:
798 case GDK_SELECTION_REQUEST:
799 case GDK_SELECTION_NOTIFY:
800 selection_name = gdk_atom_name (event->selection.selection);
801 target_name = gdk_atom_name (event->selection.target);
802 property_name = gdk_atom_name (event->selection.property);
803 g_print ("sel:%s tgt:%s prop:%s",
804 selection_name, target_name, property_name);
805 g_free (selection_name);
806 g_free (target_name);
807 g_free (property_name);
811 case GDK_DRAG_MOTION:
812 case GDK_DRAG_STATUS:
814 case GDK_DROP_FINISHED:
815 if (event->dnd.context != NULL)
816 g_print ("ctx:%p: %s %s src:%p dest:%p",
818 _gdk_win32_drag_protocol_to_string (event->dnd.context->protocol),
819 event->dnd.context->is_source ? "SOURCE" : "DEST",
820 event->dnd.context->source_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->source_window),
821 event->dnd.context->dest_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->dest_window));
823 case GDK_CLIENT_EVENT:
824 /* no more GdkEventClient */
827 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",
828 event->scroll.x, event->scroll.y,
829 event->scroll.x_root, event->scroll.y_root,
830 (event->scroll.direction == GDK_SCROLL_UP ? "UP" :
831 (event->scroll.direction == GDK_SCROLL_DOWN ? "DOWN" :
832 (event->scroll.direction == GDK_SCROLL_LEFT ? "LEFT" :
833 (event->scroll.direction == GDK_SCROLL_RIGHT ? "RIGHT" :
835 print_event_state (event->scroll.state);
837 case GDK_WINDOW_STATE:
839 _gdk_win32_window_state_to_string (event->window_state.changed_mask),
840 _gdk_win32_window_state_to_string (event->window_state.new_window_state));
843 (event->setting.action == GDK_SETTING_ACTION_NEW ? "NEW" :
844 (event->setting.action == GDK_SETTING_ACTION_CHANGED ? "CHANGED" :
845 (event->setting.action == GDK_SETTING_ACTION_DELETED ? "DELETED" :
847 (event->setting.name ? event->setting.name : "NULL"));
848 case GDK_GRAB_BROKEN:
850 (event->grab_broken.keyboard ? "KEYBOARD" : "POINTER"),
851 (event->grab_broken.implicit ? "IMPLICIT" : "EXPLICIT"),
852 (event->grab_broken.grab_window ? GDK_WINDOW_HWND (event->grab_broken.grab_window) : 0));
857 g_print ("%s", (debug_indent == 0 ? "\n" : ""));
861 decode_key_lparam (LPARAM lParam)
863 static char buf[100];
866 if (HIWORD (lParam) & KF_UP)
867 p += g_sprintf (p, "KF_UP ");
868 if (HIWORD (lParam) & KF_REPEAT)
869 p += g_sprintf (p, "KF_REPEAT ");
870 if (HIWORD (lParam) & KF_ALTDOWN)
871 p += g_sprintf (p, "KF_ALTDOWN ");
872 if (HIWORD (lParam) & KF_EXTENDED)
873 p += g_sprintf (p, "KF_EXTENDED ");
874 p += g_sprintf (p, "sc:%d rep:%d", LOBYTE (HIWORD (lParam)), LOWORD (lParam));
882 fixup_event (GdkEvent *event)
884 if (event->any.window)
885 g_object_ref (event->any.window);
886 if (((event->any.type == GDK_ENTER_NOTIFY) ||
887 (event->any.type == GDK_LEAVE_NOTIFY)) &&
888 (event->crossing.subwindow != NULL))
889 g_object_ref (event->crossing.subwindow);
890 event->any.send_event = InSendMessage ();
894 _gdk_win32_append_event (GdkEvent *event)
900 link = _gdk_event_queue_append (_gdk_display, event);
901 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
902 /* event morphing, the passed in may not be valid afterwards */
903 _gdk_windowing_got_event (_gdk_display, link, event, 0);
905 _gdk_event_queue_append (_gdk_display, event);
906 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
911 fill_key_event_string (GdkEvent *event)
916 /* Fill in event->string crudely, since various programs
921 if (event->key.keyval != GDK_KEY_VoidSymbol)
922 c = gdk_keyval_to_unicode (event->key.keyval);
929 /* Apply the control key - Taken from Xlib
931 if (event->key.state & GDK_CONTROL_MASK)
933 if ((c >= '@' && c < '\177') || c == ' ')
937 event->key.string = g_memdup ("\0\0", 2);
938 event->key.length = 1;
941 else if (c >= '3' && c <= '7')
949 len = g_unichar_to_utf8 (c, buf);
952 event->key.string = g_locale_from_utf8 (buf, len,
953 NULL, &bytes_written,
955 if (event->key.string)
956 event->key.length = bytes_written;
958 else if (event->key.keyval == GDK_KEY_Escape)
960 event->key.length = 1;
961 event->key.string = g_strdup ("\033");
963 else if (event->key.keyval == GDK_KEY_Return ||
964 event->key.keyval == GDK_KEY_KP_Enter)
966 event->key.length = 1;
967 event->key.string = g_strdup ("\r");
970 if (!event->key.string)
972 event->key.length = 0;
973 event->key.string = g_strdup ("");
977 static GdkFilterReturn
978 apply_event_filters (GdkWindow *window,
982 GdkFilterReturn result = GDK_FILTER_CONTINUE;
987 event = gdk_event_new (GDK_NOTHING);
989 event->any.window = g_object_ref (window);
990 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
992 /* I think GdkFilterFunc semantics require the passed-in event
993 * to already be in the queue. The filter func can generate
994 * more events and append them after it if it likes.
996 node = _gdk_event_queue_append (_gdk_display, event);
1001 GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
1004 if ((filter->flags & GDK_EVENT_FILTER_REMOVED) != 0)
1006 tmp_list = tmp_list->next;
1010 filter->ref_count++;
1011 result = filter->function (msg, event, filter->data);
1013 /* get the next node after running the function since the
1014 function may add or remove a next node */
1016 tmp_list = tmp_list->next;
1018 filter->ref_count--;
1019 if (filter->ref_count == 0)
1021 *filters = g_list_remove_link (*filters, node);
1022 g_list_free_1 (node);
1026 if (result != GDK_FILTER_CONTINUE)
1030 if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
1032 _gdk_event_queue_remove_link (_gdk_display, node);
1033 g_list_free_1 (node);
1034 gdk_event_free (event);
1036 else /* GDK_FILTER_TRANSLATE */
1038 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1039 fixup_event (event);
1040 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1046 * On Windows, transient windows will not have their own taskbar entries.
1047 * Because of this, we must hide and restore groups of transients in both
1048 * directions. That is, all transient children must be hidden or restored
1049 * with this window, but if this window's transient owner also has a
1050 * transient owner then this window's transient owner must be hidden/restored
1051 * with this one. And etc, up the chain until we hit an ancestor that has no
1054 * It would be a good idea if applications don't chain transient windows
1055 * together. There's a limit to how much evil GTK can try to shield you
1059 show_window_recurse (GdkWindow *window, gboolean hide_window)
1061 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1062 GSList *children = impl->transient_children;
1063 GdkWindow *child = NULL;
1065 if (!impl->changing_state)
1067 impl->changing_state = TRUE;
1069 if (children != NULL)
1071 while (children != NULL)
1073 child = children->data;
1074 show_window_recurse (child, hide_window);
1076 children = g_slist_next (children);
1080 if (GDK_WINDOW_IS_MAPPED (window))
1084 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_ICONIFIED)
1086 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED)
1088 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
1092 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1098 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
1102 impl->changing_state = FALSE;
1107 do_show_window (GdkWindow *window, gboolean hide_window)
1109 GdkWindow *tmp_window = NULL;
1110 GdkWindowImplWin32 *tmp_impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1112 if (!tmp_impl->changing_state)
1114 /* Find the top-level window in our transient chain. */
1115 while (tmp_impl->transient_owner != NULL)
1117 tmp_window = tmp_impl->transient_owner;
1118 tmp_impl = GDK_WINDOW_IMPL_WIN32 (tmp_window->impl);
1121 /* If we couldn't find one, use the window provided. */
1122 if (tmp_window == NULL)
1124 tmp_window = window;
1127 /* Recursively show/hide every window in the chain. */
1128 if (tmp_window != window)
1130 show_window_recurse (tmp_window, hide_window);
1136 send_crossing_event (GdkDisplay *display,
1139 GdkCrossingMode mode,
1140 GdkNotifyType notify_type,
1141 GdkWindow *subwindow,
1143 GdkModifierType mask,
1147 GdkDeviceGrabInfo *grab;
1148 GdkDeviceManagerWin32 *device_manager;
1151 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (display));
1153 grab = _gdk_display_has_device_grab (display, device_manager->core_pointer, 0);
1156 !grab->owner_events &&
1157 mode != GDK_CROSSING_UNGRAB)
1159 /* !owner_event => only report events wrt grab window, ignore rest */
1160 if ((GdkWindow *)window != grab->native_window)
1165 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1167 event = gdk_event_new (type);
1168 event->crossing.window = window;
1169 event->crossing.subwindow = subwindow;
1170 event->crossing.time = _gdk_win32_get_next_tick (time_);
1171 event->crossing.x = pt.x;
1172 event->crossing.y = pt.y;
1173 event->crossing.x_root = screen_pt->x + _gdk_offset_x;
1174 event->crossing.y_root = screen_pt->y + _gdk_offset_y;
1175 event->crossing.mode = mode;
1176 event->crossing.detail = notify_type;
1177 event->crossing.mode = mode;
1178 event->crossing.detail = notify_type;
1179 event->crossing.focus = FALSE;
1180 event->crossing.state = mask;
1181 gdk_event_set_device (event, _gdk_display->core_pointer);
1183 _gdk_win32_append_event (event);
1185 if (type == GDK_ENTER_NOTIFY &&
1186 window->extension_events != 0)
1187 _gdk_device_wintab_update_window_coords (window);
1191 get_native_parent (GdkWindow *window)
1193 if (window->parent != NULL)
1194 return window->parent->impl_window;
1199 find_common_ancestor (GdkWindow *win1,
1203 GList *path1 = NULL, *path2 = NULL;
1204 GList *list1, *list2;
1207 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
1209 path1 = g_list_prepend (path1, tmp);
1210 tmp = get_native_parent (tmp);
1214 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
1216 path2 = g_list_prepend (path2, tmp);
1217 tmp = get_native_parent (tmp);
1223 while (list1 && list2 && (list1->data == list2->data))
1225 tmp = (GdkWindow *)list1->data;
1226 list1 = g_list_next (list1);
1227 list2 = g_list_next (list2);
1229 g_list_free (path1);
1230 g_list_free (path2);
1236 synthesize_crossing_events (GdkDisplay *display,
1239 GdkCrossingMode mode,
1241 GdkModifierType mask,
1243 gboolean non_linear)
1246 GdkWindow *win, *last, *next;
1250 GdkNotifyType notify_type;
1255 return; /* No crossings generated between src and dest */
1257 c = find_common_ancestor (a, b);
1259 non_linear |= (c != a) && (c != b);
1261 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
1263 /* Traverse up from a to (excluding) c sending leave events */
1265 notify_type = GDK_NOTIFY_NONLINEAR;
1267 notify_type = GDK_NOTIFY_INFERIOR;
1269 notify_type = GDK_NOTIFY_ANCESTOR;
1270 send_crossing_event (display,
1271 a, GDK_LEAVE_NOTIFY,
1281 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1283 notify_type = GDK_NOTIFY_VIRTUAL;
1286 win = get_native_parent (a);
1287 while (win != c && win->window_type != GDK_WINDOW_ROOT)
1289 send_crossing_event (display,
1290 win, GDK_LEAVE_NOTIFY,
1298 win = get_native_parent (win);
1303 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
1305 /* Traverse down from c to b */
1309 win = get_native_parent (b);
1310 while (win != c && win->window_type != GDK_WINDOW_ROOT)
1312 path = g_list_prepend (path, win);
1313 win = get_native_parent (win);
1317 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1319 notify_type = GDK_NOTIFY_VIRTUAL;
1324 win = (GdkWindow *)list->data;
1325 list = g_list_next (list);
1327 next = (GdkWindow *)list->data;
1331 send_crossing_event (display,
1332 win, GDK_ENTER_NOTIFY,
1344 notify_type = GDK_NOTIFY_NONLINEAR;
1346 notify_type = GDK_NOTIFY_ANCESTOR;
1348 notify_type = GDK_NOTIFY_INFERIOR;
1350 send_crossing_event (display,
1351 b, GDK_ENTER_NOTIFY,
1360 /* The check_extended flag controls whether to check if the windows want
1361 * events from extended input devices and if the message should be skipped
1362 * because an extended input device is active
1365 propagate (GdkWindow **window,
1367 GdkWindow *grab_window,
1368 gboolean grab_owner_events,
1370 gboolean (*doesnt_want_it) (gint mask,
1372 gboolean check_extended)
1374 if (grab_window != NULL && !grab_owner_events)
1376 /* Event source is grabbed with owner_events FALSE */
1378 /* See if the event should be ignored because an extended input
1381 if (check_extended &&
1382 grab_window->extension_events != 0 &&
1383 _gdk_input_ignore_core)
1385 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1388 if ((*doesnt_want_it) (grab_mask, msg))
1390 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1395 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1396 assign_object (window, grab_window);
1401 /* If we come here, we know that if grab_window != NULL then
1402 * grab_owner_events is TRUE
1406 if (check_extended &&
1407 (*window)->extension_events != 0 &&
1408 _gdk_input_ignore_core)
1410 GDK_NOTE (EVENTS, g_print (" (ignored)"));
1413 if ((*doesnt_want_it) ((*window)->event_mask, msg))
1415 /* Owner doesn't want it, propagate to parent. */
1416 GdkWindow *parent = gdk_window_get_parent (*window);
1417 if (parent == _gdk_root || parent == NULL)
1419 /* No parent; check if grabbed */
1420 if (grab_window != NULL)
1422 /* Event source is grabbed with owner_events TRUE */
1424 if (check_extended &&
1425 grab_window->extension_events != 0 &&
1426 _gdk_input_ignore_core)
1428 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1431 if ((*doesnt_want_it) (grab_mask, msg))
1433 /* Grabber doesn't want it either */
1434 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1440 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1441 assign_object (window, grab_window);
1447 GDK_NOTE (EVENTS, g_print (" (undelivered)"));
1453 assign_object (window, parent);
1454 /* The only branch where we actually continue the loop */
1463 doesnt_want_key (gint mask,
1466 return (((msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) &&
1467 !(mask & GDK_KEY_RELEASE_MASK)) ||
1468 ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) &&
1469 !(mask & GDK_KEY_PRESS_MASK)));
1473 doesnt_want_char (gint mask,
1476 return !(mask & (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK));
1480 _gdk_win32_emit_configure_event (GdkWindow *window)
1482 GdkWindowImplWin32 *window_impl;
1487 window_impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1488 if (window_impl->inhibit_configure)
1491 hwnd = GDK_WINDOW_HWND (window);
1493 GetClientRect (hwnd, &client_rect);
1494 point.x = client_rect.left; /* always 0 */
1495 point.y = client_rect.top;
1497 /* top level windows need screen coords */
1498 if (gdk_window_get_parent (window) == _gdk_root)
1500 ClientToScreen (hwnd, &point);
1501 point.x += _gdk_offset_x;
1502 point.y += _gdk_offset_y;
1505 window->width = client_rect.right - client_rect.left;
1506 window->height = client_rect.bottom - client_rect.top;
1508 window->x = point.x;
1509 window->y = point.y;
1511 _gdk_window_update_size (window);
1513 if (window->event_mask & GDK_STRUCTURE_MASK)
1515 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1517 event->configure.window = window;
1519 event->configure.width = client_rect.right - client_rect.left;
1520 event->configure.height = client_rect.bottom - client_rect.top;
1522 event->configure.x = point.x;
1523 event->configure.y = point.y;
1525 _gdk_win32_append_event (event);
1530 _gdk_win32_hrgn_to_region (HRGN hrgn)
1534 cairo_region_t *result;
1538 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1540 WIN32_GDI_FAILED ("GetRegionData");
1544 rgndata = (RGNDATA *) g_malloc (nbytes);
1546 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1548 WIN32_GDI_FAILED ("GetRegionData");
1553 result = cairo_region_create ();
1554 rects = (RECT *) rgndata->Buffer;
1555 for (i = 0; i < rgndata->rdh.nCount; i++)
1559 r.x = rects[i].left;
1561 r.width = rects[i].right - r.x;
1562 r.height = rects[i].bottom - r.y;
1564 cairo_region_union_rectangle (result, &r);
1573 adjust_drag (LONG *drag,
1578 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1580 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1584 handle_wm_paint (MSG *msg,
1586 gboolean return_exposes,
1589 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1591 PAINTSTRUCT paintstruct;
1592 cairo_region_t *update_region;
1594 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1596 WIN32_GDI_FAILED ("GetUpdateRgn");
1597 DeleteObject (hrgn);
1601 hdc = BeginPaint (msg->hwnd, &paintstruct);
1603 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1604 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1605 (paintstruct.fErase ? "erase" : ""),
1607 (return_exposes ? " return_exposes" : "")));
1609 EndPaint (msg->hwnd, &paintstruct);
1611 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1612 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1614 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1615 DeleteObject (hrgn);
1621 if (!GDK_WINDOW_DESTROYED (window))
1623 GList *list = _gdk_display->queued_events;
1625 *event = gdk_event_new (GDK_EXPOSE);
1626 (*event)->expose.window = window;
1627 (*event)->expose.area.x = paintstruct.rcPaint.left;
1628 (*event)->expose.area.y = paintstruct.rcPaint.top;
1629 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1630 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1631 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1632 (*event)->expose.count = 0;
1634 while (list != NULL)
1636 GdkEventPrivate *evp = list->data;
1638 if (evp->event.any.type == GDK_EXPOSE &&
1639 evp->event.any.window == window &&
1640 !(evp->flags & GDK_EVENT_PENDING))
1641 evp->event.expose.count++;
1647 DeleteObject (hrgn);
1651 update_region = _gdk_win32_hrgn_to_region (hrgn);
1652 if (!cairo_region_is_empty (update_region))
1653 _gdk_window_invalidate_for_expose (window, update_region);
1654 cairo_region_destroy (update_region);
1656 DeleteObject (hrgn);
1659 static VOID CALLBACK
1660 modal_timer_proc (HWND hwnd,
1665 int arbitrary_limit = 10;
1667 while (_modal_operation_in_progress &&
1668 g_main_context_pending (NULL) &&
1670 g_main_context_iteration (NULL, FALSE);
1674 _gdk_win32_begin_modal_call (void)
1676 g_assert (!_modal_operation_in_progress);
1678 _modal_operation_in_progress = TRUE;
1680 modal_timer = SetTimer (NULL, 0, 10, modal_timer_proc);
1681 if (modal_timer == 0)
1682 WIN32_API_FAILED ("SetTimer");
1686 _gdk_win32_end_modal_call (void)
1688 g_assert (_modal_operation_in_progress);
1690 _modal_operation_in_progress = FALSE;
1692 if (modal_timer != 0)
1694 API_CALL (KillTimer, (NULL, modal_timer));
1699 static VOID CALLBACK
1700 sync_timer_proc (HWND hwnd,
1706 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1711 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1713 KillTimer (hwnd, sync_timer);
1717 handle_display_change (void)
1719 _gdk_monitor_init ();
1720 _gdk_root_window_size_init ();
1721 g_signal_emit_by_name (_gdk_screen, "size_changed");
1725 generate_button_event (GdkEventType type,
1730 GdkEvent *event = gdk_event_new (type);
1732 event->button.window = window;
1733 event->button.time = _gdk_win32_get_next_tick (msg->time);
1734 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1735 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1736 event->button.x_root = msg->pt.x + _gdk_offset_x;
1737 event->button.y_root = msg->pt.y + _gdk_offset_y;
1738 event->button.axes = NULL;
1739 event->button.state = build_pointer_event_state (msg);
1740 event->button.button = button;
1741 gdk_event_set_device (event, _gdk_display->core_pointer);
1743 _gdk_win32_append_event (event);
1747 ensure_stacking_on_unminimize (MSG *msg)
1750 HWND lowest_transient = NULL;
1753 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1755 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1757 /* Checking window group not implemented yet */
1760 GdkWindowImplWin32 *rover_impl =
1761 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1763 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1764 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1765 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1766 rover_impl->transient_owner != NULL))
1768 lowest_transient = rover;
1772 if (lowest_transient != NULL)
1774 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1775 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1776 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1781 ensure_stacking_on_window_pos_changing (MSG *msg,
1784 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1785 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1787 if (GetActiveWindow () == msg->hwnd &&
1788 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1789 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1790 impl->transient_owner == NULL)
1792 /* Make sure the window stays behind any transient-type windows
1793 * of the same window group.
1795 * If the window is not active and being activated, we let
1796 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1797 * handling to bring any utility windows on top of it.
1800 gboolean restacking;
1802 rover = windowpos->hwndInsertAfter;
1806 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1808 /* Checking window group not implemented yet */
1811 GdkWindowImplWin32 *rover_impl =
1812 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1814 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1815 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1816 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1817 rover_impl->transient_owner != NULL))
1820 windowpos->hwndInsertAfter = rover;
1823 rover = GetNextWindow (rover, GW_HWNDNEXT);
1828 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1836 ensure_stacking_on_activate_app (MSG *msg,
1839 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1841 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1842 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1843 impl->transient_owner != NULL)
1845 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1846 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1850 if (IsWindowVisible (msg->hwnd) &&
1851 msg->hwnd == GetActiveWindow ())
1853 /* This window is not a transient-type window and it is the
1854 * activated window. Make sure this window is as visible as
1855 * possible, just below the lowest transient-type window of this
1861 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
1863 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1865 /* Checking window group not implemented yet */
1868 GdkWindowImplWin32 *rover_impl =
1869 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1871 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1872 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1873 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1874 rover_impl->transient_owner != NULL))
1876 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1877 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1878 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1886 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
1887 GDK_BUTTON2_MASK | \
1888 GDK_BUTTON3_MASK | \
1889 GDK_BUTTON4_MASK | \
1893 gdk_event_translate (MSG *msg,
1896 RECT rect, *drag, orig_drag;
1901 BYTE key_state[256];
1903 WINDOWPOS *windowpos;
1904 gboolean ignore_leave;
1911 GdkWindow *window = NULL;
1912 GdkWindowImplWin32 *impl;
1914 GdkWindow *orig_window, *new_window;
1916 GdkDeviceManager *device_manager;
1918 GdkDeviceGrabInfo *keyboard_grab = NULL;
1919 GdkDeviceGrabInfo *pointer_grab = NULL;
1920 GdkWindow *grab_window = NULL;
1926 gboolean return_val = FALSE;
1930 if (_gdk_default_filters)
1932 /* Apply global filters */
1934 GdkFilterReturn result = apply_event_filters (NULL, msg, &_gdk_default_filters);
1936 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1937 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1938 * we return TRUE, and DefWindowProcW() will not be called.
1940 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1944 window = gdk_win32_handle_table_lookup (msg->hwnd);
1945 orig_window = window;
1949 /* XXX Handle WM_QUIT here ? */
1950 if (msg->message == WM_QUIT)
1952 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1955 else if (msg->message == WM_CREATE)
1957 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1958 GDK_WINDOW_HWND (window) = msg->hwnd;
1962 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1967 device_manager = gdk_display_get_device_manager (_gdk_display);
1969 keyboard_grab = _gdk_display_get_last_device_grab (_gdk_display,
1970 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
1971 pointer_grab = _gdk_display_get_last_device_grab (_gdk_display,
1972 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer);
1974 g_object_ref (window);
1976 /* window's refcount has now been increased, so code below should
1977 * not just return from this function, but instead goto done (or
1978 * break out of the big switch). To protect against forgetting this,
1979 * #define return to a syntax error...
1981 #define return GOTO_DONE_INSTEAD
1983 if (!GDK_WINDOW_DESTROYED (window) && window->filters)
1985 /* Apply per-window filters */
1987 GdkFilterReturn result = apply_event_filters (window, msg, &window->filters);
1989 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1996 if (msg->message == client_message)
1999 GdkFilterReturn result = GDK_FILTER_CONTINUE;
2002 GDK_NOTE (EVENTS, g_print (" client_message"));
2004 event = gdk_event_new (GDK_NOTHING);
2005 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2007 node = _gdk_event_queue_append (_gdk_display, event);
2009 tmp_list = client_filters;
2012 GdkClientFilter *filter = tmp_list->data;
2014 tmp_list = tmp_list->next;
2016 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
2018 GDK_NOTE (EVENTS, g_print (" (match)"));
2020 result = (*filter->function) (msg, event, filter->data);
2022 if (result != GDK_FILTER_CONTINUE)
2029 case GDK_FILTER_REMOVE:
2030 _gdk_event_queue_remove_link (_gdk_display, node);
2031 g_list_free_1 (node);
2032 gdk_event_free (event);
2036 case GDK_FILTER_TRANSLATE:
2037 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2038 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2042 case GDK_FILTER_CONTINUE:
2043 /* No more: Send unknown client messages on to Gtk for it to use */
2044 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2050 switch (msg->message)
2052 case WM_INPUTLANGCHANGE:
2053 _gdk_input_locale = (HKL) msg->lParam;
2054 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
2055 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
2056 LOCALE_IDEFAULTANSICODEPAGE,
2058 _gdk_input_codepage = atoi (buf);
2059 _gdk_keymap_serial++;
2061 g_print (" cs:%lu hkl:%p%s cp:%d",
2062 (gulong) msg->wParam,
2063 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
2064 _gdk_input_codepage));
2070 g_print (" %s ch:%.02x %s",
2071 _gdk_win32_key_to_string (msg->lParam),
2073 decode_key_lparam (msg->lParam)));
2075 /* If posted without us having keyboard focus, ignore */
2076 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
2077 !(HIWORD (msg->lParam) & KF_ALTDOWN))
2080 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
2081 * the keyboard is grabbed.
2083 if (!keyboard_grab &&
2084 (msg->wParam == VK_TAB ||
2085 msg->wParam == VK_SPACE ||
2086 msg->wParam == VK_F4))
2089 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
2095 g_print (" %s ch:%.02x %s",
2096 _gdk_win32_key_to_string (msg->lParam),
2098 decode_key_lparam (msg->lParam)));
2102 /* Ignore key messages intended for the IME */
2103 if (msg->wParam == VK_PROCESSKEY ||
2107 if (keyboard_grab &&
2108 !propagate (&window, msg,
2109 keyboard_grab->window,
2110 keyboard_grab->owner_events,
2111 GDK_ALL_EVENTS_MASK,
2112 doesnt_want_key, FALSE))
2115 if (GDK_WINDOW_DESTROYED (window))
2118 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
2119 msg->message == WM_SYSKEYDOWN) ?
2120 GDK_KEY_PRESS : GDK_KEY_RELEASE);
2121 event->key.window = window;
2122 event->key.time = _gdk_win32_get_next_tick (msg->time);
2123 event->key.keyval = GDK_KEY_VoidSymbol;
2124 event->key.string = NULL;
2125 event->key.length = 0;
2126 event->key.hardware_keycode = msg->wParam;
2127 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2128 if (HIWORD (msg->lParam) & KF_EXTENDED)
2130 switch (msg->wParam)
2133 event->key.hardware_keycode = VK_RCONTROL;
2135 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
2136 * for the right shift key.
2138 event->key.hardware_keycode = VK_RSHIFT;
2141 event->key.hardware_keycode = VK_RMENU;
2145 else if (msg->wParam == VK_SHIFT &&
2146 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
2147 event->key.hardware_keycode = VK_RSHIFT;
2149 API_CALL (GetKeyboardState, (key_state));
2151 /* 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]); */
2153 build_key_event_state (event, key_state);
2155 if (msg->wParam == VK_PACKET &&
2156 ToUnicode (VK_PACKET, HIWORD (msg->lParam), key_state, wbuf, 1, 0) == 1)
2157 event->key.keyval = gdk_unicode_to_keyval (wbuf[0]);
2159 gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (_gdk_display),
2160 event->key.hardware_keycode,
2166 fill_key_event_string (event);
2168 /* Reset MOD1_MASK if it is the Alt key itself */
2169 if (msg->wParam == VK_MENU)
2170 event->key.state &= ~GDK_MOD1_MASK;
2172 _gdk_win32_append_event (event);
2178 if (msg->wParam != VK_SPACE)
2180 /* To prevent beeps, don't let DefWindowProcW() be called */
2186 case WM_IME_STARTCOMPOSITION:
2187 in_ime_composition = TRUE;
2190 case WM_IME_ENDCOMPOSITION:
2191 in_ime_composition = FALSE;
2194 case WM_IME_COMPOSITION:
2195 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2196 * applications. Thus, handle WM_IME_COMPOSITION with
2197 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2198 * with ImmGetCompositionStringW().
2201 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2203 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2204 * for comments by other people that seems to have the same
2205 * experience. WM_IME_CHAR just gives question marks, apparently
2206 * because of going through some conversion to the current code
2209 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2210 * use WM_IME_COMPOSITION there, too, to simplify the code.
2212 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2214 if (!(msg->lParam & GCS_RESULTSTR))
2217 if (keyboard_grab &&
2218 !propagate (&window, msg,
2219 keyboard_grab->window,
2220 keyboard_grab->owner_events,
2221 GDK_ALL_EVENTS_MASK,
2222 doesnt_want_char, FALSE))
2225 if (GDK_WINDOW_DESTROYED (window))
2228 himc = ImmGetContext (msg->hwnd);
2229 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2230 wbuf, sizeof (wbuf));
2231 ImmReleaseContext (msg->hwnd, himc);
2235 API_CALL (GetKeyboardState, (key_state));
2237 for (i = 0; i < ccount; i++)
2239 if (window->event_mask & GDK_KEY_PRESS_MASK)
2241 /* Build a key press event */
2242 event = gdk_event_new (GDK_KEY_PRESS);
2243 event->key.window = window;
2244 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2245 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2247 _gdk_win32_append_event (event);
2250 if (window->event_mask & GDK_KEY_RELEASE_MASK)
2252 /* Build a key release event. */
2253 event = gdk_event_new (GDK_KEY_RELEASE);
2254 event->key.window = window;
2255 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2256 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2258 _gdk_win32_append_event (event);
2264 case WM_LBUTTONDOWN:
2268 case WM_MBUTTONDOWN:
2272 case WM_RBUTTONDOWN:
2276 case WM_XBUTTONDOWN:
2277 if (HIWORD (msg->wParam) == XBUTTON1)
2284 g_print (" (%d,%d)",
2285 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2287 assign_object (&window, find_window_for_mouse_event (window, msg));
2288 /* TODO_CSW?: there used to some synthesize and propagate */
2289 if (GDK_WINDOW_DESTROYED (window))
2292 if (pointer_grab == NULL)
2294 SetCapture (GDK_WINDOW_HWND (window));
2297 generate_button_event (GDK_BUTTON_PRESS, button,
2316 if (HIWORD (msg->wParam) == XBUTTON1)
2323 g_print (" (%d,%d)",
2324 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2326 assign_object (&window, find_window_for_mouse_event (window, msg));
2328 if (window->extension_events != 0 &&
2329 _gdk_input_ignore_core)
2331 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2336 if (pointer_grab != NULL && pointer_grab->implicit)
2338 gint state = build_pointer_event_state (msg);
2340 /* We keep the implicit grab until no buttons at all are held down */
2341 if ((state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (button - 1))) == 0)
2346 hwnd = WindowFromPoint (msg->pt);
2349 POINT client_pt = msg->pt;
2351 ScreenToClient (hwnd, &client_pt);
2352 GetClientRect (hwnd, &rect);
2353 if (PtInRect (&rect, client_pt))
2354 new_window = gdk_win32_handle_table_lookup (hwnd);
2356 synthesize_crossing_events (_gdk_display,
2357 pointer_grab->native_window, new_window,
2358 GDK_CROSSING_UNGRAB,
2360 0, /* TODO: Set right mask */
2363 assign_object (&mouse_window, new_window);
2364 mouse_window_ignored_leave = NULL;
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 mouse_window_ignored_leave = NULL;
2419 if (new_window != NULL)
2420 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (new_window));
2422 else if (new_window != NULL &&
2423 new_window == mouse_window_ignored_leave)
2425 /* If we ignored a leave event for this window and we're now getting
2426 input again we need to re-arm the mouse tracking, as that was
2427 cancelled by the mouseleave. */
2428 mouse_window_ignored_leave = NULL;
2429 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (new_window));
2432 assign_object (&window, find_window_for_mouse_event (window, msg));
2434 /* If we haven't moved, don't create any GDK event. Windows
2435 * sends WM_MOUSEMOVE messages after a new window is shows under
2436 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2438 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2439 msg->pt.y + _gdk_offset_y == current_root_y)
2442 current_root_x = msg->pt.x + _gdk_offset_x;
2443 current_root_y = msg->pt.y + _gdk_offset_y;
2445 event = gdk_event_new (GDK_MOTION_NOTIFY);
2446 event->motion.window = window;
2447 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2448 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2449 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2450 event->motion.x_root = current_root_x;
2451 event->motion.y_root = current_root_y;
2452 event->motion.axes = NULL;
2453 event->motion.state = build_pointer_event_state (msg);
2454 event->motion.is_hint = FALSE;
2455 gdk_event_set_device (event, _gdk_display->core_pointer);
2457 _gdk_win32_append_event (event);
2462 case WM_NCMOUSEMOVE:
2464 g_print (" (%d,%d)",
2465 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2469 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2470 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2473 hwnd = WindowFromPoint (msg->pt);
2474 ignore_leave = FALSE;
2479 POINT client_pt = msg->pt;
2481 /* The synapitics trackpad drivers have this irritating
2482 feature where it pops up a window right under the pointer
2483 when you scroll. We ignore the leave and enter events for
2485 if (GetClassNameA (hwnd, classname, sizeof(classname)) &&
2486 strcmp (classname, SYNAPSIS_ICON_WINDOW_CLASS) == 0)
2487 ignore_leave = TRUE;
2489 ScreenToClient (hwnd, &client_pt);
2490 GetClientRect (hwnd, &rect);
2491 if (PtInRect (&rect, client_pt))
2492 new_window = gdk_win32_handle_table_lookup (hwnd);
2496 synthesize_crossing_events (_gdk_display,
2497 mouse_window, new_window,
2498 GDK_CROSSING_NORMAL,
2500 0, /* TODO: Set right mask */
2503 assign_object (&mouse_window, new_window);
2504 mouse_window_ignored_leave = ignore_leave ? new_window : NULL;
2511 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2513 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2514 * that. Also, the position is in screen coordinates, not client
2515 * coordinates as with the button messages. I love the
2516 * consistency of Windows.
2518 point.x = GET_X_LPARAM (msg->lParam);
2519 point.y = GET_Y_LPARAM (msg->lParam);
2521 if ((hwnd = WindowFromPoint (point)) == NULL)
2527 /* The synapitics trackpad drivers have this irritating
2528 feature where it pops up a window right under the pointer
2529 when you scroll. We backtrack and to the toplevel and
2530 find the innermost child instead. */
2531 if (GetClassNameA (hwnd, classname, sizeof(classname)) &&
2532 strcmp (classname, SYNAPSIS_ICON_WINDOW_CLASS) == 0)
2536 /* Find our toplevel window */
2537 hwnd = GetAncestor (msg->hwnd, GA_ROOT);
2539 /* Walk back up to the outermost child at the desired point */
2541 ScreenToClient (hwnd, &point);
2542 hwndc = ChildWindowFromPoint (hwnd, point);
2543 ClientToScreen (hwnd, &point);
2544 } while (hwndc != hwnd && (hwnd = hwndc, 1));
2549 if ((new_window = gdk_win32_handle_table_lookup (msg->hwnd)) == NULL)
2552 if (new_window != window)
2554 assign_object (&window, new_window);
2557 ScreenToClient (msg->hwnd, &point);
2559 event = gdk_event_new (GDK_SCROLL);
2560 event->scroll.window = window;
2561 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2562 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2563 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2564 event->scroll.x = (gint16) point.x;
2565 event->scroll.y = (gint16) point.y;
2566 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2567 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2568 event->scroll.state = build_pointer_event_state (msg);
2569 gdk_event_set_device (event, _gdk_display->core_pointer);
2571 _gdk_win32_append_event (event);
2577 /* Just print more debugging information, don't actually handle it. */
2580 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2581 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2582 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2583 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2584 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2585 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2586 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2587 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2588 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2590 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2591 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2592 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2596 /* Just print more debugging information, don't actually handle it. */
2599 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2600 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2601 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2602 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2603 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2604 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2605 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2606 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2607 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2609 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2610 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2611 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2614 case WM_MOUSEACTIVATE:
2618 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2619 || !window->accept_focus)
2621 *ret_valp = MA_NOACTIVATE;
2625 if (_gdk_modal_blocked (gdk_window_get_toplevel (window)))
2627 *ret_valp = MA_NOACTIVATEANDEAT;
2635 if (keyboard_grab != NULL &&
2636 !GDK_WINDOW_DESTROYED (keyboard_grab->window))
2638 generate_grab_broken_event (device_manager, keyboard_grab->window, TRUE, NULL);
2643 if (keyboard_grab != NULL &&
2644 !keyboard_grab->owner_events)
2647 if (!(window->event_mask & GDK_FOCUS_CHANGE_MASK))
2650 if (GDK_WINDOW_DESTROYED (window))
2653 generate_focus_event (device_manager, window, (msg->message == WM_SETFOCUS));
2658 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2660 if (GDK_WINDOW_DESTROYED (window))
2668 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2670 200, sync_timer_proc);
2674 handle_wm_paint (msg, window, FALSE, NULL);
2678 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2679 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2681 if (pointer_grab != NULL)
2682 grab_window = pointer_grab->window;
2684 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2687 if (grab_window != NULL && p_grab_cursor != NULL)
2688 hcursor = p_grab_cursor;
2689 else if (!GDK_WINDOW_DESTROYED (window))
2690 hcursor = GDK_WINDOW_IMPL_WIN32 (window->impl)->hcursor;
2694 if (hcursor != NULL)
2696 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2697 SetCursor (hcursor);
2704 switch (msg->wParam)
2708 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2714 case WM_ENTERSIZEMOVE:
2715 case WM_ENTERMENULOOP:
2716 if (msg->message == WM_ENTERSIZEMOVE)
2717 _modal_move_resize_window = msg->hwnd;
2719 _gdk_win32_begin_modal_call ();
2722 case WM_EXITSIZEMOVE:
2723 case WM_EXITMENULOOP:
2724 if (_modal_operation_in_progress)
2726 _modal_move_resize_window = NULL;
2727 _gdk_win32_end_modal_call ();
2731 case WM_CAPTURECHANGED:
2732 /* Sometimes we don't get WM_EXITSIZEMOVE, for instance when you
2733 select move/size in the menu and then click somewhere without
2734 moving/resizing. We work around this using WM_CAPTURECHANGED. */
2735 if (_modal_operation_in_progress)
2737 _modal_move_resize_window = NULL;
2738 _gdk_win32_end_modal_call ();
2742 case WM_WINDOWPOSCHANGING:
2743 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2744 g_print (" %s %s %dx%d@%+d%+d now below %p",
2745 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2746 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2747 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2748 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2749 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2750 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2752 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2753 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2755 if (GDK_WINDOW_IS_MAPPED (window))
2756 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2759 case WM_WINDOWPOSCHANGED:
2760 windowpos = (WINDOWPOS *) msg->lParam;
2761 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2762 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2763 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2764 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2765 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2766 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2767 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2769 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2771 /* Break grabs on unmap or minimize */
2772 if (windowpos->flags & SWP_HIDEWINDOW ||
2773 ((windowpos->flags & SWP_STATECHANGED) && IsIconic (msg->hwnd)))
2775 if (pointer_grab != NULL)
2777 if (pointer_grab->window == window)
2778 gdk_pointer_ungrab (msg->time);
2781 if (keyboard_grab->window == window)
2782 gdk_keyboard_ungrab (msg->time);
2785 /* Send MAP events */
2786 if ((windowpos->flags & SWP_SHOWWINDOW) &&
2787 !GDK_WINDOW_DESTROYED (window))
2789 event = gdk_event_new (GDK_MAP);
2790 event->any.window = window;
2791 _gdk_win32_append_event (event);
2794 /* Update window state */
2795 if (windowpos->flags & (SWP_STATECHANGED | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
2797 GdkWindowState set_bits, unset_bits, old_state, new_state;
2799 old_state = window->state;
2804 if (IsWindowVisible (msg->hwnd))
2805 unset_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2807 set_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2809 if (IsIconic (msg->hwnd))
2810 set_bits |= GDK_WINDOW_STATE_ICONIFIED;
2812 unset_bits |= GDK_WINDOW_STATE_ICONIFIED;
2814 if (IsZoomed (msg->hwnd))
2815 set_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2817 unset_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2819 gdk_synthesize_window_state (window, unset_bits, set_bits);
2821 new_state = window->state;
2823 /* Whenever one window changes iconified state we need to also
2824 * change the iconified state in all transient related windows,
2825 * as windows doesn't give icons for transient childrens.
2827 if ((old_state & GDK_WINDOW_STATE_ICONIFIED) !=
2828 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2829 do_show_window (window, (new_state & GDK_WINDOW_STATE_ICONIFIED));
2832 /* When un-minimizing, make sure we're stacked under any
2833 transient-type windows. */
2834 if (!(old_state & GDK_WINDOW_STATE_ICONIFIED) &&
2835 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2836 ensure_stacking_on_unminimize (msg);
2839 /* Show, New size or position => configure event */
2840 if (!(windowpos->flags & SWP_NOCLIENTMOVE) ||
2841 !(windowpos->flags & SWP_NOCLIENTSIZE) ||
2842 (windowpos->flags & SWP_SHOWWINDOW))
2844 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2845 !IsIconic (msg->hwnd) &&
2846 !GDK_WINDOW_DESTROYED (window))
2847 _gdk_win32_emit_configure_event (window);
2849 if (window->extension_events != 0)
2850 _gdk_device_wintab_update_window_coords (window);
2853 if ((windowpos->flags & SWP_HIDEWINDOW) &&
2854 !GDK_WINDOW_DESTROYED (window))
2856 /* Send UNMAP events */
2857 event = gdk_event_new (GDK_UNMAP);
2858 event->any.window = window;
2859 _gdk_win32_append_event (event);
2861 /* Make transient parent the forground window when window unmaps */
2862 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2864 if (impl->transient_owner &&
2865 GetForegroundWindow () == GDK_WINDOW_HWND (window))
2866 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2869 if (!(windowpos->flags & SWP_NOCLIENTSIZE))
2871 if (window->resize_count > 1)
2872 window->resize_count -= 1;
2875 /* Call modal timer immediate so that we repaint faster after a resize. */
2876 if (_modal_operation_in_progress)
2877 modal_timer_proc (0,0,0,0);
2879 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2885 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2886 drag = (RECT *) msg->lParam;
2887 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2888 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2889 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2890 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2891 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2892 (msg->wParam == WMSZ_TOP ? "TOP" :
2893 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2894 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2896 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2898 _gdk_win32_rect_to_string (&rect),
2899 _gdk_win32_rect_to_string (drag)));
2901 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2903 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2905 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2906 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2908 /* Resize in increments relative to the base size */
2909 rect.left = rect.top = 0;
2910 rect.right = impl->hints.base_width;
2911 rect.bottom = impl->hints.base_height;
2912 _gdk_win32_adjust_client_rect (window, &rect);
2913 point.x = rect.left;
2915 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2916 rect.left = point.x;
2918 point.x = rect.right;
2919 point.y = rect.bottom;
2920 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2921 rect.right = point.x;
2922 rect.bottom = point.y;
2924 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2925 _gdk_win32_rect_to_string (&rect)));
2928 switch (msg->wParam)
2931 if (drag->bottom == rect.bottom)
2933 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2936 case WMSZ_BOTTOMLEFT:
2937 if (drag->bottom == rect.bottom && drag->left == rect.left)
2939 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2940 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2944 if (drag->left == rect.left)
2946 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2950 if (drag->top == rect.top && drag->left == rect.left)
2952 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2953 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2957 if (drag->top == rect.top)
2959 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2963 if (drag->top == rect.top && drag->right == rect.right)
2965 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2966 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2970 if (drag->right == rect.right)
2972 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2975 case WMSZ_BOTTOMRIGHT:
2976 if (drag->bottom == rect.bottom && drag->right == rect.right)
2978 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2979 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2983 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2984 drag->top != orig_drag.top || drag->right != orig_drag.right)
2988 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2989 _gdk_win32_rect_to_string (drag)));
2993 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2995 if (impl->hint_flags & GDK_HINT_ASPECT)
2997 RECT decorated_rect;
2998 RECT undecorated_drag;
2999 int decoration_width, decoration_height;
3000 gdouble drag_aspect;
3001 int drag_width, drag_height, new_width, new_height;
3003 GetClientRect (GDK_WINDOW_HWND (window), &rect);
3004 decorated_rect = rect;
3005 _gdk_win32_adjust_client_rect (window, &decorated_rect);
3007 /* Set undecorated_drag to the client area being dragged
3008 * out, in screen coordinates.
3010 undecorated_drag = *drag;
3011 undecorated_drag.left -= decorated_rect.left - rect.left;
3012 undecorated_drag.right -= decorated_rect.right - rect.right;
3013 undecorated_drag.top -= decorated_rect.top - rect.top;
3014 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
3016 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
3017 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
3019 drag_width = undecorated_drag.right - undecorated_drag.left;
3020 drag_height = undecorated_drag.bottom - undecorated_drag.top;
3022 drag_aspect = (gdouble) drag_width / drag_height;
3024 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
3025 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
3027 if (drag_aspect < impl->hints.min_aspect)
3029 /* Aspect is getting too narrow */
3030 switch (msg->wParam)
3034 /* User drags top or bottom edge outward. Keep height, increase width. */
3035 new_width = impl->hints.min_aspect * drag_height;
3036 drag->left -= (new_width - drag_width) / 2;
3037 drag->right = drag->left + new_width + decoration_width;
3039 case WMSZ_BOTTOMLEFT:
3040 case WMSZ_BOTTOMRIGHT:
3041 /* User drags bottom-left or bottom-right corner down. Adjust height. */
3042 new_height = drag_width / impl->hints.min_aspect;
3043 drag->bottom = drag->top + new_height + decoration_height;
3047 /* User drags left or right edge inward. Decrease height */
3048 new_height = drag_width / impl->hints.min_aspect;
3049 drag->top += (drag_height - new_height) / 2;
3050 drag->bottom = drag->top + new_height + decoration_height;
3054 /* User drags top-left or top-right corner up. Adjust height. */
3055 new_height = drag_width / impl->hints.min_aspect;
3056 drag->top = drag->bottom - new_height - decoration_height;
3059 else if (drag_aspect > impl->hints.max_aspect)
3061 /* Aspect is getting too wide */
3062 switch (msg->wParam)
3066 /* User drags top or bottom edge inward. Decrease width. */
3067 new_width = impl->hints.max_aspect * drag_height;
3068 drag->left += (drag_width - new_width) / 2;
3069 drag->right = drag->left + new_width + decoration_width;
3071 case WMSZ_BOTTOMLEFT:
3073 /* User drags bottom-left or top-left corner left. Adjust width. */
3074 new_width = impl->hints.max_aspect * drag_height;
3075 drag->left = drag->right - new_width - decoration_width;
3077 case WMSZ_BOTTOMRIGHT:
3079 /* User drags bottom-right or top-right corner right. Adjust width. */
3080 new_width = impl->hints.max_aspect * drag_height;
3081 drag->right = drag->left + new_width + decoration_width;
3085 /* User drags left or right edge outward. Increase height. */
3086 new_height = drag_width / impl->hints.max_aspect;
3087 drag->top -= (new_height - drag_height) / 2;
3088 drag->bottom = drag->top + new_height + decoration_height;
3095 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
3096 _gdk_win32_rect_to_string (drag)));
3100 case WM_GETMINMAXINFO:
3101 if (GDK_WINDOW_DESTROYED (window))
3104 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3105 mmi = (MINMAXINFO*) msg->lParam;
3106 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
3107 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3108 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3109 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3110 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3111 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3113 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
3115 rect.left = rect.top = 0;
3116 rect.right = impl->hints.min_width;
3117 rect.bottom = impl->hints.min_height;
3119 _gdk_win32_adjust_client_rect (window, &rect);
3121 mmi->ptMinTrackSize.x = rect.right - rect.left;
3122 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
3125 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
3129 rect.left = rect.top = 0;
3130 rect.right = impl->hints.max_width;
3131 rect.bottom = impl->hints.max_height;
3133 _gdk_win32_adjust_client_rect (window, &rect);
3135 /* at least on win9x we have the 16 bit trouble */
3136 maxw = rect.right - rect.left;
3137 maxh = rect.bottom - rect.top;
3138 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
3139 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
3142 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
3144 /* Don't call DefWindowProcW() */
3145 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
3146 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3147 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3148 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3149 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3150 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3153 mmi->ptMaxTrackSize.x = 30000;
3154 mmi->ptMaxTrackSize.y = 30000;
3159 if (GDK_WINDOW_DESTROYED (window))
3162 event = gdk_event_new (GDK_DELETE);
3163 event->any.window = window;
3165 _gdk_win32_append_event (event);
3167 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3169 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
3171 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3178 if (pointer_grab != NULL)
3180 if (pointer_grab->window == window)
3181 gdk_pointer_ungrab (msg->time);
3184 if (keyboard_grab &&
3185 keyboard_grab->window == window)
3186 gdk_keyboard_ungrab (msg->time);
3188 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
3189 gdk_window_destroy_notify (window);
3191 if (window == NULL || GDK_WINDOW_DESTROYED (window))
3194 event = gdk_event_new (GDK_DESTROY);
3195 event->any.window = window;
3197 _gdk_win32_append_event (event);
3202 case WM_DISPLAYCHANGE:
3203 handle_display_change ();
3206 case WM_DESTROYCLIPBOARD:
3207 if (!_ignore_destroy_clipboard)
3209 event = gdk_event_new (GDK_SELECTION_CLEAR);
3210 event->selection.window = window;
3211 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3212 event->selection.time = _gdk_win32_get_next_tick (msg->time);
3213 _gdk_win32_append_event (event);
3222 case WM_RENDERFORMAT:
3223 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
3225 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
3227 GDK_NOTE (EVENTS, g_print (" (target not found)"));
3232 /* We need to render to clipboard immediately, don't call
3233 * _gdk_win32_append_event()
3235 event = gdk_event_new (GDK_SELECTION_REQUEST);
3236 event->selection.window = window;
3237 event->selection.send_event = FALSE;
3238 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3239 event->selection.target = target;
3240 event->selection.property = _gdk_selection;
3241 event->selection.requestor = gdk_win32_handle_table_lookup (msg->hwnd);
3242 event->selection.time = msg->time;
3244 fixup_event (event);
3245 GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)"));
3246 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
3247 _gdk_event_emit (event);
3248 gdk_event_free (event);
3250 /* Now the clipboard owner should have rendered */
3251 if (!_delayed_rendering_data)
3253 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3257 if (msg->wParam == CF_DIB)
3259 _delayed_rendering_data =
3260 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3262 if (!_delayed_rendering_data)
3264 g_warning ("Cannot convert to DIB from delayed rendered image");
3269 /* The requestor is holding the clipboard, no
3270 * OpenClipboard() is required/possible
3273 g_print (" SetClipboardData(%s,%p)",
3274 _gdk_win32_cf_to_string (msg->wParam),
3275 _delayed_rendering_data));
3277 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3278 _delayed_rendering_data = NULL;
3283 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3284 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3285 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3286 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3287 HIWORD (msg->wParam) ? " minimized" : "",
3288 (HWND) msg->lParam));
3289 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3290 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3293 if (_gdk_modal_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3295 GdkWindow *modal_current = _gdk_modal_current ();
3296 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3302 /* Bring any tablet contexts to the top of the overlap order when
3303 * one of our windows is activated.
3304 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3307 if (LOWORD(msg->wParam) != WA_INACTIVE)
3308 _gdk_input_set_tablet_active ();
3311 case WM_ACTIVATEAPP:
3312 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3313 msg->wParam ? "YES" : "NO",
3314 (gint64) msg->lParam));
3315 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3316 ensure_stacking_on_activate_app (msg, window);
3319 /* Handle WINTAB events here, as we know that gdkinput.c will
3320 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3321 * constants as case labels.
3324 GDK_NOTE (EVENTS, g_print (" %d %p",
3325 (int) msg->wParam, (gpointer) msg->lParam));
3329 GDK_NOTE (EVENTS, g_print (" %d %p",
3330 (int) msg->wParam, (gpointer) msg->lParam));
3334 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3335 (gpointer) msg->wParam,
3336 LOWORD (msg->lParam),
3337 HIWORD (msg->lParam)));
3341 event = gdk_event_new (GDK_NOTHING);
3342 event->any.window = window;
3343 g_object_ref (window);
3345 if (_gdk_input_other_event (event, msg, window))
3346 _gdk_win32_append_event (event);
3348 gdk_event_free (event);
3356 g_object_unref (window);
3363 _gdk_win32_display_queue_events (GdkDisplay *display)
3367 if (modal_win32_dialog != NULL)
3370 while (!_gdk_event_queue_find_first (display) &&
3371 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3373 TranslateMessage (&msg);
3374 DispatchMessageW (&msg);
3379 gdk_event_prepare (GSource *source,
3384 GDK_THREADS_ENTER ();
3388 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3389 (modal_win32_dialog == NULL &&
3390 GetQueueStatus (QS_ALLINPUT) != 0));
3392 GDK_THREADS_LEAVE ();
3398 gdk_event_check (GSource *source)
3402 GDK_THREADS_ENTER ();
3404 if (event_poll_fd.revents & G_IO_IN)
3406 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3407 (modal_win32_dialog == NULL &&
3408 GetQueueStatus (QS_ALLINPUT) != 0));
3415 GDK_THREADS_LEAVE ();
3421 gdk_event_dispatch (GSource *source,
3422 GSourceFunc callback,
3427 GDK_THREADS_ENTER ();
3429 _gdk_win32_display_queue_events (_gdk_display);
3430 event = _gdk_event_unqueue (_gdk_display);
3434 _gdk_event_emit (event);
3436 gdk_event_free (event);
3438 /* Do drag & drop if it is still pending */
3439 if (_dnd_source_state == GDK_WIN32_DND_PENDING)
3441 _dnd_source_state = GDK_WIN32_DND_DRAGGING;
3442 _gdk_win32_dnd_do_dragdrop ();
3443 _dnd_source_state = GDK_WIN32_DND_NONE;
3447 GDK_THREADS_LEAVE ();
3453 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3455 modal_win32_dialog = window;