2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
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.
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.
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.
24 #include <cspi/spi-private.h>
25 #include <cspi/bonobo/cspi-bonobo-listener.h>
28 * SPI_freeAccessibleKeySet:
29 * @keyset: An AccessibleKeyset to free.
31 * Release the memory used by an AccessibleKeySet.
35 SPI_freeAccessibleKeySet (AccessibleKeySet *keyset)
38 g_free (keyset->keysyms);
39 g_free (keyset->keycodes);
40 while (keyset->keystrings [i])
42 g_free (keyset->keystrings [i++]);
44 g_free (keyset->keystrings);
49 * SPI_createAccessibleKeySet:
50 * @len: the number of key values in the key set.
51 * @keysyms: a UTF-8 string containing symbolic key values to be matched, or NULL if
52 * matching is performed against other key values instead.
53 * @keycodes: an array of unsigned short values which are the hardware keycodes
54 * to be matched, or NULL if the keyset is specified solely by keysyms
56 * @keystrings: an array of null-terminated character strings which specify key
57 * name values to match, or NULL if the keyset is specified solely by
58 * keycodes and/or keysyms.
60 * Create a new #AccessibleKeySet of a specified length.
61 * A KeySet is used typically to match key event values, and a matches are made
62 * using the following criteria: a match exists with a key event if all non-null
63 * i-th members of the keyset match the key event.
64 * If both keystring and keysym values are NULL, a keycode value match is
65 * forced, thus the match for keysym=0, keycode=0, keystring=NULL is
68 * Returns: a pointer to a newly-created #AccessibleKeySet.
72 SPI_createAccessibleKeySet (int len, const char *keysyms, short *keycodes,
73 const char **keystrings)
75 AccessibleKeySet *keyset = g_new0 (AccessibleKeySet, 1);
76 int i, keysym_len = 0;
77 const char *keysym_ptr = keysyms;
79 keyset->keysyms = g_new0 (unsigned long, len);
80 keyset->keycodes = g_new0 (unsigned short, len);
81 keyset->keystrings = g_new0 (char *, len);
84 keysym_len = g_utf8_strlen (keysyms, -1);
86 for (i = 0; i < len; ++i)
90 keyset->keysyms [i] = (unsigned long) g_utf8_get_char (keysym_ptr);
91 keysym_ptr = g_utf8_find_next_char (keysym_ptr, NULL);
95 keyset->keysyms [i] = 0;
99 keyset->keycodes [i] = keycodes [i];
103 keyset->keystrings [i] = g_strdup (keystrings [i]);
110 * SPI_createAccessibleEventListener:
111 * @callback : an #AccessibleEventListenerCB callback function, or NULL.
112 * @user_data: a pointer to data which will be passed to the callback when invoked.
114 * Create a new #AccessibleEventListener with a specified (in-process) callback function.
116 * Returns: a pointer to a newly-created #AccessibleEventListener.
119 AccessibleEventListener *
120 SPI_createAccessibleEventListener (AccessibleEventListenerCB callback,
123 AccessibleEventListener *listener = cspi_event_listener_new ();
126 AccessibleEventListener_addCallback (listener, callback, user_data);
132 * AccessibleEventListener_addCallback:
133 * @listener: the #AccessibleEventListener instance to modify.
134 * @callback: an #AccessibleEventListenerCB function pointer.
135 * @user_data: a pointer to data which will be passed to the callback when invoked.
137 * Add an in-process callback function to an existing AccessibleEventListener.
138 * Note that the callback function must live in the same address
139 * space as the AccessibleEventListener implementation code, thus one should not
140 * use this function to attach callbacks to a 'remote' event listener
141 * (that is, one that was not created by a client call to
142 * createAccessibleEventListener ();
144 * Returns: #TRUE if successful, otherwise #FALSE.
148 AccessibleEventListener_addCallback (AccessibleEventListener *listener,
149 AccessibleEventListenerCB callback,
152 cspi_event_listener_add_cb (listener, callback, user_data);
157 * AccessibleEventListener_unref:
158 * @listener: a pointer to the #AccessibleEventListener being operated on.
160 * Decrements an #AccessibleEventListener's reference count.
163 AccessibleEventListener_unref (AccessibleEventListener *listener)
165 cspi_event_listener_unref (listener);
169 * AccessibleEventListener_removeCallback:
170 * @listener: the #AccessibleEventListener instance to modify.
171 * @callback: an #AccessibleEventListenerCB function pointer.
173 * Remove an in-process callback function from an existing AccessibleEventListener.
175 * Returns: #TRUE if successful, otherwise #FALSE.
179 AccessibleEventListener_removeCallback (AccessibleEventListener *listener,
180 AccessibleEventListenerCB callback)
182 cspi_event_listener_remove_cb (listener, callback);
187 * SPI_createAccessibleKeystrokeListener:
188 * @callback : an #AccessibleKeystrokeListenerCB callback function, or NULL.
189 * @user_data: a pointer to data which will be passed to the callback when invoked.
191 * Create a new #AccessibleKeystrokeListener with a specified callback function.
193 * Returns: a pointer to a newly-created #AccessibleKeystrokeListener.
196 AccessibleKeystrokeListener *
197 SPI_createAccessibleKeystrokeListener (AccessibleKeystrokeListenerCB callback,
200 AccessibleDeviceListener *listener = cspi_device_listener_new ();
203 AccessibleDeviceListener_addCallback (listener, callback, user_data);
209 * AccessibleKeystrokeListener_addCallback:
210 * @listener: the #AccessibleKeystrokeListener instance to modify.
211 * @callback: an #AccessibleKeystrokeListenerCB function pointer.
212 * @user_data: a pointer to data which will be passed to the callback when invoked.
214 * Add an in-process callback function to an existing #AccessibleKeystrokeListener.
216 * Returns: #TRUE if successful, otherwise #FALSE.
220 AccessibleKeystrokeListener_addCallback (AccessibleKeystrokeListener *listener,
221 AccessibleKeystrokeListenerCB callback,
224 cspi_device_listener_add_cb (listener, callback, user_data);
229 * AccessibleKeystrokeListener_removeCallback:
230 * @listener: the #AccessibleKeystrokeListener instance to modify.
231 * @callback: an #AccessibleKeystrokeListenerCB function pointer.
233 * Remove an in-process callback function from an existing #AccessibleKeystrokeListener.
235 * Returns: #TRUE if successful, otherwise #FALSE.
239 AccessibleKeystrokeListener_removeCallback (AccessibleKeystrokeListener *listener,
240 AccessibleKeystrokeListenerCB callback)
242 cspi_device_listener_remove_cb (listener, callback);
247 * AccessibleKeystrokeListener_unref:
248 * @listener: a pointer to the #AccessibleKeystrokeListener being operated on.
250 * Decrements an #AccessibleKeystrokeListener's reference count.
253 AccessibleKeystrokeListener_unref (AccessibleKeystrokeListener *listener)
255 cspi_device_listener_unref (listener);
259 * SPI_createAccessibleDeviceListener:
260 * @callback : an #AccessibleDeviceListenerCB callback function, or NULL.
261 * @user_data: a pointer to data which will be passed to the callback when invoked.
263 * Create a new #AccessibleDeviceListener with a specified callback function.
265 * Returns: a pointer to a newly-created #AccessibleDeviceListener.
268 AccessibleDeviceListener *
269 SPI_createAccessibleDeviceListener (AccessibleDeviceListenerCB callback,
272 AccessibleDeviceListener *listener = cspi_device_listener_new ();
275 AccessibleDeviceListener_addCallback (listener, callback, user_data);
281 * AccessibleDeviceListener_addCallback:
282 * @listener: the #AccessibleDeviceListener instance to modify.
283 * @callback: an #AccessibleDeviceListenerCB function pointer.
284 * @user_data: a pointer to data which will be passed to the callback when invoked.
286 * Add an in-process callback function to an existing #AccessibleDeviceListener.
288 * Returns: #TRUE if successful, otherwise #FALSE.
292 AccessibleDeviceListener_addCallback (AccessibleDeviceListener *listener,
293 AccessibleDeviceListenerCB callback,
296 cspi_device_listener_add_cb (listener, callback, user_data);
301 * AccessibleDeviceListener_removeCallback:
302 * @listener: the #AccessibleDeviceListener instance to modify.
303 * @callback: an #AccessibleDeviceListenerCB function pointer.
305 * Remove an in-process callback function from an existing #AccessibleDeviceListener.
307 * Returns: #TRUE if successful, otherwise #FALSE.
311 AccessibleDeviceListener_removeCallback (AccessibleDeviceListener *listener,
312 AccessibleDeviceListenerCB callback)
314 cspi_device_listener_remove_cb (listener, callback);
319 * AccessibleDeviceListener_unref:
320 * @listener: a pointer to the #AccessibleDeviceListener being operated on.
322 * Decrements an #AccessibleDeviceListener's reference count.
325 AccessibleDeviceListener_unref (AccessibleDeviceListener *listener)
327 cspi_device_listener_unref (listener);
331 * AccessibleEvent_getContextString:
332 * @event: a pointer to the #AccessibleEvent being queried.
334 * Queries an #AccessibleEvent for a string whose meaning depends
335 * on the event's context, that is, the event type and details.
336 * Not all events have context strings, in which case this
337 * query returns NULL.
338 * Context strings may be returned by:
339 * object:text-changed events,
340 * in which case they represent the text inserted or deleted;
341 * window: events, in which case they indicate the window title,
344 * Returns: the context string for the event, or %NULL if
345 * there is no context string for the event.
348 AccessibleEvent_getContextString (const AccessibleEvent *e)
350 InternalEvent *foo = (InternalEvent *) e;
352 g_return_val_if_fail (foo, NULL);
353 g_return_val_if_fail (foo->data, NULL);
354 any = (CORBA_any *) foo->data;
355 if (CORBA_TypeCode_equivalent (any->_type, TC_CORBA_string, NULL))
357 return * (char **) any->_value;
361 #ifdef EVENT_CONTEXT_DEBUG
362 fprintf (stderr, "requested string, TC is not TC_CORBA_string! (%u)\n",
363 (unsigned) any->_type);
370 * AccessibleEvent_getContextObject:
371 * @event: a pointer to the #AccessibleEvent being queried.
373 * Queries an #AccessibleEvent for an #Accessible whose meaning depends
374 * on the event's context, that is, the event type and details.
375 * Not all events have context strings, in which case this
376 * query returns NULL.
377 * Context #Accessible objects may be returned by, for instance:
378 * object:child-changed events,
379 * in which case they represent the child added or deleted.
380 * Note that context #Accessibles are not guaranteed to outlive
381 * event delivery, in which case this call may return %NULL
382 * even if the object existed at the time of dispatch.
384 * Returns: the context #Accessible for the event, or %NULL if
385 * there is no context #Accessible object for the event.
388 AccessibleEvent_getContextObject (const AccessibleEvent *e)
390 InternalEvent *foo = (InternalEvent *) e;
392 g_return_val_if_fail (foo, NULL);
393 g_return_val_if_fail (foo->data, NULL);
394 any = (CORBA_any *) foo->data;
395 if (any->_type == TC_CORBA_Object)
396 return cspi_object_add (* (CORBA_Object *) any->_value);