2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008 Novell, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include <droute/droute.h>
25 #include "common/spi-dbus.h"
26 #include "common/spi-stateset.h"
28 #include "accessible-register.h"
29 #include "accessible-marshaller.h"
34 /*---------------------------------------------------------------------------*/
37 spi_dbus_append_name_and_path_inner (DBusMessageIter *iter, const char *bus_name, const char *path)
39 DBusMessageIter iter_struct;
44 dbus_message_iter_open_container (iter, DBUS_TYPE_STRUCT, NULL, &iter_struct);
45 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &bus_name);
46 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
47 dbus_message_iter_close_container (iter, &iter_struct);
51 spi_dbus_append_name_and_path (DBusMessage *message, DBusMessageIter *iter, AtkObject *obj, gboolean do_register, gboolean unref)
54 DBusMessageIter iter_struct;
55 const char *bus_name = dbus_bus_get_unique_name (atk_adaptor_app_data->bus);
57 path = atk_dbus_object_to_path (obj, do_register);
60 path = g_strdup (SPI_DBUS_PATH_NULL);
62 spi_dbus_append_name_and_path_inner (iter, bus_name, path);
70 * Marshals the D-Bus path of an AtkObject into a D-Bus message.
72 * Unrefs the AtkObject if unref is true.
75 spi_dbus_return_object (DBusMessage *message, AtkObject *obj, gboolean do_register, gboolean unref)
78 reply = dbus_message_new_method_return (message);
82 dbus_message_iter_init_append (reply, &iter);
83 spi_dbus_append_name_and_path (message, &iter, obj, do_register, unref);
90 spi_dbus_return_hyperlink (DBusMessage *message, AtkHyperlink *link, AtkObject *container, gboolean unref)
92 return spi_dbus_return_sub_object (message, G_OBJECT (link), G_OBJECT (container), unref);
96 spi_dbus_return_sub_object (DBusMessage *message, GObject *sub, GObject *container, gboolean unref)
101 path = atk_dbus_sub_object_to_path (sub, container);
104 g_object_unref (sub);
107 path = g_strdup (SPI_DBUS_PATH_NULL);
109 reply = dbus_message_new_method_return (message);
112 dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path,
121 /*---------------------------------------------------------------------------*/
124 * Marshals a variant containing the D-Bus path of an AtkObject into a D-Bus
127 * Unrefs the object if unref is true.
130 spi_dbus_return_v_object (DBusMessageIter *iter, AtkObject *obj, int unref)
132 DBusMessageIter iter_variant;
135 path = atk_dbus_object_to_path (obj, FALSE);
138 path = g_strdup (SPI_DBUS_PATH_NULL);
141 g_object_unref (obj);
143 dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(so)", &iter_variant);
144 spi_dbus_append_name_and_path_inner (&iter_variant, NULL, path);
145 dbus_message_iter_close_container (iter, &iter_variant);
148 /*---------------------------------------------------------------------------*/
151 append_atk_object_interfaces (AtkObject *object, DBusMessageIter *iter)
155 itf = SPI_DBUS_INTERFACE_ACCESSIBLE;
156 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
158 if (ATK_IS_ACTION (object))
160 itf = SPI_DBUS_INTERFACE_ACTION;
161 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
164 if (ATK_IS_COMPONENT (object))
166 itf = SPI_DBUS_INTERFACE_COMPONENT;
167 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
170 if (ATK_IS_EDITABLE_TEXT (object))
172 itf = SPI_DBUS_INTERFACE_EDITABLE_TEXT;
173 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
176 if (ATK_IS_TEXT (object))
178 itf = SPI_DBUS_INTERFACE_TEXT;
179 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
182 if (ATK_IS_HYPERTEXT (object))
184 itf = SPI_DBUS_INTERFACE_HYPERTEXT;
185 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
188 if (ATK_IS_IMAGE (object))
190 itf = SPI_DBUS_INTERFACE_IMAGE;
191 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
194 if (ATK_IS_SELECTION (object))
196 itf = SPI_DBUS_INTERFACE_SELECTION;
197 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
200 if (ATK_IS_TABLE (object))
202 itf = SPI_DBUS_INTERFACE_TABLE;
203 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
206 if (ATK_IS_VALUE (object))
208 itf = SPI_DBUS_INTERFACE_VALUE;
209 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
212 if (ATK_IS_STREAMABLE_CONTENT (object))
214 itf = "org.freedesktop.atspi.StreamableContent";
215 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
218 if (ATK_IS_DOCUMENT (object))
220 itf = "org.freedesktop.atspi.Collection";
221 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
222 itf = SPI_DBUS_INTERFACE_DOCUMENT;
223 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
226 if (ATK_IS_HYPERLINK_IMPL (object))
228 itf = SPI_DBUS_INTERFACE_HYPERLINK;
229 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
233 /*---------------------------------------------------------------------------*/
236 * Marshals the given AtkObject into the provided D-Bus iterator.
238 * The object is marshalled including all its client side cache data.
239 * The format of the structure is (o(so)a(so)assusau).
240 * This is used in the updateTree signal and the GetTree method
241 * of the org.freedesktop.atspi.Tree interface.
243 * To marshal an object its parent, and all its children must already
244 * be registered with D-Bus and have been given a D-Bus object path.
247 spi_atk_append_accessible(AtkObject *obj, gpointer data)
249 DBusMessageIter iter_struct, iter_sub_array;
250 dbus_uint32_t states [2];
253 DBusMessageIter *iter_array = (DBusMessageIter *)data;
255 const char *name, *desc;
258 set = atk_object_ref_state_set (obj);
259 dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
262 gchar *path, *path_parent;
264 /* Marshall object path */
265 path = atk_dbus_object_to_path (obj, FALSE);
267 /* Marshall parent */
268 parent = atk_object_get_parent(obj);
271 path_parent = atk_dbus_desktop_object_path ();
275 path_parent = atk_dbus_object_to_path (parent, FALSE);
278 /* This should only happen if a widget is re-parented to
279 * an AtkObject that has not been registered and is then
280 * updated. Ideally objects would be de-registered when
281 * they are removed from a registered tree object, but
282 * this would invalidate a huge amount of cache when
286 g_warning ("AT-SPI: Registered accessible marshalled when parent not registered");
288 path_parent = atk_dbus_desktop_object_path ();
292 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
293 spi_dbus_append_name_and_path_inner (&iter_struct, NULL, path_parent);
296 /* Marshall children */
297 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "(so)", &iter_sub_array);
298 if (!atk_state_set_contains_state (set, ATK_STATE_MANAGES_DESCENDANTS))
302 childcount = atk_object_get_n_accessible_children (obj);
303 for (i = 0; i < childcount; i++)
308 child = atk_object_ref_accessible_child (obj, i);
309 child_path = atk_dbus_object_to_path (child, FALSE);
312 spi_dbus_append_name_and_path_inner (&iter_sub_array, NULL, child_path);
315 g_object_unref(G_OBJECT(child));
318 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
320 /* Marshall interfaces */
321 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "s", &iter_sub_array);
322 append_atk_object_interfaces (obj, &iter_sub_array);
323 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
326 name = atk_object_get_name (obj);
329 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
332 role = spi_accessible_role_from_atk_role (atk_object_get_role (obj));
333 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &role);
335 /* Marshall description */
336 desc = atk_object_get_description (obj);
339 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &desc);
343 /* Marshall state set */
344 spi_atk_state_set_to_dbus_array (set, states);
345 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "u", &iter_sub_array);
346 for (count = 0; count < 2; count++)
348 dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_UINT32, &states[count]);
350 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
352 dbus_message_iter_close_container (iter_array, &iter_struct);
353 g_object_unref (set);
357 spi_atk_append_attribute_set (DBusMessageIter *iter, AtkAttributeSet *attr)
359 DBusMessageIter dictIter;
361 dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, "{ss}", &dictIter);
362 spi_atk_append_attribute_set_inner (&dictIter, attr);
363 dbus_message_iter_close_container (iter, &dictIter);
367 spi_atk_append_attribute_set_inner (DBusMessageIter *iter, AtkAttributeSet *attr)
369 DBusMessageIter dictEntryIter;
373 AtkAttribute *attribute = (AtkAttribute *) attr->data;
374 dbus_message_iter_open_container (iter, DBUS_TYPE_DICT_ENTRY, NULL, &dictEntryIter);
375 dbus_message_iter_append_basic (&dictEntryIter, DBUS_TYPE_STRING, &attribute->name);
376 dbus_message_iter_append_basic (&dictEntryIter, DBUS_TYPE_STRING, &attribute->value);
377 dbus_message_iter_close_container (iter, &dictEntryIter);
378 attr = g_slist_next (attr);
382 /*END------------------------------------------------------------------------*/