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;
31 atspi_action_interface_init (AtspiAction *action)
36 atspi_collection_interface_init (AtspiCollection *component)
41 atspi_component_interface_init (AtspiComponent *component)
46 atspi_document_interface_init (AtspiDocument *document)
51 atspi_editable_text_interface_init (AtspiEditableText *editable_text)
56 atspi_hypertext_interface_init (AtspiHypertext *hypertext)
61 atspi_image_interface_init (AtspiImage *image)
66 atspi_selection_interface_init (AtspiSelection *selection)
71 atspi_table_interface_init (AtspiTable *table)
76 atspi_text_interface_init (AtspiText *text)
81 atspi_value_interface_init (AtspiValue *value)
85 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT,
86 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init)
87 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COLLECTION, atspi_collection_interface_init)
88 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
89 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_DOCUMENT, atspi_document_interface_init)
90 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init)
91 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_HYPERTEXT, atspi_hypertext_interface_init)
92 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init)
93 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init)
94 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
95 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init)
96 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_VALUE, atspi_value_interface_init))
98 #ifdef DEBUG_REF_COUNTS
99 static gint accessible_count = 0;
103 atspi_accessible_init (AtspiAccessible *accessible)
105 #ifdef DEBUG_REF_COUNTS
107 g_hash_table_insert (_atspi_get_live_refs (), accessible, NULL);
108 g_print("at-spi: init: %d objects\n", accessible_count);
113 atspi_accessible_dispose (GObject *object)
115 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
117 AtspiAccessible *parent;
121 /* TODO: Only fire if object not already marked defunct */
122 memset (&e, 0, sizeof (e));
123 e.type = "object:state-changed:defunct";
124 e.source = accessible;
127 _atspi_send_event (&e);
129 if (accessible->states)
131 g_object_unref (accessible->states);
132 accessible->states = NULL;
135 parent = accessible->accessible_parent;
136 if (parent && parent->children)
138 GList*ls = g_list_find (parent->children, accessible);
141 gboolean replace = (ls == parent->children);
142 ls = g_list_remove (ls, accessible);
144 parent->children = ls;
145 g_object_unref (object);
151 g_object_unref (parent);
152 accessible->accessible_parent = NULL;
155 children = accessible->children;
156 accessible->children = NULL;
157 for (l = children; l; l = l->next)
159 AtspiAccessible *child = l->data;
160 if (child && child->accessible_parent == accessible)
162 g_object_unref (accessible);
163 child->accessible_parent = NULL;
165 g_object_unref (child);
167 g_list_free (children);
169 G_OBJECT_CLASS (atspi_accessible_parent_class) ->dispose (object);
173 atspi_accessible_finalize (GObject *object)
175 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
177 g_free (accessible->description);
178 g_free (accessible->name);
179 if (accessible->attributes)
180 g_hash_table_unref (accessible->attributes);
182 #ifdef DEBUG_REF_COUNTS
184 g_hash_table_remove (_atspi_get_live_refs (), accessible);
185 g_print ("at-spi: finalize: %d objects\n", accessible_count);
188 G_OBJECT_CLASS (atspi_accessible_parent_class)
193 atspi_accessible_class_init (AtspiAccessibleClass *klass)
195 GObjectClass *object_class = G_OBJECT_CLASS (klass);
197 object_class->dispose = atspi_accessible_dispose;
198 object_class->finalize = atspi_accessible_finalize;
201 /* TODO: Generate following from spec? */
202 static const char *role_names [] =
261 "table column header",
263 "tear off menu item",
282 "embedded component",
293 "input method window",
296 "document spreadsheet",
297 "document presentation",
310 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
313 * atspi_role_get_name:
314 * @role: an #AtspiRole object to query.
316 * Gets a localizable string that indicates the name of an #AtspiRole.
317 * <em>DEPRECATED.</em>
319 * Returns: a localizable string name for an #AtspiRole enumerated type.
322 atspi_role_get_name (AtspiRole role)
324 if (role < MAX_ROLES && role_names [(int) role])
326 return g_strdup (role_names [(int) role]);
330 return g_strdup ("");
335 * atspi_accessible_get_name:
336 * @obj: a pointer to the #AtspiAccessible object on which to operate.
338 * Gets the name of an #AtspiAccessible object.
340 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object
341 * or NULL on exception.
344 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
346 g_return_val_if_fail (obj != NULL, g_strdup (""));
347 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_NAME))
349 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
351 return g_strdup ("");
352 _atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
354 return g_strdup (obj->name);
358 * atspi_accessible_get_description:
359 * @obj: a pointer to the #AtspiAccessible object on which to operate.
361 * Gets the description of an #AtspiAccessible object.
363 * Returns: a UTF-8 string describing the #AtspiAccessible object
364 * or NULL on exception.
367 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
369 g_return_val_if_fail (obj != NULL, g_strdup (""));
371 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_DESCRIPTION))
373 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
374 "Description", error, "s",
376 return g_strdup ("");
377 _atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
379 return g_strdup (obj->description);
382 const char *str_parent = "Parent";
385 * atspi_accessible_get_parent:
386 * @obj: a pointer to the #AtspiAccessible object to query.
388 * Gets an #AtspiAccessible object's parent container.
390 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
391 * contains the given #AtspiAccessible instance, or NULL if the @obj
392 * has no parent container.
396 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
398 g_return_val_if_fail (obj != NULL, NULL);
400 if (obj->parent.app &&
401 !_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
403 DBusMessage *message, *reply;
404 DBusMessageIter iter, iter_variant;
405 message = dbus_message_new_method_call (obj->parent.app->bus_name,
407 DBUS_INTERFACE_PROPERTIES, "Get");
410 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
411 DBUS_TYPE_STRING, &str_parent,
413 reply = _atspi_dbus_send_with_reply_and_block (message, error);
416 if (strcmp (dbus_message_get_signature (reply), "v") != 0)
418 dbus_message_unref (reply);
421 dbus_message_iter_init (reply, &iter);
422 dbus_message_iter_recurse (&iter, &iter_variant);
423 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
424 dbus_message_unref (reply);
425 _atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
427 if (!obj->accessible_parent)
429 return g_object_ref (obj->accessible_parent);
433 * atspi_accessible_get_child_count:
434 * @obj: a pointer to the #AtspiAccessible object on which to operate.
436 * Gets the number of children contained by an #AtspiAccessible object.
438 * Returns: a #long indicating the number of #AtspiAccessible children
439 * contained by an #AtspiAccessible object or -1 on exception.
443 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
445 g_return_val_if_fail (obj != NULL, -1);
447 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
450 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
451 "ChildCount", error, "i", &ret))
456 return g_list_length (obj->children);
460 * atspi_accessible_get_child_at_index:
461 * @obj: a pointer to the #AtspiAccessible object on which to operate.
462 * @child_index: a #long indicating which child is specified.
464 * Gets the #AtspiAccessible child of an #AtspiAccessible object at a given index.
466 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
467 * index @child_index or NULL on exception.
470 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
474 AtspiAccessible *child;
476 g_return_val_if_fail (obj != NULL, NULL);
478 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
481 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
482 "GetChildAtIndex", error, "i",
484 return _atspi_dbus_return_accessible_from_message (reply);
487 child = g_list_nth_data (obj->children, child_index);
490 return g_object_ref (child);
494 * atspi_accessible_get_index_in_parent:
495 * @obj: a pointer to the #AtspiAccessible object on which to operate.
497 * Gets the index of an #AtspiAccessible object within its parent's
498 * #AtspiAccessible children list.
500 * Returns: a #glong indicating the index of the #AtspiAccessible object
502 * or -1 if @obj has no containing parent or on exception.
505 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
510 g_return_val_if_fail (obj != NULL, -1);
511 if (_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT) &&
512 !obj->accessible_parent)
514 if (!obj->accessible_parent ||
515 !_atspi_accessible_test_cache (obj->accessible_parent,
516 ATSPI_CACHE_CHILDREN))
518 dbus_int32_t ret = -1;
519 _atspi_dbus_call (obj, atspi_interface_accessible,
520 "GetIndexInParent", NULL, "=>i", &ret);
524 l = obj->accessible_parent->children;
527 if (l->data == obj) return i;
538 } Accessibility_Relation;
541 * atspi_accessible_get_relation_set:
542 * @obj: a pointer to the #AtspiAccessible object on which to operate.
544 * Gets the set of #AtspiRelation objects which describes this #AtspiAccessible object's
545 * relationships with other #AtspiAccessible objects.
547 * Returns: (element-type AtspiAccessible*) (transfer full): a #GArray of
548 * #AtspiRelation pointers or NULL on exception.
551 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
554 DBusMessageIter iter, iter_array;
557 g_return_val_if_fail (obj != NULL, NULL);
559 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
562 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
564 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
565 dbus_message_iter_init (reply, &iter);
566 dbus_message_iter_recurse (&iter, &iter_array);
567 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
569 AtspiRelation *relation;
570 relation = _atspi_relation_new_from_iter (&iter_array);
571 ret = g_array_append_val (ret, relation);
572 dbus_message_iter_next (&iter_array);
574 dbus_message_unref (reply);
579 * atspi_accessible_get_role:
580 * @obj: a pointer to the #AtspiAccessible object on which to operate.
582 * Gets the UI role played by an #AtspiAccessible object.
583 * This role's name can be obtained via atspi_accessible_get_role_name ().
585 * Returns: the #AtspiRole of an #AtspiAccessible object.
589 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
591 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
593 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ROLE))
596 /* TODO: Make this a property */
597 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
600 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
607 * atspi_accessible_get_role_name:
608 * @obj: a pointer to the #AtspiAccessible object on which to operate.
610 * Gets a UTF-8 string corresponding to the name of the role played by an object.
611 * This method will return useful values for roles that fall outside the
612 * enumeration used in atspi_accessible_get_role ().
614 * Returns: a UTF-8 string specifying the type of UI role played by an
615 * #AtspiAccessible object.
619 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
624 g_return_val_if_fail (obj != NULL, NULL);
626 role = atspi_accessible_get_role (obj, error);
627 if (role >= 0 && role < MAX_ROLES && role != ATSPI_ROLE_EXTENDED)
628 return g_strdup (role_names [role]);
630 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
633 retval = g_strdup ("");
639 * atspi_accessible_get_localized_role_name:
640 * @obj: a pointer to the #AtspiAccessible object on which to operate.
642 * Gets a UTF-8 string corresponding to the name of the role played by an
643 * object, translated to the current locale.
644 * This method will return useful values for roles that fall outside the
645 * enumeration used in atspi_accessible_getRole ().
647 * Returns: a localized, UTF-8 string specifying the type of UI role played
648 * by an #AtspiAccessible object.
652 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
656 g_return_val_if_fail (obj != NULL, NULL);
658 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
661 return g_strdup ("");
666 static AtspiStateSet *
669 AtspiStateSet *set = atspi_state_set_new (NULL);
670 atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
675 * atspi_accessible_get_state_set:
676 * @obj: a pointer to the #AtspiAccessible object on which to operate.
678 * Gets the states currently held by an object.
680 * Returns: (transfer full): a pointer to an #AtspiStateSet representing an
681 * object's current state set.
684 atspi_accessible_get_state_set (AtspiAccessible *obj)
686 /* TODO: Should take a GError **, but would be an API break */
687 if (!obj->parent.app || !obj->parent.app->bus)
688 return defunct_set ();
690 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
693 DBusMessageIter iter;
694 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
695 "GetState", NULL, "");
696 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
697 dbus_message_iter_init (reply, &iter);
698 _atspi_dbus_set_state (obj, &iter);
699 dbus_message_unref (reply);
700 _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
703 return g_object_ref (obj->states);
707 * atspi_accessible_get_attributes:
708 * @obj: The #AtspiAccessible being queried.
710 * Gets the #AttributeSet representing any assigned
711 * name-value pair attributes or annotations for this object.
712 * For typographic, textual, or textually-semantic attributes, see
713 * atspi_text_get_attributes instead.
715 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
716 * attributes assigned to this object.
719 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
721 DBusMessage *message;
723 g_return_val_if_fail (obj != NULL, NULL);
725 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ATTRIBUTES))
727 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
728 "GetAttributes", error, "");
729 obj->attributes = _atspi_dbus_return_hash_from_message (message);
730 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ATTRIBUTES);
733 if (!obj->attributes)
735 return g_hash_table_ref (obj->attributes);
739 add_to_attribute_array (gpointer key, gpointer value, gpointer data)
741 GArray **array = (GArray **)data;
742 gchar *str = g_strconcat (key, ":", value, NULL);
743 *array = g_array_append_val (*array, str);
747 * atspi_accessible_get_attributes_as_array:
748 * @obj: The #AtspiAccessible being queried.
750 * Gets a #GArray representing any assigned
751 * name-value pair attributes or annotations for this object.
752 * For typographic, textual, or textually-semantic attributes, see
753 * atspi_text_get_attributes_as_array instead.
755 * Returns: (element-type gchar*) (transfer full): The name-value-pair
756 * attributes assigned to this object.
759 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
761 DBusMessage *message;
763 g_return_val_if_fail (obj != NULL, NULL);
765 if (_atspi_accessible_get_cache_mask (obj) & ATSPI_CACHE_ATTRIBUTES)
767 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
768 GHashTable *attributes = atspi_accessible_get_attributes (obj, error);
771 g_hash_table_foreach (attributes, add_to_attribute_array, &array);
772 g_hash_table_unref (attributes);
776 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
777 return _atspi_dbus_return_attribute_array_from_message (message);
781 * atspi_accessible_get_application:
782 * @obj: The #AtspiAccessible being queried.
784 * Gets the containing #AtspiApplication for an object.
786 * Returns: (transfer full): the containing #AtspiApplication instance for
790 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
792 AtspiAccessible *parent;
797 parent = atspi_accessible_get_parent (obj, NULL);
798 if (!parent && obj->parent.app &&
799 atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
801 AtspiAccessible *root = g_object_ref (obj->parent.app->root);
804 g_object_unref (obj);
805 g_object_unref (parent);
806 if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
808 g_object_unref (root);
814 if (!parent || parent == obj ||
815 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
818 g_object_unref (parent);
821 g_object_unref (obj);
826 /* Application-specific methods */
829 * atspi_accessible_get_toolkit_name:
830 * @obj: a pointer to the #AtspiAccessible object on which to operate.
832 * Gets the toolkit name for an #AtspiAccessible object.
833 * Only works on application root objects.
835 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object or NULL on exception.
838 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
840 g_return_val_if_fail (obj != NULL, NULL);
842 if (!obj->parent.app)
845 if (!obj->parent.app->toolkit_name)
846 _atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName",
847 error, "s", &obj->parent.app->toolkit_name);
849 return g_strdup (obj->parent.app->toolkit_name);
853 * atspi_accessible_get_toolkit_version:
854 * @obj: a pointer to the #AtspiAccessible object on which to operate.
856 * Gets the toolkit version for an #AtspiAccessible object.
857 * Only works on application root objects.
859 * Returns: a UTF-8 string indicating the toolkit version for the #AtspiAccessible object or NULL on exception.
862 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
864 g_return_val_if_fail (obj != NULL, NULL);
866 if (!obj->parent.app)
869 if (!obj->parent.app->toolkit_version)
870 _atspi_dbus_get_property (obj, atspi_interface_application, "Version",
871 error, "s", &obj->parent.app->toolkit_version);
873 return g_strdup (obj->parent.app->toolkit_version);
877 * atspi_accessible_get_atspi_version:
878 * @obj: a pointer to the #AtspiAccessible object on which to operate.
880 * Gets the AT-SPI IPC specification version supported by the application
881 * pointed to by the #AtspiAccessible object.
882 * Only works on application root objects.
884 * Returns: a UTF-8 string indicating the AT-SPI version for the #AtspiAccessible object or NULL on exception.
887 atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
889 g_return_val_if_fail (obj != NULL, NULL);
891 if (!obj->parent.app)
894 if (!obj->parent.app->atspi_version)
895 _atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion",
896 error, "s", &obj->parent.app->atspi_version);
898 return g_strdup (obj->parent.app->atspi_version);
902 * atspi_accessible_get_id:
903 * @obj: a pointer to the #AtspiAccessible object on which to operate.
905 * Gets the application id for a #AtspiAccessible object.
906 * Only works on application root objects.
908 * Returns: a positive #gint indicating the id for the #AtspiAccessible object
909 * or -1 on exception.
912 atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
916 g_return_val_if_fail (obj != NULL, -1);
918 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
924 /* Interface query methods */
927 _atspi_accessible_is_a (AtspiAccessible *accessible,
928 const char *interface_name)
932 if (accessible == NULL)
937 if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
940 DBusMessageIter iter;
941 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
942 "GetInterfaces", NULL, "");
943 _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
944 dbus_message_iter_init (reply, &iter);
945 _atspi_dbus_set_interfaces (accessible, &iter);
946 dbus_message_unref (reply);
947 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
950 n = _atspi_get_iface_num (interface_name);
951 if (n == -1) return FALSE;
952 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
956 * atspi_accessible_is_action:
957 * @obj: a pointer to the #AtspiAccessible instance to query.
959 * Query whether the specified #AtspiAccessible implements the
960 * #AtspiAction interface.
962 * Returns: #TRUE if @obj implements the #AtspiAction interface,
966 atspi_accessible_is_action (AtspiAccessible *obj)
968 return _atspi_accessible_is_a (obj,
969 atspi_interface_action);
973 * atspi_accessible_is_application:
974 * @obj: a pointer to the #AtspiAccessible instance to query.
976 * Query whether the specified #AtspiAccessible implements the
977 * #AtspiApplication interface.
979 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
983 atspi_accessible_is_application (AtspiAccessible *obj)
985 return _atspi_accessible_is_a (obj,
986 atspi_interface_application);
990 * atspi_accessible_is_collection:
991 * @obj: a pointer to the #AtspiAccessible instance to query.
993 * Query whether the specified #AtspiAccessible implements the
994 * #AtspiCollection interface.
996 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
1000 atspi_accessible_is_collection (AtspiAccessible *obj)
1002 return _atspi_accessible_is_a (obj,
1003 atspi_interface_collection);
1007 * atspi_accessible_is_component:
1008 * @obj: a pointer to the #AtspiAccessible instance to query.
1010 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
1012 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
1016 atspi_accessible_is_component (AtspiAccessible *obj)
1018 return _atspi_accessible_is_a (obj,
1019 atspi_interface_component);
1023 * atspi_accessible_is_document:
1024 * @obj: a pointer to the #AtspiAccessible instance to query.
1026 * Query whether the specified #AtspiAccessible implements the
1027 * #AtspiDocument interface.
1029 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
1033 atspi_accessible_is_document (AtspiAccessible *obj)
1035 return _atspi_accessible_is_a (obj,
1036 atspi_interface_document);
1040 * atspi_accessible_is_editable_text:
1041 * @obj: a pointer to the #AtspiAccessible instance to query.
1043 * Query whether the specified #AtspiAccessible implements the
1044 * #AtspiEditableText interface.
1046 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
1050 atspi_accessible_is_editable_text (AtspiAccessible *obj)
1052 return _atspi_accessible_is_a (obj,
1053 atspi_interface_editable_text);
1057 * atspi_accessible_is_hypertext:
1058 * @obj: a pointer to the #AtspiAccessible instance to query.
1060 * Query whether the specified #AtspiAccessible implements the
1061 * #AtspiHypertext interface.
1063 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1067 atspi_accessible_is_hypertext (AtspiAccessible *obj)
1069 return _atspi_accessible_is_a (obj,
1070 atspi_interface_hypertext);
1074 * atspi_accessible_is_hyperlink:
1075 * @obj: a pointer to the #AtspiAccessible instance to query.
1077 * Query whether the specified #AtspiAccessible implements the
1078 * #AtspiHyperlink interface.
1080 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1084 atspi_accessible_is_hyperlink (AtspiAccessible *obj)
1086 return _atspi_accessible_is_a (obj,
1087 atspi_interface_hyperlink);
1091 * atspi_accessible_is_image:
1092 * @obj: a pointer to the #AtspiAccessible instance to query.
1094 * Query whether the specified #AtspiAccessible implements the
1095 * #AtspiImage interface.
1097 * Returns: #TRUE if @obj implements the #AtspiImage interface,
1101 atspi_accessible_is_image (AtspiAccessible *obj)
1103 return _atspi_accessible_is_a (obj,
1104 atspi_interface_image);
1108 * atspi_accessible_is_selection:
1109 * @obj: a pointer to the #AtspiAccessible instance to query.
1111 * Query whether the specified #AtspiAccessible implements the
1112 * #AtspiSelection interface.
1114 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
1118 atspi_accessible_is_selection (AtspiAccessible *obj)
1120 return _atspi_accessible_is_a (obj,
1121 atspi_interface_selection);
1125 * atspi_accessible_is_table:
1126 * @obj: a pointer to the #AtspiAccessible instance to query.
1128 * Query whether the specified #AtspiAccessible implements the
1129 * #AtspiTable interface.
1131 * Returns: #TRUE if @obj implements the #AtspiTable interface,
1135 atspi_accessible_is_table (AtspiAccessible *obj)
1137 return _atspi_accessible_is_a (obj,
1138 atspi_interface_table);
1142 * atspi_accessible_is_streamable_content:
1143 * @obj: a pointer to the #AtspiAccessible instance to query.
1145 * Query whether the specified #AtspiAccessible implements the
1146 * #AtspiStreamableContent interface.
1148 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
1152 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
1155 return _atspi_accessible_is_a (obj,
1156 atspi_interface_streamable_content);
1158 g_warning ("Streamable content not implemented");
1164 * atspi_accessible_is_text:
1165 * @obj: a pointer to the #AtspiAccessible instance to query.
1167 * Query whether the specified #AtspiAccessible implements the
1168 * #AtspiText interface.
1170 * Returns: #TRUE if @obj implements the #AtspiText interface,
1174 atspi_accessible_is_text (AtspiAccessible *obj)
1176 return _atspi_accessible_is_a (obj,
1177 atspi_interface_text);
1181 * atspi_accessible_is_value:
1182 * @obj: a pointer to the #AtspiAccessible instance to query.
1184 * Query whether the specified #AtspiAccessible implements the
1185 * #AtspiValue interface.
1187 * Returns: #TRUE if @obj implements the #AtspiValue interface,
1191 atspi_accessible_is_value (AtspiAccessible *obj)
1193 return _atspi_accessible_is_a (obj,
1194 atspi_interface_value);
1198 * atspi_accessible_get_action:
1199 * @obj: a pointer to the #AtspiAccessible instance to query.
1201 * Gets the #AtspiAction interface for an #AtspiAccessible.
1203 * Returns: (transfer full): a pointer to an #AtspiAction interface
1204 * instance, or NULL if @obj does not implement #AtspiAction.
1207 atspi_accessible_get_action (AtspiAccessible *accessible)
1209 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1210 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1214 * atspi_accessible_get_collection:
1215 * @obj: a pointer to the #AtspiAccessible instance to query.
1217 * Gets the #AtspiCollection interface for an #AtspiAccessible.
1219 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1220 * instance, or NULL if @obj does not implement #AtspiCollection.
1223 atspi_accessible_get_collection (AtspiAccessible *accessible)
1225 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1226 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1230 * atspi_accessible_get_component:
1231 * @obj: a pointer to the #AtspiAccessible instance to query.
1233 * Gets the #AtspiComponent interface for an #AtspiAccessible.
1235 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1236 * instance, or NULL if @obj does not implement #AtspiComponent.
1239 atspi_accessible_get_component (AtspiAccessible *obj)
1241 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1242 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1246 * atspi_accessible_get_document:
1247 * @obj: a pointer to the #AtspiAccessible instance to query.
1249 * Gets the #AtspiDocument interface for an #AtspiAccessible.
1251 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1252 * instance, or NULL if @obj does not implement #AtspiDocument.
1255 atspi_accessible_get_document (AtspiAccessible *accessible)
1257 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1258 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1262 * atspi_accessible_get_editable_text:
1263 * @obj: a pointer to the #AtspiAccessible instance to query.
1265 * Gets the #AtspiEditableText interface for an #AtspiAccessible.
1267 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1268 * instance, or NULL if @obj does not implement #AtspiEditableText.
1271 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1273 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1274 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1278 * atspi_accessible_get_hyperlink:
1279 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1281 * Gets the #AtspiHyperlink interface for an #AtspiAccessible.
1283 * Returns: (transfer full): the #AtspiHyperlink object associated with
1284 * the given #AtspiAccessible, or NULL if not supported.
1287 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1289 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1290 _atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1294 * atspi_accessible_get_hypertext:
1295 * @obj: a pointer to the #AtspiAccessible instance to query.
1297 * Gets the #AtspiHypertext interface for an #AtspiAccessible.
1299 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1300 * instance, or NULL if @obj does not implement #AtspiHypertext.
1303 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1305 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1306 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1310 * atspi_accessible_get_image:
1311 * @obj: a pointer to the #AtspiAccessible instance to query.
1313 * Gets the #AtspiImage interface for an #AtspiAccessible.
1315 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1316 * NULL if @obj does not implement #AtspiImage.
1319 atspi_accessible_get_image (AtspiAccessible *accessible)
1321 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1322 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1326 * atspi_accessible_get_selection:
1327 * @obj: a pointer to the #AtspiAccessible instance to query.
1329 * Gets the #AtspiSelection interface for an #AtspiAccessible.
1331 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1332 * instance, or NULL if @obj does not implement #AtspiSelection.
1335 atspi_accessible_get_selection (AtspiAccessible *accessible)
1337 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1338 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1343 * atspi_accessible_get_streamable_content:
1344 * @obj: a pointer to the #AtspiAccessible instance to query.
1346 * Gets the #AtspiStreamableContent interface for an #AtspiAccessible.
1348 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1349 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1351 AtspiStreamableContent *
1352 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1354 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1360 * atspi_accessible_get_table:
1361 * @obj: a pointer to the #AtspiAccessible instance to query.
1363 * Gets the #AtspiTable interface for an #AtspiAccessible.
1365 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1366 * NULL if @obj does not implement #AtspiTable.
1369 atspi_accessible_get_table (AtspiAccessible *obj)
1371 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1372 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1376 * atspi_accessible_get_text:
1377 * @obj: a pointer to the #AtspiAccessible instance to query.
1379 * Gets the #AtspiTable interface for an #AtspiAccessible.
1381 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1382 * NULL if @obj does not implement #AtspiText.
1385 atspi_accessible_get_text (AtspiAccessible *obj)
1387 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1388 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1392 * atspi_accessible_get_value:
1393 * @obj: a pointer to the #AtspiAccessible instance to query.
1395 * Gets the #AtspiTable interface for an #AtspiAccessible.
1397 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1398 * NULL if @obj does not implement #AtspiValue.
1401 atspi_accessible_get_value (AtspiAccessible *accessible)
1403 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1404 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1408 append_const_val (GArray *array, const gchar *val)
1410 gchar *dup = g_strdup (val);
1413 g_array_append_val (array, dup);
1417 * atspi_accessible_get_interfaces:
1418 * @obj: The #AtspiAccessible to query.
1420 * A set of pointers to all interfaces supported by an #AtspiAccessible.
1422 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1423 * describing the interfaces supported by the object. Interfaces are
1424 * denoted in short-hand (i.e. "Component", "Text" etc.).
1427 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1429 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1431 g_return_val_if_fail (obj != NULL, NULL);
1433 append_const_val (ret, "Accessible");
1434 if (atspi_accessible_is_action (obj))
1435 append_const_val (ret, "Action");
1436 if (atspi_accessible_is_collection (obj))
1437 append_const_val (ret, "Collection");
1438 if (atspi_accessible_is_component (obj))
1439 append_const_val (ret, "Component");
1440 if (atspi_accessible_is_document (obj))
1441 append_const_val (ret, "Document");
1442 if (atspi_accessible_is_editable_text (obj))
1443 append_const_val (ret, "EditableText");
1444 if (atspi_accessible_is_hypertext (obj))
1445 append_const_val (ret, "Hypertext");
1446 if (atspi_accessible_is_hyperlink (obj))
1447 append_const_val (ret, "Hyperlink");
1448 if (atspi_accessible_is_image (obj))
1449 append_const_val (ret, "Image");
1450 if (atspi_accessible_is_selection (obj))
1451 append_const_val (ret, "Selection");
1452 if (atspi_accessible_is_table (obj))
1453 append_const_val (ret, "Table");
1454 if (atspi_accessible_is_text (obj))
1455 append_const_val (ret, "Text");
1456 if (atspi_accessible_is_value (obj))
1457 append_const_val (ret, "Value");
1463 _atspi_accessible_new (AtspiApplication *app, const gchar *path)
1465 AtspiAccessible *accessible;
1467 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1468 g_return_val_if_fail (accessible != NULL, NULL);
1470 accessible->parent.app = g_object_ref (app);
1471 accessible->parent.path = g_strdup (path);
1477 * atspi_accessible_set_cache_mask:
1478 * @accessible: The #AtspiAccessible to operate on. Must be the desktop or
1479 * the root of an application.
1480 * @mask: (type int): An #AtspiCache specifying a bit mask of the types of data to cache.
1482 * Sets the type of data to cache for accessibles.
1483 * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
1484 * then the desktop's cache flag will be used.
1485 * If the desktop's cache flag is also undefined, then all possible data will
1487 * This function is intended to work around bugs in toolkits where the proper
1488 * events are not raised / to aid in testing for such bugs.
1491 atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
1493 g_return_if_fail (accessible != NULL);
1494 g_return_if_fail (accessible->parent.app != NULL);
1495 g_return_if_fail (accessible == accessible->parent.app->root);
1496 accessible->parent.app->cache = mask;
1497 enable_caching = TRUE;
1501 * atspi_accessible_clear_cache:
1502 * @accessible: The #AtspiAccessible whose cache to clear.
1504 * Clears the cached information for the given accessible and all of its
1508 atspi_accessible_clear_cache (AtspiAccessible *accessible)
1514 accessible->cached_properties = ATSPI_CACHE_NONE;
1515 for (l = accessible->children; l; l = l->next)
1516 atspi_accessible_clear_cache (l->data);
1521 * atspi_accessible_get_process_id:
1522 * @accessible: The #AtspiAccessible to query.
1524 * Returns the process id associated with the given accessible. Mainly
1525 * added for debugging; it is a shortcut to explicitly querying the
1526 * accessible's app->bus_name and then calling GetConnectionUnixProcessID.
1528 * Returns: The process ID, or -1 if defunct.
1531 atspi_accessible_get_process_id (AtspiAccessible *accessible, GError **error)
1533 DBusMessage *message, *reply;
1534 DBusConnection *bus = _atspi_bus ();
1535 dbus_uint32_t pid = -1;
1538 if (!accessible->parent.app || !accessible->parent.app->bus_name)
1541 message = dbus_message_new_method_call ("org.freedesktop.DBus",
1542 "/org/freedesktop/DBus",
1543 "org.freedesktop.DBus",
1544 "GetConnectionUnixProcessID");
1545 dbus_message_append_args (message, DBUS_TYPE_STRING,
1546 &accessible->parent.app->bus_name,
1548 dbus_error_init (&d_error);
1549 reply = dbus_connection_send_with_reply_and_block (bus, message, -1, &d_error);
1550 dbus_message_unref (message);
1551 dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &pid, DBUS_TYPE_INVALID);
1552 dbus_message_unref (reply);
1553 if (dbus_error_is_set (&d_error))
1555 g_warning ("GetConnectionUnixProcessID failed: %s", d_error.message);
1556 dbus_error_free (&d_error);
1562 _atspi_accessible_get_cache_mask (AtspiAccessible *accessible)
1566 if (!accessible->parent.app)
1567 return ATSPI_CACHE_NONE;
1569 mask = accessible->parent.app->cache;
1570 if (mask == ATSPI_CACHE_UNDEFINED &&
1571 accessible->parent.app->root &&
1572 accessible->parent.app->root->accessible_parent)
1574 AtspiAccessible *desktop = atspi_get_desktop (0);
1575 mask = desktop->parent.app->cache;
1576 g_object_unref (desktop);
1579 if (mask == ATSPI_CACHE_UNDEFINED)
1580 mask = ATSPI_CACHE_DEFAULT;
1586 _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
1588 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1589 AtspiCache result = accessible->cached_properties & mask & flag;
1590 if (accessible->states && atspi_state_set_contains (accessible->states, ATSPI_STATE_TRANSIENT))
1592 return (result != 0 && (atspi_main_loop || enable_caching) &&
1597 _atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
1599 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1601 accessible->cached_properties |= flag & mask;