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 cspi_internal_event_get_text (const InternalEvent *e)
334 g_return_val_if_fail (e, NULL);
335 g_return_val_if_fail (e->data, NULL);
336 any = (CORBA_any *) e->data;
337 if (CORBA_TypeCode_equivalent (any->_type, TC_CORBA_string, NULL))
339 return * (char **) any->_value;
343 #ifdef EVENT_CONTEXT_DEBUG
344 fprintf (stderr, "requested string, TC is not TC_CORBA_string! (%u)\n",
345 (unsigned) any->_type);
352 cspi_internal_event_get_object (const InternalEvent *e)
355 g_return_val_if_fail (e, NULL);
356 g_return_val_if_fail (e->data, NULL);
357 any = (CORBA_any *) e->data;
358 if (any->_type == TC_CORBA_Object)
359 return cspi_object_add (* (CORBA_Object *) any->_value);
366 * AccessibleTextChangedEvent_getChangeString:
367 * @event: a pointer to the #AccessibleEvent being queried.
369 * Queries an #AccessibleEvent of type "object:text-changed",
370 * returning the text inserted or deleted.
372 * Returns: a UTF-8 text string indicating the text inserted,
373 * deleted, or substituted by this event.
376 AccessibleTextChangedEvent_getChangeString (const AccessibleEvent *e)
378 InternalEvent *foo = (InternalEvent *) e;
379 /* TODO: check the event type? expensive... */
380 return cspi_internal_event_get_text (e);
384 * AccessibleChildChangedEvent_getChildAccessible:
385 * @event: a pointer to the #AccessibleEvent being queried.
387 * Queries an #AccessibleEvent of type "object:children_changed"
388 * to get a reference to the changed #Accessible.
389 * Note that context #Accessibles are not guaranteed to outlive
390 * event delivery, in which case this call may return %NULL
391 * even if the object existed at the time of dispatch.
393 * Returns: the context #Accessible for the event, or %NULL if
394 * there is no longer a valid context #Accessible
395 * object for the event.
398 AccessibleChildChangedEvent_getChildAccessible (const AccessibleEvent *e)
400 InternalEvent *foo = (InternalEvent *) e;
401 return cspi_internal_event_get_object (e);