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: a pointer tothe #AtspiAccessible object which contains the given
221 * #AtspiAccessible instance, or NULL if the @obj has no parent container.
225 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
227 g_return_val_if_fail (obj != NULL, NULL);
229 return g_object_ref (obj->accessible_parent);
233 * atspi_accessible_get_child_count:
234 * @obj: a pointer to the #AtspiAccessible object on which to operate.
236 * Get the number of children contained by an #AtspiAccessible object.
238 * Returns: a #long indicating the number of #AtspiAccessible children
239 * contained by an #AtspiAccessible object. or -1 on exception
243 atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error)
245 g_return_val_if_fail (obj != NULL, -1);
247 /* TODO: MANAGES_DESCENDANTS */
248 return g_list_length (obj->children);
252 * atspi_accessible_get_child_at_index:
253 * @obj: a pointer to the #AtspiAccessible object on which to operate.
254 * @child_index: a #long indicating which child is specified.
256 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
258 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
259 * index @child_index. or NULL on exception
262 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
266 AtspiAccessible *child;
268 g_return_val_if_fail (obj != NULL, NULL);
270 /* TODO: ManagesDescendants */
271 child = g_list_nth_data (obj->children, child_index);
274 return g_object_ref (child);
278 * atspi_accessible_get_index_in_parent
279 * @obj: a pointer to the #AtspiAccessible object on which to operate.
281 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
283 * Returns: a #glong indicating the index of the #AtspiAccessible object
284 * in its parent (i.e. containing) #AtspiAccessible instance,
285 * or -1 if @obj has no containing parent or on exception.
288 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
293 g_return_val_if_fail (obj != NULL, -1);
294 if (!obj->accessible_parent) return -1;
295 l = obj->accessible_parent->children;
298 if (l->data == obj) return i;
309 } Accessibility_Relation;
312 * atspi_accessible_get_relation_set:
313 * @obj: a pointer to the #AtspiAccessible object on which to operate.
315 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
316 * relationships with other #AtspiAccessible objects.
318 * Returns: an array of #AtspiAccessibleRelation pointers. or NULL on exception
319 * TODO:: Annotate array type
322 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
326 GArray *relation_set;
328 g_return_val_if_fail (obj != NULL, NULL);
330 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetRelationSet", error, "=>a(uao)", &relation_set))
337 * atspi_accessible_get_role:
338 * @obj: a pointer to the #AtspiAccessible object on which to operate.
340 * Get the UI role of an #AtspiAccessible object.
341 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
343 * Returns: the #AtspiRole of the object.
347 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
349 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
351 if (!obj->cached_properties & ATSPI_CACHE_ROLE)
354 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
356 obj->cached_properties |= ATSPI_CACHE_ROLE;
364 * atspi_accessible_get_role_name:
365 * @obj: a pointer to the #AtspiAccessible object on which to operate.
367 * Get a UTF-8 string describing the role this object plays in the UI.
368 * This method will return useful values for roles that fall outside the
369 * enumeration used in atspi_accessible_getRole ().
371 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
375 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
379 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
381 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
387 * atspi_accessible_get_localized_role_name:
388 * @obj: a pointer to the #AtspiAccessible object on which to operate.
390 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
391 * This method will return useful values for roles that fall outside the
392 * enumeration used in atspi_accessible_getRole ().
394 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
398 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
402 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
404 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
410 * atspi_accessible_get_state_set:
411 * @obj: a pointer to the #AtspiAccessible object on which to operate.
413 * Gets the current state of an object.
415 * Returns: a pointer to an #AtspiStateSet representing the object's current state.
418 atspi_accessible_get_state_set (AtspiAccessible *obj)
424 * atspi_accessible_get_attributes:
425 * @obj: The #AtspiAccessible being queried.
427 * Get the #AttributeSet representing any assigned
428 * name-value pair attributes or annotations for this object.
429 * For typographic, textual, or textually-semantic attributes, see
430 * atspi_text_get_attributes instead.
432 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
433 * attributes assigned to this object.
436 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
438 DBusMessage *message;
441 g_return_val_if_fail (obj != NULL, NULL);
443 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
444 ret = _atspi_dbus_hash_from_message (message);
445 dbus_message_unref (message);
450 * atspi_accessible_get_attributes_as_array:
451 * @obj: The #AtspiAccessible being queried.
453 * Get the #AttributeSet representing any assigned
454 * name-value pair attributes or annotations for this object.
455 * For typographic, textual, or textually-semantic attributes, see
456 * atspi_text_get_attributes_as_array instead.
458 * Returns: (element-type gchar*) (transfer full): The name-value-pair
459 * attributes assigned to this object.
462 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
464 DBusMessage *message;
467 g_return_val_if_fail (obj != NULL, NULL);
469 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
470 ret = _atspi_dbus_attribute_array_from_message (message);
471 dbus_message_unref (message);
476 * atspi_accessible_get_host_application:
477 * @obj: The #AtspiAccessible being queried.
479 * Get the containing #AtspiApplication for an object.
481 * Returns: the containing AtspiApplication instance for this object.
484 atspi_accessible_get_host_application (AtspiAccessible *obj, GError **error)
486 while (obj->accessible_parent) obj = obj->accessible_parent;
487 g_warning ("atspi: TODO: Application interface");
488 //return atspi_accessible_get_application (obj);
491 #if 0 // TODO: interfaces */
492 /* Interface query methods */
495 * atspi_accessible_is_action:
496 * @obj: a pointer to the #AtspiAccessible instance to query.
498 * Query whether the specified #AtspiAccessible implements #AtspiAction.
500 * Returns: #TRUE if @obj implements the #AtspiAction interface,
504 atspi_accessible_is_action (AtspiAccessible *obj)
506 return _atspi_accessible_is_a (obj,
507 atspi_interface_action);
511 * atspi_accessible_is_application:
512 * @obj: a pointer to the #AtspiAccessible instance to query.
514 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
516 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
520 atspi_accessible_is_application (AtspiAccessible *obj)
522 return _atspi_accessible_is_a (obj,
523 atspi_interface_application);
527 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
529 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
530 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
534 atspi_accessible_is_collection (AtspiAccessible *obj)
537 g_warning ("Collections not implemented");
538 return _atspi_accessible_is_a (obj,
539 atspi_interface_collection);
546 * atspi_accessible_is_component:
547 * @obj: a pointer to the #AtspiAccessible instance to query.
549 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
551 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
555 atspi_accessible_is_component (AtspiAccessible *obj)
557 return _atspi_accessible_is_a (obj,
558 atspi_interface_component);
562 * atspi_accessible_is_document:
563 * @obj: a pointer to the #AtspiAccessible instance to query.
565 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
567 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
571 atspi_accessible_is_document (AtspiAccessible *obj)
573 return _atspi_accessible_is_a (obj,
574 atspi_interface_document);
578 * atspi_accessible_is_editable_text:
579 * @obj: a pointer to the #AtspiAccessible instance to query.
581 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
583 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
587 atspi_accessible_is_editable_text (AtspiAccessible *obj)
589 return _atspi_accessible_is_a (obj,
590 atspi_interface_editable_text);
594 * atspi_accessible_is_hypertext:
595 * @obj: a pointer to the #AtspiAccessible instance to query.
597 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
599 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
603 atspi_accessible_is_hypertext (AtspiAccessible *obj)
605 return _atspi_accessible_is_a (obj,
606 atspi_interface_hypertext);
610 * atspi_accessible_is_image:
611 * @obj: a pointer to the #AtspiAccessible instance to query.
613 * Query whether the specified #AtspiAccessible implements #AtspiImage.
615 * Returns: #TRUE if @obj implements the #AtspiImage interface,
619 atspi_accessible_is_image (AtspiAccessible *obj)
621 return _atspi_accessible_is_a (obj,
622 atspi_interface_image);
626 * atspi_accessible_is_selection:
627 * @obj: a pointer to the #AtspiAccessible instance to query.
629 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
631 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
635 atspi_accessible_is_selection (AtspiAccessible *obj)
637 return _atspi_accessible_is_a (obj,
638 atspi_interface_selection);
642 * atspi_accessible_is_table:
643 * @obj: a pointer to the #AtspiAccessible instance to query.
645 * Query whether the specified #AtspiAccessible implements #AtspiTable.
647 * Returns: #TRUE if @obj implements the #AtspiTable interface,
651 atspi_accessible_is_table (AtspiAccessible *obj)
653 return _atspi_accessible_is_a (obj,
654 atspi_interface_table);
658 * atspi_accessible_is_streamable_content:
659 * @obj: a pointer to the #AtspiAccessible instance to query.
661 * Query whether the specified #AtspiAccessible implements
662 * #AtspiStreamableContent.
664 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
668 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
671 return _atspi_accessible_is_a (obj,
672 atspi_interface_streamable_content);
674 g_warning ("Streamable content not implemented");
680 * atspi_accessible_is_text:
681 * @obj: a pointer to the #AtspiAccessible instance to query.
683 * Query whether the specified #AtspiAccessible implements #AtspiText.
685 * Returns: #TRUE if @obj implements the #AtspiText interface,
689 atspi_accessible_is_text (AtspiAccessible *obj)
691 return _atspi_accessible_is_a (obj,
692 atspi_interface_text);
696 * atspi_accessible_is_value:
697 * @obj: a pointer to the #AtspiAccessible instance to query.
699 * Query whether the specified #AtspiAccessible implements #AtspiValue.
701 * Returns: #TRUE if @obj implements the #AtspiValue interface,
705 atspi_accessible_is_value (AtspiAccessible *obj)
707 return _atspi_accessible_is_a (obj,
708 atspi_interface_value);
712 * atspi_accessible_get_application:
713 * @obj: a pointer to the #AtspiAccessible instance to query.
715 * Get the #AtspiApplication interface for an #AtspiAccessible.
717 * Returns: a pointer to an #AtspiApplication interface instance, or
718 * NULL if @obj does not implement #AtspiApplication.
721 atspi_accessible_get_application (AtspiAccessible *accessible)
723 return (_atspi_accessible_is_a (accessible, atspi_interface_application) ?
728 * atspi_accessible_get_action:
729 * @obj: a pointer to the #AtspiAccessible instance to query.
731 * Get the #AtspiAction interface for an #AtspiAccessible.
733 * Returns: a pointer to an #AtspiAction interface instance, or
734 * NULL if @obj does not implement #AtspiAction.
737 atspi_accessible_get_action (AtspiAccessible *accessible)
739 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
744 * atspi_accessible_get_collection:
745 * @obj: a pointer to the #AtspiAccessible instance to query.
747 * Get the #AtspiCollection interface for an #AtspiAccessible.
749 * Returns: a pointer to an #AtspiCollection interface instance, or
750 * NULL if @obj does not implement #AtspiCollection.
753 atspi_accessible_get_collection (AtspiAccessible *accessible)
755 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
761 * atspi_accessible_get_component:
762 * @obj: a pointer to the #AtspiAccessible instance to query.
764 * Get the #AtspiComponent interface for an #AtspiAccessible.
766 * Returns: a pointer to an #AtspiComponent interface instance, or
767 * NULL if @obj does not implement #AtspiComponent.
770 atspi_accessible_get_component (AtspiAccessible *accessible)
772 return (_atspi_accessible_is_a (accessible, atspi_interface_component) ?
773 ATSPI_COMPONENT (accessible) : NULL);
778 * atspi_accessible_get_document:
779 * @obj: a pointer to the #AtspiAccessible instance to query.
781 * Get the #AtspiDocument interface for an #AtspiAccessible.
783 * Returns: a pointer to an #AtspiDocument interface instance, or
784 * NULL if @obj does not implement #AtspiDocument.
787 atspi_accessible_get_document (AtspiAccessible *accessible)
789 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
794 * atspi_accessible_get_editable_text:
795 * @obj: a pointer to the #AtspiAccessible instance to query.
797 * Get the #AtspiEditableText interface for an #AtspiAccessible.
799 * Returns: a pointer to an #AtspiEditableText interface instance, or
800 * NULL if @obj does not implement #AtspiEditableText.
803 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
805 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
810 * atspi_accessible_get_hypertext:
811 * @obj: a pointer to the #AtspiAccessible instance to query.
813 * Get the #AtspiHypertext interface for an #AtspiAccessible.
815 * Returns: a pointer to an #AtspiHypertext interface instance, or
816 * NULL if @obj does not implement #AtspiHypertext.
819 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
821 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
826 * atspi_accessible_get_image:
827 * @obj: a pointer to the #AtspiAccessible instance to query.
829 * Get the #AtspiImage interface for an #AtspiAccessible.
831 * Returns: a pointer to an #AtspiImage interface instance, or
832 * NULL if @obj does not implement #AtspiImage.
835 atspi_accessible_get_image (AtspiAccessible *accessible)
837 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
842 * atspi_accessible_get_selection:
843 * @obj: a pointer to the #AtspiAccessible instance to query.
845 * Get the #AtspiSelection interface for an #AtspiAccessible.
847 * Returns: a pointer to an #AtspiSelection interface instance, or
848 * NULL if @obj does not implement #AtspiSelection.
851 atspi_accessible_get_selection (AtspiAccessible *accessible)
853 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
858 * atspi_accessible_get_streamable_content:
859 * @obj: a pointer to the #AtspiAccessible instance to query.
861 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
863 * Returns: a pointer to an #AtspiStreamableContent interface instance, or
864 * NULL if @obj does not implement #AtspiStreamableContent.
866 AtspiStreamableContent *
867 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
869 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
874 * atspi_accessible_get_table:
875 * @obj: a pointer to the #AtspiAccessible instance to query.
877 * Get the #AtspiTable interface for an #AtspiAccessible.
879 * Returns: a pointer to an #AtspiTable interface instance, or
880 * NULL if @obj does not implement #AtspiTable.
883 atspi_accessible_get_table (AtspiAccessible *accessible)
885 return (_atspi_accessible_is_a (accessible, atspi_interface_table) ?
890 * atspi_accessible_get_text:
891 * @obj: a pointer to the #AtspiAccessible instance to query.
893 * Get the #AtspiTable interface for an #AtspiAccessible.
895 * Returns: a pointer to an #AtspiTable interface instance, or
896 * NULL if @obj does not implement #AtspiTable.
899 atspi_accessible_get_text (AtspiAccessible *accessible)
901 return (_atspi_accessible_is_a (accessible, atspi_interface_text) ?
906 * atspi_accessible_get_value:
907 * @obj: a pointer to the #AtspiAccessible instance to query.
909 * Get the #AtspiTable interface for an #AtspiAccessible.
911 * Returns: a pointer to an #AtspiTable interface instance, or
912 * NULL if @obj does not implement #AtspiTable.
915 atspi_accessible_get_value (AtspiAccessible *accessible)
917 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
922 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
925 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
927 relation_type_table [i] = SPI_RELATION_NULL;
929 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
930 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
931 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
932 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
933 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
934 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
935 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
936 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
937 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
938 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
939 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
940 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
941 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
942 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
943 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
944 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
945 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
946 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
950 static AccessibleRelationType
951 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
953 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
954 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
955 static gboolean is_initialized = FALSE;
956 AccessibleRelationType cspi_type;
959 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
961 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
963 cspi_type = cspi_relation_type_table [type];
967 cspi_type = SPI_RELATION_NULL;
972 * AccessibleRelation_getRelationType:
973 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
975 * Get the type of relationship represented by an #AtspiAccessibleRelation.
977 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
978 * encapsulated in this #AtspiAccessibleRelation object.
981 AccessibleRelationType
982 AccessibleRelation_getRelationType (AccessibleRelation *obj)
984 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
985 return cspi_relation_type_from_spi_relation_type (obj->type);
989 * AccessibleRelation_getNTargets:
990 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
992 * Get the number of objects which this relationship has as its
993 * target objects (the subject is the #AtspiAccessible from which this
994 * #AtspiAccessibleRelation originated).
996 * Returns: a short integer indicating how many target objects which the
997 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
1001 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1003 cspi_return_val_if_fail (obj, -1);
1004 return obj->targets->len;
1008 * AccessibleRelation_getTarget:
1009 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1010 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1012 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
1014 * Returns: an #AtspiAccessible which is the @i-th object with which the
1015 * originating #AtspiAccessible has relationship specified in the
1016 * #AtspiAccessibleRelation object.
1020 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1022 cspi_return_val_if_fail (obj, NULL);
1024 if (i < 0 || i >= obj->targets->len) return NULL;
1025 return cspi_object_add (
1026 g_array_index (obj->targets, Accessible *, i));
1030 * AccessibleStateSet_ref:
1031 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1033 * Increment the reference count for an #AtspiAccessibleStateSet object.
1037 AccessibleStateSet_ref (AccessibleStateSet *obj)
1039 spi_state_set_cache_ref (obj);
1043 * AccessibleStateSet_unref:
1044 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1046 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1050 AccessibleStateSet_unref (AccessibleStateSet *obj)
1052 spi_state_set_cache_unref (obj);
1055 static Accessibility_StateType
1056 spi_state_to_dbus (AccessibleState state)
1058 #define MAP_STATE(a) \
1059 case SPI_STATE_##a: \
1060 return Accessibility_STATE_##a
1064 MAP_STATE (INVALID);
1068 MAP_STATE (CHECKED);
1069 MAP_STATE (DEFUNCT);
1070 MAP_STATE (EDITABLE);
1071 MAP_STATE (ENABLED);
1072 MAP_STATE (EXPANDABLE);
1073 MAP_STATE (EXPANDED);
1074 MAP_STATE (FOCUSABLE);
1075 MAP_STATE (FOCUSED);
1076 MAP_STATE (HORIZONTAL);
1077 MAP_STATE (ICONIFIED);
1079 MAP_STATE (MULTI_LINE);
1080 MAP_STATE (MULTISELECTABLE);
1082 MAP_STATE (PRESSED);
1083 MAP_STATE (RESIZABLE);
1084 MAP_STATE (SELECTABLE);
1085 MAP_STATE (SELECTED);
1086 MAP_STATE (SENSITIVE);
1087 MAP_STATE (SHOWING);
1088 MAP_STATE (SINGLE_LINE);
1090 MAP_STATE (TRANSIENT);
1091 MAP_STATE (VERTICAL);
1092 MAP_STATE (VISIBLE);
1093 MAP_STATE (MANAGES_DESCENDANTS);
1094 MAP_STATE (INDETERMINATE);
1095 MAP_STATE (TRUNCATED);
1096 MAP_STATE (REQUIRED);
1097 MAP_STATE (INVALID_ENTRY);
1098 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1099 MAP_STATE (SELECTABLE_TEXT);
1100 MAP_STATE (IS_DEFAULT);
1101 MAP_STATE (VISITED);
1103 return Accessibility_STATE_INVALID;
1109 * AccessibleStateSet_contains:
1110 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1111 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1114 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1115 * whether @state is true for the stateset in question.
1117 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1122 AccessibleStateSet_contains (AccessibleStateSet *obj,
1123 AccessibleState state)
1125 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1129 * AccessibleStateSet_add:
1130 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1131 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1133 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1134 * given state to #TRUE in the stateset.
1138 AccessibleStateSet_add (AccessibleStateSet *obj,
1139 AccessibleState state)
1141 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1145 * AccessibleStateSet_remove:
1146 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1147 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1149 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1150 * given state to #FALSE in the stateset.)
1154 AccessibleStateSet_remove (AccessibleStateSet *obj,
1155 AccessibleState state)
1157 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1161 * AccessibleStateSet_equals:
1162 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1163 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1165 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1166 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1167 * state variables at once; construct the target state then compare against it.
1169 * @see AccessibleStateSet_compare().
1171 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1176 AccessibleStateSet_equals (AccessibleStateSet *obj,
1177 AccessibleStateSet *obj2)
1187 cmp = spi_state_set_cache_xor (obj, obj2);
1188 eq = spi_state_set_cache_is_empty (cmp);
1189 spi_state_set_cache_unref (cmp);
1195 * AccessibleStateSet_compare:
1196 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1197 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1199 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1200 * Not Yet Implemented.
1202 * @see AccessibleStateSet_equals().
1204 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1205 * the two sets but not the other.
1208 AccessibleStateSet *
1209 AccessibleStateSet_compare (AccessibleStateSet *obj,
1210 AccessibleStateSet *obj2)
1212 return spi_state_set_cache_xor (obj, obj2);
1216 * AccessibleStateSet_isEmpty:
1217 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1219 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1221 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1226 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1228 return spi_state_set_cache_is_empty (obj);
1233 _atspi_accessible_is_a (AtspiAccessible *accessible,
1234 const char *interface_name)
1238 if (accessible == NULL)
1243 n = _atspi_get_iface_num (interface_name);
1244 if (n == -1) return FALSE;
1245 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1248 /* TODO: Move to a finalizer */
1250 cspi_object_destroyed (AtspiAccessible *accessible)
1255 /* TODO: Only fire if object not already marked defunct */
1256 e.type = "object:state-change:defunct";
1257 e.source = accessible;
1260 g_value_unset (&e.any);
1261 _atspi_send_event (&e);
1263 g_free (accessible->path);
1265 if (accessible->states)
1266 g_object_unref (accessible->states);
1267 g_free (accessible->description);
1268 g_free (accessible->name);
1272 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1274 AtspiAccessible *accessible;
1276 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1277 g_return_val_if_fail (accessible != NULL, NULL);
1279 accessible->app = g_object_ref (app);
1280 accessible->path = g_strdup (path);