Debian Codegraph @

gdk/win32/gdkdevice-wintab.c

raw
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/gdkwindow.h>
21
22 #include <windowsx.h>
23 #include <objbase.h>
24
25 #include "gdkwin32.h"
26 #include "gdkdevice-wintab.h"
27
28 G_DEFINE_TYPE (GdkDeviceWintab, gdk_device_wintab, GDK_TYPE_DEVICE)
29
30 static gboolean
31 gdk_device_wintab_get_history (GdkDevice *device,
32 GdkWindow *window,
33 guint32 start,
34 guint32 stop,
35 GdkTimeCoord ***events,
36 gint *n_events)
37 {
38 return FALSE;
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_MOD1_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_wintab_get_state (GdkDevice *device,
69 GdkWindow *window,
70 gdouble *axes,
71 GdkModifierType *mask)
72 {
73 GdkDeviceWintab *device_wintab;
74
75 device_wintab = GDK_DEVICE_WINTAB (device);
76
77 /* For now just use the last known button and axis state of the device.
78 * Since graphical tablets send an insane amount of motion events each
79 * second, the info should be fairly up to date */
80 if (mask)
81 {
82 *mask = get_current_mask ();
83 *mask &= 0xFF; /* Mask away core pointer buttons */
84 *mask |= ((device_wintab->button_state << 8)
85 & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK
86 | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK
87 | GDK_BUTTON5_MASK));
88 }
89
90 if (axes && device_wintab->last_axis_data)
91 _gdk_device_wintab_translate_axes (device_wintab, window, axes, NULL, NULL);
92 }
93
94 static void
95 gdk_device_wintab_set_window_cursor (GdkDevice *device,
96 GdkWindow *window,
97 GdkCursor *cursor)
98 {
99 }
100
101 static void
102 gdk_device_wintab_warp (GdkDevice *device,
103 GdkScreen *screen,
104 gdouble x,
105 gdouble y)
106 {
107 }
108
109 static void
110 gdk_device_wintab_query_state (GdkDevice *device,
111 GdkWindow *window,
112 GdkWindow **root_window,
113 GdkWindow **child_window,
114 gdouble *root_x,
115 gdouble *root_y,
116 gdouble *win_x,
117 gdouble *win_y,
118 GdkModifierType *mask)
119 {
120 GdkDeviceWintab *device_wintab;
121 GdkScreen *screen;
122 POINT point;
123 HWND hwnd, hwndc;
124 GdkWindowImplWin32 *impl;
125
126 device_wintab = GDK_DEVICE_WINTAB (device);
127 screen = gdk_window_get_screen (window);
128 impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
129
130 hwnd = GDK_WINDOW_HWND (window);
131 _gdk_win32_get_cursor_pos (&point);
132
133 if (root_x)
134 *root_x = (point.x + _gdk_offset_x) / impl->window_scale;
135
136 if (root_y)
137 *root_y = (point.y + _gdk_offset_y) / impl->window_scale;
138
139 if (window == gdk_screen_get_root_window (screen))
140 {
141 if (win_x)
142 *win_x = (point.x + _gdk_offset_x) / impl->window_scale;
143
144 if (win_y)
145 *win_y = (point.y + _gdk_offset_y) / impl->window_scale;
146 }
147 else
148 {
149 ScreenToClient (hwnd, &point);
150
151 if (win_x)
152 *win_x = point.x / impl->window_scale;
153
154 if (win_y)
155 *win_y = point.y / impl->window_scale;
156 }
157
158 if (child_window)
159 {
160 hwndc = ChildWindowFromPoint (hwnd, point);
161
162 if (hwndc && hwndc != hwnd)
163 *child_window = gdk_win32_handle_table_lookup (hwndc);
164 else
165 *child_window = NULL; /* Direct child unknown to gdk */
166 }
167
168 if (root_window)
169 *root_window = gdk_screen_get_root_window (screen);
170
171 if (mask)
172 {
173 *mask = get_current_mask ();
174 *mask &= 0xFF; /* Mask away core pointer buttons */
175 *mask |= ((device_wintab->button_state << 8)
176 & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK
177 | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK
178 | GDK_BUTTON5_MASK));
179
180 }
181 }
182
183 static GdkGrabStatus
184 gdk_device_wintab_grab (GdkDevice *device,
185 GdkWindow *window,
186 gboolean owner_events,
187 GdkEventMask event_mask,
188 GdkWindow *confine_to,
189 GdkCursor *cursor,
190 guint32 time_)
191 {
192 return GDK_GRAB_SUCCESS;
193 }
194
195 static void
196 gdk_device_wintab_ungrab (GdkDevice *device,
197 guint32 time_)
198 {
199 }
200
201 static GdkWindow *
202 gdk_device_wintab_window_at_position (GdkDevice *device,
203 gdouble *win_x,
204 gdouble *win_y,
205 GdkModifierType *mask,
206 gboolean get_toplevel)
207 {
208 return NULL;
209 }
210
211 static void
212 gdk_device_wintab_select_window_events (GdkDevice *device,
213 GdkWindow *window,
214 GdkEventMask event_mask)
215 {
216 }
217
218 void
219 _gdk_device_wintab_translate_axes (GdkDeviceWintab *device_wintab,
220 GdkWindow *window,
221 gdouble *axes,
222 gdouble *x,
223 gdouble *y)
224 {
225 GdkDevice *device;
226 GdkWindow *impl_window;
227 gint root_x, root_y;
228 gdouble temp_x, temp_y;
229 gint i;
230
231 device = GDK_DEVICE (device_wintab);
232 impl_window = _gdk_window_get_impl_window (window);
233 temp_x = temp_y = 0;
234
235 gdk_window_get_origin (impl_window, &root_x, &root_y);
236
237 for (i = 0; i < gdk_device_get_n_axes (device); i++)
238 {
239 GdkAxisUse use;
240
241 use = gdk_device_get_axis_use (device, i);
242
243 switch (use)
244 {
245 case GDK_AXIS_X:
246 case GDK_AXIS_Y:
247 if (gdk_device_get_mode (device) == GDK_MODE_WINDOW)
248 _gdk_device_translate_window_coord (device, window, i,
249 device_wintab->last_axis_data[i],
250 &axes[i]);
251 else
252 _gdk_device_translate_screen_coord (device, window,
253 root_x, root_y, i,
254 device_wintab->last_axis_data[i],
255 &axes[i]);
256 if (use == GDK_AXIS_X)
257 temp_x = axes[i];
258 else if (use == GDK_AXIS_Y)
259 temp_y = axes[i];
260
261 break;
262 default:
263 _gdk_device_translate_axis (device, i,
264 device_wintab->last_axis_data[i],
265 &axes[i]);
266 break;
267 }
268 }
269
270 if (x)
271 *x = temp_x;
272
273 if (y)
274 *y = temp_y;
275 }
276
277 static void
278 gdk_device_wintab_class_init (GdkDeviceWintabClass *klass)
279 {
280 GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
281
282 device_class->get_history = gdk_device_wintab_get_history;
283 device_class->get_state = gdk_device_wintab_get_state;
284 device_class->set_window_cursor = gdk_device_wintab_set_window_cursor;
285 device_class->warp = gdk_device_wintab_warp;
286 device_class->query_state = gdk_device_wintab_query_state;
287 device_class->grab = gdk_device_wintab_grab;
288 device_class->ungrab = gdk_device_wintab_ungrab;
289 device_class->window_at_position = gdk_device_wintab_window_at_position;
290 device_class->select_window_events = gdk_device_wintab_select_window_events;
291 }
292
293 static void
294 gdk_device_wintab_init (GdkDeviceWintab *device_wintab)
295 {
296 }