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_component_interface_init (AtspiComponent *component)
37 atspi_editable_text_interface_init (AtspiEditableText *editable_text)
42 atspi_image_interface_init (AtspiImage *image)
47 atspi_selection_interface_init (AtspiSelection *selection)
52 atspi_table_interface_init (AtspiTable *table)
57 atspi_text_interface_init (AtspiText *text)
62 atspi_value_interface_init (AtspiValue *value)
66 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT,
67 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init)
68 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
69 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init)
70 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init)
71 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init)
72 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
73 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init)
74 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_VALUE, atspi_value_interface_init))
77 atspi_accessible_init (AtspiAccessible *accessible)
82 atspi_accessible_finalize (GObject *obj)
84 /*AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj); */
86 /* TODO: Unref parent/children, etc. */
90 atspi_accessible_class_init (AtspiAccessibleClass *klass)
92 GObjectClass *object_class = G_OBJECT_CLASS (klass);
94 object_class->finalize = atspi_accessible_finalize;
97 /* TODO: Generate following from spec? */
98 static const char *role_names [] =
156 "table-column-header",
158 "tear-off-menu-item",
188 "input method window"
191 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
194 * atspi_role_get_name
195 * @role: an #AtspiAccessibleRole object to query.
197 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
198 * <em>DEPRECATED.</em>
200 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
203 atspi_role_get_name (AtspiRole role)
205 if (role < MAX_ROLES && role_names [(int) role])
207 return g_strdup (role_names [(int) role]);
211 return g_strdup ("");
216 * atspi_accessible_get_name:
217 * @obj: a pointer to the #AtspiAccessible object on which to operate.
219 * Get the name of an #AtspiAccessible object.
221 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
222 * or NULL on exception
225 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
227 g_return_val_if_fail (obj != NULL, NULL);
228 if (!(obj->cached_properties & ATSPI_CACHE_NAME))
230 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", NULL, "s", &obj->name))
232 obj->cached_properties |= ATSPI_CACHE_NAME;
234 return g_strdup (obj->name);
238 * atspi_accessible_get_description:
239 * @obj: a pointer to the #AtspiAccessible object on which to operate.
241 * Get the description of an #AtspiAccessible object.
243 * Returns: a UTF-8 string describing the #AtspiAccessible object.
244 * or NULL on exception
247 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
249 g_return_val_if_fail (obj != NULL, NULL);
251 if (!(obj->cached_properties & ATSPI_CACHE_DESCRIPTION))
253 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetDescription", NULL, "=>s", &obj->description))
255 obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
257 return g_strdup (obj->description);
260 const char *str_parent = "Parent";
263 * atspi_accessible_get_parent:
264 * @obj: a pointer to the #AtspiAccessible object to query.
266 * Get an #AtspiAccessible object's parent container.
268 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
269 * contains the given #AtspiAccessible instance, or NULL if the @obj
270 * has no parent container.
274 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
276 g_return_val_if_fail (obj != NULL, NULL);
278 if (!(obj->cached_properties & ATSPI_CACHE_PARENT))
280 DBusMessage *message, *reply;
281 DBusMessageIter iter, iter_variant;
282 message = dbus_message_new_method_call (obj->parent.app->bus_name,
284 DBUS_INTERFACE_PROPERTIES, "Get");
287 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
288 DBUS_TYPE_STRING, &str_parent,
290 reply = _atspi_dbus_send_with_reply_and_block (message);
292 (strcmp (dbus_message_get_signature (reply), "v") != 0))
294 dbus_message_iter_init (reply, &iter);
295 dbus_message_iter_recurse (&iter, &iter_variant);
296 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
297 dbus_message_unref (reply);
298 obj->cached_properties |= ATSPI_CACHE_PARENT;
300 if (!obj->accessible_parent)
302 return g_object_ref (obj->accessible_parent);
306 * atspi_accessible_get_child_count:
307 * @obj: a pointer to the #AtspiAccessible object on which to operate.
309 * Get the number of children contained by an #AtspiAccessible object.
311 * Returns: a #long indicating the number of #AtspiAccessible children
312 * contained by an #AtspiAccessible object. or -1 on exception
316 atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error)
318 g_return_val_if_fail (obj != NULL, -1);
320 /* TODO: MANAGES_DESCENDANTS */
321 return g_list_length (obj->children);
325 * atspi_accessible_get_child_at_index:
326 * @obj: a pointer to the #AtspiAccessible object on which to operate.
327 * @child_index: a #long indicating which child is specified.
329 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
331 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
332 * index @child_index. or NULL on exception
335 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
339 AtspiAccessible *child;
341 g_return_val_if_fail (obj != NULL, NULL);
343 /* TODO: ManagesDescendants */
344 child = g_list_nth_data (obj->children, child_index);
347 return g_object_ref (child);
351 * atspi_accessible_get_index_in_parent
352 * @obj: a pointer to the #AtspiAccessible object on which to operate.
354 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
356 * Returns: a #glong indicating the index of the #AtspiAccessible object
357 * in its parent (i.e. containing) #AtspiAccessible instance,
358 * or -1 if @obj has no containing parent or on exception.
361 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
366 g_return_val_if_fail (obj != NULL, -1);
367 if (!obj->accessible_parent) return -1;
368 l = obj->accessible_parent->children;
371 if (l->data == obj) return i;
382 } Accessibility_Relation;
385 * atspi_accessible_get_relation_set:
386 * @obj: a pointer to the #AtspiAccessible object on which to operate.
388 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
389 * relationships with other #AtspiAccessible objects.
391 * Returns: an array of #AtspiAccessibleRelation pointers. or NULL on exception
392 * TODO:: Annotate array type
395 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
399 GArray *relation_set;
401 g_return_val_if_fail (obj != NULL, NULL);
403 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetRelationSet", error, "=>a(uao)", &relation_set))
410 * atspi_accessible_get_role:
411 * @obj: a pointer to the #AtspiAccessible object on which to operate.
413 * Get the UI role of an #AtspiAccessible object.
414 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
416 * Returns: the #AtspiRole of the object.
420 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
422 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
424 if (!(obj->cached_properties & ATSPI_CACHE_ROLE))
427 /* TODO: Make this a property */
428 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
430 obj->cached_properties |= ATSPI_CACHE_ROLE;
438 * atspi_accessible_get_role_name:
439 * @obj: a pointer to the #AtspiAccessible object on which to operate.
441 * Get a UTF-8 string describing the role this object plays in the UI.
442 * This method will return useful values for roles that fall outside the
443 * enumeration used in atspi_accessible_getRole ().
445 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
449 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
453 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
455 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
461 * atspi_accessible_get_localized_role_name:
462 * @obj: a pointer to the #AtspiAccessible object on which to operate.
464 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
465 * This method will return useful values for roles that fall outside the
466 * enumeration used in atspi_accessible_getRole ().
468 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
472 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
476 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
478 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
484 * atspi_accessible_get_state_set:
485 * @obj: a pointer to the #AtspiAccessible object on which to operate.
487 * Gets the current state of an object.
489 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
490 * object's current state.
493 atspi_accessible_get_state_set (AtspiAccessible *obj)
499 * atspi_accessible_get_attributes:
500 * @obj: The #AtspiAccessible being queried.
502 * Get the #AttributeSet representing any assigned
503 * name-value pair attributes or annotations for this object.
504 * For typographic, textual, or textually-semantic attributes, see
505 * atspi_text_get_attributes instead.
507 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
508 * attributes assigned to this object.
511 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
513 DBusMessage *message;
516 g_return_val_if_fail (obj != NULL, NULL);
518 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
519 ret = _atspi_dbus_hash_from_message (message);
520 dbus_message_unref (message);
525 * atspi_accessible_get_attributes_as_array:
526 * @obj: The #AtspiAccessible being queried.
528 * Get the #AttributeSet representing any assigned
529 * name-value pair attributes or annotations for this object.
530 * For typographic, textual, or textually-semantic attributes, see
531 * atspi_text_get_attributes_as_array instead.
533 * Returns: (element-type gchar*) (transfer full): The name-value-pair
534 * attributes assigned to this object.
537 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
539 DBusMessage *message;
542 g_return_val_if_fail (obj != NULL, NULL);
544 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
545 ret = _atspi_dbus_attribute_array_from_message (message);
546 dbus_message_unref (message);
551 * atspi_accessible_get_host_application:
552 * @obj: The #AtspiAccessible being queried.
554 * Get the containing #AtspiApplication for an object.
556 * Returns: (transfer full): the containing AtspiApplication instance for
560 atspi_accessible_get_host_application (AtspiAccessible *obj, GError **error)
562 AtspiAccessible *parent;
566 parent = atspi_accessible_get_parent (obj, NULL);
567 if (!parent || parent == obj ||
568 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
574 /* Interface query methods */
577 * atspi_accessible_is_action:
578 * @obj: a pointer to the #AtspiAccessible instance to query.
580 * Query whether the specified #AtspiAccessible implements #AtspiAction.
582 * Returns: #TRUE if @obj implements the #AtspiAction interface,
586 atspi_accessible_is_action (AtspiAccessible *obj)
588 return _atspi_accessible_is_a (obj,
589 atspi_interface_action);
593 * atspi_accessible_is_application:
594 * @obj: a pointer to the #AtspiAccessible instance to query.
596 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
598 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
602 atspi_accessible_is_application (AtspiAccessible *obj)
604 return _atspi_accessible_is_a (obj,
605 atspi_interface_application);
609 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
611 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
612 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
616 atspi_accessible_is_collection (AtspiAccessible *obj)
619 g_warning ("Collections not implemented");
620 return _atspi_accessible_is_a (obj,
621 atspi_interface_collection);
628 * atspi_accessible_is_component:
629 * @obj: a pointer to the #AtspiAccessible instance to query.
631 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
633 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
637 atspi_accessible_is_component (AtspiAccessible *obj)
639 return _atspi_accessible_is_a (obj,
640 atspi_interface_component);
644 * atspi_accessible_is_document:
645 * @obj: a pointer to the #AtspiAccessible instance to query.
647 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
649 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
653 atspi_accessible_is_document (AtspiAccessible *obj)
655 return _atspi_accessible_is_a (obj,
656 atspi_interface_document);
660 * atspi_accessible_is_editable_text:
661 * @obj: a pointer to the #AtspiAccessible instance to query.
663 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
665 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
669 atspi_accessible_is_editable_text (AtspiAccessible *obj)
671 return _atspi_accessible_is_a (obj,
672 atspi_interface_editable_text);
676 * atspi_accessible_is_hypertext:
677 * @obj: a pointer to the #AtspiAccessible instance to query.
679 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
681 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
685 atspi_accessible_is_hypertext (AtspiAccessible *obj)
687 return _atspi_accessible_is_a (obj,
688 atspi_interface_hypertext);
692 * atspi_accessible_is_image:
693 * @obj: a pointer to the #AtspiAccessible instance to query.
695 * Query whether the specified #AtspiAccessible implements #AtspiImage.
697 * Returns: #TRUE if @obj implements the #AtspiImage interface,
701 atspi_accessible_is_image (AtspiAccessible *obj)
703 return _atspi_accessible_is_a (obj,
704 atspi_interface_image);
708 * atspi_accessible_is_selection:
709 * @obj: a pointer to the #AtspiAccessible instance to query.
711 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
713 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
717 atspi_accessible_is_selection (AtspiAccessible *obj)
719 return _atspi_accessible_is_a (obj,
720 atspi_interface_selection);
724 * atspi_accessible_is_table:
725 * @obj: a pointer to the #AtspiAccessible instance to query.
727 * Query whether the specified #AtspiAccessible implements #AtspiTable.
729 * Returns: #TRUE if @obj implements the #AtspiTable interface,
733 atspi_accessible_is_table (AtspiAccessible *obj)
735 return _atspi_accessible_is_a (obj,
736 atspi_interface_table);
740 * atspi_accessible_is_streamable_content:
741 * @obj: a pointer to the #AtspiAccessible instance to query.
743 * Query whether the specified #AtspiAccessible implements
744 * #AtspiStreamableContent.
746 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
750 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
753 return _atspi_accessible_is_a (obj,
754 atspi_interface_streamable_content);
756 g_warning ("Streamable content not implemented");
762 * atspi_accessible_is_text:
763 * @obj: a pointer to the #AtspiAccessible instance to query.
765 * Query whether the specified #AtspiAccessible implements #AtspiText.
767 * Returns: #TRUE if @obj implements the #AtspiText interface,
771 atspi_accessible_is_text (AtspiAccessible *obj)
773 return _atspi_accessible_is_a (obj,
774 atspi_interface_text);
778 * atspi_accessible_is_value:
779 * @obj: a pointer to the #AtspiAccessible instance to query.
781 * Query whether the specified #AtspiAccessible implements #AtspiValue.
783 * Returns: #TRUE if @obj implements the #AtspiValue interface,
787 atspi_accessible_is_value (AtspiAccessible *obj)
789 return _atspi_accessible_is_a (obj,
790 atspi_interface_value);
794 * atspi_accessible_get_application:
795 * @obj: a pointer to the #AtspiAccessible instance to query.
797 * Get the #AtspiApplication interface for an #AtspiAccessible.
799 * Returns: a pointer to an #AtspiApplication interface instance, or
800 * NULL if @obj does not implement #AtspiApplication.
803 atspi_accessible_get_application (AtspiAccessible *accessible)
805 return (_atspi_accessible_is_a (accessible, atspi_interface_application) ?
806 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
810 * atspi_accessible_get_action:
811 * @obj: a pointer to the #AtspiAccessible instance to query.
813 * Get the #AtspiAction interface for an #AtspiAccessible.
815 * Returns: (transfer full): a pointer to an #AtspiAction interface
816 * instance, or NULL if @obj does not implement #AtspiAction.
819 atspi_accessible_get_action (AtspiAccessible *accessible)
821 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
822 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
826 * atspi_accessible_get_collection:
827 * @obj: a pointer to the #AtspiAccessible instance to query.
829 * Get the #AtspiCollection interface for an #AtspiAccessible.
831 * Returns: (transfer full): a pointer to an #AtspiCollection interface
832 * instance, or NULL if @obj does not implement #AtspiCollection.
835 atspi_accessible_get_collection (AtspiAccessible *accessible)
837 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
838 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
842 * atspi_accessible_get_component:
843 * @obj: a pointer to the #AtspiAccessible instance to query.
845 * Get the #AtspiComponent interface for an #AtspiAccessible.
847 * Returns: (transfer full): a pointer to an #AtspiComponent interface
848 * instance, or NULL if @obj does not implement #AtspiComponent.
851 atspi_accessible_get_component (AtspiAccessible *obj)
853 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
854 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
858 * atspi_accessible_get_document:
859 * @obj: a pointer to the #AtspiAccessible instance to query.
861 * Get the #AtspiDocument interface for an #AtspiAccessible.
863 * Returns: (transfer full): a pointer to an #AtspiDocument interface
864 * instance, or NULL if @obj does not implement #AtspiDocument.
867 atspi_accessible_get_document (AtspiAccessible *accessible)
869 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
870 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
874 * atspi_accessible_get_editable_text:
875 * @obj: a pointer to the #AtspiAccessible instance to query.
877 * Get the #AtspiEditableText interface for an #AtspiAccessible.
879 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
880 * instance, or NULL if @obj does not implement #AtspiEditableText.
883 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
885 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
886 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
890 * atspi_accessible_get_hypertext:
891 * @obj: a pointer to the #AtspiAccessible instance to query.
893 * Get the #AtspiHypertext interface for an #AtspiAccessible.
895 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
896 * instance, or NULL if @obj does not implement #AtspiHypertext.
899 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
901 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
902 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
906 * atspi_accessible_get_image:
907 * @obj: a pointer to the #AtspiAccessible instance to query.
909 * Get the #AtspiImage interface for an #AtspiAccessible.
911 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
912 * NULL if @obj does not implement #AtspiImage.
915 atspi_accessible_get_image (AtspiAccessible *accessible)
917 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
918 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
922 * atspi_accessible_get_selection:
923 * @obj: a pointer to the #AtspiAccessible instance to query.
925 * Get the #AtspiSelection interface for an #AtspiAccessible.
927 * Returns: (transfer full): a pointer to an #AtspiSelection interface
928 * instance, or NULL if @obj does not implement #AtspiSelection.
931 atspi_accessible_get_selection (AtspiAccessible *accessible)
933 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
934 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
939 * atspi_accessible_get_streamable_content:
940 * @obj: a pointer to the #AtspiAccessible instance to query.
942 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
944 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
945 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
947 AtspiStreamableContent *
948 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
950 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
956 * atspi_accessible_get_table:
957 * @obj: a pointer to the #AtspiAccessible instance to query.
959 * Get the #AtspiTable interface for an #AtspiAccessible.
961 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
962 * NULL if @obj does not implement #AtspiTable.
965 atspi_accessible_get_table (AtspiAccessible *obj)
967 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
968 g_object_ref (ATSPI_TABLE (obj)) : NULL);
972 * atspi_accessible_get_text:
973 * @obj: a pointer to the #AtspiAccessible instance to query.
975 * Get the #AtspiTable interface for an #AtspiAccessible.
977 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
978 * NULL if @obj does not implement #AtspiTable.
981 atspi_accessible_get_text (AtspiAccessible *obj)
983 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
984 g_object_ref (ATSPI_TEXT (obj)) : NULL);
988 * atspi_accessible_get_value:
989 * @obj: a pointer to the #AtspiAccessible instance to query.
991 * Get the #AtspiTable interface for an #AtspiAccessible.
993 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
994 * NULL if @obj does not implement #AtspiValue.
997 atspi_accessible_get_value (AtspiAccessible *accessible)
999 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1000 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1005 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
1008 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
1010 relation_type_table [i] = SPI_RELATION_NULL;
1012 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
1013 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
1014 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
1015 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
1016 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
1017 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
1018 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
1019 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
1020 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
1021 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
1022 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
1023 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
1024 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
1025 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
1026 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
1027 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
1028 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
1029 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
1033 static AccessibleRelationType
1034 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
1036 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
1037 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
1038 static gboolean is_initialized = FALSE;
1039 AccessibleRelationType cspi_type;
1040 if (!is_initialized)
1042 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
1044 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
1046 cspi_type = cspi_relation_type_table [type];
1050 cspi_type = SPI_RELATION_NULL;
1055 * AccessibleRelation_getRelationType:
1056 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1058 * Get the type of relationship represented by an #AtspiAccessibleRelation.
1060 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
1061 * encapsulated in this #AtspiAccessibleRelation object.
1064 AccessibleRelationType
1065 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1067 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1068 return cspi_relation_type_from_spi_relation_type (obj->type);
1072 * AccessibleRelation_getNTargets:
1073 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1075 * Get the number of objects which this relationship has as its
1076 * target objects (the subject is the #AtspiAccessible from which this
1077 * #AtspiAccessibleRelation originated).
1079 * Returns: a short integer indicating how many target objects which the
1080 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
1081 * relationship with.
1084 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1086 cspi_return_val_if_fail (obj, -1);
1087 return obj->targets->len;
1091 * AccessibleRelation_getTarget:
1092 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1093 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1095 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
1097 * Returns: an #AtspiAccessible which is the @i-th object with which the
1098 * originating #AtspiAccessible has relationship specified in the
1099 * #AtspiAccessibleRelation object.
1103 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1105 cspi_return_val_if_fail (obj, NULL);
1107 if (i < 0 || i >= obj->targets->len) return NULL;
1108 return cspi_object_add (
1109 g_array_index (obj->targets, Accessible *, i));
1113 * AccessibleStateSet_ref:
1114 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1116 * Increment the reference count for an #AtspiAccessibleStateSet object.
1120 AccessibleStateSet_ref (AccessibleStateSet *obj)
1122 spi_state_set_cache_ref (obj);
1126 * AccessibleStateSet_unref:
1127 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1129 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1133 AccessibleStateSet_unref (AccessibleStateSet *obj)
1135 spi_state_set_cache_unref (obj);
1138 static Accessibility_StateType
1139 spi_state_to_dbus (AccessibleState state)
1141 #define MAP_STATE(a) \
1142 case SPI_STATE_##a: \
1143 return Accessibility_STATE_##a
1147 MAP_STATE (INVALID);
1151 MAP_STATE (CHECKED);
1152 MAP_STATE (DEFUNCT);
1153 MAP_STATE (EDITABLE);
1154 MAP_STATE (ENABLED);
1155 MAP_STATE (EXPANDABLE);
1156 MAP_STATE (EXPANDED);
1157 MAP_STATE (FOCUSABLE);
1158 MAP_STATE (FOCUSED);
1159 MAP_STATE (HORIZONTAL);
1160 MAP_STATE (ICONIFIED);
1162 MAP_STATE (MULTI_LINE);
1163 MAP_STATE (MULTISELECTABLE);
1165 MAP_STATE (PRESSED);
1166 MAP_STATE (RESIZABLE);
1167 MAP_STATE (SELECTABLE);
1168 MAP_STATE (SELECTED);
1169 MAP_STATE (SENSITIVE);
1170 MAP_STATE (SHOWING);
1171 MAP_STATE (SINGLE_LINE);
1173 MAP_STATE (TRANSIENT);
1174 MAP_STATE (VERTICAL);
1175 MAP_STATE (VISIBLE);
1176 MAP_STATE (MANAGES_DESCENDANTS);
1177 MAP_STATE (INDETERMINATE);
1178 MAP_STATE (TRUNCATED);
1179 MAP_STATE (REQUIRED);
1180 MAP_STATE (INVALID_ENTRY);
1181 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1182 MAP_STATE (SELECTABLE_TEXT);
1183 MAP_STATE (IS_DEFAULT);
1184 MAP_STATE (VISITED);
1186 return Accessibility_STATE_INVALID;
1192 * AccessibleStateSet_contains:
1193 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1194 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1197 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1198 * whether @state is true for the stateset in question.
1200 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1205 AccessibleStateSet_contains (AccessibleStateSet *obj,
1206 AccessibleState state)
1208 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1212 * AccessibleStateSet_add:
1213 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1214 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1216 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1217 * given state to #TRUE in the stateset.
1221 AccessibleStateSet_add (AccessibleStateSet *obj,
1222 AccessibleState state)
1224 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1228 * AccessibleStateSet_remove:
1229 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1230 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1232 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1233 * given state to #FALSE in the stateset.)
1237 AccessibleStateSet_remove (AccessibleStateSet *obj,
1238 AccessibleState state)
1240 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1244 * AccessibleStateSet_equals:
1245 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1246 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1248 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1249 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1250 * state variables at once; construct the target state then compare against it.
1252 * @see AccessibleStateSet_compare().
1254 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1259 AccessibleStateSet_equals (AccessibleStateSet *obj,
1260 AccessibleStateSet *obj2)
1270 cmp = spi_state_set_cache_xor (obj, obj2);
1271 eq = spi_state_set_cache_is_empty (cmp);
1272 spi_state_set_cache_unref (cmp);
1278 * AccessibleStateSet_compare:
1279 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1280 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1282 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1283 * Not Yet Implemented.
1285 * @see AccessibleStateSet_equals().
1287 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1288 * the two sets but not the other.
1291 AccessibleStateSet *
1292 AccessibleStateSet_compare (AccessibleStateSet *obj,
1293 AccessibleStateSet *obj2)
1295 return spi_state_set_cache_xor (obj, obj2);
1299 * AccessibleStateSet_isEmpty:
1300 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1302 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1304 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1309 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1311 return spi_state_set_cache_is_empty (obj);
1316 _atspi_accessible_is_a (AtspiAccessible *accessible,
1317 const char *interface_name)
1321 if (accessible == NULL)
1326 n = _atspi_get_iface_num (interface_name);
1327 if (n == -1) return FALSE;
1328 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1331 /* TODO: Move to a finalizer */
1333 cspi_object_destroyed (AtspiAccessible *accessible)
1338 /* TODO: Only fire if object not already marked defunct */
1339 memset (&e, 0, sizeof (e));
1340 e.type = "object:state-change:defunct";
1341 e.source = accessible;
1344 _atspi_send_event (&e);
1346 g_free (accessible->parent.path);
1348 if (accessible->states)
1349 g_object_unref (accessible->states);
1350 g_free (accessible->description);
1351 g_free (accessible->name);
1355 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1357 AtspiAccessible *accessible;
1359 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1360 g_return_val_if_fail (accessible != NULL, NULL);
1362 accessible->parent.app = g_object_ref (app);
1363 accessible->parent.path = g_strdup (path);