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);
161 #ifdef DEBUG_REF_COUNTS
163 printf("at-spi: finalize: %d objects\n", accessible_count);
166 G_OBJECT_CLASS (atspi_accessible_parent_class)
171 atspi_accessible_class_init (AtspiAccessibleClass *klass)
173 GObjectClass *object_class = G_OBJECT_CLASS (klass);
175 object_class->dispose = atspi_accessible_dispose;
176 object_class->finalize = atspi_accessible_finalize;
179 /* TODO: Generate following from spec? */
180 static const char *role_names [] =
238 "table-column-header",
240 "tear-off-menu-item",
270 "input method window"
273 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
276 * atspi_role_get_name
277 * @role: an #AtspiAccessibleRole object to query.
279 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
280 * <em>DEPRECATED.</em>
282 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
285 atspi_role_get_name (AtspiRole role)
287 if (role < MAX_ROLES && role_names [(int) role])
289 return g_strdup (role_names [(int) role]);
293 return g_strdup ("");
298 * atspi_accessible_get_name:
299 * @obj: a pointer to the #AtspiAccessible object on which to operate.
301 * Get the name of an #AtspiAccessible object.
303 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
304 * or NULL on exception
307 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
309 g_return_val_if_fail (obj != NULL, g_strdup (""));
310 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_NAME))
312 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
314 return g_strdup ("");
315 _atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
317 return g_strdup (obj->name);
321 * atspi_accessible_get_description:
322 * @obj: a pointer to the #AtspiAccessible object on which to operate.
324 * Get the description of an #AtspiAccessible object.
326 * Returns: a UTF-8 string describing the #AtspiAccessible object.
327 * or NULL on exception
330 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
332 g_return_val_if_fail (obj != NULL, g_strdup (""));
334 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_DESCRIPTION))
336 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
337 "Description", error, "s",
339 return g_strdup ("");
340 _atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
342 return g_strdup (obj->description);
345 const char *str_parent = "Parent";
348 * atspi_accessible_get_parent:
349 * @obj: a pointer to the #AtspiAccessible object to query.
351 * Get an #AtspiAccessible object's parent container.
353 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
354 * contains the given #AtspiAccessible instance, or NULL if the @obj
355 * has no parent container.
359 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
361 g_return_val_if_fail (obj != NULL, NULL);
363 if (obj->parent.app &&
364 !_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
366 DBusMessage *message, *reply;
367 DBusMessageIter iter, iter_variant;
368 message = dbus_message_new_method_call (obj->parent.app->bus_name,
370 DBUS_INTERFACE_PROPERTIES, "Get");
373 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
374 DBUS_TYPE_STRING, &str_parent,
376 reply = _atspi_dbus_send_with_reply_and_block (message, error);
379 if (strcmp (dbus_message_get_signature (reply), "v") != 0)
381 dbus_message_unref (reply);
384 dbus_message_iter_init (reply, &iter);
385 dbus_message_iter_recurse (&iter, &iter_variant);
386 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
387 dbus_message_unref (reply);
388 _atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
390 if (!obj->accessible_parent)
392 return g_object_ref (obj->accessible_parent);
396 * atspi_accessible_get_child_count:
397 * @obj: a pointer to the #AtspiAccessible object on which to operate.
399 * Get the number of children contained by an #AtspiAccessible object.
401 * Returns: a #long indicating the number of #AtspiAccessible children
402 * contained by an #AtspiAccessible object. or -1 on exception
406 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
408 g_return_val_if_fail (obj != NULL, -1);
410 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
413 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
414 "ChildCount", error, "i", &ret))
419 return g_list_length (obj->children);
423 * atspi_accessible_get_child_at_index:
424 * @obj: a pointer to the #AtspiAccessible object on which to operate.
425 * @child_index: a #long indicating which child is specified.
427 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
429 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
430 * index @child_index. or NULL on exception
433 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
437 AtspiAccessible *child;
439 g_return_val_if_fail (obj != NULL, NULL);
441 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
444 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
445 "GetChildAtIndex", error, "i",
447 return _atspi_dbus_return_accessible_from_message (reply);
450 child = g_list_nth_data (obj->children, child_index);
453 return g_object_ref (child);
457 * atspi_accessible_get_index_in_parent
458 * @obj: a pointer to the #AtspiAccessible object on which to operate.
460 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
462 * Returns: a #glong indicating the index of the #AtspiAccessible object
463 * in its parent (i.e. containing) #AtspiAccessible instance,
464 * or -1 if @obj has no containing parent or on exception.
467 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
472 g_return_val_if_fail (obj != NULL, -1);
473 if (!obj->accessible_parent) return -1;
474 if (!_atspi_accessible_test_cache (obj->accessible_parent,
475 ATSPI_CACHE_CHILDREN))
477 dbus_uint32_t ret = -1;
478 _atspi_dbus_call (obj, atspi_interface_accessible,
479 "GetIndexInParent", NULL, "=>u", &ret);
483 l = obj->accessible_parent->children;
486 if (l->data == obj) return i;
497 } Accessibility_Relation;
500 * atspi_accessible_get_relation_set:
501 * @obj: a pointer to the #AtspiAccessible object on which to operate.
503 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
504 * relationships with other #AtspiAccessible objects.
506 * Returns: (element-type AtspiAccessible*) (transfer full): an array of
507 * #AtspiAccessibleRelation pointers. or NULL on exception
510 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
513 DBusMessageIter iter, iter_array;
516 g_return_val_if_fail (obj != NULL, NULL);
518 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
521 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
523 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
524 dbus_message_iter_init (reply, &iter);
525 dbus_message_iter_recurse (&iter, &iter_array);
526 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
528 AtspiRelation *relation;
529 relation = _atspi_relation_new_from_iter (&iter_array);
530 ret = g_array_append_val (ret, relation);
531 dbus_message_iter_next (&iter_array);
533 dbus_message_unref (reply);
538 * atspi_accessible_get_role:
539 * @obj: a pointer to the #AtspiAccessible object on which to operate.
541 * Get the UI role of an #AtspiAccessible object.
542 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
544 * Returns: the #AtspiRole of the object.
548 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
550 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
552 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ROLE))
555 /* TODO: Make this a property */
556 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
559 _atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
566 * atspi_accessible_get_role_name:
567 * @obj: a pointer to the #AtspiAccessible object on which to operate.
569 * Get a UTF-8 string describing the role this object plays in the UI.
570 * This method will return useful values for roles that fall outside the
571 * enumeration used in atspi_accessible_getRole ().
573 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
577 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
579 AtspiRole role = atspi_accessible_get_role (obj, error);
581 GTypeClass *type_class;
583 const gchar *name = NULL;
585 type_class = g_type_class_ref (ATSPI_TYPE_ROLE);
586 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
588 value = g_enum_get_value (G_ENUM_CLASS (type_class), role);
592 retval = value->value_nick;
596 return g_strdup (retval);
598 g_return_val_if_fail (obj != NULL, NULL);
600 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
603 retval = g_strdup ("");
609 * atspi_accessible_get_localized_role_name:
610 * @obj: a pointer to the #AtspiAccessible object on which to operate.
612 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
613 * This method will return useful values for roles that fall outside the
614 * enumeration used in atspi_accessible_getRole ().
616 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
620 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
624 g_return_val_if_fail (obj != NULL, NULL);
626 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
629 return g_strdup ("");
634 static AtspiStateSet *
637 AtspiStateSet *set = atspi_state_set_new (NULL);
638 atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
643 * atspi_accessible_get_state_set:
644 * @obj: a pointer to the #AtspiAccessible object on which to operate.
646 * Gets the current state of an object.
648 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
649 * object's current state.
652 atspi_accessible_get_state_set (AtspiAccessible *obj)
654 if (!obj->parent.app || !obj->parent.app->bus)
655 return defunct_set ();
658 if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
661 DBusMessageIter iter;
662 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
663 "GetState", NULL, "");
664 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
665 dbus_message_iter_init (reply, &iter);
666 _atspi_dbus_set_state (obj, &iter);
667 dbus_message_unref (reply);
668 _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
671 return g_object_ref (obj->states);
675 * atspi_accessible_get_attributes:
676 * @obj: The #AtspiAccessible being queried.
678 * Get the #AttributeSet representing any assigned
679 * name-value pair attributes or annotations for this object.
680 * For typographic, textual, or textually-semantic attributes, see
681 * atspi_text_get_attributes instead.
683 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
684 * attributes assigned to this object.
687 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
689 DBusMessage *message;
691 g_return_val_if_fail (obj != NULL, NULL);
693 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
694 return _atspi_dbus_return_hash_from_message (message);
698 * atspi_accessible_get_attributes_as_array:
699 * @obj: The #AtspiAccessible being queried.
701 * Get the #AttributeSet representing any assigned
702 * name-value pair attributes or annotations for this object.
703 * For typographic, textual, or textually-semantic attributes, see
704 * atspi_text_get_attributes_as_array instead.
706 * Returns: (element-type gchar*) (transfer full): The name-value-pair
707 * attributes assigned to this object.
710 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
712 DBusMessage *message;
714 g_return_val_if_fail (obj != NULL, NULL);
716 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
717 return _atspi_dbus_return_attribute_array_from_message (message);
721 * atspi_accessible_get_application:
722 * @obj: The #AtspiAccessible being queried.
724 * Get the containing #AtspiApplication for an object.
726 * Returns: (transfer full): the containing AtspiApplication instance for
730 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
732 AtspiAccessible *parent;
737 parent = atspi_accessible_get_parent (obj, NULL);
738 if (!parent && obj->parent.app &&
739 atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
741 AtspiAccessible *root = g_object_ref (obj->parent.app->root);
744 g_object_unref (obj);
745 if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
747 g_object_unref (root);
753 if (!parent || parent == obj ||
754 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
756 g_object_unref (obj);
761 /* Application-specific methods */
764 * atspi_accessible_get_toolkit_name:
765 * @obj: a pointer to the #AtspiAccessible object on which to operate.
767 * Get the toolkit for a #AtspiAccessible object.
768 * Only works on application root objects.
770 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
771 * or NULL on exception
774 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
776 g_return_val_if_fail (obj != NULL, NULL);
778 if (!obj->parent.app)
781 if (!obj->parent.app->toolkit_name)
782 _atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName",
783 error, "s", &obj->parent.app->toolkit_name);
785 return g_strdup (obj->parent.app->toolkit_name);
789 * atspi_accessible_get_toolkit_version:
790 * @obj: a pointer to the #AtspiAccessible object on which to operate.
792 * Get the toolkit version for a #AtspiAccessible object.
793 * Only works on application root objects.
795 * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
796 * or NULL on exception
799 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
801 g_return_val_if_fail (obj != NULL, NULL);
803 if (!obj->parent.app)
806 if (!obj->parent.app->toolkit_version)
807 _atspi_dbus_get_property (obj, atspi_interface_application, "Version",
808 error, "s", &obj->parent.app->toolkit_version);
810 return g_strdup (obj->parent.app->toolkit_version);
814 * atspi_accessible_get_atspi_version:
815 * @obj: a pointer to the #AtspiAccessible object on which to operate.
817 * Get the AT-SPI IPC specification version supported by the application
818 * pointed to by the #AtspiAccessible object.
819 * Only works on application root objects.
821 * Returns: a UTF-8 string indicating the AT-SPI ersion for the #AtspiAccessible object.
822 * or NULL on exception
825 atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
827 g_return_val_if_fail (obj != NULL, NULL);
829 if (!obj->parent.app)
832 if (!obj->parent.app->atspi_version)
833 _atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion",
834 error, "s", &obj->parent.app->atspi_version);
836 return g_strdup (obj->parent.app->atspi_version);
840 * atspi_accessible_get_toolkit_version:
841 * @obj: a pointer to the #AtspiAccessible object on which to operate.
843 * Get the application id for a #AtspiAccessible object.
844 * Only works on application root objects.
846 * Returns: a gint indicating the id for the #AtspiAccessible object.
850 atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
854 g_return_val_if_fail (obj != NULL, -1);
856 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
862 /* Interface query methods */
865 _atspi_accessible_is_a (AtspiAccessible *accessible,
866 const char *interface_name)
870 if (accessible == NULL)
875 if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
878 DBusMessageIter iter;
879 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
880 "GetInterfaces", NULL, "");
881 _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
882 dbus_message_iter_init (reply, &iter);
883 _atspi_dbus_set_interfaces (accessible, &iter);
884 dbus_message_unref (reply);
885 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
888 n = _atspi_get_iface_num (interface_name);
889 if (n == -1) return FALSE;
890 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
894 * atspi_accessible_is_action:
895 * @obj: a pointer to the #AtspiAccessible instance to query.
897 * Query whether the specified #AtspiAccessible implements #AtspiAction.
899 * Returns: #TRUE if @obj implements the #AtspiAction interface,
903 atspi_accessible_is_action (AtspiAccessible *obj)
905 return _atspi_accessible_is_a (obj,
906 atspi_interface_action);
910 * atspi_accessible_is_application:
911 * @obj: a pointer to the #AtspiAccessible instance to query.
913 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
915 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
919 atspi_accessible_is_application (AtspiAccessible *obj)
921 return _atspi_accessible_is_a (obj,
922 atspi_interface_application);
926 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
928 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
929 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
933 atspi_accessible_is_collection (AtspiAccessible *obj)
935 return _atspi_accessible_is_a (obj,
936 atspi_interface_collection);
940 * atspi_accessible_is_component:
941 * @obj: a pointer to the #AtspiAccessible instance to query.
943 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
945 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
949 atspi_accessible_is_component (AtspiAccessible *obj)
951 return _atspi_accessible_is_a (obj,
952 atspi_interface_component);
956 * atspi_accessible_is_document:
957 * @obj: a pointer to the #AtspiAccessible instance to query.
959 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
961 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
965 atspi_accessible_is_document (AtspiAccessible *obj)
967 return _atspi_accessible_is_a (obj,
968 atspi_interface_document);
972 * atspi_accessible_is_editable_text:
973 * @obj: a pointer to the #AtspiAccessible instance to query.
975 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
977 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
981 atspi_accessible_is_editable_text (AtspiAccessible *obj)
983 return _atspi_accessible_is_a (obj,
984 atspi_interface_editable_text);
988 * atspi_accessible_is_hypertext:
989 * @obj: a pointer to the #AtspiAccessible instance to query.
991 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
993 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
997 atspi_accessible_is_hypertext (AtspiAccessible *obj)
999 return _atspi_accessible_is_a (obj,
1000 atspi_interface_hypertext);
1004 * atspi_accessible_is_hyperlink:
1005 * @obj: a pointer to the #AtspiAccessible instance to query.
1007 * Query whether the specified #AtspiAccessible implements #AtspiHyperlink.
1009 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
1013 atspi_accessible_is_hyperlink (AtspiAccessible *obj)
1015 return _atspi_accessible_is_a (obj,
1016 atspi_interface_hyperlink);
1020 * atspi_accessible_is_image:
1021 * @obj: a pointer to the #AtspiAccessible instance to query.
1023 * Query whether the specified #AtspiAccessible implements #AtspiImage.
1025 * Returns: #TRUE if @obj implements the #AtspiImage interface,
1029 atspi_accessible_is_image (AtspiAccessible *obj)
1031 return _atspi_accessible_is_a (obj,
1032 atspi_interface_image);
1036 * atspi_accessible_is_selection:
1037 * @obj: a pointer to the #AtspiAccessible instance to query.
1039 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
1041 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
1045 atspi_accessible_is_selection (AtspiAccessible *obj)
1047 return _atspi_accessible_is_a (obj,
1048 atspi_interface_selection);
1052 * atspi_accessible_is_table:
1053 * @obj: a pointer to the #AtspiAccessible instance to query.
1055 * Query whether the specified #AtspiAccessible implements #AtspiTable.
1057 * Returns: #TRUE if @obj implements the #AtspiTable interface,
1061 atspi_accessible_is_table (AtspiAccessible *obj)
1063 return _atspi_accessible_is_a (obj,
1064 atspi_interface_table);
1068 * atspi_accessible_is_streamable_content:
1069 * @obj: a pointer to the #AtspiAccessible instance to query.
1071 * Query whether the specified #AtspiAccessible implements
1072 * #AtspiStreamableContent.
1074 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
1078 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
1081 return _atspi_accessible_is_a (obj,
1082 atspi_interface_streamable_content);
1084 g_warning ("Streamable content not implemented");
1090 * atspi_accessible_is_text:
1091 * @obj: a pointer to the #AtspiAccessible instance to query.
1093 * Query whether the specified #AtspiAccessible implements #AtspiText.
1095 * Returns: #TRUE if @obj implements the #AtspiText interface,
1099 atspi_accessible_is_text (AtspiAccessible *obj)
1101 return _atspi_accessible_is_a (obj,
1102 atspi_interface_text);
1106 * atspi_accessible_is_value:
1107 * @obj: a pointer to the #AtspiAccessible instance to query.
1109 * Query whether the specified #AtspiAccessible implements #AtspiValue.
1111 * Returns: #TRUE if @obj implements the #AtspiValue interface,
1115 atspi_accessible_is_value (AtspiAccessible *obj)
1117 return _atspi_accessible_is_a (obj,
1118 atspi_interface_value);
1122 * atspi_accessible_get_action:
1123 * @obj: a pointer to the #AtspiAccessible instance to query.
1125 * Get the #AtspiAction interface for an #AtspiAccessible.
1127 * Returns: (transfer full): a pointer to an #AtspiAction interface
1128 * instance, or NULL if @obj does not implement #AtspiAction.
1131 atspi_accessible_get_action (AtspiAccessible *accessible)
1133 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1134 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1138 * atspi_accessible_get_collection:
1139 * @obj: a pointer to the #AtspiAccessible instance to query.
1141 * Get the #AtspiCollection interface for an #AtspiAccessible.
1143 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1144 * instance, or NULL if @obj does not implement #AtspiCollection.
1147 atspi_accessible_get_collection (AtspiAccessible *accessible)
1149 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1150 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1154 * atspi_accessible_get_component:
1155 * @obj: a pointer to the #AtspiAccessible instance to query.
1157 * Get the #AtspiComponent interface for an #AtspiAccessible.
1159 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1160 * instance, or NULL if @obj does not implement #AtspiComponent.
1163 atspi_accessible_get_component (AtspiAccessible *obj)
1165 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1166 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1170 * atspi_accessible_get_document:
1171 * @obj: a pointer to the #AtspiAccessible instance to query.
1173 * Get the #AtspiDocument interface for an #AtspiAccessible.
1175 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1176 * instance, or NULL if @obj does not implement #AtspiDocument.
1179 atspi_accessible_get_document (AtspiAccessible *accessible)
1181 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1182 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1186 * atspi_accessible_get_editable_text:
1187 * @obj: a pointer to the #AtspiAccessible instance to query.
1189 * Get the #AtspiEditableText interface for an #AtspiAccessible.
1191 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1192 * instance, or NULL if @obj does not implement #AtspiEditableText.
1195 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1197 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1198 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1202 * atspi_accessible_get_hyperlink:
1203 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1205 * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
1208 * Returns: (transfer full): the #AtspiHyperlink object associated with
1209 * the given #AtspiAccessible, or NULL if not supported.
1212 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1214 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1215 atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1219 * atspi_accessible_get_hypertext:
1220 * @obj: a pointer to the #AtspiAccessible instance to query.
1222 * Get the #AtspiHypertext interface for an #AtspiAccessible.
1224 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1225 * instance, or NULL if @obj does not implement #AtspiHypertext.
1228 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1230 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1231 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1235 * atspi_accessible_get_image:
1236 * @obj: a pointer to the #AtspiAccessible instance to query.
1238 * Get the #AtspiImage interface for an #AtspiAccessible.
1240 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1241 * NULL if @obj does not implement #AtspiImage.
1244 atspi_accessible_get_image (AtspiAccessible *accessible)
1246 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1247 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1251 * atspi_accessible_get_selection:
1252 * @obj: a pointer to the #AtspiAccessible instance to query.
1254 * Get the #AtspiSelection interface for an #AtspiAccessible.
1256 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1257 * instance, or NULL if @obj does not implement #AtspiSelection.
1260 atspi_accessible_get_selection (AtspiAccessible *accessible)
1262 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1263 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1268 * atspi_accessible_get_streamable_content:
1269 * @obj: a pointer to the #AtspiAccessible instance to query.
1271 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1273 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1274 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1276 AtspiStreamableContent *
1277 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1279 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1285 * atspi_accessible_get_table:
1286 * @obj: a pointer to the #AtspiAccessible instance to query.
1288 * Get the #AtspiTable interface for an #AtspiAccessible.
1290 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1291 * NULL if @obj does not implement #AtspiTable.
1294 atspi_accessible_get_table (AtspiAccessible *obj)
1296 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1297 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1301 * atspi_accessible_get_text:
1302 * @obj: a pointer to the #AtspiAccessible instance to query.
1304 * Get the #AtspiTable interface for an #AtspiAccessible.
1306 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1307 * NULL if @obj does not implement #AtspiText.
1310 atspi_accessible_get_text (AtspiAccessible *obj)
1312 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1313 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1317 * atspi_accessible_get_value:
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 #AtspiValue interface instance, or
1323 * NULL if @obj does not implement #AtspiValue.
1326 atspi_accessible_get_value (AtspiAccessible *accessible)
1328 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1329 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1333 append_const_val (GArray *array, const gchar *val)
1335 gchar *dup = g_strdup (val);
1338 g_array_append_val (array, dup);
1342 * atspi_accessible_get_interfaces:
1344 * #obj: The #AtspiAccessible to query.
1346 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1347 * describing the interfaces supported by the object. Interfaces are
1348 * denoted in short-hand (ie, "Component", "Text", etc.)
1351 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1353 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1355 g_return_val_if_fail (obj != NULL, NULL);
1357 append_const_val (ret, "Accessible");
1358 if (atspi_accessible_is_action (obj))
1359 append_const_val (ret, "Action");
1360 if (atspi_accessible_is_collection (obj))
1361 append_const_val (ret, "Collection");
1362 if (atspi_accessible_is_component (obj))
1363 append_const_val (ret, "Component");
1364 if (atspi_accessible_is_document (obj))
1365 append_const_val (ret, "Document");
1366 if (atspi_accessible_is_editable_text (obj))
1367 append_const_val (ret, "EditableText");
1368 if (atspi_accessible_is_hypertext (obj))
1369 append_const_val (ret, "Hypertext");
1370 if (atspi_accessible_is_hyperlink (obj))
1371 append_const_val (ret, "Hyperlink");
1372 if (atspi_accessible_is_image (obj))
1373 append_const_val (ret, "Image");
1374 if (atspi_accessible_is_selection (obj))
1375 append_const_val (ret, "Selection");
1376 if (atspi_accessible_is_table (obj))
1377 append_const_val (ret, "Table");
1378 if (atspi_accessible_is_text (obj))
1379 append_const_val (ret, "Text");
1380 if (atspi_accessible_is_value (obj))
1381 append_const_val (ret, "Value");
1387 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1389 AtspiAccessible *accessible;
1391 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1392 g_return_val_if_fail (accessible != NULL, NULL);
1394 accessible->parent.app = g_object_ref (app);
1395 accessible->parent.path = g_strdup (path);
1401 * atspi_accessible_set_cache_mask:
1403 * @accessible: The #AtspiAccessible to operate on. Must be the desktop or
1404 * the root of an application.
1405 * @mask: An #AtspiCache specifying a bit mask of the types of data to cache.
1407 * Sets the type of data to cache for accessibles.
1408 * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
1409 * then the desktop's cache flag will be used.
1410 * If the desktop's cache flag is also undefined, then all possible data will
1412 * This function is intended to work around bugs in toolkits where the proper
1413 * events are not raised / to aid in testing for such bugs.
1416 atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
1418 g_return_if_fail (accessible != NULL);
1419 g_return_if_fail (accessible->parent.app != NULL);
1420 g_return_if_fail (accessible == accessible->parent.app->root);
1421 accessible->parent.app->cache = mask;
1425 * atspi_accessible_clear_cache:
1426 * @accessible: The #AtspiAccessible whose cache to clear.
1428 * Clears the cached information for the given accessible and all of its
1432 atspi_accessible_clear_cache (AtspiAccessible *accessible)
1438 accessible->cached_properties = ATSPI_CACHE_NONE;
1439 for (l = accessible->children; l; l = l->next)
1440 atspi_accessible_clear_cache (l->data);
1445 _atspi_accessible_get_cache_mask (AtspiAccessible *accessible)
1449 if (!accessible->parent.app)
1450 return ATSPI_CACHE_NONE;
1452 mask = accessible->parent.app->cache;
1453 if (mask == ATSPI_CACHE_UNDEFINED &&
1454 accessible->parent.app->root &&
1455 accessible->parent.app->root->accessible_parent)
1457 AtspiAccessible *desktop = atspi_get_desktop (0);
1458 mask = desktop->parent.app->cache;
1459 g_object_unref (desktop);
1462 if (mask == ATSPI_CACHE_UNDEFINED)
1463 mask = ATSPI_CACHE_ALL;
1469 _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
1471 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1472 AtspiCache result = accessible->cached_properties & mask & flag;
1473 return (result != 0 && atspi_main_loop && !atspi_no_cache);
1477 _atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
1479 AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1481 accessible->cached_properties |= flag & mask;