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) 2007-2008 Cody Russell
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
24 * file for a list of people on the GTK+ Team. See the ChangeLog
25 * files for a list of changes. These files are distributed with
26 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 /* Cannot use TrackMouseEvent, as the stupid WM_MOUSELEAVE message
30 * doesn't tell us where the mouse has gone. Thus we cannot use it to
31 * generate a correct GdkNotifyType. Pity, as using TrackMouseEvent
32 * otherwise would make it possible to reliably generate
33 * GDK_LEAVE_NOTIFY events, which would help get rid of those pesky
34 * tooltips sometimes popping up in the wrong place.
36 * Update: a combination of TrackMouseEvent, GetCursorPos and
37 * GetWindowPos can and is actually used to get rid of those
38 * pesky tooltips. It should be possible to use this for the
39 * whole ENTER/LEAVE NOTIFY handling but some platforms may
40 * not have TrackMouseEvent at all (?) --hb
45 #include <glib/gprintf.h>
48 #include "gdkprivate-win32.h"
49 #include "gdkinput-win32.h"
50 #include "gdkkeysyms.h"
74 #define MK_XBUTTON1 32
75 #define MK_XBUTTON2 64
79 * Private function declarations
82 static gboolean gdk_event_translate (MSG *msg,
84 static void handle_wm_paint (MSG *msg,
86 gboolean return_exposes,
89 static gboolean gdk_event_prepare (GSource *source,
91 static gboolean gdk_event_check (GSource *source);
92 static gboolean gdk_event_dispatch (GSource *source,
96 static void append_event (GdkEvent *event);
97 static gboolean is_modally_blocked (GdkWindow *window);
99 /* Private variable declarations
102 static GdkWindow *p_grab_window = NULL; /* Window that currently holds
106 static GdkWindow *p_grab_confine_to = NULL;
108 static GdkWindow *k_grab_window = NULL; /* Window the holds the
112 static GList *client_filters; /* Filters for client messages */
114 static gboolean p_grab_automatic;
115 static GdkEventMask p_grab_mask;
116 static gboolean p_grab_owner_events, k_grab_owner_events;
117 static HCURSOR p_grab_cursor;
119 static GSourceFuncs event_funcs = {
126 GPollFD event_poll_fd;
128 static GdkWindow *current_window = NULL;
129 static gint current_x, current_y;
130 static gint current_root_x, current_root_y;
131 static UINT client_message;
133 static UINT got_gdk_events_message;
134 static HWND modal_win32_dialog = NULL;
137 static HKL latin_locale = NULL;
140 static gboolean in_ime_composition = FALSE;
141 static UINT modal_timer;
142 static UINT sync_timer = 0;
144 static int debug_indent = 0;
147 assign_object (gpointer lhsp,
150 if (*(gpointer *)lhsp != rhs)
152 if (*(gpointer *)lhsp != NULL)
153 g_object_unref (*(gpointer *)lhsp);
154 *(gpointer *)lhsp = rhs;
161 track_mouse_event (DWORD dwFlags,
164 typedef BOOL (WINAPI *PFN_TrackMouseEvent) (LPTRACKMOUSEEVENT);
165 static PFN_TrackMouseEvent p_TrackMouseEvent = NULL;
166 static gboolean once = FALSE;
171 HINSTANCE commctrl32;
173 user32 = GetModuleHandle ("user32.dll");
174 if ((p_TrackMouseEvent = (PFN_TrackMouseEvent)GetProcAddress (user32, "TrackMouseEvent")) == NULL)
176 if ((commctrl32 = LoadLibrary ("commctrl32.dll")) != NULL)
177 p_TrackMouseEvent = (PFN_TrackMouseEvent)
178 GetProcAddress (commctrl32, "_TrackMouseEvent");
183 if (p_TrackMouseEvent)
186 tme.cbSize = sizeof(TRACKMOUSEEVENT);
187 tme.dwFlags = dwFlags;
188 tme.hwndTrack = hwnd;
189 tme.dwHoverTime = HOVER_DEFAULT; /* not used */
191 if (!p_TrackMouseEvent (&tme))
192 WIN32_API_FAILED ("TrackMouseEvent");
193 else if (dwFlags == TME_LEAVE)
194 GDK_NOTE (EVENTS, g_print(" (TrackMouseEvent %p)", hwnd));
195 else if (dwFlags == TME_CANCEL)
196 GDK_NOTE (EVENTS, g_print(" (cancel TrackMouseEvent %p)", hwnd));
201 _gdk_win32_get_next_tick (gulong suggested_tick)
203 static gulong cur_tick = 0;
205 if (suggested_tick == 0)
206 suggested_tick = GetTickCount ();
207 if (suggested_tick <= cur_tick)
210 return cur_tick = suggested_tick;
214 generate_focus_event (GdkWindow *window,
219 event = gdk_event_new (GDK_FOCUS_CHANGE);
220 event->focus_change.window = window;
221 event->focus_change.in = in;
223 append_event (event);
227 generate_grab_broken_event (GdkWindow *window,
229 GdkWindow *grab_window)
231 GdkEvent *event = gdk_event_new (GDK_GRAB_BROKEN);
233 event->grab_broken.window = window;
234 event->grab_broken.send_event = 0;
235 event->grab_broken.keyboard = keyboard;
236 event->grab_broken.implicit = FALSE;
237 event->grab_broken.grab_window = grab_window;
239 append_event (event);
243 inner_window_procedure (HWND hwnd,
253 msg.message = message;
256 msg.time = _gdk_win32_get_next_tick (0);
257 pos = GetMessagePos ();
258 msg.pt.x = GET_X_LPARAM (pos);
259 msg.pt.y = GET_Y_LPARAM (pos);
261 if (gdk_event_translate (&msg, &ret_val))
263 /* If gdk_event_translate() returns TRUE, we return ret_val from
264 * the window procedure.
266 if (modal_win32_dialog)
267 PostMessageW (modal_win32_dialog, got_gdk_events_message,
273 /* Otherwise call DefWindowProcW(). */
274 GDK_NOTE (EVENTS, g_print (" DefWindowProcW"));
275 return DefWindowProcW (hwnd, message, wparam, lparam);
280 _gdk_win32_window_procedure (HWND hwnd,
287 GDK_NOTE (EVENTS, g_print ("%s%*s%s %p",
288 (debug_indent > 0 ? "\n" : ""),
290 _gdk_win32_message_to_string (message), hwnd));
292 retval = inner_window_procedure (hwnd, message, wparam, lparam);
295 GDK_NOTE (EVENTS, g_print (" => %I64d%s", (gint64) retval, (debug_indent == 0 ? "\n" : "")));
301 _gdk_events_init (void)
308 /* List of languages that use a latin keyboard. Somewhat sorted in
309 * "order of least surprise", in case we have to load one of them if
310 * the user only has arabic loaded, for instance.
312 static int latin_languages[] = {
318 /* Rest in numeric order */
347 client_message = RegisterWindowMessage ("GDK_WIN32_CLIENT_MESSAGE");
348 got_gdk_events_message = RegisterWindowMessage ("GDK_WIN32_GOT_EVENTS");
351 /* Check if we have some input locale identifier loaded that uses a
352 * latin keyboard, to be able to get the virtual-key code for the
353 * latin characters corresponding to ASCII control characters.
355 if ((n = GetKeyboardLayoutList (0, NULL)) == 0)
356 WIN32_API_FAILED ("GetKeyboardLayoutList");
359 HKL *hkl_list = g_new (HKL, n);
360 if (GetKeyboardLayoutList (n, hkl_list) == 0)
361 WIN32_API_FAILED ("GetKeyboardLayoutList");
364 for (i = 0; latin_locale == NULL && i < n; i++)
365 for (j = 0; j < G_N_ELEMENTS (latin_languages); j++)
366 if (PRIMARYLANGID (LOWORD (hkl_list[i])) == latin_languages[j])
368 latin_locale = hkl_list [i];
375 if (latin_locale == NULL)
377 /* Try to load a keyboard layout with latin characters then.
380 while (latin_locale == NULL && i < G_N_ELEMENTS (latin_languages))
383 g_sprintf (id, "%08x", MAKELANGID (latin_languages[i++], SUBLANG_DEFAULT));
384 latin_locale = LoadKeyboardLayout (id, KLF_NOTELLSHELL|KLF_SUBSTITUTE_OK);
388 GDK_NOTE (EVENTS, g_print ("latin_locale = %08x\n", (guint) latin_locale));
391 source = g_source_new (&event_funcs, sizeof (GSource));
392 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
395 event_poll_fd.fd = open ("/dev/windows", O_RDONLY);
396 if (event_poll_fd.fd == -1)
397 g_error ("can't open \"/dev/windows\": %s", g_strerror (errno));
399 event_poll_fd.fd = G_WIN32_MSG_HANDLE;
401 event_poll_fd.events = G_IO_IN;
403 g_source_add_poll (source, &event_poll_fd);
404 g_source_set_can_recurse (source, TRUE);
405 g_source_attach (source, NULL);
409 gdk_events_pending (void)
412 return (_gdk_event_queue_find_first (_gdk_display) ||
413 (modal_win32_dialog == NULL &&
414 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
418 gdk_event_get_graphics_expose (GdkWindow *window)
421 GdkEvent *event = NULL;
423 g_return_val_if_fail (window != NULL, NULL);
425 GDK_NOTE (EVENTS, g_print ("gdk_event_get_graphics_expose\n"));
427 if (PeekMessageW (&msg, GDK_WINDOW_HWND (window), WM_PAINT, WM_PAINT, PM_REMOVE))
429 handle_wm_paint (&msg, window, TRUE, &event);
432 GDK_NOTE (EVENTS, g_print ("gdk_event_get_graphics_expose: got it!\n"));
437 GDK_NOTE (EVENTS, g_print ("gdk_event_get_graphics_expose: nope\n"));
442 event_mask_string (GdkEventMask mask)
444 static char bfr[500];
449 if (mask & GDK_##x##_MASK) \
450 p += g_sprintf (p, "%s" #x, (p > bfr ? " " : ""))
452 BIT (POINTER_MOTION);
453 BIT (POINTER_MOTION_HINT);
455 BIT (BUTTON1_MOTION);
456 BIT (BUTTON2_MOTION);
457 BIT (BUTTON3_MOTION);
459 BIT (BUTTON_RELEASE);
466 BIT (PROPERTY_CHANGE);
467 BIT (VISIBILITY_NOTIFY);
478 gdk_pointer_grab (GdkWindow *window,
479 gboolean owner_events,
480 GdkEventMask event_mask,
481 GdkWindow *confine_to,
486 GdkCursorPrivate *cursor_private;
487 gint return_val = GDK_GRAB_SUCCESS;
489 g_return_val_if_fail (window != NULL, 0);
490 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
491 g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
493 cursor_private = (GdkCursorPrivate*) cursor;
497 else if ((hcursor = CopyCursor (cursor_private->hcursor)) == NULL)
498 WIN32_API_FAILED ("CopyCursor");
500 return_val = _gdk_input_grab_pointer (window,
506 if (return_val == GDK_GRAB_SUCCESS)
508 if (!GDK_WINDOW_DESTROYED (window))
510 GDK_NOTE (EVENTS, g_print ("%sgdk_pointer_grab: %p %s %p %s%s",
511 (debug_indent > 0 ? "\n" : ""),
512 GDK_WINDOW_HWND (window),
513 (owner_events ? "TRUE" : "FALSE"),
515 event_mask_string (event_mask),
516 (debug_indent == 0 ? "\n" : "")));
518 p_grab_mask = event_mask;
519 p_grab_owner_events = owner_events;
520 p_grab_automatic = FALSE;
522 SetCapture (GDK_WINDOW_HWND (window));
523 return_val = GDK_GRAB_SUCCESS;
526 return_val = GDK_GRAB_ALREADY_GRABBED;
529 if (return_val == GDK_GRAB_SUCCESS)
531 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
533 if (p_grab_window != NULL && p_grab_window != window)
534 generate_grab_broken_event (p_grab_window, FALSE, window);
536 assign_object (&p_grab_window, window);
538 if (p_grab_cursor != NULL)
540 if (GetCursor () == p_grab_cursor)
542 DestroyCursor (p_grab_cursor);
545 p_grab_cursor = hcursor;
547 if (p_grab_cursor != NULL)
548 SetCursor (p_grab_cursor);
549 else if (impl->hcursor != NULL)
550 SetCursor (impl->hcursor);
552 SetCursor (LoadCursor (NULL, IDC_ARROW));
554 if (confine_to != NULL)
556 gint x, y, width, height;
559 gdk_window_get_origin (confine_to, &x, &y);
560 gdk_drawable_get_size (confine_to, &width, &height);
567 rect.right = x + width;
568 rect.bottom = y + height;
569 API_CALL (ClipCursor, (&rect));
570 p_grab_confine_to = confine_to;
573 /* FIXME: Generate GDK_CROSSING_GRAB events */
580 gdk_display_pointer_ungrab (GdkDisplay *display,
583 g_return_if_fail (display == _gdk_display);
585 GDK_NOTE (EVENTS, g_print ("%sgdk_display_pointer_ungrab%s",
586 (debug_indent > 0 ? "\n" : ""),
587 (debug_indent == 0 ? "\n" : "")));
589 _gdk_input_ungrab_pointer (time);
591 if (GetCapture () != NULL)
594 /* FIXME: Generate GDK_CROSSING_UNGRAB events */
596 assign_object (&p_grab_window, NULL);
597 if (p_grab_cursor != NULL)
599 if (GetCursor () == p_grab_cursor)
601 DestroyCursor (p_grab_cursor);
602 p_grab_cursor = NULL;
605 if (p_grab_confine_to != NULL)
607 API_CALL (ClipCursor, (NULL));
608 p_grab_confine_to = NULL;
613 find_real_window_for_grabbed_mouse_event (GdkWindow* reported_window,
619 GdkWindow* other_window = NULL;
621 points = MAKEPOINTS (msg->lParam);
624 ClientToScreen (msg->hwnd, &pt);
626 hwnd = WindowFromPoint (pt);
632 GetClientRect (hwnd, &rect);
633 ScreenToClient (hwnd, &pt);
634 if (!PtInRect (&rect, pt))
637 other_window = gdk_win32_handle_table_lookup ((GdkNativeWindow) hwnd);
640 if (other_window == NULL)
647 find_window_for_mouse_event (GdkWindow* reported_window,
650 if (p_grab_window == NULL || !p_grab_owner_events)
651 return reported_window;
653 return find_real_window_for_grabbed_mouse_event (reported_window, msg);
658 gdk_display_pointer_is_grabbed (GdkDisplay *display)
660 g_return_val_if_fail (display == _gdk_display, FALSE);
661 GDK_NOTE (EVENTS, g_print ("gdk_pointer_is_grabbed: %s\n",
662 p_grab_window != NULL ? "TRUE" : "FALSE"));
663 return p_grab_window != NULL;
669 gdk_pointer_grab_info_libgtk_only (GdkDisplay *display,
670 GdkWindow **grab_window,
671 gboolean *owner_events)
673 g_return_val_if_fail (display == _gdk_display, FALSE);
675 if (p_grab_window != NULL)
678 *grab_window = p_grab_window;
680 *owner_events = p_grab_owner_events;
690 gdk_keyboard_grab (GdkWindow *window,
691 gboolean owner_events,
694 GdkWindow *real_focus_window, *grab_focus_window;
698 g_return_val_if_fail (window != NULL, 0);
699 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
701 GDK_NOTE (EVENTS, g_print ("gdk_keyboard_grab %p%s\n",
702 GDK_WINDOW_HWND (window), owner_events ? " OWNER_EVENTS" : ""));
704 if (!GDK_WINDOW_DESTROYED (window))
706 k_grab_owner_events = owner_events;
707 return_val = GDK_GRAB_SUCCESS;
710 return_val = GDK_GRAB_ALREADY_GRABBED;
712 if (return_val == GDK_GRAB_SUCCESS)
714 if (k_grab_window != NULL && k_grab_window != window)
715 generate_grab_broken_event (k_grab_window, TRUE, window);
717 assign_object (&k_grab_window, window);
719 if (!k_grab_owner_events)
721 real_focus_window = gdk_win32_handle_table_lookup ((GdkNativeWindow) GetFocus ());
722 if (real_focus_window)
723 real_focus_window = gdk_window_get_toplevel (real_focus_window);
724 grab_focus_window = gdk_window_get_toplevel (k_grab_window);
725 if (real_focus_window != grab_focus_window)
727 /* Generate events for focus change from the window that really
728 * has focus to the grabber.
730 if (real_focus_window && !GDK_WINDOW_DESTROYED (real_focus_window)
731 && (((GdkWindowObject *) real_focus_window)->event_mask
732 & GDK_FOCUS_CHANGE_MASK))
733 generate_focus_event (real_focus_window, FALSE);
735 if (((GdkWindowObject *) grab_focus_window)->event_mask
736 & GDK_FOCUS_CHANGE_MASK)
737 generate_focus_event (grab_focus_window, TRUE);
746 gdk_display_keyboard_ungrab (GdkDisplay *display,
749 GdkWindow *real_focus_window, *grab_focus_window;
751 g_return_if_fail (display == _gdk_display);
753 GDK_NOTE (EVENTS, g_print ("gdk_display_keyboard_ungrab\n"));
755 if (k_grab_window && !k_grab_owner_events)
757 real_focus_window = gdk_win32_handle_table_lookup ((GdkNativeWindow) GetFocus ());
758 if (real_focus_window)
759 real_focus_window = gdk_window_get_toplevel (real_focus_window);
760 if (!GDK_WINDOW_DESTROYED (k_grab_window))
761 grab_focus_window = gdk_window_get_toplevel (k_grab_window);
763 grab_focus_window = NULL;
764 if (real_focus_window != grab_focus_window)
766 /* Generate events for focus change from grabber to the window that
767 * really has focus. Important for example if a new window is created
768 * while focus is grabbed.
770 if (grab_focus_window
771 && (((GdkWindowObject *) grab_focus_window)->event_mask
772 & GDK_FOCUS_CHANGE_MASK))
773 generate_focus_event (grab_focus_window, FALSE);
775 if (real_focus_window && !GDK_WINDOW_DESTROYED (real_focus_window)
776 && (((GdkWindowObject *) real_focus_window)->event_mask
777 & GDK_FOCUS_CHANGE_MASK))
778 generate_focus_event (real_focus_window, TRUE);
782 assign_object (&k_grab_window, NULL);
786 gdk_display_add_client_message_filter (GdkDisplay *display,
787 GdkAtom message_type,
792 gdk_add_client_message_filter (message_type, func, data);
796 gdk_add_client_message_filter (GdkAtom message_type,
800 GdkClientFilter *filter = g_new (GdkClientFilter, 1);
802 filter->type = message_type;
803 filter->function = func;
806 client_filters = g_list_append (client_filters, filter);
810 build_key_event_state (GdkEvent *event,
813 event->key.state = 0;
815 if (key_state[VK_SHIFT] & 0x80)
816 event->key.state |= GDK_SHIFT_MASK;
818 if (key_state[VK_CAPITAL] & 0x01)
819 event->key.state |= GDK_LOCK_MASK;
821 if (key_state[VK_LBUTTON] & 0x80)
822 event->key.state |= GDK_BUTTON1_MASK;
823 if (key_state[VK_MBUTTON] & 0x80)
824 event->key.state |= GDK_BUTTON2_MASK;
825 if (key_state[VK_RBUTTON] & 0x80)
826 event->key.state |= GDK_BUTTON3_MASK;
827 if (key_state[VK_XBUTTON1] & 0x80)
828 event->key.state |= GDK_BUTTON4_MASK;
829 if (key_state[VK_XBUTTON2] & 0x80)
830 event->key.state |= GDK_BUTTON5_MASK;
832 if (_gdk_keyboard_has_altgr &&
833 (key_state[VK_LCONTROL] & 0x80) &&
834 (key_state[VK_RMENU] & 0x80))
836 event->key.group = 1;
837 event->key.state |= GDK_MOD2_MASK;
838 if (key_state[VK_RCONTROL] & 0x80)
839 event->key.state |= GDK_CONTROL_MASK;
840 if (key_state[VK_LMENU] & 0x80)
841 event->key.state |= GDK_MOD1_MASK;
845 event->key.group = 0;
846 if (key_state[VK_CONTROL] & 0x80)
847 event->key.state |= GDK_CONTROL_MASK;
848 if (key_state[VK_MENU] & 0x80)
849 event->key.state |= GDK_MOD1_MASK;
854 build_pointer_event_state (MSG *msg)
860 if (msg->wParam & MK_CONTROL)
861 state |= GDK_CONTROL_MASK;
863 if ((msg->message != WM_LBUTTONDOWN &&
864 (msg->wParam & MK_LBUTTON)) ||
865 msg->message == WM_LBUTTONUP)
866 state |= GDK_BUTTON1_MASK;
868 if ((msg->message != WM_MBUTTONDOWN &&
869 (msg->wParam & MK_MBUTTON)) ||
870 msg->message == WM_MBUTTONUP)
871 state |= GDK_BUTTON2_MASK;
873 if ((msg->message != WM_RBUTTONDOWN &&
874 (msg->wParam & MK_RBUTTON)) ||
875 msg->message == WM_RBUTTONUP)
876 state |= GDK_BUTTON3_MASK;
878 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON1) &&
879 (msg->wParam & MK_XBUTTON1)) ||
880 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON1))
881 state |= GDK_BUTTON4_MASK;
883 if (((msg->message != WM_XBUTTONDOWN || HIWORD (msg->wParam) != XBUTTON2) &&
884 (msg->wParam & MK_XBUTTON2)) ||
885 (msg->message == WM_XBUTTONUP && HIWORD (msg->wParam) == XBUTTON2))
886 state |= GDK_BUTTON5_MASK;
888 if (msg->wParam & MK_SHIFT)
889 state |= GDK_SHIFT_MASK;
891 if (GetKeyState (VK_MENU) < 0)
892 state |= GDK_MOD1_MASK;
894 if (GetKeyState (VK_CAPITAL) & 0x1)
895 state |= GDK_LOCK_MASK;
901 build_wm_ime_composition_event (GdkEvent *event,
906 event->key.time = _gdk_win32_get_next_tick (msg->time);
908 build_key_event_state (event, key_state);
910 event->key.hardware_keycode = 0; /* FIXME: What should it be? */
911 event->key.string = NULL;
912 event->key.length = 0;
913 event->key.keyval = gdk_unicode_to_keyval (wc);
916 #ifdef G_ENABLE_DEBUG
919 print_event_state (guint state)
921 #define CASE(bit) if (state & GDK_ ## bit ## _MASK) g_print (#bit " ");
939 print_event (GdkEvent *event)
941 gchar *escaped, *kvname;
942 gchar *selection_name, *target_name, *property_name;
944 g_print ("%s%*s===> ", (debug_indent > 0 ? "\n" : ""), debug_indent, "");
945 switch (event->any.type)
947 #define CASE(x) case x: g_print (#x); break;
952 CASE (GDK_MOTION_NOTIFY);
953 CASE (GDK_BUTTON_PRESS);
954 CASE (GDK_2BUTTON_PRESS);
955 CASE (GDK_3BUTTON_PRESS);
956 CASE (GDK_BUTTON_RELEASE);
957 CASE (GDK_KEY_PRESS);
958 CASE (GDK_KEY_RELEASE);
959 CASE (GDK_ENTER_NOTIFY);
960 CASE (GDK_LEAVE_NOTIFY);
961 CASE (GDK_FOCUS_CHANGE);
962 CASE (GDK_CONFIGURE);
965 CASE (GDK_PROPERTY_NOTIFY);
966 CASE (GDK_SELECTION_CLEAR);
967 CASE (GDK_SELECTION_REQUEST);
968 CASE (GDK_SELECTION_NOTIFY);
969 CASE (GDK_PROXIMITY_IN);
970 CASE (GDK_PROXIMITY_OUT);
971 CASE (GDK_DRAG_ENTER);
972 CASE (GDK_DRAG_LEAVE);
973 CASE (GDK_DRAG_MOTION);
974 CASE (GDK_DRAG_STATUS);
975 CASE (GDK_DROP_START);
976 CASE (GDK_DROP_FINISHED);
977 CASE (GDK_CLIENT_EVENT);
978 CASE (GDK_VISIBILITY_NOTIFY);
979 CASE (GDK_NO_EXPOSE);
981 CASE (GDK_WINDOW_STATE);
983 CASE (GDK_OWNER_CHANGE);
984 CASE (GDK_GRAB_BROKEN);
986 default: g_assert_not_reached ();
989 g_print (" %p ", GDK_WINDOW_HWND (event->any.window));
991 switch (event->any.type)
995 _gdk_win32_gdkrectangle_to_string (&event->expose.area),
996 event->expose.count);
998 case GDK_MOTION_NOTIFY:
999 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s",
1000 event->motion.x, event->motion.y,
1001 event->motion.x_root, event->motion.y_root,
1002 event->motion.is_hint ? "HINT " : "");
1003 print_event_state (event->motion.state);
1005 case GDK_BUTTON_PRESS:
1006 case GDK_2BUTTON_PRESS:
1007 case GDK_3BUTTON_PRESS:
1008 case GDK_BUTTON_RELEASE:
1009 g_print ("%d (%.4g,%.4g) (%.4g,%.4g) ",
1010 event->button.button,
1011 event->button.x, event->button.y,
1012 event->button.x_root, event->button.y_root);
1013 print_event_state (event->button.state);
1016 case GDK_KEY_RELEASE:
1017 if (event->key.length == 0)
1018 escaped = g_strdup ("");
1020 escaped = g_strescape (event->key.string, NULL);
1021 kvname = gdk_keyval_name (event->key.keyval);
1022 g_print ("%#.02x group:%d %s %d:\"%s\" ",
1023 event->key.hardware_keycode, event->key.group,
1024 (kvname ? kvname : "??"),
1028 print_event_state (event->key.state);
1030 case GDK_ENTER_NOTIFY:
1031 case GDK_LEAVE_NOTIFY:
1032 g_print ("%p (%.4g,%.4g) (%.4g,%.4g) %s %s%s",
1033 event->crossing.subwindow == NULL ? NULL : GDK_WINDOW_HWND (event->crossing.subwindow),
1034 event->crossing.x, event->crossing.y,
1035 event->crossing.x_root, event->crossing.y_root,
1036 (event->crossing.mode == GDK_CROSSING_NORMAL ? "NORMAL" :
1037 (event->crossing.mode == GDK_CROSSING_GRAB ? "GRAB" :
1038 (event->crossing.mode == GDK_CROSSING_UNGRAB ? "UNGRAB" :
1040 (event->crossing.detail == GDK_NOTIFY_ANCESTOR ? "ANCESTOR" :
1041 (event->crossing.detail == GDK_NOTIFY_VIRTUAL ? "VIRTUAL" :
1042 (event->crossing.detail == GDK_NOTIFY_INFERIOR ? "INFERIOR" :
1043 (event->crossing.detail == GDK_NOTIFY_NONLINEAR ? "NONLINEAR" :
1044 (event->crossing.detail == GDK_NOTIFY_NONLINEAR_VIRTUAL ? "NONLINEAR_VIRTUAL" :
1045 (event->crossing.detail == GDK_NOTIFY_UNKNOWN ? "UNKNOWN" :
1047 event->crossing.focus ? " FOCUS" : "");
1048 print_event_state (event->crossing.state);
1050 case GDK_FOCUS_CHANGE:
1051 g_print ("%s", (event->focus_change.in ? "IN" : "OUT"));
1053 case GDK_SELECTION_REQUEST:
1054 case GDK_SELECTION_NOTIFY:
1055 case GDK_SELECTION_CLEAR:
1056 selection_name = gdk_atom_name (event->selection.selection);
1057 target_name = gdk_atom_name (event->selection.target);
1058 property_name = gdk_atom_name (event->selection.property);
1059 g_print ("sel:%s tgt:%s prop:%s",
1060 selection_name, target_name, property_name);
1061 g_free (selection_name);
1062 g_free (target_name);
1063 g_free (property_name);
1066 g_print ("x:%d y:%d w:%d h:%d",
1067 event->configure.x, event->configure.y,
1068 event->configure.width, event->configure.height);
1070 case GDK_CLIENT_EVENT:
1071 g_print ("%s %d %ld %ld %ld %ld %ld",
1072 gdk_atom_name (event->client.message_type),
1073 event->client.data_format,
1074 event->client.data.l[0],
1075 event->client.data.l[1],
1076 event->client.data.l[2],
1077 event->client.data.l[3],
1078 event->client.data.l[4]);
1081 g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",
1082 event->scroll.x, event->scroll.y,
1083 event->scroll.x_root, event->scroll.y_root,
1084 (event->scroll.direction == GDK_SCROLL_UP ? "UP" :
1085 (event->scroll.direction == GDK_SCROLL_DOWN ? "DOWN" :
1086 (event->scroll.direction == GDK_SCROLL_LEFT ? "LEFT" :
1087 (event->scroll.direction == GDK_SCROLL_RIGHT ? "RIGHT" :
1089 print_event_state (event->scroll.state);
1091 case GDK_WINDOW_STATE:
1093 _gdk_win32_window_state_to_string (event->window_state.changed_mask),
1094 _gdk_win32_window_state_to_string (event->window_state.new_window_state));
1097 (event->setting.action == GDK_SETTING_ACTION_NEW ? "NEW" :
1098 (event->setting.action == GDK_SETTING_ACTION_CHANGED ? "CHANGED" :
1099 (event->setting.action == GDK_SETTING_ACTION_DELETED ? "DELETED" :
1101 (event->setting.name ? event->setting.name : "NULL"));
1102 case GDK_GRAB_BROKEN:
1103 g_print ("%s %s %p",
1104 (event->grab_broken.keyboard ? "KEYBOARD" : "POINTER"),
1105 (event->grab_broken.implicit ? "IMPLICIT" : "EXPLICIT"),
1106 (event->grab_broken.grab_window ? GDK_WINDOW_HWND (event->grab_broken.grab_window) : 0));
1111 g_print ("%s", (debug_indent == 0 ? "\n" : ""));
1115 decode_key_lparam (LPARAM lParam)
1117 static char buf[100];
1120 if (HIWORD (lParam) & KF_UP)
1121 p += g_sprintf (p, "KF_UP ");
1122 if (HIWORD (lParam) & KF_REPEAT)
1123 p += g_sprintf (p, "KF_REPEAT ");
1124 if (HIWORD (lParam) & KF_ALTDOWN)
1125 p += g_sprintf (p, "KF_ALTDOWN ");
1126 if (HIWORD (lParam) & KF_EXTENDED)
1127 p += g_sprintf (p, "KF_EXTENDED ");
1128 p += g_sprintf (p, "sc:%d rep:%d", LOBYTE (HIWORD (lParam)), LOWORD (lParam));
1136 fixup_event (GdkEvent *event)
1138 if (event->any.window)
1139 g_object_ref (event->any.window);
1140 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1141 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1142 (event->crossing.subwindow != NULL))
1143 g_object_ref (event->crossing.subwindow);
1144 event->any.send_event = InSendMessage ();
1148 append_event (GdkEvent *event)
1150 fixup_event (event);
1151 _gdk_event_queue_append (_gdk_display, event);
1152 GDK_NOTE (EVENTS, print_event (event));
1156 fill_key_event_string (GdkEvent *event)
1161 /* Fill in event->string crudely, since various programs
1166 if (event->key.keyval != GDK_VoidSymbol)
1167 c = gdk_keyval_to_unicode (event->key.keyval);
1171 gsize bytes_written;
1174 /* Apply the control key - Taken from Xlib
1176 if (event->key.state & GDK_CONTROL_MASK)
1178 if ((c >= '@' && c < '\177') || c == ' ')
1182 event->key.string = g_memdup ("\0\0", 2);
1183 event->key.length = 1;
1186 else if (c >= '3' && c <= '7')
1187 c -= ('3' - '\033');
1194 len = g_unichar_to_utf8 (c, buf);
1197 event->key.string = g_locale_from_utf8 (buf, len,
1198 NULL, &bytes_written,
1200 if (event->key.string)
1201 event->key.length = bytes_written;
1203 else if (event->key.keyval == GDK_Escape)
1205 event->key.length = 1;
1206 event->key.string = g_strdup ("\033");
1208 else if (event->key.keyval == GDK_Return ||
1209 event->key.keyval == GDK_KP_Enter)
1211 event->key.length = 1;
1212 event->key.string = g_strdup ("\r");
1215 if (!event->key.string)
1217 event->key.length = 0;
1218 event->key.string = g_strdup ("");
1222 static GdkFilterReturn
1223 apply_event_filters (GdkWindow *window,
1227 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1232 event = gdk_event_new (GDK_NOTHING);
1234 event->any.window = g_object_ref (window);
1235 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1237 /* I think GdkFilterFunc semantics require the passed-in event
1238 * to already be in the queue. The filter func can generate
1239 * more events and append them after it if it likes.
1241 node = _gdk_event_queue_append (_gdk_display, event);
1246 GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
1248 tmp_list = tmp_list->next;
1249 result = filter->function (msg, event, filter->data);
1250 if (result != GDK_FILTER_CONTINUE)
1254 if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
1256 _gdk_event_queue_remove_link (_gdk_display, node);
1257 g_list_free_1 (node);
1258 gdk_event_free (event);
1260 else /* GDK_FILTER_TRANSLATE */
1262 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1263 fixup_event (event);
1264 GDK_NOTE (EVENTS, print_event (event));
1270 * On Windows, transient windows will not have their own taskbar entries.
1271 * Because of this, we must hide and restore groups of transients in both
1272 * directions. That is, all transient children must be hidden or restored
1273 * with this window, but if this window's transient owner also has a
1274 * transient owner then this window's transient owner must be hidden/restored
1275 * with this one. And etc, up the chain until we hit an ancestor that has no
1278 * It would be a good idea if applications don't chain transient windows
1279 * together. There's a limit to how much evil GTK can try to shield you
1283 show_window_recurse (GdkWindow *window, gboolean hide_window)
1285 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1286 GSList *children = impl->transient_children;
1287 GdkWindow *child = NULL;
1289 if (!impl->changing_state)
1291 impl->changing_state = TRUE;
1293 if (children != NULL)
1295 while (children != NULL)
1297 child = children->data;
1298 show_window_recurse (child, hide_window);
1300 children = g_slist_next (children);
1304 if (GDK_WINDOW_IS_MAPPED (window))
1308 if (GDK_WINDOW_OBJECT (window)->state & GDK_WINDOW_STATE_ICONIFIED)
1310 if (GDK_WINDOW_OBJECT (window)->state & GDK_WINDOW_STATE_MAXIMIZED)
1312 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWMAXIMIZED);
1316 ShowWindow (GDK_WINDOW_HWND (window), SW_RESTORE);
1322 ShowWindow (GDK_WINDOW_HWND (window), SW_MINIMIZE);
1326 impl->changing_state = FALSE;
1331 do_show_window (GdkWindow *window, gboolean hide_window)
1333 GdkWindow *tmp_window = NULL;
1334 GdkWindowImplWin32 *tmp_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
1336 if (!tmp_impl->changing_state)
1338 /* Find the top-level window in our transient chain. */
1339 while (tmp_impl->transient_owner != NULL)
1341 tmp_window = tmp_impl->transient_owner;
1342 tmp_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (tmp_window)->impl);
1345 /* If we couldn't find one, use the window provided. */
1346 if (tmp_window == NULL)
1348 tmp_window = window;
1351 /* Recursively show/hide every window in the chain. */
1352 if (tmp_window != window)
1354 show_window_recurse (tmp_window, hide_window);
1360 gdk_window_is_ancestor (GdkWindow *ancestor,
1363 if (ancestor == NULL || window == NULL)
1366 return (gdk_window_get_parent (window) == ancestor ||
1367 gdk_window_is_ancestor (ancestor, gdk_window_get_parent (window)));
1371 synthesize_enter_or_leave_event (GdkWindow *window,
1374 GdkCrossingMode mode,
1375 GdkNotifyType detail,
1380 gint xoffset, yoffset;
1382 event = gdk_event_new (type);
1383 event->crossing.window = window;
1384 event->crossing.subwindow = NULL;
1385 event->crossing.time = _gdk_win32_get_next_tick (msg->time);
1386 //_gdk_win32_windowing_window_get_offsets (window, &xoffset, &yoffset);
1387 event->crossing.x = x + xoffset;
1388 event->crossing.y = y + yoffset;
1389 event->crossing.x_root = msg->pt.x + _gdk_offset_x;
1390 event->crossing.y_root = msg->pt.y + _gdk_offset_y;
1391 event->crossing.mode = mode;
1392 event->crossing.detail = detail;
1393 event->crossing.focus = TRUE; /* FIXME: Set correctly */
1394 event->crossing.state = 0; /* FIXME: Set correctly */
1396 append_event (event);
1398 if (type == GDK_ENTER_NOTIFY &&
1399 ((GdkWindowObject *) window)->extension_events != 0)
1400 _gdk_input_enter_event (window);
1404 synthesize_leave_event (GdkWindow *window,
1406 GdkCrossingMode mode,
1407 GdkNotifyType detail)
1411 if (p_grab_window != NULL && !p_grab_owner_events && !(p_grab_mask & GDK_LEAVE_NOTIFY_MASK))
1414 if (!(((GdkWindowObject *) window)->event_mask & GDK_LEAVE_NOTIFY_MASK))
1417 /* Leave events are at (current_x,current_y) in current_window */
1419 if (current_window != window)
1423 ClientToScreen (GDK_WINDOW_HWND (current_window), &pt);
1424 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1425 synthesize_enter_or_leave_event (window, msg, GDK_LEAVE_NOTIFY, mode, detail, pt.x, pt.y);
1428 synthesize_enter_or_leave_event (window, msg, GDK_LEAVE_NOTIFY, mode, detail, current_x, current_y);
1430 /* This would only make sense if the WM_MOUSEMOVE messages would come
1431 * before the respective WM_MOUSELEAVE message, which apparently they
1433 track_mouse_event (TME_CANCEL, msg->hwnd);
1438 synthesize_enter_event (GdkWindow *window,
1440 GdkCrossingMode mode,
1441 GdkNotifyType detail)
1445 if (p_grab_window != NULL && !p_grab_owner_events && !(p_grab_mask & GDK_ENTER_NOTIFY_MASK))
1448 if (!(((GdkWindowObject *) window)->event_mask & GDK_ENTER_NOTIFY_MASK))
1451 /* Enter events are at GET_X_LPARAM (msg->lParam), GET_Y_LPARAM
1452 * (msg->lParam) in msg->hwnd
1455 pt.x = GET_X_LPARAM (msg->lParam);
1456 pt.y = GET_Y_LPARAM (msg->lParam);
1457 if (msg->hwnd != GDK_WINDOW_HWND (window))
1459 ClientToScreen (msg->hwnd, &pt);
1460 ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1462 synthesize_enter_or_leave_event (window, msg, GDK_ENTER_NOTIFY, mode, detail, pt.x, pt.y);
1464 track_mouse_event (TME_LEAVE, GDK_WINDOW_HWND (window));
1468 synthesize_enter_events (GdkWindow *from,
1471 GdkCrossingMode mode,
1472 GdkNotifyType detail)
1474 GdkWindow *prev = gdk_window_get_parent (to);
1477 synthesize_enter_events (from, prev, msg, mode, detail);
1478 synthesize_enter_event (to, msg, mode, detail);
1482 synthesize_leave_events (GdkWindow *from,
1485 GdkCrossingMode mode,
1486 GdkNotifyType detail)
1488 GdkWindow *next = gdk_window_get_parent (from);
1490 synthesize_leave_event (from, msg, mode, detail);
1492 synthesize_leave_events (next, to, msg, mode, detail);
1496 synthesize_crossing_events (GdkWindow *window,
1497 GdkCrossingMode mode,
1500 GdkWindow *intermediate, *tem, *common_ancestor;
1502 if (gdk_window_is_ancestor (current_window, window))
1504 /* Pointer has moved to an inferior window. */
1505 synthesize_leave_event (current_window, msg, mode, GDK_NOTIFY_INFERIOR);
1507 /* If there are intermediate windows, generate ENTER_NOTIFY
1510 intermediate = gdk_window_get_parent (window);
1511 if (intermediate != current_window)
1513 synthesize_enter_events (current_window, intermediate, msg, mode, GDK_NOTIFY_VIRTUAL);
1516 synthesize_enter_event (window, msg, mode, GDK_NOTIFY_ANCESTOR);
1518 else if (gdk_window_is_ancestor (window, current_window))
1520 /* Pointer has moved to an ancestor window. */
1521 synthesize_leave_event (current_window, msg, mode, GDK_NOTIFY_ANCESTOR);
1523 /* If there are intermediate windows, generate LEAVE_NOTIFY
1526 intermediate = gdk_window_get_parent (current_window);
1527 if (intermediate != window)
1529 synthesize_leave_events (intermediate, window, msg, mode, GDK_NOTIFY_VIRTUAL);
1532 synthesize_enter_event (window, msg, mode, GDK_NOTIFY_INFERIOR);
1534 else if (current_window)
1536 /* Find least common ancestor of current_window and window */
1537 tem = current_window;
1539 common_ancestor = gdk_window_get_parent (tem);
1540 tem = common_ancestor;
1541 } while (common_ancestor &&
1542 !gdk_window_is_ancestor (common_ancestor, window));
1543 if (common_ancestor)
1545 synthesize_leave_event (current_window, msg, mode, GDK_NOTIFY_NONLINEAR);
1546 intermediate = gdk_window_get_parent (current_window);
1547 if (intermediate != common_ancestor)
1549 synthesize_leave_events (intermediate, common_ancestor,
1550 msg, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
1552 intermediate = gdk_window_get_parent (window);
1553 if (intermediate != common_ancestor)
1555 synthesize_enter_events (common_ancestor, intermediate,
1556 msg, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
1558 synthesize_enter_event (window, msg, mode, GDK_NOTIFY_NONLINEAR);
1563 /* Dunno where we are coming from */
1564 synthesize_enter_event (window, msg, mode, GDK_NOTIFY_UNKNOWN);
1567 assign_object (¤t_window, window);
1571 synthesize_expose_events (GdkWindow *window)
1575 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
1576 GList *list = gdk_window_get_children (window);
1583 synthesize_expose_events ((GdkWindow *) list->data);
1589 if (((GdkWindowObject *) window)->input_only)
1591 else if (!(hdc = GetDC (impl->handle)))
1592 WIN32_GDI_FAILED ("GetDC");
1595 if ((k = GetClipBox (hdc, &r)) == ERROR)
1596 WIN32_GDI_FAILED ("GetClipBox");
1597 else if (k != NULLREGION)
1599 event = gdk_event_new (GDK_EXPOSE);
1600 event->expose.window = window;
1601 event->expose.area.x = r.left;
1602 event->expose.area.y = r.top;
1603 event->expose.area.width = r.right - r.left;
1604 event->expose.area.height = r.bottom - r.top;
1605 event->expose.region = gdk_region_rectangle (&(event->expose.area));
1606 event->expose.count = 0;
1608 append_event (event);
1610 GDI_CALL (ReleaseDC, (impl->handle, hdc));
1615 update_colors (GdkWindow *window,
1619 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
1620 GList *list = gdk_window_get_children (window);
1623 GDK_NOTE (COLORMAP, (top ? g_print ("update_colors:") : (void) 0));
1627 update_colors ((GdkWindow *) list->data, FALSE);
1632 if (((GdkWindowObject *) window)->input_only ||
1633 impl->colormap == NULL)
1636 if (!(hdc = GetDC (impl->handle)))
1637 WIN32_GDI_FAILED ("GetDC");
1640 GdkColormapPrivateWin32 *cmapp = GDK_WIN32_COLORMAP_DATA (impl->colormap);
1644 if ((holdpal = SelectPalette (hdc, cmapp->hpal, TRUE)) == NULL)
1645 WIN32_GDI_FAILED ("SelectPalette");
1646 else if ((k = RealizePalette (hdc)) == GDI_ERROR)
1647 WIN32_GDI_FAILED ("RealizePalette");
1652 g_print (" %p pal=%p: realized %d colors\n"
1654 impl->handle, cmapp->hpal, k) :
1656 g_print (" %p", impl->handle)));
1657 GDI_CALL (UpdateColors, (hdc));
1658 SelectPalette (hdc, holdpal, TRUE);
1659 RealizePalette (hdc);
1661 GDI_CALL (ReleaseDC, (impl->handle, hdc));
1663 GDK_NOTE (COLORMAP, (top ? g_print ("\n") : (void) 0));
1667 translate_mouse_coords (GdkWindow *window1,
1673 pt.x = GET_X_LPARAM (msg->lParam);
1674 pt.y = GET_Y_LPARAM (msg->lParam);
1675 ClientToScreen (GDK_WINDOW_HWND (window1), &pt);
1676 ScreenToClient (GDK_WINDOW_HWND (window2), &pt);
1677 msg->lParam = MAKELPARAM (pt.x, pt.y);
1680 /* The check_extended flag controls whether to check if the windows want
1681 * events from extended input devices and if the message should be skipped
1682 * because an extended input device is active
1685 propagate (GdkWindow **window,
1687 GdkWindow *grab_window,
1688 gboolean grab_owner_events,
1690 gboolean (*doesnt_want_it) (gint mask,
1692 gboolean check_extended)
1694 if (grab_window != NULL && !grab_owner_events)
1696 /* Event source is grabbed with owner_events FALSE */
1698 /* See if the event should be ignored because an extended input
1701 if (check_extended &&
1702 ((GdkWindowObject *) grab_window)->extension_events != 0 &&
1703 _gdk_input_ignore_core)
1705 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1708 if ((*doesnt_want_it) (grab_mask, msg))
1710 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1715 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1716 assign_object (window, grab_window);
1721 /* If we come here, we know that if grab_window != NULL then
1722 * grab_owner_events is TRUE
1726 if (check_extended &&
1727 ((GdkWindowObject *) *window)->extension_events != 0 &&
1728 _gdk_input_ignore_core)
1730 GDK_NOTE (EVENTS, g_print (" (ignored)"));
1733 if ((*doesnt_want_it) (((GdkWindowObject *) *window)->event_mask, msg))
1735 /* Owner doesn't want it, propagate to parent. */
1736 GdkWindow *parent = gdk_window_get_parent (*window);
1737 if (parent == _gdk_root || parent == NULL)
1739 /* No parent; check if grabbed */
1740 if (grab_window != NULL)
1742 /* Event source is grabbed with owner_events TRUE */
1744 if (check_extended &&
1745 ((GdkWindowObject *) grab_window)->extension_events != 0 &&
1746 _gdk_input_ignore_core)
1748 GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
1751 if ((*doesnt_want_it) (grab_mask, msg))
1753 /* Grabber doesn't want it either */
1754 GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
1760 GDK_NOTE (EVENTS, g_print (" (to grabber)"));
1761 assign_object (window, grab_window);
1767 GDK_NOTE (EVENTS, g_print (" (undelivered)"));
1773 assign_object (window, parent);
1774 /* The only branch where we actually continue the loop */
1783 doesnt_want_key (gint mask,
1786 return (((msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP) &&
1787 !(mask & GDK_KEY_RELEASE_MASK)) ||
1788 ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) &&
1789 !(mask & GDK_KEY_PRESS_MASK)));
1793 doesnt_want_char (gint mask,
1796 return !(mask & (GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK));
1800 doesnt_want_button_press (gint mask,
1803 return !(mask & GDK_BUTTON_PRESS_MASK);
1807 doesnt_want_button_release (gint mask,
1810 return !(mask & GDK_BUTTON_RELEASE_MASK);
1814 doesnt_want_button_motion (gint mask,
1817 return !((mask & GDK_POINTER_MOTION_MASK) ||
1818 ((msg->wParam & (MK_LBUTTON|MK_MBUTTON|MK_RBUTTON)) && (mask & GDK_BUTTON_MOTION_MASK)) ||
1819 ((msg->wParam & MK_LBUTTON) && (mask & GDK_BUTTON1_MOTION_MASK)) ||
1820 ((msg->wParam & MK_MBUTTON) && (mask & GDK_BUTTON2_MOTION_MASK)) ||
1821 ((msg->wParam & MK_RBUTTON) && (mask & GDK_BUTTON3_MOTION_MASK)));
1825 doesnt_want_scroll (gint mask,
1828 /* As there are no separate scroll events in X11, button press
1829 * events are used, so higher level code might be selecting for
1830 * either GDK_BUTTON_PRESS_MASK or GDK_SCROLL_MASK when it wants GDK
1831 * scroll events. Make sure this works in the Win32 backend, too.
1833 return !(mask & (GDK_SCROLL_MASK|GDK_BUTTON_PRESS_MASK));
1837 handle_configure_event (MSG *msg,
1842 GdkWindowObject *window_object;
1844 GetClientRect (msg->hwnd, &client_rect);
1845 point.x = client_rect.left; /* always 0 */
1846 point.y = client_rect.top;
1847 /* top level windows need screen coords */
1848 if (gdk_window_get_parent (window) == _gdk_root)
1850 ClientToScreen (msg->hwnd, &point);
1851 point.x += _gdk_offset_x;
1852 point.y += _gdk_offset_y;
1855 window_object = GDK_WINDOW_OBJECT (window);
1857 window_object->width = client_rect.right - client_rect.left;
1858 window_object->height = client_rect.bottom - client_rect.top;
1860 window_object->x = point.x;
1861 window_object->y = point.y;
1863 if (window_object->event_mask & GDK_STRUCTURE_MASK)
1865 GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
1867 event->configure.window = window;
1869 event->configure.width = client_rect.right - client_rect.left;
1870 event->configure.height = client_rect.bottom - client_rect.top;
1872 event->configure.x = point.x;
1873 event->configure.y = point.y;
1875 append_event (event);
1880 _gdk_win32_hrgn_to_region (HRGN hrgn)
1888 if ((nbytes = GetRegionData (hrgn, 0, NULL)) == 0)
1890 WIN32_GDI_FAILED ("GetRegionData");
1894 rgndata = (RGNDATA *) g_malloc (nbytes);
1896 if (GetRegionData (hrgn, nbytes, rgndata) == 0)
1898 WIN32_GDI_FAILED ("GetRegionData");
1903 result = gdk_region_new ();
1904 rects = (RECT *) rgndata->Buffer;
1905 for (i = 0; i < rgndata->rdh.nCount; i++)
1909 r.x = rects[i].left;
1911 r.width = rects[i].right - r.x;
1912 r.height = rects[i].bottom - r.y;
1914 gdk_region_union_with_rect (result, &r);
1923 adjust_drag (LONG *drag,
1928 *drag = curr + ((*drag + inc/2 - curr) / inc) * inc;
1930 *drag = curr - ((curr - *drag + inc/2) / inc) * inc;
1934 handle_wm_paint (MSG *msg,
1936 gboolean return_exposes,
1939 HRGN hrgn = CreateRectRgn (0, 0, 0, 0);
1941 PAINTSTRUCT paintstruct;
1942 GdkRegion *update_region;
1943 gint xoffset, yoffset;
1945 if (GetUpdateRgn (msg->hwnd, hrgn, FALSE) == ERROR)
1947 WIN32_GDI_FAILED ("GetUpdateRgn");
1948 DeleteObject (hrgn);
1952 hdc = BeginPaint (msg->hwnd, &paintstruct);
1954 GDK_NOTE (EVENTS, g_print (" %s %s dc %p%s",
1955 _gdk_win32_rect_to_string (&paintstruct.rcPaint),
1956 (paintstruct.fErase ? "erase" : ""),
1958 (return_exposes ? " return_exposes" : "")));
1960 EndPaint (msg->hwnd, &paintstruct);
1962 /* HB: don't generate GDK_EXPOSE events for InputOnly
1963 * windows -> backing store now works!
1965 if (((GdkWindowObject *) window)->input_only)
1967 DeleteObject (hrgn);
1971 if (!(((GdkWindowObject *) window)->event_mask & GDK_EXPOSURE_MASK))
1973 GDK_NOTE (EVENTS, g_print (" (ignored)"));
1974 DeleteObject (hrgn);
1978 #if 0 /* we need to process exposes even with GDK_NO_BG
1979 * Otherwise The GIMP canvas update is broken ....
1981 if (((GdkWindowObject *) window)->bg_pixmap == GDK_NO_BG)
1985 if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
1986 (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
1988 GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
1989 DeleteObject (hrgn);
1995 if (!GDK_WINDOW_DESTROYED (window))
1997 GList *list = _gdk_display->queued_events;
1999 *event = gdk_event_new (GDK_EXPOSE);
2000 (*event)->expose.window = window;
2001 (*event)->expose.area.x = paintstruct.rcPaint.left;
2002 (*event)->expose.area.y = paintstruct.rcPaint.top;
2003 (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left;
2004 (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top;
2005 (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn);
2006 (*event)->expose.count = 0;
2008 while (list != NULL)
2010 GdkEventPrivate *evp = list->data;
2012 if (evp->event.any.type == GDK_EXPOSE &&
2013 evp->event.any.window == window &&
2014 !(evp->flags & GDK_EVENT_PENDING))
2015 evp->event.expose.count++;
2021 DeleteObject (hrgn);
2025 update_region = _gdk_win32_hrgn_to_region (hrgn);
2027 //_gdk_win32_windowing_window_get_offsets (window, &xoffset, &yoffset);
2028 gdk_region_offset (update_region, xoffset, yoffset);
2030 _gdk_window_process_expose (window, update_region);
2031 gdk_region_destroy (update_region);
2033 DeleteObject (hrgn);
2037 handle_stuff_while_moving_or_resizing (void)
2039 int arbitrary_limit = 1;
2040 while (g_main_context_pending (NULL) && arbitrary_limit--)
2041 g_main_context_iteration (NULL, FALSE);
2044 static VOID CALLBACK
2045 modal_timer_proc (HWND hwnd,
2050 if (_sizemove_in_progress)
2051 handle_stuff_while_moving_or_resizing ();
2054 static VOID CALLBACK
2055 sync_timer_proc (HWND hwnd,
2061 if (PeekMessageW (&message, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
2066 RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
2068 KillTimer (hwnd, sync_timer);
2072 handle_display_change (void)
2074 _gdk_monitor_init ();
2075 _gdk_root_window_size_init ();
2076 g_signal_emit_by_name (_gdk_screen, "size_changed");
2080 generate_button_event (GdkEventType type,
2083 GdkWindow *orig_window,
2086 GdkEvent *event = gdk_event_new (type);
2087 gint xoffset, yoffset;
2089 event->button.window = window;
2090 event->button.time = _gdk_win32_get_next_tick (msg->time);
2091 if (window != orig_window)
2092 translate_mouse_coords (orig_window, window, msg);
2093 event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2094 event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2095 //_gdk_win32_windowing_window_get_offsets (window, &xoffset, &yoffset);
2096 event->button.x += xoffset;
2097 event->button.y += yoffset;
2098 event->button.x_root = msg->pt.x + _gdk_offset_x;
2099 event->button.y_root = msg->pt.y + _gdk_offset_y;
2100 event->button.axes = NULL;
2101 event->button.state = build_pointer_event_state (msg);
2102 event->button.button = button;
2103 event->button.device = _gdk_display->core_pointer;
2105 append_event (event);
2107 if (type == GDK_BUTTON_PRESS)
2108 _gdk_event_button_generate (_gdk_display, event);
2112 ensure_stacking_on_unminimize (MSG *msg)
2115 HWND lowest_transient = NULL;
2118 while ((rover = GetNextWindow (rover, GW_HWNDNEXT)))
2120 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
2122 /* Checking window group not implemented yet */
2125 GdkWindowImplWin32 *rover_impl =
2126 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
2128 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
2129 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
2130 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
2131 rover_impl->transient_owner != NULL))
2133 lowest_transient = rover;
2137 if (lowest_transient != NULL)
2139 GDK_NOTE (EVENTS, g_print (" restacking: %p", lowest_transient));
2140 SetWindowPos (msg->hwnd, lowest_transient, 0, 0, 0, 0,
2141 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2146 ensure_stacking_on_window_pos_changing (MSG *msg,
2149 GdkWindowImplWin32 *impl = (GdkWindowImplWin32 *)((GdkWindowObject *) window)->impl;
2150 WINDOWPOS *windowpos = (WINDOWPOS *) msg->lParam;
2152 if (GetActiveWindow () == msg->hwnd &&
2153 impl->type_hint != GDK_WINDOW_TYPE_HINT_UTILITY &&
2154 impl->type_hint != GDK_WINDOW_TYPE_HINT_DIALOG &&
2155 impl->transient_owner == NULL)
2157 /* Make sure the window stays behind any transient-type windows
2158 * of the same window group.
2160 * If the window is not active and being activated, we let
2161 * Windows bring it to the top and rely on the WM_ACTIVATEAPP
2162 * handling to bring any utility windows on top of it.
2165 gboolean restacking;
2167 rover = windowpos->hwndInsertAfter;
2171 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
2173 /* Checking window group not implemented yet */
2176 GdkWindowImplWin32 *rover_impl =
2177 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
2179 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
2180 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
2181 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
2182 rover_impl->transient_owner != NULL))
2185 windowpos->hwndInsertAfter = rover;
2188 rover = GetNextWindow (rover, GW_HWNDNEXT);
2193 GDK_NOTE (EVENTS, g_print (" restacking: %p", windowpos->hwndInsertAfter));
2201 ensure_stacking_on_activate_app (MSG *msg,
2204 GdkWindowImplWin32 *impl = (GdkWindowImplWin32 *)((GdkWindowObject *) window)->impl;
2206 if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
2207 impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
2208 impl->transient_owner != NULL)
2210 SetWindowPos (msg->hwnd, HWND_TOP, 0, 0, 0, 0,
2211 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2215 if (IsWindowVisible (msg->hwnd) &&
2216 msg->hwnd == GetActiveWindow ())
2218 /* This window is not a transient-type window and it is the
2219 * activated window. Make sure this window is as visible as
2220 * possible, just below the lowest transient-type window of this
2226 while ((rover = GetNextWindow (rover, GW_HWNDPREV)))
2228 GdkWindow *rover_gdkw = gdk_win32_handle_table_lookup (rover);
2230 /* Checking window group not implemented yet */
2233 GdkWindowImplWin32 *rover_impl =
2234 (GdkWindowImplWin32 *)((GdkWindowObject *)rover_gdkw)->impl;
2236 if (GDK_WINDOW_IS_MAPPED (rover_gdkw) &&
2237 (rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY ||
2238 rover_impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG ||
2239 rover_impl->transient_owner != NULL))
2241 GDK_NOTE (EVENTS, g_print (" restacking: %p", rover));
2242 SetWindowPos (msg->hwnd, rover, 0, 0, 0, 0,
2243 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2252 gdk_event_translate (MSG *msg,
2255 RECT rect, *drag, orig_drag;
2260 BYTE key_state[256];
2262 WINDOWPOS *windowpos;
2269 GdkWindow *window = NULL;
2270 GdkWindowImplWin32 *impl;
2272 GdkWindow *orig_window, *new_window;
2273 gint xoffset, yoffset;
2275 static gint update_colors_counter = 0;
2280 gboolean return_val = FALSE;
2284 if (_gdk_default_filters)
2286 /* Apply global filters */
2288 GdkFilterReturn result = apply_event_filters (NULL, msg, _gdk_default_filters);
2290 /* If result is GDK_FILTER_CONTINUE, we continue as if nothing
2291 * happened. If it is GDK_FILTER_REMOVE or GDK_FILTER_TRANSLATE,
2292 * we return TRUE, and DefWindowProcW() will not be called.
2294 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
2298 window = gdk_win32_handle_table_lookup ((GdkNativeWindow) msg->hwnd);
2299 orig_window = window;
2303 /* XXX Handle WM_QUIT here ? */
2304 if (msg->message == WM_QUIT)
2306 GDK_NOTE (EVENTS, g_print (" %d", (int) msg->wParam));
2309 else if (msg->message == WM_MOVE ||
2310 msg->message == WM_SIZE)
2312 /* It's quite normal to get these messages before we have
2313 * had time to register the window in our lookup table, or
2314 * when the window is being destroyed and we already have
2315 * removed it. Repost the same message to our queue so that
2316 * we will get it later when we are prepared.
2318 GDK_NOTE (EVENTS, g_print (" (posted)"));
2320 PostMessageW (msg->hwnd, msg->message, msg->wParam, msg->lParam);
2322 else if (msg->message == WM_CREATE)
2324 window = (UNALIGNED GdkWindow*) (((LPCREATESTRUCTW) msg->lParam)->lpCreateParams);
2325 GDK_WINDOW_HWND (window) = msg->hwnd;
2329 GDK_NOTE (EVENTS, g_print (" (no GdkWindow)"));
2334 g_object_ref (window);
2336 /* window's refcount has now been increased, so code below should
2337 * not just return from this function, but instead goto done (or
2338 * break out of the big switch). To protect against forgetting this,
2339 * #define return to a syntax error...
2341 #define return GOTO_DONE_INSTEAD
2343 if (!GDK_WINDOW_DESTROYED (window) && ((GdkWindowObject *) window)->filters)
2345 /* Apply per-window filters */
2347 GdkFilterReturn result = apply_event_filters (window, msg, ((GdkWindowObject *) window)->filters);
2349 if (result == GDK_FILTER_REMOVE || result == GDK_FILTER_TRANSLATE)
2356 if (msg->message == client_message)
2359 GdkFilterReturn result = GDK_FILTER_CONTINUE;
2362 GDK_NOTE (EVENTS, g_print (" client_message"));
2364 event = gdk_event_new (GDK_NOTHING);
2365 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2367 node = _gdk_event_queue_append (_gdk_display, event);
2369 tmp_list = client_filters;
2372 GdkClientFilter *filter = tmp_list->data;
2374 tmp_list = tmp_list->next;
2376 if (filter->type == GDK_POINTER_TO_ATOM (msg->wParam))
2378 GDK_NOTE (EVENTS, g_print (" (match)"));
2380 result = (*filter->function) (msg, event, filter->data);
2382 if (result != GDK_FILTER_CONTINUE)
2389 case GDK_FILTER_REMOVE:
2390 _gdk_event_queue_remove_link (_gdk_display, node);
2391 g_list_free_1 (node);
2392 gdk_event_free (event);
2396 case GDK_FILTER_TRANSLATE:
2397 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2398 GDK_NOTE (EVENTS, print_event (event));
2402 case GDK_FILTER_CONTINUE:
2403 /* Send unknown client messages on to Gtk for it to use */
2405 event->client.type = GDK_CLIENT_EVENT;
2406 event->client.window = window;
2407 event->client.message_type = GDK_POINTER_TO_ATOM (msg->wParam);
2408 event->client.data_format = 32;
2409 event->client.data.l[0] = msg->lParam;
2410 for (i = 1; i < 5; i++)
2411 event->client.data.l[i] = 0;
2412 GDK_NOTE (EVENTS, print_event (event));
2418 switch (msg->message)
2420 case WM_INPUTLANGCHANGE:
2421 _gdk_input_locale = (HKL) msg->lParam;
2422 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
2423 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
2424 LOCALE_IDEFAULTANSICODEPAGE,
2426 _gdk_input_codepage = atoi (buf);
2427 _gdk_keymap_serial++;
2429 g_print (" cs:%lu hkl:%p%s cp:%d",
2430 (gulong) msg->wParam,
2431 (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
2432 _gdk_input_codepage));
2438 g_print (" %s ch:%.02x %s",
2439 _gdk_win32_key_to_string (msg->lParam),
2441 decode_key_lparam (msg->lParam)));
2443 /* If posted without us having keyboard focus, ignore */
2444 if ((msg->wParam != VK_F10 && msg->wParam != VK_MENU) &&
2445 !(HIWORD (msg->lParam) & KF_ALTDOWN))
2448 /* Let the system handle Alt-Tab, Alt-Space and Alt-F4 unless
2449 * the keyboard is grabbed.
2451 if (k_grab_window == NULL &&
2452 (msg->wParam == VK_TAB ||
2453 msg->wParam == VK_SPACE ||
2454 msg->wParam == VK_F4))
2457 /* Jump to code in common with WM_KEYUP and WM_KEYDOWN */
2463 g_print (" %s ch:%.02x %s",
2464 _gdk_win32_key_to_string (msg->lParam),
2466 decode_key_lparam (msg->lParam)));
2470 /* Ignore key messages intended for the IME */
2471 if (msg->wParam == VK_PROCESSKEY ||
2475 if (!propagate (&window, msg,
2476 k_grab_window, k_grab_owner_events, GDK_ALL_EVENTS_MASK,
2477 doesnt_want_key, FALSE))
2480 if (GDK_WINDOW_DESTROYED (window))
2483 event = gdk_event_new ((msg->message == WM_KEYDOWN ||
2484 msg->message == WM_SYSKEYDOWN) ?
2485 GDK_KEY_PRESS : GDK_KEY_RELEASE);
2486 event->key.window = window;
2487 event->key.time = _gdk_win32_get_next_tick (msg->time);
2488 event->key.keyval = GDK_VoidSymbol;
2489 event->key.string = NULL;
2490 event->key.length = 0;
2491 event->key.hardware_keycode = msg->wParam;
2492 if (HIWORD (msg->lParam) & KF_EXTENDED)
2494 switch (msg->wParam)
2497 event->key.hardware_keycode = VK_RCONTROL;
2499 case VK_SHIFT: /* Actually, KF_EXTENDED is not set
2500 * for the right shift key.
2502 event->key.hardware_keycode = VK_RSHIFT;
2505 event->key.hardware_keycode = VK_RMENU;
2509 else if (msg->wParam == VK_SHIFT &&
2510 LOBYTE (HIWORD (msg->lParam)) == _scancode_rshift)
2511 event->key.hardware_keycode = VK_RSHIFT;
2513 API_CALL (GetKeyboardState, (key_state));
2515 /* 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]); */
2517 build_key_event_state (event, key_state);
2519 gdk_keymap_translate_keyboard_state (NULL,
2520 event->key.hardware_keycode,
2526 fill_key_event_string (event);
2528 /* Reset MOD1_MASK if it is the Alt key itself */
2529 if (msg->wParam == VK_MENU)
2530 event->key.state &= ~GDK_MOD1_MASK;
2532 append_event (event);
2538 if (msg->wParam != VK_SPACE)
2540 /* To prevent beeps, don't let DefWindowProcW() be called */
2546 case WM_IME_STARTCOMPOSITION:
2547 in_ime_composition = TRUE;
2550 case WM_IME_ENDCOMPOSITION:
2551 in_ime_composition = FALSE;
2554 case WM_IME_COMPOSITION:
2555 /* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
2556 * applications. Thus, handle WM_IME_COMPOSITION with
2557 * GCS_RESULTSTR instead, fetch the Unicode chars from the IME
2558 * with ImmGetCompositionStringW().
2561 * http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
2563 * http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
2564 * for comments by other people that seems to have the same
2565 * experience. WM_IME_CHAR just gives question marks, apparently
2566 * because of going through some conversion to the current code
2569 * WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
2570 * use WM_IME_COMPOSITION there, too, to simplify the code.
2572 GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
2574 if (!(msg->lParam & GCS_RESULTSTR))
2577 if (!propagate (&window, msg,
2578 k_grab_window, k_grab_owner_events, GDK_ALL_EVENTS_MASK,
2579 doesnt_want_char, FALSE))
2582 if (GDK_WINDOW_DESTROYED (window))
2585 himc = ImmGetContext (msg->hwnd);
2586 ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
2587 wbuf, sizeof (wbuf));
2588 ImmReleaseContext (msg->hwnd, himc);
2592 API_CALL (GetKeyboardState, (key_state));
2594 for (i = 0; i < ccount; i++)
2596 if (((GdkWindowObject *) window)->event_mask & GDK_KEY_PRESS_MASK)
2598 /* Build a key press event */
2599 event = gdk_event_new (GDK_KEY_PRESS);
2600 event->key.window = window;
2601 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2603 append_event (event);
2606 if (((GdkWindowObject *) window)->event_mask & GDK_KEY_RELEASE_MASK)
2608 /* Build a key release event. */
2609 event = gdk_event_new (GDK_KEY_RELEASE);
2610 event->key.window = window;
2611 build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
2613 append_event (event);
2619 case WM_LBUTTONDOWN:
2623 case WM_MBUTTONDOWN:
2627 case WM_RBUTTONDOWN:
2631 case WM_XBUTTONDOWN:
2632 if (HIWORD (msg->wParam) == XBUTTON1)
2639 g_print (" (%d,%d)",
2640 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2642 assign_object (&window, find_window_for_mouse_event (window, msg));
2644 if (p_grab_window != NULL)
2646 GdkWindow *real_window = find_real_window_for_grabbed_mouse_event (window, msg);
2648 if (real_window != current_window)
2649 synthesize_crossing_events (real_window, GDK_CROSSING_NORMAL, msg);
2653 if (window != current_window)
2654 synthesize_crossing_events (window, GDK_CROSSING_NORMAL, msg);
2657 if (!propagate (&window, msg,
2658 p_grab_window, p_grab_owner_events, p_grab_mask,
2659 doesnt_want_button_press, TRUE))
2662 if (GDK_WINDOW_DESTROYED (window))
2665 /* Emulate X11's automatic active grab */
2668 /* No explicit active grab, let's start one automatically */
2669 GDK_NOTE (EVENTS, g_print (" (automatic grab)"));
2670 gdk_pointer_grab (window,
2672 ((GdkWindowObject *) window)->event_mask,
2674 p_grab_automatic = TRUE;
2677 generate_button_event (GDK_BUTTON_PRESS, button,
2678 window, orig_window, msg);
2696 if (HIWORD (msg->wParam) == XBUTTON1)
2703 g_print (" (%d,%d)",
2704 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2706 assign_object (&window, find_window_for_mouse_event (window, msg));
2708 if (p_grab_window != NULL)
2710 GdkWindow *real_window = find_real_window_for_grabbed_mouse_event (window, msg);
2712 if (real_window != current_window)
2713 synthesize_crossing_events (real_window, GDK_CROSSING_NORMAL, msg);
2717 if (window != current_window)
2718 synthesize_crossing_events (window, GDK_CROSSING_NORMAL, msg);
2722 if (((GdkWindowObject *) window)->extension_events != 0 &&
2723 _gdk_input_ignore_core)
2725 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2730 if (!propagate (&window, msg,
2731 p_grab_window, p_grab_owner_events, p_grab_mask,
2732 doesnt_want_button_release, TRUE))
2735 else if (!GDK_WINDOW_DESTROYED (window))
2737 generate_button_event (GDK_BUTTON_RELEASE, button,
2738 window, orig_window, msg);
2741 if (p_grab_window != NULL &&
2743 (msg->wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)) == 0)
2745 /* Terminate automatic grab */
2746 gdk_pointer_ungrab (0);
2754 g_print (" %p (%d,%d)",
2755 (gpointer) msg->wParam,
2756 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2758 /* If we haven't moved, don't create any GDK event. Windows
2759 * sends WM_MOUSEMOVE messages after a new window is shows under
2760 * the mouse, even if the mouse hasn't moved. This disturbs gtk.
2762 if (msg->pt.x + _gdk_offset_x == current_root_x &&
2763 msg->pt.y + _gdk_offset_y == current_root_y)
2766 current_root_x = msg->pt.x + _gdk_offset_x;
2767 current_root_y = msg->pt.y + _gdk_offset_y;
2769 assign_object (&window, find_window_for_mouse_event (window, msg));
2771 if (p_grab_window != NULL)
2773 GdkWindow *real_window = find_real_window_for_grabbed_mouse_event (window, msg);
2775 if (real_window != current_window)
2777 if (p_grab_owner_events)
2779 synthesize_crossing_events (real_window, GDK_CROSSING_NORMAL, msg);
2781 else if (current_window == p_grab_window)
2783 synthesize_leave_event (p_grab_window, msg, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2784 assign_object (¤t_window, _gdk_root);
2786 else if (real_window == p_grab_window)
2788 synthesize_enter_event (p_grab_window, msg, GDK_CROSSING_NORMAL, GDK_NOTIFY_ANCESTOR);
2789 assign_object (¤t_window, p_grab_window);
2795 if (window != current_window)
2796 synthesize_crossing_events (window, GDK_CROSSING_NORMAL, msg);
2799 if (!propagate (&window, msg,
2800 p_grab_window, p_grab_owner_events, p_grab_mask,
2801 doesnt_want_button_motion, TRUE))
2804 if (GDK_WINDOW_DESTROYED (window))
2807 if (window != orig_window)
2808 translate_mouse_coords (orig_window, window, msg);
2810 event = gdk_event_new (GDK_MOTION_NOTIFY);
2811 event->motion.window = window;
2812 event->motion.time = _gdk_win32_get_next_tick (msg->time);
2813 event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam);
2814 event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam);
2815 // gdk_window_get_offsets (window, &xoffset, &yoffset);
2816 event->motion.x += xoffset;
2817 event->motion.y += yoffset;
2818 event->motion.x_root = current_root_x;
2819 event->motion.y_root = current_root_y;
2820 event->motion.axes = NULL;
2821 event->motion.state = build_pointer_event_state (msg);
2822 event->motion.is_hint = FALSE;
2823 event->motion.device = _gdk_display->core_pointer;
2825 append_event (event);
2830 case WM_NCMOUSEMOVE:
2832 g_print (" (%d,%d)",
2833 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
2834 if (current_window != NULL &&
2835 (((GdkWindowObject *) current_window)->event_mask & GDK_LEAVE_NOTIFY_MASK))
2837 synthesize_crossing_events (_gdk_root, GDK_CROSSING_NORMAL, msg);
2843 GDK_NOTE (EVENTS, g_print (" %d (%ld,%ld)",
2844 HIWORD (msg->wParam), msg->pt.x, msg->pt.y));
2846 if (!gdk_win32_handle_table_lookup ((GdkNativeWindow) WindowFromPoint (msg->pt)))
2848 GdkNotifyType detail;
2850 if (GDK_WINDOW_TYPE (current_window) != GDK_WINDOW_CHILD)
2851 detail = GDK_NOTIFY_ANCESTOR;
2853 detail = GDK_NOTIFY_UNKNOWN;
2855 /* we are only interested if we don't know the new window */
2856 synthesize_enter_or_leave_event (current_window, msg,
2857 GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, detail,
2858 current_x, current_y);
2859 assign_object (¤t_window, _gdk_root);
2863 GDK_NOTE (EVENTS, g_print (" (ignored)"));
2869 GDK_NOTE (EVENTS, g_print (" %d", (short) HIWORD (msg->wParam)));
2871 /* WM_MOUSEWHEEL is delivered to the focus window. Work around
2872 * that. Also, the position is in screen coordinates, not client
2873 * coordinates as with the button messages. I love the
2874 * consistency of Windows.
2876 point.x = GET_X_LPARAM (msg->lParam);
2877 point.y = GET_Y_LPARAM (msg->lParam);
2879 if ((hwnd = WindowFromPoint (point)) == NULL)
2883 if ((new_window = gdk_win32_handle_table_lookup ((GdkNativeWindow) msg->hwnd)) == NULL)
2886 if (new_window != window)
2888 assign_object (&window, new_window);
2891 if (!propagate (&window, msg,
2892 p_grab_window, p_grab_owner_events, p_grab_mask,
2893 doesnt_want_scroll, TRUE))
2896 if (GDK_WINDOW_DESTROYED (window))
2899 ScreenToClient (msg->hwnd, &point);
2901 event = gdk_event_new (GDK_SCROLL);
2902 event->scroll.window = window;
2903 event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
2904 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
2905 event->scroll.time = _gdk_win32_get_next_tick (msg->time);
2906 //_gdk_win32_windowing_window_get_offsets (window, &xoffset, &yoffset);
2907 event->scroll.x = (gint16) point.x + xoffset;
2908 event->scroll.y = (gint16) point.y + yoffset;
2909 event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x;
2910 event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y;
2911 event->scroll.state = build_pointer_event_state (msg);
2912 event->scroll.device = _gdk_display->core_pointer;
2914 append_event (event);
2920 /* Just print more debugging information, don't actually handle it. */
2923 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2924 (LOWORD (msg->wParam) == SB_LEFT ? "LEFT" :
2925 (LOWORD (msg->wParam) == SB_RIGHT ? "RIGHT" :
2926 (LOWORD (msg->wParam) == SB_LINELEFT ? "LINELEFT" :
2927 (LOWORD (msg->wParam) == SB_LINERIGHT ? "LINERIGHT" :
2928 (LOWORD (msg->wParam) == SB_PAGELEFT ? "PAGELEFT" :
2929 (LOWORD (msg->wParam) == SB_PAGERIGHT ? "PAGERIGHT" :
2930 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2931 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2933 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2934 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2935 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2939 /* Just print more debugging information, don't actually handle it. */
2942 (LOWORD (msg->wParam) == SB_ENDSCROLL ? "ENDSCROLL" :
2943 (LOWORD (msg->wParam) == SB_BOTTOM ? "BOTTOM" :
2944 (LOWORD (msg->wParam) == SB_TOP ? "TOP" :
2945 (LOWORD (msg->wParam) == SB_LINEDOWN ? "LINDOWN" :
2946 (LOWORD (msg->wParam) == SB_LINEUP ? "LINEUP" :
2947 (LOWORD (msg->wParam) == SB_PAGEDOWN ? "PAGEDOWN" :
2948 (LOWORD (msg->wParam) == SB_PAGEUP ? "PAGEUP" :
2949 (LOWORD (msg->wParam) == SB_THUMBPOSITION ? "THUMBPOSITION" :
2950 (LOWORD (msg->wParam) == SB_THUMBTRACK ? "THUMBTRACK" :
2952 (LOWORD (msg->wParam) == SB_THUMBPOSITION ||
2953 LOWORD (msg->wParam) == SB_THUMBTRACK) ?
2954 (g_print (" %d", HIWORD (msg->wParam)), 0) : 0));
2957 case WM_QUERYNEWPALETTE:
2958 if (gdk_visual_get_system ()->type == GDK_VISUAL_PSEUDO_COLOR)
2960 synthesize_expose_events (window);
2961 update_colors_counter = 0;
2966 case WM_PALETTECHANGED:
2967 GDK_NOTE (EVENTS_OR_COLORMAP, g_print (" %p", (HWND) msg->wParam));
2968 if (gdk_visual_get_system ()->type != GDK_VISUAL_PSEUDO_COLOR)
2973 if (msg->hwnd == (HWND) msg->wParam)
2976 if (++update_colors_counter == 5)
2978 synthesize_expose_events (window);
2979 update_colors_counter = 0;
2983 update_colors (window, TRUE);
2986 case WM_MOUSEACTIVATE:
2990 if (gdk_window_get_window_type (window) == GDK_WINDOW_TEMP
2991 || !((GdkWindowObject *)window)->accept_focus)
2993 *ret_valp = MA_NOACTIVATE;
2997 tmp = _gdk_modal_current ();
3001 if (gdk_window_get_toplevel (window) != tmp)
3003 *ret_valp = MA_NOACTIVATEANDEAT;
3012 if (p_grab_window != NULL && !GDK_WINDOW_DESTROYED (p_grab_window))
3013 generate_grab_broken_event (p_grab_window, FALSE, NULL);
3015 if (k_grab_window != NULL && !GDK_WINDOW_DESTROYED (k_grab_window)
3016 && k_grab_window != p_grab_window)
3017 generate_grab_broken_event (k_grab_window, TRUE, NULL);
3021 if (k_grab_window != NULL && !k_grab_owner_events)
3024 if (!(((GdkWindowObject *) window)->event_mask & GDK_FOCUS_CHANGE_MASK))
3027 if (GDK_WINDOW_DESTROYED (window))
3030 generate_focus_event (window, (msg->message == WM_SETFOCUS));
3035 GDK_NOTE (EVENTS, g_print (" %p", (HANDLE) msg->wParam));
3037 if (GDK_WINDOW_DESTROYED (window))
3045 sync_timer = SetTimer (GDK_WINDOW_HWND (window),
3047 200, sync_timer_proc);
3051 handle_wm_paint (msg, window, FALSE, NULL);
3055 GDK_NOTE (EVENTS, g_print (" %#x %#x",
3056 LOWORD (msg->lParam), HIWORD (msg->lParam)));
3058 if (p_grab_window == NULL && LOWORD (msg->lParam) != HTCLIENT)
3061 if (p_grab_window != NULL && p_grab_cursor != NULL)
3062 hcursor = p_grab_cursor;
3063 else if (!GDK_WINDOW_DESTROYED (window))
3064 hcursor = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl)->hcursor;
3068 if (hcursor != NULL)
3070 GDK_NOTE (EVENTS, g_print (" (SetCursor(%p)", hcursor));
3071 SetCursor (hcursor);
3078 GDK_NOTE (EVENTS, g_print (" %s %s",
3079 (msg->wParam ? "YES" : "NO"),
3080 (msg->lParam == 0 ? "ShowWindow" :
3081 (msg->lParam == SW_OTHERUNZOOM ? "OTHERUNZOOM" :
3082 (msg->lParam == SW_OTHERZOOM ? "OTHERZOOM" :
3083 (msg->lParam == SW_PARENTCLOSING ? "PARENTCLOSING" :
3084 (msg->lParam == SW_PARENTOPENING ? "PARENTOPENING" :
3087 if (!(((GdkWindowObject *) window)->event_mask & GDK_STRUCTURE_MASK))
3090 if (msg->lParam == SW_OTHERUNZOOM ||
3091 msg->lParam == SW_OTHERZOOM)
3094 if (GDK_WINDOW_DESTROYED (window))
3097 event = gdk_event_new (msg->wParam ? GDK_MAP : GDK_UNMAP);
3098 event->any.window = window;
3100 append_event (event);
3102 if (event->any.type == GDK_UNMAP)
3104 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
3106 if (impl->transient_owner && GetForegroundWindow () == GDK_WINDOW_HWND (window))
3108 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3111 if (p_grab_window == window)
3113 gdk_pointer_ungrab (msg->time);
3116 if (k_grab_window == window)
3118 gdk_keyboard_ungrab (msg->time);
3126 switch (msg->wParam)
3130 do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
3138 g_print (" %s %dx%d",
3139 (msg->wParam == SIZE_MAXHIDE ? "MAXHIDE" :
3140 (msg->wParam == SIZE_MAXIMIZED ? "MAXIMIZED" :
3141 (msg->wParam == SIZE_MAXSHOW ? "MAXSHOW" :
3142 (msg->wParam == SIZE_MINIMIZED ? "MINIMIZED" :
3143 (msg->wParam == SIZE_RESTORED ? "RESTORED" : "?"))))),
3144 LOWORD (msg->lParam), HIWORD (msg->lParam)));
3146 if (msg->wParam == SIZE_MINIMIZED)
3148 /* Don't generate any GDK event. This is *not* an UNMAP. */
3150 if (p_grab_window == window)
3151 gdk_pointer_ungrab (msg->time);
3153 if (k_grab_window == window)
3154 gdk_keyboard_ungrab (msg->time);
3156 gdk_synthesize_window_state (window,
3157 GDK_WINDOW_STATE_WITHDRAWN,
3158 GDK_WINDOW_STATE_ICONIFIED);
3159 do_show_window (window, TRUE);
3161 else if ((msg->wParam == SIZE_RESTORED ||
3162 msg->wParam == SIZE_MAXIMIZED) &&
3163 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
3165 GdkWindowState withdrawn_bit =
3166 IsWindowVisible (msg->hwnd) ? GDK_WINDOW_STATE_WITHDRAWN : 0;
3168 if (((GdkWindowObject *) window)->state & GDK_WINDOW_STATE_ICONIFIED)
3169 ensure_stacking_on_unminimize (msg);
3171 if (!GDK_WINDOW_DESTROYED (window))
3172 handle_configure_event (msg, window);
3174 if (msg->wParam == SIZE_RESTORED)
3176 gdk_synthesize_window_state (window,
3177 GDK_WINDOW_STATE_ICONIFIED |
3178 GDK_WINDOW_STATE_MAXIMIZED |
3182 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_TEMP && !GDK_WINDOW_IS_MAPPED (window))
3184 do_show_window (window, FALSE);
3187 else if (msg->wParam == SIZE_MAXIMIZED)
3189 gdk_synthesize_window_state (window,
3190 GDK_WINDOW_STATE_ICONIFIED |
3192 GDK_WINDOW_STATE_MAXIMIZED);
3195 if (((GdkWindowObject *) window)->resize_count > 1)
3196 ((GdkWindowObject *) window)->resize_count -= 1;
3198 if (((GdkWindowObject *) window)->extension_events != 0)
3199 _gdk_input_configure_event (window);
3205 case WM_ENTERSIZEMOVE:
3206 _sizemove_in_progress = TRUE;
3207 modal_timer = SetTimer (NULL, 0, 20, modal_timer_proc);
3210 case WM_EXITSIZEMOVE:
3211 _sizemove_in_progress = FALSE;
3212 KillTimer (NULL, modal_timer);
3215 case WM_ENTERMENULOOP:
3216 _sizemove_in_progress = TRUE;
3217 modal_timer = SetTimer (NULL, 0, 20, modal_timer_proc);
3220 case WM_EXITMENULOOP:
3221 _sizemove_in_progress = FALSE;
3222 KillTimer (NULL, modal_timer);
3225 case WM_WINDOWPOSCHANGING:
3226 GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
3227 g_print (" %s %s %dx%d@%+d%+d now below %p",
3228 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
3229 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
3230 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
3231 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
3232 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
3233 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
3235 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
3236 GetNextWindow (msg->hwnd, GW_HWNDPREV))));
3238 if (GDK_WINDOW_IS_MAPPED (window))
3239 return_val = ensure_stacking_on_window_pos_changing (msg, window);
3242 case WM_WINDOWPOSCHANGED:
3243 windowpos = (WINDOWPOS *) msg->lParam;
3244 GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
3245 _gdk_win32_window_pos_bits_to_string (windowpos->flags),
3246 (windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
3247 (windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
3248 (windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
3249 (windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
3250 (sprintf (buf, "%p", windowpos->hwndInsertAfter),
3252 windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
3254 /* If position and size haven't changed, don't do anything */
3255 if (_sizemove_in_progress &&
3256 (windowpos->flags & SWP_NOMOVE) &&
3257 (windowpos->flags & SWP_NOSIZE))
3260 /* Once we've entered the moving or sizing modal loop, we won't
3261 * return to the main loop until we're done sizing or moving.
3263 if (_sizemove_in_progress &&
3264 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
3265 !GDK_WINDOW_DESTROYED (window))
3267 if (((GdkWindowObject *) window)->event_mask & GDK_STRUCTURE_MASK)
3269 GDK_NOTE (EVENTS, g_print (" do magic"));
3270 if (((GdkWindowObject *) window)->resize_count > 1)
3271 ((GdkWindowObject *) window)->resize_count -= 1;
3273 handle_configure_event (msg, window);
3274 g_main_context_iteration (NULL, FALSE);
3276 /* Dispatch main loop - to realize resizes... */
3277 handle_stuff_while_moving_or_resizing ();
3279 /* Claim as handled, so that WM_SIZE and WM_MOVE are avoided */
3287 GetWindowRect (GDK_WINDOW_HWND (window), &rect);
3288 drag = (RECT *) msg->lParam;
3289 GDK_NOTE (EVENTS, g_print (" %s curr:%s drag:%s",
3290 (msg->wParam == WMSZ_BOTTOM ? "BOTTOM" :
3291 (msg->wParam == WMSZ_BOTTOMLEFT ? "BOTTOMLEFT" :
3292 (msg->wParam == WMSZ_LEFT ? "LEFT" :
3293 (msg->wParam == WMSZ_TOPLEFT ? "TOPLEFT" :
3294 (msg->wParam == WMSZ_TOP ? "TOP" :
3295 (msg->wParam == WMSZ_TOPRIGHT ? "TOPRIGHT" :
3296 (msg->wParam == WMSZ_RIGHT ? "RIGHT" :
3298 (msg->wParam == WMSZ_BOTTOMRIGHT ? "BOTTOMRIGHT" :
3300 _gdk_win32_rect_to_string (&rect),
3301 _gdk_win32_rect_to_string (drag)));
3303 impl = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
3305 if (impl->hint_flags & GDK_HINT_RESIZE_INC)
3307 GDK_NOTE (EVENTS, g_print (" (RESIZE_INC)"));
3308 if (impl->hint_flags & GDK_HINT_BASE_SIZE)
3310 /* Resize in increments relative to the base size */
3311 rect.left = rect.top = 0;
3312 rect.right = impl->hints.base_width;
3313 rect.bottom = impl->hints.base_height;
3314 _gdk_win32_adjust_client_rect (window, &rect);
3315 point.x = rect.left;
3317 ClientToScreen (GDK_WINDOW_HWND (window), &point);
3318 rect.left = point.x;
3320 point.x = rect.right;
3321 point.y = rect.bottom;
3322 ClientToScreen (GDK_WINDOW_HWND (window), &point);
3323 rect.right = point.x;
3324 rect.bottom = point.y;
3326 GDK_NOTE (EVENTS, g_print (" (also BASE_SIZE, using %s)",
3327 _gdk_win32_rect_to_string (&rect)));
3330 switch (msg->wParam)
3333 if (drag->bottom == rect.bottom)
3335 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
3338 case WMSZ_BOTTOMLEFT:
3339 if (drag->bottom == rect.bottom && drag->left == rect.left)
3341 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
3342 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
3346 if (drag->left == rect.left)
3348 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
3352 if (drag->top == rect.top && drag->left == rect.left)
3354 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
3355 adjust_drag (&drag->left, rect.left, impl->hints.width_inc);
3359 if (drag->top == rect.top)
3361 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
3365 if (drag->top == rect.top && drag->right == rect.right)
3367 adjust_drag (&drag->top, rect.top, impl->hints.height_inc);
3368 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
3372 if (drag->right == rect.right)
3374 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
3377 case WMSZ_BOTTOMRIGHT:
3378 if (drag->bottom == rect.bottom && drag->right == rect.right)
3380 adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc);
3381 adjust_drag (&drag->right, rect.right, impl->hints.width_inc);
3385 if (drag->bottom != orig_drag.bottom || drag->left != orig_drag.left ||
3386 drag->top != orig_drag.top || drag->right != orig_drag.right)
3390 GDK_NOTE (EVENTS, g_print (" (handled RESIZE_INC: %s)",
3391 _gdk_win32_rect_to_string (drag)));
3395 /* WM_GETMINMAXINFO handles min_size and max_size hints? */
3397 if (impl->hint_flags & GDK_HINT_ASPECT)
3399 RECT decorated_rect;
3400 RECT undecorated_drag;
3401 int decoration_width, decoration_height;
3402 gdouble drag_aspect;
3403 int drag_width, drag_height, new_width, new_height;
3405 GetClientRect (GDK_WINDOW_HWND (window), &rect);
3406 decorated_rect = rect;
3407 _gdk_win32_adjust_client_rect (window, &decorated_rect);
3409 /* Set undecorated_drag to the client area being dragged
3410 * out, in screen coordinates.
3412 undecorated_drag = *drag;
3413 undecorated_drag.left -= decorated_rect.left - rect.left;
3414 undecorated_drag.right -= decorated_rect.right - rect.right;
3415 undecorated_drag.top -= decorated_rect.top - rect.top;
3416 undecorated_drag.bottom -= decorated_rect.bottom - rect.bottom;
3418 decoration_width = (decorated_rect.right - decorated_rect.left) - (rect.right - rect.left);
3419 decoration_height = (decorated_rect.bottom - decorated_rect.top) - (rect.bottom - rect.top);
3421 drag_width = undecorated_drag.right - undecorated_drag.left;
3422 drag_height = undecorated_drag.bottom - undecorated_drag.top;
3424 drag_aspect = (gdouble) drag_width / drag_height;
3426 GDK_NOTE (EVENTS, g_print (" (ASPECT:%g--%g curr: %g)",
3427 impl->hints.min_aspect, impl->hints.max_aspect, drag_aspect));
3429 if (drag_aspect < impl->hints.min_aspect)
3431 /* Aspect is getting too narrow */
3432 switch (msg->wParam)
3436 /* User drags top or bottom edge outward. Keep height, increase width. */
3437 new_width = impl->hints.min_aspect * drag_height;
3438 drag->left -= (new_width - drag_width) / 2;
3439 drag->right = drag->left + new_width + decoration_width;
3441 case WMSZ_BOTTOMLEFT:
3442 case WMSZ_BOTTOMRIGHT:
3443 /* User drags bottom-left or bottom-right corner down. Adjust height. */
3444 new_height = drag_width / impl->hints.min_aspect;
3445 drag->bottom = drag->top + new_height + decoration_height;
3449 /* User drags left or right edge inward. Decrease height */
3450 new_height = drag_width / impl->hints.min_aspect;
3451 drag->top += (drag_height - new_height) / 2;
3452 drag->bottom = drag->top + new_height + decoration_height;
3456 /* User drags top-left or top-right corner up. Adjust height. */
3457 new_height = drag_width / impl->hints.min_aspect;
3458 drag->top = drag->bottom - new_height - decoration_height;
3461 else if (drag_aspect > impl->hints.max_aspect)
3463 /* Aspect is getting too wide */
3464 switch (msg->wParam)
3468 /* User drags top or bottom edge inward. Decrease width. */
3469 new_width = impl->hints.max_aspect * drag_height;
3470 drag->left += (drag_width - new_width) / 2;
3471 drag->right = drag->left + new_width + decoration_width;
3473 case WMSZ_BOTTOMLEFT:
3475 /* User drags bottom-left or top-left corner left. Adjust width. */
3476 new_width = impl->hints.max_aspect * drag_height;
3477 drag->left = drag->right - new_width - decoration_width;
3479 case WMSZ_BOTTOMRIGHT:
3481 /* User drags bottom-right or top-right corner right. Adjust width. */
3482 new_width = impl->hints.max_aspect * drag_height;
3483 drag->right = drag->left + new_width + decoration_width;
3487 /* User drags left or right edge outward. Increase height. */
3488 new_height = drag_width / impl->hints.max_aspect;
3489 drag->top -= (new_height - drag_height) / 2;
3490 drag->bottom = drag->top + new_height + decoration_height;
3497 GDK_NOTE (EVENTS, g_print (" (handled ASPECT: %s)",
3498 _gdk_win32_rect_to_string (drag)));
3502 case WM_GETMINMAXINFO:
3503 if (GDK_WINDOW_DESTROYED (window))
3506 impl = GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl);
3507 mmi = (MINMAXINFO*) msg->lParam;
3508 GDK_NOTE (EVENTS, g_print (" (mintrack:%ldx%ld maxtrack:%ldx%ld "
3509 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3510 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3511 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3512 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3513 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3515 if (impl->hint_flags & GDK_HINT_MIN_SIZE)
3517 rect.left = rect.top = 0;
3518 rect.right = impl->hints.min_width;
3519 rect.bottom = impl->hints.min_height;
3521 _gdk_win32_adjust_client_rect (window, &rect);
3523 mmi->ptMinTrackSize.x = rect.right - rect.left;
3524 mmi->ptMinTrackSize.y = rect.bottom - rect.top;
3527 if (impl->hint_flags & GDK_HINT_MAX_SIZE)
3531 rect.left = rect.top = 0;
3532 rect.right = impl->hints.max_width;
3533 rect.bottom = impl->hints.max_height;
3535 _gdk_win32_adjust_client_rect (window, &rect);
3537 /* at least on win9x we have the 16 bit trouble */
3538 maxw = rect.right - rect.left;
3539 maxh = rect.bottom - rect.top;
3540 mmi->ptMaxTrackSize.x = maxw > 0 && maxw < G_MAXSHORT ? maxw : G_MAXSHORT;
3541 mmi->ptMaxTrackSize.y = maxh > 0 && maxh < G_MAXSHORT ? maxh : G_MAXSHORT;
3544 if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))
3546 /* Don't call DefWindowProcW() */
3547 GDK_NOTE (EVENTS, g_print (" (handled, mintrack:%ldx%ld maxtrack:%ldx%ld "
3548 "maxpos:%+ld%+ld maxsize:%ldx%ld)",
3549 mmi->ptMinTrackSize.x, mmi->ptMinTrackSize.y,
3550 mmi->ptMaxTrackSize.x, mmi->ptMaxTrackSize.y,
3551 mmi->ptMaxPosition.x, mmi->ptMaxPosition.y,
3552 mmi->ptMaxSize.x, mmi->ptMaxSize.y));
3558 GDK_NOTE (EVENTS, g_print (" (%d,%d)",
3559 GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam)));
3561 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
3562 !IsIconic (msg->hwnd))
3564 if (!GDK_WINDOW_DESTROYED (window))
3565 handle_configure_event (msg, window);
3572 if (GDK_WINDOW_DESTROYED (window))
3575 event = gdk_event_new (GDK_DELETE);
3576 event->any.window = window;
3578 append_event (event);
3580 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
3582 if (impl->transient_owner && GetForegroundWindow() == GDK_WINDOW_HWND (window))
3584 SetForegroundWindow (GDK_WINDOW_HWND (impl->transient_owner));
3591 if (window == current_window)
3592 assign_object (¤t_window, _gdk_root);
3594 if (p_grab_window == window)
3595 gdk_pointer_ungrab (msg->time);
3597 if (k_grab_window == window)
3598 gdk_keyboard_ungrab (msg->time);
3600 if ((window != NULL) && (msg->hwnd != GetDesktopWindow ()))
3601 gdk_window_destroy_notify (window);
3603 if (window == NULL || GDK_WINDOW_DESTROYED (window))
3606 event = gdk_event_new (GDK_DESTROY);
3607 event->any.window = window;
3609 append_event (event);
3614 case WM_DISPLAYCHANGE:
3615 handle_display_change ();
3618 case WM_DESTROYCLIPBOARD:
3619 if (!_ignore_destroy_clipboard)
3621 event = gdk_event_new (GDK_SELECTION_CLEAR);
3622 event->selection.window = window;
3623 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3624 event->selection.time = _gdk_win32_get_next_tick (msg->time);
3625 append_event (event);
3634 case WM_RENDERFORMAT:
3635 GDK_NOTE (EVENTS, g_print (" %s", _gdk_win32_cf_to_string (msg->wParam)));
3637 if (!(target = g_hash_table_lookup (_format_atom_table, GINT_TO_POINTER (msg->wParam))))
3639 GDK_NOTE (EVENTS, g_print (" (target not found)"));
3644 /* We need to render to clipboard immediately, don't call
3647 if (_gdk_event_func)
3649 event = gdk_event_new (GDK_SELECTION_REQUEST);
3650 event->selection.window = window;
3651 event->selection.send_event = FALSE;
3652 event->selection.selection = GDK_SELECTION_CLIPBOARD;
3653 event->selection.target = target;
3654 event->selection.property = _gdk_selection;
3655 event->selection.requestor = msg->hwnd;
3656 event->selection.time = msg->time;
3658 fixup_event (event);
3659 GDK_NOTE (EVENTS, g_print (" (calling gdk_event_func)"));
3660 GDK_NOTE (EVENTS, print_event (event));
3661 (*_gdk_event_func) (event, _gdk_event_data);
3662 gdk_event_free (event);
3664 /* Now the clipboard owner should have rendered */
3665 if (!_delayed_rendering_data)
3667 GDK_NOTE (EVENTS, g_print (" (no _delayed_rendering_data?)"));
3671 if (msg->wParam == CF_DIB)
3673 _delayed_rendering_data =
3674 _gdk_win32_selection_convert_to_dib (_delayed_rendering_data,
3676 if (!_delayed_rendering_data)
3678 g_warning ("Cannot convert to DIB from delayed rendered image");
3683 /* The requestor is holding the clipboard, no
3684 * OpenClipboard() is required/possible
3687 g_print (" SetClipboardData(%s,%p)",
3688 _gdk_win32_cf_to_string (msg->wParam),
3689 _delayed_rendering_data));
3691 API_CALL (SetClipboardData, (msg->wParam, _delayed_rendering_data));
3692 _delayed_rendering_data = NULL;
3698 GDK_NOTE (EVENTS, g_print (" %s%s %p",
3699 (LOWORD (msg->wParam) == WA_ACTIVE ? "ACTIVE" :
3700 (LOWORD (msg->wParam) == WA_CLICKACTIVE ? "CLICKACTIVE" :
3701 (LOWORD (msg->wParam) == WA_INACTIVE ? "INACTIVE" : "???"))),
3702 HIWORD (msg->wParam) ? " minimized" : "",
3703 (HWND) msg->lParam));
3704 /* We handle mouse clicks for modally-blocked windows under WM_MOUSEACTIVATE,
3705 * but we still need to deal with alt-tab, or with SetActiveWindow() type
3708 if (is_modally_blocked (window) && LOWORD (msg->wParam) == WA_ACTIVE)
3710 GdkWindow *modal_current = _gdk_modal_current ();
3711 SetActiveWindow (GDK_WINDOW_HWND (modal_current));
3717 /* Bring any tablet contexts to the top of the overlap order when
3718 * one of our windows is activated.
3719 * NOTE: It doesn't seem to work well if it is done in WM_ACTIVATEAPP
3722 if (LOWORD(msg->wParam) != WA_INACTIVE)
3723 _gdk_input_set_tablet_active ();
3726 case WM_ACTIVATEAPP:
3727 GDK_NOTE (EVENTS, g_print (" %s thread: %I64d",
3728 msg->wParam ? "YES" : "NO",
3729 (gint64) msg->lParam));
3730 if (msg->wParam && GDK_WINDOW_IS_MAPPED (window))
3731 ensure_stacking_on_activate_app (msg, window);
3734 /* Handle WINTAB events here, as we know that gdkinput.c will
3735 * use the fixed WT_DEFBASE as lcMsgBase, and we thus can use the
3736 * constants as case labels.
3739 GDK_NOTE (EVENTS, g_print (" %d %p",
3740 (int) msg->wParam, (gpointer) msg->lParam));
3744 GDK_NOTE (EVENTS, g_print (" %d %p",
3745 (int) msg->wParam, (gpointer) msg->lParam));
3749 GDK_NOTE (EVENTS, g_print (" %p %d %d",
3750 (gpointer) msg->wParam,
3751 LOWORD (msg->lParam),
3752 HIWORD (msg->lParam)));
3756 event = gdk_event_new (GDK_NOTHING);
3757 event->any.window = window;
3758 g_object_ref (window);
3760 if (_gdk_input_other_event (event, msg, window))
3761 append_event (event);
3763 gdk_event_free (event);
3771 g_object_unref (window);
3778 _gdk_events_queue (GdkDisplay *display)
3782 if (modal_win32_dialog != NULL)
3785 while (!_gdk_event_queue_find_first (display) &&
3786 PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3788 TranslateMessage (&msg);
3789 DispatchMessageW (&msg);
3794 gdk_event_prepare (GSource *source,
3800 GDK_THREADS_ENTER ();
3804 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3805 (modal_win32_dialog == NULL &&
3806 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3808 GDK_THREADS_LEAVE ();
3814 gdk_event_check (GSource *source)
3819 GDK_THREADS_ENTER ();
3821 if (event_poll_fd.revents & G_IO_IN)
3823 retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
3824 (modal_win32_dialog == NULL &&
3825 PeekMessageW (&msg, NULL, 0, 0, PM_NOREMOVE)));
3832 GDK_THREADS_LEAVE ();
3838 gdk_event_dispatch (GSource *source,
3839 GSourceFunc callback,
3844 GDK_THREADS_ENTER ();
3846 _gdk_events_queue (_gdk_display);
3847 event = _gdk_event_unqueue (_gdk_display);
3851 if (_gdk_event_func)
3852 (*_gdk_event_func) (event, _gdk_event_data);
3854 gdk_event_free (event);
3857 GDK_THREADS_LEAVE ();
3863 gdk_win32_set_modal_dialog_libgtk_only (HWND window)
3865 modal_win32_dialog = window;
3869 is_modally_blocked (GdkWindow *window)
3871 GdkWindow *modal_current = _gdk_modal_current ();
3872 return modal_current != NULL ? gdk_window_get_toplevel (window) != modal_current : FALSE;
3876 check_for_too_much_data (GdkEvent *event)
3878 if (event->client.data.l[1] ||
3879 event->client.data.l[2] ||
3880 event->client.data.l[3] ||
3881 event->client.data.l[4])
3883 g_warning ("Only four bytes of data are passed in client messages on Win32\n");
3888 gdk_event_send_client_message_for_display (GdkDisplay *display,
3890 GdkNativeWindow winid)
3892 check_for_too_much_data (event);
3894 return PostMessageW ((HWND) winid, client_message,
3895 (WPARAM) event->client.message_type,
3896 event->client.data.l[0]);
3900 gdk_screen_broadcast_client_message (GdkScreen *screen,
3903 check_for_too_much_data (event);
3905 PostMessageW (HWND_BROADCAST, client_message,
3906 (WPARAM) event->client.message_type,
3907 event->client.data.l[0]);
3916 /* Process all messages currently available */
3917 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3919 TranslateMessage (&msg);
3920 DispatchMessageW (&msg);
3928 gdk_display_sync (GdkDisplay * display)
3932 g_return_if_fail (display == _gdk_display);
3934 /* Process all messages currently available */
3935 while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE))
3936 DispatchMessageW (&msg);
3940 gdk_display_flush (GdkDisplay * display)
3942 g_return_if_fail (display == _gdk_display);
3948 gdk_net_wm_supports (GdkAtom property)
3954 _gdk_windowing_event_data_copy (const GdkEvent *src,
3960 _gdk_windowing_event_data_free (GdkEvent *event)