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.h"
28 static GHashTable *path2ptr;
29 static guint objindex;
32 deregister_object (gpointer obj)
34 g_hash_table_remove (path2ptr, obj);
38 register_object (AtkObject * obj)
42 path2ptr = g_hash_table_new (g_int_hash, g_int_equal);
46 while (g_hash_table_lookup (path2ptr, (gpointer)++ objindex))
48 /* g_object_get_data returning 0 means no data, so handle wrap-around */
52 g_hash_table_insert (path2ptr, (gpointer) objindex, obj);
53 g_object_set_data_full (G_OBJECT (obj), "dbus-id", (gpointer) objindex,
59 spi_dbus_get_object (const char *path)
66 data = g_hash_table_lookup (path2ptr, (gpointer) index);
68 return ATK_OBJECT (data);
73 spi_dbus_get_path (AtkObject * obj)
75 guint index = (guint) g_object_get_data (G_OBJECT (obj), "dbus-id");
77 index = register_object (obj);
78 return g_strdup_printf ("/org/freedesktop/atspi/accessible/%d", index);
82 spi_dbus_general_error (DBusMessage * message)
84 return dbus_message_new_error (message,
85 "org.freedesktop.accessibility.GeneralError",
89 /* Reply with the given object and dereference it if unref is TRUE */
91 spi_dbus_return_object (DBusMessage * message, AtkObject * obj, int unref)
94 const char *path = spi_dbus_get_path (obj);
99 /* Should we have a more specific error for this? */
100 return spi_dbus_general_error (message);
102 reply = dbus_message_new_method_return (message);
105 dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, path,
112 spi_dbus_return_rect (DBusMessage * message, gint ix, gint iy, gint iwidth,
116 dbus_uint32_t x, y, width, height;
122 reply = dbus_message_new_method_return (message);
125 DBusMessageIter iter, sub;
126 dbus_message_iter_init_append (reply, &iter);
127 if (!dbus_message_iter_open_container
128 (&iter, DBUS_TYPE_STRUCT, NULL, &sub))
130 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &x);
131 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &y);
132 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &width);
133 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &height);
134 if (!dbus_message_iter_close_container (&iter, &sub))
139 /* todo: return an error */
144 spi_dbus_return_v_object (DBusMessageIter * iter, AtkObject * obj, int unref)
146 const char *path = spi_dbus_get_path (obj);
148 g_object_unref (obj);
151 return droute_return_v_object (iter, path);
156 spi_dbus_initialize (DRouteData * data)
158 spi_initialize_accessible (data);
159 spi_initialize_action(data);
160 spi_initialize_component (data);
161 spi_initialize_document (data);
162 spi_initialize_editabletext (data);
163 spi_initialize_hyperlink (data);
164 spi_initialize_hypertext (data);
165 spi_initialize_image (data);
166 spi_initialize_selection (data);
167 spi_initialize_table (data);
168 spi_initialize_text (data);
169 spi_initialize_value (data);
173 spi_get_tree (AtkObject * obj, GString * str, DRouteData * data)
184 role = spi_accessible_role_from_atk_role (atk_object_get_role (obj));;
185 name = atk_object_get_name (obj);
188 path = spi_dbus_get_path (obj);
189 g_string_append_printf (str,
190 "<object path=\"%s\" name=\"%s\" role=\"%d\">\n",
192 for (l = data->interfaces; l; l = g_slist_next (l))
194 DRouteInterface *iface_def = (DRouteInterface *) l->data;
196 if (iface_def->get_datum)
197 datum = (*iface_def->get_datum) (path, data->user_data);
200 g_string_append_printf (str, "<interface name=\"%s\"/>\n",
202 if (iface_def->free_datum)
203 (*iface_def->free_datum) (datum);
206 childcount = atk_object_get_n_accessible_children (obj);
207 for (i = 0; i < childcount; i++)
209 AtkObject *child = atk_object_ref_accessible_child (obj, i);
210 str = spi_get_tree (child, str, data);
211 g_object_unref (child);
213 str = g_string_append (str, "</object>\n");