| 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 "gdkdisplayprivate.h" |
| 26 |
#include "gdkdevice-win32.h" |
| 27 |
#include "gdkwin32.h" |
| 28 |
|
| 29 |
G_DEFINE_TYPE (GdkDeviceWin32, gdk_device_win32, GDK_TYPE_DEVICE) |
| 30 |
|
| 31 |
static gboolean |
| 32 |
gdk_device_win32_get_history (GdkDevice *device, |
| 33 |
GdkWindow *window, |
| 34 |
guint32 start, |
| 35 |
guint32 stop, |
| 36 |
GdkTimeCoord ***events, |
| 37 |
gint *n_events) |
| 38 |
{ |
| 39 |
return FALSE; |
| 40 |
} |
| 41 |
|
| 42 |
static void |
| 43 |
gdk_device_win32_get_state (GdkDevice *device, |
| 44 |
GdkWindow *window, |
| 45 |
gdouble *axes, |
| 46 |
GdkModifierType *mask) |
| 47 |
{ |
| 48 |
gint x_int, y_int; |
| 49 |
|
| 50 |
gdk_window_get_device_position (window, device, &x_int, &y_int, mask); |
| 51 |
|
| 52 |
if (axes) |
| 53 |
{ |
| 54 |
axes[0] = x_int; |
| 55 |
axes[1] = y_int; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
static void |
| 60 |
gdk_device_win32_set_window_cursor (GdkDevice *device, |
| 61 |
GdkWindow *window, |
| 62 |
GdkCursor *cursor) |
| 63 |
{ |
| 64 |
} |
| 65 |
|
| 66 |
static void |
| 67 |
gdk_device_win32_warp (GdkDevice *device, |
| 68 |
GdkScreen *screen, |
| 69 |
gdouble x, |
| 70 |
gdouble y) |
| 71 |
{ |
| 72 |
} |
| 73 |
|
| 74 |
static GdkModifierType |
| 75 |
get_current_mask (void) |
| 76 |
{ |
| 77 |
GdkModifierType mask; |
| 78 |
BYTE kbd[256]; |
| 79 |
|
| 80 |
GetKeyboardState (kbd); |
| 81 |
mask = 0; |
| 82 |
if (kbd[VK_SHIFT] & 0x80) |
| 83 |
mask |= GDK_SHIFT_MASK; |
| 84 |
if (kbd[VK_CAPITAL] & 0x80) |
| 85 |
mask |= GDK_LOCK_MASK; |
| 86 |
if (kbd[VK_CONTROL] & 0x80) |
| 87 |
mask |= GDK_CONTROL_MASK; |
| 88 |
if (kbd[VK_MENU] & 0x80) |
| 89 |
mask |= GDK_MOD1_MASK; |
| 90 |
if (kbd[VK_LBUTTON] & 0x80) |
| 91 |
mask |= GDK_BUTTON1_MASK; |
| 92 |
if (kbd[VK_MBUTTON] & 0x80) |
| 93 |
mask |= GDK_BUTTON2_MASK; |
| 94 |
if (kbd[VK_RBUTTON] & 0x80) |
| 95 |
mask |= GDK_BUTTON3_MASK; |
| 96 |
|
| 97 |
return mask; |
| 98 |
} |
| 99 |
|
| 100 |
static void |
| 101 |
gdk_device_win32_query_state (GdkDevice *device, |
| 102 |
GdkWindow *window, |
| 103 |
GdkWindow **root_window, |
| 104 |
GdkWindow **child_window, |
| 105 |
gdouble *root_x, |
| 106 |
gdouble *root_y, |
| 107 |
gdouble *win_x, |
| 108 |
gdouble *win_y, |
| 109 |
GdkModifierType *mask) |
| 110 |
{ |
| 111 |
GdkScreen *screen; |
| 112 |
POINT point; |
| 113 |
HWND hwnd, hwndc; |
| 114 |
GdkWindowImplWin32 *impl; |
| 115 |
|
| 116 |
screen = gdk_window_get_screen (window); |
| 117 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 118 |
|
| 119 |
hwnd = GDK_WINDOW_HWND (window); |
| 120 |
_gdk_win32_get_cursor_pos (&point); |
| 121 |
|
| 122 |
if (root_x) |
| 123 |
*root_x = (point.x + _gdk_offset_x) / impl->window_scale; |
| 124 |
|
| 125 |
if (root_y) |
| 126 |
*root_y = (point.y + _gdk_offset_y) / impl->window_scale; |
| 127 |
|
| 128 |
if (window == gdk_screen_get_root_window (screen)) |
| 129 |
{ |
| 130 |
if (win_x) |
| 131 |
*win_x = (point.x + _gdk_offset_x) / impl->window_scale; |
| 132 |
|
| 133 |
if (win_y) |
| 134 |
*win_y = (point.y + _gdk_offset_y) / impl->window_scale; |
| 135 |
} |
| 136 |
else |
| 137 |
{ |
| 138 |
ScreenToClient (hwnd, &point); |
| 139 |
|
| 140 |
if (win_x) |
| 141 |
*win_x = point.x / impl->window_scale; |
| 142 |
|
| 143 |
if (win_y) |
| 144 |
*win_y = point.y / impl->window_scale; |
| 145 |
} |
| 146 |
|
| 147 |
if (child_window) |
| 148 |
{ |
| 149 |
if (window == gdk_screen_get_root_window (screen)) |
| 150 |
{ |
| 151 |
/* Always use WindowFromPoint when searching from the root window. |
| 152 |
* Only WindowFromPoint is able to look through transparent |
| 153 |
* layered windows. |
| 154 |
*/ |
| 155 |
hwndc = GetAncestor (WindowFromPoint (point), GA_ROOT); |
| 156 |
} |
| 157 |
else |
| 158 |
{ |
| 159 |
hwndc = ChildWindowFromPoint (hwnd, point); |
| 160 |
} |
| 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 |
*mask = get_current_mask (); |
| 173 |
} |
| 174 |
|
| 175 |
static GdkGrabStatus |
| 176 |
gdk_device_win32_grab (GdkDevice *device, |
| 177 |
GdkWindow *window, |
| 178 |
gboolean owner_events, |
| 179 |
GdkEventMask event_mask, |
| 180 |
GdkWindow *confine_to, |
| 181 |
GdkCursor *cursor, |
| 182 |
guint32 time_) |
| 183 |
{ |
| 184 |
/* No support for grabbing the slave atm */ |
| 185 |
return GDK_GRAB_NOT_VIEWABLE; |
| 186 |
} |
| 187 |
|
| 188 |
static void |
| 189 |
gdk_device_win32_ungrab (GdkDevice *device, |
| 190 |
guint32 time_) |
| 191 |
{ |
| 192 |
} |
| 193 |
|
| 194 |
static void |
| 195 |
screen_to_client (HWND hwnd, POINT screen_pt, POINT *client_pt) |
| 196 |
{ |
| 197 |
*client_pt = screen_pt; |
| 198 |
ScreenToClient (hwnd, client_pt); |
| 199 |
} |
| 200 |
|
| 201 |
GdkWindow * |
| 202 |
_gdk_device_win32_window_at_position (GdkDevice *device, |
| 203 |
gdouble *win_x, |
| 204 |
gdouble *win_y, |
| 205 |
GdkModifierType *mask, |
| 206 |
gboolean get_toplevel) |
| 207 |
{ |
| 208 |
GdkWindow *window = NULL; |
| 209 |
GdkWindowImplWin32 *impl = NULL; |
| 210 |
POINT screen_pt, client_pt; |
| 211 |
HWND hwnd; |
| 212 |
RECT rect; |
| 213 |
|
| 214 |
if (!_gdk_win32_get_cursor_pos (&screen_pt)) |
| 215 |
return NULL; |
| 216 |
|
| 217 |
hwnd = WindowFromPoint (screen_pt); |
| 218 |
|
| 219 |
if (get_toplevel) |
| 220 |
{ |
| 221 |
/* Use WindowFromPoint instead of ChildWindowFromPoint(Ex). |
| 222 |
* Only WindowFromPoint is able to look through transparent |
| 223 |
* layered windows. |
| 224 |
*/ |
| 225 |
hwnd = GetAncestor (hwnd, GA_ROOT); |
| 226 |
} |
| 227 |
|
| 228 |
/* Verify that we're really inside the client area of the window */ |
| 229 |
GetClientRect (hwnd, &rect); |
| 230 |
screen_to_client (hwnd, screen_pt, &client_pt); |
| 231 |
if (!PtInRect (&rect, client_pt)) |
| 232 |
hwnd = NULL; |
| 233 |
|
| 234 |
if (!get_toplevel && hwnd == NULL) |
| 235 |
{ |
| 236 |
/* If we didn't hit any window, return the root window */ |
| 237 |
/* note that the root window ain't a toplevel window */ |
| 238 |
window = gdk_get_default_root_window (); |
| 239 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 240 |
|
| 241 |
if (win_x) |
| 242 |
*win_x = (screen_pt.x + _gdk_offset_x) / impl->window_scale; |
| 243 |
if (win_y) |
| 244 |
*win_y = (screen_pt.y + _gdk_offset_y) / impl->window_scale; |
| 245 |
|
| 246 |
return window; |
| 247 |
} |
| 248 |
|
| 249 |
window = gdk_win32_handle_table_lookup (hwnd); |
| 250 |
|
| 251 |
if (window && (win_x || win_y)) |
| 252 |
{ |
| 253 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 254 |
|
| 255 |
if (win_x) |
| 256 |
*win_x = client_pt.x / impl->window_scale; |
| 257 |
if (win_y) |
| 258 |
*win_y = client_pt.y / impl->window_scale; |
| 259 |
} |
| 260 |
|
| 261 |
return window; |
| 262 |
} |
| 263 |
|
| 264 |
static void |
| 265 |
gdk_device_win32_select_window_events (GdkDevice *device, |
| 266 |
GdkWindow *window, |
| 267 |
GdkEventMask event_mask) |
| 268 |
{ |
| 269 |
} |
| 270 |
|
| 271 |
static void |
| 272 |
gdk_device_win32_class_init (GdkDeviceWin32Class *klass) |
| 273 |
{ |
| 274 |
GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass); |
| 275 |
|
| 276 |
device_class->get_history = gdk_device_win32_get_history; |
| 277 |
device_class->get_state = gdk_device_win32_get_state; |
| 278 |
device_class->set_window_cursor = gdk_device_win32_set_window_cursor; |
| 279 |
device_class->warp = gdk_device_win32_warp; |
| 280 |
device_class->query_state = gdk_device_win32_query_state; |
| 281 |
device_class->grab = gdk_device_win32_grab; |
| 282 |
device_class->ungrab = gdk_device_win32_ungrab; |
| 283 |
device_class->window_at_position = _gdk_device_win32_window_at_position; |
| 284 |
device_class->select_window_events = gdk_device_win32_select_window_events; |
| 285 |
} |
| 286 |
|
| 287 |
static void |
| 288 |
gdk_device_win32_init (GdkDeviceWin32 *device_win32) |
| 289 |
{ |
| 290 |
GdkDevice *device; |
| 291 |
|
| 292 |
device = GDK_DEVICE (device_win32); |
| 293 |
|
| 294 |
_gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1); |
| 295 |
_gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1); |
| 296 |
} |