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;
590 g_return_val_if_fail (obj != NULL, NULL);
592 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
593 ret = _atspi_dbus_hash_from_message (message);
594 dbus_message_unref (message);
599 * atspi_accessible_get_attributes_as_array:
600 * @obj: The #AtspiAccessible being queried.
602 * Get the #AttributeSet representing any assigned
603 * name-value pair attributes or annotations for this object.
604 * For typographic, textual, or textually-semantic attributes, see
605 * atspi_text_get_attributes_as_array instead.
607 * Returns: (element-type gchar*) (transfer full): The name-value-pair
608 * attributes assigned to this object.
611 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
613 DBusMessage *message;
616 g_return_val_if_fail (obj != NULL, NULL);
618 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
619 ret = _atspi_dbus_attribute_array_from_message (message);
621 dbus_message_unref (message);
626 * atspi_accessible_get_application:
627 * @obj: The #AtspiAccessible being queried.
629 * Get the containing #AtspiApplication for an object.
631 * Returns: (transfer full): the containing AtspiApplication instance for
635 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
637 AtspiAccessible *parent;
641 parent = atspi_accessible_get_parent (obj, NULL);
642 if (!parent || parent == obj ||
643 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
644 return g_object_ref (obj);
649 /* Applicatio-specific methods */
652 * atspi_accessible_get_toolkit_name:
653 * @obj: a pointer to the #AtspiAccessible object on which to operate.
655 * Get the toolkit for a #AtspiAccessible object.
656 * Only works on application root objects.
658 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
659 * or NULL on exception
662 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
666 g_return_val_if_fail (obj != NULL, NULL);
668 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName", error, "s", &ret))
670 return g_strdup (ret);
674 * atspi_accessible_get_toolkit_version:
675 * @obj: a pointer to the #AtspiAccessible object on which to operate.
677 * Get the toolkit version for a #AtspiAccessible object.
678 * Only works on application root objects.
680 * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
681 * or NULL on exception
684 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
688 g_return_val_if_fail (obj != NULL, NULL);
690 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitVersion", error, "s", &ret))
692 return g_strdup (ret);
694 /* Interface query methods */
697 * atspi_accessible_is_action:
698 * @obj: a pointer to the #AtspiAccessible instance to query.
700 * Query whether the specified #AtspiAccessible implements #AtspiAction.
702 * Returns: #TRUE if @obj implements the #AtspiAction interface,
706 atspi_accessible_is_action (AtspiAccessible *obj)
708 return _atspi_accessible_is_a (obj,
709 atspi_interface_action);
713 * atspi_accessible_is_application:
714 * @obj: a pointer to the #AtspiAccessible instance to query.
716 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
718 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
722 atspi_accessible_is_application (AtspiAccessible *obj)
724 return _atspi_accessible_is_a (obj,
725 atspi_interface_application);
729 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
731 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
732 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
736 atspi_accessible_is_collection (AtspiAccessible *obj)
739 g_warning ("Collections not implemented");
740 return _atspi_accessible_is_a (obj,
741 atspi_interface_collection);
748 * atspi_accessible_is_component:
749 * @obj: a pointer to the #AtspiAccessible instance to query.
751 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
753 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
757 atspi_accessible_is_component (AtspiAccessible *obj)
759 return _atspi_accessible_is_a (obj,
760 atspi_interface_component);
764 * atspi_accessible_is_document:
765 * @obj: a pointer to the #AtspiAccessible instance to query.
767 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
769 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
773 atspi_accessible_is_document (AtspiAccessible *obj)
775 return _atspi_accessible_is_a (obj,
776 atspi_interface_document);
780 * atspi_accessible_is_editable_text:
781 * @obj: a pointer to the #AtspiAccessible instance to query.
783 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
785 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
789 atspi_accessible_is_editable_text (AtspiAccessible *obj)
791 return _atspi_accessible_is_a (obj,
792 atspi_interface_editable_text);
796 * atspi_accessible_is_hypertext:
797 * @obj: a pointer to the #AtspiAccessible instance to query.
799 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
801 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
805 atspi_accessible_is_hypertext (AtspiAccessible *obj)
807 return _atspi_accessible_is_a (obj,
808 atspi_interface_hypertext);
812 * atspi_accessible_is_image:
813 * @obj: a pointer to the #AtspiAccessible instance to query.
815 * Query whether the specified #AtspiAccessible implements #AtspiImage.
817 * Returns: #TRUE if @obj implements the #AtspiImage interface,
821 atspi_accessible_is_image (AtspiAccessible *obj)
823 return _atspi_accessible_is_a (obj,
824 atspi_interface_image);
828 * atspi_accessible_is_selection:
829 * @obj: a pointer to the #AtspiAccessible instance to query.
831 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
833 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
837 atspi_accessible_is_selection (AtspiAccessible *obj)
839 return _atspi_accessible_is_a (obj,
840 atspi_interface_selection);
844 * atspi_accessible_is_table:
845 * @obj: a pointer to the #AtspiAccessible instance to query.
847 * Query whether the specified #AtspiAccessible implements #AtspiTable.
849 * Returns: #TRUE if @obj implements the #AtspiTable interface,
853 atspi_accessible_is_table (AtspiAccessible *obj)
855 return _atspi_accessible_is_a (obj,
856 atspi_interface_table);
860 * atspi_accessible_is_streamable_content:
861 * @obj: a pointer to the #AtspiAccessible instance to query.
863 * Query whether the specified #AtspiAccessible implements
864 * #AtspiStreamableContent.
866 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
870 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
873 return _atspi_accessible_is_a (obj,
874 atspi_interface_streamable_content);
876 g_warning ("Streamable content not implemented");
882 * atspi_accessible_is_text:
883 * @obj: a pointer to the #AtspiAccessible instance to query.
885 * Query whether the specified #AtspiAccessible implements #AtspiText.
887 * Returns: #TRUE if @obj implements the #AtspiText interface,
891 atspi_accessible_is_text (AtspiAccessible *obj)
893 return _atspi_accessible_is_a (obj,
894 atspi_interface_text);
898 * atspi_accessible_is_value:
899 * @obj: a pointer to the #AtspiAccessible instance to query.
901 * Query whether the specified #AtspiAccessible implements #AtspiValue.
903 * Returns: #TRUE if @obj implements the #AtspiValue interface,
907 atspi_accessible_is_value (AtspiAccessible *obj)
909 return _atspi_accessible_is_a (obj,
910 atspi_interface_value);
914 * atspi_accessible_get_action:
915 * @obj: a pointer to the #AtspiAccessible instance to query.
917 * Get the #AtspiAction interface for an #AtspiAccessible.
919 * Returns: (transfer full): a pointer to an #AtspiAction interface
920 * instance, or NULL if @obj does not implement #AtspiAction.
923 atspi_accessible_get_action (AtspiAccessible *accessible)
925 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
926 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
930 * atspi_accessible_get_collection:
931 * @obj: a pointer to the #AtspiAccessible instance to query.
933 * Get the #AtspiCollection interface for an #AtspiAccessible.
935 * Returns: (transfer full): a pointer to an #AtspiCollection interface
936 * instance, or NULL if @obj does not implement #AtspiCollection.
939 atspi_accessible_get_collection (AtspiAccessible *accessible)
941 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
942 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
946 * atspi_accessible_get_component:
947 * @obj: a pointer to the #AtspiAccessible instance to query.
949 * Get the #AtspiComponent interface for an #AtspiAccessible.
951 * Returns: (transfer full): a pointer to an #AtspiComponent interface
952 * instance, or NULL if @obj does not implement #AtspiComponent.
955 atspi_accessible_get_component (AtspiAccessible *obj)
957 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
958 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
962 * atspi_accessible_get_document:
963 * @obj: a pointer to the #AtspiAccessible instance to query.
965 * Get the #AtspiDocument interface for an #AtspiAccessible.
967 * Returns: (transfer full): a pointer to an #AtspiDocument interface
968 * instance, or NULL if @obj does not implement #AtspiDocument.
971 atspi_accessible_get_document (AtspiAccessible *accessible)
973 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
974 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
978 * atspi_accessible_get_editable_text:
979 * @obj: a pointer to the #AtspiAccessible instance to query.
981 * Get the #AtspiEditableText interface for an #AtspiAccessible.
983 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
984 * instance, or NULL if @obj does not implement #AtspiEditableText.
987 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
989 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
990 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
994 * atspi_accessible_get_hyperlink:
995 * @accessible: a pointer to the #AtspiAccessible object on which to operate.
997 * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
1000 * Returns: (transfer full): the #AtspiHyperlink object associated with
1001 * the given #AtspiAccessible, or NULL if not supported.
1004 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1006 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1007 atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1011 * atspi_accessible_get_hypertext:
1012 * @obj: a pointer to the #AtspiAccessible instance to query.
1014 * Get the #AtspiHypertext interface for an #AtspiAccessible.
1016 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1017 * instance, or NULL if @obj does not implement #AtspiHypertext.
1020 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1022 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1023 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
1027 * atspi_accessible_get_image:
1028 * @obj: a pointer to the #AtspiAccessible instance to query.
1030 * Get the #AtspiImage interface for an #AtspiAccessible.
1032 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1033 * NULL if @obj does not implement #AtspiImage.
1036 atspi_accessible_get_image (AtspiAccessible *accessible)
1038 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1039 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1043 * atspi_accessible_get_selection:
1044 * @obj: a pointer to the #AtspiAccessible instance to query.
1046 * Get the #AtspiSelection interface for an #AtspiAccessible.
1048 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1049 * instance, or NULL if @obj does not implement #AtspiSelection.
1052 atspi_accessible_get_selection (AtspiAccessible *accessible)
1054 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1055 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1060 * atspi_accessible_get_streamable_content:
1061 * @obj: a pointer to the #AtspiAccessible instance to query.
1063 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1065 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1066 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1068 AtspiStreamableContent *
1069 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1071 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1077 * atspi_accessible_get_table:
1078 * @obj: a pointer to the #AtspiAccessible instance to query.
1080 * Get the #AtspiTable interface for an #AtspiAccessible.
1082 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1083 * NULL if @obj does not implement #AtspiTable.
1086 atspi_accessible_get_table (AtspiAccessible *obj)
1088 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1089 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1093 * atspi_accessible_get_text:
1094 * @obj: a pointer to the #AtspiAccessible instance to query.
1096 * Get the #AtspiTable interface for an #AtspiAccessible.
1098 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1099 * NULL if @obj does not implement #AtspiTable.
1102 atspi_accessible_get_text (AtspiAccessible *obj)
1104 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1105 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1109 * atspi_accessible_get_value:
1110 * @obj: a pointer to the #AtspiAccessible instance to query.
1112 * Get the #AtspiTable interface for an #AtspiAccessible.
1114 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1115 * NULL if @obj does not implement #AtspiValue.
1118 atspi_accessible_get_value (AtspiAccessible *accessible)
1120 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1121 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1126 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
1129 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
1131 relation_type_table [i] = SPI_RELATION_NULL;
1133 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
1134 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
1135 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
1136 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
1137 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
1138 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
1139 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
1140 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
1141 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
1142 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
1143 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
1144 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
1145 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
1146 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
1147 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
1148 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
1149 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
1150 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
1154 static AccessibleRelationType
1155 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
1157 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
1158 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
1159 static gboolean is_initialized = FALSE;
1160 AccessibleRelationType cspi_type;
1161 if (!is_initialized)
1163 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
1165 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
1167 cspi_type = cspi_relation_type_table [type];
1171 cspi_type = SPI_RELATION_NULL;
1176 * AccessibleRelation_getRelationType:
1177 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1179 * Get the type of relationship represented by an #AtspiAccessibleRelation.
1181 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
1182 * encapsulated in this #AtspiAccessibleRelation object.
1185 AccessibleRelationType
1186 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1188 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1189 return cspi_relation_type_from_spi_relation_type (obj->type);
1193 * AccessibleRelation_getNTargets:
1194 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1196 * Get the number of objects which this relationship has as its
1197 * target objects (the subject is the #AtspiAccessible from which this
1198 * #AtspiAccessibleRelation originated).
1200 * Returns: a short integer indicating how many target objects which the
1201 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
1202 * relationship with.
1205 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1207 cspi_return_val_if_fail (obj, -1);
1208 return obj->targets->len;
1212 * AccessibleRelation_getTarget:
1213 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1214 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1216 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
1218 * Returns: an #AtspiAccessible which is the @i-th object with which the
1219 * originating #AtspiAccessible has relationship specified in the
1220 * #AtspiAccessibleRelation object.
1224 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1226 cspi_return_val_if_fail (obj, NULL);
1228 if (i < 0 || i >= obj->targets->len) return NULL;
1229 return cspi_object_add (
1230 g_array_index (obj->targets, Accessible *, i));
1234 * AccessibleStateSet_ref:
1235 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1237 * Increment the reference count for an #AtspiAccessibleStateSet object.
1241 AccessibleStateSet_ref (AccessibleStateSet *obj)
1243 spi_state_set_cache_ref (obj);
1247 * AccessibleStateSet_unref:
1248 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1250 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1254 AccessibleStateSet_unref (AccessibleStateSet *obj)
1256 spi_state_set_cache_unref (obj);
1259 static Accessibility_StateType
1260 spi_state_to_dbus (AccessibleState state)
1262 #define MAP_STATE(a) \
1263 case SPI_STATE_##a: \
1264 return Accessibility_STATE_##a
1268 MAP_STATE (INVALID);
1272 MAP_STATE (CHECKED);
1273 MAP_STATE (DEFUNCT);
1274 MAP_STATE (EDITABLE);
1275 MAP_STATE (ENABLED);
1276 MAP_STATE (EXPANDABLE);
1277 MAP_STATE (EXPANDED);
1278 MAP_STATE (FOCUSABLE);
1279 MAP_STATE (FOCUSED);
1280 MAP_STATE (HORIZONTAL);
1281 MAP_STATE (ICONIFIED);
1283 MAP_STATE (MULTI_LINE);
1284 MAP_STATE (MULTISELECTABLE);
1286 MAP_STATE (PRESSED);
1287 MAP_STATE (RESIZABLE);
1288 MAP_STATE (SELECTABLE);
1289 MAP_STATE (SELECTED);
1290 MAP_STATE (SENSITIVE);
1291 MAP_STATE (SHOWING);
1292 MAP_STATE (SINGLE_LINE);
1294 MAP_STATE (TRANSIENT);
1295 MAP_STATE (VERTICAL);
1296 MAP_STATE (VISIBLE);
1297 MAP_STATE (MANAGES_DESCENDANTS);
1298 MAP_STATE (INDETERMINATE);
1299 MAP_STATE (TRUNCATED);
1300 MAP_STATE (REQUIRED);
1301 MAP_STATE (INVALID_ENTRY);
1302 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1303 MAP_STATE (SELECTABLE_TEXT);
1304 MAP_STATE (IS_DEFAULT);
1305 MAP_STATE (VISITED);
1307 return Accessibility_STATE_INVALID;
1313 * AccessibleStateSet_contains:
1314 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1315 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1318 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1319 * whether @state is true for the stateset in question.
1321 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1326 AccessibleStateSet_contains (AccessibleStateSet *obj,
1327 AccessibleState state)
1329 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1333 * AccessibleStateSet_add:
1334 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1335 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1337 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1338 * given state to #TRUE in the stateset.
1342 AccessibleStateSet_add (AccessibleStateSet *obj,
1343 AccessibleState state)
1345 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1349 * AccessibleStateSet_remove:
1350 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1351 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1353 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1354 * given state to #FALSE in the stateset.)
1358 AccessibleStateSet_remove (AccessibleStateSet *obj,
1359 AccessibleState state)
1361 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1365 * AccessibleStateSet_equals:
1366 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1367 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1369 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1370 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1371 * state variables at once; construct the target state then compare against it.
1373 * @see AccessibleStateSet_compare().
1375 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1380 AccessibleStateSet_equals (AccessibleStateSet *obj,
1381 AccessibleStateSet *obj2)
1391 cmp = spi_state_set_cache_xor (obj, obj2);
1392 eq = spi_state_set_cache_is_empty (cmp);
1393 spi_state_set_cache_unref (cmp);
1399 * AccessibleStateSet_compare:
1400 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1401 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1403 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1404 * Not Yet Implemented.
1406 * @see AccessibleStateSet_equals().
1408 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1409 * the two sets but not the other.
1412 AccessibleStateSet *
1413 AccessibleStateSet_compare (AccessibleStateSet *obj,
1414 AccessibleStateSet *obj2)
1416 return spi_state_set_cache_xor (obj, obj2);
1420 * AccessibleStateSet_isEmpty:
1421 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1423 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1425 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1430 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1432 return spi_state_set_cache_is_empty (obj);
1437 _atspi_accessible_is_a (AtspiAccessible *accessible,
1438 const char *interface_name)
1442 if (accessible == NULL)
1447 if (!(accessible->cached_properties & ATSPI_CACHE_INTERFACES))
1450 DBusMessageIter iter;
1451 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
1452 "GetInterfaces", NULL, "");
1453 _ATSPI_DBUS_CHECK_SIG (reply, "as", FALSE);
1454 dbus_message_iter_init (reply, &iter);
1455 _atspi_dbus_set_interfaces (accessible, &iter);
1456 dbus_message_unref (reply);
1459 n = _atspi_get_iface_num (interface_name);
1460 if (n == -1) return FALSE;
1461 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1465 append_const_val (GArray *array, const gchar *val)
1467 gchar *dup = g_strdup (val);
1470 g_array_append_val (array, dup);
1474 * atspi_accessible_get_interfaces:
1476 * #obj: The #AtspiAccessible to query.
1478 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1479 * describing the interfaces supported by the object. Interfaces are
1480 * denoted in short-hand (ie, "Component", "Text", etc.)
1483 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1485 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1490 g_return_val_if_fail (obj != NULL, NULL);
1492 if (atspi_accessible_is_action (obj))
1493 append_const_val (ret, "Action");
1494 if (atspi_accessible_is_collection (obj))
1495 append_const_val (ret, "Collection");
1496 if (atspi_accessible_is_component (obj))
1497 append_const_val (ret, "Component");
1498 if (atspi_accessible_is_document (obj))
1499 append_const_val (ret, "Document");
1500 if (atspi_accessible_is_editable_text (obj))
1501 append_const_val (ret, "EditableText");
1502 if (atspi_accessible_is_hypertext (obj))
1503 append_const_val (ret, "Hypertext");
1504 if (atspi_accessible_is_image (obj))
1505 append_const_val (ret, "Image");
1506 if (atspi_accessible_is_selection (obj))
1507 append_const_val (ret, "Selection");
1508 if (atspi_accessible_is_table (obj))
1509 append_const_val (ret, "Table");
1510 if (atspi_accessible_is_text (obj))
1511 append_const_val (ret, "Text");
1512 if (atspi_accessible_is_value (obj))
1513 append_const_val (ret, "Value");
1518 /* TODO: Move to a finalizer */
1520 cspi_object_destroyed (AtspiAccessible *accessible)
1525 /* TODO: Only fire if object not already marked defunct */
1526 memset (&e, 0, sizeof (e));
1527 e.type = "object:state-change:defunct";
1528 e.source = accessible;
1531 _atspi_send_event (&e);
1533 g_free (accessible->parent.path);
1535 if (accessible->states)
1536 g_object_unref (accessible->states);
1537 g_free (accessible->description);
1538 g_free (accessible->name);
1542 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1544 AtspiAccessible *accessible;
1546 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1547 g_return_val_if_fail (accessible != NULL, NULL);
1549 accessible->parent.app = g_object_ref (app);
1550 accessible->parent.path = g_strdup (path);