Updated NEWS; committed Marc's patch for state-change events
[platform/core/uifw/at-spi2-atk.git] / cspi / spi_registry.c
index 0d75803..904c857 100644 (file)
@@ -42,7 +42,6 @@
  *
  *            object:property-change
  *            object:property-change:accessible-name
- *            object:property-change:accessible-state
  *            object:property-change:accessible-description
  *            object:property-change:accessible-parent
  *            object:property-change:accessible-value
@@ -56,6 +55,7 @@
  *
  *    (other object events)
  *
+ *            object:state-changed 
  *            object:children-changed
  *            object:visible-data-changed
  *            object:selection-changed
  *            object:column-deleted
  *            object:model-changed
  *
+ *  (window events)
+ *
+ *            window:minimize
+ *            window:maximize
+ *            window:restore
+ *            window:close
+ *            window:create
+ *            window:reparent
+ *            window:desktop-create
+ *            window:desktop-destroy
+ *            window:focus-in
+ *            window:focus-out
+ *            window:raise
+ *            window:lower
+ *            window:move
+ *            window:resize
+ *            window:shade
+ *            window:unshade
+ *            window:restyle
+ *
  * NOTE: this string may be UTF-8, but should not contain byte value 56
  *            (ascii ':'), except as a delimiter, since non-UTF-8 string
  *            delimiting functions are used internally.
@@ -199,10 +219,11 @@ SPI_getDesktop (int i)
 
 /**
  * SPI_getDesktopList:
- * @list: a pointer to an array of #Accessible objects.
+ * @desktop_list: a pointer to an array of #Accessible references.
  *
  * Get the list of virtual desktops.  On return, @list will point
- *     to a newly-created array of virtual desktop pointers.
+ *     to a newly-created, NULL terminated array of virtual desktop
+ *     pointers.
  *     It is the responsibility of the caller to free this array when
  *     it is no longer needed.
  *
@@ -213,13 +234,64 @@ SPI_getDesktop (int i)
  *          placed in the list pointed to by parameter @list.
  **/
 int
-SPI_getDesktopList (Accessible **list)
+SPI_getDesktopList (Accessible ***desktop_list)
 {
-  *list = NULL;
-  return 0;
+  int i;
+  Accessible **list;
+  Accessibility_DesktopSeq *desktops;
+
+  if (!desktop_list)
+         return 0;
+
+  *desktop_list = NULL;
+
+  desktops = Accessibility_Registry_getDesktopList (cspi_registry (),
+                                                   cspi_ev ());
+
+  cspi_return_val_if_ev ("getting desktop list", 0);
+
+  list = g_new0 (Accessible *, desktops->_length + 1);
+
+  for (i = 0; i < desktops->_length; i++)
+    {
+      list [i] = cspi_object_add (
+             CORBA_Object_duplicate (desktops->_buffer [i], cspi_ev ()));
+    }
+  list [i] = NULL;
+
+  CORBA_free (desktops);
+
+  *desktop_list = list;
+
+  return i;
 }
 
 /**
+ * SPI_freeDesktopList:
+ * @desktop_list: a pointer to an array of #Accessible objects
+ * as returned from @SPI_getDesktopList
+ * 
+ * This routine frees the memory associated with the list.
+ **/
+void
+SPI_freeDesktopList (Accessible **desktop_list)
+{
+  Accessible **p;
+  
+  for (p = desktop_list; p && *p; p++)
+    {
+      cspi_object_unref (*p);
+    }
+  g_free (desktop_list);
+}
+
+/**
+ * SPI_KEYSET_ALL_KEYS:
+ * @SPI_KEYSET_ALL_KEYS: A special value for an AccessibleKeySet type, which tacitly
+ *                       includes all keycodes and keyvals for the specified modifier set.
+ **/
+
+/**
  * SPI_registerAccessibleKeystrokeListener:
  * @listener:  a pointer to the #AccessibleKeystrokeListener for which
  *             keystroke events are requested.
@@ -244,10 +316,10 @@ SPI_getDesktopList (Accessible **list)
  * Returns: #TRUE if successful, otherwise #FALSE.
  **/
 SPIBoolean
-SPI_registerAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
-                                        AccessibleKeySet *keys,
-                                        AccessibleKeyMaskType modmask,
-                                        AccessibleKeyEventMask eventmask,
+SPI_registerAccessibleKeystrokeListener (AccessibleKeystrokeListener  *listener,
+                                        AccessibleKeySet             *keys,
+                                        AccessibleKeyMaskType         modmask,
+                                        AccessibleKeyEventMask        eventmask,
                                         AccessibleKeyListenerSyncType sync_type)
 {
   gint                                i, mask;
@@ -255,6 +327,7 @@ SPI_registerAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
   Accessibility_KeyEventTypeSeq       key_events;
   Accessibility_ControllerEventMask   controller_event_mask;
   Accessibility_DeviceEventController device_event_controller;
+  Accessibility_EventListenerMode     listener_mode;
 
   if (!listener)
     {
@@ -312,13 +385,20 @@ SPI_registerAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
   
   controller_event_mask = (CORBA_unsigned_long) modmask;
 
+  listener_mode.synchronous =
+         (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_SYNCHRONOUS)!=0);
+  listener_mode.preemptive =
+         (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_CANCONSUME)!=0);
+  listener_mode.global =
+         (CORBA_boolean) ((sync_type & SPI_KEYLISTENER_ALL_WINDOWS)!=0);
+
   Accessibility_DeviceEventController_registerKeystrokeListener (
     device_event_controller,
     cspi_event_listener_get_corba (listener),
     &key_set,
     controller_event_mask,
     &key_events,
-    ((sync_type & SPI_KEYLISTENER_ALL_WINDOWS)!=0) ? CORBA_TRUE : CORBA_FALSE,
+    &listener_mode,
     cspi_ev ());
 
   cspi_return_val_if_ev ("registering keystroke listener", FALSE);
