2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* spi_registry.c: Global functions wrapping the registry */
25 #include <cspi/spi-private.h>
28 * SPI_registerGlobalEventListener:
29 * @listener: the #AccessibleEventListener to be registered against an
31 * @eventType: a character string indicating the type of events for which
32 * notification is requested. Format is
33 * EventClass:major_type:minor_type:detail
34 * where all subfields other than EventClass are optional.
35 * EventClasses include "object", "window", "mouse",
36 * and toolkit events (e.g. "Gtk", "AWT").
37 * Examples: "focus:", "Gtk:GtkWidget:button_press_event".
39 * Legal object event types:
41 * (property change events)
43 * object:property-change
44 * object:property-change:accessible-name
45 * object:property-change:accessible-state
46 * object:property-change:accessible-description
47 * object:property-change:accessible-parent
48 * object:property-change:accessible-value
49 * object:property-change:accessible-role
50 * object:property-change:accessible-table-caption
51 * object:property-change:accessible-table-column-description
52 * object:property-change:accessible-table-column-header
53 * object:property-change:accessible-table-row-description
54 * object:property-change:accessible-table-row-header
55 * object:property-change:accessible-table-summary
57 * (other object events)
59 * object:children-changed
60 * object:visible-data-changed
61 * object:selection-changed
62 * object:text-selection-changed
64 * object:text-caret-moved
66 * object:row-reordered
68 * object:column-inserted
69 * object:column-reordered
70 * object:column-deleted
71 * object:model-changed
81 * window:desktop-create
82 * window:desktop-destroy
93 * NOTE: this string may be UTF-8, but should not contain byte value 56
94 * (ascii ':'), except as a delimiter, since non-UTF-8 string
95 * delimiting functions are used internally.
96 * In general, listening to
97 * toolkit-specific events is not recommended.
99 * Add an in-process callback function to an existing AccessibleEventListener.
101 * Returns: #TRUE if successful, otherwise #FALSE.
104 SPI_registerGlobalEventListener (AccessibleEventListener *listener,
105 const char *eventType)
114 Accessibility_Registry_registerGlobalEventListener (
116 cspi_event_listener_get_corba (listener),
117 eventType, cspi_ev ());
119 retval = !cspi_exception ();
125 * SPI_deregisterGlobalEventListenerAll:
126 * @listener: the #AccessibleEventListener to be registered against
129 * deregisters an AccessibleEventListener from the registry, for all
130 * event types it may be listening to. Use
131 * AccessibleEventListener_unref to release the
132 * listener reference.
134 * Returns: #TRUE if successful, otherwise #FALSE.
137 SPI_deregisterGlobalEventListenerAll (AccessibleEventListener *listener)
144 Accessibility_Registry_deregisterGlobalEventListenerAll (
146 cspi_event_listener_get_corba (listener),
149 return !cspi_exception ();
153 * SPI_deregisterGlobalEventListener:
154 * @listener: the #AccessibleEventListener registered against an event type.
155 * @eventType: a string specifying the event type for which this
156 * listener is to be deregistered.
158 * deregisters an AccessibleEventListener from the registry, for a specific
161 * Returns: #TRUE if successful, otherwise #FALSE.
164 SPI_deregisterGlobalEventListener (AccessibleEventListener *listener,
165 const char *eventType)
172 Accessibility_Registry_deregisterGlobalEventListener (
174 cspi_event_listener_get_corba (listener),
175 (CORBA_char *) eventType, cspi_ev ());
177 return !cspi_exception ();
181 * SPI_getDesktopCount:
183 * Get the number of virtual desktops.
184 * NOTE: currently multiple virtual desktops are not implemented, this
185 * function always returns '1'.
187 * Returns: an integer indicating the number of active virtual desktops.
190 SPI_getDesktopCount ()
194 retval = Accessibility_Registry_getDesktopCount (
195 cspi_registry (), cspi_ev ());
197 cspi_return_val_if_ev ("getDesktopCount", -1);
204 * @i: an integer indicating which of the accessible desktops is to be returned.
206 * Get the virtual desktop indicated by index @i.
207 * NOTE: currently multiple virtual desktops are not implemented, this
208 * function always returns '1'.
210 * Returns: a pointer to the 'i-th' virtual desktop's #Accessible representation.
213 SPI_getDesktop (int i)
215 return cspi_object_add (
216 Accessibility_Registry_getDesktop (
217 cspi_registry (), (CORBA_short) i, cspi_ev ()));
221 * SPI_getDesktopList:
222 * @desktop_list: a pointer to an array of #Accessible references.
224 * Get the list of virtual desktops. On return, @list will point
225 * to a newly-created, NULL terminated array of virtual desktop
227 * It is the responsibility of the caller to free this array when
228 * it is no longer needed.
230 * Not Yet Implemented : this implementation always returns a single
231 * #Accessible desktop.
233 * Returns: an integer indicating how many virtual desktops have been
234 * placed in the list pointed to by parameter @list.
237 SPI_getDesktopList (Accessible ***desktop_list)
241 Accessibility_DesktopSeq *desktops;
246 *desktop_list = NULL;
248 desktops = Accessibility_Registry_getDesktopList (cspi_registry (),
251 cspi_return_val_if_ev ("getting desktop list", 0);
253 list = g_new0 (Accessible *, desktops->_length + 1);
255 for (i = 0; i < desktops->_length; i++)
257 list [i] = cspi_object_add (
258 CORBA_Object_duplicate (desktops->_buffer [i], cspi_ev ()));
262 CORBA_free (desktops);
264 *desktop_list = list;
270 * SPI_freeDesktopList:
271 * @desktop_list: a pointer to an array of #Accessible objects
272 * as returned from @SPI_getDesktopList
274 * This routine frees the memory associated with the list.
277 SPI_freeDesktopList (Accessible **desktop_list)
281 for (p = desktop_list; p && *p; p++)
283 cspi_object_unref (*p);
285 g_free (desktop_list);
289 * SPI_registerAccessibleKeystrokeListener:
290 * @listener: a pointer to the #AccessibleKeystrokeListener for which
291 * keystroke events are requested.
292 * @keys: a pointer to the #AccessibleKeySet indicating which
293 * keystroke events are requested, or #CSPI_KEYSET_ALL_KEYS.
294 * @modmask: an #AccessibleKeyMaskType mask indicating which
295 * key event modifiers must be set in combination with @keys,
296 * events will only be reported for key events for which all
297 * modifiers in @modmask are set. If you wish to listen for
298 * events with multiple modifier combinations you must call
299 * registerAccessibleKeystrokeListener() once for each combination.
300 * @eventmask: an #AccessibleKeyMaskType mask indicating which
301 * types of key events are requested (#SPI_KEY_PRESSED, etc.).
302 * @sync_type: a #AccessibleKeyListenerSyncType parameter indicating
303 * the behavior of the notification/listener transaction.
305 * Register a listener for keystroke events, either pre-emptively for
306 * all windows (CSPI_KEYLISTENER_ALL_WINDOWS), or
307 * non-preemptively (CSPI_KEYLISTENER_NOSYNC).
308 * ( Other sync_type values may be available in the future.)
310 * Returns: #TRUE if successful, otherwise #FALSE.
313 SPI_registerAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
314 AccessibleKeySet *keys,
315 AccessibleKeyMaskType modmask,
316 AccessibleKeyEventMask eventmask,
317 AccessibleKeyListenerSyncType sync_type)
320 Accessibility_KeySet key_set;
321 Accessibility_KeyEventTypeSeq key_events;
322 Accessibility_ControllerEventMask controller_event_mask;
323 Accessibility_DeviceEventController device_event_controller;
324 Accessibility_EventListenerMode listener_mode;
331 device_event_controller =
332 Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
334 cspi_return_val_if_ev ("getting event controller", FALSE);
336 /* copy the keyval filter values from the C api into the CORBA KeySet */
339 key_set._length = keys->len;
340 key_set._buffer = Accessibility_KeySet_allocbuf (keys->len);
341 for (i = 0; i < key_set._length; ++i)
343 /* we overload the keyset long w/keycodes, the - bit acts as a flag */
344 key_set._buffer[i] = (keys->keysyms[i]) ? keys->keysyms[i] :
346 /* fprintf (stderr, "key-set %d = %d\n", i, (int) key_set->_buffer[i]); */
352 key_set._buffer = NULL;
355 /* copy the event filter values from the C api into the CORBA KeyEventTypeSeq */
360 if (mask & eventmask)
366 while (mask & 0xFFFF);
368 key_events._buffer = Accessibility_KeyEventTypeSeq_allocbuf (i);
370 if (eventmask & SPI_KEY_PRESSED)
372 key_events._buffer[i++] = Accessibility_KEY_PRESSED;
374 if (eventmask & SPI_KEY_RELEASED)
376 key_events._buffer[i++] = Accessibility_KEY_RELEASED;
378 key_events._length = i;
380 controller_event_mask = (CORBA_unsigned_long) modmask;
382 listener_mode.synchronous =
383 (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_SYNCHRONOUS)!=0);
384 listener_mode.preemptive =
385 (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_CANCONSUME)!=0);
386 listener_mode.global =
387 (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_ALL_WINDOWS)!=0);
389 Accessibility_DeviceEventController_registerKeystrokeListener (
390 device_event_controller,
391 cspi_event_listener_get_corba (listener),
393 controller_event_mask,
398 cspi_return_val_if_ev ("registering keystroke listener", FALSE);
400 cspi_release_unref (device_event_controller);
406 * SPI_deregisterAccessibleKeystrokeListener:
407 * @listener: a pointer to the #AccessibleKeystrokeListener for which
408 * keystroke events are requested.
409 * @modmask: the key modifier mask for which this listener is to be
410 * 'deregistered' (of type #AccessibleeyMaskType).
412 * Removes a keystroke event listener from the registry's listener queue,
413 * ceasing notification of events with modifiers matching @modmask.
415 * Returns: #TRUE if successful, otherwise #FALSE.
418 SPI_deregisterAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
419 AccessibleKeyMaskType modmask)
421 Accessibility_ControllerEventMask controller_event_mask;
422 Accessibility_KeySet key_set;
423 Accessibility_KeyEventTypeSeq key_events;
424 Accessibility_DeviceEventController device_event_controller;
431 device_event_controller =
432 Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
434 cspi_return_val_if_ev ("getting keystroke listener", FALSE);
436 controller_event_mask = (CORBA_unsigned_long) modmask;
438 key_events._buffer = NULL;
439 key_events._length = 0;
441 key_set._buffer = NULL;
444 Accessibility_DeviceEventController_deregisterKeystrokeListener (
445 device_event_controller,
446 cspi_event_listener_get_corba (listener),
448 controller_event_mask,
452 cspi_release_unref (device_event_controller);
458 * SPI_generateKeyboardEvent:
459 * @keyval: a long integer indicating the keycode or keysym of the key event
461 * @synth_type: a #AccessibleKeySynthType flag indicating whether @keyval
462 * is to be interpreted as a keysym rather than a keycode
463 * (CSPI_KEYSYM), or whether to synthesize
464 * SPI_KEY_PRESS, SPI_KEY_RELEASE, or both (SPI_KEY_PRESSRELEASE).
466 * Synthesize a keyboard event (as if a hardware keyboard event occurred in the
467 * current UI context).
469 * Returns: #TRUE if successful, otherwise #FALSE.
472 SPI_generateKeyboardEvent (long int keyval,
474 AccessibleKeySynthType synth_type)
476 /* TODO: check current modifier status and
477 * send keycode to alter, if necessary
480 /* TODO: implement keystring use case */
481 Accessibility_KeySynthType keysynth_type;
482 Accessibility_DeviceEventController device_event_controller =
483 Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
485 cspi_return_val_if_ev ("getting event controller for key event gen", FALSE);
490 keysynth_type = Accessibility_KEY_PRESS;
492 case SPI_KEY_RELEASE:
493 keysynth_type = Accessibility_KEY_RELEASE;
495 case SPI_KEY_PRESSRELEASE:
496 keysynth_type = Accessibility_KEY_PRESSRELEASE;
499 keysynth_type = Accessibility_KEY_SYM;
502 keysynth_type = Accessibility_KEY_STRING;
506 Accessibility_DeviceEventController_generateKeyboardEvent (device_event_controller,
512 cspi_return_val_if_ev ("generating keyboard event", FALSE);
514 cspi_release_unref (device_event_controller);
520 * SPI_generateMouseEvent:
521 * @x: a #long indicating the screen x coordinate of the mouse event.
522 * @y: a #long indicating the screen y coordinate of the mouse event.
523 * @name: a string indicating which mouse event to be synthesized
524 * (e.g. "button1", "button2", "mousemove").
526 * Synthesize a mouse event at a specific screen coordinate.
527 * Most AT clients should use the #AccessibleAction interface when
528 * tempted to generate mouse events, rather than this method.
529 * Not Yet Implemented.
531 * Returns: #TRUE if successful, otherwise #FALSE.
534 SPI_generateMouseEvent (long x, long y, char *name)