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.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 #include "atspi-private.h"
28 atspi_action_interface_init (AtspiAction *action)
33 atspi_collection_interface_init (AtspiCollection *component)
38 atspi_component_interface_init (AtspiComponent *component)
43 atspi_document_interface_init (AtspiDocument *document)
47 atspi_editable_text_interface_init (AtspiEditableText *editable_text)
52 atspi_hypertext_interface_init (AtspiHypertext *hypertext)
57 atspi_image_interface_init (AtspiImage *image)
62 atspi_selection_interface_init (AtspiSelection *selection)
67 atspi_table_interface_init (AtspiTable *table)
72 atspi_text_interface_init (AtspiText *text)
77 atspi_value_interface_init (AtspiValue *value)
81 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT,
82 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init)
83 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COLLECTION, atspi_collection_interface_init)
84 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
85 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_DOCUMENT, atspi_document_interface_init)
86 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init)
87 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_HYPERTEXT, atspi_hypertext_interface_init)
88 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init)
89 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init)
90 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
91 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init)
92 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_VALUE, atspi_value_interface_init))
94 #ifdef DEBUG_REF_COUNTS
95 static gint accessible_count = 0;
99 atspi_accessible_init (AtspiAccessible *accessible)
101 #ifdef DEBUG_REF_COUNTS
103 printf("at-spi: init: %d objects\n", accessible_count);
108 atspi_accessible_dispose (GObject *object)
110 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
113 AtspiAccessible *parent;
115 /* TODO: Only fire if object not already marked defunct */
116 memset (&e, 0, sizeof (e));
117 e.type = "object:state-change:defunct";
118 e.source = accessible;
121 _atspi_send_event (&e);
123 if (accessible->states)
125 g_object_unref (accessible->states);
126 accessible->states = NULL;
129 parent = accessible->accessible_parent;
130 if (parent && parent->children)
132 GList*ls = g_list_find (parent->children, accessible);
135 gboolean replace = (ls == parent->children);
136 ls = g_list_remove (ls, accessible);
138 parent->children = ls;
139 g_object_unref (object);
145 g_object_unref (parent);
146 accessible->accessible_parent = NULL;
149 G_OBJECT_CLASS (atspi_accessible_parent_class) ->dispose (object);
153 atspi_accessible_finalize (GObject *object)
155 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
157 g_free (accessible->description);
158 g_free (accessible->name);
160 #ifdef DEBUG_REF_COUNTS
162 printf("at-spi: finalize: %d objects\n", accessible_count);
165 G_OBJECT_CLASS (atspi_accessible_parent_class)
170 atspi_accessible_class_init (AtspiAccessibleClass *klass)
172 GObjectClass *object_class = G_OBJECT_CLASS (klass);
174 object_class->dispose = atspi_accessible_dispose;
175 object_class->finalize = atspi_accessible_finalize;
178 /* TODO: Generate following from spec? */
179 static const char *role_names [] =
237 "table-column-header",
239 "tear-off-menu-item",
269 "input method window"
272 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
275 * atspi_role_get_name
276 * @role: an #AtspiAccessibleRole object to query.
278 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
279 * <em>DEPRECATED.</em>
281 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
284 atspi_role_get_name (AtspiRole role)
286 if (role < MAX_ROLES && role_names [(int) role])
288 return g_strdup (role_names [(int) role]);
292 return g_strdup ("");
297 * atspi_accessible_get_name:
298 * @obj: a pointer to the #AtspiAccessible object on which to operate.
300 * Get the name of an #AtspiAccessible object.
302 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
303 * or NULL on exception
306 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
308 g_return_val_if_fail (obj != NULL, g_strdup (""));
309 if (!(obj->cached_properties & ATSPI_CACHE_NAME))
311 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
313 return g_strdup ("");
314 obj->cached_properties |= ATSPI_CACHE_NAME;
316 return g_strdup (obj->name);
320 * atspi_accessible_get_description:
321 * @obj: a pointer to the #AtspiAccessible object on which to operate.
323 * Get the description of an #AtspiAccessible object.
325 * Returns: a UTF-8 string describing the #AtspiAccessible object.
326 * or NULL on exception
329 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
331 g_return_val_if_fail (obj != NULL, g_strdup (""));
333 if (!(obj->cached_properties & ATSPI_CACHE_DESCRIPTION))
335 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
336 "Description", error, "s",
338 return g_strdup ("");
339 obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
341 return g_strdup (obj->description);
344 const char *str_parent = "Parent";
347 * atspi_accessible_get_parent:
348 * @obj: a pointer to the #AtspiAccessible object to query.
350 * Get an #AtspiAccessible object's parent container.
352 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
353 * contains the given #AtspiAccessible instance, or NULL if the @obj
354 * has no parent container.
358 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
360 g_return_val_if_fail (obj != NULL, NULL);
362 if (obj->parent.app && !(obj->cached_properties & ATSPI_CACHE_PARENT))
364 DBusMessage *message, *reply;
365 DBusMessageIter iter, iter_variant;
366 message = dbus_message_new_method_call (obj->parent.app->bus_name,
368 DBUS_INTERFACE_PROPERTIES, "Get");
371 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
372 DBUS_TYPE_STRING, &str_parent,
374 reply = _atspi_dbus_send_with_reply_and_block (message);
377 if (strcmp (dbus_message_get_signature (reply), "v") != 0)
379 dbus_message_unref (reply);
382 dbus_message_iter_init (reply, &iter);
383 dbus_message_iter_recurse (&iter, &iter_variant);
384 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
385 dbus_message_unref (reply);
386 obj->cached_properties |= ATSPI_CACHE_PARENT;
388 if (!obj->accessible_parent)
390 return g_object_ref (obj->accessible_parent);
394 * atspi_accessible_get_child_count:
395 * @obj: a pointer to the #AtspiAccessible object on which to operate.
397 * Get the number of children contained by an #AtspiAccessible object.
399 * Returns: a #long indicating the number of #AtspiAccessible children
400 * contained by an #AtspiAccessible object. or -1 on exception
404 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
406 g_return_val_if_fail (obj != NULL, -1);
408 if (!(obj->cached_properties & ATSPI_CACHE_CHILDREN))
411 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
412 "ChildCount", error, "i", &ret))
417 return g_list_length (obj->children);
421 * atspi_accessible_get_child_at_index:
422 * @obj: a pointer to the #AtspiAccessible object on which to operate.
423 * @child_index: a #long indicating which child is specified.
425 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
427 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
428 * index @child_index. or NULL on exception
431 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
435 AtspiAccessible *child;
437 g_return_val_if_fail (obj != NULL, NULL);
439 if (!(obj->cached_properties & ATSPI_CACHE_CHILDREN))
442 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
443 "GetChildAtIndex", error, "i",
445 return _atspi_dbus_return_accessible_from_message (reply);
448 child = g_list_nth_data (obj->children, child_index);
451 return g_object_ref (child);
455 * atspi_accessible_get_index_in_parent
456 * @obj: a pointer to the #AtspiAccessible object on which to operate.
458 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
460 * Returns: a #glong indicating the index of the #AtspiAccessible object
461 * in its parent (i.e. containing) #AtspiAccessible instance,
462 * or -1 if @obj has no containing parent or on exception.
465 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
470 g_return_val_if_fail (obj != NULL, -1);
471 if (!obj->accessible_parent) return -1;
472 if (!(obj->accessible_parent->cached_properties & ATSPI_CACHE_CHILDREN))
474 dbus_uint32_t ret = -1;
475 _atspi_dbus_call (obj, atspi_interface_accessible,
476 "GetIndexInParent", NULL, "=>u", &ret);
480 l = obj->accessible_parent->children;
483 if (l->data == obj) return i;
494 } Accessibility_Relation;
497 * atspi_accessible_get_relation_set:
498 * @obj: a pointer to the #AtspiAccessible object on which to operate.
500 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
501 * relationships with other #AtspiAccessible objects.
503 * Returns: (element-type AtspiAccessible*) (transfer full): an array of
504 * #AtspiAccessibleRelation pointers. or NULL on exception
507 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
510 DBusMessageIter iter, iter_array;
513 g_return_val_if_fail (obj != NULL, NULL);
515 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
518 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
520 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
521 dbus_message_iter_init (reply, &iter);
522 dbus_message_iter_recurse (&iter, &iter_array);
523 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
526 AtspiRelation *relation;
527 relation = _atspi_relation_new_from_iter (&iter_array);
528 new_array = 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 (!(obj->cached_properties & ATSPI_CACHE_ROLE))
555 /* TODO: Make this a property */
556 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
558 obj->cached_properties |= 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)
581 g_return_val_if_fail (obj != NULL, NULL);
583 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
586 retval = g_strdup ("");
592 * atspi_accessible_get_localized_role_name:
593 * @obj: a pointer to the #AtspiAccessible object on which to operate.
595 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
596 * This method will return useful values for roles that fall outside the
597 * enumeration used in atspi_accessible_getRole ().
599 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
603 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
607 g_return_val_if_fail (obj != NULL, NULL);
609 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
612 return g_strdup ("");
617 static AtspiStateSet *
620 AtspiStateSet *set = atspi_state_set_new (NULL);
621 atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
626 * atspi_accessible_get_state_set:
627 * @obj: a pointer to the #AtspiAccessible object on which to operate.
629 * Gets the current state of an object.
631 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
632 * object's current state.
635 atspi_accessible_get_state_set (AtspiAccessible *obj)
637 if (!obj->parent.app || !obj->parent.app->bus)
638 return defunct_set ();
641 if (!(obj->cached_properties & ATSPI_CACHE_STATES))
644 DBusMessageIter iter;
645 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
646 "GetState", NULL, "");
647 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
648 dbus_message_iter_init (reply, &iter);
649 _atspi_dbus_set_state (obj, &iter);
650 dbus_message_unref (reply);
653 return g_object_ref (obj->states);
657 * atspi_accessible_get_attributes:
658 * @obj: The #AtspiAccessible being queried.
660 * Get the #AttributeSet representing any assigned
661 * name-value pair attributes or annotations for this object.
662 * For typographic, textual, or textually-semantic attributes, see
663 * atspi_text_get_attributes instead.
665 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
666 * attributes assigned to this object.
669 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
671 DBusMessage *message;
673 g_return_val_if_fail (obj != NULL, NULL);
675 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
676 return _atspi_dbus_return_hash_from_message (message);
680 * atspi_accessible_get_attributes_as_array:
681 * @obj: The #AtspiAccessible being queried.
683 * Get the #AttributeSet representing any assigned
684 * name-value pair attributes or annotations for this object.
685 * For typographic, textual, or textually-semantic attributes, see
686 * atspi_text_get_attributes_as_array instead.
688 * Returns: (element-type gchar*) (transfer full): The name-value-pair
689 * attributes assigned to this object.
692 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
694 DBusMessage *message;
696 g_return_val_if_fail (obj != NULL, NULL);
698 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
699 return _atspi_dbus_return_attribute_array_from_message (message);
703 * atspi_accessible_get_application:
704 * @obj: The #AtspiAccessible being queried.
706 * Get the containing #AtspiApplication for an object.
708 * Returns: (transfer full): the containing AtspiApplication instance for
712 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
714 AtspiAccessible *parent;
719 parent = atspi_accessible_get_parent (obj, NULL);
720 if (!parent || parent == obj ||
721 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
723 g_object_unref (obj);
728 /* Application-specific methods */
731 * atspi_accessible_get_toolkit_name:
732 * @obj: a pointer to the #AtspiAccessible object on which to operate.
734 * Get the toolkit for a #AtspiAccessible object.
735 * Only works on application root objects.
737 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
738 * or NULL on exception
741 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
745 g_return_val_if_fail (obj != NULL, NULL);
747 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName", error, "s", &ret))
749 return g_strdup (ret);
753 * atspi_accessible_get_toolkit_version:
754 * @obj: a pointer to the #AtspiAccessible object on which to operate.
756 * Get the toolkit version for a #AtspiAccessible object.
757 * Only works on application root objects.
759 * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
760 * or NULL on exception
763 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
767 g_return_val_if_fail (obj != NULL, NULL);
769 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitVersion", error, "s", &ret))
771 return g_strdup (ret);
773 /* Interface query methods */
776 * atspi_accessible_is_action:
777 * @obj: a pointer to the #AtspiAccessible instance to query.
779 * Query whether the specified #AtspiAccessible implements #AtspiAction.
781 * Returns: #TRUE if @obj implements the #AtspiAction interface,
785 atspi_accessible_is_action (AtspiAccessible *obj)
787 return _atspi_accessible_is_a (obj,
788 atspi_interface_action);
792 * atspi_accessible_is_application:
793 * @obj: a pointer to the #AtspiAccessible instance to query.
795 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
797 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
801 atspi_accessible_is_application (AtspiAccessible *obj)
803 return _atspi_accessible_is_a (obj,
804 atspi_interface_application);
808 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
810 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
811 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
815 atspi_accessible_is_collection (AtspiAccessible *obj)
817 return _atspi_accessible_is_a (obj,
818 atspi_interface_collection);
822 * atspi_accessible_is_component:
823 * @obj: a pointer to the #AtspiAccessible instance to query.
825 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
827 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
831 atspi_accessible_is_component (AtspiAccessible *obj)
833 return _atspi_accessible_is_a (obj,
834 atspi_interface_component);
838 * atspi_accessible_is_document:
839 * @obj: a pointer to the #AtspiAccessible instance to query.
841 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
843 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
847 atspi_accessible_is_document (AtspiAccessible *obj)
849 return _atspi_accessible_is_a (obj,
850 atspi_interface_document);
854 * atspi_accessible_is_editable_text:
855 * @obj: a pointer to the #AtspiAccessible instance to query.
857 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
859 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
863 atspi_accessible_is_editable_text (AtspiAccessible *obj)
865 return _atspi_accessible_is_a (obj,
866 atspi_interface_editable_text);
870 * atspi_accessible_is_hypertext:
871 * @obj: a pointer to the #AtspiAccessible instance to query.
873 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
875 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
879 atspi_accessible_is_hypertext (AtspiAccessible *obj)
881 return _atspi_accessible_is_a (obj,
882 atspi_interface_hypertext);
886 * atspi_accessible_is_image:
887 * @obj: a pointer to the #AtspiAccessible instance to query.
889 * Query whether the specified #AtspiAccessible implements #AtspiImage.
891 * Returns: #TRUE if @obj implements the #AtspiImage interface,
895 atspi_accessible_is_image (AtspiAccessible *obj)
897 return _atspi_accessible_is_a (obj,
898 atspi_interface_image);
902 * atspi_accessible_is_selection:
903 * @obj: a pointer to the #AtspiAccessible instance to query.
905 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
907 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
911 atspi_accessible_is_selection (AtspiAccessible *obj)
913 return _atspi_accessible_is_a (obj,
914 atspi_interface_selection);
918 * atspi_accessible_is_table:
919 * @obj: a pointer to the #AtspiAccessible instance to query.
921 * Query whether the specified #AtspiAccessible implements #AtspiTable.
923 * Returns: #TRUE if @obj implements the #AtspiTable interface,
927 atspi_accessible_is_table (AtspiAccessible *obj)
929 return _atspi_accessible_is_a (obj,
930 atspi_interface_table);
934 * atspi_accessible_is_streamable_content:
935 * @obj: a pointer to the #AtspiAccessible instance to query.
937 * Query whether the specified #AtspiAccessible implements
938 * #AtspiStreamableContent.
940 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
944 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
947 return _atspi_accessible_is_a (obj,
948 atspi_interface_streamable_content);
950 g_warning (_("Streamable content not implemented"));
956 * atspi_accessible_is_text:
957 * @obj: a pointer to the #AtspiAccessible instance to query.
959 * Query whether the specified #AtspiAccessible implements #AtspiText.
961 * Returns: #TRUE if @obj implements the #AtspiText interface,
965 atspi_accessible_is_text (AtspiAccessible *obj)
967 return _atspi_accessible_is_a (obj,
968 atspi_interface_text);
972 * atspi_accessible_is_value:
973 * @obj: a pointer to the #AtspiAccessible instance to query.
975 * Query whether the specified #AtspiAccessible implements #AtspiValue.
977 * Returns: #TRUE if @obj implements the #AtspiValue interface,
981 atspi_accessible_is_value (AtspiAccessible *obj)
983 return _atspi_accessible_is_a (obj,
984 atspi_interface_value);
988 * atspi_accessible_get_action:
989 * @obj: a pointer to the #AtspiAccessible instance to query.
991 * Get the #AtspiAction interface for an #AtspiAccessible.
993 * Returns: (transfer full): a pointer to an #AtspiAction interface
994 * instance, or NULL if @obj does not implement #AtspiAction.
997 atspi_accessible_get_action (AtspiAccessible *accessible)
999 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1000 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
1004 * atspi_accessible_get_collection:
1005 * @obj: a pointer to the #AtspiAccessible instance to query.
1007 * Get the #AtspiCollection interface for an #AtspiAccessible.
1009 * Returns: (transfer full): a pointer to an #AtspiCollection interface
1010 * instance, or NULL if @obj does not implement #AtspiCollection.
1013 atspi_accessible_get_collection (AtspiAccessible *accessible)
1015 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1016 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1020 * atspi_accessible_get_component:
1021 * @obj: a pointer to the #AtspiAccessible instance to query.
1023 * Get the #AtspiComponent interface for an #AtspiAccessible.
1025 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1026 * instance, or NULL if @obj does not implement #AtspiComponent.
1029 atspi_accessible_get_component (AtspiAccessible *obj)
1031 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1032 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1036 * atspi_accessible_get_document:
1037 * @obj: a pointer to the #AtspiAccessible instance to query.
1039 * Get the #AtspiDocument interface for an #AtspiAccessible.
1041 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1042 * instance, or NULL if @obj does not implement #AtspiDocument.
1045 atspi_accessible_get_document (AtspiAccessible *accessible)
1047 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1048 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1052 * atspi_accessible_get_editable_text:
1053 * @obj: a pointer to the #AtspiAccessible instance to query.
1055 * Get the #AtspiEditableText interface for an #AtspiAccessible.
1057 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1058 * instance, or NULL if @obj does not implement #AtspiEditableText.
1061 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1063 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1064 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1068 * atspi_accessible_get_hyperlink:
1069 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1071 * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
1074 * Returns: (transfer full): the #AtspiHyperlink object associated with
1075 * the given #AtspiAccessible, or NULL if not supported.
1078 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1080 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1081 atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1085 * atspi_accessible_get_hypertext:
1086 * @obj: a pointer to the #AtspiAccessible instance to query.
1088 * Get the #AtspiHypertext interface for an #AtspiAccessible.
1090 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1091 * instance, or NULL if @obj does not implement #AtspiHypertext.
1094 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1096 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1097 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1101 * atspi_accessible_get_image:
1102 * @obj: a pointer to the #AtspiAccessible instance to query.
1104 * Get the #AtspiImage interface for an #AtspiAccessible.
1106 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1107 * NULL if @obj does not implement #AtspiImage.
1110 atspi_accessible_get_image (AtspiAccessible *accessible)
1112 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1113 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1117 * atspi_accessible_get_selection:
1118 * @obj: a pointer to the #AtspiAccessible instance to query.
1120 * Get the #AtspiSelection interface for an #AtspiAccessible.
1122 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1123 * instance, or NULL if @obj does not implement #AtspiSelection.
1126 atspi_accessible_get_selection (AtspiAccessible *accessible)
1128 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1129 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1134 * atspi_accessible_get_streamable_content:
1135 * @obj: a pointer to the #AtspiAccessible instance to query.
1137 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1139 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1140 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1142 AtspiStreamableContent *
1143 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1145 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1151 * atspi_accessible_get_table:
1152 * @obj: a pointer to the #AtspiAccessible instance to query.
1154 * Get the #AtspiTable interface for an #AtspiAccessible.
1156 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1157 * NULL if @obj does not implement #AtspiTable.
1160 atspi_accessible_get_table (AtspiAccessible *obj)
1162 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1163 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1167 * atspi_accessible_get_text:
1168 * @obj: a pointer to the #AtspiAccessible instance to query.
1170 * Get the #AtspiTable interface for an #AtspiAccessible.
1172 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1173 * NULL if @obj does not implement #AtspiText.
1176 atspi_accessible_get_text (AtspiAccessible *obj)
1178 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1179 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1183 * atspi_accessible_get_value:
1184 * @obj: a pointer to the #AtspiAccessible instance to query.
1186 * Get the #AtspiTable interface for an #AtspiAccessible.
1188 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1189 * NULL if @obj does not implement #AtspiValue.
1192 atspi_accessible_get_value (AtspiAccessible *accessible)
1194 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1195 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1199 _atspi_accessible_is_a (AtspiAccessible *accessible,
1200 const char *interface_name)
1204 if (accessible == NULL)
1209 if (!(accessible->cached_properties & ATSPI_CACHE_INTERFACES))
1212 DBusMessageIter iter;
1213 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
1214 "GetInterfaces", NULL, "");
1215 _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
1216 dbus_message_iter_init (reply, &iter);
1217 _atspi_dbus_set_interfaces (accessible, &iter);
1218 dbus_message_unref (reply);
1221 n = _atspi_get_iface_num (interface_name);
1222 if (n == -1) return FALSE;
1223 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1227 append_const_val (GArray *array, const gchar *val)
1229 gchar *dup = g_strdup (val);
1232 g_array_append_val (array, dup);
1236 * atspi_accessible_get_interfaces:
1238 * #obj: The #AtspiAccessible to query.
1240 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1241 * describing the interfaces supported by the object. Interfaces are
1242 * denoted in short-hand (ie, "Component", "Text", etc.)
1245 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1247 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1252 g_return_val_if_fail (obj != NULL, NULL);
1254 if (atspi_accessible_is_action (obj))
1255 append_const_val (ret, "Action");
1256 if (atspi_accessible_is_collection (obj))
1257 append_const_val (ret, "Collection");
1258 if (atspi_accessible_is_component (obj))
1259 append_const_val (ret, "Component");
1260 if (atspi_accessible_is_document (obj))
1261 append_const_val (ret, "Document");
1262 if (atspi_accessible_is_editable_text (obj))
1263 append_const_val (ret, "EditableText");
1264 if (atspi_accessible_is_hypertext (obj))
1265 append_const_val (ret, "Hypertext");
1266 if (atspi_accessible_is_image (obj))
1267 append_const_val (ret, "Image");
1268 if (atspi_accessible_is_selection (obj))
1269 append_const_val (ret, "Selection");
1270 if (atspi_accessible_is_table (obj))
1271 append_const_val (ret, "Table");
1272 if (atspi_accessible_is_text (obj))
1273 append_const_val (ret, "Text");
1274 if (atspi_accessible_is_value (obj))
1275 append_const_val (ret, "Value");
1281 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1283 AtspiAccessible *accessible;
1285 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1286 g_return_val_if_fail (accessible != NULL, NULL);
1288 accessible->parent.app = g_object_ref (app);
1289 accessible->parent.path = g_strdup (path);