2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
7 * Copyright 2010, 2011 Novell, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
25 #include "atspi-private.h"
28 static gboolean enable_caching = FALSE;
31 atspi_action_interface_init (AtspiAction *action)
36 atspi_collection_interface_init (AtspiCollection *component)
41 atspi_component_interface_init (AtspiComponent *component)
46 atspi_document_interface_init (AtspiDocument *document)
51 atspi_editable_text_interface_init (AtspiEditableText *editable_text)
56 atspi_hypertext_interface_init (AtspiHypertext *hypertext)
61 atspi_image_interface_init (AtspiImage *image)
66 atspi_selection_interface_init (AtspiSelection *selection)
71 atspi_table_interface_init (AtspiTable *table)
76 atspi_text_interface_init (AtspiText *text)
81 atspi_value_interface_init (AtspiValue *value)
85 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT,
86 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init)
87 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COLLECTION, atspi_collection_interface_init)
88 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
89 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_DOCUMENT, atspi_document_interface_init)
90 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init)
91 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_HYPERTEXT, atspi_hypertext_interface_init)
92 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init)
93 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init)
94 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
95 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init)
96 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_VALUE, atspi_value_interface_init))
98 #ifdef DEBUG_REF_COUNTS
99 static gint accessible_count = 0;
103 atspi_accessible_init (AtspiAccessible *accessible)
105 #ifdef DEBUG_REF_COUNTS
107 g_print("at-spi: init: %d objects\n", accessible_count);
112 atspi_accessible_dispose (GObject *object)
114 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
116 AtspiAccessible *parent;
120 /* TODO: Only fire if object not already marked defunct */
121 memset (&e, 0, sizeof (e));
122 e.type = "object:state-changed:defunct";
123 e.source = accessible;
126 _atspi_send_event (&e);
128 if (accessible->states)
130 g_object_unref (accessible->states);
131 accessible->states = NULL;
134 parent = accessible->accessible_parent;
135 if (parent && parent->children)
137 GList*ls = g_list_find (parent->children, accessible);
140 gboolean replace = (ls == parent->children);
141 ls = g_list_remove (ls, accessible);
143 parent->children = ls;
144 g_object_unref (object);
150 g_object_unref (parent);
151 accessible->accessible_parent = NULL;
154 children = accessible->children;
155 accessible->children = NULL;
156 for (l = children; l; l = l->next)
158 AtspiAccessible *child = l->data;
159 if (child && child->accessible_parent == accessible)
161 g_object_unref (accessible);
162 child->accessible_parent = NULL;
164 g_object_unref (child);
166 g_list_free (children);
168 G_OBJECT_CLASS (atspi_accessible_parent_class) ->dispose (object);
172 atspi_accessible_finalize (GObject *object)
174 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
176 g_free (accessible->description);
177 g_free (accessible->name);
178 if (accessible->attributes)
179 g_hash_table_unref (accessible->attributes);
181 #ifdef DEBUG_REF_COUNTS
183 g_print ("at-spi: finalize: %d objects\n", accessible_count);
186 G_OBJECT_CLASS (atspi_accessible_parent_class)
191 atspi_accessible_class_init (AtspiAccessibleClass *klass)
193 GObjectClass *object_class = G_OBJECT_CLASS (klass);
195 object_class->dispose = atspi_accessible_dispose;
196 object_class->finalize = atspi_accessible_finalize;
199 /* TODO: Generate following from spec? */
200 static const char *role_names [] =
259 "table column header",
261 "tear off menu item",
280 "embedded component",
291 "input method window",
294 "document spreadsheet",
295 "document presentation",
307 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
310 * atspi_role_get_name:
311 * @role: an #AtspiRole object to query.
313 * Gets a localizable string that indicates the name of an #AtspiRole.
314 * <em>DEPRECATED.</em>
316 * Returns: a localizable string name for an #AtspiRole enumerated type.
319 atspi_role_get_name (AtspiRole role)
321 if (role < MAX_ROLES && role_names [(int) role])
323 return g_strdup (role_names [(int) role]);
327 return g_strdup ("");
332 * atspi_accessible_get_name:
333 * @obj: a pointer to the #AtspiAccessible object on which to operate.
335 * Gets the name of an #AtspiAccessible object.
337 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object
338 * or NULL on exception.
341 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
343 g_return_val_if_fail (obj != NULL, g_strdup (""));
344 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_NAME))
346 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
348 return g_strdup ("");
349 _atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
351 return g_strdup (obj->name);
355 * atspi_accessible_get_description:
356 * @obj: a pointer to the #AtspiAccessible object on which to operate.
358 * Gets the description of an #AtspiAccessible object.
360 * Returns: a UTF-8 string describing the #AtspiAccessible object
361 * or NULL on exception.
364 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
366 g_return_val_if_fail (obj != NULL, g_strdup (""));
368 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_DESCRIPTION))
370 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
371 "Description", error, "s",
373 return g_strdup ("");
374 _atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
376 return g_strdup (obj->description);
379 const char *str_parent = "Parent";
382 * atspi_accessible_get_parent:
383 * @obj: a pointer to the #AtspiAccessible object to query.
385 * Gets an #AtspiAccessible object's parent container.
387 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
388 * contains the given #AtspiAccessible instance, or NULL if the @obj
389 * has no parent container.
393 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
395 g_return_val_if_fail (obj != NULL, NULL);
397 if (obj->parent.app &&
398 !_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
400 DBusMessage *message, *reply;
401 DBusMessageIter iter, iter_variant;
402 message = dbus_message_new_method_call (obj->parent.app->bus_name,
404 DBUS_INTERFACE_PROPERTIES, "Get");
407 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
408 DBUS_TYPE_STRING, &str_parent,
410 reply = _atspi_dbus_send_with_reply_and_block (message, error);
413 if (strcmp (dbus_message_get_signature (reply), "v") != 0)
415 dbus_message_unref (reply);
418 dbus_message_iter_init (reply, &iter);
419 dbus_message_iter_recurse (&iter, &iter_variant);
420 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
421 dbus_message_unref (reply);
422 _atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
424 if (!obj->accessible_parent)
426 return g_object_ref (obj->accessible_parent);
430 * atspi_accessible_get_child_count:
431 * @obj: a pointer to the #AtspiAccessible object on which to operate.
433 * Gets the number of children contained by an #AtspiAccessible object.
435 * Returns: a #long indicating the number of #AtspiAccessible children
436 * contained by an #AtspiAccessible object or -1 on exception.
440 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
442 g_return_val_if_fail (obj != NULL, -1);
444 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
447 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
448 "ChildCount", error, "i", &ret))
453 return g_list_length (obj->children);
457 * atspi_accessible_get_child_at_index:
458 * @obj: a pointer to the #AtspiAccessible object on which to operate.
459 * @child_index: a #long indicating which child is specified.
461 * Gets the #AtspiAccessible child of an #AtspiAccessible object at a given index.
463 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
464 * index @child_index or NULL on exception.
467 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
471 AtspiAccessible *child;
473 g_return_val_if_fail (obj != NULL, NULL);
475 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
478 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
479 "GetChildAtIndex", error, "i",
481 return _atspi_dbus_return_accessible_from_message (reply);
484 child = g_list_nth_data (obj->children, child_index);
487 return g_object_ref (child);
491 * atspi_accessible_get_index_in_parent:
492 * @obj: a pointer to the #AtspiAccessible object on which to operate.
494 * Gets the index of an #AtspiAccessible object within its parent's
495 * #AtspiAccessible children list.
497 * Returns: a #glong indicating the index of the #AtspiAccessible object
499 * or -1 if @obj has no containing parent or on exception.
502 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
507 g_return_val_if_fail (obj != NULL, -1);
508 if (_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT) &&
509 !obj->accessible_parent)
511 if (!obj->accessible_parent ||
512 !_atspi_accessible_test_cache (obj->accessible_parent,
513 ATSPI_CACHE_CHILDREN))
515 dbus_int32_t ret = -1;
516 _atspi_dbus_call (obj, atspi_interface_accessible,
517 "GetIndexInParent", NULL, "=>i", &ret);
521 l = obj->accessible_parent->children;
524 if (l->data == obj) return i;
535 } Accessibility_Relation;
538 * atspi_accessible_get_relation_set:
539 * @obj: a pointer to the #AtspiAccessible object on which to operate.
541 * Gets the set of #AtspiRelation objects which describes this #AtspiAccessible object's
542 * relationships with other #AtspiAccessible objects.
544 * Returns: (element-type AtspiAccessible*) (transfer full): a #GArray of
545 * #AtspiRelation pointers or NULL on exception.
548 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
551 DBusMessageIter iter, iter_array;
554 g_return_val_if_fail (obj != NULL, NULL);
556 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
559 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
561 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
562 dbus_message_iter_init (reply, &iter);
563 dbus_message_iter_recurse (&iter, &iter_array);
564 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
566 AtspiRelation *relation;
567 relation = _atspi_relation_new_from_iter (&iter_array);
568 ret = g_array_append_val (ret, relation);
569 dbus_message_iter_next (&iter_array);
571 dbus_message_unref (reply);
576 * atspi_accessible_get_role:
577 * @obj: a pointer to the #AtspiAccessible object on which to operate.
579 * Gets the UI role played by an #AtspiAccessible object.
580 * This role's name can be obtained via atspi_accessible_get_role_name ().
582 * Returns: the #AtspiRole of an #AtspiAccessible object.
586 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
588 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
590 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ROLE))
593 /* TODO: Make this a property */
594 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
597 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
604 * atspi_accessible_get_role_name:
605 * @obj: a pointer to the #AtspiAccessible object on which to operate.
607 * Gets a UTF-8 string corresponding to the name of the role played by an object.
608 * This method will return useful values for roles that fall outside the
609 * enumeration used in atspi_accessible_get_role ().
611 * Returns: a UTF-8 string specifying the type of UI role played by an
612 * #AtspiAccessible object.
616 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
621 g_return_val_if_fail (obj != NULL, NULL);
623 role = atspi_accessible_get_role (obj, error);
624 if (role >= 0 && role < MAX_ROLES && role != ATSPI_ROLE_EXTENDED)
625 return g_strdup (role_names [role]);
627 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
630 retval = g_strdup ("");
636 * atspi_accessible_get_localized_role_name:
637 * @obj: a pointer to the #AtspiAccessible object on which to operate.
639 * Gets a UTF-8 string corresponding to the name of the role played by an
640 * object, translated to the current locale.
641 * This method will return useful values for roles that fall outside the
642 * enumeration used in atspi_accessible_getRole ().
644 * Returns: a localized, UTF-8 string specifying the type of UI role played
645 * by an #AtspiAccessible object.
649 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
653 g_return_val_if_fail (obj != NULL, NULL);
655 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
658 return g_strdup ("");
663 static AtspiStateSet *
666 AtspiStateSet *set = atspi_state_set_new (NULL);
667 atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
672 * atspi_accessible_get_state_set:
673 * @obj: a pointer to the #AtspiAccessible object on which to operate.
675 * Gets the states currently held by an object.
677 * Returns: (transfer full): a pointer to an #AtspiStateSet representing an
678 * object's current state set.
681 atspi_accessible_get_state_set (AtspiAccessible *obj)
683 /* TODO: Should take a GError **, but would be an API break */
684 if (!obj->parent.app || !obj->parent.app->bus)
685 return defunct_set ();
687 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
690 DBusMessageIter iter;
691 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
692 "GetState", NULL, "");
693 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
694 dbus_message_iter_init (reply, &iter);
695 _atspi_dbus_set_state (obj, &iter);
696 dbus_message_unref (reply);
697 _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
700 return g_object_ref (obj->states);
704 * atspi_accessible_get_attributes:
705 * @obj: The #AtspiAccessible being queried.
707 * Gets the #AttributeSet representing any assigned
708 * name-value pair attributes or annotations for this object.
709 * For typographic, textual, or textually-semantic attributes, see
710 * atspi_text_get_attributes instead.
712 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
713 * attributes assigned to this object.
716 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
718 DBusMessage *message;
720 g_return_val_if_fail (obj != NULL, NULL);
722 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ATTRIBUTES))
724 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
725 "GetAttributes", error, "");
726 obj->attributes = _atspi_dbus_return_hash_from_message (message);
727 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ATTRIBUTES);
730 if (!obj->attributes)
732 return g_hash_table_ref (obj->attributes);
736 add_to_attribute_array (gpointer key, gpointer value, gpointer data)
738 GArray **array = (GArray **)data;
739 gchar *str = g_strconcat (key, ":", value, NULL);
740 *array = g_array_append_val (*array, str);
744 * atspi_accessible_get_attributes_as_array:
745 * @obj: The #AtspiAccessible being queried.
747 * Gets a #GArray representing any assigned
748 * name-value pair attributes or annotations for this object.
749 * For typographic, textual, or textually-semantic attributes, see
750 * atspi_text_get_attributes_as_array instead.
752 * Returns: (element-type gchar*) (transfer full): The name-value-pair
753 * attributes assigned to this object.
756 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
758 DBusMessage *message;
760 g_return_val_if_fail (obj != NULL, NULL);
762 if (_atspi_accessible_get_cache_mask (obj) & ATSPI_CACHE_ATTRIBUTES)
764 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
765 GHashTable *attributes = atspi_accessible_get_attributes (obj, error);
768 g_hash_table_foreach (attributes, add_to_attribute_array, &array);
769 g_hash_table_unref (attributes);
773 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
774 return _atspi_dbus_return_attribute_array_from_message (message);
778 * atspi_accessible_get_application:
779 * @obj: The #AtspiAccessible being queried.
781 * Gets the containing #AtspiApplication for an object.
783 * Returns: (transfer full): the containing #AtspiApplication instance for
787 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
789 AtspiAccessible *parent;
794 parent = atspi_accessible_get_parent (obj, NULL);
795 if (!parent && obj->parent.app &&
796 atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
798 AtspiAccessible *root = g_object_ref (obj->parent.app->root);
801 g_object_unref (obj);
802 if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
804 g_object_unref (root);
810 if (!parent || parent == obj ||
811 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
813 g_object_unref (obj);
818 /* Application-specific methods */
821 * atspi_accessible_get_toolkit_name:
822 * @obj: a pointer to the #AtspiAccessible object on which to operate.
824 * Gets the toolkit name for an #AtspiAccessible object.
825 * Only works on application root objects.
827 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object or NULL on exception.
830 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
832 g_return_val_if_fail (obj != NULL, NULL);
834 if (!obj->parent.app)
837 if (!obj->parent.app->toolkit_name)
838 _atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName",
839 error, "s", &obj->parent.app->toolkit_name);
841 return g_strdup (obj->parent.app->toolkit_name);
845 * atspi_accessible_get_toolkit_version:
846 * @obj: a pointer to the #AtspiAccessible object on which to operate.
848 * Gets the toolkit version for an #AtspiAccessible object.
849 * Only works on application root objects.
851 * Returns: a UTF-8 string indicating the toolkit version for the #AtspiAccessible object or NULL on exception.
854 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
856 g_return_val_if_fail (obj != NULL, NULL);
858 if (!obj->parent.app)
861 if (!obj->parent.app->toolkit_version)
862 _atspi_dbus_get_property (obj, atspi_interface_application, "Version",
863 error, "s", &obj->parent.app->toolkit_version);
865 return g_strdup (obj->parent.app->toolkit_version);
869 * atspi_accessible_get_atspi_version:
870 * @obj: a pointer to the #AtspiAccessible object on which to operate.
872 * Gets the AT-SPI IPC specification version supported by the application
873 * pointed to by the #AtspiAccessible object.
874 * Only works on application root objects.
876 * Returns: a UTF-8 string indicating the AT-SPI version for the #AtspiAccessible object or NULL on exception.
879 atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
881 g_return_val_if_fail (obj != NULL, NULL);
883 if (!obj->parent.app)
886 if (!obj->parent.app->atspi_version)
887 _atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion",
888 error, "s", &obj->parent.app->atspi_version);
890 return g_strdup (obj->parent.app->atspi_version);
894 * atspi_accessible_get_id:
895 * @obj: a pointer to the #AtspiAccessible object on which to operate.
897 * Gets the application id for a #AtspiAccessible object.
898 * Only works on application root objects.
900 * Returns: a positive #gint indicating the id for the #AtspiAccessible object
901 * or -1 on exception.
904 atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
908 g_return_val_if_fail (obj != NULL, -1);
910 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
916 /* Interface query methods */
919 _atspi_accessible_is_a (AtspiAccessible *accessible,
920 const char *interface_name)
924 if (accessible == NULL)
929 if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
932 DBusMessageIter iter;
933 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
934 "GetInterfaces", NULL, "");
935 _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
936 dbus_message_iter_init (reply, &iter);
937 _atspi_dbus_set_interfaces (accessible, &iter);
938 dbus_message_unref (reply);
939 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
942 n = _atspi_get_iface_num (interface_name);
943 if (n == -1) return FALSE;
944 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
948 * atspi_accessible_is_action:
949 * @obj: a pointer to the #AtspiAccessible instance to query.
951 * Query whether the specified #AtspiAccessible implements the
952 * #AtspiAction interface.
954 * Returns: #TRUE if @obj implements the #AtspiAction interface,
958 atspi_accessible_is_action (AtspiAccessible *obj)
960 return _atspi_accessible_is_a (obj,
961 atspi_interface_action);
965 * atspi_accessible_is_application:
966 * @obj: a pointer to the #AtspiAccessible instance to query.
968 * Query whether the specified #AtspiAccessible implements the
969 * #AtspiApplication interface.
971 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
975 atspi_accessible_is_application (AtspiAccessible *obj)
977 return _atspi_accessible_is_a (obj,
978 atspi_interface_application);
982 * atspi_accessible_is_collection:
983 * @obj: a pointer to the #AtspiAccessible instance to query.
985 * Query whether the specified #AtspiAccessible implements the
986 * #AtspiCollection interface.
988 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
992 atspi_accessible_is_collection (AtspiAccessible *obj)
994 return _atspi_accessible_is_a (obj,
995 atspi_interface_collection);
999 * atspi_accessible_is_component:
1000 * @obj: a pointer to the #AtspiAccessible instance to query.
1002 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
1004 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
1008 atspi_accessible_is_component (AtspiAccessible *obj)
1010 return _atspi_accessible_is_a (obj,
1011 atspi_interface_component);
1015 * atspi_accessible_is_document:
1016 * @obj: a pointer to the #AtspiAccessible instance to query.
1018 * Query whether the specified #AtspiAccessible implements the
1019 * #AtspiDocument interface.
1021 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
1025 atspi_accessible_is_document (AtspiAccessible *obj)
1027 return _atspi_accessible_is_a (obj,
1028 atspi_interface_document);
1032 * atspi_accessible_is_editable_text:
1033 * @obj: a pointer to the #AtspiAccessible instance to query.
1035 * Query whether the specified #AtspiAccessible implements the
1036 * #AtspiEditableText interface.
1038 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
1042 atspi_accessible_is_editable_text (AtspiAccessible *obj)
1044 return _atspi_accessible_is_a (obj,
1045 atspi_interface_editable_text);
1049 * atspi_accessible_is_hypertext:
1050 * @obj: a pointer to the #AtspiAccessible instance to query.
1052 * Query whether the specified #AtspiAccessible implements the
1053 * #AtspiHypertext interface.
1055 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1059 atspi_accessible_is_hypertext (AtspiAccessible *obj)
1061 return _atspi_accessible_is_a (obj,
1062 atspi_interface_hypertext);
1066 * atspi_accessible_is_hyperlink:
1067 * @obj: a pointer to the #AtspiAccessible instance to query.
1069 * Query whether the specified #AtspiAccessible implements the
1070 * #AtspiHyperlink interface.
1072 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1076 atspi_accessible_is_hyperlink (AtspiAccessible *obj)
1078 return _atspi_accessible_is_a (obj,
1079 atspi_interface_hyperlink);
1083 * atspi_accessible_is_image:
1084 * @obj: a pointer to the #AtspiAccessible instance to query.
1086 * Query whether the specified #AtspiAccessible implements the
1087 * #AtspiImage interface.
1089 * Returns: #TRUE if @obj implements the #AtspiImage interface,
1093 atspi_accessible_is_image (AtspiAccessible *obj)
1095 return _atspi_accessible_is_a (obj,
1096 atspi_interface_image);
1100 * atspi_accessible_is_selection:
1101 * @obj: a pointer to the #AtspiAccessible instance to query.
1103 * Query whether the specified #AtspiAccessible implements the
1104 * #AtspiSelection interface.
1106 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
1110 atspi_accessible_is_selection (AtspiAccessible *obj)
1112 return _atspi_accessible_is_a (obj,
1113 atspi_interface_selection);
1117 * atspi_accessible_is_table:
1118 * @obj: a pointer to the #AtspiAccessible instance to query.
1120 * Query whether the specified #AtspiAccessible implements the
1121 * #AtspiTable interface.
1123 * Returns: #TRUE if @obj implements the #AtspiTable interface,
1127 atspi_accessible_is_table (AtspiAccessible *obj)
1129 return _atspi_accessible_is_a (obj,
1130 atspi_interface_table);
1134 * atspi_accessible_is_streamable_content:
1135 * @obj: a pointer to the #AtspiAccessible instance to query.
1137 * Query whether the specified #AtspiAccessible implements the
1138 * #AtspiStreamableContent interface.
1140 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
1144 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
1147 return _atspi_accessible_is_a (obj,
1148 atspi_interface_streamable_content);
1150 g_warning ("Streamable content not implemented");
1156 * atspi_accessible_is_text:
1157 * @obj: a pointer to the #AtspiAccessible instance to query.
1159 * Query whether the specified #AtspiAccessible implements the
1160 * #AtspiText interface.
1162 * Returns: #TRUE if @obj implements the #AtspiText interface,
1166 atspi_accessible_is_text (AtspiAccessible *obj)
1168 return _atspi_accessible_is_a (obj,
1169 atspi_interface_text);
1173 * atspi_accessible_is_value:
1174 * @obj: a pointer to the #AtspiAccessible instance to query.
1176 * Query whether the specified #AtspiAccessible implements the
1177 * #AtspiValue interface.
1179 * Returns: #TRUE if @obj implements the #AtspiValue interface,
1183 atspi_accessible_is_value (AtspiAccessible *obj)
1185 return _atspi_accessible_is_a (obj,
1186 atspi_interface_value);
1190 * atspi_accessible_get_action:
1191 * @obj: a pointer to the #AtspiAccessible instance to query.
1193 * Gets the #AtspiAction interface for an #AtspiAccessible.
1195 * Returns: (transfer full): a pointer to an #AtspiAction interface
1196 * instance, or NULL if @obj does not implement #AtspiAction.
1199 atspi_accessible_get_action (AtspiAccessible *accessible)
1201 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1202 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1206 * atspi_accessible_get_collection:
1207 * @obj: a pointer to the #AtspiAccessible instance to query.
1209 * Gets the #AtspiCollection interface for an #AtspiAccessible.
1211 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1212 * instance, or NULL if @obj does not implement #AtspiCollection.
1215 atspi_accessible_get_collection (AtspiAccessible *accessible)
1217 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1218 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1222 * atspi_accessible_get_component:
1223 * @obj: a pointer to the #AtspiAccessible instance to query.
1225 * Gets the #AtspiComponent interface for an #AtspiAccessible.
1227 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1228 * instance, or NULL if @obj does not implement #AtspiComponent.
1231 atspi_accessible_get_component (AtspiAccessible *obj)
1233 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1234 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1238 * atspi_accessible_get_document:
1239 * @obj: a pointer to the #AtspiAccessible instance to query.
1241 * Gets the #AtspiDocument interface for an #AtspiAccessible.
1243 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1244 * instance, or NULL if @obj does not implement #AtspiDocument.
1247 atspi_accessible_get_document (AtspiAccessible *accessible)
1249 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1250 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1254 * atspi_accessible_get_editable_text:
1255 * @obj: a pointer to the #AtspiAccessible instance to query.
1257 * Gets the #AtspiEditableText interface for an #AtspiAccessible.
1259 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1260 * instance, or NULL if @obj does not implement #AtspiEditableText.
1263 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1265 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1266 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1270 * atspi_accessible_get_hyperlink:
1271 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1273 * Gets the #AtspiHyperlink interface for an #AtspiAccessible.
1275 * Returns: (transfer full): the #AtspiHyperlink object associated with
1276 * the given #AtspiAccessible, or NULL if not supported.
1279 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1281 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1282 _atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1286 * atspi_accessible_get_hypertext:
1287 * @obj: a pointer to the #AtspiAccessible instance to query.
1289 * Gets the #AtspiHypertext interface for an #AtspiAccessible.
1291 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1292 * instance, or NULL if @obj does not implement #AtspiHypertext.
1295 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1297 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1298 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1302 * atspi_accessible_get_image:
1303 * @obj: a pointer to the #AtspiAccessible instance to query.
1305 * Gets the #AtspiImage interface for an #AtspiAccessible.
1307 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1308 * NULL if @obj does not implement #AtspiImage.
1311 atspi_accessible_get_image (AtspiAccessible *accessible)
1313 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1314 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1318 * atspi_accessible_get_selection:
1319 * @obj: a pointer to the #AtspiAccessible instance to query.
1321 * Gets the #AtspiSelection interface for an #AtspiAccessible.
1323 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1324 * instance, or NULL if @obj does not implement #AtspiSelection.
1327 atspi_accessible_get_selection (AtspiAccessible *accessible)
1329 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1330 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1335 * atspi_accessible_get_streamable_content:
1336 * @obj: a pointer to the #AtspiAccessible instance to query.
1338 * Gets the #AtspiStreamableContent interface for an #AtspiAccessible.
1340 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1341 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1343 AtspiStreamableContent *
1344 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1346 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1352 * atspi_accessible_get_table:
1353 * @obj: a pointer to the #AtspiAccessible instance to query.
1355 * Gets the #AtspiTable interface for an #AtspiAccessible.
1357 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1358 * NULL if @obj does not implement #AtspiTable.
1361 atspi_accessible_get_table (AtspiAccessible *obj)
1363 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1364 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1368 * atspi_accessible_get_text:
1369 * @obj: a pointer to the #AtspiAccessible instance to query.
1371 * Gets the #AtspiTable interface for an #AtspiAccessible.
1373 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1374 * NULL if @obj does not implement #AtspiText.
1377 atspi_accessible_get_text (AtspiAccessible *obj)
1379 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1380 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1384 * atspi_accessible_get_value:
1385 * @obj: a pointer to the #AtspiAccessible instance to query.
1387 * Gets the #AtspiTable interface for an #AtspiAccessible.
1389 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1390 * NULL if @obj does not implement #AtspiValue.
1393 atspi_accessible_get_value (AtspiAccessible *accessible)
1395 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1396 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1400 append_const_val (GArray *array, const gchar *val)
1402 gchar *dup = g_strdup (val);
1405 g_array_append_val (array, dup);
1409 * atspi_accessible_get_interfaces:
1410 * @obj: The #AtspiAccessible to query.
1412 * A set of pointers to all interfaces supported by an #AtspiAccessible.
1414 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1415 * describing the interfaces supported by the object. Interfaces are
1416 * denoted in short-hand (i.e. "Component", "Text" etc.).
1419 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1421 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1423 g_return_val_if_fail (obj != NULL, NULL);
1425 append_const_val (ret, "Accessible");
1426 if (atspi_accessible_is_action (obj))
1427 append_const_val (ret, "Action");
1428 if (atspi_accessible_is_collection (obj))
1429 append_const_val (ret, "Collection");
1430 if (atspi_accessible_is_component (obj))
1431 append_const_val (ret, "Component");
1432 if (atspi_accessible_is_document (obj))
1433 append_const_val (ret, "Document");
1434 if (atspi_accessible_is_editable_text (obj))
1435 append_const_val (ret, "EditableText");
1436 if (atspi_accessible_is_hypertext (obj))
1437 append_const_val (ret, "Hypertext");
1438 if (atspi_accessible_is_hyperlink (obj))
1439 append_const_val (ret, "Hyperlink");
1440 if (atspi_accessible_is_image (obj))
1441 append_const_val (ret, "Image");
1442 if (atspi_accessible_is_selection (obj))
1443 append_const_val (ret, "Selection");
1444 if (atspi_accessible_is_table (obj))
1445 append_const_val (ret, "Table");
1446 if (atspi_accessible_is_text (obj))
1447 append_const_val (ret, "Text");
1448 if (atspi_accessible_is_value (obj))
1449 append_const_val (ret, "Value");
1455 _atspi_accessible_new (AtspiApplication *app, const gchar *path)
1457 AtspiAccessible *accessible;
1459 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1460 g_return_val_if_fail (accessible != NULL, NULL);
1462 accessible->parent.app = g_object_ref (app);
1463 accessible->parent.path = g_strdup (path);
1469 * atspi_accessible_set_cache_mask:
1470 * @accessible: The #AtspiAccessible to operate on. Must be the desktop or
1471 * the root of an application.
1472 * @mask: (type int): An #AtspiCache specifying a bit mask of the types of data to cache.
1474 * Sets the type of data to cache for accessibles.
1475 * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
1476 * then the desktop's cache flag will be used.
1477 * If the desktop's cache flag is also undefined, then all possible data will
1479 * This function is intended to work around bugs in toolkits where the proper
1480 * events are not raised / to aid in testing for such bugs.
1483 atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
1485 g_return_if_fail (accessible != NULL);
1486 g_return_if_fail (accessible->parent.app != NULL);
1487 g_return_if_fail (accessible == accessible->parent.app->root);
1488 accessible->parent.app->cache = mask;
1489 enable_caching = TRUE;
1493 * atspi_accessible_clear_cache:
1494 * @accessible: The #AtspiAccessible whose cache to clear.
1496 * Clears the cached information for the given accessible and all of its
1500 atspi_accessible_clear_cache (AtspiAccessible *accessible)
1506 accessible->cached_properties = ATSPI_CACHE_NONE;
1507 for (l = accessible->children; l; l = l->next)
1508 atspi_accessible_clear_cache (l->data);
1513 * atspi_accessible_get_process_id:
1514 * @accessible: The #AtspiAccessible to query.
1516 * Returns the process id associated with the given accessible. Mainly
1517 * added for debugging; it is a shortcut to explicitly querying the
1518 * accessible's app->bus_name and then calling GetConnectionUnixProcessID.
1520 * Returns: The process ID, or -1 if defunct.
1523 atspi_accessible_get_process_id (AtspiAccessible *accessible, GError **error)
1525 DBusMessage *message, *reply;
1526 DBusConnection *bus = _atspi_bus ();
1527 dbus_uint32_t pid = -1;
1530 if (!accessible->parent.app || !accessible->parent.app->bus_name)
1533 message = dbus_message_new_method_call ("org.freedesktop.DBus",
1534 "/org/freedesktop/DBus",
1535 "org.freedesktop.DBus",
1536 "GetConnectionUnixProcessID");
1537 dbus_message_append_args (message, DBUS_TYPE_STRING,
1538 &accessible->parent.app->bus_name,
1540 dbus_error_init (&d_error);
1541 reply = dbus_connection_send_with_reply_and_block (bus, message, -1, &d_error);
1542 dbus_message_unref (message);
1543 dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &pid, DBUS_TYPE_INVALID);
1544 dbus_message_unref (reply);
1545 if (dbus_error_is_set (&d_error))
1547 g_warning ("GetConnectionUnixProcessID failed: %s", d_error.message);
1548 dbus_error_free (&d_error);
1554 _atspi_accessible_get_cache_mask (AtspiAccessible *accessible)
1558 if (!accessible->parent.app)
1559 return ATSPI_CACHE_NONE;
1561 mask = accessible->parent.app->cache;
1562 if (mask == ATSPI_CACHE_UNDEFINED &&
1563 accessible->parent.app->root &&
1564 accessible->parent.app->root->accessible_parent)
1566 AtspiAccessible *desktop = atspi_get_desktop (0);
1567 mask = desktop->parent.app->cache;
1568 g_object_unref (desktop);
1571 if (mask == ATSPI_CACHE_UNDEFINED)
1572 mask = ATSPI_CACHE_DEFAULT;
1578 _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
1580 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1581 AtspiCache result = accessible->cached_properties & mask & flag;
1582 if (accessible->states && atspi_state_set_contains (accessible->states, ATSPI_STATE_TRANSIENT))
1584 return (result != 0 && (atspi_main_loop || enable_caching) &&
1589 _atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
1591 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1593 accessible->cached_properties |= flag & mask;