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"
28 static gboolean enable_caching = FALSE;
29 static guint quark_locale;
32 atspi_action_interface_init (AtspiAction *action)
37 atspi_collection_interface_init (AtspiCollection *component)
42 atspi_component_interface_init (AtspiComponent *component)
47 atspi_document_interface_init (AtspiDocument *document)
52 atspi_editable_text_interface_init (AtspiEditableText *editable_text)
57 atspi_hypertext_interface_init (AtspiHypertext *hypertext)
62 atspi_image_interface_init (AtspiImage *image)
67 atspi_selection_interface_init (AtspiSelection *selection)
72 atspi_table_interface_init (AtspiTable *table)
77 atspi_text_interface_init (AtspiText *text)
82 atspi_value_interface_init (AtspiValue *value)
86 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT,
87 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init)
88 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COLLECTION, atspi_collection_interface_init)
89 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
90 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_DOCUMENT, atspi_document_interface_init)
91 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init)
92 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_HYPERTEXT, atspi_hypertext_interface_init)
93 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init)
94 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init)
95 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
96 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init)
97 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_VALUE, atspi_value_interface_init))
99 #ifdef DEBUG_REF_COUNTS
100 static gint accessible_count = 0;
104 atspi_accessible_init (AtspiAccessible *accessible)
106 #ifdef DEBUG_REF_COUNTS
108 g_hash_table_insert (_atspi_get_live_refs (), accessible, NULL);
109 g_print("at-spi: init: %d objects\n", accessible_count);
114 atspi_accessible_dispose (GObject *object)
116 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
118 AtspiAccessible *parent;
122 /* TODO: Only fire if object not already marked defunct */
123 memset (&e, 0, sizeof (e));
124 e.type = "object:state-changed:defunct";
125 e.source = accessible;
128 _atspi_send_event (&e);
130 if (accessible->states)
132 g_object_unref (accessible->states);
133 accessible->states = NULL;
136 parent = accessible->accessible_parent;
137 if (parent && parent->children)
139 GList*ls = g_list_find (parent->children, accessible);
142 gboolean replace = (ls == parent->children);
143 ls = g_list_remove (ls, accessible);
145 parent->children = ls;
146 g_object_unref (object);
152 g_object_unref (parent);
153 accessible->accessible_parent = NULL;
156 children = accessible->children;
157 accessible->children = NULL;
158 for (l = children; l; l = l->next)
160 AtspiAccessible *child = l->data;
161 if (child && child->accessible_parent == accessible)
163 g_object_unref (accessible);
164 child->accessible_parent = NULL;
166 g_object_unref (child);
168 g_list_free (children);
170 G_OBJECT_CLASS (atspi_accessible_parent_class) ->dispose (object);
174 atspi_accessible_finalize (GObject *object)
176 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
178 g_free (accessible->description);
179 g_free (accessible->name);
180 if (accessible->attributes)
181 g_hash_table_unref (accessible->attributes);
183 #ifdef DEBUG_REF_COUNTS
185 g_hash_table_remove (_atspi_get_live_refs (), accessible);
186 g_print ("at-spi: finalize: %d objects\n", accessible_count);
189 G_OBJECT_CLASS (atspi_accessible_parent_class)
194 atspi_accessible_class_init (AtspiAccessibleClass *klass)
196 GObjectClass *object_class = G_OBJECT_CLASS (klass);
198 object_class->dispose = atspi_accessible_dispose;
199 object_class->finalize = atspi_accessible_finalize;
201 quark_locale = g_quark_from_string ("accessible-locale");
204 /* TODO: Generate following from spec? */
205 static const char *role_names [] =
264 "table column header",
266 "tear off menu item",
285 "embedded component",
296 "input method window",
299 "document spreadsheet",
300 "document presentation",
313 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
316 * atspi_role_get_name:
317 * @role: an #AtspiRole object to query.
319 * Gets a localizable string that indicates the name of an #AtspiRole.
320 * <em>DEPRECATED.</em>
322 * Returns: a localizable string name for an #AtspiRole enumerated type.
325 atspi_role_get_name (AtspiRole role)
327 if (role < MAX_ROLES && role_names [(int) role])
329 return g_strdup (role_names [(int) role]);
333 return g_strdup ("");
338 * atspi_accessible_get_name:
339 * @obj: a pointer to the #AtspiAccessible object on which to operate.
341 * Gets the name of an #AtspiAccessible object.
343 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object
344 * or NULL on exception.
347 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
349 g_return_val_if_fail (obj != NULL, g_strdup (""));
350 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_NAME))
352 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
354 return g_strdup ("");
355 _atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
357 return g_strdup (obj->name);
361 * atspi_accessible_get_description:
362 * @obj: a pointer to the #AtspiAccessible object on which to operate.
364 * Gets the description of an #AtspiAccessible object.
366 * Returns: a UTF-8 string describing the #AtspiAccessible object
367 * or NULL on exception.
370 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
372 g_return_val_if_fail (obj != NULL, g_strdup (""));
374 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_DESCRIPTION))
376 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
377 "Description", error, "s",
379 return g_strdup ("");
380 _atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
382 return g_strdup (obj->description);
385 const char *str_parent = "Parent";
388 * atspi_accessible_get_parent:
389 * @obj: a pointer to the #AtspiAccessible object to query.
391 * Gets an #AtspiAccessible object's parent container.
393 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
394 * contains the given #AtspiAccessible instance, or NULL if the @obj
395 * has no parent container.
399 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
401 g_return_val_if_fail (obj != NULL, NULL);
403 if (obj->parent.app &&
404 !_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
406 DBusMessage *message, *reply;
407 DBusMessageIter iter, iter_variant;
408 message = dbus_message_new_method_call (obj->parent.app->bus_name,
410 DBUS_INTERFACE_PROPERTIES, "Get");
413 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
414 DBUS_TYPE_STRING, &str_parent,
416 reply = _atspi_dbus_send_with_reply_and_block (message, error);
419 if (strcmp (dbus_message_get_signature (reply), "v") != 0)
421 dbus_message_unref (reply);
424 dbus_message_iter_init (reply, &iter);
425 dbus_message_iter_recurse (&iter, &iter_variant);
426 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
427 dbus_message_unref (reply);
428 _atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
430 if (!obj->accessible_parent)
432 return g_object_ref (obj->accessible_parent);
436 * atspi_accessible_get_child_count:
437 * @obj: a pointer to the #AtspiAccessible object on which to operate.
439 * Gets the number of children contained by an #AtspiAccessible object.
441 * Returns: a #long indicating the number of #AtspiAccessible children
442 * contained by an #AtspiAccessible object or -1 on exception.
446 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
448 g_return_val_if_fail (obj != NULL, -1);
450 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
453 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
454 "ChildCount", error, "i", &ret))
459 return g_list_length (obj->children);
463 * atspi_accessible_get_child_at_index:
464 * @obj: a pointer to the #AtspiAccessible object on which to operate.
465 * @child_index: a #long indicating which child is specified.
467 * Gets the #AtspiAccessible child of an #AtspiAccessible object at a given index.
469 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
470 * index @child_index or NULL on exception.
473 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
477 AtspiAccessible *child;
479 g_return_val_if_fail (obj != NULL, NULL);
481 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
484 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
485 "GetChildAtIndex", error, "i",
487 return _atspi_dbus_return_accessible_from_message (reply);
490 child = g_list_nth_data (obj->children, child_index);
493 return g_object_ref (child);
497 * atspi_accessible_get_index_in_parent:
498 * @obj: a pointer to the #AtspiAccessible object on which to operate.
500 * Gets the index of an #AtspiAccessible object within its parent's
501 * #AtspiAccessible children list.
503 * Returns: a #glong indicating the index of the #AtspiAccessible object
505 * or -1 if @obj has no containing parent or on exception.
508 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
513 g_return_val_if_fail (obj != NULL, -1);
514 if (_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT) &&
515 !obj->accessible_parent)
517 if (!obj->accessible_parent ||
518 !_atspi_accessible_test_cache (obj->accessible_parent,
519 ATSPI_CACHE_CHILDREN))
521 dbus_int32_t ret = -1;
522 _atspi_dbus_call (obj, atspi_interface_accessible,
523 "GetIndexInParent", NULL, "=>i", &ret);
527 l = obj->accessible_parent->children;
530 if (l->data == obj) return i;
541 } Accessibility_Relation;
544 * atspi_accessible_get_relation_set:
545 * @obj: a pointer to the #AtspiAccessible object on which to operate.
547 * Gets the set of #AtspiRelation objects which describes this #AtspiAccessible object's
548 * relationships with other #AtspiAccessible objects.
550 * Returns: (element-type AtspiAccessible*) (transfer full): a #GArray of
551 * #AtspiRelation pointers or NULL on exception.
554 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
557 DBusMessageIter iter, iter_array;
560 g_return_val_if_fail (obj != NULL, NULL);
562 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
565 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
567 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
568 dbus_message_iter_init (reply, &iter);
569 dbus_message_iter_recurse (&iter, &iter_array);
570 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
572 AtspiRelation *relation;
573 relation = _atspi_relation_new_from_iter (&iter_array);
574 ret = g_array_append_val (ret, relation);
575 dbus_message_iter_next (&iter_array);
577 dbus_message_unref (reply);
582 * atspi_accessible_get_role:
583 * @obj: a pointer to the #AtspiAccessible object on which to operate.
585 * Gets the UI role played by an #AtspiAccessible object.
586 * This role's name can be obtained via atspi_accessible_get_role_name ().
588 * Returns: the #AtspiRole of an #AtspiAccessible object.
592 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
594 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
596 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ROLE))
599 /* TODO: Make this a property */
600 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
603 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
610 * atspi_accessible_get_role_name:
611 * @obj: a pointer to the #AtspiAccessible object on which to operate.
613 * Gets a UTF-8 string corresponding to the name of the role played by an object.
614 * This method will return useful values for roles that fall outside the
615 * enumeration used in atspi_accessible_get_role ().
617 * Returns: a UTF-8 string specifying the type of UI role played by an
618 * #AtspiAccessible object.
622 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
627 g_return_val_if_fail (obj != NULL, NULL);
629 role = atspi_accessible_get_role (obj, error);
630 if (role >= 0 && role < MAX_ROLES && role != ATSPI_ROLE_EXTENDED)
631 return g_strdup (role_names [role]);
633 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
636 retval = g_strdup ("");
642 * atspi_accessible_get_localized_role_name:
643 * @obj: a pointer to the #AtspiAccessible object on which to operate.
645 * Gets a UTF-8 string corresponding to the name of the role played by an
646 * object, translated to the current locale.
647 * This method will return useful values for roles that fall outside the
648 * enumeration used in atspi_accessible_getRole ().
650 * Returns: a localized, UTF-8 string specifying the type of UI role played
651 * by an #AtspiAccessible object.
655 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
659 g_return_val_if_fail (obj != NULL, NULL);
661 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
664 return g_strdup ("");
669 static AtspiStateSet *
672 AtspiStateSet *set = atspi_state_set_new (NULL);
673 atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
678 * atspi_accessible_get_state_set:
679 * @obj: a pointer to the #AtspiAccessible object on which to operate.
681 * Gets the states currently held by an object.
683 * Returns: (transfer full): a pointer to an #AtspiStateSet representing an
684 * object's current state set.
687 atspi_accessible_get_state_set (AtspiAccessible *obj)
689 /* TODO: Should take a GError **, but would be an API break */
690 if (!obj->parent.app || !obj->parent.app->bus)
691 return defunct_set ();
693 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
696 DBusMessageIter iter;
697 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
698 "GetState", NULL, "");
699 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
700 dbus_message_iter_init (reply, &iter);
701 _atspi_dbus_set_state (obj, &iter);
702 dbus_message_unref (reply);
703 _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
706 return g_object_ref (obj->states);
710 * atspi_accessible_get_attributes:
711 * @obj: The #AtspiAccessible being queried.
713 * Gets the #AttributeSet representing any assigned
714 * name-value pair attributes or annotations for this object.
715 * For typographic, textual, or textually-semantic attributes, see
716 * atspi_text_get_attributes instead.
718 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
719 * attributes assigned to this object.
722 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
724 DBusMessage *message;
726 g_return_val_if_fail (obj != NULL, NULL);
728 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ATTRIBUTES))
730 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
731 "GetAttributes", error, "");
732 obj->attributes = _atspi_dbus_return_hash_from_message (message);
733 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ATTRIBUTES);
736 if (!obj->attributes)
738 return g_hash_table_ref (obj->attributes);
742 add_to_attribute_array (gpointer key, gpointer value, gpointer data)
744 GArray **array = (GArray **)data;
745 gchar *str = g_strconcat (key, ":", value, NULL);
746 *array = g_array_append_val (*array, str);
750 * atspi_accessible_get_attributes_as_array:
751 * @obj: The #AtspiAccessible being queried.
753 * Gets a #GArray representing any assigned
754 * name-value pair attributes or annotations for this object.
755 * For typographic, textual, or textually-semantic attributes, see
756 * atspi_text_get_attributes_as_array instead.
758 * Returns: (element-type gchar*) (transfer full): The name-value-pair
759 * attributes assigned to this object.
762 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
764 DBusMessage *message;
766 g_return_val_if_fail (obj != NULL, NULL);
768 if (_atspi_accessible_get_cache_mask (obj) & ATSPI_CACHE_ATTRIBUTES)
770 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
771 GHashTable *attributes = atspi_accessible_get_attributes (obj, error);
774 g_hash_table_foreach (attributes, add_to_attribute_array, &array);
775 g_hash_table_unref (attributes);
779 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
780 return _atspi_dbus_return_attribute_array_from_message (message);
784 * atspi_accessible_get_application:
785 * @obj: The #AtspiAccessible being queried.
787 * Gets the containing #AtspiApplication for an object.
789 * Returns: (transfer full): the containing #AtspiApplication instance for
793 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
795 AtspiAccessible *parent;
800 parent = atspi_accessible_get_parent (obj, NULL);
801 if (!parent && obj->parent.app &&
802 atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
804 AtspiAccessible *root = g_object_ref (obj->parent.app->root);
807 g_object_unref (obj);
808 g_object_unref (parent);
809 if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
811 g_object_unref (root);
817 if (!parent || parent == obj ||
818 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
821 g_object_unref (parent);
824 g_object_unref (obj);
829 /* Application-specific methods */
832 * atspi_accessible_get_toolkit_name:
833 * @obj: a pointer to the #AtspiAccessible object on which to operate.
835 * Gets the toolkit name for an #AtspiAccessible object.
836 * Only works on application root objects.
838 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object or NULL on exception.
841 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
843 g_return_val_if_fail (obj != NULL, NULL);
845 if (!obj->parent.app)
848 if (!obj->parent.app->toolkit_name)
849 _atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName",
850 error, "s", &obj->parent.app->toolkit_name);
852 return g_strdup (obj->parent.app->toolkit_name);
856 * atspi_accessible_get_toolkit_version:
857 * @obj: a pointer to the #AtspiAccessible object on which to operate.
859 * Gets the toolkit version for an #AtspiAccessible object.
860 * Only works on application root objects.
862 * Returns: a UTF-8 string indicating the toolkit version for the #AtspiAccessible object or NULL on exception.
865 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
867 g_return_val_if_fail (obj != NULL, NULL);
869 if (!obj->parent.app)
872 if (!obj->parent.app->toolkit_version)
873 _atspi_dbus_get_property (obj, atspi_interface_application, "Version",
874 error, "s", &obj->parent.app->toolkit_version);
876 return g_strdup (obj->parent.app->toolkit_version);
880 * atspi_accessible_get_atspi_version:
881 * @obj: a pointer to the #AtspiAccessible object on which to operate.
883 * Gets the AT-SPI IPC specification version supported by the application
884 * pointed to by the #AtspiAccessible object.
885 * Only works on application root objects.
887 * Returns: a UTF-8 string indicating the AT-SPI version for the #AtspiAccessible object or NULL on exception.
890 atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
892 g_return_val_if_fail (obj != NULL, NULL);
894 if (!obj->parent.app)
897 if (!obj->parent.app->atspi_version)
898 _atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion",
899 error, "s", &obj->parent.app->atspi_version);
901 return g_strdup (obj->parent.app->atspi_version);
905 * atspi_accessible_get_id:
906 * @obj: a pointer to the #AtspiAccessible object on which to operate.
908 * Gets the application id for a #AtspiAccessible object.
909 * Only works on application root objects.
911 * Returns: a positive #gint indicating the id for the #AtspiAccessible object
912 * or -1 on exception.
915 atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
919 g_return_val_if_fail (obj != NULL, -1);
921 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
927 /* Interface query methods */
930 _atspi_accessible_is_a (AtspiAccessible *accessible,
931 const char *interface_name)
935 if (accessible == NULL)
940 if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
943 DBusMessageIter iter;
944 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
945 "GetInterfaces", NULL, "");
946 _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
947 dbus_message_iter_init (reply, &iter);
948 _atspi_dbus_set_interfaces (accessible, &iter);
949 dbus_message_unref (reply);
950 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
953 n = _atspi_get_iface_num (interface_name);
954 if (n == -1) return FALSE;
955 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
959 * atspi_accessible_is_action:
960 * @obj: a pointer to the #AtspiAccessible instance to query.
962 * Query whether the specified #AtspiAccessible implements the
963 * #AtspiAction interface.
965 * Returns: #TRUE if @obj implements the #AtspiAction interface,
969 atspi_accessible_is_action (AtspiAccessible *obj)
971 return _atspi_accessible_is_a (obj,
972 atspi_interface_action);
976 * atspi_accessible_is_application:
977 * @obj: a pointer to the #AtspiAccessible instance to query.
979 * Query whether the specified #AtspiAccessible implements the
980 * #AtspiApplication interface.
982 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
986 atspi_accessible_is_application (AtspiAccessible *obj)
988 return _atspi_accessible_is_a (obj,
989 atspi_interface_application);
993 * atspi_accessible_is_collection:
994 * @obj: a pointer to the #AtspiAccessible instance to query.
996 * Query whether the specified #AtspiAccessible implements the
997 * #AtspiCollection interface.
999 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
1003 atspi_accessible_is_collection (AtspiAccessible *obj)
1005 return _atspi_accessible_is_a (obj,
1006 atspi_interface_collection);
1010 * atspi_accessible_is_component:
1011 * @obj: a pointer to the #AtspiAccessible instance to query.
1013 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
1015 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
1019 atspi_accessible_is_component (AtspiAccessible *obj)
1021 return _atspi_accessible_is_a (obj,
1022 atspi_interface_component);
1026 * atspi_accessible_is_document:
1027 * @obj: a pointer to the #AtspiAccessible instance to query.
1029 * Query whether the specified #AtspiAccessible implements the
1030 * #AtspiDocument interface.
1032 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
1036 atspi_accessible_is_document (AtspiAccessible *obj)
1038 return _atspi_accessible_is_a (obj,
1039 atspi_interface_document);
1043 * atspi_accessible_is_editable_text:
1044 * @obj: a pointer to the #AtspiAccessible instance to query.
1046 * Query whether the specified #AtspiAccessible implements the
1047 * #AtspiEditableText interface.
1049 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
1053 atspi_accessible_is_editable_text (AtspiAccessible *obj)
1055 return _atspi_accessible_is_a (obj,
1056 atspi_interface_editable_text);
1060 * atspi_accessible_is_hypertext:
1061 * @obj: a pointer to the #AtspiAccessible instance to query.
1063 * Query whether the specified #AtspiAccessible implements the
1064 * #AtspiHypertext interface.
1066 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1070 atspi_accessible_is_hypertext (AtspiAccessible *obj)
1072 return _atspi_accessible_is_a (obj,
1073 atspi_interface_hypertext);
1077 * atspi_accessible_is_hyperlink:
1078 * @obj: a pointer to the #AtspiAccessible instance to query.
1080 * Query whether the specified #AtspiAccessible implements the
1081 * #AtspiHyperlink interface.
1083 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1087 atspi_accessible_is_hyperlink (AtspiAccessible *obj)
1089 return _atspi_accessible_is_a (obj,
1090 atspi_interface_hyperlink);
1094 * atspi_accessible_is_image:
1095 * @obj: a pointer to the #AtspiAccessible instance to query.
1097 * Query whether the specified #AtspiAccessible implements the
1098 * #AtspiImage interface.
1100 * Returns: #TRUE if @obj implements the #AtspiImage interface,
1104 atspi_accessible_is_image (AtspiAccessible *obj)
1106 return _atspi_accessible_is_a (obj,
1107 atspi_interface_image);
1111 * atspi_accessible_is_selection:
1112 * @obj: a pointer to the #AtspiAccessible instance to query.
1114 * Query whether the specified #AtspiAccessible implements the
1115 * #AtspiSelection interface.
1117 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
1121 atspi_accessible_is_selection (AtspiAccessible *obj)
1123 return _atspi_accessible_is_a (obj,
1124 atspi_interface_selection);
1128 * atspi_accessible_is_table:
1129 * @obj: a pointer to the #AtspiAccessible instance to query.
1131 * Query whether the specified #AtspiAccessible implements the
1132 * #AtspiTable interface.
1134 * Returns: #TRUE if @obj implements the #AtspiTable interface,
1138 atspi_accessible_is_table (AtspiAccessible *obj)
1140 return _atspi_accessible_is_a (obj,
1141 atspi_interface_table);
1145 * atspi_accessible_is_streamable_content:
1146 * @obj: a pointer to the #AtspiAccessible instance to query.
1148 * Query whether the specified #AtspiAccessible implements the
1149 * #AtspiStreamableContent interface.
1151 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
1155 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
1158 return _atspi_accessible_is_a (obj,
1159 atspi_interface_streamable_content);
1161 g_warning ("Streamable content not implemented");
1167 * atspi_accessible_is_text:
1168 * @obj: a pointer to the #AtspiAccessible instance to query.
1170 * Query whether the specified #AtspiAccessible implements the
1171 * #AtspiText interface.
1173 * Returns: #TRUE if @obj implements the #AtspiText interface,
1177 atspi_accessible_is_text (AtspiAccessible *obj)
1179 return _atspi_accessible_is_a (obj,
1180 atspi_interface_text);
1184 * atspi_accessible_is_value:
1185 * @obj: a pointer to the #AtspiAccessible instance to query.
1187 * Query whether the specified #AtspiAccessible implements the
1188 * #AtspiValue interface.
1190 * Returns: #TRUE if @obj implements the #AtspiValue interface,
1194 atspi_accessible_is_value (AtspiAccessible *obj)
1196 return _atspi_accessible_is_a (obj,
1197 atspi_interface_value);
1201 * atspi_accessible_get_action:
1202 * @obj: a pointer to the #AtspiAccessible instance to query.
1204 * Gets the #AtspiAction interface for an #AtspiAccessible.
1206 * Returns: (transfer full): a pointer to an #AtspiAction interface
1207 * instance, or NULL if @obj does not implement #AtspiAction.
1210 atspi_accessible_get_action (AtspiAccessible *accessible)
1212 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1213 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1217 * atspi_accessible_get_collection:
1218 * @obj: a pointer to the #AtspiAccessible instance to query.
1220 * Gets the #AtspiCollection interface for an #AtspiAccessible.
1222 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1223 * instance, or NULL if @obj does not implement #AtspiCollection.
1226 atspi_accessible_get_collection (AtspiAccessible *accessible)
1228 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1229 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1233 * atspi_accessible_get_component:
1234 * @obj: a pointer to the #AtspiAccessible instance to query.
1236 * Gets the #AtspiComponent interface for an #AtspiAccessible.
1238 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1239 * instance, or NULL if @obj does not implement #AtspiComponent.
1242 atspi_accessible_get_component (AtspiAccessible *obj)
1244 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1245 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1249 * atspi_accessible_get_document:
1250 * @obj: a pointer to the #AtspiAccessible instance to query.
1252 * Gets the #AtspiDocument interface for an #AtspiAccessible.
1254 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1255 * instance, or NULL if @obj does not implement #AtspiDocument.
1258 atspi_accessible_get_document (AtspiAccessible *accessible)
1260 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1261 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1265 * atspi_accessible_get_editable_text:
1266 * @obj: a pointer to the #AtspiAccessible instance to query.
1268 * Gets the #AtspiEditableText interface for an #AtspiAccessible.
1270 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1271 * instance, or NULL if @obj does not implement #AtspiEditableText.
1274 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1276 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1277 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1281 * atspi_accessible_get_hyperlink:
1282 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1284 * Gets the #AtspiHyperlink interface for an #AtspiAccessible.
1286 * Returns: (transfer full): the #AtspiHyperlink object associated with
1287 * the given #AtspiAccessible, or NULL if not supported.
1290 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1292 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1293 _atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1297 * atspi_accessible_get_hypertext:
1298 * @obj: a pointer to the #AtspiAccessible instance to query.
1300 * Gets the #AtspiHypertext interface for an #AtspiAccessible.
1302 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1303 * instance, or NULL if @obj does not implement #AtspiHypertext.
1306 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1308 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1309 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1313 * atspi_accessible_get_image:
1314 * @obj: a pointer to the #AtspiAccessible instance to query.
1316 * Gets the #AtspiImage interface for an #AtspiAccessible.
1318 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1319 * NULL if @obj does not implement #AtspiImage.
1322 atspi_accessible_get_image (AtspiAccessible *accessible)
1324 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1325 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1329 * atspi_accessible_get_selection:
1330 * @obj: a pointer to the #AtspiAccessible instance to query.
1332 * Gets the #AtspiSelection interface for an #AtspiAccessible.
1334 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1335 * instance, or NULL if @obj does not implement #AtspiSelection.
1338 atspi_accessible_get_selection (AtspiAccessible *accessible)
1340 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1341 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1346 * atspi_accessible_get_streamable_content:
1347 * @obj: a pointer to the #AtspiAccessible instance to query.
1349 * Gets the #AtspiStreamableContent interface for an #AtspiAccessible.
1351 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1352 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1354 AtspiStreamableContent *
1355 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1357 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1363 * atspi_accessible_get_table:
1364 * @obj: a pointer to the #AtspiAccessible instance to query.
1366 * Gets the #AtspiTable interface for an #AtspiAccessible.
1368 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1369 * NULL if @obj does not implement #AtspiTable.
1372 atspi_accessible_get_table (AtspiAccessible *obj)
1374 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1375 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1379 * atspi_accessible_get_text:
1380 * @obj: a pointer to the #AtspiAccessible instance to query.
1382 * Gets the #AtspiTable interface for an #AtspiAccessible.
1384 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1385 * NULL if @obj does not implement #AtspiText.
1388 atspi_accessible_get_text (AtspiAccessible *obj)
1390 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1391 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1395 * atspi_accessible_get_value:
1396 * @obj: a pointer to the #AtspiAccessible instance to query.
1398 * Gets the #AtspiTable interface for an #AtspiAccessible.
1400 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1401 * NULL if @obj does not implement #AtspiValue.
1404 atspi_accessible_get_value (AtspiAccessible *accessible)
1406 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1407 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1411 append_const_val (GArray *array, const gchar *val)
1413 gchar *dup = g_strdup (val);
1416 g_array_append_val (array, dup);
1420 * atspi_accessible_get_interfaces:
1421 * @obj: The #AtspiAccessible to query.
1423 * A set of pointers to all interfaces supported by an #AtspiAccessible.
1425 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1426 * describing the interfaces supported by the object. Interfaces are
1427 * denoted in short-hand (i.e. "Component", "Text" etc.).
1430 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1432 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1434 g_return_val_if_fail (obj != NULL, NULL);
1436 append_const_val (ret, "Accessible");
1437 if (atspi_accessible_is_action (obj))
1438 append_const_val (ret, "Action");
1439 if (atspi_accessible_is_collection (obj))
1440 append_const_val (ret, "Collection");
1441 if (atspi_accessible_is_component (obj))
1442 append_const_val (ret, "Component");
1443 if (atspi_accessible_is_document (obj))
1444 append_const_val (ret, "Document");
1445 if (atspi_accessible_is_editable_text (obj))
1446 append_const_val (ret, "EditableText");
1447 if (atspi_accessible_is_hypertext (obj))
1448 append_const_val (ret, "Hypertext");
1449 if (atspi_accessible_is_hyperlink (obj))
1450 append_const_val (ret, "Hyperlink");
1451 if (atspi_accessible_is_image (obj))
1452 append_const_val (ret, "Image");
1453 if (atspi_accessible_is_selection (obj))
1454 append_const_val (ret, "Selection");
1455 if (atspi_accessible_is_table (obj))
1456 append_const_val (ret, "Table");
1457 if (atspi_accessible_is_text (obj))
1458 append_const_val (ret, "Text");
1459 if (atspi_accessible_is_value (obj))
1460 append_const_val (ret, "Value");
1466 _atspi_accessible_new (AtspiApplication *app, const gchar *path)
1468 AtspiAccessible *accessible;
1470 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1471 g_return_val_if_fail (accessible != NULL, NULL);
1473 accessible->parent.app = g_object_ref (app);
1474 accessible->parent.path = g_strdup (path);
1480 * atspi_accessible_set_cache_mask:
1481 * @accessible: The #AtspiAccessible to operate on. Must be the desktop or
1482 * the root of an application.
1483 * @mask: (type int): An #AtspiCache specifying a bit mask of the types of data to cache.
1485 * Sets the type of data to cache for accessibles.
1486 * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
1487 * then the desktop's cache flag will be used.
1488 * If the desktop's cache flag is also undefined, then all possible data will
1490 * This function is intended to work around bugs in toolkits where the proper
1491 * events are not raised / to aid in testing for such bugs.
1494 atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
1496 g_return_if_fail (accessible != NULL);
1497 g_return_if_fail (accessible->parent.app != NULL);
1498 g_return_if_fail (accessible == accessible->parent.app->root);
1499 accessible->parent.app->cache = mask;
1500 enable_caching = TRUE;
1504 * atspi_accessible_clear_cache:
1505 * @accessible: The #AtspiAccessible whose cache to clear.
1507 * Clears the cached information for the given accessible and all of its
1511 atspi_accessible_clear_cache (AtspiAccessible *accessible)
1517 accessible->cached_properties = ATSPI_CACHE_NONE;
1518 for (l = accessible->children; l; l = l->next)
1519 atspi_accessible_clear_cache (l->data);
1524 * atspi_accessible_get_process_id:
1525 * @accessible: The #AtspiAccessible to query.
1527 * Returns the process id associated with the given accessible. Mainly
1528 * added for debugging; it is a shortcut to explicitly querying the
1529 * accessible's app->bus_name and then calling GetConnectionUnixProcessID.
1531 * Returns: The process ID, or -1 if defunct.
1534 atspi_accessible_get_process_id (AtspiAccessible *accessible, GError **error)
1536 DBusMessage *message, *reply;
1537 DBusConnection *bus = _atspi_bus ();
1538 dbus_uint32_t pid = -1;
1541 if (!accessible->parent.app || !accessible->parent.app->bus_name)
1544 message = dbus_message_new_method_call ("org.freedesktop.DBus",
1545 "/org/freedesktop/DBus",
1546 "org.freedesktop.DBus",
1547 "GetConnectionUnixProcessID");
1548 dbus_message_append_args (message, DBUS_TYPE_STRING,
1549 &accessible->parent.app->bus_name,
1551 dbus_error_init (&d_error);
1552 reply = dbus_connection_send_with_reply_and_block (bus, message, -1, &d_error);
1553 dbus_message_unref (message);
1554 dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &pid, DBUS_TYPE_INVALID);
1555 dbus_message_unref (reply);
1556 if (dbus_error_is_set (&d_error))
1558 g_warning ("GetConnectionUnixProcessID failed: %s", d_error.message);
1559 dbus_error_free (&d_error);
1565 _atspi_accessible_get_cache_mask (AtspiAccessible *accessible)
1569 if (!accessible->parent.app)
1570 return ATSPI_CACHE_NONE;
1572 mask = accessible->parent.app->cache;
1573 if (mask == ATSPI_CACHE_UNDEFINED &&
1574 accessible->parent.app->root &&
1575 accessible->parent.app->root->accessible_parent)
1577 AtspiAccessible *desktop = atspi_get_desktop (0);
1578 mask = desktop->parent.app->cache;
1579 g_object_unref (desktop);
1582 if (mask == ATSPI_CACHE_UNDEFINED)
1583 mask = ATSPI_CACHE_DEFAULT;
1589 _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
1591 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1592 AtspiCache result = accessible->cached_properties & mask & flag;
1593 if (accessible->states && atspi_state_set_contains (accessible->states, ATSPI_STATE_TRANSIENT))
1595 return (result != 0 && (atspi_main_loop || enable_caching) &&
1600 _atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
1602 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1604 accessible->cached_properties |= flag & mask;
1608 * atspi_accessible_get_locale:
1609 * @accessible: an #AtspiAccessible
1611 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
1616 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
1617 * locale of @accessible.
1620 atspi_accessible_get_object_locale (AtspiAccessible *accessible, GError **error)
1624 g_return_val_if_fail (accessible != NULL, NULL);
1626 locale = g_object_get_qdata (G_OBJECT (accessible), quark_locale);
1629 if (!_atspi_dbus_get_property (accessible, atspi_interface_accessible,
1630 "Locale", error, "s", &locale))
1633 g_object_set_qdata_full (G_OBJECT (accessible), quark_locale, locale,