| 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-virtual.h" |
| 27 |
#include "gdkdevice-win32.h" |
| 28 |
#include "gdkwin32.h" |
| 29 |
|
| 30 |
G_DEFINE_TYPE (GdkDeviceVirtual, gdk_device_virtual, GDK_TYPE_DEVICE) |
| 31 |
|
| 32 |
void |
| 33 |
_gdk_device_virtual_set_active (GdkDevice *device, |
| 34 |
GdkDevice *new_active) |
| 35 |
{ |
| 36 |
GdkDeviceVirtual *virtual = GDK_DEVICE_VIRTUAL (device); |
| 37 |
int n_axes, i; |
| 38 |
GdkAtom label_atom; |
| 39 |
GdkAxisUse use; |
| 40 |
gdouble min_value, max_value, resolution; |
| 41 |
|
| 42 |
if (virtual->active_device == new_active) |
| 43 |
return; |
| 44 |
|
| 45 |
virtual->active_device = new_active; |
| 46 |
|
| 47 |
if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD) |
| 48 |
{ |
| 49 |
_gdk_device_reset_axes (device); |
| 50 |
n_axes = gdk_device_get_n_axes (new_active); |
| 51 |
for (i = 0; i < n_axes; i++) |
| 52 |
{ |
| 53 |
_gdk_device_get_axis_info (new_active, i, |
| 54 |
&label_atom, &use, |
| 55 |
&min_value, &max_value, &resolution); |
| 56 |
_gdk_device_add_axis (device, |
| 57 |
label_atom, use, |
| 58 |
min_value, max_value, resolution); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
g_signal_emit_by_name (G_OBJECT (device), "changed"); |
| 63 |
} |
| 64 |
|
| 65 |
static gboolean |
| 66 |
gdk_device_virtual_get_history (GdkDevice *device, |
| 67 |
GdkWindow *window, |
| 68 |
guint32 start, |
| 69 |
guint32 stop, |
| 70 |
GdkTimeCoord ***events, |
| 71 |
gint *n_events) |
| 72 |
{ |
| 73 |
/* History is only per slave device */ |
| 74 |
return FALSE; |
| 75 |
} |
| 76 |
|
| 77 |
static void |
| 78 |
gdk_device_virtual_get_state (GdkDevice *device, |
| 79 |
GdkWindow *window, |
| 80 |
gdouble *axes, |
| 81 |
GdkModifierType *mask) |
| 82 |
{ |
| 83 |
GdkDeviceVirtual *virtual = GDK_DEVICE_VIRTUAL (device); |
| 84 |
GdkDevice *active = virtual->active_device; |
| 85 |
|
| 86 |
GDK_DEVICE_GET_CLASS (active)->get_state (active, |
| 87 |
window, axes, mask); |
| 88 |
} |
| 89 |
|
| 90 |
static void |
| 91 |
gdk_device_virtual_set_window_cursor (GdkDevice *device, |
| 92 |
GdkWindow *window, |
| 93 |
GdkCursor *cursor) |
| 94 |
{ |
| 95 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 96 |
GdkCursor *previous_cursor = impl->cursor; |
| 97 |
|
| 98 |
if (cursor != NULL && GDK_WIN32_CURSOR (cursor)->hcursor != NULL) |
| 99 |
{ |
| 100 |
SetCursor (GDK_WIN32_CURSOR (cursor)->hcursor); |
| 101 |
} |
| 102 |
else if (previous_cursor != NULL && |
| 103 |
GetCursor () == GDK_WIN32_CURSOR (previous_cursor)->hcursor) |
| 104 |
{ |
| 105 |
/* The caller will unref previous_cursor shortly, |
| 106 |
* but it holds the handle to currently-used cursor, |
| 107 |
* and we can't call SetCursor(NULL). |
| 108 |
*/ |
| 109 |
g_warning (G_STRLOC ": Refusing to replace cursor %p (handle %p) with NULL. " |
| 110 |
"Expect ugly results.", |
| 111 |
previous_cursor, GDK_WIN32_CURSOR (previous_cursor)->hcursor); |
| 112 |
} |
| 113 |
else |
| 114 |
{ |
| 115 |
/* Up the stack all effors were made already to ensure that |
| 116 |
* the "cursor" argument is non-NULL. |
| 117 |
* If it is, calling SetCursor(NULL) is absolutely not |
| 118 |
* the right decision, so we just warn and bail out. |
| 119 |
*/ |
| 120 |
g_warning (G_STRLOC ": Refusing to set NULL cursor"); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
static void |
| 125 |
gdk_device_virtual_warp (GdkDevice *device, |
| 126 |
GdkScreen *screen, |
| 127 |
gdouble x, |
| 128 |
gdouble y) |
| 129 |
{ |
| 130 |
SetCursorPos (x - _gdk_offset_x, y - _gdk_offset_y); |
| 131 |
} |
| 132 |
|
| 133 |
static void |
| 134 |
gdk_device_virtual_query_state (GdkDevice *device, |
| 135 |
GdkWindow *window, |
| 136 |
GdkWindow **root_window, |
| 137 |
GdkWindow **child_window, |
| 138 |
gdouble *root_x, |
| 139 |
gdouble *root_y, |
| 140 |
gdouble *win_x, |
| 141 |
gdouble *win_y, |
| 142 |
GdkModifierType *mask) |
| 143 |
{ |
| 144 |
GdkDeviceVirtual *virtual = GDK_DEVICE_VIRTUAL (device); |
| 145 |
|
| 146 |
_gdk_device_query_state (virtual->active_device, |
| 147 |
window, root_window, child_window, |
| 148 |
root_x, root_y, |
| 149 |
win_x, win_y, |
| 150 |
mask); |
| 151 |
} |
| 152 |
|
| 153 |
static GdkGrabStatus |
| 154 |
gdk_device_virtual_grab (GdkDevice *device, |
| 155 |
GdkWindow *window, |
| 156 |
gboolean owner_events, |
| 157 |
GdkEventMask event_mask, |
| 158 |
GdkWindow *confine_to, |
| 159 |
GdkCursor *cursor, |
| 160 |
guint32 time_) |
| 161 |
{ |
| 162 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 163 |
|
| 164 |
if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD) |
| 165 |
{ |
| 166 |
if (_gdk_win32_grab_cursor != NULL) |
| 167 |
{ |
| 168 |
if (GetCursor () == GDK_WIN32_CURSOR (_gdk_win32_grab_cursor)->hcursor) |
| 169 |
SetCursor (NULL); |
| 170 |
} |
| 171 |
|
| 172 |
g_set_object (&_gdk_win32_grab_cursor, cursor); |
| 173 |
|
| 174 |
if (_gdk_win32_grab_cursor != NULL) |
| 175 |
SetCursor (GDK_WIN32_CURSOR (_gdk_win32_grab_cursor)->hcursor); |
| 176 |
else if (impl->cursor != NULL) |
| 177 |
SetCursor (GDK_WIN32_CURSOR (impl->cursor)->hcursor); |
| 178 |
else |
| 179 |
SetCursor (LoadCursor (NULL, IDC_ARROW)); |
| 180 |
|
| 181 |
SetCapture (GDK_WINDOW_HWND (window)); |
| 182 |
} |
| 183 |
|
| 184 |
return GDK_GRAB_SUCCESS; |
| 185 |
} |
| 186 |
|
| 187 |
static void |
| 188 |
gdk_device_virtual_ungrab (GdkDevice *device, |
| 189 |
guint32 time_) |
| 190 |
{ |
| 191 |
GdkDeviceGrabInfo *info; |
| 192 |
GdkDisplay *display; |
| 193 |
|
| 194 |
display = gdk_device_get_display (device); |
| 195 |
info = _gdk_display_get_last_device_grab (display, device); |
| 196 |
|
| 197 |
if (info) |
| 198 |
info->serial_end = 0; |
| 199 |
|
| 200 |
if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD) |
| 201 |
{ |
| 202 |
if (_gdk_win32_grab_cursor != NULL) |
| 203 |
{ |
| 204 |
if (GetCursor () == GDK_WIN32_CURSOR (_gdk_win32_grab_cursor)->hcursor) |
| 205 |
SetCursor (NULL); |
| 206 |
} |
| 207 |
g_clear_object (&_gdk_win32_grab_cursor); |
| 208 |
|
| 209 |
ReleaseCapture (); |
| 210 |
} |
| 211 |
|
| 212 |
_gdk_display_device_grab_update (display, device, device, 0); |
| 213 |
} |
| 214 |
|
| 215 |
static void |
| 216 |
gdk_device_virtual_select_window_events (GdkDevice *device, |
| 217 |
GdkWindow *window, |
| 218 |
GdkEventMask event_mask) |
| 219 |
{ |
| 220 |
} |
| 221 |
|
| 222 |
static void |
| 223 |
gdk_device_virtual_class_init (GdkDeviceVirtualClass *klass) |
| 224 |
{ |
| 225 |
GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass); |
| 226 |
|
| 227 |
device_class->get_history = gdk_device_virtual_get_history; |
| 228 |
device_class->get_state = gdk_device_virtual_get_state; |
| 229 |
device_class->set_window_cursor = gdk_device_virtual_set_window_cursor; |
| 230 |
device_class->warp = gdk_device_virtual_warp; |
| 231 |
device_class->query_state = gdk_device_virtual_query_state; |
| 232 |
device_class->grab = gdk_device_virtual_grab; |
| 233 |
device_class->ungrab = gdk_device_virtual_ungrab; |
| 234 |
device_class->window_at_position = _gdk_device_win32_window_at_position; |
| 235 |
device_class->select_window_events = gdk_device_virtual_select_window_events; |
| 236 |
} |
| 237 |
|
| 238 |
static void |
| 239 |
gdk_device_virtual_init (GdkDeviceVirtual *device_virtual) |
| 240 |
{ |
| 241 |
} |