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);
811 * atspi_accessible_get_action:
812 * @obj: a pointer to the #AtspiAccessible instance to query.
814 * Get the #AtspiAction interface for an #AtspiAccessible.
816 * Returns: (transfer full): a pointer to an #AtspiAction interface
817 * instance, or NULL if @obj does not implement #AtspiAction.
820 atspi_accessible_get_action (AtspiAccessible *accessible)
822 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
827 * atspi_accessible_get_collection:
828 * @obj: a pointer to the #AtspiAccessible instance to query.
830 * Get the #AtspiCollection interface for an #AtspiAccessible.
832 * Returns: (transfer full): a pointer to an #AtspiCollection interface
833 * instance, or NULL if @obj does not implement #AtspiCollection.
836 atspi_accessible_get_collection (AtspiAccessible *accessible)
838 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
844 * atspi_accessible_get_component:
845 * @obj: a pointer to the #AtspiAccessible instance to query.
847 * Get the #AtspiComponent interface for an #AtspiAccessible.
849 * Returns: (transfer full): a pointer to an #AtspiComponent interface
850 * instance, or NULL if @obj does not implement #AtspiComponent.
853 atspi_accessible_get_component (AtspiAccessible *obj)
855 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
856 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
860 * atspi_accessible_get_document:
861 * @obj: a pointer to the #AtspiAccessible instance to query.
863 * Get the #AtspiDocument interface for an #AtspiAccessible.
865 * Returns: (transfer full): a pointer to an #AtspiDocument interface
866 * instance, or NULL if @obj does not implement #AtspiDocument.
869 atspi_accessible_get_document (AtspiAccessible *accessible)
871 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
872 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
876 * atspi_accessible_get_editable_text:
877 * @obj: a pointer to the #AtspiAccessible instance to query.
879 * Get the #AtspiEditableText interface for an #AtspiAccessible.
881 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
882 * instance, or NULL if @obj does not implement #AtspiEditableText.
885 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
887 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
888 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
892 * atspi_accessible_get_hypertext:
893 * @obj: a pointer to the #AtspiAccessible instance to query.
895 * Get the #AtspiHypertext interface for an #AtspiAccessible.
897 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
898 * instance, or NULL if @obj does not implement #AtspiHypertext.
901 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
903 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
904 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
908 * atspi_accessible_get_image:
909 * @obj: a pointer to the #AtspiAccessible instance to query.
911 * Get the #AtspiImage interface for an #AtspiAccessible.
913 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
914 * NULL if @obj does not implement #AtspiImage.
917 atspi_accessible_get_image (AtspiAccessible *accessible)
919 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
920 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
924 * atspi_accessible_get_selection:
925 * @obj: a pointer to the #AtspiAccessible instance to query.
927 * Get the #AtspiSelection interface for an #AtspiAccessible.
929 * Returns: (transfer full): a pointer to an #AtspiSelection interface
930 * instance, or NULL if @obj does not implement #AtspiSelection.
933 atspi_accessible_get_selection (AtspiAccessible *accessible)
935 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
936 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
941 * atspi_accessible_get_streamable_content:
942 * @obj: a pointer to the #AtspiAccessible instance to query.
944 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
946 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
947 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
949 AtspiStreamableContent *
950 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
952 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
958 * atspi_accessible_get_table:
959 * @obj: a pointer to the #AtspiAccessible instance to query.
961 * Get the #AtspiTable interface for an #AtspiAccessible.
963 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
964 * NULL if @obj does not implement #AtspiTable.
967 atspi_accessible_get_table (AtspiAccessible *obj)
969 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
970 g_object_ref (ATSPI_TABLE (obj)) : NULL);
974 * atspi_accessible_get_text:
975 * @obj: a pointer to the #AtspiAccessible instance to query.
977 * Get the #AtspiTable interface for an #AtspiAccessible.
979 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
980 * NULL if @obj does not implement #AtspiTable.
983 atspi_accessible_get_text (AtspiAccessible *obj)
985 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
986 g_object_ref (ATSPI_TEXT (obj)) : NULL);
990 * atspi_accessible_get_value:
991 * @obj: a pointer to the #AtspiAccessible instance to query.
993 * Get the #AtspiTable interface for an #AtspiAccessible.
995 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
996 * NULL if @obj does not implement #AtspiValue.
999 atspi_accessible_get_value (AtspiAccessible *accessible)
1001 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1002 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1007 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
1010 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
1012 relation_type_table [i] = SPI_RELATION_NULL;
1014 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
1015 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
1016 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
1017 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
1018 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
1019 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
1020 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
1021 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
1022 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
1023 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
1024 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
1025 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
1026 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
1027 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
1028 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
1029 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
1030 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
1031 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
1035 static AccessibleRelationType
1036 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
1038 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
1039 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
1040 static gboolean is_initialized = FALSE;
1041 AccessibleRelationType cspi_type;
1042 if (!is_initialized)
1044 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
1046 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
1048 cspi_type = cspi_relation_type_table [type];
1052 cspi_type = SPI_RELATION_NULL;
1057 * AccessibleRelation_getRelationType:
1058 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1060 * Get the type of relationship represented by an #AtspiAccessibleRelation.
1062 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
1063 * encapsulated in this #AtspiAccessibleRelation object.
1066 AccessibleRelationType
1067 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1069 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1070 return cspi_relation_type_from_spi_relation_type (obj->type);
1074 * AccessibleRelation_getNTargets:
1075 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1077 * Get the number of objects which this relationship has as its
1078 * target objects (the subject is the #AtspiAccessible from which this
1079 * #AtspiAccessibleRelation originated).
1081 * Returns: a short integer indicating how many target objects which the
1082 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
1083 * relationship with.
1086 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1088 cspi_return_val_if_fail (obj, -1);
1089 return obj->targets->len;
1093 * AccessibleRelation_getTarget:
1094 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1095 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1097 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
1099 * Returns: an #AtspiAccessible which is the @i-th object with which the
1100 * originating #AtspiAccessible has relationship specified in the
1101 * #AtspiAccessibleRelation object.
1105 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1107 cspi_return_val_if_fail (obj, NULL);
1109 if (i < 0 || i >= obj->targets->len) return NULL;
1110 return cspi_object_add (
1111 g_array_index (obj->targets, Accessible *, i));
1115 * AccessibleStateSet_ref:
1116 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1118 * Increment the reference count for an #AtspiAccessibleStateSet object.
1122 AccessibleStateSet_ref (AccessibleStateSet *obj)
1124 spi_state_set_cache_ref (obj);
1128 * AccessibleStateSet_unref:
1129 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1131 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1135 AccessibleStateSet_unref (AccessibleStateSet *obj)
1137 spi_state_set_cache_unref (obj);
1140 static Accessibility_StateType
1141 spi_state_to_dbus (AccessibleState state)
1143 #define MAP_STATE(a) \
1144 case SPI_STATE_##a: \
1145 return Accessibility_STATE_##a
1149 MAP_STATE (INVALID);
1153 MAP_STATE (CHECKED);
1154 MAP_STATE (DEFUNCT);
1155 MAP_STATE (EDITABLE);
1156 MAP_STATE (ENABLED);
1157 MAP_STATE (EXPANDABLE);
1158 MAP_STATE (EXPANDED);
1159 MAP_STATE (FOCUSABLE);
1160 MAP_STATE (FOCUSED);
1161 MAP_STATE (HORIZONTAL);
1162 MAP_STATE (ICONIFIED);
1164 MAP_STATE (MULTI_LINE);
1165 MAP_STATE (MULTISELECTABLE);
1167 MAP_STATE (PRESSED);
1168 MAP_STATE (RESIZABLE);
1169 MAP_STATE (SELECTABLE);
1170 MAP_STATE (SELECTED);
1171 MAP_STATE (SENSITIVE);
1172 MAP_STATE (SHOWING);
1173 MAP_STATE (SINGLE_LINE);
1175 MAP_STATE (TRANSIENT);
1176 MAP_STATE (VERTICAL);
1177 MAP_STATE (VISIBLE);
1178 MAP_STATE (MANAGES_DESCENDANTS);
1179 MAP_STATE (INDETERMINATE);
1180 MAP_STATE (TRUNCATED);
1181 MAP_STATE (REQUIRED);
1182 MAP_STATE (INVALID_ENTRY);
1183 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1184 MAP_STATE (SELECTABLE_TEXT);
1185 MAP_STATE (IS_DEFAULT);
1186 MAP_STATE (VISITED);
1188 return Accessibility_STATE_INVALID;
1194 * AccessibleStateSet_contains:
1195 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1196 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1199 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1200 * whether @state is true for the stateset in question.
1202 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1207 AccessibleStateSet_contains (AccessibleStateSet *obj,
1208 AccessibleState state)
1210 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1214 * AccessibleStateSet_add:
1215 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1216 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1218 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1219 * given state to #TRUE in the stateset.
1223 AccessibleStateSet_add (AccessibleStateSet *obj,
1224 AccessibleState state)
1226 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1230 * AccessibleStateSet_remove:
1231 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1232 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1234 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1235 * given state to #FALSE in the stateset.)
1239 AccessibleStateSet_remove (AccessibleStateSet *obj,
1240 AccessibleState state)
1242 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1246 * AccessibleStateSet_equals:
1247 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1248 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1250 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1251 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1252 * state variables at once; construct the target state then compare against it.
1254 * @see AccessibleStateSet_compare().
1256 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1261 AccessibleStateSet_equals (AccessibleStateSet *obj,
1262 AccessibleStateSet *obj2)
1272 cmp = spi_state_set_cache_xor (obj, obj2);
1273 eq = spi_state_set_cache_is_empty (cmp);
1274 spi_state_set_cache_unref (cmp);
1280 * AccessibleStateSet_compare:
1281 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1282 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1284 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1285 * Not Yet Implemented.
1287 * @see AccessibleStateSet_equals().
1289 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1290 * the two sets but not the other.
1293 AccessibleStateSet *
1294 AccessibleStateSet_compare (AccessibleStateSet *obj,
1295 AccessibleStateSet *obj2)
1297 return spi_state_set_cache_xor (obj, obj2);
1301 * AccessibleStateSet_isEmpty:
1302 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1304 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1306 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1311 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1313 return spi_state_set_cache_is_empty (obj);
1318 _atspi_accessible_is_a (AtspiAccessible *accessible,
1319 const char *interface_name)
1323 if (accessible == NULL)
1328 n = _atspi_get_iface_num (interface_name);
1329 if (n == -1) return FALSE;
1330 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1333 /* TODO: Move to a finalizer */
1335 cspi_object_destroyed (AtspiAccessible *accessible)
1340 /* TODO: Only fire if object not already marked defunct */
1341 memset (&e, 0, sizeof (e));
1342 e.type = "object:state-change:defunct";
1343 e.source = accessible;
1346 _atspi_send_event (&e);
1348 g_free (accessible->parent.path);
1350 if (accessible->states)
1351 g_object_unref (accessible->states);
1352 g_free (accessible->description);
1353 g_free (accessible->name);
1357 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1359 AtspiAccessible *accessible;
1361 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1362 g_return_val_if_fail (accessible != NULL, NULL);
1364 accessible->parent.app = g_object_ref (app);
1365 accessible->parent.path = g_strdup (path);