2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
7 * Copyright 2010, 2011 Novell, 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 "atspi-private.h"
26 #include "atspi-accessible-private.h"
29 static gboolean enable_caching = FALSE;
30 static guint quark_locale;
33 atspi_action_interface_init (AtspiAction *action)
38 atspi_collection_interface_init (AtspiCollection *component)
43 atspi_component_interface_init (AtspiComponent *component)
48 atspi_document_interface_init (AtspiDocument *document)
53 atspi_editable_text_interface_init (AtspiEditableText *editable_text)
58 atspi_hypertext_interface_init (AtspiHypertext *hypertext)
63 atspi_image_interface_init (AtspiImage *image)
68 atspi_selection_interface_init (AtspiSelection *selection)
73 atspi_table_interface_init (AtspiTable *table)
78 atspi_table_cell_interface_init (AtspiTableCell *cell)
83 atspi_text_interface_init (AtspiText *text)
88 atspi_value_interface_init (AtspiValue *value)
92 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT,
93 G_ADD_PRIVATE (AtspiAccessible)
94 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init)
95 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COLLECTION, atspi_collection_interface_init)
96 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
97 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_DOCUMENT, atspi_document_interface_init)
98 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init)
99 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_HYPERTEXT, atspi_hypertext_interface_init)
100 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init)
101 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init)
102 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
103 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE_CELL, atspi_table_cell_interface_init)
104 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init)
105 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_VALUE, atspi_value_interface_init))
107 #ifdef DEBUG_REF_COUNTS
108 static gint accessible_count = 0;
112 atspi_accessible_init (AtspiAccessible *accessible)
114 #ifdef DEBUG_REF_COUNTS
116 g_hash_table_insert (_atspi_get_live_refs (), accessible, NULL);
117 g_print("at-spi: init: %d objects\n", accessible_count);
120 accessible->priv = atspi_accessible_get_instance_private (accessible);
124 atspi_accessible_dispose (GObject *object)
126 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
128 AtspiAccessible *parent;
132 /* TODO: Only fire if object not already marked defunct */
133 memset (&e, 0, sizeof (e));
134 e.type = "object:state-changed:defunct";
135 e.source = accessible;
138 _atspi_send_event (&e);
140 if (accessible->states)
142 g_object_unref (accessible->states);
143 accessible->states = NULL;
146 parent = accessible->accessible_parent;
147 if (parent && parent->children)
149 GList*ls = g_list_find (parent->children, accessible);
152 gboolean replace = (ls == parent->children);
153 ls = g_list_remove (ls, accessible);
155 parent->children = ls;
156 g_object_unref (object);
162 g_object_unref (parent);
163 accessible->accessible_parent = NULL;
166 children = accessible->children;
167 accessible->children = NULL;
168 for (l = children; l; l = l->next)
170 AtspiAccessible *child = l->data;
171 if (child && child->accessible_parent == accessible)
173 g_object_unref (accessible);
174 child->accessible_parent = NULL;
176 g_object_unref (child);
178 g_list_free (children);
180 G_OBJECT_CLASS (atspi_accessible_parent_class) ->dispose (object);
184 atspi_accessible_finalize (GObject *object)
186 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
188 g_free (accessible->description);
189 g_free (accessible->name);
190 if (accessible->attributes)
191 g_hash_table_unref (accessible->attributes);
193 if (accessible->priv->cache)
194 g_hash_table_destroy (accessible->priv->cache);
196 #ifdef DEBUG_REF_COUNTS
198 g_hash_table_remove (_atspi_get_live_refs (), accessible);
199 g_print ("at-spi: finalize: %d objects\n", accessible_count);
202 G_OBJECT_CLASS (atspi_accessible_parent_class)
207 atspi_accessible_class_init (AtspiAccessibleClass *klass)
209 GObjectClass *object_class = G_OBJECT_CLASS (klass);
211 object_class->dispose = atspi_accessible_dispose;
212 object_class->finalize = atspi_accessible_finalize;
214 quark_locale = g_quark_from_string ("accessible-locale");
218 * atspi_accessible_get_name:
219 * @obj: a pointer to the #AtspiAccessible object on which to operate.
221 * Gets the name of an #AtspiAccessible object.
223 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object
224 * or NULL on exception.
227 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
229 g_return_val_if_fail (obj != NULL, g_strdup (""));
230 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_NAME))
232 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
234 return g_strdup ("");
235 _atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
237 return g_strdup (obj->name);
242 * atspi_accessible_get_unique_id:
243 * @obj: a pointer to the #AtspiAccessible object on which to operate.
245 * Gets the identificator, uniquely identifying object, or NULL if an error occured.
247 * Returns: a UTF-8 string describing the #AtspiAccessible object
248 * or NULL on exception or NULL object passed.
251 atspi_accessible_get_unique_id(AtspiAccessible *obj, GError **error)
254 g_set_error(error, ATSPI_ERROR, ATSPI_ERROR_IPC, "argument is null");
259 gchar *bus_name = atspi_accessible_get_bus_name(obj, error);
260 if (bus_name && bus_name[0]) {
261 gchar *path = atspi_accessible_get_path(obj, error);
263 id = g_strdup_printf("%s:%s", bus_name, path);
265 g_set_error(error, ATSPI_ERROR, ATSPI_ERROR_IPC, "failed to get path");
269 g_set_error(error, ATSPI_ERROR, ATSPI_ERROR_IPC, "failed to get bus name");
275 * atspi_accessible_get_bus_name:
276 * @obj: a pointer to the #AtspiAccessible object on which to operate.
278 * Gets the bus name, where object belongs.
280 * Returns: a UTF-8 string describing the #AtspiAccessible object's
281 * bus name or empty string on exception or NULL object passed.
284 atspi_accessible_get_bus_name(AtspiAccessible *obj, GError **error)
286 if (!obj || !obj->parent.app)
288 return g_strdup (obj->parent.app->bus_name);
292 * atspi_accessible_get_path:
293 * @obj: a pointer to the #AtspiAccessible object on which to operate.
295 * Gets the path, uniquely identifying object over its bus name.
297 * Returns: a UTF-8 string describing the #AtspiAccessible object
298 * or empty string on exception or NULL object passed.
301 atspi_accessible_get_path(AtspiAccessible *obj, GError **error)
303 static const char *prefix = "/org/a11y/atspi/accessible/";
304 static int prefix_len = 27;
308 AtspiObject *o = ATSPI_OBJECT (obj);
311 if (strncmp(o->path, prefix, prefix_len) == 0)
312 return g_strdup(o->path + prefix_len);
313 return g_strdup (o->path);
317 * atspi_accessible_get_navigable_at_point:
318 * @root: a pointer to the #AtspiAccessible to start search from.
319 * @x: a #gint specifying the x coordinate of the point in question.
320 * @y: a #gint specifying the y coordinate of the point in question.
321 * @ctype: the coordinate system of the point (@x, @y)
322 * (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
324 * Finds the accessible element closest to user (highest in z-order), at a given coordinate within an #AtspiAccessible.
325 * This should be the element, that should be picked, when doing mouse click or finger tap at given coordinates.
327 * Returns: (nullable) (transfer full): a pointer to an
328 * #AtspiAccessible descendant (of any depth) of the specified component which
329 * contains the point (@x, @y), or NULL if no descendant contains
333 atspi_accessible_get_navigable_at_point (AtspiAccessible *root,
336 AtspiCoordType ctype, GError **error)
338 dbus_int32_t d_x = x, d_y = y;
339 dbus_uint32_t d_ctype = ctype;
341 AtspiAccessible *return_value = NULL;
342 unsigned char recurse = 0;
344 g_return_val_if_fail (root != NULL, NULL);
346 reply = _atspi_dbus_call_partial (root, atspi_interface_accessible, "GetNavigableAtPoint", error, "iiu", d_x, d_y, d_ctype);
348 AtspiAccessible *tmp = _atspi_dbus_return_accessible_and_recurse_info_from_message (reply, &recurse);
351 g_object_unref(return_value);
352 return_value = root = tmp;
357 static unsigned char are_objects_on_the_same_bus(AtspiAccessible *obj1, AtspiAccessible *obj2)
359 const char *bus_name_1 = obj1->parent.app->bus_name;
360 const char *bus_name_2 = obj2->parent.app->bus_name;
361 return strcmp(bus_name_1, bus_name_2) == 0;
364 static unsigned char object_is_valid(AtspiAccessible *obj)
368 AtspiStateSet *ss = atspi_accessible_get_state_set(obj);
371 unsigned char valid = atspi_state_set_contains(ss, ATSPI_STATE_DEFUNCT) == 0;
377 NEIGHBOR_SEARCH_MODE_NORMAL = 0,
378 NEIGHBOR_SEARCH_MODE_RECURSE_FROM_ROOT = 1,
379 NEIGHBOR_SEARCH_MODE_CONTINUE_AFTER_FAILED_RECURSING = 2,
380 } GetNeighborSearchMode;
382 * atspi_accessible_get_neighbor:
383 * @root: a pointer to a #AtspiAccessible, which represents current root of subtree to search
384 * @start: a pointer to the #AtspiAccessible to start search from (can be null, which means start from root)
385 * @direction: direction, in which search (forward or backward)
387 * Calculates next (or previous) accessible element in logical order or null if none found.
389 * Returns: (nullable) (transfer full): a pointer to an
390 * #AtspiAccessible element, which is next (previous) in logical order or null if none found.
393 atspi_accessible_get_neighbor (AtspiAccessible *root,
394 AtspiAccessible *start,
395 AtspiNeighborSearchDirection direction,
398 g_return_val_if_fail (object_is_valid(root), NULL);
399 if (!object_is_valid(start))
401 const char *root_path = ATSPI_OBJECT(root)->path;
402 AtspiAccessible *return_value = NULL;
404 unsigned char recurse;
405 GetNeighborSearchMode search_mode = NEIGHBOR_SEARCH_MODE_NORMAL;
406 GQueue *children_root_stack = g_queue_new();
409 const char *path = are_objects_on_the_same_bus(root, start) ? root_path : "";
410 DBusMessage *reply = _atspi_dbus_call_partial (start, atspi_interface_accessible, "GetNeighbor", error, "sii", path, (int)direction, (int)search_mode);
411 AtspiAccessible *ret = _atspi_dbus_return_accessible_and_recurse_info_from_message (reply, &recurse);
412 // got return value and request for recursive search, it means ret is on another bridge, than start
413 // thus we're recursing. should the recurse failed to find anything it will end with
414 if (ret && recurse) {
415 g_object_unref(G_OBJECT(start));
416 g_queue_push_tail(children_root_stack, ret);
419 search_mode = NEIGHBOR_SEARCH_MODE_RECURSE_FROM_ROOT;
422 // found the one we've been looking for
424 g_object_unref(G_OBJECT(start));
429 // we've stepped into different bridges previously and now we're going back to the last one
430 // and continuing search where we left
431 if (!g_queue_is_empty(children_root_stack)) {
432 g_object_unref(G_OBJECT(start));
433 start = g_queue_pop_tail(children_root_stack);
434 search_mode = NEIGHBOR_SEARCH_MODE_CONTINUE_AFTER_FAILED_RECURSING;
437 // there's no more bridges to check, but we might have started from one
438 // in that case there might be bridges "below" start, which we yet have to visit
439 if (!are_objects_on_the_same_bus(root, start)) {
440 unsigned char continue_loop = 1;
441 while(continue_loop) {
442 AtspiAccessible *parent = atspi_accessible_get_parent(start, NULL);
443 continue_loop = parent ? are_objects_on_the_same_bus(start, parent) : 0;
444 g_object_unref(G_OBJECT(start));
447 // going up thru parents put us in weird place (we didnt meet root on the way)
452 // start object now points to different bridge and must be treated as "resume after recursing"
453 search_mode = NEIGHBOR_SEARCH_MODE_CONTINUE_AFTER_FAILED_RECURSING;
458 g_object_unref(start);
462 while(!g_queue_is_empty(children_root_stack))
463 g_object_unref(g_queue_pop_tail(children_root_stack));
464 g_queue_free(children_root_stack);
470 * atspi_accessible_get_description:
471 * @obj: a pointer to the #AtspiAccessible object on which to operate.
473 * Gets the description of an #AtspiAccessible object.
475 * Returns: a UTF-8 string describing the #AtspiAccessible object
476 * or NULL on exception.
479 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
481 g_return_val_if_fail (obj != NULL, g_strdup (""));
483 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_DESCRIPTION))
485 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
486 "Description", error, "s",
488 return g_strdup ("");
489 _atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
491 return g_strdup (obj->description);
494 const char *str_parent = "Parent";
497 * atspi_accessible_get_parent:
498 * @obj: a pointer to the #AtspiAccessible object to query.
500 * Gets an #AtspiAccessible object's parent container.
502 * Returns: (nullable) (transfer full): a pointer to the
503 * #AtspiAccessible object which contains the given
504 * #AtspiAccessible instance, or NULL if the @obj has no
509 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
511 g_return_val_if_fail (obj != NULL, NULL);
513 if (obj->parent.app &&
514 !_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
516 DBusMessage *message, *reply;
517 DBusMessageIter iter, iter_variant;
518 message = dbus_message_new_method_call (obj->parent.app->bus_name,
520 DBUS_INTERFACE_PROPERTIES, "Get");
523 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
524 DBUS_TYPE_STRING, &str_parent,
526 reply = _atspi_dbus_send_with_reply_and_block (message, error);
529 if (strcmp (dbus_message_get_signature (reply), "v") != 0)
531 dbus_message_unref (reply);
534 dbus_message_iter_init (reply, &iter);
535 dbus_message_iter_recurse (&iter, &iter_variant);
536 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
537 dbus_message_unref (reply);
538 _atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
540 if (!obj->accessible_parent)
542 return g_object_ref (obj->accessible_parent);
546 * atspi_accessible_get_child_count:
547 * @obj: a pointer to the #AtspiAccessible object on which to operate.
549 * Gets the number of children contained by an #AtspiAccessible object.
551 * Returns: a #long indicating the number of #AtspiAccessible children
552 * contained by an #AtspiAccessible object or -1 on exception.
556 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
558 g_return_val_if_fail (obj != NULL, -1);
560 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
563 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
564 "ChildCount", error, "i", &ret))
569 return g_list_length (obj->children);
573 * atspi_accessible_get_child_at_index:
574 * @obj: a pointer to the #AtspiAccessible object on which to operate.
575 * @child_index: a #long indicating which child is specified.
577 * Gets the #AtspiAccessible child of an #AtspiAccessible object at a given index.
579 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
580 * index @child_index or NULL on exception.
583 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
587 AtspiAccessible *child;
589 g_return_val_if_fail (obj != NULL, NULL);
591 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
594 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
595 "GetChildAtIndex", error, "i",
597 return _atspi_dbus_return_accessible_from_message (reply);
600 child = g_list_nth_data (obj->children, child_index);
603 return g_object_ref (child);
607 * atspi_accessible_get_index_in_parent:
608 * @obj: a pointer to the #AtspiAccessible object on which to operate.
610 * Gets the index of an #AtspiAccessible object within its parent's
611 * #AtspiAccessible children list.
613 * Returns: a #glong indicating the index of the #AtspiAccessible object
615 * or -1 if @obj has no containing parent or on exception.
618 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
623 g_return_val_if_fail (obj != NULL, -1);
624 if (_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT) &&
625 !obj->accessible_parent)
627 if (!obj->accessible_parent ||
628 !_atspi_accessible_test_cache (obj->accessible_parent,
629 ATSPI_CACHE_CHILDREN))
631 dbus_int32_t ret = -1;
632 _atspi_dbus_call (obj, atspi_interface_accessible,
633 "GetIndexInParent", NULL, "=>i", &ret);
637 l = obj->accessible_parent->children;
640 if (l->data == obj) return i;
651 } Accessibility_Relation;
654 * atspi_accessible_get_relation_set:
655 * @obj: a pointer to the #AtspiAccessible object on which to operate.
657 * Gets the set of #AtspiRelation objects which describes this #AtspiAccessible object's
658 * relationships with other #AtspiAccessible objects.
660 * Returns: (element-type AtspiRelation*) (transfer full): a #GArray of
661 * #AtspiRelation pointers or NULL on exception.
664 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
667 DBusMessageIter iter, iter_array;
670 g_return_val_if_fail (obj != NULL, NULL);
672 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
675 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
677 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
678 dbus_message_iter_init (reply, &iter);
679 dbus_message_iter_recurse (&iter, &iter_array);
680 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
682 AtspiRelation *relation;
683 relation = _atspi_relation_new_from_iter (&iter_array);
684 ret = g_array_append_val (ret, relation);
685 dbus_message_iter_next (&iter_array);
687 dbus_message_unref (reply);
692 * atspi_accessible_get_role:
693 * @obj: a pointer to the #AtspiAccessible object on which to operate.
695 * Gets the UI role played by an #AtspiAccessible object.
696 * This role's name can be obtained via atspi_accessible_get_role_name ().
698 * Returns: the #AtspiRole of an #AtspiAccessible object.
702 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
704 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
706 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ROLE))
709 /* TODO: Make this a property */
710 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
713 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
720 * atspi_accessible_get_role_name:
721 * @obj: a pointer to the #AtspiAccessible object on which to operate.
723 * Gets a UTF-8 string corresponding to the name of the role played by an object.
724 * This method will return useful values for roles that fall outside the
725 * enumeration used in atspi_accessible_get_role ().
727 * Returns: a UTF-8 string specifying the type of UI role played by an
728 * #AtspiAccessible object.
732 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
734 gchar *retval = NULL;
737 g_return_val_if_fail (obj != NULL, NULL);
739 role = atspi_accessible_get_role (obj, error);
740 if (role >= 0 && role < ATSPI_ROLE_COUNT && role != ATSPI_ROLE_EXTENDED)
741 return atspi_role_get_name (role);
743 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
746 retval = g_strdup ("");
752 * atspi_accessible_get_localized_role_name:
753 * @obj: a pointer to the #AtspiAccessible object on which to operate.
755 * Gets a UTF-8 string corresponding to the name of the role played by an
756 * object, translated to the current locale.
757 * This method will return useful values for roles that fall outside the
758 * enumeration used in atspi_accessible_getRole ().
760 * Returns: a localized, UTF-8 string specifying the type of UI role played
761 * by an #AtspiAccessible object.
765 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
769 g_return_val_if_fail (obj != NULL, NULL);
771 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
774 return g_strdup ("");
779 static AtspiStateSet *
782 AtspiStateSet *set = atspi_state_set_new (NULL);
783 atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
788 * atspi_accessible_get_state_set:
789 * @obj: a pointer to the #AtspiAccessible object on which to operate.
791 * Gets the states currently held by an object.
793 * Returns: (transfer full): a pointer to an #AtspiStateSet representing an
794 * object's current state set.
797 atspi_accessible_get_state_set (AtspiAccessible *obj)
799 /* TODO: Should take a GError **, but would be an API break */
800 if (!obj->parent.app || !obj->parent.app->bus)
801 return defunct_set ();
803 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
806 DBusMessageIter iter;
807 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
808 "GetState", NULL, "");
809 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
810 dbus_message_iter_init (reply, &iter);
811 _atspi_dbus_set_state (obj, &iter);
812 dbus_message_unref (reply);
813 _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
815 return g_object_ref (obj->states);
819 * atspi_accessible_get_attributes:
820 * @obj: The #AtspiAccessible being queried.
822 * Gets the #AttributeSet representing any assigned
823 * name-value pair attributes or annotations for this object.
824 * For typographic, textual, or textually-semantic attributes, see
825 * atspi_text_get_attributes instead.
827 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
828 * attributes assigned to this object.
831 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
833 DBusMessage *message;
835 g_return_val_if_fail (obj != NULL, NULL);
837 if (obj->priv->cache)
839 GValue *val = g_hash_table_lookup (obj->priv->cache, "Attributes");
841 return g_value_dup_boxed (val);
844 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ATTRIBUTES))
846 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
847 "GetAttributes", error, "");
848 obj->attributes = _atspi_dbus_return_hash_from_message (message);
849 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ATTRIBUTES);
852 if (!obj->attributes)
854 return g_hash_table_ref (obj->attributes);
858 add_to_attribute_array (gpointer key, gpointer value, gpointer data)
860 GArray **array = (GArray **)data;
861 gchar *str = g_strconcat (key, ":", value, NULL);
862 *array = g_array_append_val (*array, str);
866 * atspi_accessible_get_attributes_as_array:
867 * @obj: The #AtspiAccessible being queried.
869 * Gets a #GArray representing any assigned
870 * name-value pair attributes or annotations for this object.
871 * For typographic, textual, or textually-semantic attributes, see
872 * atspi_text_get_attributes_as_array instead.
874 * Returns: (element-type gchar*) (transfer full): The name-value-pair
875 * attributes assigned to this object.
878 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
880 DBusMessage *message;
882 g_return_val_if_fail (obj != NULL, NULL);
884 if (obj->priv->cache)
886 GValue *val = g_hash_table_lookup (obj->priv->cache, "Attributes");
889 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
890 GHashTable *attributes = g_value_get_boxed (val);
891 g_hash_table_foreach (attributes, add_to_attribute_array, &array);
896 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
897 return _atspi_dbus_return_attribute_array_from_message (message);
901 * atspi_accessible_get_application:
902 * @obj: The #AtspiAccessible being queried.
904 * Gets the containing #AtspiApplication for an object.
906 * Returns: (transfer full): the containing #AtspiApplication instance for
910 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
912 AtspiAccessible *parent;
917 parent = atspi_accessible_get_parent (obj, NULL);
918 if (!parent && obj->parent.app &&
919 atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
921 AtspiAccessible *root = g_object_ref (obj->parent.app->root);
924 g_object_unref (obj);
925 if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
927 g_object_unref (root);
933 if (!parent || parent == obj ||
934 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
937 g_object_unref (parent);
940 g_object_unref (obj);
945 /* Application-specific methods */
948 * atspi_accessible_get_toolkit_name:
949 * @obj: a pointer to the #AtspiAccessible object on which to operate.
951 * Gets the toolkit name for an #AtspiAccessible object.
952 * Only works on application root objects.
954 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object or NULL on exception.
957 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
959 g_return_val_if_fail (obj != NULL, NULL);
961 if (!obj->parent.app)
964 if (!obj->parent.app->toolkit_name)
965 _atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName",
966 error, "s", &obj->parent.app->toolkit_name);
968 return g_strdup (obj->parent.app->toolkit_name);
972 * atspi_accessible_get_toolkit_version:
973 * @obj: a pointer to the #AtspiAccessible object on which to operate.
975 * Gets the toolkit version for an #AtspiAccessible object.
976 * Only works on application root objects.
978 * Returns: a UTF-8 string indicating the toolkit version for the #AtspiAccessible object or NULL on exception.
981 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
983 g_return_val_if_fail (obj != NULL, NULL);
985 if (!obj->parent.app)
988 if (!obj->parent.app->toolkit_version)
989 _atspi_dbus_get_property (obj, atspi_interface_application, "Version",
990 error, "s", &obj->parent.app->toolkit_version);
992 return g_strdup (obj->parent.app->toolkit_version);
996 * atspi_accessible_get_atspi_version:
997 * @obj: a pointer to the #AtspiAccessible object on which to operate.
999 * Gets the AT-SPI IPC specification version supported by the application
1000 * pointed to by the #AtspiAccessible object.
1001 * Only works on application root objects.
1003 * Returns: a UTF-8 string indicating the AT-SPI version for the #AtspiAccessible object or NULL on exception.
1006 atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
1008 g_return_val_if_fail (obj != NULL, NULL);
1010 if (!obj->parent.app)
1013 if (!obj->parent.app->atspi_version)
1014 _atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion",
1015 error, "s", &obj->parent.app->atspi_version);
1017 return g_strdup (obj->parent.app->atspi_version);
1021 * atspi_accessible_get_id:
1022 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1024 * Gets the application id for a #AtspiAccessible object.
1025 * Only works on application root objects.
1027 * Returns: a positive #gint indicating the id for the #AtspiAccessible object
1028 * or -1 on exception.
1031 atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
1035 g_return_val_if_fail (obj != NULL, -1);
1037 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
1043 /* Interface query methods */
1046 _atspi_accessible_is_a (AtspiAccessible *accessible,
1047 const char *interface_name)
1051 if (accessible == NULL)
1056 if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
1059 DBusMessageIter iter;
1060 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
1061 "GetInterfaces", NULL, "");
1062 _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
1063 dbus_message_iter_init (reply, &iter);
1064 _atspi_dbus_set_interfaces (accessible, &iter);
1065 dbus_message_unref (reply);
1066 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
1069 n = _atspi_get_iface_num (interface_name);
1070 if (n == -1) return FALSE;
1071 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1075 * atspi_accessible_is_action:
1076 * @obj: a pointer to the #AtspiAccessible instance to query.
1078 * Query whether the specified #AtspiAccessible implements the
1079 * #AtspiAction interface.
1081 * Returns: #TRUE if @obj implements the #AtspiAction interface,
1085 atspi_accessible_is_action (AtspiAccessible *obj)
1087 return _atspi_accessible_is_a (obj,
1088 atspi_interface_action);
1092 * atspi_accessible_is_application:
1093 * @obj: a pointer to the #AtspiAccessible instance to query.
1095 * Query whether the specified #AtspiAccessible implements the
1096 * #AtspiApplication interface.
1098 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
1102 atspi_accessible_is_application (AtspiAccessible *obj)
1104 return _atspi_accessible_is_a (obj,
1105 atspi_interface_application);
1109 * atspi_accessible_is_collection:
1110 * @obj: a pointer to the #AtspiAccessible instance to query.
1112 * Query whether the specified #AtspiAccessible implements the
1113 * #AtspiCollection interface.
1115 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
1119 atspi_accessible_is_collection (AtspiAccessible *obj)
1121 return _atspi_accessible_is_a (obj,
1122 atspi_interface_collection);
1126 * atspi_accessible_is_component:
1127 * @obj: a pointer to the #AtspiAccessible instance to query.
1129 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
1131 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
1135 atspi_accessible_is_component (AtspiAccessible *obj)
1137 return _atspi_accessible_is_a (obj,
1138 atspi_interface_component);
1142 * atspi_accessible_is_document:
1143 * @obj: a pointer to the #AtspiAccessible instance to query.
1145 * Query whether the specified #AtspiAccessible implements the
1146 * #AtspiDocument interface.
1148 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
1152 atspi_accessible_is_document (AtspiAccessible *obj)
1154 return _atspi_accessible_is_a (obj,
1155 atspi_interface_document);
1159 * atspi_accessible_is_editable_text:
1160 * @obj: a pointer to the #AtspiAccessible instance to query.
1162 * Query whether the specified #AtspiAccessible implements the
1163 * #AtspiEditableText interface.
1165 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
1169 atspi_accessible_is_editable_text (AtspiAccessible *obj)
1171 return _atspi_accessible_is_a (obj,
1172 atspi_interface_editable_text);
1176 * atspi_accessible_is_hypertext:
1177 * @obj: a pointer to the #AtspiAccessible instance to query.
1179 * Query whether the specified #AtspiAccessible implements the
1180 * #AtspiHypertext interface.
1182 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1186 atspi_accessible_is_hypertext (AtspiAccessible *obj)
1188 return _atspi_accessible_is_a (obj,
1189 atspi_interface_hypertext);
1193 * atspi_accessible_is_hyperlink:
1194 * @obj: a pointer to the #AtspiAccessible instance to query.
1196 * Query whether the specified #AtspiAccessible implements the
1197 * #AtspiHyperlink interface.
1199 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1203 atspi_accessible_is_hyperlink (AtspiAccessible *obj)
1205 return _atspi_accessible_is_a (obj,
1206 atspi_interface_hyperlink);
1210 * atspi_accessible_is_image:
1211 * @obj: a pointer to the #AtspiAccessible instance to query.
1213 * Query whether the specified #AtspiAccessible implements the
1214 * #AtspiImage interface.
1216 * Returns: #TRUE if @obj implements the #AtspiImage interface,
1220 atspi_accessible_is_image (AtspiAccessible *obj)
1222 return _atspi_accessible_is_a (obj,
1223 atspi_interface_image);
1227 * atspi_accessible_is_selection:
1228 * @obj: a pointer to the #AtspiAccessible instance to query.
1230 * Query whether the specified #AtspiAccessible implements the
1231 * #AtspiSelection interface.
1233 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
1237 atspi_accessible_is_selection (AtspiAccessible *obj)
1239 return _atspi_accessible_is_a (obj,
1240 atspi_interface_selection);
1244 * atspi_accessible_is_table:
1245 * @obj: a pointer to the #AtspiAccessible instance to query.
1247 * Query whether the specified #AtspiAccessible implements the
1248 * #AtspiTable interface.
1250 * Returns: #TRUE if @obj implements the #AtspiTable interface,
1254 atspi_accessible_is_table (AtspiAccessible *obj)
1256 return _atspi_accessible_is_a (obj,
1257 atspi_interface_table);
1261 * atspi_accessible_is_table_cell:
1262 * @obj: a pointer to the #AtspiAccessible instance to query.
1264 * Query whether the specified #AtspiAccessible implements the
1265 * #AtspiTableCell interface.
1267 * Returns: #TRUE if @obj implements the #AtspiTable interface,
1271 atspi_accessible_is_table_cell (AtspiAccessible *obj)
1273 return _atspi_accessible_is_a (obj,
1274 atspi_interface_table_cell);
1278 * atspi_accessible_is_streamable_content:
1279 * @obj: a pointer to the #AtspiAccessible instance to query.
1281 * Query whether the specified #AtspiAccessible implements the
1282 * #AtspiStreamableContent interface.
1284 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
1288 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
1291 return _atspi_accessible_is_a (obj,
1292 atspi_interface_streamable_content);
1294 g_warning ("Streamable content not implemented");
1300 * atspi_accessible_is_text:
1301 * @obj: a pointer to the #AtspiAccessible instance to query.
1303 * Query whether the specified #AtspiAccessible implements the
1304 * #AtspiText interface.
1306 * Returns: #TRUE if @obj implements the #AtspiText interface,
1310 atspi_accessible_is_text (AtspiAccessible *obj)
1312 return _atspi_accessible_is_a (obj,
1313 atspi_interface_text);
1317 * atspi_accessible_is_value:
1318 * @obj: a pointer to the #AtspiAccessible instance to query.
1320 * Query whether the specified #AtspiAccessible implements the
1321 * #AtspiValue interface.
1323 * Returns: #TRUE if @obj implements the #AtspiValue interface,
1327 atspi_accessible_is_value (AtspiAccessible *obj)
1329 return _atspi_accessible_is_a (obj,
1330 atspi_interface_value);
1334 * atspi_accessible_get_action: (rename-to atspi_accessible_get_action_iface)
1335 * @obj: a pointer to the #AtspiAccessible instance to query.
1337 * Gets the #AtspiAction interface for an #AtspiAccessible.
1339 * Returns: (transfer full): a pointer to an #AtspiAction interface
1340 * instance, or NULL if @obj does not implement #AtspiAction.
1342 * Deprecated: 2.10: Use atspi_accessible_get_action_iface instead.
1345 atspi_accessible_get_action (AtspiAccessible *accessible)
1347 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1348 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1352 * atspi_accessible_get_action_iface:
1353 * @obj: a pointer to the #AtspiAccessible instance to query.
1355 * Gets the #AtspiAction interface for an #AtspiAccessible.
1357 * Returns: (transfer full): a pointer to an #AtspiAction interface
1358 * instance, or NULL if @obj does not implement #AtspiAction.
1361 atspi_accessible_get_action_iface (AtspiAccessible *accessible)
1363 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1364 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1368 * atspi_accessible_get_collection: (rename-to atspi_accessible_get_collection_iface)
1369 * @obj: a pointer to the #AtspiAccessible instance to query.
1371 * Gets the #AtspiCollection interface for an #AtspiAccessible.
1373 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1374 * instance, or NULL if @obj does not implement #AtspiCollection.
1376 * Deprecated: 2.10: Use atspi_accessible_get_collection_iface instead.
1379 atspi_accessible_get_collection (AtspiAccessible *accessible)
1381 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1382 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1386 * atspi_accessible_get_collection_iface:
1387 * @obj: a pointer to the #AtspiAccessible instance to query.
1389 * Gets the #AtspiCollection interface for an #AtspiAccessible.
1391 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1392 * instance, or NULL if @obj does not implement #AtspiCollection.
1395 atspi_accessible_get_collection_iface (AtspiAccessible *accessible)
1397 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1398 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1402 * atspi_accessible_get_component: (rename-to atspi_accessible_get_component_iface)
1403 * @obj: a pointer to the #AtspiAccessible instance to query.
1405 * Gets the #AtspiComponent interface for an #AtspiAccessible.
1407 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1408 * instance, or NULL if @obj does not implement #AtspiComponent.
1410 * Deprecated: 2.10: Use atspi_accessible_get_component_iface instead.
1413 atspi_accessible_get_component (AtspiAccessible *obj)
1415 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1416 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1420 * atspi_accessible_get_component_iface:
1421 * @obj: a pointer to the #AtspiAccessible instance to query.
1423 * Gets the #AtspiComponent interface for an #AtspiAccessible.
1425 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1426 * instance, or NULL if @obj does not implement #AtspiComponent.
1429 atspi_accessible_get_component_iface (AtspiAccessible *obj)
1431 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1432 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1436 * atspi_accessible_get_document: (rename-to atspi_accessible_get_document_iface)
1437 * @obj: a pointer to the #AtspiAccessible instance to query.
1439 * Gets the #AtspiDocument interface for an #AtspiAccessible.
1441 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1442 * instance, or NULL if @obj does not implement #AtspiDocument.
1444 * Deprecated: 2.10: Use atspi_accessible_get_document_iface instead.
1447 atspi_accessible_get_document (AtspiAccessible *accessible)
1449 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1450 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1454 * atspi_accessible_get_document_iface:
1455 * @obj: a pointer to the #AtspiAccessible instance to query.
1457 * Gets the #AtspiDocument interface for an #AtspiAccessible.
1459 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1460 * instance, or NULL if @obj does not implement #AtspiDocument.
1463 atspi_accessible_get_document_iface (AtspiAccessible *accessible)
1465 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1466 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1470 * atspi_accessible_get_editable_text: (rename-to atspi_accessible_get_editable_text_iface)
1471 * @obj: a pointer to the #AtspiAccessible instance to query.
1473 * Gets the #AtspiEditableText interface for an #AtspiAccessible.
1475 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1476 * instance, or NULL if @obj does not implement #AtspiEditableText.
1478 * Deprecated: 2.10: Use atspi_accessible_get_editable_text_iface instead.
1481 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1483 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1484 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1488 * atspi_accessible_get_editable_text_iface:
1489 * @obj: a pointer to the #AtspiAccessible instance to query.
1491 * Gets the #AtspiEditableText interface for an #AtspiAccessible.
1493 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1494 * instance, or NULL if @obj does not implement #AtspiEditableText.
1497 atspi_accessible_get_editable_text_iface (AtspiAccessible *accessible)
1499 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1500 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1504 * atspi_accessible_get_hyperlink:
1505 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1507 * Gets the #AtspiHyperlink interface for an #AtspiAccessible.
1509 * Returns: (transfer full): the #AtspiHyperlink object associated with
1510 * the given #AtspiAccessible, or NULL if not supported.
1513 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1515 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1516 _atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1520 * atspi_accessible_get_hypertext: (rename-to atspi_accessible_get_hypertext_iface)
1521 * @obj: a pointer to the #AtspiAccessible instance to query.
1523 * Gets the #AtspiHypertext interface for an #AtspiAccessible.
1525 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1526 * instance, or NULL if @obj does not implement #AtspiHypertext.
1528 * Deprecated: 2.10: Use atspi_accessible_get_hypertext_iface instead.
1531 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1533 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1534 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1538 * atspi_accessible_get_hypertext_iface:
1539 * @obj: a pointer to the #AtspiAccessible instance to query.
1541 * Gets the #AtspiHypertext interface for an #AtspiAccessible.
1543 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1544 * instance, or NULL if @obj does not implement #AtspiHypertext.
1547 atspi_accessible_get_hypertext_iface (AtspiAccessible *accessible)
1549 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1550 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1554 * atspi_accessible_get_image: (rename-to atspi_accessible_get_image_iface)
1555 * @obj: a pointer to the #AtspiAccessible instance to query.
1557 * Gets the #AtspiImage interface for an #AtspiAccessible.
1559 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1560 * NULL if @obj does not implement #AtspiImage.
1562 * Deprecated: 2.10: Use atspi_accessible_get_image_iface instead.
1565 atspi_accessible_get_image (AtspiAccessible *accessible)
1567 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1568 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1572 * atspi_accessible_get_image_iface:
1573 * @obj: a pointer to the #AtspiAccessible instance to query.
1575 * Gets the #AtspiImage interface for an #AtspiAccessible.
1577 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1578 * NULL if @obj does not implement #AtspiImage.
1581 atspi_accessible_get_image_iface (AtspiAccessible *accessible)
1583 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1584 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1588 * atspi_accessible_get_selection: (rename-to atspi_accessible_get_selection_iface)
1589 * @obj: a pointer to the #AtspiAccessible instance to query.
1591 * Gets the #AtspiSelection interface for an #AtspiAccessible.
1593 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1594 * instance, or NULL if @obj does not implement #AtspiSelection.
1596 * Deprecated: 2.10: Use atspi_accessible_get_selection_iface instead.
1599 atspi_accessible_get_selection (AtspiAccessible *accessible)
1601 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1602 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1606 * atspi_accessible_get_selection_iface:
1607 * @obj: a pointer to the #AtspiAccessible instance to query.
1609 * Gets the #AtspiSelection interface for an #AtspiAccessible.
1611 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1612 * instance, or NULL if @obj does not implement #AtspiSelection.
1615 atspi_accessible_get_selection_iface (AtspiAccessible *accessible)
1617 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1618 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1623 * atspi_accessible_get_streamable_content:
1624 * @obj: a pointer to the #AtspiAccessible instance to query.
1626 * Gets the #AtspiStreamableContent interface for an #AtspiAccessible.
1628 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1629 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1631 AtspiStreamableContent *
1632 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1634 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1640 * atspi_accessible_get_table: (rename-to atspi_accessible_get_table_iface)
1641 * @obj: a pointer to the #AtspiAccessible instance to query.
1643 * Gets the #AtspiTable interface for an #AtspiAccessible.
1645 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1646 * NULL if @obj does not implement #AtspiTable.
1648 * Deprecated: 2.10: Use atspi_accessible_get_table_iface instead.
1651 atspi_accessible_get_table (AtspiAccessible *obj)
1653 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1654 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1658 * atspi_accessible_get_table_iface:
1659 * @obj: a pointer to the #AtspiAccessible instance to query.
1661 * Gets the #AtspiTable interface for an #AtspiAccessible.
1663 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1664 * NULL if @obj does not implement #AtspiTable.
1667 atspi_accessible_get_table_iface (AtspiAccessible *obj)
1669 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1670 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1674 * atspi_accessible_get_table_cell:
1675 * @obj: a pointer to the #AtspiAccessible instance to query.
1677 * Gets the #AtspiTableCell interface for an #AtspiAccessible.
1679 * Returns: (transfer full): a pointer to an #AtspiTableCell interface instance,
1680 * or NULL if @obj does not implement #AtspiTable.
1683 atspi_accessible_get_table_cell (AtspiAccessible *obj)
1685 return (_atspi_accessible_is_a (obj, atspi_interface_table_cell) ?
1686 g_object_ref (ATSPI_TABLE_CELL (obj)) : NULL);
1690 * atspi_accessible_get_text: (rename-to atspi_accessible_get_text_iface)
1691 * @obj: a pointer to the #AtspiAccessible instance to query.
1693 * Gets the #AtspiTable interface for an #AtspiAccessible.
1695 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1696 * NULL if @obj does not implement #AtspiText.
1698 * Deprecated: 2.10: Use atspi_accessible_get_text_iface instead.
1701 atspi_accessible_get_text (AtspiAccessible *obj)
1703 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1704 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1708 * atspi_accessible_get_text_iface:
1709 * @obj: a pointer to the #AtspiAccessible instance to query.
1711 * Gets the #AtspiTable interface for an #AtspiAccessible.
1713 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1714 * NULL if @obj does not implement #AtspiText.
1717 atspi_accessible_get_text_iface (AtspiAccessible *obj)
1719 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1720 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1724 * atspi_accessible_get_value: (rename-to atspi_accessible_get_value_iface)
1725 * @obj: a pointer to the #AtspiAccessible instance to query.
1727 * Gets the #AtspiTable interface for an #AtspiAccessible.
1729 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1730 * NULL if @obj does not implement #AtspiValue.
1732 * Deprecated: 2.10: Use atspi_accessible_get_value_iface instead.
1735 atspi_accessible_get_value (AtspiAccessible *accessible)
1737 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1738 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1742 * atspi_accessible_get_value_iface:
1743 * @obj: a pointer to the #AtspiAccessible instance to query.
1745 * Gets the #AtspiTable interface for an #AtspiAccessible.
1747 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1748 * NULL if @obj does not implement #AtspiValue.
1751 atspi_accessible_get_value_iface (AtspiAccessible *accessible)
1753 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1754 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1758 append_const_val (GArray *array, const gchar *val)
1760 gchar *dup = g_strdup (val);
1763 g_array_append_val (array, dup);
1767 * atspi_accessible_get_interfaces:
1768 * @obj: The #AtspiAccessible to query.
1770 * A set of pointers to all interfaces supported by an #AtspiAccessible.
1772 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1773 * describing the interfaces supported by the object. Interfaces are
1774 * denoted in short-hand (i.e. "Component", "Text" etc.).
1777 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1779 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1781 g_return_val_if_fail (obj != NULL, NULL);
1783 append_const_val (ret, "Accessible");
1784 if (atspi_accessible_is_action (obj))
1785 append_const_val (ret, "Action");
1786 if (atspi_accessible_is_collection (obj))
1787 append_const_val (ret, "Collection");
1788 if (atspi_accessible_is_component (obj))
1789 append_const_val (ret, "Component");
1790 if (atspi_accessible_is_document (obj))
1791 append_const_val (ret, "Document");
1792 if (atspi_accessible_is_editable_text (obj))
1793 append_const_val (ret, "EditableText");
1794 if (atspi_accessible_is_hypertext (obj))
1795 append_const_val (ret, "Hypertext");
1796 if (atspi_accessible_is_hyperlink (obj))
1797 append_const_val (ret, "Hyperlink");
1798 if (atspi_accessible_is_image (obj))
1799 append_const_val (ret, "Image");
1800 if (atspi_accessible_is_selection (obj))
1801 append_const_val (ret, "Selection");
1802 if (atspi_accessible_is_table (obj))
1803 append_const_val (ret, "Table");
1804 if (atspi_accessible_is_table_cell (obj))
1805 append_const_val (ret, "TableCell");
1806 if (atspi_accessible_is_text (obj))
1807 append_const_val (ret, "Text");
1808 if (atspi_accessible_is_value (obj))
1809 append_const_val (ret, "Value");
1815 _atspi_accessible_new (AtspiApplication *app, const gchar *path)
1817 AtspiAccessible *accessible;
1819 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1820 g_return_val_if_fail (accessible != NULL, NULL);
1822 accessible->parent.app = g_object_ref (app);
1823 accessible->parent.path = g_strdup (path);
1829 * atspi_accessible_set_cache_mask:
1830 * @accessible: The #AtspiAccessible to operate on. Must be the desktop or
1831 * the root of an application.
1832 * @mask: An #AtspiCache specifying a bit mask of the types of data to cache.
1834 * Sets the type of data to cache for accessibles.
1835 * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
1836 * then the desktop's cache flag will be used.
1837 * If the desktop's cache flag is also undefined, then all possible data will
1839 * This function is intended to work around bugs in toolkits where the proper
1840 * events are not raised / to aid in testing for such bugs.
1843 atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
1845 g_return_if_fail (accessible != NULL);
1846 g_return_if_fail (accessible->parent.app != NULL);
1847 g_return_if_fail (accessible == accessible->parent.app->root);
1848 accessible->parent.app->cache = mask;
1849 enable_caching = TRUE;
1853 * atspi_accessible_clear_cache:
1854 * @accessible: The #AtspiAccessible whose cache to clear.
1856 * Clears the cached information for the given accessible and all of its
1860 atspi_accessible_clear_cache (AtspiAccessible *accessible)
1866 accessible->cached_properties = ATSPI_CACHE_NONE;
1867 for (l = accessible->children; l; l = l->next)
1868 atspi_accessible_clear_cache (l->data);
1873 * atspi_accessible_get_process_id:
1874 * @accessible: The #AtspiAccessible to query.
1875 * @error: a pointer to a %NULL #GError pointer
1877 * Returns the process id associated with the given accessible. Mainly
1878 * added for debugging; it is a shortcut to explicitly querying the
1879 * accessible's app->bus_name and then calling GetConnectionUnixProcessID.
1881 * Returns: The process ID or undetermined value if @error is set.
1884 atspi_accessible_get_process_id (AtspiAccessible *accessible, GError **error)
1886 DBusMessage *message, *reply;
1887 DBusConnection *bus = _atspi_bus ();
1888 dbus_uint32_t pid = -1;
1891 if (!accessible->parent.app || !accessible->parent.app->bus_name)
1893 g_set_error_literal(error, ATSPI_ERROR, ATSPI_ERROR_IPC, "Process is defunct");
1897 message = dbus_message_new_method_call ("org.freedesktop.DBus",
1898 "/org/freedesktop/DBus",
1899 "org.freedesktop.DBus",
1900 "GetConnectionUnixProcessID");
1901 dbus_message_append_args (message, DBUS_TYPE_STRING,
1902 &accessible->parent.app->bus_name,
1904 dbus_error_init (&d_error);
1905 reply = dbus_connection_send_with_reply_and_block (bus, message, -1, &d_error);
1906 dbus_message_unref (message);
1909 if (!strcmp (dbus_message_get_signature (reply), "u"))
1910 dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &pid, DBUS_TYPE_INVALID);
1911 dbus_message_unref (reply);
1913 if (dbus_error_is_set (&d_error))
1915 g_set_error_literal(error, ATSPI_ERROR, ATSPI_ERROR_IPC, "Process is defunct");
1916 dbus_error_free (&d_error);
1922 _atspi_accessible_get_cache_mask (AtspiAccessible *accessible)
1926 if (!accessible->parent.app)
1927 return ATSPI_CACHE_NONE;
1929 mask = accessible->parent.app->cache;
1930 if (mask == ATSPI_CACHE_UNDEFINED &&
1931 accessible->parent.app->root &&
1932 accessible->parent.app->root->accessible_parent)
1934 AtspiAccessible *desktop = atspi_get_desktop (0);
1935 mask = desktop->parent.app->cache;
1936 g_object_unref (desktop);
1939 if (mask == ATSPI_CACHE_UNDEFINED)
1940 mask = ATSPI_CACHE_DEFAULT;
1946 _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
1948 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1949 AtspiCache result = accessible->cached_properties & mask & flag;
1950 if (accessible->states && atspi_state_set_contains (accessible->states, ATSPI_STATE_TRANSIENT))
1952 return (result != 0 && (atspi_main_loop || enable_caching ||
1953 flag == ATSPI_CACHE_INTERFACES) &&
1958 _atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
1960 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1962 accessible->cached_properties |= flag & mask;
1966 * atspi_accessible_get_locale:
1967 * @accessible: an #AtspiAccessible
1969 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
1974 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
1975 * locale of @accessible.
1978 atspi_accessible_get_object_locale (AtspiAccessible *accessible, GError **error)
1982 g_return_val_if_fail (accessible != NULL, NULL);
1984 locale = g_object_get_qdata (G_OBJECT (accessible), quark_locale);
1987 if (!_atspi_dbus_get_property (accessible, atspi_interface_accessible,
1988 "Locale", error, "s", &locale))
1991 g_object_set_qdata_full (G_OBJECT (accessible), quark_locale, locale,
1998 free_value (gpointer data)
2000 GValue *value = data;
2002 g_value_unset (value);
2007 _atspi_accessible_ref_cache (AtspiAccessible *accessible)
2009 AtspiAccessiblePrivate *priv = accessible->priv;
2011 priv->cache_ref_count++;
2013 return g_hash_table_ref (priv->cache);
2014 priv->cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2020 _atspi_accessible_unref_cache (AtspiAccessible *accessible)
2022 AtspiAccessiblePrivate *priv = accessible->priv;
2026 g_hash_table_unref (priv->cache);
2027 if (--priv->cache_ref_count == 0)