1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 #include <gdk/gdkwindow.h>
25 #include "gdkdisplayprivate.h"
26 #include "gdkdevice-win32.h"
29 static gboolean gdk_device_win32_get_history (GdkDevice *device,
33 GdkTimeCoord ***events,
35 static void gdk_device_win32_get_state (GdkDevice *device,
38 GdkModifierType *mask);
39 static void gdk_device_win32_set_window_cursor (GdkDevice *device,
42 static void gdk_device_win32_warp (GdkDevice *device,
46 static void gdk_device_win32_query_state (GdkDevice *device,
48 GdkWindow **root_window,
49 GdkWindow **child_window,
54 GdkModifierType *mask);
55 static GdkGrabStatus gdk_device_win32_grab (GdkDevice *device,
57 gboolean owner_events,
58 GdkEventMask event_mask,
59 GdkWindow *confine_to,
62 static void gdk_device_win32_ungrab (GdkDevice *device,
64 static GdkWindow * gdk_device_win32_window_at_position (GdkDevice *device,
67 GdkModifierType *mask,
68 gboolean get_toplevel);
69 static void gdk_device_win32_select_window_events (GdkDevice *device,
71 GdkEventMask event_mask);
74 G_DEFINE_TYPE (GdkDeviceWin32, gdk_device_win32, GDK_TYPE_DEVICE)
77 gdk_device_win32_class_init (GdkDeviceWin32Class *klass)
79 GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
81 device_class->get_history = gdk_device_win32_get_history;
82 device_class->get_state = gdk_device_win32_get_state;
83 device_class->set_window_cursor = gdk_device_win32_set_window_cursor;
84 device_class->warp = gdk_device_win32_warp;
85 device_class->query_state = gdk_device_win32_query_state;
86 device_class->grab = gdk_device_win32_grab;
87 device_class->ungrab = gdk_device_win32_ungrab;
88 device_class->window_at_position = gdk_device_win32_window_at_position;
89 device_class->select_window_events = gdk_device_win32_select_window_events;
93 gdk_device_win32_init (GdkDeviceWin32 *device_win32)
97 device = GDK_DEVICE (device_win32);
99 _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1);
100 _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1);
104 gdk_device_win32_get_history (GdkDevice *device,
108 GdkTimeCoord ***events,
115 gdk_device_win32_get_state (GdkDevice *device,
118 GdkModifierType *mask)
122 gdk_window_get_pointer (window, &x_int, &y_int, mask);
132 gdk_device_win32_set_window_cursor (GdkDevice *device,
139 gdk_device_win32_warp (GdkDevice *device,
146 static GdkModifierType
147 get_current_mask (void)
149 GdkModifierType mask;
152 GetKeyboardState (kbd);
154 if (kbd[VK_SHIFT] & 0x80)
155 mask |= GDK_SHIFT_MASK;
156 if (kbd[VK_CAPITAL] & 0x80)
157 mask |= GDK_LOCK_MASK;
158 if (kbd[VK_CONTROL] & 0x80)
159 mask |= GDK_CONTROL_MASK;
160 if (kbd[VK_MENU] & 0x80)
161 mask |= GDK_MOD1_MASK;
162 if (kbd[VK_LBUTTON] & 0x80)
163 mask |= GDK_BUTTON1_MASK;
164 if (kbd[VK_MBUTTON] & 0x80)
165 mask |= GDK_BUTTON2_MASK;
166 if (kbd[VK_RBUTTON] & 0x80)
167 mask |= GDK_BUTTON3_MASK;
173 gdk_device_win32_query_state (GdkDevice *device,
175 GdkWindow **root_window,
176 GdkWindow **child_window,
181 GdkModifierType *mask)
186 hwnd = GDK_WINDOW_HWND (window);
187 GetCursorPos (&point);
195 ScreenToClient (hwnd, &point);
203 if (window == _gdk_root)
206 *win_x += _gdk_offset_x;
209 *win_y += _gdk_offset_y;
214 hwndc = ChildWindowFromPoint (hwnd, point);
216 if (hwndc && hwndc != hwnd)
217 *child_window = gdk_win32_handle_table_lookup (hwndc);
219 *child_window = NULL; /* Direct child unknown to gdk */
226 screen = gdk_window_get_screen (window);
227 *root_window = gdk_screen_get_root_window (screen);
231 *mask = get_current_mask ();
235 gdk_device_win32_grab (GdkDevice *device,
237 gboolean owner_events,
238 GdkEventMask event_mask,
239 GdkWindow *confine_to,
243 /* No support for grabbing the slave atm */
244 return GDK_GRAB_NOT_VIEWABLE;
248 gdk_device_win32_ungrab (GdkDevice *device,
254 screen_to_client (HWND hwnd, POINT screen_pt, POINT *client_pt)
256 *client_pt = screen_pt;
257 ScreenToClient (hwnd, client_pt);
261 gdk_device_win32_window_at_position (GdkDevice *device,
264 GdkModifierType *mask,
265 gboolean get_toplevel)
267 GdkWindow *window = NULL;
268 POINT screen_pt, client_pt;
272 GetCursorPos (&screen_pt);
276 /* Only consider visible children of the desktop to avoid the various
277 * non-visible windows you often find on a running Windows box. These
278 * might overlap our windows and cause our walk to fail. As we assume
279 * WindowFromPoint() can find our windows, we follow similar logic
280 * here, and ignore invisible and disabled windows.
282 hwnd = GetDesktopWindow ();
284 window = gdk_win32_handle_table_lookup (hwnd);
286 if (window != NULL &&
287 GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT &&
288 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
291 screen_to_client (hwnd, screen_pt, &client_pt);
292 hwndc = ChildWindowFromPointEx (hwnd, client_pt, CWP_SKIPDISABLED |
295 /* Verify that we're really inside the client area of the window */
298 GetClientRect (hwndc, &rect);
299 screen_to_client (hwndc, screen_pt, &client_pt);
300 if (!PtInRect (&rect, client_pt))
304 } while (hwndc != hwnd && (hwnd = hwndc, 1));
309 hwnd = WindowFromPoint (screen_pt);
311 /* Verify that we're really inside the client area of the window */
312 GetClientRect (hwnd, &rect);
313 screen_to_client (hwnd, screen_pt, &client_pt);
314 if (!PtInRect (&rect, client_pt))
317 /* If we didn't hit any window at that point, return the desktop */
321 *win_x = screen_pt.x + _gdk_offset_x;
323 *win_y = screen_pt.y + _gdk_offset_y;
327 window = gdk_win32_handle_table_lookup (hwnd);
330 if (window && (win_x || win_y))
333 *win_x = client_pt.x;
335 *win_y = client_pt.y;
342 gdk_device_win32_select_window_events (GdkDevice *device,
344 GdkEventMask event_mask)