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 ((GdkNativeWindow) 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 _gdk_win32_display_add_client_message_filter (GdkDisplay *display,
549 GdkAtom message_type,
553 GdkClientFilter *filter = g_new (GdkClientFilter, 1);
555 filter->type = message_type;
556 filter->function = func;
559 client_filters = g_list_append (client_filters, filter);
563 build_key_event_state (GdkEvent *event,
566 event->key.state = 0;
568 if (key_state[VK_SHIFT] & 0x80)
569 event->key.state |= GDK_SHIFT_MASK;
571 if (key_state[VK_CAPITAL] & 0x01)
572 event->key.state |= GDK_LOCK_MASK;
574 if (key_state[VK_LBUTTON] & 0x80)
575 event->key.state |= GDK_BUTTON1_MASK;
576 if (key_state[VK_MBUTTON] & 0x80)
577 event->key.state |= GDK_BUTTON2_MASK;
578 if (key_state[VK_RBUTTON] & 0x80)
579 event->key.state |= GDK_BUTTON3_MASK;
580 if (key_state[VK_XBUTTON1] & 0x80)
581 event->key.state |= GDK_BUTTON4_MASK;
582 if (key_state[VK_XBUTTON2] & 0x80)
583 event->key.state |= GDK_BUTTON5_MASK;
585 if (_gdk_keyboard_has_altgr &&
586 (key_state[VK_LCONTROL] & 0x80) &&
587 (key_state[VK_RMENU] & 0x80))
589 event->key.group = 1;
590 event->key.state |= GDK_MOD2_MASK;
591 if (key_state[VK_RCONTROL] & 0x80)
592 event->key.state |= GDK_CONTROL_MASK;
593 if (key_state[VK_LMENU] & 0x80)
594 event->key.state |= GDK_MOD1_MASK;
598 event->key.group = 0;
599 if (key_state[VK_CONTROL] & 0x80)
600 event->key.state |= GDK_CONTROL_MASK;
601 if (key_state[VK_MENU] & 0x80)
602 event->key.state |= GDK_MOD1_MASK;
607 build_pointer_event_state (MSG *msg)
613 if (msg->wParam & MK_CONTROL)
614 state |= GDK_CONTROL_MASK;
616 if ((msg->message != WM_LBUTTONDOWN &&
617 (msg->wParam & MK_LBUTTON)) ||
618 msg->message == WM_LBUTTONUP)
619 state |= GDK_BUTTON1_MASK;
621 if ((msg->message != WM_MBUTTONDOWN &&
622 (msg->wParam & MK_MBUTTON)) ||
623 msg->message == WM_MBUTTONUP)
624 state |= GDK_BUTTON2_MASK;
626 if ((msg->message != WM_RBUTTONDOWN &&
627 (msg->wParam & MK_RBUTTON)) ||
628 msg->message == WM_RBUTTONUP)
629 state |= GDK_BUTTON3_MASK;
631 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON1) &&
632 (msg->wParam & MK_XBUTTON1)) ||
633 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON1))
634 state |= GDK_BUTTON4_MASK;
636 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON2) &&
637 (msg->wParam & MK_XBUTTON2)) ||
638 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON2))
639 state |= GDK_BUTTON5_MASK;
641 if (msg->wParam & MK_SHIFT)
642 state |= GDK_SHIFT_MASK;
644 if (GetKeyState (VK_MENU) < 0)
645 state |= GDK_MOD1_MASK;
647 if (GetKeyState (VK_CAPITAL) & 0x1)
648 state |= GDK_LOCK_MASK;
654 build_wm_ime_composition_event (GdkEvent *event,
659 event->key.time = _gdk_win32_get_next_tick (msg->time);
661 build_key_event_state (event, key_state);
663 event->key.hardware_keycode = 0; /* FIXME: What should it be? */
664 event->key.string = NULL;
665 event->key.length = 0;
666 event->key.keyval = gdk_unicode_to_keyval (wc);
669 #ifdef G_ENABLE_DEBUG
672 print_event_state (guint state)
674 #define CASE(bit) if (state & GDK_ ## bit ## _MASK) g_print (#bit " ");
692 _gdk_win32_print_event (const GdkEvent *event)
694 gchar *escaped, *kvname;
695 gchar *selection_name, *target_name, *property_name;
697 g_print ("%s%*s===> ", (debug_indent > 0 ? "\n" : ""), debug_indent, "");
698 switch (event->any.type)
700 #define CASE(x) case x: g_print (#x); break;
705 CASE (GDK_MOTION_NOTIFY);
706 CASE (GDK_BUTTON_PRESS);
707 CASE (GDK_2BUTTON_PRESS);
708 CASE (GDK_3BUTTON_PRESS);
709 CASE (GDK_BUTTON_RELEASE);
710 CASE (GDK_KEY_PRESS);
711 CASE (GDK_KEY_RELEASE);
712 CASE (GDK_ENTER_NOTIFY);
713 CASE (GDK_LEAVE_NOTIFY);
714 CASE (GDK_FOCUS_CHANGE);
715 CASE (GDK_CONFIGURE);
718 CASE (GDK_PROPERTY_NOTIFY);
719 CASE (GDK_SELECTION_CLEAR);
720 CASE (GDK_SELECTION_REQUEST);
721 CASE (GDK_SELECTION_NOTIFY);
722 CASE (GDK_PROXIMITY_IN);
723 CASE (GDK_PROXIMITY_OUT);
724 CASE (GDK_DRAG_ENTER);
725 CASE (GDK_DRAG_LEAVE);
726 CASE (GDK_DRAG_MOTION);
727 CASE (GDK_DRAG_STATUS);
728 CASE (GDK_DROP_START);
729 CASE (GDK_DROP_FINISHED);
730 CASE (GDK_CLIENT_EVENT);
731 CASE (GDK_VISIBILITY_NOTIFY);
733 CASE (GDK_WINDOW_STATE);
735 CASE (GDK_OWNER_CHANGE);
736 CASE (GDK_GRAB_BROKEN);
738 default: g_assert_not_reached ();
741 g_print (" %p ", event->any.window ? GDK_WINDOW_HWND (event->any.window) : NULL);
743 switch (event->any.type)
747 _gdk_win32_gdkrectangle_to_string (&event->expose.area),
748 event->expose.count);
750 case GDK_MOTION_NOTIFY:
751 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s",
752 event->motion.x, event->motion.y,
753 event->motion.x_root, event->motion.y_root,
754 event->motion.is_hint ? "HINT " : "");
755 print_event_state (event->motion.state);
757 case GDK_BUTTON_PRESS:
758 case GDK_2BUTTON_PRESS:
759 case GDK_3BUTTON_PRESS:
760 case GDK_BUTTON_RELEASE:
761 g_print ("%d (%.4g,%.4g) (%.4g,%.4g) ",
762 event->button.button,
763 event->button.x, event->button.y,
764 event->button.x_root, event->button.y_root);
765 print_event_state (event->button.state);
768 case GDK_KEY_RELEASE:
769 if (event->key.length == 0)
770 escaped = g_strdup ("");
772 escaped = g_strescape (event->key.string, NULL);
773 kvname = gdk_keyval_name (event->key.keyval);
774 g_print ("%#.02x group:%d %s %d:\"%s\" ",
775 event->key.hardware_keycode, event->key.group,
776 (kvname ? kvname : "??"),
780 print_event_state (event->key.state);
782 case GDK_ENTER_NOTIFY:
783 case GDK_LEAVE_NOTIFY:
784 g_print ("%p (%.4g,%.4g) (%.4g,%.4g) %s %s%s",
785 event->crossing.subwindow == NULL ? NULL : GDK_WINDOW_HWND (event->crossing.subwindow),
786 event->crossing.x, event->crossing.y,
787 event->crossing.x_root, event->crossing.y_root,
788 (event->crossing.mode == GDK_CROSSING_NORMAL ? "NORMAL" :
789 (event->crossing.mode == GDK_CROSSING_GRAB ? "GRAB" :
790 (event->crossing.mode == GDK_CROSSING_UNGRAB ? "UNGRAB" :
792 (event->crossing.detail == GDK_NOTIFY_ANCESTOR ? "ANCESTOR" :
793 (event->crossing.detail == GDK_NOTIFY_VIRTUAL ? "VIRTUAL" :
794 (event->crossing.detail == GDK_NOTIFY_INFERIOR ? "INFERIOR" :
795 (event->crossing.detail == GDK_NOTIFY_NONLINEAR ? "NONLINEAR" :
796 (event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL ? "NONLINEAR_VIRTUAL" :
797 (event->crossing.detail == GDK_NOTIFY_UNKNOWN ? "UNKNOWN" :
799 event->crossing.focus ? " FOCUS" : "");
800 print_event_state (event->crossing.state);
802 case GDK_FOCUS_CHANGE:
803 g_print ("%s", (event->focus_change.in ? "IN" : "OUT"));
806 g_print ("x:%d y:%d w:%d h:%d",
807 event->configure.x, event->configure.y,
808 event->configure.width, event->configure.height);
810 case GDK_SELECTION_CLEAR:
811 case GDK_SELECTION_REQUEST:
812 case GDK_SELECTION_NOTIFY:
813 selection_name = gdk_atom_name (event->selection.selection);
814 target_name = gdk_atom_name (event->selection.target);
815 property_name = gdk_atom_name (event->selection.property);
816 g_print ("sel:%s tgt:%s prop:%s",
817 selection_name, target_name, property_name);
818 g_free (selection_name);
819 g_free (target_name);
820 g_free (property_name);
824 case GDK_DRAG_MOTION:
825 case GDK_DRAG_STATUS:
827 case GDK_DROP_FINISHED:
828 if (event->dnd.context != NULL)
829 g_print ("ctx:%p: %s %s src:%p dest:%p",
831 _gdk_win32_drag_protocol_to_string (event->dnd.context->protocol),
832 event->dnd.context->is_source ? "SOURCE" : "DEST",
833 event->dnd.context->source_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->source_window),
834 event->dnd.context->dest_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->dest_window));
836 case GDK_CLIENT_EVENT:
837 g_print ("%s %d %ld %ld %ld %ld %ld",
838 gdk_atom_name (event->client.message_type),
839 event->client.data_format,
840 event->client.data.l[0],
841 event->client.data.l[1],
842 event->client.data.l[2],
843 event->client.data.l[3],
844 event->client.data.l[4]);
847 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",
848 event->scroll.x, event->scroll.y,
849 event->scroll.x_root, event->scroll.y_root,
850 (event->scroll.direction == GDK_SCROLL_UP ? "UP" :
851 (event->scroll.direction == GDK_SCROLL_DOWN ? "DOWN" :
852 (event->scroll.direction == GDK_SCROLL_LEFT ? "LEFT" :
853 (event->scroll.direction == GDK_SCROLL_RIGHT ? "RIGHT" :
855 print_event_state (event->scroll.state);
857 case GDK_WINDOW_STATE:
859 _gdk_win32_window_state_to_string (event->window_state.changed_mask),
860 _gdk_win32_window_state_to_string (event->window_state.new_window_state));
863 (event->setting.action == GDK_SETTING_ACTION_NEW ? "NEW" :
864 (event->setting.action == GDK_SETTING_ACTION_CHANGED ? "CHANGED" :
865 (event->setting.action == GDK_SETTING_ACTION_DELETED ? "DELETED" :
867 (event->setting.name ? event->setting.name : "NULL"));
868 case GDK_GRAB_BROKEN:
870 (event->grab_broken.keyboard ? "KEYBOARD" : "POINTER"),
871 (event->grab_broken.implicit ? "IMPLICIT" : "EXPLICIT"),
872 (event->grab_broken.grab_window ? GDK_WINDOW_HWND (event->grab_broken.grab_window) : 0));
877 g_print ("%s", (debug_indent == 0 ? "\n" : ""));
881 decode_key_lparam (LPARAM lParam)
883 static char buf[100];
886 if (HIWORD (lParam) & KF_UP)
887 p += g_sprintf (p, "KF_UP ");
888 if (HIWORD (lParam) & KF_REPEAT)
889 p += g_sprintf (p, "KF_REPEAT ");
890 if (HIWORD (lParam) & KF_ALTDOWN)
891 p += g_sprintf (p, "KF_ALTDOWN ");
892 if (HIWORD (lParam) & KF_EXTENDED)
893 p += g_sprintf (p, "KF_EXTENDED ");
894 p += g_sprintf (p, "sc:%d rep:%d", LOBYTE (HIWORD (lParam)), LOWORD (lParam));
902 fixup_event (GdkEvent *event)
904 if (event->any.window)
905 g_object_ref (event->any.window);
906 if (((event->any.type == GDK_ENTER_NOTIFY) ||
907 (event->any.type == GDK_LEAVE_NOTIFY)) &&
908 (event->crossing.subwindow != NULL))
909 g_object_ref (event->crossing.subwindow);
910 event->any.send_event = InSendMessage ();
914 append_event (GdkEvent *event)
920 link = _gdk_event_queue_append (_gdk_display, event);
921 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
922 /* event morphing, the passed in may not be valid afterwards */
923 _gdk_windowing_got_event (_gdk_display, link, event, 0);
925 _gdk_event_queue_append (_gdk_display, event);
926 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
931 fill_key_event_string (GdkEvent *event)
936 /* Fill in event->string crudely, since various programs
941 if (event->key.keyval != GDK_KEY_VoidSymbol)
942 c = gdk_keyval_to_unicode (event->key.keyval);
949 /* Apply the control key - Taken from Xlib
951 if (event->key.state & GDK_CONTROL_MASK)
953 if ((c >= '@' && c < '\177') || c == ' ')
957 event->key.string = g_memdup ("\0\0", 2);
958 event->key.length = 1;
961 else if (c >= '3' && c <= '7')
969 len = g_unichar_to_utf8 (c, buf);
972 event->key.string = g_locale_from_utf8 (buf, len,
973 NULL, &bytes_written,
975 if (event->key.string)
976 event->key.length = bytes_written;
978 else if (event->key.keyval == GDK_KEY_Escape)
980 event->key.length = 1;
981 event->key.string = g_strdup ("\033");
983 else if (event->key.keyval == GDK_KEY_Return ||
984 event->key.keyval == GDK_KEY_KP_Enter)
986 event->key.length = 1;
987 event->key.string = g_strdup ("\r");
990 if (!event->key.string)
992 event->key.length = 0;
993 event->key.string = g_strdup ("");
997 static GdkFilterReturn
998 apply_event_filters (GdkWindow *window,
1002 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1007 event = gdk_event_new (GDK_NOTHING);
1009 event->any.window = g_object_ref (window);
1010 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1012 /* I think GdkFilterFunc semantics require the passed-in event
1013 * to already be in the queue. The filter func can generate
1014 * more events and append them after it if it likes.
1016 node = _gdk_event_queue_append (_gdk_display, event);
1018 tmp_list = *filters;
1021 GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
1024 if ((filter->flags & GDK_EVENT_FILTER_REMOVED) != 0)
1026 tmp_list = tmp_list->next;
1030 filter->ref_count++;
1031 result = filter->function (msg, event, filter->data);
1033 /* get the next node after running the function since the
1034 function may add or remove a next node */
1036 tmp_list = tmp_list->next;
1038 filter->ref_count--;
1039 if (filter->ref_count == 0)
1041 *filters = g_list_remove_link (*filters, node);
1042 g_list_free_1 (node);
1046 if (result != GDK_FILTER_CONTINUE)
1050 if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
1052 _gdk_event_queue_remove_link (_gdk_display, node);
1053 g_list_free_1 (node);
1054 gdk_event_free (event);
1056 else /* GDK_FILTER_TRANSLATE */
1058 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1059 fixup_event (event);
1060 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1066 * On Windows, transient windows will not have their own taskbar entries.
1067 * Because of this, we must hide and restore groups of transients in both
1068 * directions. That is, all transient children must be hidden or restored
1069 * with this window, but if this window's transient owner also has a
1070 * transient owner then this window's transient owner must be hidden/restored
1071 * with this one. And etc, up the chain until we hit an ancestor that has no
1074 * It would be a good idea if applications don't chain transient windows
1075 * together. There's a limit to how much evil GTK can try to shield you
1079 show_window_recurse (GdkWindow *window, gboolean hide_window)
1081 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1082 GSList *children = impl->transient_children;
1083 GdkWindow *child = NULL;
1085 if (!impl->changing_state)
1087 impl->changing_state = TRUE;
1089 if (children != NULL)
1091 while (children != NULL)
1093 child = children->data;
1094 show_window_recurse (child, hide_window);
1096 children = g_slist_next (children);
1100 if (GDK_WINDOW_IS_MAPPED (window))
1104 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_ICONIFIED)
1106 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED)
1108 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
1112 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1118 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
1122 impl->changing_state = FALSE;
1127 do_show_window (GdkWindow *window, gboolean hide_window)
1129 GdkWindow *tmp_window = NULL;
1130 GdkWindowImplWin32 *tmp_impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1132 if (!tmp_impl->changing_state)
1134 /* Find the top-level window in our transient chain. */
1135 while (tmp_impl->transient_owner != NULL)
1137 tmp_window = tmp_impl->transient_owner;
1138 tmp_impl = GDK_WINDOW_IMPL_WIN32 (tmp_window->impl);
1141 /* If we couldn't find one, use the window provided. */
1142 if (tmp_window == NULL)
1144 tmp_window = window;
1147 /* Recursively show/hide every window in the chain. */
1148 if (tmp_window != window)
1150 show_window_recurse (tmp_window, hide_window);
1156 synthesize_enter_or_leave_event (GdkWindow *window,
1159 GdkCrossingMode mode,
1160 GdkNotifyType detail)
1166 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1168 event = gdk_event_new (type);
1169 event->crossing.window = window;
1170 event->crossing.subwindow = NULL;
1171 event->crossing.time = _gdk_win32_get_next_tick (msg->time);
1172 event->crossing.x = pt.x;
1173 event->crossing.y = pt.y;
1174 event->crossing.x_root = msg->pt.x + _gdk_offset_x;
1175 event->crossing.y_root = msg->pt.y + _gdk_offset_y;
1176 event->crossing.mode = mode;
1177 event->crossing.detail = detail;
1178 event->crossing.focus = TRUE; /* FIXME: Set correctly */
1179 event->crossing.state = 0; /* FIXME: Set correctly */
1180 gdk_event_set_device (event, _gdk_display->core_pointer);
1182 append_event (event);
1184 if (type == GDK_ENTER_NOTIFY &&
1185 window->extension_events != 0)
1186 _gdk_device_wintab_update_window_coords (window);
1189 /* The check_extended flag controls whether to check if the windows want
1190 * events from extended input devices and if the message should be skipped
1191 * because an extended input device is active
1194 propagate (GdkWindow **window,
1196 GdkWindow *grab_window,
1197 gboolean grab_owner_events,
1199 gboolean (*doesnt_want_it) (gint mask,
1201 gboolean check_extended)
1203 if (grab_window != NULL && !grab_owner_events)
1205 /* Event source is grabbed with owner_events FALSE */
1207 /* See if the event should be ignored because an extended input
1210 if (check_extended &&
1211 grab_window->extension_events != 0 &&
1212 _gdk_input_ignore_core)
1214 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1217 if ((*doesnt_want_it) (grab_mask, msg))
1219 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1224 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1225 assign_object (window, grab_window);
1230 /* If we come here, we know that if grab_window != NULL then
1231 * grab_owner_events is TRUE
1235 if (check_extended &&
1236 (*window)->extension_events != 0 &&
1237 _gdk_input_ignore_core)
1239 GDK_NOTE (EVENTS, g_print (" (ignored)"));
1242 if ((*doesnt_want_it) ((*window)->event_mask, msg))
1244 /* Owner doesn't want it, propagate to parent. */
1245 GdkWindow *parent = gdk_window_get_parent (*window);
1246 if (parent == _gdk_root || parent == NULL)
1248 /* No parent; check if grabbed */
1249 if (grab_window != NULL)
1251 /* Event source is grabbed with owner_events TRUE */
1253 if (check_extended &&
1254 grab_window->extension_events != 0 &&
1255 _gdk_input_ignore_core)
1257 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1260 if ((*doesnt_want_it) (grab_mask, msg))
1262 /* Grabber doesn't want it either */
1263 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1269 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1270 assign_object (window, grab_window);
1276 GDK_NOTE (EVENTS, g_print (" (undelivered)"));
1282 assign_object (window, parent);
1283 /* The only branch where we actually continue the loop */
1292 doesnt_want_key (gint mask,
1295 return (((msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) &&
1296 !(mask & GDK_KEY_RELEASE_MASK)) ||
1297 ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) &&
1298 !(mask & GDK_KEY_PRESS_MASK)));
1302 doesnt_want_char (gint mask,
1305 return !(mask & (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK));
1309 handle_configure_event (MSG *msg,
1315 GetClientRect (msg->hwnd, &client_rect);
1316 point.x = client_rect.left; /* always 0 */
1317 point.y = client_rect.top;
1319 /* top level windows need screen coords */
1320 if (gdk_window_get_parent (window) == _gdk_root)
1322 ClientToScreen (msg->hwnd, &point);
1323 point.x += _gdk_offset_x;
1324 point.y += _gdk_offset_y;
1327 window->width = client_rect.right - client_rect.left;
1328 window->height = client_rect.bottom - client_rect.top;
1330 window->x = point.x;
1331 window->y = point.y;
1333 _gdk_window_update_size (window);
1335 if (window->event_mask & GDK_STRUCTURE_MASK)
1337 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1339 event->configure.window = window;
1341 event->configure.width = client_rect.right - client_rect.left;
1342 event->configure.height = client_rect.bottom - client_rect.top;
1344 event->configure.x = point.x;
1345 event->configure.y = point.y;
1347 append_event (event);
1352 _gdk_win32_hrgn_to_region (HRGN hrgn)
1356 cairo_region_t *result;
1360 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1362 WIN32_GDI_FAILED ("GetRegionData");
1366 rgndata = (RGNDATA *) g_malloc (nbytes);
1368 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1370 WIN32_GDI_FAILED ("GetRegionData");
1375 result = cairo_region_create ();
1376 rects = (RECT *) rgndata->Buffer;
1377 for (i = 0; i < rgndata->rdh.nCount; i++)
1381 r.x = rects[i].left;
1383 r.width = rects[i].right - r.x;
1384 r.height = rects[i].bottom - r.y;
1386 cairo_region_union_rectangle (result, &r);
1395 adjust_drag (LONG *drag,
1400 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1402 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1406 handle_wm_paint (MSG *msg,
1408 gboolean return_exposes,
1411 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1413 PAINTSTRUCT paintstruct;
1414 cairo_region_t *update_region;
1416 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1418 WIN32_GDI_FAILED ("GetUpdateRgn");
1419 DeleteObject (hrgn);
1423 hdc = BeginPaint (msg->hwnd, &paintstruct);
1425 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1426 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1427 (paintstruct.fErase ? "erase" : ""),
1429 (return_exposes ? " return_exposes" : "")));
1431 EndPaint (msg->hwnd, &paintstruct);
1433 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1434 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1436 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1437 DeleteObject (hrgn);
1443 if (!GDK_WINDOW_DESTROYED (window))
1445 GList *list = _gdk_display->queued_events;
1447 *event = gdk_event_new (GDK_EXPOSE);
1448 (*event)->expose.window = window;
1449 (*event)->expose.area.x = paintstruct.rcPaint.left;
1450 (*event)->expose.area.y = paintstruct.rcPaint.top;
1451 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1452 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1453 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1454 (*event)->expose.count = 0;
1456 while (list != NULL)
1458 GdkEventPrivate *evp = list->data;
1460 if (evp->event.any.type == GDK_EXPOSE &&
1461 evp->event.any.window == window &&
1462 !(evp->flags & GDK_EVENT_PENDING))
1463 evp->event.expose.count++;
1469 DeleteObject (hrgn);
1473 update_region = _gdk_win32_hrgn_to_region (hrgn);
1474 if (!cairo_region_is_empty (update_region))
1475 _gdk_window_invalidate_for_expose (window, update_region);
1476 cairo_region_destroy (update_region);
1478 DeleteObject (hrgn);
1481 static VOID CALLBACK
1482 modal_timer_proc (HWND hwnd,
1487 int arbitrary_limit = 1;
1489 while (_modal_operation_in_progress &&
1490 g_main_context_pending (NULL) &&
1492 g_main_context_iteration (NULL, FALSE);
1496 _gdk_win32_begin_modal_call (void)
1498 g_assert (!_modal_operation_in_progress);
1500 _modal_operation_in_progress = TRUE;
1502 modal_timer = SetTimer (NULL, 0, 10, modal_timer_proc);
1503 if (modal_timer == 0)
1504 WIN32_API_FAILED ("SetTimer");
1508 _gdk_win32_end_modal_call (void)
1510 g_assert (_modal_operation_in_progress);
1512 _modal_operation_in_progress = FALSE;
1514 if (modal_timer != 0)
1516 API_CALL (KillTimer, (NULL, modal_timer));
1521 static VOID CALLBACK
1522 sync_timer_proc (HWND hwnd,
1528 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1533 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1535 KillTimer (hwnd, sync_timer);
1539 handle_display_change (void)
1541 _gdk_monitor_init ();
1542 _gdk_root_window_size_init ();
1543 g_signal_emit_by_name (_gdk_screen, "size_changed");
1547 generate_button_event (GdkEventType type,
1552 GdkEvent *event = gdk_event_new (type);
1554 event->button.window = window;
1555 event->button.time = _gdk_win32_get_next_tick (msg->time);
1556 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1557 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1558 event->button.x_root = msg->pt.x + _gdk_offset_x;
1559 event->button.y_root = msg->pt.y + _gdk_offset_y;
1560 event->button.axes = NULL;
1561 event->button.state = build_pointer_event_state (msg);
1562 event->button.button = button;
1563 gdk_event_set_device (event, _gdk_display->core_pointer);
1565 append_event (event);
1569 ensure_stacking_on_unminimize (MSG *msg)
1572 HWND lowest_transient = NULL;
1575 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1577 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1579 /* Checking window group not implemented yet */
1582 GdkWindowImplWin32 *rover_impl =
1583 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1585 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1586 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1587 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1588 rover_impl->transient_owner != NULL))
1590 lowest_transient = rover;
1594 if (lowest_transient != NULL)
1596 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1597 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1598 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1603 ensure_stacking_on_window_pos_changing (MSG *msg,
1606 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1607 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1609 if (GetActiveWindow () == msg->hwnd &&
1610 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1611 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1612 impl->transient_owner == NULL)
1614 /* Make sure the window stays behind any transient-type windows
1615 * of the same window group.
1617 * If the window is not active and being activated, we let
1618 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1619 * handling to bring any utility windows on top of it.
1622 gboolean restacking;
1624 rover = windowpos->hwndInsertAfter;
1628 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1630 /* Checking window group not implemented yet */
1633 GdkWindowImplWin32 *rover_impl =
1634 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1636 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1637 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1638 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1639 rover_impl->transient_owner != NULL))
1642 windowpos->hwndInsertAfter = rover;
1645 rover = GetNextWindow (rover, GW_HWNDNEXT);
1650 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1658 ensure_stacking_on_activate_app (MSG *msg,
1661 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1663 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1664 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1665 impl->transient_owner != NULL)
1667 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1668 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1672 if (IsWindowVisible (msg->hwnd) &&
1673 msg->hwnd == GetActiveWindow ())
1675 /* This window is not a transient-type window and it is the
1676 * activated window. Make sure this window is as visible as
1677 * possible, just below the lowest transient-type window of this
1683 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
1685 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1687 /* Checking window group not implemented yet */
1690 GdkWindowImplWin32 *rover_impl =
1691 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1693 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1694 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1695 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1696 rover_impl->transient_owner != NULL))
1698 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1699 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1700 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1709 gdk_event_translate (MSG *msg,
1712 RECT rect, *drag, orig_drag;
1717 BYTE key_state[256];
1719 WINDOWPOS *windowpos;
1726 GdkWindow *window = NULL;
1727 GdkWindowImplWin32 *impl;
1729 GdkWindow *orig_window, *new_window, *toplevel;
1731 GdkDeviceManager *device_manager;
1733 GdkDeviceGrabInfo *keyboard_grab = NULL;
1734 GdkDeviceGrabInfo *pointer_grab = NULL;
1735 GdkWindow *grab_window = NULL;
1741 gboolean return_val = FALSE;
1745 if (_gdk_default_filters)
1747 /* Apply global filters */
1749 GdkFilterReturn result = apply_event_filters (NULL, msg, &_gdk_default_filters);
1751 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1752 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1753 * we return TRUE, and DefWindowProcW() will not be called.
1755 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1759 window = gdk_win32_handle_table_lookup ((GdkNativeWindow) msg->hwnd);
1760 orig_window = window;
1764 /* XXX Handle WM_QUIT here ? */
1765 if (msg->message == WM_QUIT)
1767 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1770 else if (msg->message == WM_MOVE ||
1771 msg->message == WM_SIZE)
1773 /* It's quite normal to get these messages before we have
1774 * had time to register the window in our lookup table, or
1775 * when the window is being destroyed and we already have
1776 * removed it. Repost the same message to our queue so that
1777 * we will get it later when we are prepared.
1779 GDK_NOTE (EVENTS, g_print (" (posted)"));
1781 PostMessageW (msg->hwnd, msg->message, msg->wParam, msg->lParam);
1783 else if (msg->message == WM_CREATE)
1785 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1786 GDK_WINDOW_HWND (window) = msg->hwnd;
1790 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1795 device_manager = gdk_display_get_device_manager (_gdk_display);
1797 keyboard_grab = _gdk_display_get_last_device_grab (_gdk_display,
1798 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
1799 pointer_grab = _gdk_display_get_last_device_grab (_gdk_display,
1800 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer);
1802 g_object_ref (window);
1804 /* window's refcount has now been increased, so code below should
1805 * not just return from this function, but instead goto done (or
1806 * break out of the big switch). To protect against forgetting this,
1807 * #define return to a syntax error...
1809 #define return GOTO_DONE_INSTEAD
1811 if (!GDK_WINDOW_DESTROYED (window) && window->filters)
1813 /* Apply per-window filters */
1815 GdkFilterReturn result = apply_event_filters (window, msg, &window->filters);
1817 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1824 if (msg->message == client_message)
1827 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1830 GDK_NOTE (EVENTS, g_print (" client_message"));
1832 event = gdk_event_new (GDK_NOTHING);
1833 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1835 node = _gdk_event_queue_append (_gdk_display, event);
1837 tmp_list = client_filters;
1840 GdkClientFilter *filter = tmp_list->data;
1842 tmp_list = tmp_list->next;
1844 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
1846 GDK_NOTE (EVENTS, g_print (" (match)"));
1848 result = (*filter->function) (msg, event, filter->data);
1850 if (result != GDK_FILTER_CONTINUE)
1857 case GDK_FILTER_REMOVE:
1858 _gdk_event_queue_remove_link (_gdk_display, node);
1859 g_list_free_1 (node);
1860 gdk_event_free (event);
1864 case GDK_FILTER_TRANSLATE:
1865 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1866 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1870 case GDK_FILTER_CONTINUE:
1871 /* Send unknown client messages on to Gtk for it to use */
1873 event->client.type = GDK_CLIENT_EVENT;
1874 event->client.window = window;
1875 event->client.message_type = GDK_POINTER_TO_ATOM (msg->wParam);
1876 event->client.data_format = 32;
1877 event->client.data.l[0] = msg->lParam;
1878 for (i = 1; i < 5; i++)
1879 event->client.data.l[i] = 0;
1880 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1886 switch (msg->message)
1888 case WM_INPUTLANGCHANGE:
1889 _gdk_input_locale = (HKL) msg->lParam;
1890 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
1891 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
1892 LOCALE_IDEFAULTANSICODEPAGE,
1894 _gdk_input_codepage = atoi (buf);
1895 _gdk_keymap_serial++;
1897 g_print (" cs:%lu hkl:%p%s cp:%d",
1898 (gulong) msg->wParam,
1899 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
1900 _gdk_input_codepage));
1906 g_print (" %s ch:%.02x %s",
1907 _gdk_win32_key_to_string (msg->lParam),
1909 decode_key_lparam (msg->lParam)));
1911 /* If posted without us having keyboard focus, ignore */
1912 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
1913 !(HIWORD (msg->lParam) & KF_ALTDOWN))
1916 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
1917 * the keyboard is grabbed.
1919 if (!keyboard_grab &&
1920 (msg->wParam == VK_TAB ||
1921 msg->wParam == VK_SPACE ||
1922 msg->wParam == VK_F4))
1925 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
1931 g_print (" %s ch:%.02x %s",
1932 _gdk_win32_key_to_string (msg->lParam),
1934 decode_key_lparam (msg->lParam)));
1938 /* Ignore key messages intended for the IME */
1939 if (msg->wParam == VK_PROCESSKEY ||
1943 if (keyboard_grab &&
1944 !propagate (&window, msg,
1945 keyboard_grab->window,
1946 keyboard_grab->owner_events,
1947 GDK_ALL_EVENTS_MASK,
1948 doesnt_want_key, FALSE))
1951 if (GDK_WINDOW_DESTROYED (window))
1954 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
1955 msg->message == WM_SYSKEYDOWN) ?
1956 GDK_KEY_PRESS : GDK_KEY_RELEASE);
1957 event->key.window = window;
1958 event->key.time = _gdk_win32_get_next_tick (msg->time);
1959 event->key.keyval = GDK_KEY_VoidSymbol;
1960 event->key.string = NULL;
1961 event->key.length = 0;
1962 event->key.hardware_keycode = msg->wParam;
1963 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
1964 if (HIWORD (msg->lParam) & KF_EXTENDED)
1966 switch (msg->wParam)
1969 event->key.hardware_keycode = VK_RCONTROL;
1971 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
1972 * for the right shift key.
1974 event->key.hardware_keycode = VK_RSHIFT;
1977 event->key.hardware_keycode = VK_RMENU;
1981 else if (msg->wParam == VK_SHIFT &&
1982 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
1983 event->key.hardware_keycode = VK_RSHIFT;
1985 API_CALL (GetKeyboardState, (key_state));
1987 /* 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]); */
1989 build_key_event_state (event, key_state);
1991 gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (_gdk_display),
1992 event->key.hardware_keycode,
1998 fill_key_event_string (event);
2000 /* Reset MOD1_MASK if it is the Alt key itself */
2001 if (msg->wParam == VK_MENU)
2002 event->key.state &= ~GDK_MOD1_MASK;
2004 append_event (event);
2010 if (msg->wParam != VK_SPACE)
2012 /* To prevent beeps, don't let DefWindowProcW() be called */
2018 case WM_IME_STARTCOMPOSITION:
2019 in_ime_composition = TRUE;
2022 case WM_IME_ENDCOMPOSITION:
2023 in_ime_composition = FALSE;
2026 case WM_IME_COMPOSITION:
2027 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2028 * applications. Thus, handle WM_IME_COMPOSITION with
2029 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2030 * with ImmGetCompositionStringW().
2033 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2035 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2036 * for comments by other people that seems to have the same
2037 * experience. WM_IME_CHAR just gives question marks, apparently
2038 * because of going through some conversion to the current code
2041 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2042 * use WM_IME_COMPOSITION there, too, to simplify the code.
2044 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2046 if (!(msg->lParam & GCS_RESULTSTR))
2049 if (keyboard_grab &&
2050 !propagate (&window, msg,
2051 keyboard_grab->window,
2052 keyboard_grab->owner_events,
2053 GDK_ALL_EVENTS_MASK,
2054 doesnt_want_char, FALSE))
2057 if (GDK_WINDOW_DESTROYED (window))
2060 himc = ImmGetContext (msg->hwnd);
2061 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2062 wbuf, sizeof (wbuf));
2063 ImmReleaseContext (msg->hwnd, himc);
2067 API_CALL (GetKeyboardState, (key_state));
2069 for (i = 0; i < ccount; i++)
2071 if (window->event_mask & GDK_KEY_PRESS_MASK)
2073 /* Build a key press event */
2074 event = gdk_event_new (GDK_KEY_PRESS);
2075 event->key.window = window;
2076 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2077 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2079 append_event (event);
2082 if (window->event_mask & GDK_KEY_RELEASE_MASK)
2084 /* Build a key release event. */
2085 event = gdk_event_new (GDK_KEY_RELEASE);
2086 event->key.window = window;
2087 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2088 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2090 append_event (event);
2096 case WM_LBUTTONDOWN:
2100 case WM_MBUTTONDOWN:
2104 case WM_RBUTTONDOWN:
2108 case WM_XBUTTONDOWN:
2109 if (HIWORD (msg->wParam) == XBUTTON1)
2116 g_print (" (%d,%d)",
2117 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2119 assign_object (&window, find_window_for_mouse_event (window, msg));
2120 /* TODO_CSW?: there used to some synthesize and propagate */
2121 if (GDK_WINDOW_DESTROYED (window))
2124 /* TODO_CSW? Emulate X11's automatic active grab */
2125 generate_button_event (GDK_BUTTON_PRESS, button,
2144 if (HIWORD (msg->wParam) == XBUTTON1)
2151 g_print (" (%d,%d)",
2152 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2154 assign_object (&window, find_window_for_mouse_event (window, msg));
2156 if (window->extension_events != 0 &&
2157 _gdk_input_ignore_core)
2159 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2164 generate_button_event (GDK_BUTTON_RELEASE, button,
2172 g_print (" %p (%d,%d)",
2173 (gpointer) msg->wParam,
2174 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2176 assign_object (&window, find_window_for_mouse_event (window, msg));
2177 toplevel = gdk_window_get_toplevel (window);
2178 if (current_toplevel != toplevel)
2180 GDK_NOTE (EVENTS, g_print (" toplevel %p -> %p",
2181 current_toplevel ? GDK_WINDOW_HWND (current_toplevel) : NULL,
2182 toplevel ? GDK_WINDOW_HWND (toplevel) : NULL));
2183 if (current_toplevel)
2184 synthesize_enter_or_leave_event (current_toplevel, msg,
2185 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2186 synthesize_enter_or_leave_event (toplevel, msg,
2187 GDK_ENTER_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2188 assign_object (¤t_toplevel, toplevel);
2189 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (toplevel));
2192 /* If we haven't moved, don't create any GDK event. Windows
2193 * sends WM_MOUSEMOVE messages after a new window is shows under
2194 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2196 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2197 msg->pt.y + _gdk_offset_y == current_root_y)
2200 current_root_x = msg->pt.x + _gdk_offset_x;
2201 current_root_y = msg->pt.y + _gdk_offset_y;
2203 event = gdk_event_new (GDK_MOTION_NOTIFY);
2204 event->motion.window = window;
2205 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2206 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2207 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2208 event->motion.x_root = current_root_x;
2209 event->motion.y_root = current_root_y;
2210 event->motion.axes = NULL;
2211 event->motion.state = build_pointer_event_state (msg);
2212 event->motion.is_hint = FALSE;
2213 gdk_event_set_device (event, _gdk_display->core_pointer);
2215 append_event (event);
2220 case WM_NCMOUSEMOVE:
2222 g_print (" (%d,%d)",
2223 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2224 #if 0 /* TODO_CSW? */
2225 if (current_toplevel != NULL &&
2226 (current_toplevel->event_mask & GDK_LEAVE_NOTIFY_MASK))
2228 synthesize_enter_or_leave_event (current_toplevel, msg,
2229 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2235 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2236 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2238 if (!gdk_win32_handle_table_lookup ((GdkNativeWindow) WindowFromPoint (msg->pt)))
2240 /* we are only interested if we don't know the new window */
2241 if (current_toplevel)
2242 synthesize_enter_or_leave_event (current_toplevel, msg,
2243 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2244 assign_object (¤t_toplevel, NULL);
2248 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2255 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2257 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2258 * that. Also, the position is in screen coordinates, not client
2259 * coordinates as with the button messages. I love the
2260 * consistency of Windows.
2262 point.x = GET_X_LPARAM (msg->lParam);
2263 point.y = GET_Y_LPARAM (msg->lParam);
2265 if ((hwnd = WindowFromPoint (point)) == NULL)
2269 if ((new_window = gdk_win32_handle_table_lookup ((GdkNativeWindow) msg->hwnd)) == NULL)
2272 if (new_window != window)
2274 assign_object (&window, new_window);
2277 ScreenToClient (msg->hwnd, &point);
2279 event = gdk_event_new (GDK_SCROLL);
2280 event->scroll.window = window;
2281 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2282 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2283 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2284 event->scroll.x = (gint16) point.x;
2285 event->scroll.y = (gint16) point.y;
2286 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2287 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2288 event->scroll.state = build_pointer_event_state (msg);
2289 gdk_event_set_device (event, _gdk_display->core_pointer);
2291 append_event (event);
2297 /* Just print more debugging information, don't actually handle it. */
2300 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2301 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2302 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2303 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2304 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2305 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2306 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2307 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2308 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2310 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2311 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2312 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2316 /* Just print more debugging information, don't actually handle it. */
2319 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2320 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2321 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2322 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2323 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2324 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2325 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2326 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2327 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2329 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2330 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2331 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2334 case WM_MOUSEACTIVATE:
2338 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2339 || !window->accept_focus)
2341 *ret_valp = MA_NOACTIVATE;
2345 tmp = _gdk_modal_current ();
2349 if (gdk_window_get_toplevel (window) != tmp)
2351 *ret_valp = MA_NOACTIVATEANDEAT;
2360 if (keyboard_grab != NULL &&
2361 !GDK_WINDOW_DESTROYED (keyboard_grab->window))
2363 generate_grab_broken_event (device_manager, keyboard_grab->window, TRUE, NULL);
2368 if (keyboard_grab != NULL &&
2369 !keyboard_grab->owner_events)
2372 if (!(window->event_mask & GDK_FOCUS_CHANGE_MASK))
2375 if (GDK_WINDOW_DESTROYED (window))
2378 generate_focus_event (device_manager, window, (msg->message == WM_SETFOCUS));
2383 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2385 if (GDK_WINDOW_DESTROYED (window))
2393 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2395 200, sync_timer_proc);
2399 handle_wm_paint (msg, window, FALSE, NULL);
2403 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2404 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2406 if (pointer_grab != NULL)
2407 grab_window = pointer_grab->window;
2409 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2412 if (grab_window != NULL && p_grab_cursor != NULL)
2413 hcursor = p_grab_cursor;
2414 else if (!GDK_WINDOW_DESTROYED (window))
2415 hcursor = GDK_WINDOW_IMPL_WIN32 (window->impl)->hcursor;
2419 if (hcursor != NULL)
2421 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2422 SetCursor (hcursor);
2429 GDK_NOTE (EVENTS, g_print (" %s %s",
2430 (msg->wParam ? "YES" : "NO"),
2431 (msg->lParam == 0 ? "ShowWindow" :
2432 (msg->lParam == SW_OTHERUNZOOM ? "OTHERUNZOOM" :
2433 (msg->lParam == SW_OTHERZOOM ? "OTHERZOOM" :
2434 (msg->lParam == SW_PARENTCLOSING ? "PARENTCLOSING" :
2435 (msg->lParam == SW_PARENTOPENING ? "PARENTOPENING" :
2438 if (!(window->event_mask & GDK_STRUCTURE_MASK))
2441 if (msg->lParam == SW_OTHERUNZOOM ||
2442 msg->lParam == SW_OTHERZOOM)
2445 if (GDK_WINDOW_DESTROYED (window))
2448 event = gdk_event_new (msg->wParam ? GDK_MAP : GDK_UNMAP);
2449 event->any.window = window;
2451 append_event (event);
2453 if (event->any.type == GDK_UNMAP)
2455 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2457 if (impl->transient_owner && GetForegroundWindow () == GDK_WINDOW_HWND (window))
2459 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2462 if (pointer_grab != NULL)
2464 if (pointer_grab->window == window)
2465 gdk_pointer_ungrab (msg->time);
2468 if (keyboard_grab &&
2469 keyboard_grab->window == window)
2470 gdk_keyboard_ungrab (msg->time);
2477 switch (msg->wParam)
2481 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2489 g_print (" %s %dx%d",
2490 (msg->wParam == SIZE_MAXHIDE ? "MAXHIDE" :
2491 (msg->wParam == SIZE_MAXIMIZED ? "MAXIMIZED" :
2492 (msg->wParam == SIZE_MAXSHOW ? "MAXSHOW" :
2493 (msg->wParam == SIZE_MINIMIZED ? "MINIMIZED" :
2494 (msg->wParam == SIZE_RESTORED ? "RESTORED" : "?"))))),
2495 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2497 if (msg->wParam == SIZE_MINIMIZED)
2499 /* Don't generate any GDK event. This is *not* an UNMAP. */
2500 if (pointer_grab != NULL)
2502 if (pointer_grab->window == window)
2503 gdk_pointer_ungrab (msg->time);
2505 if (keyboard_grab &&
2506 keyboard_grab->window == window)
2507 gdk_keyboard_ungrab (msg->time);
2509 gdk_synthesize_window_state (window,
2510 GDK_WINDOW_STATE_WITHDRAWN,
2511 GDK_WINDOW_STATE_ICONIFIED);
2512 do_show_window (window, TRUE);
2514 else if ((msg->wParam == SIZE_RESTORED ||
2515 msg->wParam == SIZE_MAXIMIZED) &&
2516 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
2518 GdkWindowState withdrawn_bit =
2519 IsWindowVisible (msg->hwnd) ? GDK_WINDOW_STATE_WITHDRAWN : 0;
2521 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
2522 ensure_stacking_on_unminimize (msg);
2524 if (!GDK_WINDOW_DESTROYED (window))
2525 handle_configure_event (msg, window);
2527 if (msg->wParam == SIZE_RESTORED)
2529 gdk_synthesize_window_state (window,
2530 GDK_WINDOW_STATE_ICONIFIED |
2531 GDK_WINDOW_STATE_MAXIMIZED |
2535 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_TEMP && !GDK_WINDOW_IS_MAPPED (window))
2537 do_show_window (window, FALSE);
2540 else if (msg->wParam == SIZE_MAXIMIZED)
2542 gdk_synthesize_window_state (window,
2543 GDK_WINDOW_STATE_ICONIFIED |
2545 GDK_WINDOW_STATE_MAXIMIZED);
2548 if (window->resize_count > 1)
2549 window->resize_count -= 1;
2551 if (window->extension_events != 0)
2552 _gdk_device_wintab_update_window_coords (window);
2558 case WM_ENTERSIZEMOVE:
2559 case WM_ENTERMENULOOP:
2560 _gdk_win32_begin_modal_call ();
2563 case WM_EXITSIZEMOVE:
2564 case WM_EXITMENULOOP:
2565 _gdk_win32_end_modal_call ();
2568 case WM_WINDOWPOSCHANGING:
2569 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2570 g_print (" %s %s %dx%d@%+d%+d now below %p",
2571 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2572 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2573 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2574 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2575 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2576 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2578 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2579 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2581 if (GDK_WINDOW_IS_MAPPED (window))
2582 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2585 case WM_WINDOWPOSCHANGED:
2586 windowpos = (WINDOWPOS *) msg->lParam;
2587 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2588 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2589 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2590 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2591 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2592 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2593 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2595 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2597 /* If position and size haven't changed, don't do anything */
2598 if (_modal_operation_in_progress &&
2599 (windowpos->flags & SWP_NOMOVE) &&
2600 (windowpos->flags & SWP_NOSIZE))
2603 /* Once we've entered the moving or sizing modal loop, we won't
2604 * return to the main loop until we're done sizing or moving.
2606 if (_modal_operation_in_progress &&
2607 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2608 !GDK_WINDOW_DESTROYED (window))
2610 if (window->event_mask & GDK_STRUCTURE_MASK)
2612 GDK_NOTE (EVENTS, g_print (" do magic"));
2613 if (window->resize_count > 1)
2614 window->resize_count -= 1;
2616 handle_configure_event (msg, window);
2617 g_main_context_iteration (NULL, FALSE);
2619 /* Dispatch main loop - to realize resizes... */
2620 modal_timer_proc (msg->hwnd, msg->message, 0, msg->time);
2622 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2630 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2631 drag = (RECT *) msg->lParam;
2632 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2633 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2634 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2635 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2636 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2637 (msg->wParam == WMSZ_TOP ? "TOP" :
2638 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2639 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2641 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2643 _gdk_win32_rect_to_string (&rect),
2644 _gdk_win32_rect_to_string (drag)));
2646 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2648 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2650 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2651 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2653 /* Resize in increments relative to the base size */
2654 rect.left = rect.top = 0;
2655 rect.right = impl->hints.base_width;
2656 rect.bottom = impl->hints.base_height;
2657 _gdk_win32_adjust_client_rect (window, &rect);
2658 point.x = rect.left;
2660 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2661 rect.left = point.x;
2663 point.x = rect.right;
2664 point.y = rect.bottom;
2665 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2666 rect.right = point.x;
2667 rect.bottom = point.y;
2669 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2670 _gdk_win32_rect_to_string (&rect)));
2673 switch (msg->wParam)
2676 if (drag->bottom == rect.bottom)
2678 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2681 case WMSZ_BOTTOMLEFT:
2682 if (drag->bottom == rect.bottom && drag->left == rect.left)
2684 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2685 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2689 if (drag->left == rect.left)
2691 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2695 if (drag->top == rect.top && drag->left == rect.left)
2697 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2698 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2702 if (drag->top == rect.top)
2704 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2708 if (drag->top == rect.top && drag->right == rect.right)
2710 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2711 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2715 if (drag->right == rect.right)
2717 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2720 case WMSZ_BOTTOMRIGHT:
2721 if (drag->bottom == rect.bottom && drag->right == rect.right)
2723 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2724 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2728 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2729 drag->top != orig_drag.top || drag->right != orig_drag.right)
2733 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2734 _gdk_win32_rect_to_string (drag)));
2738 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2740 if (impl->hint_flags & GDK_HINT_ASPECT)
2742 RECT decorated_rect;
2743 RECT undecorated_drag;
2744 int decoration_width, decoration_height;
2745 gdouble drag_aspect;
2746 int drag_width, drag_height, new_width, new_height;
2748 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2749 decorated_rect = rect;
2750 _gdk_win32_adjust_client_rect (window, &decorated_rect);
2752 /* Set undecorated_drag to the client area being dragged
2753 * out, in screen coordinates.
2755 undecorated_drag = *drag;
2756 undecorated_drag.left -= decorated_rect.left - rect.left;
2757 undecorated_drag.right -= decorated_rect.right - rect.right;
2758 undecorated_drag.top -= decorated_rect.top - rect.top;
2759 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
2761 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
2762 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
2764 drag_width = undecorated_drag.right - undecorated_drag.left;
2765 drag_height = undecorated_drag.bottom - undecorated_drag.top;
2767 drag_aspect = (gdouble) drag_width / drag_height;
2769 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
2770 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
2772 if (drag_aspect < impl->hints.min_aspect)
2774 /* Aspect is getting too narrow */
2775 switch (msg->wParam)
2779 /* User drags top or bottom edge outward. Keep height, increase width. */
2780 new_width = impl->hints.min_aspect * drag_height;
2781 drag->left -= (new_width - drag_width) / 2;
2782 drag->right = drag->left + new_width + decoration_width;
2784 case WMSZ_BOTTOMLEFT:
2785 case WMSZ_BOTTOMRIGHT:
2786 /* User drags bottom-left or bottom-right corner down. Adjust height. */
2787 new_height = drag_width / impl->hints.min_aspect;
2788 drag->bottom = drag->top + new_height + decoration_height;
2792 /* User drags left or right edge inward. Decrease height */
2793 new_height = drag_width / impl->hints.min_aspect;
2794 drag->top += (drag_height - new_height) / 2;
2795 drag->bottom = drag->top + new_height + decoration_height;
2799 /* User drags top-left or top-right corner up. Adjust height. */
2800 new_height = drag_width / impl->hints.min_aspect;
2801 drag->top = drag->bottom - new_height - decoration_height;
2804 else if (drag_aspect > impl->hints.max_aspect)
2806 /* Aspect is getting too wide */
2807 switch (msg->wParam)
2811 /* User drags top or bottom edge inward. Decrease width. */
2812 new_width = impl->hints.max_aspect * drag_height;
2813 drag->left += (drag_width - new_width) / 2;
2814 drag->right = drag->left + new_width + decoration_width;
2816 case WMSZ_BOTTOMLEFT:
2818 /* User drags bottom-left or top-left corner left. Adjust width. */
2819 new_width = impl->hints.max_aspect * drag_height;
2820 drag->left = drag->right - new_width - decoration_width;
2822 case WMSZ_BOTTOMRIGHT:
2824 /* User drags bottom-right or top-right corner right. Adjust width. */
2825 new_width = impl->hints.max_aspect * drag_height;
2826 drag->right = drag->left + new_width + decoration_width;
2830 /* User drags left or right edge outward. Increase height. */
2831 new_height = drag_width / impl->hints.max_aspect;
2832 drag->top -= (new_height - drag_height) / 2;
2833 drag->bottom = drag->top + new_height + decoration_height;
2840 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
2841 _gdk_win32_rect_to_string (drag)));
2845 case WM_GETMINMAXINFO:
2846 if (GDK_WINDOW_DESTROYED (window))
2849 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2850 mmi = (MINMAXINFO*) msg->lParam;
2851 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
2852 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
2853 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
2854 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
2855 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
2856 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
2858 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
2860 rect.left = rect.top = 0;
2861 rect.right = impl->hints.min_width;
2862 rect.bottom = impl->hints.min_height;
2864 _gdk_win32_adjust_client_rect (window, &rect);
2866 mmi->ptMinTrackSize.x = rect.right - rect.left;
2867 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
2870 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
2874 rect.left = rect.top = 0;
2875 rect.right = impl->hints.max_width;
2876 rect.bottom = impl->hints.max_height;
2878 _gdk_win32_adjust_client_rect (window, &rect);
2880 /* at least on win9x we have the 16 bit trouble */
2881 maxw = rect.right - rect.left;
2882 maxh = rect.bottom - rect.top;
2883 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
2884 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
2887 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
2889 /* Don't call DefWindowProcW() */
2890 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
2891 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
2892 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
2893 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
2894 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
2895 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
2901 GDK_NOTE (EVENTS, g_print (" (%d,%d)",
2902 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2904 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2905 !IsIconic (msg->hwnd))
2907 if (!GDK_WINDOW_DESTROYED (window))
2908 handle_configure_event (msg, window);
2915 if (GDK_WINDOW_DESTROYED (window))
2918 event = gdk_event_new (GDK_DELETE);
2919 event->any.window = window;
2921 append_event (event);
2923 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2925 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
2927 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2934 if (pointer_grab != NULL)
2936 if (pointer_grab->window == window)
2937 gdk_pointer_ungrab (msg->time);
2940 if (keyboard_grab &&
2941 keyboard_grab->window == window)
2942 gdk_keyboard_ungrab (msg->time);
2944 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
2945 gdk_window_destroy_notify (window);
2947 if (window == NULL || GDK_WINDOW_DESTROYED (window))
2950 event = gdk_event_new (GDK_DESTROY);
2951 event->any.window = window;
2953 append_event (event);
2958 case WM_DISPLAYCHANGE:
2959 handle_display_change ();
2962 case WM_DESTROYCLIPBOARD:
2963 if (!_ignore_destroy_clipboard)
2965 event = gdk_event_new (GDK_SELECTION_CLEAR);
2966 event->selection.window = window;
2967 event->selection.selection = GDK_SELECTION_CLIPBOARD;
2968 event->selection.time = _gdk_win32_get_next_tick (msg->time);
2969 append_event (event);
2978 case WM_RENDERFORMAT:
2979 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
2981 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
2983 GDK_NOTE (EVENTS, g_print (" (target not found)"));
2988 /* We need to render to clipboard immediately, don't call
2991 event = gdk_event_new (GDK_SELECTION_REQUEST);
2992 event->selection.window = window;
2993 event->selection.send_event = FALSE;
2994 event->selection.selection = GDK_SELECTION_CLIPBOARD;
2995 event->selection.target = target;
2996 event->selection.property = _gdk_selection;
2997 event->selection.requestor = msg->hwnd;
2998 event->selection.time = msg->time;
3000 fixup_event (event);
3001 GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)"));
3002 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
3003 _gdk_event_emit (event);
3004 gdk_event_free (event);
3006 /* Now the clipboard owner should have rendered */
3007 if (!_delayed_rendering_data)
3009 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3013 if (msg->wParam == CF_DIB)
3015 _delayed_rendering_data =
3016 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3018 if (!_delayed_rendering_data)
3020 g_warning ("Cannot convert to DIB from delayed rendered image");
3025 /* The requestor is holding the clipboard, no
3026 * OpenClipboard() is required/possible
3029 g_print (" SetClipboardData(%s,%p)",
3030 _gdk_win32_cf_to_string (msg->wParam),
3031 _delayed_rendering_data));
3033 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3034 _delayed_rendering_data = NULL;
3039 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3040 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3041 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3042 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3043 HIWORD (msg->wParam) ? " minimized" : "",
3044 (HWND) msg->lParam));
3045 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3046 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3049 if (is_modally_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3051 GdkWindow *modal_current = _gdk_modal_current ();
3052 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3058 /* Bring any tablet contexts to the top of the overlap order when
3059 * one of our windows is activated.
3060 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3063 if (LOWORD(msg->wParam) != WA_INACTIVE)
3064 _gdk_input_set_tablet_active ();
3067 case WM_ACTIVATEAPP:
3068 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3069 msg->wParam ? "YES" : "NO",
3070 (gint64) msg->lParam));
3071 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3072 ensure_stacking_on_activate_app (msg, window);
3075 /* Handle WINTAB events here, as we know that gdkinput.c will
3076 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3077 * constants as case labels.
3080 GDK_NOTE (EVENTS, g_print (" %d %p",
3081 (int) msg->wParam, (gpointer) msg->lParam));
3085 GDK_NOTE (EVENTS, g_print (" %d %p",
3086 (int) msg->wParam, (gpointer) msg->lParam));
3090 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3091 (gpointer) msg->wParam,
3092 LOWORD (msg->lParam),
3093 HIWORD (msg->lParam)));
3097 event = gdk_event_new (GDK_NOTHING);
3098 event->any.window = window;
3099 g_object_ref (window);
3101 if (_gdk_input_other_event (event, msg, window))
3102 append_event (event);
3104 gdk_event_free (event);
3112 g_object_unref (window);
3119 _gdk_win32_display_queue_events (GdkDisplay *display)
3123 if (modal_win32_dialog != NULL)
3126 while (!_gdk_event_queue_find_first (display) &&
3127 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3129 TranslateMessage (&msg);
3130 DispatchMessageW (&msg);
3135 gdk_event_prepare (GSource *source,
3141 GDK_THREADS_ENTER ();
3145 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3146 (modal_win32_dialog == NULL &&
3147 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3149 GDK_THREADS_LEAVE ();
3155 gdk_event_check (GSource *source)
3160 GDK_THREADS_ENTER ();
3162 if (event_poll_fd.revents & G_IO_IN)
3164 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3165 (modal_win32_dialog == NULL &&
3166 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3173 GDK_THREADS_LEAVE ();
3179 gdk_event_dispatch (GSource *source,
3180 GSourceFunc callback,
3185 GDK_THREADS_ENTER ();
3187 _gdk_win32_display_queue_events (_gdk_display);
3188 event = _gdk_event_unqueue (_gdk_display);
3192 _gdk_event_emit (event);
3194 gdk_event_free (event);
3196 /* Do drag & drop if it is still pending */
3197 if (_dnd_source_state == GDK_WIN32_DND_PENDING)
3199 _dnd_source_state = GDK_WIN32_DND_DRAGGING;
3200 _gdk_win32_dnd_do_dragdrop ();
3201 _dnd_source_state = GDK_WIN32_DND_NONE;
3205 GDK_THREADS_LEAVE ();
3211 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3213 modal_win32_dialog = window;
3217 is_modally_blocked (GdkWindow *window)
3219 GdkWindow *modal_current = _gdk_modal_current ();
3220 return modal_current != NULL ? gdk_window_get_toplevel (window) != modal_current : FALSE;
3224 check_for_too_much_data (GdkEvent *event)
3226 if (event->client.data.l[1] ||
3227 event->client.data.l[2] ||
3228 event->client.data.l[3] ||
3229 event->client.data.l[4])
3231 g_warning ("Only four bytes of data are passed in client messages on Win32\n");
3236 _gdk_win32_display_send_client_message (GdkDisplay *display,
3238 GdkNativeWindow winid)
3240 check_for_too_much_data (event);
3242 return PostMessageW ((HWND) winid, client_message,
3243 (WPARAM) event->client.message_type,
3244 event->client.data.l[0]);
3248 _gdk_win32_screen_broadcast_client_message (GdkScreen *screen,
3251 check_for_too_much_data (event);
3253 PostMessageW (HWND_BROADCAST, client_message,
3254 (WPARAM) event->client.message_type,
3255 event->client.data.l[0]);
3259 _gdk_win32_display_sync (GdkDisplay * display)
3263 g_return_if_fail (display == _gdk_display);
3265 /* Process all messages currently available */
3266 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3267 DispatchMessageW (&msg);