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 ", GDK_WINDOW_HWND (event->any.window));
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"));
892 case GDK_SELECTION_REQUEST:
893 case GDK_SELECTION_NOTIFY:
894 case GDK_SELECTION_CLEAR:
895 selection_name = gdk_atom_name (event->selection.selection);
896 target_name = gdk_atom_name (event->selection.target);
897 property_name = gdk_atom_name (event->selection.property);
898 g_print ("sel:%s tgt:%s prop:%s",
899 selection_name, target_name, property_name);
900 g_free (selection_name);
901 g_free (target_name);
902 g_free (property_name);
905 g_print ("x:%d y:%d w:%d h:%d",
906 event->configure.x, event->configure.y,
907 event->configure.width, event->configure.height);
909 case GDK_CLIENT_EVENT:
910 g_print ("%s %d %ld %ld %ld %ld %ld",
911 gdk_atom_name (event->client.message_type),
912 event->client.data_format,
913 event->client.data.l[0],
914 event->client.data.l[1],
915 event->client.data.l[2],
916 event->client.data.l[3],
917 event->client.data.l[4]);
920 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",
921 event->scroll.x, event->scroll.y,
922 event->scroll.x_root, event->scroll.y_root,
923 (event->scroll.direction == GDK_SCROLL_UP ? "UP" :
924 (event->scroll.direction == GDK_SCROLL_DOWN ? "DOWN" :
925 (event->scroll.direction == GDK_SCROLL_LEFT ? "LEFT" :
926 (event->scroll.direction == GDK_SCROLL_RIGHT ? "RIGHT" :
928 print_event_state (event->scroll.state);
930 case GDK_WINDOW_STATE:
932 _gdk_win32_window_state_to_string (event->window_state.changed_mask),
933 _gdk_win32_window_state_to_string (event->window_state.new_window_state));
936 (event->setting.action == GDK_SETTING_ACTION_NEW ? "NEW" :
937 (event->setting.action == GDK_SETTING_ACTION_CHANGED ? "CHANGED" :
938 (event->setting.action == GDK_SETTING_ACTION_DELETED ? "DELETED" :
940 (event->setting.name ? event->setting.name : "NULL"));
941 case GDK_GRAB_BROKEN:
943 (event->grab_broken.keyboard ? "KEYBOARD" : "POINTER"),
944 (event->grab_broken.implicit ? "IMPLICIT" : "EXPLICIT"),
945 (event->grab_broken.grab_window ? GDK_WINDOW_HWND (event->grab_broken.grab_window) : 0));
950 g_print ("%s", (debug_indent == 0 ? "\n" : ""));
954 decode_key_lparam (LPARAM lParam)
956 static char buf[100];
959 if (HIWORD (lParam) & KF_UP)
960 p += g_sprintf (p, "KF_UP ");
961 if (HIWORD (lParam) & KF_REPEAT)
962 p += g_sprintf (p, "KF_REPEAT ");
963 if (HIWORD (lParam) & KF_ALTDOWN)
964 p += g_sprintf (p, "KF_ALTDOWN ");
965 if (HIWORD (lParam) & KF_EXTENDED)
966 p += g_sprintf (p, "KF_EXTENDED ");
967 p += g_sprintf (p, "sc:%d rep:%d", LOBYTE (HIWORD (lParam)), LOWORD (lParam));
975 fixup_event (GdkEvent *event)
977 if (event->any.window)
978 g_object_ref (event->any.window);
979 if (((event->any.type == GDK_ENTER_NOTIFY) ||
980 (event->any.type == GDK_LEAVE_NOTIFY)) &&
981 (event->crossing.subwindow != NULL))
982 g_object_ref (event->crossing.subwindow);
983 event->any.send_event = InSendMessage ();
987 append_event (GdkEvent *event)
993 link = _gdk_event_queue_append (_gdk_display, event);
994 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
995 /* event morphing, the passed in may not be valid afterwards */
996 _gdk_windowing_got_event (_gdk_display, link, event, 0);
998 _gdk_event_queue_append (_gdk_display, event);
999 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1004 fill_key_event_string (GdkEvent *event)
1009 /* Fill in event->string crudely, since various programs
1014 if (event->key.keyval != GDK_VoidSymbol)
1015 c = gdk_keyval_to_unicode (event->key.keyval);
1019 gsize bytes_written;
1022 /* Apply the control key - Taken from Xlib
1024 if (event->key.state & GDK_CONTROL_MASK)
1026 if ((c >= '@' && c < '\177') || c == ' ')
1030 event->key.string = g_memdup ("\0\0", 2);
1031 event->key.length = 1;
1034 else if (c >= '3' && c <= '7')
1035 c -= ('3' - '\033');
1042 len = g_unichar_to_utf8 (c, buf);
1045 event->key.string = g_locale_from_utf8 (buf, len,
1046 NULL, &bytes_written,
1048 if (event->key.string)
1049 event->key.length = bytes_written;
1051 else if (event->key.keyval == GDK_Escape)
1053 event->key.length = 1;
1054 event->key.string = g_strdup ("\033");
1056 else if (event->key.keyval == GDK_Return ||
1057 event->key.keyval == GDK_KP_Enter)
1059 event->key.length = 1;
1060 event->key.string = g_strdup ("\r");
1063 if (!event->key.string)
1065 event->key.length = 0;
1066 event->key.string = g_strdup ("");
1070 static GdkFilterReturn
1071 apply_event_filters (GdkWindow *window,
1075 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1080 event = gdk_event_new (GDK_NOTHING);
1082 event->any.window = g_object_ref (window);
1083 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1085 /* I think GdkFilterFunc semantics require the passed-in event
1086 * to already be in the queue. The filter func can generate
1087 * more events and append them after it if it likes.
1089 node = _gdk_event_queue_append (_gdk_display, event);
1094 GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
1096 tmp_list = tmp_list->next;
1097 result = filter->function (msg, event, filter->data);
1098 if (result != GDK_FILTER_CONTINUE)
1102 if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
1104 _gdk_event_queue_remove_link (_gdk_display, node);
1105 g_list_free_1 (node);
1106 gdk_event_free (event);
1108 else /* GDK_FILTER_TRANSLATE */
1110 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1111 fixup_event (event);
1112 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1118 * On Windows, transient windows will not have their own taskbar entries.
1119 * Because of this, we must hide and restore groups of transients in both
1120 * directions. That is, all transient children must be hidden or restored
1121 * with this window, but if this window's transient owner also has a
1122 * transient owner then this window's transient owner must be hidden/restored
1123 * with this one. And etc, up the chain until we hit an ancestor that has no
1126 * It would be a good idea if applications don't chain transient windows
1127 * together. There's a limit to how much evil GTK can try to shield you
1131 show_window_recurse (GdkWindow *window, gboolean hide_window)
1133 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1134 GSList *children = impl->transient_children;
1135 GdkWindow *child = NULL;
1137 if (!impl->changing_state)
1139 impl->changing_state = TRUE;
1141 if (children != NULL)
1143 while (children != NULL)
1145 child = children->data;
1146 show_window_recurse (child, hide_window);
1148 children = g_slist_next (children);
1152 if (GDK_WINDOW_IS_MAPPED (window))
1156 if (GDK_WINDOW_OBJECT (window)->state & GDK_WINDOW_STATE_ICONIFIED)
1158 if (GDK_WINDOW_OBJECT (window)->state & GDK_WINDOW_STATE_MAXIMIZED)
1160 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
1164 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1170 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
1174 impl->changing_state = FALSE;
1179 do_show_window (GdkWindow *window, gboolean hide_window)
1181 GdkWindow *tmp_window = NULL;
1182 GdkWindowImplWin32 *tmp_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1184 if (!tmp_impl->changing_state)
1186 /* Find the top-level window in our transient chain. */
1187 while (tmp_impl->transient_owner != NULL)
1189 tmp_window = tmp_impl->transient_owner;
1190 tmp_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (tmp_window)->impl);
1193 /* If we couldn't find one, use the window provided. */
1194 if (tmp_window == NULL)
1196 tmp_window = window;
1199 /* Recursively show/hide every window in the chain. */
1200 if (tmp_window != window)
1202 show_window_recurse (tmp_window, hide_window);
1208 synthesize_enter_or_leave_event (GdkWindow *window,
1211 GdkCrossingMode mode,
1212 GdkNotifyType detail)
1218 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1220 event = gdk_event_new (type);
1221 event->crossing.window = window;
1222 event->crossing.subwindow = NULL;
1223 event->crossing.time = _gdk_win32_get_next_tick (msg->time);
1224 event->crossing.x = pt.x;
1225 event->crossing.y = pt.y;
1226 event->crossing.x_root = msg->pt.x + _gdk_offset_x;
1227 event->crossing.y_root = msg->pt.y + _gdk_offset_y;
1228 event->crossing.mode = mode;
1229 event->crossing.detail = detail;
1230 event->crossing.focus = TRUE; /* FIXME: Set correctly */
1231 event->crossing.state = 0; /* FIXME: Set correctly */
1233 append_event (event);
1235 if (type == GDK_ENTER_NOTIFY &&
1236 ((GdkWindowObject *) window)->extension_events != 0)
1237 _gdk_input_enter_event (window);
1241 synthesize_expose_events (GdkWindow *window)
1245 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
1246 GList *list = gdk_window_get_children (window);
1253 synthesize_expose_events ((GdkWindow *) list->data);
1259 if (((GdkWindowObject *) window)->input_only)
1261 else if (!(hdc = GetDC (impl->handle)))
1262 WIN32_GDI_FAILED ("GetDC");
1265 if ((k = GetClipBox (hdc, &r)) == ERROR)
1266 WIN32_GDI_FAILED ("GetClipBox");
1267 else if (k != NULLREGION)
1269 event = gdk_event_new (GDK_EXPOSE);
1270 event->expose.window = window;
1271 event->expose.area.x = r.left;
1272 event->expose.area.y = r.top;
1273 event->expose.area.width = r.right - r.left;
1274 event->expose.area.height = r.bottom - r.top;
1275 event->expose.region = gdk_region_rectangle (&(event->expose.area));
1276 event->expose.count = 0;
1278 append_event (event);
1280 GDI_CALL (ReleaseDC, (impl->handle, hdc));
1285 update_colors (GdkWindow *window,
1289 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
1290 GList *list = gdk_window_get_children (window);
1293 GDK_NOTE (COLORMAP, (top ? g_print ("update_colors:") : (void) 0));
1297 update_colors ((GdkWindow *) list->data, FALSE);
1302 if (((GdkWindowObject *) window)->input_only ||
1303 impl->colormap == NULL)
1306 if (!(hdc = GetDC (impl->handle)))
1307 WIN32_GDI_FAILED ("GetDC");
1310 GdkColormapPrivateWin32 *cmapp = GDK_WIN32_COLORMAP_DATA (impl->colormap);
1314 if ((holdpal = SelectPalette (hdc, cmapp->hpal, TRUE)) == NULL)
1315 WIN32_GDI_FAILED ("SelectPalette");
1316 else if ((k = RealizePalette (hdc)) == GDI_ERROR)
1317 WIN32_GDI_FAILED ("RealizePalette");
1322 g_print (" %p pal=%p: realized %d colors\n"
1324 impl->handle, cmapp->hpal, k) :
1326 g_print (" %p", impl->handle)));
1327 GDI_CALL (UpdateColors, (hdc));
1328 SelectPalette (hdc, holdpal, TRUE);
1329 RealizePalette (hdc);
1331 GDI_CALL (ReleaseDC, (impl->handle, hdc));
1333 GDK_NOTE (COLORMAP, (top ? g_print ("\n") : (void) 0));
1336 /* The check_extended flag controls whether to check if the windows want
1337 * events from extended input devices and if the message should be skipped
1338 * because an extended input device is active
1341 propagate (GdkWindow **window,
1343 GdkWindow *grab_window,
1344 gboolean grab_owner_events,
1346 gboolean (*doesnt_want_it) (gint mask,
1348 gboolean check_extended)
1350 if (grab_window != NULL && !grab_owner_events)
1352 /* Event source is grabbed with owner_events FALSE */
1354 /* See if the event should be ignored because an extended input
1357 if (check_extended &&
1358 ((GdkWindowObject *) grab_window)->extension_events != 0 &&
1359 _gdk_input_ignore_core)
1361 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1364 if ((*doesnt_want_it) (grab_mask, msg))
1366 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1371 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1372 assign_object (window, grab_window);
1377 /* If we come here, we know that if grab_window != NULL then
1378 * grab_owner_events is TRUE
1382 if (check_extended &&
1383 ((GdkWindowObject *) *window)->extension_events != 0 &&
1384 _gdk_input_ignore_core)
1386 GDK_NOTE (EVENTS, g_print (" (ignored)"));
1389 if ((*doesnt_want_it) (((GdkWindowObject *) *window)->event_mask, msg))
1391 /* Owner doesn't want it, propagate to parent. */
1392 GdkWindow *parent = gdk_window_get_parent (*window);
1393 if (parent == _gdk_root || parent == NULL)
1395 /* No parent; check if grabbed */
1396 if (grab_window != NULL)
1398 /* Event source is grabbed with owner_events TRUE */
1400 if (check_extended &&
1401 ((GdkWindowObject *) grab_window)->extension_events != 0 &&
1402 _gdk_input_ignore_core)
1404 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1407 if ((*doesnt_want_it) (grab_mask, msg))
1409 /* Grabber doesn't want it either */
1410 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1416 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1417 assign_object (window, grab_window);
1423 GDK_NOTE (EVENTS, g_print (" (undelivered)"));
1429 assign_object (window, parent);
1430 /* The only branch where we actually continue the loop */
1439 doesnt_want_key (gint mask,
1442 return (((msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) &&
1443 !(mask & GDK_KEY_RELEASE_MASK)) ||
1444 ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) &&
1445 !(mask & GDK_KEY_PRESS_MASK)));
1449 doesnt_want_char (gint mask,
1452 return !(mask & (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK));
1456 handle_configure_event (MSG *msg,
1461 GdkWindowObject *window_object;
1463 GetClientRect (msg->hwnd, &client_rect);
1464 point.x = client_rect.left; /* always 0 */
1465 point.y = client_rect.top;
1467 /* top level windows need screen coords */
1468 if (gdk_window_get_parent (window) == _gdk_root)
1470 ClientToScreen (msg->hwnd, &point);
1471 point.x += _gdk_offset_x;
1472 point.y += _gdk_offset_y;
1475 window_object = GDK_WINDOW_OBJECT (window);
1477 window_object->width = client_rect.right - client_rect.left;
1478 window_object->height = client_rect.bottom - client_rect.top;
1480 window_object->x = point.x;
1481 window_object->y = point.y;
1483 _gdk_window_update_size (window);
1485 if (window_object->event_mask & GDK_STRUCTURE_MASK)
1487 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1489 event->configure.window = window;
1491 event->configure.width = client_rect.right - client_rect.left;
1492 event->configure.height = client_rect.bottom - client_rect.top;
1494 event->configure.x = point.x;
1495 event->configure.y = point.y;
1497 append_event (event);
1502 _gdk_win32_hrgn_to_region (HRGN hrgn)
1510 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1512 WIN32_GDI_FAILED ("GetRegionData");
1516 rgndata = (RGNDATA *) g_malloc (nbytes);
1518 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1520 WIN32_GDI_FAILED ("GetRegionData");
1525 result = gdk_region_new ();
1526 rects = (RECT *) rgndata->Buffer;
1527 for (i = 0; i < rgndata->rdh.nCount; i++)
1531 r.x = rects[i].left;
1533 r.width = rects[i].right - r.x;
1534 r.height = rects[i].bottom - r.y;
1536 gdk_region_union_with_rect (result, &r);
1545 adjust_drag (LONG *drag,
1550 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1552 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1556 handle_wm_paint (MSG *msg,
1558 gboolean return_exposes,
1561 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1563 PAINTSTRUCT paintstruct;
1564 GdkRegion *update_region;
1566 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1568 WIN32_GDI_FAILED ("GetUpdateRgn");
1569 DeleteObject (hrgn);
1573 hdc = BeginPaint (msg->hwnd, &paintstruct);
1575 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1576 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1577 (paintstruct.fErase ? "erase" : ""),
1579 (return_exposes ? " return_exposes" : "")));
1581 EndPaint (msg->hwnd, &paintstruct);
1583 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1584 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1586 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1587 DeleteObject (hrgn);
1593 if (!GDK_WINDOW_DESTROYED (window))
1595 GList *list = _gdk_display->queued_events;
1597 *event = gdk_event_new (GDK_EXPOSE);
1598 (*event)->expose.window = window;
1599 (*event)->expose.area.x = paintstruct.rcPaint.left;
1600 (*event)->expose.area.y = paintstruct.rcPaint.top;
1601 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1602 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1603 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1604 (*event)->expose.count = 0;
1606 while (list != NULL)
1608 GdkEventPrivate *evp = list->data;
1610 if (evp->event.any.type == GDK_EXPOSE &&
1611 evp->event.any.window == window &&
1612 !(evp->flags & GDK_EVENT_PENDING))
1613 evp->event.expose.count++;
1619 DeleteObject (hrgn);
1623 update_region = _gdk_win32_hrgn_to_region (hrgn);
1624 if (!gdk_region_empty (update_region))
1625 _gdk_window_invalidate_for_expose (window, update_region);
1626 gdk_region_destroy (update_region);
1628 DeleteObject (hrgn);
1632 handle_stuff_while_moving_or_resizing (void)
1634 int arbitrary_limit = 1;
1635 while (g_main_context_pending (NULL) && arbitrary_limit--)
1636 g_main_context_iteration (NULL, FALSE);
1639 static VOID CALLBACK
1640 modal_timer_proc (HWND hwnd,
1645 if (_sizemove_in_progress)
1646 handle_stuff_while_moving_or_resizing ();
1649 static VOID CALLBACK
1650 sync_timer_proc (HWND hwnd,
1656 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1661 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1663 KillTimer (hwnd, sync_timer);
1667 handle_display_change (void)
1669 _gdk_monitor_init ();
1670 _gdk_root_window_size_init ();
1671 g_signal_emit_by_name (_gdk_screen, "size_changed");
1675 generate_button_event (GdkEventType type,
1680 GdkEvent *event = gdk_event_new (type);
1682 event->button.window = window;
1683 event->button.time = _gdk_win32_get_next_tick (msg->time);
1684 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1685 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1686 event->button.x_root = msg->pt.x + _gdk_offset_x;
1687 event->button.y_root = msg->pt.y + _gdk_offset_y;
1688 event->button.axes = NULL;
1689 event->button.state = build_pointer_event_state (msg);
1690 event->button.button = button;
1691 event->button.device = _gdk_display->core_pointer;
1693 append_event (event);
1697 ensure_stacking_on_unminimize (MSG *msg)
1700 HWND lowest_transient = NULL;
1703 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1705 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1707 /* Checking window group not implemented yet */
1710 GdkWindowImplWin32 *rover_impl =
1711 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
1713 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1714 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1715 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1716 rover_impl->transient_owner != NULL))
1718 lowest_transient = rover;
1722 if (lowest_transient != NULL)
1724 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1725 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1726 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1731 ensure_stacking_on_window_pos_changing (MSG *msg,
1734 GdkWindowImplWin32 *impl = (GdkWindowImplWin32 *)((GdkWindowObject *) window)->impl;
1735 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1737 if (GetActiveWindow () == msg->hwnd &&
1738 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1739 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1740 impl->transient_owner == NULL)
1742 /* Make sure the window stays behind any transient-type windows
1743 * of the same window group.
1745 * If the window is not active and being activated, we let
1746 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1747 * handling to bring any utility windows on top of it.
1750 gboolean restacking;
1752 rover = windowpos->hwndInsertAfter;
1756 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1758 /* Checking window group not implemented yet */
1761 GdkWindowImplWin32 *rover_impl =
1762 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
1764 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1765 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1766 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1767 rover_impl->transient_owner != NULL))
1770 windowpos->hwndInsertAfter = rover;
1773 rover = GetNextWindow (rover, GW_HWNDNEXT);
1778 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1786 ensure_stacking_on_activate_app (MSG *msg,
1789 GdkWindowImplWin32 *impl = (GdkWindowImplWin32 *)((GdkWindowObject *) window)->impl;
1791 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1792 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1793 impl->transient_owner != NULL)
1795 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1796 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1800 if (IsWindowVisible (msg->hwnd) &&
1801 msg->hwnd == GetActiveWindow ())
1803 /* This window is not a transient-type window and it is the
1804 * activated window. Make sure this window is as visible as
1805 * possible, just below the lowest transient-type window of this
1811 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
1813 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1815 /* Checking window group not implemented yet */
1818 GdkWindowImplWin32 *rover_impl =
1819 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
1821 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1822 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1823 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1824 rover_impl->transient_owner != NULL))
1826 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1827 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1828 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1837 gdk_event_translate (MSG *msg,
1840 RECT rect, *drag, orig_drag;
1845 BYTE key_state[256];
1847 WINDOWPOS *windowpos;
1854 GdkWindow *window = NULL;
1855 GdkWindowImplWin32 *impl;
1857 GdkWindow *orig_window, *new_window, *toplevel;
1859 GdkPointerGrabInfo *grab = NULL;
1860 GdkWindow *grab_window = NULL;
1862 static gint update_colors_counter = 0;
1867 gboolean return_val = FALSE;
1871 if (_gdk_default_filters)
1873 /* Apply global filters */
1875 GdkFilterReturn result = apply_event_filters (NULL, msg, _gdk_default_filters);
1877 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1878 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1879 * we return TRUE, and DefWindowProcW() will not be called.
1881 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1885 window = gdk_win32_handle_table_lookup ((GdkNativeWindow) msg->hwnd);
1886 orig_window = window;
1890 /* XXX Handle WM_QUIT here ? */
1891 if (msg->message == WM_QUIT)
1893 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1896 else if (msg->message == WM_MOVE ||
1897 msg->message == WM_SIZE)
1899 /* It's quite normal to get these messages before we have
1900 * had time to register the window in our lookup table, or
1901 * when the window is being destroyed and we already have
1902 * removed it. Repost the same message to our queue so that
1903 * we will get it later when we are prepared.
1905 GDK_NOTE (EVENTS, g_print (" (posted)"));
1907 PostMessageW (msg->hwnd, msg->message, msg->wParam, msg->lParam);
1909 else if (msg->message == WM_CREATE)
1911 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1912 GDK_WINDOW_HWND (window) = msg->hwnd;
1916 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1921 g_object_ref (window);
1923 /* window's refcount has now been increased, so code below should
1924 * not just return from this function, but instead goto done (or
1925 * break out of the big switch). To protect against forgetting this,
1926 * #define return to a syntax error...
1928 #define return GOTO_DONE_INSTEAD
1930 if (!GDK_WINDOW_DESTROYED (window) && ((GdkWindowObject *) window)->filters)
1932 /* Apply per-window filters */
1934 GdkFilterReturn result = apply_event_filters (window, msg, ((GdkWindowObject *) window)->filters);
1936 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1943 if (msg->message == client_message)
1946 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1949 GDK_NOTE (EVENTS, g_print (" client_message"));
1951 event = gdk_event_new (GDK_NOTHING);
1952 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1954 node = _gdk_event_queue_append (_gdk_display, event);
1956 tmp_list = client_filters;
1959 GdkClientFilter *filter = tmp_list->data;
1961 tmp_list = tmp_list->next;
1963 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
1965 GDK_NOTE (EVENTS, g_print (" (match)"));
1967 result = (*filter->function) (msg, event, filter->data);
1969 if (result != GDK_FILTER_CONTINUE)
1976 case GDK_FILTER_REMOVE:
1977 _gdk_event_queue_remove_link (_gdk_display, node);
1978 g_list_free_1 (node);
1979 gdk_event_free (event);
1983 case GDK_FILTER_TRANSLATE:
1984 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1985 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
1989 case GDK_FILTER_CONTINUE:
1990 /* Send unknown client messages on to Gtk for it to use */
1992 event->client.type = GDK_CLIENT_EVENT;
1993 event->client.window = window;
1994 event->client.message_type = GDK_POINTER_TO_ATOM (msg->wParam);
1995 event->client.data_format = 32;
1996 event->client.data.l[0] = msg->lParam;
1997 for (i = 1; i < 5; i++)
1998 event->client.data.l[i] = 0;
1999 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
2005 switch (msg->message)
2007 case WM_INPUTLANGCHANGE:
2008 _gdk_input_locale = (HKL) msg->lParam;
2009 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
2010 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
2011 LOCALE_IDEFAULTANSICODEPAGE,
2013 _gdk_input_codepage = atoi (buf);
2014 _gdk_keymap_serial++;
2016 g_print (" cs:%lu hkl:%p%s cp:%d",
2017 (gulong) msg->wParam,
2018 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
2019 _gdk_input_codepage));
2025 g_print (" %s ch:%.02x %s",
2026 _gdk_win32_key_to_string (msg->lParam),
2028 decode_key_lparam (msg->lParam)));
2030 /* If posted without us having keyboard focus, ignore */
2031 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
2032 !(HIWORD (msg->lParam) & KF_ALTDOWN))
2035 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
2036 * the keyboard is grabbed.
2038 if (_gdk_display->keyboard_grab.window == NULL &&
2039 (msg->wParam == VK_TAB ||
2040 msg->wParam == VK_SPACE ||
2041 msg->wParam == VK_F4))
2044 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
2050 g_print (" %s ch:%.02x %s",
2051 _gdk_win32_key_to_string (msg->lParam),
2053 decode_key_lparam (msg->lParam)));
2057 /* Ignore key messages intended for the IME */
2058 if (msg->wParam == VK_PROCESSKEY ||
2062 if (!propagate (&window, msg,
2063 _gdk_display->keyboard_grab.window,
2064 _gdk_display->keyboard_grab.owner_events,
2065 GDK_ALL_EVENTS_MASK,
2066 doesnt_want_key, FALSE))
2069 if (GDK_WINDOW_DESTROYED (window))
2072 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
2073 msg->message == WM_SYSKEYDOWN) ?
2074 GDK_KEY_PRESS : GDK_KEY_RELEASE);
2075 event->key.window = window;
2076 event->key.time = _gdk_win32_get_next_tick (msg->time);
2077 event->key.keyval = GDK_VoidSymbol;
2078 event->key.string = NULL;
2079 event->key.length = 0;
2080 event->key.hardware_keycode = msg->wParam;
2081 if (HIWORD (msg->lParam) & KF_EXTENDED)
2083 switch (msg->wParam)
2086 event->key.hardware_keycode = VK_RCONTROL;
2088 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
2089 * for the right shift key.
2091 event->key.hardware_keycode = VK_RSHIFT;
2094 event->key.hardware_keycode = VK_RMENU;
2098 else if (msg->wParam == VK_SHIFT &&
2099 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
2100 event->key.hardware_keycode = VK_RSHIFT;
2102 API_CALL (GetKeyboardState, (key_state));
2104 /* 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]); */
2106 build_key_event_state (event, key_state);
2108 gdk_keymap_translate_keyboard_state (NULL,
2109 event->key.hardware_keycode,
2115 fill_key_event_string (event);
2117 /* Reset MOD1_MASK if it is the Alt key itself */
2118 if (msg->wParam == VK_MENU)
2119 event->key.state &= ~GDK_MOD1_MASK;
2121 append_event (event);
2127 if (msg->wParam != VK_SPACE)
2129 /* To prevent beeps, don't let DefWindowProcW() be called */
2135 case WM_IME_STARTCOMPOSITION:
2136 in_ime_composition = TRUE;
2139 case WM_IME_ENDCOMPOSITION:
2140 in_ime_composition = FALSE;
2143 case WM_IME_COMPOSITION:
2144 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2145 * applications. Thus, handle WM_IME_COMPOSITION with
2146 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2147 * with ImmGetCompositionStringW().
2150 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2152 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2153 * for comments by other people that seems to have the same
2154 * experience. WM_IME_CHAR just gives question marks, apparently
2155 * because of going through some conversion to the current code
2158 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2159 * use WM_IME_COMPOSITION there, too, to simplify the code.
2161 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2163 if (!(msg->lParam & GCS_RESULTSTR))
2166 if (!propagate (&window, msg,
2167 _gdk_display->keyboard_grab.window,
2168 _gdk_display->keyboard_grab.owner_events,
2169 GDK_ALL_EVENTS_MASK,
2170 doesnt_want_char, FALSE))
2173 if (GDK_WINDOW_DESTROYED (window))
2176 himc = ImmGetContext (msg->hwnd);
2177 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2178 wbuf, sizeof (wbuf));
2179 ImmReleaseContext (msg->hwnd, himc);
2183 API_CALL (GetKeyboardState, (key_state));
2185 for (i = 0; i < ccount; i++)
2187 if (((GdkWindowObject *) window)->event_mask & GDK_KEY_PRESS_MASK)
2189 /* Build a key press event */
2190 event = gdk_event_new (GDK_KEY_PRESS);
2191 event->key.window = window;
2192 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2194 append_event (event);
2197 if (((GdkWindowObject *) window)->event_mask & GDK_KEY_RELEASE_MASK)
2199 /* Build a key release event. */
2200 event = gdk_event_new (GDK_KEY_RELEASE);
2201 event->key.window = window;
2202 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2204 append_event (event);
2210 case WM_LBUTTONDOWN:
2214 case WM_MBUTTONDOWN:
2218 case WM_RBUTTONDOWN:
2222 case WM_XBUTTONDOWN:
2223 if (HIWORD (msg->wParam) == XBUTTON1)
2230 g_print (" (%d,%d)",
2231 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2233 assign_object (&window, find_window_for_mouse_event (window, msg));
2234 /* TODO_CSW?: there used to some synthesize and propagate */
2235 if (GDK_WINDOW_DESTROYED (window))
2238 /* TODO_CSW? Emulate X11's automatic active grab */
2239 generate_button_event (GDK_BUTTON_PRESS, button,
2258 if (HIWORD (msg->wParam) == XBUTTON1)
2265 g_print (" (%d,%d)",
2266 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2268 assign_object (&window, find_window_for_mouse_event (window, msg));
2270 if (((GdkWindowObject *) window)->extension_events != 0 &&
2271 _gdk_input_ignore_core)
2273 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2278 generate_button_event (GDK_BUTTON_RELEASE, button,
2286 g_print (" %p (%d,%d)",
2287 (gpointer) msg->wParam,
2288 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2290 assign_object (&window, find_window_for_mouse_event (window, msg));
2291 toplevel = gdk_window_get_toplevel (window);
2292 if (current_toplevel != toplevel)
2294 GDK_NOTE (EVENTS, g_print (" toplevel %p -> %p",
2295 current_toplevel ? GDK_WINDOW_HWND (current_toplevel) : NULL,
2296 toplevel ? GDK_WINDOW_HWND (toplevel) : NULL));
2297 if (current_toplevel)
2298 synthesize_enter_or_leave_event (current_toplevel, msg,
2299 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2300 synthesize_enter_or_leave_event (toplevel, msg,
2301 GDK_ENTER_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2302 assign_object (¤t_toplevel, toplevel);
2303 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (toplevel));
2306 /* If we haven't moved, don't create any GDK event. Windows
2307 * sends WM_MOUSEMOVE messages after a new window is shows under
2308 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2310 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2311 msg->pt.y + _gdk_offset_y == current_root_y)
2314 current_root_x = msg->pt.x + _gdk_offset_x;
2315 current_root_y = msg->pt.y + _gdk_offset_y;
2317 event = gdk_event_new (GDK_MOTION_NOTIFY);
2318 event->motion.window = window;
2319 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2320 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2321 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2322 event->motion.x_root = current_root_x;
2323 event->motion.y_root = current_root_y;
2324 event->motion.axes = NULL;
2325 event->motion.state = build_pointer_event_state (msg);
2326 event->motion.is_hint = FALSE;
2327 event->motion.device = _gdk_display->core_pointer;
2329 append_event (event);
2334 case WM_NCMOUSEMOVE:
2336 g_print (" (%d,%d)",
2337 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2338 #if 0 /* TODO_CSW? */
2339 if (current_toplevel != NULL &&
2340 (((GdkWindowObject *) current_toplevel)->event_mask & GDK_LEAVE_NOTIFY_MASK))
2342 synthesize_enter_or_leave_event (current_toplevel, msg,
2343 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2349 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2350 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2352 if (!gdk_win32_handle_table_lookup ((GdkNativeWindow) WindowFromPoint (msg->pt)))
2354 /* we are only interested if we don't know the new window */
2355 if (current_toplevel)
2356 synthesize_enter_or_leave_event (current_toplevel, msg,
2357 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2358 assign_object (¤t_toplevel, NULL);
2362 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2369 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2371 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2372 * that. Also, the position is in screen coordinates, not client
2373 * coordinates as with the button messages. I love the
2374 * consistency of Windows.
2376 point.x = GET_X_LPARAM (msg->lParam);
2377 point.y = GET_Y_LPARAM (msg->lParam);
2379 if ((hwnd = WindowFromPoint (point)) == NULL)
2383 if ((new_window = gdk_win32_handle_table_lookup ((GdkNativeWindow) msg->hwnd)) == NULL)
2386 if (new_window != window)
2388 assign_object (&window, new_window);
2391 ScreenToClient (msg->hwnd, &point);
2393 event = gdk_event_new (GDK_SCROLL);
2394 event->scroll.window = window;
2395 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2396 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2397 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2398 event->scroll.x = (gint16) point.x;
2399 event->scroll.y = (gint16) point.y;
2400 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2401 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2402 event->scroll.state = build_pointer_event_state (msg);
2403 event->scroll.device = _gdk_display->core_pointer;
2405 append_event (event);
2411 /* Just print more debugging information, don't actually handle it. */
2414 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2415 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2416 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2417 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2418 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2419 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2420 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2421 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2422 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2424 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2425 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2426 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2430 /* Just print more debugging information, don't actually handle it. */
2433 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2434 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2435 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2436 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2437 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2438 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2439 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2440 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2441 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2443 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2444 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2445 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2448 case WM_QUERYNEWPALETTE:
2449 if (gdk_visual_get_system ()->type == GDK_VISUAL_PSEUDO_COLOR)
2451 synthesize_expose_events (window);
2452 update_colors_counter = 0;
2457 case WM_PALETTECHANGED:
2458 GDK_NOTE (EVENTS_OR_COLORMAP, g_print (" %p", (HWND) msg->wParam));
2459 if (gdk_visual_get_system ()->type != GDK_VISUAL_PSEUDO_COLOR)
2464 if (msg->hwnd == (HWND) msg->wParam)
2467 if (++update_colors_counter == 5)
2469 synthesize_expose_events (window);
2470 update_colors_counter = 0;
2474 update_colors (window, TRUE);
2477 case WM_MOUSEACTIVATE:
2481 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2482 || !((GdkWindowObject *)window)->accept_focus)
2484 *ret_valp = MA_NOACTIVATE;
2488 tmp = _gdk_modal_current ();
2492 if (gdk_window_get_toplevel (window) != tmp)
2494 *ret_valp = MA_NOACTIVATEANDEAT;
2503 if (_gdk_display->keyboard_grab.window != NULL &&
2504 !GDK_WINDOW_DESTROYED (_gdk_display->keyboard_grab.window))
2506 generate_grab_broken_event (_gdk_display->keyboard_grab.window, FALSE, NULL);
2511 if (_gdk_display->keyboard_grab.window != NULL &&
2512 !_gdk_display->keyboard_grab.owner_events)
2515 if (!(((GdkWindowObject *) window)->event_mask & GDK_FOCUS_CHANGE_MASK))
2518 if (GDK_WINDOW_DESTROYED (window))
2521 generate_focus_event (window, (msg->message == WM_SETFOCUS));
2526 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2528 if (GDK_WINDOW_DESTROYED (window))
2536 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2538 200, sync_timer_proc);
2542 handle_wm_paint (msg, window, FALSE, NULL);
2546 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2547 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2549 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
2552 grab_window = grab->window;
2555 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2558 if (grab_window != NULL && p_grab_cursor != NULL)
2559 hcursor = p_grab_cursor;
2560 else if (!GDK_WINDOW_DESTROYED (window))
2561 hcursor = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl)->hcursor;
2565 if (hcursor != NULL)
2567 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2568 SetCursor (hcursor);
2575 GDK_NOTE (EVENTS, g_print (" %s %s",
2576 (msg->wParam ? "YES" : "NO"),
2577 (msg->lParam == 0 ? "ShowWindow" :
2578 (msg->lParam == SW_OTHERUNZOOM ? "OTHERUNZOOM" :
2579 (msg->lParam == SW_OTHERZOOM ? "OTHERZOOM" :
2580 (msg->lParam == SW_PARENTCLOSING ? "PARENTCLOSING" :
2581 (msg->lParam == SW_PARENTOPENING ? "PARENTOPENING" :
2584 if (!(((GdkWindowObject *) window)->event_mask & GDK_STRUCTURE_MASK))
2587 if (msg->lParam == SW_OTHERUNZOOM ||
2588 msg->lParam == SW_OTHERZOOM)
2591 if (GDK_WINDOW_DESTROYED (window))
2594 event = gdk_event_new (msg->wParam ? GDK_MAP : GDK_UNMAP);
2595 event->any.window = window;
2597 append_event (event);
2599 if (event->any.type == GDK_UNMAP)
2601 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
2603 if (impl->transient_owner && GetForegroundWindow () == GDK_WINDOW_HWND (window))
2605 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2608 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
2611 if (grab->window == window)
2612 gdk_pointer_ungrab (msg->time);
2615 if (_gdk_display->keyboard_grab.window == window)
2616 gdk_keyboard_ungrab (msg->time);
2623 switch (msg->wParam)
2627 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2635 g_print (" %s %dx%d",
2636 (msg->wParam == SIZE_MAXHIDE ? "MAXHIDE" :
2637 (msg->wParam == SIZE_MAXIMIZED ? "MAXIMIZED" :
2638 (msg->wParam == SIZE_MAXSHOW ? "MAXSHOW" :
2639 (msg->wParam == SIZE_MINIMIZED ? "MINIMIZED" :
2640 (msg->wParam == SIZE_RESTORED ? "RESTORED" : "?"))))),
2641 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2643 if (msg->wParam == SIZE_MINIMIZED)
2645 /* Don't generate any GDK event. This is *not* an UNMAP. */
2646 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
2649 if (grab->window == window)
2650 gdk_pointer_ungrab (msg->time);
2652 if (_gdk_display->keyboard_grab.window == window)
2653 gdk_keyboard_ungrab (msg->time);
2655 gdk_synthesize_window_state (window,
2656 GDK_WINDOW_STATE_WITHDRAWN,
2657 GDK_WINDOW_STATE_ICONIFIED);
2658 do_show_window (window, TRUE);
2660 else if ((msg->wParam == SIZE_RESTORED ||
2661 msg->wParam == SIZE_MAXIMIZED) &&
2662 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
2664 GdkWindowState withdrawn_bit =
2665 IsWindowVisible (msg->hwnd) ? GDK_WINDOW_STATE_WITHDRAWN : 0;
2667 if (((GdkWindowObject *) window)->state & GDK_WINDOW_STATE_ICONIFIED)
2668 ensure_stacking_on_unminimize (msg);
2670 if (!GDK_WINDOW_DESTROYED (window))
2671 handle_configure_event (msg, window);
2673 if (msg->wParam == SIZE_RESTORED)
2675 gdk_synthesize_window_state (window,
2676 GDK_WINDOW_STATE_ICONIFIED |
2677 GDK_WINDOW_STATE_MAXIMIZED |
2681 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_TEMP && !GDK_WINDOW_IS_MAPPED (window))
2683 do_show_window (window, FALSE);
2686 else if (msg->wParam == SIZE_MAXIMIZED)
2688 gdk_synthesize_window_state (window,
2689 GDK_WINDOW_STATE_ICONIFIED |
2691 GDK_WINDOW_STATE_MAXIMIZED);
2694 if (((GdkWindowObject *) window)->resize_count > 1)
2695 ((GdkWindowObject *) window)->resize_count -= 1;
2697 if (((GdkWindowObject *) window)->extension_events != 0)
2698 _gdk_input_configure_event (window);
2704 case WM_ENTERSIZEMOVE:
2705 _sizemove_in_progress = TRUE;
2706 modal_timer = SetTimer (NULL, 0, 20, modal_timer_proc);
2709 case WM_EXITSIZEMOVE:
2710 _sizemove_in_progress = FALSE;
2711 KillTimer (NULL, modal_timer);
2714 case WM_ENTERMENULOOP:
2715 _sizemove_in_progress = TRUE;
2716 modal_timer = SetTimer (NULL, 0, 20, modal_timer_proc);
2719 case WM_EXITMENULOOP:
2720 _sizemove_in_progress = FALSE;
2721 KillTimer (NULL, modal_timer);
2724 case WM_WINDOWPOSCHANGING:
2725 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2726 g_print (" %s %s %dx%d@%+d%+d now below %p",
2727 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2728 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2729 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2730 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2731 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2732 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2734 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2735 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2737 if (GDK_WINDOW_IS_MAPPED (window))
2738 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2741 case WM_WINDOWPOSCHANGED:
2742 windowpos = (WINDOWPOS *) msg->lParam;
2743 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2744 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2745 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2746 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2747 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2748 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2749 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2751 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2753 /* If position and size haven't changed, don't do anything */
2754 if (_sizemove_in_progress &&
2755 (windowpos->flags & SWP_NOMOVE) &&
2756 (windowpos->flags & SWP_NOSIZE))
2759 /* Once we've entered the moving or sizing modal loop, we won't
2760 * return to the main loop until we're done sizing or moving.
2762 if (_sizemove_in_progress &&
2763 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2764 !GDK_WINDOW_DESTROYED (window))
2766 if (((GdkWindowObject *) window)->event_mask & GDK_STRUCTURE_MASK)
2768 GDK_NOTE (EVENTS, g_print (" do magic"));
2769 if (((GdkWindowObject *) window)->resize_count > 1)
2770 ((GdkWindowObject *) window)->resize_count -= 1;
2772 handle_configure_event (msg, window);
2773 g_main_context_iteration (NULL, FALSE);
2775 /* Dispatch main loop - to realize resizes... */
2776 handle_stuff_while_moving_or_resizing ();
2778 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2786 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2787 drag = (RECT *) msg->lParam;
2788 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2789 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2790 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2791 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2792 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2793 (msg->wParam == WMSZ_TOP ? "TOP" :
2794 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2795 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2797 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2799 _gdk_win32_rect_to_string (&rect),
2800 _gdk_win32_rect_to_string (drag)));
2802 impl = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
2804 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2806 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2807 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2809 /* Resize in increments relative to the base size */
2810 rect.left = rect.top = 0;
2811 rect.right = impl->hints.base_width;
2812 rect.bottom = impl->hints.base_height;
2813 _gdk_win32_adjust_client_rect (window, &rect);
2814 point.x = rect.left;
2816 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2817 rect.left = point.x;
2819 point.x = rect.right;
2820 point.y = rect.bottom;
2821 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2822 rect.right = point.x;
2823 rect.bottom = point.y;
2825 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2826 _gdk_win32_rect_to_string (&rect)));
2829 switch (msg->wParam)
2832 if (drag->bottom == rect.bottom)
2834 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2837 case WMSZ_BOTTOMLEFT:
2838 if (drag->bottom == rect.bottom && drag->left == rect.left)
2840 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2841 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2845 if (drag->left == rect.left)
2847 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2851 if (drag->top == rect.top && drag->left == rect.left)
2853 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2854 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2858 if (drag->top == rect.top)
2860 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2864 if (drag->top == rect.top && drag->right == rect.right)
2866 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2867 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2871 if (drag->right == rect.right)
2873 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2876 case WMSZ_BOTTOMRIGHT:
2877 if (drag->bottom == rect.bottom && drag->right == rect.right)
2879 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2880 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2884 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2885 drag->top != orig_drag.top || drag->right != orig_drag.right)
2889 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2890 _gdk_win32_rect_to_string (drag)));
2894 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2896 if (impl->hint_flags & GDK_HINT_ASPECT)
2898 RECT decorated_rect;
2899 RECT undecorated_drag;
2900 int decoration_width, decoration_height;
2901 gdouble drag_aspect;
2902 int drag_width, drag_height, new_width, new_height;
2904 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2905 decorated_rect = rect;
2906 _gdk_win32_adjust_client_rect (window, &decorated_rect);
2908 /* Set undecorated_drag to the client area being dragged
2909 * out, in screen coordinates.
2911 undecorated_drag = *drag;
2912 undecorated_drag.left -= decorated_rect.left - rect.left;
2913 undecorated_drag.right -= decorated_rect.right - rect.right;
2914 undecorated_drag.top -= decorated_rect.top - rect.top;
2915 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
2917 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
2918 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
2920 drag_width = undecorated_drag.right - undecorated_drag.left;
2921 drag_height = undecorated_drag.bottom - undecorated_drag.top;
2923 drag_aspect = (gdouble) drag_width / drag_height;
2925 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
2926 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
2928 if (drag_aspect < impl->hints.min_aspect)
2930 /* Aspect is getting too narrow */
2931 switch (msg->wParam)
2935 /* User drags top or bottom edge outward. Keep height, increase width. */
2936 new_width = impl->hints.min_aspect * drag_height;
2937 drag->left -= (new_width - drag_width) / 2;
2938 drag->right = drag->left + new_width + decoration_width;
2940 case WMSZ_BOTTOMLEFT:
2941 case WMSZ_BOTTOMRIGHT:
2942 /* User drags bottom-left or bottom-right corner down. Adjust height. */
2943 new_height = drag_width / impl->hints.min_aspect;
2944 drag->bottom = drag->top + new_height + decoration_height;
2948 /* User drags left or right edge inward. Decrease height */
2949 new_height = drag_width / impl->hints.min_aspect;
2950 drag->top += (drag_height - new_height) / 2;
2951 drag->bottom = drag->top + new_height + decoration_height;
2955 /* User drags top-left or top-right corner up. Adjust height. */
2956 new_height = drag_width / impl->hints.min_aspect;
2957 drag->top = drag->bottom - new_height - decoration_height;
2960 else if (drag_aspect > impl->hints.max_aspect)
2962 /* Aspect is getting too wide */
2963 switch (msg->wParam)
2967 /* User drags top or bottom edge inward. Decrease width. */
2968 new_width = impl->hints.max_aspect * drag_height;
2969 drag->left += (drag_width - new_width) / 2;
2970 drag->right = drag->left + new_width + decoration_width;
2972 case WMSZ_BOTTOMLEFT:
2974 /* User drags bottom-left or top-left corner left. Adjust width. */
2975 new_width = impl->hints.max_aspect * drag_height;
2976 drag->left = drag->right - new_width - decoration_width;
2978 case WMSZ_BOTTOMRIGHT:
2980 /* User drags bottom-right or top-right corner right. Adjust width. */
2981 new_width = impl->hints.max_aspect * drag_height;
2982 drag->right = drag->left + new_width + decoration_width;
2986 /* User drags left or right edge outward. Increase height. */
2987 new_height = drag_width / impl->hints.max_aspect;
2988 drag->top -= (new_height - drag_height) / 2;
2989 drag->bottom = drag->top + new_height + decoration_height;
2996 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
2997 _gdk_win32_rect_to_string (drag)));
3001 case WM_GETMINMAXINFO:
3002 if (GDK_WINDOW_DESTROYED (window))
3005 impl = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
3006 mmi = (MINMAXINFO*) msg->lParam;
3007 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
3008 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3009 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3010 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3011 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3012 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3014 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
3016 rect.left = rect.top = 0;
3017 rect.right = impl->hints.min_width;
3018 rect.bottom = impl->hints.min_height;
3020 _gdk_win32_adjust_client_rect (window, &rect);
3022 mmi->ptMinTrackSize.x = rect.right - rect.left;
3023 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
3026 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
3030 rect.left = rect.top = 0;
3031 rect.right = impl->hints.max_width;
3032 rect.bottom = impl->hints.max_height;
3034 _gdk_win32_adjust_client_rect (window, &rect);
3036 /* at least on win9x we have the 16 bit trouble */
3037 maxw = rect.right - rect.left;
3038 maxh = rect.bottom - rect.top;
3039 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
3040 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
3043 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
3045 /* Don't call DefWindowProcW() */
3046 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
3047 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3048 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3049 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3050 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3051 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3057 GDK_NOTE (EVENTS, g_print (" (%d,%d)",
3058 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
3060 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
3061 !IsIconic (msg->hwnd))
3063 if (!GDK_WINDOW_DESTROYED (window))
3064 handle_configure_event (msg, window);
3071 if (GDK_WINDOW_DESTROYED (window))
3074 event = gdk_event_new (GDK_DELETE);
3075 event->any.window = window;
3077 append_event (event);
3079 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
3081 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
3083 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3090 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
3093 if (grab->window == window)
3094 gdk_pointer_ungrab (msg->time);
3097 if (_gdk_display->keyboard_grab.window == window)
3098 gdk_keyboard_ungrab (msg->time);
3100 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
3101 gdk_window_destroy_notify (window);
3103 if (window == NULL || GDK_WINDOW_DESTROYED (window))
3106 event = gdk_event_new (GDK_DESTROY);
3107 event->any.window = window;
3109 append_event (event);
3114 case WM_DISPLAYCHANGE:
3115 handle_display_change ();
3118 case WM_DESTROYCLIPBOARD:
3119 if (!_ignore_destroy_clipboard)
3121 event = gdk_event_new (GDK_SELECTION_CLEAR);
3122 event->selection.window = window;
3123 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3124 event->selection.time = _gdk_win32_get_next_tick (msg->time);
3125 append_event (event);
3134 case WM_RENDERFORMAT:
3135 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
3137 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
3139 GDK_NOTE (EVENTS, g_print (" (target not found)"));
3144 /* We need to render to clipboard immediately, don't call
3147 if (_gdk_event_func)
3149 event = gdk_event_new (GDK_SELECTION_REQUEST);
3150 event->selection.window = window;
3151 event->selection.send_event = FALSE;
3152 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3153 event->selection.target = target;
3154 event->selection.property = _gdk_selection;
3155 event->selection.requestor = msg->hwnd;
3156 event->selection.time = msg->time;
3158 fixup_event (event);
3159 GDK_NOTE (EVENTS, g_print (" (calling gdk_event_func)"));
3160 GDK_NOTE (EVENTS, _gdk_win32_print_event (event));
3161 (*_gdk_event_func) (event, _gdk_event_data);
3162 gdk_event_free (event);
3164 /* Now the clipboard owner should have rendered */
3165 if (!_delayed_rendering_data)
3167 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3171 if (msg->wParam == CF_DIB)
3173 _delayed_rendering_data =
3174 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3176 if (!_delayed_rendering_data)
3178 g_warning ("Cannot convert to DIB from delayed rendered image");
3183 /* The requestor is holding the clipboard, no
3184 * OpenClipboard() is required/possible
3187 g_print (" SetClipboardData(%s,%p)",
3188 _gdk_win32_cf_to_string (msg->wParam),
3189 _delayed_rendering_data));
3191 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3192 _delayed_rendering_data = NULL;
3198 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3199 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3200 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3201 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3202 HIWORD (msg->wParam) ? " minimized" : "",
3203 (HWND) msg->lParam));
3204 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3205 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3208 if (is_modally_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3210 GdkWindow *modal_current = _gdk_modal_current ();
3211 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3217 /* Bring any tablet contexts to the top of the overlap order when
3218 * one of our windows is activated.
3219 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3222 if (LOWORD(msg->wParam) != WA_INACTIVE)
3223 _gdk_input_set_tablet_active ();
3226 case WM_ACTIVATEAPP:
3227 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3228 msg->wParam ? "YES" : "NO",
3229 (gint64) msg->lParam));
3230 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3231 ensure_stacking_on_activate_app (msg, window);
3234 /* Handle WINTAB events here, as we know that gdkinput.c will
3235 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3236 * constants as case labels.
3239 GDK_NOTE (EVENTS, g_print (" %d %p",
3240 (int) msg->wParam, (gpointer) msg->lParam));
3244 GDK_NOTE (EVENTS, g_print (" %d %p",
3245 (int) msg->wParam, (gpointer) msg->lParam));
3249 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3250 (gpointer) msg->wParam,
3251 LOWORD (msg->lParam),
3252 HIWORD (msg->lParam)));
3256 event = gdk_event_new (GDK_NOTHING);
3257 event->any.window = window;
3258 g_object_ref (window);
3260 if (_gdk_input_other_event (event, msg, window))
3261 append_event (event);
3263 gdk_event_free (event);
3271 g_object_unref (window);
3278 _gdk_events_queue (GdkDisplay *display)
3282 if (modal_win32_dialog != NULL)
3285 while (!_gdk_event_queue_find_first (display) &&
3286 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3288 TranslateMessage (&msg);
3289 DispatchMessageW (&msg);
3294 gdk_event_prepare (GSource *source,
3300 GDK_THREADS_ENTER ();
3304 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3305 (modal_win32_dialog == NULL &&
3306 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3308 GDK_THREADS_LEAVE ();
3314 gdk_event_check (GSource *source)
3319 GDK_THREADS_ENTER ();
3321 if (event_poll_fd.revents & G_IO_IN)
3323 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3324 (modal_win32_dialog == NULL &&
3325 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3332 GDK_THREADS_LEAVE ();
3338 gdk_event_dispatch (GSource *source,
3339 GSourceFunc callback,
3344 GDK_THREADS_ENTER ();
3346 _gdk_events_queue (_gdk_display);
3347 event = _gdk_event_unqueue (_gdk_display);
3351 if (_gdk_event_func)
3352 (*_gdk_event_func) (event, _gdk_event_data);
3354 gdk_event_free (event);
3357 GDK_THREADS_LEAVE ();
3363 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3365 modal_win32_dialog = window;
3369 is_modally_blocked (GdkWindow *window)
3371 GdkWindow *modal_current = _gdk_modal_current ();
3372 return modal_current != NULL ? gdk_window_get_toplevel (window) != modal_current : FALSE;
3376 check_for_too_much_data (GdkEvent *event)
3378 if (event->client.data.l[1] ||
3379 event->client.data.l[2] ||
3380 event->client.data.l[3] ||
3381 event->client.data.l[4])
3383 g_warning ("Only four bytes of data are passed in client messages on Win32\n");
3388 gdk_event_send_client_message_for_display (GdkDisplay *display,
3390 GdkNativeWindow winid)
3392 check_for_too_much_data (event);
3394 return PostMessageW ((HWND) winid, client_message,
3395 (WPARAM) event->client.message_type,
3396 event->client.data.l[0]);
3400 gdk_screen_broadcast_client_message (GdkScreen *screen,
3403 check_for_too_much_data (event);
3405 PostMessageW (HWND_BROADCAST, client_message,
3406 (WPARAM) event->client.message_type,
3407 event->client.data.l[0]);
3416 /* Process all messages currently available */
3417 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3419 TranslateMessage (&msg);
3420 DispatchMessageW (&msg);
3428 gdk_display_sync (GdkDisplay * display)
3432 g_return_if_fail (display == _gdk_display);
3434 /* Process all messages currently available */
3435 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3436 DispatchMessageW (&msg);
3440 gdk_display_flush (GdkDisplay * display)
3442 g_return_if_fail (display == _gdk_display);
3448 gdk_net_wm_supports (GdkAtom property)
3454 _gdk_windowing_event_data_copy (const GdkEvent *src,
3460 _gdk_windowing_event_data_free (GdkEvent *event)