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"
26 G_DEFINE_TYPE (AtspiAccessible, atspi_accessible, G_TYPE_OBJECT)
29 atspi_accessible_init (AtspiAccessible *accessible)
34 atspi_accessible_finalize (GObject *obj)
36 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj);
39 g_object_unref (accessible->app);
41 g_free (accessible->path);
45 atspi_accessible_class_init (AtspiAccessibleClass *klass)
47 GObjectClass *object_class = G_OBJECT_CLASS (klass);
49 object_class->finalize = atspi_accessible_finalize;
51 /* TODO: Generate following from spec? */
52 static const char *role_names [] =
110 "table-column-header",
112 "tear-off-menu-item",
142 "input method window"
145 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
148 * atspi_role_get_name
149 * @role: an #AtspiAccessibleRole object to query.
151 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
152 * <em>DEPRECATED.</em>
154 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
157 atspi_role_get_name (AtspiRole role)
159 if (role < MAX_ROLES && role_names [(int) role])
161 return g_strdup (role_names [(int) role]);
165 return g_strdup ("");
170 * atspi_accessible_get_name:
171 * @obj: a pointer to the #AtspiAccessible object on which to operate.
173 * Get the name of an #AtspiAccessible object.
175 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
176 * or NULL on exception
179 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
181 g_return_val_if_fail (obj != NULL, NULL);
182 if (!obj->cached_properties & ATSPI_CACHE_NAME)
184 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetName", NULL, "=>s", &obj->name))
186 obj->cached_properties |= ATSPI_CACHE_NAME;
188 return g_strdup (obj->name);
192 * atspi_accessible_get_description:
193 * @obj: a pointer to the #AtspiAccessible object on which to operate.
195 * Get the description of an #AtspiAccessible object.
197 * Returns: a UTF-8 string describing the #AtspiAccessible object.
198 * or NULL on exception
201 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
203 g_return_val_if_fail (obj != NULL, NULL);
205 if (!obj->cached_properties & ATSPI_CACHE_DESCRIPTION)
207 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetDescription", NULL, "=>s", &obj->description))
209 obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
211 return g_strdup (obj->description);
215 * atspi_accessible_get_parent:
216 * @obj: a pointer to the #AtspiAccessible object to query.
218 * Get an #AtspiAccessible object's parent container.
220 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
221 * contains the given #AtspiAccessible instance, or NULL if the @obj
222 * has no parent container.
226 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
228 g_return_val_if_fail (obj != NULL, NULL);
230 return g_object_ref (obj->accessible_parent);
234 * atspi_accessible_get_child_count:
235 * @obj: a pointer to the #AtspiAccessible object on which to operate.
237 * Get the number of children contained by an #AtspiAccessible object.
239 * Returns: a #long indicating the number of #AtspiAccessible children
240 * contained by an #AtspiAccessible object. or -1 on exception
244 atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error)
246 g_return_val_if_fail (obj != NULL, -1);
248 /* TODO: MANAGES_DESCENDANTS */
249 return g_list_length (obj->children);
253 * atspi_accessible_get_child_at_index:
254 * @obj: a pointer to the #AtspiAccessible object on which to operate.
255 * @child_index: a #long indicating which child is specified.
257 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
259 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
260 * index @child_index. or NULL on exception
263 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
267 AtspiAccessible *child;
269 g_return_val_if_fail (obj != NULL, NULL);
271 /* TODO: ManagesDescendants */
272 child = g_list_nth_data (obj->children, child_index);
275 return g_object_ref (child);
279 * atspi_accessible_get_index_in_parent
280 * @obj: a pointer to the #AtspiAccessible object on which to operate.
282 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
284 * Returns: a #glong indicating the index of the #AtspiAccessible object
285 * in its parent (i.e. containing) #AtspiAccessible instance,
286 * or -1 if @obj has no containing parent or on exception.
289 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
294 g_return_val_if_fail (obj != NULL, -1);
295 if (!obj->accessible_parent) return -1;
296 l = obj->accessible_parent->children;
299 if (l->data == obj) return i;
310 } Accessibility_Relation;
313 * atspi_accessible_get_relation_set:
314 * @obj: a pointer to the #AtspiAccessible object on which to operate.
316 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
317 * relationships with other #AtspiAccessible objects.
319 * Returns: an array of #AtspiAccessibleRelation pointers. or NULL on exception
320 * TODO:: Annotate array type
323 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
327 GArray *relation_set;
329 g_return_val_if_fail (obj != NULL, NULL);
331 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetRelationSet", error, "=>a(uao)", &relation_set))
338 * atspi_accessible_get_role:
339 * @obj: a pointer to the #AtspiAccessible object on which to operate.
341 * Get the UI role of an #AtspiAccessible object.
342 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
344 * Returns: the #AtspiRole of the object.
348 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
350 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
352 if (!obj->cached_properties & ATSPI_CACHE_ROLE)
355 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
357 obj->cached_properties |= ATSPI_CACHE_ROLE;
365 * atspi_accessible_get_role_name:
366 * @obj: a pointer to the #AtspiAccessible object on which to operate.
368 * Get a UTF-8 string describing the role this object plays in the UI.
369 * This method will return useful values for roles that fall outside the
370 * enumeration used in atspi_accessible_getRole ().
372 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
376 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
380 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
382 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
388 * atspi_accessible_get_localized_role_name:
389 * @obj: a pointer to the #AtspiAccessible object on which to operate.
391 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
392 * This method will return useful values for roles that fall outside the
393 * enumeration used in atspi_accessible_getRole ().
395 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
399 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
403 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
405 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
411 * atspi_accessible_get_state_set:
412 * @obj: a pointer to the #AtspiAccessible object on which to operate.
414 * Gets the current state of an object.
416 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
417 * object's current state.
420 atspi_accessible_get_state_set (AtspiAccessible *obj)
426 * atspi_accessible_get_attributes:
427 * @obj: The #AtspiAccessible being queried.
429 * Get the #AttributeSet representing any assigned
430 * name-value pair attributes or annotations for this object.
431 * For typographic, textual, or textually-semantic attributes, see
432 * atspi_text_get_attributes instead.
434 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
435 * attributes assigned to this object.
438 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
440 DBusMessage *message;
443 g_return_val_if_fail (obj != NULL, NULL);
445 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
446 ret = _atspi_dbus_hash_from_message (message);
447 dbus_message_unref (message);
452 * atspi_accessible_get_attributes_as_array:
453 * @obj: The #AtspiAccessible being queried.
455 * Get the #AttributeSet representing any assigned
456 * name-value pair attributes or annotations for this object.
457 * For typographic, textual, or textually-semantic attributes, see
458 * atspi_text_get_attributes_as_array instead.
460 * Returns: (element-type gchar*) (transfer full): The name-value-pair
461 * attributes assigned to this object.
464 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
466 DBusMessage *message;
469 g_return_val_if_fail (obj != NULL, NULL);
471 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
472 ret = _atspi_dbus_attribute_array_from_message (message);
473 dbus_message_unref (message);
478 * atspi_accessible_get_host_application:
479 * @obj: The #AtspiAccessible being queried.
481 * Get the containing #AtspiApplication for an object.
483 * Returns: the containing AtspiApplication instance for this object.
486 atspi_accessible_get_host_application (AtspiAccessible *obj, GError **error)
488 while (obj->accessible_parent) obj = obj->accessible_parent;
489 g_warning ("atspi: TODO: Application interface");
490 //return atspi_accessible_get_application (obj);
493 #if 0 // TODO: interfaces */
494 /* Interface query methods */
497 * atspi_accessible_is_action:
498 * @obj: a pointer to the #AtspiAccessible instance to query.
500 * Query whether the specified #AtspiAccessible implements #AtspiAction.
502 * Returns: #TRUE if @obj implements the #AtspiAction interface,
506 atspi_accessible_is_action (AtspiAccessible *obj)
508 return _atspi_accessible_is_a (obj,
509 atspi_interface_action);
513 * atspi_accessible_is_application:
514 * @obj: a pointer to the #AtspiAccessible instance to query.
516 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
518 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
522 atspi_accessible_is_application (AtspiAccessible *obj)
524 return _atspi_accessible_is_a (obj,
525 atspi_interface_application);
529 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
531 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
532 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
536 atspi_accessible_is_collection (AtspiAccessible *obj)
539 g_warning ("Collections not implemented");
540 return _atspi_accessible_is_a (obj,
541 atspi_interface_collection);
548 * atspi_accessible_is_component:
549 * @obj: a pointer to the #AtspiAccessible instance to query.
551 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
553 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
557 atspi_accessible_is_component (AtspiAccessible *obj)
559 return _atspi_accessible_is_a (obj,
560 atspi_interface_component);
564 * atspi_accessible_is_document:
565 * @obj: a pointer to the #AtspiAccessible instance to query.
567 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
569 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
573 atspi_accessible_is_document (AtspiAccessible *obj)
575 return _atspi_accessible_is_a (obj,
576 atspi_interface_document);
580 * atspi_accessible_is_editable_text:
581 * @obj: a pointer to the #AtspiAccessible instance to query.
583 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
585 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
589 atspi_accessible_is_editable_text (AtspiAccessible *obj)
591 return _atspi_accessible_is_a (obj,
592 atspi_interface_editable_text);
596 * atspi_accessible_is_hypertext:
597 * @obj: a pointer to the #AtspiAccessible instance to query.
599 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
601 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
605 atspi_accessible_is_hypertext (AtspiAccessible *obj)
607 return _atspi_accessible_is_a (obj,
608 atspi_interface_hypertext);
612 * atspi_accessible_is_image:
613 * @obj: a pointer to the #AtspiAccessible instance to query.
615 * Query whether the specified #AtspiAccessible implements #AtspiImage.
617 * Returns: #TRUE if @obj implements the #AtspiImage interface,
621 atspi_accessible_is_image (AtspiAccessible *obj)
623 return _atspi_accessible_is_a (obj,
624 atspi_interface_image);
628 * atspi_accessible_is_selection:
629 * @obj: a pointer to the #AtspiAccessible instance to query.
631 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
633 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
637 atspi_accessible_is_selection (AtspiAccessible *obj)
639 return _atspi_accessible_is_a (obj,
640 atspi_interface_selection);
644 * atspi_accessible_is_table:
645 * @obj: a pointer to the #AtspiAccessible instance to query.
647 * Query whether the specified #AtspiAccessible implements #AtspiTable.
649 * Returns: #TRUE if @obj implements the #AtspiTable interface,
653 atspi_accessible_is_table (AtspiAccessible *obj)
655 return _atspi_accessible_is_a (obj,
656 atspi_interface_table);
660 * atspi_accessible_is_streamable_content:
661 * @obj: a pointer to the #AtspiAccessible instance to query.
663 * Query whether the specified #AtspiAccessible implements
664 * #AtspiStreamableContent.
666 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
670 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
673 return _atspi_accessible_is_a (obj,
674 atspi_interface_streamable_content);
676 g_warning ("Streamable content not implemented");
682 * atspi_accessible_is_text:
683 * @obj: a pointer to the #AtspiAccessible instance to query.
685 * Query whether the specified #AtspiAccessible implements #AtspiText.
687 * Returns: #TRUE if @obj implements the #AtspiText interface,
691 atspi_accessible_is_text (AtspiAccessible *obj)
693 return _atspi_accessible_is_a (obj,
694 atspi_interface_text);
698 * atspi_accessible_is_value:
699 * @obj: a pointer to the #AtspiAccessible instance to query.
701 * Query whether the specified #AtspiAccessible implements #AtspiValue.
703 * Returns: #TRUE if @obj implements the #AtspiValue interface,
707 atspi_accessible_is_value (AtspiAccessible *obj)
709 return _atspi_accessible_is_a (obj,
710 atspi_interface_value);
714 * atspi_accessible_get_application:
715 * @obj: a pointer to the #AtspiAccessible instance to query.
717 * Get the #AtspiApplication interface for an #AtspiAccessible.
719 * Returns: a pointer to an #AtspiApplication interface instance, or
720 * NULL if @obj does not implement #AtspiApplication.
723 atspi_accessible_get_application (AtspiAccessible *accessible)
725 return (_atspi_accessible_is_a (accessible, atspi_interface_application) ?
730 * atspi_accessible_get_action:
731 * @obj: a pointer to the #AtspiAccessible instance to query.
733 * Get the #AtspiAction interface for an #AtspiAccessible.
735 * Returns: a pointer to an #AtspiAction interface instance, or
736 * NULL if @obj does not implement #AtspiAction.
739 atspi_accessible_get_action (AtspiAccessible *accessible)
741 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
746 * atspi_accessible_get_collection:
747 * @obj: a pointer to the #AtspiAccessible instance to query.
749 * Get the #AtspiCollection interface for an #AtspiAccessible.
751 * Returns: a pointer to an #AtspiCollection interface instance, or
752 * NULL if @obj does not implement #AtspiCollection.
755 atspi_accessible_get_collection (AtspiAccessible *accessible)
757 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
763 * atspi_accessible_get_component:
764 * @obj: a pointer to the #AtspiAccessible instance to query.
766 * Get the #AtspiComponent interface for an #AtspiAccessible.
768 * Returns: a pointer to an #AtspiComponent interface instance, or
769 * NULL if @obj does not implement #AtspiComponent.
772 atspi_accessible_get_component (AtspiAccessible *accessible)
774 return (_atspi_accessible_is_a (accessible, atspi_interface_component) ?
775 ATSPI_COMPONENT (accessible) : NULL);
780 * atspi_accessible_get_document:
781 * @obj: a pointer to the #AtspiAccessible instance to query.
783 * Get the #AtspiDocument interface for an #AtspiAccessible.
785 * Returns: a pointer to an #AtspiDocument interface instance, or
786 * NULL if @obj does not implement #AtspiDocument.
789 atspi_accessible_get_document (AtspiAccessible *accessible)
791 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
796 * atspi_accessible_get_editable_text:
797 * @obj: a pointer to the #AtspiAccessible instance to query.
799 * Get the #AtspiEditableText interface for an #AtspiAccessible.
801 * Returns: a pointer to an #AtspiEditableText interface instance, or
802 * NULL if @obj does not implement #AtspiEditableText.
805 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
807 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
812 * atspi_accessible_get_hypertext:
813 * @obj: a pointer to the #AtspiAccessible instance to query.
815 * Get the #AtspiHypertext interface for an #AtspiAccessible.
817 * Returns: a pointer to an #AtspiHypertext interface instance, or
818 * NULL if @obj does not implement #AtspiHypertext.
821 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
823 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
828 * atspi_accessible_get_image:
829 * @obj: a pointer to the #AtspiAccessible instance to query.
831 * Get the #AtspiImage interface for an #AtspiAccessible.
833 * Returns: a pointer to an #AtspiImage interface instance, or
834 * NULL if @obj does not implement #AtspiImage.
837 atspi_accessible_get_image (AtspiAccessible *accessible)
839 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
844 * atspi_accessible_get_selection:
845 * @obj: a pointer to the #AtspiAccessible instance to query.
847 * Get the #AtspiSelection interface for an #AtspiAccessible.
849 * Returns: a pointer to an #AtspiSelection interface instance, or
850 * NULL if @obj does not implement #AtspiSelection.
853 atspi_accessible_get_selection (AtspiAccessible *accessible)
855 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
860 * atspi_accessible_get_streamable_content:
861 * @obj: a pointer to the #AtspiAccessible instance to query.
863 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
865 * Returns: a pointer to an #AtspiStreamableContent interface instance, or
866 * NULL if @obj does not implement #AtspiStreamableContent.
868 AtspiStreamableContent *
869 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
871 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
876 * atspi_accessible_get_table:
877 * @obj: a pointer to the #AtspiAccessible instance to query.
879 * Get the #AtspiTable interface for an #AtspiAccessible.
881 * Returns: a pointer to an #AtspiTable interface instance, or
882 * NULL if @obj does not implement #AtspiTable.
885 atspi_accessible_get_table (AtspiAccessible *accessible)
887 return (_atspi_accessible_is_a (accessible, atspi_interface_table) ?
892 * atspi_accessible_get_text:
893 * @obj: a pointer to the #AtspiAccessible instance to query.
895 * Get the #AtspiTable interface for an #AtspiAccessible.
897 * Returns: a pointer to an #AtspiTable interface instance, or
898 * NULL if @obj does not implement #AtspiTable.
901 atspi_accessible_get_text (AtspiAccessible *accessible)
903 return (_atspi_accessible_is_a (accessible, atspi_interface_text) ?
908 * atspi_accessible_get_value:
909 * @obj: a pointer to the #AtspiAccessible instance to query.
911 * Get the #AtspiTable interface for an #AtspiAccessible.
913 * Returns: a pointer to an #AtspiTable interface instance, or
914 * NULL if @obj does not implement #AtspiTable.
917 atspi_accessible_get_value (AtspiAccessible *accessible)
919 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
924 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
927 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
929 relation_type_table [i] = SPI_RELATION_NULL;
931 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
932 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
933 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
934 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
935 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
936 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
937 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
938 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
939 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
940 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
941 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
942 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
943 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
944 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
945 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
946 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
947 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
948 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
952 static AccessibleRelationType
953 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
955 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
956 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
957 static gboolean is_initialized = FALSE;
958 AccessibleRelationType cspi_type;
961 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
963 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
965 cspi_type = cspi_relation_type_table [type];
969 cspi_type = SPI_RELATION_NULL;
974 * AccessibleRelation_getRelationType:
975 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
977 * Get the type of relationship represented by an #AtspiAccessibleRelation.
979 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
980 * encapsulated in this #AtspiAccessibleRelation object.
983 AccessibleRelationType
984 AccessibleRelation_getRelationType (AccessibleRelation *obj)
986 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
987 return cspi_relation_type_from_spi_relation_type (obj->type);
991 * AccessibleRelation_getNTargets:
992 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
994 * Get the number of objects which this relationship has as its
995 * target objects (the subject is the #AtspiAccessible from which this
996 * #AtspiAccessibleRelation originated).
998 * Returns: a short integer indicating how many target objects which the
999 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
1000 * relationship with.
1003 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1005 cspi_return_val_if_fail (obj, -1);
1006 return obj->targets->len;
1010 * AccessibleRelation_getTarget:
1011 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1012 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1014 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
1016 * Returns: an #AtspiAccessible which is the @i-th object with which the
1017 * originating #AtspiAccessible has relationship specified in the
1018 * #AtspiAccessibleRelation object.
1022 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1024 cspi_return_val_if_fail (obj, NULL);
1026 if (i < 0 || i >= obj->targets->len) return NULL;
1027 return cspi_object_add (
1028 g_array_index (obj->targets, Accessible *, i));
1032 * AccessibleStateSet_ref:
1033 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1035 * Increment the reference count for an #AtspiAccessibleStateSet object.
1039 AccessibleStateSet_ref (AccessibleStateSet *obj)
1041 spi_state_set_cache_ref (obj);
1045 * AccessibleStateSet_unref:
1046 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1048 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1052 AccessibleStateSet_unref (AccessibleStateSet *obj)
1054 spi_state_set_cache_unref (obj);
1057 static Accessibility_StateType
1058 spi_state_to_dbus (AccessibleState state)
1060 #define MAP_STATE(a) \
1061 case SPI_STATE_##a: \
1062 return Accessibility_STATE_##a
1066 MAP_STATE (INVALID);
1070 MAP_STATE (CHECKED);
1071 MAP_STATE (DEFUNCT);
1072 MAP_STATE (EDITABLE);
1073 MAP_STATE (ENABLED);
1074 MAP_STATE (EXPANDABLE);
1075 MAP_STATE (EXPANDED);
1076 MAP_STATE (FOCUSABLE);
1077 MAP_STATE (FOCUSED);
1078 MAP_STATE (HORIZONTAL);
1079 MAP_STATE (ICONIFIED);
1081 MAP_STATE (MULTI_LINE);
1082 MAP_STATE (MULTISELECTABLE);
1084 MAP_STATE (PRESSED);
1085 MAP_STATE (RESIZABLE);
1086 MAP_STATE (SELECTABLE);
1087 MAP_STATE (SELECTED);
1088 MAP_STATE (SENSITIVE);
1089 MAP_STATE (SHOWING);
1090 MAP_STATE (SINGLE_LINE);
1092 MAP_STATE (TRANSIENT);
1093 MAP_STATE (VERTICAL);
1094 MAP_STATE (VISIBLE);
1095 MAP_STATE (MANAGES_DESCENDANTS);
1096 MAP_STATE (INDETERMINATE);
1097 MAP_STATE (TRUNCATED);
1098 MAP_STATE (REQUIRED);
1099 MAP_STATE (INVALID_ENTRY);
1100 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1101 MAP_STATE (SELECTABLE_TEXT);
1102 MAP_STATE (IS_DEFAULT);
1103 MAP_STATE (VISITED);
1105 return Accessibility_STATE_INVALID;
1111 * AccessibleStateSet_contains:
1112 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1113 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1116 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1117 * whether @state is true for the stateset in question.
1119 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1124 AccessibleStateSet_contains (AccessibleStateSet *obj,
1125 AccessibleState state)
1127 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1131 * AccessibleStateSet_add:
1132 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1133 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1135 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1136 * given state to #TRUE in the stateset.
1140 AccessibleStateSet_add (AccessibleStateSet *obj,
1141 AccessibleState state)
1143 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1147 * AccessibleStateSet_remove:
1148 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1149 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1151 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1152 * given state to #FALSE in the stateset.)
1156 AccessibleStateSet_remove (AccessibleStateSet *obj,
1157 AccessibleState state)
1159 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1163 * AccessibleStateSet_equals:
1164 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1165 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1167 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1168 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1169 * state variables at once; construct the target state then compare against it.
1171 * @see AccessibleStateSet_compare().
1173 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1178 AccessibleStateSet_equals (AccessibleStateSet *obj,
1179 AccessibleStateSet *obj2)
1189 cmp = spi_state_set_cache_xor (obj, obj2);
1190 eq = spi_state_set_cache_is_empty (cmp);
1191 spi_state_set_cache_unref (cmp);
1197 * AccessibleStateSet_compare:
1198 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1199 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1201 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1202 * Not Yet Implemented.
1204 * @see AccessibleStateSet_equals().
1206 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1207 * the two sets but not the other.
1210 AccessibleStateSet *
1211 AccessibleStateSet_compare (AccessibleStateSet *obj,
1212 AccessibleStateSet *obj2)
1214 return spi_state_set_cache_xor (obj, obj2);
1218 * AccessibleStateSet_isEmpty:
1219 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1221 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1223 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1228 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1230 return spi_state_set_cache_is_empty (obj);
1235 _atspi_accessible_is_a (AtspiAccessible *accessible,
1236 const char *interface_name)
1240 if (accessible == NULL)
1245 n = _atspi_get_iface_num (interface_name);
1246 if (n == -1) return FALSE;
1247 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1250 /* TODO: Move to a finalizer */
1252 cspi_object_destroyed (AtspiAccessible *accessible)
1257 /* TODO: Only fire if object not already marked defunct */
1258 e.type = "object:state-change:defunct";
1259 e.source = accessible;
1262 g_value_unset (&e.any);
1263 _atspi_send_event (&e);
1265 g_free (accessible->path);
1267 if (accessible->states)
1268 g_object_unref (accessible->states);
1269 g_free (accessible->description);
1270 g_free (accessible->name);
1274 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1276 AtspiAccessible *accessible;
1278 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1279 g_return_val_if_fail (accessible != NULL, NULL);
1281 accessible->app = g_object_ref (app);
1282 accessible->path = g_strdup (path);