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_selection_interface_init (AtspiSelection *selection)
38 atspi_table_interface_init (AtspiTable *table)
43 atspi_text_interface_init (AtspiText *text)
47 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, G_TYPE_OBJECT,
48 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
49 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init)
50 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
51 G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init))
54 atspi_accessible_init (AtspiAccessible *accessible)
59 atspi_accessible_finalize (GObject *obj)
61 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj);
64 g_object_unref (accessible->app);
66 g_free (accessible->path);
70 atspi_accessible_class_init (AtspiAccessibleClass *klass)
72 GObjectClass *object_class = G_OBJECT_CLASS (klass);
74 object_class->finalize = atspi_accessible_finalize;
77 /* TODO: Generate following from spec? */
78 static const char *role_names [] =
136 "table-column-header",
138 "tear-off-menu-item",
168 "input method window"
171 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
174 * atspi_role_get_name
175 * @role: an #AtspiAccessibleRole object to query.
177 * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
178 * <em>DEPRECATED.</em>
180 * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
183 atspi_role_get_name (AtspiRole role)
185 if (role < MAX_ROLES && role_names [(int) role])
187 return g_strdup (role_names [(int) role]);
191 return g_strdup ("");
196 * atspi_accessible_get_name:
197 * @obj: a pointer to the #AtspiAccessible object on which to operate.
199 * Get the name of an #AtspiAccessible object.
201 * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
202 * or NULL on exception
205 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
207 g_return_val_if_fail (obj != NULL, NULL);
208 if (!(obj->cached_properties & ATSPI_CACHE_NAME))
210 if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", NULL, "s", &obj->name))
212 obj->cached_properties |= ATSPI_CACHE_NAME;
214 return g_strdup (obj->name);
218 * atspi_accessible_get_description:
219 * @obj: a pointer to the #AtspiAccessible object on which to operate.
221 * Get the description of an #AtspiAccessible object.
223 * Returns: a UTF-8 string describing the #AtspiAccessible object.
224 * or NULL on exception
227 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
229 g_return_val_if_fail (obj != NULL, NULL);
231 if (!(obj->cached_properties & ATSPI_CACHE_DESCRIPTION))
233 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetDescription", NULL, "=>s", &obj->description))
235 obj->cached_properties |= ATSPI_CACHE_DESCRIPTION;
237 return g_strdup (obj->description);
240 const char *str_parent = "Parent";
243 * atspi_accessible_get_parent:
244 * @obj: a pointer to the #AtspiAccessible object to query.
246 * Get an #AtspiAccessible object's parent container.
248 * Returns: (transfer full): a pointer to the #AtspiAccessible object which
249 * contains the given #AtspiAccessible instance, or NULL if the @obj
250 * has no parent container.
254 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
256 g_return_val_if_fail (obj != NULL, NULL);
258 if (!(obj->cached_properties & ATSPI_CACHE_PARENT))
260 DBusMessage *message, *reply;
261 DBusMessageIter iter, iter_variant;
262 message = dbus_message_new_method_call (obj->app->bus_name, obj->path,
263 DBUS_INTERFACE_PROPERTIES, "Get");
266 dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
267 DBUS_TYPE_STRING, &str_parent,
269 reply = _atspi_dbus_send_with_reply_and_block (message);
271 (strcmp (dbus_message_get_signature (reply), "v") != 0))
273 dbus_message_iter_init (reply, &iter);
274 dbus_message_iter_recurse (&iter, &iter_variant);
275 obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
276 dbus_message_unref (reply);
277 obj->cached_properties |= ATSPI_CACHE_PARENT;
279 if (!obj->accessible_parent)
281 return g_object_ref (obj->accessible_parent);
285 * atspi_accessible_get_child_count:
286 * @obj: a pointer to the #AtspiAccessible object on which to operate.
288 * Get the number of children contained by an #AtspiAccessible object.
290 * Returns: a #long indicating the number of #AtspiAccessible children
291 * contained by an #AtspiAccessible object. or -1 on exception
295 atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error)
297 g_return_val_if_fail (obj != NULL, -1);
299 /* TODO: MANAGES_DESCENDANTS */
300 return g_list_length (obj->children);
304 * atspi_accessible_get_child_at_index:
305 * @obj: a pointer to the #AtspiAccessible object on which to operate.
306 * @child_index: a #long indicating which child is specified.
308 * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
310 * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
311 * index @child_index. or NULL on exception
314 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
318 AtspiAccessible *child;
320 g_return_val_if_fail (obj != NULL, NULL);
322 /* TODO: ManagesDescendants */
323 child = g_list_nth_data (obj->children, child_index);
326 return g_object_ref (child);
330 * atspi_accessible_get_index_in_parent
331 * @obj: a pointer to the #AtspiAccessible object on which to operate.
333 * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
335 * Returns: a #glong indicating the index of the #AtspiAccessible object
336 * in its parent (i.e. containing) #AtspiAccessible instance,
337 * or -1 if @obj has no containing parent or on exception.
340 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
345 g_return_val_if_fail (obj != NULL, -1);
346 if (!obj->accessible_parent) return -1;
347 l = obj->accessible_parent->children;
350 if (l->data == obj) return i;
361 } Accessibility_Relation;
364 * atspi_accessible_get_relation_set:
365 * @obj: a pointer to the #AtspiAccessible object on which to operate.
367 * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
368 * relationships with other #AtspiAccessible objects.
370 * Returns: an array of #AtspiAccessibleRelation pointers. or NULL on exception
371 * TODO:: Annotate array type
374 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
378 GArray *relation_set;
380 g_return_val_if_fail (obj != NULL, NULL);
382 if (!_atspi_dbus_call (obj, atspi_interface_accessible, "GetRelationSet", error, "=>a(uao)", &relation_set))
389 * atspi_accessible_get_role:
390 * @obj: a pointer to the #AtspiAccessible object on which to operate.
392 * Get the UI role of an #AtspiAccessible object.
393 * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
395 * Returns: the #AtspiRole of the object.
399 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
401 g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
403 if (!(obj->cached_properties & ATSPI_CACHE_ROLE))
406 /* TODO: Make this a property */
407 if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", NULL, "=>u", &role))
409 obj->cached_properties |= ATSPI_CACHE_ROLE;
417 * atspi_accessible_get_role_name:
418 * @obj: a pointer to the #AtspiAccessible object on which to operate.
420 * Get a UTF-8 string describing the role this object plays in the UI.
421 * This method will return useful values for roles that fall outside the
422 * enumeration used in atspi_accessible_getRole ().
424 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
428 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
432 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
434 _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
440 * atspi_accessible_get_localized_role_name:
441 * @obj: a pointer to the #AtspiAccessible object on which to operate.
443 * Get a UTF-8 string describing the (localized) role this object plays in the UI.
444 * This method will return useful values for roles that fall outside the
445 * enumeration used in atspi_accessible_getRole ().
447 * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
451 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
455 g_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
457 _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
463 * atspi_accessible_get_state_set:
464 * @obj: a pointer to the #AtspiAccessible object on which to operate.
466 * Gets the current state of an object.
468 * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
469 * object's current state.
472 atspi_accessible_get_state_set (AtspiAccessible *obj)
478 * atspi_accessible_get_attributes:
479 * @obj: The #AtspiAccessible being queried.
481 * Get the #AttributeSet representing any assigned
482 * name-value pair attributes or annotations for this object.
483 * For typographic, textual, or textually-semantic attributes, see
484 * atspi_text_get_attributes instead.
486 * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
487 * attributes assigned to this object.
490 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
492 DBusMessage *message;
495 g_return_val_if_fail (obj != NULL, NULL);
497 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
498 ret = _atspi_dbus_hash_from_message (message);
499 dbus_message_unref (message);
504 * atspi_accessible_get_attributes_as_array:
505 * @obj: The #AtspiAccessible being queried.
507 * Get the #AttributeSet representing any assigned
508 * name-value pair attributes or annotations for this object.
509 * For typographic, textual, or textually-semantic attributes, see
510 * atspi_text_get_attributes_as_array instead.
512 * Returns: (element-type gchar*) (transfer full): The name-value-pair
513 * attributes assigned to this object.
516 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
518 DBusMessage *message;
521 g_return_val_if_fail (obj != NULL, NULL);
523 message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
524 ret = _atspi_dbus_attribute_array_from_message (message);
525 dbus_message_unref (message);
530 * atspi_accessible_get_host_application:
531 * @obj: The #AtspiAccessible being queried.
533 * Get the containing #AtspiApplication for an object.
535 * Returns: (transfer full): the containing AtspiApplication instance for
539 atspi_accessible_get_host_application (AtspiAccessible *obj, GError **error)
541 AtspiAccessible *parent;
545 parent = atspi_accessible_get_parent (obj, NULL);
546 if (!parent || parent == obj ||
547 atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
553 #if 0 // TODO: interfaces */
554 /* Interface query methods */
557 * atspi_accessible_is_action:
558 * @obj: a pointer to the #AtspiAccessible instance to query.
560 * Query whether the specified #AtspiAccessible implements #AtspiAction.
562 * Returns: #TRUE if @obj implements the #AtspiAction interface,
566 atspi_accessible_is_action (AtspiAccessible *obj)
568 return _atspi_accessible_is_a (obj,
569 atspi_interface_action);
573 * atspi_accessible_is_application:
574 * @obj: a pointer to the #AtspiAccessible instance to query.
576 * Query whether the specified #AtspiAccessible implements #AtspiApplication.
578 * Returns: #TRUE if @obj implements the #AtspiApplication interface,
582 atspi_accessible_is_application (AtspiAccessible *obj)
584 return _atspi_accessible_is_a (obj,
585 atspi_interface_application);
589 * atspi_accessible_is_collection: * @obj: a pointer to the #AtspiAccessible instance to query.
591 * Query whether the specified #AtspiAccessible implements #AtspiCollection.
592 * Returns: #TRUE if @obj implements the #AtspiCollection interface,
596 atspi_accessible_is_collection (AtspiAccessible *obj)
599 g_warning ("Collections not implemented");
600 return _atspi_accessible_is_a (obj,
601 atspi_interface_collection);
608 * atspi_accessible_is_component:
609 * @obj: a pointer to the #AtspiAccessible instance to query.
611 * Query whether the specified #AtspiAccessible implements #AtspiComponent.
613 * Returns: #TRUE if @obj implements the #AtspiComponent interface,
617 atspi_accessible_is_component (AtspiAccessible *obj)
619 return _atspi_accessible_is_a (obj,
620 atspi_interface_component);
624 * atspi_accessible_is_document:
625 * @obj: a pointer to the #AtspiAccessible instance to query.
627 * Query whether the specified #AtspiAccessible implements #AtspiDocument.
629 * Returns: #TRUE if @obj implements the #AtspiDocument interface,
633 atspi_accessible_is_document (AtspiAccessible *obj)
635 return _atspi_accessible_is_a (obj,
636 atspi_interface_document);
640 * atspi_accessible_is_editable_text:
641 * @obj: a pointer to the #AtspiAccessible instance to query.
643 * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
645 * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
649 atspi_accessible_is_editable_text (AtspiAccessible *obj)
651 return _atspi_accessible_is_a (obj,
652 atspi_interface_editable_text);
656 * atspi_accessible_is_hypertext:
657 * @obj: a pointer to the #AtspiAccessible instance to query.
659 * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
661 * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
665 atspi_accessible_is_hypertext (AtspiAccessible *obj)
667 return _atspi_accessible_is_a (obj,
668 atspi_interface_hypertext);
672 * atspi_accessible_is_image:
673 * @obj: a pointer to the #AtspiAccessible instance to query.
675 * Query whether the specified #AtspiAccessible implements #AtspiImage.
677 * Returns: #TRUE if @obj implements the #AtspiImage interface,
681 atspi_accessible_is_image (AtspiAccessible *obj)
683 return _atspi_accessible_is_a (obj,
684 atspi_interface_image);
688 * atspi_accessible_is_selection:
689 * @obj: a pointer to the #AtspiAccessible instance to query.
691 * Query whether the specified #AtspiAccessible implements #AtspiSelection.
693 * Returns: #TRUE if @obj implements the #AtspiSelection interface,
697 atspi_accessible_is_selection (AtspiAccessible *obj)
699 return _atspi_accessible_is_a (obj,
700 atspi_interface_selection);
704 * atspi_accessible_is_table:
705 * @obj: a pointer to the #AtspiAccessible instance to query.
707 * Query whether the specified #AtspiAccessible implements #AtspiTable.
709 * Returns: #TRUE if @obj implements the #AtspiTable interface,
713 atspi_accessible_is_table (AtspiAccessible *obj)
715 return _atspi_accessible_is_a (obj,
716 atspi_interface_table);
720 * atspi_accessible_is_streamable_content:
721 * @obj: a pointer to the #AtspiAccessible instance to query.
723 * Query whether the specified #AtspiAccessible implements
724 * #AtspiStreamableContent.
726 * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
730 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
733 return _atspi_accessible_is_a (obj,
734 atspi_interface_streamable_content);
736 g_warning ("Streamable content not implemented");
742 * atspi_accessible_is_text:
743 * @obj: a pointer to the #AtspiAccessible instance to query.
745 * Query whether the specified #AtspiAccessible implements #AtspiText.
747 * Returns: #TRUE if @obj implements the #AtspiText interface,
751 atspi_accessible_is_text (AtspiAccessible *obj)
753 return _atspi_accessible_is_a (obj,
754 atspi_interface_text);
758 * atspi_accessible_is_value:
759 * @obj: a pointer to the #AtspiAccessible instance to query.
761 * Query whether the specified #AtspiAccessible implements #AtspiValue.
763 * Returns: #TRUE if @obj implements the #AtspiValue interface,
767 atspi_accessible_is_value (AtspiAccessible *obj)
769 return _atspi_accessible_is_a (obj,
770 atspi_interface_value);
774 * atspi_accessible_get_application:
775 * @obj: a pointer to the #AtspiAccessible instance to query.
777 * Get the #AtspiApplication interface for an #AtspiAccessible.
779 * Returns: a pointer to an #AtspiApplication interface instance, or
780 * NULL if @obj does not implement #AtspiApplication.
783 atspi_accessible_get_application (AtspiAccessible *accessible)
785 return (_atspi_accessible_is_a (accessible, atspi_interface_application) ?
790 * atspi_accessible_get_action:
791 * @obj: a pointer to the #AtspiAccessible instance to query.
793 * Get the #AtspiAction interface for an #AtspiAccessible.
795 * Returns: a pointer to an #AtspiAction interface instance, or
796 * NULL if @obj does not implement #AtspiAction.
799 atspi_accessible_get_action (AtspiAccessible *accessible)
801 return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
806 * atspi_accessible_get_collection:
807 * @obj: a pointer to the #AtspiAccessible instance to query.
809 * Get the #AtspiCollection interface for an #AtspiAccessible.
811 * Returns: a pointer to an #AtspiCollection interface instance, or
812 * NULL if @obj does not implement #AtspiCollection.
815 atspi_accessible_get_collection (AtspiAccessible *accessible)
817 return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
823 * atspi_accessible_get_component:
824 * @obj: a pointer to the #AtspiAccessible instance to query.
826 * Get the #AtspiComponent interface for an #AtspiAccessible.
828 * Returns: (transfer full): a pointer to an #AtspiComponent interface
829 * instance, or NULL if @obj does not implement #AtspiComponent.
832 atspi_accessible_get_component (AtspiAccessible *obj)
834 return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
835 g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
840 * atspi_accessible_get_document:
841 * @obj: a pointer to the #AtspiAccessible instance to query.
843 * Get the #AtspiDocument interface for an #AtspiAccessible.
845 * Returns: a pointer to an #AtspiDocument interface instance, or
846 * NULL if @obj does not implement #AtspiDocument.
849 atspi_accessible_get_document (AtspiAccessible *accessible)
851 return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
856 * atspi_accessible_get_editable_text:
857 * @obj: a pointer to the #AtspiAccessible instance to query.
859 * Get the #AtspiEditableText interface for an #AtspiAccessible.
861 * Returns: a pointer to an #AtspiEditableText interface instance, or
862 * NULL if @obj does not implement #AtspiEditableText.
865 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
867 return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
872 * atspi_accessible_get_hypertext:
873 * @obj: a pointer to the #AtspiAccessible instance to query.
875 * Get the #AtspiHypertext interface for an #AtspiAccessible.
877 * Returns: a pointer to an #AtspiHypertext interface instance, or
878 * NULL if @obj does not implement #AtspiHypertext.
881 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
883 return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
888 * atspi_accessible_get_image:
889 * @obj: a pointer to the #AtspiAccessible instance to query.
891 * Get the #AtspiImage interface for an #AtspiAccessible.
893 * Returns: a pointer to an #AtspiImage interface instance, or
894 * NULL if @obj does not implement #AtspiImage.
897 atspi_accessible_get_image (AtspiAccessible *accessible)
899 return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
905 * atspi_accessible_get_selection:
906 * @obj: a pointer to the #AtspiAccessible instance to query.
908 * Get the #AtspiSelection interface for an #AtspiAccessible.
910 * Returns: (transfer full): a pointer to an #AtspiSelection interface
911 * instance, or NULL if @obj does not implement #AtspiSelection.
914 atspi_accessible_get_selection (AtspiAccessible *accessible)
916 return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
917 g_object_ref (ATSPI_SELECTION (accessible)) : NULL);
922 * atspi_accessible_get_streamable_content:
923 * @obj: a pointer to the #AtspiAccessible instance to query.
925 * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
927 * Returns: a pointer to an #AtspiStreamableContent interface instance, or
928 * NULL if @obj does not implement #AtspiStreamableContent.
930 AtspiStreamableContent *
931 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
933 return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
939 * atspi_accessible_get_table:
940 * @obj: a pointer to the #AtspiAccessible instance to query.
942 * Get the #AtspiTable interface for an #AtspiAccessible.
944 * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
945 * NULL if @obj does not implement #AtspiTable.
948 atspi_accessible_get_table (AtspiAccessible *obj)
950 return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
951 g_object_ref (ATSPI_TABLE (obj)) : NULL);
955 * atspi_accessible_get_text:
956 * @obj: a pointer to the #AtspiAccessible instance to query.
958 * Get the #AtspiTable interface for an #AtspiAccessible.
960 * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
961 * NULL if @obj does not implement #AtspiTable.
964 atspi_accessible_get_text (AtspiAccessible *obj)
966 return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
967 g_object_ref (ATSPI_TEXT (obj)) : NULL);
972 * atspi_accessible_get_value:
973 * @obj: a pointer to the #AtspiAccessible instance to query.
975 * Get the #AtspiTable interface for an #AtspiAccessible.
977 * Returns: a pointer to an #AtspiTable interface instance, or
978 * NULL if @obj does not implement #AtspiTable.
981 atspi_accessible_get_value (AtspiAccessible *accessible)
983 return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
988 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
991 for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
993 relation_type_table [i] = SPI_RELATION_NULL;
995 relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
996 relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
997 relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
998 relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
999 relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
1000 relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
1001 relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
1002 relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
1003 relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
1004 relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
1005 relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
1006 relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
1007 relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
1008 relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
1009 relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
1010 relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
1011 relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
1012 relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
1016 static AccessibleRelationType
1017 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
1019 /* array is sized according to IDL RelationType because IDL RelationTypes are the index */
1020 static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
1021 static gboolean is_initialized = FALSE;
1022 AccessibleRelationType cspi_type;
1023 if (!is_initialized)
1025 is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);
1027 if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
1029 cspi_type = cspi_relation_type_table [type];
1033 cspi_type = SPI_RELATION_NULL;
1038 * AccessibleRelation_getRelationType:
1039 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1041 * Get the type of relationship represented by an #AtspiAccessibleRelation.
1043 * Returns: an #AtspiAccessibleRelationType indicating the type of relation
1044 * encapsulated in this #AtspiAccessibleRelation object.
1047 AccessibleRelationType
1048 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1050 cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1051 return cspi_relation_type_from_spi_relation_type (obj->type);
1055 * AccessibleRelation_getNTargets:
1056 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1058 * Get the number of objects which this relationship has as its
1059 * target objects (the subject is the #AtspiAccessible from which this
1060 * #AtspiAccessibleRelation originated).
1062 * Returns: a short integer indicating how many target objects which the
1063 * originating #AtspiAccessible object has the #AtspiAccessibleRelation
1064 * relationship with.
1067 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1069 cspi_return_val_if_fail (obj, -1);
1070 return obj->targets->len;
1074 * AccessibleRelation_getTarget:
1075 * @obj: a pointer to the #AtspiAccessibleRelation object to query.
1076 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1078 * Get the @i-th target of a specified #AtspiAccessibleRelation relationship.
1080 * Returns: an #AtspiAccessible which is the @i-th object with which the
1081 * originating #AtspiAccessible has relationship specified in the
1082 * #AtspiAccessibleRelation object.
1086 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1088 cspi_return_val_if_fail (obj, NULL);
1090 if (i < 0 || i >= obj->targets->len) return NULL;
1091 return cspi_object_add (
1092 g_array_index (obj->targets, Accessible *, i));
1096 * AccessibleStateSet_ref:
1097 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1099 * Increment the reference count for an #AtspiAccessibleStateSet object.
1103 AccessibleStateSet_ref (AccessibleStateSet *obj)
1105 spi_state_set_cache_ref (obj);
1109 * AccessibleStateSet_unref:
1110 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1112 * Decrement the reference count for an #AtspiAccessibleStateSet object.
1116 AccessibleStateSet_unref (AccessibleStateSet *obj)
1118 spi_state_set_cache_unref (obj);
1121 static Accessibility_StateType
1122 spi_state_to_dbus (AccessibleState state)
1124 #define MAP_STATE(a) \
1125 case SPI_STATE_##a: \
1126 return Accessibility_STATE_##a
1130 MAP_STATE (INVALID);
1134 MAP_STATE (CHECKED);
1135 MAP_STATE (DEFUNCT);
1136 MAP_STATE (EDITABLE);
1137 MAP_STATE (ENABLED);
1138 MAP_STATE (EXPANDABLE);
1139 MAP_STATE (EXPANDED);
1140 MAP_STATE (FOCUSABLE);
1141 MAP_STATE (FOCUSED);
1142 MAP_STATE (HORIZONTAL);
1143 MAP_STATE (ICONIFIED);
1145 MAP_STATE (MULTI_LINE);
1146 MAP_STATE (MULTISELECTABLE);
1148 MAP_STATE (PRESSED);
1149 MAP_STATE (RESIZABLE);
1150 MAP_STATE (SELECTABLE);
1151 MAP_STATE (SELECTED);
1152 MAP_STATE (SENSITIVE);
1153 MAP_STATE (SHOWING);
1154 MAP_STATE (SINGLE_LINE);
1156 MAP_STATE (TRANSIENT);
1157 MAP_STATE (VERTICAL);
1158 MAP_STATE (VISIBLE);
1159 MAP_STATE (MANAGES_DESCENDANTS);
1160 MAP_STATE (INDETERMINATE);
1161 MAP_STATE (TRUNCATED);
1162 MAP_STATE (REQUIRED);
1163 MAP_STATE (INVALID_ENTRY);
1164 MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1165 MAP_STATE (SELECTABLE_TEXT);
1166 MAP_STATE (IS_DEFAULT);
1167 MAP_STATE (VISITED);
1169 return Accessibility_STATE_INVALID;
1175 * AccessibleStateSet_contains:
1176 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1177 * @state: an #AtspiAccessibleState for which the specified #AtspiAccessibleStateSet
1180 * Determine whether a given #AtspiAccessibleStateSet includes a given state; that is,
1181 * whether @state is true for the stateset in question.
1183 * Returns: #TRUE if @state is true/included in the given #AtspiAccessibleStateSet,
1188 AccessibleStateSet_contains (AccessibleStateSet *obj,
1189 AccessibleState state)
1191 return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1195 * AccessibleStateSet_add:
1196 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1197 * @state: an #AtspiAccessibleState to be added to the specified #AtspiAccessibleStateSet
1199 * Add a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1200 * given state to #TRUE in the stateset.
1204 AccessibleStateSet_add (AccessibleStateSet *obj,
1205 AccessibleState state)
1207 spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1211 * AccessibleStateSet_remove:
1212 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1213 * @state: an #AtspiAccessibleState to be removed from the specified #AtspiAccessibleStateSet
1215 * Remove a particular #AtspiAccessibleState to an #AtspiAccessibleStateSet (i.e. set the
1216 * given state to #FALSE in the stateset.)
1220 AccessibleStateSet_remove (AccessibleStateSet *obj,
1221 AccessibleState state)
1223 spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1227 * AccessibleStateSet_equals:
1228 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1229 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1231 * Determine whether two instances of #AtspiAccessibleStateSet are equivalent (i.e.
1232 * consist of the same #AtspiAccessibleStates). Useful for checking multiple
1233 * state variables at once; construct the target state then compare against it.
1235 * @see AccessibleStateSet_compare().
1237 * Returns: #TRUE if the two #AtspiAccessibleStateSets are equivalent,
1242 AccessibleStateSet_equals (AccessibleStateSet *obj,
1243 AccessibleStateSet *obj2)
1253 cmp = spi_state_set_cache_xor (obj, obj2);
1254 eq = spi_state_set_cache_is_empty (cmp);
1255 spi_state_set_cache_unref (cmp);
1261 * AccessibleStateSet_compare:
1262 * @obj: a pointer to the first #AtspiAccessibleStateSet object on which to operate.
1263 * @obj2: a pointer to the second #AtspiAccessibleStateSet object on which to operate.
1265 * Determine the differences between two instances of #AtspiAccessibleStateSet.
1266 * Not Yet Implemented.
1268 * @see AccessibleStateSet_equals().
1270 * Returns: an #AtspiAccessibleStateSet object containing all states contained on one of
1271 * the two sets but not the other.
1274 AccessibleStateSet *
1275 AccessibleStateSet_compare (AccessibleStateSet *obj,
1276 AccessibleStateSet *obj2)
1278 return spi_state_set_cache_xor (obj, obj2);
1282 * AccessibleStateSet_isEmpty:
1283 * @obj: a pointer to the #AtspiAccessibleStateSet object on which to operate.
1285 * Determine whether a given #AtspiAccessibleStateSet is the empty set.
1287 * Returns: #TRUE if the given #AtspiAccessibleStateSet contains no (true) states,
1292 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1294 return spi_state_set_cache_is_empty (obj);
1299 _atspi_accessible_is_a (AtspiAccessible *accessible,
1300 const char *interface_name)
1304 if (accessible == NULL)
1309 n = _atspi_get_iface_num (interface_name);
1310 if (n == -1) return FALSE;
1311 return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
1314 /* TODO: Move to a finalizer */
1316 cspi_object_destroyed (AtspiAccessible *accessible)
1321 /* TODO: Only fire if object not already marked defunct */
1322 memset (&e, 0, sizeof (e));
1323 e.type = "object:state-change:defunct";
1324 e.source = accessible;
1327 _atspi_send_event (&e);
1329 g_free (accessible->path);
1331 if (accessible->states)
1332 g_object_unref (accessible->states);
1333 g_free (accessible->description);
1334 g_free (accessible->name);
1338 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1340 AtspiAccessible *accessible;
1342 accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1343 g_return_val_if_fail (accessible != NULL, NULL);
1345 accessible->app = g_object_ref (app);
1346 accessible->path = g_strdup (path);