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_get_property (obj, atspi_interface_accessible,
273 "Description", error, "s",
275 return g_strdup ("");
276 obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
278 return g_strdup (obj->description);
281 const char *str_parent = "Parent";
284 * atspi_accessible_get_parent:
285 * @obj: a pointer to the #AtspiAccessible object to query.
287 * Get an #AtspiAccessible object's parent container.
289 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
290 * contains the given #AtspiAccessible instance, or NULL if the @obj
291 * has no parent container.
295 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
297 g_return_val_if_fail (obj != NULL, NULL);
299 if (!(obj->cached_properties & ATSPI_CACHE_PARENT))
301 DBusMessage *message, *reply;
302 DBusMessageIter iter, iter_variant;
303 message = dbus_message_new_method_call (obj->parent.app->bus_name,
305 DBUS_INTERFACE_PROPERTIES, "Get");
308 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
309 DBUS_TYPE_STRING, &str_parent,
311 reply = _atspi_dbus_send_with_reply_and_block (message);
313 (strcmp (dbus_message_get_signature (reply), "v") != 0))
315 dbus_message_iter_init (reply, &iter);
316 dbus_message_iter_recurse (&iter, &iter_variant);
317 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
318 dbus_message_unref (reply);
319 obj->cached_properties |= ATSPI_CACHE_PARENT;
321 if (!obj->accessible_parent)
323 return g_object_ref (obj->accessible_parent);
327 * atspi_accessible_get_child_count:
328 * @obj: a pointer to the #AtspiAccessible object on which to operate.
330 * Get the number of children contained by an #AtspiAccessible object.
332 * Returns: a #long indicating the number of #AtspiAccessible children
333 * contained by an #AtspiAccessible object. or -1 on exception
337 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
339 g_return_val_if_fail (obj != NULL, -1);
341 if (!(obj->cached_properties & ATSPI_CACHE_CHILDREN))
344 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
345 "ChildCount", error, "i", &ret))
350 return g_list_length (obj->children);
354 * atspi_accessible_get_child_at_index:
355 * @obj: a pointer to the #AtspiAccessible object on which to operate.
356 * @child_index: a #long indicating which child is specified.
358 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
360 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
361 * index @child_index. or NULL on exception
364 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
368 AtspiAccessible *child;
370 g_return_val_if_fail (obj != NULL, NULL);
372 if (!(obj->cached_properties & ATSPI_CACHE_CHILDREN))
375 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
376 "GetChildAtIndex", error, "i",
378 return _atspi_dbus_return_accessible_from_message (reply);
381 child = g_list_nth_data (obj->children, child_index);
384 return g_object_ref (child);
388 * atspi_accessible_get_index_in_parent
389 * @obj: a pointer to the #AtspiAccessible object on which to operate.
391 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
393 * Returns: a #glong indicating the index of the #AtspiAccessible object
394 * in its parent (i.e. containing) #AtspiAccessible instance,
395 * or -1 if @obj has no containing parent or on exception.
398 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
403 g_return_val_if_fail (obj != NULL, -1);
404 if (!obj->accessible_parent) return -1;
405 if (!(obj->accessible_parent->cached_properties & ATSPI_CACHE_CHILDREN))
407 dbus_uint32_t ret = -1;
408 _atspi_dbus_call (obj, atspi_interface_accessible,
409 "GetIndexInParent", NULL, "=>u", &ret);
413 l = obj->accessible_parent->children;
416 if (l->data == obj) return i;
427 } Accessibility_Relation;
430 * atspi_accessible_get_relation_set:
431 * @obj: a pointer to the #AtspiAccessible object on which to operate.
433 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
434 * relationships with other #AtspiAccessible objects.
436 * Returns: (element-type AtspiAccessible*) (transfer full): an array of
437 * #AtspiAccessibleRelation pointers. or NULL on exception
440 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
443 DBusMessageIter iter, iter_array;
446 g_return_val_if_fail (obj != NULL, NULL);
448 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
449 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", NULL);
451 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
452 dbus_message_iter_init (reply, &iter);
453 dbus_message_iter_recurse (&iter, &iter_array);
454 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
457 AtspiRelation *relation;
458 relation = _atspi_relation_new_from_iter (&iter_array);
459 new_array = g_array_append_val (ret, relation);
462 dbus_message_iter_next (&iter_array);
468 * atspi_accessible_get_role:
469 * @obj: a pointer to the #AtspiAccessible object on which to operate.
471 * Get the UI role of an #AtspiAccessible object.
472 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
474 * Returns: the #AtspiRole of the object.
478 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
480 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
482 if (!(obj->cached_properties & ATSPI_CACHE_ROLE))
485 /* TODO: Make this a property */
486 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
488 obj->cached_properties |= ATSPI_CACHE_ROLE;
496 * atspi_accessible_get_role_name:
497 * @obj: a pointer to the #AtspiAccessible object on which to operate.
499 * Get a UTF-8 string describing the role this object plays in the UI.
500 * This method will return useful values for roles that fall outside the
501 * enumeration used in atspi_accessible_getRole ().
503 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
507 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
511 g_return_val_if_fail (obj != NULL, NULL);
513 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
516 retval = g_strdup ("");
522 * atspi_accessible_get_localized_role_name:
523 * @obj: a pointer to the #AtspiAccessible object on which to operate.
525 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
526 * This method will return useful values for roles that fall outside the
527 * enumeration used in atspi_accessible_getRole ().
529 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
533 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
537 g_return_val_if_fail (obj != NULL, NULL);
539 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
542 return g_strdup ("");
548 * atspi_accessible_get_state_set:
549 * @obj: a pointer to the #AtspiAccessible object on which to operate.
551 * Gets the current state of an object.
553 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
554 * object's current state.
557 atspi_accessible_get_state_set (AtspiAccessible *obj)
559 if (!(obj->cached_properties & ATSPI_CACHE_STATES))
562 DBusMessageIter iter;
563 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
564 "GetState", NULL, "");
565 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL);
566 dbus_message_iter_init (reply, &iter);
567 _atspi_dbus_set_state (obj, &iter);
568 dbus_message_unref (reply);
571 return g_object_ref (obj->states);
575 * atspi_accessible_get_attributes:
576 * @obj: The #AtspiAccessible being queried.
578 * Get the #AttributeSet representing any assigned
579 * name-value pair attributes or annotations for this object.
580 * For typographic, textual, or textually-semantic attributes, see
581 * atspi_text_get_attributes instead.
583 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
584 * attributes assigned to this object.
587 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
589 DBusMessage *message;
591 g_return_val_if_fail (obj != NULL, NULL);
593 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
594 return _atspi_dbus_return_hash_from_message (message);
598 * atspi_accessible_get_attributes_as_array:
599 * @obj: The #AtspiAccessible being queried.
601 * Get the #AttributeSet representing any assigned
602 * name-value pair attributes or annotations for this object.
603 * For typographic, textual, or textually-semantic attributes, see
604 * atspi_text_get_attributes_as_array instead.
606 * Returns: (element-type gchar*) (transfer full): The name-value-pair
607 * attributes assigned to this object.
610 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
612 DBusMessage *message;
614 g_return_val_if_fail (obj != NULL, NULL);
616 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
617 return _atspi_dbus_return_attribute_array_from_message (message);
621 * atspi_accessible_get_application:
622 * @obj: The #AtspiAccessible being queried.
624 * Get the containing #AtspiApplication for an object.
626 * Returns: (transfer full): the containing AtspiApplication instance for
630 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
632 AtspiAccessible *parent;
636 parent = atspi_accessible_get_parent (obj, NULL);
637 if (!parent || parent == obj ||
638 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
639 return g_object_ref (obj);
644 /* Application-specific methods */
647 * atspi_accessible_get_toolkit_name:
648 * @obj: a pointer to the #AtspiAccessible object on which to operate.
650 * Get the toolkit for a #AtspiAccessible object.
651 * Only works on application root objects.
653 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
654 * or NULL on exception
657 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
661 g_return_val_if_fail (obj != NULL, NULL);
663 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName", error, "s", &ret))
665 return g_strdup (ret);
669 * atspi_accessible_get_toolkit_version:
670 * @obj: a pointer to the #AtspiAccessible object on which to operate.
672 * Get the toolkit version for a #AtspiAccessible object.
673 * Only works on application root objects.
675 * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
676 * or NULL on exception
679 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
683 g_return_val_if_fail (obj != NULL, NULL);
685 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitVersion", error, "s", &ret))
687 return g_strdup (ret);
689 /* Interface query methods */
692 * atspi_accessible_is_action:
693 * @obj: a pointer to the #AtspiAccessible instance to query.
695 * Query whether the specified #AtspiAccessible implements #AtspiAction.
697 * Returns: #TRUE if @obj implements the #AtspiAction interface,
701 atspi_accessible_is_action (AtspiAccessible *obj)
703 return _atspi_accessible_is_a (obj,
704 atspi_interface_action);
708 * atspi_accessible_is_application:
709 * @obj: a pointer to the #AtspiAccessible instance to query.
711 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
713 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
717 atspi_accessible_is_application (AtspiAccessible *obj)
719 return _atspi_accessible_is_a (obj,
720 atspi_interface_application);
724 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
726 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
727 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
731 atspi_accessible_is_collection (AtspiAccessible *obj)
734 g_warning ("Collections not implemented");
735 return _atspi_accessible_is_a (obj,
736 atspi_interface_collection);
743 * atspi_accessible_is_component:
744 * @obj: a pointer to the #AtspiAccessible instance to query.
746 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
748 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
752 atspi_accessible_is_component (AtspiAccessible *obj)
754 return _atspi_accessible_is_a (obj,
755 atspi_interface_component);
759 * atspi_accessible_is_document:
760 * @obj: a pointer to the #AtspiAccessible instance to query.
762 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
764 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
768 atspi_accessible_is_document (AtspiAccessible *obj)
770 return _atspi_accessible_is_a (obj,
771 atspi_interface_document);
775 * atspi_accessible_is_editable_text:
776 * @obj: a pointer to the #AtspiAccessible instance to query.
778 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
780 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
784 atspi_accessible_is_editable_text (AtspiAccessible *obj)
786 return _atspi_accessible_is_a (obj,
787 atspi_interface_editable_text);
791 * atspi_accessible_is_hypertext:
792 * @obj: a pointer to the #AtspiAccessible instance to query.
794 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
796 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
800 atspi_accessible_is_hypertext (AtspiAccessible *obj)
802 return _atspi_accessible_is_a (obj,
803 atspi_interface_hypertext);
807 * atspi_accessible_is_image:
808 * @obj: a pointer to the #AtspiAccessible instance to query.
810 * Query whether the specified #AtspiAccessible implements #AtspiImage.
812 * Returns: #TRUE if @obj implements the #AtspiImage interface,
816 atspi_accessible_is_image (AtspiAccessible *obj)
818 return _atspi_accessible_is_a (obj,
819 atspi_interface_image);
823 * atspi_accessible_is_selection:
824 * @obj: a pointer to the #AtspiAccessible instance to query.
826 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
828 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
832 atspi_accessible_is_selection (AtspiAccessible *obj)
834 return _atspi_accessible_is_a (obj,
835 atspi_interface_selection);
839 * atspi_accessible_is_table:
840 * @obj: a pointer to the #AtspiAccessible instance to query.
842 * Query whether the specified #AtspiAccessible implements #AtspiTable.
844 * Returns: #TRUE if @obj implements the #AtspiTable interface,
848 atspi_accessible_is_table (AtspiAccessible *obj)
850 return _atspi_accessible_is_a (obj,
851 atspi_interface_table);
855 * atspi_accessible_is_streamable_content:
856 * @obj: a pointer to the #AtspiAccessible instance to query.
858 * Query whether the specified #AtspiAccessible implements
859 * #AtspiStreamableContent.
861 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
865 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
868 return _atspi_accessible_is_a (obj,
869 atspi_interface_streamable_content);
871 g_warning ("Streamable content not implemented");
877 * atspi_accessible_is_text:
878 * @obj: a pointer to the #AtspiAccessible instance to query.
880 * Query whether the specified #AtspiAccessible implements #AtspiText.
882 * Returns: #TRUE if @obj implements the #AtspiText interface,
886 atspi_accessible_is_text (AtspiAccessible *obj)
888 return _atspi_accessible_is_a (obj,
889 atspi_interface_text);
893 * atspi_accessible_is_value:
894 * @obj: a pointer to the #AtspiAccessible instance to query.
896 * Query whether the specified #AtspiAccessible implements #AtspiValue.
898 * Returns: #TRUE if @obj implements the #AtspiValue interface,
902 atspi_accessible_is_value (AtspiAccessible *obj)
904 return _atspi_accessible_is_a (obj,
905 atspi_interface_value);
909 * atspi_accessible_get_action:
910 * @obj: a pointer to the #AtspiAccessible instance to query.
912 * Get the #AtspiAction interface for an #AtspiAccessible.
914 * Returns: (transfer full): a pointer to an #AtspiAction interface
915 * instance, or NULL if @obj does not implement #AtspiAction.
918 atspi_accessible_get_action (AtspiAccessible *accessible)
920 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
921 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
925 * atspi_accessible_get_collection:
926 * @obj: a pointer to the #AtspiAccessible instance to query.
928 * Get the #AtspiCollection interface for an #AtspiAccessible.
930 * Returns: (transfer full): a pointer to an #AtspiCollection interface
931 * instance, or NULL if @obj does not implement #AtspiCollection.
934 atspi_accessible_get_collection (AtspiAccessible *accessible)
936 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
937 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
941 * atspi_accessible_get_component:
942 * @obj: a pointer to the #AtspiAccessible instance to query.
944 * Get the #AtspiComponent interface for an #AtspiAccessible.
946 * Returns: (transfer full): a pointer to an #AtspiComponent interface
947 * instance, or NULL if @obj does not implement #AtspiComponent.
950 atspi_accessible_get_component (AtspiAccessible *obj)
952 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
953 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
957 * atspi_accessible_get_document:
958 * @obj: a pointer to the #AtspiAccessible instance to query.
960 * Get the #AtspiDocument interface for an #AtspiAccessible.
962 * Returns: (transfer full): a pointer to an #AtspiDocument interface
963 * instance, or NULL if @obj does not implement #AtspiDocument.
966 atspi_accessible_get_document (AtspiAccessible *accessible)
968 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
969 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
973 * atspi_accessible_get_editable_text:
974 * @obj: a pointer to the #AtspiAccessible instance to query.
976 * Get the #AtspiEditableText interface for an #AtspiAccessible.
978 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
979 * instance, or NULL if @obj does not implement #AtspiEditableText.
982 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
984 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
985 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
989 * atspi_accessible_get_hyperlink:
990 * @obj: a pointer to the #AtspiAccessible object on which to operate.
992 * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
995 * Returns: (transfer full): the #AtspiHyperlink object associated with
996 * the given #AtspiAccessible, or NULL if not supported.
999 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1001 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1002 atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1006 * atspi_accessible_get_hypertext:
1007 * @obj: a pointer to the #AtspiAccessible instance to query.
1009 * Get the #AtspiHypertext interface for an #AtspiAccessible.
1011 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1012 * instance, or NULL if @obj does not implement #AtspiHypertext.
1015 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1017 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1018 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1022 * atspi_accessible_get_image:
1023 * @obj: a pointer to the #AtspiAccessible instance to query.
1025 * Get the #AtspiImage interface for an #AtspiAccessible.
1027 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1028 * NULL if @obj does not implement #AtspiImage.
1031 atspi_accessible_get_image (AtspiAccessible *accessible)
1033 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1034 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1038 * atspi_accessible_get_selection:
1039 * @obj: a pointer to the #AtspiAccessible instance to query.
1041 * Get the #AtspiSelection interface for an #AtspiAccessible.
1043 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1044 * instance, or NULL if @obj does not implement #AtspiSelection.
1047 atspi_accessible_get_selection (AtspiAccessible *accessible)
1049 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1050 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1055 * atspi_accessible_get_streamable_content:
1056 * @obj: a pointer to the #AtspiAccessible instance to query.
1058 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1060 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1061 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1063 AtspiStreamableContent *
1064 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1066 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1072 * atspi_accessible_get_table:
1073 * @obj: a pointer to the #AtspiAccessible instance to query.
1075 * Get the #AtspiTable interface for an #AtspiAccessible.
1077 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1078 * NULL if @obj does not implement #AtspiTable.
1081 atspi_accessible_get_table (AtspiAccessible *obj)
1083 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1084 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1088 * atspi_accessible_get_text:
1089 * @obj: a pointer to the #AtspiAccessible instance to query.
1091 * Get the #AtspiTable interface for an #AtspiAccessible.
1093 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1094 * NULL if @obj does not implement #AtspiText.
1097 atspi_accessible_get_text (AtspiAccessible *obj)
1099 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1100 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1104 * atspi_accessible_get_value:
1105 * @obj: a pointer to the #AtspiAccessible instance to query.
1107 * Get the #AtspiTable interface for an #AtspiAccessible.
1109 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1110 * NULL if @obj does not implement #AtspiValue.
1113 atspi_accessible_get_value (AtspiAccessible *accessible)
1115 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1116 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1120 _atspi_accessible_is_a (AtspiAccessible *accessible,
1121 const char *interface_name)
1125 if (accessible == NULL)
1130 if (!(accessible->cached_properties & ATSPI_CACHE_INTERFACES))
1133 DBusMessageIter iter;
1134 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
1135 "GetInterfaces", NULL, "");
1136 _ATSPI_DBUS_CHECK_SIG (reply, "as", FALSE);
1137 dbus_message_iter_init (reply, &iter);
1138 _atspi_dbus_set_interfaces (accessible, &iter);
1139 dbus_message_unref (reply);
1142 n = _atspi_get_iface_num (interface_name);
1143 if (n == -1) return FALSE;
1144 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1148 append_const_val (GArray *array, const gchar *val)
1150 gchar *dup = g_strdup (val);
1153 g_array_append_val (array, dup);
1157 * atspi_accessible_get_interfaces:
1159 * #obj: The #AtspiAccessible to query.
1161 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1162 * describing the interfaces supported by the object. Interfaces are
1163 * denoted in short-hand (ie, "Component", "Text", etc.)
1166 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1168 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1173 g_return_val_if_fail (obj != NULL, NULL);
1175 if (atspi_accessible_is_action (obj))
1176 append_const_val (ret, "Action");
1177 if (atspi_accessible_is_collection (obj))
1178 append_const_val (ret, "Collection");
1179 if (atspi_accessible_is_component (obj))
1180 append_const_val (ret, "Component");
1181 if (atspi_accessible_is_document (obj))
1182 append_const_val (ret, "Document");
1183 if (atspi_accessible_is_editable_text (obj))
1184 append_const_val (ret, "EditableText");
1185 if (atspi_accessible_is_hypertext (obj))
1186 append_const_val (ret, "Hypertext");
1187 if (atspi_accessible_is_image (obj))
1188 append_const_val (ret, "Image");
1189 if (atspi_accessible_is_selection (obj))
1190 append_const_val (ret, "Selection");
1191 if (atspi_accessible_is_table (obj))
1192 append_const_val (ret, "Table");
1193 if (atspi_accessible_is_text (obj))
1194 append_const_val (ret, "Text");
1195 if (atspi_accessible_is_value (obj))
1196 append_const_val (ret, "Value");
1201 /* TODO: Move to a finalizer */
1203 cspi_object_destroyed (AtspiAccessible *accessible)
1208 /* TODO: Only fire if object not already marked defunct */
1209 memset (&e, 0, sizeof (e));
1210 e.type = "object:state-change:defunct";
1211 e.source = accessible;
1214 _atspi_send_event (&e);
1216 g_free (accessible->parent.path);
1218 if (accessible->states)
1219 g_object_unref (accessible->states);
1220 g_free (accessible->description);
1221 g_free (accessible->name);
1225 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1227 AtspiAccessible *accessible;
1229 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1230 g_return_val_if_fail (accessible != NULL, NULL);
1232 accessible->parent.app = g_object_ref (app);
1233 accessible->parent.path = g_strdup (path);