2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008 Novell, Inc.
6 * Copyright 2001, 2002 Sun Microsystems Inc.,
7 * Copyright 2001, 2002 Ximian, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
25 #include "accessible.h"
27 #define get_object(message) spi_dbus_get_object(dbus_message_get_path(message))
30 get_object_from_path (const char *path, void *user_data)
32 return spi_dbus_get_object (path);
36 impl_get_name (const char *path, DBusMessageIter * iter, void *user_data)
38 AtkObject *object = spi_dbus_get_object (path);
41 return droute_return_v_string (iter, atk_object_get_name (object));
45 impl_set_name (const char *path, DBusMessageIter * iter, void *user_data)
47 AtkObject *object = spi_dbus_get_object (path);
48 const char *name = droute_get_v_string (iter);
49 atk_object_set_name (object, name);
54 impl_get_description (const char *path, DBusMessageIter * iter,
57 AtkObject *object = spi_dbus_get_object (path);
60 return droute_return_v_string (iter, atk_object_get_description (object));
64 impl_set_description (const char *path, DBusMessageIter * iter,
67 AtkObject *object = spi_dbus_get_object (path);
68 const char *description = droute_get_v_string (iter);
69 atk_object_set_description (object, description);
74 impl_get_parent (const char *path, DBusMessageIter * iter, void *user_data)
76 AtkObject *object = spi_dbus_get_object (path);
80 return spi_dbus_return_v_object (iter, atk_object_get_parent (object),
85 impl_get_childCount (const char *path, DBusMessageIter * iter,
88 AtkObject *object = spi_dbus_get_object (path);
92 return droute_return_v_int32 (iter,
93 atk_object_get_n_accessible_children
98 impl_getChildren (DBusConnection * bus, DBusMessage * message,
101 AtkObject *object = get_object (message);
105 DBusMessageIter iter, iter_array;
108 return spi_dbus_general_error (message);
109 count = atk_object_get_n_accessible_children (object);
110 reply = dbus_message_new_method_return (message);
111 if (!reply) goto oom;
112 dbus_message_iter_init_append (reply, &iter);
113 if (!dbus_message_iter_open_container
114 (&iter, DBUS_TYPE_ARRAY, "o", &iter_array))
116 for (i = 0; i < count; i++)
118 AtkObject *child = atk_object_ref_accessible_child (object, i);
119 char *path = spi_dbus_get_path (child);
122 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_OBJECT_PATH,
127 g_object_unref (child);
129 if (!dbus_message_iter_close_container (&iter, &iter_array))
133 // TODO: handle out-of-memory
138 impl_getIndexInParent (DBusConnection * bus, DBusMessage * message,
141 AtkObject *object = get_object (message);
146 return spi_dbus_general_error (message);
147 rv = atk_object_get_index_in_parent (object);
148 reply = dbus_message_new_method_return (message);
151 dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
158 spi_init_relation_type_table (Accessibility_RelationType *types)
162 for (i = 0; i < ATK_RELATION_LAST_DEFINED; i++)
163 types[i] = Accessibility_RELATION_NULL;
165 types[ATK_RELATION_CONTROLLED_BY] = Accessibility_RELATION_CONTROLLED_BY;
166 types[ATK_RELATION_CONTROLLER_FOR] = Accessibility_RELATION_CONTROLLER_FOR;
167 types[ATK_RELATION_LABEL_FOR] = Accessibility_RELATION_LABEL_FOR;
168 types[ATK_RELATION_LABELLED_BY] = Accessibility_RELATION_LABELLED_BY;
169 types[ATK_RELATION_MEMBER_OF] = Accessibility_RELATION_MEMBER_OF;
170 types[ATK_RELATION_NODE_CHILD_OF] = Accessibility_RELATION_NODE_CHILD_OF;
171 types[ATK_RELATION_FLOWS_TO] = Accessibility_RELATION_FLOWS_TO;
172 types[ATK_RELATION_FLOWS_FROM] = Accessibility_RELATION_FLOWS_FROM;
173 types[ATK_RELATION_SUBWINDOW_OF] = Accessibility_RELATION_SUBWINDOW_OF;
174 types[ATK_RELATION_EMBEDS] = Accessibility_RELATION_EMBEDS;
175 types[ATK_RELATION_EMBEDDED_BY] = Accessibility_RELATION_EMBEDDED_BY;
176 types[ATK_RELATION_POPUP_FOR] = Accessibility_RELATION_POPUP_FOR;
177 types[ATK_RELATION_PARENT_WINDOW_OF] = Accessibility_RELATION_PARENT_WINDOW_OF;
178 types[ATK_RELATION_DESCRIPTION_FOR] = Accessibility_RELATION_DESCRIPTION_FOR;
179 types[ATK_RELATION_DESCRIBED_BY] = Accessibility_RELATION_DESCRIBED_BY;
184 static Accessibility_RelationType
185 spi_relation_type_from_atk_relation_type (AtkRelationType type)
187 static gboolean is_initialized = FALSE;
188 static Accessibility_RelationType spi_relation_type_table [ATK_RELATION_LAST_DEFINED];
189 Accessibility_RelationType spi_type;
192 is_initialized = spi_init_relation_type_table (spi_relation_type_table);
194 if (type > ATK_RELATION_NULL && type < ATK_RELATION_LAST_DEFINED)
195 spi_type = spi_relation_type_table[type];
197 spi_type = Accessibility_RELATION_EXTENDED;
202 impl_getRelationSet (DBusConnection * bus, DBusMessage * message,
205 AtkObject *object = get_object (message);
208 DBusMessageIter iter, iter_array, iter_struct, iter_targets;
213 return spi_dbus_general_error (message);
214 reply = dbus_message_new_method_return (message);
215 if (!reply) return NULL;
216 set = atk_object_ref_relation_set (object);
217 dbus_message_iter_init_append (reply, &iter);
218 if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(uao)", &iter_array))
222 count = atk_relation_set_get_n_relations (set);
223 for (i = 0; i < count; i++)
225 AtkRelation *r = atk_relation_set_get_relation (set, i);
230 rt= atk_relation_get_relation_type (r);
231 type = spi_relation_type_from_atk_relation_type (rt);
232 target = atk_relation_get_target (r);
233 if (!dbus_message_iter_open_container (&iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct))
237 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &type);
238 if (!dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "o", &iter_targets))
242 for (j = 0; j < target->len; j++)
244 AtkObject *obj = target->pdata[j];
247 path = spi_dbus_get_path (obj);
248 dbus_message_iter_append (&iter_targets, DBUS_TYPE_OBJECT_PATH, &path);
250 dbus_message_iter_close_container (&iter_struct, &iter_targets);
251 dbus_message_iter_close_container (&iter_array, &iter_struct);
253 dbus_message_iter_close_container (&iter, &iter_array);
255 // TODO: handle out of memory */
260 spi_init_role_lookup_table (Accessibility_Role * role_table)
263 /* if it's not in the list below, dunno what it is */
264 for (i = 0; i < ATK_ROLE_LAST_DEFINED; ++i)
266 role_table[i] = Accessibility_ROLE_UNKNOWN;
269 role_table[ATK_ROLE_INVALID] = Accessibility_ROLE_INVALID;
270 role_table[ATK_ROLE_ACCEL_LABEL] = Accessibility_ROLE_ACCELERATOR_LABEL;
271 role_table[ATK_ROLE_ALERT] = Accessibility_ROLE_ALERT;
272 role_table[ATK_ROLE_ANIMATION] = Accessibility_ROLE_ANIMATION;
273 role_table[ATK_ROLE_ARROW] = Accessibility_ROLE_ARROW;
274 role_table[ATK_ROLE_CALENDAR] = Accessibility_ROLE_CALENDAR;
275 role_table[ATK_ROLE_CANVAS] = Accessibility_ROLE_CANVAS;
276 role_table[ATK_ROLE_CHECK_BOX] = Accessibility_ROLE_CHECK_BOX;
277 role_table[ATK_ROLE_CHECK_MENU_ITEM] = Accessibility_ROLE_CHECK_MENU_ITEM;
278 role_table[ATK_ROLE_COLOR_CHOOSER] = Accessibility_ROLE_COLOR_CHOOSER;
279 role_table[ATK_ROLE_COLUMN_HEADER] = Accessibility_ROLE_COLUMN_HEADER;
280 role_table[ATK_ROLE_COMBO_BOX] = Accessibility_ROLE_COMBO_BOX;
281 role_table[ATK_ROLE_DATE_EDITOR] = Accessibility_ROLE_DATE_EDITOR;
282 role_table[ATK_ROLE_DESKTOP_ICON] = Accessibility_ROLE_DESKTOP_ICON;
283 role_table[ATK_ROLE_DESKTOP_FRAME] = Accessibility_ROLE_DESKTOP_FRAME;
284 role_table[ATK_ROLE_DIAL] = Accessibility_ROLE_DIAL;
285 role_table[ATK_ROLE_DIALOG] = Accessibility_ROLE_DIALOG;
286 role_table[ATK_ROLE_DIRECTORY_PANE] = Accessibility_ROLE_DIRECTORY_PANE;
287 role_table[ATK_ROLE_DRAWING_AREA] = Accessibility_ROLE_DRAWING_AREA;
288 role_table[ATK_ROLE_FILE_CHOOSER] = Accessibility_ROLE_FILE_CHOOSER;
289 role_table[ATK_ROLE_FILLER] = Accessibility_ROLE_FILLER;
290 role_table[ATK_ROLE_FONT_CHOOSER] = Accessibility_ROLE_FONT_CHOOSER;
291 role_table[ATK_ROLE_FRAME] = Accessibility_ROLE_FRAME;
292 role_table[ATK_ROLE_GLASS_PANE] = Accessibility_ROLE_GLASS_PANE;
293 role_table[ATK_ROLE_HTML_CONTAINER] = Accessibility_ROLE_HTML_CONTAINER;
294 role_table[ATK_ROLE_ICON] = Accessibility_ROLE_ICON;
295 role_table[ATK_ROLE_IMAGE] = Accessibility_ROLE_IMAGE;
296 role_table[ATK_ROLE_INTERNAL_FRAME] = Accessibility_ROLE_INTERNAL_FRAME;
297 role_table[ATK_ROLE_LABEL] = Accessibility_ROLE_LABEL;
298 role_table[ATK_ROLE_LAYERED_PANE] = Accessibility_ROLE_LAYERED_PANE;
299 role_table[ATK_ROLE_LIST] = Accessibility_ROLE_LIST;
300 role_table[ATK_ROLE_LIST_ITEM] = Accessibility_ROLE_LIST_ITEM;
301 role_table[ATK_ROLE_MENU] = Accessibility_ROLE_MENU;
302 role_table[ATK_ROLE_MENU_BAR] = Accessibility_ROLE_MENU_BAR;
303 role_table[ATK_ROLE_MENU_ITEM] = Accessibility_ROLE_MENU_ITEM;
304 role_table[ATK_ROLE_OPTION_PANE] = Accessibility_ROLE_OPTION_PANE;
305 role_table[ATK_ROLE_PAGE_TAB] = Accessibility_ROLE_PAGE_TAB;
306 role_table[ATK_ROLE_PAGE_TAB_LIST] = Accessibility_ROLE_PAGE_TAB_LIST;
307 role_table[ATK_ROLE_PANEL] = Accessibility_ROLE_PANEL;
308 role_table[ATK_ROLE_PASSWORD_TEXT] = Accessibility_ROLE_PASSWORD_TEXT;
309 role_table[ATK_ROLE_POPUP_MENU] = Accessibility_ROLE_POPUP_MENU;
310 role_table[ATK_ROLE_PROGRESS_BAR] = Accessibility_ROLE_PROGRESS_BAR;
311 role_table[ATK_ROLE_PUSH_BUTTON] = Accessibility_ROLE_PUSH_BUTTON;
312 role_table[ATK_ROLE_RADIO_BUTTON] = Accessibility_ROLE_RADIO_BUTTON;
313 role_table[ATK_ROLE_RADIO_MENU_ITEM] = Accessibility_ROLE_RADIO_MENU_ITEM;
314 role_table[ATK_ROLE_ROOT_PANE] = Accessibility_ROLE_ROOT_PANE;
315 role_table[ATK_ROLE_ROW_HEADER] = Accessibility_ROLE_ROW_HEADER;
316 role_table[ATK_ROLE_SCROLL_BAR] = Accessibility_ROLE_SCROLL_BAR;
317 role_table[ATK_ROLE_SCROLL_PANE] = Accessibility_ROLE_SCROLL_PANE;
318 role_table[ATK_ROLE_SEPARATOR] = Accessibility_ROLE_SEPARATOR;
319 role_table[ATK_ROLE_SLIDER] = Accessibility_ROLE_SLIDER;
320 role_table[ATK_ROLE_SPIN_BUTTON] = Accessibility_ROLE_SPIN_BUTTON;
321 role_table[ATK_ROLE_SPLIT_PANE] = Accessibility_ROLE_SPLIT_PANE;
322 role_table[ATK_ROLE_STATUSBAR] = Accessibility_ROLE_STATUS_BAR;
323 role_table[ATK_ROLE_TABLE] = Accessibility_ROLE_TABLE;
324 role_table[ATK_ROLE_TABLE_CELL] = Accessibility_ROLE_TABLE_CELL;
325 role_table[ATK_ROLE_TABLE_COLUMN_HEADER] =
326 Accessibility_ROLE_TABLE_COLUMN_HEADER;
327 role_table[ATK_ROLE_TABLE_ROW_HEADER] = Accessibility_ROLE_TABLE_ROW_HEADER;
328 role_table[ATK_ROLE_TEAR_OFF_MENU_ITEM] =
329 Accessibility_ROLE_TEAROFF_MENU_ITEM;
330 role_table[ATK_ROLE_TERMINAL] = Accessibility_ROLE_TERMINAL;
331 role_table[ATK_ROLE_TEXT] = Accessibility_ROLE_TEXT;
332 role_table[ATK_ROLE_TOGGLE_BUTTON] = Accessibility_ROLE_TOGGLE_BUTTON;
333 role_table[ATK_ROLE_TOOL_BAR] = Accessibility_ROLE_TOOL_BAR;
334 role_table[ATK_ROLE_TOOL_TIP] = Accessibility_ROLE_TOOL_TIP;
335 role_table[ATK_ROLE_TREE] = Accessibility_ROLE_TREE;
336 role_table[ATK_ROLE_TREE_TABLE] = Accessibility_ROLE_TREE_TABLE;
337 role_table[ATK_ROLE_UNKNOWN] = Accessibility_ROLE_UNKNOWN;
338 role_table[ATK_ROLE_VIEWPORT] = Accessibility_ROLE_VIEWPORT;
339 role_table[ATK_ROLE_WINDOW] = Accessibility_ROLE_WINDOW;
340 role_table[ATK_ROLE_HEADER] = Accessibility_ROLE_HEADER;
341 role_table[ATK_ROLE_FOOTER] = Accessibility_ROLE_FOOTER;
342 role_table[ATK_ROLE_PARAGRAPH] = Accessibility_ROLE_PARAGRAPH;
343 role_table[ATK_ROLE_RULER] = Accessibility_ROLE_RULER;
344 role_table[ATK_ROLE_APPLICATION] = Accessibility_ROLE_APPLICATION;
345 role_table[ATK_ROLE_AUTOCOMPLETE] = Accessibility_ROLE_AUTOCOMPLETE;
346 role_table[ATK_ROLE_EDITBAR] = Accessibility_ROLE_EDITBAR;
347 role_table[ATK_ROLE_EMBEDDED] = Accessibility_ROLE_EMBEDDED;
348 role_table[ATK_ROLE_ENTRY] = Accessibility_ROLE_ENTRY;
349 role_table[ATK_ROLE_CHART] = Accessibility_ROLE_CHART;
350 role_table[ATK_ROLE_CAPTION] = Accessibility_ROLE_CAPTION;
351 role_table[ATK_ROLE_DOCUMENT_FRAME] = Accessibility_ROLE_DOCUMENT_FRAME;
352 role_table[ATK_ROLE_HEADING] = Accessibility_ROLE_HEADING;
353 role_table[ATK_ROLE_PAGE] = Accessibility_ROLE_PAGE;
354 role_table[ATK_ROLE_SECTION] = Accessibility_ROLE_SECTION;
355 role_table[ATK_ROLE_FORM] = Accessibility_ROLE_FORM;
356 role_table[ATK_ROLE_REDUNDANT_OBJECT] = Accessibility_ROLE_REDUNDANT_OBJECT;
357 role_table[ATK_ROLE_LINK] = Accessibility_ROLE_LINK;
358 role_table[ATK_ROLE_INPUT_METHOD_WINDOW] =
359 Accessibility_ROLE_INPUT_METHOD_WINDOW;
364 spi_accessible_role_from_atk_role (AtkRole role)
366 static gboolean is_initialized = FALSE;
367 static Accessibility_Role spi_role_table[ATK_ROLE_LAST_DEFINED];
368 Accessibility_Role spi_role;
372 is_initialized = spi_init_role_lookup_table (spi_role_table);
375 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
377 spi_role = spi_role_table[role];
381 spi_role = Accessibility_ROLE_EXTENDED;
387 impl_getRole (DBusConnection * bus, DBusMessage * message, void *user_data)
389 AtkObject *object = get_object (message);
395 return spi_dbus_general_error (message);
396 role = atk_object_get_role (object);
397 rv = spi_accessible_role_from_atk_role (role);
398 reply = dbus_message_new_method_return (message);
401 dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
408 impl_get_role_str (void *datum)
410 g_assert (ATK_IS_OBJECT (datum));
411 return g_strdup_printf ("%d",
412 spi_accessible_role_from_atk_role
413 (atk_object_get_role ((AtkObject *) datum)));
417 impl_getRoleName (DBusConnection * bus, DBusMessage * message,
420 AtkObject *object = get_object (message);
422 const char *role_name;
426 return spi_dbus_general_error (message);
427 role = atk_object_get_role (object);
428 role_name = atk_role_get_name (role);
431 reply = dbus_message_new_method_return (message);
434 dbus_message_append_args (reply, DBUS_TYPE_STRING, &role_name,
441 impl_getLocalizedRoleName (DBusConnection * bus, DBusMessage * message,
444 AtkObject *object = get_object (message);
446 const char *role_name;
450 return spi_dbus_general_error (message);
451 role = atk_object_get_role (object);
452 role_name = atk_role_get_localized_name (role);
455 reply = dbus_message_new_method_return (message);
458 dbus_message_append_args (reply, DBUS_TYPE_STRING, &role_name,
465 impl_getState (DBusConnection * bus, DBusMessage * message, void *user_data)
467 AtkObject *object = get_object (message);
469 dbus_uint32_t *array = rv;
473 return spi_dbus_general_error (message);
474 spi_atk_state_to_dbus_array (object, rv);
475 reply = dbus_message_new_method_return (message);
478 dbus_message_append_args (reply, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &array,
479 2, DBUS_TYPE_INVALID);
485 impl_getAttributes (DBusConnection * bus, DBusMessage * message,
488 AtkObject *object = get_object (message);
490 AtkAttributeSet *attributes;
491 AtkAttribute *attr = NULL;
493 gint n_attributes = 0;
497 return spi_dbus_general_error (message);
499 attributes = atk_object_get_attributes (object);
501 n_attributes = g_slist_length (attributes);
503 retval = (char **) g_malloc (n_attributes * sizeof (char *));
505 for (i = 0; i < n_attributes; ++i)
507 attr = g_slist_nth_data (attributes, i);
508 retval[i] = g_strconcat (attr->name, ":", attr->value, NULL);
511 atk_attribute_set_free (attributes);
512 reply = dbus_message_new_method_return (message);
515 dbus_message_append_args (reply, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
516 &retval, n_attributes, DBUS_TYPE_INVALID);
518 for (i = 0; i < n_attributes; i++)
525 impl_getApplication (DBusConnection * bus, DBusMessage * message,
528 AtkObject *root = atk_get_root ();
529 return spi_dbus_return_object (message, root, FALSE);
532 static DRouteMethod methods[] = {
533 //{impl_isEqual, "isEqual"},
534 {impl_getChildren, "getChildren"},
535 {impl_getIndexInParent, "getIndexInParent"},
536 {impl_getRelationSet, "getRelationSet"},
537 {impl_getRole, "getRole"},
538 {impl_getRoleName, "getRoleName"},
539 {impl_getLocalizedRoleName, "getLocalizedRoleName"},
540 {impl_getState, "getState"},
541 {impl_getAttributes, "getAttributes"},
542 {impl_getApplication, "getApplication"},
546 static DRouteProperty properties[] = {
547 {impl_get_name, impl_set_name, "name"},
548 {impl_get_description, impl_set_description, "description"},
549 {impl_get_parent, NULL, "parent"},
550 //{impl_get_childCount, NULL, "childCount"},
551 //{NULL, NULL, NULL, "role"},
556 spi_initialize_accessible (DRouteData * data)
558 droute_add_interface (data, SPI_DBUS_INTERFACE_ACCESSIBLE,
560 (DRouteGetDatumFunction) get_object_from_path, NULL);