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 [] =
241 "table-column-header",
243 "tear-off-menu-item",
273 "input method window"
276 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
279 * atspi_role_get_name
280 * @role: an #AtspiAccessibleRole object to query.
282 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
283 * <em>DEPRECATED.</em>
285 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
288 atspi_role_get_name (AtspiRole role)
290 if (role < MAX_ROLES && role_names [(int) role])
292 return g_strdup (role_names [(int) role]);
296 return g_strdup ("");
301 * atspi_accessible_get_name:
302 * @obj: a pointer to the #AtspiAccessible object on which to operate.
304 * Get the name of an #AtspiAccessible object.
306 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
307 * or NULL on exception
310 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
312 g_return_val_if_fail (obj != NULL, g_strdup (""));
313 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_NAME))
315 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
317 return g_strdup ("");
318 _atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
320 return g_strdup (obj->name);
324 * atspi_accessible_get_description:
325 * @obj: a pointer to the #AtspiAccessible object on which to operate.
327 * Get the description of an #AtspiAccessible object.
329 * Returns: a UTF-8 string describing the #AtspiAccessible object.
330 * or NULL on exception
333 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
335 g_return_val_if_fail (obj != NULL, g_strdup (""));
337 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_DESCRIPTION))
339 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
340 "Description", error, "s",
342 return g_strdup ("");
343 _atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
345 return g_strdup (obj->description);
348 const char *str_parent = "Parent";
351 * atspi_accessible_get_parent:
352 * @obj: a pointer to the #AtspiAccessible object to query.
354 * Get an #AtspiAccessible object's parent container.
356 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
357 * contains the given #AtspiAccessible instance, or NULL if the @obj
358 * has no parent container.
362 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
364 g_return_val_if_fail (obj != NULL, NULL);
366 if (obj->parent.app &&
367 !_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
369 DBusMessage *message, *reply;
370 DBusMessageIter iter, iter_variant;
371 message = dbus_message_new_method_call (obj->parent.app->bus_name,
373 DBUS_INTERFACE_PROPERTIES, "Get");
376 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
377 DBUS_TYPE_STRING, &str_parent,
379 reply = _atspi_dbus_send_with_reply_and_block (message, error);
382 if (strcmp (dbus_message_get_signature (reply), "v") != 0)
384 dbus_message_unref (reply);
387 dbus_message_iter_init (reply, &iter);
388 dbus_message_iter_recurse (&iter, &iter_variant);
389 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
390 dbus_message_unref (reply);
391 _atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
393 if (!obj->accessible_parent)
395 return g_object_ref (obj->accessible_parent);
399 * atspi_accessible_get_child_count:
400 * @obj: a pointer to the #AtspiAccessible object on which to operate.
402 * Get the number of children contained by an #AtspiAccessible object.
404 * Returns: a #long indicating the number of #AtspiAccessible children
405 * contained by an #AtspiAccessible object. or -1 on exception
409 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
411 g_return_val_if_fail (obj != NULL, -1);
413 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
416 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
417 "ChildCount", error, "i", &ret))
422 return g_list_length (obj->children);
426 * atspi_accessible_get_child_at_index:
427 * @obj: a pointer to the #AtspiAccessible object on which to operate.
428 * @child_index: a #long indicating which child is specified.
430 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
432 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
433 * index @child_index. or NULL on exception
436 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
440 AtspiAccessible *child;
442 g_return_val_if_fail (obj != NULL, NULL);
444 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
447 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
448 "GetChildAtIndex", error, "i",
450 return _atspi_dbus_return_accessible_from_message (reply);
453 child = g_list_nth_data (obj->children, child_index);
456 return g_object_ref (child);
460 * atspi_accessible_get_index_in_parent
461 * @obj: a pointer to the #AtspiAccessible object on which to operate.
463 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
465 * Returns: a #glong indicating the index of the #AtspiAccessible object
466 * in its parent (i.e. containing) #AtspiAccessible instance,
467 * or -1 if @obj has no containing parent or on exception.
470 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
475 g_return_val_if_fail (obj != NULL, -1);
476 if (!obj->accessible_parent) return -1;
477 if (!_atspi_accessible_test_cache (obj->accessible_parent,
478 ATSPI_CACHE_CHILDREN))
480 dbus_uint32_t ret = -1;
481 _atspi_dbus_call (obj, atspi_interface_accessible,
482 "GetIndexInParent", NULL, "=>u", &ret);
486 l = obj->accessible_parent->children;
489 if (l->data == obj) return i;
500 } Accessibility_Relation;
503 * atspi_accessible_get_relation_set:
504 * @obj: a pointer to the #AtspiAccessible object on which to operate.
506 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
507 * relationships with other #AtspiAccessible objects.
509 * Returns: (element-type AtspiAccessible*) (transfer full): an array of
510 * #AtspiAccessibleRelation pointers. or NULL on exception
513 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
516 DBusMessageIter iter, iter_array;
519 g_return_val_if_fail (obj != NULL, NULL);
521 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
524 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
526 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
527 dbus_message_iter_init (reply, &iter);
528 dbus_message_iter_recurse (&iter, &iter_array);
529 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
531 AtspiRelation *relation;
532 relation = _atspi_relation_new_from_iter (&iter_array);
533 ret = g_array_append_val (ret, relation);
534 dbus_message_iter_next (&iter_array);
536 dbus_message_unref (reply);
541 * atspi_accessible_get_role:
542 * @obj: a pointer to the #AtspiAccessible object on which to operate.
544 * Get the UI role of an #AtspiAccessible object.
545 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
547 * Returns: the #AtspiRole of the object.
551 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
553 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
555 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ROLE))
558 /* TODO: Make this a property */
559 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
562 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
569 * atspi_accessible_get_role_name:
570 * @obj: a pointer to the #AtspiAccessible object on which to operate.
572 * Get a UTF-8 string describing the role this object plays in the UI.
573 * This method will return useful values for roles that fall outside the
574 * enumeration used in atspi_accessible_getRole ().
576 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
580 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
585 g_return_val_if_fail (obj != NULL, NULL);
587 role = atspi_accessible_get_role (obj, error);
588 if (role >= 0 && role < MAX_ROLES && role != ATSPI_ROLE_EXTENDED)
589 return g_strdup (role_names [role]);
591 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
594 retval = g_strdup ("");
600 * atspi_accessible_get_localized_role_name:
601 * @obj: a pointer to the #AtspiAccessible object on which to operate.
603 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
604 * This method will return useful values for roles that fall outside the
605 * enumeration used in atspi_accessible_getRole ().
607 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
611 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
615 g_return_val_if_fail (obj != NULL, NULL);
617 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
620 return g_strdup ("");
625 static AtspiStateSet *
628 AtspiStateSet *set = atspi_state_set_new (NULL);
629 atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
634 * atspi_accessible_get_state_set:
635 * @obj: a pointer to the #AtspiAccessible object on which to operate.
637 * Gets the current state of an object.
639 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
640 * object's current state.
643 atspi_accessible_get_state_set (AtspiAccessible *obj)
645 if (!obj->parent.app || !obj->parent.app->bus)
646 return defunct_set ();
649 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
652 DBusMessageIter iter;
653 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
654 "GetState", NULL, "");
655 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
656 dbus_message_iter_init (reply, &iter);
657 _atspi_dbus_set_state (obj, &iter);
658 dbus_message_unref (reply);
659 _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
662 return g_object_ref (obj->states);
666 * atspi_accessible_get_attributes:
667 * @obj: The #AtspiAccessible being queried.
669 * Get the #AttributeSet representing any assigned
670 * name-value pair attributes or annotations for this object.
671 * For typographic, textual, or textually-semantic attributes, see
672 * atspi_text_get_attributes instead.
674 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
675 * attributes assigned to this object.
678 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
680 DBusMessage *message;
682 g_return_val_if_fail (obj != NULL, NULL);
684 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ATTRIBUTES))
686 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
687 "GetAttributes", error, "");
688 obj->attributes = _atspi_dbus_return_hash_from_message (message);
689 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ATTRIBUTES);
692 if (!obj->attributes)
694 return g_hash_table_ref (obj->attributes);
698 add_to_attribute_array (gpointer key, gpointer value, gpointer data)
700 GArray **array = (GArray **)data;
701 gchar *str = g_strconcat (key, ":", value, NULL);
702 *array = g_array_append_val (*array, str);
706 * atspi_accessible_get_attributes_as_array:
707 * @obj: The #AtspiAccessible being queried.
709 * Get the #AttributeSet representing any assigned
710 * name-value pair attributes or annotations for this object.
711 * For typographic, textual, or textually-semantic attributes, see
712 * atspi_text_get_attributes_as_array instead.
714 * Returns: (element-type gchar*) (transfer full): The name-value-pair
715 * attributes assigned to this object.
718 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
720 DBusMessage *message;
722 g_return_val_if_fail (obj != NULL, NULL);
724 if (_atspi_accessible_get_cache_mask (obj) & ATSPI_CACHE_ATTRIBUTES)
726 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
727 GHashTable *attributes = atspi_accessible_get_attributes (obj, error);
730 g_hash_table_foreach (attributes, add_to_attribute_array, &array);
731 g_hash_table_unref (attributes);
735 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
736 return _atspi_dbus_return_attribute_array_from_message (message);
740 * atspi_accessible_get_application:
741 * @obj: The #AtspiAccessible being queried.
743 * Get the containing #AtspiApplication for an object.
745 * Returns: (transfer full): the containing AtspiApplication instance for
749 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
751 AtspiAccessible *parent;
756 parent = atspi_accessible_get_parent (obj, NULL);
757 if (!parent && obj->parent.app &&
758 atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
760 AtspiAccessible *root = g_object_ref (obj->parent.app->root);
763 g_object_unref (obj);
764 if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
766 g_object_unref (root);
772 if (!parent || parent == obj ||
773 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
775 g_object_unref (obj);
780 /* Application-specific methods */
783 * atspi_accessible_get_toolkit_name:
784 * @obj: a pointer to the #AtspiAccessible object on which to operate.
786 * Get the toolkit for a #AtspiAccessible object.
787 * Only works on application root objects.
789 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
790 * or NULL on exception
793 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
795 g_return_val_if_fail (obj != NULL, NULL);
797 if (!obj->parent.app)
800 if (!obj->parent.app->toolkit_name)
801 _atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName",
802 error, "s", &obj->parent.app->toolkit_name);
804 return g_strdup (obj->parent.app->toolkit_name);
808 * atspi_accessible_get_toolkit_version:
809 * @obj: a pointer to the #AtspiAccessible object on which to operate.
811 * Get the toolkit version for a #AtspiAccessible object.
812 * Only works on application root objects.
814 * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
815 * or NULL on exception
818 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
820 g_return_val_if_fail (obj != NULL, NULL);
822 if (!obj->parent.app)
825 if (!obj->parent.app->toolkit_version)
826 _atspi_dbus_get_property (obj, atspi_interface_application, "Version",
827 error, "s", &obj->parent.app->toolkit_version);
829 return g_strdup (obj->parent.app->toolkit_version);
833 * atspi_accessible_get_atspi_version:
834 * @obj: a pointer to the #AtspiAccessible object on which to operate.
836 * Get the AT-SPI IPC specification version supported by the application
837 * pointed to by the #AtspiAccessible object.
838 * Only works on application root objects.
840 * Returns: a UTF-8 string indicating the AT-SPI ersion for the #AtspiAccessible object.
841 * or NULL on exception
844 atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
846 g_return_val_if_fail (obj != NULL, NULL);
848 if (!obj->parent.app)
851 if (!obj->parent.app->atspi_version)
852 _atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion",
853 error, "s", &obj->parent.app->atspi_version);
855 return g_strdup (obj->parent.app->atspi_version);
859 * atspi_accessible_get_toolkit_version:
860 * @obj: a pointer to the #AtspiAccessible object on which to operate.
862 * Get the application id for a #AtspiAccessible object.
863 * Only works on application root objects.
865 * Returns: a gint indicating the id for the #AtspiAccessible object.
869 atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
873 g_return_val_if_fail (obj != NULL, -1);
875 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
881 /* Interface query methods */
884 _atspi_accessible_is_a (AtspiAccessible *accessible,
885 const char *interface_name)
889 if (accessible == NULL)
894 if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
897 DBusMessageIter iter;
898 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
899 "GetInterfaces", NULL, "");
900 _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
901 dbus_message_iter_init (reply, &iter);
902 _atspi_dbus_set_interfaces (accessible, &iter);
903 dbus_message_unref (reply);
904 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
907 n = _atspi_get_iface_num (interface_name);
908 if (n == -1) return FALSE;
909 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
913 * atspi_accessible_is_action:
914 * @obj: a pointer to the #AtspiAccessible instance to query.
916 * Query whether the specified #AtspiAccessible implements #AtspiAction.
918 * Returns: #TRUE if @obj implements the #AtspiAction interface,
922 atspi_accessible_is_action (AtspiAccessible *obj)
924 return _atspi_accessible_is_a (obj,
925 atspi_interface_action);
929 * atspi_accessible_is_application:
930 * @obj: a pointer to the #AtspiAccessible instance to query.
932 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
934 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
938 atspi_accessible_is_application (AtspiAccessible *obj)
940 return _atspi_accessible_is_a (obj,
941 atspi_interface_application);
945 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
947 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
948 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
952 atspi_accessible_is_collection (AtspiAccessible *obj)
954 return _atspi_accessible_is_a (obj,
955 atspi_interface_collection);
959 * atspi_accessible_is_component:
960 * @obj: a pointer to the #AtspiAccessible instance to query.
962 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
964 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
968 atspi_accessible_is_component (AtspiAccessible *obj)
970 return _atspi_accessible_is_a (obj,
971 atspi_interface_component);
975 * atspi_accessible_is_document:
976 * @obj: a pointer to the #AtspiAccessible instance to query.
978 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
980 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
984 atspi_accessible_is_document (AtspiAccessible *obj)
986 return _atspi_accessible_is_a (obj,
987 atspi_interface_document);
991 * atspi_accessible_is_editable_text:
992 * @obj: a pointer to the #AtspiAccessible instance to query.
994 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
996 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
1000 atspi_accessible_is_editable_text (AtspiAccessible *obj)
1002 return _atspi_accessible_is_a (obj,
1003 atspi_interface_editable_text);
1007 * atspi_accessible_is_hypertext:
1008 * @obj: a pointer to the #AtspiAccessible instance to query.
1010 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
1012 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1016 atspi_accessible_is_hypertext (AtspiAccessible *obj)
1018 return _atspi_accessible_is_a (obj,
1019 atspi_interface_hypertext);
1023 * atspi_accessible_is_hyperlink:
1024 * @obj: a pointer to the #AtspiAccessible instance to query.
1026 * Query whether the specified #AtspiAccessible implements #AtspiHyperlink.
1028 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1032 atspi_accessible_is_hyperlink (AtspiAccessible *obj)
1034 return _atspi_accessible_is_a (obj,
1035 atspi_interface_hyperlink);
1039 * atspi_accessible_is_image:
1040 * @obj: a pointer to the #AtspiAccessible instance to query.
1042 * Query whether the specified #AtspiAccessible implements #AtspiImage.
1044 * Returns: #TRUE if @obj implements the #AtspiImage interface,
1048 atspi_accessible_is_image (AtspiAccessible *obj)
1050 return _atspi_accessible_is_a (obj,
1051 atspi_interface_image);
1055 * atspi_accessible_is_selection:
1056 * @obj: a pointer to the #AtspiAccessible instance to query.
1058 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
1060 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
1064 atspi_accessible_is_selection (AtspiAccessible *obj)
1066 return _atspi_accessible_is_a (obj,
1067 atspi_interface_selection);
1071 * atspi_accessible_is_table:
1072 * @obj: a pointer to the #AtspiAccessible instance to query.
1074 * Query whether the specified #AtspiAccessible implements #AtspiTable.
1076 * Returns: #TRUE if @obj implements the #AtspiTable interface,
1080 atspi_accessible_is_table (AtspiAccessible *obj)
1082 return _atspi_accessible_is_a (obj,
1083 atspi_interface_table);
1087 * atspi_accessible_is_streamable_content:
1088 * @obj: a pointer to the #AtspiAccessible instance to query.
1090 * Query whether the specified #AtspiAccessible implements
1091 * #AtspiStreamableContent.
1093 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
1097 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
1100 return _atspi_accessible_is_a (obj,
1101 atspi_interface_streamable_content);
1103 g_warning ("Streamable content not implemented");
1109 * atspi_accessible_is_text:
1110 * @obj: a pointer to the #AtspiAccessible instance to query.
1112 * Query whether the specified #AtspiAccessible implements #AtspiText.
1114 * Returns: #TRUE if @obj implements the #AtspiText interface,
1118 atspi_accessible_is_text (AtspiAccessible *obj)
1120 return _atspi_accessible_is_a (obj,
1121 atspi_interface_text);
1125 * atspi_accessible_is_value:
1126 * @obj: a pointer to the #AtspiAccessible instance to query.
1128 * Query whether the specified #AtspiAccessible implements #AtspiValue.
1130 * Returns: #TRUE if @obj implements the #AtspiValue interface,
1134 atspi_accessible_is_value (AtspiAccessible *obj)
1136 return _atspi_accessible_is_a (obj,
1137 atspi_interface_value);
1141 * atspi_accessible_get_action:
1142 * @obj: a pointer to the #AtspiAccessible instance to query.
1144 * Get the #AtspiAction interface for an #AtspiAccessible.
1146 * Returns: (transfer full): a pointer to an #AtspiAction interface
1147 * instance, or NULL if @obj does not implement #AtspiAction.
1150 atspi_accessible_get_action (AtspiAccessible *accessible)
1152 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1153 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1157 * atspi_accessible_get_collection:
1158 * @obj: a pointer to the #AtspiAccessible instance to query.
1160 * Get the #AtspiCollection interface for an #AtspiAccessible.
1162 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1163 * instance, or NULL if @obj does not implement #AtspiCollection.
1166 atspi_accessible_get_collection (AtspiAccessible *accessible)
1168 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1169 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1173 * atspi_accessible_get_component:
1174 * @obj: a pointer to the #AtspiAccessible instance to query.
1176 * Get the #AtspiComponent interface for an #AtspiAccessible.
1178 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1179 * instance, or NULL if @obj does not implement #AtspiComponent.
1182 atspi_accessible_get_component (AtspiAccessible *obj)
1184 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1185 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1189 * atspi_accessible_get_document:
1190 * @obj: a pointer to the #AtspiAccessible instance to query.
1192 * Get the #AtspiDocument interface for an #AtspiAccessible.
1194 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1195 * instance, or NULL if @obj does not implement #AtspiDocument.
1198 atspi_accessible_get_document (AtspiAccessible *accessible)
1200 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1201 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1205 * atspi_accessible_get_editable_text:
1206 * @obj: a pointer to the #AtspiAccessible instance to query.
1208 * Get the #AtspiEditableText interface for an #AtspiAccessible.
1210 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1211 * instance, or NULL if @obj does not implement #AtspiEditableText.
1214 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1216 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1217 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1221 * atspi_accessible_get_hyperlink:
1222 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1224 * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
1227 * Returns: (transfer full): the #AtspiHyperlink object associated with
1228 * the given #AtspiAccessible, or NULL if not supported.
1231 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1233 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1234 atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1238 * atspi_accessible_get_hypertext:
1239 * @obj: a pointer to the #AtspiAccessible instance to query.
1241 * Get the #AtspiHypertext interface for an #AtspiAccessible.
1243 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1244 * instance, or NULL if @obj does not implement #AtspiHypertext.
1247 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1249 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1250 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1254 * atspi_accessible_get_image:
1255 * @obj: a pointer to the #AtspiAccessible instance to query.
1257 * Get the #AtspiImage interface for an #AtspiAccessible.
1259 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1260 * NULL if @obj does not implement #AtspiImage.
1263 atspi_accessible_get_image (AtspiAccessible *accessible)
1265 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1266 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1270 * atspi_accessible_get_selection:
1271 * @obj: a pointer to the #AtspiAccessible instance to query.
1273 * Get the #AtspiSelection interface for an #AtspiAccessible.
1275 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1276 * instance, or NULL if @obj does not implement #AtspiSelection.
1279 atspi_accessible_get_selection (AtspiAccessible *accessible)
1281 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1282 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1287 * atspi_accessible_get_streamable_content:
1288 * @obj: a pointer to the #AtspiAccessible instance to query.
1290 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1292 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1293 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1295 AtspiStreamableContent *
1296 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1298 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1304 * atspi_accessible_get_table:
1305 * @obj: a pointer to the #AtspiAccessible instance to query.
1307 * Get the #AtspiTable interface for an #AtspiAccessible.
1309 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1310 * NULL if @obj does not implement #AtspiTable.
1313 atspi_accessible_get_table (AtspiAccessible *obj)
1315 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1316 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1320 * atspi_accessible_get_text:
1321 * @obj: a pointer to the #AtspiAccessible instance to query.
1323 * Get the #AtspiTable interface for an #AtspiAccessible.
1325 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1326 * NULL if @obj does not implement #AtspiText.
1329 atspi_accessible_get_text (AtspiAccessible *obj)
1331 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1332 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1336 * atspi_accessible_get_value:
1337 * @obj: a pointer to the #AtspiAccessible instance to query.
1339 * Get the #AtspiTable interface for an #AtspiAccessible.
1341 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1342 * NULL if @obj does not implement #AtspiValue.
1345 atspi_accessible_get_value (AtspiAccessible *accessible)
1347 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1348 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1352 append_const_val (GArray *array, const gchar *val)
1354 gchar *dup = g_strdup (val);
1357 g_array_append_val (array, dup);
1361 * atspi_accessible_get_interfaces:
1363 * #obj: The #AtspiAccessible to query.
1365 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1366 * describing the interfaces supported by the object. Interfaces are
1367 * denoted in short-hand (ie, "Component", "Text", etc.)
1370 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1372 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1374 g_return_val_if_fail (obj != NULL, NULL);
1376 append_const_val (ret, "Accessible");
1377 if (atspi_accessible_is_action (obj))
1378 append_const_val (ret, "Action");
1379 if (atspi_accessible_is_collection (obj))
1380 append_const_val (ret, "Collection");
1381 if (atspi_accessible_is_component (obj))
1382 append_const_val (ret, "Component");
1383 if (atspi_accessible_is_document (obj))
1384 append_const_val (ret, "Document");
1385 if (atspi_accessible_is_editable_text (obj))
1386 append_const_val (ret, "EditableText");
1387 if (atspi_accessible_is_hypertext (obj))
1388 append_const_val (ret, "Hypertext");
1389 if (atspi_accessible_is_hyperlink (obj))
1390 append_const_val (ret, "Hyperlink");
1391 if (atspi_accessible_is_image (obj))
1392 append_const_val (ret, "Image");
1393 if (atspi_accessible_is_selection (obj))
1394 append_const_val (ret, "Selection");
1395 if (atspi_accessible_is_table (obj))
1396 append_const_val (ret, "Table");
1397 if (atspi_accessible_is_text (obj))
1398 append_const_val (ret, "Text");
1399 if (atspi_accessible_is_value (obj))
1400 append_const_val (ret, "Value");
1406 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1408 AtspiAccessible *accessible;
1410 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1411 g_return_val_if_fail (accessible != NULL, NULL);
1413 accessible->parent.app = g_object_ref (app);
1414 accessible->parent.path = g_strdup (path);
1420 * atspi_accessible_set_cache_mask:
1422 * @accessible: The #AtspiAccessible to operate on. Must be the desktop or
1423 * the root of an application.
1424 * @mask: (type int): An #AtspiCache specifying a bit mask of the types of data to cache.
1426 * Sets the type of data to cache for accessibles.
1427 * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
1428 * then the desktop's cache flag will be used.
1429 * If the desktop's cache flag is also undefined, then all possible data will
1431 * This function is intended to work around bugs in toolkits where the proper
1432 * events are not raised / to aid in testing for such bugs.
1435 atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
1437 g_return_if_fail (accessible != NULL);
1438 g_return_if_fail (accessible->parent.app != NULL);
1439 g_return_if_fail (accessible == accessible->parent.app->root);
1440 accessible->parent.app->cache = mask;
1444 * atspi_accessible_clear_cache:
1445 * @accessible: The #AtspiAccessible whose cache to clear.
1447 * Clears the cached information for the given accessible and all of its
1451 atspi_accessible_clear_cache (AtspiAccessible *accessible)
1457 accessible->cached_properties = ATSPI_CACHE_NONE;
1458 for (l = accessible->children; l; l = l->next)
1459 atspi_accessible_clear_cache (l->data);
1464 _atspi_accessible_get_cache_mask (AtspiAccessible *accessible)
1468 if (!accessible->parent.app)
1469 return ATSPI_CACHE_NONE;
1471 mask = accessible->parent.app->cache;
1472 if (mask == ATSPI_CACHE_UNDEFINED &&
1473 accessible->parent.app->root &&
1474 accessible->parent.app->root->accessible_parent)
1476 AtspiAccessible *desktop = atspi_get_desktop (0);
1477 mask = desktop->parent.app->cache;
1478 g_object_unref (desktop);
1481 if (mask == ATSPI_CACHE_UNDEFINED)
1482 mask = ATSPI_CACHE_DEFAULT;
1488 _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
1490 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1491 AtspiCache result = accessible->cached_properties & mask & flag;
1492 return (result != 0 && atspi_main_loop && !atspi_no_cache);
1496 _atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
1498 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1500 accessible->cached_properties |= flag & mask;