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"
33 /*---------------------------------------------------------------------------*/
36 * Marshals the D-Bus path of an AtkObject into a D-Bus message.
38 * Unrefs the AtkObject if unref is true.
41 spi_dbus_return_object (DBusMessage *message, AtkObject *obj, gboolean do_register, gboolean unref)
46 path = atk_dbus_object_to_path (obj, do_register);
52 path = g_strdup (SPI_DBUS_PATH_NULL);
54 reply = dbus_message_new_method_return (message);
57 dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path,
67 spi_dbus_return_hyperlink (DBusMessage *message, AtkHyperlink *link, AtkObject *container, gboolean unref)
69 return spi_dbus_return_sub_object (message, G_OBJECT (link), G_OBJECT (container), unref);
73 spi_dbus_return_sub_object (DBusMessage *message, GObject *sub, GObject *container, gboolean unref)
78 path = atk_dbus_sub_object_to_path (sub, container);
84 path = g_strdup (SPI_DBUS_PATH_NULL);
86 reply = dbus_message_new_method_return (message);
89 dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path,
98 /*---------------------------------------------------------------------------*/
101 * Marshals a variant containing the D-Bus path of an AtkObject into a D-Bus
104 * Unrefs the object if unref is true.
107 spi_dbus_return_v_object (DBusMessageIter *iter, AtkObject *obj, int unref)
111 path = atk_dbus_object_to_path (obj, FALSE);
114 path = g_strdup (SPI_DBUS_PATH_NULL);
117 g_object_unref (obj);
119 return droute_return_v_object (iter, path);
122 /*---------------------------------------------------------------------------*/
125 append_atk_object_interfaces (AtkObject *object, DBusMessageIter *iter)
129 itf = SPI_DBUS_INTERFACE_ACCESSIBLE;
130 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
132 if (ATK_IS_ACTION (object))
134 itf = SPI_DBUS_INTERFACE_ACTION;
135 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
138 if (ATK_IS_COMPONENT (object))
140 itf = SPI_DBUS_INTERFACE_COMPONENT;
141 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
144 if (ATK_IS_EDITABLE_TEXT (object))
146 itf = SPI_DBUS_INTERFACE_EDITABLE_TEXT;
147 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
150 if (ATK_IS_TEXT (object))
152 itf = SPI_DBUS_INTERFACE_TEXT;
153 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
156 if (ATK_IS_HYPERTEXT (object))
158 itf = SPI_DBUS_INTERFACE_HYPERTEXT;
159 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
162 if (ATK_IS_IMAGE (object))
164 itf = SPI_DBUS_INTERFACE_IMAGE;
165 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
168 if (ATK_IS_SELECTION (object))
170 itf = SPI_DBUS_INTERFACE_SELECTION;
171 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
174 if (ATK_IS_TABLE (object))
176 itf = SPI_DBUS_INTERFACE_TABLE;
177 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
180 if (ATK_IS_VALUE (object))
182 itf = SPI_DBUS_INTERFACE_VALUE;
183 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
186 if (ATK_IS_STREAMABLE_CONTENT (object))
188 itf = "org.freedesktop.atspi.StreamableContent";
189 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
192 if (ATK_IS_DOCUMENT (object))
194 itf = "org.freedesktop.atspi.Collection";
195 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
196 itf = SPI_DBUS_INTERFACE_DOCUMENT;
197 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
200 if (ATK_IS_HYPERLINK_IMPL (object))
202 itf = SPI_DBUS_INTERFACE_HYPERLINK;
203 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
207 /*---------------------------------------------------------------------------*/
210 * Marshals the given AtkObject into the provided D-Bus iterator.
212 * The object is marshalled including all its client side cache data.
213 * The format of the structure is (ooaoassusau).
214 * This is used in the updateTree signal and the GetTree method
215 * of the org.freedesktop.atspi.Tree interface.
217 * To marshal an object its parent, and all its children must already
218 * be registered with D-Bus and have been given a D-Bus object path.
221 spi_atk_append_accessible(AtkObject *obj, gpointer iter)
223 DBusMessageIter *iter_array;
224 DBusMessageIter iter_struct, iter_sub_array;
225 dbus_uint32_t states [2];
229 const char *name, *desc;
232 iter_array = (DBusMessageIter *) iter;
234 set = atk_object_ref_state_set (obj);
235 dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
238 gchar *path, *path_parent;
240 /* Marshall object path */
241 path = atk_dbus_object_to_path (obj, FALSE);
242 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
244 /* Marshall parent */
245 parent = atk_object_get_parent(obj);
248 path_parent = atk_dbus_desktop_object_path ();
252 path_parent = atk_dbus_object_to_path (parent, FALSE);
255 /* This should only happen if a widget is re-parented to
256 * an AtkObject that has not been registered and is then
257 * updated. Ideally objects would be de-registered when
258 * they are removed from a registered tree object, but
259 * this would invalidate a huge amount of cache when
263 g_warning ("AT-SPI: Registered accessible marshalled when parent not registered");
265 path_parent = atk_dbus_desktop_object_path ();
268 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path_parent);
271 /* Marshall children */
272 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "o", &iter_sub_array);
273 if (!atk_state_set_contains_state (set, ATK_STATE_MANAGES_DESCENDANTS))
277 childcount = atk_object_get_n_accessible_children (obj);
278 for (i = 0; i < childcount; i++)
283 child = atk_object_ref_accessible_child (obj, i);
284 child_path = atk_dbus_object_to_path (child, FALSE);
287 dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_OBJECT_PATH, &child_path);
290 g_object_unref(G_OBJECT(child));
293 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
295 /* Marshall interfaces */
296 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "s", &iter_sub_array);
297 append_atk_object_interfaces (obj, &iter_sub_array);
298 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
301 name = atk_object_get_name (obj);
304 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
307 role = spi_accessible_role_from_atk_role (atk_object_get_role (obj));
308 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &role);
310 /* Marshall description */
311 desc = atk_object_get_description (obj);
314 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &desc);
318 /* Marshall state set */
319 spi_atk_state_set_to_dbus_array (set, states);
320 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "u", &iter_sub_array);
321 for (count = 0; count < 2; count++)
323 dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_UINT32, &states[count]);
325 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
327 dbus_message_iter_close_container (iter_array, &iter_struct);
328 g_object_unref (set);
332 spi_atk_append_attribute_set (DBusMessageIter *iter, AtkAttributeSet *attr)
334 DBusMessageIter dictIter;
336 dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, "{ss}", &dictIter);
337 spi_atk_append_attribute_set_inner (&dictIter, attr);
338 dbus_message_iter_close_container (iter, &dictIter);
342 spi_atk_append_attribute_set_inner (DBusMessageIter *iter, AtkAttributeSet *attr)
344 DBusMessageIter dictEntryIter;
348 AtkAttribute *attribute = (AtkAttribute *) attr->data;
349 dbus_message_iter_open_container (iter, DBUS_TYPE_DICT_ENTRY, NULL, &dictEntryIter);
350 dbus_message_iter_append_basic (&dictEntryIter, DBUS_TYPE_STRING, &attribute->name);
351 dbus_message_iter_append_basic (&dictEntryIter, DBUS_TYPE_STRING, &attribute->value);
352 dbus_message_iter_close_container (iter, &dictEntryIter);
353 attr = g_slist_next (attr);
357 /*END------------------------------------------------------------------------*/