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 "accessible-register.h"
24 #include "accessible-marshaller.h"
26 #include "spi-common/spi-dbus.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);
46 reply = dbus_message_new_method_return (message);
49 dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, path,
55 /*---------------------------------------------------------------------------*/
58 * Marshals a variant containing the D-Bus path of an AtkObject into a D-Bus
61 * Unrefs the object if unref is true.
64 spi_dbus_return_v_object (DBusMessageIter *iter, AtkObject *obj, int unref)
68 path = atk_dbus_object_to_path (obj);
73 return droute_return_v_object (iter, path);
76 /*---------------------------------------------------------------------------*/
79 append_atk_object_interfaces (AtkObject *object, DBusMessageIter *iter)
83 itf = SPI_DBUS_INTERFACE_ACCESSIBLE;
84 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
86 if (ATK_IS_ACTION (object))
88 itf = SPI_DBUS_INTERFACE_ACTION;
89 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
92 if (ATK_IS_COMPONENT (object))
94 itf = SPI_DBUS_INTERFACE_COMPONENT;
95 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
98 if (ATK_IS_EDITABLE_TEXT (object))
100 itf = SPI_DBUS_INTERFACE_EDITABLE_TEXT;
101 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
104 if (ATK_IS_TEXT (object))
106 itf = SPI_DBUS_INTERFACE_TEXT;
107 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
110 if (ATK_IS_HYPERTEXT (object))
112 itf = SPI_DBUS_INTERFACE_HYPERTEXT;
113 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
116 if (ATK_IS_IMAGE (object))
118 itf = SPI_DBUS_INTERFACE_IMAGE;
119 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
122 if (ATK_IS_SELECTION (object))
124 itf = SPI_DBUS_INTERFACE_SELECTION;
125 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
128 if (ATK_IS_TABLE (object))
130 itf = SPI_DBUS_INTERFACE_TABLE;
131 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
134 if (ATK_IS_VALUE (object))
136 itf = SPI_DBUS_INTERFACE_VALUE;
137 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
140 if (ATK_IS_STREAMABLE_CONTENT (object))
142 itf = "org.freedesktop.atspi.StreamableContent";
143 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
146 if (ATK_IS_DOCUMENT (object))
148 itf = "org.freedesktop.atspi.Collection";
149 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
150 itf = SPI_DBUS_INTERFACE_DOCUMENT;
151 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
154 if (ATK_IS_HYPERLINK_IMPL (object))
156 itf = SPI_DBUS_INTERFACE_HYPERLINK;
157 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
161 /*---------------------------------------------------------------------------*/
164 * Marshals the given AtkObject into the provided D-Bus iterator.
166 * The object is marshalled including all its client side cache data.
167 * The format of the structure is (ooaoassusau).
168 * This is used in the updateTree signal and the getTree method
169 * of the org.freedesktop.atspi.Tree interface.
171 * To marshal an object its parent, and all its children must already
172 * be registered with D-Bus and have been given a D-Bus object path.
175 spi_atk_append_accessible(AtkObject *obj, gpointer iter)
177 DBusMessageIter *iter_array;
178 DBusMessageIter iter_struct, iter_sub_array;
179 dbus_int32_t states [2];
182 const char *name, *desc;
187 iter_array = (DBusMessageIter *) iter;
189 dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
192 gchar *path, *path_parent;
194 /* Marshall object path */
195 path = atk_dbus_object_to_path (obj);
196 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
198 /* Marshall parent */
199 parent = atk_object_get_parent(obj);
202 path_parent = g_strdup("/");
206 path_parent = atk_dbus_object_to_path (parent);
209 g_critical ("AT-SPI: Object registered without registering parent");
210 path_parent = g_strdup("/");
213 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path_parent);
216 /* Marshall children */
217 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "o", &iter_sub_array);
221 childcount = atk_object_get_n_accessible_children (obj);
222 for (i = 0; i < childcount; i++)
227 child = atk_object_ref_accessible_child (obj, i);
228 child_path = atk_dbus_object_to_path (child);
229 g_object_unref(G_OBJECT(child));
230 if (G_LIKELY (child_path))
232 dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_OBJECT_PATH, &child_path);
236 g_critical ("AT-SPI: Child object exists in accessible tree but has not been registered");
241 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
243 /* Marshall interfaces */
244 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "s", &iter_sub_array);
245 append_atk_object_interfaces (obj, &iter_sub_array);
246 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
249 name = atk_object_get_name (obj);
252 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
255 role = spi_accessible_role_from_atk_role (atk_object_get_role (obj));
256 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &role);
258 /* Marshall description */
259 desc = atk_object_get_description (obj);
262 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &desc);
266 /* Marshall state set */
267 spi_atk_state_to_dbus_array (obj, &states);
268 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "u", &iter_sub_array);
269 for (count = 0; count < 2; count++)
271 dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_UINT32, &states[count]);
273 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
275 dbus_message_iter_close_container (iter_array, &iter_struct);
278 /*END------------------------------------------------------------------------*/