2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 #include "atspi-private.h"
28 atspi_component_interface_init (AtspiComponent *component)
33 atspi_table_interface_init (AtspiTable *table)
38 atspi_text_interface_init (AtspiText *text)
42 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, G_TYPE_OBJECT,
43 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
44 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
45 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init))
48 atspi_accessible_init (AtspiAccessible *accessible)
53 atspi_accessible_finalize (GObject *obj)
55 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj);
58 g_object_unref (accessible->app);
60 g_free (accessible->path);
64 atspi_accessible_class_init (AtspiAccessibleClass *klass)
66 GObjectClass *object_class = G_OBJECT_CLASS (klass);
68 object_class->finalize = atspi_accessible_finalize;
71 /* TODO: Generate following from spec? */
72 static const char *role_names [] =
130 "table-column-header",
132 "tear-off-menu-item",
162 "input method window"
165 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
168 * atspi_role_get_name
169 * @role: an #AtspiAccessibleRole object to query.
171 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
172 * <em>DEPRECATED.</em>
174 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
177 atspi_role_get_name (AtspiRole role)
179 if (role < MAX_ROLES && role_names [(int) role])
181 return g_strdup (role_names [(int) role]);
185 return g_strdup ("");
190 * atspi_accessible_get_name:
191 * @obj: a pointer to the #AtspiAccessible object on which to operate.
193 * Get the name of an #AtspiAccessible object.
195 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
196 * or NULL on exception
199 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
201 g_return_val_if_fail (obj != NULL, NULL);
202 if (!(obj->cached_properties & ATSPI_CACHE_NAME))
204 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", NULL, "s", &obj->name))
206 obj->cached_properties |= ATSPI_CACHE_NAME;
208 return g_strdup (obj->name);
212 * atspi_accessible_get_description:
213 * @obj: a pointer to the #AtspiAccessible object on which to operate.
215 * Get the description of an #AtspiAccessible object.
217 * Returns: a UTF-8 string describing the #AtspiAccessible object.
218 * or NULL on exception
221 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
223 g_return_val_if_fail (obj != NULL, NULL);
225 if (!(obj->cached_properties & ATSPI_CACHE_DESCRIPTION))
227 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetDescription", NULL, "=>s", &obj->description))
229 obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
231 return g_strdup (obj->description);
234 const char *str_parent = "Parent";
237 * atspi_accessible_get_parent:
238 * @obj: a pointer to the #AtspiAccessible object to query.
240 * Get an #AtspiAccessible object's parent container.
242 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
243 * contains the given #AtspiAccessible instance, or NULL if the @obj
244 * has no parent container.
248 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
250 g_return_val_if_fail (obj != NULL, NULL);
252 if (!(obj->cached_properties & ATSPI_CACHE_PARENT))
254 DBusMessage *message, *reply;
255 DBusMessageIter iter, iter_variant;
256 message = dbus_message_new_method_call (obj->app->bus_name, obj->path,
257 DBUS_INTERFACE_PROPERTIES, "Get");
260 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
261 DBUS_TYPE_STRING, &str_parent,
263 reply = _atspi_dbus_send_with_reply_and_block (message);
265 (strcmp (dbus_message_get_signature (reply), "v") != 0))
267 dbus_message_iter_init (reply, &iter);
268 dbus_message_iter_recurse (&iter, &iter_variant);
269 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
270 dbus_message_unref (reply);
271 obj->cached_properties |= ATSPI_CACHE_PARENT;
273 if (!obj->accessible_parent)
275 return g_object_ref (obj->accessible_parent);
279 * atspi_accessible_get_child_count:
280 * @obj: a pointer to the #AtspiAccessible object on which to operate.
282 * Get the number of children contained by an #AtspiAccessible object.
284 * Returns: a #long indicating the number of #AtspiAccessible children
285 * contained by an #AtspiAccessible object. or -1 on exception
289 atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error)
291 g_return_val_if_fail (obj != NULL, -1);
293 /* TODO: MANAGES_DESCENDANTS */
294 return g_list_length (obj->children);
298 * atspi_accessible_get_child_at_index:
299 * @obj: a pointer to the #AtspiAccessible object on which to operate.
300 * @child_index: a #long indicating which child is specified.
302 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
304 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
305 * index @child_index. or NULL on exception
308 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
312 AtspiAccessible *child;
314 g_return_val_if_fail (obj != NULL, NULL);
316 /* TODO: ManagesDescendants */
317 child = g_list_nth_data (obj->children, child_index);
320 return g_object_ref (child);
324 * atspi_accessible_get_index_in_parent
325 * @obj: a pointer to the #AtspiAccessible object on which to operate.
327 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
329 * Returns: a #glong indicating the index of the #AtspiAccessible object
330 * in its parent (i.e. containing) #AtspiAccessible instance,
331 * or -1 if @obj has no containing parent or on exception.
334 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
339 g_return_val_if_fail (obj != NULL, -1);
340 if (!obj->accessible_parent) return -1;
341 l = obj->accessible_parent->children;
344 if (l->data == obj) return i;
355 } Accessibility_Relation;
358 * atspi_accessible_get_relation_set:
359 * @obj: a pointer to the #AtspiAccessible object on which to operate.
361 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
362 * relationships with other #AtspiAccessible objects.
364 * Returns: an array of #AtspiAccessibleRelation pointers. or NULL on exception
365 * TODO:: Annotate array type
368 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
372 GArray *relation_set;
374 g_return_val_if_fail (obj != NULL, NULL);
376 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetRelationSet", error, "=>a(uao)", &relation_set))
383 * atspi_accessible_get_role:
384 * @obj: a pointer to the #AtspiAccessible object on which to operate.
386 * Get the UI role of an #AtspiAccessible object.
387 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
389 * Returns: the #AtspiRole of the object.
393 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
395 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
397 if (!(obj->cached_properties & ATSPI_CACHE_ROLE))
400 /* TODO: Make this a property */
401 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
403 obj->cached_properties |= ATSPI_CACHE_ROLE;
411 * atspi_accessible_get_role_name:
412 * @obj: a pointer to the #AtspiAccessible object on which to operate.
414 * Get a UTF-8 string describing the role this object plays in the UI.
415 * This method will return useful values for roles that fall outside the
416 * enumeration used in atspi_accessible_getRole ().
418 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
422 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
426 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
428 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
434 * atspi_accessible_get_localized_role_name:
435 * @obj: a pointer to the #AtspiAccessible object on which to operate.
437 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
438 * This method will return useful values for roles that fall outside the
439 * enumeration used in atspi_accessible_getRole ().
441 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
445 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
449 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
451 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
457 * atspi_accessible_get_state_set:
458 * @obj: a pointer to the #AtspiAccessible object on which to operate.
460 * Gets the current state of an object.
462 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
463 * object's current state.
466 atspi_accessible_get_state_set (AtspiAccessible *obj)
472 * atspi_accessible_get_attributes:
473 * @obj: The #AtspiAccessible being queried.
475 * Get the #AttributeSet representing any assigned
476 * name-value pair attributes or annotations for this object.
477 * For typographic, textual, or textually-semantic attributes, see
478 * atspi_text_get_attributes instead.
480 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
481 * attributes assigned to this object.
484 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
486 DBusMessage *message;
489 g_return_val_if_fail (obj != NULL, NULL);
491 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
492 ret = _atspi_dbus_hash_from_message (message);
493 dbus_message_unref (message);
498 * atspi_accessible_get_attributes_as_array:
499 * @obj: The #AtspiAccessible being queried.
501 * Get the #AttributeSet representing any assigned
502 * name-value pair attributes or annotations for this object.
503 * For typographic, textual, or textually-semantic attributes, see
504 * atspi_text_get_attributes_as_array instead.
506 * Returns: (element-type gchar*) (transfer full): The name-value-pair
507 * attributes assigned to this object.
510 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
512 DBusMessage *message;
515 g_return_val_if_fail (obj != NULL, NULL);
517 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
518 ret = _atspi_dbus_attribute_array_from_message (message);
519 dbus_message_unref (message);
524 * atspi_accessible_get_host_application:
525 * @obj: The #AtspiAccessible being queried.
527 * Get the containing #AtspiApplication for an object.
529 * Returns: (transfer full): the containing AtspiApplication instance for
533 atspi_accessible_get_host_application (AtspiAccessible *obj, GError **error)
535 AtspiAccessible *parent;
539 parent = atspi_accessible_get_parent (obj, NULL);
540 if (!parent || parent == obj ||
541 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
547 #if 0 // TODO: interfaces */
548 /* Interface query methods */
551 * atspi_accessible_is_action:
552 * @obj: a pointer to the #AtspiAccessible instance to query.
554 * Query whether the specified #AtspiAccessible implements #AtspiAction.
556 * Returns: #TRUE if @obj implements the #AtspiAction interface,
560 atspi_accessible_is_action (AtspiAccessible *obj)
562 return _atspi_accessible_is_a (obj,
563 atspi_interface_action);
567 * atspi_accessible_is_application:
568 * @obj: a pointer to the #AtspiAccessible instance to query.
570 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
572 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
576 atspi_accessible_is_application (AtspiAccessible *obj)
578 return _atspi_accessible_is_a (obj,
579 atspi_interface_application);
583 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
585 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
586 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
590 atspi_accessible_is_collection (AtspiAccessible *obj)
593 g_warning ("Collections not implemented");
594 return _atspi_accessible_is_a (obj,
595 atspi_interface_collection);
602 * atspi_accessible_is_component:
603 * @obj: a pointer to the #AtspiAccessible instance to query.
605 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
607 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
611 atspi_accessible_is_component (AtspiAccessible *obj)
613 return _atspi_accessible_is_a (obj,
614 atspi_interface_component);
618 * atspi_accessible_is_document:
619 * @obj: a pointer to the #AtspiAccessible instance to query.
621 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
623 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
627 atspi_accessible_is_document (AtspiAccessible *obj)
629 return _atspi_accessible_is_a (obj,
630 atspi_interface_document);
634 * atspi_accessible_is_editable_text:
635 * @obj: a pointer to the #AtspiAccessible instance to query.
637 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
639 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
643 atspi_accessible_is_editable_text (AtspiAccessible *obj)
645 return _atspi_accessible_is_a (obj,
646 atspi_interface_editable_text);
650 * atspi_accessible_is_hypertext:
651 * @obj: a pointer to the #AtspiAccessible instance to query.
653 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
655 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
659 atspi_accessible_is_hypertext (AtspiAccessible *obj)
661 return _atspi_accessible_is_a (obj,
662 atspi_interface_hypertext);
666 * atspi_accessible_is_image:
667 * @obj: a pointer to the #AtspiAccessible instance to query.
669 * Query whether the specified #AtspiAccessible implements #AtspiImage.
671 * Returns: #TRUE if @obj implements the #AtspiImage interface,
675 atspi_accessible_is_image (AtspiAccessible *obj)
677 return _atspi_accessible_is_a (obj,
678 atspi_interface_image);
682 * atspi_accessible_is_selection:
683 * @obj: a pointer to the #AtspiAccessible instance to query.
685 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
687 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
691 atspi_accessible_is_selection (AtspiAccessible *obj)
693 return _atspi_accessible_is_a (obj,
694 atspi_interface_selection);
698 * atspi_accessible_is_table:
699 * @obj: a pointer to the #AtspiAccessible instance to query.
701 * Query whether the specified #AtspiAccessible implements #AtspiTable.
703 * Returns: #TRUE if @obj implements the #AtspiTable interface,
707 atspi_accessible_is_table (AtspiAccessible *obj)
709 return _atspi_accessible_is_a (obj,
710 atspi_interface_table);
714 * atspi_accessible_is_streamable_content:
715 * @obj: a pointer to the #AtspiAccessible instance to query.
717 * Query whether the specified #AtspiAccessible implements
718 * #AtspiStreamableContent.
720 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
724 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
727 return _atspi_accessible_is_a (obj,
728 atspi_interface_streamable_content);
730 g_warning ("Streamable content not implemented");
736 * atspi_accessible_is_text:
737 * @obj: a pointer to the #AtspiAccessible instance to query.
739 * Query whether the specified #AtspiAccessible implements #AtspiText.
741 * Returns: #TRUE if @obj implements the #AtspiText interface,
745 atspi_accessible_is_text (AtspiAccessible *obj)
747 return _atspi_accessible_is_a (obj,
748 atspi_interface_text);
752 * atspi_accessible_is_value:
753 * @obj: a pointer to the #AtspiAccessible instance to query.
755 * Query whether the specified #AtspiAccessible implements #AtspiValue.
757 * Returns: #TRUE if @obj implements the #AtspiValue interface,
761 atspi_accessible_is_value (AtspiAccessible *obj)
763 return _atspi_accessible_is_a (obj,
764 atspi_interface_value);
768 * atspi_accessible_get_application:
769 * @obj: a pointer to the #AtspiAccessible instance to query.
771 * Get the #AtspiApplication interface for an #AtspiAccessible.
773 * Returns: a pointer to an #AtspiApplication interface instance, or
774 * NULL if @obj does not implement #AtspiApplication.
777 atspi_accessible_get_application (AtspiAccessible *accessible)
779 return (_atspi_accessible_is_a (accessible, atspi_interface_application) ?
784 * atspi_accessible_get_action:
785 * @obj: a pointer to the #AtspiAccessible instance to query.
787 * Get the #AtspiAction interface for an #AtspiAccessible.
789 * Returns: a pointer to an #AtspiAction interface instance, or
790 * NULL if @obj does not implement #AtspiAction.
793 atspi_accessible_get_action (AtspiAccessible *accessible)
795 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
800 * atspi_accessible_get_collection:
801 * @obj: a pointer to the #AtspiAccessible instance to query.
803 * Get the #AtspiCollection interface for an #AtspiAccessible.
805 * Returns: a pointer to an #AtspiCollection interface instance, or
806 * NULL if @obj does not implement #AtspiCollection.
809 atspi_accessible_get_collection (AtspiAccessible *accessible)
811 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
817 * atspi_accessible_get_component:
818 * @obj: a pointer to the #AtspiAccessible instance to query.
820 * Get the #AtspiComponent interface for an #AtspiAccessible.
822 * Returns: (transfer full): a pointer to an #AtspiComponent interface
823 * instance, or NULL if @obj does not implement #AtspiComponent.
826 atspi_accessible_get_component (AtspiAccessible *obj)
828 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
829 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
834 * atspi_accessible_get_document:
835 * @obj: a pointer to the #AtspiAccessible instance to query.
837 * Get the #AtspiDocument interface for an #AtspiAccessible.
839 * Returns: a pointer to an #AtspiDocument interface instance, or
840 * NULL if @obj does not implement #AtspiDocument.
843 atspi_accessible_get_document (AtspiAccessible *accessible)
845 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
850 * atspi_accessible_get_editable_text:
851 * @obj: a pointer to the #AtspiAccessible instance to query.
853 * Get the #AtspiEditableText interface for an #AtspiAccessible.
855 * Returns: a pointer to an #AtspiEditableText interface instance, or
856 * NULL if @obj does not implement #AtspiEditableText.
859 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
861 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
866 * atspi_accessible_get_hypertext:
867 * @obj: a pointer to the #AtspiAccessible instance to query.
869 * Get the #AtspiHypertext interface for an #AtspiAccessible.
871 * Returns: a pointer to an #AtspiHypertext interface instance, or
872 * NULL if @obj does not implement #AtspiHypertext.
875 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
877 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
882 * atspi_accessible_get_image:
883 * @obj: a pointer to the #AtspiAccessible instance to query.
885 * Get the #AtspiImage interface for an #AtspiAccessible.
887 * Returns: a pointer to an #AtspiImage interface instance, or
888 * NULL if @obj does not implement #AtspiImage.
891 atspi_accessible_get_image (AtspiAccessible *accessible)
893 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
898 * atspi_accessible_get_selection:
899 * @obj: a pointer to the #AtspiAccessible instance to query.
901 * Get the #AtspiSelection interface for an #AtspiAccessible.
903 * Returns: a pointer to an #AtspiSelection interface instance, or
904 * NULL if @obj does not implement #AtspiSelection.
907 atspi_accessible_get_selection (AtspiAccessible *accessible)
909 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
914 * atspi_accessible_get_streamable_content:
915 * @obj: a pointer to the #AtspiAccessible instance to query.
917 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
919 * Returns: a pointer to an #AtspiStreamableContent interface instance, or
920 * NULL if @obj does not implement #AtspiStreamableContent.
922 AtspiStreamableContent *
923 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
925 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
931 * atspi_accessible_get_table:
932 * @obj: a pointer to the #AtspiAccessible instance to query.
934 * Get the #AtspiTable interface for an #AtspiAccessible.
936 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
937 * NULL if @obj does not implement #AtspiTable.
940 atspi_accessible_get_table (AtspiAccessible *obj)
942 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
943 g_object_ref (ATSPI_TABLE (obj)) : NULL);
947 * atspi_accessible_get_text:
948 * @obj: a pointer to the #AtspiAccessible instance to query.
950 * Get the #AtspiTable interface for an #AtspiAccessible.
952 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
953 * NULL if @obj does not implement #AtspiTable.
956 atspi_accessible_get_text (AtspiAccessible *obj)
958 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
959 g_object_ref (ATSPI_TEXT (obj)) : NULL);
964 * atspi_accessible_get_value:
965 * @obj: a pointer to the #AtspiAccessible instance to query.
967 * Get the #AtspiTable interface for an #AtspiAccessible.
969 * Returns: a pointer to an #AtspiTable interface instance, or
970 * NULL if @obj does not implement #AtspiTable.
973 atspi_accessible_get_value (AtspiAccessible *accessible)
975 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
980 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
983 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
985 relation_type_table [i] = SPI_RELATION_NULL;
987 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
988 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
989 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
990 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
991 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
992 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
993 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
994 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
995 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
996 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
997 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
998 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
999 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
1000 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
1001 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
1002 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
1003 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
1004 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
1008 static AccessibleRelationType
1009 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
1011 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
1012 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
1013 static gboolean is_initialized = FALSE;
1014 AccessibleRelationType cspi_type;
1015 if (!is_initialized)
1017 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
1019 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
1021 cspi_type = cspi_relation_type_table [type];
1025 cspi_type = SPI_RELATION_NULL;
1030 * AccessibleRelation_getRelationType:
1031 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1033 * Get the type of relationship represented by an #AtspiAccessibleRelation.
1035 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
1036 * encapsulated in this #AtspiAccessibleRelation object.
1039 AccessibleRelationType
1040 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1042 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1043 return cspi_relation_type_from_spi_relation_type (obj->type);
1047 * AccessibleRelation_getNTargets:
1048 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1050 * Get the number of objects which this relationship has as its
1051 * target objects (the subject is the #AtspiAccessible from which this
1052 * #AtspiAccessibleRelation originated).
1054 * Returns: a short integer indicating how many target objects which the
1055 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
1056 * relationship with.
1059 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1061 cspi_return_val_if_fail (obj, -1);
1062 return obj->targets->len;
1066 * AccessibleRelation_getTarget:
1067 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1068 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1070 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
1072 * Returns: an #AtspiAccessible which is the @i-th object with which the
1073 * originating #AtspiAccessible has relationship specified in the
1074 * #AtspiAccessibleRelation object.
1078 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1080 cspi_return_val_if_fail (obj, NULL);
1082 if (i < 0 || i >= obj->targets->len) return NULL;
1083 return cspi_object_add (
1084 g_array_index (obj->targets, Accessible *, i));
1088 * AccessibleStateSet_ref:
1089 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1091 * Increment the reference count for an #AtspiAccessibleStateSet object.
1095 AccessibleStateSet_ref (AccessibleStateSet *obj)
1097 spi_state_set_cache_ref (obj);
1101 * AccessibleStateSet_unref:
1102 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1104 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1108 AccessibleStateSet_unref (AccessibleStateSet *obj)
1110 spi_state_set_cache_unref (obj);
1113 static Accessibility_StateType
1114 spi_state_to_dbus (AccessibleState state)
1116 #define MAP_STATE(a) \
1117 case SPI_STATE_##a: \
1118 return Accessibility_STATE_##a
1122 MAP_STATE (INVALID);
1126 MAP_STATE (CHECKED);
1127 MAP_STATE (DEFUNCT);
1128 MAP_STATE (EDITABLE);
1129 MAP_STATE (ENABLED);
1130 MAP_STATE (EXPANDABLE);
1131 MAP_STATE (EXPANDED);
1132 MAP_STATE (FOCUSABLE);
1133 MAP_STATE (FOCUSED);
1134 MAP_STATE (HORIZONTAL);
1135 MAP_STATE (ICONIFIED);
1137 MAP_STATE (MULTI_LINE);
1138 MAP_STATE (MULTISELECTABLE);
1140 MAP_STATE (PRESSED);
1141 MAP_STATE (RESIZABLE);
1142 MAP_STATE (SELECTABLE);
1143 MAP_STATE (SELECTED);
1144 MAP_STATE (SENSITIVE);
1145 MAP_STATE (SHOWING);
1146 MAP_STATE (SINGLE_LINE);
1148 MAP_STATE (TRANSIENT);
1149 MAP_STATE (VERTICAL);
1150 MAP_STATE (VISIBLE);
1151 MAP_STATE (MANAGES_DESCENDANTS);
1152 MAP_STATE (INDETERMINATE);
1153 MAP_STATE (TRUNCATED);
1154 MAP_STATE (REQUIRED);
1155 MAP_STATE (INVALID_ENTRY);
1156 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1157 MAP_STATE (SELECTABLE_TEXT);
1158 MAP_STATE (IS_DEFAULT);
1159 MAP_STATE (VISITED);
1161 return Accessibility_STATE_INVALID;
1167 * AccessibleStateSet_contains:
1168 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1169 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1172 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1173 * whether @state is true for the stateset in question.
1175 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1180 AccessibleStateSet_contains (AccessibleStateSet *obj,
1181 AccessibleState state)
1183 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1187 * AccessibleStateSet_add:
1188 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1189 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1191 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1192 * given state to #TRUE in the stateset.
1196 AccessibleStateSet_add (AccessibleStateSet *obj,
1197 AccessibleState state)
1199 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1203 * AccessibleStateSet_remove:
1204 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1205 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1207 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1208 * given state to #FALSE in the stateset.)
1212 AccessibleStateSet_remove (AccessibleStateSet *obj,
1213 AccessibleState state)
1215 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1219 * AccessibleStateSet_equals:
1220 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1221 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1223 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1224 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1225 * state variables at once; construct the target state then compare against it.
1227 * @see AccessibleStateSet_compare().
1229 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1234 AccessibleStateSet_equals (AccessibleStateSet *obj,
1235 AccessibleStateSet *obj2)
1245 cmp = spi_state_set_cache_xor (obj, obj2);
1246 eq = spi_state_set_cache_is_empty (cmp);
1247 spi_state_set_cache_unref (cmp);
1253 * AccessibleStateSet_compare:
1254 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1255 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1257 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1258 * Not Yet Implemented.
1260 * @see AccessibleStateSet_equals().
1262 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1263 * the two sets but not the other.
1266 AccessibleStateSet *
1267 AccessibleStateSet_compare (AccessibleStateSet *obj,
1268 AccessibleStateSet *obj2)
1270 return spi_state_set_cache_xor (obj, obj2);
1274 * AccessibleStateSet_isEmpty:
1275 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1277 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1279 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1284 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1286 return spi_state_set_cache_is_empty (obj);
1291 _atspi_accessible_is_a (AtspiAccessible *accessible,
1292 const char *interface_name)
1296 if (accessible == NULL)
1301 n = _atspi_get_iface_num (interface_name);
1302 if (n == -1) return FALSE;
1303 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1306 /* TODO: Move to a finalizer */
1308 cspi_object_destroyed (AtspiAccessible *accessible)
1313 /* TODO: Only fire if object not already marked defunct */
1314 memset (&e, 0, sizeof (e));
1315 e.type = "object:state-change:defunct";
1316 e.source = accessible;
1319 _atspi_send_event (&e);
1321 g_free (accessible->path);
1323 if (accessible->states)
1324 g_object_unref (accessible->states);
1325 g_free (accessible->description);
1326 g_free (accessible->name);
1330 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1332 AtspiAccessible *accessible;
1334 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1335 g_return_val_if_fail (accessible != NULL, NULL);
1337 accessible->app = g_object_ref (app);
1338 accessible->path = g_strdup (path);