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)
42 atspi_editable_text_interface_init (AtspiEditableText *editable_text)
47 atspi_hypertext_interface_init (AtspiHypertext *hypertext)
52 atspi_image_interface_init (AtspiImage *image)
57 atspi_selection_interface_init (AtspiSelection *selection)
62 atspi_table_interface_init (AtspiTable *table)
67 atspi_text_interface_init (AtspiText *text)
72 atspi_value_interface_init (AtspiValue *value)
76 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT,
77 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init)
78 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COLLECTION, atspi_collection_interface_init)
79 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
80 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init)
81 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_HYPERTEXT, atspi_hypertext_interface_init)
82 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init)
83 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init)
84 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
85 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init)
86 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_VALUE, atspi_value_interface_init))
89 atspi_accessible_init (AtspiAccessible *accessible)
94 atspi_accessible_finalize (GObject *obj)
96 /*AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj); */
98 /* TODO: Unref parent/children, etc. */
102 atspi_accessible_class_init (AtspiAccessibleClass *klass)
104 GObjectClass *object_class = G_OBJECT_CLASS (klass);
106 object_class->finalize = atspi_accessible_finalize;
109 /* TODO: Generate following from spec? */
110 static const char *role_names [] =
168 "table-column-header",
170 "tear-off-menu-item",
200 "input method window"
203 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
206 * atspi_role_get_name
207 * @role: an #AtspiAccessibleRole object to query.
209 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
210 * <em>DEPRECATED.</em>
212 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
215 atspi_role_get_name (AtspiRole role)
217 if (role < MAX_ROLES && role_names [(int) role])
219 return g_strdup (role_names [(int) role]);
223 return g_strdup ("");
228 * atspi_accessible_get_name:
229 * @obj: a pointer to the #AtspiAccessible object on which to operate.
231 * Get the name of an #AtspiAccessible object.
233 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
234 * or NULL on exception
237 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
239 g_return_val_if_fail (obj != NULL, NULL);
240 if (!(obj->cached_properties & ATSPI_CACHE_NAME))
242 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
245 obj->cached_properties |= ATSPI_CACHE_NAME;
247 return g_strdup (obj->name);
251 * atspi_accessible_get_description:
252 * @obj: a pointer to the #AtspiAccessible object on which to operate.
254 * Get the description of an #AtspiAccessible object.
256 * Returns: a UTF-8 string describing the #AtspiAccessible object.
257 * or NULL on exception
260 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
262 g_return_val_if_fail (obj != NULL, NULL);
264 if (!(obj->cached_properties & ATSPI_CACHE_DESCRIPTION))
266 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetDescription", NULL, "=>s", &obj->description))
268 obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
270 return g_strdup (obj->description);
273 const char *str_parent = "Parent";
276 * atspi_accessible_get_parent:
277 * @obj: a pointer to the #AtspiAccessible object to query.
279 * Get an #AtspiAccessible object's parent container.
281 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
282 * contains the given #AtspiAccessible instance, or NULL if the @obj
283 * has no parent container.
287 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
289 g_return_val_if_fail (obj != NULL, NULL);
291 if (!(obj->cached_properties & ATSPI_CACHE_PARENT))
293 DBusMessage *message, *reply;
294 DBusMessageIter iter, iter_variant;
295 message = dbus_message_new_method_call (obj->parent.app->bus_name,
297 DBUS_INTERFACE_PROPERTIES, "Get");
300 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
301 DBUS_TYPE_STRING, &str_parent,
303 reply = _atspi_dbus_send_with_reply_and_block (message);
305 (strcmp (dbus_message_get_signature (reply), "v") != 0))
307 dbus_message_iter_init (reply, &iter);
308 dbus_message_iter_recurse (&iter, &iter_variant);
309 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
310 dbus_message_unref (reply);
311 obj->cached_properties |= ATSPI_CACHE_PARENT;
313 if (!obj->accessible_parent)
315 return g_object_ref (obj->accessible_parent);
319 * atspi_accessible_get_child_count:
320 * @obj: a pointer to the #AtspiAccessible object on which to operate.
322 * Get the number of children contained by an #AtspiAccessible object.
324 * Returns: a #long indicating the number of #AtspiAccessible children
325 * contained by an #AtspiAccessible object. or -1 on exception
329 atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error)
331 g_return_val_if_fail (obj != NULL, -1);
333 /* TODO: MANAGES_DESCENDANTS */
334 return g_list_length (obj->children);
338 * atspi_accessible_get_child_at_index:
339 * @obj: a pointer to the #AtspiAccessible object on which to operate.
340 * @child_index: a #long indicating which child is specified.
342 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
344 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
345 * index @child_index. or NULL on exception
348 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
352 AtspiAccessible *child;
354 g_return_val_if_fail (obj != NULL, NULL);
356 /* TODO: ManagesDescendants */
357 child = g_list_nth_data (obj->children, child_index);
360 return g_object_ref (child);
364 * atspi_accessible_get_index_in_parent
365 * @obj: a pointer to the #AtspiAccessible object on which to operate.
367 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
369 * Returns: a #glong indicating the index of the #AtspiAccessible object
370 * in its parent (i.e. containing) #AtspiAccessible instance,
371 * or -1 if @obj has no containing parent or on exception.
374 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
379 g_return_val_if_fail (obj != NULL, -1);
380 if (!obj->accessible_parent) return -1;
381 l = obj->accessible_parent->children;
384 if (l->data == obj) return i;
395 } Accessibility_Relation;
398 * atspi_accessible_get_relation_set:
399 * @obj: a pointer to the #AtspiAccessible object on which to operate.
401 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
402 * relationships with other #AtspiAccessible objects.
404 * Returns: (element-type AtspiAccessible*) (transfer full): an array of
405 * #AtspiAccessibleRelation pointers. or NULL on exception
408 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
411 DBusMessageIter iter, iter_array;
414 g_return_val_if_fail (obj != NULL, NULL);
416 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
417 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", NULL);
419 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
420 dbus_message_iter_init (reply, &iter);
421 dbus_message_iter_recurse (&iter, &iter_array);
422 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
425 AtspiRelation *relation;
426 relation = _atspi_relation_new_from_iter (&iter_array);
427 new_array = g_array_append_val (ret, relation);
430 dbus_message_iter_next (&iter_array);
436 * atspi_accessible_get_role:
437 * @obj: a pointer to the #AtspiAccessible object on which to operate.
439 * Get the UI role of an #AtspiAccessible object.
440 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
442 * Returns: the #AtspiRole of the object.
446 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
448 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
450 if (!(obj->cached_properties & ATSPI_CACHE_ROLE))
453 /* TODO: Make this a property */
454 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
456 obj->cached_properties |= ATSPI_CACHE_ROLE;
464 * atspi_accessible_get_role_name:
465 * @obj: a pointer to the #AtspiAccessible object on which to operate.
467 * Get a UTF-8 string describing the role this object plays in the UI.
468 * This method will return useful values for roles that fall outside the
469 * enumeration used in atspi_accessible_getRole ().
471 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
475 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
479 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
481 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
487 * atspi_accessible_get_localized_role_name:
488 * @obj: a pointer to the #AtspiAccessible object on which to operate.
490 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
491 * This method will return useful values for roles that fall outside the
492 * enumeration used in atspi_accessible_getRole ().
494 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
498 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
502 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
504 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
510 * atspi_accessible_get_state_set:
511 * @obj: a pointer to the #AtspiAccessible object on which to operate.
513 * Gets the current state of an object.
515 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
516 * object's current state.
519 atspi_accessible_get_state_set (AtspiAccessible *obj)
521 if (!(obj->cached_properties & ATSPI_CACHE_STATES))
524 DBusMessageIter iter;
525 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
526 "GetState", NULL, "");
527 _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL);
528 dbus_message_iter_init (reply, &iter);
529 _atspi_dbus_set_state (obj, &iter);
530 dbus_message_unref (reply);
533 return g_object_ref (obj->states);
537 * atspi_accessible_get_attributes:
538 * @obj: The #AtspiAccessible being queried.
540 * Get the #AttributeSet representing any assigned
541 * name-value pair attributes or annotations for this object.
542 * For typographic, textual, or textually-semantic attributes, see
543 * atspi_text_get_attributes instead.
545 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
546 * attributes assigned to this object.
549 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
551 DBusMessage *message;
554 g_return_val_if_fail (obj != NULL, NULL);
556 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
557 ret = _atspi_dbus_hash_from_message (message);
558 dbus_message_unref (message);
563 * atspi_accessible_get_attributes_as_array:
564 * @obj: The #AtspiAccessible being queried.
566 * Get the #AttributeSet representing any assigned
567 * name-value pair attributes or annotations for this object.
568 * For typographic, textual, or textually-semantic attributes, see
569 * atspi_text_get_attributes_as_array instead.
571 * Returns: (element-type gchar*) (transfer full): The name-value-pair
572 * attributes assigned to this object.
575 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
577 DBusMessage *message;
580 g_return_val_if_fail (obj != NULL, NULL);
582 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
583 ret = _atspi_dbus_attribute_array_from_message (message);
585 dbus_message_unref (message);
590 * atspi_accessible_get_application:
591 * @obj: The #AtspiAccessible being queried.
593 * Get the containing #AtspiApplication for an object.
595 * Returns: (transfer full): the containing AtspiApplication instance for
599 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
601 AtspiAccessible *parent;
605 parent = atspi_accessible_get_parent (obj, NULL);
606 if (!parent || parent == obj ||
607 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
608 return g_object_ref (obj);
613 /* Applicatio-specific methods */
616 * atspi_accessible_get_toolkit_name:
617 * @obj: a pointer to the #AtspiAccessible object on which to operate.
619 * Get the toolkit for a #AtspiAccessible object.
620 * Only works on application root objects.
622 * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
623 * or NULL on exception
626 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
630 g_return_val_if_fail (obj != NULL, NULL);
632 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName", error, "s", &ret))
634 return g_strdup (ret);
638 * atspi_accessible_get_toolkit_version:
639 * @obj: a pointer to the #AtspiAccessible object on which to operate.
641 * Get the toolkit version for a #AtspiAccessible object.
642 * Only works on application root objects.
644 * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
645 * or NULL on exception
648 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
652 g_return_val_if_fail (obj != NULL, NULL);
654 if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitVersion", error, "s", &ret))
656 return g_strdup (ret);
658 /* Interface query methods */
661 * atspi_accessible_is_action:
662 * @obj: a pointer to the #AtspiAccessible instance to query.
664 * Query whether the specified #AtspiAccessible implements #AtspiAction.
666 * Returns: #TRUE if @obj implements the #AtspiAction interface,
670 atspi_accessible_is_action (AtspiAccessible *obj)
672 return _atspi_accessible_is_a (obj,
673 atspi_interface_action);
677 * atspi_accessible_is_application:
678 * @obj: a pointer to the #AtspiAccessible instance to query.
680 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
682 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
686 atspi_accessible_is_application (AtspiAccessible *obj)
688 return _atspi_accessible_is_a (obj,
689 atspi_interface_application);
693 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
695 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
696 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
700 atspi_accessible_is_collection (AtspiAccessible *obj)
703 g_warning ("Collections not implemented");
704 return _atspi_accessible_is_a (obj,
705 atspi_interface_collection);
712 * atspi_accessible_is_component:
713 * @obj: a pointer to the #AtspiAccessible instance to query.
715 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
717 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
721 atspi_accessible_is_component (AtspiAccessible *obj)
723 return _atspi_accessible_is_a (obj,
724 atspi_interface_component);
728 * atspi_accessible_is_document:
729 * @obj: a pointer to the #AtspiAccessible instance to query.
731 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
733 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
737 atspi_accessible_is_document (AtspiAccessible *obj)
739 return _atspi_accessible_is_a (obj,
740 atspi_interface_document);
744 * atspi_accessible_is_editable_text:
745 * @obj: a pointer to the #AtspiAccessible instance to query.
747 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
749 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
753 atspi_accessible_is_editable_text (AtspiAccessible *obj)
755 return _atspi_accessible_is_a (obj,
756 atspi_interface_editable_text);
760 * atspi_accessible_is_hypertext:
761 * @obj: a pointer to the #AtspiAccessible instance to query.
763 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
765 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
769 atspi_accessible_is_hypertext (AtspiAccessible *obj)
771 return _atspi_accessible_is_a (obj,
772 atspi_interface_hypertext);
776 * atspi_accessible_is_image:
777 * @obj: a pointer to the #AtspiAccessible instance to query.
779 * Query whether the specified #AtspiAccessible implements #AtspiImage.
781 * Returns: #TRUE if @obj implements the #AtspiImage interface,
785 atspi_accessible_is_image (AtspiAccessible *obj)
787 return _atspi_accessible_is_a (obj,
788 atspi_interface_image);
792 * atspi_accessible_is_selection:
793 * @obj: a pointer to the #AtspiAccessible instance to query.
795 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
797 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
801 atspi_accessible_is_selection (AtspiAccessible *obj)
803 return _atspi_accessible_is_a (obj,
804 atspi_interface_selection);
808 * atspi_accessible_is_table:
809 * @obj: a pointer to the #AtspiAccessible instance to query.
811 * Query whether the specified #AtspiAccessible implements #AtspiTable.
813 * Returns: #TRUE if @obj implements the #AtspiTable interface,
817 atspi_accessible_is_table (AtspiAccessible *obj)
819 return _atspi_accessible_is_a (obj,
820 atspi_interface_table);
824 * atspi_accessible_is_streamable_content:
825 * @obj: a pointer to the #AtspiAccessible instance to query.
827 * Query whether the specified #AtspiAccessible implements
828 * #AtspiStreamableContent.
830 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
834 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
837 return _atspi_accessible_is_a (obj,
838 atspi_interface_streamable_content);
840 g_warning ("Streamable content not implemented");
846 * atspi_accessible_is_text:
847 * @obj: a pointer to the #AtspiAccessible instance to query.
849 * Query whether the specified #AtspiAccessible implements #AtspiText.
851 * Returns: #TRUE if @obj implements the #AtspiText interface,
855 atspi_accessible_is_text (AtspiAccessible *obj)
857 return _atspi_accessible_is_a (obj,
858 atspi_interface_text);
862 * atspi_accessible_is_value:
863 * @obj: a pointer to the #AtspiAccessible instance to query.
865 * Query whether the specified #AtspiAccessible implements #AtspiValue.
867 * Returns: #TRUE if @obj implements the #AtspiValue interface,
871 atspi_accessible_is_value (AtspiAccessible *obj)
873 return _atspi_accessible_is_a (obj,
874 atspi_interface_value);
878 * atspi_accessible_get_action:
879 * @obj: a pointer to the #AtspiAccessible instance to query.
881 * Get the #AtspiAction interface for an #AtspiAccessible.
883 * Returns: (transfer full): a pointer to an #AtspiAction interface
884 * instance, or NULL if @obj does not implement #AtspiAction.
887 atspi_accessible_get_action (AtspiAccessible *accessible)
889 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
890 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
894 * atspi_accessible_get_collection:
895 * @obj: a pointer to the #AtspiAccessible instance to query.
897 * Get the #AtspiCollection interface for an #AtspiAccessible.
899 * Returns: (transfer full): a pointer to an #AtspiCollection interface
900 * instance, or NULL if @obj does not implement #AtspiCollection.
903 atspi_accessible_get_collection (AtspiAccessible *accessible)
905 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
906 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
910 * atspi_accessible_get_component:
911 * @obj: a pointer to the #AtspiAccessible instance to query.
913 * Get the #AtspiComponent interface for an #AtspiAccessible.
915 * Returns: (transfer full): a pointer to an #AtspiComponent interface
916 * instance, or NULL if @obj does not implement #AtspiComponent.
919 atspi_accessible_get_component (AtspiAccessible *obj)
921 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
922 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
926 * atspi_accessible_get_document:
927 * @obj: a pointer to the #AtspiAccessible instance to query.
929 * Get the #AtspiDocument interface for an #AtspiAccessible.
931 * Returns: (transfer full): a pointer to an #AtspiDocument interface
932 * instance, or NULL if @obj does not implement #AtspiDocument.
935 atspi_accessible_get_document (AtspiAccessible *accessible)
937 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
938 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
942 * atspi_accessible_get_editable_text:
943 * @obj: a pointer to the #AtspiAccessible instance to query.
945 * Get the #AtspiEditableText interface for an #AtspiAccessible.
947 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
948 * instance, or NULL if @obj does not implement #AtspiEditableText.
951 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
953 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
954 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
958 * atspi_accessible_get_hyperlink:
959 * @accessible: a pointer to the #AtspiAccessible object on which to operate.
961 * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
964 * Returns: (transfer full): the #AtspiHyperlink object associated with
965 * the given #AtspiAccessible, or NULL if not supported.
968 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
970 return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
971 atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
975 * atspi_accessible_get_hypertext:
976 * @obj: a pointer to the #AtspiAccessible instance to query.
978 * Get the #AtspiHypertext interface for an #AtspiAccessible.
980 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
981 * instance, or NULL if @obj does not implement #AtspiHypertext.
984 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
986 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
987 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
991 * atspi_accessible_get_image:
992 * @obj: a pointer to the #AtspiAccessible instance to query.
994 * Get the #AtspiImage interface for an #AtspiAccessible.
996 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
997 * NULL if @obj does not implement #AtspiImage.
1000 atspi_accessible_get_image (AtspiAccessible *accessible)
1002 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1003 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
1007 * atspi_accessible_get_selection:
1008 * @obj: a pointer to the #AtspiAccessible instance to query.
1010 * Get the #AtspiSelection interface for an #AtspiAccessible.
1012 * Returns: (transfer full): a pointer to an #AtspiSelection interface
1013 * instance, or NULL if @obj does not implement #AtspiSelection.
1016 atspi_accessible_get_selection (AtspiAccessible *accessible)
1018 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1019 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
1024 * atspi_accessible_get_streamable_content:
1025 * @obj: a pointer to the #AtspiAccessible instance to query.
1027 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1029 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1030 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
1032 AtspiStreamableContent *
1033 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1035 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1041 * atspi_accessible_get_table:
1042 * @obj: a pointer to the #AtspiAccessible instance to query.
1044 * Get the #AtspiTable interface for an #AtspiAccessible.
1046 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1047 * NULL if @obj does not implement #AtspiTable.
1050 atspi_accessible_get_table (AtspiAccessible *obj)
1052 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1053 g_object_ref (ATSPI_TABLE (obj)) : NULL);
1057 * atspi_accessible_get_text:
1058 * @obj: a pointer to the #AtspiAccessible instance to query.
1060 * Get the #AtspiTable interface for an #AtspiAccessible.
1062 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1063 * NULL if @obj does not implement #AtspiTable.
1066 atspi_accessible_get_text (AtspiAccessible *obj)
1068 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1069 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1073 * atspi_accessible_get_value:
1074 * @obj: a pointer to the #AtspiAccessible instance to query.
1076 * Get the #AtspiTable interface for an #AtspiAccessible.
1078 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1079 * NULL if @obj does not implement #AtspiValue.
1082 atspi_accessible_get_value (AtspiAccessible *accessible)
1084 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1085 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1090 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
1093 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
1095 relation_type_table [i] = SPI_RELATION_NULL;
1097 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
1098 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
1099 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
1100 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
1101 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
1102 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
1103 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
1104 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
1105 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
1106 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
1107 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
1108 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
1109 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
1110 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
1111 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
1112 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
1113 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
1114 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
1118 static AccessibleRelationType
1119 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
1121 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
1122 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
1123 static gboolean is_initialized = FALSE;
1124 AccessibleRelationType cspi_type;
1125 if (!is_initialized)
1127 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
1129 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
1131 cspi_type = cspi_relation_type_table [type];
1135 cspi_type = SPI_RELATION_NULL;
1140 * AccessibleRelation_getRelationType:
1141 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1143 * Get the type of relationship represented by an #AtspiAccessibleRelation.
1145 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
1146 * encapsulated in this #AtspiAccessibleRelation object.
1149 AccessibleRelationType
1150 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1152 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1153 return cspi_relation_type_from_spi_relation_type (obj->type);
1157 * AccessibleRelation_getNTargets:
1158 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1160 * Get the number of objects which this relationship has as its
1161 * target objects (the subject is the #AtspiAccessible from which this
1162 * #AtspiAccessibleRelation originated).
1164 * Returns: a short integer indicating how many target objects which the
1165 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
1166 * relationship with.
1169 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1171 cspi_return_val_if_fail (obj, -1);
1172 return obj->targets->len;
1176 * AccessibleRelation_getTarget:
1177 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1178 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1180 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
1182 * Returns: an #AtspiAccessible which is the @i-th object with which the
1183 * originating #AtspiAccessible has relationship specified in the
1184 * #AtspiAccessibleRelation object.
1188 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1190 cspi_return_val_if_fail (obj, NULL);
1192 if (i < 0 || i >= obj->targets->len) return NULL;
1193 return cspi_object_add (
1194 g_array_index (obj->targets, Accessible *, i));
1198 * AccessibleStateSet_ref:
1199 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1201 * Increment the reference count for an #AtspiAccessibleStateSet object.
1205 AccessibleStateSet_ref (AccessibleStateSet *obj)
1207 spi_state_set_cache_ref (obj);
1211 * AccessibleStateSet_unref:
1212 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1214 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1218 AccessibleStateSet_unref (AccessibleStateSet *obj)
1220 spi_state_set_cache_unref (obj);
1223 static Accessibility_StateType
1224 spi_state_to_dbus (AccessibleState state)
1226 #define MAP_STATE(a) \
1227 case SPI_STATE_##a: \
1228 return Accessibility_STATE_##a
1232 MAP_STATE (INVALID);
1236 MAP_STATE (CHECKED);
1237 MAP_STATE (DEFUNCT);
1238 MAP_STATE (EDITABLE);
1239 MAP_STATE (ENABLED);
1240 MAP_STATE (EXPANDABLE);
1241 MAP_STATE (EXPANDED);
1242 MAP_STATE (FOCUSABLE);
1243 MAP_STATE (FOCUSED);
1244 MAP_STATE (HORIZONTAL);
1245 MAP_STATE (ICONIFIED);
1247 MAP_STATE (MULTI_LINE);
1248 MAP_STATE (MULTISELECTABLE);
1250 MAP_STATE (PRESSED);
1251 MAP_STATE (RESIZABLE);
1252 MAP_STATE (SELECTABLE);
1253 MAP_STATE (SELECTED);
1254 MAP_STATE (SENSITIVE);
1255 MAP_STATE (SHOWING);
1256 MAP_STATE (SINGLE_LINE);
1258 MAP_STATE (TRANSIENT);
1259 MAP_STATE (VERTICAL);
1260 MAP_STATE (VISIBLE);
1261 MAP_STATE (MANAGES_DESCENDANTS);
1262 MAP_STATE (INDETERMINATE);
1263 MAP_STATE (TRUNCATED);
1264 MAP_STATE (REQUIRED);
1265 MAP_STATE (INVALID_ENTRY);
1266 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1267 MAP_STATE (SELECTABLE_TEXT);
1268 MAP_STATE (IS_DEFAULT);
1269 MAP_STATE (VISITED);
1271 return Accessibility_STATE_INVALID;
1277 * AccessibleStateSet_contains:
1278 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1279 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1282 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1283 * whether @state is true for the stateset in question.
1285 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1290 AccessibleStateSet_contains (AccessibleStateSet *obj,
1291 AccessibleState state)
1293 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1297 * AccessibleStateSet_add:
1298 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1299 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1301 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1302 * given state to #TRUE in the stateset.
1306 AccessibleStateSet_add (AccessibleStateSet *obj,
1307 AccessibleState state)
1309 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1313 * AccessibleStateSet_remove:
1314 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1315 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1317 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1318 * given state to #FALSE in the stateset.)
1322 AccessibleStateSet_remove (AccessibleStateSet *obj,
1323 AccessibleState state)
1325 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1329 * AccessibleStateSet_equals:
1330 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1331 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1333 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1334 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1335 * state variables at once; construct the target state then compare against it.
1337 * @see AccessibleStateSet_compare().
1339 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1344 AccessibleStateSet_equals (AccessibleStateSet *obj,
1345 AccessibleStateSet *obj2)
1355 cmp = spi_state_set_cache_xor (obj, obj2);
1356 eq = spi_state_set_cache_is_empty (cmp);
1357 spi_state_set_cache_unref (cmp);
1363 * AccessibleStateSet_compare:
1364 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1365 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1367 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1368 * Not Yet Implemented.
1370 * @see AccessibleStateSet_equals().
1372 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1373 * the two sets but not the other.
1376 AccessibleStateSet *
1377 AccessibleStateSet_compare (AccessibleStateSet *obj,
1378 AccessibleStateSet *obj2)
1380 return spi_state_set_cache_xor (obj, obj2);
1384 * AccessibleStateSet_isEmpty:
1385 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1387 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1389 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1394 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1396 return spi_state_set_cache_is_empty (obj);
1401 _atspi_accessible_is_a (AtspiAccessible *accessible,
1402 const char *interface_name)
1406 if (accessible == NULL)
1411 if (!(accessible->cached_properties & ATSPI_CACHE_INTERFACES))
1414 DBusMessageIter iter;
1415 reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
1416 "GetInterfaces", NULL, "");
1417 _ATSPI_DBUS_CHECK_SIG (reply, "as", FALSE);
1418 dbus_message_iter_init (reply, &iter);
1419 _atspi_dbus_set_interfaces (accessible, &iter);
1420 dbus_message_unref (reply);
1423 n = _atspi_get_iface_num (interface_name);
1424 if (n == -1) return FALSE;
1425 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1429 append_const_val (GArray *array, const gchar *val)
1431 gchar *dup = g_strdup (val);
1434 g_array_append_val (array, dup);
1438 * atspi_accessible_get_interfaces:
1440 * #obj: The #AtspiAccessible to query.
1442 * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1443 * describing the interfaces supported by the object. Interfaces are
1444 * denoted in short-hand (ie, "Component", "Text", etc.)
1447 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1449 GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1454 g_return_val_if_fail (obj != NULL, NULL);
1456 if (atspi_accessible_is_action (obj))
1457 append_const_val (ret, "Action");
1458 if (atspi_accessible_is_collection (obj))
1459 append_const_val (ret, "Collection");
1460 if (atspi_accessible_is_component (obj))
1461 append_const_val (ret, "Component");
1462 if (atspi_accessible_is_document (obj))
1463 append_const_val (ret, "Document");
1464 if (atspi_accessible_is_editable_text (obj))
1465 append_const_val (ret, "EditableText");
1466 if (atspi_accessible_is_hypertext (obj))
1467 append_const_val (ret, "Hypertext");
1468 if (atspi_accessible_is_image (obj))
1469 append_const_val (ret, "Image");
1470 if (atspi_accessible_is_selection (obj))
1471 append_const_val (ret, "Selection");
1472 if (atspi_accessible_is_table (obj))
1473 append_const_val (ret, "Table");
1474 if (atspi_accessible_is_text (obj))
1475 append_const_val (ret, "Text");
1476 if (atspi_accessible_is_value (obj))
1477 append_const_val (ret, "Value");
1482 /* TODO: Move to a finalizer */
1484 cspi_object_destroyed (AtspiAccessible *accessible)
1489 /* TODO: Only fire if object not already marked defunct */
1490 memset (&e, 0, sizeof (e));
1491 e.type = "object:state-change:defunct";
1492 e.source = accessible;
1495 _atspi_send_event (&e);
1497 g_free (accessible->parent.path);
1499 if (accessible->states)
1500 g_object_unref (accessible->states);
1501 g_free (accessible->description);
1502 g_free (accessible->name);
1506 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1508 AtspiAccessible *accessible;
1510 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1511 g_return_val_if_fail (accessible != NULL, NULL);
1513 accessible->parent.app = g_object_ref (app);
1514 accessible->parent.path = g_strdup (path);