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.
24 #include <droute/droute.h>
26 #include "common/spi-dbus.h"
27 #include "common/spi-stateset.h"
29 #include "accessible-register.h"
30 #include "accessible-marshaller.h"
35 /*---------------------------------------------------------------------------*/
38 spi_dbus_append_name_and_path_inner (DBusMessageIter *iter, const char *bus_name, const char *path)
40 DBusMessageIter iter_struct;
45 dbus_message_iter_open_container (iter, DBUS_TYPE_STRUCT, NULL, &iter_struct);
46 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &bus_name);
47 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
48 dbus_message_iter_close_container (iter, &iter_struct);
52 spi_dbus_append_name_and_path (DBusMessage *message, DBusMessageIter *iter, AtkObject *obj, gboolean do_register, gboolean unref)
55 DBusMessageIter iter_struct;
56 const char *bus_name = dbus_bus_get_unique_name (atk_adaptor_app_data->bus);
58 path = atk_dbus_object_to_path (obj, do_register);
61 path = g_strdup (SPI_DBUS_PATH_NULL);
63 spi_dbus_append_name_and_path_inner (iter, bus_name, path);
71 * Marshals the D-Bus path of an AtkObject into a D-Bus message.
73 * Unrefs the AtkObject if unref is true.
76 spi_dbus_return_object (DBusMessage *message, AtkObject *obj, gboolean do_register, gboolean unref)
79 reply = dbus_message_new_method_return (message);
83 dbus_message_iter_init_append (reply, &iter);
84 spi_dbus_append_name_and_path (message, &iter, obj, do_register, unref);
91 spi_dbus_return_hyperlink (DBusMessage *message, AtkHyperlink *link, AtkObject *container, gboolean unref)
93 return spi_dbus_return_sub_object (message, G_OBJECT (link), G_OBJECT (container), unref);
97 spi_dbus_return_sub_object (DBusMessage *message, GObject *sub, GObject *container, gboolean unref)
102 path = atk_dbus_sub_object_to_path (sub, container);
105 g_object_unref (sub);
108 path = g_strdup (SPI_DBUS_PATH_NULL);
110 reply = dbus_message_new_method_return (message);
113 dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path,
122 /*---------------------------------------------------------------------------*/
125 * Marshals a variant containing the D-Bus path of an AtkObject into a D-Bus
128 * Unrefs the object if unref is true.
131 spi_dbus_return_v_object (DBusMessageIter *iter, AtkObject *obj, int unref)
133 DBusMessageIter iter_variant;
136 path = atk_dbus_object_to_path (obj, FALSE);
139 path = g_strdup (SPI_DBUS_PATH_NULL);
142 g_object_unref (obj);
144 dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(so)", &iter_variant);
145 spi_dbus_append_name_and_path_inner (&iter_variant, NULL, path);
146 dbus_message_iter_close_container (iter, &iter_variant);
149 /*---------------------------------------------------------------------------*/
152 append_atk_object_interfaces (AtkObject *object, DBusMessageIter *iter)
156 itf = SPI_DBUS_INTERFACE_ACCESSIBLE;
157 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
159 if (ATK_IS_ACTION (object))
161 itf = SPI_DBUS_INTERFACE_ACTION;
162 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
165 if (ATK_IS_COMPONENT (object))
167 itf = SPI_DBUS_INTERFACE_COMPONENT;
168 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
171 if (ATK_IS_EDITABLE_TEXT (object))
173 itf = SPI_DBUS_INTERFACE_EDITABLE_TEXT;
174 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
177 if (ATK_IS_TEXT (object))
179 itf = SPI_DBUS_INTERFACE_TEXT;
180 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
183 if (ATK_IS_HYPERTEXT (object))
185 itf = SPI_DBUS_INTERFACE_HYPERTEXT;
186 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
189 if (ATK_IS_IMAGE (object))
191 itf = SPI_DBUS_INTERFACE_IMAGE;
192 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
195 if (ATK_IS_SELECTION (object))
197 itf = SPI_DBUS_INTERFACE_SELECTION;
198 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
201 if (ATK_IS_TABLE (object))
203 itf = SPI_DBUS_INTERFACE_TABLE;
204 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
207 if (ATK_IS_VALUE (object))
209 itf = SPI_DBUS_INTERFACE_VALUE;
210 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
213 if (ATK_IS_STREAMABLE_CONTENT (object))
215 itf = "org.freedesktop.atspi.StreamableContent";
216 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
219 if (ATK_IS_DOCUMENT (object))
221 itf = "org.freedesktop.atspi.Collection";
222 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
223 itf = SPI_DBUS_INTERFACE_DOCUMENT;
224 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
227 if (ATK_IS_HYPERLINK_IMPL (object))
229 itf = SPI_DBUS_INTERFACE_HYPERLINK;
230 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
234 /*---------------------------------------------------------------------------*/
237 * Marshals the given AtkObject into the provided D-Bus iterator.
239 * The object is marshalled including all its client side cache data.
240 * The format of the structure is (o(so)a(so)assusau).
241 * This is used in the updateTree signal and the GetTree method
242 * of the org.freedesktop.atspi.Tree interface.
244 * To marshal an object its parent, and all its children must already
245 * be registered with D-Bus and have been given a D-Bus object path.
248 spi_atk_append_accessible(AtkObject *obj, gpointer data)
250 DBusMessageIter iter_struct, iter_sub_array;
251 dbus_uint32_t states [2];
254 DBusMessageIter *iter_array = (DBusMessageIter *)data;
256 const char *name, *desc;
259 set = atk_object_ref_state_set (obj);
260 dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
263 gchar *path, *path_parent;
265 /* Marshall object path */
266 path = atk_dbus_object_to_path (obj, FALSE);
268 /* Marshall parent */
269 parent = atk_object_get_parent(obj);
272 path_parent = atk_dbus_desktop_object_path ();
276 path_parent = atk_dbus_object_to_path (parent, FALSE);
279 /* This should only happen if a widget is re-parented to
280 * an AtkObject that has not been registered and is then
281 * updated. Ideally objects would be de-registered when
282 * they are removed from a registered tree object, but
283 * this would invalidate a huge amount of cache when
287 g_warning ("AT-SPI: Registered accessible marshalled when parent not registered");
289 path_parent = atk_dbus_desktop_object_path ();
293 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
294 spi_dbus_append_name_and_path_inner (&iter_struct, NULL, path_parent);
297 /* Marshall children */
298 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "(so)", &iter_sub_array);
299 if (!atk_state_set_contains_state (set, ATK_STATE_MANAGES_DESCENDANTS))
303 childcount = atk_object_get_n_accessible_children (obj);
304 for (i = 0; i < childcount; i++)
309 child = atk_object_ref_accessible_child (obj, i);
310 child_path = atk_dbus_object_to_path (child, FALSE);
313 spi_dbus_append_name_and_path_inner (&iter_sub_array, NULL, child_path);
316 g_object_unref(G_OBJECT(child));
319 #ifdef __ATK_PLUG_H__
320 if (ATK_IS_SOCKET (obj) && atk_socket_is_occupied (ATK_SOCKET(obj)))
322 AtkSocket *socket = ATK_SOCKET(obj);
323 gchar *child_name, *child_path;
324 child_name = g_strdup (socket->embedded_plug_id);
325 child_path = strchr (child_name + 1, ':');
328 *(child_path++) = '\0';
329 spi_dbus_append_name_and_path_inner (&iter_sub_array, child_name, child_path);
335 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
337 /* Marshall interfaces */
338 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "s", &iter_sub_array);
339 append_atk_object_interfaces (obj, &iter_sub_array);
340 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
343 name = atk_object_get_name (obj);
346 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
349 role = spi_accessible_role_from_atk_role (atk_object_get_role (obj));
350 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &role);
352 /* Marshall description */
353 desc = atk_object_get_description (obj);
356 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &desc);
360 /* Marshall state set */
361 spi_atk_state_set_to_dbus_array (set, states);
362 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "u", &iter_sub_array);
363 for (count = 0; count < 2; count++)
365 dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_UINT32, &states[count]);
367 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
369 dbus_message_iter_close_container (iter_array, &iter_struct);
370 g_object_unref (set);
374 spi_atk_append_attribute_set (DBusMessageIter *iter, AtkAttributeSet *attr)
376 DBusMessageIter dictIter;
378 dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, "{ss}", &dictIter);
379 spi_atk_append_attribute_set_inner (&dictIter, attr);
380 dbus_message_iter_close_container (iter, &dictIter);
384 spi_atk_append_attribute_set_inner (DBusMessageIter *iter, AtkAttributeSet *attr)
386 DBusMessageIter dictEntryIter;
390 AtkAttribute *attribute = (AtkAttribute *) attr->data;
391 dbus_message_iter_open_container (iter, DBUS_TYPE_DICT_ENTRY, NULL, &dictEntryIter);
392 dbus_message_iter_append_basic (&dictEntryIter, DBUS_TYPE_STRING, &attribute->name);
393 dbus_message_iter_append_basic (&dictEntryIter, DBUS_TYPE_STRING, &attribute->value);
394 dbus_message_iter_close_container (iter, &dictEntryIter);
395 attr = g_slist_next (attr);
399 /*END------------------------------------------------------------------------*/