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"
29 atspi_action_interface_init (AtspiAction *action)
34 atspi_collection_interface_init (AtspiCollection *component)
39 atspi_component_interface_init (AtspiComponent *component)
44 atspi_document_interface_init (AtspiDocument *document)
49 atspi_editable_text_interface_init (AtspiEditableText *editable_text)
54 atspi_hypertext_interface_init (AtspiHypertext *hypertext)
59 atspi_image_interface_init (AtspiImage *image)
64 atspi_selection_interface_init (AtspiSelection *selection)
69 atspi_table_interface_init (AtspiTable *table)
74 atspi_text_interface_init (AtspiText *text)
79 atspi_value_interface_init (AtspiValue *value)
83 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT,
84 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init)
85 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COLLECTION, atspi_collection_interface_init)
86 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
87 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_DOCUMENT, atspi_document_interface_init)
88 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init)
89 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_HYPERTEXT, atspi_hypertext_interface_init)
90 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init)
91 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init)
92 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
93 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init)
94 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_VALUE, atspi_value_interface_init))
96 #ifdef DEBUG_REF_COUNTS
97 static gint accessible_count = 0;
101 atspi_accessible_init (AtspiAccessible *accessible)
103 #ifdef DEBUG_REF_COUNTS
105 printf("at-spi: init: %d objects\n", accessible_count);
110 atspi_accessible_dispose (GObject *object)
112 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
114 AtspiAccessible *parent;
116 /* TODO: Only fire if object not already marked defunct */
117 memset (&e, 0, sizeof (e));
118 e.type = "object:state-change:defunct";
119 e.source = accessible;
122 _atspi_send_event (&e);
124 if (accessible->states)
126 g_object_unref (accessible->states);
127 accessible->states = NULL;
130 parent = accessible->accessible_parent;
131 if (parent && parent->children)
133 GList*ls = g_list_find (parent->children, accessible);
136 gboolean replace = (ls == parent->children);
137 ls = g_list_remove (ls, accessible);
139 parent->children = ls;
140 g_object_unref (object);
146 g_object_unref (parent);
147 accessible->accessible_parent = NULL;
150 G_OBJECT_CLASS (atspi_accessible_parent_class) ->dispose (object);
154 atspi_accessible_finalize (GObject *object)
156 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
158 g_free (accessible->description);
159 g_free (accessible->name);
160 if (accessible->attributes)
161 g_hash_table_unref (accessible->attributes);
163 #ifdef DEBUG_REF_COUNTS
165 g_print ("at-spi: finalize: %d objects\n", accessible_count);
168 G_OBJECT_CLASS (atspi_accessible_parent_class)
173 atspi_accessible_class_init (AtspiAccessibleClass *klass)
175 GObjectClass *object_class = G_OBJECT_CLASS (klass);
177 object_class->dispose = atspi_accessible_dispose;
178 object_class->finalize = atspi_accessible_finalize;
181 /* TODO: Generate following from spec? */
182 static const char *role_names [] =
240 "table-column-header",
242 "tear-off-menu-item",
272 "input method window"
275 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
278 * atspi_role_get_name
279 * @role: an #AtspiAccessibleRole object to query.
281 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
282 * <em>DEPRECATED.</em>
284 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
287 atspi_role_get_name (AtspiRole role)
289 if (role < MAX_ROLES && role_names [(int) role])
291 return g_strdup (role_names [(int) role]);
295 return g_strdup ("");
300 * atspi_accessible_get_name:
301 * @obj: a pointer to the #AtspiAccessible object on which to operate.
303 * Get the name of an #AtspiAccessible object.
305 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
306 * or NULL on exception
309 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
311 g_return_val_if_fail (obj != NULL, g_strdup (""));
312 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_NAME))
314 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
316 return g_strdup ("");
317 _atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
319 return g_strdup (obj->name);
323 * atspi_accessible_get_description:
324 * @obj: a pointer to the #AtspiAccessible object on which to operate.
326 * Get the description of an #AtspiAccessible object.
328 * Returns: a UTF-8 string describing the #AtspiAccessible object.
329 * or NULL on exception
332 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
334 g_return_val_if_fail (obj != NULL, g_strdup (""));
336 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_DESCRIPTION))
338 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
339 "Description", error, "s",
341 return g_strdup ("");
342 _atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
344 return g_strdup (obj->description);
347 const char *str_parent = "Parent";
350 * atspi_accessible_get_parent:
351 * @obj: a pointer to the #AtspiAccessible object to query.
353 * Get an #AtspiAccessible object's parent container.
355 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
356 * contains the given #AtspiAccessible instance, or NULL if the @obj
357 * has no parent container.
361 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
363 g_return_val_if_fail (obj != NULL, NULL);
365 if (obj->parent.app &&
366 !_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
368 DBusMessage *message, *reply;
369 DBusMessageIter iter, iter_variant;
370 message = dbus_message_new_method_call (obj->parent.app->bus_name,
372 DBUS_INTERFACE_PROPERTIES, "Get");
375 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
376 DBUS_TYPE_STRING, &str_parent,
378 reply = _atspi_dbus_send_with_reply_and_block (message, error);
381 if (strcmp (dbus_message_get_signature (reply), "v") != 0)
383 dbus_message_unref (reply);
386 dbus_message_iter_init (reply, &iter);
387 dbus_message_iter_recurse (&iter, &iter_variant);
388 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
389 dbus_message_unref (reply);
390 _atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
392 if (!obj->accessible_parent)
394 return g_object_ref (obj->accessible_parent);
398 * atspi_accessible_get_child_count:
399 * @obj: a pointer to the #AtspiAccessible object on which to operate.
401 * Get the number of children contained by an #AtspiAccessible object.
403 * Returns: a #long indicating the number of #AtspiAccessible children
404 * contained by an #AtspiAccessible object. or -1 on exception
408 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
410 g_return_val_if_fail (obj != NULL, -1);
412 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
415 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
416 "ChildCount", error, "i", &ret))
421 return g_list_length (obj->children);
425 * atspi_accessible_get_child_at_index:
426 * @obj: a pointer to the #AtspiAccessible object on which to operate.
427 * @child_index: a #long indicating which child is specified.
429 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
431 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
432 * index @child_index. or NULL on exception
435 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
439 AtspiAccessible *child;
441 g_return_val_if_fail (obj != NULL, NULL);
443 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
446 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
447 "GetChildAtIndex", error, "i",
449 return _atspi_dbus_return_accessible_from_message (reply);
452 child = g_list_nth_data (obj->children, child_index);
455 return g_object_ref (child);
459 * atspi_accessible_get_index_in_parent
460 * @obj: a pointer to the #AtspiAccessible object on which to operate.
462 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
464 * Returns: a #glong indicating the index of the #AtspiAccessible object
465 * in its parent (i.e. containing) #AtspiAccessible instance,
466 * or -1 if @obj has no containing parent or on exception.
469 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
474 g_return_val_if_fail (obj != NULL, -1);
475 if (!obj->accessible_parent) return -1;
476 if (!_atspi_accessible_test_cache (obj->accessible_parent,
477 ATSPI_CACHE_CHILDREN))
479 dbus_uint32_t ret = -1;
480 _atspi_dbus_call (obj, atspi_interface_accessible,
481 "GetIndexInParent", NULL, "=>u", &ret);
485 l = obj->accessible_parent->children;
488 if (l->data == obj) return i;
499 } Accessibility_Relation;
502 * atspi_accessible_get_relation_set:
503 * @obj: a pointer to the #AtspiAccessible object on which to operate.
505 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
506 * relationships with other #AtspiAccessible objects.
508 * Returns: (element-type AtspiAccessible*) (transfer full): an array of
509 * #AtspiAccessibleRelation pointers. or NULL on exception
512 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
515 DBusMessageIter iter, iter_array;
518 g_return_val_if_fail (obj != NULL, NULL);
520 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
523 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
525 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
526 dbus_message_iter_init (reply, &iter);
527 dbus_message_iter_recurse (&iter, &iter_array);
528 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
530 AtspiRelation *relation;
531 relation = _atspi_relation_new_from_iter (&iter_array);
532 ret = g_array_append_val (ret, relation);
533 dbus_message_iter_next (&iter_array);
535 dbus_message_unref (reply);
540 * atspi_accessible_get_role:
541 * @obj: a pointer to the #AtspiAccessible object on which to operate.
543 * Get the UI role of an #AtspiAccessible object.
544 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
546 * Returns: the #AtspiRole of the object.
550 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
552 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
554 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ROLE))
557 /* TODO: Make this a property */
558 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
561 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
568 * atspi_accessible_get_role_name:
569 * @obj: a pointer to the #AtspiAccessible object on which to operate.
571 * Get a UTF-8 string describing the role this object plays in the UI.
572 * This method will return useful values for roles that fall outside the
573 * enumeration used in atspi_accessible_getRole ().
575 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
579 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
581 AtspiRole role = atspi_accessible_get_role (obj, error);
583 GTypeClass *type_class;
585 const gchar *name = NULL;
587 type_class = g_type_class_ref (ATSPI_TYPE_ROLE);
588 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
590 value = g_enum_get_value (G_ENUM_CLASS (type_class), role);
594 retval = value->value_nick;
598 return g_strdup (retval);
600 g_return_val_if_fail (obj != NULL, NULL);
602 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
605 retval = g_strdup ("");
611 * atspi_accessible_get_localized_role_name:
612 * @obj: a pointer to the #AtspiAccessible object on which to operate.
614 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
615 * This method will return useful values for roles that fall outside the
616 * enumeration used in atspi_accessible_getRole ().
618 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
622 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
626 g_return_val_if_fail (obj != NULL, NULL);
628 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
631 return g_strdup ("");
636 static AtspiStateSet *
639 AtspiStateSet *set = atspi_state_set_new (NULL);
640 atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
645 * atspi_accessible_get_state_set:
646 * @obj: a pointer to the #AtspiAccessible object on which to operate.
648 * Gets the current state of an object.
650 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
651 * object's current state.
654 atspi_accessible_get_state_set (AtspiAccessible *obj)
656 if (!obj->parent.app || !obj->parent.app->bus)
657 return defunct_set ();
660 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
663 DBusMessageIter iter;
664 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
665 "GetState", NULL, "");
666 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
667 dbus_message_iter_init (reply, &iter);
668 _atspi_dbus_set_state (obj, &iter);
669 dbus_message_unref (reply);
670 _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
673 return g_object_ref (obj->states);
677 * atspi_accessible_get_attributes:
678 * @obj: The #AtspiAccessible being queried.
680 * Get the #AttributeSet representing any assigned
681 * name-value pair attributes or annotations for this object.
682 * For typographic, textual, or textually-semantic attributes, see
683 * atspi_text_get_attributes instead.
685 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
686 * attributes assigned to this object.
689 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
691 DBusMessage *message;
693 g_return_val_if_fail (obj != NULL, NULL);
695 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ATTRIBUTES))
697 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
698 "GetAttributes", error, "");
699 obj->attributes = _atspi_dbus_return_hash_from_message (message);
700 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ATTRIBUTES);
703 if (!obj->attributes)
705 return g_hash_table_ref (obj->attributes);
709 add_to_attribute_array (gpointer key, gpointer value, gpointer data)
711 GArray **array = (GArray **)data;
712 gchar *str = g_strconcat (key, ":", value, NULL);
713 *array = g_array_append_val (*array, str);
717 * atspi_accessible_get_attributes_as_array:
718 * @obj: The #AtspiAccessible being queried.
720 * Get the #AttributeSet representing any assigned
721 * name-value pair attributes or annotations for this object.
722 * For typographic, textual, or textually-semantic attributes, see
723 * atspi_text_get_attributes_as_array instead.
725 * Returns: (element-type gchar*) (transfer full): The name-value-pair
726 * attributes assigned to this object.
729 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
731 DBusMessage *message;
733 g_return_val_if_fail (obj != NULL, NULL);
735 if (_atspi_accessible_get_cache_mask (obj) & ATSPI_CACHE_ATTRIBUTES)
737 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
738 GHashTable *attributes = atspi_accessible_get_attributes (obj, error);
741 g_hash_table_foreach (attributes, add_to_attribute_array, &array);
742 g_hash_table_unref (attributes);
746 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
747 return _atspi_dbus_return_attribute_array_from_message (message);
751 * atspi_accessible_get_application:
752 * @obj: The #AtspiAccessible being queried.
754 * Get the containing #AtspiApplication for an object.
756 * Returns: (transfer full): the containing AtspiApplication instance for
760 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
762 AtspiAccessible *parent;
767 parent = atspi_accessible_get_parent (obj, NULL);
768 if (!parent && obj->parent.app &&
769 atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
771 AtspiAccessible *root = g_object_ref (obj->parent.app->root);
774 g_object_unref (obj);
775 if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
777 g_object_unref (root);
783 if (!parent || parent == obj ||
784 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
786 g_object_unref (obj);
791 /* Application-specific methods */
794 * atspi_accessible_get_toolkit_name:
795 * @obj: a pointer to the #AtspiAccessible object on which to operate.
797 * Get the toolkit for a #AtspiAccessible object.
798 * Only works on application root objects.
800 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
801 * or NULL on exception
804 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
806 g_return_val_if_fail (obj != NULL, NULL);
808 if (!obj->parent.app)
811 if (!obj->parent.app->toolkit_name)
812 _atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName",
813 error, "s", &obj->parent.app->toolkit_name);
815 return g_strdup (obj->parent.app->toolkit_name);
819 * atspi_accessible_get_toolkit_version:
820 * @obj: a pointer to the #AtspiAccessible object on which to operate.
822 * Get the toolkit version for a #AtspiAccessible object.
823 * Only works on application root objects.
825 * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
826 * or NULL on exception
829 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
831 g_return_val_if_fail (obj != NULL, NULL);
833 if (!obj->parent.app)
836 if (!obj->parent.app->toolkit_version)
837 _atspi_dbus_get_property (obj, atspi_interface_application, "Version",
838 error, "s", &obj->parent.app->toolkit_version);
840 return g_strdup (obj->parent.app->toolkit_version);
844 * atspi_accessible_get_atspi_version:
845 * @obj: a pointer to the #AtspiAccessible object on which to operate.
847 * Get the AT-SPI IPC specification version supported by the application
848 * pointed to by the #AtspiAccessible object.
849 * Only works on application root objects.
851 * Returns: a UTF-8 string indicating the AT-SPI ersion for the #AtspiAccessible object.
852 * or NULL on exception
855 atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
857 g_return_val_if_fail (obj != NULL, NULL);
859 if (!obj->parent.app)
862 if (!obj->parent.app->atspi_version)
863 _atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion",
864 error, "s", &obj->parent.app->atspi_version);
866 return g_strdup (obj->parent.app->atspi_version);
870 * atspi_accessible_get_toolkit_version:
871 * @obj: a pointer to the #AtspiAccessible object on which to operate.
873 * Get the application id for a #AtspiAccessible object.
874 * Only works on application root objects.
876 * Returns: a gint indicating the id for the #AtspiAccessible object.
880 atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
884 g_return_val_if_fail (obj != NULL, -1);
886 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
892 /* Interface query methods */
895 _atspi_accessible_is_a (AtspiAccessible *accessible,
896 const char *interface_name)
900 if (accessible == NULL)
905 if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
908 DBusMessageIter iter;
909 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
910 "GetInterfaces", NULL, "");
911 _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
912 dbus_message_iter_init (reply, &iter);
913 _atspi_dbus_set_interfaces (accessible, &iter);
914 dbus_message_unref (reply);
915 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
918 n = _atspi_get_iface_num (interface_name);
919 if (n == -1) return FALSE;
920 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
924 * atspi_accessible_is_action:
925 * @obj: a pointer to the #AtspiAccessible instance to query.
927 * Query whether the specified #AtspiAccessible implements #AtspiAction.
929 * Returns: #TRUE if @obj implements the #AtspiAction interface,
933 atspi_accessible_is_action (AtspiAccessible *obj)
935 return _atspi_accessible_is_a (obj,
936 atspi_interface_action);
940 * atspi_accessible_is_application:
941 * @obj: a pointer to the #AtspiAccessible instance to query.
943 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
945 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
949 atspi_accessible_is_application (AtspiAccessible *obj)
951 return _atspi_accessible_is_a (obj,
952 atspi_interface_application);
956 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
958 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
959 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
963 atspi_accessible_is_collection (AtspiAccessible *obj)
965 return _atspi_accessible_is_a (obj,
966 atspi_interface_collection);
970 * atspi_accessible_is_component:
971 * @obj: a pointer to the #AtspiAccessible instance to query.
973 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
975 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
979 atspi_accessible_is_component (AtspiAccessible *obj)
981 return _atspi_accessible_is_a (obj,
982 atspi_interface_component);
986 * atspi_accessible_is_document:
987 * @obj: a pointer to the #AtspiAccessible instance to query.
989 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
991 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
995 atspi_accessible_is_document (AtspiAccessible *obj)
997 return _atspi_accessible_is_a (obj,
998 atspi_interface_document);
1002 * atspi_accessible_is_editable_text:
1003 * @obj: a pointer to the #AtspiAccessible instance to query.
1005 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
1007 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
1011 atspi_accessible_is_editable_text (AtspiAccessible *obj)
1013 return _atspi_accessible_is_a (obj,
1014 atspi_interface_editable_text);
1018 * atspi_accessible_is_hypertext:
1019 * @obj: a pointer to the #AtspiAccessible instance to query.
1021 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
1023 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1027 atspi_accessible_is_hypertext (AtspiAccessible *obj)
1029 return _atspi_accessible_is_a (obj,
1030 atspi_interface_hypertext);
1034 * atspi_accessible_is_hyperlink:
1035 * @obj: a pointer to the #AtspiAccessible instance to query.
1037 * Query whether the specified #AtspiAccessible implements #AtspiHyperlink.
1039 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1043 atspi_accessible_is_hyperlink (AtspiAccessible *obj)
1045 return _atspi_accessible_is_a (obj,
1046 atspi_interface_hyperlink);
1050 * atspi_accessible_is_image:
1051 * @obj: a pointer to the #AtspiAccessible instance to query.
1053 * Query whether the specified #AtspiAccessible implements #AtspiImage.
1055 * Returns: #TRUE if @obj implements the #AtspiImage interface,
1059 atspi_accessible_is_image (AtspiAccessible *obj)
1061 return _atspi_accessible_is_a (obj,
1062 atspi_interface_image);
1066 * atspi_accessible_is_selection:
1067 * @obj: a pointer to the #AtspiAccessible instance to query.
1069 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
1071 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
1075 atspi_accessible_is_selection (AtspiAccessible *obj)
1077 return _atspi_accessible_is_a (obj,
1078 atspi_interface_selection);
1082 * atspi_accessible_is_table:
1083 * @obj: a pointer to the #AtspiAccessible instance to query.
1085 * Query whether the specified #AtspiAccessible implements #AtspiTable.
1087 * Returns: #TRUE if @obj implements the #AtspiTable interface,
1091 atspi_accessible_is_table (AtspiAccessible *obj)
1093 return _atspi_accessible_is_a (obj,
1094 atspi_interface_table);
1098 * atspi_accessible_is_streamable_content:
1099 * @obj: a pointer to the #AtspiAccessible instance to query.
1101 * Query whether the specified #AtspiAccessible implements
1102 * #AtspiStreamableContent.
1104 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
1108 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
1111 return _atspi_accessible_is_a (obj,
1112 atspi_interface_streamable_content);
1114 g_warning ("Streamable content not implemented");
1120 * atspi_accessible_is_text:
1121 * @obj: a pointer to the #AtspiAccessible instance to query.
1123 * Query whether the specified #AtspiAccessible implements #AtspiText.
1125 * Returns: #TRUE if @obj implements the #AtspiText interface,
1129 atspi_accessible_is_text (AtspiAccessible *obj)
1131 return _atspi_accessible_is_a (obj,
1132 atspi_interface_text);
1136 * atspi_accessible_is_value:
1137 * @obj: a pointer to the #AtspiAccessible instance to query.
1139 * Query whether the specified #AtspiAccessible implements #AtspiValue.
1141 * Returns: #TRUE if @obj implements the #AtspiValue interface,
1145 atspi_accessible_is_value (AtspiAccessible *obj)
1147 return _atspi_accessible_is_a (obj,
1148 atspi_interface_value);
1152 * atspi_accessible_get_action:
1153 * @obj: a pointer to the #AtspiAccessible instance to query.
1155 * Get the #AtspiAction interface for an #AtspiAccessible.
1157 * Returns: (transfer full): a pointer to an #AtspiAction interface
1158 * instance, or NULL if @obj does not implement #AtspiAction.
1161 atspi_accessible_get_action (AtspiAccessible *accessible)
1163 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1164 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1168 * atspi_accessible_get_collection:
1169 * @obj: a pointer to the #AtspiAccessible instance to query.
1171 * Get the #AtspiCollection interface for an #AtspiAccessible.
1173 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1174 * instance, or NULL if @obj does not implement #AtspiCollection.
1177 atspi_accessible_get_collection (AtspiAccessible *accessible)
1179 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1180 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1184 * atspi_accessible_get_component:
1185 * @obj: a pointer to the #AtspiAccessible instance to query.
1187 * Get the #AtspiComponent interface for an #AtspiAccessible.
1189 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1190 * instance, or NULL if @obj does not implement #AtspiComponent.
1193 atspi_accessible_get_component (AtspiAccessible *obj)
1195 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1196 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1200 * atspi_accessible_get_document:
1201 * @obj: a pointer to the #AtspiAccessible instance to query.
1203 * Get the #AtspiDocument interface for an #AtspiAccessible.
1205 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1206 * instance, or NULL if @obj does not implement #AtspiDocument.
1209 atspi_accessible_get_document (AtspiAccessible *accessible)
1211 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1212 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1216 * atspi_accessible_get_editable_text:
1217 * @obj: a pointer to the #AtspiAccessible instance to query.
1219 * Get the #AtspiEditableText interface for an #AtspiAccessible.
1221 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1222 * instance, or NULL if @obj does not implement #AtspiEditableText.
1225 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1227 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1228 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1232 * atspi_accessible_get_hyperlink:
1233 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1235 * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
1238 * Returns: (transfer full): the #AtspiHyperlink object associated with
1239 * the given #AtspiAccessible, or NULL if not supported.
1242 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1244 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1245 atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1249 * atspi_accessible_get_hypertext:
1250 * @obj: a pointer to the #AtspiAccessible instance to query.
1252 * Get the #AtspiHypertext interface for an #AtspiAccessible.
1254 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1255 * instance, or NULL if @obj does not implement #AtspiHypertext.
1258 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1260 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1261 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1265 * atspi_accessible_get_image:
1266 * @obj: a pointer to the #AtspiAccessible instance to query.
1268 * Get the #AtspiImage interface for an #AtspiAccessible.
1270 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1271 * NULL if @obj does not implement #AtspiImage.
1274 atspi_accessible_get_image (AtspiAccessible *accessible)
1276 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1277 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1281 * atspi_accessible_get_selection:
1282 * @obj: a pointer to the #AtspiAccessible instance to query.
1284 * Get the #AtspiSelection interface for an #AtspiAccessible.
1286 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1287 * instance, or NULL if @obj does not implement #AtspiSelection.
1290 atspi_accessible_get_selection (AtspiAccessible *accessible)
1292 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1293 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1298 * atspi_accessible_get_streamable_content:
1299 * @obj: a pointer to the #AtspiAccessible instance to query.
1301 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1303 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1304 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1306 AtspiStreamableContent *
1307 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1309 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1315 * atspi_accessible_get_table:
1316 * @obj: a pointer to the #AtspiAccessible instance to query.
1318 * Get the #AtspiTable interface for an #AtspiAccessible.
1320 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1321 * NULL if @obj does not implement #AtspiTable.
1324 atspi_accessible_get_table (AtspiAccessible *obj)
1326 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1327 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1331 * atspi_accessible_get_text:
1332 * @obj: a pointer to the #AtspiAccessible instance to query.
1334 * Get the #AtspiTable interface for an #AtspiAccessible.
1336 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1337 * NULL if @obj does not implement #AtspiText.
1340 atspi_accessible_get_text (AtspiAccessible *obj)
1342 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1343 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1347 * atspi_accessible_get_value:
1348 * @obj: a pointer to the #AtspiAccessible instance to query.
1350 * Get the #AtspiTable interface for an #AtspiAccessible.
1352 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1353 * NULL if @obj does not implement #AtspiValue.
1356 atspi_accessible_get_value (AtspiAccessible *accessible)
1358 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1359 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1363 append_const_val (GArray *array, const gchar *val)
1365 gchar *dup = g_strdup (val);
1368 g_array_append_val (array, dup);
1372 * atspi_accessible_get_interfaces:
1374 * #obj: The #AtspiAccessible to query.
1376 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1377 * describing the interfaces supported by the object. Interfaces are
1378 * denoted in short-hand (ie, "Component", "Text", etc.)
1381 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1383 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1385 g_return_val_if_fail (obj != NULL, NULL);
1387 append_const_val (ret, "Accessible");
1388 if (atspi_accessible_is_action (obj))
1389 append_const_val (ret, "Action");
1390 if (atspi_accessible_is_collection (obj))
1391 append_const_val (ret, "Collection");
1392 if (atspi_accessible_is_component (obj))
1393 append_const_val (ret, "Component");
1394 if (atspi_accessible_is_document (obj))
1395 append_const_val (ret, "Document");
1396 if (atspi_accessible_is_editable_text (obj))
1397 append_const_val (ret, "EditableText");
1398 if (atspi_accessible_is_hypertext (obj))
1399 append_const_val (ret, "Hypertext");
1400 if (atspi_accessible_is_hyperlink (obj))
1401 append_const_val (ret, "Hyperlink");
1402 if (atspi_accessible_is_image (obj))
1403 append_const_val (ret, "Image");
1404 if (atspi_accessible_is_selection (obj))
1405 append_const_val (ret, "Selection");
1406 if (atspi_accessible_is_table (obj))
1407 append_const_val (ret, "Table");
1408 if (atspi_accessible_is_text (obj))
1409 append_const_val (ret, "Text");
1410 if (atspi_accessible_is_value (obj))
1411 append_const_val (ret, "Value");
1417 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1419 AtspiAccessible *accessible;
1421 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1422 g_return_val_if_fail (accessible != NULL, NULL);
1424 accessible->parent.app = g_object_ref (app);
1425 accessible->parent.path = g_strdup (path);
1431 * atspi_accessible_set_cache_mask:
1433 * @accessible: The #AtspiAccessible to operate on. Must be the desktop or
1434 * the root of an application.
1435 * @mask: An #AtspiCache specifying a bit mask of the types of data to cache.
1437 * Sets the type of data to cache for accessibles.
1438 * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
1439 * then the desktop's cache flag will be used.
1440 * If the desktop's cache flag is also undefined, then all possible data will
1442 * This function is intended to work around bugs in toolkits where the proper
1443 * events are not raised / to aid in testing for such bugs.
1446 atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
1448 g_return_if_fail (accessible != NULL);
1449 g_return_if_fail (accessible->parent.app != NULL);
1450 g_return_if_fail (accessible == accessible->parent.app->root);
1451 accessible->parent.app->cache = mask;
1455 * atspi_accessible_clear_cache:
1456 * @accessible: The #AtspiAccessible whose cache to clear.
1458 * Clears the cached information for the given accessible and all of its
1462 atspi_accessible_clear_cache (AtspiAccessible *accessible)
1468 accessible->cached_properties = ATSPI_CACHE_NONE;
1469 for (l = accessible->children; l; l = l->next)
1470 atspi_accessible_clear_cache (l->data);
1475 _atspi_accessible_get_cache_mask (AtspiAccessible *accessible)
1479 if (!accessible->parent.app)
1480 return ATSPI_CACHE_NONE;
1482 mask = accessible->parent.app->cache;
1483 if (mask == ATSPI_CACHE_UNDEFINED &&
1484 accessible->parent.app->root &&
1485 accessible->parent.app->root->accessible_parent)
1487 AtspiAccessible *desktop = atspi_get_desktop (0);
1488 mask = desktop->parent.app->cache;
1489 g_object_unref (desktop);
1492 if (mask == ATSPI_CACHE_UNDEFINED)
1493 mask = ATSPI_CACHE_DEFAULT;
1499 _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
1501 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1502 AtspiCache result = accessible->cached_properties & mask & flag;
1503 return (result != 0 && atspi_main_loop && !atspi_no_cache);
1507 _atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
1509 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1511 accessible->cached_properties |= flag & mask;