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-description
46 * object:property-change:accessible-parent
47 * object:property-change:accessible-value
48 * object:property-change:accessible-role
49 * object:property-change:accessible-table-caption
50 * object:property-change:accessible-table-column-description
51 * object:property-change:accessible-table-column-header
52 * object:property-change:accessible-table-row-description
53 * object:property-change:accessible-table-row-header
54 * object:property-change:accessible-table-summary
56 * (other object events)
58 * object:state-changed
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)
112 Accessibility_Registry_registerGlobalEventListener (
114 cspi_event_listener_get_corba (listener),
115 eventType, cspi_ev ());
117 return !cspi_exception ();
121 * SPI_deregisterGlobalEventListenerAll:
122 * @listener: the #AccessibleEventListener to be registered against
125 * deregisters an AccessibleEventListener from the registry, for all
126 * event types it may be listening to. Use
127 * AccessibleEventListener_unref to release the
128 * listener reference.
130 * Returns: #TRUE if successful, otherwise #FALSE.
133 SPI_deregisterGlobalEventListenerAll (AccessibleEventListener *listener)
140 Accessibility_Registry_deregisterGlobalEventListenerAll (
142 cspi_event_listener_get_corba (listener),
145 return !cspi_exception ();
149 * SPI_deregisterGlobalEventListener:
150 * @listener: the #AccessibleEventListener registered against an event type.
151 * @eventType: a string specifying the event type for which this
152 * listener is to be deregistered.
154 * deregisters an AccessibleEventListener from the registry, for a specific
157 * Returns: #TRUE if successful, otherwise #FALSE.
160 SPI_deregisterGlobalEventListener (AccessibleEventListener *listener,
161 const char *eventType)
168 Accessibility_Registry_deregisterGlobalEventListener (
170 cspi_event_listener_get_corba (listener),
171 eventType, cspi_ev ());
173 return !cspi_exception ();
177 * SPI_getDesktopCount:
179 * Get the number of virtual desktops.
180 * NOTE: currently multiple virtual desktops are not implemented, this
181 * function always returns '1'.
183 * Returns: an integer indicating the number of active virtual desktops.
186 SPI_getDesktopCount ()
190 retval = Accessibility_Registry_getDesktopCount (
191 cspi_registry (), cspi_ev ());
193 cspi_return_val_if_ev ("getDesktopCount", -1);
200 * @i: an integer indicating which of the accessible desktops is to be returned.
202 * Get the virtual desktop indicated by index @i.
203 * NOTE: currently multiple virtual desktops are not implemented, this
204 * function always returns '1'.
206 * Returns: a pointer to the 'i-th' virtual desktop's #Accessible representation.
209 SPI_getDesktop (int i)
211 return cspi_object_add (
212 Accessibility_Registry_getDesktop (
213 cspi_registry (), i, cspi_ev ()));
217 * SPI_getDesktopList:
218 * @desktop_list: a pointer to an array of #Accessible references.
220 * Get the list of virtual desktops. On return, @list will point
221 * to a newly-created, NULL terminated array of virtual desktop
223 * It is the responsibility of the caller to free this array when
224 * it is no longer needed.
226 * Not Yet Implemented : this implementation always returns a single
227 * #Accessible desktop.
229 * Returns: an integer indicating how many virtual desktops have been
230 * placed in the list pointed to by parameter @list.
233 SPI_getDesktopList (Accessible ***desktop_list)
237 Accessibility_DesktopSeq *desktops;
242 *desktop_list = NULL;
244 desktops = Accessibility_Registry_getDesktopList (cspi_registry (),
247 cspi_return_val_if_ev ("getDesktopList", 0);
249 list = g_new0 (Accessible *, desktops->_length + 1);
251 for (i = 0; i < desktops->_length; i++)
253 list [i] = cspi_object_add (
254 CORBA_Object_duplicate (desktops->_buffer [i], cspi_ev ()));
258 CORBA_free (desktops);
260 *desktop_list = list;
266 * SPI_freeDesktopList:
267 * @desktop_list: a pointer to an array of #Accessible objects
268 * as returned from @SPI_getDesktopList
270 * This routine frees the memory associated with the list.
273 SPI_freeDesktopList (Accessible **desktop_list)
277 for (p = desktop_list; p && *p; p++)
279 cspi_object_unref (*p);
281 g_free (desktop_list);
285 * SPI_KEYSET_ALL_KEYS:
286 * @SPI_KEYSET_ALL_KEYS: A special value for an AccessibleKeySet type, which tacitly
287 * includes all keycodes and keyvals for the specified modifier set.
291 * SPI_registerAccessibleKeystrokeListener:
292 * @listener: a pointer to the #AccessibleKeystrokeListener for which
293 * keystroke events are requested.
294 * @keys: a pointer to the #AccessibleKeySet indicating which
295 * keystroke events are requested, or #CSPI_KEYSET_ALL_KEYS.
296 * @modmask: an #AccessibleKeyMaskType mask indicating which
297 * key event modifiers must be set in combination with @keys,
298 * events will only be reported for key events for which all
299 * modifiers in @modmask are set. If you wish to listen for
300 * events with multiple modifier combinations you must call
301 * registerAccessibleKeystrokeListener() once for each combination.
302 * @eventmask: an #AccessibleKeyMaskType mask indicating which
303 * types of key events are requested (#SPI_KEY_PRESSED, etc.).
304 * @sync_type: a #AccessibleKeyListenerSyncType parameter indicating
305 * the behavior of the notification/listener transaction.
307 * Register a listener for keystroke events, either pre-emptively for
308 * all windows (CSPI_KEYLISTENER_ALL_WINDOWS), or
309 * non-preemptively (CSPI_KEYLISTENER_NOSYNC).
310 * ( Other sync_type values may be available in the future.)
312 * Returns: #TRUE if successful, otherwise #FALSE.
315 SPI_registerAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
316 AccessibleKeySet *keys,
317 AccessibleKeyMaskType modmask,
318 AccessibleKeyEventMask eventmask,
319 AccessibleKeyListenerSyncType sync_type)
322 Accessibility_KeySet key_set;
323 Accessibility_KeyEventTypeSeq key_events;
324 Accessibility_ControllerEventMask controller_event_mask;
325 Accessibility_DeviceEventController device_event_controller;
326 Accessibility_EventListenerMode listener_mode;
333 device_event_controller =
334 Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
336 cspi_return_val_if_ev ("getting event controller", FALSE);
338 /* copy the keyval filter values from the C api into the CORBA KeySet */
341 key_set._length = keys->len;
342 key_set._buffer = Accessibility_KeySet_allocbuf (keys->len);
343 for (i = 0; i < key_set._length; ++i)
345 key_set._buffer[i].keycode = keys->keycodes[i];
346 key_set._buffer[i].keysym = keys->keysyms[i];
347 if (keys->keystrings && keys->keystrings[i])
349 key_set._buffer[i].keystring = keys->keystrings[i];
353 key_set._buffer[i].keystring = CORBA_string_dup("");
360 key_set._buffer = NULL;
363 /* copy the event filter values from the C api into the CORBA KeyEventTypeSeq */
368 if (mask & eventmask)
374 while (mask & 0xFFFF);
376 key_events._buffer = Accessibility_KeyEventTypeSeq_allocbuf (i);
378 if (eventmask & SPI_KEY_PRESSED)
380 key_events._buffer[i++] = Accessibility_KEY_PRESSED;
382 if (eventmask & SPI_KEY_RELEASED)
384 key_events._buffer[i++] = Accessibility_KEY_RELEASED;
386 key_events._length = i;
388 controller_event_mask = (CORBA_unsigned_long) modmask;
390 listener_mode.synchronous =
391 (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_SYNCHRONOUS)!=0);
392 listener_mode.preemptive =
393 (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_CANCONSUME)!=0);
394 listener_mode.global =
395 (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_ALL_WINDOWS)!=0);
397 Accessibility_DeviceEventController_registerKeystrokeListener (
398 device_event_controller,
399 cspi_event_listener_get_corba (listener),
401 controller_event_mask,
406 cspi_return_val_if_ev ("registering keystroke listener", FALSE);
408 cspi_release_unref (device_event_controller);
414 * SPI_deregisterAccessibleKeystrokeListener:
415 * @listener: a pointer to the #AccessibleKeystrokeListener for which
416 * keystroke events are requested.
417 * @modmask: the key modifier mask for which this listener is to be
418 * 'deregistered' (of type #AccessibleeyMaskType).
420 * Removes a keystroke event listener from the registry's listener queue,
421 * ceasing notification of events with modifiers matching @modmask.
423 * Returns: #TRUE if successful, otherwise #FALSE.
426 SPI_deregisterAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
427 AccessibleKeyMaskType modmask)
429 Accessibility_ControllerEventMask controller_event_mask;
430 Accessibility_KeySet key_set;
431 Accessibility_KeyEventTypeSeq key_events;
432 Accessibility_DeviceEventController device_event_controller;
439 device_event_controller =
440 Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
442 cspi_return_val_if_ev ("getting keystroke listener", FALSE);
444 controller_event_mask = (CORBA_unsigned_long) modmask;
446 key_events._buffer = NULL;
447 key_events._length = 0;
449 key_set._buffer = NULL;
452 Accessibility_DeviceEventController_deregisterKeystrokeListener (
453 device_event_controller,
454 cspi_event_listener_get_corba (listener),
456 controller_event_mask,
460 cspi_release_unref (device_event_controller);
466 * SPI_generateKeyboardEvent:
467 * @keyval: a long integer indicating the keycode or keysym of the key event
469 * @keystring: an (optional) UTF-8 string which, if @keyval is NULL,
470 * indicates a 'composed' keyboard input string which is
471 * being synthesized; this type of keyboard event synthesis does
472 * not emulate hardware keypresses but injects the string
473 * as though a composing input method (such as XIM) were used.
474 * @synth_type: a #AccessibleKeySynthType flag indicating whether @keyval
475 * is to be interpreted as a keysym rather than a keycode
476 * (CSPI_KEYSYM), or whether to synthesize
477 * SPI_KEY_PRESS, SPI_KEY_RELEASE, or both (SPI_KEY_PRESSRELEASE).
479 * Synthesize a keyboard event (as if a hardware keyboard event occurred in the
480 * current UI context).
482 * Returns: #TRUE if successful, otherwise #FALSE.
485 SPI_generateKeyboardEvent (long int keyval,
487 AccessibleKeySynthType synth_type)
489 /* TODO: check current modifier status and
490 * send keycode to alter, if necessary
493 /* TODO: implement keystring use case */
494 Accessibility_KeySynthType keysynth_type;
495 Accessibility_DeviceEventController device_event_controller =
496 Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
498 cspi_return_val_if_ev ("getting event controller for key event gen", FALSE);
503 keysynth_type = Accessibility_KEY_PRESS;
505 case SPI_KEY_RELEASE:
506 keysynth_type = Accessibility_KEY_RELEASE;
508 case SPI_KEY_PRESSRELEASE:
509 keysynth_type = Accessibility_KEY_PRESSRELEASE;
512 keysynth_type = Accessibility_KEY_SYM;
515 keysynth_type = Accessibility_KEY_STRING;
521 Accessibility_DeviceEventController_generateKeyboardEvent (device_event_controller,
527 cspi_return_val_if_ev ("generating keyboard event", FALSE);
529 cspi_release_unref (device_event_controller);
535 * SPI_generateMouseEvent:
536 * @x: a #long indicating the screen x coordinate of the mouse event.
537 * @y: a #long indicating the screen y coordinate of the mouse event.
538 * @name: a string indicating which mouse event to be synthesized
539 * (e.g. "b1p", "b1c", "b2r", "rel", "abs").
541 * Synthesize a mouse event at a specific screen coordinate.
542 * Most AT clients should use the #AccessibleAction interface when
543 * tempted to generate mouse events, rather than this method.
544 * Event names: b1p = button 1 press; b2r = button 2 release;
545 * b3c = button 3 click; b2d = button 2 double-click;
546 * abs = absolute motion; rel = relative motion.
548 * Returns: #TRUE if successful, otherwise #FALSE.
551 SPI_generateMouseEvent (long x, long y, char *name)
553 Accessibility_DeviceEventController device_event_controller =
554 Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
556 cspi_return_val_if_ev ("getting event controller for mouse event gen", FALSE);
558 Accessibility_DeviceEventController_generateMouseEvent (device_event_controller,
559 x, y, name, cspi_ev ());
560 cspi_return_val_if_ev ("generating mouse event", FALSE);
562 cspi_release_unref (device_event_controller);