2009-10-10 Mike Gorse <mgorse@novell.com>
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / accessible-marshaller.c
index 6e9de23..fdd8a6d 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-#include "spi-common/spi-dbus.h"
+#include <droute/droute.h>
+
+#include "common/spi-dbus.h"
+#include "common/spi-stateset.h"
 
 #include "accessible-register.h"
 #include "accessible-marshaller.h"
 
+#include "adaptors.h"
+
 /*---------------------------------------------------------------------------*/
 
 /*
  * Unrefs the AtkObject if unref is true.
  */
 DBusMessage *
-spi_dbus_return_object (DBusMessage *message, AtkObject *obj, gboolean unref)
+spi_dbus_return_object (DBusMessage *message, AtkObject *obj, gboolean do_register, gboolean unref)
 {
   DBusMessage *reply;
   gchar *path;
 
-  path = atk_dbus_object_to_path (obj);
+  path = atk_dbus_object_to_path (obj, do_register);
 
-  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_TYPE_INVALID);
+    }
+
+  g_free (path);
+
+  return reply;
+}
+
+DBusMessage *
+spi_dbus_return_hyperlink (DBusMessage *message, AtkHyperlink *link, AtkObject *container, gboolean unref)
+{
+  return spi_dbus_return_sub_object (message, G_OBJECT (link), G_OBJECT (container), unref);
+}
+
+DBusMessage *
+spi_dbus_return_sub_object (DBusMessage *message, GObject *sub, GObject *container, gboolean unref)
+{
+  DBusMessage *reply;
+  gchar *path;
+
+  path = atk_dbus_sub_object_to_path (sub, container);
+
+  if (sub && unref)
+    g_object_unref (sub);
+
+  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;
 }
 
@@ -65,7 +108,10 @@ spi_dbus_return_v_object (DBusMessageIter *iter, AtkObject *obj, int unref)
 {
   char *path;
 
-  path = atk_dbus_object_to_path (obj);
+  path = atk_dbus_object_to_path (obj, FALSE);
+
+  if (!path)
+    path = g_strdup (SPI_DBUS_PATH_NULL);
 
   if (unref)
     g_object_unref (obj);
@@ -75,7 +121,7 @@ spi_dbus_return_v_object (DBusMessageIter *iter, AtkObject *obj, int unref)
 
 /*---------------------------------------------------------------------------*/
 
-static void
+void
 append_atk_object_interfaces (AtkObject *object, DBusMessageIter *iter)
 {
   const gchar *itf;
@@ -176,23 +222,23 @@ spi_atk_append_accessible(AtkObject *obj, gpointer iter)
 {
   DBusMessageIter *iter_array;
   DBusMessageIter iter_struct, iter_sub_array;
-  dbus_int32_t states [2];
+  dbus_uint32_t states [2];
   int count;
+  AtkStateSet *set;
 
   const char *name, *desc;
-  int i;
   dbus_uint32_t role;
-  GSList *l;
 
   iter_array = (DBusMessageIter *) iter;
 
+  set = atk_object_ref_state_set (obj);
   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);
+      path = atk_dbus_object_to_path (obj, FALSE);
       dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
 
       /* Marshall parent */
@@ -203,7 +249,7 @@ spi_atk_append_accessible(AtkObject *obj, gpointer iter)
         }
       else
         {
-          path_parent = atk_dbus_object_to_path (parent);
+          path_parent = atk_dbus_object_to_path (parent, FALSE);
           if (!path_parent)
             {
               /* This should only happen if a widget is re-parented to
@@ -224,6 +270,7 @@ spi_atk_append_accessible(AtkObject *obj, gpointer iter)
 
       /* Marshall children */
       dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "o", &iter_sub_array);
+      if (!atk_state_set_contains_state (set, ATK_STATE_MANAGES_DESCENDANTS))
         {
           gint childcount, i;
 
@@ -234,7 +281,7 @@ spi_atk_append_accessible(AtkObject *obj, gpointer iter)
               gchar *child_path;
 
               child = atk_object_ref_accessible_child (obj, i);
-              child_path = atk_dbus_object_to_path (child);
+              child_path = atk_dbus_object_to_path (child, FALSE);
               if (child_path)
                 {
                   dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_OBJECT_PATH, &child_path);
@@ -269,7 +316,7 @@ spi_atk_append_accessible(AtkObject *obj, gpointer iter)
       g_free(path);
 
       /* Marshall state set */
-      spi_atk_state_to_dbus_array (obj, &states);
+      spi_atk_state_set_to_dbus_array (set, states);
       dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "u", &iter_sub_array);
       for (count = 0; count < 2; count++)
         {
@@ -278,6 +325,33 @@ spi_atk_append_accessible(AtkObject *obj, gpointer iter)
       dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
     }
   dbus_message_iter_close_container (iter_array, &iter_struct);
+  g_object_unref (set);
+}
+
+void
+spi_atk_append_attribute_set (DBusMessageIter *iter, AtkAttributeSet *attr)
+{
+  DBusMessageIter dictIter;
+
+  dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, "{ss}", &dictIter);
+  spi_atk_append_attribute_set_inner (&dictIter, attr);
+  dbus_message_iter_close_container (iter, &dictIter);
+}
+
+void
+spi_atk_append_attribute_set_inner (DBusMessageIter *iter, AtkAttributeSet *attr)
+{
+  DBusMessageIter dictEntryIter;
+
+  while (attr)
+    {
+      AtkAttribute *attribute = (AtkAttribute *) attr->data;
+      dbus_message_iter_open_container (iter, DBUS_TYPE_DICT_ENTRY, NULL, &dictEntryIter);
+      dbus_message_iter_append_basic (&dictEntryIter, DBUS_TYPE_STRING, &attribute->name);
+      dbus_message_iter_append_basic (&dictEntryIter, DBUS_TYPE_STRING, &attribute->value);
+      dbus_message_iter_close_container (iter, &dictEntryIter);
+      attr = g_slist_next (attr);
+    }
 }
 
 /*END------------------------------------------------------------------------*/