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",
308 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
311 * atspi_role_get_name:
312 * @role: an #AtspiRole object to query.
314 * Gets a localizable string that indicates the name of an #AtspiRole.
315 * <em>DEPRECATED.</em>
317 * Returns: a localizable string name for an #AtspiRole enumerated type.
320 atspi_role_get_name (AtspiRole role)
322 if (role < MAX_ROLES && role_names [(int) role])
324 return g_strdup (role_names [(int) role]);
328 return g_strdup ("");
333 * atspi_accessible_get_name:
334 * @obj: a pointer to the #AtspiAccessible object on which to operate.
336 * Gets the name of an #AtspiAccessible object.
338 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object
339 * or NULL on exception.
342 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
344 g_return_val_if_fail (obj != NULL, g_strdup (""));
345 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_NAME))
347 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
349 return g_strdup ("");
350 _atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
352 return g_strdup (obj->name);
356 * atspi_accessible_get_description:
357 * @obj: a pointer to the #AtspiAccessible object on which to operate.
359 * Gets the description of an #AtspiAccessible object.
361 * Returns: a UTF-8 string describing the #AtspiAccessible object
362 * or NULL on exception.
365 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
367 g_return_val_if_fail (obj != NULL, g_strdup (""));
369 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_DESCRIPTION))
371 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
372 "Description", error, "s",
374 return g_strdup ("");
375 _atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
377 return g_strdup (obj->description);
380 const char *str_parent = "Parent";
383 * atspi_accessible_get_parent:
384 * @obj: a pointer to the #AtspiAccessible object to query.
386 * Gets an #AtspiAccessible object's parent container.
388 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
389 * contains the given #AtspiAccessible instance, or NULL if the @obj
390 * has no parent container.
394 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
396 g_return_val_if_fail (obj != NULL, NULL);
398 if (obj->parent.app &&
399 !_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
401 DBusMessage *message, *reply;
402 DBusMessageIter iter, iter_variant;
403 message = dbus_message_new_method_call (obj->parent.app->bus_name,
405 DBUS_INTERFACE_PROPERTIES, "Get");
408 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
409 DBUS_TYPE_STRING, &str_parent,
411 reply = _atspi_dbus_send_with_reply_and_block (message, error);
414 if (strcmp (dbus_message_get_signature (reply), "v") != 0)
416 dbus_message_unref (reply);
419 dbus_message_iter_init (reply, &iter);
420 dbus_message_iter_recurse (&iter, &iter_variant);
421 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
422 dbus_message_unref (reply);
423 _atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
425 if (!obj->accessible_parent)
427 return g_object_ref (obj->accessible_parent);
431 * atspi_accessible_get_child_count:
432 * @obj: a pointer to the #AtspiAccessible object on which to operate.
434 * Gets the number of children contained by an #AtspiAccessible object.
436 * Returns: a #long indicating the number of #AtspiAccessible children
437 * contained by an #AtspiAccessible object or -1 on exception.
441 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
443 g_return_val_if_fail (obj != NULL, -1);
445 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
448 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
449 "ChildCount", error, "i", &ret))
454 return g_list_length (obj->children);
458 * atspi_accessible_get_child_at_index:
459 * @obj: a pointer to the #AtspiAccessible object on which to operate.
460 * @child_index: a #long indicating which child is specified.
462 * Gets the #AtspiAccessible child of an #AtspiAccessible object at a given index.
464 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
465 * index @child_index or NULL on exception.
468 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
472 AtspiAccessible *child;
474 g_return_val_if_fail (obj != NULL, NULL);
476 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
479 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
480 "GetChildAtIndex", error, "i",
482 return _atspi_dbus_return_accessible_from_message (reply);
485 child = g_list_nth_data (obj->children, child_index);
488 return g_object_ref (child);
492 * atspi_accessible_get_index_in_parent:
493 * @obj: a pointer to the #AtspiAccessible object on which to operate.
495 * Gets the index of an #AtspiAccessible object within its parent's
496 * #AtspiAccessible children list.
498 * Returns: a #glong indicating the index of the #AtspiAccessible object
500 * or -1 if @obj has no containing parent or on exception.
503 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
508 g_return_val_if_fail (obj != NULL, -1);
509 if (_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT) &&
510 !obj->accessible_parent)
512 if (!obj->accessible_parent ||
513 !_atspi_accessible_test_cache (obj->accessible_parent,
514 ATSPI_CACHE_CHILDREN))
516 dbus_int32_t ret = -1;
517 _atspi_dbus_call (obj, atspi_interface_accessible,
518 "GetIndexInParent", NULL, "=>i", &ret);
522 l = obj->accessible_parent->children;
525 if (l->data == obj) return i;
536 } Accessibility_Relation;
539 * atspi_accessible_get_relation_set:
540 * @obj: a pointer to the #AtspiAccessible object on which to operate.
542 * Gets the set of #AtspiRelation objects which describes this #AtspiAccessible object's
543 * relationships with other #AtspiAccessible objects.
545 * Returns: (element-type AtspiAccessible*) (transfer full): a #GArray of
546 * #AtspiRelation pointers or NULL on exception.
549 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
552 DBusMessageIter iter, iter_array;
555 g_return_val_if_fail (obj != NULL, NULL);
557 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
560 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
562 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
563 dbus_message_iter_init (reply, &iter);
564 dbus_message_iter_recurse (&iter, &iter_array);
565 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
567 AtspiRelation *relation;
568 relation = _atspi_relation_new_from_iter (&iter_array);
569 ret = g_array_append_val (ret, relation);
570 dbus_message_iter_next (&iter_array);
572 dbus_message_unref (reply);
577 * atspi_accessible_get_role:
578 * @obj: a pointer to the #AtspiAccessible object on which to operate.
580 * Gets the UI role played by an #AtspiAccessible object.
581 * This role's name can be obtained via atspi_accessible_get_role_name ().
583 * Returns: the #AtspiRole of an #AtspiAccessible object.
587 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
589 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
591 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ROLE))
594 /* TODO: Make this a property */
595 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
598 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
605 * atspi_accessible_get_role_name:
606 * @obj: a pointer to the #AtspiAccessible object on which to operate.
608 * Gets a UTF-8 string corresponding to the name of the role played by an object.
609 * This method will return useful values for roles that fall outside the
610 * enumeration used in atspi_accessible_get_role ().
612 * Returns: a UTF-8 string specifying the type of UI role played by an
613 * #AtspiAccessible object.
617 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
622 g_return_val_if_fail (obj != NULL, NULL);
624 role = atspi_accessible_get_role (obj, error);
625 if (role >= 0 && role < MAX_ROLES && role != ATSPI_ROLE_EXTENDED)
626 return g_strdup (role_names [role]);
628 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
631 retval = g_strdup ("");
637 * atspi_accessible_get_localized_role_name:
638 * @obj: a pointer to the #AtspiAccessible object on which to operate.
640 * Gets a UTF-8 string corresponding to the name of the role played by an
641 * object, translated to the current locale.
642 * This method will return useful values for roles that fall outside the
643 * enumeration used in atspi_accessible_getRole ().
645 * Returns: a localized, UTF-8 string specifying the type of UI role played
646 * by an #AtspiAccessible object.
650 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
654 g_return_val_if_fail (obj != NULL, NULL);
656 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
659 return g_strdup ("");
664 static AtspiStateSet *
667 AtspiStateSet *set = atspi_state_set_new (NULL);
668 atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
673 * atspi_accessible_get_state_set:
674 * @obj: a pointer to the #AtspiAccessible object on which to operate.
676 * Gets the states currently held by an object.
678 * Returns: (transfer full): a pointer to an #AtspiStateSet representing an
679 * object's current state set.
682 atspi_accessible_get_state_set (AtspiAccessible *obj)
684 /* TODO: Should take a GError **, but would be an API break */
685 if (!obj->parent.app || !obj->parent.app->bus)
686 return defunct_set ();
688 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
691 DBusMessageIter iter;
692 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
693 "GetState", NULL, "");
694 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
695 dbus_message_iter_init (reply, &iter);
696 _atspi_dbus_set_state (obj, &iter);
697 dbus_message_unref (reply);
698 _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
701 return g_object_ref (obj->states);
705 * atspi_accessible_get_attributes:
706 * @obj: The #AtspiAccessible being queried.
708 * Gets the #AttributeSet representing any assigned
709 * name-value pair attributes or annotations for this object.
710 * For typographic, textual, or textually-semantic attributes, see
711 * atspi_text_get_attributes instead.
713 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
714 * attributes assigned to this object.
717 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
719 DBusMessage *message;
721 g_return_val_if_fail (obj != NULL, NULL);
723 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ATTRIBUTES))
725 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
726 "GetAttributes", error, "");
727 obj->attributes = _atspi_dbus_return_hash_from_message (message);
728 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ATTRIBUTES);
731 if (!obj->attributes)
733 return g_hash_table_ref (obj->attributes);
737 add_to_attribute_array (gpointer key, gpointer value, gpointer data)
739 GArray **array = (GArray **)data;
740 gchar *str = g_strconcat (key, ":", value, NULL);
741 *array = g_array_append_val (*array, str);
745 * atspi_accessible_get_attributes_as_array:
746 * @obj: The #AtspiAccessible being queried.
748 * Gets a #GArray representing any assigned
749 * name-value pair attributes or annotations for this object.
750 * For typographic, textual, or textually-semantic attributes, see
751 * atspi_text_get_attributes_as_array instead.
753 * Returns: (element-type gchar*) (transfer full): The name-value-pair
754 * attributes assigned to this object.
757 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
759 DBusMessage *message;
761 g_return_val_if_fail (obj != NULL, NULL);
763 if (_atspi_accessible_get_cache_mask (obj) & ATSPI_CACHE_ATTRIBUTES)
765 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
766 GHashTable *attributes = atspi_accessible_get_attributes (obj, error);
769 g_hash_table_foreach (attributes, add_to_attribute_array, &array);
770 g_hash_table_unref (attributes);
774 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
775 return _atspi_dbus_return_attribute_array_from_message (message);
779 * atspi_accessible_get_application:
780 * @obj: The #AtspiAccessible being queried.
782 * Gets the containing #AtspiApplication for an object.
784 * Returns: (transfer full): the containing #AtspiApplication instance for
788 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
790 AtspiAccessible *parent;
795 parent = atspi_accessible_get_parent (obj, NULL);
796 if (!parent && obj->parent.app &&
797 atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
799 AtspiAccessible *root = g_object_ref (obj->parent.app->root);
802 g_object_unref (obj);
803 g_object_unref (parent);
804 if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
806 g_object_unref (root);
812 if (!parent || parent == obj ||
813 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
816 g_object_unref (parent);
819 g_object_unref (obj);
824 /* Application-specific methods */
827 * atspi_accessible_get_toolkit_name:
828 * @obj: a pointer to the #AtspiAccessible object on which to operate.
830 * Gets the toolkit name for an #AtspiAccessible object.
831 * Only works on application root objects.
833 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object or NULL on exception.
836 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
838 g_return_val_if_fail (obj != NULL, NULL);
840 if (!obj->parent.app)
843 if (!obj->parent.app->toolkit_name)
844 _atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName",
845 error, "s", &obj->parent.app->toolkit_name);
847 return g_strdup (obj->parent.app->toolkit_name);
851 * atspi_accessible_get_toolkit_version:
852 * @obj: a pointer to the #AtspiAccessible object on which to operate.
854 * Gets the toolkit version for an #AtspiAccessible object.
855 * Only works on application root objects.
857 * Returns: a UTF-8 string indicating the toolkit version for the #AtspiAccessible object or NULL on exception.
860 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
862 g_return_val_if_fail (obj != NULL, NULL);
864 if (!obj->parent.app)
867 if (!obj->parent.app->toolkit_version)
868 _atspi_dbus_get_property (obj, atspi_interface_application, "Version",
869 error, "s", &obj->parent.app->toolkit_version);
871 return g_strdup (obj->parent.app->toolkit_version);
875 * atspi_accessible_get_atspi_version:
876 * @obj: a pointer to the #AtspiAccessible object on which to operate.
878 * Gets the AT-SPI IPC specification version supported by the application
879 * pointed to by the #AtspiAccessible object.
880 * Only works on application root objects.
882 * Returns: a UTF-8 string indicating the AT-SPI version for the #AtspiAccessible object or NULL on exception.
885 atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
887 g_return_val_if_fail (obj != NULL, NULL);
889 if (!obj->parent.app)
892 if (!obj->parent.app->atspi_version)
893 _atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion",
894 error, "s", &obj->parent.app->atspi_version);
896 return g_strdup (obj->parent.app->atspi_version);
900 * atspi_accessible_get_id:
901 * @obj: a pointer to the #AtspiAccessible object on which to operate.
903 * Gets the application id for a #AtspiAccessible object.
904 * Only works on application root objects.
906 * Returns: a positive #gint indicating the id for the #AtspiAccessible object
907 * or -1 on exception.
910 atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
914 g_return_val_if_fail (obj != NULL, -1);
916 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
922 /* Interface query methods */
925 _atspi_accessible_is_a (AtspiAccessible *accessible,
926 const char *interface_name)
930 if (accessible == NULL)
935 if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
938 DBusMessageIter iter;
939 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
940 "GetInterfaces", NULL, "");
941 _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
942 dbus_message_iter_init (reply, &iter);
943 _atspi_dbus_set_interfaces (accessible, &iter);
944 dbus_message_unref (reply);
945 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
948 n = _atspi_get_iface_num (interface_name);
949 if (n == -1) return FALSE;
950 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
954 * atspi_accessible_is_action:
955 * @obj: a pointer to the #AtspiAccessible instance to query.
957 * Query whether the specified #AtspiAccessible implements the
958 * #AtspiAction interface.
960 * Returns: #TRUE if @obj implements the #AtspiAction interface,
964 atspi_accessible_is_action (AtspiAccessible *obj)
966 return _atspi_accessible_is_a (obj,
967 atspi_interface_action);
971 * atspi_accessible_is_application:
972 * @obj: a pointer to the #AtspiAccessible instance to query.
974 * Query whether the specified #AtspiAccessible implements the
975 * #AtspiApplication interface.
977 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
981 atspi_accessible_is_application (AtspiAccessible *obj)
983 return _atspi_accessible_is_a (obj,
984 atspi_interface_application);
988 * atspi_accessible_is_collection:
989 * @obj: a pointer to the #AtspiAccessible instance to query.
991 * Query whether the specified #AtspiAccessible implements the
992 * #AtspiCollection interface.
994 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
998 atspi_accessible_is_collection (AtspiAccessible *obj)
1000 return _atspi_accessible_is_a (obj,
1001 atspi_interface_collection);
1005 * atspi_accessible_is_component:
1006 * @obj: a pointer to the #AtspiAccessible instance to query.
1008 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
1010 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
1014 atspi_accessible_is_component (AtspiAccessible *obj)
1016 return _atspi_accessible_is_a (obj,
1017 atspi_interface_component);
1021 * atspi_accessible_is_document:
1022 * @obj: a pointer to the #AtspiAccessible instance to query.
1024 * Query whether the specified #AtspiAccessible implements the
1025 * #AtspiDocument interface.
1027 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
1031 atspi_accessible_is_document (AtspiAccessible *obj)
1033 return _atspi_accessible_is_a (obj,
1034 atspi_interface_document);
1038 * atspi_accessible_is_editable_text:
1039 * @obj: a pointer to the #AtspiAccessible instance to query.
1041 * Query whether the specified #AtspiAccessible implements the
1042 * #AtspiEditableText interface.
1044 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
1048 atspi_accessible_is_editable_text (AtspiAccessible *obj)
1050 return _atspi_accessible_is_a (obj,
1051 atspi_interface_editable_text);
1055 * atspi_accessible_is_hypertext:
1056 * @obj: a pointer to the #AtspiAccessible instance to query.
1058 * Query whether the specified #AtspiAccessible implements the
1059 * #AtspiHypertext interface.
1061 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1065 atspi_accessible_is_hypertext (AtspiAccessible *obj)
1067 return _atspi_accessible_is_a (obj,
1068 atspi_interface_hypertext);
1072 * atspi_accessible_is_hyperlink:
1073 * @obj: a pointer to the #AtspiAccessible instance to query.
1075 * Query whether the specified #AtspiAccessible implements the
1076 * #AtspiHyperlink interface.
1078 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1082 atspi_accessible_is_hyperlink (AtspiAccessible *obj)
1084 return _atspi_accessible_is_a (obj,
1085 atspi_interface_hyperlink);
1089 * atspi_accessible_is_image:
1090 * @obj: a pointer to the #AtspiAccessible instance to query.
1092 * Query whether the specified #AtspiAccessible implements the
1093 * #AtspiImage interface.
1095 * Returns: #TRUE if @obj implements the #AtspiImage interface,
1099 atspi_accessible_is_image (AtspiAccessible *obj)
1101 return _atspi_accessible_is_a (obj,
1102 atspi_interface_image);
1106 * atspi_accessible_is_selection:
1107 * @obj: a pointer to the #AtspiAccessible instance to query.
1109 * Query whether the specified #AtspiAccessible implements the
1110 * #AtspiSelection interface.
1112 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
1116 atspi_accessible_is_selection (AtspiAccessible *obj)
1118 return _atspi_accessible_is_a (obj,
1119 atspi_interface_selection);
1123 * atspi_accessible_is_table:
1124 * @obj: a pointer to the #AtspiAccessible instance to query.
1126 * Query whether the specified #AtspiAccessible implements the
1127 * #AtspiTable interface.
1129 * Returns: #TRUE if @obj implements the #AtspiTable interface,
1133 atspi_accessible_is_table (AtspiAccessible *obj)
1135 return _atspi_accessible_is_a (obj,
1136 atspi_interface_table);
1140 * atspi_accessible_is_streamable_content:
1141 * @obj: a pointer to the #AtspiAccessible instance to query.
1143 * Query whether the specified #AtspiAccessible implements the
1144 * #AtspiStreamableContent interface.
1146 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
1150 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
1153 return _atspi_accessible_is_a (obj,
1154 atspi_interface_streamable_content);
1156 g_warning ("Streamable content not implemented");
1162 * atspi_accessible_is_text:
1163 * @obj: a pointer to the #AtspiAccessible instance to query.
1165 * Query whether the specified #AtspiAccessible implements the
1166 * #AtspiText interface.
1168 * Returns: #TRUE if @obj implements the #AtspiText interface,
1172 atspi_accessible_is_text (AtspiAccessible *obj)
1174 return _atspi_accessible_is_a (obj,
1175 atspi_interface_text);
1179 * atspi_accessible_is_value:
1180 * @obj: a pointer to the #AtspiAccessible instance to query.
1182 * Query whether the specified #AtspiAccessible implements the
1183 * #AtspiValue interface.
1185 * Returns: #TRUE if @obj implements the #AtspiValue interface,
1189 atspi_accessible_is_value (AtspiAccessible *obj)
1191 return _atspi_accessible_is_a (obj,
1192 atspi_interface_value);
1196 * atspi_accessible_get_action:
1197 * @obj: a pointer to the #AtspiAccessible instance to query.
1199 * Gets the #AtspiAction interface for an #AtspiAccessible.
1201 * Returns: (transfer full): a pointer to an #AtspiAction interface
1202 * instance, or NULL if @obj does not implement #AtspiAction.
1205 atspi_accessible_get_action (AtspiAccessible *accessible)
1207 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1208 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1212 * atspi_accessible_get_collection:
1213 * @obj: a pointer to the #AtspiAccessible instance to query.
1215 * Gets the #AtspiCollection interface for an #AtspiAccessible.
1217 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1218 * instance, or NULL if @obj does not implement #AtspiCollection.
1221 atspi_accessible_get_collection (AtspiAccessible *accessible)
1223 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1224 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1228 * atspi_accessible_get_component:
1229 * @obj: a pointer to the #AtspiAccessible instance to query.
1231 * Gets the #AtspiComponent interface for an #AtspiAccessible.
1233 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1234 * instance, or NULL if @obj does not implement #AtspiComponent.
1237 atspi_accessible_get_component (AtspiAccessible *obj)
1239 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1240 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1244 * atspi_accessible_get_document:
1245 * @obj: a pointer to the #AtspiAccessible instance to query.
1247 * Gets the #AtspiDocument interface for an #AtspiAccessible.
1249 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1250 * instance, or NULL if @obj does not implement #AtspiDocument.
1253 atspi_accessible_get_document (AtspiAccessible *accessible)
1255 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1256 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1260 * atspi_accessible_get_editable_text:
1261 * @obj: a pointer to the #AtspiAccessible instance to query.
1263 * Gets the #AtspiEditableText interface for an #AtspiAccessible.
1265 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1266 * instance, or NULL if @obj does not implement #AtspiEditableText.
1269 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1271 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1272 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1276 * atspi_accessible_get_hyperlink:
1277 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1279 * Gets the #AtspiHyperlink interface for an #AtspiAccessible.
1281 * Returns: (transfer full): the #AtspiHyperlink object associated with
1282 * the given #AtspiAccessible, or NULL if not supported.
1285 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1287 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1288 _atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1292 * atspi_accessible_get_hypertext:
1293 * @obj: a pointer to the #AtspiAccessible instance to query.
1295 * Gets the #AtspiHypertext interface for an #AtspiAccessible.
1297 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1298 * instance, or NULL if @obj does not implement #AtspiHypertext.
1301 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1303 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1304 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1308 * atspi_accessible_get_image:
1309 * @obj: a pointer to the #AtspiAccessible instance to query.
1311 * Gets the #AtspiImage interface for an #AtspiAccessible.
1313 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1314 * NULL if @obj does not implement #AtspiImage.
1317 atspi_accessible_get_image (AtspiAccessible *accessible)
1319 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1320 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1324 * atspi_accessible_get_selection:
1325 * @obj: a pointer to the #AtspiAccessible instance to query.
1327 * Gets the #AtspiSelection interface for an #AtspiAccessible.
1329 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1330 * instance, or NULL if @obj does not implement #AtspiSelection.
1333 atspi_accessible_get_selection (AtspiAccessible *accessible)
1335 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1336 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1341 * atspi_accessible_get_streamable_content:
1342 * @obj: a pointer to the #AtspiAccessible instance to query.
1344 * Gets the #AtspiStreamableContent interface for an #AtspiAccessible.
1346 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1347 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1349 AtspiStreamableContent *
1350 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1352 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1358 * atspi_accessible_get_table:
1359 * @obj: a pointer to the #AtspiAccessible instance to query.
1361 * Gets the #AtspiTable interface for an #AtspiAccessible.
1363 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1364 * NULL if @obj does not implement #AtspiTable.
1367 atspi_accessible_get_table (AtspiAccessible *obj)
1369 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1370 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1374 * atspi_accessible_get_text:
1375 * @obj: a pointer to the #AtspiAccessible instance to query.
1377 * Gets the #AtspiTable interface for an #AtspiAccessible.
1379 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1380 * NULL if @obj does not implement #AtspiText.
1383 atspi_accessible_get_text (AtspiAccessible *obj)
1385 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1386 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1390 * atspi_accessible_get_value:
1391 * @obj: a pointer to the #AtspiAccessible instance to query.
1393 * Gets the #AtspiTable interface for an #AtspiAccessible.
1395 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1396 * NULL if @obj does not implement #AtspiValue.
1399 atspi_accessible_get_value (AtspiAccessible *accessible)
1401 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1402 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1406 append_const_val (GArray *array, const gchar *val)
1408 gchar *dup = g_strdup (val);
1411 g_array_append_val (array, dup);
1415 * atspi_accessible_get_interfaces:
1416 * @obj: The #AtspiAccessible to query.
1418 * A set of pointers to all interfaces supported by an #AtspiAccessible.
1420 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1421 * describing the interfaces supported by the object. Interfaces are
1422 * denoted in short-hand (i.e. "Component", "Text" etc.).
1425 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1427 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1429 g_return_val_if_fail (obj != NULL, NULL);
1431 append_const_val (ret, "Accessible");
1432 if (atspi_accessible_is_action (obj))
1433 append_const_val (ret, "Action");
1434 if (atspi_accessible_is_collection (obj))
1435 append_const_val (ret, "Collection");
1436 if (atspi_accessible_is_component (obj))
1437 append_const_val (ret, "Component");
1438 if (atspi_accessible_is_document (obj))
1439 append_const_val (ret, "Document");
1440 if (atspi_accessible_is_editable_text (obj))
1441 append_const_val (ret, "EditableText");
1442 if (atspi_accessible_is_hypertext (obj))
1443 append_const_val (ret, "Hypertext");
1444 if (atspi_accessible_is_hyperlink (obj))
1445 append_const_val (ret, "Hyperlink");
1446 if (atspi_accessible_is_image (obj))
1447 append_const_val (ret, "Image");
1448 if (atspi_accessible_is_selection (obj))
1449 append_const_val (ret, "Selection");
1450 if (atspi_accessible_is_table (obj))
1451 append_const_val (ret, "Table");
1452 if (atspi_accessible_is_text (obj))
1453 append_const_val (ret, "Text");
1454 if (atspi_accessible_is_value (obj))
1455 append_const_val (ret, "Value");
1461 _atspi_accessible_new (AtspiApplication *app, const gchar *path)
1463 AtspiAccessible *accessible;
1465 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1466 g_return_val_if_fail (accessible != NULL, NULL);
1468 accessible->parent.app = g_object_ref (app);
1469 accessible->parent.path = g_strdup (path);
1475 * atspi_accessible_set_cache_mask:
1476 * @accessible: The #AtspiAccessible to operate on. Must be the desktop or
1477 * the root of an application.
1478 * @mask: (type int): An #AtspiCache specifying a bit mask of the types of data to cache.
1480 * Sets the type of data to cache for accessibles.
1481 * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
1482 * then the desktop's cache flag will be used.
1483 * If the desktop's cache flag is also undefined, then all possible data will
1485 * This function is intended to work around bugs in toolkits where the proper
1486 * events are not raised / to aid in testing for such bugs.
1489 atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
1491 g_return_if_fail (accessible != NULL);
1492 g_return_if_fail (accessible->parent.app != NULL);
1493 g_return_if_fail (accessible == accessible->parent.app->root);
1494 accessible->parent.app->cache = mask;
1495 enable_caching = TRUE;
1499 * atspi_accessible_clear_cache:
1500 * @accessible: The #AtspiAccessible whose cache to clear.
1502 * Clears the cached information for the given accessible and all of its
1506 atspi_accessible_clear_cache (AtspiAccessible *accessible)
1512 accessible->cached_properties = ATSPI_CACHE_NONE;
1513 for (l = accessible->children; l; l = l->next)
1514 atspi_accessible_clear_cache (l->data);
1519 * atspi_accessible_get_process_id:
1520 * @accessible: The #AtspiAccessible to query.
1522 * Returns the process id associated with the given accessible. Mainly
1523 * added for debugging; it is a shortcut to explicitly querying the
1524 * accessible's app->bus_name and then calling GetConnectionUnixProcessID.
1526 * Returns: The process ID, or -1 if defunct.
1529 atspi_accessible_get_process_id (AtspiAccessible *accessible, GError **error)
1531 DBusMessage *message, *reply;
1532 DBusConnection *bus = _atspi_bus ();
1533 dbus_uint32_t pid = -1;
1536 if (!accessible->parent.app || !accessible->parent.app->bus_name)
1539 message = dbus_message_new_method_call ("org.freedesktop.DBus",
1540 "/org/freedesktop/DBus",
1541 "org.freedesktop.DBus",
1542 "GetConnectionUnixProcessID");
1543 dbus_message_append_args (message, DBUS_TYPE_STRING,
1544 &accessible->parent.app->bus_name,
1546 dbus_error_init (&d_error);
1547 reply = dbus_connection_send_with_reply_and_block (bus, message, -1, &d_error);
1548 dbus_message_unref (message);
1549 dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &pid, DBUS_TYPE_INVALID);
1550 dbus_message_unref (reply);
1551 if (dbus_error_is_set (&d_error))
1553 g_warning ("GetConnectionUnixProcessID failed: %s", d_error.message);
1554 dbus_error_free (&d_error);
1560 _atspi_accessible_get_cache_mask (AtspiAccessible *accessible)
1564 if (!accessible->parent.app)
1565 return ATSPI_CACHE_NONE;
1567 mask = accessible->parent.app->cache;
1568 if (mask == ATSPI_CACHE_UNDEFINED &&
1569 accessible->parent.app->root &&
1570 accessible->parent.app->root->accessible_parent)
1572 AtspiAccessible *desktop = atspi_get_desktop (0);
1573 mask = desktop->parent.app->cache;
1574 g_object_unref (desktop);
1577 if (mask == ATSPI_CACHE_UNDEFINED)
1578 mask = ATSPI_CACHE_DEFAULT;
1584 _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
1586 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1587 AtspiCache result = accessible->cached_properties & mask & flag;
1588 if (accessible->states && atspi_state_set_contains (accessible->states, ATSPI_STATE_TRANSIENT))
1590 return (result != 0 && (atspi_main_loop || enable_caching) &&
1595 _atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
1597 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1599 accessible->cached_properties |= flag & mask;