2009-04-23 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / accessible-marshaller.c
index 75c225c..d8d069f 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-#include "accessible-register.h"
-#include "accessible-marshaller.h"
-
 #include "spi-common/spi-dbus.h"
 
-#define INVALID_PATH "/Invalid"
+#include "accessible-register.h"
+#include "accessible-marshaller.h"
 
 /*---------------------------------------------------------------------------*/
 
@@ -42,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;
 }
 
@@ -201,14 +205,24 @@ spi_atk_append_accessible(AtkObject *obj, gpointer iter)
       parent = atk_object_get_parent(obj);
       if (parent == NULL)
         {
-          path_parent = g_strdup("/");
+          path_parent = atk_dbus_desktop_object_path ();
         }
       else
         {
           path_parent = atk_dbus_object_to_path (parent);
           if (!path_parent)
             {
-              path_parent = g_strdup(INVALID_PATH);
+              /* 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);
@@ -227,13 +241,12 @@ spi_atk_append_accessible(AtkObject *obj, gpointer iter)
 
               child = atk_object_ref_accessible_child (obj, i);
               child_path = atk_dbus_object_to_path (child);
-              g_object_unref(G_OBJECT(child));
-              if (!G_LIKELY (child_path))
+              if (child_path)
                 {
-                  child_path = g_strdup(INVALID_PATH);
+                  dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_OBJECT_PATH, &child_path);
+                  g_free (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);
@@ -273,5 +286,31 @@ spi_atk_append_accessible(AtkObject *obj, gpointer iter)
   dbus_message_iter_close_container (iter_array, &iter_struct);
 }
 
+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------------------------------------------------------------------------*/