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 /* spi_registry.c: Global functions wrapping the registry */
26 #include <cspi/spi-private.h>
29 * SPI_registerGlobalEventListener:
30 * @listener: the #AccessibleEventListener to be registered against an
32 * @eventType: a character string indicating the type of events for which
33 * notification is requested. Format is
34 * EventClass:major_type:minor_type:detail
35 * where all subfields other than EventClass are optional.
36 * EventClasses include "object", "window", "mouse",
37 * and toolkit events (e.g. "Gtk", "AWT").
38 * Examples: "focus:", "Gtk:GtkWidget:button_press_event".
40 * Legal object event types:
42 * (property change events)
44 * object:property-change
45 * object:property-change:accessible-name
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:state-changed
60 * object:children-changed
61 * object:visible-data-changed
62 * object:selection-changed
63 * object:text-selection-changed
65 * object:text-caret-moved
67 * object:row-reordered
69 * object:column-inserted
70 * object:column-reordered
71 * object:column-deleted
72 * object:model-changed
82 * window:desktop-create
83 * window:desktop-destroy
106 * NOTE: this string may be UTF-8, but should not contain byte value 56
107 * (ascii ':'), except as a delimiter, since non-UTF-8 string
108 * delimiting functions are used internally.
109 * In general, listening to
110 * toolkit-specific events is not recommended.
112 * Add an in-process callback function to an existing AccessibleEventListener.
114 * Returns: #TRUE if successful, otherwise #FALSE.
117 SPI_registerGlobalEventListener (AccessibleEventListener *listener,
118 const char *eventType)
125 Accessibility_Registry_registerGlobalEventListener (
127 cspi_event_listener_get_corba (listener),
128 eventType, cspi_ev ());
130 return !cspi_exception ();
134 * SPI_deregisterGlobalEventListenerAll:
135 * @listener: the #AccessibleEventListener to be registered against
138 * deregisters an AccessibleEventListener from the registry, for all
139 * event types it may be listening to. Use
140 * AccessibleEventListener_unref to release the
141 * listener reference.
143 * Returns: #TRUE if successful, otherwise #FALSE.
146 SPI_deregisterGlobalEventListenerAll (AccessibleEventListener *listener)
153 Accessibility_Registry_deregisterGlobalEventListenerAll (
155 cspi_event_listener_get_corba (listener),
158 return !cspi_exception ();
162 * SPI_deregisterGlobalEventListener:
163 * @listener: the #AccessibleEventListener registered against an event type.
164 * @eventType: a string specifying the event type for which this
165 * listener is to be deregistered.
167 * deregisters an AccessibleEventListener from the registry, for a specific
170 * Returns: #TRUE if successful, otherwise #FALSE.
173 SPI_deregisterGlobalEventListener (AccessibleEventListener *listener,
174 const char *eventType)
181 Accessibility_Registry_deregisterGlobalEventListener (
183 cspi_event_listener_get_corba (listener),
184 eventType, cspi_ev ());
186 return !cspi_exception ();
190 * SPI_getDesktopCount:
192 * Get the number of virtual desktops.
193 * NOTE: currently multiple virtual desktops are not implemented, this
194 * function always returns '1'.
196 * Returns: an integer indicating the number of active virtual desktops.
199 SPI_getDesktopCount ()
203 retval = Accessibility_Registry_getDesktopCount (
204 cspi_registry (), cspi_ev ());
206 cspi_return_val_if_ev ("getDesktopCount", -1);
213 * @i: an integer indicating which of the accessible desktops is to be returned.
215 * Get the virtual desktop indicated by index @i.
216 * NOTE: currently multiple virtual desktops are not implemented, this
217 * function always returns '1'.
219 * Returns: a pointer to the 'i-th' virtual desktop's #Accessible representation.
222 SPI_getDesktop (int i)
224 return cspi_object_add (
225 Accessibility_Registry_getDesktop (
226 cspi_registry (), i, cspi_ev ()));
230 * SPI_getDesktopList:
231 * @desktop_list: a pointer to an array of #Accessible references.
233 * Get the list of virtual desktops. On return, @list will point
234 * to a newly-created, NULL terminated array of virtual desktop
236 * It is the responsibility of the caller to free this array when
237 * it is no longer needed.
239 * Not Yet Implemented : this implementation always returns a single
240 * #Accessible desktop.
242 * Returns: an integer indicating how many virtual desktops have been
243 * placed in the list pointed to by parameter @list.
246 SPI_getDesktopList (Accessible ***desktop_list)
250 Accessibility_DesktopSeq *desktops;
255 *desktop_list = NULL;
257 desktops = Accessibility_Registry_getDesktopList (cspi_registry (),
260 cspi_return_val_if_ev ("getDesktopList", 0);
262 list = g_new0 (Accessible *, desktops->_length + 1);
264 for (i = 0; i < desktops->_length; i++)
266 list [i] = cspi_object_add (
267 CORBA_Object_duplicate (desktops->_buffer [i], cspi_ev ()));
271 CORBA_free (desktops);
273 *desktop_list = list;
279 * SPI_freeDesktopList:
280 * @desktop_list: a pointer to an array of #Accessible objects
281 * as returned from @SPI_getDesktopList
283 * This routine frees the memory associated with the list.
286 SPI_freeDesktopList (Accessible **desktop_list)
290 for (p = desktop_list; p && *p; p++)
292 cspi_object_unref (*p);
294 g_free (desktop_list);
298 * SPI_KEYSET_ALL_KEYS:
299 * @SPI_KEYSET_ALL_KEYS: A special value for an AccessibleKeySet type, which tacitly
300 * includes all keycodes and keyvals for the specified modifier set.
304 * SPI_registerAccessibleKeystrokeListener:
305 * @listener: a pointer to the #AccessibleKeystrokeListener for which
306 * keystroke events are requested.
307 * @keys: a pointer to the #AccessibleKeySet indicating which
308 * keystroke events are requested, or #CSPI_KEYSET_ALL_KEYS.
309 * @modmask: an #AccessibleKeyMaskType mask indicating which
310 * key event modifiers must be set in combination with @keys,
311 * events will only be reported for key events for which all
312 * modifiers in @modmask are set. If you wish to listen for
313 * events with multiple modifier combinations you must call
314 * registerAccessibleKeystrokeListener() once for each combination.
315 * @eventmask: an #AccessibleKeyMaskType mask indicating which
316 * types of key events are requested (#SPI_KEY_PRESSED, etc.).
317 * @sync_type: a #AccessibleKeyListenerSyncType parameter indicating
318 * the behavior of the notification/listener transaction.
320 * Register a listener for keystroke events, either pre-emptively for
321 * all windows (CSPI_KEYLISTENER_ALL_WINDOWS), or
322 * non-preemptively (CSPI_KEYLISTENER_NOSYNC).
323 * ( Other sync_type values may be available in the future.)
325 * Returns: #TRUE if successful, otherwise #FALSE.
328 SPI_registerAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
329 AccessibleKeySet *keys,
330 AccessibleKeyMaskType modmask,
331 AccessibleKeyEventMask eventmask,
332 AccessibleKeyListenerSyncType sync_type)
335 Accessibility_KeySet key_set;
336 Accessibility_KeyEventTypeSeq key_events;
337 Accessibility_ControllerEventMask controller_event_mask;
338 Accessibility_DeviceEventController device_event_controller;
339 Accessibility_EventListenerMode listener_mode;
340 SPIBoolean retval = FALSE;
347 device_event_controller =
348 Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
350 cspi_return_val_if_ev ("getting event controller", FALSE);
352 /* copy the keyval filter values from the C api into the CORBA KeySet */
355 key_set._length = keys->len;
356 key_set._buffer = Accessibility_KeySet_allocbuf (keys->len);
357 for (i = 0; i < key_set._length; ++i)
359 key_set._buffer[i].keycode = keys->keycodes[i];
360 key_set._buffer[i].keysym = keys->keysyms[i];
361 if (keys->keystrings && keys->keystrings[i])
363 key_set._buffer[i].keystring = keys->keystrings[i];
367 key_set._buffer[i].keystring = CORBA_string_dup("");
374 key_set._buffer = NULL;
377 /* copy the event filter values from the C api into the CORBA KeyEventTypeSeq */
382 if (mask & eventmask)
388 while (mask & 0xFFFF);
390 key_events._buffer = Accessibility_KeyEventTypeSeq_allocbuf (i);
392 if (eventmask & SPI_KEY_PRESSED)
394 key_events._buffer[i++] = Accessibility_KEY_PRESSED;
396 if (eventmask & SPI_KEY_RELEASED)
398 key_events._buffer[i++] = Accessibility_KEY_RELEASED;
400 key_events._length = i;
402 controller_event_mask = (CORBA_unsigned_long) modmask;
404 listener_mode.synchronous =
405 (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_SYNCHRONOUS)!=0);
406 listener_mode.preemptive =
407 (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_CANCONSUME)!=0);
408 listener_mode.global =
409 (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_ALL_WINDOWS)!=0);
411 retval = Accessibility_DeviceEventController_registerKeystrokeListener (
412 device_event_controller,
413 cspi_event_listener_get_corba (listener),
415 controller_event_mask,
420 cspi_return_val_if_ev ("registering keystroke listener", FALSE);
422 cspi_release_unref (device_event_controller);
428 * SPI_deregisterAccessibleKeystrokeListener:
429 * @listener: a pointer to the #AccessibleKeystrokeListener for which
430 * keystroke events are requested.
431 * @modmask: the key modifier mask for which this listener is to be
432 * 'deregistered' (of type #AccessibleeyMaskType).
434 * Removes a keystroke event listener from the registry's listener queue,
435 * ceasing notification of events with modifiers matching @modmask.
437 * Returns: #TRUE if successful, otherwise #FALSE.
440 SPI_deregisterAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
441 AccessibleKeyMaskType modmask)
443 Accessibility_ControllerEventMask controller_event_mask;
444 Accessibility_KeySet key_set;
445 Accessibility_KeyEventTypeSeq key_events;
446 Accessibility_DeviceEventController device_event_controller;
453 device_event_controller =
454 Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
456 cspi_return_val_if_ev ("getting keystroke listener", FALSE);
458 controller_event_mask = (CORBA_unsigned_long) modmask;
460 key_events._buffer = NULL;
461 key_events._length = 0;
463 key_set._buffer = NULL;
466 Accessibility_DeviceEventController_deregisterKeystrokeListener (
467 device_event_controller,
468 cspi_event_listener_get_corba (listener),
470 controller_event_mask,
474 cspi_release_unref (device_event_controller);
480 * SPI_generateKeyboardEvent:
481 * @keyval: a long integer indicating the keycode or keysym of the key event
483 * @keystring: an (optional) UTF-8 string which, if @keyval is NULL,
484 * indicates a 'composed' keyboard input string which is
485 * being synthesized; this type of keyboard event synthesis does
486 * not emulate hardware keypresses but injects the string
487 * as though a composing input method (such as XIM) were used.
488 * @synth_type: a #AccessibleKeySynthType flag indicating whether @keyval
489 * is to be interpreted as a keysym rather than a keycode
490 * (CSPI_KEYSYM), or whether to synthesize
491 * SPI_KEY_PRESS, SPI_KEY_RELEASE, or both (SPI_KEY_PRESSRELEASE).
493 * Synthesize a keyboard event (as if a hardware keyboard event occurred in the
494 * current UI context).
496 * Returns: #TRUE if successful, otherwise #FALSE.
499 SPI_generateKeyboardEvent (long int keyval,
501 AccessibleKeySynthType synth_type)
503 /* TODO: check current modifier status and
504 * send keycode to alter, if necessary
507 /* TODO: implement keystring use case */
508 Accessibility_KeySynthType keysynth_type;
509 Accessibility_DeviceEventController device_event_controller =
510 Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
512 cspi_return_val_if_ev ("getting event controller for key event gen", FALSE);
517 keysynth_type = Accessibility_KEY_PRESS;
519 case SPI_KEY_RELEASE:
520 keysynth_type = Accessibility_KEY_RELEASE;
522 case SPI_KEY_PRESSRELEASE:
523 keysynth_type = Accessibility_KEY_PRESSRELEASE;
526 keysynth_type = Accessibility_KEY_SYM;
529 keysynth_type = Accessibility_KEY_STRING;
535 Accessibility_DeviceEventController_generateKeyboardEvent (device_event_controller,
541 cspi_return_val_if_ev ("generating keyboard event", FALSE);
543 cspi_release_unref (device_event_controller);
549 * SPI_generateMouseEvent:
550 * @x: a #long indicating the screen x coordinate of the mouse event.
551 * @y: a #long indicating the screen y coordinate of the mouse event.
552 * @name: a string indicating which mouse event to be synthesized
553 * (e.g. "b1p", "b1c", "b2r", "rel", "abs").
555 * Synthesize a mouse event at a specific screen coordinate.
556 * Most AT clients should use the #AccessibleAction interface when
557 * tempted to generate mouse events, rather than this method.
558 * Event names: b1p = button 1 press; b2r = button 2 release;
559 * b3c = button 3 click; b2d = button 2 double-click;
560 * abs = absolute motion; rel = relative motion.
562 * Returns: #TRUE if successful, otherwise #FALSE.
565 SPI_generateMouseEvent (long x, long y, char *name)
567 Accessibility_DeviceEventController device_event_controller =
568 Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
570 cspi_return_val_if_ev ("getting event controller for mouse event gen", FALSE);
572 Accessibility_DeviceEventController_generateMouseEvent (device_event_controller,
573 x, y, name, cspi_ev ());
574 cspi_return_val_if_ev ("generating mouse event", FALSE);
576 cspi_release_unref (device_event_controller);