Added missing Table methods (RT approval from MMeeks, 15 April).
[platform/core/uifw/at-spi2-atk.git] / cspi / spi_event.c
index a6280e0..469dedc 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+#include <cspi/spi-private.h>
+
+
+
+/**
+ * SPI_freeAccessibleKeySet:
+ * @keyset: An AccessibleKeyset to free.
+ *
+ * Release the memory used by an AccessibleKeySet.
+ *
+ **/
+void
+SPI_freeAccessibleKeySet (AccessibleKeySet *keyset)
+{
+  int i = 0;   
+  g_free (keyset->keysyms);
+  g_free (keyset->keycodes);
+  while (keyset->keystrings [i])
+    {
+      g_free (keyset->keystrings [i++]);
+    }
+  g_free (keyset->keystrings);
+  g_free (keyset);
+}
+
+/**
+ * SPI_createAccessibleKeySet:
+ * @len: the number of key values in the key set.
+ * @keysyms: a UTF-8 string containing symbolic key values to be matched, or NULL if
+ *           matching is performed against other key values instead.
+ * @keycodes: an array of unsigned short values which are the hardware keycodes
+ *           to be matched, or NULL if the keyset is specified solely by keysyms
+ *           and/or keystrings.
+ * @keystrings: an array of null-terminated character strings which specify key
+ *             name values to match, or NULL if the keyset is specified solely by
+ *             keycodes and/or keysyms.
+ *
+ * Create a new #AccessibleKeySet of a specified length.
+ * A KeySet is used typically to match key event values, and a matches are made
+ * using the following criteria: a match exists with a key event if all non-null
+ * i-th members of the keyset match the key event.
+ * If both keystring and keysym values are NULL, a keycode value match is
+ * forced, thus the match for keysym=0, keycode=0, keystring=NULL is
+ * keycode 0.
+ *
+ * Returns: a pointer to a newly-created #AccessibleKeySet.
+ *
+ **/
+AccessibleKeySet *
+SPI_createAccessibleKeySet (int len, const char *keysyms, short *keycodes,
+                           const char **keystrings)
+{
+  AccessibleKeySet *keyset = g_new0 (AccessibleKeySet, 1);
+  int i, keysym_len = 0;
+  const char *keysym_ptr = keysyms;
+  keyset->len = len;
+  keyset->keysyms = g_new0 (unsigned long, len);
+  keyset->keycodes = g_new0 (unsigned short, len);
+  keyset->keystrings = g_new0 (char *, len);
+  if (keysyms)
+    {
+      keysym_len = g_utf8_strlen (keysyms, -1);
+    }
+  for (i = 0; i < len; ++i)
+    {
+      if (i < keysym_len)
+        {
+         keyset->keysyms [i] = (unsigned long) g_utf8_get_char (keysym_ptr);
+         keysym_ptr = g_utf8_find_next_char (keysym_ptr, NULL);
+        }
+      else
+        {
+          keyset->keysyms [i] = 0;
+        }
+      if (keycodes)
+        {
+         keyset->keycodes [i] = keycodes [i];
+       }
+      if (keystrings)
+        {
+         keyset->keystrings [i] = g_strdup (keystrings [i]);
+       }
+    }
+  return keyset;       
+}
+
 /**
- * createAccessibleEventListener:
+ * SPI_createAccessibleEventListener:
  * @callback : an #AccessibleEventListenerCB callback function, or NULL.
+ * @user_data: a pointer to data which will be passed to the callback when invoked.
  *
  * Create a new #AccessibleEventListener with a specified (in-process) callback function.
  *
  *
  **/
 AccessibleEventListener *
-createAccessibleEventListener (AccessibleEventListenerCB callback)
+SPI_createAccessibleEventListener (AccessibleEventListenerCB callback,
+                                  void                     *user_data)
 {
-  AccessibleEventListener *listener = spi_event_listener_new ();
+  AccessibleEventListener *listener = cspi_event_listener_new ();
   if (callback)
     {
-      spi_event_listener_add_callback (listener, callback);
+      AccessibleEventListener_addCallback (listener, callback, user_data);
     }
   return listener;
 }
@@ -44,6 +132,7 @@ createAccessibleEventListener (AccessibleEventListenerCB callback)
  * AccessibleEventListener_addCallback:
  * @listener: the #AccessibleEventListener instance to modify.
  * @callback: an #AccessibleEventListenerCB function pointer.
+ * @user_data: a pointer to data which will be passed to the callback when invoked.
  *
  * Add an in-process callback function to an existing AccessibleEventListener.
  * Note that the callback function must live in the same address
