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)
583 g_return_val_if_fail (obj != NULL, NULL);
585 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
588 retval = g_strdup ("");
594 * atspi_accessible_get_localized_role_name:
595 * @obj: a pointer to the #AtspiAccessible object on which to operate.
597 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
598 * This method will return useful values for roles that fall outside the
599 * enumeration used in atspi_accessible_getRole ().
601 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
605 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
609 g_return_val_if_fail (obj != NULL, NULL);
611 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
614 return g_strdup ("");
619 static AtspiStateSet *
622 AtspiStateSet *set = atspi_state_set_new (NULL);
623 atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
628 * atspi_accessible_get_state_set:
629 * @obj: a pointer to the #AtspiAccessible object on which to operate.
631 * Gets the current state of an object.
633 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
634 * object's current state.
637 atspi_accessible_get_state_set (AtspiAccessible *obj)
639 if (!obj->parent.app || !obj->parent.app->bus)
640 return defunct_set ();
643 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
646 DBusMessageIter iter;
647 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
648 "GetState", NULL, "");
649 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
650 dbus_message_iter_init (reply, &iter);
651 _atspi_dbus_set_state (obj, &iter);
652 dbus_message_unref (reply);
653 _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
656 return g_object_ref (obj->states);
660 * atspi_accessible_get_attributes:
661 * @obj: The #AtspiAccessible being queried.
663 * Get the #AttributeSet representing any assigned
664 * name-value pair attributes or annotations for this object.
665 * For typographic, textual, or textually-semantic attributes, see
666 * atspi_text_get_attributes instead.
668 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
669 * attributes assigned to this object.
672 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
674 DBusMessage *message;
676 g_return_val_if_fail (obj != NULL, NULL);
678 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ATTRIBUTES))
680 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
681 "GetAttributes", error, "");
682 obj->attributes = _atspi_dbus_return_hash_from_message (message);
683 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ATTRIBUTES);
686 if (!obj->attributes)
688 return g_hash_table_ref (obj->attributes);
692 add_to_attribute_array (gpointer key, gpointer value, gpointer data)
694 GArray **array = (GArray **)data;
695 gchar *str = g_strconcat (key, ":", value, NULL);
696 *array = g_array_append_val (*array, str);
700 * atspi_accessible_get_attributes_as_array:
701 * @obj: The #AtspiAccessible being queried.
703 * Get the #AttributeSet representing any assigned
704 * name-value pair attributes or annotations for this object.
705 * For typographic, textual, or textually-semantic attributes, see
706 * atspi_text_get_attributes_as_array instead.
708 * Returns: (element-type gchar*) (transfer full): The name-value-pair
709 * attributes assigned to this object.
712 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
714 DBusMessage *message;
716 g_return_val_if_fail (obj != NULL, NULL);
718 if (_atspi_accessible_get_cache_mask (obj) & ATSPI_CACHE_ATTRIBUTES)
720 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
721 GHashTable *attributes = atspi_accessible_get_attributes (obj, error);
724 g_hash_table_foreach (attributes, add_to_attribute_array, &array);
725 g_hash_table_unref (attributes);
729 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
730 return _atspi_dbus_return_attribute_array_from_message (message);
734 * atspi_accessible_get_application:
735 * @obj: The #AtspiAccessible being queried.
737 * Get the containing #AtspiApplication for an object.
739 * Returns: (transfer full): the containing AtspiApplication instance for
743 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
745 AtspiAccessible *parent;
750 parent = atspi_accessible_get_parent (obj, NULL);
751 if (!parent && obj->parent.app &&
752 atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
754 AtspiAccessible *root = g_object_ref (obj->parent.app->root);
757 g_object_unref (obj);
758 if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
760 g_object_unref (root);
766 if (!parent || parent == obj ||
767 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
769 g_object_unref (obj);
774 /* Application-specific methods */
777 * atspi_accessible_get_toolkit_name:
778 * @obj: a pointer to the #AtspiAccessible object on which to operate.
780 * Get the toolkit for a #AtspiAccessible object.
781 * Only works on application root objects.
783 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
784 * or NULL on exception
787 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
789 g_return_val_if_fail (obj != NULL, NULL);
791 if (!obj->parent.app)
794 if (!obj->parent.app->toolkit_name)
795 _atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName",
796 error, "s", &obj->parent.app->toolkit_name);
798 return g_strdup (obj->parent.app->toolkit_name);
802 * atspi_accessible_get_toolkit_version:
803 * @obj: a pointer to the #AtspiAccessible object on which to operate.
805 * Get the toolkit version for a #AtspiAccessible object.
806 * Only works on application root objects.
808 * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
809 * or NULL on exception
812 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
814 g_return_val_if_fail (obj != NULL, NULL);
816 if (!obj->parent.app)
819 if (!obj->parent.app->toolkit_version)
820 _atspi_dbus_get_property (obj, atspi_interface_application, "Version",
821 error, "s", &obj->parent.app->toolkit_version);
823 return g_strdup (obj->parent.app->toolkit_version);
827 * atspi_accessible_get_atspi_version:
828 * @obj: a pointer to the #AtspiAccessible object on which to operate.
830 * Get the AT-SPI IPC specification version supported by the application
831 * pointed to by the #AtspiAccessible object.
832 * Only works on application root objects.
834 * Returns: a UTF-8 string indicating the AT-SPI ersion for the #AtspiAccessible object.
835 * or NULL on exception
838 atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
840 g_return_val_if_fail (obj != NULL, NULL);
842 if (!obj->parent.app)
845 if (!obj->parent.app->atspi_version)
846 _atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion",
847 error, "s", &obj->parent.app->atspi_version);
849 return g_strdup (obj->parent.app->atspi_version);
853 * atspi_accessible_get_toolkit_version:
854 * @obj: a pointer to the #AtspiAccessible object on which to operate.
856 * Get the application id for a #AtspiAccessible object.
857 * Only works on application root objects.
859 * Returns: a gint indicating the id for the #AtspiAccessible object.
863 atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
867 g_return_val_if_fail (obj != NULL, -1);
869 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
875 /* Interface query methods */
878 _atspi_accessible_is_a (AtspiAccessible *accessible,
879 const char *interface_name)
883 if (accessible == NULL)
888 if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
891 DBusMessageIter iter;
892 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
893 "GetInterfaces", NULL, "");
894 _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
895 dbus_message_iter_init (reply, &iter);
896 _atspi_dbus_set_interfaces (accessible, &iter);
897 dbus_message_unref (reply);
898 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
901 n = _atspi_get_iface_num (interface_name);
902 if (n == -1) return FALSE;
903 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
907 * atspi_accessible_is_action:
908 * @obj: a pointer to the #AtspiAccessible instance to query.
910 * Query whether the specified #AtspiAccessible implements #AtspiAction.
912 * Returns: #TRUE if @obj implements the #AtspiAction interface,
916 atspi_accessible_is_action (AtspiAccessible *obj)
918 return _atspi_accessible_is_a (obj,
919 atspi_interface_action);
923 * atspi_accessible_is_application:
924 * @obj: a pointer to the #AtspiAccessible instance to query.
926 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
928 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
932 atspi_accessible_is_application (AtspiAccessible *obj)
934 return _atspi_accessible_is_a (obj,
935 atspi_interface_application);
939 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
941 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
942 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
946 atspi_accessible_is_collection (AtspiAccessible *obj)
948 return _atspi_accessible_is_a (obj,
949 atspi_interface_collection);
953 * atspi_accessible_is_component:
954 * @obj: a pointer to the #AtspiAccessible instance to query.
956 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
958 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
962 atspi_accessible_is_component (AtspiAccessible *obj)
964 return _atspi_accessible_is_a (obj,
965 atspi_interface_component);
969 * atspi_accessible_is_document:
970 * @obj: a pointer to the #AtspiAccessible instance to query.
972 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
974 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
978 atspi_accessible_is_document (AtspiAccessible *obj)
980 return _atspi_accessible_is_a (obj,
981 atspi_interface_document);
985 * atspi_accessible_is_editable_text:
986 * @obj: a pointer to the #AtspiAccessible instance to query.
988 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
990 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
994 atspi_accessible_is_editable_text (AtspiAccessible *obj)
996 return _atspi_accessible_is_a (obj,
997 atspi_interface_editable_text);
1001 * atspi_accessible_is_hypertext:
1002 * @obj: a pointer to the #AtspiAccessible instance to query.
1004 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
1006 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1010 atspi_accessible_is_hypertext (AtspiAccessible *obj)
1012 return _atspi_accessible_is_a (obj,
1013 atspi_interface_hypertext);
1017 * atspi_accessible_is_hyperlink:
1018 * @obj: a pointer to the #AtspiAccessible instance to query.
1020 * Query whether the specified #AtspiAccessible implements #AtspiHyperlink.
1022 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1026 atspi_accessible_is_hyperlink (AtspiAccessible *obj)
1028 return _atspi_accessible_is_a (obj,
1029 atspi_interface_hyperlink);
1033 * atspi_accessible_is_image:
1034 * @obj: a pointer to the #AtspiAccessible instance to query.
1036 * Query whether the specified #AtspiAccessible implements #AtspiImage.
1038 * Returns: #TRUE if @obj implements the #AtspiImage interface,
1042 atspi_accessible_is_image (AtspiAccessible *obj)
1044 return _atspi_accessible_is_a (obj,
1045 atspi_interface_image);
1049 * atspi_accessible_is_selection:
1050 * @obj: a pointer to the #AtspiAccessible instance to query.
1052 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
1054 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
1058 atspi_accessible_is_selection (AtspiAccessible *obj)
1060 return _atspi_accessible_is_a (obj,
1061 atspi_interface_selection);
1065 * atspi_accessible_is_table:
1066 * @obj: a pointer to the #AtspiAccessible instance to query.
1068 * Query whether the specified #AtspiAccessible implements #AtspiTable.
1070 * Returns: #TRUE if @obj implements the #AtspiTable interface,
1074 atspi_accessible_is_table (AtspiAccessible *obj)
1076 return _atspi_accessible_is_a (obj,
1077 atspi_interface_table);
1081 * atspi_accessible_is_streamable_content:
1082 * @obj: a pointer to the #AtspiAccessible instance to query.
1084 * Query whether the specified #AtspiAccessible implements
1085 * #AtspiStreamableContent.
1087 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
1091 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
1094 return _atspi_accessible_is_a (obj,
1095 atspi_interface_streamable_content);
1097 g_warning ("Streamable content not implemented");
1103 * atspi_accessible_is_text:
1104 * @obj: a pointer to the #AtspiAccessible instance to query.
1106 * Query whether the specified #AtspiAccessible implements #AtspiText.
1108 * Returns: #TRUE if @obj implements the #AtspiText interface,
1112 atspi_accessible_is_text (AtspiAccessible *obj)
1114 return _atspi_accessible_is_a (obj,
1115 atspi_interface_text);
1119 * atspi_accessible_is_value:
1120 * @obj: a pointer to the #AtspiAccessible instance to query.
1122 * Query whether the specified #AtspiAccessible implements #AtspiValue.
1124 * Returns: #TRUE if @obj implements the #AtspiValue interface,
1128 atspi_accessible_is_value (AtspiAccessible *obj)
1130 return _atspi_accessible_is_a (obj,
1131 atspi_interface_value);
1135 * atspi_accessible_get_action:
1136 * @obj: a pointer to the #AtspiAccessible instance to query.
1138 * Get the #AtspiAction interface for an #AtspiAccessible.
1140 * Returns: (transfer full): a pointer to an #AtspiAction interface
1141 * instance, or NULL if @obj does not implement #AtspiAction.
1144 atspi_accessible_get_action (AtspiAccessible *accessible)
1146 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1147 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1151 * atspi_accessible_get_collection:
1152 * @obj: a pointer to the #AtspiAccessible instance to query.
1154 * Get the #AtspiCollection interface for an #AtspiAccessible.
1156 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1157 * instance, or NULL if @obj does not implement #AtspiCollection.
1160 atspi_accessible_get_collection (AtspiAccessible *accessible)
1162 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1163 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1167 * atspi_accessible_get_component:
1168 * @obj: a pointer to the #AtspiAccessible instance to query.
1170 * Get the #AtspiComponent interface for an #AtspiAccessible.
1172 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1173 * instance, or NULL if @obj does not implement #AtspiComponent.
1176 atspi_accessible_get_component (AtspiAccessible *obj)
1178 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1179 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1183 * atspi_accessible_get_document:
1184 * @obj: a pointer to the #AtspiAccessible instance to query.
1186 * Get the #AtspiDocument interface for an #AtspiAccessible.
1188 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1189 * instance, or NULL if @obj does not implement #AtspiDocument.
1192 atspi_accessible_get_document (AtspiAccessible *accessible)
1194 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1195 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1199 * atspi_accessible_get_editable_text:
1200 * @obj: a pointer to the #AtspiAccessible instance to query.
1202 * Get the #AtspiEditableText interface for an #AtspiAccessible.
1204 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1205 * instance, or NULL if @obj does not implement #AtspiEditableText.
1208 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1210 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1211 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1215 * atspi_accessible_get_hyperlink:
1216 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1218 * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
1221 * Returns: (transfer full): the #AtspiHyperlink object associated with
1222 * the given #AtspiAccessible, or NULL if not supported.
1225 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1227 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1228 atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1232 * atspi_accessible_get_hypertext:
1233 * @obj: a pointer to the #AtspiAccessible instance to query.
1235 * Get the #AtspiHypertext interface for an #AtspiAccessible.
1237 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1238 * instance, or NULL if @obj does not implement #AtspiHypertext.
1241 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1243 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1244 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1248 * atspi_accessible_get_image:
1249 * @obj: a pointer to the #AtspiAccessible instance to query.
1251 * Get the #AtspiImage interface for an #AtspiAccessible.
1253 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1254 * NULL if @obj does not implement #AtspiImage.
1257 atspi_accessible_get_image (AtspiAccessible *accessible)
1259 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1260 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1264 * atspi_accessible_get_selection:
1265 * @obj: a pointer to the #AtspiAccessible instance to query.
1267 * Get the #AtspiSelection interface for an #AtspiAccessible.
1269 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1270 * instance, or NULL if @obj does not implement #AtspiSelection.
1273 atspi_accessible_get_selection (AtspiAccessible *accessible)
1275 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1276 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1281 * atspi_accessible_get_streamable_content:
1282 * @obj: a pointer to the #AtspiAccessible instance to query.
1284 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1286 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1287 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1289 AtspiStreamableContent *
1290 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1292 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1298 * atspi_accessible_get_table:
1299 * @obj: a pointer to the #AtspiAccessible instance to query.
1301 * Get the #AtspiTable interface for an #AtspiAccessible.
1303 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1304 * NULL if @obj does not implement #AtspiTable.
1307 atspi_accessible_get_table (AtspiAccessible *obj)
1309 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1310 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1314 * atspi_accessible_get_text:
1315 * @obj: a pointer to the #AtspiAccessible instance to query.
1317 * Get the #AtspiTable interface for an #AtspiAccessible.
1319 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1320 * NULL if @obj does not implement #AtspiText.
1323 atspi_accessible_get_text (AtspiAccessible *obj)
1325 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1326 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1330 * atspi_accessible_get_value:
1331 * @obj: a pointer to the #AtspiAccessible instance to query.
1333 * Get the #AtspiTable interface for an #AtspiAccessible.
1335 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1336 * NULL if @obj does not implement #AtspiValue.
1339 atspi_accessible_get_value (AtspiAccessible *accessible)
1341 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1342 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1346 append_const_val (GArray *array, const gchar *val)
1348 gchar *dup = g_strdup (val);
1351 g_array_append_val (array, dup);
1355 * atspi_accessible_get_interfaces:
1357 * #obj: The #AtspiAccessible to query.
1359 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1360 * describing the interfaces supported by the object. Interfaces are
1361 * denoted in short-hand (ie, "Component", "Text", etc.)
1364 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1366 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1368 g_return_val_if_fail (obj != NULL, NULL);
1370 append_const_val (ret, "Accessible");
1371 if (atspi_accessible_is_action (obj))
1372 append_const_val (ret, "Action");
1373 if (atspi_accessible_is_collection (obj))
1374 append_const_val (ret, "Collection");
1375 if (atspi_accessible_is_component (obj))
1376 append_const_val (ret, "Component");
1377 if (atspi_accessible_is_document (obj))
1378 append_const_val (ret, "Document");
1379 if (atspi_accessible_is_editable_text (obj))
1380 append_const_val (ret, "EditableText");
1381 if (atspi_accessible_is_hypertext (obj))
1382 append_const_val (ret, "Hypertext");
1383 if (atspi_accessible_is_hyperlink (obj))
1384 append_const_val (ret, "Hyperlink");
1385 if (atspi_accessible_is_image (obj))
1386 append_const_val (ret, "Image");
1387 if (atspi_accessible_is_selection (obj))
1388 append_const_val (ret, "Selection");
1389 if (atspi_accessible_is_table (obj))
1390 append_const_val (ret, "Table");
1391 if (atspi_accessible_is_text (obj))
1392 append_const_val (ret, "Text");
1393 if (atspi_accessible_is_value (obj))
1394 append_const_val (ret, "Value");
1400 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1402 AtspiAccessible *accessible;
1404 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1405 g_return_val_if_fail (accessible != NULL, NULL);
1407 accessible->parent.app = g_object_ref (app);
1408 accessible->parent.path = g_strdup (path);
1414 * atspi_accessible_set_cache_mask:
1416 * @accessible: The #AtspiAccessible to operate on. Must be the desktop or
1417 * the root of an application.
1418 * @mask: (type int): An #AtspiCache specifying a bit mask of the types of data to cache.
1420 * Sets the type of data to cache for accessibles.
1421 * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
1422 * then the desktop's cache flag will be used.
1423 * If the desktop's cache flag is also undefined, then all possible data will
1425 * This function is intended to work around bugs in toolkits where the proper
1426 * events are not raised / to aid in testing for such bugs.
1429 atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
1431 g_return_if_fail (accessible != NULL);
1432 g_return_if_fail (accessible->parent.app != NULL);
1433 g_return_if_fail (accessible == accessible->parent.app->root);
1434 accessible->parent.app->cache = mask;
1438 * atspi_accessible_clear_cache:
1439 * @accessible: The #AtspiAccessible whose cache to clear.
1441 * Clears the cached information for the given accessible and all of its
1445 atspi_accessible_clear_cache (AtspiAccessible *accessible)
1451 accessible->cached_properties = ATSPI_CACHE_NONE;
1452 for (l = accessible->children; l; l = l->next)
1453 atspi_accessible_clear_cache (l->data);
1458 _atspi_accessible_get_cache_mask (AtspiAccessible *accessible)
1462 if (!accessible->parent.app)
1463 return ATSPI_CACHE_NONE;
1465 mask = accessible->parent.app->cache;
1466 if (mask == ATSPI_CACHE_UNDEFINED &&
1467 accessible->parent.app->root &&
1468 accessible->parent.app->root->accessible_parent)
1470 AtspiAccessible *desktop = atspi_get_desktop (0);
1471 mask = desktop->parent.app->cache;
1472 g_object_unref (desktop);
1475 if (mask == ATSPI_CACHE_UNDEFINED)
1476 mask = ATSPI_CACHE_DEFAULT;
1482 _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
1484 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1485 AtspiCache result = accessible->cached_properties & mask & flag;
1486 return (result != 0 && atspi_main_loop && !atspi_no_cache);
1490 _atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
1492 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1494 accessible->cached_properties |= flag & mask;