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))
95 atspi_accessible_init (AtspiAccessible *accessible)
100 atspi_accessible_finalize (GObject *obj)
102 /*AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj); */
104 /* TODO: Unref parent/children, etc. */
108 atspi_accessible_class_init (AtspiAccessibleClass *klass)
110 GObjectClass *object_class = G_OBJECT_CLASS (klass);
112 object_class->finalize = atspi_accessible_finalize;
115 /* TODO: Generate following from spec? */
116 static const char *role_names [] =
174 "table-column-header",
176 "tear-off-menu-item",
206 "input method window"
209 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
212 * atspi_role_get_name
213 * @role: an #AtspiAccessibleRole object to query.
215 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
216 * <em>DEPRECATED.</em>
218 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
221 atspi_role_get_name (AtspiRole role)
223 if (role < MAX_ROLES && role_names [(int) role])
225 return g_strdup (role_names [(int) role]);
229 return g_strdup ("");
234 * atspi_accessible_get_name:
235 * @obj: a pointer to the #AtspiAccessible object on which to operate.
237 * Get the name of an #AtspiAccessible object.
239 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
240 * or NULL on exception
243 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
245 g_return_val_if_fail (obj != NULL, g_strdup (""));
246 if (!(obj->cached_properties & ATSPI_CACHE_NAME))
248 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
250 return g_strdup ("");
251 obj->cached_properties |= ATSPI_CACHE_NAME;
253 return g_strdup (obj->name);
257 * atspi_accessible_get_description:
258 * @obj: a pointer to the #AtspiAccessible object on which to operate.
260 * Get the description of an #AtspiAccessible object.
262 * Returns: a UTF-8 string describing the #AtspiAccessible object.
263 * or NULL on exception
266 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
268 g_return_val_if_fail (obj != NULL, g_strdup (""));
270 if (!(obj->cached_properties & ATSPI_CACHE_DESCRIPTION))
272 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetDescription", NULL, "=>s", &obj->description))
273 return g_strdup ("");
274 obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
276 return g_strdup (obj->description);
279 const char *str_parent = "Parent";
282 * atspi_accessible_get_parent:
283 * @obj: a pointer to the #AtspiAccessible object to query.
285 * Get an #AtspiAccessible object's parent container.
287 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
288 * contains the given #AtspiAccessible instance, or NULL if the @obj
289 * has no parent container.
293 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
295 g_return_val_if_fail (obj != NULL, NULL);
297 if (!(obj->cached_properties & ATSPI_CACHE_PARENT))
299 DBusMessage *message, *reply;
300 DBusMessageIter iter, iter_variant;
301 message = dbus_message_new_method_call (obj->parent.app->bus_name,
303 DBUS_INTERFACE_PROPERTIES, "Get");
306 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
307 DBUS_TYPE_STRING, &str_parent,
309 reply = _atspi_dbus_send_with_reply_and_block (message);
311 (strcmp (dbus_message_get_signature (reply), "v") != 0))
313 dbus_message_iter_init (reply, &iter);
314 dbus_message_iter_recurse (&iter, &iter_variant);
315 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
316 dbus_message_unref (reply);
317 obj->cached_properties |= ATSPI_CACHE_PARENT;
319 if (!obj->accessible_parent)
321 return g_object_ref (obj->accessible_parent);
325 * atspi_accessible_get_child_count:
326 * @obj: a pointer to the #AtspiAccessible object on which to operate.
328 * Get the number of children contained by an #AtspiAccessible object.
330 * Returns: a #long indicating the number of #AtspiAccessible children
331 * contained by an #AtspiAccessible object. or -1 on exception
335 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
337 g_return_val_if_fail (obj != NULL, -1);
339 if (!(obj->cached_properties & ATSPI_CACHE_CHILDREN))
342 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
343 "ChildCount", error, "i", &ret))
348 return g_list_length (obj->children);
352 * atspi_accessible_get_child_at_index:
353 * @obj: a pointer to the #AtspiAccessible object on which to operate.
354 * @child_index: a #long indicating which child is specified.
356 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
358 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
359 * index @child_index. or NULL on exception
362 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
366 AtspiAccessible *child;
368 g_return_val_if_fail (obj != NULL, NULL);
370 if (!(obj->cached_properties & ATSPI_CACHE_CHILDREN))
373 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
374 "GetChildAtIndex", error, "i",
376 return _atspi_dbus_return_accessible_from_message (reply);
379 child = g_list_nth_data (obj->children, child_index);
382 return g_object_ref (child);
386 * atspi_accessible_get_index_in_parent
387 * @obj: a pointer to the #AtspiAccessible object on which to operate.
389 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
391 * Returns: a #glong indicating the index of the #AtspiAccessible object
392 * in its parent (i.e. containing) #AtspiAccessible instance,
393 * or -1 if @obj has no containing parent or on exception.
396 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
401 g_return_val_if_fail (obj != NULL, -1);
402 if (!obj->accessible_parent) return -1;
403 if (!(obj->accessible_parent->cached_properties & ATSPI_CACHE_CHILDREN))
405 dbus_uint32_t ret = -1;
406 _atspi_dbus_call (obj, atspi_interface_accessible,
407 "GetIndexInParent", NULL, "=>u", &ret);
411 l = obj->accessible_parent->children;
414 if (l->data == obj) return i;
425 } Accessibility_Relation;
428 * atspi_accessible_get_relation_set:
429 * @obj: a pointer to the #AtspiAccessible object on which to operate.
431 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
432 * relationships with other #AtspiAccessible objects.
434 * Returns: (element-type AtspiAccessible*) (transfer full): an array of
435 * #AtspiAccessibleRelation pointers. or NULL on exception
438 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
441 DBusMessageIter iter, iter_array;
444 g_return_val_if_fail (obj != NULL, NULL);
446 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
447 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", NULL);
449 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
450 dbus_message_iter_init (reply, &iter);
451 dbus_message_iter_recurse (&iter, &iter_array);
452 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
455 AtspiRelation *relation;
456 relation = _atspi_relation_new_from_iter (&iter_array);
457 new_array = g_array_append_val (ret, relation);
460 dbus_message_iter_next (&iter_array);
466 * atspi_accessible_get_role:
467 * @obj: a pointer to the #AtspiAccessible object on which to operate.
469 * Get the UI role of an #AtspiAccessible object.
470 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
472 * Returns: the #AtspiRole of the object.
476 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
478 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
480 if (!(obj->cached_properties & ATSPI_CACHE_ROLE))
483 /* TODO: Make this a property */
484 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
486 obj->cached_properties |= ATSPI_CACHE_ROLE;
494 * atspi_accessible_get_role_name:
495 * @obj: a pointer to the #AtspiAccessible object on which to operate.
497 * Get a UTF-8 string describing the role this object plays in the UI.
498 * This method will return useful values for roles that fall outside the
499 * enumeration used in atspi_accessible_getRole ().
501 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
505 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
509 g_return_val_if_fail (obj != NULL, NULL);
511 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
514 retval = g_strdup ("");
520 * atspi_accessible_get_localized_role_name:
521 * @obj: a pointer to the #AtspiAccessible object on which to operate.
523 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
524 * This method will return useful values for roles that fall outside the
525 * enumeration used in atspi_accessible_getRole ().
527 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
531 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
535 g_return_val_if_fail (obj != NULL, NULL);
537 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
540 return g_strdup ("");
546 * atspi_accessible_get_state_set:
547 * @obj: a pointer to the #AtspiAccessible object on which to operate.
549 * Gets the current state of an object.
551 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
552 * object's current state.
555 atspi_accessible_get_state_set (AtspiAccessible *obj)
557 if (!(obj->cached_properties & ATSPI_CACHE_STATES))
560 DBusMessageIter iter;
561 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
562 "GetState", NULL, "");
563 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL);
564 dbus_message_iter_init (reply, &iter);
565 _atspi_dbus_set_state (obj, &iter);
566 dbus_message_unref (reply);
569 return g_object_ref (obj->states);
573 * atspi_accessible_get_attributes:
574 * @obj: The #AtspiAccessible being queried.
576 * Get the #AttributeSet representing any assigned
577 * name-value pair attributes or annotations for this object.
578 * For typographic, textual, or textually-semantic attributes, see
579 * atspi_text_get_attributes instead.
581 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
582 * attributes assigned to this object.
585 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
587 DBusMessage *message;
589 g_return_val_if_fail (obj != NULL, NULL);
591 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
592 return _atspi_dbus_return_hash_from_message (message);
596 * atspi_accessible_get_attributes_as_array:
597 * @obj: The #AtspiAccessible being queried.
599 * Get the #AttributeSet representing any assigned
600 * name-value pair attributes or annotations for this object.
601 * For typographic, textual, or textually-semantic attributes, see
602 * atspi_text_get_attributes_as_array instead.
604 * Returns: (element-type gchar*) (transfer full): The name-value-pair
605 * attributes assigned to this object.
608 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
610 DBusMessage *message;
612 g_return_val_if_fail (obj != NULL, NULL);
614 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
615 return _atspi_dbus_return_attribute_array_from_message (message);
619 * atspi_accessible_get_application:
620 * @obj: The #AtspiAccessible being queried.
622 * Get the containing #AtspiApplication for an object.
624 * Returns: (transfer full): the containing AtspiApplication instance for
628 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
630 AtspiAccessible *parent;
634 parent = atspi_accessible_get_parent (obj, NULL);
635 if (!parent || parent == obj ||
636 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
637 return g_object_ref (obj);
642 /* Application-specific methods */
645 * atspi_accessible_get_toolkit_name:
646 * @obj: a pointer to the #AtspiAccessible object on which to operate.
648 * Get the toolkit for a #AtspiAccessible object.
649 * Only works on application root objects.
651 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
652 * or NULL on exception
655 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
659 g_return_val_if_fail (obj != NULL, NULL);
661 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName", error, "s", &ret))
663 return g_strdup (ret);
667 * atspi_accessible_get_toolkit_version:
668 * @obj: a pointer to the #AtspiAccessible object on which to operate.
670 * Get the toolkit version for a #AtspiAccessible object.
671 * Only works on application root objects.
673 * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
674 * or NULL on exception
677 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
681 g_return_val_if_fail (obj != NULL, NULL);
683 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitVersion", error, "s", &ret))
685 return g_strdup (ret);
687 /* Interface query methods */
690 * atspi_accessible_is_action:
691 * @obj: a pointer to the #AtspiAccessible instance to query.
693 * Query whether the specified #AtspiAccessible implements #AtspiAction.
695 * Returns: #TRUE if @obj implements the #AtspiAction interface,
699 atspi_accessible_is_action (AtspiAccessible *obj)
701 return _atspi_accessible_is_a (obj,
702 atspi_interface_action);
706 * atspi_accessible_is_application:
707 * @obj: a pointer to the #AtspiAccessible instance to query.
709 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
711 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
715 atspi_accessible_is_application (AtspiAccessible *obj)
717 return _atspi_accessible_is_a (obj,
718 atspi_interface_application);
722 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
724 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
725 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
729 atspi_accessible_is_collection (AtspiAccessible *obj)
732 g_warning ("Collections not implemented");
733 return _atspi_accessible_is_a (obj,
734 atspi_interface_collection);
741 * atspi_accessible_is_component:
742 * @obj: a pointer to the #AtspiAccessible instance to query.
744 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
746 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
750 atspi_accessible_is_component (AtspiAccessible *obj)
752 return _atspi_accessible_is_a (obj,
753 atspi_interface_component);
757 * atspi_accessible_is_document:
758 * @obj: a pointer to the #AtspiAccessible instance to query.
760 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
762 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
766 atspi_accessible_is_document (AtspiAccessible *obj)
768 return _atspi_accessible_is_a (obj,
769 atspi_interface_document);
773 * atspi_accessible_is_editable_text:
774 * @obj: a pointer to the #AtspiAccessible instance to query.
776 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
778 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
782 atspi_accessible_is_editable_text (AtspiAccessible *obj)
784 return _atspi_accessible_is_a (obj,
785 atspi_interface_editable_text);
789 * atspi_accessible_is_hypertext:
790 * @obj: a pointer to the #AtspiAccessible instance to query.
792 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
794 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
798 atspi_accessible_is_hypertext (AtspiAccessible *obj)
800 return _atspi_accessible_is_a (obj,
801 atspi_interface_hypertext);
805 * atspi_accessible_is_image:
806 * @obj: a pointer to the #AtspiAccessible instance to query.
808 * Query whether the specified #AtspiAccessible implements #AtspiImage.
810 * Returns: #TRUE if @obj implements the #AtspiImage interface,
814 atspi_accessible_is_image (AtspiAccessible *obj)
816 return _atspi_accessible_is_a (obj,
817 atspi_interface_image);
821 * atspi_accessible_is_selection:
822 * @obj: a pointer to the #AtspiAccessible instance to query.
824 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
826 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
830 atspi_accessible_is_selection (AtspiAccessible *obj)
832 return _atspi_accessible_is_a (obj,
833 atspi_interface_selection);
837 * atspi_accessible_is_table:
838 * @obj: a pointer to the #AtspiAccessible instance to query.
840 * Query whether the specified #AtspiAccessible implements #AtspiTable.
842 * Returns: #TRUE if @obj implements the #AtspiTable interface,
846 atspi_accessible_is_table (AtspiAccessible *obj)
848 return _atspi_accessible_is_a (obj,
849 atspi_interface_table);
853 * atspi_accessible_is_streamable_content:
854 * @obj: a pointer to the #AtspiAccessible instance to query.
856 * Query whether the specified #AtspiAccessible implements
857 * #AtspiStreamableContent.
859 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
863 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
866 return _atspi_accessible_is_a (obj,
867 atspi_interface_streamable_content);
869 g_warning ("Streamable content not implemented");
875 * atspi_accessible_is_text:
876 * @obj: a pointer to the #AtspiAccessible instance to query.
878 * Query whether the specified #AtspiAccessible implements #AtspiText.
880 * Returns: #TRUE if @obj implements the #AtspiText interface,
884 atspi_accessible_is_text (AtspiAccessible *obj)
886 return _atspi_accessible_is_a (obj,
887 atspi_interface_text);
891 * atspi_accessible_is_value:
892 * @obj: a pointer to the #AtspiAccessible instance to query.
894 * Query whether the specified #AtspiAccessible implements #AtspiValue.
896 * Returns: #TRUE if @obj implements the #AtspiValue interface,
900 atspi_accessible_is_value (AtspiAccessible *obj)
902 return _atspi_accessible_is_a (obj,
903 atspi_interface_value);
907 * atspi_accessible_get_action:
908 * @obj: a pointer to the #AtspiAccessible instance to query.
910 * Get the #AtspiAction interface for an #AtspiAccessible.
912 * Returns: (transfer full): a pointer to an #AtspiAction interface
913 * instance, or NULL if @obj does not implement #AtspiAction.
916 atspi_accessible_get_action (AtspiAccessible *accessible)
918 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
919 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
923 * atspi_accessible_get_collection:
924 * @obj: a pointer to the #AtspiAccessible instance to query.
926 * Get the #AtspiCollection interface for an #AtspiAccessible.
928 * Returns: (transfer full): a pointer to an #AtspiCollection interface
929 * instance, or NULL if @obj does not implement #AtspiCollection.
932 atspi_accessible_get_collection (AtspiAccessible *accessible)
934 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
935 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
939 * atspi_accessible_get_component:
940 * @obj: a pointer to the #AtspiAccessible instance to query.
942 * Get the #AtspiComponent interface for an #AtspiAccessible.
944 * Returns: (transfer full): a pointer to an #AtspiComponent interface
945 * instance, or NULL if @obj does not implement #AtspiComponent.
948 atspi_accessible_get_component (AtspiAccessible *obj)
950 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
951 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
955 * atspi_accessible_get_document:
956 * @obj: a pointer to the #AtspiAccessible instance to query.
958 * Get the #AtspiDocument interface for an #AtspiAccessible.
960 * Returns: (transfer full): a pointer to an #AtspiDocument interface
961 * instance, or NULL if @obj does not implement #AtspiDocument.
964 atspi_accessible_get_document (AtspiAccessible *accessible)
966 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
967 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
971 * atspi_accessible_get_editable_text:
972 * @obj: a pointer to the #AtspiAccessible instance to query.
974 * Get the #AtspiEditableText interface for an #AtspiAccessible.
976 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
977 * instance, or NULL if @obj does not implement #AtspiEditableText.
980 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
982 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
983 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
987 * atspi_accessible_get_hyperlink:
988 * @obj: a pointer to the #AtspiAccessible object on which to operate.
990 * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
993 * Returns: (transfer full): the #AtspiHyperlink object associated with
994 * the given #AtspiAccessible, or NULL if not supported.
997 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
999 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1000 atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1004 * atspi_accessible_get_hypertext:
1005 * @obj: a pointer to the #AtspiAccessible instance to query.
1007 * Get the #AtspiHypertext interface for an #AtspiAccessible.
1009 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1010 * instance, or NULL if @obj does not implement #AtspiHypertext.
1013 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1015 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1016 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1020 * atspi_accessible_get_image:
1021 * @obj: a pointer to the #AtspiAccessible instance to query.
1023 * Get the #AtspiImage interface for an #AtspiAccessible.
1025 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1026 * NULL if @obj does not implement #AtspiImage.
1029 atspi_accessible_get_image (AtspiAccessible *accessible)
1031 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1032 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1036 * atspi_accessible_get_selection:
1037 * @obj: a pointer to the #AtspiAccessible instance to query.
1039 * Get the #AtspiSelection interface for an #AtspiAccessible.
1041 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1042 * instance, or NULL if @obj does not implement #AtspiSelection.
1045 atspi_accessible_get_selection (AtspiAccessible *accessible)
1047 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1048 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1053 * atspi_accessible_get_streamable_content:
1054 * @obj: a pointer to the #AtspiAccessible instance to query.
1056 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1058 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1059 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1061 AtspiStreamableContent *
1062 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1064 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1070 * atspi_accessible_get_table:
1071 * @obj: a pointer to the #AtspiAccessible instance to query.
1073 * Get the #AtspiTable interface for an #AtspiAccessible.
1075 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1076 * NULL if @obj does not implement #AtspiTable.
1079 atspi_accessible_get_table (AtspiAccessible *obj)
1081 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1082 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1086 * atspi_accessible_get_text:
1087 * @obj: a pointer to the #AtspiAccessible instance to query.
1089 * Get the #AtspiTable interface for an #AtspiAccessible.
1091 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1092 * NULL if @obj does not implement #AtspiText.
1095 atspi_accessible_get_text (AtspiAccessible *obj)
1097 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1098 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1102 * atspi_accessible_get_value:
1103 * @obj: a pointer to the #AtspiAccessible instance to query.
1105 * Get the #AtspiTable interface for an #AtspiAccessible.
1107 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1108 * NULL if @obj does not implement #AtspiValue.
1111 atspi_accessible_get_value (AtspiAccessible *accessible)
1113 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1114 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1118 _atspi_accessible_is_a (AtspiAccessible *accessible,
1119 const char *interface_name)
1123 if (accessible == NULL)
1128 if (!(accessible->cached_properties & ATSPI_CACHE_INTERFACES))
1131 DBusMessageIter iter;
1132 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
1133 "GetInterfaces", NULL, "");
1134 _ATSPI_DBUS_CHECK_SIG (reply, "as", FALSE);
1135 dbus_message_iter_init (reply, &iter);
1136 _atspi_dbus_set_interfaces (accessible, &iter);
1137 dbus_message_unref (reply);
1140 n = _atspi_get_iface_num (interface_name);
1141 if (n == -1) return FALSE;
1142 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1146 append_const_val (GArray *array, const gchar *val)
1148 gchar *dup = g_strdup (val);
1151 g_array_append_val (array, dup);
1155 * atspi_accessible_get_interfaces:
1157 * #obj: The #AtspiAccessible to query.
1159 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1160 * describing the interfaces supported by the object. Interfaces are
1161 * denoted in short-hand (ie, "Component", "Text", etc.)
1164 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1166 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1171 g_return_val_if_fail (obj != NULL, NULL);
1173 if (atspi_accessible_is_action (obj))
1174 append_const_val (ret, "Action");
1175 if (atspi_accessible_is_collection (obj))
1176 append_const_val (ret, "Collection");
1177 if (atspi_accessible_is_component (obj))
1178 append_const_val (ret, "Component");
1179 if (atspi_accessible_is_document (obj))
1180 append_const_val (ret, "Document");
1181 if (atspi_accessible_is_editable_text (obj))
1182 append_const_val (ret, "EditableText");
1183 if (atspi_accessible_is_hypertext (obj))
1184 append_const_val (ret, "Hypertext");
1185 if (atspi_accessible_is_image (obj))
1186 append_const_val (ret, "Image");
1187 if (atspi_accessible_is_selection (obj))
1188 append_const_val (ret, "Selection");
1189 if (atspi_accessible_is_table (obj))
1190 append_const_val (ret, "Table");
1191 if (atspi_accessible_is_text (obj))
1192 append_const_val (ret, "Text");
1193 if (atspi_accessible_is_value (obj))
1194 append_const_val (ret, "Value");
1199 /* TODO: Move to a finalizer */
1201 cspi_object_destroyed (AtspiAccessible *accessible)
1206 /* TODO: Only fire if object not already marked defunct */
1207 memset (&e, 0, sizeof (e));
1208 e.type = "object:state-change:defunct";
1209 e.source = accessible;
1212 _atspi_send_event (&e);
1214 g_free (accessible->parent.path);
1216 if (accessible->states)
1217 g_object_unref (accessible->states);
1218 g_free (accessible->description);
1219 g_free (accessible->name);
1223 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1225 AtspiAccessible *accessible;
1227 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1228 g_return_val_if_fail (accessible != NULL, NULL);
1230 accessible->parent.app = g_object_ref (app);
1231 accessible->parent.path = g_strdup (path);