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 "spi-common/spi-dbus.h"
25 #include "accessible-register.h"
26 #include "accessible-marshaller.h"
28 /*---------------------------------------------------------------------------*/
31 * Marshals the D-Bus path of an AtkObject into a D-Bus message.
33 * Unrefs the AtkObject if unref is true.
36 spi_dbus_return_object (DBusMessage *message, AtkObject *obj, gboolean unref)
41 path = atk_dbus_object_to_path (obj);
47 path = g_strdup (SPI_DBUS_PATH_NULL);
49 reply = dbus_message_new_method_return (message);
52 dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path,
61 /*---------------------------------------------------------------------------*/
64 * Marshals a variant containing the D-Bus path of an AtkObject into a D-Bus
67 * Unrefs the object if unref is true.
70 spi_dbus_return_v_object (DBusMessageIter *iter, AtkObject *obj, int unref)
74 path = atk_dbus_object_to_path (obj);
79 return droute_return_v_object (iter, path);
82 /*---------------------------------------------------------------------------*/
85 append_atk_object_interfaces (AtkObject *object, DBusMessageIter *iter)
89 itf = SPI_DBUS_INTERFACE_ACCESSIBLE;
90 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
92 if (ATK_IS_ACTION (object))
94 itf = SPI_DBUS_INTERFACE_ACTION;
95 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
98 if (ATK_IS_COMPONENT (object))
100 itf = SPI_DBUS_INTERFACE_COMPONENT;
101 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
104 if (ATK_IS_EDITABLE_TEXT (object))
106 itf = SPI_DBUS_INTERFACE_EDITABLE_TEXT;
107 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
110 if (ATK_IS_TEXT (object))
112 itf = SPI_DBUS_INTERFACE_TEXT;
113 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
116 if (ATK_IS_HYPERTEXT (object))
118 itf = SPI_DBUS_INTERFACE_HYPERTEXT;
119 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
122 if (ATK_IS_IMAGE (object))
124 itf = SPI_DBUS_INTERFACE_IMAGE;
125 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
128 if (ATK_IS_SELECTION (object))
130 itf = SPI_DBUS_INTERFACE_SELECTION;
131 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
134 if (ATK_IS_TABLE (object))
136 itf = SPI_DBUS_INTERFACE_TABLE;
137 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
140 if (ATK_IS_VALUE (object))
142 itf = SPI_DBUS_INTERFACE_VALUE;
143 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
146 if (ATK_IS_STREAMABLE_CONTENT (object))
148 itf = "org.freedesktop.atspi.StreamableContent";
149 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
152 if (ATK_IS_DOCUMENT (object))
154 itf = "org.freedesktop.atspi.Collection";
155 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
156 itf = SPI_DBUS_INTERFACE_DOCUMENT;
157 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
160 if (ATK_IS_HYPERLINK_IMPL (object))
162 itf = SPI_DBUS_INTERFACE_HYPERLINK;
163 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
167 /*---------------------------------------------------------------------------*/
170 * Marshals the given AtkObject into the provided D-Bus iterator.
172 * The object is marshalled including all its client side cache data.
173 * The format of the structure is (ooaoassusau).
174 * This is used in the updateTree signal and the getTree method
175 * of the org.freedesktop.atspi.Tree interface.
177 * To marshal an object its parent, and all its children must already
178 * be registered with D-Bus and have been given a D-Bus object path.
181 spi_atk_append_accessible(AtkObject *obj, gpointer iter)
183 DBusMessageIter *iter_array;
184 DBusMessageIter iter_struct, iter_sub_array;
185 dbus_int32_t states [2];
188 const char *name, *desc;
193 iter_array = (DBusMessageIter *) iter;
195 dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
198 gchar *path, *path_parent;
200 /* Marshall object path */
201 path = atk_dbus_object_to_path (obj);
202 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
204 /* Marshall parent */
205 parent = atk_object_get_parent(obj);
208 path_parent = atk_dbus_desktop_object_path ();
212 path_parent = atk_dbus_object_to_path (parent);
215 /* This should only happen if a widget is re-parented to
216 * an AtkObject that has not been registered and is then
217 * updated. Ideally objects would be de-registered when
218 * they are removed from a registered tree object, but
219 * this would invalidate a huge amount of cache when
223 g_warning ("AT-SPI: Registered accessible marshalled when parent not registered");
225 path_parent = atk_dbus_desktop_object_path ();
228 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path_parent);
231 /* Marshall children */
232 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "o", &iter_sub_array);
236 childcount = atk_object_get_n_accessible_children (obj);
237 for (i = 0; i < childcount; i++)
242 child = atk_object_ref_accessible_child (obj, i);
243 child_path = atk_dbus_object_to_path (child);
246 dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_OBJECT_PATH, &child_path);
249 g_object_unref(G_OBJECT(child));
252 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
254 /* Marshall interfaces */
255 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "s", &iter_sub_array);
256 append_atk_object_interfaces (obj, &iter_sub_array);
257 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
260 name = atk_object_get_name (obj);
263 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
266 role = spi_accessible_role_from_atk_role (atk_object_get_role (obj));
267 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &role);
269 /* Marshall description */
270 desc = atk_object_get_description (obj);
273 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &desc);
277 /* Marshall state set */
278 spi_atk_state_to_dbus_array (obj, &states);
279 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "u", &iter_sub_array);
280 for (count = 0; count < 2; count++)
282 dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_UINT32, &states[count]);
284 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
286 dbus_message_iter_close_container (iter_array, &iter_struct);
290 spi_atk_append_attribute_set (DBusMessageIter *iter, AtkAttributeSet *attr)
292 DBusMessageIter dictIter;
294 dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, "{ss}", &dictIter);
295 spi_atk_append_attribute_set_inner (&dictIter, attr);
296 dbus_message_iter_close_container (iter, &dictIter);
300 spi_atk_append_attribute_set_inner (DBusMessageIter *iter, AtkAttributeSet *attr)
302 DBusMessageIter dictEntryIter;
306 AtkAttribute *attribute = (AtkAttribute *) attr->data;
307 dbus_message_iter_open_container (iter, DBUS_TYPE_DICT_ENTRY, NULL, &dictEntryIter);
308 dbus_message_iter_append_basic (&dictEntryIter, DBUS_TYPE_STRING, &attribute->name);
309 dbus_message_iter_append_basic (&dictEntryIter, DBUS_TYPE_STRING, &attribute->value);
310 dbus_message_iter_close_container (iter, &dictEntryIter);
311 attr = g_slist_next (attr);
315 /*END------------------------------------------------------------------------*/