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 gboolean p_grab_automatic;
106 static GdkEventMask p_grab_mask;
107 static gboolean p_grab_owner_events, k_grab_owner_events;
108 static HCURSOR p_grab_cursor;
110 static GSourceFuncs event_funcs = {
117 GPollFD event_poll_fd;
119 static GdkWindow *current_toplevel = NULL;
120 static gint current_x, current_y;
121 static gint current_root_x, current_root_y;
122 static UINT client_message;
124 static UINT got_gdk_events_message;
125 static HWND modal_win32_dialog = NULL;
128 static HKL latin_locale = NULL;
131 static gboolean in_ime_composition = FALSE;
132 static UINT modal_timer;
133 static UINT sync_timer = 0;
135 static int debug_indent = 0;
138 assign_object (gpointer lhsp,
141 if (*(gpointer *)lhsp != rhs)
143 if (*(gpointer *)lhsp != NULL)
144 g_object_unref (*(gpointer *)lhsp);
145 *(gpointer *)lhsp = rhs;
152 track_mouse_event (DWORD dwFlags,
155 typedef BOOL (WINAPI *PFN_TrackMouseEvent) (LPTRACKMOUSEEVENT);
156 static PFN_TrackMouseEvent p_TrackMouseEvent = NULL;
157 static gboolean once = FALSE;
162 HINSTANCE commctrl32;
164 user32 = GetModuleHandle ("user32.dll");
165 if ((p_TrackMouseEvent = (PFN_TrackMouseEvent)GetProcAddress (user32, "TrackMouseEvent")) == NULL)
167 if ((commctrl32 = LoadLibrary ("commctrl32.dll")) != NULL)
168 p_TrackMouseEvent = (PFN_TrackMouseEvent)
169 GetProcAddress (commctrl32, "_TrackMouseEvent");
174 if (p_TrackMouseEvent)
177 tme.cbSize = sizeof(TRACKMOUSEEVENT);
178 tme.dwFlags = dwFlags;
179 tme.hwndTrack = hwnd;
180 tme.dwHoverTime = HOVER_DEFAULT; /* not used */
182 if (!p_TrackMouseEvent (&tme))
183 WIN32_API_FAILED ("TrackMouseEvent");
184 else if (dwFlags == TME_LEAVE)
185 GDK_NOTE (EVENTS, g_print(" (TrackMouseEvent %p)", hwnd));
186 else if (dwFlags == TME_CANCEL)
187 GDK_NOTE (EVENTS, g_print(" (cancel TrackMouseEvent %p)", hwnd));
192 _gdk_win32_get_next_tick (gulong suggested_tick)
194 static gulong cur_tick = 0;
196 if (suggested_tick == 0)
197 suggested_tick = GetTickCount ();
198 if (suggested_tick <= cur_tick)
201 return cur_tick = suggested_tick;
205 generate_focus_event (GdkWindow *window,
210 event = gdk_event_new (GDK_FOCUS_CHANGE);
211 event->focus_change.window = window;
212 event->focus_change.in = in;
214 append_event (event);
218 generate_grab_broken_event (GdkWindow *window,
220 GdkWindow *grab_window)
222 GdkEvent *event = gdk_event_new (GDK_GRAB_BROKEN);
224 event->grab_broken.window = window;
225 event->grab_broken.send_event = 0;
226 event->grab_broken.keyboard = keyboard;
227 event->grab_broken.implicit = FALSE;
228 event->grab_broken.grab_window = grab_window;
230 append_event (event);
234 inner_window_procedure (HWND hwnd,
244 msg.message = message;
247 msg.time = _gdk_win32_get_next_tick (0);
248 pos = GetMessagePos ();
249 msg.pt.x = GET_X_LPARAM (pos);
250 msg.pt.y = GET_Y_LPARAM (pos);
252 if (gdk_event_translate (&msg, &ret_val))
254 /* If gdk_event_translate() returns TRUE, we return ret_val from
255 * the window procedure.
257 if (modal_win32_dialog)
258 PostMessageW (modal_win32_dialog, got_gdk_events_message,
264 /* Otherwise call DefWindowProcW(). */
265 GDK_NOTE (EVENTLOOP, g_print (" DefWindowProcW"));
266 return DefWindowProcW (hwnd, message, wparam, lparam);
271 _gdk_win32_window_procedure (HWND hwnd,
278 GDK_NOTE (EVENTS, g_print ("%s%*s%s %p",
279 (debug_indent > 0 ? "\n" : ""),
281 _gdk_win32_message_to_string (message), hwnd));
283 retval = inner_window_procedure (hwnd, message, wparam, lparam);
286 GDK_NOTE (EVENTS, g_print (" => %I64d%s", (gint64) retval, (debug_indent == 0 ? "\n" : "")));
292 _gdk_events_init (void)
299 /* List of languages that use a latin keyboard. Somewhat sorted in
300 * "order of least surprise", in case we have to load one of them if
301 * the user only has arabic loaded, for instance.
303 static int latin_languages[] = {
309 /* Rest in numeric order */
338 client_message = RegisterWindowMessage ("GDK_WIN32_CLIENT_MESSAGE");
339 got_gdk_events_message = RegisterWindowMessage ("GDK_WIN32_GOT_EVENTS");
342 /* Check if we have some input locale identifier loaded that uses a
343 * latin keyboard, to be able to get the virtual-key code for the
344 * latin characters corresponding to ASCII control characters.
346 if ((n = GetKeyboardLayoutList (0, NULL)) == 0)
347 WIN32_API_FAILED ("GetKeyboardLayoutList");
350 HKL *hkl_list = g_new (HKL, n);
351 if (GetKeyboardLayoutList (n, hkl_list) == 0)
352 WIN32_API_FAILED ("GetKeyboardLayoutList");
355 for (i = 0; latin_locale == NULL && i < n; i++)
356 for (j = 0; j < G_N_ELEMENTS (latin_languages); j++)
357 if (PRIMARYLANGID (LOWORD (hkl_list[i])) == latin_languages[j])
359 latin_locale = hkl_list [i];
366 if (latin_locale == NULL)
368 /* Try to load a keyboard layout with latin characters then.
371 while (latin_locale == NULL && i < G_N_ELEMENTS (latin_languages))
374 g_sprintf (id, "%08x", MAKELANGID (latin_languages[i++], SUBLANG_DEFAULT));
375 latin_locale = LoadKeyboardLayout (id, KLF_NOTELLSHELL|KLF_SUBSTITUTE_OK);
379 GDK_NOTE (EVENTS, g_print ("latin_locale = %08x\n", (guint) latin_locale));
382 source = g_source_new (&event_funcs, sizeof (GSource));
383 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
386 event_poll_fd.fd = open ("/dev/windows", O_RDONLY);
387 if (event_poll_fd.fd == -1)
388 g_error ("can't open \"/dev/windows\": %s", g_strerror (errno));
390 event_poll_fd.fd = G_WIN32_MSG_HANDLE;
392 event_poll_fd.events = G_IO_IN;
394 g_source_add_poll (source, &event_poll_fd);
395 g_source_set_can_recurse (source, TRUE);
396 g_source_attach (source, NULL);
400 gdk_events_pending (void)
403 return (_gdk_event_queue_find_first (_gdk_display) ||
404 (modal_win32_dialog == NULL &&
405 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
409 gdk_event_get_graphics_expose (GdkWindow *window)
412 GdkEvent *event = NULL;
414 g_return_val_if_fail (window != NULL, NULL);
416 GDK_NOTE (EVENTS, g_print ("gdk_event_get_graphics_expose\n"));
418 if (PeekMessageW (&msg, GDK_WINDOW_HWND (window), WM_PAINT, WM_PAINT, PM_REMOVE))
420 handle_wm_paint (&msg, window, TRUE, &event);
423 GDK_NOTE (EVENTS, g_print ("gdk_event_get_graphics_expose: got it!\n"));
428 GDK_NOTE (EVENTS, g_print ("gdk_event_get_graphics_expose: nope\n"));
433 event_mask_string (GdkEventMask mask)
435 static char bfr[500];
440 if (mask & GDK_##x##_MASK) \
441 p += g_sprintf (p, "%s" #x, (p > bfr ? " " : ""))
443 BIT (POINTER_MOTION);
444 BIT (POINTER_MOTION_HINT);
446 BIT (BUTTON1_MOTION);
447 BIT (BUTTON2_MOTION);
448 BIT (BUTTON3_MOTION);
450 BIT (BUTTON_RELEASE);
457 BIT (PROPERTY_CHANGE);
458 BIT (VISIBILITY_NOTIFY);
469 _gdk_windowing_pointer_grab (GdkWindow *window,
470 GdkWindow *native_window,
471 gboolean owner_events,
472 GdkEventMask event_mask,
473 GdkWindow *confine_to,
477 SetCapture (GDK_WINDOW_HWND (native_window));
478 /* TODO_CSW: grab brokens, confine window, cursor, input_grab */
479 return GDK_GRAB_SUCCESS;
483 gdk_display_pointer_ungrab (GdkDisplay *display,
486 GdkPointerGrabInfo *info;
488 info = _gdk_display_get_last_pointer_grab (display);
491 info->serial_end = 0;
494 /* TODO_CSW: cursor, confines, etc */
496 _gdk_display_pointer_grab_update (display, 0);
501 find_window_for_mouse_event (GdkWindow* reported_window,
507 GdkWindow* other_window = NULL;
509 if (!_gdk_display_get_last_pointer_grab (_gdk_display))
510 return reported_window;
512 points = MAKEPOINTS (msg->lParam);
515 ClientToScreen (msg->hwnd, &pt);
517 hwnd = WindowFromPoint (pt);
523 GetClientRect (hwnd, &rect);
524 ScreenToClient (hwnd, &pt);
525 if (!PtInRect (&rect, pt))
528 other_window = gdk_win32_handle_table_lookup ((GdkNativeWindow) hwnd);
531 if (other_window == NULL)
534 /* need to also adjust the coordinates to the new window */
537 ClientToScreen (msg->hwnd, &pt);
538 ScreenToClient (GDK_WINDOW_HWND (other_window), &pt);
539 /* ATTENTION: need to update client coords */
540 msg->lParam = MAKELPARAM (pt.x, pt.y);
546 gdk_keyboard_grab (GdkWindow *window,
547 gboolean owner_events,
553 g_return_val_if_fail (window != NULL, 0);
554 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
556 GDK_NOTE (EVENTS, g_print ("gdk_keyboard_grab %p%s\n",
557 GDK_WINDOW_HWND (window), owner_events ? " OWNER_EVENTS" : ""));
559 display = gdk_drawable_get_display (window);
560 toplevel = gdk_window_get_toplevel (window);
562 _gdk_display_set_has_keyboard_grab (display,
569 return GDK_GRAB_SUCCESS;
573 gdk_display_keyboard_ungrab (GdkDisplay *display,
576 GDK_NOTE (EVENTS, g_print ("gdk_display_keyboard_ungrab\n"));
577 _gdk_display_unset_has_keyboard_grab (display, FALSE);
581 gdk_display_add_client_message_filter (GdkDisplay *display,
582 GdkAtom message_type,
587 gdk_add_client_message_filter (message_type, func, data);
591 gdk_add_client_message_filter (GdkAtom message_type,
595 GdkClientFilter *filter = g_new (GdkClientFilter, 1);
597 filter->type = message_type;
598 filter->function = func;
601 client_filters = g_list_append (client_filters, filter);
605 build_key_event_state (GdkEvent *event,
608 event->key.state = 0;
610 if (key_state[VK_SHIFT] & 0x80)
611 event->key.state |= GDK_SHIFT_MASK;
613 if (key_state[VK_CAPITAL] & 0x01)
614 event->key.state |= GDK_LOCK_MASK;
616 if (key_state[VK_LBUTTON] & 0x80)
617 event->key.state |= GDK_BUTTON1_MASK;
618 if (key_state[VK_MBUTTON] & 0x80)
619 event->key.state |= GDK_BUTTON2_MASK;
620 if (key_state[VK_RBUTTON] & 0x80)
621 event->key.state |= GDK_BUTTON3_MASK;
622 if (key_state[VK_XBUTTON1] & 0x80)
623 event->key.state |= GDK_BUTTON4_MASK;
624 if (key_state[VK_XBUTTON2] & 0x80)
625 event->key.state |= GDK_BUTTON5_MASK;
627 if (_gdk_keyboard_has_altgr &&
628 (key_state[VK_LCONTROL] & 0x80) &&
629 (key_state[VK_RMENU] & 0x80))
631 event->key.group = 1;
632 event->key.state |= GDK_MOD2_MASK;
633 if (key_state[VK_RCONTROL] & 0x80)
634 event->key.state |= GDK_CONTROL_MASK;
635 if (key_state[VK_LMENU] & 0x80)
636 event->key.state |= GDK_MOD1_MASK;
640 event->key.group = 0;
641 if (key_state[VK_CONTROL] & 0x80)
642 event->key.state |= GDK_CONTROL_MASK;
643 if (key_state[VK_MENU] & 0x80)
644 event->key.state |= GDK_MOD1_MASK;
649 build_pointer_event_state (MSG *msg)
655 if (msg->wParam & MK_CONTROL)
656 state |= GDK_CONTROL_MASK;
658 if ((msg->message != WM_LBUTTONDOWN &&
659 (msg->wParam & MK_LBUTTON)) ||
660 msg->message == WM_LBUTTONUP)
661 state |= GDK_BUTTON1_MASK;
663 if ((msg->message != WM_MBUTTONDOWN &&
664 (msg->wParam & MK_MBUTTON)) ||
665 msg->message == WM_MBUTTONUP)
666 state |= GDK_BUTTON2_MASK;
668 if ((msg->message != WM_RBUTTONDOWN &&
669 (msg->wParam & MK_RBUTTON)) ||
670 msg->message == WM_RBUTTONUP)
671 state |= GDK_BUTTON3_MASK;
673 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON1) &&
674 (msg->wParam & MK_XBUTTON1)) ||
675 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON1))
676 state |= GDK_BUTTON4_MASK;
678 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON2) &&
679 (msg->wParam & MK_XBUTTON2)) ||
680 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON2))
681 state |= GDK_BUTTON5_MASK;
683 if (msg->wParam & MK_SHIFT)
684 state |= GDK_SHIFT_MASK;
686 if (GetKeyState (VK_MENU) < 0)
687 state |= GDK_MOD1_MASK;
689 if (GetKeyState (VK_CAPITAL) & 0x1)
690 state |= GDK_LOCK_MASK;
696 build_wm_ime_composition_event (GdkEvent *event,
701 event->key.time = _gdk_win32_get_next_tick (msg->time);
703 build_key_event_state (event, key_state);
705 event->key.hardware_keycode = 0; /* FIXME: What should it be? */
706 event->key.string = NULL;
707 event->key.length = 0;
708 event->key.keyval = gdk_unicode_to_keyval (wc);
711 #ifdef G_ENABLE_DEBUG
714 print_event_state (guint state)
716 #define CASE(bit) if (state & GDK_ ## bit ## _MASK) g_print (#bit " ");
734 print_event (const GdkEvent *event)
736 gchar *escaped, *kvname;
737 gchar *selection_name, *target_name, *property_name;
739 g_print ("%s%*s===> ", (debug_indent > 0 ? "\n" : ""), debug_indent, "");
740 switch (event->any.type)
742 #define CASE(x) case x: g_print (#x); break;
747 CASE (GDK_MOTION_NOTIFY);
748 CASE (GDK_BUTTON_PRESS);
749 CASE (GDK_2BUTTON_PRESS);
750 CASE (GDK_3BUTTON_PRESS);
751 CASE (GDK_BUTTON_RELEASE);
752 CASE (GDK_KEY_PRESS);
753 CASE (GDK_KEY_RELEASE);
754 CASE (GDK_ENTER_NOTIFY);
755 CASE (GDK_LEAVE_NOTIFY);
756 CASE (GDK_FOCUS_CHANGE);
757 CASE (GDK_CONFIGURE);
760 CASE (GDK_PROPERTY_NOTIFY);
761 CASE (GDK_SELECTION_CLEAR);
762 CASE (GDK_SELECTION_REQUEST);
763 CASE (GDK_SELECTION_NOTIFY);
764 CASE (GDK_PROXIMITY_IN);
765 CASE (GDK_PROXIMITY_OUT);
766 CASE (GDK_DRAG_ENTER);
767 CASE (GDK_DRAG_LEAVE);
768 CASE (GDK_DRAG_MOTION);
769 CASE (GDK_DRAG_STATUS);
770 CASE (GDK_DROP_START);
771 CASE (GDK_DROP_FINISHED);
772 CASE (GDK_CLIENT_EVENT);
773 CASE (GDK_VISIBILITY_NOTIFY);
774 CASE (GDK_NO_EXPOSE);
776 CASE (GDK_WINDOW_STATE);
778 CASE (GDK_OWNER_CHANGE);
779 CASE (GDK_GRAB_BROKEN);
781 default: g_assert_not_reached ();
784 g_print (" %p ", GDK_WINDOW_HWND (event->any.window));
786 switch (event->any.type)
790 _gdk_win32_gdkrectangle_to_string (&event->expose.area),
791 event->expose.count);
793 case GDK_MOTION_NOTIFY:
794 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s",
795 event->motion.x, event->motion.y,
796 event->motion.x_root, event->motion.y_root,
797 event->motion.is_hint ? "HINT " : "");
798 print_event_state (event->motion.state);
800 case GDK_BUTTON_PRESS:
801 case GDK_2BUTTON_PRESS:
802 case GDK_3BUTTON_PRESS:
803 case GDK_BUTTON_RELEASE:
804 g_print ("%d (%.4g,%.4g) (%.4g,%.4g) ",
805 event->button.button,
806 event->button.x, event->button.y,
807 event->button.x_root, event->button.y_root);
808 print_event_state (event->button.state);
811 case GDK_KEY_RELEASE:
812 if (event->key.length == 0)
813 escaped = g_strdup ("");
815 escaped = g_strescape (event->key.string, NULL);
816 kvname = gdk_keyval_name (event->key.keyval);
817 g_print ("%#.02x group:%d %s %d:\"%s\" ",
818 event->key.hardware_keycode, event->key.group,
819 (kvname ? kvname : "??"),
823 print_event_state (event->key.state);
825 case GDK_ENTER_NOTIFY:
826 case GDK_LEAVE_NOTIFY:
827 g_print ("%p (%.4g,%.4g) (%.4g,%.4g) %s %s%s",
828 event->crossing.subwindow == NULL ? NULL : GDK_WINDOW_HWND (event->crossing.subwindow),
829 event->crossing.x, event->crossing.y,
830 event->crossing.x_root, event->crossing.y_root,
831 (event->crossing.mode == GDK_CROSSING_NORMAL ? "NORMAL" :
832 (event->crossing.mode == GDK_CROSSING_GRAB ? "GRAB" :
833 (event->crossing.mode == GDK_CROSSING_UNGRAB ? "UNGRAB" :
835 (event->crossing.detail == GDK_NOTIFY_ANCESTOR ? "ANCESTOR" :
836 (event->crossing.detail == GDK_NOTIFY_VIRTUAL ? "VIRTUAL" :
837 (event->crossing.detail == GDK_NOTIFY_INFERIOR ? "INFERIOR" :
838 (event->crossing.detail == GDK_NOTIFY_NONLINEAR ? "NONLINEAR" :
839 (event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL ? "NONLINEAR_VIRTUAL" :
840 (event->crossing.detail == GDK_NOTIFY_UNKNOWN ? "UNKNOWN" :
842 event->crossing.focus ? " FOCUS" : "");
843 print_event_state (event->crossing.state);
845 case GDK_FOCUS_CHANGE:
846 g_print ("%s", (event->focus_change.in ? "IN" : "OUT"));
848 case GDK_SELECTION_REQUEST:
849 case GDK_SELECTION_NOTIFY:
850 case GDK_SELECTION_CLEAR:
851 selection_name = gdk_atom_name (event->selection.selection);
852 target_name = gdk_atom_name (event->selection.target);
853 property_name = gdk_atom_name (event->selection.property);
854 g_print ("sel:%s tgt:%s prop:%s",
855 selection_name, target_name, property_name);
856 g_free (selection_name);
857 g_free (target_name);
858 g_free (property_name);
861 g_print ("x:%d y:%d w:%d h:%d",
862 event->configure.x, event->configure.y,
863 event->configure.width, event->configure.height);
865 case GDK_CLIENT_EVENT:
866 g_print ("%s %d %ld %ld %ld %ld %ld",
867 gdk_atom_name (event->client.message_type),
868 event->client.data_format,
869 event->client.data.l[0],
870 event->client.data.l[1],
871 event->client.data.l[2],
872 event->client.data.l[3],
873 event->client.data.l[4]);
876 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",
877 event->scroll.x, event->scroll.y,
878 event->scroll.x_root, event->scroll.y_root,
879 (event->scroll.direction == GDK_SCROLL_UP ? "UP" :
880 (event->scroll.direction == GDK_SCROLL_DOWN ? "DOWN" :
881 (event->scroll.direction == GDK_SCROLL_LEFT ? "LEFT" :
882 (event->scroll.direction == GDK_SCROLL_RIGHT ? "RIGHT" :
884 print_event_state (event->scroll.state);
886 case GDK_WINDOW_STATE:
888 _gdk_win32_window_state_to_string (event->window_state.changed_mask),
889 _gdk_win32_window_state_to_string (event->window_state.new_window_state));
892 (event->setting.action == GDK_SETTING_ACTION_NEW ? "NEW" :
893 (event->setting.action == GDK_SETTING_ACTION_CHANGED ? "CHANGED" :
894 (event->setting.action == GDK_SETTING_ACTION_DELETED ? "DELETED" :
896 (event->setting.name ? event->setting.name : "NULL"));
897 case GDK_GRAB_BROKEN:
899 (event->grab_broken.keyboard ? "KEYBOARD" : "POINTER"),
900 (event->grab_broken.implicit ? "IMPLICIT" : "EXPLICIT"),
901 (event->grab_broken.grab_window ? GDK_WINDOW_HWND (event->grab_broken.grab_window) : 0));
906 g_print ("%s", (debug_indent == 0 ? "\n" : ""));
910 decode_key_lparam (LPARAM lParam)
912 static char buf[100];
915 if (HIWORD (lParam) & KF_UP)
916 p += g_sprintf (p, "KF_UP ");
917 if (HIWORD (lParam) & KF_REPEAT)
918 p += g_sprintf (p, "KF_REPEAT ");
919 if (HIWORD (lParam) & KF_ALTDOWN)
920 p += g_sprintf (p, "KF_ALTDOWN ");
921 if (HIWORD (lParam) & KF_EXTENDED)
922 p += g_sprintf (p, "KF_EXTENDED ");
923 p += g_sprintf (p, "sc:%d rep:%d", LOBYTE (HIWORD (lParam)), LOWORD (lParam));
931 fixup_event (GdkEvent *event)
933 if (event->any.window)
934 g_object_ref (event->any.window);
935 if (((event->any.type == GDK_ENTER_NOTIFY) ||
936 (event->any.type == GDK_LEAVE_NOTIFY)) &&
937 (event->crossing.subwindow != NULL))
938 g_object_ref (event->crossing.subwindow);
939 event->any.send_event = InSendMessage ();
943 append_event (GdkEvent *event)
949 link = _gdk_event_queue_append (_gdk_display, event);
950 /* event morphing, the passed in may not be valid afterwards */
951 _gdk_windowing_got_event (_gdk_display, link, event, 0);
953 _gdk_event_queue_append (_gdk_display, event);
954 GDK_NOTE (EVENTS, print_event (event));
959 fill_key_event_string (GdkEvent *event)
964 /* Fill in event->string crudely, since various programs
969 if (event->key.keyval != GDK_VoidSymbol)
970 c = gdk_keyval_to_unicode (event->key.keyval);
977 /* Apply the control key - Taken from Xlib
979 if (event->key.state & GDK_CONTROL_MASK)
981 if ((c >= '@' && c < '\177') || c == ' ')
985 event->key.string = g_memdup ("\0\0", 2);
986 event->key.length = 1;
989 else if (c >= '3' && c <= '7')
997 len = g_unichar_to_utf8 (c, buf);
1000 event->key.string = g_locale_from_utf8 (buf, len,
1001 NULL, &bytes_written,
1003 if (event->key.string)
1004 event->key.length = bytes_written;
1006 else if (event->key.keyval == GDK_Escape)
1008 event->key.length = 1;
1009 event->key.string = g_strdup ("\033");
1011 else if (event->key.keyval == GDK_Return ||
1012 event->key.keyval == GDK_KP_Enter)
1014 event->key.length = 1;
1015 event->key.string = g_strdup ("\r");
1018 if (!event->key.string)
1020 event->key.length = 0;
1021 event->key.string = g_strdup ("");
1025 static GdkFilterReturn
1026 apply_event_filters (GdkWindow *window,
1030 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1035 event = gdk_event_new (GDK_NOTHING);
1037 event->any.window = g_object_ref (window);
1038 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1040 /* I think GdkFilterFunc semantics require the passed-in event
1041 * to already be in the queue. The filter func can generate
1042 * more events and append them after it if it likes.
1044 node = _gdk_event_queue_append (_gdk_display, event);
1049 GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
1051 tmp_list = tmp_list->next;
1052 result = filter->function (msg, event, filter->data);
1053 if (result != GDK_FILTER_CONTINUE)
1057 if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
1059 _gdk_event_queue_remove_link (_gdk_display, node);
1060 g_list_free_1 (node);
1061 gdk_event_free (event);
1063 else /* GDK_FILTER_TRANSLATE */
1065 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1066 fixup_event (event);
1067 GDK_NOTE (EVENTS, print_event (event));
1073 * On Windows, transient windows will not have their own taskbar entries.
1074 * Because of this, we must hide and restore groups of transients in both
1075 * directions. That is, all transient children must be hidden or restored
1076 * with this window, but if this window's transient owner also has a
1077 * transient owner then this window's transient owner must be hidden/restored
1078 * with this one. And etc, up the chain until we hit an ancestor that has no
1081 * It would be a good idea if applications don't chain transient windows
1082 * together. There's a limit to how much evil GTK can try to shield you
1086 show_window_recurse (GdkWindow *window, gboolean hide_window)
1088 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1089 GSList *children = impl->transient_children;
1090 GdkWindow *child = NULL;
1092 if (!impl->changing_state)
1094 impl->changing_state = TRUE;
1096 if (children != NULL)
1098 while (children != NULL)
1100 child = children->data;
1101 show_window_recurse (child, hide_window);
1103 children = g_slist_next (children);
1107 if (GDK_WINDOW_IS_MAPPED (window))
1111 if (GDK_WINDOW_OBJECT (window)->state & GDK_WINDOW_STATE_ICONIFIED)
1113 if (GDK_WINDOW_OBJECT (window)->state & GDK_WINDOW_STATE_MAXIMIZED)
1115 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
1119 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1125 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
1129 impl->changing_state = FALSE;
1134 do_show_window (GdkWindow *window, gboolean hide_window)
1136 GdkWindow *tmp_window = NULL;
1137 GdkWindowImplWin32 *tmp_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1139 if (!tmp_impl->changing_state)
1141 /* Find the top-level window in our transient chain. */
1142 while (tmp_impl->transient_owner != NULL)
1144 tmp_window = tmp_impl->transient_owner;
1145 tmp_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (tmp_window)->impl);
1148 /* If we couldn't find one, use the window provided. */
1149 if (tmp_window == NULL)
1151 tmp_window = window;
1154 /* Recursively show/hide every window in the chain. */
1155 if (tmp_window != window)
1157 show_window_recurse (tmp_window, hide_window);
1163 gdk_window_is_ancestor (GdkWindow *ancestor,
1166 if (ancestor == NULL || window == NULL)
1169 return (gdk_window_get_parent (window) == ancestor ||
1170 gdk_window_is_ancestor (ancestor, gdk_window_get_parent (window)));
1174 synthesize_enter_or_leave_event (GdkWindow *window,
1177 GdkCrossingMode mode,
1178 GdkNotifyType detail)
1184 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1186 event = gdk_event_new (type);
1187 event->crossing.window = window;
1188 event->crossing.subwindow = NULL;
1189 event->crossing.time = _gdk_win32_get_next_tick (msg->time);
1190 event->crossing.x = pt.x;
1191 event->crossing.y = pt.y;
1192 event->crossing.x_root = msg->pt.x + _gdk_offset_x;
1193 event->crossing.y_root = msg->pt.y + _gdk_offset_y;
1194 event->crossing.mode = mode;
1195 event->crossing.detail = detail;
1196 event->crossing.focus = TRUE; /* FIXME: Set correctly */
1197 event->crossing.state = 0; /* FIXME: Set correctly */
1199 append_event (event);
1201 if (type == GDK_ENTER_NOTIFY &&
1202 ((GdkWindowObject *) window)->extension_events != 0)
1203 _gdk_input_enter_event (window);
1207 synthesize_expose_events (GdkWindow *window)
1211 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
1212 GList *list = gdk_window_get_children (window);
1219 synthesize_expose_events ((GdkWindow *) list->data);
1225 if (((GdkWindowObject *) window)->input_only)
1227 else if (!(hdc = GetDC (impl->handle)))
1228 WIN32_GDI_FAILED ("GetDC");
1231 if ((k = GetClipBox (hdc, &r)) == ERROR)
1232 WIN32_GDI_FAILED ("GetClipBox");
1233 else if (k != NULLREGION)
1235 event = gdk_event_new (GDK_EXPOSE);
1236 event->expose.window = window;
1237 event->expose.area.x = r.left;
1238 event->expose.area.y = r.top;
1239 event->expose.area.width = r.right - r.left;
1240 event->expose.area.height = r.bottom - r.top;
1241 event->expose.region = gdk_region_rectangle (&(event->expose.area));
1242 event->expose.count = 0;
1244 append_event (event);
1246 GDI_CALL (ReleaseDC, (impl->handle, hdc));
1251 update_colors (GdkWindow *window,
1255 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
1256 GList *list = gdk_window_get_children (window);
1259 GDK_NOTE (COLORMAP, (top ? g_print ("update_colors:") : (void) 0));
1263 update_colors ((GdkWindow *) list->data, FALSE);
1268 if (((GdkWindowObject *) window)->input_only ||
1269 impl->colormap == NULL)
1272 if (!(hdc = GetDC (impl->handle)))
1273 WIN32_GDI_FAILED ("GetDC");
1276 GdkColormapPrivateWin32 *cmapp = GDK_WIN32_COLORMAP_DATA (impl->colormap);
1280 if ((holdpal = SelectPalette (hdc, cmapp->hpal, TRUE)) == NULL)
1281 WIN32_GDI_FAILED ("SelectPalette");
1282 else if ((k = RealizePalette (hdc)) == GDI_ERROR)
1283 WIN32_GDI_FAILED ("RealizePalette");
1288 g_print (" %p pal=%p: realized %d colors\n"
1290 impl->handle, cmapp->hpal, k) :
1292 g_print (" %p", impl->handle)));
1293 GDI_CALL (UpdateColors, (hdc));
1294 SelectPalette (hdc, holdpal, TRUE);
1295 RealizePalette (hdc);
1297 GDI_CALL (ReleaseDC, (impl->handle, hdc));
1299 GDK_NOTE (COLORMAP, (top ? g_print ("\n") : (void) 0));
1303 translate_mouse_coords (GdkWindow *window1,
1309 pt.x = GET_X_LPARAM (msg->lParam);
1310 pt.y = GET_Y_LPARAM (msg->lParam);
1311 ClientToScreen (GDK_WINDOW_HWND (window1), &pt);
1312 ScreenToClient (GDK_WINDOW_HWND (window2), &pt);
1313 msg->lParam = MAKELPARAM (pt.x, pt.y);
1316 /* The check_extended flag controls whether to check if the windows want
1317 * events from extended input devices and if the message should be skipped
1318 * because an extended input device is active
1321 propagate (GdkWindow **window,
1323 GdkWindow *grab_window,
1324 gboolean grab_owner_events,
1326 gboolean (*doesnt_want_it) (gint mask,
1328 gboolean check_extended)
1330 if (grab_window != NULL && !grab_owner_events)
1332 /* Event source is grabbed with owner_events FALSE */
1334 /* See if the event should be ignored because an extended input
1337 if (check_extended &&
1338 ((GdkWindowObject *) grab_window)->extension_events != 0 &&
1339 _gdk_input_ignore_core)
1341 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1344 if ((*doesnt_want_it) (grab_mask, msg))
1346 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1351 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1352 assign_object (window, grab_window);
1357 /* If we come here, we know that if grab_window != NULL then
1358 * grab_owner_events is TRUE
1362 if (check_extended &&
1363 ((GdkWindowObject *) *window)->extension_events != 0 &&
1364 _gdk_input_ignore_core)
1366 GDK_NOTE (EVENTS, g_print (" (ignored)"));
1369 if ((*doesnt_want_it) (((GdkWindowObject *) *window)->event_mask, msg))
1371 /* Owner doesn't want it, propagate to parent. */
1372 GdkWindow *parent = gdk_window_get_parent (*window);
1373 if (parent == _gdk_root || parent == NULL)
1375 /* No parent; check if grabbed */
1376 if (grab_window != NULL)
1378 /* Event source is grabbed with owner_events TRUE */
1380 if (check_extended &&
1381 ((GdkWindowObject *) grab_window)->extension_events != 0 &&
1382 _gdk_input_ignore_core)
1384 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1387 if ((*doesnt_want_it) (grab_mask, msg))
1389 /* Grabber doesn't want it either */
1390 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1396 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1397 assign_object (window, grab_window);
1403 GDK_NOTE (EVENTS, g_print (" (undelivered)"));
1409 assign_object (window, parent);
1410 /* The only branch where we actually continue the loop */
1419 doesnt_want_key (gint mask,
1422 return (((msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) &&
1423 !(mask & GDK_KEY_RELEASE_MASK)) ||
1424 ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) &&
1425 !(mask & GDK_KEY_PRESS_MASK)));
1429 doesnt_want_char (gint mask,
1432 return !(mask & (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK));
1436 doesnt_want_button_press (gint mask,
1439 return !(mask & GDK_BUTTON_PRESS_MASK);
1443 doesnt_want_button_release (gint mask,
1446 return !(mask & GDK_BUTTON_RELEASE_MASK);
1450 doesnt_want_button_motion (gint mask,
1453 return !((mask & GDK_POINTER_MOTION_MASK) ||
1454 ((msg->wParam & (MK_LBUTTON|MK_MBUTTON|MK_RBUTTON)) && (mask & GDK_BUTTON_MOTION_MASK)) ||
1455 ((msg->wParam & MK_LBUTTON) && (mask & GDK_BUTTON1_MOTION_MASK)) ||
1456 ((msg->wParam & MK_MBUTTON) && (mask & GDK_BUTTON2_MOTION_MASK)) ||
1457 ((msg->wParam & MK_RBUTTON) && (mask & GDK_BUTTON3_MOTION_MASK)));
1461 doesnt_want_scroll (gint mask,
1464 /* As there are no separate scroll events in X11, button press
1465 * events are used, so higher level code might be selecting for
1466 * either GDK_BUTTON_PRESS_MASK or GDK_SCROLL_MASK when it wants GDK
1467 * scroll events. Make sure this works in the Win32 backend, too.
1469 return !(mask & (GDK_SCROLL_MASK|GDK_BUTTON_PRESS_MASK));
1473 handle_configure_event (MSG *msg,
1478 GdkWindowObject *window_object;
1480 GetClientRect (msg->hwnd, &client_rect);
1481 point.x = client_rect.left; /* always 0 */
1482 point.y = client_rect.top;
1484 /* top level windows need screen coords */
1485 if (gdk_window_get_parent (window) == _gdk_root)
1487 ClientToScreen (msg->hwnd, &point);
1488 point.x += _gdk_offset_x;
1489 point.y += _gdk_offset_y;
1492 window_object = GDK_WINDOW_OBJECT (window);
1494 window_object->width = client_rect.right - client_rect.left;
1495 window_object->height = client_rect.bottom - client_rect.top;
1497 window_object->x = point.x;
1498 window_object->y = point.y;
1500 _gdk_window_update_size (window);
1502 if (window_object->event_mask & GDK_STRUCTURE_MASK)
1504 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1506 event->configure.window = window;
1508 event->configure.width = client_rect.right - client_rect.left;
1509 event->configure.height = client_rect.bottom - client_rect.top;
1511 event->configure.x = point.x;
1512 event->configure.y = point.y;
1514 append_event (event);
1519 _gdk_win32_hrgn_to_region (HRGN hrgn)
1527 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1529 WIN32_GDI_FAILED ("GetRegionData");
1533 rgndata = (RGNDATA *) g_malloc (nbytes);
1535 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1537 WIN32_GDI_FAILED ("GetRegionData");
1542 result = gdk_region_new ();
1543 rects = (RECT *) rgndata->Buffer;
1544 for (i = 0; i < rgndata->rdh.nCount; i++)
1548 r.x = rects[i].left;
1550 r.width = rects[i].right - r.x;
1551 r.height = rects[i].bottom - r.y;
1553 gdk_region_union_with_rect (result, &r);
1562 adjust_drag (LONG *drag,
1567 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1569 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1573 handle_wm_paint (MSG *msg,
1575 gboolean return_exposes,
1578 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1580 PAINTSTRUCT paintstruct;
1581 GdkRegion *update_region;
1583 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1585 WIN32_GDI_FAILED ("GetUpdateRgn");
1586 DeleteObject (hrgn);
1590 hdc = BeginPaint (msg->hwnd, &paintstruct);
1592 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1593 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1594 (paintstruct.fErase ? "erase" : ""),
1596 (return_exposes ? " return_exposes" : "")));
1598 EndPaint (msg->hwnd, &paintstruct);
1600 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1601 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1603 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1604 DeleteObject (hrgn);
1610 if (!GDK_WINDOW_DESTROYED (window))
1612 GList *list = _gdk_display->queued_events;
1614 *event = gdk_event_new (GDK_EXPOSE);
1615 (*event)->expose.window = window;
1616 (*event)->expose.area.x = paintstruct.rcPaint.left;
1617 (*event)->expose.area.y = paintstruct.rcPaint.top;
1618 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
1619 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
1620 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
1621 (*event)->expose.count = 0;
1623 while (list != NULL)
1625 GdkEventPrivate *evp = list->data;
1627 if (evp->event.any.type == GDK_EXPOSE &&
1628 evp->event.any.window == window &&
1629 !(evp->flags & GDK_EVENT_PENDING))
1630 evp->event.expose.count++;
1636 DeleteObject (hrgn);
1640 update_region = _gdk_win32_hrgn_to_region (hrgn);
1641 if (!gdk_region_empty (update_region))
1642 _gdk_window_invalidate_for_expose (window, update_region);
1643 gdk_region_destroy (update_region);
1645 DeleteObject (hrgn);
1649 handle_stuff_while_moving_or_resizing (void)
1651 int arbitrary_limit = 1;
1652 while (g_main_context_pending (NULL) && arbitrary_limit--)
1653 g_main_context_iteration (NULL, FALSE);
1656 static VOID CALLBACK
1657 modal_timer_proc (HWND hwnd,
1662 if (_sizemove_in_progress)
1663 handle_stuff_while_moving_or_resizing ();
1666 static VOID CALLBACK
1667 sync_timer_proc (HWND hwnd,
1673 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
1678 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
1680 KillTimer (hwnd, sync_timer);
1684 handle_display_change (void)
1686 _gdk_monitor_init ();
1687 _gdk_root_window_size_init ();
1688 g_signal_emit_by_name (_gdk_screen, "size_changed");
1692 generate_button_event (GdkEventType type,
1697 GdkEvent *event = gdk_event_new (type);
1699 event->button.window = window;
1700 event->button.time = _gdk_win32_get_next_tick (msg->time);
1701 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
1702 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
1703 event->button.x_root = msg->pt.x + _gdk_offset_x;
1704 event->button.y_root = msg->pt.y + _gdk_offset_y;
1705 event->button.axes = NULL;
1706 event->button.state = build_pointer_event_state (msg);
1707 event->button.button = button;
1708 event->button.device = _gdk_display->core_pointer;
1710 append_event (event);
1714 ensure_stacking_on_unminimize (MSG *msg)
1717 HWND lowest_transient = NULL;
1720 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
1722 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1724 /* Checking window group not implemented yet */
1727 GdkWindowImplWin32 *rover_impl =
1728 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
1730 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1731 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1732 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1733 rover_impl->transient_owner != NULL))
1735 lowest_transient = rover;
1739 if (lowest_transient != NULL)
1741 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
1742 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
1743 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1748 ensure_stacking_on_window_pos_changing (MSG *msg,
1751 GdkWindowImplWin32 *impl = (GdkWindowImplWin32 *)((GdkWindowObject *) window)->impl;
1752 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
1754 if (GetActiveWindow () == msg->hwnd &&
1755 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
1756 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
1757 impl->transient_owner == NULL)
1759 /* Make sure the window stays behind any transient-type windows
1760 * of the same window group.
1762 * If the window is not active and being activated, we let
1763 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
1764 * handling to bring any utility windows on top of it.
1767 gboolean restacking;
1769 rover = windowpos->hwndInsertAfter;
1773 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1775 /* Checking window group not implemented yet */
1778 GdkWindowImplWin32 *rover_impl =
1779 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
1781 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1782 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1783 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1784 rover_impl->transient_owner != NULL))
1787 windowpos->hwndInsertAfter = rover;
1790 rover = GetNextWindow (rover, GW_HWNDNEXT);
1795 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
1803 ensure_stacking_on_activate_app (MSG *msg,
1806 GdkWindowImplWin32 *impl = (GdkWindowImplWin32 *)((GdkWindowObject *) window)->impl;
1808 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1809 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1810 impl->transient_owner != NULL)
1812 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
1813 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1817 if (IsWindowVisible (msg->hwnd) &&
1818 msg->hwnd == GetActiveWindow ())
1820 /* This window is not a transient-type window and it is the
1821 * activated window. Make sure this window is as visible as
1822 * possible, just below the lowest transient-type window of this
1828 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
1830 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
1832 /* Checking window group not implemented yet */
1835 GdkWindowImplWin32 *rover_impl =
1836 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
1838 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
1839 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
1840 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
1841 rover_impl->transient_owner != NULL))
1843 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
1844 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
1845 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1854 gdk_event_translate (MSG *msg,
1857 RECT rect, *drag, orig_drag;
1862 BYTE key_state[256];
1864 WINDOWPOS *windowpos;
1871 GdkWindow *window = NULL;
1872 GdkWindowImplWin32 *impl;
1874 GdkWindow *orig_window, *new_window, *toplevel;
1876 GdkPointerGrabInfo *grab = NULL;
1877 GdkWindow *grab_window = NULL;
1878 guint grab_mask = 0;
1879 gboolean grab_owner_events = FALSE;
1881 static gint update_colors_counter = 0;
1886 gboolean return_val = FALSE;
1890 if (_gdk_default_filters)
1892 /* Apply global filters */
1894 GdkFilterReturn result = apply_event_filters (NULL, msg, _gdk_default_filters);
1896 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
1897 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
1898 * we return TRUE, and DefWindowProcW() will not be called.
1900 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1904 window = gdk_win32_handle_table_lookup ((GdkNativeWindow) msg->hwnd);
1905 orig_window = window;
1909 /* XXX Handle WM_QUIT here ? */
1910 if (msg->message == WM_QUIT)
1912 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
1915 else if (msg->message == WM_MOVE ||
1916 msg->message == WM_SIZE)
1918 /* It's quite normal to get these messages before we have
1919 * had time to register the window in our lookup table, or
1920 * when the window is being destroyed and we already have
1921 * removed it. Repost the same message to our queue so that
1922 * we will get it later when we are prepared.
1924 GDK_NOTE (EVENTS, g_print (" (posted)"));
1926 PostMessageW (msg->hwnd, msg->message, msg->wParam, msg->lParam);
1928 else if (msg->message == WM_CREATE)
1930 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
1931 GDK_WINDOW_HWND (window) = msg->hwnd;
1935 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
1940 g_object_ref (window);
1942 /* window's refcount has now been increased, so code below should
1943 * not just return from this function, but instead goto done (or
1944 * break out of the big switch). To protect against forgetting this,
1945 * #define return to a syntax error...
1947 #define return GOTO_DONE_INSTEAD
1949 if (!GDK_WINDOW_DESTROYED (window) && ((GdkWindowObject *) window)->filters)
1951 /* Apply per-window filters */
1953 GdkFilterReturn result = apply_event_filters (window, msg, ((GdkWindowObject *) window)->filters);
1955 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
1962 if (msg->message == client_message)
1965 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1968 GDK_NOTE (EVENTS, g_print (" client_message"));
1970 event = gdk_event_new (GDK_NOTHING);
1971 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1973 node = _gdk_event_queue_append (_gdk_display, event);
1975 tmp_list = client_filters;
1978 GdkClientFilter *filter = tmp_list->data;
1980 tmp_list = tmp_list->next;
1982 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
1984 GDK_NOTE (EVENTS, g_print (" (match)"));
1986 result = (*filter->function) (msg, event, filter->data);
1988 if (result != GDK_FILTER_CONTINUE)
1995 case GDK_FILTER_REMOVE:
1996 _gdk_event_queue_remove_link (_gdk_display, node);
1997 g_list_free_1 (node);
1998 gdk_event_free (event);
2002 case GDK_FILTER_TRANSLATE:
2003 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2004 GDK_NOTE (EVENTS, print_event (event));
2008 case GDK_FILTER_CONTINUE:
2009 /* Send unknown client messages on to Gtk for it to use */
2011 event->client.type = GDK_CLIENT_EVENT;
2012 event->client.window = window;
2013 event->client.message_type = GDK_POINTER_TO_ATOM (msg->wParam);
2014 event->client.data_format = 32;
2015 event->client.data.l[0] = msg->lParam;
2016 for (i = 1; i < 5; i++)
2017 event->client.data.l[i] = 0;
2018 GDK_NOTE (EVENTS, print_event (event));
2024 switch (msg->message)
2026 case WM_INPUTLANGCHANGE:
2027 _gdk_input_locale = (HKL) msg->lParam;
2028 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
2029 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
2030 LOCALE_IDEFAULTANSICODEPAGE,
2032 _gdk_input_codepage = atoi (buf);
2033 _gdk_keymap_serial++;
2035 g_print (" cs:%lu hkl:%p%s cp:%d",
2036 (gulong) msg->wParam,
2037 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
2038 _gdk_input_codepage));
2044 g_print (" %s ch:%.02x %s",
2045 _gdk_win32_key_to_string (msg->lParam),
2047 decode_key_lparam (msg->lParam)));
2049 /* If posted without us having keyboard focus, ignore */
2050 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
2051 !(HIWORD (msg->lParam) & KF_ALTDOWN))
2054 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
2055 * the keyboard is grabbed.
2057 if (_gdk_display->keyboard_grab.window == NULL &&
2058 (msg->wParam == VK_TAB ||
2059 msg->wParam == VK_SPACE ||
2060 msg->wParam == VK_F4))
2063 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
2069 g_print (" %s ch:%.02x %s",
2070 _gdk_win32_key_to_string (msg->lParam),
2072 decode_key_lparam (msg->lParam)));
2076 /* Ignore key messages intended for the IME */
2077 if (msg->wParam == VK_PROCESSKEY ||
2081 if (!propagate (&window, msg,
2082 _gdk_display->keyboard_grab.window,
2083 _gdk_display->keyboard_grab.owner_events,
2084 GDK_ALL_EVENTS_MASK,
2085 doesnt_want_key, FALSE))
2088 if (GDK_WINDOW_DESTROYED (window))
2091 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
2092 msg->message == WM_SYSKEYDOWN) ?
2093 GDK_KEY_PRESS : GDK_KEY_RELEASE);
2094 event->key.window = window;
2095 event->key.time = _gdk_win32_get_next_tick (msg->time);
2096 event->key.keyval = GDK_VoidSymbol;
2097 event->key.string = NULL;
2098 event->key.length = 0;
2099 event->key.hardware_keycode = msg->wParam;
2100 if (HIWORD (msg->lParam) & KF_EXTENDED)
2102 switch (msg->wParam)
2105 event->key.hardware_keycode = VK_RCONTROL;
2107 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
2108 * for the right shift key.
2110 event->key.hardware_keycode = VK_RSHIFT;
2113 event->key.hardware_keycode = VK_RMENU;
2117 else if (msg->wParam == VK_SHIFT &&
2118 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
2119 event->key.hardware_keycode = VK_RSHIFT;
2121 API_CALL (GetKeyboardState, (key_state));
2123 /* 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]); */
2125 build_key_event_state (event, key_state);
2127 gdk_keymap_translate_keyboard_state (NULL,
2128 event->key.hardware_keycode,
2134 fill_key_event_string (event);
2136 /* Reset MOD1_MASK if it is the Alt key itself */
2137 if (msg->wParam == VK_MENU)
2138 event->key.state &= ~GDK_MOD1_MASK;
2140 append_event (event);
2146 if (msg->wParam != VK_SPACE)
2148 /* To prevent beeps, don't let DefWindowProcW() be called */
2154 case WM_IME_STARTCOMPOSITION:
2155 in_ime_composition = TRUE;
2158 case WM_IME_ENDCOMPOSITION:
2159 in_ime_composition = FALSE;
2162 case WM_IME_COMPOSITION:
2163 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2164 * applications. Thus, handle WM_IME_COMPOSITION with
2165 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2166 * with ImmGetCompositionStringW().
2169 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2171 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2172 * for comments by other people that seems to have the same
2173 * experience. WM_IME_CHAR just gives question marks, apparently
2174 * because of going through some conversion to the current code
2177 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2178 * use WM_IME_COMPOSITION there, too, to simplify the code.
2180 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2182 if (!(msg->lParam & GCS_RESULTSTR))
2185 if (!propagate (&window, msg,
2186 _gdk_display->keyboard_grab.window,
2187 _gdk_display->keyboard_grab.owner_events,
2188 GDK_ALL_EVENTS_MASK,
2189 doesnt_want_char, FALSE))
2192 if (GDK_WINDOW_DESTROYED (window))
2195 himc = ImmGetContext (msg->hwnd);
2196 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2197 wbuf, sizeof (wbuf));
2198 ImmReleaseContext (msg->hwnd, himc);
2202 API_CALL (GetKeyboardState, (key_state));
2204 for (i = 0; i < ccount; i++)
2206 if (((GdkWindowObject *) window)->event_mask & GDK_KEY_PRESS_MASK)
2208 /* Build a key press event */
2209 event = gdk_event_new (GDK_KEY_PRESS);
2210 event->key.window = window;
2211 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2213 append_event (event);
2216 if (((GdkWindowObject *) window)->event_mask & GDK_KEY_RELEASE_MASK)
2218 /* Build a key release event. */
2219 event = gdk_event_new (GDK_KEY_RELEASE);
2220 event->key.window = window;
2221 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2223 append_event (event);
2229 case WM_LBUTTONDOWN:
2233 case WM_MBUTTONDOWN:
2237 case WM_RBUTTONDOWN:
2241 case WM_XBUTTONDOWN:
2242 if (HIWORD (msg->wParam) == XBUTTON1)
2249 g_print (" (%d,%d)",
2250 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2252 assign_object (&window, find_window_for_mouse_event (window, msg));
2253 /* TODO_CSW?: there used to some synthesize and propagate */
2254 if (GDK_WINDOW_DESTROYED (window))
2257 /* TODO_CSW? Emulate X11's automatic active grab */
2258 generate_button_event (GDK_BUTTON_PRESS, button,
2277 if (HIWORD (msg->wParam) == XBUTTON1)
2284 g_print (" (%d,%d)",
2285 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2287 assign_object (&window, find_window_for_mouse_event (window, msg));
2289 if (((GdkWindowObject *) window)->extension_events != 0 &&
2290 _gdk_input_ignore_core)
2292 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2297 generate_button_event (GDK_BUTTON_RELEASE, button,
2305 g_print (" %p (%d,%d)",
2306 (gpointer) msg->wParam,
2307 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2309 assign_object (&window, find_window_for_mouse_event (window, msg));
2310 toplevel = gdk_window_get_toplevel (window);
2311 if (current_toplevel != toplevel)
2313 GDK_NOTE (EVENTS, g_print (" toplevel %p -> %p",
2314 current_toplevel ? GDK_WINDOW_HWND (current_toplevel) : NULL,
2315 toplevel ? GDK_WINDOW_HWND (toplevel) : NULL));
2316 if (current_toplevel)
2317 synthesize_enter_or_leave_event (current_toplevel, msg,
2318 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2319 synthesize_enter_or_leave_event (toplevel, msg,
2320 GDK_ENTER_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2321 assign_object (¤t_toplevel, toplevel);
2322 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (toplevel));
2325 /* If we haven't moved, don't create any GDK event. Windows
2326 * sends WM_MOUSEMOVE messages after a new window is shows under
2327 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2329 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2330 msg->pt.y + _gdk_offset_y == current_root_y)
2333 current_root_x = msg->pt.x + _gdk_offset_x;
2334 current_root_y = msg->pt.y + _gdk_offset_y;
2336 event = gdk_event_new (GDK_MOTION_NOTIFY);
2337 event->motion.window = window;
2338 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2339 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2340 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2341 event->motion.x_root = current_root_x;
2342 event->motion.y_root = current_root_y;
2343 event->motion.axes = NULL;
2344 event->motion.state = build_pointer_event_state (msg);
2345 event->motion.is_hint = FALSE;
2346 event->motion.device = _gdk_display->core_pointer;
2348 append_event (event);
2353 case WM_NCMOUSEMOVE:
2355 g_print (" (%d,%d)",
2356 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2357 #if 0 /* TODO_CSW? */
2358 if (current_toplevel != NULL &&
2359 (((GdkWindowObject *) current_toplevel)->event_mask & GDK_LEAVE_NOTIFY_MASK))
2361 synthesize_enter_or_leave_event (current_toplevel, msg,
2362 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2368 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2369 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2371 if (!gdk_win32_handle_table_lookup ((GdkNativeWindow) WindowFromPoint (msg->pt)))
2373 /* we are only interested if we don't know the new window */
2374 if (current_toplevel)
2375 synthesize_enter_or_leave_event (current_toplevel, msg,
2376 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2377 assign_object (¤t_toplevel, NULL);
2381 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2388 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2390 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2391 * that. Also, the position is in screen coordinates, not client
2392 * coordinates as with the button messages. I love the
2393 * consistency of Windows.
2395 point.x = GET_X_LPARAM (msg->lParam);
2396 point.y = GET_Y_LPARAM (msg->lParam);
2398 if ((hwnd = WindowFromPoint (point)) == NULL)
2402 if ((new_window = gdk_win32_handle_table_lookup ((GdkNativeWindow) msg->hwnd)) == NULL)
2405 if (new_window != window)
2407 assign_object (&window, new_window);
2410 ScreenToClient (msg->hwnd, &point);
2412 event = gdk_event_new (GDK_SCROLL);
2413 event->scroll.window = window;
2414 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2415 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2416 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2417 event->scroll.x = (gint16) point.x;
2418 event->scroll.y = (gint16) point.y;
2419 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2420 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2421 event->scroll.state = build_pointer_event_state (msg);
2422 event->scroll.device = _gdk_display->core_pointer;
2424 append_event (event);
2430 /* Just print more debugging information, don't actually handle it. */
2433 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2434 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2435 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2436 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2437 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2438 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2439 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
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));
2449 /* Just print more debugging information, don't actually handle it. */
2452 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2453 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2454 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2455 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2456 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2457 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2458 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2459 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2460 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2462 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2463 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2464 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2467 case WM_QUERYNEWPALETTE:
2468 if (gdk_visual_get_system ()->type == GDK_VISUAL_PSEUDO_COLOR)
2470 synthesize_expose_events (window);
2471 update_colors_counter = 0;
2476 case WM_PALETTECHANGED:
2477 GDK_NOTE (EVENTS_OR_COLORMAP, g_print (" %p", (HWND) msg->wParam));
2478 if (gdk_visual_get_system ()->type != GDK_VISUAL_PSEUDO_COLOR)
2483 if (msg->hwnd == (HWND) msg->wParam)
2486 if (++update_colors_counter == 5)
2488 synthesize_expose_events (window);
2489 update_colors_counter = 0;
2493 update_colors (window, TRUE);
2496 case WM_MOUSEACTIVATE:
2500 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2501 || !((GdkWindowObject *)window)->accept_focus)
2503 *ret_valp = MA_NOACTIVATE;
2507 tmp = _gdk_modal_current ();
2511 if (gdk_window_get_toplevel (window) != tmp)
2513 *ret_valp = MA_NOACTIVATEANDEAT;
2522 if (_gdk_display->keyboard_grab.window != NULL &&
2523 !GDK_WINDOW_DESTROYED (_gdk_display->keyboard_grab.window))
2525 generate_grab_broken_event (_gdk_display->keyboard_grab.window, FALSE, NULL);
2530 if (_gdk_display->keyboard_grab.window != NULL &&
2531 !_gdk_display->keyboard_grab.owner_events)
2534 if (!(((GdkWindowObject *) window)->event_mask & GDK_FOCUS_CHANGE_MASK))
2537 if (GDK_WINDOW_DESTROYED (window))
2540 generate_focus_event (window, (msg->message == WM_SETFOCUS));
2545 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
2547 if (GDK_WINDOW_DESTROYED (window))
2555 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
2557 200, sync_timer_proc);
2561 handle_wm_paint (msg, window, FALSE, NULL);
2565 GDK_NOTE (EVENTS, g_print (" %#x %#x",
2566 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2568 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
2571 grab_window = grab->window;
2574 if (grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
2577 if (grab_window != NULL && p_grab_cursor != NULL)
2578 hcursor = p_grab_cursor;
2579 else if (!GDK_WINDOW_DESTROYED (window))
2580 hcursor = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl)->hcursor;
2584 if (hcursor != NULL)
2586 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
2587 SetCursor (hcursor);
2594 GDK_NOTE (EVENTS, g_print (" %s %s",
2595 (msg->wParam ? "YES" : "NO"),
2596 (msg->lParam == 0 ? "ShowWindow" :
2597 (msg->lParam == SW_OTHERUNZOOM ? "OTHERUNZOOM" :
2598 (msg->lParam == SW_OTHERZOOM ? "OTHERZOOM" :
2599 (msg->lParam == SW_PARENTCLOSING ? "PARENTCLOSING" :
2600 (msg->lParam == SW_PARENTOPENING ? "PARENTOPENING" :
2603 if (!(((GdkWindowObject *) window)->event_mask & GDK_STRUCTURE_MASK))
2606 if (msg->lParam == SW_OTHERUNZOOM ||
2607 msg->lParam == SW_OTHERZOOM)
2610 if (GDK_WINDOW_DESTROYED (window))
2613 event = gdk_event_new (msg->wParam ? GDK_MAP : GDK_UNMAP);
2614 event->any.window = window;
2616 append_event (event);
2618 if (event->any.type == GDK_UNMAP)
2620 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
2622 if (impl->transient_owner && GetForegroundWindow () == GDK_WINDOW_HWND (window))
2624 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
2627 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
2630 if (grab->window == window)
2631 gdk_pointer_ungrab (msg->time);
2634 if (_gdk_display->keyboard_grab.window == window)
2635 gdk_keyboard_ungrab (msg->time);
2642 switch (msg->wParam)
2646 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
2654 g_print (" %s %dx%d",
2655 (msg->wParam == SIZE_MAXHIDE ? "MAXHIDE" :
2656 (msg->wParam == SIZE_MAXIMIZED ? "MAXIMIZED" :
2657 (msg->wParam == SIZE_MAXSHOW ? "MAXSHOW" :
2658 (msg->wParam == SIZE_MINIMIZED ? "MINIMIZED" :
2659 (msg->wParam == SIZE_RESTORED ? "RESTORED" : "?"))))),
2660 LOWORD (msg->lParam), HIWORD (msg->lParam)));
2662 if (msg->wParam == SIZE_MINIMIZED)
2664 /* Don't generate any GDK event. This is *not* an UNMAP. */
2665 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
2668 if (grab->window == window)
2669 gdk_pointer_ungrab (msg->time);
2671 if (_gdk_display->keyboard_grab.window == window)
2672 gdk_keyboard_ungrab (msg->time);
2674 gdk_synthesize_window_state (window,
2675 GDK_WINDOW_STATE_WITHDRAWN,
2676 GDK_WINDOW_STATE_ICONIFIED);
2677 do_show_window (window, TRUE);
2679 else if ((msg->wParam == SIZE_RESTORED ||
2680 msg->wParam == SIZE_MAXIMIZED) &&
2681 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
2683 GdkWindowState withdrawn_bit =
2684 IsWindowVisible (msg->hwnd) ? GDK_WINDOW_STATE_WITHDRAWN : 0;
2686 if (((GdkWindowObject *) window)->state & GDK_WINDOW_STATE_ICONIFIED)
2687 ensure_stacking_on_unminimize (msg);
2689 if (!GDK_WINDOW_DESTROYED (window))
2690 handle_configure_event (msg, window);
2692 if (msg->wParam == SIZE_RESTORED)
2694 gdk_synthesize_window_state (window,
2695 GDK_WINDOW_STATE_ICONIFIED |
2696 GDK_WINDOW_STATE_MAXIMIZED |
2700 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_TEMP && !GDK_WINDOW_IS_MAPPED (window))
2702 do_show_window (window, FALSE);
2705 else if (msg->wParam == SIZE_MAXIMIZED)
2707 gdk_synthesize_window_state (window,
2708 GDK_WINDOW_STATE_ICONIFIED |
2710 GDK_WINDOW_STATE_MAXIMIZED);
2713 if (((GdkWindowObject *) window)->resize_count > 1)
2714 ((GdkWindowObject *) window)->resize_count -= 1;
2716 if (((GdkWindowObject *) window)->extension_events != 0)
2717 _gdk_input_configure_event (window);
2723 case WM_ENTERSIZEMOVE:
2724 _sizemove_in_progress = TRUE;
2725 modal_timer = SetTimer (NULL, 0, 20, modal_timer_proc);
2728 case WM_EXITSIZEMOVE:
2729 _sizemove_in_progress = FALSE;
2730 KillTimer (NULL, modal_timer);
2733 case WM_ENTERMENULOOP:
2734 _sizemove_in_progress = TRUE;
2735 modal_timer = SetTimer (NULL, 0, 20, modal_timer_proc);
2738 case WM_EXITMENULOOP:
2739 _sizemove_in_progress = FALSE;
2740 KillTimer (NULL, modal_timer);
2743 case WM_WINDOWPOSCHANGING:
2744 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
2745 g_print (" %s %s %dx%d@%+d%+d now below %p",
2746 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2747 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2748 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2749 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2750 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2751 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2753 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
2754 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
2756 if (GDK_WINDOW_IS_MAPPED (window))
2757 return_val = ensure_stacking_on_window_pos_changing (msg, window);
2760 case WM_WINDOWPOSCHANGED:
2761 windowpos = (WINDOWPOS *) msg->lParam;
2762 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
2763 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
2764 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
2765 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
2766 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
2767 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
2768 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
2770 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
2772 /* If position and size haven't changed, don't do anything */
2773 if (_sizemove_in_progress &&
2774 (windowpos->flags & SWP_NOMOVE) &&
2775 (windowpos->flags & SWP_NOSIZE))
2778 /* Once we've entered the moving or sizing modal loop, we won't
2779 * return to the main loop until we're done sizing or moving.
2781 if (_sizemove_in_progress &&
2782 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
2783 !GDK_WINDOW_DESTROYED (window))
2785 if (((GdkWindowObject *) window)->event_mask & GDK_STRUCTURE_MASK)
2787 GDK_NOTE (EVENTS, g_print (" do magic"));
2788 if (((GdkWindowObject *) window)->resize_count > 1)
2789 ((GdkWindowObject *) window)->resize_count -= 1;
2791 handle_configure_event (msg, window);
2792 g_main_context_iteration (NULL, FALSE);
2794 /* Dispatch main loop - to realize resizes... */
2795 handle_stuff_while_moving_or_resizing ();
2797 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
2805 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
2806 drag = (RECT *) msg->lParam;
2807 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
2808 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
2809 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
2810 (msg->wParam == WMSZ_LEFT ? "LEFT" :
2811 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
2812 (msg->wParam == WMSZ_TOP ? "TOP" :
2813 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
2814 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
2816 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
2818 _gdk_win32_rect_to_string (&rect),
2819 _gdk_win32_rect_to_string (drag)));
2821 impl = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
2823 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
2825 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
2826 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
2828 /* Resize in increments relative to the base size */
2829 rect.left = rect.top = 0;
2830 rect.right = impl->hints.base_width;
2831 rect.bottom = impl->hints.base_height;
2832 _gdk_win32_adjust_client_rect (window, &rect);
2833 point.x = rect.left;
2835 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2836 rect.left = point.x;
2838 point.x = rect.right;
2839 point.y = rect.bottom;
2840 ClientToScreen (GDK_WINDOW_HWND (window), &point);
2841 rect.right = point.x;
2842 rect.bottom = point.y;
2844 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
2845 _gdk_win32_rect_to_string (&rect)));
2848 switch (msg->wParam)
2851 if (drag->bottom == rect.bottom)
2853 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2856 case WMSZ_BOTTOMLEFT:
2857 if (drag->bottom == rect.bottom && drag->left == rect.left)
2859 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2860 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2864 if (drag->left == rect.left)
2866 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2870 if (drag->top == rect.top && drag->left == rect.left)
2872 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2873 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
2877 if (drag->top == rect.top)
2879 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2883 if (drag->top == rect.top && drag->right == rect.right)
2885 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
2886 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2890 if (drag->right == rect.right)
2892 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2895 case WMSZ_BOTTOMRIGHT:
2896 if (drag->bottom == rect.bottom && drag->right == rect.right)
2898 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
2899 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
2903 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
2904 drag->top != orig_drag.top || drag->right != orig_drag.right)
2908 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
2909 _gdk_win32_rect_to_string (drag)));
2913 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
2915 if (impl->hint_flags & GDK_HINT_ASPECT)
2917 RECT decorated_rect;
2918 RECT undecorated_drag;
2919 int decoration_width, decoration_height;
2920 gdouble drag_aspect;
2921 int drag_width, drag_height, new_width, new_height;
2923 GetClientRect (GDK_WINDOW_HWND (window), &rect);
2924 decorated_rect = rect;
2925 _gdk_win32_adjust_client_rect (window, &decorated_rect);
2927 /* Set undecorated_drag to the client area being dragged
2928 * out, in screen coordinates.
2930 undecorated_drag = *drag;
2931 undecorated_drag.left -= decorated_rect.left - rect.left;
2932 undecorated_drag.right -= decorated_rect.right - rect.right;
2933 undecorated_drag.top -= decorated_rect.top - rect.top;
2934 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
2936 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
2937 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
2939 drag_width = undecorated_drag.right - undecorated_drag.left;
2940 drag_height = undecorated_drag.bottom - undecorated_drag.top;
2942 drag_aspect = (gdouble) drag_width / drag_height;
2944 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
2945 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
2947 if (drag_aspect < impl->hints.min_aspect)
2949 /* Aspect is getting too narrow */
2950 switch (msg->wParam)
2954 /* User drags top or bottom edge outward. Keep height, increase width. */
2955 new_width = impl->hints.min_aspect * drag_height;
2956 drag->left -= (new_width - drag_width) / 2;
2957 drag->right = drag->left + new_width + decoration_width;
2959 case WMSZ_BOTTOMLEFT:
2960 case WMSZ_BOTTOMRIGHT:
2961 /* User drags bottom-left or bottom-right corner down. Adjust height. */
2962 new_height = drag_width / impl->hints.min_aspect;
2963 drag->bottom = drag->top + new_height + decoration_height;
2967 /* User drags left or right edge inward. Decrease height */
2968 new_height = drag_width / impl->hints.min_aspect;
2969 drag->top += (drag_height - new_height) / 2;
2970 drag->bottom = drag->top + new_height + decoration_height;
2974 /* User drags top-left or top-right corner up. Adjust height. */
2975 new_height = drag_width / impl->hints.min_aspect;
2976 drag->top = drag->bottom - new_height - decoration_height;
2979 else if (drag_aspect > impl->hints.max_aspect)
2981 /* Aspect is getting too wide */
2982 switch (msg->wParam)
2986 /* User drags top or bottom edge inward. Decrease width. */
2987 new_width = impl->hints.max_aspect * drag_height;
2988 drag->left += (drag_width - new_width) / 2;
2989 drag->right = drag->left + new_width + decoration_width;
2991 case WMSZ_BOTTOMLEFT:
2993 /* User drags bottom-left or top-left corner left. Adjust width. */
2994 new_width = impl->hints.max_aspect * drag_height;
2995 drag->left = drag->right - new_width - decoration_width;
2997 case WMSZ_BOTTOMRIGHT:
2999 /* User drags bottom-right or top-right corner right. Adjust width. */
3000 new_width = impl->hints.max_aspect * drag_height;
3001 drag->right = drag->left + new_width + decoration_width;
3005 /* User drags left or right edge outward. Increase height. */
3006 new_height = drag_width / impl->hints.max_aspect;
3007 drag->top -= (new_height - drag_height) / 2;
3008 drag->bottom = drag->top + new_height + decoration_height;
3015 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
3016 _gdk_win32_rect_to_string (drag)));
3020 case WM_GETMINMAXINFO:
3021 if (GDK_WINDOW_DESTROYED (window))
3024 impl = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
3025 mmi = (MINMAXINFO*) msg->lParam;
3026 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
3027 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3028 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3029 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3030 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3031 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3033 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
3035 rect.left = rect.top = 0;
3036 rect.right = impl->hints.min_width;
3037 rect.bottom = impl->hints.min_height;
3039 _gdk_win32_adjust_client_rect (window, &rect);
3041 mmi->ptMinTrackSize.x = rect.right - rect.left;
3042 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
3045 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
3049 rect.left = rect.top = 0;
3050 rect.right = impl->hints.max_width;
3051 rect.bottom = impl->hints.max_height;
3053 _gdk_win32_adjust_client_rect (window, &rect);
3055 /* at least on win9x we have the 16 bit trouble */
3056 maxw = rect.right - rect.left;
3057 maxh = rect.bottom - rect.top;
3058 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
3059 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
3062 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
3064 /* Don't call DefWindowProcW() */
3065 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
3066 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3067 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3068 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3069 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3070 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3076 GDK_NOTE (EVENTS, g_print (" (%d,%d)",
3077 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
3079 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
3080 !IsIconic (msg->hwnd))
3082 if (!GDK_WINDOW_DESTROYED (window))
3083 handle_configure_event (msg, window);
3090 if (GDK_WINDOW_DESTROYED (window))
3093 event = gdk_event_new (GDK_DELETE);
3094 event->any.window = window;
3096 append_event (event);
3098 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
3100 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
3102 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3109 grab = _gdk_display_get_last_pointer_grab (_gdk_display);
3112 if (grab->window == window)
3113 gdk_pointer_ungrab (msg->time);
3116 if (_gdk_display->keyboard_grab.window == window)
3117 gdk_keyboard_ungrab (msg->time);
3119 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
3120 gdk_window_destroy_notify (window);
3122 if (window == NULL || GDK_WINDOW_DESTROYED (window))
3125 event = gdk_event_new (GDK_DESTROY);
3126 event->any.window = window;
3128 append_event (event);
3133 case WM_DISPLAYCHANGE:
3134 handle_display_change ();
3137 case WM_DESTROYCLIPBOARD:
3138 if (!_ignore_destroy_clipboard)
3140 event = gdk_event_new (GDK_SELECTION_CLEAR);
3141 event->selection.window = window;
3142 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3143 event->selection.time = _gdk_win32_get_next_tick (msg->time);
3144 append_event (event);
3153 case WM_RENDERFORMAT:
3154 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
3156 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
3158 GDK_NOTE (EVENTS, g_print (" (target not found)"));
3163 /* We need to render to clipboard immediately, don't call
3166 if (_gdk_event_func)
3168 event = gdk_event_new (GDK_SELECTION_REQUEST);
3169 event->selection.window = window;
3170 event->selection.send_event = FALSE;
3171 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3172 event->selection.target = target;
3173 event->selection.property = _gdk_selection;
3174 event->selection.requestor = msg->hwnd;
3175 event->selection.time = msg->time;
3177 fixup_event (event);
3178 GDK_NOTE (EVENTS, g_print (" (calling gdk_event_func)"));
3179 GDK_NOTE (EVENTS, print_event (event));
3180 (*_gdk_event_func) (event, _gdk_event_data);
3181 gdk_event_free (event);
3183 /* Now the clipboard owner should have rendered */
3184 if (!_delayed_rendering_data)
3186 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3190 if (msg->wParam == CF_DIB)
3192 _delayed_rendering_data =
3193 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3195 if (!_delayed_rendering_data)
3197 g_warning ("Cannot convert to DIB from delayed rendered image");
3202 /* The requestor is holding the clipboard, no
3203 * OpenClipboard() is required/possible
3206 g_print (" SetClipboardData(%s,%p)",
3207 _gdk_win32_cf_to_string (msg->wParam),
3208 _delayed_rendering_data));
3210 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3211 _delayed_rendering_data = NULL;
3217 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3218 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3219 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3220 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3221 HIWORD (msg->wParam) ? " minimized" : "",
3222 (HWND) msg->lParam));
3223 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3224 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3227 if (is_modally_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3229 GdkWindow *modal_current = _gdk_modal_current ();
3230 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3236 /* Bring any tablet contexts to the top of the overlap order when
3237 * one of our windows is activated.
3238 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3241 if (LOWORD(msg->wParam) != WA_INACTIVE)
3242 _gdk_input_set_tablet_active ();
3245 case WM_ACTIVATEAPP:
3246 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3247 msg->wParam ? "YES" : "NO",
3248 (gint64) msg->lParam));
3249 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3250 ensure_stacking_on_activate_app (msg, window);
3253 /* Handle WINTAB events here, as we know that gdkinput.c will
3254 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3255 * constants as case labels.
3258 GDK_NOTE (EVENTS, g_print (" %d %p",
3259 (int) msg->wParam, (gpointer) msg->lParam));
3263 GDK_NOTE (EVENTS, g_print (" %d %p",
3264 (int) msg->wParam, (gpointer) msg->lParam));
3268 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3269 (gpointer) msg->wParam,
3270 LOWORD (msg->lParam),
3271 HIWORD (msg->lParam)));
3275 event = gdk_event_new (GDK_NOTHING);
3276 event->any.window = window;
3277 g_object_ref (window);
3279 if (_gdk_input_other_event (event, msg, window))
3280 append_event (event);
3282 gdk_event_free (event);
3290 g_object_unref (window);
3297 _gdk_events_queue (GdkDisplay *display)
3301 if (modal_win32_dialog != NULL)
3304 while (!_gdk_event_queue_find_first (display) &&
3305 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3307 TranslateMessage (&msg);
3308 DispatchMessageW (&msg);
3313 gdk_event_prepare (GSource *source,
3319 GDK_THREADS_ENTER ();
3323 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3324 (modal_win32_dialog == NULL &&
3325 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3327 GDK_THREADS_LEAVE ();
3333 gdk_event_check (GSource *source)
3338 GDK_THREADS_ENTER ();
3340 if (event_poll_fd.revents & G_IO_IN)
3342 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3343 (modal_win32_dialog == NULL &&
3344 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3351 GDK_THREADS_LEAVE ();
3357 gdk_event_dispatch (GSource *source,
3358 GSourceFunc callback,
3363 GDK_THREADS_ENTER ();
3365 _gdk_events_queue (_gdk_display);
3366 event = _gdk_event_unqueue (_gdk_display);
3370 if (_gdk_event_func)
3371 (*_gdk_event_func) (event, _gdk_event_data);
3373 gdk_event_free (event);
3376 GDK_THREADS_LEAVE ();
3382 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3384 modal_win32_dialog = window;
3388 is_modally_blocked (GdkWindow *window)
3390 GdkWindow *modal_current = _gdk_modal_current ();
3391 return modal_current != NULL ? gdk_window_get_toplevel (window) != modal_current : FALSE;
3395 check_for_too_much_data (GdkEvent *event)
3397 if (event->client.data.l[1] ||
3398 event->client.data.l[2] ||
3399 event->client.data.l[3] ||
3400 event->client.data.l[4])
3402 g_warning ("Only four bytes of data are passed in client messages on Win32\n");
3407 gdk_event_send_client_message_for_display (GdkDisplay *display,
3409 GdkNativeWindow winid)
3411 check_for_too_much_data (event);
3413 return PostMessageW ((HWND) winid, client_message,
3414 (WPARAM) event->client.message_type,
3415 event->client.data.l[0]);
3419 gdk_screen_broadcast_client_message (GdkScreen *screen,
3422 check_for_too_much_data (event);
3424 PostMessageW (HWND_BROADCAST, client_message,
3425 (WPARAM) event->client.message_type,
3426 event->client.data.l[0]);
3435 /* Process all messages currently available */
3436 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3438 TranslateMessage (&msg);
3439 DispatchMessageW (&msg);
3447 gdk_display_sync (GdkDisplay * display)
3451 g_return_if_fail (display == _gdk_display);
3453 /* Process all messages currently available */
3454 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3455 DispatchMessageW (&msg);
3459 gdk_display_flush (GdkDisplay * display)
3461 g_return_if_fail (display == _gdk_display);
3467 gdk_net_wm_supports (GdkAtom property)
3473 _gdk_windowing_event_data_copy (const GdkEvent *src,
3479 _gdk_windowing_event_data_free (GdkEvent *event)