* atk-adaptor/component-adaptor.c, atk-adaptor/image-adaptor.c,
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / accessible-marshaller.c
index a60f2c8..30d6b33 100644 (file)
@@ -20,6 +20,8 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#include "spi-common/spi-dbus.h"
+
 #include "accessible-register.h"
 #include "accessible-marshaller.h"
 
@@ -38,15 +40,21 @@ spi_dbus_return_object (DBusMessage *message, AtkObject *obj, gboolean unref)
 
   path = atk_dbus_object_to_path (obj);
 
-  if (unref)
+  if (obj && unref)
     g_object_unref (obj);
 
+  if (!path)
+    path = g_strdup (SPI_DBUS_PATH_NULL);
+
   reply = dbus_message_new_method_return (message);
   if (reply)
     {
-      dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, path,
+      dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path,
                                 DBUS_TYPE_INVALID);
     }
+
+  g_free (path);
+
   return reply;
 }
 
@@ -71,5 +79,212 @@ spi_dbus_return_v_object (DBusMessageIter *iter, AtkObject *obj, int unref)
   return droute_return_v_object (iter, path);
 }
 
+/*---------------------------------------------------------------------------*/
+
+static void
+append_atk_object_interfaces (AtkObject *object, DBusMessageIter *iter)
+{
+  const gchar *itf;
+
+  itf = SPI_DBUS_INTERFACE_ACCESSIBLE;
+  dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+
+  if (ATK_IS_ACTION (object))
+    {
+      itf = SPI_DBUS_INTERFACE_ACTION;
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+
+  if (ATK_IS_COMPONENT (object))
+    {
+      itf = SPI_DBUS_INTERFACE_COMPONENT;
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+
+  if (ATK_IS_EDITABLE_TEXT (object))
+    {
+      itf = SPI_DBUS_INTERFACE_EDITABLE_TEXT;
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+
+  if (ATK_IS_TEXT (object))
+    {
+      itf = SPI_DBUS_INTERFACE_TEXT;
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+
+  if (ATK_IS_HYPERTEXT (object))
+    {
+      itf = SPI_DBUS_INTERFACE_HYPERTEXT;
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+
+  if (ATK_IS_IMAGE (object))
+    {
+      itf = SPI_DBUS_INTERFACE_IMAGE;
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+
+  if (ATK_IS_SELECTION (object))
+    {
+      itf = SPI_DBUS_INTERFACE_SELECTION;
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+
+  if (ATK_IS_TABLE (object))
+    {
+      itf = SPI_DBUS_INTERFACE_TABLE;
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+
+  if (ATK_IS_VALUE (object))
+    {
+      itf = SPI_DBUS_INTERFACE_VALUE;
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+
+  if (ATK_IS_STREAMABLE_CONTENT (object))
+    {
+      itf = "org.freedesktop.atspi.StreamableContent";
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+
+  if (ATK_IS_DOCUMENT (object))
+    {
+      itf = "org.freedesktop.atspi.Collection";
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+      itf = SPI_DBUS_INTERFACE_DOCUMENT;
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+
+  if (ATK_IS_HYPERLINK_IMPL (object))
+    {
+      itf = SPI_DBUS_INTERFACE_HYPERLINK;
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
+    }
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*
+ * Marshals the given AtkObject into the provided D-Bus iterator.
+ *
+ * The object is marshalled including all its client side cache data.
+ * The format of the structure is (ooaoassusau).
+ * This is used in the updateTree signal and the getTree method
+ * of the org.freedesktop.atspi.Tree interface.
+ *
+ * To marshal an object its parent, and all its children must already
+ * be registered with D-Bus and have been given a D-Bus object path.
+ */
+void
+spi_atk_append_accessible(AtkObject *obj, gpointer iter)
+{
+  DBusMessageIter *iter_array;
+  DBusMessageIter iter_struct, iter_sub_array;
+  dbus_int32_t states [2];
+  int count;
+
+  const char *name, *desc;
+  int i;
+  dbus_uint32_t role;
+  GSList *l;
+
+  iter_array = (DBusMessageIter *) iter;
+
+  dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
+    {
+      AtkObject *parent;
+      gchar *path, *path_parent;
+
+      /* Marshall object path */
+      path = atk_dbus_object_to_path (obj);
+      dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
+
+      /* Marshall parent */
+      parent = atk_object_get_parent(obj);
+      if (parent == NULL)
+        {
+          path_parent = atk_dbus_desktop_object_path ();
+        }
+      else
+        {
+          path_parent = atk_dbus_object_to_path (parent);
+          if (!path_parent)
+            {
+              /* This should only happen if a widget is re-parented to
+               * an AtkObject that has not been registered and is then
+               * updated. Ideally objects would be de-registered when
+               * they are removed from a registered tree object, but
+               * this would invalidate a huge amount of cache when
+               * re-parenting.
+               */
+#if SPI_ATK_DEBUG
+              g_warning ("AT-SPI: Registered accessible marshalled when parent not registered");
+#endif
+              path_parent = atk_dbus_desktop_object_path ();
+            }
+        }
+      dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path_parent);
+      g_free(path_parent);
+
+      /* Marshall children */
+      dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "o", &iter_sub_array);
+        {
+          gint childcount, i;
+
+          childcount = atk_object_get_n_accessible_children (obj);
+          for (i = 0; i < childcount; i++)
+            {
+              AtkObject *child;
+              gchar *child_path;
+
+              child = atk_object_ref_accessible_child (obj, i);
+              child_path = atk_dbus_object_to_path (child);
+              if (child_path)
+                {
+                  dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_OBJECT_PATH, &child_path);
+                  g_free (child_path);
+                }
+              g_object_unref(G_OBJECT(child));
+            }
+        }
+      dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
+
+      /* Marshall interfaces */
+      dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "s", &iter_sub_array);
+      append_atk_object_interfaces (obj, &iter_sub_array);
+      dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
+
+      /* Marshall name */
+      name = atk_object_get_name (obj);
+      if (!name)
+        name = "";
+      dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
+
+      /* Marshall role */
+      role = spi_accessible_role_from_atk_role (atk_object_get_role (obj));
+      dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &role);
+
+      /* Marshall description */
+      desc = atk_object_get_description (obj);
+      if (!desc)
+        desc = "";
+      dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &desc);
+
+      g_free(path);
+
+      /* Marshall state set */
+      spi_atk_state_to_dbus_array (obj, &states);
+      dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "u", &iter_sub_array);
+      for (count = 0; count < 2; count++)
+        {
+          dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_UINT32, &states[count]);
+        }
+      dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
+    }
+  dbus_message_iter_close_container (iter_array, &iter_struct);
+}
+
 /*END------------------------------------------------------------------------*/