Debian Codegraph @

gdk/win32/gdkdevice-win32.c

raw symbols SCIP
1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 2009 Carlos Garnacho <[email protected]>
3 *
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.
8 *
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.
13 *
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/>.
16 */
17
18 #include "config.h"
19
20 #include <gdk/gdksurface.h>
21
22 #include <windowsx.h>
23 #include <objbase.h>
24 #include <math.h>
25
26 #include "gdkdevice-win32.h"
27 #include "gdkwin32.h"
28 #include "gdkdisplay-win32.h"
29 #include "gdkdevice-virtual.h"
30 #include "gdkdevice-wintab.h"
31
32 G_DEFINE_TYPE (GdkDeviceWin32, gdk_device_win32, GDK_TYPE_DEVICE)
33
34 static void
35 gdk_device_win32_set_surface_cursor (GdkDevice *device,
36 GdkSurface *surface,
37 GdkCursor *cursor)
38 {
39 }
40
41 static GdkModifierType
42 get_current_mask (void)
43 {
44 GdkModifierType mask;
45 BYTE kbd[256];
46
47 GetKeyboardState (kbd);
48 mask = 0;
49 if (kbd[VK_SHIFT] & 0x80)
50 mask |= GDK_SHIFT_MASK;
51 if (kbd[VK_CAPITAL] & 0x80)
52 mask |= GDK_LOCK_MASK;
53 if (kbd[VK_CONTROL] & 0x80)
54 mask |= GDK_CONTROL_MASK;
55 if (kbd[VK_MENU] & 0x80)
56 mask |= GDK_ALT_MASK;
57 if (kbd[VK_LBUTTON] & 0x80)
58 mask |= GDK_BUTTON1_MASK;
59 if (kbd[VK_MBUTTON] & 0x80)
60 mask |= GDK_BUTTON2_MASK;
61 if (kbd[VK_RBUTTON] & 0x80)
62 mask |= GDK_BUTTON3_MASK;
63
64 return mask;
65 }
66
67 static void
68 gdk_device_win32_query_state (GdkDevice *device,
69 GdkSurface *surface,
70 GdkSurface **child_surface,
71 double *win_x,
72 double *win_y,
73 GdkModifierType *mask)
74 {
75 POINT point;
76 HWND hwnd, hwndc;
77 int scale;
78 GdkDisplay *display = gdk_device_get_display (device);
79
80 if (surface)
81 {
82 scale = GDK_WIN32_SURFACE (surface)->surface_scale;
83 hwnd = GDK_SURFACE_HWND (surface);
84 }
85 else
86 {
87 scale = GDK_WIN32_DISPLAY (display)->surface_scale;
88 hwnd = NULL;
89 }
90
91 _gdk_win32_get_cursor_pos (display, &point);
92
93 if (hwnd)
94 ScreenToClient (hwnd, &point);
95
96 if (win_x)
97 *win_x = point.x / scale;
98
99 if (win_y)
100 *win_y = point.y / scale;
101
102 if (hwnd && child_surface)
103 {
104 hwndc = ChildWindowFromPoint (hwnd, point);
105
106 if (hwndc && hwndc != hwnd)
107 *child_surface = gdk_win32_display_handle_table_lookup_ (display, hwndc);
108 else
109 *child_surface = NULL; /* Direct child unknown to gdk */
110 }
111
112 if (mask)
113 *mask = get_current_mask ();
114 }
115
116 void
117 _gdk_device_win32_query_state (GdkDevice *device,
118 GdkSurface *surface,
119 GdkSurface **child_surface,
120 double *win_x,
121 double *win_y,
122 GdkModifierType *mask)
123 {
124 if (GDK_IS_DEVICE_VIRTUAL (device))
125 gdk_device_virtual_query_state (device, surface, child_surface, win_x, win_y, mask);
126 else if (GDK_IS_DEVICE_WINTAB (device))
127 gdk_device_wintab_query_state (device, surface, child_surface, win_x, win_y, mask);
128 else
129 gdk_device_win32_query_state (device, surface, child_surface, win_x, win_y, mask);
130 }
131
132 static GdkGrabStatus
133 gdk_device_win32_grab (GdkDevice *device,
134 GdkSurface *surface,
135 gboolean owner_events,
136 GdkEventMask event_mask,
137 GdkSurface *confine_to,
138 GdkCursor *cursor,
139 guint32 time_)
140 {
141 /* No support for grabbing physical devices atm */
142 return GDK_GRAB_NOT_VIEWABLE;
143 }
144
145 static void
146 gdk_device_win32_ungrab (GdkDevice *device,
147 guint32 time_)
148 {
149 }
150
151 static void
152 screen_to_client (HWND hwnd, POINT screen_pt, POINT *client_pt)
153 {
154 *client_pt = screen_pt;
155 ScreenToClient (hwnd, client_pt);
156 }
157
158 GdkSurface *
159 _gdk_device_win32_surface_at_position (GdkDevice *device,
160 double *win_x,
161 double *win_y,
162 GdkModifierType *mask)
163 {
164 GdkSurface *surface = NULL;
165 GdkWin32Surface *impl = NULL;
166 POINT screen_pt, client_pt;
167 HWND hwnd;
168 RECT rect;
169 GdkDisplay *display = gdk_device_get_display (device);
170
171 if (!_gdk_win32_get_cursor_pos (display, &screen_pt))
172 return NULL;
173
174 /* Use WindowFromPoint instead of ChildWindowFromPoint(Ex).
175 * Only WindowFromPoint is able to look through transparent
176 * layered HWNDs.
177 */
178 hwnd = GetAncestor (WindowFromPoint (screen_pt), GA_ROOT);
179
180 /* Verify that we're really inside the client area of the HWND */
181 GetClientRect (hwnd, &rect);
182 screen_to_client (hwnd, screen_pt, &client_pt);
183 if (!PtInRect (&rect, client_pt))
184 hwnd = NULL;
185
186 surface = gdk_win32_display_handle_table_lookup_ (display, hwnd);
187
188 if (surface && (win_x || win_y))
189 {
190 impl = GDK_WIN32_SURFACE (surface);
191
192 if (win_x)
193 *win_x = client_pt.x / impl->surface_scale;
194 if (win_y)
195 *win_y = client_pt.y / impl->surface_scale;
196 }
197
198 return surface;
199 }
200
201 static void
202 gdk_device_win32_class_init (GdkDeviceWin32Class *klass)
203 {
204 GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
205
206 device_class->set_surface_cursor = gdk_device_win32_set_surface_cursor;
207 device_class->grab = gdk_device_win32_grab;
208 device_class->ungrab = gdk_device_win32_ungrab;
209 device_class->surface_at_position = _gdk_device_win32_surface_at_position;
210 }
211
212 static void
213 gdk_device_win32_init (GdkDeviceWin32 *device_win32)
214 {
215 GdkDevice *device;
216
217 device = GDK_DEVICE (device_win32);
218
219 _gdk_device_add_axis (device, GDK_AXIS_X, 0, 0, 1);
220 _gdk_device_add_axis (device, GDK_AXIS_Y, 0, 0, 1);
221 }