@@ -55,15 +144,28 @@ createAccessibleEventListener (AccessibleEventListenerCB callback)
  * Returns: #TRUE if successful, otherwise #FALSE.
  *
  **/
-boolean
+SPIBoolean
 AccessibleEventListener_addCallback (AccessibleEventListener *listener,
-                          AccessibleEventListenerCB callback)
+                                    AccessibleEventListenerCB callback,
+                                    void                     *user_data)
 {
-  spi_event_listener_add_callback (listener, callback);
+  cspi_event_listener_add_cb (listener, callback, user_data);
   return TRUE;
 }
 
 /**
+ * AccessibleEventListener_unref:
+ * @listener: a pointer to the #AccessibleEventListener being operated on.
+ *
+ * Decrements an #AccessibleEventListener's reference count.
+ **/
+void
+AccessibleEventListener_unref (AccessibleEventListener *listener)
+{
+  cspi_event_listener_unref (listener);
+}
+
+/**
  * AccessibleEventListener_removeCallback:
  * @listener: the #AccessibleEventListener instance to modify.
  * @callback: an #AccessibleEventListenerCB function pointer.
@@ -73,17 +175,18 @@ AccessibleEventListener_addCallback (AccessibleEventListener *listener,
  * Returns: #TRUE if successful, otherwise #FALSE.
  *
  **/
-boolean
-AccessibleEventListener_removeCallback (AccessibleEventListener *listener,
+SPIBoolean
+AccessibleEventListener_removeCallback (AccessibleEventListener  *listener,
                                        AccessibleEventListenerCB callback)
 {
-  spi_event_listener_remove_callback (listener, callback);
+  cspi_event_listener_remove_cb (listener, callback);
   return TRUE;
 }
 
 /**
  * createAccessibleKeystrokeListener:
  * @callback : an #AccessibleKeystrokeListenerCB callback function, or NULL.
+ * @user_data: a pointer to data which will be passed to the callback when invoked.
  *
  * Create a new #AccessibleKeystrokeListener with a specified callback function.
  *
@@ -91,31 +194,34 @@ AccessibleEventListener_removeCallback (AccessibleEventListener *listener,
  *
  **/
 AccessibleKeystrokeListener *
-createAccessibleKeystrokeListener (AccessibleKeystrokeListenerCB callback)
+SPI_createAccessibleKeystrokeListener (AccessibleKeystrokeListenerCB callback,
+                                      void                         *user_data)
 {
-  SpiKeystrokeListener *listener = spi_keystroke_listener_new ();
+  AccessibleKeystrokeListener *listener = cspi_keystroke_listener_new ();
   if (callback)
     {
-      spi_keystroke_listener_add_callback (listener, callback);
+      AccessibleKeystrokeListener_addCallback (listener, callback, user_data);
     }
-  return (AccessibleKeystrokeListener *)listener;
+  return listener;
 }
 
 /**
  * AccessibleKeystrokeListener_addCallback:
  * @listener: the #AccessibleKeystrokeListener instance to modify.
  * @callback: an #AccessibleKeystrokeListenerCB function pointer.
+ * @user_data: a pointer to data which will be passed to the callback when invoked.
  *
  * Add an in-process callback function to an existing #AccessibleKeystrokeListener.
  *
  * Returns: #TRUE if successful, otherwise #FALSE.
  *
  **/
-boolean
+SPIBoolean
 AccessibleKeystrokeListener_addCallback (AccessibleKeystrokeListener *listener,
-                                        AccessibleKeystrokeListenerCB callback)
+                                        AccessibleKeystrokeListenerCB callback,
+                                        void                         *user_data)
 {
-  spi_keystroke_listener_add_callback (listener, callback);
+  cspi_keystroke_listener_add_cb (listener, callback, user_data);
   return TRUE;
 }
 
@@ -129,11 +235,22 @@ AccessibleKeystrokeListener_addCallback (AccessibleKeystrokeListener *listener,
  * Returns: #TRUE if successful, otherwise #FALSE.
  *
  **/
-boolean
+SPIBoolean
 AccessibleKeystrokeListener_removeCallback (AccessibleKeystrokeListener *listener,
                                            AccessibleKeystrokeListenerCB callback)
 {
-  spi_keystroke_listener_remove_callback (listener, callback);
+  cspi_keystroke_listener_remove_cb (listener, callback);
   return TRUE;
 }
 
+/**
+ * AccessibleKeystrokeListener_unref:
+ * @listener: a pointer to the #AccessibleKeystrokeListener being operated on.
+ *
+ * Decrements an #AccessibleKeystrokeListener's reference count.
+ **/
+void
+AccessibleKeystrokeListener_unref (AccessibleKeystrokeListener *listener)
+{
+  cspi_keystroke_listener_unref (listener);
+}