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",
262 "embedded component",
273 "input method window",
276 "document spreadsheet",
277 "document presentation",
289 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
292 * atspi_role_get_name
293 * @role: an #AtspiAccessibleRole object to query.
295 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
296 * <em>DEPRECATED.</em>
298 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
301 atspi_role_get_name (AtspiRole role)
303 if (role < MAX_ROLES && role_names [(int) role])
305 return g_strdup (role_names [(int) role]);
309 return g_strdup ("");
314 * atspi_accessible_get_name:
315 * @obj: a pointer to the #AtspiAccessible object on which to operate.
317 * Get the name of an #AtspiAccessible object.
319 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
320 * or NULL on exception
323 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
325 g_return_val_if_fail (obj != NULL, g_strdup (""));
326 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_NAME))
328 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
330 return g_strdup ("");
331 _atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
333 return g_strdup (obj->name);
337 * atspi_accessible_get_description:
338 * @obj: a pointer to the #AtspiAccessible object on which to operate.
340 * Get the description of an #AtspiAccessible object.
342 * Returns: a UTF-8 string describing the #AtspiAccessible object.
343 * or NULL on exception
346 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
348 g_return_val_if_fail (obj != NULL, g_strdup (""));
350 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_DESCRIPTION))
352 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
353 "Description", error, "s",
355 return g_strdup ("");
356 _atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
358 return g_strdup (obj->description);
361 const char *str_parent = "Parent";
364 * atspi_accessible_get_parent:
365 * @obj: a pointer to the #AtspiAccessible object to query.
367 * Get an #AtspiAccessible object's parent container.
369 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
370 * contains the given #AtspiAccessible instance, or NULL if the @obj
371 * has no parent container.
375 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
377 g_return_val_if_fail (obj != NULL, NULL);
379 if (obj->parent.app &&
380 !_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
382 DBusMessage *message, *reply;
383 DBusMessageIter iter, iter_variant;
384 message = dbus_message_new_method_call (obj->parent.app->bus_name,
386 DBUS_INTERFACE_PROPERTIES, "Get");
389 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
390 DBUS_TYPE_STRING, &str_parent,
392 reply = _atspi_dbus_send_with_reply_and_block (message, error);
395 if (strcmp (dbus_message_get_signature (reply), "v") != 0)
397 dbus_message_unref (reply);
400 dbus_message_iter_init (reply, &iter);
401 dbus_message_iter_recurse (&iter, &iter_variant);
402 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
403 dbus_message_unref (reply);
404 _atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
406 if (!obj->accessible_parent)
408 return g_object_ref (obj->accessible_parent);
412 * atspi_accessible_get_child_count:
413 * @obj: a pointer to the #AtspiAccessible object on which to operate.
415 * Get the number of children contained by an #AtspiAccessible object.
417 * Returns: a #long indicating the number of #AtspiAccessible children
418 * contained by an #AtspiAccessible object. or -1 on exception
422 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
424 g_return_val_if_fail (obj != NULL, -1);
426 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
429 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
430 "ChildCount", error, "i", &ret))
435 return g_list_length (obj->children);
439 * atspi_accessible_get_child_at_index:
440 * @obj: a pointer to the #AtspiAccessible object on which to operate.
441 * @child_index: a #long indicating which child is specified.
443 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
445 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
446 * index @child_index. or NULL on exception
449 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
453 AtspiAccessible *child;
455 g_return_val_if_fail (obj != NULL, NULL);
457 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
460 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
461 "GetChildAtIndex", error, "i",
463 return _atspi_dbus_return_accessible_from_message (reply);
466 child = g_list_nth_data (obj->children, child_index);
469 return g_object_ref (child);
473 * atspi_accessible_get_index_in_parent
474 * @obj: a pointer to the #AtspiAccessible object on which to operate.
476 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
478 * Returns: a #glong indicating the index of the #AtspiAccessible object
479 * in its parent (i.e. containing) #AtspiAccessible instance,
480 * or -1 if @obj has no containing parent or on exception.
483 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
488 g_return_val_if_fail (obj != NULL, -1);
489 if (!obj->accessible_parent) return -1;
490 if (!_atspi_accessible_test_cache (obj->accessible_parent,
491 ATSPI_CACHE_CHILDREN))
493 dbus_uint32_t ret = -1;
494 _atspi_dbus_call (obj, atspi_interface_accessible,
495 "GetIndexInParent", NULL, "=>u", &ret);
499 l = obj->accessible_parent->children;
502 if (l->data == obj) return i;
513 } Accessibility_Relation;
516 * atspi_accessible_get_relation_set:
517 * @obj: a pointer to the #AtspiAccessible object on which to operate.
519 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
520 * relationships with other #AtspiAccessible objects.
522 * Returns: (element-type AtspiAccessible*) (transfer full): an array of
523 * #AtspiAccessibleRelation pointers. or NULL on exception
526 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
529 DBusMessageIter iter, iter_array;
532 g_return_val_if_fail (obj != NULL, NULL);
534 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
537 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
539 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
540 dbus_message_iter_init (reply, &iter);
541 dbus_message_iter_recurse (&iter, &iter_array);
542 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
544 AtspiRelation *relation;
545 relation = _atspi_relation_new_from_iter (&iter_array);
546 ret = g_array_append_val (ret, relation);
547 dbus_message_iter_next (&iter_array);
549 dbus_message_unref (reply);
554 * atspi_accessible_get_role:
555 * @obj: a pointer to the #AtspiAccessible object on which to operate.
557 * Get the UI role of an #AtspiAccessible object.
558 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
560 * Returns: the #AtspiRole of the object.
564 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
566 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
568 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ROLE))
571 /* TODO: Make this a property */
572 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
575 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
582 * atspi_accessible_get_role_name:
583 * @obj: a pointer to the #AtspiAccessible object on which to operate.
585 * Get a UTF-8 string describing the role this object plays in the UI.
586 * This method will return useful values for roles that fall outside the
587 * enumeration used in atspi_accessible_getRole ().
589 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
593 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
598 g_return_val_if_fail (obj != NULL, NULL);
600 role = atspi_accessible_get_role (obj, error);
601 if (role >= 0 && role < MAX_ROLES && role != ATSPI_ROLE_EXTENDED)
602 return g_strdup (role_names [role]);
604 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
607 retval = g_strdup ("");
613 * atspi_accessible_get_localized_role_name:
614 * @obj: a pointer to the #AtspiAccessible object on which to operate.
616 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
617 * This method will return useful values for roles that fall outside the
618 * enumeration used in atspi_accessible_getRole ().
620 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
624 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
628 g_return_val_if_fail (obj != NULL, NULL);
630 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
633 return g_strdup ("");
638 static AtspiStateSet *
641 AtspiStateSet *set = atspi_state_set_new (NULL);
642 atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
647 * atspi_accessible_get_state_set:
648 * @obj: a pointer to the #AtspiAccessible object on which to operate.
650 * Gets the current state of an object.
652 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
653 * object's current state.
656 atspi_accessible_get_state_set (AtspiAccessible *obj)
658 if (!obj->parent.app || !obj->parent.app->bus)
659 return defunct_set ();
662 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
665 DBusMessageIter iter;
666 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
667 "GetState", NULL, "");
668 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
669 dbus_message_iter_init (reply, &iter);
670 _atspi_dbus_set_state (obj, &iter);
671 dbus_message_unref (reply);
672 _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
675 return g_object_ref (obj->states);
679 * atspi_accessible_get_attributes:
680 * @obj: The #AtspiAccessible being queried.
682 * Get the #AttributeSet representing any assigned
683 * name-value pair attributes or annotations for this object.
684 * For typographic, textual, or textually-semantic attributes, see
685 * atspi_text_get_attributes instead.
687 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
688 * attributes assigned to this object.
691 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
693 DBusMessage *message;
695 g_return_val_if_fail (obj != NULL, NULL);
697 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ATTRIBUTES))
699 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
700 "GetAttributes", error, "");
701 obj->attributes = _atspi_dbus_return_hash_from_message (message);
702 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ATTRIBUTES);
705 if (!obj->attributes)
707 return g_hash_table_ref (obj->attributes);
711 add_to_attribute_array (gpointer key, gpointer value, gpointer data)
713 GArray **array = (GArray **)data;
714 gchar *str = g_strconcat (key, ":", value, NULL);
715 *array = g_array_append_val (*array, str);
719 * atspi_accessible_get_attributes_as_array:
720 * @obj: The #AtspiAccessible being queried.
722 * Get the #AttributeSet representing any assigned
723 * name-value pair attributes or annotations for this object.
724 * For typographic, textual, or textually-semantic attributes, see
725 * atspi_text_get_attributes_as_array instead.
727 * Returns: (element-type gchar*) (transfer full): The name-value-pair
728 * attributes assigned to this object.
731 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
733 DBusMessage *message;
735 g_return_val_if_fail (obj != NULL, NULL);
737 if (_atspi_accessible_get_cache_mask (obj) & ATSPI_CACHE_ATTRIBUTES)
739 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
740 GHashTable *attributes = atspi_accessible_get_attributes (obj, error);
743 g_hash_table_foreach (attributes, add_to_attribute_array, &array);
744 g_hash_table_unref (attributes);
748 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
749 return _atspi_dbus_return_attribute_array_from_message (message);
753 * atspi_accessible_get_application:
754 * @obj: The #AtspiAccessible being queried.
756 * Get the containing #AtspiApplication for an object.
758 * Returns: (transfer full): the containing AtspiApplication instance for
762 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
764 AtspiAccessible *parent;
769 parent = atspi_accessible_get_parent (obj, NULL);
770 if (!parent && obj->parent.app &&
771 atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
773 AtspiAccessible *root = g_object_ref (obj->parent.app->root);
776 g_object_unref (obj);
777 if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
779 g_object_unref (root);
785 if (!parent || parent == obj ||
786 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
788 g_object_unref (obj);
793 /* Application-specific methods */
796 * atspi_accessible_get_toolkit_name:
797 * @obj: a pointer to the #AtspiAccessible object on which to operate.
799 * Get the toolkit for a #AtspiAccessible object.
800 * Only works on application root objects.
802 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
803 * or NULL on exception
806 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
808 g_return_val_if_fail (obj != NULL, NULL);
810 if (!obj->parent.app)
813 if (!obj->parent.app->toolkit_name)
814 _atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName",
815 error, "s", &obj->parent.app->toolkit_name);
817 return g_strdup (obj->parent.app->toolkit_name);
821 * atspi_accessible_get_toolkit_version:
822 * @obj: a pointer to the #AtspiAccessible object on which to operate.
824 * Get the toolkit version for a #AtspiAccessible object.
825 * Only works on application root objects.
827 * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
828 * or NULL on exception
831 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
833 g_return_val_if_fail (obj != NULL, NULL);
835 if (!obj->parent.app)
838 if (!obj->parent.app->toolkit_version)
839 _atspi_dbus_get_property (obj, atspi_interface_application, "Version",
840 error, "s", &obj->parent.app->toolkit_version);
842 return g_strdup (obj->parent.app->toolkit_version);
846 * atspi_accessible_get_atspi_version:
847 * @obj: a pointer to the #AtspiAccessible object on which to operate.
849 * Get the AT-SPI IPC specification version supported by the application
850 * pointed to by the #AtspiAccessible object.
851 * Only works on application root objects.
853 * Returns: a UTF-8 string indicating the AT-SPI ersion for the #AtspiAccessible object.
854 * or NULL on exception
857 atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
859 g_return_val_if_fail (obj != NULL, NULL);
861 if (!obj->parent.app)
864 if (!obj->parent.app->atspi_version)
865 _atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion",
866 error, "s", &obj->parent.app->atspi_version);
868 return g_strdup (obj->parent.app->atspi_version);
872 * atspi_accessible_get_toolkit_version:
873 * @obj: a pointer to the #AtspiAccessible object on which to operate.
875 * Get the application id for a #AtspiAccessible object.
876 * Only works on application root objects.
878 * Returns: a gint indicating the id for the #AtspiAccessible object.
882 atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
886 g_return_val_if_fail (obj != NULL, -1);
888 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
894 /* Interface query methods */
897 _atspi_accessible_is_a (AtspiAccessible *accessible,
898 const char *interface_name)
902 if (accessible == NULL)
907 if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
910 DBusMessageIter iter;
911 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
912 "GetInterfaces", NULL, "");
913 _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
914 dbus_message_iter_init (reply, &iter);
915 _atspi_dbus_set_interfaces (accessible, &iter);
916 dbus_message_unref (reply);
917 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
920 n = _atspi_get_iface_num (interface_name);
921 if (n == -1) return FALSE;
922 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
926 * atspi_accessible_is_action:
927 * @obj: a pointer to the #AtspiAccessible instance to query.
929 * Query whether the specified #AtspiAccessible implements #AtspiAction.
931 * Returns: #TRUE if @obj implements the #AtspiAction interface,
935 atspi_accessible_is_action (AtspiAccessible *obj)
937 return _atspi_accessible_is_a (obj,
938 atspi_interface_action);
942 * atspi_accessible_is_application:
943 * @obj: a pointer to the #AtspiAccessible instance to query.
945 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
947 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
951 atspi_accessible_is_application (AtspiAccessible *obj)
953 return _atspi_accessible_is_a (obj,
954 atspi_interface_application);
958 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
960 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
961 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
965 atspi_accessible_is_collection (AtspiAccessible *obj)
967 return _atspi_accessible_is_a (obj,
968 atspi_interface_collection);
972 * atspi_accessible_is_component:
973 * @obj: a pointer to the #AtspiAccessible instance to query.
975 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
977 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
981 atspi_accessible_is_component (AtspiAccessible *obj)
983 return _atspi_accessible_is_a (obj,
984 atspi_interface_component);
988 * atspi_accessible_is_document:
989 * @obj: a pointer to the #AtspiAccessible instance to query.
991 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
993 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
997 atspi_accessible_is_document (AtspiAccessible *obj)
999 return _atspi_accessible_is_a (obj,
1000 atspi_interface_document);
1004 * atspi_accessible_is_editable_text:
1005 * @obj: a pointer to the #AtspiAccessible instance to query.
1007 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
1009 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
1013 atspi_accessible_is_editable_text (AtspiAccessible *obj)
1015 return _atspi_accessible_is_a (obj,
1016 atspi_interface_editable_text);
1020 * atspi_accessible_is_hypertext:
1021 * @obj: a pointer to the #AtspiAccessible instance to query.
1023 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
1025 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1029 atspi_accessible_is_hypertext (AtspiAccessible *obj)
1031 return _atspi_accessible_is_a (obj,
1032 atspi_interface_hypertext);
1036 * atspi_accessible_is_hyperlink:
1037 * @obj: a pointer to the #AtspiAccessible instance to query.
1039 * Query whether the specified #AtspiAccessible implements #AtspiHyperlink.
1041 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1045 atspi_accessible_is_hyperlink (AtspiAccessible *obj)
1047 return _atspi_accessible_is_a (obj,
1048 atspi_interface_hyperlink);
1052 * atspi_accessible_is_image:
1053 * @obj: a pointer to the #AtspiAccessible instance to query.
1055 * Query whether the specified #AtspiAccessible implements #AtspiImage.
1057 * Returns: #TRUE if @obj implements the #AtspiImage interface,
1061 atspi_accessible_is_image (AtspiAccessible *obj)
1063 return _atspi_accessible_is_a (obj,
1064 atspi_interface_image);
1068 * atspi_accessible_is_selection:
1069 * @obj: a pointer to the #AtspiAccessible instance to query.
1071 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
1073 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
1077 atspi_accessible_is_selection (AtspiAccessible *obj)
1079 return _atspi_accessible_is_a (obj,
1080 atspi_interface_selection);
1084 * atspi_accessible_is_table:
1085 * @obj: a pointer to the #AtspiAccessible instance to query.
1087 * Query whether the specified #AtspiAccessible implements #AtspiTable.
1089 * Returns: #TRUE if @obj implements the #AtspiTable interface,
1093 atspi_accessible_is_table (AtspiAccessible *obj)
1095 return _atspi_accessible_is_a (obj,
1096 atspi_interface_table);
1100 * atspi_accessible_is_streamable_content:
1101 * @obj: a pointer to the #AtspiAccessible instance to query.
1103 * Query whether the specified #AtspiAccessible implements
1104 * #AtspiStreamableContent.
1106 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
1110 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
1113 return _atspi_accessible_is_a (obj,
1114 atspi_interface_streamable_content);
1116 g_warning ("Streamable content not implemented");
1122 * atspi_accessible_is_text:
1123 * @obj: a pointer to the #AtspiAccessible instance to query.
1125 * Query whether the specified #AtspiAccessible implements #AtspiText.
1127 * Returns: #TRUE if @obj implements the #AtspiText interface,
1131 atspi_accessible_is_text (AtspiAccessible *obj)
1133 return _atspi_accessible_is_a (obj,
1134 atspi_interface_text);
1138 * atspi_accessible_is_value:
1139 * @obj: a pointer to the #AtspiAccessible instance to query.
1141 * Query whether the specified #AtspiAccessible implements #AtspiValue.
1143 * Returns: #TRUE if @obj implements the #AtspiValue interface,
1147 atspi_accessible_is_value (AtspiAccessible *obj)
1149 return _atspi_accessible_is_a (obj,
1150 atspi_interface_value);
1154 * atspi_accessible_get_action:
1155 * @obj: a pointer to the #AtspiAccessible instance to query.
1157 * Get the #AtspiAction interface for an #AtspiAccessible.
1159 * Returns: (transfer full): a pointer to an #AtspiAction interface
1160 * instance, or NULL if @obj does not implement #AtspiAction.
1163 atspi_accessible_get_action (AtspiAccessible *accessible)
1165 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1166 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1170 * atspi_accessible_get_collection:
1171 * @obj: a pointer to the #AtspiAccessible instance to query.
1173 * Get the #AtspiCollection interface for an #AtspiAccessible.
1175 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1176 * instance, or NULL if @obj does not implement #AtspiCollection.
1179 atspi_accessible_get_collection (AtspiAccessible *accessible)
1181 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1182 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1186 * atspi_accessible_get_component:
1187 * @obj: a pointer to the #AtspiAccessible instance to query.
1189 * Get the #AtspiComponent interface for an #AtspiAccessible.
1191 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1192 * instance, or NULL if @obj does not implement #AtspiComponent.
1195 atspi_accessible_get_component (AtspiAccessible *obj)
1197 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1198 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1202 * atspi_accessible_get_document:
1203 * @obj: a pointer to the #AtspiAccessible instance to query.
1205 * Get the #AtspiDocument interface for an #AtspiAccessible.
1207 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1208 * instance, or NULL if @obj does not implement #AtspiDocument.
1211 atspi_accessible_get_document (AtspiAccessible *accessible)
1213 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1214 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1218 * atspi_accessible_get_editable_text:
1219 * @obj: a pointer to the #AtspiAccessible instance to query.
1221 * Get the #AtspiEditableText interface for an #AtspiAccessible.
1223 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1224 * instance, or NULL if @obj does not implement #AtspiEditableText.
1227 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1229 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1230 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1234 * atspi_accessible_get_hyperlink:
1235 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1237 * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
1240 * Returns: (transfer full): the #AtspiHyperlink object associated with
1241 * the given #AtspiAccessible, or NULL if not supported.
1244 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1246 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1247 _atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1251 * atspi_accessible_get_hypertext:
1252 * @obj: a pointer to the #AtspiAccessible instance to query.
1254 * Get the #AtspiHypertext interface for an #AtspiAccessible.
1256 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1257 * instance, or NULL if @obj does not implement #AtspiHypertext.
1260 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1262 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1263 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1267 * atspi_accessible_get_image:
1268 * @obj: a pointer to the #AtspiAccessible instance to query.
1270 * Get the #AtspiImage interface for an #AtspiAccessible.
1272 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1273 * NULL if @obj does not implement #AtspiImage.
1276 atspi_accessible_get_image (AtspiAccessible *accessible)
1278 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1279 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1283 * atspi_accessible_get_selection:
1284 * @obj: a pointer to the #AtspiAccessible instance to query.
1286 * Get the #AtspiSelection interface for an #AtspiAccessible.
1288 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1289 * instance, or NULL if @obj does not implement #AtspiSelection.
1292 atspi_accessible_get_selection (AtspiAccessible *accessible)
1294 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1295 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1300 * atspi_accessible_get_streamable_content:
1301 * @obj: a pointer to the #AtspiAccessible instance to query.
1303 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1305 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1306 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1308 AtspiStreamableContent *
1309 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1311 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1317 * atspi_accessible_get_table:
1318 * @obj: a pointer to the #AtspiAccessible instance to query.
1320 * Get the #AtspiTable interface for an #AtspiAccessible.
1322 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1323 * NULL if @obj does not implement #AtspiTable.
1326 atspi_accessible_get_table (AtspiAccessible *obj)
1328 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1329 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1333 * atspi_accessible_get_text:
1334 * @obj: a pointer to the #AtspiAccessible instance to query.
1336 * Get the #AtspiTable interface for an #AtspiAccessible.
1338 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1339 * NULL if @obj does not implement #AtspiText.
1342 atspi_accessible_get_text (AtspiAccessible *obj)
1344 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1345 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1349 * atspi_accessible_get_value:
1350 * @obj: a pointer to the #AtspiAccessible instance to query.
1352 * Get the #AtspiTable interface for an #AtspiAccessible.
1354 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1355 * NULL if @obj does not implement #AtspiValue.
1358 atspi_accessible_get_value (AtspiAccessible *accessible)
1360 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1361 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1365 append_const_val (GArray *array, const gchar *val)
1367 gchar *dup = g_strdup (val);
1370 g_array_append_val (array, dup);
1374 * atspi_accessible_get_interfaces:
1376 * #obj: The #AtspiAccessible to query.
1378 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1379 * describing the interfaces supported by the object. Interfaces are
1380 * denoted in short-hand (ie, "Component", "Text", etc.)
1383 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1385 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1387 g_return_val_if_fail (obj != NULL, NULL);
1389 append_const_val (ret, "Accessible");
1390 if (atspi_accessible_is_action (obj))
1391 append_const_val (ret, "Action");
1392 if (atspi_accessible_is_collection (obj))
1393 append_const_val (ret, "Collection");
1394 if (atspi_accessible_is_component (obj))
1395 append_const_val (ret, "Component");
1396 if (atspi_accessible_is_document (obj))
1397 append_const_val (ret, "Document");
1398 if (atspi_accessible_is_editable_text (obj))
1399 append_const_val (ret, "EditableText");
1400 if (atspi_accessible_is_hypertext (obj))
1401 append_const_val (ret, "Hypertext");
1402 if (atspi_accessible_is_hyperlink (obj))
1403 append_const_val (ret, "Hyperlink");
1404 if (atspi_accessible_is_image (obj))
1405 append_const_val (ret, "Image");
1406 if (atspi_accessible_is_selection (obj))
1407 append_const_val (ret, "Selection");
1408 if (atspi_accessible_is_table (obj))
1409 append_const_val (ret, "Table");
1410 if (atspi_accessible_is_text (obj))
1411 append_const_val (ret, "Text");
1412 if (atspi_accessible_is_value (obj))
1413 append_const_val (ret, "Value");
1419 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1421 AtspiAccessible *accessible;
1423 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1424 g_return_val_if_fail (accessible != NULL, NULL);
1426 accessible->parent.app = g_object_ref (app);
1427 accessible->parent.path = g_strdup (path);
1433 * atspi_accessible_set_cache_mask:
1435 * @accessible: The #AtspiAccessible to operate on. Must be the desktop or
1436 * the root of an application.
1437 * @mask: (type int): An #AtspiCache specifying a bit mask of the types of data to cache.
1439 * Sets the type of data to cache for accessibles.
1440 * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
1441 * then the desktop's cache flag will be used.
1442 * If the desktop's cache flag is also undefined, then all possible data will
1444 * This function is intended to work around bugs in toolkits where the proper
1445 * events are not raised / to aid in testing for such bugs.
1448 atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
1450 g_return_if_fail (accessible != NULL);
1451 g_return_if_fail (accessible->parent.app != NULL);
1452 g_return_if_fail (accessible == accessible->parent.app->root);
1453 accessible->parent.app->cache = mask;
1457 * atspi_accessible_clear_cache:
1458 * @accessible: The #AtspiAccessible whose cache to clear.
1460 * Clears the cached information for the given accessible and all of its
1464 atspi_accessible_clear_cache (AtspiAccessible *accessible)
1470 accessible->cached_properties = ATSPI_CACHE_NONE;
1471 for (l = accessible->children; l; l = l->next)
1472 atspi_accessible_clear_cache (l->data);
1477 * atspi_accessible_get_process_id:
1478 * @accessible: The #AtspiAccessible to query.
1480 * Returns the process id associated with the given accessible. Mainly
1481 * added for debugging; it is a shortcut to explicitly querying the
1482 * accessible's app->bus_name and then calling GetConnectionUnixProcessID.
1484 * Returns: The process ID, or -1 if defunct.
1487 atspi_accessible_get_process_id (AtspiAccessible *accessible, GError **error)
1489 DBusMessage *message, *reply;
1490 DBusConnection *bus = _atspi_bus ();
1491 dbus_uint32_t pid = -1;
1494 if (!accessible->parent.app || !accessible->parent.app->bus_name)
1497 message = dbus_message_new_method_call ("org.freedesktop.DBus",
1498 "/org/freedesktop/DBus",
1499 "org.freedesktop.DBus",
1500 "GetConnectionUnixProcessID");
1501 dbus_message_append_args (message, DBUS_TYPE_STRING,
1502 &accessible->parent.app->bus_name,
1504 dbus_error_init (&d_error);
1505 reply = dbus_connection_send_with_reply_and_block (bus, message, -1, &d_error);
1506 dbus_message_unref (message);
1507 dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &pid, DBUS_TYPE_INVALID);
1508 dbus_message_unref (reply);
1509 dbus_error_free (&d_error);
1514 _atspi_accessible_get_cache_mask (AtspiAccessible *accessible)
1518 if (!accessible->parent.app)
1519 return ATSPI_CACHE_NONE;
1521 mask = accessible->parent.app->cache;
1522 if (mask == ATSPI_CACHE_UNDEFINED &&
1523 accessible->parent.app->root &&
1524 accessible->parent.app->root->accessible_parent)
1526 AtspiAccessible *desktop = atspi_get_desktop (0);
1527 mask = desktop->parent.app->cache;
1528 g_object_unref (desktop);
1531 if (mask == ATSPI_CACHE_UNDEFINED)
1532 mask = ATSPI_CACHE_DEFAULT;
1538 _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
1540 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1541 AtspiCache result = accessible->cached_properties & mask & flag;
1542 return (result != 0 && atspi_main_loop && !atspi_no_cache);
1546 _atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
1548 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1550 accessible->cached_properties |= flag & mask;