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 "gdkprivate-win32.h"
50 #include "gdkinput-win32.h"
51 #include "gdkkeysyms.h"
75 #define MK_XBUTTON1 32
76 #define MK_XBUTTON2 64
80 * Private function declarations
83 static gboolean gdk_event_translate (MSG *msg,
85 static void handle_wm_paint (MSG *msg,
87 gboolean return_exposes,
90 static gboolean gdk_event_prepare (GSource *source,
92 static gboolean gdk_event_check (GSource *source);
93 static gboolean gdk_event_dispatch (GSource *source,
97 static void append_event (GdkEvent *event);
98 static gboolean is_modally_blocked (GdkWindow *window);
100 /* Private variable declarations
103 static GList *client_filters; /* Filters for client messages */
105 static HCURSOR p_grab_cursor;
107 static GSourceFuncs event_funcs = {
114 GPollFD event_poll_fd;
116 static GdkWindow *current_toplevel = NULL;
117 static gint current_x, current_y;
118 static gint current_root_x, current_root_y;
119 static UINT client_message;
121 static UINT got_gdk_events_message;
122 static HWND modal_win32_dialog = NULL;
125 static HKL latin_locale = NULL;
128 static gboolean in_ime_composition = FALSE;
129 static UINT modal_timer;
130 static UINT sync_timer = 0;
132 static int debug_indent = 0;
135 assign_object (gpointer lhsp,
138 if (*(gpointer *)lhsp != rhs)
140 if (*(gpointer *)lhsp != NULL)
141 g_object_unref (*(gpointer *)lhsp);
142 *(gpointer *)lhsp = rhs;
149 track_mouse_event (DWORD dwFlags,
152 typedef BOOL (WINAPI *PFN_TrackMouseEvent) (LPTRACKMOUSEEVENT);
153 static PFN_TrackMouseEvent p_TrackMouseEvent = NULL;
154 static gboolean once = FALSE;
159 HINSTANCE commctrl32;
161 user32 = GetModuleHandle ("user32.dll");
162 if ((p_TrackMouseEvent = (PFN_TrackMouseEvent)GetProcAddress (user32, "TrackMouseEvent")) == NULL)
164 if ((commctrl32 = LoadLibrary ("commctrl32.dll")) != NULL)
165 p_TrackMouseEvent = (PFN_TrackMouseEvent)
166 GetProcAddress (commctrl32, "_TrackMouseEvent");
171 if (p_TrackMouseEvent)
174 tme.cbSize = sizeof(TRACKMOUSEEVENT);
175 tme.dwFlags = dwFlags;
176 tme.hwndTrack = hwnd;
177 tme.dwHoverTime = HOVER_DEFAULT; /* not used */
179 if (!p_TrackMouseEvent (&tme))
180 WIN32_API_FAILED ("TrackMouseEvent");
181 else if (dwFlags == TME_LEAVE)
182 GDK_NOTE (EVENTS, g_print(" (TrackMouseEvent %p)", hwnd));
183 else if (dwFlags == TME_CANCEL)
184 GDK_NOTE (EVENTS, g_print(" (cancel TrackMouseEvent %p)", hwnd));
189 _gdk_win32_get_next_tick (gulong suggested_tick)
191 static gulong cur_tick = 0;
193 if (suggested_tick == 0)
194 suggested_tick = GetTickCount ();
195 if (suggested_tick <= cur_tick)
198 return cur_tick = suggested_tick;
202 generate_focus_event (GdkWindow *window,
207 event = gdk_event_new (GDK_FOCUS_CHANGE);
208 event->focus_change.window = window;
209 event->focus_change.in = in;
211 append_event (event);
215 generate_grab_broken_event (GdkWindow *window,
217 GdkWindow *grab_window)
219 GdkEvent *event = gdk_event_new (GDK_GRAB_BROKEN);
221 event->grab_broken.window = window;
222 event->grab_broken.send_event = 0;
223 event->grab_broken.keyboard = keyboard;
224 event->grab_broken.implicit = FALSE;
225 event->grab_broken.grab_window = grab_window;
227 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_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_events_pending (void)
400 return (_gdk_event_queue_find_first (_gdk_display) ||
401 (modal_win32_dialog == NULL &&
402 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
406 gdk_event_get_graphics_expose (GdkWindow *window)
409 GdkEvent *event = NULL;
411 g_return_val_if_fail (window != NULL, NULL);
413 GDK_NOTE (EVENTS, g_print ("gdk_event_get_graphics_expose\n"));
415 if (PeekMessageW (&msg, GDK_WINDOW_HWND (window), WM_PAINT, WM_PAINT, PM_REMOVE))
417 handle_wm_paint (&msg, window, TRUE, &event);
420 GDK_NOTE (EVENTS, g_print ("gdk_event_get_graphics_expose: got it!\n"));
425 GDK_NOTE (EVENTS, g_print ("gdk_event_get_graphics_expose: nope\n"));
429 #if 0 /* Unused, but might be useful to re-introduce in some debugging output? */
432 event_mask_string (GdkEventMask mask)
434 static char bfr[500];
439 if (mask & GDK_##x##_MASK) \
440 p += g_sprintf (p, "%s" #x, (p > bfr ? " " : ""))
442 BIT (POINTER_MOTION);
443 BIT (POINTER_MOTION_HINT);
445 BIT (BUTTON1_MOTION);
446 BIT (BUTTON2_MOTION);
447 BIT (BUTTON3_MOTION);
449 BIT (BUTTON_RELEASE);
456 BIT (PROPERTY_CHANGE);
457 BIT (VISIBILITY_NOTIFY);
470 _gdk_windowing_pointer_grab (GdkWindow *window,
471 GdkWindow *native_window,
472 gboolean owner_events,
473 GdkEventMask event_mask,
474 GdkWindow *confine_to,
479 GdkCursorPrivate *cursor_private;
482 g_return_val_if_fail (window != NULL, 0);
483 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
484 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
486 cursor_private = (GdkCursorPrivate*) cursor;
490 else if ((hcursor = CopyCursor (cursor_private->hcursor)) == NULL)
491 WIN32_API_FAILED ("CopyCursor");
493 return_val = _gdk_input_grab_pointer (native_window,
499 if (return_val == GDK_GRAB_SUCCESS)
501 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) native_window)->impl);
503 SetCapture (GDK_WINDOW_HWND (native_window));
504 /* TODO_CSW: grab brokens, confine window, input_grab */
505 if (p_grab_cursor != NULL)
507 if (GetCursor () == p_grab_cursor)
509 DestroyCursor (p_grab_cursor);
512 p_grab_cursor = hcursor;
514 if (p_grab_cursor != NULL)
515 SetCursor (p_grab_cursor);
516 else if (impl->hcursor != NULL)
517 SetCursor (impl->hcursor);
519 SetCursor (LoadCursor (NULL, IDC_ARROW));
527 gdk_display_pointer_ungrab (GdkDisplay *display,
530 GdkPointerGrabInfo *info;
532 info = _gdk_display_get_last_pointer_grab (display);
535 info->serial_end = 0;
538 /* TODO_CSW: cursor, confines, etc */
540 _gdk_display_pointer_grab_update (display, 0);
545 find_window_for_mouse_event (GdkWindow* reported_window,
551 GdkWindow* other_window = NULL;
553 if (!_gdk_display_get_last_pointer_grab (_gdk_display))
554 return reported_window;
556 points = MAKEPOINTS (msg->lParam);
559 ClientToScreen (msg->hwnd, &pt);
561 hwnd = WindowFromPoint (pt);
567 GetClientRect (hwnd, &rect);
568 ScreenToClient (hwnd, &pt);
569 if (!PtInRect (&rect, pt))
572 other_window = gdk_win32_handle_table_lookup ((GdkNativeWindow) hwnd);
575 if (other_window == NULL)
578 /* need to also adjust the coordinates to the new window */
581 ClientToScreen (msg->hwnd, &pt);
582 ScreenToClient (GDK_WINDOW_HWND (other_window), &pt);
583 /* ATTENTION: need to update client coords */
584 msg->lParam = MAKELPARAM (pt.x, pt.y);
590 gdk_keyboard_grab (GdkWindow *window,
591 gboolean owner_events,
597 g_return_val_if_fail (window != NULL, 0);
598 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
600 GDK_NOTE (EVENTS, g_print ("gdk_keyboard_grab %p%s\n",
601 GDK_WINDOW_HWND (window), owner_events ? " OWNER_EVENTS" : ""));
603 display = gdk_drawable_get_display (window);
604 toplevel = gdk_window_get_toplevel (window);
606 _gdk_display_set_has_keyboard_grab (display,
613 return GDK_GRAB_SUCCESS;
617 gdk_display_keyboard_ungrab (GdkDisplay *display,
620 GDK_NOTE (EVENTS, g_print ("gdk_display_keyboard_ungrab\n"));
621 _gdk_display_unset_has_keyboard_grab (display, FALSE);
625 gdk_display_add_client_message_filter (GdkDisplay *display,
626 GdkAtom message_type,
631 gdk_add_client_message_filter (message_type, func, data);
635 gdk_add_client_message_filter (GdkAtom message_type,
639 GdkClientFilter *filter = g_new (GdkClientFilter, 1);
641 filter->type = message_type;
642 filter->function = func;
645 client_filters = g_list_append (client_filters, filter);
649 build_key_event_state (GdkEvent *event,
652 event->key.state = 0;
654 if (key_state[VK_SHIFT] & 0x80)
655 event->key.state |= GDK_SHIFT_MASK;
657 if (key_state[VK_CAPITAL] & 0x01)
658 event->key.state |= GDK_LOCK_MASK;
660 if (key_state[VK_LBUTTON] & 0x80)
661 event->key.state |= GDK_BUTTON1_MASK;
662 if (key_state[VK_MBUTTON] & 0x80)
663 event->key.state |= GDK_BUTTON2_MASK;
664 if (key_state[VK_RBUTTON] & 0x80)
665 event->key.state |= GDK_BUTTON3_MASK;
666 if (key_state[VK_XBUTTON1] & 0x80)
667 event->key.state |= GDK_BUTTON4_MASK;
668 if (key_state[VK_XBUTTON2] & 0x80)
669 event->key.state |= GDK_BUTTON5_MASK;
671 if (_gdk_keyboard_has_altgr &&
672 (key_state[VK_LCONTROL] & 0x80) &&
673 (key_state[VK_RMENU] & 0x80))
675 event->key.group = 1;
676 event->key.state |= GDK_MOD2_MASK;
677 if (key_state[VK_RCONTROL] & 0x80)
678 event->key.state |= GDK_CONTROL_MASK;
679 if (key_state[VK_LMENU] & 0x80)
680 event->key.state |= GDK_MOD1_MASK;
684 event->key.group = 0;
685 if (key_state[VK_CONTROL] & 0x80)
686 event->key.state |= GDK_CONTROL_MASK;
687 if (key_state[VK_MENU] & 0x80)
688 event->key.state |= GDK_MOD1_MASK;
693 build_pointer_event_state (MSG *msg)
699 if (msg->wParam & MK_CONTROL)
700 state |= GDK_CONTROL_MASK;
702 if ((msg->message != WM_LBUTTONDOWN &&
703 (msg->wParam & MK_LBUTTON)) ||
704 msg->message == WM_LBUTTONUP)
705 state |= GDK_BUTTON1_MASK;
707 if ((msg->message != WM_MBUTTONDOWN &&
708 (msg->wParam & MK_MBUTTON)) ||
709 msg->message == WM_MBUTTONUP)
710 state |= GDK_BUTTON2_MASK;
712 if ((msg->message != WM_RBUTTONDOWN &&
713 (msg->wParam & MK_RBUTTON)) ||
714 msg->message == WM_RBUTTONUP)
715 state |= GDK_BUTTON3_MASK;
717 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON1) &&
718 (msg->wParam & MK_XBUTTON1)) ||
719 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON1))
720 state |= GDK_BUTTON4_MASK;
722 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON2) &&
723 (msg->wParam & MK_XBUTTON2)) ||
724 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON2))
725 state |= GDK_BUTTON5_MASK;
727 if (msg->wParam & MK_SHIFT)
728 state |= GDK_SHIFT_MASK;
730 if (GetKeyState (VK_MENU) < 0)
731 state |= GDK_MOD1_MASK;
733 if (GetKeyState (VK_CAPITAL) & 0x1)
734 state |= GDK_LOCK_MASK;
740 build_wm_ime_composition_event (GdkEvent *event,
745 event->key.time = _gdk_win32_get_next_tick (msg->time);
747 build_key_event_state (event, key_state);
749 event->key.hardware_keycode = 0; /* FIXME: What should it be? */
750 event->key.string = NULL;
751 event->key.length = 0;
752 event->key.keyval = gdk_unicode_to_keyval (wc);
755 #ifdef G_ENABLE_DEBUG
758 print_event_state (guint state)
760 #define CASE(bit) if (state & GDK_ ## bit ## _MASK) g_print (#bit " ");
778 _gdk_win32_print_event (const GdkEvent *event)
780 gchar *escaped, *kvname;
781 gchar *selection_name, *target_name, *property_name;
783 g_print ("%s%*s===> ", (debug_indent > 0 ? "\n" : ""), debug_indent, "");
784 switch (event->any.type)
786 #define CASE(x) case x: g_print (#x); break;
791 CASE (GDK_MOTION_NOTIFY);
792 CASE (GDK_BUTTON_PRESS);
793 CASE (GDK_2BUTTON_PRESS);
794 CASE (GDK_3BUTTON_PRESS);
795 CASE (GDK_BUTTON_RELEASE);
796 CASE (GDK_KEY_PRESS);
797 CASE (GDK_KEY_RELEASE);
798 CASE (GDK_ENTER_NOTIFY);
799 CASE (GDK_LEAVE_NOTIFY);
800 CASE (GDK_FOCUS_CHANGE);
801 CASE (GDK_CONFIGURE);
804 CASE (GDK_PROPERTY_NOTIFY);
805 CASE (GDK_SELECTION_CLEAR);
806 CASE (GDK_SELECTION_REQUEST);
807 CASE (GDK_SELECTION_NOTIFY);
808 CASE (GDK_PROXIMITY_IN);
809 CASE (GDK_PROXIMITY_OUT);
810 CASE (GDK_DRAG_ENTER);
811 CASE (GDK_DRAG_LEAVE);
812 CASE (GDK_DRAG_MOTION);
813 CASE (GDK_DRAG_STATUS);
814 CASE (GDK_DROP_START);
815 CASE (GDK_DROP_FINISHED);
816 CASE (GDK_CLIENT_EVENT);
817 CASE (GDK_VISIBILITY_NOTIFY);
818 CASE (GDK_NO_EXPOSE);
820 CASE (GDK_WINDOW_STATE);
822 CASE (GDK_OWNER_CHANGE);
823 CASE (GDK_GRAB_BROKEN);
825 default: g_assert_not_reached ();
828 g_print (" %p ", event->any.window ? GDK_WINDOW_HWND (event->any.window) : NULL);
830 switch (event->any.type)
834 _gdk_win32_gdkrectangle_to_string (&event->expose.area),
835 event->expose.count);
837 case GDK_MOTION_NOTIFY:
838 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s",
839 event->motion.x, event->motion.y,
840 event->motion.x_root, event->motion.y_root,
841 event->motion.is_hint ? "HINT " : "");
842 print_event_state (event->motion.state);
844 case GDK_BUTTON_PRESS:
845 case GDK_2BUTTON_PRESS:
846 case GDK_3BUTTON_PRESS:
847 case GDK_BUTTON_RELEASE:
848 g_print ("%d (%.4g,%.4g) (%.4g,%.4g) ",
849 event->button.button,
850 event->button.x, event->button.y,
851 event->button.x_root, event->button.y_root);
852 print_event_state (event->button.state);
855 case GDK_KEY_RELEASE:
856 if (event->key.length == 0)
857 escaped = g_strdup ("");
859 escaped = g_strescape (event->key.string, NULL);
860 kvname = gdk_keyval_name (event->key.keyval);
861 g_print ("%#.02x group:%d %s %d:\"%s\" ",
862 event->key.hardware_keycode, event->key.group,
863 (kvname ? kvname : "??"),
867 print_event_state (event->key.state);
869 case GDK_ENTER_NOTIFY:
870 case GDK_LEAVE_NOTIFY:
871 g_print ("%p (%.4g,%.4g) (%.4g,%.4g) %s %s%s",
872 event->crossing.subwindow == NULL ? NULL : GDK_WINDOW_HWND (event->crossing.subwindow),
873 event->crossing.x, event->crossing.y,
874 event->crossing.x_root, event->crossing.y_root,
875 (event->crossing.mode == GDK_CROSSING_NORMAL ? "NORMAL" :
876 (event->crossing.mode == GDK_CROSSING_GRAB ? "GRAB" :
877 (event->crossing.mode == GDK_CROSSING_UNGRAB ? "UNGRAB" :
879 (event->crossing.detail == GDK_NOTIFY_ANCESTOR ? "ANCESTOR" :
880 (event->crossing.detail == GDK_NOTIFY_VIRTUAL ? "VIRTUAL" :
881 (event->crossing.detail == GDK_NOTIFY_INFERIOR ? "INFERIOR" :
882 (event->crossing.detail == GDK_NOTIFY_NONLINEAR ? "NONLINEAR" :
883 (event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL ? "NONLINEAR_VIRTUAL" :
884 (event->crossing.detail == GDK_NOTIFY_UNKNOWN ? "UNKNOWN" :
886 event->crossing.focus ? " FOCUS" : "");
887 print_event_state (event->crossing.state);
889 case GDK_FOCUS_CHANGE:
890 g_print ("%s", (event->focus_change.in ? "IN" : "OUT"));
893 g_print ("x:%d y:%d w:%d h:%d",
894 event->configure.x, event->configure.y,
895 event->configure.width, event->configure.height);
897 case GDK_SELECTION_CLEAR:
898 case GDK_SELECTION_REQUEST:
899 case GDK_SELECTION_NOTIFY:
900 selection_name = gdk_atom_name (event->selection.selection);
901 target_name = gdk_atom_name (event->selection.target);
902 property_name = gdk_atom_name (event->selection.property);
903 g_print ("sel:%s tgt:%s prop:%s",
904 selection_name, target_name, property_name);
905 g_free (selection_name);
906 g_free (target_name);
907 g_free (property_name);
911 case GDK_DRAG_MOTION:
912 case GDK_DRAG_STATUS:
914 case GDK_DROP_FINISHED:
915 if (event->dnd.context != NULL)
916 g_print ("ctx:%p: %s %s src:%p dest:%p",
918 _gdk_win32_drag_protocol_to_string (event->dnd.context->protocol),
919 event->dnd.context->is_source ? "SOURCE" : "DEST",
920 event->dnd.context->source_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->source_window),
921 event->dnd.context->dest_window == NULL ? NULL : GDK_WINDOW_HWND (event->dnd.context->dest_window));
923 case GDK_CLIENT_EVENT:
924 g_print ("%s %d %ld %ld %ld %ld %ld",
925 gdk_atom_name (event->client.message_type),
926 event->client.data_format,
927 event->client.data.l[0],
928 event->client.data.l[1],
929 event->client.data.l[2],
930 event->client.data.l[3],
931 event->client.data.l[4]);
934 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",
935 event->scroll.x, event->scroll.y,
936 event->scroll.x_root, event->scroll.y_root,
937 (event->scroll.direction == GDK_SCROLL_UP ? "UP" :
938 (event->scroll.direction == GDK_SCROLL_DOWN ? "DOWN" :
939 (event->scroll.direction == GDK_SCROLL_LEFT ? "LEFT" :
940 (event->scroll.direction == GDK_SCROLL_RIGHT ? "RIGHT" :
942 print_event_state (event->scroll.state);
944 case GDK_WINDOW_STATE:
946 _gdk_win32_window_state_to_string (event->window_state.changed_mask),
947 _gdk_win32_window_state_to_string (event->window_state.new_window_state));
950 (event->setting.action == GDK_SETTING_ACTION_NEW ? "NEW" :
951 (event->setting.action == GDK_SETTING_ACTION_CHANGED ? "CHANGED" :
952 (event->setting.action == GDK_SETTING_ACTION_DELETED ? "DELETED" :
954 (event->setting.name ? event->setting.name : "NULL"));
955 case GDK_GRAB_BROKEN:
957 (event->grab_broken.keyboard ? "KEYBOARD" : "POINTER"),
958 (event->grab_broken.implicit ? "IMPLICIT" : "EXPLICIT"),
959 (event->grab_broken.grab_window ? GDK_WINDOW_HWND (event->grab_broken.grab_window) : 0));
964 g_print ("%s", (debug_indent == 0 ? "\n" : ""));
968 decode_key_lparam (LPARAM lParam)
970 static char buf[100];
973 if (HIWORD (lParam) & KF_UP)
974 p += g_sprintf (p, "KF_UP ");
975 if (HIWORD (lParam) & KF_REPEAT)
976 p += g_sprintf (p, "KF_REPEAT ");
977 if (HIWORD (lParam) & KF_ALTDOWN)
978 p += g_sprintf (p, "KF_ALTDOWN ");
979 if (HIWORD (lParam) & KF_EXTENDED)
980 p += g_sprintf (p, "KF_EXTENDED ");
981 p += g_sprintf (p, "sc:%d rep:%d", LOBYTE (HIWORD (lParam)), LOWORD (lParam));
989 fixup_event (GdkEvent *event)
991 if (event->any.window)
992 g_object_ref (event->any.window);
993 if (((event->any.type == GDK_ENTER_NOTIFY) ||
994 (event->any.type == GDK_LEAVE_NOTIFY)) &&
995 (event->crossing.subwindow != NULL))
996 g_object_ref (event->crossing.subwindow);
997 event->any.send_event = InSendMessage ();
1001 append_event (GdkEvent *event)
1005 fixup_event (event);
1007 link = _gdk_event_queue_append (_gdk_display, event);
1008 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1009 /* event morphing, the passed in may not be valid afterwards */
1010 _gdk_windowing_got_event (_gdk_display, link, event, 0);
1012 _gdk_event_queue_append (_gdk_display, event);
1013 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1018 fill_key_event_string (GdkEvent *event)
1023 /* Fill in event->string crudely, since various programs
1028 if (event->key.keyval != GDK_VoidSymbol)
1029 c = gdk_keyval_to_unicode (event->key.keyval);
1033 gsize bytes_written;
1036 /* Apply the control key - Taken from Xlib
1038 if (event->key.state & GDK_CONTROL_MASK)
1040 if ((c >= '@' && c < '\177') || c == ' ')
1044 event->key.string = g_memdup ("\0\0", 2);
1045 event->key.length = 1;
1048 else if (c >= '3' && c <= '7')
1049 c -= ('3' - '\033');
1056 len = g_unichar_to_utf8 (c, buf);
1059 event->key.string = g_locale_from_utf8 (buf, len,
1060 NULL, &bytes_written,
1062 if (event->key.string)
1063 event->key.length = bytes_written;
1065 else if (event->key.keyval == GDK_Escape)
1067 event->key.length = 1;
1068 event->key.string = g_strdup ("\033");
1070 else if (event->key.keyval == GDK_Return ||
1071 event->key.keyval == GDK_KP_Enter)
1073 event->key.length = 1;
1074 event->key.string = g_strdup ("\r");
1077 if (!event->key.string)
1079 event->key.length = 0;
1080 event->key.string = g_strdup ("");
1084 static GdkFilterReturn
1085 apply_event_filters (GdkWindow *window,
1089 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1094 event = gdk_event_new (GDK_NOTHING);
1096 event->any.window = g_object_ref (window);
1097 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1099 /* I think GdkFilterFunc semantics require the passed-in event
1100 * to already be in the queue. The filter func can generate
1101 * more events and append them after it if it likes.
1103 node = _gdk_event_queue_append (_gdk_display, event);
1108 GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
1110 tmp_list = tmp_list->next;
1111 result = filter->function (msg, event, filter->data);
1112 if (result != GDK_FILTER_CONTINUE)
1116 if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
1118 _gdk_event_queue_remove_link (_gdk_display, node);
1119 g_list_free_1 (node);
1120 gdk_event_free (event);
1122 else /* GDK_FILTER_TRANSLATE */
1124 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1125 fixup_event (event);
1126 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1132 * On Windows, transient windows will not have their own taskbar entries.
1133 * Because of this, we must hide and restore groups of transients in both
1134 * directions. That is, all transient children must be hidden or restored
1135 * with this window, but if this window's transient owner also has a
1136 * transient owner then this window's transient owner must be hidden/restored
1137 * with this one. And etc, up the chain until we hit an ancestor that has no
1140 * It would be a good idea if applications don't chain transient windows
1141 * together. There's a limit to how much evil GTK can try to shield you
1145 show_window_recurse (GdkWindow *window, gboolean hide_window)
1147 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1148 GSList *children = impl->transient_children;
1149 GdkWindow *child = NULL;
1151 if (!impl->changing_state)
1153 impl->changing_state = TRUE;
1155 if (children != NULL)
1157 while (children != NULL)
1159 child = children->data;
1160 show_window_recurse (child, hide_window);
1162 children = g_slist_next (children);
1166 if (GDK_WINDOW_IS_MAPPED (window))
1170 if (GDK_WINDOW_OBJECT (window)->state & GDK_WINDOW_STATE_ICONIFIED)
1172 if (GDK_WINDOW_OBJECT (window)->state & GDK_WINDOW_STATE_MAXIMIZED)
1174 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
1178 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1184 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
1188 impl->changing_state = FALSE;
1193 do_show_window (GdkWindow *window, gboolean hide_window)
1195 GdkWindow *tmp_window = NULL;
1196 GdkWindowImplWin32 *tmp_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1198 if (!tmp_impl->changing_state)
1200 /* Find the top-level window in our transient chain. */
1201 while (tmp_impl->transient_owner != NULL)
1203 tmp_window = tmp_impl->transient_owner;
1204 tmp_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (tmp_window)->impl);
1207 /* If we couldn't find one, use the window provided. */
1208 if (tmp_window == NULL)
1210 tmp_window = window;
1213 /* Recursively show/hide every window in the chain. */
1214 if (tmp_window != window)
1216 show_window_recurse (tmp_window, hide_window);
1222 synthesize_enter_or_leave_event (GdkWindow *window,
1225 GdkCrossingMode mode,
1226 GdkNotifyType detail)
1232 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1234 event = gdk_event_new (type);
1235 event->crossing.window = window;
1236 event->crossing.subwindow = NULL;
1237 event->crossing.time = _gdk_win32_get_next_tick (msg->time);
1238 event->crossing.x = pt.x;
1239 event->crossing.y = pt.y;
1240 event->crossing.x_root = msg->pt.x + _gdk_offset_x;
1241 event->crossing.y_root = msg->pt.y + _gdk_offset_y;
1242 event->crossing.mode = mode;
1243 event->crossing.detail = detail;
1244 event->crossing.focus = TRUE; /* FIXME: Set correctly */
1245 event->crossing.state = 0; /* FIXME: Set correctly */
1247 append_event (event);
1249 if (type == GDK_ENTER_NOTIFY &&
1250 ((GdkWindowObject *) window)->extension_events != 0)
1251 _gdk_input_enter_event (window);
1255 synthesize_expose_events (GdkWindow *window)
1259 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
1260 GList *list = gdk_window_get_children (window);
1267 synthesize_expose_events ((GdkWindow *) list->data);
1273 if (((GdkWindowObject *) window)->input_only)
1275 else if (!(hdc = GetDC (impl->handle)))
1276 WIN32_GDI_FAILED ("GetDC");
1279 if ((k = GetClipBox (hdc, &r)) == ERROR)
1280 WIN32_GDI_FAILED ("GetClipBox");
1281 else if (k != NULLREGION)
1283 event = gdk_event_new (GDK_EXPOSE);
1284 event->expose.window = window;
1285 event->expose.area.x = r.left;
1286 event->expose.area.y = r.top;
1287 event->expose.area.width = r.right - r.left;
1288 event->expose.area.height = r.bottom - r.top;
1289 event->expose.region = gdk_region_rectangle (&(event->expose.area));
1290 event->expose.count = 0;
1292 append_event (event);
1294 GDI_CALL (ReleaseDC, (impl->handle, hdc));
1299 update_colors (GdkWindow *window,
1303 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
1304 GList *list = gdk_window_get_children (window);
1307 GDK_NOTE (COLORMAP, (top ? g_print ("update_colors:") : (void) 0));
1311 update_colors ((GdkWindow *) list->data, FALSE);
1316 if (((GdkWindowObject *) window)->input_only ||
1317 impl->colormap == NULL)
1320 if (!(hdc = GetDC (impl->handle)))
1321 WIN32_GDI_FAILED ("GetDC");
1324 GdkColormapPrivateWin32 *cmapp = GDK_WIN32_COLORMAP_DATA (impl->colormap);
1328 if ((holdpal = SelectPalette (hdc, cmapp->hpal, TRUE)) == NULL)
1329 WIN32_GDI_FAILED ("SelectPalette");
1330 else if ((k = RealizePalette (hdc)) == GDI_ERROR)
1331 WIN32_GDI_FAILED ("RealizePalette");
1336 g_print (" %p pal=%p: realized %d colors\n"
1338 impl->handle, cmapp->hpal, k) :
1340 g_print (" %p", impl->handle)));
1341 GDI_CALL (UpdateColors, (hdc));
1342 SelectPalette (hdc, holdpal, TRUE);
1343 RealizePalette (hdc);
1345 GDI_CALL (ReleaseDC, (impl->handle, hdc));
1347 GDK_NOTE (COLORMAP, (top ? g_print ("\n") : (void) 0));
1350 /* The check_extended flag controls whether to check if the windows want
1351 * events from extended input devices and if the message should be skipped
1352 * because an extended input device is active
1355 propagate (GdkWindow **window,
1357 GdkWindow *grab_window,
1358 gboolean grab_owner_events,
1360 gboolean (*doesnt_want_it) (gint mask,
1362 gboolean check_extended)
1364 if (grab_window != NULL && !grab_owner_events)
1366 /* Event source is grabbed with owner_events FALSE */
1368 /* See if the event should be ignored because an extended input
1371 if (check_extended &&
1372 ((GdkWindowObject *) grab_window)->extension_events != 0 &&
1373 _gdk_input_ignore_core)
1375 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1378 if ((*doesnt_want_it) (grab_mask, msg))
1380 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1385 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1386 assign_object (window, grab_window);
1391 /* If we come here, we know that if grab_window != NULL then
1392 * grab_owner_events is TRUE
1396 if (check_extended &&
1397 ((GdkWindowObject *) *window)->extension_events != 0 &&
1398 _gdk_input_ignore_core)
1400 GDK_NOTE (EVENTS, g_print (" (ignored)"));
1403 if ((*doesnt_want_it) (((GdkWindowObject *) *window)->event_mask, msg))
1405 /* Owner doesn't want it, propagate to parent. */
1406 GdkWindow *parent = gdk_window_get_parent (*window);
1407 if (parent == _gdk_root || parent == NULL)
1409 /* No parent; check if grabbed */
1410 if (grab_window != NULL)
1412 /* Event source is grabbed with owner_events TRUE */
1414 if (check_extended &&
1415 ((GdkWindowObject *) grab_window)->extension_events != 0 &&
1416 _gdk_input_ignore_core)
1418 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1421 if ((*doesnt_want_it) (grab_mask, msg))
1423 /* Grabber doesn't want it either */
1424 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1430 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1431 assign_object (window, grab_window);
1437 GDK_NOTE (EVENTS, g_print (" (undelivered)"));
1443 assign_object (window, parent);
1444 /* The only branch where we actually continue the loop */
1453 doesnt_want_key (gint mask,
1456 return (((msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) &&
1457 !(mask & GDK_KEY_RELEASE_MASK)) ||
1458 ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) &&
1459 !(mask & GDK_KEY_PRESS_MASK)));
1463 doesnt_want_char (gint mask,
1466 return !(mask & (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK));
1470 handle_configure_event (MSG *msg,
1475 GdkWindowObject *window_object;
1477 GetClientRect (msg->hwnd, &client_rect);
1478 point.x = client_rect.left; /* always 0 */
1479 point.y = client_rect.top;
1481 /* top level windows need screen coords */
1482 if (gdk_window_get_parent (window) == _gdk_root)
1484 ClientToScreen (msg->hwnd, &point);
1485 point.x += _gdk_offset_x;
1486 point.y += _gdk_offset_y;
1489 window_object = GDK_WINDOW_OBJECT (window);
1491 window_object->width = client_rect.right - client_rect.left;
1492 window_object->height = client_rect.bottom - client_rect.top;
1494 window_object->x = point.x;
1495 window_object->y = point.y;
1497 _gdk_window_update_size (window);
1499 if (window_object->event_mask & GDK_STRUCTURE_MASK)
1501 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1503 event->configure.window = window;
1505 event->configure.width = client_rect.right - client_rect.left;
1506 event->configure.height = client_rect.bottom - client_rect.top;
1508 event->configure.x = point.x;
1509 event->configure.y = point.y;
1511 append_event (event);
1516 _gdk_win32_hrgn_to_region (HRGN hrgn)
1524 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1526 WIN32_GDI_FAILED ("GetRegionData");
1530 rgndata = (RGNDATA *) g_malloc (nbytes);
1532 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1534 WIN32_GDI_FAILED ("GetRegionData");
1539 result = gdk_region_new ();
1540 rects = (RECT *) rgndata->Buffer;
1541 for (i = 0; i < rgndata->rdh.nCount; i++)
1545 r.x = rects[i].left;
1547 r.width = rects[i].right - r.x;
1548 r.height = rects[i].bottom - r.y;
1550 gdk_region_union_with_rect (result, &r);
1559 adjust_drag (LONG *drag,
1564 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1566 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1570 handle_wm_paint (MSG *msg,
1572 gboolean return_exposes,
1575 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1577 PAINTSTRUCT paintstruct;
1578 GdkRegion *update_region;
1580 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1582 WIN32_GDI_FAILED ("GetUpdateRgn");
1583 DeleteObject (hrgn);
1587 hdc = BeginPaint (msg->hwnd, &paintstruct);
1589 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1590 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1591 (paintstruct.fErase ? "erase" : ""),
1593 (return_exposes ? " return_exposes" : "")));
1595 EndPaint (msg->hwnd, &paintstruct);
1597 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1598 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1600 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1601 DeleteObject (hrgn);
1607 if (!GDK_WINDOW_DESTROYED (window))
1609 GList *list = _gdk_display->queued_events;
1611 *event = gdk_event_new (GDK_EXPOSE);
1612 (*event)->expose.window = window;
1613 (*event)->expose.area.x = paintstruct.rcPaint.left;
1614 (*event)->expose.area.y = paintstruct.rcPaint.top;
1615 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1616 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1617 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1618 (*event)->expose.count = 0;
1620 while (list != NULL)
1622 GdkEventPrivate *evp = list->data;
1624 if (evp->event.any.type == GDK_EXPOSE &&
1625 evp->event.any.window == window &&
1626 !(evp->flags & GDK_EVENT_PENDING))
1627 evp->event.expose.count++;
1633 DeleteObject (hrgn);
1637 update_region = _gdk_win32_hrgn_to_region (hrgn);
1638 if (!gdk_region_empty (update_region))
1639 _gdk_window_invalidate_for_expose (window, update_region);
1640 gdk_region_destroy (update_region);
1642 DeleteObject (hrgn);
1645 static VOID CALLBACK
1646 modal_timer_proc (HWND hwnd,
1651 int arbitrary_limit = 1;
1653 while (_modal_operation_in_progress &&
1654 g_main_context_pending (NULL) &&
1656 g_main_context_iteration (NULL, FALSE);
1660 _gdk_win32_begin_modal_call (void)
1662 g_assert (!_modal_operation_in_progress);
1664 _modal_operation_in_progress = TRUE;
1666 modal_timer = SetTimer (NULL, 0, 10, modal_timer_proc);
1667 if (modal_timer == 0)
1668 WIN32_API_FAILED ("SetTimer");
1672 _gdk_win32_end_modal_call (void)
1674 g_assert (_modal_operation_in_progress);
1676 _modal_operation_in_progress = FALSE;
1678 if (modal_timer != 0)
1680 API_CALL (KillTimer, (NULL, modal_timer));
1685 static VOID CALLBACK
1686 sync_timer_proc (HWND hwnd,
1692 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1697 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1699 KillTimer (hwnd, sync_timer);
1703 handle_display_change (void)
1705 _gdk_monitor_init ();
1706 _gdk_root_window_size_init ();
1707 g_signal_emit_by_name (_gdk_screen, "size_changed");
1711 generate_button_event (GdkEventType type,
1716 GdkEvent *event = gdk_event_new (type);
1718 event->button.window = window;
1719 event->button.time = _gdk_win32_get_next_tick (msg->time);
1720 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1721 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1722 event->button.x_root = msg->pt.x + _gdk_offset_x;
1723 event->button.y_root = msg->pt.y + _gdk_offset_y;
1724 event->button.axes = NULL;
1725 event->button.state = build_pointer_event_state (msg);
1726 event->button.button = button;
1727 event->button.device = _gdk_display->core_pointer;
1729 append_event (event);
1733 ensure_stacking_on_unminimize (MSG *msg)
1736 HWND lowest_transient = NULL;
1739 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1741 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1743 /* Checking window group not implemented yet */
1746 GdkWindowImplWin32 *rover_impl =
1747 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
1749 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1750 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1751 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1752 rover_impl->transient_owner != NULL))
1754 lowest_transient = rover;
1758 if (lowest_transient != NULL)
1760 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1761 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1762 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1767 ensure_stacking_on_window_pos_changing (MSG *msg,
1770 GdkWindowImplWin32 *impl = (GdkWindowImplWin32 *)((GdkWindowObject *) window)->impl;
1771 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1773 if (GetActiveWindow () == msg->hwnd &&
1774 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1775 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1776 impl->transient_owner == NULL)
1778 /* Make sure the window stays behind any transient-type windows
1779 * of the same window group.
1781 * If the window is not active and being activated, we let
1782 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1783 * handling to bring any utility windows on top of it.
1786 gboolean restacking;
1788 rover = windowpos->hwndInsertAfter;
1792 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1794 /* Checking window group not implemented yet */
1797 GdkWindowImplWin32 *rover_impl =
1798 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
1800 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1801 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1802 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1803 rover_impl->transient_owner != NULL))
1806 windowpos->hwndInsertAfter = rover;
1809 rover = GetNextWindow (rover, GW_HWNDNEXT);
1814 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1822 ensure_stacking_on_activate_app (MSG *msg,
1825 GdkWindowImplWin32 *impl = (GdkWindowImplWin32 *)((GdkWindowObject *) window)->impl;
1827 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1828 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1829 impl->transient_owner != NULL)
1831 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1832 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1836 if (IsWindowVisible (msg->hwnd) &&
1837 msg->hwnd == GetActiveWindow ())
1839 /* This window is not a transient-type window and it is the
1840 * activated window. Make sure this window is as visible as
1841 * possible, just below the lowest transient-type window of this
1847 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
1849 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1851 /* Checking window group not implemented yet */
1854 GdkWindowImplWin32 *rover_impl =
1855 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
1857 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1858 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1859 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1860 rover_impl->transient_owner != NULL))
1862 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1863 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1864 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1873 gdk_event_translate (MSG *msg,
1876 RECT rect, *drag, orig_drag;
1881 BYTE key_state[256];
1883 WINDOWPOS *windowpos;
1890 GdkWindow *window = NULL;
1891 GdkWindowImplWin32 *impl;
1893 GdkWindow *orig_window, *new_window, *toplevel;
1895 GdkPointerGrabInfo *grab = NULL;
1896 GdkWindow *grab_window = NULL;
1898 static gint update_colors_counter = 0;
1903 gboolean return_val = FALSE;
1907 if (_gdk_default_filters)
1909 /* Apply global filters */
1911 GdkFilterReturn result = apply_event_filters (NULL, msg, _gdk_default_filters);
1913 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1914 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1915 * we return TRUE, and DefWindowProcW() will not be called.
1917 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1921 window = gdk_win32_handle_table_lookup ((GdkNativeWindow) msg->hwnd);
1922 orig_window = window;
1926 /* XXX Handle WM_QUIT here ? */
1927 if (msg->message == WM_QUIT)
1929 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1932 else if (msg->message == WM_MOVE ||
1933 msg->message == WM_SIZE)
1935 /* It's quite normal to get these messages before we have
1936 * had time to register the window in our lookup table, or
1937 * when the window is being destroyed and we already have
1938 * removed it. Repost the same message to our queue so that
1939 * we will get it later when we are prepared.
1941 GDK_NOTE (EVENTS, g_print (" (posted)"));
1943 PostMessageW (msg->hwnd, msg->message, msg->wParam, msg->lParam);
1945 else if (msg->message == WM_CREATE)
1947 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1948 GDK_WINDOW_HWND (window) = msg->hwnd;
1952 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1957 g_object_ref (window);
1959 /* window's refcount has now been increased, so code below should
1960 * not just return from this function, but instead goto done (or
1961 * break out of the big switch). To protect against forgetting this,
1962 * #define return to a syntax error...
1964 #define return GOTO_DONE_INSTEAD
1966 if (!GDK_WINDOW_DESTROYED (window) && ((GdkWindowObject *) window)->filters)
1968 /* Apply per-window filters */
1970 GdkFilterReturn result = apply_event_filters (window, msg, ((GdkWindowObject *) window)->filters);
1972 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1979 if (msg->message == client_message)
1982 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1985 GDK_NOTE (EVENTS, g_print (" client_message"));
1987 event = gdk_event_new (GDK_NOTHING);
1988 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1990 node = _gdk_event_queue_append (_gdk_display, event);
1992 tmp_list = client_filters;
1995 GdkClientFilter *filter = tmp_list->data;
1997 tmp_list = tmp_list->next;
1999 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
2001 GDK_NOTE (EVENTS, g_print (" (match)"));
2003 result = (*filter->function) (msg, event, filter->data);
2005 if (result != GDK_FILTER_CONTINUE)
2012 case GDK_FILTER_REMOVE:
2013 _gdk_event_queue_remove_link (_gdk_display, node);
2014 g_list_free_1 (node);
2015 gdk_event_free (event);
2019 case GDK_FILTER_TRANSLATE:
2020 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2021 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2025 case GDK_FILTER_CONTINUE:
2026 /* Send unknown client messages on to Gtk for it to use */
2028 event->client.type = GDK_CLIENT_EVENT;
2029 event->client.window = window;
2030 event->client.message_type = GDK_POINTER_TO_ATOM (msg->wParam);
2031 event->client.data_format = 32;
2032 event->client.data.l[0] = msg->lParam;
2033 for (i = 1; i < 5; i++)
2034 event->client.data.l[i] = 0;
2035 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2041 switch (msg->message)
2043 case WM_INPUTLANGCHANGE:
2044 _gdk_input_locale = (HKL) msg->lParam;
2045 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
2046 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
2047 LOCALE_IDEFAULTANSICODEPAGE,
2049 _gdk_input_codepage = atoi (buf);
2050 _gdk_keymap_serial++;
2052 g_print (" cs:%lu hkl:%p%s cp:%d",
2053 (gulong) msg->wParam,
2054 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
2055 _gdk_input_codepage));
2061 g_print (" %s ch:%.02x %s",
2062 _gdk_win32_key_to_string (msg->lParam),
2064 decode_key_lparam (msg->lParam)));
2066 /* If posted without us having keyboard focus, ignore */
2067 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
2068 !(HIWORD (msg->lParam) & KF_ALTDOWN))
2071 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
2072 * the keyboard is grabbed.
2074 if (_gdk_display->keyboard_grab.window == NULL &&
2075 (msg->wParam == VK_TAB ||
2076 msg->wParam == VK_SPACE ||
2077 msg->wParam == VK_F4))
2080 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
2086 g_print (" %s ch:%.02x %s",
2087 _gdk_win32_key_to_string (msg->lParam),
2089 decode_key_lparam (msg->lParam)));
2093 /* Ignore key messages intended for the IME */
2094 if (msg->wParam == VK_PROCESSKEY ||
2098 if (!propagate (&window, msg,
2099 _gdk_display->keyboard_grab.window,
2100 _gdk_display->keyboard_grab.owner_events,
2101 GDK_ALL_EVENTS_MASK,
2102 doesnt_want_key, FALSE))
2105 if (GDK_WINDOW_DESTROYED (window))
2108 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
2109 msg->message == WM_SYSKEYDOWN) ?
2110 GDK_KEY_PRESS : GDK_KEY_RELEASE);
2111 event->key.window = window;
2112 event->key.time = _gdk_win32_get_next_tick (msg->time);
2113 event->key.keyval = GDK_VoidSymbol;
2114 event->key.string = NULL;
2115 event->key.length = 0;
2116 event->key.hardware_keycode = msg->wParam;
2117 if (HIWORD (msg->lParam) & KF_EXTENDED)
2119 switch (msg->wParam)
2122 event->key.hardware_keycode = VK_RCONTROL;
2124 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
2125 * for the right shift key.
2127 event->key.hardware_keycode = VK_RSHIFT;
2130 event->key.hardware_keycode = VK_RMENU;
2134 else if (msg->wParam == VK_SHIFT &&
2135 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
2136 event->key.hardware_keycode = VK_RSHIFT;
2138 API_CALL (GetKeyboardState, (key_state));
2140 /* 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]); */
2142 build_key_event_state (event, key_state);
2144 gdk_keymap_translate_keyboard_state (NULL,
2145 event->key.hardware_keycode,
2151 fill_key_event_string (event);
2153 /* Reset MOD1_MASK if it is the Alt key itself */
2154 if (msg->wParam == VK_MENU)
2155 event->key.state &= ~GDK_MOD1_MASK;
2157 append_event (event);
2163 if (msg->wParam != VK_SPACE)
2165 /* To prevent beeps, don't let DefWindowProcW() be called */
2171 case WM_IME_STARTCOMPOSITION:
2172 in_ime_composition = TRUE;
2175 case WM_IME_ENDCOMPOSITION:
2176 in_ime_composition = FALSE;
2179 case WM_IME_COMPOSITION:
2180 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2181 * applications. Thus, handle WM_IME_COMPOSITION with
2182 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2183 * with ImmGetCompositionStringW().
2186 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2188 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2189 * for comments by other people that seems to have the same
2190 * experience. WM_IME_CHAR just gives question marks, apparently
2191 * because of going through some conversion to the current code
2194 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2195 * use WM_IME_COMPOSITION there, too, to simplify the code.
2197 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2199 if (!(msg->lParam & GCS_RESULTSTR))
2202 if (!propagate (&window, msg,
2203 _gdk_display->keyboard_grab.window,
2204 _gdk_display->keyboard_grab.owner_events,
2205 GDK_ALL_EVENTS_MASK,
2206 doesnt_want_char, FALSE))
2209 if (GDK_WINDOW_DESTROYED (window))
2212 himc = ImmGetContext (msg->hwnd);
2213 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2214 wbuf, sizeof (wbuf));
2215 ImmReleaseContext (msg->hwnd, himc);
2219 API_CALL (GetKeyboardState, (key_state));
2221 for (i = 0; i < ccount; i++)
2223 if (((GdkWindowObject *) window)->event_mask & GDK_KEY_PRESS_MASK)
2225 /* Build a key press event */
2226 event = gdk_event_new (GDK_KEY_PRESS);
2227 event->key.window = window;
2228 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2230 append_event (event);
2233 if (((GdkWindowObject *) window)->event_mask & GDK_KEY_RELEASE_MASK)
2235 /* Build a key release event. */
2236 event = gdk_event_new (GDK_KEY_RELEASE);
2237 event->key.window = window;
2238 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2240 append_event (event);
2246 case WM_LBUTTONDOWN:
2250 case WM_MBUTTONDOWN:
2254 case WM_RBUTTONDOWN:
2258 case WM_XBUTTONDOWN:
2259 if (HIWORD (msg->wParam) == XBUTTON1)
2266 g_print (" (%d,%d)",
2267 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2269 assign_object (&window, find_window_for_mouse_event (window, msg));
2270 /* TODO_CSW?: there used to some synthesize and propagate */
2271 if (GDK_WINDOW_DESTROYED (window))
2274 /* TODO_CSW? Emulate X11's automatic active grab */
2275 generate_button_event (GDK_BUTTON_PRESS, button,
2294 if (HIWORD (msg->wParam) == XBUTTON1)
2301 g_print (" (%d,%d)",
2302 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2304 assign_object (&window, find_window_for_mouse_event (window, msg));
2306 if (((GdkWindowObject *) window)->extension_events != 0 &&
2307 _gdk_input_ignore_core)
2309 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2314 generate_button_event (GDK_BUTTON_RELEASE, button,
2322 g_print (" %p (%d,%d)",
2323 (gpointer) msg->wParam,
2324 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2326 assign_object (&window, find_window_for_mouse_event (window, msg));
2327 toplevel = gdk_window_get_toplevel (window);
2328 if (current_toplevel != toplevel)
2330 GDK_NOTE (EVENTS, g_print (" toplevel %p -> %p",
2331 current_toplevel ? GDK_WINDOW_HWND (current_toplevel) : NULL,
2332 toplevel ? GDK_WINDOW_HWND (toplevel) : NULL));
2333 if (current_toplevel)
2334 synthesize_enter_or_leave_event (current_toplevel, msg,
2335 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2336 synthesize_enter_or_leave_event (toplevel, msg,
2337 GDK_ENTER_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2338 assign_object (¤t_toplevel, toplevel);
2339 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (toplevel));
2342 /* If we haven't moved, don't create any GDK event. Windows
2343 * sends WM_MOUSEMOVE messages after a new window is shows under
2344 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2346 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2347 msg->pt.y + _gdk_offset_y == current_root_y)
2350 current_root_x = msg->pt.x + _gdk_offset_x;
2351 current_root_y = msg->pt.y + _gdk_offset_y;
2353 event = gdk_event_new (GDK_MOTION_NOTIFY);
2354 event->motion.window = window;
2355 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2356 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2357 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2358 event->motion.x_root = current_root_x;
2359 event->motion.y_root = current_root_y;
2360 event->motion.axes = NULL;
2361 event->motion.state = build_pointer_event_state (msg);
2362 event->motion.is_hint = FALSE;
2363 event->motion.device = _gdk_display->core_pointer;
2365 append_event (event);
2370 case WM_NCMOUSEMOVE:
2372 g_print (" (%d,%d)",
2373 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2374 #if 0 /* TODO_CSW? */
2375 if (current_toplevel != NULL &&
2376 (((GdkWindowObject *) current_toplevel)->event_mask & GDK_LEAVE_NOTIFY_MASK))
2378 synthesize_enter_or_leave_event (current_toplevel, msg,
2379 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2385 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2386 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2388 if (!gdk_win32_handle_table_lookup ((GdkNativeWindow) WindowFromPoint (msg->pt)))
2390 /* we are only interested if we don't know the new window */
2391 if (current_toplevel)
2392 synthesize_enter_or_leave_event (current_toplevel, msg,
2393 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2394 assign_object (¤t_toplevel, NULL);
2398 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2405 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2407 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2408 * that. Also, the position is in screen coordinates, not client
2409 * coordinates as with the button messages. I love the
2410 * consistency of Windows.
2412 point.x = GET_X_LPARAM (msg->lParam);
2413 point.y = GET_Y_LPARAM (msg->lParam);
2415 if ((hwnd = WindowFromPoint (point)) == NULL)
2419 if ((new_window = gdk_win32_handle_table_lookup ((GdkNativeWindow) msg->hwnd)) == NULL)
2422 if (new_window != window)
2424 assign_object (&window, new_window);
2427 ScreenToClient (msg->hwnd, &point);
2429 event = gdk_event_new (GDK_SCROLL);
2430 event->scroll.window = window;
2431 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2432 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2433 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2434 event->scroll.x = (gint16) point.x;
2435 event->scroll.y = (gint16) point.y;
2436 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2437 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2438 event->scroll.state = build_pointer_event_state (msg);
2439 event->scroll.device = _gdk_display->core_pointer;
2441 append_event (event);
2447 /* Just print more debugging information, don't actually handle it. */
2450 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2451 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2452 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2453 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2454 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2455 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2456 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2457 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2458 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2460 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2461 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2462 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2466 /* Just print more debugging information, don't actually handle it. */
2469 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2470 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2471 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2472 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2473 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2474 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2475 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2476 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2477 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2479 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2480 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2481 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2484 case WM_QUERYNEWPALETTE:
2485 if (gdk_visual_get_system ()->type == GDK_VISUAL_PSEUDO_COLOR)
2487 synthesize_expose_events (window);
2488 update_colors_counter = 0;
2493 case WM_PALETTECHANGED:
2494 GDK_NOTE (EVENTS_OR_COLORMAP, g_print (" %p", (HWND) msg->wParam));
2495 if (gdk_visual_get_system ()->type != GDK_VISUAL_PSEUDO_COLOR)
2500 if (msg->hwnd == (HWND) msg->wParam)
2503 if (++update_colors_counter == 5)
2505 synthesize_expose_events (window);
2506 update_colors_counter = 0;
2510 update_colors (window, TRUE);
2513 case WM_MOUSEACTIVATE:
2517 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2518 || !((GdkWindowObject *)window)->accept_focus)
2520 *ret_valp = MA_NOACTIVATE;
2524 tmp = _gdk_modal_current ();
2528 if (gdk_window_get_toplevel (window) != tmp)
2530 *ret_valp = MA_NOACTIVATEANDEAT;
2539 if (_gdk_display->keyboard_grab.window != NULL &&
2540 !GDK_WINDOW_DESTROYED (_gdk_display->keyboard_grab.window))
2542 generate_grab_broken_event (_gdk_display->keyboard_grab.window, FALSE, NULL);
2547 if (_gdk_display->keyboard_grab.window != NULL &&
2548 !_gdk_display->keyboard_grab.owner_events)
2551 if (!(((GdkWindowObject *) window)->event_mask & GDK_FOCUS_CHANGE_MASK))
2554 if (GDK_WINDOW_DESTROYED (window))
2557 generate_focus_event (window, (msg->message == WM_SETFOCUS));
2562 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2564 if (GDK_WINDOW_DESTROYED (window))
2572 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2574 200, sync_timer_proc);
2578 handle_wm_paint (msg, window, FALSE, NULL);
2582 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2583 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2585 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
2588 grab_window = grab->window;
2591 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2594 if (grab_window != NULL && p_grab_cursor != NULL)
2595 hcursor = p_grab_cursor;
2596 else if (!GDK_WINDOW_DESTROYED (window))
2597 hcursor = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl)->hcursor;
2601 if (hcursor != NULL)
2603 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2604 SetCursor (hcursor);
2611 GDK_NOTE (EVENTS, g_print (" %s %s",
2612 (msg->wParam ? "YES" : "NO"),
2613 (msg->lParam == 0 ? "ShowWindow" :
2614 (msg->lParam == SW_OTHERUNZOOM ? "OTHERUNZOOM" :
2615 (msg->lParam == SW_OTHERZOOM ? "OTHERZOOM" :
2616 (msg->lParam == SW_PARENTCLOSING ? "PARENTCLOSING" :
2617 (msg->lParam == SW_PARENTOPENING ? "PARENTOPENING" :
2620 if (!(((GdkWindowObject *) window)->event_mask & GDK_STRUCTURE_MASK))
2623 if (msg->lParam == SW_OTHERUNZOOM ||
2624 msg->lParam == SW_OTHERZOOM)
2627 if (GDK_WINDOW_DESTROYED (window))
2630 event = gdk_event_new (msg->wParam ? GDK_MAP : GDK_UNMAP);
2631 event->any.window = window;
2633 append_event (event);
2635 if (event->any.type == GDK_UNMAP)
2637 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
2639 if (impl->transient_owner && GetForegroundWindow () == GDK_WINDOW_HWND (window))
2641 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2644 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
2647 if (grab->window == window)
2648 gdk_pointer_ungrab (msg->time);
2651 if (_gdk_display->keyboard_grab.window == window)
2652 gdk_keyboard_ungrab (msg->time);
2659 switch (msg->wParam)
2663 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2671 g_print (" %s %dx%d",
2672 (msg->wParam == SIZE_MAXHIDE ? "MAXHIDE" :
2673 (msg->wParam == SIZE_MAXIMIZED ? "MAXIMIZED" :
2674 (msg->wParam == SIZE_MAXSHOW ? "MAXSHOW" :
2675 (msg->wParam == SIZE_MINIMIZED ? "MINIMIZED" :
2676 (msg->wParam == SIZE_RESTORED ? "RESTORED" : "?"))))),
2677 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2679 if (msg->wParam == SIZE_MINIMIZED)
2681 /* Don't generate any GDK event. This is *not* an UNMAP. */
2682 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
2685 if (grab->window == window)
2686 gdk_pointer_ungrab (msg->time);
2688 if (_gdk_display->keyboard_grab.window == window)
2689 gdk_keyboard_ungrab (msg->time);
2691 gdk_synthesize_window_state (window,
2692 GDK_WINDOW_STATE_WITHDRAWN,
2693 GDK_WINDOW_STATE_ICONIFIED);
2694 do_show_window (window, TRUE);
2696 else if ((msg->wParam == SIZE_RESTORED ||
2697 msg->wParam == SIZE_MAXIMIZED) &&
2698 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
2700 GdkWindowState withdrawn_bit =
2701 IsWindowVisible (msg->hwnd) ? GDK_WINDOW_STATE_WITHDRAWN : 0;
2703 if (((GdkWindowObject *) window)->state & GDK_WINDOW_STATE_ICONIFIED)
2704 ensure_stacking_on_unminimize (msg);
2706 if (!GDK_WINDOW_DESTROYED (window))
2707 handle_configure_event (msg, window);
2709 if (msg->wParam == SIZE_RESTORED)
2711 gdk_synthesize_window_state (window,
2712 GDK_WINDOW_STATE_ICONIFIED |
2713 GDK_WINDOW_STATE_MAXIMIZED |
2717 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_TEMP && !GDK_WINDOW_IS_MAPPED (window))
2719 do_show_window (window, FALSE);
2722 else if (msg->wParam == SIZE_MAXIMIZED)
2724 gdk_synthesize_window_state (window,
2725 GDK_WINDOW_STATE_ICONIFIED |
2727 GDK_WINDOW_STATE_MAXIMIZED);
2730 if (((GdkWindowObject *) window)->resize_count > 1)
2731 ((GdkWindowObject *) window)->resize_count -= 1;
2733 if (((GdkWindowObject *) window)->extension_events != 0)
2734 _gdk_input_configure_event (window);
2740 case WM_ENTERSIZEMOVE:
2741 case WM_ENTERMENULOOP:
2742 _gdk_win32_begin_modal_call ();
2745 case WM_EXITSIZEMOVE:
2746 case WM_EXITMENULOOP:
2747 _gdk_win32_end_modal_call ();
2750 case WM_WINDOWPOSCHANGING:
2751 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2752 g_print (" %s %s %dx%d@%+d%+d now below %p",
2753 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2754 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2755 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2756 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2757 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2758 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2760 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2761 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2763 if (GDK_WINDOW_IS_MAPPED (window))
2764 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2767 case WM_WINDOWPOSCHANGED:
2768 windowpos = (WINDOWPOS *) msg->lParam;
2769 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2770 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2771 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2772 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2773 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2774 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2775 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2777 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2779 /* If position and size haven't changed, don't do anything */
2780 if (_modal_operation_in_progress &&
2781 (windowpos->flags & SWP_NOMOVE) &&
2782 (windowpos->flags & SWP_NOSIZE))
2785 /* Once we've entered the moving or sizing modal loop, we won't
2786 * return to the main loop until we're done sizing or moving.
2788 if (_modal_operation_in_progress &&
2789 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2790 !GDK_WINDOW_DESTROYED (window))
2792 if (((GdkWindowObject *) window)->event_mask & GDK_STRUCTURE_MASK)
2794 GDK_NOTE (EVENTS, g_print (" do magic"));
2795 if (((GdkWindowObject *) window)->resize_count > 1)
2796 ((GdkWindowObject *) window)->resize_count -= 1;
2798 handle_configure_event (msg, window);
2799 g_main_context_iteration (NULL, FALSE);
2801 /* Dispatch main loop - to realize resizes... */
2802 modal_timer_proc (msg->hwnd, msg->message, 0, msg->time);
2804 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2812 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2813 drag = (RECT *) msg->lParam;
2814 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2815 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2816 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2817 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2818 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2819 (msg->wParam == WMSZ_TOP ? "TOP" :
2820 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2821 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2823 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2825 _gdk_win32_rect_to_string (&rect),
2826 _gdk_win32_rect_to_string (drag)));
2828 impl = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
2830 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2832 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2833 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2835 /* Resize in increments relative to the base size */
2836 rect.left = rect.top = 0;
2837 rect.right = impl->hints.base_width;
2838 rect.bottom = impl->hints.base_height;
2839 _gdk_win32_adjust_client_rect (window, &rect);
2840 point.x = rect.left;
2842 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2843 rect.left = point.x;
2845 point.x = rect.right;
2846 point.y = rect.bottom;
2847 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2848 rect.right = point.x;
2849 rect.bottom = point.y;
2851 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2852 _gdk_win32_rect_to_string (&rect)));
2855 switch (msg->wParam)
2858 if (drag->bottom == rect.bottom)
2860 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2863 case WMSZ_BOTTOMLEFT:
2864 if (drag->bottom == rect.bottom && drag->left == rect.left)
2866 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2867 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2871 if (drag->left == rect.left)
2873 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2877 if (drag->top == rect.top && drag->left == rect.left)
2879 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2880 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2884 if (drag->top == rect.top)
2886 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2890 if (drag->top == rect.top && drag->right == rect.right)
2892 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2893 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2897 if (drag->right == rect.right)
2899 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2902 case WMSZ_BOTTOMRIGHT:
2903 if (drag->bottom == rect.bottom && drag->right == rect.right)
2905 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2906 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2910 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2911 drag->top != orig_drag.top || drag->right != orig_drag.right)
2915 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2916 _gdk_win32_rect_to_string (drag)));
2920 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2922 if (impl->hint_flags & GDK_HINT_ASPECT)
2924 RECT decorated_rect;
2925 RECT undecorated_drag;
2926 int decoration_width, decoration_height;
2927 gdouble drag_aspect;
2928 int drag_width, drag_height, new_width, new_height;
2930 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2931 decorated_rect = rect;
2932 _gdk_win32_adjust_client_rect (window, &decorated_rect);
2934 /* Set undecorated_drag to the client area being dragged
2935 * out, in screen coordinates.
2937 undecorated_drag = *drag;
2938 undecorated_drag.left -= decorated_rect.left - rect.left;
2939 undecorated_drag.right -= decorated_rect.right - rect.right;
2940 undecorated_drag.top -= decorated_rect.top - rect.top;
2941 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
2943 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
2944 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
2946 drag_width = undecorated_drag.right - undecorated_drag.left;
2947 drag_height = undecorated_drag.bottom - undecorated_drag.top;
2949 drag_aspect = (gdouble) drag_width / drag_height;
2951 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
2952 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
2954 if (drag_aspect < impl->hints.min_aspect)
2956 /* Aspect is getting too narrow */
2957 switch (msg->wParam)
2961 /* User drags top or bottom edge outward. Keep height, increase width. */
2962 new_width = impl->hints.min_aspect * drag_height;
2963 drag->left -= (new_width - drag_width) / 2;
2964 drag->right = drag->left + new_width + decoration_width;
2966 case WMSZ_BOTTOMLEFT:
2967 case WMSZ_BOTTOMRIGHT:
2968 /* User drags bottom-left or bottom-right corner down. Adjust height. */
2969 new_height = drag_width / impl->hints.min_aspect;
2970 drag->bottom = drag->top + new_height + decoration_height;
2974 /* User drags left or right edge inward. Decrease height */
2975 new_height = drag_width / impl->hints.min_aspect;
2976 drag->top += (drag_height - new_height) / 2;
2977 drag->bottom = drag->top + new_height + decoration_height;
2981 /* User drags top-left or top-right corner up. Adjust height. */
2982 new_height = drag_width / impl->hints.min_aspect;
2983 drag->top = drag->bottom - new_height - decoration_height;
2986 else if (drag_aspect > impl->hints.max_aspect)
2988 /* Aspect is getting too wide */
2989 switch (msg->wParam)
2993 /* User drags top or bottom edge inward. Decrease width. */
2994 new_width = impl->hints.max_aspect * drag_height;
2995 drag->left += (drag_width - new_width) / 2;
2996 drag->right = drag->left + new_width + decoration_width;
2998 case WMSZ_BOTTOMLEFT:
3000 /* User drags bottom-left or top-left corner left. Adjust width. */
3001 new_width = impl->hints.max_aspect * drag_height;
3002 drag->left = drag->right - new_width - decoration_width;
3004 case WMSZ_BOTTOMRIGHT:
3006 /* User drags bottom-right or top-right corner right. Adjust width. */
3007 new_width = impl->hints.max_aspect * drag_height;
3008 drag->right = drag->left + new_width + decoration_width;
3012 /* User drags left or right edge outward. Increase height. */
3013 new_height = drag_width / impl->hints.max_aspect;
3014 drag->top -= (new_height - drag_height) / 2;
3015 drag->bottom = drag->top + new_height + decoration_height;
3022 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
3023 _gdk_win32_rect_to_string (drag)));
3027 case WM_GETMINMAXINFO:
3028 if (GDK_WINDOW_DESTROYED (window))
3031 impl = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
3032 mmi = (MINMAXINFO*) msg->lParam;
3033 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
3034 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3035 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3036 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3037 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3038 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3040 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
3042 rect.left = rect.top = 0;
3043 rect.right = impl->hints.min_width;
3044 rect.bottom = impl->hints.min_height;
3046 _gdk_win32_adjust_client_rect (window, &rect);
3048 mmi->ptMinTrackSize.x = rect.right - rect.left;
3049 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
3052 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
3056 rect.left = rect.top = 0;
3057 rect.right = impl->hints.max_width;
3058 rect.bottom = impl->hints.max_height;
3060 _gdk_win32_adjust_client_rect (window, &rect);
3062 /* at least on win9x we have the 16 bit trouble */
3063 maxw = rect.right - rect.left;
3064 maxh = rect.bottom - rect.top;
3065 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
3066 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
3069 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
3071 /* Don't call DefWindowProcW() */
3072 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
3073 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3074 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3075 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3076 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3077 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3083 GDK_NOTE (EVENTS, g_print (" (%d,%d)",
3084 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
3086 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
3087 !IsIconic (msg->hwnd))
3089 if (!GDK_WINDOW_DESTROYED (window))
3090 handle_configure_event (msg, window);
3097 if (GDK_WINDOW_DESTROYED (window))
3100 event = gdk_event_new (GDK_DELETE);
3101 event->any.window = window;
3103 append_event (event);
3105 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
3107 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
3109 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3116 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
3119 if (grab->window == window)
3120 gdk_pointer_ungrab (msg->time);
3123 if (_gdk_display->keyboard_grab.window == window)
3124 gdk_keyboard_ungrab (msg->time);
3126 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
3127 gdk_window_destroy_notify (window);
3129 if (window == NULL || GDK_WINDOW_DESTROYED (window))
3132 event = gdk_event_new (GDK_DESTROY);
3133 event->any.window = window;
3135 append_event (event);
3140 case WM_DISPLAYCHANGE:
3141 handle_display_change ();
3144 case WM_DESTROYCLIPBOARD:
3145 if (!_ignore_destroy_clipboard)
3147 event = gdk_event_new (GDK_SELECTION_CLEAR);
3148 event->selection.window = window;
3149 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3150 event->selection.time = _gdk_win32_get_next_tick (msg->time);
3151 append_event (event);
3160 case WM_RENDERFORMAT:
3161 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
3163 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
3165 GDK_NOTE (EVENTS, g_print (" (target not found)"));
3170 /* We need to render to clipboard immediately, don't call
3173 if (_gdk_event_func)
3175 event = gdk_event_new (GDK_SELECTION_REQUEST);
3176 event->selection.window = window;
3177 event->selection.send_event = FALSE;
3178 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3179 event->selection.target = target;
3180 event->selection.property = _gdk_selection;
3181 event->selection.requestor = msg->hwnd;
3182 event->selection.time = msg->time;
3184 fixup_event (event);
3185 GDK_NOTE (EVENTS, g_print (" (calling gdk_event_func)"));
3186 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
3187 (*_gdk_event_func) (event, _gdk_event_data);
3188 gdk_event_free (event);
3190 /* Now the clipboard owner should have rendered */
3191 if (!_delayed_rendering_data)
3193 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3197 if (msg->wParam == CF_DIB)
3199 _delayed_rendering_data =
3200 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3202 if (!_delayed_rendering_data)
3204 g_warning ("Cannot convert to DIB from delayed rendered image");
3209 /* The requestor is holding the clipboard, no
3210 * OpenClipboard() is required/possible
3213 g_print (" SetClipboardData(%s,%p)",
3214 _gdk_win32_cf_to_string (msg->wParam),
3215 _delayed_rendering_data));
3217 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3218 _delayed_rendering_data = NULL;
3224 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3225 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3226 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3227 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3228 HIWORD (msg->wParam) ? " minimized" : "",
3229 (HWND) msg->lParam));
3230 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3231 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3234 if (is_modally_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3236 GdkWindow *modal_current = _gdk_modal_current ();
3237 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3243 /* Bring any tablet contexts to the top of the overlap order when
3244 * one of our windows is activated.
3245 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3248 if (LOWORD(msg->wParam) != WA_INACTIVE)
3249 _gdk_input_set_tablet_active ();
3252 case WM_ACTIVATEAPP:
3253 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3254 msg->wParam ? "YES" : "NO",
3255 (gint64) msg->lParam));
3256 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3257 ensure_stacking_on_activate_app (msg, window);
3260 /* Handle WINTAB events here, as we know that gdkinput.c will
3261 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3262 * constants as case labels.
3265 GDK_NOTE (EVENTS, g_print (" %d %p",
3266 (int) msg->wParam, (gpointer) msg->lParam));
3270 GDK_NOTE (EVENTS, g_print (" %d %p",
3271 (int) msg->wParam, (gpointer) msg->lParam));
3275 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3276 (gpointer) msg->wParam,
3277 LOWORD (msg->lParam),
3278 HIWORD (msg->lParam)));
3282 event = gdk_event_new (GDK_NOTHING);
3283 event->any.window = window;
3284 g_object_ref (window);
3286 if (_gdk_input_other_event (event, msg, window))
3287 append_event (event);
3289 gdk_event_free (event);
3297 g_object_unref (window);
3304 _gdk_events_queue (GdkDisplay *display)
3308 if (modal_win32_dialog != NULL)
3311 while (!_gdk_event_queue_find_first (display) &&
3312 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3314 TranslateMessage (&msg);
3315 DispatchMessageW (&msg);
3320 gdk_event_prepare (GSource *source,
3326 GDK_THREADS_ENTER ();
3330 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3331 (modal_win32_dialog == NULL &&
3332 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3334 GDK_THREADS_LEAVE ();
3340 gdk_event_check (GSource *source)
3345 GDK_THREADS_ENTER ();
3347 if (event_poll_fd.revents & G_IO_IN)
3349 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3350 (modal_win32_dialog == NULL &&
3351 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3358 GDK_THREADS_LEAVE ();
3364 gdk_event_dispatch (GSource *source,
3365 GSourceFunc callback,
3370 GDK_THREADS_ENTER ();
3372 _gdk_events_queue (_gdk_display);
3373 event = _gdk_event_unqueue (_gdk_display);
3377 if (_gdk_event_func)
3378 (*_gdk_event_func) (event, _gdk_event_data);
3380 gdk_event_free (event);
3382 /* Do drag & drop if it is still pending */
3383 if (_dnd_source_state == GDK_WIN32_DND_PENDING)
3385 _dnd_source_state = GDK_WIN32_DND_DRAGGING;
3386 _gdk_win32_dnd_do_dragdrop ();
3387 _dnd_source_state = GDK_WIN32_DND_NONE;
3391 GDK_THREADS_LEAVE ();
3397 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3399 modal_win32_dialog = window;
3403 is_modally_blocked (GdkWindow *window)
3405 GdkWindow *modal_current = _gdk_modal_current ();
3406 return modal_current != NULL ? gdk_window_get_toplevel (window) != modal_current : FALSE;
3410 check_for_too_much_data (GdkEvent *event)
3412 if (event->client.data.l[1] ||
3413 event->client.data.l[2] ||
3414 event->client.data.l[3] ||
3415 event->client.data.l[4])
3417 g_warning ("Only four bytes of data are passed in client messages on Win32\n");
3422 gdk_event_send_client_message_for_display (GdkDisplay *display,
3424 GdkNativeWindow winid)
3426 check_for_too_much_data (event);
3428 return PostMessageW ((HWND) winid, client_message,
3429 (WPARAM) event->client.message_type,
3430 event->client.data.l[0]);
3434 gdk_screen_broadcast_client_message (GdkScreen *screen,
3437 check_for_too_much_data (event);
3439 PostMessageW (HWND_BROADCAST, client_message,
3440 (WPARAM) event->client.message_type,
3441 event->client.data.l[0]);
3450 /* Process all messages currently available */
3451 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3453 TranslateMessage (&msg);
3454 DispatchMessageW (&msg);
3462 gdk_display_sync (GdkDisplay * display)
3466 g_return_if_fail (display == _gdk_display);
3468 /* Process all messages currently available */
3469 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3470 DispatchMessageW (&msg);
3474 gdk_display_flush (GdkDisplay * display)
3476 g_return_if_fail (display == _gdk_display);
3482 gdk_net_wm_supports (GdkAtom property)
3488 _gdk_windowing_event_data_copy (const GdkEvent *src,
3494 _gdk_windowing_event_data_free (GdkEvent *event)