@@ -342,7 +422,7 @@ SPI_registerAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
  **/
 SPIBoolean
 SPI_deregisterAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
-                                          AccessibleKeyMaskType modmask)
+                                          AccessibleKeyMaskType        modmask)
 {
   Accessibility_ControllerEventMask   controller_event_mask;
   Accessibility_KeySet                key_set;
@@ -373,7 +453,6 @@ SPI_deregisterAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener
     &key_set,
     controller_event_mask,
     &key_events,
-    (CORBA_boolean) TRUE,
     cspi_ev ());
 
   cspi_release_unref (device_event_controller);
@@ -382,9 +461,14 @@ SPI_deregisterAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener
 }
 
 /**
- * SPI_generateKeyEvent:
+ * SPI_generateKeyboardEvent:
  * @keyval: a long integer indicating the keycode or keysym of the key event
  *           being synthesized.
+ * @keystring: an (optional) UTF-8 string which, if @keyval is NULL,
+ *           indicates a 'composed' keyboard input string which is 
+ *           being synthesized; this type of keyboard event synthesis does
+ *           not emulate hardware keypresses but injects the string 
+ *           as though a composing input method (such as XIM) were used.
  * @synth_type: a #AccessibleKeySynthType flag indicating whether @keyval
  *           is to be interpreted as a keysym rather than a keycode
  *           (CSPI_KEYSYM), or whether to synthesize
@@ -396,21 +480,49 @@ SPI_deregisterAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener
  * Returns: #TRUE if successful, otherwise #FALSE.
  **/
 SPIBoolean
-SPI_generateKeyEvent (long int keyval, AccessibleKeySynthType synth_type)
+SPI_generateKeyboardEvent (long int keyval,
+                          char *keystring,
+                          AccessibleKeySynthType synth_type)
 {
 /* TODO: check current modifier status and
  *  send keycode to alter, if necessary
  */
+       
+  /* TODO: implement keystring use case */
+  Accessibility_KeySynthType keysynth_type;
   Accessibility_DeviceEventController device_event_controller = 
          Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
 
-  g_print ("keyval %d\n", (int) keyval);
-  cspi_return_val_if_ev ("getting event controller", FALSE);
+  cspi_return_val_if_ev ("getting event controller for key event gen", FALSE);
+
+  switch (synth_type)
+    {
+      case SPI_KEY_PRESS:
+         keysynth_type = Accessibility_KEY_PRESS;
+         break;
+      case SPI_KEY_RELEASE:
+         keysynth_type = Accessibility_KEY_RELEASE;
+         break;
+      case SPI_KEY_PRESSRELEASE:
+         keysynth_type = Accessibility_KEY_PRESSRELEASE;
+         break;
+      case SPI_KEY_SYM:
+         keysynth_type = Accessibility_KEY_SYM;
+         break;
+      case SPI_KEY_STRING:
+         keysynth_type = Accessibility_KEY_STRING;
+         break;
+      default:
+          return FALSE;
+    }
 
-  Accessibility_DeviceEventController_generateKeyEvent (device_event_controller,
-                                                       keyval,
-                                                       (unsigned long) synth_type,
-                                                       cspi_ev ());
+  Accessibility_DeviceEventController_generateKeyboardEvent (device_event_controller,
+                                                            keyval,
+                                                            "",
+                                                            keysynth_type,
+                                                            cspi_ev ());
+
+  cspi_return_val_if_ev ("generating keyboard event", FALSE);
 
   cspi_release_unref (device_event_controller);
 
@@ -422,18 +534,31 @@ SPI_generateKeyEvent (long int keyval, AccessibleKeySynthType synth_type)
  * @x: a #long indicating the screen x coordinate of the mouse event.
  * @y: a #long indicating the screen y coordinate of the mouse event.
  * @name: a string indicating which mouse event to be synthesized
- *        (e.g. "button1", "button2", "mousemove").
+ *        (e.g. "b1p", "b1c", "b2r", "rel", "abs").
  *
  * Synthesize a mouse event at a specific screen coordinate.
  * Most AT clients should use the #AccessibleAction interface when
  * tempted to generate mouse events, rather than this method.
- * Not Yet Implemented.
+ * Event names: b1p = button 1 press; b2r = button 2 release;
+ *              b3c = button 3 click; b2d = button 2 double-click;
+ *              abs = absolute motion; rel = relative motion.
  *
  * Returns: #TRUE if successful, otherwise #FALSE.
  **/
 SPIBoolean
 SPI_generateMouseEvent (long x, long y, char *name)
 {
-  return FALSE;
+  Accessibility_DeviceEventController device_event_controller = 
+         Accessibility_Registry_getDeviceEventController (cspi_registry (), cspi_ev ());
+
+  cspi_return_val_if_ev ("getting event controller for mouse event gen", FALSE);
+
+  Accessibility_DeviceEventController_generateMouseEvent (device_event_controller,
+                                                         x, y, name, cspi_ev ());
+  cspi_return_val_if_ev ("generating mouse event", FALSE);
+
+  cspi_release_unref (device_event_controller);
+
+  return TRUE;
 }