Debian Codegraph @

gdk/win32/gdktestutils-win32.c

raw
1 /* Gtk+ testing utilities
2 * Copyright (C) 2007 Imendio AB
3 * Authors: Tim Janik
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20 #include <gdk/gdktestutils.h>
21 #include <gdk/gdkkeysyms.h>
22 #include <win32/gdkwin32.h>
23 #include "gdkalias.h"
24
25 void
26 gdk_test_render_sync (GdkWindow *window)
27 {
28 }
29
30 gboolean
31 gdk_test_simulate_key (GdkWindow *window,
32 gint x,
33 gint y,
34 guint keyval,
35 GdkModifierType modifiers,
36 GdkEventType key_pressrelease)
37 {
38 gboolean success = FALSE;
39 GdkKeymapKey *keys = NULL;
40 gint n_keys = 0;
41 INPUT ip;
42 gint i;
43
44 g_return_val_if_fail (key_pressrelease == GDK_KEY_PRESS || key_pressrelease == GDK_KEY_RELEASE, FALSE);
45 g_return_val_if_fail (window != NULL, FALSE);
46
47 ip.type = INPUT_KEYBOARD;
48 ip.ki.wScan = 0;
49 ip.ki.time = 0;
50 ip.ki.dwExtraInfo = 0;
51
52 switch (key_pressrelease)
53 {
54 case GDK_KEY_PRESS:
55 ip.ki.dwFlags = 0;
56 break;
57 case GDK_KEY_RELEASE:
58 ip.ki.dwFlags = KEYEVENTF_KEYUP;
59 break;
60 default:
61 /* Not a key event. */
62 return FALSE;
63 }
64 if (gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), keyval, &keys, &n_keys))
65 {
66 for (i = 0; i < n_keys; i++)
67 {
68 if (key_pressrelease == GDK_KEY_PRESS)
69 {
70 /* AltGr press. */
71 if (keys[i].group)
72 {
73 /* According to some virtualbox code I found, AltGr is
74 * simulated on win32 with LCtrl+RAlt */
75 ip.ki.wVk = VK_CONTROL;
76 SendInput(1, &ip, sizeof(INPUT));
77 ip.ki.wVk = VK_MENU;
78 SendInput(1, &ip, sizeof(INPUT));
79 }
80 /* Shift press. */
81 if (keys[i].level || (modifiers & GDK_SHIFT_MASK))
82 {
83 ip.ki.wVk = VK_SHIFT;
84 SendInput(1, &ip, sizeof(INPUT));
85 }
86 }
87
88 /* Key pressed/released. */
89 ip.ki.wVk = keys[i].keycode;
90 SendInput(1, &ip, sizeof(INPUT));
91
92 if (key_pressrelease == GDK_KEY_RELEASE)
93 {
94 /* Shift release. */
95 if (keys[i].level || (modifiers & GDK_SHIFT_MASK))
96 {
97 ip.ki.wVk = VK_SHIFT;
98 SendInput(1, &ip, sizeof(INPUT));
99 }
100 /* AltrGr release. */
101 if (keys[i].group)
102 {
103 ip.ki.wVk = VK_MENU;
104 SendInput(1, &ip, sizeof(INPUT));
105 ip.ki.wVk = VK_CONTROL;
106 SendInput(1, &ip, sizeof(INPUT));
107 }
108 }
109
110 /* No need to loop for alternative keycodes. We want only one
111 * key generated. */
112 success = TRUE;
113 break;
114 }
115 g_free (keys);
116 }
117 return success;
118 }
119
120 gboolean
121 gdk_test_simulate_button (GdkWindow *window,
122 gint x,
123 gint y,
124 guint button, /*1..3*/
125 GdkModifierType modifiers,
126 GdkEventType button_pressrelease)
127 {
128 g_return_val_if_fail (button_pressrelease == GDK_BUTTON_PRESS || button_pressrelease == GDK_BUTTON_RELEASE, FALSE);
129 g_return_val_if_fail (window != NULL, FALSE);
130
131 return FALSE;
132 }