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)
32 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, G_TYPE_OBJECT,
33 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init))
36 atspi_accessible_init (AtspiAccessible *accessible)
41 atspi_accessible_finalize (GObject *obj)
43 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj);
46 g_object_unref (accessible->app);
48 g_free (accessible->path);
52 atspi_accessible_class_init (AtspiAccessibleClass *klass)
54 GObjectClass *object_class = G_OBJECT_CLASS (klass);
56 object_class->finalize = atspi_accessible_finalize;
59 /* TODO: Generate following from spec? */
60 static const char *role_names [] =
118 "table-column-header",
120 "tear-off-menu-item",
150 "input method window"
153 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
156 * atspi_role_get_name
157 * @role: an #AtspiAccessibleRole object to query.
159 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
160 * <em>DEPRECATED.</em>
162 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
165 atspi_role_get_name (AtspiRole role)
167 if (role < MAX_ROLES && role_names [(int) role])
169 return g_strdup (role_names [(int) role]);
173 return g_strdup ("");
178 * atspi_accessible_get_name:
179 * @obj: a pointer to the #AtspiAccessible object on which to operate.
181 * Get the name of an #AtspiAccessible object.
183 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
184 * or NULL on exception
187 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
189 g_return_val_if_fail (obj != NULL, NULL);
190 if (!(obj->cached_properties & ATSPI_CACHE_NAME))
192 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", NULL, "s", &obj->name))
194 obj->cached_properties |= ATSPI_CACHE_NAME;
196 return g_strdup (obj->name);
200 * atspi_accessible_get_description:
201 * @obj: a pointer to the #AtspiAccessible object on which to operate.
203 * Get the description of an #AtspiAccessible object.
205 * Returns: a UTF-8 string describing the #AtspiAccessible object.
206 * or NULL on exception
209 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
211 g_return_val_if_fail (obj != NULL, NULL);
213 if (!(obj->cached_properties & ATSPI_CACHE_DESCRIPTION))
215 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetDescription", NULL, "=>s", &obj->description))
217 obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
219 return g_strdup (obj->description);
222 const char *str_parent = "Parent";
225 * atspi_accessible_get_parent:
226 * @obj: a pointer to the #AtspiAccessible object to query.
228 * Get an #AtspiAccessible object's parent container.
230 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
231 * contains the given #AtspiAccessible instance, or NULL if the @obj
232 * has no parent container.
236 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
238 g_return_val_if_fail (obj != NULL, NULL);
240 if (!(obj->cached_properties & ATSPI_CACHE_PARENT))
242 DBusMessage *message, *reply;
243 DBusMessageIter iter, iter_variant;
244 message = dbus_message_new_method_call (obj->app->bus_name, obj->path,
245 DBUS_INTERFACE_PROPERTIES, "Get");
248 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
249 DBUS_TYPE_STRING, &str_parent,
251 reply = _atspi_dbus_send_with_reply_and_block (message);
253 (strcmp (dbus_message_get_signature (reply), "v") != 0))
255 dbus_message_iter_init (reply, &iter);
256 dbus_message_iter_recurse (&iter, &iter_variant);
257 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
258 dbus_message_unref (reply);
259 obj->cached_properties |= ATSPI_CACHE_PARENT;
261 if (!obj->accessible_parent)
263 return g_object_ref (obj->accessible_parent);
267 * atspi_accessible_get_child_count:
268 * @obj: a pointer to the #AtspiAccessible object on which to operate.
270 * Get the number of children contained by an #AtspiAccessible object.
272 * Returns: a #long indicating the number of #AtspiAccessible children
273 * contained by an #AtspiAccessible object. or -1 on exception
277 atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error)
279 g_return_val_if_fail (obj != NULL, -1);
281 /* TODO: MANAGES_DESCENDANTS */
282 return g_list_length (obj->children);
286 * atspi_accessible_get_child_at_index:
287 * @obj: a pointer to the #AtspiAccessible object on which to operate.
288 * @child_index: a #long indicating which child is specified.
290 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
292 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
293 * index @child_index. or NULL on exception
296 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
300 AtspiAccessible *child;
302 g_return_val_if_fail (obj != NULL, NULL);
304 /* TODO: ManagesDescendants */
305 child = g_list_nth_data (obj->children, child_index);
308 return g_object_ref (child);
312 * atspi_accessible_get_index_in_parent
313 * @obj: a pointer to the #AtspiAccessible object on which to operate.
315 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
317 * Returns: a #glong indicating the index of the #AtspiAccessible object
318 * in its parent (i.e. containing) #AtspiAccessible instance,
319 * or -1 if @obj has no containing parent or on exception.
322 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
327 g_return_val_if_fail (obj != NULL, -1);
328 if (!obj->accessible_parent) return -1;
329 l = obj->accessible_parent->children;
332 if (l->data == obj) return i;
343 } Accessibility_Relation;
346 * atspi_accessible_get_relation_set:
347 * @obj: a pointer to the #AtspiAccessible object on which to operate.
349 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
350 * relationships with other #AtspiAccessible objects.
352 * Returns: an array of #AtspiAccessibleRelation pointers. or NULL on exception
353 * TODO:: Annotate array type
356 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
360 GArray *relation_set;
362 g_return_val_if_fail (obj != NULL, NULL);
364 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetRelationSet", error, "=>a(uao)", &relation_set))
371 * atspi_accessible_get_role:
372 * @obj: a pointer to the #AtspiAccessible object on which to operate.
374 * Get the UI role of an #AtspiAccessible object.
375 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
377 * Returns: the #AtspiRole of the object.
381 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
383 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
385 if (!(obj->cached_properties & ATSPI_CACHE_ROLE))
388 /* TODO: Make this a property */
389 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
391 obj->cached_properties |= ATSPI_CACHE_ROLE;
399 * atspi_accessible_get_role_name:
400 * @obj: a pointer to the #AtspiAccessible object on which to operate.
402 * Get a UTF-8 string describing the role this object plays in the UI.
403 * This method will return useful values for roles that fall outside the
404 * enumeration used in atspi_accessible_getRole ().
406 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
410 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
414 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
416 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
422 * atspi_accessible_get_localized_role_name:
423 * @obj: a pointer to the #AtspiAccessible object on which to operate.
425 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
426 * This method will return useful values for roles that fall outside the
427 * enumeration used in atspi_accessible_getRole ().
429 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
433 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
437 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
439 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
445 * atspi_accessible_get_state_set:
446 * @obj: a pointer to the #AtspiAccessible object on which to operate.
448 * Gets the current state of an object.
450 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
451 * object's current state.
454 atspi_accessible_get_state_set (AtspiAccessible *obj)
460 * atspi_accessible_get_attributes:
461 * @obj: The #AtspiAccessible being queried.
463 * Get the #AttributeSet representing any assigned
464 * name-value pair attributes or annotations for this object.
465 * For typographic, textual, or textually-semantic attributes, see
466 * atspi_text_get_attributes instead.
468 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
469 * attributes assigned to this object.
472 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
474 DBusMessage *message;
477 g_return_val_if_fail (obj != NULL, NULL);
479 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
480 ret = _atspi_dbus_hash_from_message (message);
481 dbus_message_unref (message);
486 * atspi_accessible_get_attributes_as_array:
487 * @obj: The #AtspiAccessible being queried.
489 * Get the #AttributeSet representing any assigned
490 * name-value pair attributes or annotations for this object.
491 * For typographic, textual, or textually-semantic attributes, see
492 * atspi_text_get_attributes_as_array instead.
494 * Returns: (element-type gchar*) (transfer full): The name-value-pair
495 * attributes assigned to this object.
498 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
500 DBusMessage *message;
503 g_return_val_if_fail (obj != NULL, NULL);
505 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
506 ret = _atspi_dbus_attribute_array_from_message (message);
507 dbus_message_unref (message);
512 * atspi_accessible_get_host_application:
513 * @obj: The #AtspiAccessible being queried.
515 * Get the containing #AtspiApplication for an object.
517 * Returns: (transfer full): the containing AtspiApplication instance for
521 atspi_accessible_get_host_application (AtspiAccessible *obj, GError **error)
523 AtspiAccessible *parent;
527 parent = atspi_accessible_get_parent (obj, NULL);
528 if (!parent || parent == obj ||
529 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
535 #if 0 // TODO: interfaces */
536 /* Interface query methods */
539 * atspi_accessible_is_action:
540 * @obj: a pointer to the #AtspiAccessible instance to query.
542 * Query whether the specified #AtspiAccessible implements #AtspiAction.
544 * Returns: #TRUE if @obj implements the #AtspiAction interface,
548 atspi_accessible_is_action (AtspiAccessible *obj)
550 return _atspi_accessible_is_a (obj,
551 atspi_interface_action);
555 * atspi_accessible_is_application:
556 * @obj: a pointer to the #AtspiAccessible instance to query.
558 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
560 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
564 atspi_accessible_is_application (AtspiAccessible *obj)
566 return _atspi_accessible_is_a (obj,
567 atspi_interface_application);
571 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
573 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
574 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
578 atspi_accessible_is_collection (AtspiAccessible *obj)
581 g_warning ("Collections not implemented");
582 return _atspi_accessible_is_a (obj,
583 atspi_interface_collection);
590 * atspi_accessible_is_component:
591 * @obj: a pointer to the #AtspiAccessible instance to query.
593 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
595 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
599 atspi_accessible_is_component (AtspiAccessible *obj)
601 return _atspi_accessible_is_a (obj,
602 atspi_interface_component);
606 * atspi_accessible_is_document:
607 * @obj: a pointer to the #AtspiAccessible instance to query.
609 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
611 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
615 atspi_accessible_is_document (AtspiAccessible *obj)
617 return _atspi_accessible_is_a (obj,
618 atspi_interface_document);
622 * atspi_accessible_is_editable_text:
623 * @obj: a pointer to the #AtspiAccessible instance to query.
625 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
627 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
631 atspi_accessible_is_editable_text (AtspiAccessible *obj)
633 return _atspi_accessible_is_a (obj,
634 atspi_interface_editable_text);
638 * atspi_accessible_is_hypertext:
639 * @obj: a pointer to the #AtspiAccessible instance to query.
641 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
643 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
647 atspi_accessible_is_hypertext (AtspiAccessible *obj)
649 return _atspi_accessible_is_a (obj,
650 atspi_interface_hypertext);
654 * atspi_accessible_is_image:
655 * @obj: a pointer to the #AtspiAccessible instance to query.
657 * Query whether the specified #AtspiAccessible implements #AtspiImage.
659 * Returns: #TRUE if @obj implements the #AtspiImage interface,
663 atspi_accessible_is_image (AtspiAccessible *obj)
665 return _atspi_accessible_is_a (obj,
666 atspi_interface_image);
670 * atspi_accessible_is_selection:
671 * @obj: a pointer to the #AtspiAccessible instance to query.
673 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
675 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
679 atspi_accessible_is_selection (AtspiAccessible *obj)
681 return _atspi_accessible_is_a (obj,
682 atspi_interface_selection);
686 * atspi_accessible_is_table:
687 * @obj: a pointer to the #AtspiAccessible instance to query.
689 * Query whether the specified #AtspiAccessible implements #AtspiTable.
691 * Returns: #TRUE if @obj implements the #AtspiTable interface,
695 atspi_accessible_is_table (AtspiAccessible *obj)
697 return _atspi_accessible_is_a (obj,
698 atspi_interface_table);
702 * atspi_accessible_is_streamable_content:
703 * @obj: a pointer to the #AtspiAccessible instance to query.
705 * Query whether the specified #AtspiAccessible implements
706 * #AtspiStreamableContent.
708 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
712 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
715 return _atspi_accessible_is_a (obj,
716 atspi_interface_streamable_content);
718 g_warning ("Streamable content not implemented");
724 * atspi_accessible_is_text:
725 * @obj: a pointer to the #AtspiAccessible instance to query.
727 * Query whether the specified #AtspiAccessible implements #AtspiText.
729 * Returns: #TRUE if @obj implements the #AtspiText interface,
733 atspi_accessible_is_text (AtspiAccessible *obj)
735 return _atspi_accessible_is_a (obj,
736 atspi_interface_text);
740 * atspi_accessible_is_value:
741 * @obj: a pointer to the #AtspiAccessible instance to query.
743 * Query whether the specified #AtspiAccessible implements #AtspiValue.
745 * Returns: #TRUE if @obj implements the #AtspiValue interface,
749 atspi_accessible_is_value (AtspiAccessible *obj)
751 return _atspi_accessible_is_a (obj,
752 atspi_interface_value);
756 * atspi_accessible_get_application:
757 * @obj: a pointer to the #AtspiAccessible instance to query.
759 * Get the #AtspiApplication interface for an #AtspiAccessible.
761 * Returns: a pointer to an #AtspiApplication interface instance, or
762 * NULL if @obj does not implement #AtspiApplication.
765 atspi_accessible_get_application (AtspiAccessible *accessible)
767 return (_atspi_accessible_is_a (accessible, atspi_interface_application) ?
772 * atspi_accessible_get_action:
773 * @obj: a pointer to the #AtspiAccessible instance to query.
775 * Get the #AtspiAction interface for an #AtspiAccessible.
777 * Returns: a pointer to an #AtspiAction interface instance, or
778 * NULL if @obj does not implement #AtspiAction.
781 atspi_accessible_get_action (AtspiAccessible *accessible)
783 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
788 * atspi_accessible_get_collection:
789 * @obj: a pointer to the #AtspiAccessible instance to query.
791 * Get the #AtspiCollection interface for an #AtspiAccessible.
793 * Returns: a pointer to an #AtspiCollection interface instance, or
794 * NULL if @obj does not implement #AtspiCollection.
797 atspi_accessible_get_collection (AtspiAccessible *accessible)
799 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
805 * atspi_accessible_get_component:
806 * @obj: a pointer to the #AtspiAccessible instance to query.
808 * Get the #AtspiComponent interface for an #AtspiAccessible.
810 * Returns: (transfer full): a pointer to an #AtspiComponent interface
811 * instance, or NULL if @obj does not implement #AtspiComponent.
814 atspi_accessible_get_component (AtspiAccessible *accessible)
816 return (_atspi_accessible_is_a (accessible, atspi_interface_component) ?
817 ATSPI_COMPONENT (accessible) : NULL);
822 * atspi_accessible_get_document:
823 * @obj: a pointer to the #AtspiAccessible instance to query.
825 * Get the #AtspiDocument interface for an #AtspiAccessible.
827 * Returns: a pointer to an #AtspiDocument interface instance, or
828 * NULL if @obj does not implement #AtspiDocument.
831 atspi_accessible_get_document (AtspiAccessible *accessible)
833 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
838 * atspi_accessible_get_editable_text:
839 * @obj: a pointer to the #AtspiAccessible instance to query.
841 * Get the #AtspiEditableText interface for an #AtspiAccessible.
843 * Returns: a pointer to an #AtspiEditableText interface instance, or
844 * NULL if @obj does not implement #AtspiEditableText.
847 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
849 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
854 * atspi_accessible_get_hypertext:
855 * @obj: a pointer to the #AtspiAccessible instance to query.
857 * Get the #AtspiHypertext interface for an #AtspiAccessible.
859 * Returns: a pointer to an #AtspiHypertext interface instance, or
860 * NULL if @obj does not implement #AtspiHypertext.
863 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
865 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
870 * atspi_accessible_get_image:
871 * @obj: a pointer to the #AtspiAccessible instance to query.
873 * Get the #AtspiImage interface for an #AtspiAccessible.
875 * Returns: a pointer to an #AtspiImage interface instance, or
876 * NULL if @obj does not implement #AtspiImage.
879 atspi_accessible_get_image (AtspiAccessible *accessible)
881 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
886 * atspi_accessible_get_selection:
887 * @obj: a pointer to the #AtspiAccessible instance to query.
889 * Get the #AtspiSelection interface for an #AtspiAccessible.
891 * Returns: a pointer to an #AtspiSelection interface instance, or
892 * NULL if @obj does not implement #AtspiSelection.
895 atspi_accessible_get_selection (AtspiAccessible *accessible)
897 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
902 * atspi_accessible_get_streamable_content:
903 * @obj: a pointer to the #AtspiAccessible instance to query.
905 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
907 * Returns: a pointer to an #AtspiStreamableContent interface instance, or
908 * NULL if @obj does not implement #AtspiStreamableContent.
910 AtspiStreamableContent *
911 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
913 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
918 * atspi_accessible_get_table:
919 * @obj: a pointer to the #AtspiAccessible instance to query.
921 * Get the #AtspiTable interface for an #AtspiAccessible.
923 * Returns: a pointer to an #AtspiTable interface instance, or
924 * NULL if @obj does not implement #AtspiTable.
927 atspi_accessible_get_table (AtspiAccessible *accessible)
929 return (_atspi_accessible_is_a (accessible, atspi_interface_table) ?
934 * atspi_accessible_get_text:
935 * @obj: a pointer to the #AtspiAccessible instance to query.
937 * Get the #AtspiTable interface for an #AtspiAccessible.
939 * Returns: a pointer to an #AtspiTable interface instance, or
940 * NULL if @obj does not implement #AtspiTable.
943 atspi_accessible_get_text (AtspiAccessible *accessible)
945 return (_atspi_accessible_is_a (accessible, atspi_interface_text) ?
950 * atspi_accessible_get_value:
951 * @obj: a pointer to the #AtspiAccessible instance to query.
953 * Get the #AtspiTable interface for an #AtspiAccessible.
955 * Returns: a pointer to an #AtspiTable interface instance, or
956 * NULL if @obj does not implement #AtspiTable.
959 atspi_accessible_get_value (AtspiAccessible *accessible)
961 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
966 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
969 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
971 relation_type_table [i] = SPI_RELATION_NULL;
973 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
974 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
975 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
976 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
977 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
978 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
979 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
980 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
981 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
982 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
983 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
984 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
985 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
986 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
987 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
988 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
989 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
990 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
994 static AccessibleRelationType
995 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
997 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
998 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
999 static gboolean is_initialized = FALSE;
1000 AccessibleRelationType cspi_type;
1001 if (!is_initialized)
1003 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
1005 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
1007 cspi_type = cspi_relation_type_table [type];
1011 cspi_type = SPI_RELATION_NULL;
1016 * AccessibleRelation_getRelationType:
1017 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1019 * Get the type of relationship represented by an #AtspiAccessibleRelation.
1021 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
1022 * encapsulated in this #AtspiAccessibleRelation object.
1025 AccessibleRelationType
1026 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1028 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1029 return cspi_relation_type_from_spi_relation_type (obj->type);
1033 * AccessibleRelation_getNTargets:
1034 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1036 * Get the number of objects which this relationship has as its
1037 * target objects (the subject is the #AtspiAccessible from which this
1038 * #AtspiAccessibleRelation originated).
1040 * Returns: a short integer indicating how many target objects which the
1041 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
1042 * relationship with.
1045 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1047 cspi_return_val_if_fail (obj, -1);
1048 return obj->targets->len;
1052 * AccessibleRelation_getTarget:
1053 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1054 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1056 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
1058 * Returns: an #AtspiAccessible which is the @i-th object with which the
1059 * originating #AtspiAccessible has relationship specified in the
1060 * #AtspiAccessibleRelation object.
1064 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1066 cspi_return_val_if_fail (obj, NULL);
1068 if (i < 0 || i >= obj->targets->len) return NULL;
1069 return cspi_object_add (
1070 g_array_index (obj->targets, Accessible *, i));
1074 * AccessibleStateSet_ref:
1075 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1077 * Increment the reference count for an #AtspiAccessibleStateSet object.
1081 AccessibleStateSet_ref (AccessibleStateSet *obj)
1083 spi_state_set_cache_ref (obj);
1087 * AccessibleStateSet_unref:
1088 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1090 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1094 AccessibleStateSet_unref (AccessibleStateSet *obj)
1096 spi_state_set_cache_unref (obj);
1099 static Accessibility_StateType
1100 spi_state_to_dbus (AccessibleState state)
1102 #define MAP_STATE(a) \
1103 case SPI_STATE_##a: \
1104 return Accessibility_STATE_##a
1108 MAP_STATE (INVALID);
1112 MAP_STATE (CHECKED);
1113 MAP_STATE (DEFUNCT);
1114 MAP_STATE (EDITABLE);
1115 MAP_STATE (ENABLED);
1116 MAP_STATE (EXPANDABLE);
1117 MAP_STATE (EXPANDED);
1118 MAP_STATE (FOCUSABLE);
1119 MAP_STATE (FOCUSED);
1120 MAP_STATE (HORIZONTAL);
1121 MAP_STATE (ICONIFIED);
1123 MAP_STATE (MULTI_LINE);
1124 MAP_STATE (MULTISELECTABLE);
1126 MAP_STATE (PRESSED);
1127 MAP_STATE (RESIZABLE);
1128 MAP_STATE (SELECTABLE);
1129 MAP_STATE (SELECTED);
1130 MAP_STATE (SENSITIVE);
1131 MAP_STATE (SHOWING);
1132 MAP_STATE (SINGLE_LINE);
1134 MAP_STATE (TRANSIENT);
1135 MAP_STATE (VERTICAL);
1136 MAP_STATE (VISIBLE);
1137 MAP_STATE (MANAGES_DESCENDANTS);
1138 MAP_STATE (INDETERMINATE);
1139 MAP_STATE (TRUNCATED);
1140 MAP_STATE (REQUIRED);
1141 MAP_STATE (INVALID_ENTRY);
1142 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1143 MAP_STATE (SELECTABLE_TEXT);
1144 MAP_STATE (IS_DEFAULT);
1145 MAP_STATE (VISITED);
1147 return Accessibility_STATE_INVALID;
1153 * AccessibleStateSet_contains:
1154 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1155 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1158 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1159 * whether @state is true for the stateset in question.
1161 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1166 AccessibleStateSet_contains (AccessibleStateSet *obj,
1167 AccessibleState state)
1169 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1173 * AccessibleStateSet_add:
1174 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1175 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1177 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1178 * given state to #TRUE in the stateset.
1182 AccessibleStateSet_add (AccessibleStateSet *obj,
1183 AccessibleState state)
1185 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1189 * AccessibleStateSet_remove:
1190 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1191 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1193 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1194 * given state to #FALSE in the stateset.)
1198 AccessibleStateSet_remove (AccessibleStateSet *obj,
1199 AccessibleState state)
1201 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1205 * AccessibleStateSet_equals:
1206 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1207 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1209 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1210 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1211 * state variables at once; construct the target state then compare against it.
1213 * @see AccessibleStateSet_compare().
1215 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1220 AccessibleStateSet_equals (AccessibleStateSet *obj,
1221 AccessibleStateSet *obj2)
1231 cmp = spi_state_set_cache_xor (obj, obj2);
1232 eq = spi_state_set_cache_is_empty (cmp);
1233 spi_state_set_cache_unref (cmp);
1239 * AccessibleStateSet_compare:
1240 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1241 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1243 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1244 * Not Yet Implemented.
1246 * @see AccessibleStateSet_equals().
1248 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1249 * the two sets but not the other.
1252 AccessibleStateSet *
1253 AccessibleStateSet_compare (AccessibleStateSet *obj,
1254 AccessibleStateSet *obj2)
1256 return spi_state_set_cache_xor (obj, obj2);
1260 * AccessibleStateSet_isEmpty:
1261 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1263 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1265 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1270 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1272 return spi_state_set_cache_is_empty (obj);
1277 _atspi_accessible_is_a (AtspiAccessible *accessible,
1278 const char *interface_name)
1282 if (accessible == NULL)
1287 n = _atspi_get_iface_num (interface_name);
1288 if (n == -1) return FALSE;
1289 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1292 /* TODO: Move to a finalizer */
1294 cspi_object_destroyed (AtspiAccessible *accessible)
1299 /* TODO: Only fire if object not already marked defunct */
1300 memset (&e, 0, sizeof (e));
1301 e.type = "object:state-change:defunct";
1302 e.source = accessible;
1305 _atspi_send_event (&e);
1307 g_free (accessible->path);
1309 if (accessible->states)
1310 g_object_unref (accessible->states);
1311 g_free (accessible->description);
1312 g_free (accessible->name);
1316 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1318 AtspiAccessible *accessible;
1320 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1321 g_return_val_if_fail (accessible != NULL, NULL);
1323 accessible->app = g_object_ref (app);
1324 accessible->path = g_strdup (path);