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"
27 G_DEFINE_TYPE (AtspiAccessible, atspi_accessible, G_TYPE_OBJECT)
30 atspi_accessible_init (AtspiAccessible *accessible)
35 atspi_accessible_finalize (GObject *obj)
37 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj);
40 g_object_unref (accessible->app);
42 g_free (accessible->path);
46 atspi_accessible_class_init (AtspiAccessibleClass *klass)
48 GObjectClass *object_class = G_OBJECT_CLASS (klass);
50 object_class->finalize = atspi_accessible_finalize;
53 /* TODO: Generate following from spec? */
54 static const char *role_names [] =
112 "table-column-header",
114 "tear-off-menu-item",
144 "input method window"
147 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
150 * atspi_role_get_name
151 * @role: an #AtspiAccessibleRole object to query.
153 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
154 * <em>DEPRECATED.</em>
156 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
159 atspi_role_get_name (AtspiRole role)
161 if (role < MAX_ROLES && role_names [(int) role])
163 return g_strdup (role_names [(int) role]);
167 return g_strdup ("");
172 * atspi_accessible_get_name:
173 * @obj: a pointer to the #AtspiAccessible object on which to operate.
175 * Get the name of an #AtspiAccessible object.
177 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
178 * or NULL on exception
181 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
183 g_return_val_if_fail (obj != NULL, NULL);
184 if (!(obj->cached_properties & ATSPI_CACHE_NAME))
186 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", NULL, "s", &obj->name))
188 obj->cached_properties |= ATSPI_CACHE_NAME;
190 return g_strdup (obj->name);
194 * atspi_accessible_get_description:
195 * @obj: a pointer to the #AtspiAccessible object on which to operate.
197 * Get the description of an #AtspiAccessible object.
199 * Returns: a UTF-8 string describing the #AtspiAccessible object.
200 * or NULL on exception
203 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
205 g_return_val_if_fail (obj != NULL, NULL);
207 if (!(obj->cached_properties & ATSPI_CACHE_DESCRIPTION))
209 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetDescription", NULL, "=>s", &obj->description))
211 obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
213 return g_strdup (obj->description);
216 const char *str_parent = "Parent";
219 * atspi_accessible_get_parent:
220 * @obj: a pointer to the #AtspiAccessible object to query.
222 * Get an #AtspiAccessible object's parent container.
224 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
225 * contains the given #AtspiAccessible instance, or NULL if the @obj
226 * has no parent container.
230 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
232 g_return_val_if_fail (obj != NULL, NULL);
234 if (!(obj->cached_properties & ATSPI_CACHE_PARENT))
236 DBusMessage *message, *reply;
237 DBusMessageIter iter, iter_variant;
238 message = dbus_message_new_method_call (obj->app->bus_name, obj->path,
239 DBUS_INTERFACE_PROPERTIES, "Get");
242 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
243 DBUS_TYPE_STRING, &str_parent,
245 reply = _atspi_dbus_send_with_reply_and_block (message);
247 (strcmp (dbus_message_get_signature (reply), "v") != 0))
249 dbus_message_iter_init (reply, &iter);
250 dbus_message_iter_recurse (&iter, &iter_variant);
251 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
252 dbus_message_unref (reply);
253 obj->cached_properties |= ATSPI_CACHE_PARENT;
255 if (!obj->accessible_parent)
257 return g_object_ref (obj->accessible_parent);
261 * atspi_accessible_get_child_count:
262 * @obj: a pointer to the #AtspiAccessible object on which to operate.
264 * Get the number of children contained by an #AtspiAccessible object.
266 * Returns: a #long indicating the number of #AtspiAccessible children
267 * contained by an #AtspiAccessible object. or -1 on exception
271 atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error)
273 g_return_val_if_fail (obj != NULL, -1);
275 /* TODO: MANAGES_DESCENDANTS */
276 return g_list_length (obj->children);
280 * atspi_accessible_get_child_at_index:
281 * @obj: a pointer to the #AtspiAccessible object on which to operate.
282 * @child_index: a #long indicating which child is specified.
284 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
286 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
287 * index @child_index. or NULL on exception
290 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
294 AtspiAccessible *child;
296 g_return_val_if_fail (obj != NULL, NULL);
298 /* TODO: ManagesDescendants */
299 child = g_list_nth_data (obj->children, child_index);
302 return g_object_ref (child);
306 * atspi_accessible_get_index_in_parent
307 * @obj: a pointer to the #AtspiAccessible object on which to operate.
309 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
311 * Returns: a #glong indicating the index of the #AtspiAccessible object
312 * in its parent (i.e. containing) #AtspiAccessible instance,
313 * or -1 if @obj has no containing parent or on exception.
316 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
321 g_return_val_if_fail (obj != NULL, -1);
322 if (!obj->accessible_parent) return -1;
323 l = obj->accessible_parent->children;
326 if (l->data == obj) return i;
337 } Accessibility_Relation;
340 * atspi_accessible_get_relation_set:
341 * @obj: a pointer to the #AtspiAccessible object on which to operate.
343 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
344 * relationships with other #AtspiAccessible objects.
346 * Returns: an array of #AtspiAccessibleRelation pointers. or NULL on exception
347 * TODO:: Annotate array type
350 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
354 GArray *relation_set;
356 g_return_val_if_fail (obj != NULL, NULL);
358 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetRelationSet", error, "=>a(uao)", &relation_set))
365 * atspi_accessible_get_role:
366 * @obj: a pointer to the #AtspiAccessible object on which to operate.
368 * Get the UI role of an #AtspiAccessible object.
369 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
371 * Returns: the #AtspiRole of the object.
375 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
377 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
379 if (!(obj->cached_properties & ATSPI_CACHE_ROLE))
382 /* TODO: Make this a property */
383 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
385 obj->cached_properties |= ATSPI_CACHE_ROLE;
393 * atspi_accessible_get_role_name:
394 * @obj: a pointer to the #AtspiAccessible object on which to operate.
396 * Get a UTF-8 string describing the role this object plays in the UI.
397 * This method will return useful values for roles that fall outside the
398 * enumeration used in atspi_accessible_getRole ().
400 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
404 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
408 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
410 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
416 * atspi_accessible_get_localized_role_name:
417 * @obj: a pointer to the #AtspiAccessible object on which to operate.
419 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
420 * This method will return useful values for roles that fall outside the
421 * enumeration used in atspi_accessible_getRole ().
423 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
427 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
431 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
433 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
439 * atspi_accessible_get_state_set:
440 * @obj: a pointer to the #AtspiAccessible object on which to operate.
442 * Gets the current state of an object.
444 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
445 * object's current state.
448 atspi_accessible_get_state_set (AtspiAccessible *obj)
454 * atspi_accessible_get_attributes:
455 * @obj: The #AtspiAccessible being queried.
457 * Get the #AttributeSet representing any assigned
458 * name-value pair attributes or annotations for this object.
459 * For typographic, textual, or textually-semantic attributes, see
460 * atspi_text_get_attributes instead.
462 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
463 * attributes assigned to this object.
466 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
468 DBusMessage *message;
471 g_return_val_if_fail (obj != NULL, NULL);
473 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
474 ret = _atspi_dbus_hash_from_message (message);
475 dbus_message_unref (message);
480 * atspi_accessible_get_attributes_as_array:
481 * @obj: The #AtspiAccessible being queried.
483 * Get the #AttributeSet representing any assigned
484 * name-value pair attributes or annotations for this object.
485 * For typographic, textual, or textually-semantic attributes, see
486 * atspi_text_get_attributes_as_array instead.
488 * Returns: (element-type gchar*) (transfer full): The name-value-pair
489 * attributes assigned to this object.
492 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
494 DBusMessage *message;
497 g_return_val_if_fail (obj != NULL, NULL);
499 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
500 ret = _atspi_dbus_attribute_array_from_message (message);
501 dbus_message_unref (message);
506 * atspi_accessible_get_host_application:
507 * @obj: The #AtspiAccessible being queried.
509 * Get the containing #AtspiApplication for an object.
511 * Returns: (transfer full): the containing AtspiApplication instance for
515 atspi_accessible_get_host_application (AtspiAccessible *obj, GError **error)
517 AtspiAccessible *parent;
521 parent = atspi_accessible_get_parent (obj, NULL);
522 if (!parent || parent == obj ||
523 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
529 #if 0 // TODO: interfaces */
530 /* Interface query methods */
533 * atspi_accessible_is_action:
534 * @obj: a pointer to the #AtspiAccessible instance to query.
536 * Query whether the specified #AtspiAccessible implements #AtspiAction.
538 * Returns: #TRUE if @obj implements the #AtspiAction interface,
542 atspi_accessible_is_action (AtspiAccessible *obj)
544 return _atspi_accessible_is_a (obj,
545 atspi_interface_action);
549 * atspi_accessible_is_application:
550 * @obj: a pointer to the #AtspiAccessible instance to query.
552 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
554 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
558 atspi_accessible_is_application (AtspiAccessible *obj)
560 return _atspi_accessible_is_a (obj,
561 atspi_interface_application);
565 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
567 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
568 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
572 atspi_accessible_is_collection (AtspiAccessible *obj)
575 g_warning ("Collections not implemented");
576 return _atspi_accessible_is_a (obj,
577 atspi_interface_collection);
584 * atspi_accessible_is_component:
585 * @obj: a pointer to the #AtspiAccessible instance to query.
587 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
589 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
593 atspi_accessible_is_component (AtspiAccessible *obj)
595 return _atspi_accessible_is_a (obj,
596 atspi_interface_component);
600 * atspi_accessible_is_document:
601 * @obj: a pointer to the #AtspiAccessible instance to query.
603 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
605 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
609 atspi_accessible_is_document (AtspiAccessible *obj)
611 return _atspi_accessible_is_a (obj,
612 atspi_interface_document);
616 * atspi_accessible_is_editable_text:
617 * @obj: a pointer to the #AtspiAccessible instance to query.
619 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
621 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
625 atspi_accessible_is_editable_text (AtspiAccessible *obj)
627 return _atspi_accessible_is_a (obj,
628 atspi_interface_editable_text);
632 * atspi_accessible_is_hypertext:
633 * @obj: a pointer to the #AtspiAccessible instance to query.
635 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
637 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
641 atspi_accessible_is_hypertext (AtspiAccessible *obj)
643 return _atspi_accessible_is_a (obj,
644 atspi_interface_hypertext);
648 * atspi_accessible_is_image:
649 * @obj: a pointer to the #AtspiAccessible instance to query.
651 * Query whether the specified #AtspiAccessible implements #AtspiImage.
653 * Returns: #TRUE if @obj implements the #AtspiImage interface,
657 atspi_accessible_is_image (AtspiAccessible *obj)
659 return _atspi_accessible_is_a (obj,
660 atspi_interface_image);
664 * atspi_accessible_is_selection:
665 * @obj: a pointer to the #AtspiAccessible instance to query.
667 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
669 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
673 atspi_accessible_is_selection (AtspiAccessible *obj)
675 return _atspi_accessible_is_a (obj,
676 atspi_interface_selection);
680 * atspi_accessible_is_table:
681 * @obj: a pointer to the #AtspiAccessible instance to query.
683 * Query whether the specified #AtspiAccessible implements #AtspiTable.
685 * Returns: #TRUE if @obj implements the #AtspiTable interface,
689 atspi_accessible_is_table (AtspiAccessible *obj)
691 return _atspi_accessible_is_a (obj,
692 atspi_interface_table);
696 * atspi_accessible_is_streamable_content:
697 * @obj: a pointer to the #AtspiAccessible instance to query.
699 * Query whether the specified #AtspiAccessible implements
700 * #AtspiStreamableContent.
702 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
706 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
709 return _atspi_accessible_is_a (obj,
710 atspi_interface_streamable_content);
712 g_warning ("Streamable content not implemented");
718 * atspi_accessible_is_text:
719 * @obj: a pointer to the #AtspiAccessible instance to query.
721 * Query whether the specified #AtspiAccessible implements #AtspiText.
723 * Returns: #TRUE if @obj implements the #AtspiText interface,
727 atspi_accessible_is_text (AtspiAccessible *obj)
729 return _atspi_accessible_is_a (obj,
730 atspi_interface_text);
734 * atspi_accessible_is_value:
735 * @obj: a pointer to the #AtspiAccessible instance to query.
737 * Query whether the specified #AtspiAccessible implements #AtspiValue.
739 * Returns: #TRUE if @obj implements the #AtspiValue interface,
743 atspi_accessible_is_value (AtspiAccessible *obj)
745 return _atspi_accessible_is_a (obj,
746 atspi_interface_value);
750 * atspi_accessible_get_application:
751 * @obj: a pointer to the #AtspiAccessible instance to query.
753 * Get the #AtspiApplication interface for an #AtspiAccessible.
755 * Returns: a pointer to an #AtspiApplication interface instance, or
756 * NULL if @obj does not implement #AtspiApplication.
759 atspi_accessible_get_application (AtspiAccessible *accessible)
761 return (_atspi_accessible_is_a (accessible, atspi_interface_application) ?
766 * atspi_accessible_get_action:
767 * @obj: a pointer to the #AtspiAccessible instance to query.
769 * Get the #AtspiAction interface for an #AtspiAccessible.
771 * Returns: a pointer to an #AtspiAction interface instance, or
772 * NULL if @obj does not implement #AtspiAction.
775 atspi_accessible_get_action (AtspiAccessible *accessible)
777 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
782 * atspi_accessible_get_collection:
783 * @obj: a pointer to the #AtspiAccessible instance to query.
785 * Get the #AtspiCollection interface for an #AtspiAccessible.
787 * Returns: a pointer to an #AtspiCollection interface instance, or
788 * NULL if @obj does not implement #AtspiCollection.
791 atspi_accessible_get_collection (AtspiAccessible *accessible)
793 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
799 * atspi_accessible_get_component:
800 * @obj: a pointer to the #AtspiAccessible instance to query.
802 * Get the #AtspiComponent interface for an #AtspiAccessible.
804 * Returns: a pointer to an #AtspiComponent interface instance, or
805 * NULL if @obj does not implement #AtspiComponent.
808 atspi_accessible_get_component (AtspiAccessible *accessible)
810 return (_atspi_accessible_is_a (accessible, atspi_interface_component) ?
811 ATSPI_COMPONENT (accessible) : NULL);
816 * atspi_accessible_get_document:
817 * @obj: a pointer to the #AtspiAccessible instance to query.
819 * Get the #AtspiDocument interface for an #AtspiAccessible.
821 * Returns: a pointer to an #AtspiDocument interface instance, or
822 * NULL if @obj does not implement #AtspiDocument.
825 atspi_accessible_get_document (AtspiAccessible *accessible)
827 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
832 * atspi_accessible_get_editable_text:
833 * @obj: a pointer to the #AtspiAccessible instance to query.
835 * Get the #AtspiEditableText interface for an #AtspiAccessible.
837 * Returns: a pointer to an #AtspiEditableText interface instance, or
838 * NULL if @obj does not implement #AtspiEditableText.
841 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
843 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
848 * atspi_accessible_get_hypertext:
849 * @obj: a pointer to the #AtspiAccessible instance to query.
851 * Get the #AtspiHypertext interface for an #AtspiAccessible.
853 * Returns: a pointer to an #AtspiHypertext interface instance, or
854 * NULL if @obj does not implement #AtspiHypertext.
857 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
859 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
864 * atspi_accessible_get_image:
865 * @obj: a pointer to the #AtspiAccessible instance to query.
867 * Get the #AtspiImage interface for an #AtspiAccessible.
869 * Returns: a pointer to an #AtspiImage interface instance, or
870 * NULL if @obj does not implement #AtspiImage.
873 atspi_accessible_get_image (AtspiAccessible *accessible)
875 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
880 * atspi_accessible_get_selection:
881 * @obj: a pointer to the #AtspiAccessible instance to query.
883 * Get the #AtspiSelection interface for an #AtspiAccessible.
885 * Returns: a pointer to an #AtspiSelection interface instance, or
886 * NULL if @obj does not implement #AtspiSelection.
889 atspi_accessible_get_selection (AtspiAccessible *accessible)
891 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
896 * atspi_accessible_get_streamable_content:
897 * @obj: a pointer to the #AtspiAccessible instance to query.
899 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
901 * Returns: a pointer to an #AtspiStreamableContent interface instance, or
902 * NULL if @obj does not implement #AtspiStreamableContent.
904 AtspiStreamableContent *
905 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
907 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
912 * atspi_accessible_get_table:
913 * @obj: a pointer to the #AtspiAccessible instance to query.
915 * Get the #AtspiTable interface for an #AtspiAccessible.
917 * Returns: a pointer to an #AtspiTable interface instance, or
918 * NULL if @obj does not implement #AtspiTable.
921 atspi_accessible_get_table (AtspiAccessible *accessible)
923 return (_atspi_accessible_is_a (accessible, atspi_interface_table) ?
928 * atspi_accessible_get_text:
929 * @obj: a pointer to the #AtspiAccessible instance to query.
931 * Get the #AtspiTable interface for an #AtspiAccessible.
933 * Returns: a pointer to an #AtspiTable interface instance, or
934 * NULL if @obj does not implement #AtspiTable.
937 atspi_accessible_get_text (AtspiAccessible *accessible)
939 return (_atspi_accessible_is_a (accessible, atspi_interface_text) ?
944 * atspi_accessible_get_value:
945 * @obj: a pointer to the #AtspiAccessible instance to query.
947 * Get the #AtspiTable interface for an #AtspiAccessible.
949 * Returns: a pointer to an #AtspiTable interface instance, or
950 * NULL if @obj does not implement #AtspiTable.
953 atspi_accessible_get_value (AtspiAccessible *accessible)
955 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
960 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
963 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
965 relation_type_table [i] = SPI_RELATION_NULL;
967 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
968 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
969 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
970 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
971 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
972 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
973 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
974 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
975 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
976 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
977 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
978 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
979 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
980 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
981 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
982 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
983 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
984 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
988 static AccessibleRelationType
989 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
991 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
992 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
993 static gboolean is_initialized = FALSE;
994 AccessibleRelationType cspi_type;
997 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
999 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
1001 cspi_type = cspi_relation_type_table [type];
1005 cspi_type = SPI_RELATION_NULL;
1010 * AccessibleRelation_getRelationType:
1011 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1013 * Get the type of relationship represented by an #AtspiAccessibleRelation.
1015 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
1016 * encapsulated in this #AtspiAccessibleRelation object.
1019 AccessibleRelationType
1020 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1022 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1023 return cspi_relation_type_from_spi_relation_type (obj->type);
1027 * AccessibleRelation_getNTargets:
1028 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1030 * Get the number of objects which this relationship has as its
1031 * target objects (the subject is the #AtspiAccessible from which this
1032 * #AtspiAccessibleRelation originated).
1034 * Returns: a short integer indicating how many target objects which the
1035 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
1036 * relationship with.
1039 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1041 cspi_return_val_if_fail (obj, -1);
1042 return obj->targets->len;
1046 * AccessibleRelation_getTarget:
1047 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1048 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1050 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
1052 * Returns: an #AtspiAccessible which is the @i-th object with which the
1053 * originating #AtspiAccessible has relationship specified in the
1054 * #AtspiAccessibleRelation object.
1058 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1060 cspi_return_val_if_fail (obj, NULL);
1062 if (i < 0 || i >= obj->targets->len) return NULL;
1063 return cspi_object_add (
1064 g_array_index (obj->targets, Accessible *, i));
1068 * AccessibleStateSet_ref:
1069 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1071 * Increment the reference count for an #AtspiAccessibleStateSet object.
1075 AccessibleStateSet_ref (AccessibleStateSet *obj)
1077 spi_state_set_cache_ref (obj);
1081 * AccessibleStateSet_unref:
1082 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1084 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1088 AccessibleStateSet_unref (AccessibleStateSet *obj)
1090 spi_state_set_cache_unref (obj);
1093 static Accessibility_StateType
1094 spi_state_to_dbus (AccessibleState state)
1096 #define MAP_STATE(a) \
1097 case SPI_STATE_##a: \
1098 return Accessibility_STATE_##a
1102 MAP_STATE (INVALID);
1106 MAP_STATE (CHECKED);
1107 MAP_STATE (DEFUNCT);
1108 MAP_STATE (EDITABLE);
1109 MAP_STATE (ENABLED);
1110 MAP_STATE (EXPANDABLE);
1111 MAP_STATE (EXPANDED);
1112 MAP_STATE (FOCUSABLE);
1113 MAP_STATE (FOCUSED);
1114 MAP_STATE (HORIZONTAL);
1115 MAP_STATE (ICONIFIED);
1117 MAP_STATE (MULTI_LINE);
1118 MAP_STATE (MULTISELECTABLE);
1120 MAP_STATE (PRESSED);
1121 MAP_STATE (RESIZABLE);
1122 MAP_STATE (SELECTABLE);
1123 MAP_STATE (SELECTED);
1124 MAP_STATE (SENSITIVE);
1125 MAP_STATE (SHOWING);
1126 MAP_STATE (SINGLE_LINE);
1128 MAP_STATE (TRANSIENT);
1129 MAP_STATE (VERTICAL);
1130 MAP_STATE (VISIBLE);
1131 MAP_STATE (MANAGES_DESCENDANTS);
1132 MAP_STATE (INDETERMINATE);
1133 MAP_STATE (TRUNCATED);
1134 MAP_STATE (REQUIRED);
1135 MAP_STATE (INVALID_ENTRY);
1136 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1137 MAP_STATE (SELECTABLE_TEXT);
1138 MAP_STATE (IS_DEFAULT);
1139 MAP_STATE (VISITED);
1141 return Accessibility_STATE_INVALID;
1147 * AccessibleStateSet_contains:
1148 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1149 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1152 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1153 * whether @state is true for the stateset in question.
1155 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1160 AccessibleStateSet_contains (AccessibleStateSet *obj,
1161 AccessibleState state)
1163 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1167 * AccessibleStateSet_add:
1168 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1169 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1171 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1172 * given state to #TRUE in the stateset.
1176 AccessibleStateSet_add (AccessibleStateSet *obj,
1177 AccessibleState state)
1179 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1183 * AccessibleStateSet_remove:
1184 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1185 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1187 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1188 * given state to #FALSE in the stateset.)
1192 AccessibleStateSet_remove (AccessibleStateSet *obj,
1193 AccessibleState state)
1195 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1199 * AccessibleStateSet_equals:
1200 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1201 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1203 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1204 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1205 * state variables at once; construct the target state then compare against it.
1207 * @see AccessibleStateSet_compare().
1209 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1214 AccessibleStateSet_equals (AccessibleStateSet *obj,
1215 AccessibleStateSet *obj2)
1225 cmp = spi_state_set_cache_xor (obj, obj2);
1226 eq = spi_state_set_cache_is_empty (cmp);
1227 spi_state_set_cache_unref (cmp);
1233 * AccessibleStateSet_compare:
1234 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1235 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1237 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1238 * Not Yet Implemented.
1240 * @see AccessibleStateSet_equals().
1242 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1243 * the two sets but not the other.
1246 AccessibleStateSet *
1247 AccessibleStateSet_compare (AccessibleStateSet *obj,
1248 AccessibleStateSet *obj2)
1250 return spi_state_set_cache_xor (obj, obj2);
1254 * AccessibleStateSet_isEmpty:
1255 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1257 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1259 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1264 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1266 return spi_state_set_cache_is_empty (obj);
1271 _atspi_accessible_is_a (AtspiAccessible *accessible,
1272 const char *interface_name)
1276 if (accessible == NULL)
1281 n = _atspi_get_iface_num (interface_name);
1282 if (n == -1) return FALSE;
1283 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1286 /* TODO: Move to a finalizer */
1288 cspi_object_destroyed (AtspiAccessible *accessible)
1293 /* TODO: Only fire if object not already marked defunct */
1294 memset (&e, 0, sizeof (e));
1295 e.type = "object:state-change:defunct";
1296 e.source = accessible;
1299 _atspi_send_event (&e);
1301 g_free (accessible->path);
1303 if (accessible->states)
1304 g_object_unref (accessible->states);
1305 g_free (accessible->description);
1306 g_free (accessible->name);
1310 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1312 AtspiAccessible *accessible;
1314 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1315 g_return_val_if_fail (accessible != NULL, NULL);
1317 accessible->app = g_object_ref (app);
1318 accessible->path = g_strdup (path);