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 #define INVALID_PATH "/Invalid"
30 /*---------------------------------------------------------------------------*/
33 * Marshals the D-Bus path of an AtkObject into a D-Bus message.
35 * Unrefs the AtkObject if unref is true.
38 spi_dbus_return_object (DBusMessage *message, AtkObject *obj, gboolean unref)
43 path = atk_dbus_object_to_path (obj);
48 reply = dbus_message_new_method_return (message);
51 dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, path,
57 /*---------------------------------------------------------------------------*/
60 * Marshals a variant containing the D-Bus path of an AtkObject into a D-Bus
63 * Unrefs the object if unref is true.
66 spi_dbus_return_v_object (DBusMessageIter *iter, AtkObject *obj, int unref)
70 path = atk_dbus_object_to_path (obj);
75 return droute_return_v_object (iter, path);
78 /*---------------------------------------------------------------------------*/
81 append_atk_object_interfaces (AtkObject *object, DBusMessageIter *iter)
85 itf = SPI_DBUS_INTERFACE_ACCESSIBLE;
86 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
88 if (ATK_IS_ACTION (object))
90 itf = SPI_DBUS_INTERFACE_ACTION;
91 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
94 if (ATK_IS_COMPONENT (object))
96 itf = SPI_DBUS_INTERFACE_COMPONENT;
97 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
100 if (ATK_IS_EDITABLE_TEXT (object))
102 itf = SPI_DBUS_INTERFACE_EDITABLE_TEXT;
103 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
106 if (ATK_IS_TEXT (object))
108 itf = SPI_DBUS_INTERFACE_TEXT;
109 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
112 if (ATK_IS_HYPERTEXT (object))
114 itf = SPI_DBUS_INTERFACE_HYPERTEXT;
115 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
118 if (ATK_IS_IMAGE (object))
120 itf = SPI_DBUS_INTERFACE_IMAGE;
121 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
124 if (ATK_IS_SELECTION (object))
126 itf = SPI_DBUS_INTERFACE_SELECTION;
127 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
130 if (ATK_IS_TABLE (object))
132 itf = SPI_DBUS_INTERFACE_TABLE;
133 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
136 if (ATK_IS_VALUE (object))
138 itf = SPI_DBUS_INTERFACE_VALUE;
139 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
142 if (ATK_IS_STREAMABLE_CONTENT (object))
144 itf = "org.freedesktop.atspi.StreamableContent";
145 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
148 if (ATK_IS_DOCUMENT (object))
150 itf = "org.freedesktop.atspi.Collection";
151 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
152 itf = SPI_DBUS_INTERFACE_DOCUMENT;
153 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
156 if (ATK_IS_HYPERLINK_IMPL (object))
158 itf = SPI_DBUS_INTERFACE_HYPERLINK;
159 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &itf);
163 /*---------------------------------------------------------------------------*/
166 * Marshals the given AtkObject into the provided D-Bus iterator.
168 * The object is marshalled including all its client side cache data.
169 * The format of the structure is (ooaoassusau).
170 * This is used in the updateTree signal and the getTree method
171 * of the org.freedesktop.atspi.Tree interface.
173 * To marshal an object its parent, and all its children must already
174 * be registered with D-Bus and have been given a D-Bus object path.
177 spi_atk_append_accessible(AtkObject *obj, gpointer iter)
179 DBusMessageIter *iter_array;
180 DBusMessageIter iter_struct, iter_sub_array;
181 dbus_int32_t states [2];
184 const char *name, *desc;
189 iter_array = (DBusMessageIter *) iter;
191 dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
194 gchar *path, *path_parent;
196 /* Marshall object path */
197 path = atk_dbus_object_to_path (obj);
198 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
200 /* Marshall parent */
201 parent = atk_object_get_parent(obj);
204 path_parent = g_strdup("/");
208 path_parent = atk_dbus_object_to_path (parent);
211 path_parent = g_strdup(INVALID_PATH);
214 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path_parent);
217 /* Marshall children */
218 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "o", &iter_sub_array);
222 childcount = atk_object_get_n_accessible_children (obj);
223 for (i = 0; i < childcount; i++)
228 child = atk_object_ref_accessible_child (obj, i);
229 child_path = atk_dbus_object_to_path (child);
230 g_object_unref(G_OBJECT(child));
231 if (!G_LIKELY (child_path))
233 child_path = g_strdup(INVALID_PATH);
235 dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_OBJECT_PATH, &child_path);
239 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
241 /* Marshall interfaces */
242 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "s", &iter_sub_array);
243 append_atk_object_interfaces (obj, &iter_sub_array);
244 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
247 name = atk_object_get_name (obj);
250 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
253 role = spi_accessible_role_from_atk_role (atk_object_get_role (obj));
254 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &role);
256 /* Marshall description */
257 desc = atk_object_get_description (obj);
260 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &desc);
264 /* Marshall state set */
265 spi_atk_state_to_dbus_array (obj, &states);
266 dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "u", &iter_sub_array);
267 for (count = 0; count < 2; count++)
269 dbus_message_iter_append_basic (&iter_sub_array, DBUS_TYPE_UINT32, &states[count]);
271 dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
273 dbus_message_iter_close_container (iter_array, &iter_struct);
276 /*END------------------------------------------------------------------------*/