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 (AtspiAccessible *accessible)
37 g_object_unref (accessible->app);
39 g_free (accessible->path);
43 atspi_accessible_class_init (AtspiAccessibleClass *klass)
45 GObjectClass *object_class = G_OBJECT_CLASS (klass);
47 object_class->finalize = atspi_accessible_finalize;
49 /* TODO: Generate following from spec? */
50 static const char *role_names [] =
108 "table-column-header",
110 "tear-off-menu-item",
140 "input method window"
143 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
146 * atspi_role_get_name
147 * @role: an #AtspiAccessibleRole object to query.
149 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
150 * <em>DEPRECATED.</em>
152 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
155 atspi_role_get_name (AtspiRole role)
157 if (role < MAX_ROLES && role_names [(int) role])
159 return g_strdup (role_names [(int) role]);
163 return g_strdup ("");
168 * atspi_accessible_get_name:
169 * @obj: a pointer to the #AtspiAccessible object on which to operate.
171 * Get the name of an #AtspiAccessible object.
173 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
174 * or NULL on exception
177 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
179 g_return_val_if_fail (obj != NULL, NULL);
180 return g_strdup (obj->name);
184 * atspi_accessible_get_description:
185 * @obj: a pointer to the #AtspiAccessible object on which to operate.
187 * Get the description of an #AtspiAccessible object.
189 * Returns: a UTF-8 string describing the #AtspiAccessible object.
190 * or NULL on exception
193 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
195 g_return_val_if_fail (obj != NULL, NULL);
197 return g_strdup (obj->description);
201 * atspi_accessible_get_parent:
202 * @obj: a pointer to the #AtspiAccessible object to query.
204 * Get an #AtspiAccessible object's parent container.
206 * Returns: a pointer tothe #AtspiAccessible object which contains the given
207 * #AtspiAccessible instance, or NULL if the @obj has no parent container.
211 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
213 g_return_val_if_fail (obj != NULL, NULL);
215 return g_object_ref (obj->accessible_parent);
219 * atspi_accessible_get_child_count:
220 * @obj: a pointer to the #AtspiAccessible object on which to operate.
222 * Get the number of children contained by an #AtspiAccessible object.
224 * Returns: a #long indicating the number of #AtspiAccessible children
225 * contained by an #AtspiAccessible object. or -1 on exception
229 atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error)
231 g_return_val_if_fail (obj != NULL, -1);
233 /* TODO: MANAGES_DESCENDANTS */
234 return g_list_length (obj->children);
238 * atspi_accessible_get_child_at_index:
239 * @obj: a pointer to the #AtspiAccessible object on which to operate.
240 * @child_index: a #long indicating which child is specified.
242 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
244 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
245 * index @child_index. or NULL on exception
248 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
252 AtspiAccessible *child;
254 g_return_val_if_fail (obj != NULL, NULL);
256 /* TODO: ManagesDescendants */
257 child = g_list_nth_data (obj->children, child_index);
258 return g_object_ref (child);
262 * atspi_accessible_get_index_in_parent
263 * @obj: a pointer to the #AtspiAccessible object on which to operate.
265 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
267 * Returns: a #glong indicating the index of the #AtspiAccessible object
268 * in its parent (i.e. containing) #AtspiAccessible instance,
269 * or -1 if @obj has no containing parent or on exception.
272 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
277 g_return_val_if_fail (obj != NULL, -1);
278 if (!obj->accessible_parent) return -1;
279 l = obj->accessible_parent->children;
282 if (l->data == obj) return i;
293 } Accessibility_Relation;
296 * atspi_accessible_get_relation_set:
297 * @obj: a pointer to the #AtspiAccessible object on which to operate.
299 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
300 * relationships with other #AtspiAccessible objects.
302 * Returns: an array of #AtspiAccessibleRelation pointers. or NULL on exception
303 * TODO:: Annotate array type
306 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
310 GArray *relation_set;
312 g_return_val_if_fail (obj != NULL, NULL);
314 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetRelationSet", error, "=>a(uao)", &relation_set))
321 * atspi_accessible_get_role:
322 * @obj: a pointer to the #AtspiAccessible object on which to operate.
324 * Get the UI role of an #AtspiAccessible object.
325 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
327 * Returns: the #AtspiRole of the object.
331 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
333 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
339 * atspi_accessible_get_role_name:
340 * @obj: a pointer to the #AtspiAccessible object on which to operate.
342 * Get a UTF-8 string describing the role this object plays in the UI.
343 * This method will return useful values for roles that fall outside the
344 * enumeration used in atspi_accessible_getRole ().
346 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
350 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
354 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
356 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
362 * atspi_accessible_get_localized_role_name:
363 * @obj: a pointer to the #AtspiAccessible object on which to operate.
365 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
366 * This method will return useful values for roles that fall outside the
367 * enumeration used in atspi_accessible_getRole ().
369 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
373 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
377 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
379 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
385 * atspi_accessible_get_state_set:
386 * @obj: a pointer to the #AtspiAccessible object on which to operate.
388 * Gets the current state of an object.
390 * Returns: a pointer to an #AtspiStateSet representing the object's current state.
393 atspi_accessible_get_state_set (AtspiAccessible *obj)
399 * atspi_accessible_get_attributes:
400 * @obj: The #AtspiAccessible being queried.
402 * Get the #AttributeSet representing any assigned
403 * name-value pair attributes or annotations for this object.
404 * For typographic, textual, or textually-semantic attributes, see
405 * atspi_text_get_attributes instead.
407 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
408 * attributes assigned to this object.
411 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
413 DBusMessage *message;
416 g_return_val_if_fail (obj != NULL, NULL);
418 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
419 ret = _atspi_dbus_hash_from_message (message);
420 dbus_message_unref (message);
425 * atspi_accessible_get_attributes_as_array:
426 * @obj: The #AtspiAccessible being queried.
428 * Get the #AttributeSet representing any assigned
429 * name-value pair attributes or annotations for this object.
430 * For typographic, textual, or textually-semantic attributes, see
431 * atspi_text_get_attributes_as_array instead.
433 * Returns: (element-type gchar*) (transfer full): The name-value-pair
434 * attributes assigned to this object.
437 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
439 DBusMessage *message;
442 g_return_val_if_fail (obj != NULL, NULL);
444 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
445 ret = _atspi_dbus_attribute_array_from_message (message);
446 dbus_message_unref (message);
451 * atspi_accessible_get_host_application:
452 * @obj: The #AtspiAccessible being queried.
454 * Get the containing #AtspiApplication for an object.
456 * Returns: the containing AtspiApplication instance for this object.
459 atspi_accessible_get_host_application (AtspiAccessible *obj, GError **error)
461 while (obj->accessible_parent) obj = obj->accessible_parent;
462 g_warning ("atspi: TODO: Application interface");
463 //return atspi_accessible_get_application (obj);
466 #if 0 // TODO: interfaces */
467 /* Interface query methods */
470 * atspi_accessible_is_action:
471 * @obj: a pointer to the #AtspiAccessible instance to query.
473 * Query whether the specified #AtspiAccessible implements #AtspiAction.
475 * Returns: #TRUE if @obj implements the #AtspiAction interface,
479 atspi_accessible_is_action (AtspiAccessible *obj)
481 return _atspi_accessible_is_a (obj,
482 atspi_interface_action);
486 * atspi_accessible_is_application:
487 * @obj: a pointer to the #AtspiAccessible instance to query.
489 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
491 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
495 atspi_accessible_is_application (AtspiAccessible *obj)
497 return _atspi_accessible_is_a (obj,
498 atspi_interface_application);
502 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
504 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
505 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
509 atspi_accessible_is_collection (AtspiAccessible *obj)
512 g_warning ("Collections not implemented");
513 return _atspi_accessible_is_a (obj,
514 atspi_interface_collection);
521 * atspi_accessible_is_component:
522 * @obj: a pointer to the #AtspiAccessible instance to query.
524 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
526 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
530 atspi_accessible_is_component (AtspiAccessible *obj)
532 return _atspi_accessible_is_a (obj,
533 atspi_interface_component);
537 * atspi_accessible_is_document:
538 * @obj: a pointer to the #AtspiAccessible instance to query.
540 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
542 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
546 atspi_accessible_is_document (AtspiAccessible *obj)
548 return _atspi_accessible_is_a (obj,
549 atspi_interface_document);
553 * atspi_accessible_is_editable_text:
554 * @obj: a pointer to the #AtspiAccessible instance to query.
556 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
558 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
562 atspi_accessible_is_editable_text (AtspiAccessible *obj)
564 return _atspi_accessible_is_a (obj,
565 atspi_interface_editable_text);
569 * atspi_accessible_is_hypertext:
570 * @obj: a pointer to the #AtspiAccessible instance to query.
572 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
574 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
578 atspi_accessible_is_hypertext (AtspiAccessible *obj)
580 return _atspi_accessible_is_a (obj,
581 atspi_interface_hypertext);
585 * atspi_accessible_is_image:
586 * @obj: a pointer to the #AtspiAccessible instance to query.
588 * Query whether the specified #AtspiAccessible implements #AtspiImage.
590 * Returns: #TRUE if @obj implements the #AtspiImage interface,
594 atspi_accessible_is_image (AtspiAccessible *obj)
596 return _atspi_accessible_is_a (obj,
597 atspi_interface_image);
601 * atspi_accessible_is_selection:
602 * @obj: a pointer to the #AtspiAccessible instance to query.
604 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
606 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
610 atspi_accessible_is_selection (AtspiAccessible *obj)
612 return _atspi_accessible_is_a (obj,
613 atspi_interface_selection);
617 * atspi_accessible_is_table:
618 * @obj: a pointer to the #AtspiAccessible instance to query.
620 * Query whether the specified #AtspiAccessible implements #AtspiTable.
622 * Returns: #TRUE if @obj implements the #AtspiTable interface,
626 atspi_accessible_is_table (AtspiAccessible *obj)
628 return _atspi_accessible_is_a (obj,
629 atspi_interface_table);
633 * atspi_accessible_is_streamable_content:
634 * @obj: a pointer to the #AtspiAccessible instance to query.
636 * Query whether the specified #AtspiAccessible implements
637 * #AtspiStreamableContent.
639 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
643 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
646 return _atspi_accessible_is_a (obj,
647 atspi_interface_streamable_content);
649 g_warning ("Streamable content not implemented");
655 * atspi_accessible_is_text:
656 * @obj: a pointer to the #AtspiAccessible instance to query.
658 * Query whether the specified #AtspiAccessible implements #AtspiText.
660 * Returns: #TRUE if @obj implements the #AtspiText interface,
664 atspi_accessible_is_text (AtspiAccessible *obj)
666 return _atspi_accessible_is_a (obj,
667 atspi_interface_text);
671 * atspi_accessible_is_value:
672 * @obj: a pointer to the #AtspiAccessible instance to query.
674 * Query whether the specified #AtspiAccessible implements #AtspiValue.
676 * Returns: #TRUE if @obj implements the #AtspiValue interface,
680 atspi_accessible_is_value (AtspiAccessible *obj)
682 return _atspi_accessible_is_a (obj,
683 atspi_interface_value);
687 * atspi_accessible_get_application:
688 * @obj: a pointer to the #AtspiAccessible instance to query.
690 * Get the #AtspiApplication interface for an #AtspiAccessible.
692 * Returns: a pointer to an #AtspiApplication interface instance, or
693 * NULL if @obj does not implement #AtspiApplication.
696 atspi_accessible_get_application (AtspiAccessible *accessible)
698 return (_atspi_accessible_is_a (accessible, atspi_interface_application) ?
703 * atspi_accessible_get_action:
704 * @obj: a pointer to the #AtspiAccessible instance to query.
706 * Get the #AtspiAction interface for an #AtspiAccessible.
708 * Returns: a pointer to an #AtspiAction interface instance, or
709 * NULL if @obj does not implement #AtspiAction.
712 atspi_accessible_get_action (AtspiAccessible *accessible)
714 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
719 * atspi_accessible_get_collection:
720 * @obj: a pointer to the #AtspiAccessible instance to query.
722 * Get the #AtspiCollection interface for an #AtspiAccessible.
724 * Returns: a pointer to an #AtspiCollection interface instance, or
725 * NULL if @obj does not implement #AtspiCollection.
728 atspi_accessible_get_collection (AtspiAccessible *accessible)
730 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
736 * atspi_accessible_get_component:
737 * @obj: a pointer to the #AtspiAccessible instance to query.
739 * Get the #AtspiComponent interface for an #AtspiAccessible.
741 * Returns: a pointer to an #AtspiComponent interface instance, or
742 * NULL if @obj does not implement #AtspiComponent.
745 atspi_accessible_get_component (AtspiAccessible *accessible)
747 return (_atspi_accessible_is_a (accessible, atspi_interface_component) ?
753 * atspi_accessible_get_document:
754 * @obj: a pointer to the #AtspiAccessible instance to query.
756 * Get the #AtspiDocument interface for an #AtspiAccessible.
758 * Returns: a pointer to an #AtspiDocument interface instance, or
759 * NULL if @obj does not implement #AtspiDocument.
762 atspi_accessible_get_document (AtspiAccessible *accessible)
764 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
769 * atspi_accessible_get_editable_text:
770 * @obj: a pointer to the #AtspiAccessible instance to query.
772 * Get the #AtspiEditableText interface for an #AtspiAccessible.
774 * Returns: a pointer to an #AtspiEditableText interface instance, or
775 * NULL if @obj does not implement #AtspiEditableText.
778 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
780 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
785 * atspi_accessible_get_hypertext:
786 * @obj: a pointer to the #AtspiAccessible instance to query.
788 * Get the #AtspiHypertext interface for an #AtspiAccessible.
790 * Returns: a pointer to an #AtspiHypertext interface instance, or
791 * NULL if @obj does not implement #AtspiHypertext.
794 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
796 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
801 * atspi_accessible_get_image:
802 * @obj: a pointer to the #AtspiAccessible instance to query.
804 * Get the #AtspiImage interface for an #AtspiAccessible.
806 * Returns: a pointer to an #AtspiImage interface instance, or
807 * NULL if @obj does not implement #AtspiImage.
810 atspi_accessible_get_image (AtspiAccessible *accessible)
812 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
817 * atspi_accessible_get_selection:
818 * @obj: a pointer to the #AtspiAccessible instance to query.
820 * Get the #AtspiSelection interface for an #AtspiAccessible.
822 * Returns: a pointer to an #AtspiSelection interface instance, or
823 * NULL if @obj does not implement #AtspiSelection.
826 atspi_accessible_get_selection (AtspiAccessible *accessible)
828 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
833 * atspi_accessible_get_streamable_content:
834 * @obj: a pointer to the #AtspiAccessible instance to query.
836 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
838 * Returns: a pointer to an #AtspiStreamableContent interface instance, or
839 * NULL if @obj does not implement #AtspiStreamableContent.
841 AtspiStreamableContent *
842 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
844 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
849 * atspi_accessible_get_table:
850 * @obj: a pointer to the #AtspiAccessible instance to query.
852 * Get the #AtspiTable interface for an #AtspiAccessible.
854 * Returns: a pointer to an #AtspiTable interface instance, or
855 * NULL if @obj does not implement #AtspiTable.
858 atspi_accessible_get_table (AtspiAccessible *accessible)
860 return (_atspi_accessible_is_a (accessible, atspi_interface_table) ?
865 * atspi_accessible_get_text:
866 * @obj: a pointer to the #AtspiAccessible instance to query.
868 * Get the #AtspiTable interface for an #AtspiAccessible.
870 * Returns: a pointer to an #AtspiTable interface instance, or
871 * NULL if @obj does not implement #AtspiTable.
874 atspi_accessible_get_text (AtspiAccessible *accessible)
876 return (_atspi_accessible_is_a (accessible, atspi_interface_text) ?
881 * atspi_accessible_get_value:
882 * @obj: a pointer to the #AtspiAccessible instance to query.
884 * Get the #AtspiTable interface for an #AtspiAccessible.
886 * Returns: a pointer to an #AtspiTable interface instance, or
887 * NULL if @obj does not implement #AtspiTable.
890 atspi_accessible_get_value (AtspiAccessible *accessible)
892 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
897 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
900 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
902 relation_type_table [i] = SPI_RELATION_NULL;
904 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
905 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
906 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
907 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
908 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
909 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
910 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
911 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
912 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
913 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
914 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
915 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
916 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
917 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
918 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
919 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
920 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
921 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
925 static AccessibleRelationType
926 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
928 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
929 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
930 static gboolean is_initialized = FALSE;
931 AccessibleRelationType cspi_type;
934 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
936 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
938 cspi_type = cspi_relation_type_table [type];
942 cspi_type = SPI_RELATION_NULL;
947 * AccessibleRelation_getRelationType:
948 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
950 * Get the type of relationship represented by an #AtspiAccessibleRelation.
952 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
953 * encapsulated in this #AtspiAccessibleRelation object.
956 AccessibleRelationType
957 AccessibleRelation_getRelationType (AccessibleRelation *obj)
959 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
960 return cspi_relation_type_from_spi_relation_type (obj->type);
964 * AccessibleRelation_getNTargets:
965 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
967 * Get the number of objects which this relationship has as its
968 * target objects (the subject is the #AtspiAccessible from which this
969 * #AtspiAccessibleRelation originated).
971 * Returns: a short integer indicating how many target objects which the
972 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
976 AccessibleRelation_getNTargets (AccessibleRelation *obj)
978 cspi_return_val_if_fail (obj, -1);
979 return obj->targets->len;
983 * AccessibleRelation_getTarget:
984 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
985 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
987 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
989 * Returns: an #AtspiAccessible which is the @i-th object with which the
990 * originating #AtspiAccessible has relationship specified in the
991 * #AtspiAccessibleRelation object.
995 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
997 cspi_return_val_if_fail (obj, NULL);
999 if (i < 0 || i >= obj->targets->len) return NULL;
1000 return cspi_object_add (
1001 g_array_index (obj->targets, Accessible *, i));
1005 * AccessibleStateSet_ref:
1006 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1008 * Increment the reference count for an #AtspiAccessibleStateSet object.
1012 AccessibleStateSet_ref (AccessibleStateSet *obj)
1014 spi_state_set_cache_ref (obj);
1018 * AccessibleStateSet_unref:
1019 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1021 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1025 AccessibleStateSet_unref (AccessibleStateSet *obj)
1027 spi_state_set_cache_unref (obj);
1030 static Accessibility_StateType
1031 spi_state_to_dbus (AccessibleState state)
1033 #define MAP_STATE(a) \
1034 case SPI_STATE_##a: \
1035 return Accessibility_STATE_##a
1039 MAP_STATE (INVALID);
1043 MAP_STATE (CHECKED);
1044 MAP_STATE (DEFUNCT);
1045 MAP_STATE (EDITABLE);
1046 MAP_STATE (ENABLED);
1047 MAP_STATE (EXPANDABLE);
1048 MAP_STATE (EXPANDED);
1049 MAP_STATE (FOCUSABLE);
1050 MAP_STATE (FOCUSED);
1051 MAP_STATE (HORIZONTAL);
1052 MAP_STATE (ICONIFIED);
1054 MAP_STATE (MULTI_LINE);
1055 MAP_STATE (MULTISELECTABLE);
1057 MAP_STATE (PRESSED);
1058 MAP_STATE (RESIZABLE);
1059 MAP_STATE (SELECTABLE);
1060 MAP_STATE (SELECTED);
1061 MAP_STATE (SENSITIVE);
1062 MAP_STATE (SHOWING);
1063 MAP_STATE (SINGLE_LINE);
1065 MAP_STATE (TRANSIENT);
1066 MAP_STATE (VERTICAL);
1067 MAP_STATE (VISIBLE);
1068 MAP_STATE (MANAGES_DESCENDANTS);
1069 MAP_STATE (INDETERMINATE);
1070 MAP_STATE (TRUNCATED);
1071 MAP_STATE (REQUIRED);
1072 MAP_STATE (INVALID_ENTRY);
1073 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1074 MAP_STATE (SELECTABLE_TEXT);
1075 MAP_STATE (IS_DEFAULT);
1076 MAP_STATE (VISITED);
1078 return Accessibility_STATE_INVALID;
1084 * AccessibleStateSet_contains:
1085 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1086 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1089 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1090 * whether @state is true for the stateset in question.
1092 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1097 AccessibleStateSet_contains (AccessibleStateSet *obj,
1098 AccessibleState state)
1100 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1104 * AccessibleStateSet_add:
1105 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1106 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1108 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1109 * given state to #TRUE in the stateset.
1113 AccessibleStateSet_add (AccessibleStateSet *obj,
1114 AccessibleState state)
1116 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1120 * AccessibleStateSet_remove:
1121 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1122 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1124 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1125 * given state to #FALSE in the stateset.)
1129 AccessibleStateSet_remove (AccessibleStateSet *obj,
1130 AccessibleState state)
1132 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1136 * AccessibleStateSet_equals:
1137 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1138 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1140 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1141 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1142 * state variables at once; construct the target state then compare against it.
1144 * @see AccessibleStateSet_compare().
1146 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1151 AccessibleStateSet_equals (AccessibleStateSet *obj,
1152 AccessibleStateSet *obj2)
1162 cmp = spi_state_set_cache_xor (obj, obj2);
1163 eq = spi_state_set_cache_is_empty (cmp);
1164 spi_state_set_cache_unref (cmp);
1170 * AccessibleStateSet_compare:
1171 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1172 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1174 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1175 * Not Yet Implemented.
1177 * @see AccessibleStateSet_equals().
1179 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1180 * the two sets but not the other.
1183 AccessibleStateSet *
1184 AccessibleStateSet_compare (AccessibleStateSet *obj,
1185 AccessibleStateSet *obj2)
1187 return spi_state_set_cache_xor (obj, obj2);
1191 * AccessibleStateSet_isEmpty:
1192 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1194 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1196 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1201 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1203 return spi_state_set_cache_is_empty (obj);
1208 _atspi_accessible_is_a (AtspiAccessible *accessible,
1209 const char *interface_name)
1213 if (accessible == NULL)
1218 n = _atspi_get_iface_num (interface_name);
1219 if (n == -1) return FALSE;
1220 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1223 /* TODO: Move to a finalizer */
1225 cspi_object_destroyed (AtspiAccessible *accessible)
1230 /* TODO: Only fire if object not already marked defunct */
1231 memset (&e, 0, sizeof(e));
1232 e.type = "object:state-change:defunct";
1233 e.source = accessible;
1236 g_warning ("atspi: TODO: Finish events");
1237 atspi_dispatch_event (&e);
1240 g_free (accessible->path);
1242 if (accessible->states)
1243 g_object_unref (accessible->states);
1244 g_free (accessible->description);
1245 g_free (accessible->name);
1249 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1251 AtspiAccessible *accessible;
1253 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1254 g_return_val_if_fail (accessible != NULL, NULL);
1256 accessible->app = g_object_ref (app);
1257 accessible->path = g_strdup (path);