1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright (C) 1998-2002 Tor Lillqvist
4 * Copyright (C) 2001,2009 Hans Breuer
5 * Copyright (C) 2007-2009 Cody Russell
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
25 * file for a list of people on the GTK+ Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 /* Cannot use TrackMouseEvent, as the stupid WM_MOUSELEAVE message
31 * doesn't tell us where the mouse has gone. Thus we cannot use it to
32 * generate a correct GdkNotifyType. Pity, as using TrackMouseEvent
33 * otherwise would make it possible to reliably generate
34 * GDK_LEAVE_NOTIFY events, which would help get rid of those pesky
35 * tooltips sometimes popping up in the wrong place.
37 * Update: a combination of TrackMouseEvent, GetCursorPos and
38 * GetWindowPos can and is actually used to get rid of those
39 * pesky tooltips. It should be possible to use this for the
40 * whole ENTER/LEAVE NOTIFY handling but some platforms may
41 * not have TrackMouseEvent at all (?) --hb
46 #include <glib/gprintf.h>
49 #include "gdkdisplayprivate.h"
50 #include "gdkprivate-win32.h"
52 #include "gdkkeysyms.h"
53 #include "gdkdevicemanager-win32.h"
54 #include "gdkdeviceprivate.h"
55 #include "gdkdevice-wintab.h"
56 #include "gdkwin32dnd.h"
57 #include "gdkdndprivate.h"
81 #define MK_XBUTTON1 32
82 #define MK_XBUTTON2 64
85 /* Undefined flags: */
86 #define SWP_NOCLIENTSIZE 0x0800
87 #define SWP_NOCLIENTMOVE 0x1000
88 #define SWP_STATECHANGED 0x8000
90 * Private function declarations
93 static gboolean gdk_event_translate (MSG *msg,
95 static void handle_wm_paint (MSG *msg,
97 gboolean return_exposes,
100 static gboolean gdk_event_prepare (GSource *source,
102 static gboolean gdk_event_check (GSource *source);
103 static gboolean gdk_event_dispatch (GSource *source,
104 GSourceFunc callback,
107 /* Private variable declarations
110 static GList *client_filters; /* Filters for client messages */
111 extern gint _gdk_input_ignore_core;
113 static HCURSOR p_grab_cursor;
115 static GSourceFuncs event_funcs = {
122 GPollFD event_poll_fd;
124 static GdkWindow *mouse_window = NULL;
125 static gint current_x, current_y;
126 static gint current_root_x, current_root_y;
127 static UINT client_message;
129 static UINT got_gdk_events_message;
130 static HWND modal_win32_dialog = NULL;
133 static HKL latin_locale = NULL;
136 static gboolean in_ime_composition = FALSE;
137 static UINT modal_timer;
138 static UINT sync_timer = 0;
140 static int debug_indent = 0;
143 assign_object (gpointer lhsp,
146 if (*(gpointer *)lhsp != rhs)
148 if (*(gpointer *)lhsp != NULL)
149 g_object_unref (*(gpointer *)lhsp);
150 *(gpointer *)lhsp = rhs;
157 track_mouse_event (DWORD dwFlags,
162 tme.cbSize = sizeof(TRACKMOUSEEVENT);
163 tme.dwFlags = dwFlags;
164 tme.hwndTrack = hwnd;
165 tme.dwHoverTime = HOVER_DEFAULT; /* not used */
167 if (!TrackMouseEvent (&tme))
168 WIN32_API_FAILED ("TrackMouseEvent");
169 else if (dwFlags == TME_LEAVE)
170 GDK_NOTE (EVENTS, g_print(" (TrackMouseEvent %p)", hwnd));
171 else if (dwFlags == TME_CANCEL)
172 GDK_NOTE (EVENTS, g_print(" (cancel TrackMouseEvent %p)", hwnd));
176 _gdk_win32_get_next_tick (gulong suggested_tick)
178 static gulong cur_tick = 0;
180 if (suggested_tick == 0)
181 suggested_tick = GetTickCount ();
182 if (suggested_tick <= cur_tick)
185 return cur_tick = suggested_tick;
189 generate_focus_event (GdkDeviceManager *device_manager,
196 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
198 event = gdk_event_new (GDK_FOCUS_CHANGE);
199 event->focus_change.window = window;
200 event->focus_change.in = in;
201 gdk_event_set_device (event, device);
203 _gdk_win32_append_event (event);
207 generate_grab_broken_event (GdkDeviceManager *device_manager,
210 GdkWindow *grab_window)
212 GdkEvent *event = gdk_event_new (GDK_GRAB_BROKEN);
216 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
218 device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer;
220 event->grab_broken.window = window;
221 event->grab_broken.send_event = 0;
222 event->grab_broken.keyboard = keyboard;
223 event->grab_broken.implicit = FALSE;
224 event->grab_broken.grab_window = grab_window;
225 gdk_event_set_device (event, device);
227 _gdk_win32_append_event (event);
231 inner_window_procedure (HWND hwnd,
241 msg.message = message;
244 msg.time = _gdk_win32_get_next_tick (0);
245 pos = GetMessagePos ();
246 msg.pt.x = GET_X_LPARAM (pos);
247 msg.pt.y = GET_Y_LPARAM (pos);
249 if (gdk_event_translate (&msg, &ret_val))
251 /* If gdk_event_translate() returns TRUE, we return ret_val from
252 * the window procedure.
254 if (modal_win32_dialog)
255 PostMessageW (modal_win32_dialog, got_gdk_events_message,
261 /* Otherwise call DefWindowProcW(). */
262 GDK_NOTE (EVENTS, g_print (" DefWindowProcW"));
263 return DefWindowProcW (hwnd, message, wparam, lparam);
268 _gdk_win32_window_procedure (HWND hwnd,
275 GDK_NOTE (EVENTS, g_print ("%s%*s%s %p",
276 (debug_indent > 0 ? "\n" : ""),
278 _gdk_win32_message_to_string (message), hwnd));
280 retval = inner_window_procedure (hwnd, message, wparam, lparam);
283 GDK_NOTE (EVENTS, g_print (" => %I64d%s", (gint64) retval, (debug_indent == 0 ? "\n" : "")));
289 _gdk_events_init (void)
296 /* List of languages that use a latin keyboard. Somewhat sorted in
297 * "order of least surprise", in case we have to load one of them if
298 * the user only has arabic loaded, for instance.
300 static int latin_languages[] = {
306 /* Rest in numeric order */
335 client_message = RegisterWindowMessage ("GDK_WIN32_CLIENT_MESSAGE");
336 got_gdk_events_message = RegisterWindowMessage ("GDK_WIN32_GOT_EVENTS");
339 /* Check if we have some input locale identifier loaded that uses a
340 * latin keyboard, to be able to get the virtual-key code for the
341 * latin characters corresponding to ASCII control characters.
343 if ((n = GetKeyboardLayoutList (0, NULL)) == 0)
344 WIN32_API_FAILED ("GetKeyboardLayoutList");
347 HKL *hkl_list = g_new (HKL, n);
348 if (GetKeyboardLayoutList (n, hkl_list) == 0)
349 WIN32_API_FAILED ("GetKeyboardLayoutList");
352 for (i = 0; latin_locale == NULL && i < n; i++)
353 for (j = 0; j < G_N_ELEMENTS (latin_languages); j++)
354 if (PRIMARYLANGID (LOWORD (hkl_list[i])) == latin_languages[j])
356 latin_locale = hkl_list [i];
363 if (latin_locale == NULL)
365 /* Try to load a keyboard layout with latin characters then.
368 while (latin_locale == NULL && i < G_N_ELEMENTS (latin_languages))
371 g_sprintf (id, "%08x", MAKELANGID (latin_languages[i++], SUBLANG_DEFAULT));
372 latin_locale = LoadKeyboardLayout (id, KLF_NOTELLSHELL|KLF_SUBSTITUTE_OK);
376 GDK_NOTE (EVENTS, g_print ("latin_locale = %08x\n", (guint) latin_locale));
379 source = g_source_new (&event_funcs, sizeof (GSource));
380 g_source_set_name (source, "GDK Win32 event source");
381 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
384 event_poll_fd.fd = open ("/dev/windows", O_RDONLY);
385 if (event_poll_fd.fd == -1)
386 g_error ("can't open \"/dev/windows\": %s", g_strerror (errno));
388 event_poll_fd.fd = G_WIN32_MSG_HANDLE;
390 event_poll_fd.events = G_IO_IN;
392 g_source_add_poll (source, &event_poll_fd);
393 g_source_set_can_recurse (source, TRUE);
394 g_source_attach (source, NULL);
398 _gdk_win32_display_has_pending (GdkDisplay *display)
400 return (_gdk_event_queue_find_first (display) ||
401 (modal_win32_dialog == NULL &&
402 GetQueueStatus (QS_ALLINPUT) != 0));
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,
504 GdkDeviceManagerWin32 *device_manager;
505 GdkWindow *event_window;
508 GdkDeviceGrabInfo *grab;
510 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (_gdk_display));
512 grab = _gdk_display_get_last_device_grab (_gdk_display, device_manager->core_pointer);
514 return reported_window;
518 if (!grab->owner_events)
519 event_window = grab->native_window;
523 hwnd = WindowFromPoint (pt);
526 POINT client_pt = pt;
528 ScreenToClient (hwnd, &client_pt);
529 GetClientRect (hwnd, &rect);
530 if (PtInRect (&rect, client_pt))
531 event_window = gdk_win32_handle_table_lookup (hwnd);
533 if (event_window == NULL)
534 event_window = grab->native_window;
537 /* need to also adjust the coordinates to the new window */
538 ScreenToClient (GDK_WINDOW_HWND (event_window), &pt);
540 /* ATTENTION: need to update client coords */
541 msg->lParam = MAKELPARAM (pt.x, pt.y);
547 build_key_event_state (GdkEvent *event,
550 event->key.state = 0;
552 if (key_state[VK_SHIFT] & 0x80)
553 event->key.state |= GDK_SHIFT_MASK;
555 if (key_state[VK_CAPITAL] & 0x01)
556 event->key.state |= GDK_LOCK_MASK;
558 if (key_state[VK_LBUTTON] & 0x80)
559 event->key.state |= GDK_BUTTON1_MASK;
560 if (key_state[VK_MBUTTON] & 0x80)
561 event->key.state |= GDK_BUTTON2_MASK;
562 if (key_state[VK_RBUTTON] & 0x80)
563 event->key.state |= GDK_BUTTON3_MASK;
564 if (key_state[VK_XBUTTON1] & 0x80)
565 event->key.state |= GDK_BUTTON4_MASK;
566 if (key_state[VK_XBUTTON2] & 0x80)
567 event->key.state |= GDK_BUTTON5_MASK;
569 if (_gdk_keyboard_has_altgr &&
570 (key_state[VK_LCONTROL] & 0x80) &&
571 (key_state[VK_RMENU] & 0x80))
573 event->key.group = 1;
574 event->key.state |= GDK_MOD2_MASK;
575 if (key_state[VK_RCONTROL] & 0x80)
576 event->key.state |= GDK_CONTROL_MASK;
577 if (key_state[VK_LMENU] & 0x80)
578 event->key.state |= GDK_MOD1_MASK;
582 event->key.group = 0;
583 if (key_state[VK_CONTROL] & 0x80)
584 event->key.state |= GDK_CONTROL_MASK;
585 if (key_state[VK_MENU] & 0x80)
586 event->key.state |= GDK_MOD1_MASK;
591 build_pointer_event_state (MSG *msg)
597 if (msg->wParam & MK_CONTROL)
598 state |= GDK_CONTROL_MASK;
600 if ((msg->message != WM_LBUTTONDOWN &&
601 (msg->wParam & MK_LBUTTON)) ||
602 msg->message == WM_LBUTTONUP)
603 state |= GDK_BUTTON1_MASK;
605 if ((msg->message != WM_MBUTTONDOWN &&
606 (msg->wParam & MK_MBUTTON)) ||
607 msg->message == WM_MBUTTONUP)
608 state |= GDK_BUTTON2_MASK;
610 if ((msg->message != WM_RBUTTONDOWN &&
611 (msg->wParam & MK_RBUTTON)) ||
612 msg->message == WM_RBUTTONUP)
613 state |= GDK_BUTTON3_MASK;
615 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON1) &&
616 (msg->wParam & MK_XBUTTON1)) ||
617 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON1))
618 state |= GDK_BUTTON4_MASK;
620 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON2) &&
621 (msg->wParam & MK_XBUTTON2)) ||
622 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON2))
623 state |= GDK_BUTTON5_MASK;
625 if (msg->wParam & MK_SHIFT)
626 state |= GDK_SHIFT_MASK;
628 if (GetKeyState (VK_MENU) < 0)
629 state |= GDK_MOD1_MASK;
631 if (GetKeyState (VK_CAPITAL) & 0x1)
632 state |= GDK_LOCK_MASK;
638 build_wm_ime_composition_event (GdkEvent *event,
643 event->key.time = _gdk_win32_get_next_tick (msg->time);
645 build_key_event_state (event, key_state);
647 event->key.hardware_keycode = 0; /* FIXME: What should it be? */
648 event->key.string = NULL;
649 event->key.length = 0;
650 event->key.keyval = gdk_unicode_to_keyval (wc);
653 #ifdef G_ENABLE_DEBUG
656 print_event_state (guint state)
658 #define CASE(bit) if (state & GDK_ ## bit ## _MASK) g_print (#bit " ");
676 _gdk_win32_print_event (const GdkEvent *event)
678 gchar *escaped, *kvname;
679 gchar *selection_name, *target_name, *property_name;
681 g_print ("%s%*s===> ", (debug_indent > 0 ? "\n" : ""), debug_indent, "");
682 switch (event->any.type)
684 #define CASE(x) case x: g_print (#x); break;
689 CASE (GDK_MOTION_NOTIFY);
690 CASE (GDK_BUTTON_PRESS);
691 CASE (GDK_2BUTTON_PRESS);
692 CASE (GDK_3BUTTON_PRESS);
693 CASE (GDK_BUTTON_RELEASE);
694 CASE (GDK_KEY_PRESS);
695 CASE (GDK_KEY_RELEASE);
696 CASE (GDK_ENTER_NOTIFY);
697 CASE (GDK_LEAVE_NOTIFY);
698 CASE (GDK_FOCUS_CHANGE);
699 CASE (GDK_CONFIGURE);
702 CASE (GDK_PROPERTY_NOTIFY);
703 CASE (GDK_SELECTION_CLEAR);
704 CASE (GDK_SELECTION_REQUEST);
705 CASE (GDK_SELECTION_NOTIFY);
706 CASE (GDK_PROXIMITY_IN);
707 CASE (GDK_PROXIMITY_OUT);
708 CASE (GDK_DRAG_ENTER);
709 CASE (GDK_DRAG_LEAVE);
710 CASE (GDK_DRAG_MOTION);
711 CASE (GDK_DRAG_STATUS);
712 CASE (GDK_DROP_START);
713 CASE (GDK_DROP_FINISHED);
714 CASE (GDK_CLIENT_EVENT);
715 CASE (GDK_VISIBILITY_NOTIFY);
717 CASE (GDK_WINDOW_STATE);
719 CASE (GDK_OWNER_CHANGE);
720 CASE (GDK_GRAB_BROKEN);
722 default: g_assert_not_reached ();
725 g_print (" %p ", event->any.window ? GDK_WINDOW_HWND (event->any.window) : NULL);
727 switch (event->any.type)
731 _gdk_win32_gdkrectangle_to_string (&event->expose.area),
732 event->expose.count);
734 case GDK_MOTION_NOTIFY:
735 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s",
736 event->motion.x, event->motion.y,
737 event->motion.x_root, event->motion.y_root,
738 event->motion.is_hint ? "HINT " : "");
739 print_event_state (event->motion.state);
741 case GDK_BUTTON_PRESS:
742 case GDK_2BUTTON_PRESS:
743 case GDK_3BUTTON_PRESS:
744 case GDK_BUTTON_RELEASE:
745 g_print ("%d (%.4g,%.4g) (%.4g,%.4g) ",
746 event->button.button,
747 event->button.x, event->button.y,
748 event->button.x_root, event->button.y_root);
749 print_event_state (event->button.state);
752 case GDK_KEY_RELEASE:
753 if (event->key.length == 0)
754 escaped = g_strdup ("");
756 escaped = g_strescape (event->key.string, NULL);
757 kvname = gdk_keyval_name (event->key.keyval);
758 g_print ("%#.02x group:%d %s %d:\"%s\" ",
759 event->key.hardware_keycode, event->key.group,
760 (kvname ? kvname : "??"),
764 print_event_state (event->key.state);
766 case GDK_ENTER_NOTIFY:
767 case GDK_LEAVE_NOTIFY:
768 g_print ("%p (%.4g,%.4g) (%.4g,%.4g) %s %s%s",
769 event->crossing.subwindow == NULL ? NULL : GDK_WINDOW_HWND (event->crossing.subwindow),
770 event->crossing.x, event->crossing.y,
771 event->crossing.x_root, event->crossing.y_root,
772 (event->crossing.mode == GDK_CROSSING_NORMAL ? "NORMAL" :
773 (event->crossing.mode == GDK_CROSSING_GRAB ? "GRAB" :
774 (event->crossing.mode == GDK_CROSSING_UNGRAB ? "UNGRAB" :
776 (event->crossing.detail == GDK_NOTIFY_ANCESTOR ? "ANCESTOR" :
777 (event->crossing.detail == GDK_NOTIFY_VIRTUAL ? "VIRTUAL" :
778 (event->crossing.detail == GDK_NOTIFY_INFERIOR ? "INFERIOR" :
779 (event->crossing.detail == GDK_NOTIFY_NONLINEAR ? "NONLINEAR" :
780 (event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL ? "NONLINEAR_VIRTUAL" :
781 (event->crossing.detail == GDK_NOTIFY_UNKNOWN ? "UNKNOWN" :
783 event->crossing.focus ? " FOCUS" : "");
784 print_event_state (event->crossing.state);
786 case GDK_FOCUS_CHANGE:
787 g_print ("%s", (event->focus_change.in ? "IN" : "OUT"));
790 g_print ("x:%d y:%d w:%d h:%d",
791 event->configure.x, event->configure.y,
792 event->configure.width, event->configure.height);
794 case GDK_SELECTION_CLEAR:
795 case GDK_SELECTION_REQUEST:
796 case GDK_SELECTION_NOTIFY:
797 selection_name = gdk_atom_name (event->selection.selection);
798 target_name = gdk_atom_name (event->selection.target);
799 property_name = gdk_atom_name (event->selection.property);
800 g_print ("sel:%s tgt:%s prop:%s",
801 selection_name, target_name, property_name);
802 g_free (selection_name);
803 g_free (target_name);
804 g_free (property_name);
808 case GDK_DRAG_MOTION:
809 case GDK_DRAG_STATUS:
811 case GDK_DROP_FINISHED:
812 if (event->dnd.context != NULL)
813 g_print ("ctx:%p: %s %s src:%p dest:%p",
815 _gdk_win32_drag_protocol_to_string (event->dnd.context->protocol),
816 event->dnd.context->is_source ? "SOURCE" : "DEST",
817 event->dnd.context->source_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->source_window),
818 event->dnd.context->dest_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->dest_window));
820 case GDK_CLIENT_EVENT:
821 /* no more GdkEventClient */
824 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",
825 event->scroll.x, event->scroll.y,
826 event->scroll.x_root, event->scroll.y_root,
827 (event->scroll.direction == GDK_SCROLL_UP ? "UP" :
828 (event->scroll.direction == GDK_SCROLL_DOWN ? "DOWN" :
829 (event->scroll.direction == GDK_SCROLL_LEFT ? "LEFT" :
830 (event->scroll.direction == GDK_SCROLL_RIGHT ? "RIGHT" :
832 print_event_state (event->scroll.state);
834 case GDK_WINDOW_STATE:
836 _gdk_win32_window_state_to_string (event->window_state.changed_mask),
837 _gdk_win32_window_state_to_string (event->window_state.new_window_state));
840 (event->setting.action == GDK_SETTING_ACTION_NEW ? "NEW" :
841 (event->setting.action == GDK_SETTING_ACTION_CHANGED ? "CHANGED" :
842 (event->setting.action == GDK_SETTING_ACTION_DELETED ? "DELETED" :
844 (event->setting.name ? event->setting.name : "NULL"));
845 case GDK_GRAB_BROKEN:
847 (event->grab_broken.keyboard ? "KEYBOARD" : "POINTER"),
848 (event->grab_broken.implicit ? "IMPLICIT" : "EXPLICIT"),
849 (event->grab_broken.grab_window ? GDK_WINDOW_HWND (event->grab_broken.grab_window) : 0));
854 g_print ("%s", (debug_indent == 0 ? "\n" : ""));
858 decode_key_lparam (LPARAM lParam)
860 static char buf[100];
863 if (HIWORD (lParam) & KF_UP)
864 p += g_sprintf (p, "KF_UP ");
865 if (HIWORD (lParam) & KF_REPEAT)
866 p += g_sprintf (p, "KF_REPEAT ");
867 if (HIWORD (lParam) & KF_ALTDOWN)
868 p += g_sprintf (p, "KF_ALTDOWN ");
869 if (HIWORD (lParam) & KF_EXTENDED)
870 p += g_sprintf (p, "KF_EXTENDED ");
871 p += g_sprintf (p, "sc:%d rep:%d", LOBYTE (HIWORD (lParam)), LOWORD (lParam));
879 fixup_event (GdkEvent *event)
881 if (event->any.window)
882 g_object_ref (event->any.window);
883 if (((event->any.type == GDK_ENTER_NOTIFY) ||
884 (event->any.type == GDK_LEAVE_NOTIFY)) &&
885 (event->crossing.subwindow != NULL))
886 g_object_ref (event->crossing.subwindow);
887 event->any.send_event = InSendMessage ();
891 _gdk_win32_append_event (GdkEvent *event)
897 link = _gdk_event_queue_append (_gdk_display, event);
898 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
899 /* event morphing, the passed in may not be valid afterwards */
900 _gdk_windowing_got_event (_gdk_display, link, event, 0);
902 _gdk_event_queue_append (_gdk_display, event);
903 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
908 fill_key_event_string (GdkEvent *event)
913 /* Fill in event->string crudely, since various programs
918 if (event->key.keyval != GDK_KEY_VoidSymbol)
919 c = gdk_keyval_to_unicode (event->key.keyval);
926 /* Apply the control key - Taken from Xlib
928 if (event->key.state & GDK_CONTROL_MASK)
930 if ((c >= '@' && c < '\177') || c == ' ')
934 event->key.string = g_memdup ("\0\0", 2);
935 event->key.length = 1;
938 else if (c >= '3' && c <= '7')
946 len = g_unichar_to_utf8 (c, buf);
949 event->key.string = g_locale_from_utf8 (buf, len,
950 NULL, &bytes_written,
952 if (event->key.string)
953 event->key.length = bytes_written;
955 else if (event->key.keyval == GDK_KEY_Escape)
957 event->key.length = 1;
958 event->key.string = g_strdup ("\033");
960 else if (event->key.keyval == GDK_KEY_Return ||
961 event->key.keyval == GDK_KEY_KP_Enter)
963 event->key.length = 1;
964 event->key.string = g_strdup ("\r");
967 if (!event->key.string)
969 event->key.length = 0;
970 event->key.string = g_strdup ("");
974 static GdkFilterReturn
975 apply_event_filters (GdkWindow *window,
979 GdkFilterReturn result = GDK_FILTER_CONTINUE;
984 event = gdk_event_new (GDK_NOTHING);
986 event->any.window = g_object_ref (window);
987 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
989 /* I think GdkFilterFunc semantics require the passed-in event
990 * to already be in the queue. The filter func can generate
991 * more events and append them after it if it likes.
993 node = _gdk_event_queue_append (_gdk_display, event);
998 GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
1001 if ((filter->flags & GDK_EVENT_FILTER_REMOVED) != 0)
1003 tmp_list = tmp_list->next;
1007 filter->ref_count++;
1008 result = filter->function (msg, event, filter->data);
1010 /* get the next node after running the function since the
1011 function may add or remove a next node */
1013 tmp_list = tmp_list->next;
1015 filter->ref_count--;
1016 if (filter->ref_count == 0)
1018 *filters = g_list_remove_link (*filters, node);
1019 g_list_free_1 (node);
1023 if (result != GDK_FILTER_CONTINUE)
1027 if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
1029 _gdk_event_queue_remove_link (_gdk_display, node);
1030 g_list_free_1 (node);
1031 gdk_event_free (event);
1033 else /* GDK_FILTER_TRANSLATE */
1035 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1036 fixup_event (event);
1037 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1043 * On Windows, transient windows will not have their own taskbar entries.
1044 * Because of this, we must hide and restore groups of transients in both
1045 * directions. That is, all transient children must be hidden or restored
1046 * with this window, but if this window's transient owner also has a
1047 * transient owner then this window's transient owner must be hidden/restored
1048 * with this one. And etc, up the chain until we hit an ancestor that has no
1051 * It would be a good idea if applications don't chain transient windows
1052 * together. There's a limit to how much evil GTK can try to shield you
1056 show_window_recurse (GdkWindow *window, gboolean hide_window)
1058 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1059 GSList *children = impl->transient_children;
1060 GdkWindow *child = NULL;
1062 if (!impl->changing_state)
1064 impl->changing_state = TRUE;
1066 if (children != NULL)
1068 while (children != NULL)
1070 child = children->data;
1071 show_window_recurse (child, hide_window);
1073 children = g_slist_next (children);
1077 if (GDK_WINDOW_IS_MAPPED (window))
1081 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_ICONIFIED)
1083 if (gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED)
1085 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
1089 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1095 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
1099 impl->changing_state = FALSE;
1104 do_show_window (GdkWindow *window, gboolean hide_window)
1106 GdkWindow *tmp_window = NULL;
1107 GdkWindowImplWin32 *tmp_impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1109 if (!tmp_impl->changing_state)
1111 /* Find the top-level window in our transient chain. */
1112 while (tmp_impl->transient_owner != NULL)
1114 tmp_window = tmp_impl->transient_owner;
1115 tmp_impl = GDK_WINDOW_IMPL_WIN32 (tmp_window->impl);
1118 /* If we couldn't find one, use the window provided. */
1119 if (tmp_window == NULL)
1121 tmp_window = window;
1124 /* Recursively show/hide every window in the chain. */
1125 if (tmp_window != window)
1127 show_window_recurse (tmp_window, hide_window);
1133 send_crossing_event (GdkDisplay *display,
1136 GdkCrossingMode mode,
1137 GdkNotifyType notify_type,
1138 GdkWindow *subwindow,
1140 GdkModifierType mask,
1144 GdkDeviceGrabInfo *grab;
1145 GdkDeviceManagerWin32 *device_manager;
1148 device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (display));
1150 grab = _gdk_display_has_device_grab (display, device_manager->core_pointer, 0);
1153 !grab->owner_events &&
1154 mode != GDK_CROSSING_UNGRAB)
1156 /* !owner_event => only report events wrt grab window, ignore rest */
1157 if ((GdkWindow *)window != grab->native_window)
1162 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1164 event = gdk_event_new (type);
1165 event->crossing.window = window;
1166 event->crossing.subwindow = subwindow;
1167 event->crossing.time = _gdk_win32_get_next_tick (time_);
1168 event->crossing.x = pt.x;
1169 event->crossing.y = pt.y;
1170 event->crossing.x_root = screen_pt->x + _gdk_offset_x;
1171 event->crossing.y_root = screen_pt->y + _gdk_offset_y;
1172 event->crossing.mode = mode;
1173 event->crossing.detail = notify_type;
1174 event->crossing.mode = mode;
1175 event->crossing.detail = notify_type;
1176 event->crossing.focus = FALSE;
1177 event->crossing.state = mask;
1178 gdk_event_set_device (event, _gdk_display->core_pointer);
1180 _gdk_win32_append_event (event);
1182 if (type == GDK_ENTER_NOTIFY &&
1183 window->extension_events != 0)
1184 _gdk_device_wintab_update_window_coords (window);
1188 get_native_parent (GdkWindow *window)
1190 if (window->parent != NULL)
1191 return window->parent->impl_window;
1196 find_common_ancestor (GdkWindow *win1,
1200 GList *path1 = NULL, *path2 = NULL;
1201 GList *list1, *list2;
1204 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
1206 path1 = g_list_prepend (path1, tmp);
1207 tmp = get_native_parent (tmp);
1211 while (tmp != NULL && tmp->window_type != GDK_WINDOW_ROOT)
1213 path2 = g_list_prepend (path2, tmp);
1214 tmp = get_native_parent (tmp);
1220 while (list1 && list2 && (list1->data == list2->data))
1222 tmp = (GdkWindow *)list1->data;
1223 list1 = g_list_next (list1);
1224 list2 = g_list_next (list2);
1226 g_list_free (path1);
1227 g_list_free (path2);
1233 synthesize_crossing_events (GdkDisplay *display,
1236 GdkCrossingMode mode,
1238 GdkModifierType mask,
1240 gboolean non_linear)
1243 GdkWindow *win, *last, *next;
1247 GdkNotifyType notify_type;
1252 return; /* No crossings generated between src and dest */
1254 c = find_common_ancestor (a, b);
1256 non_linear |= (c != a) && (c != b);
1258 if (a) /* There might not be a source (i.e. if no previous pointer_in_window) */
1260 /* Traverse up from a to (excluding) c sending leave events */
1262 notify_type = GDK_NOTIFY_NONLINEAR;
1264 notify_type = GDK_NOTIFY_INFERIOR;
1266 notify_type = GDK_NOTIFY_ANCESTOR;
1267 send_crossing_event (display,
1268 a, GDK_LEAVE_NOTIFY,
1278 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1280 notify_type = GDK_NOTIFY_VIRTUAL;
1283 win = get_native_parent (a);
1284 while (win != c && win->window_type != GDK_WINDOW_ROOT)
1286 send_crossing_event (display,
1287 win, GDK_LEAVE_NOTIFY,
1295 win = get_native_parent (win);
1300 if (b) /* Might not be a dest, e.g. if we're moving out of the window */
1302 /* Traverse down from c to b */
1306 win = get_native_parent (b);
1307 while (win != c && win->window_type != GDK_WINDOW_ROOT)
1309 path = g_list_prepend (path, win);
1310 win = get_native_parent (win);
1314 notify_type = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1316 notify_type = GDK_NOTIFY_VIRTUAL;
1321 win = (GdkWindow *)list->data;
1322 list = g_list_next (list);
1324 next = (GdkWindow *)list->data;
1328 send_crossing_event (display,
1329 win, GDK_ENTER_NOTIFY,
1341 notify_type = GDK_NOTIFY_NONLINEAR;
1343 notify_type = GDK_NOTIFY_ANCESTOR;
1345 notify_type = GDK_NOTIFY_INFERIOR;
1347 send_crossing_event (display,
1348 b, GDK_ENTER_NOTIFY,
1357 /* The check_extended flag controls whether to check if the windows want
1358 * events from extended input devices and if the message should be skipped
1359 * because an extended input device is active
1362 propagate (GdkWindow **window,
1364 GdkWindow *grab_window,
1365 gboolean grab_owner_events,
1367 gboolean (*doesnt_want_it) (gint mask,
1369 gboolean check_extended)
1371 if (grab_window != NULL && !grab_owner_events)
1373 /* Event source is grabbed with owner_events FALSE */
1375 /* See if the event should be ignored because an extended input
1378 if (check_extended &&
1379 grab_window->extension_events != 0 &&
1380 _gdk_input_ignore_core)
1382 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1385 if ((*doesnt_want_it) (grab_mask, msg))
1387 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1392 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1393 assign_object (window, grab_window);
1398 /* If we come here, we know that if grab_window != NULL then
1399 * grab_owner_events is TRUE
1403 if (check_extended &&
1404 (*window)->extension_events != 0 &&
1405 _gdk_input_ignore_core)
1407 GDK_NOTE (EVENTS, g_print (" (ignored)"));
1410 if ((*doesnt_want_it) ((*window)->event_mask, msg))
1412 /* Owner doesn't want it, propagate to parent. */
1413 GdkWindow *parent = gdk_window_get_parent (*window);
1414 if (parent == _gdk_root || parent == NULL)
1416 /* No parent; check if grabbed */
1417 if (grab_window != NULL)
1419 /* Event source is grabbed with owner_events TRUE */
1421 if (check_extended &&
1422 grab_window->extension_events != 0 &&
1423 _gdk_input_ignore_core)
1425 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1428 if ((*doesnt_want_it) (grab_mask, msg))
1430 /* Grabber doesn't want it either */
1431 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1437 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1438 assign_object (window, grab_window);
1444 GDK_NOTE (EVENTS, g_print (" (undelivered)"));
1450 assign_object (window, parent);
1451 /* The only branch where we actually continue the loop */
1460 doesnt_want_key (gint mask,
1463 return (((msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) &&
1464 !(mask & GDK_KEY_RELEASE_MASK)) ||
1465 ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) &&
1466 !(mask & GDK_KEY_PRESS_MASK)));
1470 doesnt_want_char (gint mask,
1473 return !(mask & (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK));
1477 _gdk_win32_emit_configure_event (GdkWindow *window)
1479 GdkWindowImplWin32 *window_impl;
1484 window_impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1485 if (window_impl->inhibit_configure)
1488 hwnd = GDK_WINDOW_HWND (window);
1490 GetClientRect (hwnd, &client_rect);
1491 point.x = client_rect.left; /* always 0 */
1492 point.y = client_rect.top;
1494 /* top level windows need screen coords */
1495 if (gdk_window_get_parent (window) == _gdk_root)
1497 ClientToScreen (hwnd, &point);
1498 point.x += _gdk_offset_x;
1499 point.y += _gdk_offset_y;
1502 window->width = client_rect.right - client_rect.left;
1503 window->height = client_rect.bottom - client_rect.top;
1505 window->x = point.x;
1506 window->y = point.y;
1508 _gdk_window_update_size (window);
1510 if (window->event_mask & GDK_STRUCTURE_MASK)
1512 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1514 event->configure.window = window;
1516 event->configure.width = client_rect.right - client_rect.left;
1517 event->configure.height = client_rect.bottom - client_rect.top;
1519 event->configure.x = point.x;
1520 event->configure.y = point.y;
1522 _gdk_win32_append_event (event);
1527 _gdk_win32_hrgn_to_region (HRGN hrgn)
1531 cairo_region_t *result;
1535 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1537 WIN32_GDI_FAILED ("GetRegionData");
1541 rgndata = (RGNDATA *) g_malloc (nbytes);
1543 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1545 WIN32_GDI_FAILED ("GetRegionData");
1550 result = cairo_region_create ();
1551 rects = (RECT *) rgndata->Buffer;
1552 for (i = 0; i < rgndata->rdh.nCount; i++)
1556 r.x = rects[i].left;
1558 r.width = rects[i].right - r.x;
1559 r.height = rects[i].bottom - r.y;
1561 cairo_region_union_rectangle (result, &r);
1570 adjust_drag (LONG *drag,
1575 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1577 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1581 handle_wm_paint (MSG *msg,
1583 gboolean return_exposes,
1586 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1588 PAINTSTRUCT paintstruct;
1589 cairo_region_t *update_region;
1591 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1593 WIN32_GDI_FAILED ("GetUpdateRgn");
1594 DeleteObject (hrgn);
1598 hdc = BeginPaint (msg->hwnd, &paintstruct);
1600 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1601 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1602 (paintstruct.fErase ? "erase" : ""),
1604 (return_exposes ? " return_exposes" : "")));
1606 EndPaint (msg->hwnd, &paintstruct);
1608 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1609 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1611 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1612 DeleteObject (hrgn);
1618 if (!GDK_WINDOW_DESTROYED (window))
1620 GList *list = _gdk_display->queued_events;
1622 *event = gdk_event_new (GDK_EXPOSE);
1623 (*event)->expose.window = window;
1624 (*event)->expose.area.x = paintstruct.rcPaint.left;
1625 (*event)->expose.area.y = paintstruct.rcPaint.top;
1626 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1627 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1628 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1629 (*event)->expose.count = 0;
1631 while (list != NULL)
1633 GdkEventPrivate *evp = list->data;
1635 if (evp->event.any.type == GDK_EXPOSE &&
1636 evp->event.any.window == window &&
1637 !(evp->flags & GDK_EVENT_PENDING))
1638 evp->event.expose.count++;
1644 DeleteObject (hrgn);
1648 update_region = _gdk_win32_hrgn_to_region (hrgn);
1649 if (!cairo_region_is_empty (update_region))
1650 _gdk_window_invalidate_for_expose (window, update_region);
1651 cairo_region_destroy (update_region);
1653 DeleteObject (hrgn);
1656 static VOID CALLBACK
1657 modal_timer_proc (HWND hwnd,
1662 int arbitrary_limit = 10;
1664 while (_modal_operation_in_progress &&
1665 g_main_context_pending (NULL) &&
1667 g_main_context_iteration (NULL, FALSE);
1671 _gdk_win32_begin_modal_call (void)
1673 g_assert (!_modal_operation_in_progress);
1675 _modal_operation_in_progress = TRUE;
1677 modal_timer = SetTimer (NULL, 0, 10, modal_timer_proc);
1678 if (modal_timer == 0)
1679 WIN32_API_FAILED ("SetTimer");
1683 _gdk_win32_end_modal_call (void)
1685 g_assert (_modal_operation_in_progress);
1687 _modal_operation_in_progress = FALSE;
1689 if (modal_timer != 0)
1691 API_CALL (KillTimer, (NULL, modal_timer));
1696 static VOID CALLBACK
1697 sync_timer_proc (HWND hwnd,
1703 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1708 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1710 KillTimer (hwnd, sync_timer);
1714 handle_display_change (void)
1716 _gdk_monitor_init ();
1717 _gdk_root_window_size_init ();
1718 g_signal_emit_by_name (_gdk_screen, "size_changed");
1722 generate_button_event (GdkEventType type,
1727 GdkEvent *event = gdk_event_new (type);
1729 event->button.window = window;
1730 event->button.time = _gdk_win32_get_next_tick (msg->time);
1731 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1732 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1733 event->button.x_root = msg->pt.x + _gdk_offset_x;
1734 event->button.y_root = msg->pt.y + _gdk_offset_y;
1735 event->button.axes = NULL;
1736 event->button.state = build_pointer_event_state (msg);
1737 event->button.button = button;
1738 gdk_event_set_device (event, _gdk_display->core_pointer);
1740 _gdk_win32_append_event (event);
1744 ensure_stacking_on_unminimize (MSG *msg)
1747 HWND lowest_transient = NULL;
1750 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1752 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1754 /* Checking window group not implemented yet */
1757 GdkWindowImplWin32 *rover_impl =
1758 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1760 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1761 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1762 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1763 rover_impl->transient_owner != NULL))
1765 lowest_transient = rover;
1769 if (lowest_transient != NULL)
1771 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1772 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1773 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1778 ensure_stacking_on_window_pos_changing (MSG *msg,
1781 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1782 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1784 if (GetActiveWindow () == msg->hwnd &&
1785 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1786 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1787 impl->transient_owner == NULL)
1789 /* Make sure the window stays behind any transient-type windows
1790 * of the same window group.
1792 * If the window is not active and being activated, we let
1793 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1794 * handling to bring any utility windows on top of it.
1797 gboolean restacking;
1799 rover = windowpos->hwndInsertAfter;
1803 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1805 /* Checking window group not implemented yet */
1808 GdkWindowImplWin32 *rover_impl =
1809 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1811 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1812 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1813 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1814 rover_impl->transient_owner != NULL))
1817 windowpos->hwndInsertAfter = rover;
1820 rover = GetNextWindow (rover, GW_HWNDNEXT);
1825 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1833 ensure_stacking_on_activate_app (MSG *msg,
1836 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
1838 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1839 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1840 impl->transient_owner != NULL)
1842 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1843 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1847 if (IsWindowVisible (msg->hwnd) &&
1848 msg->hwnd == GetActiveWindow ())
1850 /* This window is not a transient-type window and it is the
1851 * activated window. Make sure this window is as visible as
1852 * possible, just below the lowest transient-type window of this
1858 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
1860 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1862 /* Checking window group not implemented yet */
1865 GdkWindowImplWin32 *rover_impl =
1866 GDK_WINDOW_IMPL_WIN32 (rover_gdkw->impl);
1868 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1869 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1870 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1871 rover_impl->transient_owner != NULL))
1873 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1874 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1875 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1883 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
1884 GDK_BUTTON2_MASK | \
1885 GDK_BUTTON3_MASK | \
1886 GDK_BUTTON4_MASK | \
1890 gdk_event_translate (MSG *msg,
1893 RECT rect, *drag, orig_drag;
1898 BYTE key_state[256];
1900 WINDOWPOS *windowpos;
1907 GdkWindow *window = NULL;
1908 GdkWindowImplWin32 *impl;
1910 GdkWindow *orig_window, *new_window;
1912 GdkDeviceManager *device_manager;
1914 GdkDeviceGrabInfo *keyboard_grab = NULL;
1915 GdkDeviceGrabInfo *pointer_grab = NULL;
1916 GdkWindow *grab_window = NULL;
1922 gboolean return_val = FALSE;
1926 if (_gdk_default_filters)
1928 /* Apply global filters */
1930 GdkFilterReturn result = apply_event_filters (NULL, msg, &_gdk_default_filters);
1932 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1933 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1934 * we return TRUE, and DefWindowProcW() will not be called.
1936 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1940 window = gdk_win32_handle_table_lookup (msg->hwnd);
1941 orig_window = window;
1945 /* XXX Handle WM_QUIT here ? */
1946 if (msg->message == WM_QUIT)
1948 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1951 else if (msg->message == WM_CREATE)
1953 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1954 GDK_WINDOW_HWND (window) = msg->hwnd;
1958 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1963 device_manager = gdk_display_get_device_manager (_gdk_display);
1965 keyboard_grab = _gdk_display_get_last_device_grab (_gdk_display,
1966 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
1967 pointer_grab = _gdk_display_get_last_device_grab (_gdk_display,
1968 GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer);
1970 g_object_ref (window);
1972 /* window's refcount has now been increased, so code below should
1973 * not just return from this function, but instead goto done (or
1974 * break out of the big switch). To protect against forgetting this,
1975 * #define return to a syntax error...
1977 #define return GOTO_DONE_INSTEAD
1979 if (!GDK_WINDOW_DESTROYED (window) && window->filters)
1981 /* Apply per-window filters */
1983 GdkFilterReturn result = apply_event_filters (window, msg, &window->filters);
1985 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1992 if (msg->message == client_message)
1995 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1998 GDK_NOTE (EVENTS, g_print (" client_message"));
2000 event = gdk_event_new (GDK_NOTHING);
2001 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2003 node = _gdk_event_queue_append (_gdk_display, event);
2005 tmp_list = client_filters;
2008 GdkClientFilter *filter = tmp_list->data;
2010 tmp_list = tmp_list->next;
2012 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
2014 GDK_NOTE (EVENTS, g_print (" (match)"));
2016 result = (*filter->function) (msg, event, filter->data);
2018 if (result != GDK_FILTER_CONTINUE)
2025 case GDK_FILTER_REMOVE:
2026 _gdk_event_queue_remove_link (_gdk_display, node);
2027 g_list_free_1 (node);
2028 gdk_event_free (event);
2032 case GDK_FILTER_TRANSLATE:
2033 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2034 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2038 case GDK_FILTER_CONTINUE:
2039 /* No more: Send unknown client messages on to Gtk for it to use */
2040 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2046 switch (msg->message)
2048 case WM_INPUTLANGCHANGE:
2049 _gdk_input_locale = (HKL) msg->lParam;
2050 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
2051 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
2052 LOCALE_IDEFAULTANSICODEPAGE,
2054 _gdk_input_codepage = atoi (buf);
2055 _gdk_keymap_serial++;
2057 g_print (" cs:%lu hkl:%p%s cp:%d",
2058 (gulong) msg->wParam,
2059 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
2060 _gdk_input_codepage));
2066 g_print (" %s ch:%.02x %s",
2067 _gdk_win32_key_to_string (msg->lParam),
2069 decode_key_lparam (msg->lParam)));
2071 /* If posted without us having keyboard focus, ignore */
2072 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
2073 !(HIWORD (msg->lParam) & KF_ALTDOWN))
2076 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
2077 * the keyboard is grabbed.
2079 if (!keyboard_grab &&
2080 (msg->wParam == VK_TAB ||
2081 msg->wParam == VK_SPACE ||
2082 msg->wParam == VK_F4))
2085 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
2091 g_print (" %s ch:%.02x %s",
2092 _gdk_win32_key_to_string (msg->lParam),
2094 decode_key_lparam (msg->lParam)));
2098 /* Ignore key messages intended for the IME */
2099 if (msg->wParam == VK_PROCESSKEY ||
2103 if (keyboard_grab &&
2104 !propagate (&window, msg,
2105 keyboard_grab->window,
2106 keyboard_grab->owner_events,
2107 GDK_ALL_EVENTS_MASK,
2108 doesnt_want_key, FALSE))
2111 if (GDK_WINDOW_DESTROYED (window))
2114 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
2115 msg->message == WM_SYSKEYDOWN) ?
2116 GDK_KEY_PRESS : GDK_KEY_RELEASE);
2117 event->key.window = window;
2118 event->key.time = _gdk_win32_get_next_tick (msg->time);
2119 event->key.keyval = GDK_KEY_VoidSymbol;
2120 event->key.string = NULL;
2121 event->key.length = 0;
2122 event->key.hardware_keycode = msg->wParam;
2123 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2124 if (HIWORD (msg->lParam) & KF_EXTENDED)
2126 switch (msg->wParam)
2129 event->key.hardware_keycode = VK_RCONTROL;
2131 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
2132 * for the right shift key.
2134 event->key.hardware_keycode = VK_RSHIFT;
2137 event->key.hardware_keycode = VK_RMENU;
2141 else if (msg->wParam == VK_SHIFT &&
2142 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
2143 event->key.hardware_keycode = VK_RSHIFT;
2145 API_CALL (GetKeyboardState, (key_state));
2147 /* 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]); */
2149 build_key_event_state (event, key_state);
2151 if (msg->wParam == VK_PACKET &&
2152 ToUnicode (VK_PACKET, HIWORD (msg->lParam), key_state, wbuf, 1, 0) == 1)
2153 event->key.keyval = gdk_unicode_to_keyval (wbuf[0]);
2155 gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (_gdk_display),
2156 event->key.hardware_keycode,
2162 fill_key_event_string (event);
2164 /* Reset MOD1_MASK if it is the Alt key itself */
2165 if (msg->wParam == VK_MENU)
2166 event->key.state &= ~GDK_MOD1_MASK;
2168 _gdk_win32_append_event (event);
2174 if (msg->wParam != VK_SPACE)
2176 /* To prevent beeps, don't let DefWindowProcW() be called */
2182 case WM_IME_STARTCOMPOSITION:
2183 in_ime_composition = TRUE;
2186 case WM_IME_ENDCOMPOSITION:
2187 in_ime_composition = FALSE;
2190 case WM_IME_COMPOSITION:
2191 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2192 * applications. Thus, handle WM_IME_COMPOSITION with
2193 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2194 * with ImmGetCompositionStringW().
2197 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2199 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2200 * for comments by other people that seems to have the same
2201 * experience. WM_IME_CHAR just gives question marks, apparently
2202 * because of going through some conversion to the current code
2205 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2206 * use WM_IME_COMPOSITION there, too, to simplify the code.
2208 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2210 if (!(msg->lParam & GCS_RESULTSTR))
2213 if (keyboard_grab &&
2214 !propagate (&window, msg,
2215 keyboard_grab->window,
2216 keyboard_grab->owner_events,
2217 GDK_ALL_EVENTS_MASK,
2218 doesnt_want_char, FALSE))
2221 if (GDK_WINDOW_DESTROYED (window))
2224 himc = ImmGetContext (msg->hwnd);
2225 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2226 wbuf, sizeof (wbuf));
2227 ImmReleaseContext (msg->hwnd, himc);
2231 API_CALL (GetKeyboardState, (key_state));
2233 for (i = 0; i < ccount; i++)
2235 if (window->event_mask & GDK_KEY_PRESS_MASK)
2237 /* Build a key press event */
2238 event = gdk_event_new (GDK_KEY_PRESS);
2239 event->key.window = window;
2240 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2241 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2243 _gdk_win32_append_event (event);
2246 if (window->event_mask & GDK_KEY_RELEASE_MASK)
2248 /* Build a key release event. */
2249 event = gdk_event_new (GDK_KEY_RELEASE);
2250 event->key.window = window;
2251 gdk_event_set_device (event, GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard);
2252 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2254 _gdk_win32_append_event (event);
2260 case WM_LBUTTONDOWN:
2264 case WM_MBUTTONDOWN:
2268 case WM_RBUTTONDOWN:
2272 case WM_XBUTTONDOWN:
2273 if (HIWORD (msg->wParam) == XBUTTON1)
2280 g_print (" (%d,%d)",
2281 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2283 assign_object (&window, find_window_for_mouse_event (window, msg));
2284 /* TODO_CSW?: there used to some synthesize and propagate */
2285 if (GDK_WINDOW_DESTROYED (window))
2288 if (pointer_grab == NULL)
2290 SetCapture (GDK_WINDOW_HWND (window));
2293 generate_button_event (GDK_BUTTON_PRESS, button,
2312 if (HIWORD (msg->wParam) == XBUTTON1)
2319 g_print (" (%d,%d)",
2320 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2322 assign_object (&window, find_window_for_mouse_event (window, msg));
2324 if (window->extension_events != 0 &&
2325 _gdk_input_ignore_core)
2327 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2332 if (pointer_grab != NULL && pointer_grab->implicit)
2334 gint state = build_pointer_event_state (msg);
2336 /* We keep the implicit grab until no buttons at all are held down */
2337 if ((state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (button - 1))) == 0)
2342 hwnd = WindowFromPoint (msg->pt);
2345 POINT client_pt = msg->pt;
2347 ScreenToClient (hwnd, &client_pt);
2348 GetClientRect (hwnd, &rect);
2349 if (PtInRect (&rect, client_pt))
2350 new_window = gdk_win32_handle_table_lookup (hwnd);
2352 synthesize_crossing_events (_gdk_display,
2353 pointer_grab->native_window, new_window,
2354 GDK_CROSSING_UNGRAB,
2356 0, /* TODO: Set right mask */
2359 assign_object (&mouse_window, new_window);
2363 generate_button_event (GDK_BUTTON_RELEASE, button,
2371 g_print (" %p (%d,%d)",
2372 (gpointer) msg->wParam,
2373 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2375 new_window = window;
2377 if (pointer_grab != NULL)
2383 hwnd = WindowFromPoint (pt);
2386 POINT client_pt = pt;
2388 ScreenToClient (hwnd, &client_pt);
2389 GetClientRect (hwnd, &rect);
2390 if (PtInRect (&rect, client_pt))
2391 new_window = gdk_win32_handle_table_lookup (hwnd);
2394 if (!pointer_grab->owner_events &&
2395 new_window != NULL &&
2396 new_window != pointer_grab->native_window)
2400 if (mouse_window != new_window)
2402 GDK_NOTE (EVENTS, g_print (" mouse_sinwod %p -> %p",
2403 mouse_window ? GDK_WINDOW_HWND (mouse_window) : NULL,
2404 new_window ? GDK_WINDOW_HWND (new_window) : NULL));
2405 synthesize_crossing_events (_gdk_display,
2406 mouse_window, new_window,
2407 GDK_CROSSING_NORMAL,
2409 0, /* TODO: Set right mask */
2412 assign_object (&mouse_window, new_window);
2413 if (new_window != NULL)
2414 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (new_window));
2417 assign_object (&window, find_window_for_mouse_event (window, msg));
2419 /* If we haven't moved, don't create any GDK event. Windows
2420 * sends WM_MOUSEMOVE messages after a new window is shows under
2421 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2423 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2424 msg->pt.y + _gdk_offset_y == current_root_y)
2427 current_root_x = msg->pt.x + _gdk_offset_x;
2428 current_root_y = msg->pt.y + _gdk_offset_y;
2430 event = gdk_event_new (GDK_MOTION_NOTIFY);
2431 event->motion.window = window;
2432 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2433 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2434 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2435 event->motion.x_root = current_root_x;
2436 event->motion.y_root = current_root_y;
2437 event->motion.axes = NULL;
2438 event->motion.state = build_pointer_event_state (msg);
2439 event->motion.is_hint = FALSE;
2440 gdk_event_set_device (event, _gdk_display->core_pointer);
2442 _gdk_win32_append_event (event);
2447 case WM_NCMOUSEMOVE:
2449 g_print (" (%d,%d)",
2450 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2454 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2455 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2458 hwnd = WindowFromPoint (msg->pt);
2461 POINT client_pt = msg->pt;
2463 ScreenToClient (hwnd, &client_pt);
2464 GetClientRect (hwnd, &rect);
2465 if (PtInRect (&rect, client_pt))
2466 new_window = gdk_win32_handle_table_lookup (hwnd);
2469 synthesize_crossing_events (_gdk_display,
2470 mouse_window, new_window,
2471 GDK_CROSSING_NORMAL,
2473 0, /* TODO: Set right mask */
2476 assign_object (&mouse_window, new_window);
2482 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2484 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2485 * that. Also, the position is in screen coordinates, not client
2486 * coordinates as with the button messages. I love the
2487 * consistency of Windows.
2489 point.x = GET_X_LPARAM (msg->lParam);
2490 point.y = GET_Y_LPARAM (msg->lParam);
2492 if ((hwnd = WindowFromPoint (point)) == NULL)
2496 if ((new_window = gdk_win32_handle_table_lookup (msg->hwnd)) == NULL)
2499 if (new_window != window)
2501 assign_object (&window, new_window);
2504 ScreenToClient (msg->hwnd, &point);
2506 event = gdk_event_new (GDK_SCROLL);
2507 event->scroll.window = window;
2508 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2509 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2510 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2511 event->scroll.x = (gint16) point.x;
2512 event->scroll.y = (gint16) point.y;
2513 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2514 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2515 event->scroll.state = build_pointer_event_state (msg);
2516 gdk_event_set_device (event, _gdk_display->core_pointer);
2518 _gdk_win32_append_event (event);
2524 /* Just print more debugging information, don't actually handle it. */
2527 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2528 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2529 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2530 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2531 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2532 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2533 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2534 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2535 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2537 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2538 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2539 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2543 /* Just print more debugging information, don't actually handle it. */
2546 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2547 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2548 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2549 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2550 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2551 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2552 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2553 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2554 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2556 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2557 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2558 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2561 case WM_MOUSEACTIVATE:
2565 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2566 || !window->accept_focus)
2568 *ret_valp = MA_NOACTIVATE;
2572 if (_gdk_modal_blocked (gdk_window_get_toplevel (window)))
2574 *ret_valp = MA_NOACTIVATEANDEAT;
2582 if (keyboard_grab != NULL &&
2583 !GDK_WINDOW_DESTROYED (keyboard_grab->window))
2585 generate_grab_broken_event (device_manager, keyboard_grab->window, TRUE, NULL);
2590 if (keyboard_grab != NULL &&
2591 !keyboard_grab->owner_events)
2594 if (!(window->event_mask & GDK_FOCUS_CHANGE_MASK))
2597 if (GDK_WINDOW_DESTROYED (window))
2600 generate_focus_event (device_manager, window, (msg->message == WM_SETFOCUS));
2605 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2607 if (GDK_WINDOW_DESTROYED (window))
2615 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2617 200, sync_timer_proc);
2621 handle_wm_paint (msg, window, FALSE, NULL);
2625 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2626 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2628 if (pointer_grab != NULL)
2629 grab_window = pointer_grab->window;
2631 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2634 if (grab_window != NULL && p_grab_cursor != NULL)
2635 hcursor = p_grab_cursor;
2636 else if (!GDK_WINDOW_DESTROYED (window))
2637 hcursor = GDK_WINDOW_IMPL_WIN32 (window->impl)->hcursor;
2641 if (hcursor != NULL)
2643 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2644 SetCursor (hcursor);
2651 switch (msg->wParam)
2655 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2661 case WM_ENTERSIZEMOVE:
2662 case WM_ENTERMENULOOP:
2663 if (msg->message == WM_ENTERSIZEMOVE)
2664 _modal_move_resize_window = msg->hwnd;
2666 _gdk_win32_begin_modal_call ();
2669 case WM_EXITSIZEMOVE:
2670 case WM_EXITMENULOOP:
2671 if (_modal_operation_in_progress)
2673 _modal_move_resize_window = NULL;
2674 _gdk_win32_end_modal_call ();
2678 case WM_CAPTURECHANGED:
2679 /* Sometimes we don't get WM_EXITSIZEMOVE, for instance when you
2680 select move/size in the menu and then click somewhere without
2681 moving/resizing. We work around this using WM_CAPTURECHANGED. */
2682 if (_modal_operation_in_progress)
2684 _modal_move_resize_window = NULL;
2685 _gdk_win32_end_modal_call ();
2689 case WM_WINDOWPOSCHANGING:
2690 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2691 g_print (" %s %s %dx%d@%+d%+d now below %p",
2692 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2693 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2694 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2695 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2696 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2697 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2699 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2700 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2702 if (GDK_WINDOW_IS_MAPPED (window))
2703 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2706 case WM_WINDOWPOSCHANGED:
2707 windowpos = (WINDOWPOS *) msg->lParam;
2708 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2709 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2710 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2711 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2712 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2713 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2714 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2716 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2718 /* Break grabs on unmap or minimize */
2719 if (windowpos->flags & SWP_HIDEWINDOW ||
2720 ((windowpos->flags & SWP_STATECHANGED) && IsIconic (msg->hwnd)))
2722 if (pointer_grab != NULL)
2724 if (pointer_grab->window == window)
2725 gdk_pointer_ungrab (msg->time);
2728 if (keyboard_grab->window == window)
2729 gdk_keyboard_ungrab (msg->time);
2732 /* Send MAP events */
2733 if ((windowpos->flags & SWP_SHOWWINDOW) &&
2734 !GDK_WINDOW_DESTROYED (window))
2736 event = gdk_event_new (GDK_MAP);
2737 event->any.window = window;
2738 _gdk_win32_append_event (event);
2741 /* Update window state */
2742 if (windowpos->flags & (SWP_STATECHANGED | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
2744 GdkWindowState set_bits, unset_bits, old_state, new_state;
2746 old_state = window->state;
2751 if (IsWindowVisible (msg->hwnd))
2752 unset_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2754 set_bits |= GDK_WINDOW_STATE_WITHDRAWN;
2756 if (IsIconic (msg->hwnd))
2757 set_bits |= GDK_WINDOW_STATE_ICONIFIED;
2759 unset_bits |= GDK_WINDOW_STATE_ICONIFIED;
2761 if (IsZoomed (msg->hwnd))
2762 set_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2764 unset_bits |= GDK_WINDOW_STATE_MAXIMIZED;
2766 gdk_synthesize_window_state (window, unset_bits, set_bits);
2768 new_state = window->state;
2770 /* Whenever one window changes iconified state we need to also
2771 * change the iconified state in all transient related windows,
2772 * as windows doesn't give icons for transient childrens.
2774 if ((old_state & GDK_WINDOW_STATE_ICONIFIED) !=
2775 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2776 do_show_window (window, (new_state & GDK_WINDOW_STATE_ICONIFIED));
2779 /* When un-minimizing, make sure we're stacked under any
2780 transient-type windows. */
2781 if (!(old_state & GDK_WINDOW_STATE_ICONIFIED) &&
2782 (new_state & GDK_WINDOW_STATE_ICONIFIED))
2783 ensure_stacking_on_unminimize (msg);
2786 /* Show, New size or position => configure event */
2787 if (!(windowpos->flags & SWP_NOCLIENTMOVE) ||
2788 !(windowpos->flags & SWP_NOCLIENTSIZE) ||
2789 (windowpos->flags & SWP_SHOWWINDOW))
2791 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2792 !IsIconic (msg->hwnd) &&
2793 !GDK_WINDOW_DESTROYED (window))
2794 _gdk_win32_emit_configure_event (window);
2796 if (window->extension_events != 0)
2797 _gdk_device_wintab_update_window_coords (window);
2800 if ((windowpos->flags & SWP_HIDEWINDOW) &&
2801 !GDK_WINDOW_DESTROYED (window))
2803 /* Send UNMAP events */
2804 event = gdk_event_new (GDK_UNMAP);
2805 event->any.window = window;
2806 _gdk_win32_append_event (event);
2808 /* Make transient parent the forground window when window unmaps */
2809 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2811 if (impl->transient_owner &&
2812 GetForegroundWindow () == GDK_WINDOW_HWND (window))
2813 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2816 if (!(windowpos->flags & SWP_NOCLIENTSIZE))
2818 if (window->resize_count > 1)
2819 window->resize_count -= 1;
2822 /* Call modal timer immediate so that we repaint faster after a resize. */
2823 if (_modal_operation_in_progress)
2824 modal_timer_proc (0,0,0,0);
2826 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2832 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2833 drag = (RECT *) msg->lParam;
2834 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2835 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2836 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2837 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2838 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2839 (msg->wParam == WMSZ_TOP ? "TOP" :
2840 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2841 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2843 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2845 _gdk_win32_rect_to_string (&rect),
2846 _gdk_win32_rect_to_string (drag)));
2848 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
2850 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2852 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2853 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2855 /* Resize in increments relative to the base size */
2856 rect.left = rect.top = 0;
2857 rect.right = impl->hints.base_width;
2858 rect.bottom = impl->hints.base_height;
2859 _gdk_win32_adjust_client_rect (window, &rect);
2860 point.x = rect.left;
2862 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2863 rect.left = point.x;
2865 point.x = rect.right;
2866 point.y = rect.bottom;
2867 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2868 rect.right = point.x;
2869 rect.bottom = point.y;
2871 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2872 _gdk_win32_rect_to_string (&rect)));
2875 switch (msg->wParam)
2878 if (drag->bottom == rect.bottom)
2880 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2883 case WMSZ_BOTTOMLEFT:
2884 if (drag->bottom == rect.bottom && drag->left == rect.left)
2886 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2887 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2891 if (drag->left == rect.left)
2893 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2897 if (drag->top == rect.top && drag->left == rect.left)
2899 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2900 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2904 if (drag->top == rect.top)
2906 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2910 if (drag->top == rect.top && drag->right == rect.right)
2912 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2913 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2917 if (drag->right == rect.right)
2919 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2922 case WMSZ_BOTTOMRIGHT:
2923 if (drag->bottom == rect.bottom && drag->right == rect.right)
2925 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2926 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2930 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2931 drag->top != orig_drag.top || drag->right != orig_drag.right)
2935 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2936 _gdk_win32_rect_to_string (drag)));
2940 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2942 if (impl->hint_flags & GDK_HINT_ASPECT)
2944 RECT decorated_rect;
2945 RECT undecorated_drag;
2946 int decoration_width, decoration_height;
2947 gdouble drag_aspect;
2948 int drag_width, drag_height, new_width, new_height;
2950 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2951 decorated_rect = rect;
2952 _gdk_win32_adjust_client_rect (window, &decorated_rect);
2954 /* Set undecorated_drag to the client area being dragged
2955 * out, in screen coordinates.
2957 undecorated_drag = *drag;
2958 undecorated_drag.left -= decorated_rect.left - rect.left;
2959 undecorated_drag.right -= decorated_rect.right - rect.right;
2960 undecorated_drag.top -= decorated_rect.top - rect.top;
2961 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
2963 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
2964 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
2966 drag_width = undecorated_drag.right - undecorated_drag.left;
2967 drag_height = undecorated_drag.bottom - undecorated_drag.top;
2969 drag_aspect = (gdouble) drag_width / drag_height;
2971 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
2972 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
2974 if (drag_aspect < impl->hints.min_aspect)
2976 /* Aspect is getting too narrow */
2977 switch (msg->wParam)
2981 /* User drags top or bottom edge outward. Keep height, increase width. */
2982 new_width = impl->hints.min_aspect * drag_height;
2983 drag->left -= (new_width - drag_width) / 2;
2984 drag->right = drag->left + new_width + decoration_width;
2986 case WMSZ_BOTTOMLEFT:
2987 case WMSZ_BOTTOMRIGHT:
2988 /* User drags bottom-left or bottom-right corner down. Adjust height. */
2989 new_height = drag_width / impl->hints.min_aspect;
2990 drag->bottom = drag->top + new_height + decoration_height;
2994 /* User drags left or right edge inward. Decrease height */
2995 new_height = drag_width / impl->hints.min_aspect;
2996 drag->top += (drag_height - new_height) / 2;
2997 drag->bottom = drag->top + new_height + decoration_height;
3001 /* User drags top-left or top-right corner up. Adjust height. */
3002 new_height = drag_width / impl->hints.min_aspect;
3003 drag->top = drag->bottom - new_height - decoration_height;
3006 else if (drag_aspect > impl->hints.max_aspect)
3008 /* Aspect is getting too wide */
3009 switch (msg->wParam)
3013 /* User drags top or bottom edge inward. Decrease width. */
3014 new_width = impl->hints.max_aspect * drag_height;
3015 drag->left += (drag_width - new_width) / 2;
3016 drag->right = drag->left + new_width + decoration_width;
3018 case WMSZ_BOTTOMLEFT:
3020 /* User drags bottom-left or top-left corner left. Adjust width. */
3021 new_width = impl->hints.max_aspect * drag_height;
3022 drag->left = drag->right - new_width - decoration_width;
3024 case WMSZ_BOTTOMRIGHT:
3026 /* User drags bottom-right or top-right corner right. Adjust width. */
3027 new_width = impl->hints.max_aspect * drag_height;
3028 drag->right = drag->left + new_width + decoration_width;
3032 /* User drags left or right edge outward. Increase height. */
3033 new_height = drag_width / impl->hints.max_aspect;
3034 drag->top -= (new_height - drag_height) / 2;
3035 drag->bottom = drag->top + new_height + decoration_height;
3042 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
3043 _gdk_win32_rect_to_string (drag)));
3047 case WM_GETMINMAXINFO:
3048 if (GDK_WINDOW_DESTROYED (window))
3051 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3052 mmi = (MINMAXINFO*) msg->lParam;
3053 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
3054 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3055 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3056 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3057 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3058 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3060 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
3062 rect.left = rect.top = 0;
3063 rect.right = impl->hints.min_width;
3064 rect.bottom = impl->hints.min_height;
3066 _gdk_win32_adjust_client_rect (window, &rect);
3068 mmi->ptMinTrackSize.x = rect.right - rect.left;
3069 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
3072 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
3076 rect.left = rect.top = 0;
3077 rect.right = impl->hints.max_width;
3078 rect.bottom = impl->hints.max_height;
3080 _gdk_win32_adjust_client_rect (window, &rect);
3082 /* at least on win9x we have the 16 bit trouble */
3083 maxw = rect.right - rect.left;
3084 maxh = rect.bottom - rect.top;
3085 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
3086 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
3089 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
3091 /* Don't call DefWindowProcW() */
3092 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
3093 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3094 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3095 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3096 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3097 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3100 mmi->ptMaxTrackSize.x = 30000;
3101 mmi->ptMaxTrackSize.y = 30000;
3106 if (GDK_WINDOW_DESTROYED (window))
3109 event = gdk_event_new (GDK_DELETE);
3110 event->any.window = window;
3112 _gdk_win32_append_event (event);
3114 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
3116 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
3118 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3125 if (pointer_grab != NULL)
3127 if (pointer_grab->window == window)
3128 gdk_pointer_ungrab (msg->time);
3131 if (keyboard_grab &&
3132 keyboard_grab->window == window)
3133 gdk_keyboard_ungrab (msg->time);
3135 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
3136 gdk_window_destroy_notify (window);
3138 if (window == NULL || GDK_WINDOW_DESTROYED (window))
3141 event = gdk_event_new (GDK_DESTROY);
3142 event->any.window = window;
3144 _gdk_win32_append_event (event);
3149 case WM_DISPLAYCHANGE:
3150 handle_display_change ();
3153 case WM_DESTROYCLIPBOARD:
3154 if (!_ignore_destroy_clipboard)
3156 event = gdk_event_new (GDK_SELECTION_CLEAR);
3157 event->selection.window = window;
3158 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3159 event->selection.time = _gdk_win32_get_next_tick (msg->time);
3160 _gdk_win32_append_event (event);
3169 case WM_RENDERFORMAT:
3170 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
3172 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
3174 GDK_NOTE (EVENTS, g_print (" (target not found)"));
3179 /* We need to render to clipboard immediately, don't call
3180 * _gdk_win32_append_event()
3182 event = gdk_event_new (GDK_SELECTION_REQUEST);
3183 event->selection.window = window;
3184 event->selection.send_event = FALSE;
3185 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3186 event->selection.target = target;
3187 event->selection.property = _gdk_selection;
3188 event->selection.requestor = gdk_win32_handle_table_lookup (msg->hwnd);
3189 event->selection.time = msg->time;
3191 fixup_event (event);
3192 GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)"));
3193 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
3194 _gdk_event_emit (event);
3195 gdk_event_free (event);
3197 /* Now the clipboard owner should have rendered */
3198 if (!_delayed_rendering_data)
3200 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3204 if (msg->wParam == CF_DIB)
3206 _delayed_rendering_data =
3207 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3209 if (!_delayed_rendering_data)
3211 g_warning ("Cannot convert to DIB from delayed rendered image");
3216 /* The requestor is holding the clipboard, no
3217 * OpenClipboard() is required/possible
3220 g_print (" SetClipboardData(%s,%p)",
3221 _gdk_win32_cf_to_string (msg->wParam),
3222 _delayed_rendering_data));
3224 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3225 _delayed_rendering_data = NULL;
3230 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3231 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3232 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3233 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3234 HIWORD (msg->wParam) ? " minimized" : "",
3235 (HWND) msg->lParam));
3236 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3237 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3240 if (_gdk_modal_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3242 GdkWindow *modal_current = _gdk_modal_current ();
3243 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3249 /* Bring any tablet contexts to the top of the overlap order when
3250 * one of our windows is activated.
3251 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3254 if (LOWORD(msg->wParam) != WA_INACTIVE)
3255 _gdk_input_set_tablet_active ();
3258 case WM_ACTIVATEAPP:
3259 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3260 msg->wParam ? "YES" : "NO",
3261 (gint64) msg->lParam));
3262 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3263 ensure_stacking_on_activate_app (msg, window);
3266 /* Handle WINTAB events here, as we know that gdkinput.c will
3267 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3268 * constants as case labels.
3271 GDK_NOTE (EVENTS, g_print (" %d %p",
3272 (int) msg->wParam, (gpointer) msg->lParam));
3276 GDK_NOTE (EVENTS, g_print (" %d %p",
3277 (int) msg->wParam, (gpointer) msg->lParam));
3281 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3282 (gpointer) msg->wParam,
3283 LOWORD (msg->lParam),
3284 HIWORD (msg->lParam)));
3288 event = gdk_event_new (GDK_NOTHING);
3289 event->any.window = window;
3290 g_object_ref (window);
3292 if (_gdk_input_other_event (event, msg, window))
3293 _gdk_win32_append_event (event);
3295 gdk_event_free (event);
3303 g_object_unref (window);
3310 _gdk_win32_display_queue_events (GdkDisplay *display)
3314 if (modal_win32_dialog != NULL)
3317 while (!_gdk_event_queue_find_first (display) &&
3318 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3320 TranslateMessage (&msg);
3321 DispatchMessageW (&msg);
3326 gdk_event_prepare (GSource *source,
3331 GDK_THREADS_ENTER ();
3335 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3336 (modal_win32_dialog == NULL &&
3337 GetQueueStatus (QS_ALLINPUT) != 0));
3339 GDK_THREADS_LEAVE ();
3345 gdk_event_check (GSource *source)
3349 GDK_THREADS_ENTER ();
3351 if (event_poll_fd.revents & G_IO_IN)
3353 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3354 (modal_win32_dialog == NULL &&
3355 GetQueueStatus (QS_ALLINPUT) != 0));
3362 GDK_THREADS_LEAVE ();
3368 gdk_event_dispatch (GSource *source,
3369 GSourceFunc callback,
3374 GDK_THREADS_ENTER ();
3376 _gdk_win32_display_queue_events (_gdk_display);
3377 event = _gdk_event_unqueue (_gdk_display);
3381 _gdk_event_emit (event);
3383 gdk_event_free (event);
3385 /* Do drag & drop if it is still pending */
3386 if (_dnd_source_state == GDK_WIN32_DND_PENDING)
3388 _dnd_source_state = GDK_WIN32_DND_DRAGGING;
3389 _gdk_win32_dnd_do_dragdrop ();
3390 _dnd_source_state = GDK_WIN32_DND_NONE;
3394 GDK_THREADS_LEAVE ();
3400 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3402 modal_win32_dialog = window;