Changes to introspection generation to remove DOCTYPE and XML
[platform/core/uifw/at-spi2-atk.git] / test / keypad-test.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <ctype.h>
27 #include <unistd.h>
28 #include <glib-object.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <sys/un.h>
32 #include <cspi/spi.h>
33 #define XK_MISCELLANY
34 #include <X11/keysymdef.h>
35 #include <gdk/gdk.h>
36 #include <gdk/gdkx.h>
37
38 static SPIBoolean report_keypad_key_event  (const AccessibleKeystroke *stroke, void *user_data);
39
40 static short *get_keypad_keycodes (void);
41
42 static AccessibleKeystrokeListener *keypad_key_listener;
43 static AccessibleKeySet            *keypad_keyset;
44
45 static Display *get_display (void);
46
47 int
48 main (int argc, char **argv)
49 {
50   SPIBoolean retval = FALSE;
51         
52   SPI_init ();
53
54   gdk_init (&argc, &argv); /* 
55                 * needed in this test program only  
56                 * because we are calling GDK_DISPLAY() 
57                 */
58
59   /* prepare the keyboard snoopers */
60   keypad_key_listener = SPI_createAccessibleKeystrokeListener (report_keypad_key_event, NULL);
61   keypad_keyset = SPI_createAccessibleKeySet (16, NULL, get_keypad_keycodes (), NULL);
62
63   retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
64                                           keypad_keyset,
65                                           SPI_KEYMASK_UNMODIFIED,
66                                           (unsigned long) ( SPI_KEY_PRESSED |
67                                                             SPI_KEY_RELEASED ),
68                                           SPI_KEYLISTENER_ALL_WINDOWS);
69   fprintf (stderr, "Keypad key registry: result %s\n", retval ? "succeeded" : 
70         "failed");
71
72   retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
73                                           keypad_keyset,
74                                           SPI_KEYMASK_SHIFT,
75                                           (unsigned long) ( SPI_KEY_PRESSED |
76                                                             SPI_KEY_RELEASED ),
77                                           SPI_KEYLISTENER_ALL_WINDOWS);
78
79   fprintf (stderr, "Shift-Keypad key registry: result %s\n", retval ? "succeeded" : 
80         "failed");
81
82   retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
83                                           keypad_keyset,
84                                           SPI_KEYMASK_MOD2,
85                                           (unsigned long) ( SPI_KEY_PRESSED |
86                                                             SPI_KEY_RELEASED ),
87                                           SPI_KEYLISTENER_ALL_WINDOWS);
88
89   fprintf (stderr, "Mod2-Keypad key registry: result %s\n", retval ? "succeeded" : 
90         "failed");
91
92   retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
93                                           keypad_keyset,
94                                           SPI_KEYMASK_MOD3,
95                                           (unsigned long) ( SPI_KEY_PRESSED |
96                                                             SPI_KEY_RELEASED ),
97                                           SPI_KEYLISTENER_ALL_WINDOWS);
98
99   fprintf (stderr, "Mod3-Keypad key registry: result %s\n", retval ? "succeeded" : 
100         "failed");
101
102   retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
103                                           keypad_keyset,
104                                           SPI_KEYMASK_MOD2 | SPI_KEYMASK_SHIFT,
105                                           (unsigned long) ( SPI_KEY_PRESSED |
106                                                             SPI_KEY_RELEASED ),
107                                           SPI_KEYLISTENER_ALL_WINDOWS);
108
109   fprintf (stderr, "Mod2-Shift-Keypad key registry: result %s\n", retval ? "succeeded" : 
110         "failed");
111
112   retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
113                                           keypad_keyset,
114                                           SPI_KEYMASK_MOD3 | SPI_KEYMASK_SHIFT,
115                                           (unsigned long) ( SPI_KEY_PRESSED |
116                                                             SPI_KEY_RELEASED ),
117                                           SPI_KEYLISTENER_ALL_WINDOWS);
118
119   fprintf (stderr, "Mod3-Shift-Keypad key registry: result %s\n", retval ? "succeeded" : 
120         "failed");
121
122   SPI_event_main ();
123
124   putenv ("AT_BRIDGE_SHUTDOWN=1");
125
126   return SPI_exit ();
127 }
128
129 static Display*
130 get_display (void)
131 {
132         return GDK_DISPLAY ();
133 }
134
135 static short*
136 get_keypad_keycodes (void)
137 {
138         short *keycodes = (short *) g_new0 (short *, 16);
139         int i;
140
141         keycodes [0] = XKeysymToKeycode (get_display (), XK_KP_0);
142         keycodes [1] = XKeysymToKeycode (get_display (), XK_KP_1);
143         keycodes [2] = XKeysymToKeycode (get_display (), XK_KP_2);
144         keycodes [3] = XKeysymToKeycode (get_display (), XK_KP_3);
145         keycodes [4] = XKeysymToKeycode (get_display (), XK_KP_4);
146         keycodes [5] = XKeysymToKeycode (get_display (), XK_KP_5);
147         keycodes [6] = XKeysymToKeycode (get_display (), XK_KP_6);
148         keycodes [7] = XKeysymToKeycode (get_display (), XK_KP_7);
149         keycodes [8] = XKeysymToKeycode (get_display (), XK_KP_8);
150         keycodes [9] = XKeysymToKeycode (get_display (), XK_KP_9);
151         keycodes [10] = XKeysymToKeycode (get_display (), XK_KP_Divide);
152         keycodes [11] = XKeysymToKeycode (get_display (), XK_KP_Multiply);
153         keycodes [12] = XKeysymToKeycode (get_display (), XK_KP_Add);
154         keycodes [13] = XKeysymToKeycode (get_display (), XK_KP_Subtract);
155         keycodes [14] = XKeysymToKeycode (get_display (), XK_KP_Decimal);
156         keycodes [15] = XKeysymToKeycode (get_display (), XK_KP_Enter);
157
158         for (i = 0; i < 16; ++i)
159         {
160                 fprintf (stderr, "keycode[%d] = %d\n", i, (int) keycodes[i]);
161         }
162         return keycodes;
163 }
164
165 static void
166 print_key_event (const AccessibleKeystroke *key, char *prefix)
167 {
168   fprintf (stderr, "%s KeyEvent %s%c [keysym 0x%ld] (keycode %d); string=%s; time=%lx\n",
169            prefix,
170           (key->modifiers & SPI_KEYMASK_ALT)?"Alt-":"",
171           ((key->modifiers & SPI_KEYMASK_SHIFT)^(key->modifiers & SPI_KEYMASK_SHIFTLOCK))?
172           (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID),
173            key->keyID,
174           (int) key->keycode,
175           key->keystring,
176           (long int) key->timestamp);   
177 }
178
179 static SPIBoolean
180 report_keypad_key_event (const AccessibleKeystroke *key, void *user_data)
181 {
182   print_key_event (key, "keypad");
183   return FALSE;
184 }
185
186