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_image_interface_init (AtspiImage *image)
52 atspi_selection_interface_init (AtspiSelection *selection)
57 atspi_table_interface_init (AtspiTable *table)
62 atspi_text_interface_init (AtspiText *text)
67 atspi_value_interface_init (AtspiValue *value)
71 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT,
72 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init)
73 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COLLECTION, atspi_collection_interface_init)
74 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
75 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init)
76 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init)
77 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init)
78 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
79 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init)
80 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_VALUE, atspi_value_interface_init))
83 atspi_accessible_init (AtspiAccessible *accessible)
88 atspi_accessible_finalize (GObject *obj)
90 /*AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj); */
92 /* TODO: Unref parent/children, etc. */
96 atspi_accessible_class_init (AtspiAccessibleClass *klass)
98 GObjectClass *object_class = G_OBJECT_CLASS (klass);
100 object_class->finalize = atspi_accessible_finalize;
103 /* TODO: Generate following from spec? */
104 static const char *role_names [] =
162 "table-column-header",
164 "tear-off-menu-item",
194 "input method window"
197 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
200 * atspi_role_get_name
201 * @role: an #AtspiAccessibleRole object to query.
203 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
204 * <em>DEPRECATED.</em>
206 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
209 atspi_role_get_name (AtspiRole role)
211 if (role < MAX_ROLES && role_names [(int) role])
213 return g_strdup (role_names [(int) role]);
217 return g_strdup ("");
222 * atspi_accessible_get_name:
223 * @obj: a pointer to the #AtspiAccessible object on which to operate.
225 * Get the name of an #AtspiAccessible object.
227 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
228 * or NULL on exception
231 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
233 g_return_val_if_fail (obj != NULL, NULL);
234 if (!(obj->cached_properties & ATSPI_CACHE_NAME))
236 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", NULL, "s", &obj->name))
238 obj->cached_properties |= ATSPI_CACHE_NAME;
240 return g_strdup (obj->name);
244 * atspi_accessible_get_description:
245 * @obj: a pointer to the #AtspiAccessible object on which to operate.
247 * Get the description of an #AtspiAccessible object.
249 * Returns: a UTF-8 string describing the #AtspiAccessible object.
250 * or NULL on exception
253 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
255 g_return_val_if_fail (obj != NULL, NULL);
257 if (!(obj->cached_properties & ATSPI_CACHE_DESCRIPTION))
259 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetDescription", NULL, "=>s", &obj->description))
261 obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
263 return g_strdup (obj->description);
266 const char *str_parent = "Parent";
269 * atspi_accessible_get_parent:
270 * @obj: a pointer to the #AtspiAccessible object to query.
272 * Get an #AtspiAccessible object's parent container.
274 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
275 * contains the given #AtspiAccessible instance, or NULL if the @obj
276 * has no parent container.
280 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
282 g_return_val_if_fail (obj != NULL, NULL);
284 if (!(obj->cached_properties & ATSPI_CACHE_PARENT))
286 DBusMessage *message, *reply;
287 DBusMessageIter iter, iter_variant;
288 message = dbus_message_new_method_call (obj->parent.app->bus_name,
290 DBUS_INTERFACE_PROPERTIES, "Get");
293 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
294 DBUS_TYPE_STRING, &str_parent,
296 reply = _atspi_dbus_send_with_reply_and_block (message);
298 (strcmp (dbus_message_get_signature (reply), "v") != 0))
300 dbus_message_iter_init (reply, &iter);
301 dbus_message_iter_recurse (&iter, &iter_variant);
302 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
303 dbus_message_unref (reply);
304 obj->cached_properties |= ATSPI_CACHE_PARENT;
306 if (!obj->accessible_parent)
308 return g_object_ref (obj->accessible_parent);
312 * atspi_accessible_get_child_count:
313 * @obj: a pointer to the #AtspiAccessible object on which to operate.
315 * Get the number of children contained by an #AtspiAccessible object.
317 * Returns: a #long indicating the number of #AtspiAccessible children
318 * contained by an #AtspiAccessible object. or -1 on exception
322 atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error)
324 g_return_val_if_fail (obj != NULL, -1);
326 /* TODO: MANAGES_DESCENDANTS */
327 return g_list_length (obj->children);
331 * atspi_accessible_get_child_at_index:
332 * @obj: a pointer to the #AtspiAccessible object on which to operate.
333 * @child_index: a #long indicating which child is specified.
335 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
337 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
338 * index @child_index. or NULL on exception
341 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
345 AtspiAccessible *child;
347 g_return_val_if_fail (obj != NULL, NULL);
349 /* TODO: ManagesDescendants */
350 child = g_list_nth_data (obj->children, child_index);
353 return g_object_ref (child);
357 * atspi_accessible_get_index_in_parent
358 * @obj: a pointer to the #AtspiAccessible object on which to operate.
360 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
362 * Returns: a #glong indicating the index of the #AtspiAccessible object
363 * in its parent (i.e. containing) #AtspiAccessible instance,
364 * or -1 if @obj has no containing parent or on exception.
367 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
372 g_return_val_if_fail (obj != NULL, -1);
373 if (!obj->accessible_parent) return -1;
374 l = obj->accessible_parent->children;
377 if (l->data == obj) return i;
388 } Accessibility_Relation;
391 * atspi_accessible_get_relation_set:
392 * @obj: a pointer to the #AtspiAccessible object on which to operate.
394 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
395 * relationships with other #AtspiAccessible objects.
397 * Returns: (element-type AtspiAccessible*) (transfer full): an array of
398 * #AtspiAccessibleRelation pointers. or NULL on exception
401 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
404 DBusMessageIter iter, iter_array;
407 g_return_val_if_fail (obj != NULL, NULL);
409 reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
410 _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", NULL);
412 ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
413 dbus_message_iter_init (reply, &iter);
414 dbus_message_iter_recurse (&iter, &iter_array);
415 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
418 AtspiRelation *relation;
419 relation = _atspi_relation_new_from_iter (&iter_array);
420 new_array = g_array_append_val (ret, relation);
423 dbus_message_iter_next (&iter_array);
429 * atspi_accessible_get_role:
430 * @obj: a pointer to the #AtspiAccessible object on which to operate.
432 * Get the UI role of an #AtspiAccessible object.
433 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
435 * Returns: the #AtspiRole of the object.
439 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
441 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
443 if (!(obj->cached_properties & ATSPI_CACHE_ROLE))
446 /* TODO: Make this a property */
447 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
449 obj->cached_properties |= ATSPI_CACHE_ROLE;
457 * atspi_accessible_get_role_name:
458 * @obj: a pointer to the #AtspiAccessible object on which to operate.
460 * Get a UTF-8 string describing the role this object plays in the UI.
461 * This method will return useful values for roles that fall outside the
462 * enumeration used in atspi_accessible_getRole ().
464 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
468 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
472 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
474 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
480 * atspi_accessible_get_localized_role_name:
481 * @obj: a pointer to the #AtspiAccessible object on which to operate.
483 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
484 * This method will return useful values for roles that fall outside the
485 * enumeration used in atspi_accessible_getRole ().
487 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
491 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
495 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
497 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
503 * atspi_accessible_get_state_set:
504 * @obj: a pointer to the #AtspiAccessible object on which to operate.
506 * Gets the current state of an object.
508 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
509 * object's current state.
512 atspi_accessible_get_state_set (AtspiAccessible *obj)
518 * atspi_accessible_get_attributes:
519 * @obj: The #AtspiAccessible being queried.
521 * Get the #AttributeSet representing any assigned
522 * name-value pair attributes or annotations for this object.
523 * For typographic, textual, or textually-semantic attributes, see
524 * atspi_text_get_attributes instead.
526 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
527 * attributes assigned to this object.
530 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
532 DBusMessage *message;
535 g_return_val_if_fail (obj != NULL, NULL);
537 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
538 ret = _atspi_dbus_hash_from_message (message);
539 dbus_message_unref (message);
544 * atspi_accessible_get_attributes_as_array:
545 * @obj: The #AtspiAccessible being queried.
547 * Get the #AttributeSet representing any assigned
548 * name-value pair attributes or annotations for this object.
549 * For typographic, textual, or textually-semantic attributes, see
550 * atspi_text_get_attributes_as_array instead.
552 * Returns: (element-type gchar*) (transfer full): The name-value-pair
553 * attributes assigned to this object.
556 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
558 DBusMessage *message;
561 g_return_val_if_fail (obj != NULL, NULL);
563 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
564 ret = _atspi_dbus_attribute_array_from_message (message);
565 dbus_message_unref (message);
570 * atspi_accessible_get_host_application:
571 * @obj: The #AtspiAccessible being queried.
573 * Get the containing #AtspiApplication for an object.
575 * Returns: (transfer full): the containing AtspiApplication instance for
579 atspi_accessible_get_host_application (AtspiAccessible *obj, GError **error)
581 AtspiAccessible *parent;
585 parent = atspi_accessible_get_parent (obj, NULL);
586 if (!parent || parent == obj ||
587 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
593 /* Interface query methods */
596 * atspi_accessible_is_action:
597 * @obj: a pointer to the #AtspiAccessible instance to query.
599 * Query whether the specified #AtspiAccessible implements #AtspiAction.
601 * Returns: #TRUE if @obj implements the #AtspiAction interface,
605 atspi_accessible_is_action (AtspiAccessible *obj)
607 return _atspi_accessible_is_a (obj,
608 atspi_interface_action);
612 * atspi_accessible_is_application:
613 * @obj: a pointer to the #AtspiAccessible instance to query.
615 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
617 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
621 atspi_accessible_is_application (AtspiAccessible *obj)
623 return _atspi_accessible_is_a (obj,
624 atspi_interface_application);
628 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
630 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
631 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
635 atspi_accessible_is_collection (AtspiAccessible *obj)
638 g_warning ("Collections not implemented");
639 return _atspi_accessible_is_a (obj,
640 atspi_interface_collection);
647 * atspi_accessible_is_component:
648 * @obj: a pointer to the #AtspiAccessible instance to query.
650 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
652 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
656 atspi_accessible_is_component (AtspiAccessible *obj)
658 return _atspi_accessible_is_a (obj,
659 atspi_interface_component);
663 * atspi_accessible_is_document:
664 * @obj: a pointer to the #AtspiAccessible instance to query.
666 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
668 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
672 atspi_accessible_is_document (AtspiAccessible *obj)
674 return _atspi_accessible_is_a (obj,
675 atspi_interface_document);
679 * atspi_accessible_is_editable_text:
680 * @obj: a pointer to the #AtspiAccessible instance to query.
682 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
684 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
688 atspi_accessible_is_editable_text (AtspiAccessible *obj)
690 return _atspi_accessible_is_a (obj,
691 atspi_interface_editable_text);
695 * atspi_accessible_is_hypertext:
696 * @obj: a pointer to the #AtspiAccessible instance to query.
698 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
700 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
704 atspi_accessible_is_hypertext (AtspiAccessible *obj)
706 return _atspi_accessible_is_a (obj,
707 atspi_interface_hypertext);
711 * atspi_accessible_is_image:
712 * @obj: a pointer to the #AtspiAccessible instance to query.
714 * Query whether the specified #AtspiAccessible implements #AtspiImage.
716 * Returns: #TRUE if @obj implements the #AtspiImage interface,
720 atspi_accessible_is_image (AtspiAccessible *obj)
722 return _atspi_accessible_is_a (obj,
723 atspi_interface_image);
727 * atspi_accessible_is_selection:
728 * @obj: a pointer to the #AtspiAccessible instance to query.
730 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
732 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
736 atspi_accessible_is_selection (AtspiAccessible *obj)
738 return _atspi_accessible_is_a (obj,
739 atspi_interface_selection);
743 * atspi_accessible_is_table:
744 * @obj: a pointer to the #AtspiAccessible instance to query.
746 * Query whether the specified #AtspiAccessible implements #AtspiTable.
748 * Returns: #TRUE if @obj implements the #AtspiTable interface,
752 atspi_accessible_is_table (AtspiAccessible *obj)
754 return _atspi_accessible_is_a (obj,
755 atspi_interface_table);
759 * atspi_accessible_is_streamable_content:
760 * @obj: a pointer to the #AtspiAccessible instance to query.
762 * Query whether the specified #AtspiAccessible implements
763 * #AtspiStreamableContent.
765 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
769 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
772 return _atspi_accessible_is_a (obj,
773 atspi_interface_streamable_content);
775 g_warning ("Streamable content not implemented");
781 * atspi_accessible_is_text:
782 * @obj: a pointer to the #AtspiAccessible instance to query.
784 * Query whether the specified #AtspiAccessible implements #AtspiText.
786 * Returns: #TRUE if @obj implements the #AtspiText interface,
790 atspi_accessible_is_text (AtspiAccessible *obj)
792 return _atspi_accessible_is_a (obj,
793 atspi_interface_text);
797 * atspi_accessible_is_value:
798 * @obj: a pointer to the #AtspiAccessible instance to query.
800 * Query whether the specified #AtspiAccessible implements #AtspiValue.
802 * Returns: #TRUE if @obj implements the #AtspiValue interface,
806 atspi_accessible_is_value (AtspiAccessible *obj)
808 return _atspi_accessible_is_a (obj,
809 atspi_interface_value);
813 * atspi_accessible_get_application:
814 * @obj: a pointer to the #AtspiAccessible instance to query.
816 * Get the #AtspiApplication interface for an #AtspiAccessible.
818 * Returns: a pointer to an #AtspiApplication interface instance, or
819 * NULL if @obj does not implement #AtspiApplication.
822 atspi_accessible_get_application (AtspiAccessible *accessible)
824 return (_atspi_accessible_is_a (accessible, atspi_interface_application) ?
825 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
829 * atspi_accessible_get_action:
830 * @obj: a pointer to the #AtspiAccessible instance to query.
832 * Get the #AtspiAction interface for an #AtspiAccessible.
834 * Returns: (transfer full): a pointer to an #AtspiAction interface
835 * instance, or NULL if @obj does not implement #AtspiAction.
838 atspi_accessible_get_action (AtspiAccessible *accessible)
840 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
841 g_object_ref (ATSPI_ACTION (accessible)) : NULL);
845 * atspi_accessible_get_collection:
846 * @obj: a pointer to the #AtspiAccessible instance to query.
848 * Get the #AtspiCollection interface for an #AtspiAccessible.
850 * Returns: (transfer full): a pointer to an #AtspiCollection interface
851 * instance, or NULL if @obj does not implement #AtspiCollection.
854 atspi_accessible_get_collection (AtspiAccessible *accessible)
856 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
857 g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);
861 * atspi_accessible_get_component:
862 * @obj: a pointer to the #AtspiAccessible instance to query.
864 * Get the #AtspiComponent interface for an #AtspiAccessible.
866 * Returns: (transfer full): a pointer to an #AtspiComponent interface
867 * instance, or NULL if @obj does not implement #AtspiComponent.
870 atspi_accessible_get_component (AtspiAccessible *obj)
872 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
873 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
877 * atspi_accessible_get_document:
878 * @obj: a pointer to the #AtspiAccessible instance to query.
880 * Get the #AtspiDocument interface for an #AtspiAccessible.
882 * Returns: (transfer full): a pointer to an #AtspiDocument interface
883 * instance, or NULL if @obj does not implement #AtspiDocument.
886 atspi_accessible_get_document (AtspiAccessible *accessible)
888 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
889 g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);
893 * atspi_accessible_get_editable_text:
894 * @obj: a pointer to the #AtspiAccessible instance to query.
896 * Get the #AtspiEditableText interface for an #AtspiAccessible.
898 * Returns: (transfer full): a pointer to an #AtspiEditableText interface
899 * instance, or NULL if @obj does not implement #AtspiEditableText.
902 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
904 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
905 g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);
909 * atspi_accessible_get_hypertext:
910 * @obj: a pointer to the #AtspiAccessible instance to query.
912 * Get the #AtspiHypertext interface for an #AtspiAccessible.
914 * Returns: (transfer full): a pointer to an #AtspiHypertext interface
915 * instance, or NULL if @obj does not implement #AtspiHypertext.
918 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
920 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
921 g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);
925 * atspi_accessible_get_image:
926 * @obj: a pointer to the #AtspiAccessible instance to query.
928 * Get the #AtspiImage interface for an #AtspiAccessible.
930 * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
931 * NULL if @obj does not implement #AtspiImage.
934 atspi_accessible_get_image (AtspiAccessible *accessible)
936 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
937 g_object_ref (ATSPI_IMAGE (accessible)) : NULL);
941 * atspi_accessible_get_selection:
942 * @obj: a pointer to the #AtspiAccessible instance to query.
944 * Get the #AtspiSelection interface for an #AtspiAccessible.
946 * Returns: (transfer full): a pointer to an #AtspiSelection interface
947 * instance, or NULL if @obj does not implement #AtspiSelection.
950 atspi_accessible_get_selection (AtspiAccessible *accessible)
952 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
953 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
958 * atspi_accessible_get_streamable_content:
959 * @obj: a pointer to the #AtspiAccessible instance to query.
961 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
963 * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
964 * instance, or NULL if @obj does not implement #AtspiStreamableContent.
966 AtspiStreamableContent *
967 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
969 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
975 * atspi_accessible_get_table:
976 * @obj: a pointer to the #AtspiAccessible instance to query.
978 * Get the #AtspiTable interface for an #AtspiAccessible.
980 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
981 * NULL if @obj does not implement #AtspiTable.
984 atspi_accessible_get_table (AtspiAccessible *obj)
986 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
987 g_object_ref (ATSPI_TABLE (obj)) : NULL);
991 * atspi_accessible_get_text:
992 * @obj: a pointer to the #AtspiAccessible instance to query.
994 * Get the #AtspiTable interface for an #AtspiAccessible.
996 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
997 * NULL if @obj does not implement #AtspiTable.
1000 atspi_accessible_get_text (AtspiAccessible *obj)
1002 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1003 g_object_ref (ATSPI_TEXT (obj)) : NULL);
1007 * atspi_accessible_get_value:
1008 * @obj: a pointer to the #AtspiAccessible instance to query.
1010 * Get the #AtspiTable interface for an #AtspiAccessible.
1012 * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1013 * NULL if @obj does not implement #AtspiValue.
1016 atspi_accessible_get_value (AtspiAccessible *accessible)
1018 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1019 g_object_ref (ATSPI_VALUE (accessible)) : NULL);
1024 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
1027 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
1029 relation_type_table [i] = SPI_RELATION_NULL;
1031 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
1032 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
1033 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
1034 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
1035 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
1036 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
1037 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
1038 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
1039 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
1040 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
1041 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
1042 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
1043 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
1044 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
1045 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
1046 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
1047 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
1048 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
1052 static AccessibleRelationType
1053 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
1055 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
1056 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
1057 static gboolean is_initialized = FALSE;
1058 AccessibleRelationType cspi_type;
1059 if (!is_initialized)
1061 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
1063 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
1065 cspi_type = cspi_relation_type_table [type];
1069 cspi_type = SPI_RELATION_NULL;
1074 * AccessibleRelation_getRelationType:
1075 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1077 * Get the type of relationship represented by an #AtspiAccessibleRelation.
1079 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
1080 * encapsulated in this #AtspiAccessibleRelation object.
1083 AccessibleRelationType
1084 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1086 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1087 return cspi_relation_type_from_spi_relation_type (obj->type);
1091 * AccessibleRelation_getNTargets:
1092 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1094 * Get the number of objects which this relationship has as its
1095 * target objects (the subject is the #AtspiAccessible from which this
1096 * #AtspiAccessibleRelation originated).
1098 * Returns: a short integer indicating how many target objects which the
1099 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
1100 * relationship with.
1103 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1105 cspi_return_val_if_fail (obj, -1);
1106 return obj->targets->len;
1110 * AccessibleRelation_getTarget:
1111 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1112 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1114 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
1116 * Returns: an #AtspiAccessible which is the @i-th object with which the
1117 * originating #AtspiAccessible has relationship specified in the
1118 * #AtspiAccessibleRelation object.
1122 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1124 cspi_return_val_if_fail (obj, NULL);
1126 if (i < 0 || i >= obj->targets->len) return NULL;
1127 return cspi_object_add (
1128 g_array_index (obj->targets, Accessible *, i));
1132 * AccessibleStateSet_ref:
1133 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1135 * Increment the reference count for an #AtspiAccessibleStateSet object.
1139 AccessibleStateSet_ref (AccessibleStateSet *obj)
1141 spi_state_set_cache_ref (obj);
1145 * AccessibleStateSet_unref:
1146 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1148 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1152 AccessibleStateSet_unref (AccessibleStateSet *obj)
1154 spi_state_set_cache_unref (obj);
1157 static Accessibility_StateType
1158 spi_state_to_dbus (AccessibleState state)
1160 #define MAP_STATE(a) \
1161 case SPI_STATE_##a: \
1162 return Accessibility_STATE_##a
1166 MAP_STATE (INVALID);
1170 MAP_STATE (CHECKED);
1171 MAP_STATE (DEFUNCT);
1172 MAP_STATE (EDITABLE);
1173 MAP_STATE (ENABLED);
1174 MAP_STATE (EXPANDABLE);
1175 MAP_STATE (EXPANDED);
1176 MAP_STATE (FOCUSABLE);
1177 MAP_STATE (FOCUSED);
1178 MAP_STATE (HORIZONTAL);
1179 MAP_STATE (ICONIFIED);
1181 MAP_STATE (MULTI_LINE);
1182 MAP_STATE (MULTISELECTABLE);
1184 MAP_STATE (PRESSED);
1185 MAP_STATE (RESIZABLE);
1186 MAP_STATE (SELECTABLE);
1187 MAP_STATE (SELECTED);
1188 MAP_STATE (SENSITIVE);
1189 MAP_STATE (SHOWING);
1190 MAP_STATE (SINGLE_LINE);
1192 MAP_STATE (TRANSIENT);
1193 MAP_STATE (VERTICAL);
1194 MAP_STATE (VISIBLE);
1195 MAP_STATE (MANAGES_DESCENDANTS);
1196 MAP_STATE (INDETERMINATE);
1197 MAP_STATE (TRUNCATED);
1198 MAP_STATE (REQUIRED);
1199 MAP_STATE (INVALID_ENTRY);
1200 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1201 MAP_STATE (SELECTABLE_TEXT);
1202 MAP_STATE (IS_DEFAULT);
1203 MAP_STATE (VISITED);
1205 return Accessibility_STATE_INVALID;
1211 * AccessibleStateSet_contains:
1212 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1213 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1216 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1217 * whether @state is true for the stateset in question.
1219 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1224 AccessibleStateSet_contains (AccessibleStateSet *obj,
1225 AccessibleState state)
1227 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1231 * AccessibleStateSet_add:
1232 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1233 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1235 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1236 * given state to #TRUE in the stateset.
1240 AccessibleStateSet_add (AccessibleStateSet *obj,
1241 AccessibleState state)
1243 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1247 * AccessibleStateSet_remove:
1248 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1249 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1251 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1252 * given state to #FALSE in the stateset.)
1256 AccessibleStateSet_remove (AccessibleStateSet *obj,
1257 AccessibleState state)
1259 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1263 * AccessibleStateSet_equals:
1264 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1265 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1267 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1268 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1269 * state variables at once; construct the target state then compare against it.
1271 * @see AccessibleStateSet_compare().
1273 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1278 AccessibleStateSet_equals (AccessibleStateSet *obj,
1279 AccessibleStateSet *obj2)
1289 cmp = spi_state_set_cache_xor (obj, obj2);
1290 eq = spi_state_set_cache_is_empty (cmp);
1291 spi_state_set_cache_unref (cmp);
1297 * AccessibleStateSet_compare:
1298 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1299 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1301 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1302 * Not Yet Implemented.
1304 * @see AccessibleStateSet_equals().
1306 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1307 * the two sets but not the other.
1310 AccessibleStateSet *
1311 AccessibleStateSet_compare (AccessibleStateSet *obj,
1312 AccessibleStateSet *obj2)
1314 return spi_state_set_cache_xor (obj, obj2);
1318 * AccessibleStateSet_isEmpty:
1319 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1321 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1323 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1328 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1330 return spi_state_set_cache_is_empty (obj);
1335 _atspi_accessible_is_a (AtspiAccessible *accessible,
1336 const char *interface_name)
1340 if (accessible == NULL)
1345 n = _atspi_get_iface_num (interface_name);
1346 if (n == -1) return FALSE;
1347 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1350 /* TODO: Move to a finalizer */
1352 cspi_object_destroyed (AtspiAccessible *accessible)
1357 /* TODO: Only fire if object not already marked defunct */
1358 memset (&e, 0, sizeof (e));
1359 e.type = "object:state-change:defunct";
1360 e.source = accessible;
1363 _atspi_send_event (&e);
1365 g_free (accessible->parent.path);
1367 if (accessible->states)
1368 g_object_unref (accessible->states);
1369 g_free (accessible->description);
1370 g_free (accessible->name);
1374 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1376 AtspiAccessible *accessible;
1378 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1379 g_return_val_if_fail (accessible != NULL, NULL);
1381 accessible->parent.app = g_object_ref (app);
1382 accessible->parent.path = g_strdup (path);