| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
|
| 20 |
#include <gdk/gdksurface.h> |
| 21 |
|
| 22 |
#include <windowsx.h> |
| 23 |
#include <objbase.h> |
| 24 |
|
| 25 |
#include "gdkwin32.h" |
| 26 |
#include "gdkdevice-wintab.h" |
| 27 |
#include "gdkdisplay-win32.h" |
| 28 |
|
| 29 |
G_DEFINE_TYPE (GdkDeviceWintab, gdk_device_wintab, GDK_TYPE_DEVICE) |
| 30 |
|
| 31 |
static GdkModifierType |
| 32 |
get_current_mask (void) |
| 33 |
{ |
| 34 |
GdkModifierType mask; |
| 35 |
BYTE kbd[256]; |
| 36 |
|
| 37 |
GetKeyboardState (kbd); |
| 38 |
mask = 0; |
| 39 |
if (kbd[VK_SHIFT] & 0x80) |
| 40 |
mask |= GDK_SHIFT_MASK; |
| 41 |
if (kbd[VK_CAPITAL] & 0x80) |
| 42 |
mask |= GDK_LOCK_MASK; |
| 43 |
if (kbd[VK_CONTROL] & 0x80) |
| 44 |
mask |= GDK_CONTROL_MASK; |
| 45 |
if (kbd[VK_MENU] & 0x80) |
| 46 |
mask |= GDK_ALT_MASK; |
| 47 |
if (kbd[VK_LBUTTON] & 0x80) |
| 48 |
mask |= GDK_BUTTON1_MASK; |
| 49 |
if (kbd[VK_MBUTTON] & 0x80) |
| 50 |
mask |= GDK_BUTTON2_MASK; |
| 51 |
if (kbd[VK_RBUTTON] & 0x80) |
| 52 |
mask |= GDK_BUTTON3_MASK; |
| 53 |
|
| 54 |
return mask; |
| 55 |
} |
| 56 |
|
| 57 |
static void |
| 58 |
gdk_device_wintab_set_surface_cursor (GdkDevice *device, |
| 59 |
GdkSurface *surface, |
| 60 |
GdkCursor *cursor) |
| 61 |
{ |
| 62 |
} |
| 63 |
|
| 64 |
void |
| 65 |
gdk_device_wintab_query_state (GdkDevice *device, |
| 66 |
GdkSurface *surface, |
| 67 |
GdkSurface **child_surface, |
| 68 |
double *win_x, |
| 69 |
double *win_y, |
| 70 |
GdkModifierType *mask) |
| 71 |
{ |
| 72 |
GdkDeviceWintab *device_wintab; |
| 73 |
POINT point; |
| 74 |
HWND hwnd, hwndc; |
| 75 |
int scale; |
| 76 |
GdkDisplay *display = gdk_device_get_display (device); |
| 77 |
|
| 78 |
device_wintab = GDK_DEVICE_WINTAB (device); |
| 79 |
if (surface) |
| 80 |
{ |
| 81 |
scale = GDK_WIN32_SURFACE (surface)->surface_scale; |
| 82 |
hwnd = GDK_SURFACE_HWND (surface); |
| 83 |
} |
| 84 |
else |
| 85 |
{ |
| 86 |
scale = GDK_WIN32_DISPLAY (display)->surface_scale; |
| 87 |
hwnd = NULL; |
| 88 |
} |
| 89 |
|
| 90 |
_gdk_win32_get_cursor_pos (display, &point); |
| 91 |
|
| 92 |
if (hwnd) |
| 93 |
ScreenToClient (hwnd, &point); |
| 94 |
|
| 95 |
if (win_x) |
| 96 |
*win_x = point.x / scale; |
| 97 |
|
| 98 |
if (win_y) |
| 99 |
*win_y = point.y / scale; |
| 100 |
|
| 101 |
if (hwnd && child_surface) |
| 102 |
{ |
| 103 |
hwndc = ChildWindowFromPoint (hwnd, point); |
| 104 |
|
| 105 |
if (hwndc && hwndc != hwnd) |
| 106 |
*child_surface = gdk_win32_display_handle_table_lookup_ (display, hwndc); |
| 107 |
else |
| 108 |
*child_surface = NULL; |
| 109 |
} |
| 110 |
|
| 111 |
if (mask) |
| 112 |
{ |
| 113 |
*mask = get_current_mask (); |
| 114 |
*mask &= 0xFF; |
| 115 |
*mask |= ((device_wintab->button_state << 8) |
| 116 |
& (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK |
| 117 |
| GDK_BUTTON3_MASK | GDK_BUTTON4_MASK |
| 118 |
| GDK_BUTTON5_MASK)); |
| 119 |
|
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
static GdkGrabStatus |
| 124 |
gdk_device_wintab_grab (GdkDevice *device, |
| 125 |
GdkSurface *surface, |
| 126 |
gboolean owner_events, |
| 127 |
GdkEventMask event_mask, |
| 128 |
GdkSurface *confine_to, |
| 129 |
GdkCursor *cursor, |
| 130 |
guint32 time_) |
| 131 |
{ |
| 132 |
return GDK_GRAB_SUCCESS; |
| 133 |
} |
| 134 |
|
| 135 |
static void |
| 136 |
gdk_device_wintab_ungrab (GdkDevice *device, |
| 137 |
guint32 time_) |
| 138 |
{ |
| 139 |
} |
| 140 |
|
| 141 |
static GdkSurface * |
| 142 |
gdk_device_wintab_surface_at_position (GdkDevice *device, |
| 143 |
double *win_x, |
| 144 |
double *win_y, |
| 145 |
GdkModifierType *mask) |
| 146 |
{ |
| 147 |
return NULL; |
| 148 |
} |
| 149 |
|
| 150 |
void |
| 151 |
_gdk_device_wintab_translate_axes (GdkDeviceWintab *device_wintab, |
| 152 |
GdkSurface *surface, |
| 153 |
double *axes, |
| 154 |
double *x, |
| 155 |
double *y) |
| 156 |
{ |
| 157 |
GdkDevice *device; |
| 158 |
GdkSurface *impl_surface; |
| 159 |
int root_x, root_y; |
| 160 |
double temp_x, temp_y; |
| 161 |
int i; |
| 162 |
|
| 163 |
device = GDK_DEVICE (device_wintab); |
| 164 |
impl_surface = surface; |
| 165 |
temp_x = temp_y = 0; |
| 166 |
|
| 167 |
gdk_surface_get_origin (impl_surface, &root_x, &root_y); |
| 168 |
|
| 169 |
for (i = 0; i < gdk_device_get_n_axes (device); i++) |
| 170 |
{ |
| 171 |
GdkAxisUse use; |
| 172 |
|
| 173 |
use = gdk_device_get_axis_use (device, i); |
| 174 |
|
| 175 |
switch (use) |
| 176 |
{ |
| 177 |
case GDK_AXIS_X: |
| 178 |
case GDK_AXIS_Y: |
| 179 |
{ |
| 180 |
HMONITOR hmonitor; |
| 181 |
MONITORINFO minfo = {sizeof (MONITORINFO),}; |
| 182 |
|
| 183 |
hmonitor = MonitorFromWindow (GDK_SURFACE_HWND (surface), |
| 184 |
MONITOR_DEFAULTTONEAREST); |
| 185 |
GetMonitorInfo (hmonitor, &minfo); |
| 186 |
|
| 187 |
|
| 188 |
_gdk_device_translate_screen_coord (device, surface, |
| 189 |
root_x, root_y, |
| 190 |
minfo.rcWork.right - minfo.rcWork.left, |
| 191 |
minfo.rcWork.bottom - minfo.rcWork.top, |
| 192 |
i, |
| 193 |
device_wintab->last_axis_data[i], |
| 194 |
&axes[use]); |
| 195 |
} |
| 196 |
if (use == GDK_AXIS_X) |
| 197 |
temp_x = axes[use]; |
| 198 |
else if (use == GDK_AXIS_Y) |
| 199 |
temp_y = axes[use]; |
| 200 |
|
| 201 |
break; |
| 202 |
default: |
| 203 |
_gdk_device_translate_axis (device, i, |
| 204 |
device_wintab->last_axis_data[i], |
| 205 |
&axes[use]); |
| 206 |
break; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
if (x) |
| 211 |
*x = temp_x; |
| 212 |
|
| 213 |
if (y) |
| 214 |
*y = temp_y; |
| 215 |
} |
| 216 |
|
| 217 |
static void |
| 218 |
gdk_device_wintab_class_init (GdkDeviceWintabClass *klass) |
| 219 |
{ |
| 220 |
GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass); |
| 221 |
|
| 222 |
device_class->set_surface_cursor = gdk_device_wintab_set_surface_cursor; |
| 223 |
device_class->grab = gdk_device_wintab_grab; |
| 224 |
device_class->ungrab = gdk_device_wintab_ungrab; |
| 225 |
device_class->surface_at_position = gdk_device_wintab_surface_at_position; |
| 226 |
} |
| 227 |
|
| 228 |
static void |
| 229 |
gdk_device_wintab_init (GdkDeviceWintab *device_wintab) |
| 230 |
{ |
| 231 |
} |