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->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);
376 (strcmp (dbus_message_get_signature (reply), "v") != 0))
378 dbus_message_iter_init (reply, &iter);
379 dbus_message_iter_recurse (&iter, &iter_variant);
380 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
381 dbus_message_unref (reply);
382 obj->cached_properties |= ATSPI_CACHE_PARENT;
384 if (!obj->accessible_parent)
386 return g_object_ref (obj->accessible_parent);
390 * atspi_accessible_get_child_count:
391 * @obj: a pointer to the #AtspiAccessible object on which to operate.
393 * Get the number of children contained by an #AtspiAccessible object.
395 * Returns: a #long indicating the number of #AtspiAccessible children
396 * contained by an #AtspiAccessible object. or -1 on exception
400 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
402 g_return_val_if_fail (obj != NULL, -1);
404 if (!(obj->cached_properties & ATSPI_CACHE_CHILDREN))
407 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
408 "ChildCount", error, "i", &ret))
413 return g_list_length (obj->children);
417 * atspi_accessible_get_child_at_index:
418 * @obj: a pointer to the #AtspiAccessible object on which to operate.
419 * @child_index: a #long indicating which child is specified.
421 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
423 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
424 * index @child_index. or NULL on exception
427 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
431 AtspiAccessible *child;
433 g_return_val_if_fail (obj != NULL, NULL);
435 if (!(obj->cached_properties & ATSPI_CACHE_CHILDREN))
438 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
439 "GetChildAtIndex", error, "i",
441 return _atspi_dbus_return_accessible_from_message (reply);
444 child = g_list_nth_data (obj->children, child_index);
447 return g_object_ref (child);
451 * atspi_accessible_get_index_in_parent
452 * @obj: a pointer to the #AtspiAccessible object on which to operate.
454 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
456 * Returns: a #glong indicating the index of the #AtspiAccessible object
457 * in its parent (i.e. containing) #AtspiAccessible instance,
458 * or -1 if @obj has no containing parent or on exception.
461 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
466 g_return_val_if_fail (obj != NULL, -1);
467 if (!obj->accessible_parent) return -1;
468 if (!(obj->accessible_parent->cached_properties & ATSPI_CACHE_CHILDREN))
470 dbus_uint32_t ret = -1;
471 _atspi_dbus_call (obj, atspi_interface_accessible,
472 "GetIndexInParent", NULL, "=>u", &ret);
476 l = obj->accessible_parent->children;
479 if (l->data == obj) return i;
490 } Accessibility_Relation;
493 * atspi_accessible_get_relation_set:
494 * @obj: a pointer to the #AtspiAccessible object on which to operate.
496 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
497 * relationships with other #AtspiAccessible objects.
499 * Returns: (element-type AtspiAccessible*) (transfer full): an array of
500 * #AtspiAccessibleRelation pointers. or NULL on exception
503 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
506 DBusMessageIter iter, iter_array;
509 g_return_val_if_fail (obj != NULL, NULL);
511 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
512 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", NULL);
514 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
515 dbus_message_iter_init (reply, &iter);
516 dbus_message_iter_recurse (&iter, &iter_array);
517 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
520 AtspiRelation *relation;
521 relation = _atspi_relation_new_from_iter (&iter_array);
522 new_array = g_array_append_val (ret, relation);
525 dbus_message_iter_next (&iter_array);
531 * atspi_accessible_get_role:
532 * @obj: a pointer to the #AtspiAccessible object on which to operate.
534 * Get the UI role of an #AtspiAccessible object.
535 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
537 * Returns: the #AtspiRole of the object.
541 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
543 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
545 if (!(obj->cached_properties & ATSPI_CACHE_ROLE))
548 /* TODO: Make this a property */
549 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
551 obj->cached_properties |= ATSPI_CACHE_ROLE;
559 * atspi_accessible_get_role_name:
560 * @obj: a pointer to the #AtspiAccessible object on which to operate.
562 * Get a UTF-8 string describing the role this object plays in the UI.
563 * This method will return useful values for roles that fall outside the
564 * enumeration used in atspi_accessible_getRole ().
566 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
570 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
574 g_return_val_if_fail (obj != NULL, NULL);
576 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
579 retval = g_strdup ("");
585 * atspi_accessible_get_localized_role_name:
586 * @obj: a pointer to the #AtspiAccessible object on which to operate.
588 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
589 * This method will return useful values for roles that fall outside the
590 * enumeration used in atspi_accessible_getRole ().
592 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
596 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
600 g_return_val_if_fail (obj != NULL, NULL);
602 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
605 return g_strdup ("");
611 * atspi_accessible_get_state_set:
612 * @obj: a pointer to the #AtspiAccessible object on which to operate.
614 * Gets the current state of an object.
616 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
617 * object's current state.
620 atspi_accessible_get_state_set (AtspiAccessible *obj)
622 if (!(obj->cached_properties & ATSPI_CACHE_STATES))
625 DBusMessageIter iter;
626 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
627 "GetState", NULL, "");
628 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL);
629 dbus_message_iter_init (reply, &iter);
630 _atspi_dbus_set_state (obj, &iter);
631 dbus_message_unref (reply);
634 return g_object_ref (obj->states);
638 * atspi_accessible_get_attributes:
639 * @obj: The #AtspiAccessible being queried.
641 * Get the #AttributeSet representing any assigned
642 * name-value pair attributes or annotations for this object.
643 * For typographic, textual, or textually-semantic attributes, see
644 * atspi_text_get_attributes instead.
646 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
647 * attributes assigned to this object.
650 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
652 DBusMessage *message;
654 g_return_val_if_fail (obj != NULL, NULL);
656 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
657 return _atspi_dbus_return_hash_from_message (message);
661 * atspi_accessible_get_attributes_as_array:
662 * @obj: The #AtspiAccessible being queried.
664 * Get the #AttributeSet representing any assigned
665 * name-value pair attributes or annotations for this object.
666 * For typographic, textual, or textually-semantic attributes, see
667 * atspi_text_get_attributes_as_array instead.
669 * Returns: (element-type gchar*) (transfer full): The name-value-pair
670 * attributes assigned to this object.
673 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
675 DBusMessage *message;
677 g_return_val_if_fail (obj != NULL, NULL);
679 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
680 return _atspi_dbus_return_attribute_array_from_message (message);
684 * atspi_accessible_get_application:
685 * @obj: The #AtspiAccessible being queried.
687 * Get the containing #AtspiApplication for an object.
689 * Returns: (transfer full): the containing AtspiApplication instance for
693 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
695 AtspiAccessible *parent;
700 parent = atspi_accessible_get_parent (obj, NULL);
701 if (!parent || parent == obj ||
702 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
704 g_object_unref (obj);
709 /* Application-specific methods */
712 * atspi_accessible_get_toolkit_name:
713 * @obj: a pointer to the #AtspiAccessible object on which to operate.
715 * Get the toolkit for a #AtspiAccessible object.
716 * Only works on application root objects.
718 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
719 * or NULL on exception
722 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
726 g_return_val_if_fail (obj != NULL, NULL);
728 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName", error, "s", &ret))
730 return g_strdup (ret);
734 * atspi_accessible_get_toolkit_version:
735 * @obj: a pointer to the #AtspiAccessible object on which to operate.
737 * Get the toolkit version for a #AtspiAccessible object.
738 * Only works on application root objects.
740 * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
741 * or NULL on exception
744 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
748 g_return_val_if_fail (obj != NULL, NULL);
750 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitVersion", error, "s", &ret))
752 return g_strdup (ret);
754 /* Interface query methods */
757 * atspi_accessible_is_action:
758 * @obj: a pointer to the #AtspiAccessible instance to query.
760 * Query whether the specified #AtspiAccessible implements #AtspiAction.
762 * Returns: #TRUE if @obj implements the #AtspiAction interface,
766 atspi_accessible_is_action (AtspiAccessible *obj)
768 return _atspi_accessible_is_a (obj,
769 atspi_interface_action);
773 * atspi_accessible_is_application:
774 * @obj: a pointer to the #AtspiAccessible instance to query.
776 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
778 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
782 atspi_accessible_is_application (AtspiAccessible *obj)
784 return _atspi_accessible_is_a (obj,
785 atspi_interface_application);
789 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
791 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
792 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
796 atspi_accessible_is_collection (AtspiAccessible *obj)
798 return _atspi_accessible_is_a (obj,
799 atspi_interface_collection);
803 * atspi_accessible_is_component:
804 * @obj: a pointer to the #AtspiAccessible instance to query.
806 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
808 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
812 atspi_accessible_is_component (AtspiAccessible *obj)
814 return _atspi_accessible_is_a (obj,
815 atspi_interface_component);
819 * atspi_accessible_is_document:
820 * @obj: a pointer to the #AtspiAccessible instance to query.
822 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
824 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
828 atspi_accessible_is_document (AtspiAccessible *obj)
830 return _atspi_accessible_is_a (obj,
831 atspi_interface_document);
835 * atspi_accessible_is_editable_text:
836 * @obj: a pointer to the #AtspiAccessible instance to query.
838 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
840 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
844 atspi_accessible_is_editable_text (AtspiAccessible *obj)
846 return _atspi_accessible_is_a (obj,
847 atspi_interface_editable_text);
851 * atspi_accessible_is_hypertext:
852 * @obj: a pointer to the #AtspiAccessible instance to query.
854 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
856 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
860 atspi_accessible_is_hypertext (AtspiAccessible *obj)
862 return _atspi_accessible_is_a (obj,
863 atspi_interface_hypertext);
867 * atspi_accessible_is_image:
868 * @obj: a pointer to the #AtspiAccessible instance to query.
870 * Query whether the specified #AtspiAccessible implements #AtspiImage.
872 * Returns: #TRUE if @obj implements the #AtspiImage interface,
876 atspi_accessible_is_image (AtspiAccessible *obj)
878 return _atspi_accessible_is_a (obj,
879 atspi_interface_image);
883 * atspi_accessible_is_selection:
884 * @obj: a pointer to the #AtspiAccessible instance to query.
886 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
888 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
892 atspi_accessible_is_selection (AtspiAccessible *obj)
894 return _atspi_accessible_is_a (obj,
895 atspi_interface_selection);
899 * atspi_accessible_is_table:
900 * @obj: a pointer to the #AtspiAccessible instance to query.
902 * Query whether the specified #AtspiAccessible implements #AtspiTable.
904 * Returns: #TRUE if @obj implements the #AtspiTable interface,
908 atspi_accessible_is_table (AtspiAccessible *obj)
910 return _atspi_accessible_is_a (obj,
911 atspi_interface_table);
915 * atspi_accessible_is_streamable_content:
916 * @obj: a pointer to the #AtspiAccessible instance to query.
918 * Query whether the specified #AtspiAccessible implements
919 * #AtspiStreamableContent.
921 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
925 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
928 return _atspi_accessible_is_a (obj,
929 atspi_interface_streamable_content);
931 g_warning (_("Streamable content not implemented"));
937 * atspi_accessible_is_text:
938 * @obj: a pointer to the #AtspiAccessible instance to query.
940 * Query whether the specified #AtspiAccessible implements #AtspiText.
942 * Returns: #TRUE if @obj implements the #AtspiText interface,
946 atspi_accessible_is_text (AtspiAccessible *obj)
948 return _atspi_accessible_is_a (obj,
949 atspi_interface_text);
953 * atspi_accessible_is_value:
954 * @obj: a pointer to the #AtspiAccessible instance to query.
956 * Query whether the specified #AtspiAccessible implements #AtspiValue.
958 * Returns: #TRUE if @obj implements the #AtspiValue interface,
962 atspi_accessible_is_value (AtspiAccessible *obj)
964 return _atspi_accessible_is_a (obj,
965 atspi_interface_value);
969 * atspi_accessible_get_action:
970 * @obj: a pointer to the #AtspiAccessible instance to query.
972 * Get the #AtspiAction interface for an #AtspiAccessible.
974 * Returns: (transfer full): a pointer to an #AtspiAction interface
975 * instance, or NULL if @obj does not implement #AtspiAction.
978 atspi_accessible_get_action (AtspiAccessible *accessible)
980 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
981 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
985 * atspi_accessible_get_collection:
986 * @obj: a pointer to the #AtspiAccessible instance to query.
988 * Get the #AtspiCollection interface for an #AtspiAccessible.
990 * Returns: (transfer full): a pointer to an #AtspiCollection interface
991 * instance, or NULL if @obj does not implement #AtspiCollection.
994 atspi_accessible_get_collection (AtspiAccessible *accessible)
996 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
997 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
1001 * atspi_accessible_get_component:
1002 * @obj: a pointer to the #AtspiAccessible instance to query.
1004 * Get the #AtspiComponent interface for an #AtspiAccessible.
1006 * Returns: (transfer full): a pointer to an #AtspiComponent interface
1007 * instance, or NULL if @obj does not implement #AtspiComponent.
1010 atspi_accessible_get_component (AtspiAccessible *obj)
1012 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1013 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1017 * atspi_accessible_get_document:
1018 * @obj: a pointer to the #AtspiAccessible instance to query.
1020 * Get the #AtspiDocument interface for an #AtspiAccessible.
1022 * Returns: (transfer full): a pointer to an #AtspiDocument interface
1023 * instance, or NULL if @obj does not implement #AtspiDocument.
1026 atspi_accessible_get_document (AtspiAccessible *accessible)
1028 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1029 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
1033 * atspi_accessible_get_editable_text:
1034 * @obj: a pointer to the #AtspiAccessible instance to query.
1036 * Get the #AtspiEditableText interface for an #AtspiAccessible.
1038 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1039 * instance, or NULL if @obj does not implement #AtspiEditableText.
1042 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1044 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1045 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
1049 * atspi_accessible_get_hyperlink:
1050 * @obj: a pointer to the #AtspiAccessible object on which to operate.
1052 * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
1055 * Returns: (transfer full): the #AtspiHyperlink object associated with
1056 * the given #AtspiAccessible, or NULL if not supported.
1059 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1061 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1062 atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1066 * atspi_accessible_get_hypertext:
1067 * @obj: a pointer to the #AtspiAccessible instance to query.
1069 * Get the #AtspiHypertext interface for an #AtspiAccessible.
1071 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1072 * instance, or NULL if @obj does not implement #AtspiHypertext.
1075 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1077 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1078 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1082 * atspi_accessible_get_image:
1083 * @obj: a pointer to the #AtspiAccessible instance to query.
1085 * Get the #AtspiImage interface for an #AtspiAccessible.
1087 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1088 * NULL if @obj does not implement #AtspiImage.
1091 atspi_accessible_get_image (AtspiAccessible *accessible)
1093 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1094 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1098 * atspi_accessible_get_selection:
1099 * @obj: a pointer to the #AtspiAccessible instance to query.
1101 * Get the #AtspiSelection interface for an #AtspiAccessible.
1103 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1104 * instance, or NULL if @obj does not implement #AtspiSelection.
1107 atspi_accessible_get_selection (AtspiAccessible *accessible)
1109 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1110 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1115 * atspi_accessible_get_streamable_content:
1116 * @obj: a pointer to the #AtspiAccessible instance to query.
1118 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1120 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1121 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1123 AtspiStreamableContent *
1124 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1126 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1132 * atspi_accessible_get_table:
1133 * @obj: a pointer to the #AtspiAccessible instance to query.
1135 * Get the #AtspiTable interface for an #AtspiAccessible.
1137 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1138 * NULL if @obj does not implement #AtspiTable.
1141 atspi_accessible_get_table (AtspiAccessible *obj)
1143 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1144 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1148 * atspi_accessible_get_text:
1149 * @obj: a pointer to the #AtspiAccessible instance to query.
1151 * Get the #AtspiTable interface for an #AtspiAccessible.
1153 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1154 * NULL if @obj does not implement #AtspiText.
1157 atspi_accessible_get_text (AtspiAccessible *obj)
1159 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1160 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1164 * atspi_accessible_get_value:
1165 * @obj: a pointer to the #AtspiAccessible instance to query.
1167 * Get the #AtspiTable interface for an #AtspiAccessible.
1169 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1170 * NULL if @obj does not implement #AtspiValue.
1173 atspi_accessible_get_value (AtspiAccessible *accessible)
1175 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1176 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1180 _atspi_accessible_is_a (AtspiAccessible *accessible,
1181 const char *interface_name)
1185 if (accessible == NULL)
1190 if (!(accessible->cached_properties & ATSPI_CACHE_INTERFACES))
1193 DBusMessageIter iter;
1194 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
1195 "GetInterfaces", NULL, "");
1196 _ATSPI_DBUS_CHECK_SIG (reply, "as", FALSE);
1197 dbus_message_iter_init (reply, &iter);
1198 _atspi_dbus_set_interfaces (accessible, &iter);
1199 dbus_message_unref (reply);
1202 n = _atspi_get_iface_num (interface_name);
1203 if (n == -1) return FALSE;
1204 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1208 append_const_val (GArray *array, const gchar *val)
1210 gchar *dup = g_strdup (val);
1213 g_array_append_val (array, dup);
1217 * atspi_accessible_get_interfaces:
1219 * #obj: The #AtspiAccessible to query.
1221 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1222 * describing the interfaces supported by the object. Interfaces are
1223 * denoted in short-hand (ie, "Component", "Text", etc.)
1226 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1228 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1233 g_return_val_if_fail (obj != NULL, NULL);
1235 if (atspi_accessible_is_action (obj))
1236 append_const_val (ret, "Action");
1237 if (atspi_accessible_is_collection (obj))
1238 append_const_val (ret, "Collection");
1239 if (atspi_accessible_is_component (obj))
1240 append_const_val (ret, "Component");
1241 if (atspi_accessible_is_document (obj))
1242 append_const_val (ret, "Document");
1243 if (atspi_accessible_is_editable_text (obj))
1244 append_const_val (ret, "EditableText");
1245 if (atspi_accessible_is_hypertext (obj))
1246 append_const_val (ret, "Hypertext");
1247 if (atspi_accessible_is_image (obj))
1248 append_const_val (ret, "Image");
1249 if (atspi_accessible_is_selection (obj))
1250 append_const_val (ret, "Selection");
1251 if (atspi_accessible_is_table (obj))
1252 append_const_val (ret, "Table");
1253 if (atspi_accessible_is_text (obj))
1254 append_const_val (ret, "Text");
1255 if (atspi_accessible_is_value (obj))
1256 append_const_val (ret, "Value");
1262 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1264 AtspiAccessible *accessible;
1266 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1267 g_return_val_if_fail (accessible != NULL, NULL);
1269 accessible->parent.app = g_object_ref (app);
1270 accessible->parent.path = g_strdup (path);