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"
51 #include "gdkkeysyms.h"
52 #include "gdkdevicemanager-win32.h"
53 #include "gdkdeviceprivate.h"
54 #include "gdkdevice-wintab.h"
56 #include "gdkwin32dnd.h"
57 #include "gdkdndprivate.h"
81 #define MK_XBUTTON1 32
82 #define MK_XBUTTON2 64
86 * Private function declarations
89 static gboolean gdk_event_translate (MSG *msg,
91 static void handle_wm_paint (MSG *msg,
93 gboolean return_exposes,
96 static gboolean gdk_event_prepare (GSource *source,
98 static gboolean gdk_event_check (GSource *source);
99 static gboolean gdk_event_dispatch (GSource *source,
100 GSourceFunc callback,
103 static void append_event (GdkEvent *event);
104 static gboolean is_modally_blocked (GdkWindow *window);
106 /* Private variable declarations
109 static GList *client_filters; /* Filters for client messages */
110 extern gint _gdk_input_ignore_core;
112 static HCURSOR p_grab_cursor;
114 static GSourceFuncs event_funcs = {
121 GPollFD event_poll_fd;
123 static GdkWindow *current_toplevel = NULL;
124 static gint current_x, current_y;
125 static gint current_root_x, current_root_y;
126 static UINT client_message;
128 static UINT got_gdk_events_message;
129 static HWND modal_win32_dialog = NULL;
132 static HKL latin_locale = NULL;
135 static gboolean in_ime_composition = FALSE;
136 static UINT modal_timer;
137 static UINT sync_timer = 0;
139 static int debug_indent = 0;
142 assign_object (gpointer lhsp,
145 if (*(gpointer *)lhsp != rhs)
147 if (*(gpointer *)lhsp != NULL)
148 g_object_unref (*(gpointer *)lhsp);
149 *(gpointer *)lhsp = rhs;
156 track_mouse_event (DWORD dwFlags,
161 tme.cbSize = sizeof(TRACKMOUSEEVENT);
162 tme.dwFlags = dwFlags;
163 tme.hwndTrack = hwnd;
164 tme.dwHoverTime = HOVER_DEFAULT; /* not used */
166 if (!TrackMouseEvent (&tme))
167 WIN32_API_FAILED ("TrackMouseEvent");
168 else if (dwFlags == TME_LEAVE)
169 GDK_NOTE (EVENTS, g_print(" (TrackMouseEvent %p)", hwnd));
170 else if (dwFlags == TME_CANCEL)
171 GDK_NOTE (EVENTS, g_print(" (cancel TrackMouseEvent %p)", hwnd));
175 _gdk_win32_get_next_tick (gulong suggested_tick)
177 static gulong cur_tick = 0;
179 if (suggested_tick == 0)
180 suggested_tick = GetTickCount ();
181 if (suggested_tick <= cur_tick)
184 return cur_tick = suggested_tick;
188 generate_focus_event (GdkDeviceManager *device_manager,
195 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
197 event = gdk_event_new (GDK_FOCUS_CHANGE);
198 event->focus_change.window = window;
199 event->focus_change.in = in;
200 gdk_event_set_device (event, device);
202 append_event (event);
206 generate_grab_broken_event (GdkDeviceManager *device_manager,
209 GdkWindow *grab_window)
211 GdkEvent *event = gdk_event_new (GDK_GRAB_BROKEN);
215 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
217 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer;
219 event->grab_broken.window = window;
220 event->grab_broken.send_event = 0;
221 event->grab_broken.keyboard = keyboard;
222 event->grab_broken.implicit = FALSE;
223 event->grab_broken.grab_window = grab_window;
224 gdk_event_set_device (event, device);
226 append_event (event);
230 inner_window_procedure (HWND hwnd,
240 msg.message = message;
243 msg.time = _gdk_win32_get_next_tick (0);
244 pos = GetMessagePos ();
245 msg.pt.x = GET_X_LPARAM (pos);
246 msg.pt.y = GET_Y_LPARAM (pos);
248 if (gdk_event_translate (&msg, &ret_val))
250 /* If gdk_event_translate() returns TRUE, we return ret_val from
251 * the window procedure.
253 if (modal_win32_dialog)
254 PostMessageW (modal_win32_dialog, got_gdk_events_message,
260 /* Otherwise call DefWindowProcW(). */
261 GDK_NOTE (EVENTS, g_print (" DefWindowProcW"));
262 return DefWindowProcW (hwnd, message, wparam, lparam);
267 _gdk_win32_window_procedure (HWND hwnd,
274 GDK_NOTE (EVENTS, g_print ("%s%*s%s %p",
275 (debug_indent > 0 ? "\n" : ""),
277 _gdk_win32_message_to_string (message), hwnd));
279 retval = inner_window_procedure (hwnd, message, wparam, lparam);
282 GDK_NOTE (EVENTS, g_print (" => %I64d%s", (gint64) retval, (debug_indent == 0 ? "\n" : "")));
288 _gdk_events_init (void)
295 /* List of languages that use a latin keyboard. Somewhat sorted in
296 * "order of least surprise", in case we have to load one of them if
297 * the user only has arabic loaded, for instance.
299 static int latin_languages[] = {
305 /* Rest in numeric order */
334 client_message = RegisterWindowMessage ("GDK_WIN32_CLIENT_MESSAGE");
335 got_gdk_events_message = RegisterWindowMessage ("GDK_WIN32_GOT_EVENTS");
338 /* Check if we have some input locale identifier loaded that uses a
339 * latin keyboard, to be able to get the virtual-key code for the
340 * latin characters corresponding to ASCII control characters.
342 if ((n = GetKeyboardLayoutList (0, NULL)) == 0)
343 WIN32_API_FAILED ("GetKeyboardLayoutList");
346 HKL *hkl_list = g_new (HKL, n);
347 if (GetKeyboardLayoutList (n, hkl_list) == 0)
348 WIN32_API_FAILED ("GetKeyboardLayoutList");
351 for (i = 0; latin_locale == NULL && i < n; i++)
352 for (j = 0; j < G_N_ELEMENTS (latin_languages); j++)
353 if (PRIMARYLANGID (LOWORD (hkl_list[i])) == latin_languages[j])
355 latin_locale = hkl_list [i];
362 if (latin_locale == NULL)
364 /* Try to load a keyboard layout with latin characters then.
367 while (latin_locale == NULL && i < G_N_ELEMENTS (latin_languages))
370 g_sprintf (id, "%08x", MAKELANGID (latin_languages[i++], SUBLANG_DEFAULT));
371 latin_locale = LoadKeyboardLayout (id, KLF_NOTELLSHELL|KLF_SUBSTITUTE_OK);
375 GDK_NOTE (EVENTS, g_print ("latin_locale = %08x\n", (guint) latin_locale));
378 source = g_source_new (&event_funcs, sizeof (GSource));
379 g_source_set_name (source, "GDK Win32 event source");
380 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
383 event_poll_fd.fd = open ("/dev/windows", O_RDONLY);
384 if (event_poll_fd.fd == -1)
385 g_error ("can't open \"/dev/windows\": %s", g_strerror (errno));
387 event_poll_fd.fd = G_WIN32_MSG_HANDLE;
389 event_poll_fd.events = G_IO_IN;
391 g_source_add_poll (source, &event_poll_fd);
392 g_source_set_can_recurse (source, TRUE);
393 g_source_attach (source, NULL);
397 _gdk_win32_display_has_pending (GdkDisplay *display)
400 return (_gdk_event_queue_find_first (display) ||
401 (modal_win32_dialog == NULL &&
402 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
405 #if 0 /* Unused, but might be useful to re-introduce in some debugging output? */
408 event_mask_string (GdkEventMask mask)
410 static char bfr[500];
415 if (mask & GDK_##x##_MASK) \
416 p += g_sprintf (p, "%s" #x, (p > bfr ? " " : ""))
418 BIT (POINTER_MOTION);
419 BIT (POINTER_MOTION_HINT);
421 BIT (BUTTON1_MOTION);
422 BIT (BUTTON2_MOTION);
423 BIT (BUTTON3_MOTION);
425 BIT (BUTTON_RELEASE);
432 BIT (PROPERTY_CHANGE);
433 BIT (VISIBILITY_NOTIFY);
446 _gdk_windowing_device_grab (GdkDevice *device,
448 GdkWindow *native_window,
449 gboolean owner_events,
450 GdkEventMask event_mask,
451 GdkWindow *confine_to,
456 GdkWin32Cursor *cursor_private;
458 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (native_window->impl);
460 g_return_val_if_fail (window != NULL, 0);
461 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
462 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
464 cursor_private = (GdkWin32Cursor*) cursor;
468 else if ((hcursor = CopyCursor (cursor_private->hcursor)) == NULL)
469 WIN32_API_FAILED ("CopyCursor");
471 return_val = GDK_DEVICE_GET_CLASS (device)->grab (device,
479 /* TODO_CSW: grab brokens, confine window, input_grab */
480 if (p_grab_cursor != NULL)
482 if (GetCursor () == p_grab_cursor)
484 DestroyCursor (p_grab_cursor);
487 p_grab_cursor = hcursor;
489 if (p_grab_cursor != NULL)
490 SetCursor (p_grab_cursor);
491 else if (impl->hcursor != NULL)
492 SetCursor (impl->hcursor);
494 SetCursor (LoadCursor (NULL, IDC_ARROW));
500 find_window_for_mouse_event (GdkWindow* reported_window,
506 GdkWindow* other_window = NULL;
507 GdkDeviceManagerWin32 *device_manager;
509 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (_gdk_display));
511 if (!_gdk_display_get_last_device_grab (_gdk_display, device_manager->core_pointer))
512 return reported_window;
514 points = MAKEPOINTS (msg->lParam);
517 ClientToScreen (msg->hwnd, &pt);
519 hwnd = WindowFromPoint (pt);
525 GetClientRect (hwnd, &rect);
526 ScreenToClient (hwnd, &pt);
527 if (!PtInRect (&rect, pt))
530 other_window = gdk_win32_handle_table_lookup (hwnd);
533 if (other_window == NULL)
536 /* need to also adjust the coordinates to the new window */
539 ClientToScreen (msg->hwnd, &pt);
540 ScreenToClient (GDK_WINDOW_HWND (other_window), &pt);
541 /* ATTENTION: need to update client coords */
542 msg->lParam = MAKELPARAM (pt.x, pt.y);
548 build_key_event_state (GdkEvent *event,
551 event->key.state = 0;
553 if (key_state[VK_SHIFT] & 0x80)
554 event->key.state |= GDK_SHIFT_MASK;
556 if (key_state[VK_CAPITAL] & 0x01)
557 event->key.state |= GDK_LOCK_MASK;
559 if (key_state[VK_LBUTTON] & 0x80)
560 event->key.state |= GDK_BUTTON1_MASK;
561 if (key_state[VK_MBUTTON] & 0x80)
562 event->key.state |= GDK_BUTTON2_MASK;
563 if (key_state[VK_RBUTTON] & 0x80)
564 event->key.state |= GDK_BUTTON3_MASK;
565 if (key_state[VK_XBUTTON1] & 0x80)
566 event->key.state |= GDK_BUTTON4_MASK;
567 if (key_state[VK_XBUTTON2] & 0x80)
568 event->key.state |= GDK_BUTTON5_MASK;
570 if (_gdk_keyboard_has_altgr &&
571 (key_state[VK_LCONTROL] & 0x80) &&
572 (key_state[VK_RMENU] & 0x80))
574 event->key.group = 1;
575 event->key.state |= GDK_MOD2_MASK;
576 if (key_state[VK_RCONTROL] & 0x80)
577 event->key.state |= GDK_CONTROL_MASK;
578 if (key_state[VK_LMENU] & 0x80)
579 event->key.state |= GDK_MOD1_MASK;
583 event->key.group = 0;
584 if (key_state[VK_CONTROL] & 0x80)
585 event->key.state |= GDK_CONTROL_MASK;
586 if (key_state[VK_MENU] & 0x80)
587 event->key.state |= GDK_MOD1_MASK;
592 build_pointer_event_state (MSG *msg)
598 if (msg->wParam & MK_CONTROL)
599 state |= GDK_CONTROL_MASK;
601 if ((msg->message != WM_LBUTTONDOWN &&
602 (msg->wParam & MK_LBUTTON)) ||
603 msg->message == WM_LBUTTONUP)
604 state |= GDK_BUTTON1_MASK;
606 if ((msg->message != WM_MBUTTONDOWN &&
607 (msg->wParam & MK_MBUTTON)) ||
608 msg->message == WM_MBUTTONUP)
609 state |= GDK_BUTTON2_MASK;
611 if ((msg->message != WM_RBUTTONDOWN &&
612 (msg->wParam & MK_RBUTTON)) ||
613 msg->message == WM_RBUTTONUP)
614 state |= GDK_BUTTON3_MASK;
616 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON1) &&
617 (msg->wParam & MK_XBUTTON1)) ||
618 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON1))
619 state |= GDK_BUTTON4_MASK;
621 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON2) &&
622 (msg->wParam & MK_XBUTTON2)) ||
623 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON2))
624 state |= GDK_BUTTON5_MASK;
626 if (msg->wParam & MK_SHIFT)
627 state |= GDK_SHIFT_MASK;
629 if (GetKeyState (VK_MENU) < 0)
630 state |= GDK_MOD1_MASK;
632 if (GetKeyState (VK_CAPITAL) & 0x1)
633 state |= GDK_LOCK_MASK;
639 build_wm_ime_composition_event (GdkEvent *event,
644 event->key.time = _gdk_win32_get_next_tick (msg->time);
646 build_key_event_state (event, key_state);
648 event->key.hardware_keycode = 0; /* FIXME: What should it be? */
649 event->key.string = NULL;
650 event->key.length = 0;
651 event->key.keyval = gdk_unicode_to_keyval (wc);
654 #ifdef G_ENABLE_DEBUG
657 print_event_state (guint state)
659 #define CASE(bit) if (state & GDK_ ## bit ## _MASK) g_print (#bit " ");
677 _gdk_win32_print_event (const GdkEvent *event)
679 gchar *escaped, *kvname;
680 gchar *selection_name, *target_name, *property_name;
682 g_print ("%s%*s===> ", (debug_indent > 0 ? "\n" : ""), debug_indent, "");
683 switch (event->any.type)
685 #define CASE(x) case x: g_print (#x); break;
690 CASE (GDK_MOTION_NOTIFY);
691 CASE (GDK_BUTTON_PRESS);
692 CASE (GDK_2BUTTON_PRESS);
693 CASE (GDK_3BUTTON_PRESS);
694 CASE (GDK_BUTTON_RELEASE);
695 CASE (GDK_KEY_PRESS);
696 CASE (GDK_KEY_RELEASE);
697 CASE (GDK_ENTER_NOTIFY);
698 CASE (GDK_LEAVE_NOTIFY);
699 CASE (GDK_FOCUS_CHANGE);
700 CASE (GDK_CONFIGURE);
703 CASE (GDK_PROPERTY_NOTIFY);
704 CASE (GDK_SELECTION_CLEAR);
705 CASE (GDK_SELECTION_REQUEST);
706 CASE (GDK_SELECTION_NOTIFY);
707 CASE (GDK_PROXIMITY_IN);
708 CASE (GDK_PROXIMITY_OUT);
709 CASE (GDK_DRAG_ENTER);
710 CASE (GDK_DRAG_LEAVE);
711 CASE (GDK_DRAG_MOTION);
712 CASE (GDK_DRAG_STATUS);
713 CASE (GDK_DROP_START);
714 CASE (GDK_DROP_FINISHED);
715 CASE (GDK_CLIENT_EVENT);
716 CASE (GDK_VISIBILITY_NOTIFY);
718 CASE (GDK_WINDOW_STATE);
720 CASE (GDK_OWNER_CHANGE);
721 CASE (GDK_GRAB_BROKEN);
723 default: g_assert_not_reached ();
726 g_print (" %p ", event->any.window ? GDK_WINDOW_HWND (event->any.window) : NULL);
728 switch (event->any.type)
732 _gdk_win32_gdkrectangle_to_string (&event->expose.area),
733 event->expose.count);
735 case GDK_MOTION_NOTIFY:
736 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s",
737 event->motion.x, event->motion.y,
738 event->motion.x_root, event->motion.y_root,
739 event->motion.is_hint ? "HINT " : "");
740 print_event_state (event->motion.state);
742 case GDK_BUTTON_PRESS:
743 case GDK_2BUTTON_PRESS:
744 case GDK_3BUTTON_PRESS:
745 case GDK_BUTTON_RELEASE:
746 g_print ("%d (%.4g,%.4g) (%.4g,%.4g) ",
747 event->button.button,
748 event->button.x, event->button.y,
749 event->button.x_root, event->button.y_root);
750 print_event_state (event->button.state);
753 case GDK_KEY_RELEASE:
754 if (event->key.length == 0)
755 escaped = g_strdup ("");
757 escaped = g_strescape (event->key.string, NULL);
758 kvname = gdk_keyval_name (event->key.keyval);
759 g_print ("%#.02x group:%d %s %d:\"%s\" ",
760 event->key.hardware_keycode, event->key.group,
761 (kvname ? kvname : "??"),
765 print_event_state (event->key.state);
767 case GDK_ENTER_NOTIFY:
768 case GDK_LEAVE_NOTIFY:
769 g_print ("%p (%.4g,%.4g) (%.4g,%.4g) %s %s%s",
770 event->crossing.subwindow == NULL ? NULL : GDK_WINDOW_HWND (event->crossing.subwindow),
771 event->crossing.x, event->crossing.y,
772 event->crossing.x_root, event->crossing.y_root,
773 (event->crossing.mode == GDK_CROSSING_NORMAL ? "NORMAL" :
774 (event->crossing.mode == GDK_CROSSING_GRAB ? "GRAB" :
775 (event->crossing.mode == GDK_CROSSING_UNGRAB ? "UNGRAB" :
777 (event->crossing.detail == GDK_NOTIFY_ANCESTOR ? "ANCESTOR" :
778 (event->crossing.detail == GDK_NOTIFY_VIRTUAL ? "VIRTUAL" :
779 (event->crossing.detail == GDK_NOTIFY_INFERIOR ? "INFERIOR" :
780 (event->crossing.detail == GDK_NOTIFY_NONLINEAR ? "NONLINEAR" :
781 (event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL ? "NONLINEAR_VIRTUAL" :
782 (event->crossing.detail == GDK_NOTIFY_UNKNOWN ? "UNKNOWN" :
784 event->crossing.focus ? " FOCUS" : "");
785 print_event_state (event->crossing.state);
787 case GDK_FOCUS_CHANGE:
788 g_print ("%s", (event->focus_change.in ? "IN" : "OUT"));
791 g_print ("x:%d y:%d w:%d h:%d",
792 event->configure.x, event->configure.y,
793 event->configure.width, event->configure.height);
795 case GDK_SELECTION_CLEAR:
796 case GDK_SELECTION_REQUEST:
797 case GDK_SELECTION_NOTIFY:
798 selection_name = gdk_atom_name (event->selection.selection);
799 target_name = gdk_atom_name (event->selection.target);
800 property_name = gdk_atom_name (event->selection.property);
801 g_print ("sel:%s tgt:%s prop:%s",
802 selection_name, target_name, property_name);
803 g_free (selection_name);
804 g_free (target_name);
805 g_free (property_name);
809 case GDK_DRAG_MOTION:
810 case GDK_DRAG_STATUS:
812 case GDK_DROP_FINISHED:
813 if (event->dnd.context != NULL)
814 g_print ("ctx:%p: %s %s src:%p dest:%p",
816 _gdk_win32_drag_protocol_to_string (event->dnd.context->protocol),
817 event->dnd.context->is_source ? "SOURCE" : "DEST",
818 event->dnd.context->source_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->source_window),
819 event->dnd.context->dest_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->dest_window));
821 case GDK_CLIENT_EVENT:
822 /* no more GdkEventClient */
825 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",
826 event->scroll.x, event->scroll.y,
827 event->scroll.x_root, event->scroll.y_root,
828 (event->scroll.direction == GDK_SCROLL_UP ? "UP" :
829 (event->scroll.direction == GDK_SCROLL_DOWN ? "DOWN" :
830 (event->scroll.direction == GDK_SCROLL_LEFT ? "LEFT" :
831 (event->scroll.direction == GDK_SCROLL_RIGHT ? "RIGHT" :
833 print_event_state (event->scroll.state);
835 case GDK_WINDOW_STATE:
837 _gdk_win32_window_state_to_string (event->window_state.changed_mask),
838 _gdk_win32_window_state_to_string (event->window_state.new_window_state));
841 (event->setting.action == GDK_SETTING_ACTION_NEW ? "NEW" :
842 (event->setting.action == GDK_SETTING_ACTION_CHANGED ? "CHANGED" :
843 (event->setting.action == GDK_SETTING_ACTION_DELETED ? "DELETED" :
845 (event->setting.name ? event->setting.name : "NULL"));
846 case GDK_GRAB_BROKEN:
848 (event->grab_broken.keyboard ? "KEYBOARD" : "POINTER"),
849 (event->grab_broken.implicit ? "IMPLICIT" : "EXPLICIT"),
850 (event->grab_broken.grab_window ? GDK_WINDOW_HWND (event->grab_broken.grab_window) : 0));
855 g_print ("%s", (debug_indent == 0 ? "\n" : ""));
859 decode_key_lparam (LPARAM lParam)
861 static char buf[100];
864 if (HIWORD (lParam) & KF_UP)
865 p += g_sprintf (p, "KF_UP ");
866 if (HIWORD (lParam) & KF_REPEAT)
867 p += g_sprintf (p, "KF_REPEAT ");
868 if (HIWORD (lParam) & KF_ALTDOWN)
869 p += g_sprintf (p, "KF_ALTDOWN ");
870 if (HIWORD (lParam) & KF_EXTENDED)
871 p += g_sprintf (p, "KF_EXTENDED ");
872 p += g_sprintf (p, "sc:%d rep:%d", LOBYTE (HIWORD (lParam)), LOWORD (lParam));
880 fixup_event (GdkEvent *event)
882 if (event->any.window)
883 g_object_ref (event->any.window);
884 if (((event->any.type == GDK_ENTER_NOTIFY) ||
885 (event->any.type == GDK_LEAVE_NOTIFY)) &&
886 (event->crossing.subwindow != NULL))
887 g_object_ref (event->crossing.subwindow);
888 event->any.send_event = InSendMessage ();
892 append_event (GdkEvent *event)
898 link = _gdk_event_queue_append (_gdk_display, event);
899 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
900 /* event morphing, the passed in may not be valid afterwards */
901 _gdk_windowing_got_event (_gdk_display, link, event, 0);
903 _gdk_event_queue_append (_gdk_display, event);
904 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
909 fill_key_event_string (GdkEvent *event)
914 /* Fill in event->string crudely, since various programs
919 if (event->key.keyval != GDK_KEY_VoidSymbol)
920 c = gdk_keyval_to_unicode (event->key.keyval);
927 /* Apply the control key - Taken from Xlib
929 if (event->key.state & GDK_CONTROL_MASK)
931 if ((c >= '@' && c < '\177') || c == ' ')
935 event->key.string = g_memdup ("\0\0", 2);
936 event->key.length = 1;
939 else if (c >= '3' && c <= '7')
947 len = g_unichar_to_utf8 (c, buf);
950 event->key.string = g_locale_from_utf8 (buf, len,
951 NULL, &bytes_written,
953 if (event->key.string)
954 event->key.length = bytes_written;
956 else if (event->key.keyval == GDK_KEY_Escape)
958 event->key.length = 1;
959 event->key.string = g_strdup ("\033");
961 else if (event->key.keyval == GDK_KEY_Return ||
962 event->key.keyval == GDK_KEY_KP_Enter)
964 event->key.length = 1;
965 event->key.string = g_strdup ("\r");
968 if (!event->key.string)
970 event->key.length = 0;
971 event->key.string = g_strdup ("");
975 static GdkFilterReturn
976 apply_event_filters (GdkWindow *window,
980 GdkFilterReturn result = GDK_FILTER_CONTINUE;
985 event = gdk_event_new (GDK_NOTHING);
987 event->any.window = g_object_ref (window);
988 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
990 /* I think GdkFilterFunc semantics require the passed-in event
991 * to already be in the queue. The filter func can generate
992 * more events and append them after it if it likes.
994 node = _gdk_event_queue_append (_gdk_display, event);
999 GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
1002 if ((filter->flags & GDK_EVENT_FILTER_REMOVED) != 0)
1004 tmp_list = tmp_list->next;
1008 filter->ref_count++;
1009 result = filter->function (msg, event, filter->data);
1011 /* get the next node after running the function since the
1012 function may add or remove a next node */
1014 tmp_list = tmp_list->next;
1016 filter->ref_count--;
1017 if (filter->ref_count == 0)
1019 *filters = g_list_remove_link (*filters, node);
1020 g_list_free_1 (node);
1024 if (result != GDK_FILTER_CONTINUE)
1028 if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
1030 _gdk_event_queue_remove_link (_gdk_display, node);
1031 g_list_free_1 (node);
1032 gdk_event_free (event);
1034 else /* GDK_FILTER_TRANSLATE */
1036 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1037 fixup_event (event);
1038 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1044 * On Windows, transient windows will not have their own taskbar entries.
1045 * Because of this, we must hide and restore groups of transients in both
1046 * directions. That is, all transient children must be hidden or restored
1047 * with this window, but if this window's transient owner also has a
1048 * transient owner then this window's transient owner must be hidden/restored
1049 * with this one. And etc, up the chain until we hit an ancestor that has no
1052 * It would be a good idea if applications don't chain transient windows
1053 * together. There's a limit to how much evil GTK can try to shield you
1057 show_window_recurse (GdkWindow *window, gboolean hide_window)
1059 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1060 GSList *children = impl->transient_children;
1061 GdkWindow *child = NULL;
1063 if (!impl->changing_state)
1065 impl->changing_state = TRUE;
1067 if (children != NULL)
1069 while (children != NULL)
1071 child = children->data;
1072 show_window_recurse (child, hide_window);
1074 children = g_slist_next (children);
1078 if (GDK_WINDOW_IS_MAPPED (window))
1082 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_ICONIFIED)
1084 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED)
1086 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
1090 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1096 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
1100 impl->changing_state = FALSE;
1105 do_show_window (GdkWindow *window, gboolean hide_window)
1107 GdkWindow *tmp_window = NULL;
1108 GdkWindowImplWin32 *tmp_impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1110 if (!tmp_impl->changing_state)
1112 /* Find the top-level window in our transient chain. */
1113 while (tmp_impl->transient_owner != NULL)
1115 tmp_window = tmp_impl->transient_owner;
1116 tmp_impl = GDK_WINDOW_IMPL_WIN32 (tmp_window->impl);
1119 /* If we couldn't find one, use the window provided. */
1120 if (tmp_window == NULL)
1122 tmp_window = window;
1125 /* Recursively show/hide every window in the chain. */
1126 if (tmp_window != window)
1128 show_window_recurse (tmp_window, hide_window);
1134 synthesize_enter_or_leave_event (GdkWindow *window,
1137 GdkCrossingMode mode,
1138 GdkNotifyType detail)
1144 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1146 event = gdk_event_new (type);
1147 event->crossing.window = window;
1148 event->crossing.subwindow = NULL;
1149 event->crossing.time = _gdk_win32_get_next_tick (msg->time);
1150 event->crossing.x = pt.x;
1151 event->crossing.y = pt.y;
1152 event->crossing.x_root = msg->pt.x + _gdk_offset_x;
1153 event->crossing.y_root = msg->pt.y + _gdk_offset_y;
1154 event->crossing.mode = mode;
1155 event->crossing.detail = detail;
1156 event->crossing.focus = TRUE; /* FIXME: Set correctly */
1157 event->crossing.state = 0; /* FIXME: Set correctly */
1158 gdk_event_set_device (event, _gdk_display->core_pointer);
1160 append_event (event);
1162 if (type == GDK_ENTER_NOTIFY &&
1163 window->extension_events != 0)
1164 _gdk_device_wintab_update_window_coords (window);
1167 /* The check_extended flag controls whether to check if the windows want
1168 * events from extended input devices and if the message should be skipped
1169 * because an extended input device is active
1172 propagate (GdkWindow **window,
1174 GdkWindow *grab_window,
1175 gboolean grab_owner_events,
1177 gboolean (*doesnt_want_it) (gint mask,
1179 gboolean check_extended)
1181 if (grab_window != NULL && !grab_owner_events)
1183 /* Event source is grabbed with owner_events FALSE */
1185 /* See if the event should be ignored because an extended input
1188 if (check_extended &&
1189 grab_window->extension_events != 0 &&
1190 _gdk_input_ignore_core)
1192 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1195 if ((*doesnt_want_it) (grab_mask, msg))
1197 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1202 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1203 assign_object (window, grab_window);
1208 /* If we come here, we know that if grab_window != NULL then
1209 * grab_owner_events is TRUE
1213 if (check_extended &&
1214 (*window)->extension_events != 0 &&
1215 _gdk_input_ignore_core)
1217 GDK_NOTE (EVENTS, g_print (" (ignored)"));
1220 if ((*doesnt_want_it) ((*window)->event_mask, msg))
1222 /* Owner doesn't want it, propagate to parent. */
1223 GdkWindow *parent = gdk_window_get_parent (*window);
1224 if (parent == _gdk_root || parent == NULL)
1226 /* No parent; check if grabbed */
1227 if (grab_window != NULL)
1229 /* Event source is grabbed with owner_events TRUE */
1231 if (check_extended &&
1232 grab_window->extension_events != 0 &&
1233 _gdk_input_ignore_core)
1235 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1238 if ((*doesnt_want_it) (grab_mask, msg))
1240 /* Grabber doesn't want it either */
1241 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1247 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1248 assign_object (window, grab_window);
1254 GDK_NOTE (EVENTS, g_print (" (undelivered)"));
1260 assign_object (window, parent);
1261 /* The only branch where we actually continue the loop */
1270 doesnt_want_key (gint mask,
1273 return (((msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) &&
1274 !(mask & GDK_KEY_RELEASE_MASK)) ||
1275 ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) &&
1276 !(mask & GDK_KEY_PRESS_MASK)));
1280 doesnt_want_char (gint mask,
1283 return !(mask & (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK));
1287 handle_configure_event (MSG *msg,
1293 GetClientRect (msg->hwnd, &client_rect);
1294 point.x = client_rect.left; /* always 0 */
1295 point.y = client_rect.top;
1297 /* top level windows need screen coords */
1298 if (gdk_window_get_parent (window) == _gdk_root)
1300 ClientToScreen (msg->hwnd, &point);
1301 point.x += _gdk_offset_x;
1302 point.y += _gdk_offset_y;
1305 window->width = client_rect.right - client_rect.left;
1306 window->height = client_rect.bottom - client_rect.top;
1308 window->x = point.x;
1309 window->y = point.y;
1311 _gdk_window_update_size (window);
1313 if (window->event_mask & GDK_STRUCTURE_MASK)
1315 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1317 event->configure.window = window;
1319 event->configure.width = client_rect.right - client_rect.left;
1320 event->configure.height = client_rect.bottom - client_rect.top;
1322 event->configure.x = point.x;
1323 event->configure.y = point.y;
1325 append_event (event);
1330 _gdk_win32_hrgn_to_region (HRGN hrgn)
1334 cairo_region_t *result;
1338 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1340 WIN32_GDI_FAILED ("GetRegionData");
1344 rgndata = (RGNDATA *) g_malloc (nbytes);
1346 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1348 WIN32_GDI_FAILED ("GetRegionData");
1353 result = cairo_region_create ();
1354 rects = (RECT *) rgndata->Buffer;
1355 for (i = 0; i < rgndata->rdh.nCount; i++)
1359 r.x = rects[i].left;
1361 r.width = rects[i].right - r.x;
1362 r.height = rects[i].bottom - r.y;
1364 cairo_region_union_rectangle (result, &r);
1373 adjust_drag (LONG *drag,
1378 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1380 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1384 handle_wm_paint (MSG *msg,
1386 gboolean return_exposes,
1389 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1391 PAINTSTRUCT paintstruct;
1392 cairo_region_t *update_region;
1394 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1396 WIN32_GDI_FAILED ("GetUpdateRgn");
1397 DeleteObject (hrgn);
1401 hdc = BeginPaint (msg->hwnd, &paintstruct);
1403 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1404 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1405 (paintstruct.fErase ? "erase" : ""),
1407 (return_exposes ? " return_exposes" : "")));
1409 EndPaint (msg->hwnd, &paintstruct);
1411 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1412 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1414 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1415 DeleteObject (hrgn);
1421 if (!GDK_WINDOW_DESTROYED (window))
1423 GList *list = _gdk_display->queued_events;
1425 *event = gdk_event_new (GDK_EXPOSE);
1426 (*event)->expose.window = window;
1427 (*event)->expose.area.x = paintstruct.rcPaint.left;
1428 (*event)->expose.area.y = paintstruct.rcPaint.top;
1429 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1430 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1431 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1432 (*event)->expose.count = 0;
1434 while (list != NULL)
1436 GdkEventPrivate *evp = list->data;
1438 if (evp->event.any.type == GDK_EXPOSE &&
1439 evp->event.any.window == window &&
1440 !(evp->flags & GDK_EVENT_PENDING))
1441 evp->event.expose.count++;
1447 DeleteObject (hrgn);
1451 update_region = _gdk_win32_hrgn_to_region (hrgn);
1452 if (!cairo_region_is_empty (update_region))
1453 _gdk_window_invalidate_for_expose (window, update_region);
1454 cairo_region_destroy (update_region);
1456 DeleteObject (hrgn);
1459 static VOID CALLBACK
1460 modal_timer_proc (HWND hwnd,
1465 int arbitrary_limit = 1;
1467 while (_modal_operation_in_progress &&
1468 g_main_context_pending (NULL) &&
1470 g_main_context_iteration (NULL, FALSE);
1474 _gdk_win32_begin_modal_call (void)
1476 g_assert (!_modal_operation_in_progress);
1478 _modal_operation_in_progress = TRUE;
1480 modal_timer = SetTimer (NULL, 0, 10, modal_timer_proc);
1481 if (modal_timer == 0)
1482 WIN32_API_FAILED ("SetTimer");
1486 _gdk_win32_end_modal_call (void)
1488 g_assert (_modal_operation_in_progress);
1490 _modal_operation_in_progress = FALSE;
1492 if (modal_timer != 0)
1494 API_CALL (KillTimer, (NULL, modal_timer));
1499 static VOID CALLBACK
1500 sync_timer_proc (HWND hwnd,
1506 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1511 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1513 KillTimer (hwnd, sync_timer);
1517 handle_display_change (void)
1519 _gdk_monitor_init ();
1520 _gdk_root_window_size_init ();
1521 g_signal_emit_by_name (_gdk_screen, "size_changed");
1525 generate_button_event (GdkEventType type,
1530 GdkEvent *event = gdk_event_new (type);
1532 event->button.window = window;
1533 event->button.time = _gdk_win32_get_next_tick (msg->time);
1534 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1535 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1536 event->button.x_root = msg->pt.x + _gdk_offset_x;
1537 event->button.y_root = msg->pt.y + _gdk_offset_y;
1538 event->button.axes = NULL;
1539 event->button.state = build_pointer_event_state (msg);
1540 event->button.button = button;
1541 gdk_event_set_device (event, _gdk_display->core_pointer);
1543 append_event (event);
1547 ensure_stacking_on_unminimize (MSG *msg)
1550 HWND lowest_transient = NULL;
1553 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1555 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1557 /* Checking window group not implemented yet */
1560 GdkWindowImplWin32 *rover_impl =
1561 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1563 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1564 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1565 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1566 rover_impl->transient_owner != NULL))
1568 lowest_transient = rover;
1572 if (lowest_transient != NULL)
1574 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1575 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1576 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1581 ensure_stacking_on_window_pos_changing (MSG *msg,
1584 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1585 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1587 if (GetActiveWindow () == msg->hwnd &&
1588 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1589 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1590 impl->transient_owner == NULL)
1592 /* Make sure the window stays behind any transient-type windows
1593 * of the same window group.
1595 * If the window is not active and being activated, we let
1596 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1597 * handling to bring any utility windows on top of it.
1600 gboolean restacking;
1602 rover = windowpos->hwndInsertAfter;
1606 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1608 /* Checking window group not implemented yet */
1611 GdkWindowImplWin32 *rover_impl =
1612 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1614 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1615 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1616 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1617 rover_impl->transient_owner != NULL))
1620 windowpos->hwndInsertAfter = rover;
1623 rover = GetNextWindow (rover, GW_HWNDNEXT);
1628 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1636 ensure_stacking_on_activate_app (MSG *msg,
1639 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1641 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1642 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1643 impl->transient_owner != NULL)
1645 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1646 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1650 if (IsWindowVisible (msg->hwnd) &&
1651 msg->hwnd == GetActiveWindow ())
1653 /* This window is not a transient-type window and it is the
1654 * activated window. Make sure this window is as visible as
1655 * possible, just below the lowest transient-type window of this
1661 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
1663 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1665 /* Checking window group not implemented yet */
1668 GdkWindowImplWin32 *rover_impl =
1669 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1671 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1672 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1673 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1674 rover_impl->transient_owner != NULL))
1676 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1677 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1678 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1687 gdk_event_translate (MSG *msg,
1690 RECT rect, *drag, orig_drag;
1695 BYTE key_state[256];
1697 WINDOWPOS *windowpos;
1704 GdkWindow *window = NULL;
1705 GdkWindowImplWin32 *impl;
1707 GdkWindow *orig_window, *new_window, *toplevel;
1709 GdkDeviceManager *device_manager;
1711 GdkDeviceGrabInfo *keyboard_grab = NULL;
1712 GdkDeviceGrabInfo *pointer_grab = NULL;
1713 GdkWindow *grab_window = NULL;
1719 gboolean return_val = FALSE;
1723 if (_gdk_default_filters)
1725 /* Apply global filters */
1727 GdkFilterReturn result = apply_event_filters (NULL, msg, &_gdk_default_filters);
1729 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1730 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1731 * we return TRUE, and DefWindowProcW() will not be called.
1733 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1737 window = gdk_win32_handle_table_lookup (msg->hwnd);
1738 orig_window = window;
1742 /* XXX Handle WM_QUIT here ? */
1743 if (msg->message == WM_QUIT)
1745 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1748 else if (msg->message == WM_MOVE ||
1749 msg->message == WM_SIZE)
1751 /* It's quite normal to get these messages before we have
1752 * had time to register the window in our lookup table, or
1753 * when the window is being destroyed and we already have
1754 * removed it. Repost the same message to our queue so that
1755 * we will get it later when we are prepared.
1757 GDK_NOTE (EVENTS, g_print (" (posted)"));
1759 PostMessageW (msg->hwnd, msg->message, msg->wParam, msg->lParam);
1761 else if (msg->message == WM_CREATE)
1763 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1764 GDK_WINDOW_HWND (window) = msg->hwnd;
1768 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1773 device_manager = gdk_display_get_device_manager (_gdk_display);
1775 keyboard_grab = _gdk_display_get_last_device_grab (_gdk_display,
1776 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
1777 pointer_grab = _gdk_display_get_last_device_grab (_gdk_display,
1778 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer);
1780 g_object_ref (window);
1782 /* window's refcount has now been increased, so code below should
1783 * not just return from this function, but instead goto done (or
1784 * break out of the big switch). To protect against forgetting this,
1785 * #define return to a syntax error...
1787 #define return GOTO_DONE_INSTEAD
1789 if (!GDK_WINDOW_DESTROYED (window) && window->filters)
1791 /* Apply per-window filters */
1793 GdkFilterReturn result = apply_event_filters (window, msg, &window->filters);
1795 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1802 if (msg->message == client_message)
1805 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1808 GDK_NOTE (EVENTS, g_print (" client_message"));
1810 event = gdk_event_new (GDK_NOTHING);
1811 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1813 node = _gdk_event_queue_append (_gdk_display, event);
1815 tmp_list = client_filters;
1818 GdkClientFilter *filter = tmp_list->data;
1820 tmp_list = tmp_list->next;
1822 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
1824 GDK_NOTE (EVENTS, g_print (" (match)"));
1826 result = (*filter->function) (msg, event, filter->data);
1828 if (result != GDK_FILTER_CONTINUE)
1835 case GDK_FILTER_REMOVE:
1836 _gdk_event_queue_remove_link (_gdk_display, node);
1837 g_list_free_1 (node);
1838 gdk_event_free (event);
1842 case GDK_FILTER_TRANSLATE:
1843 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1844 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1848 case GDK_FILTER_CONTINUE:
1849 /* No more: Send unknown client messages on to Gtk for it to use */
1850 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1856 switch (msg->message)
1858 case WM_INPUTLANGCHANGE:
1859 _gdk_input_locale = (HKL) msg->lParam;
1860 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
1861 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
1862 LOCALE_IDEFAULTANSICODEPAGE,
1864 _gdk_input_codepage = atoi (buf);
1865 _gdk_keymap_serial++;
1867 g_print (" cs:%lu hkl:%p%s cp:%d",
1868 (gulong) msg->wParam,
1869 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
1870 _gdk_input_codepage));
1876 g_print (" %s ch:%.02x %s",
1877 _gdk_win32_key_to_string (msg->lParam),
1879 decode_key_lparam (msg->lParam)));
1881 /* If posted without us having keyboard focus, ignore */
1882 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
1883 !(HIWORD (msg->lParam) & KF_ALTDOWN))
1886 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
1887 * the keyboard is grabbed.
1889 if (!keyboard_grab &&
1890 (msg->wParam == VK_TAB ||
1891 msg->wParam == VK_SPACE ||
1892 msg->wParam == VK_F4))
1895 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
1901 g_print (" %s ch:%.02x %s",
1902 _gdk_win32_key_to_string (msg->lParam),
1904 decode_key_lparam (msg->lParam)));
1908 /* Ignore key messages intended for the IME */
1909 if (msg->wParam == VK_PROCESSKEY ||
1913 if (keyboard_grab &&
1914 !propagate (&window, msg,
1915 keyboard_grab->window,
1916 keyboard_grab->owner_events,
1917 GDK_ALL_EVENTS_MASK,
1918 doesnt_want_key, FALSE))
1921 if (GDK_WINDOW_DESTROYED (window))
1924 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
1925 msg->message == WM_SYSKEYDOWN) ?
1926 GDK_KEY_PRESS : GDK_KEY_RELEASE);
1927 event->key.window = window;
1928 event->key.time = _gdk_win32_get_next_tick (msg->time);
1929 event->key.keyval = GDK_KEY_VoidSymbol;
1930 event->key.string = NULL;
1931 event->key.length = 0;
1932 event->key.hardware_keycode = msg->wParam;
1933 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
1934 if (HIWORD (msg->lParam) & KF_EXTENDED)
1936 switch (msg->wParam)
1939 event->key.hardware_keycode = VK_RCONTROL;
1941 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
1942 * for the right shift key.
1944 event->key.hardware_keycode = VK_RSHIFT;
1947 event->key.hardware_keycode = VK_RMENU;
1951 else if (msg->wParam == VK_SHIFT &&
1952 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
1953 event->key.hardware_keycode = VK_RSHIFT;
1955 API_CALL (GetKeyboardState, (key_state));
1957 /* 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]); */
1959 build_key_event_state (event, key_state);
1961 gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (_gdk_display),
1962 event->key.hardware_keycode,
1968 fill_key_event_string (event);
1970 /* Reset MOD1_MASK if it is the Alt key itself */
1971 if (msg->wParam == VK_MENU)
1972 event->key.state &= ~GDK_MOD1_MASK;
1974 append_event (event);
1980 if (msg->wParam != VK_SPACE)
1982 /* To prevent beeps, don't let DefWindowProcW() be called */
1988 case WM_IME_STARTCOMPOSITION:
1989 in_ime_composition = TRUE;
1992 case WM_IME_ENDCOMPOSITION:
1993 in_ime_composition = FALSE;
1996 case WM_IME_COMPOSITION:
1997 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
1998 * applications. Thus, handle WM_IME_COMPOSITION with
1999 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2000 * with ImmGetCompositionStringW().
2003 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2005 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2006 * for comments by other people that seems to have the same
2007 * experience. WM_IME_CHAR just gives question marks, apparently
2008 * because of going through some conversion to the current code
2011 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2012 * use WM_IME_COMPOSITION there, too, to simplify the code.
2014 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2016 if (!(msg->lParam & GCS_RESULTSTR))
2019 if (keyboard_grab &&
2020 !propagate (&window, msg,
2021 keyboard_grab->window,
2022 keyboard_grab->owner_events,
2023 GDK_ALL_EVENTS_MASK,
2024 doesnt_want_char, FALSE))
2027 if (GDK_WINDOW_DESTROYED (window))
2030 himc = ImmGetContext (msg->hwnd);
2031 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2032 wbuf, sizeof (wbuf));
2033 ImmReleaseContext (msg->hwnd, himc);
2037 API_CALL (GetKeyboardState, (key_state));
2039 for (i = 0; i < ccount; i++)
2041 if (window->event_mask & GDK_KEY_PRESS_MASK)
2043 /* Build a key press event */
2044 event = gdk_event_new (GDK_KEY_PRESS);
2045 event->key.window = window;
2046 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2047 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2049 append_event (event);
2052 if (window->event_mask & GDK_KEY_RELEASE_MASK)
2054 /* Build a key release event. */
2055 event = gdk_event_new (GDK_KEY_RELEASE);
2056 event->key.window = window;
2057 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2058 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2060 append_event (event);
2066 case WM_LBUTTONDOWN:
2070 case WM_MBUTTONDOWN:
2074 case WM_RBUTTONDOWN:
2078 case WM_XBUTTONDOWN:
2079 if (HIWORD (msg->wParam) == XBUTTON1)
2086 g_print (" (%d,%d)",
2087 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2089 assign_object (&window, find_window_for_mouse_event (window, msg));
2090 /* TODO_CSW?: there used to some synthesize and propagate */
2091 if (GDK_WINDOW_DESTROYED (window))
2094 /* TODO_CSW? Emulate X11's automatic active grab */
2095 generate_button_event (GDK_BUTTON_PRESS, button,
2114 if (HIWORD (msg->wParam) == XBUTTON1)
2121 g_print (" (%d,%d)",
2122 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2124 assign_object (&window, find_window_for_mouse_event (window, msg));
2126 if (window->extension_events != 0 &&
2127 _gdk_input_ignore_core)
2129 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2134 generate_button_event (GDK_BUTTON_RELEASE, button,
2142 g_print (" %p (%d,%d)",
2143 (gpointer) msg->wParam,
2144 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2146 assign_object (&window, find_window_for_mouse_event (window, msg));
2147 toplevel = gdk_window_get_toplevel (window);
2148 if (current_toplevel != toplevel)
2150 GDK_NOTE (EVENTS, g_print (" toplevel %p -> %p",
2151 current_toplevel ? GDK_WINDOW_HWND (current_toplevel) : NULL,
2152 toplevel ? GDK_WINDOW_HWND (toplevel) : NULL));
2153 if (current_toplevel)
2154 synthesize_enter_or_leave_event (current_toplevel, msg,
2155 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2156 synthesize_enter_or_leave_event (toplevel, msg,
2157 GDK_ENTER_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2158 assign_object (¤t_toplevel, toplevel);
2159 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (toplevel));
2162 /* If we haven't moved, don't create any GDK event. Windows
2163 * sends WM_MOUSEMOVE messages after a new window is shows under
2164 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2166 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2167 msg->pt.y + _gdk_offset_y == current_root_y)
2170 current_root_x = msg->pt.x + _gdk_offset_x;
2171 current_root_y = msg->pt.y + _gdk_offset_y;
2173 event = gdk_event_new (GDK_MOTION_NOTIFY);
2174 event->motion.window = window;
2175 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2176 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2177 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2178 event->motion.x_root = current_root_x;
2179 event->motion.y_root = current_root_y;
2180 event->motion.axes = NULL;
2181 event->motion.state = build_pointer_event_state (msg);
2182 event->motion.is_hint = FALSE;
2183 gdk_event_set_device (event, _gdk_display->core_pointer);
2185 append_event (event);
2190 case WM_NCMOUSEMOVE:
2192 g_print (" (%d,%d)",
2193 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2194 #if 0 /* TODO_CSW? */
2195 if (current_toplevel != NULL &&
2196 (current_toplevel->event_mask & GDK_LEAVE_NOTIFY_MASK))
2198 synthesize_enter_or_leave_event (current_toplevel, msg,
2199 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2205 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2206 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2208 if (!gdk_win32_handle_table_lookup (WindowFromPoint (msg->pt)))
2210 /* we are only interested if we don't know the new window */
2211 if (current_toplevel)
2212 synthesize_enter_or_leave_event (current_toplevel, msg,
2213 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2214 assign_object (¤t_toplevel, NULL);
2218 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2225 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2227 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2228 * that. Also, the position is in screen coordinates, not client
2229 * coordinates as with the button messages. I love the
2230 * consistency of Windows.
2232 point.x = GET_X_LPARAM (msg->lParam);
2233 point.y = GET_Y_LPARAM (msg->lParam);
2235 if ((hwnd = WindowFromPoint (point)) == NULL)
2239 if ((new_window = gdk_win32_handle_table_lookup (msg->hwnd)) == NULL)
2242 if (new_window != window)
2244 assign_object (&window, new_window);
2247 ScreenToClient (msg->hwnd, &point);
2249 event = gdk_event_new (GDK_SCROLL);
2250 event->scroll.window = window;
2251 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2252 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2253 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2254 event->scroll.x = (gint16) point.x;
2255 event->scroll.y = (gint16) point.y;
2256 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2257 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2258 event->scroll.state = build_pointer_event_state (msg);
2259 gdk_event_set_device (event, _gdk_display->core_pointer);
2261 append_event (event);
2267 /* Just print more debugging information, don't actually handle it. */
2270 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2271 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2272 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2273 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2274 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2275 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2276 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2277 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2278 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2280 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2281 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2282 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2286 /* Just print more debugging information, don't actually handle it. */
2289 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2290 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2291 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2292 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2293 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2294 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2295 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2296 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2297 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2299 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2300 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2301 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2304 case WM_MOUSEACTIVATE:
2308 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2309 || !window->accept_focus)
2311 *ret_valp = MA_NOACTIVATE;
2315 tmp = _gdk_modal_current ();
2319 if (gdk_window_get_toplevel (window) != tmp)
2321 *ret_valp = MA_NOACTIVATEANDEAT;
2330 if (keyboard_grab != NULL &&
2331 !GDK_WINDOW_DESTROYED (keyboard_grab->window))
2333 generate_grab_broken_event (device_manager, keyboard_grab->window, TRUE, NULL);
2338 if (keyboard_grab != NULL &&
2339 !keyboard_grab->owner_events)
2342 if (!(window->event_mask & GDK_FOCUS_CHANGE_MASK))
2345 if (GDK_WINDOW_DESTROYED (window))
2348 generate_focus_event (device_manager, window, (msg->message == WM_SETFOCUS));
2353 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2355 if (GDK_WINDOW_DESTROYED (window))
2363 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2365 200, sync_timer_proc);
2369 handle_wm_paint (msg, window, FALSE, NULL);
2373 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2374 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2376 if (pointer_grab != NULL)
2377 grab_window = pointer_grab->window;
2379 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2382 if (grab_window != NULL && p_grab_cursor != NULL)
2383 hcursor = p_grab_cursor;
2384 else if (!GDK_WINDOW_DESTROYED (window))
2385 hcursor = GDK_WINDOW_IMPL_WIN32 (window->impl)->hcursor;
2389 if (hcursor != NULL)
2391 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2392 SetCursor (hcursor);
2399 GDK_NOTE (EVENTS, g_print (" %s %s",
2400 (msg->wParam ? "YES" : "NO"),
2401 (msg->lParam == 0 ? "ShowWindow" :
2402 (msg->lParam == SW_OTHERUNZOOM ? "OTHERUNZOOM" :
2403 (msg->lParam == SW_OTHERZOOM ? "OTHERZOOM" :
2404 (msg->lParam == SW_PARENTCLOSING ? "PARENTCLOSING" :
2405 (msg->lParam == SW_PARENTOPENING ? "PARENTOPENING" :
2408 if (!(window->event_mask & GDK_STRUCTURE_MASK))
2411 if (msg->lParam == SW_OTHERUNZOOM ||
2412 msg->lParam == SW_OTHERZOOM)
2415 if (GDK_WINDOW_DESTROYED (window))
2418 event = gdk_event_new (msg->wParam ? GDK_MAP : GDK_UNMAP);
2419 event->any.window = window;
2421 append_event (event);
2423 if (event->any.type == GDK_UNMAP)
2425 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2427 if (impl->transient_owner && GetForegroundWindow () == GDK_WINDOW_HWND (window))
2429 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2432 if (pointer_grab != NULL)
2434 if (pointer_grab->window == window)
2435 gdk_pointer_ungrab (msg->time);
2438 if (keyboard_grab &&
2439 keyboard_grab->window == window)
2440 gdk_keyboard_ungrab (msg->time);
2447 switch (msg->wParam)
2451 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2459 g_print (" %s %dx%d",
2460 (msg->wParam == SIZE_MAXHIDE ? "MAXHIDE" :
2461 (msg->wParam == SIZE_MAXIMIZED ? "MAXIMIZED" :
2462 (msg->wParam == SIZE_MAXSHOW ? "MAXSHOW" :
2463 (msg->wParam == SIZE_MINIMIZED ? "MINIMIZED" :
2464 (msg->wParam == SIZE_RESTORED ? "RESTORED" : "?"))))),
2465 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2467 if (msg->wParam == SIZE_MINIMIZED)
2469 /* Don't generate any GDK event. This is *not* an UNMAP. */
2470 if (pointer_grab != NULL)
2472 if (pointer_grab->window == window)
2473 gdk_pointer_ungrab (msg->time);
2475 if (keyboard_grab &&
2476 keyboard_grab->window == window)
2477 gdk_keyboard_ungrab (msg->time);
2479 gdk_synthesize_window_state (window,
2480 GDK_WINDOW_STATE_WITHDRAWN,
2481 GDK_WINDOW_STATE_ICONIFIED);
2482 do_show_window (window, TRUE);
2484 else if ((msg->wParam == SIZE_RESTORED ||
2485 msg->wParam == SIZE_MAXIMIZED) &&
2486 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
2488 GdkWindowState withdrawn_bit =
2489 IsWindowVisible (msg->hwnd) ? GDK_WINDOW_STATE_WITHDRAWN : 0;
2491 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
2492 ensure_stacking_on_unminimize (msg);
2494 if (!GDK_WINDOW_DESTROYED (window))
2495 handle_configure_event (msg, window);
2497 if (msg->wParam == SIZE_RESTORED)
2499 gdk_synthesize_window_state (window,
2500 GDK_WINDOW_STATE_ICONIFIED |
2501 GDK_WINDOW_STATE_MAXIMIZED |
2505 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_TEMP && !GDK_WINDOW_IS_MAPPED (window))
2507 do_show_window (window, FALSE);
2510 else if (msg->wParam == SIZE_MAXIMIZED)
2512 gdk_synthesize_window_state (window,
2513 GDK_WINDOW_STATE_ICONIFIED |
2515 GDK_WINDOW_STATE_MAXIMIZED);
2518 if (window->resize_count > 1)
2519 window->resize_count -= 1;
2521 if (window->extension_events != 0)
2522 _gdk_device_wintab_update_window_coords (window);
2528 case WM_ENTERSIZEMOVE:
2529 case WM_ENTERMENULOOP:
2530 _gdk_win32_begin_modal_call ();
2533 case WM_EXITSIZEMOVE:
2534 case WM_EXITMENULOOP:
2535 _gdk_win32_end_modal_call ();
2538 case WM_WINDOWPOSCHANGING:
2539 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2540 g_print (" %s %s %dx%d@%+d%+d now below %p",
2541 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2542 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2543 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2544 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2545 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2546 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2548 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2549 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2551 if (GDK_WINDOW_IS_MAPPED (window))
2552 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2555 case WM_WINDOWPOSCHANGED:
2556 windowpos = (WINDOWPOS *) msg->lParam;
2557 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2558 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2559 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2560 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2561 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2562 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2563 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2565 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2567 /* If position and size haven't changed, don't do anything */
2568 if (_modal_operation_in_progress &&
2569 (windowpos->flags & SWP_NOMOVE) &&
2570 (windowpos->flags & SWP_NOSIZE))
2573 /* Once we've entered the moving or sizing modal loop, we won't
2574 * return to the main loop until we're done sizing or moving.
2576 if (_modal_operation_in_progress &&
2577 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2578 !GDK_WINDOW_DESTROYED (window))
2580 if (window->event_mask & GDK_STRUCTURE_MASK)
2582 GDK_NOTE (EVENTS, g_print (" do magic"));
2583 if (window->resize_count > 1)
2584 window->resize_count -= 1;
2586 handle_configure_event (msg, window);
2587 g_main_context_iteration (NULL, FALSE);
2589 /* Dispatch main loop - to realize resizes... */
2590 modal_timer_proc (msg->hwnd, msg->message, 0, msg->time);
2592 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2600 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2601 drag = (RECT *) msg->lParam;
2602 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2603 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2604 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2605 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2606 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2607 (msg->wParam == WMSZ_TOP ? "TOP" :
2608 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2609 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2611 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2613 _gdk_win32_rect_to_string (&rect),
2614 _gdk_win32_rect_to_string (drag)));
2616 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2618 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2620 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2621 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2623 /* Resize in increments relative to the base size */
2624 rect.left = rect.top = 0;
2625 rect.right = impl->hints.base_width;
2626 rect.bottom = impl->hints.base_height;
2627 _gdk_win32_adjust_client_rect (window, &rect);
2628 point.x = rect.left;
2630 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2631 rect.left = point.x;
2633 point.x = rect.right;
2634 point.y = rect.bottom;
2635 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2636 rect.right = point.x;
2637 rect.bottom = point.y;
2639 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2640 _gdk_win32_rect_to_string (&rect)));
2643 switch (msg->wParam)
2646 if (drag->bottom == rect.bottom)
2648 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2651 case WMSZ_BOTTOMLEFT:
2652 if (drag->bottom == rect.bottom && drag->left == rect.left)
2654 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2655 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2659 if (drag->left == rect.left)
2661 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2665 if (drag->top == rect.top && drag->left == rect.left)
2667 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2668 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2672 if (drag->top == rect.top)
2674 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2678 if (drag->top == rect.top && drag->right == rect.right)
2680 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2681 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2685 if (drag->right == rect.right)
2687 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2690 case WMSZ_BOTTOMRIGHT:
2691 if (drag->bottom == rect.bottom && drag->right == rect.right)
2693 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2694 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2698 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2699 drag->top != orig_drag.top || drag->right != orig_drag.right)
2703 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2704 _gdk_win32_rect_to_string (drag)));
2708 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2710 if (impl->hint_flags & GDK_HINT_ASPECT)
2712 RECT decorated_rect;
2713 RECT undecorated_drag;
2714 int decoration_width, decoration_height;
2715 gdouble drag_aspect;
2716 int drag_width, drag_height, new_width, new_height;
2718 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2719 decorated_rect = rect;
2720 _gdk_win32_adjust_client_rect (window, &decorated_rect);
2722 /* Set undecorated_drag to the client area being dragged
2723 * out, in screen coordinates.
2725 undecorated_drag = *drag;
2726 undecorated_drag.left -= decorated_rect.left - rect.left;
2727 undecorated_drag.right -= decorated_rect.right - rect.right;
2728 undecorated_drag.top -= decorated_rect.top - rect.top;
2729 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
2731 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
2732 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
2734 drag_width = undecorated_drag.right - undecorated_drag.left;
2735 drag_height = undecorated_drag.bottom - undecorated_drag.top;
2737 drag_aspect = (gdouble) drag_width / drag_height;
2739 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
2740 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
2742 if (drag_aspect < impl->hints.min_aspect)
2744 /* Aspect is getting too narrow */
2745 switch (msg->wParam)
2749 /* User drags top or bottom edge outward. Keep height, increase width. */
2750 new_width = impl->hints.min_aspect * drag_height;
2751 drag->left -= (new_width - drag_width) / 2;
2752 drag->right = drag->left + new_width + decoration_width;
2754 case WMSZ_BOTTOMLEFT:
2755 case WMSZ_BOTTOMRIGHT:
2756 /* User drags bottom-left or bottom-right corner down. Adjust height. */
2757 new_height = drag_width / impl->hints.min_aspect;
2758 drag->bottom = drag->top + new_height + decoration_height;
2762 /* User drags left or right edge inward. Decrease height */
2763 new_height = drag_width / impl->hints.min_aspect;
2764 drag->top += (drag_height - new_height) / 2;
2765 drag->bottom = drag->top + new_height + decoration_height;
2769 /* User drags top-left or top-right corner up. Adjust height. */
2770 new_height = drag_width / impl->hints.min_aspect;
2771 drag->top = drag->bottom - new_height - decoration_height;
2774 else if (drag_aspect > impl->hints.max_aspect)
2776 /* Aspect is getting too wide */
2777 switch (msg->wParam)
2781 /* User drags top or bottom edge inward. Decrease width. */
2782 new_width = impl->hints.max_aspect * drag_height;
2783 drag->left += (drag_width - new_width) / 2;
2784 drag->right = drag->left + new_width + decoration_width;
2786 case WMSZ_BOTTOMLEFT:
2788 /* User drags bottom-left or top-left corner left. Adjust width. */
2789 new_width = impl->hints.max_aspect * drag_height;
2790 drag->left = drag->right - new_width - decoration_width;
2792 case WMSZ_BOTTOMRIGHT:
2794 /* User drags bottom-right or top-right corner right. Adjust width. */
2795 new_width = impl->hints.max_aspect * drag_height;
2796 drag->right = drag->left + new_width + decoration_width;
2800 /* User drags left or right edge outward. Increase height. */
2801 new_height = drag_width / impl->hints.max_aspect;
2802 drag->top -= (new_height - drag_height) / 2;
2803 drag->bottom = drag->top + new_height + decoration_height;
2810 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
2811 _gdk_win32_rect_to_string (drag)));
2815 case WM_GETMINMAXINFO:
2816 if (GDK_WINDOW_DESTROYED (window))
2819 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2820 mmi = (MINMAXINFO*) msg->lParam;
2821 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
2822 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
2823 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
2824 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
2825 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
2826 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
2828 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
2830 rect.left = rect.top = 0;
2831 rect.right = impl->hints.min_width;
2832 rect.bottom = impl->hints.min_height;
2834 _gdk_win32_adjust_client_rect (window, &rect);
2836 mmi->ptMinTrackSize.x = rect.right - rect.left;
2837 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
2840 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
2844 rect.left = rect.top = 0;
2845 rect.right = impl->hints.max_width;
2846 rect.bottom = impl->hints.max_height;
2848 _gdk_win32_adjust_client_rect (window, &rect);
2850 /* at least on win9x we have the 16 bit trouble */
2851 maxw = rect.right - rect.left;
2852 maxh = rect.bottom - rect.top;
2853 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
2854 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
2857 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
2859 /* Don't call DefWindowProcW() */
2860 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
2861 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
2862 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
2863 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
2864 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
2865 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
2871 GDK_NOTE (EVENTS, g_print (" (%d,%d)",
2872 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2874 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2875 !IsIconic (msg->hwnd))
2877 if (!GDK_WINDOW_DESTROYED (window))
2878 handle_configure_event (msg, window);
2885 if (GDK_WINDOW_DESTROYED (window))
2888 event = gdk_event_new (GDK_DELETE);
2889 event->any.window = window;
2891 append_event (event);
2893 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2895 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
2897 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2904 if (pointer_grab != NULL)
2906 if (pointer_grab->window == window)
2907 gdk_pointer_ungrab (msg->time);
2910 if (keyboard_grab &&
2911 keyboard_grab->window == window)
2912 gdk_keyboard_ungrab (msg->time);
2914 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
2915 gdk_window_destroy_notify (window);
2917 if (window == NULL || GDK_WINDOW_DESTROYED (window))
2920 event = gdk_event_new (GDK_DESTROY);
2921 event->any.window = window;
2923 append_event (event);
2928 case WM_DISPLAYCHANGE:
2929 handle_display_change ();
2932 case WM_DESTROYCLIPBOARD:
2933 if (!_ignore_destroy_clipboard)
2935 event = gdk_event_new (GDK_SELECTION_CLEAR);
2936 event->selection.window = window;
2937 event->selection.selection = GDK_SELECTION_CLIPBOARD;
2938 event->selection.time = _gdk_win32_get_next_tick (msg->time);
2939 append_event (event);
2948 case WM_RENDERFORMAT:
2949 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
2951 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
2953 GDK_NOTE (EVENTS, g_print (" (target not found)"));
2958 /* We need to render to clipboard immediately, don't call
2961 event = gdk_event_new (GDK_SELECTION_REQUEST);
2962 event->selection.window = window;
2963 event->selection.send_event = FALSE;
2964 event->selection.selection = GDK_SELECTION_CLIPBOARD;
2965 event->selection.target = target;
2966 event->selection.property = _gdk_selection;
2967 event->selection.requestor = gdk_win32_handle_table_lookup (msg->hwnd);
2968 event->selection.time = msg->time;
2970 fixup_event (event);
2971 GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)"));
2972 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2973 _gdk_event_emit (event);
2974 gdk_event_free (event);
2976 /* Now the clipboard owner should have rendered */
2977 if (!_delayed_rendering_data)
2979 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
2983 if (msg->wParam == CF_DIB)
2985 _delayed_rendering_data =
2986 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
2988 if (!_delayed_rendering_data)
2990 g_warning ("Cannot convert to DIB from delayed rendered image");
2995 /* The requestor is holding the clipboard, no
2996 * OpenClipboard() is required/possible
2999 g_print (" SetClipboardData(%s,%p)",
3000 _gdk_win32_cf_to_string (msg->wParam),
3001 _delayed_rendering_data));
3003 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3004 _delayed_rendering_data = NULL;
3009 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3010 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3011 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3012 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3013 HIWORD (msg->wParam) ? " minimized" : "",
3014 (HWND) msg->lParam));
3015 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3016 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3019 if (is_modally_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3021 GdkWindow *modal_current = _gdk_modal_current ();
3022 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3028 /* Bring any tablet contexts to the top of the overlap order when
3029 * one of our windows is activated.
3030 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3033 if (LOWORD(msg->wParam) != WA_INACTIVE)
3034 _gdk_input_set_tablet_active ();
3037 case WM_ACTIVATEAPP:
3038 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3039 msg->wParam ? "YES" : "NO",
3040 (gint64) msg->lParam));
3041 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3042 ensure_stacking_on_activate_app (msg, window);
3045 /* Handle WINTAB events here, as we know that gdkinput.c will
3046 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3047 * constants as case labels.
3050 GDK_NOTE (EVENTS, g_print (" %d %p",
3051 (int) msg->wParam, (gpointer) msg->lParam));
3055 GDK_NOTE (EVENTS, g_print (" %d %p",
3056 (int) msg->wParam, (gpointer) msg->lParam));
3060 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3061 (gpointer) msg->wParam,
3062 LOWORD (msg->lParam),
3063 HIWORD (msg->lParam)));
3067 event = gdk_event_new (GDK_NOTHING);
3068 event->any.window = window;
3069 g_object_ref (window);
3071 if (_gdk_input_other_event (event, msg, window))
3072 append_event (event);
3074 gdk_event_free (event);
3082 g_object_unref (window);
3089 _gdk_win32_display_queue_events (GdkDisplay *display)
3093 if (modal_win32_dialog != NULL)
3096 while (!_gdk_event_queue_find_first (display) &&
3097 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3099 TranslateMessage (&msg);
3100 DispatchMessageW (&msg);
3105 gdk_event_prepare (GSource *source,
3111 GDK_THREADS_ENTER ();
3115 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3116 (modal_win32_dialog == NULL &&
3117 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3119 GDK_THREADS_LEAVE ();
3125 gdk_event_check (GSource *source)
3130 GDK_THREADS_ENTER ();
3132 if (event_poll_fd.revents & G_IO_IN)
3134 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3135 (modal_win32_dialog == NULL &&
3136 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3143 GDK_THREADS_LEAVE ();
3149 gdk_event_dispatch (GSource *source,
3150 GSourceFunc callback,
3155 GDK_THREADS_ENTER ();
3157 _gdk_win32_display_queue_events (_gdk_display);
3158 event = _gdk_event_unqueue (_gdk_display);
3162 _gdk_event_emit (event);
3164 gdk_event_free (event);
3166 /* Do drag & drop if it is still pending */
3167 if (_dnd_source_state == GDK_WIN32_DND_PENDING)
3169 _dnd_source_state = GDK_WIN32_DND_DRAGGING;
3170 _gdk_win32_dnd_do_dragdrop ();
3171 _dnd_source_state = GDK_WIN32_DND_NONE;
3175 GDK_THREADS_LEAVE ();
3181 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3183 modal_win32_dialog = window;
3187 is_modally_blocked (GdkWindow *window)
3189 GdkWindow *modal_current = _gdk_modal_current ();
3190 return modal_current != NULL ? gdk_window_get_toplevel (window) != modal_current : FALSE;
3194 _gdk_win32_display_sync (GdkDisplay * display)
3198 g_return_if_fail (display == _gdk_display);
3200 /* Process all messages currently available */
3201 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3202 DispatchMessageW (&msg);