1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <glib-object.h>
26 #include <glib/gi18n-lib.h>
32 #undef FOCUS_EVENT /* <windows.h> pollutes the namespace
33 * like a six hundred pound gorilla */
37 #include "atkmarshal.h"
38 #include "atkprivate.h"
42 * @Short_description: The base object class for the Accessibility Toolkit API.
45 * This class is the primary class for accessibility support via the
46 * Accessibility ToolKit (ATK). Objects which are instances of
47 * #AtkObject (or instances of AtkObject-derived types) are queried
48 * for properties which relate basic (and generic) properties of a UI
49 * component such as name and description. Instances of #AtkObject
50 * may also be queried as to whether they implement other ATK
51 * interfaces (e.g. #AtkAction, #AtkComponent, etc.), as appropriate
52 * to the role which a given UI component plays in a user interface.
54 * All UI components in an application which provide useful
55 * information or services to the user must provide corresponding
56 * #AtkObject instances on request (in GTK+, for instance, usually on
57 * a call to #gtk_widget_get_accessible ()), either via ATK support
58 * built into the toolkit for the widget class or ancestor class, or
59 * in the case of custom widgets, if the inherited #AtkObject
60 * implementation is insufficient, via instances of a new #AtkObject
63 * See also: #AtkObjectFactory, #AtkRegistry. (GTK+ users see also
68 static GPtrArray *role_names = NULL;
72 PROP_0, /* gobject convention */
76 PROP_PARENT, /* ancestry has changed */
82 PROP_TABLE_COLUMN_DESCRIPTION,
83 PROP_TABLE_COLUMN_HEADER,
84 PROP_TABLE_ROW_DESCRIPTION,
85 PROP_TABLE_ROW_HEADER,
87 PROP_TABLE_CAPTION_OBJECT,
88 PROP_HYPERTEXT_NUM_LINKS,
89 PROP_LAST /* gobject convention */
98 ACTIVE_DESCENDANT_CHANGED,
103 /* These are listed here for extraction by intltool */
106 N_("accelerator label")
113 N_("check menu item")
126 /* I know it looks wrong but that is what Java returns */
150 N_("radio menu item")
162 N_("table column header")
163 N_("table row header")
164 N_("tear off menu item")
182 N_("embedded component")
190 N_("redundant object")
193 N_("input method window")
196 N_("document spreadsheet")
197 N_("document presentation")
220 N_("description list")
221 N_("description term")
222 N_("description value")
225 static void atk_object_class_init (AtkObjectClass *klass);
226 static void atk_object_init (AtkObject *accessible,
227 AtkObjectClass *klass);
228 static AtkRelationSet* atk_object_real_ref_relation_set
229 (AtkObject *accessible);
230 static void atk_object_real_initialize (AtkObject *accessible,
232 static void atk_object_real_set_property (GObject *object,
236 static void atk_object_real_get_property (GObject *object,
240 static void atk_object_finalize (GObject *object);
241 static const gchar* atk_object_real_get_name (AtkObject *object);
242 static const gchar* atk_object_real_get_description
244 static AtkObject* atk_object_real_get_parent (AtkObject *object);
245 static AtkRole atk_object_real_get_role (AtkObject *object);
246 static AtkLayer atk_object_real_get_layer (AtkObject *object);
247 static AtkStateSet* atk_object_real_ref_state_set
249 static void atk_object_real_set_name (AtkObject *object,
251 static void atk_object_real_set_description
253 const gchar *description);
254 static void atk_object_real_set_parent (AtkObject *object,
256 static void atk_object_real_set_role (AtkObject *object,
258 static void atk_object_notify (GObject *obj,
260 static const gchar* atk_object_real_get_object_locale
263 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
265 static gpointer parent_class = NULL;
267 static const gchar* const atk_object_name_property_name = "accessible-name";
268 static const gchar* const atk_object_name_property_description = "accessible-description";
269 static const gchar* const atk_object_name_property_parent = "accessible-parent";
270 static const gchar* const atk_object_name_property_value = "accessible-value";
271 static const gchar* const atk_object_name_property_role = "accessible-role";
272 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
273 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
274 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
275 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
276 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
277 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
278 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
279 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
280 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
281 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
285 static HMODULE atk_dll;
288 DllMain (HINSTANCE hinstDLL,
294 case DLL_PROCESS_ATTACH:
295 atk_dll = (HMODULE) hinstDLL;
305 initialize_role_names ()
307 GTypeClass *enum_class;
308 GEnumValue *enum_value;
310 gchar *role_name = NULL;
315 role_names = g_ptr_array_new ();
316 enum_class = g_type_class_ref (ATK_TYPE_ROLE);
317 if (!G_IS_ENUM_CLASS(enum_class))
320 for (i = 0; i < ATK_ROLE_LAST_DEFINED; i++)
322 enum_value = g_enum_get_value (G_ENUM_CLASS (enum_class), i);
323 role_name = g_strdup (enum_value->value_nick);
324 // We want the role names to be in the format "check button" and not "check-button"
325 _compact_name (role_name);
326 g_ptr_array_add (role_names, role_name);
329 g_type_class_unref (enum_class);
334 atk_object_get_type (void)
336 static GType type = 0;
340 static const GTypeInfo typeInfo =
342 sizeof (AtkObjectClass),
343 (GBaseInitFunc) NULL,
344 (GBaseFinalizeFunc) NULL,
345 (GClassInitFunc) atk_object_class_init,
346 (GClassFinalizeFunc) NULL,
350 (GInstanceInitFunc) atk_object_init,
352 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
358 atk_object_class_init (AtkObjectClass *klass)
360 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
362 parent_class = g_type_class_peek_parent (klass);
364 gobject_class->set_property = atk_object_real_set_property;
365 gobject_class->get_property = atk_object_real_get_property;
366 gobject_class->finalize = atk_object_finalize;
367 gobject_class->notify = atk_object_notify;
369 klass->get_name = atk_object_real_get_name;
370 klass->get_description = atk_object_real_get_description;
371 klass->get_parent = atk_object_real_get_parent;
372 klass->get_n_children = NULL;
373 klass->ref_child = NULL;
374 klass->get_index_in_parent = NULL;
375 klass->ref_relation_set = atk_object_real_ref_relation_set;
376 klass->get_role = atk_object_real_get_role;
377 klass->get_layer = atk_object_real_get_layer;
378 klass->get_mdi_zorder = NULL;
379 klass->initialize = atk_object_real_initialize;
380 klass->ref_state_set = atk_object_real_ref_state_set;
381 klass->set_name = atk_object_real_set_name;
382 klass->set_description = atk_object_real_set_description;
383 klass->set_parent = atk_object_real_set_parent;
384 klass->set_role = atk_object_real_set_role;
385 klass->get_object_locale = atk_object_real_get_object_locale;
388 * We do not define default signal handlers here
390 klass->children_changed = NULL;
391 klass->focus_event = NULL;
392 klass->property_change = NULL;
393 klass->visible_data_changed = NULL;
394 klass->active_descendant_changed = NULL;
396 _gettext_initialization ();
398 g_object_class_install_property (gobject_class,
400 g_param_spec_string (atk_object_name_property_name,
401 _("Accessible Name"),
402 _("Object instance\'s name formatted for assistive technology access"),
405 g_object_class_install_property (gobject_class,
407 g_param_spec_string (atk_object_name_property_description,
408 _("Accessible Description"),
409 _("Description of an object, formatted for assistive technology access"),
412 g_object_class_install_property (gobject_class,
414 g_param_spec_object (atk_object_name_property_parent,
415 _("Accessible Parent"),
416 _("Parent of the current accessible as returned by atk_object_get_parent()"),
421 * AtkObject:accessible-value:
423 * Numeric value of this object, in case being and AtkValue.
425 * Deprecated: Since 2.12. Use atk_value_get_value_and_text() to get
426 * the value, and value-changed signal to be notified on their value
429 g_object_class_install_property (gobject_class,
431 g_param_spec_double (atk_object_name_property_value,
432 _("Accessible Value"),
433 _("Is used to notify that the value has changed"),
438 g_object_class_install_property (gobject_class,
440 g_param_spec_int (atk_object_name_property_role,
441 _("Accessible Role"),
442 _("The accessible role of this object"),
447 g_object_class_install_property (gobject_class,
449 g_param_spec_int (atk_object_name_property_component_layer,
450 _("Accessible Layer"),
451 _("The accessible layer of this object"),
456 g_object_class_install_property (gobject_class,
458 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
459 _("Accessible MDI Value"),
460 _("The accessible MDI value of this object"),
467 * AtkObject:accessible-table-caption:
471 * Deprecated: Since 1.3. Use table-caption-object instead.
473 g_object_class_install_property (gobject_class,
475 g_param_spec_string (atk_object_name_property_table_caption,
476 _("Accessible Table Caption"),
477 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
481 * AtkObject:accessible-table-column-header:
483 * Accessible table column header.
485 * Deprecated: Since 2.12. Use atk_table_get_column_header() and
486 * atk_table_set_column_header() instead.
488 g_object_class_install_property (gobject_class,
489 PROP_TABLE_COLUMN_HEADER,
490 g_param_spec_object (atk_object_name_property_table_column_header,
491 _("Accessible Table Column Header"),
492 _("Is used to notify that the table column header has changed"),
497 * AtkObject:accessible-table-column-description:
499 * Accessible table column description.
501 * Deprecated: Since 2.12. Use atk_table_get_column_description()
502 * and atk_table_set_column_description() instead.
504 g_object_class_install_property (gobject_class,
505 PROP_TABLE_COLUMN_DESCRIPTION,
506 g_param_spec_string (atk_object_name_property_table_column_description,
507 _("Accessible Table Column Description"),
508 _("Is used to notify that the table column description has changed"),
513 * AtkObject:accessible-table-row-header:
515 * Accessible table row header.
517 * Deprecated: Since 2.12. Use atk_table_get_row_header() and
518 * atk_table_set_row_header() instead.
520 g_object_class_install_property (gobject_class,
521 PROP_TABLE_ROW_HEADER,
522 g_param_spec_object (atk_object_name_property_table_row_header,
523 _("Accessible Table Row Header"),
524 _("Is used to notify that the table row header has changed"),
528 * AtkObject:accessible-table-row-description:
530 * Accessible table row description.
532 * Deprecated: Since 2.12. Use atk_table_get_row_description() and
533 * atk_table_set_row_description() instead.
535 g_object_class_install_property (gobject_class,
536 PROP_TABLE_ROW_DESCRIPTION,
537 g_param_spec_string (atk_object_name_property_table_row_description,
538 _("Accessible Table Row Description"),
539 _("Is used to notify that the table row description has changed"),
542 g_object_class_install_property (gobject_class,
544 g_param_spec_object (atk_object_name_property_table_summary,
545 _("Accessible Table Summary"),
546 _("Is used to notify that the table summary has changed"),
549 g_object_class_install_property (gobject_class,
550 PROP_TABLE_CAPTION_OBJECT,
551 g_param_spec_object (atk_object_name_property_table_caption_object,
552 _("Accessible Table Caption Object"),
553 _("Is used to notify that the table caption has changed"),
556 g_object_class_install_property (gobject_class,
557 PROP_HYPERTEXT_NUM_LINKS,
558 g_param_spec_int (atk_object_name_property_hypertext_num_links,
559 _("Number of Accessible Hypertext Links"),
560 _("The number of links which the current AtkHypertext has"),
567 * AtkObject::children-changed:
568 * @atkobject: the object which received the signal.
569 * @arg1: The index of the added or removed child. The value can be
570 * -1. This is used if the value is not known by the implementor
571 * when the child is added/removed or irrelevant.
572 * @arg2: A gpointer to the child AtkObject which was added or
573 * removed. If the child was removed, it is possible that it is not
574 * available for the implementor. In that case this pointer can be
577 * The signal "children-changed" is emitted when a child is added or
578 * removed form an object. It supports two details: "add" and
581 atk_object_signals[CHILDREN_CHANGED] =
582 g_signal_new ("children_changed",
583 G_TYPE_FROM_CLASS (klass),
584 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
585 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
587 g_cclosure_marshal_VOID__UINT_POINTER,
589 2, G_TYPE_UINT, G_TYPE_POINTER);
592 * AtkObject::focus-event:
593 * @atkobject: the object which received the signal
594 * @arg1: a boolean value which indicates whether the object gained
597 * The signal "focus-event" is emitted when an object gained or lost
600 * Deprecated: Since 2.9.4. Use #AtkObject::state-change signal instead.
602 atk_object_signals[FOCUS_EVENT] =
603 g_signal_new ("focus_event",
604 G_TYPE_FROM_CLASS (klass),
606 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
608 g_cclosure_marshal_VOID__BOOLEAN,
612 * AtkObject::property-change:
613 * @atkobject: the object which received the signal.
614 * @arg1: an #AtkPropertyValues containing the new value of the
615 * property which changed.
617 * The signal "property-change" is emitted when an object's property
618 * value changes. @arg1 contains an #AtkPropertyValues with the name
619 * and the new value of the property whose value has changed. Note
620 * that, as with GObject notify, getting this signal does not
621 * guarantee that the value of the property has actually changed; it
622 * may also be emitted when the setter of the property is called to
623 * reinstate the previous value.
625 * Toolkit implementor note: ATK implementors should use
626 * g_object_notify() to emit property-changed
627 * notifications. #AtkObject::property-changed is needed by the
628 * implementation of atk_add_global_event_listener() because GObject
629 * notify doesn't support emission hooks.
631 atk_object_signals[PROPERTY_CHANGE] =
632 g_signal_new ("property_change",
633 G_TYPE_FROM_CLASS (klass),
634 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
635 G_STRUCT_OFFSET (AtkObjectClass, property_change),
636 (GSignalAccumulator) NULL, NULL,
637 g_cclosure_marshal_VOID__POINTER,
642 * AtkObject::state-change:
643 * @atkobject: the object which received the signal.
644 * @arg1: The name of the state which has changed
645 * @arg2: A boolean which indicates whether the state has been set or unset.
647 * The "state-change" signal is emitted when an object's state
648 * changes. The detail value identifies the state type which has
651 atk_object_signals[STATE_CHANGE] =
652 g_signal_new ("state_change",
653 G_TYPE_FROM_CLASS (klass),
654 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
655 G_STRUCT_OFFSET (AtkObjectClass, state_change),
656 (GSignalAccumulator) NULL, NULL,
657 atk_marshal_VOID__STRING_BOOLEAN,
663 * AtkObject::visible-data-changed:
664 * @atkobject: the object which received the signal.
666 * The "visible-data-changed" signal is emitted when the visual
667 * appearance of the object changed.
669 atk_object_signals[VISIBLE_DATA_CHANGED] =
670 g_signal_new ("visible_data_changed",
671 G_TYPE_FROM_CLASS (klass),
673 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
674 (GSignalAccumulator) NULL, NULL,
675 g_cclosure_marshal_VOID__VOID,
679 * AtkObject::active-descendant-changed:
680 * @atkobject: the object which received the signal.
681 * @arg1: the newly focused object.
683 * The "active-descendant-changed" signal is emitted by an object
684 * which has the state ATK_STATE_MANAGES_DESCENDANTS when the focus
685 * object in the object changes. For instance, a table will emit the
686 * signal when the cell in the table which has focus changes.
688 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
689 g_signal_new ("active_descendant_changed",
690 G_TYPE_FROM_CLASS (klass),
691 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
692 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
694 g_cclosure_marshal_VOID__POINTER,
700 atk_object_init (AtkObject *accessible,
701 AtkObjectClass *klass)
703 accessible->name = NULL;
704 accessible->description = NULL;
705 accessible->accessible_parent = NULL;
706 accessible->relation_set = atk_relation_set_new();
707 accessible->role = ATK_ROLE_UNKNOWN;
711 atk_implementor_get_type (void)
713 static GType type = 0;
717 static const GTypeInfo typeInfo =
719 sizeof (AtkImplementorIface),
720 (GBaseInitFunc) NULL,
721 (GBaseFinalizeFunc) NULL,
724 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
731 * atk_object_get_name:
732 * @accessible: an #AtkObject
734 * Gets the accessible name of the accessible.
736 * Returns: a character string representing the accessible name of the object.
739 atk_object_get_name (AtkObject *accessible)
741 AtkObjectClass *klass;
743 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
745 klass = ATK_OBJECT_GET_CLASS (accessible);
747 return (klass->get_name) (accessible);
753 * atk_object_get_description:
754 * @accessible: an #AtkObject
756 * Gets the accessible description of the accessible.
758 * Returns: a character string representing the accessible description
763 atk_object_get_description (AtkObject *accessible)
765 AtkObjectClass *klass;
767 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
769 klass = ATK_OBJECT_GET_CLASS (accessible);
770 if (klass->get_description)
771 return (klass->get_description) (accessible);
777 * atk_object_get_parent:
778 * @accessible: an #AtkObject
780 * Gets the accessible parent of the accessible. By default this is
781 * the one assigned with atk_object_set_parent(), but it is assumed
782 * that ATK implementors have ways to get the parent of the object
783 * without the need of assigning it manually with
784 * atk_object_set_parent(), and will return it with this method.
786 * If you are only interested on the parent assigned with
787 * atk_object_set_parent(), use atk_object_peek_parent().
789 * Returns: (transfer none): an #AtkObject representing the accessible
790 * parent of the accessible
793 atk_object_get_parent (AtkObject *accessible)
795 AtkObjectClass *klass;
797 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
799 klass = ATK_OBJECT_GET_CLASS (accessible);
800 if (klass->get_parent)
801 return (klass->get_parent) (accessible);
807 * atk_object_peek_parent:
808 * @accessible: an #AtkObject
810 * Gets the accessible parent of the accessible, if it has been
811 * manually assigned with atk_object_set_parent. Otherwise, this
812 * function returns %NULL.
814 * This method is intended as an utility for ATK implementors, and not
815 * to be exposed to accessible tools. See atk_object_get_parent() for
818 * Returns: (transfer none): an #AtkObject representing the accessible
819 * parent of the accessible if assigned
822 atk_object_peek_parent (AtkObject *accessible)
824 return accessible->accessible_parent;
828 * atk_object_get_n_accessible_children:
829 * @accessible: an #AtkObject
831 * Gets the number of accessible children of the accessible.
833 * Returns: an integer representing the number of accessible children
837 atk_object_get_n_accessible_children (AtkObject *accessible)
839 AtkObjectClass *klass;
841 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
843 klass = ATK_OBJECT_GET_CLASS (accessible);
844 if (klass->get_n_children)
845 return (klass->get_n_children) (accessible);
851 * atk_object_ref_accessible_child:
852 * @accessible: an #AtkObject
853 * @i: a gint representing the position of the child, starting from 0
855 * Gets a reference to the specified accessible child of the object.
856 * The accessible children are 0-based so the first accessible child is
857 * at index 0, the second at index 1 and so on.
859 * Returns: (transfer full): an #AtkObject representing the specified
860 * accessible child of the accessible.
863 atk_object_ref_accessible_child (AtkObject *accessible,
866 AtkObjectClass *klass;
868 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
870 klass = ATK_OBJECT_GET_CLASS (accessible);
871 if (klass->ref_child)
872 return (klass->ref_child) (accessible, i);
878 * atk_object_ref_relation_set:
879 * @accessible: an #AtkObject
881 * Gets the #AtkRelationSet associated with the object.
883 * Returns: (transfer full): an #AtkRelationSet representing the relation set
887 atk_object_ref_relation_set (AtkObject *accessible)
889 AtkObjectClass *klass;
891 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
893 klass = ATK_OBJECT_GET_CLASS (accessible);
894 if (klass->ref_relation_set)
895 return (klass->ref_relation_set) (accessible);
902 * @name: a character string describing the new role.
904 * Registers the role specified by @name. @name must be a meaningful
905 * name. So it should not be empty, or consisting on whitespaces.
907 * Deprecated: Since 2.12. If your application/toolkit doesn't find a
908 * suitable role for a specific object defined at #AtkRole, please
909 * submit a bug in order to add a new role to the specification.
911 * Returns: an #AtkRole for the new role if added
912 * properly. ATK_ROLE_INVALID in case of error.
915 atk_role_register (const gchar *name)
917 gboolean valid = FALSE;
919 glong length = g_utf8_strlen (name, -1);
921 for (i=0; i < length; i++) {
929 return ATK_ROLE_INVALID;
932 initialize_role_names ();
934 g_ptr_array_add (role_names, g_strdup (name));
935 return role_names->len - 1;
939 * atk_object_get_role:
940 * @accessible: an #AtkObject
942 * Gets the role of the accessible.
944 * Returns: an #AtkRole which is the role of the accessible
947 atk_object_get_role (AtkObject *accessible)
949 AtkObjectClass *klass;
951 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
953 klass = ATK_OBJECT_GET_CLASS (accessible);
955 return (klass->get_role) (accessible);
957 return ATK_ROLE_UNKNOWN;
961 * atk_object_get_layer:
962 * @accessible: an #AtkObject
964 * Gets the layer of the accessible.
966 * Deprecated: Use atk_component_get_layer instead.
968 * Returns: an #AtkLayer which is the layer of the accessible
971 atk_object_get_layer (AtkObject *accessible)
973 AtkObjectClass *klass;
975 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
977 klass = ATK_OBJECT_GET_CLASS (accessible);
978 if (klass->get_layer)
979 return (klass->get_layer) (accessible);
981 return ATK_LAYER_INVALID;
985 * atk_object_get_mdi_zorder:
986 * @accessible: an #AtkObject
988 * Gets the zorder of the accessible. The value G_MININT will be returned
989 * if the layer of the accessible is not ATK_LAYER_MDI.
991 * Deprecated: Use atk_component_get_mdi_zorder instead.
993 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
994 * which the component is shown in relation to other components in the same
999 atk_object_get_mdi_zorder (AtkObject *accessible)
1001 AtkObjectClass *klass;
1003 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
1005 klass = ATK_OBJECT_GET_CLASS (accessible);
1006 if (klass->get_mdi_zorder)
1007 return (klass->get_mdi_zorder) (accessible);
1013 * atk_object_ref_state_set:
1014 * @accessible: an #AtkObject
1016 * Gets a reference to the state set of the accessible; the caller must
1017 * unreference it when it is no longer needed.
1019 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
1020 * set of the accessible
1023 atk_object_ref_state_set (AtkObject *accessible)
1025 AtkObjectClass *klass;
1027 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1029 klass = ATK_OBJECT_GET_CLASS (accessible);
1030 if (klass->ref_state_set)
1031 return (klass->ref_state_set) (accessible);
1037 * atk_object_get_index_in_parent:
1038 * @accessible: an #AtkObject
1040 * Gets the 0-based index of this accessible in its parent; returns -1 if the
1041 * accessible does not have an accessible parent.
1043 * Returns: an integer which is the index of the accessible in its parent
1046 atk_object_get_index_in_parent (AtkObject *accessible)
1048 AtkObjectClass *klass;
1050 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
1052 klass = ATK_OBJECT_GET_CLASS (accessible);
1053 if (klass->get_index_in_parent)
1054 return (klass->get_index_in_parent) (accessible);
1060 * atk_object_set_name:
1061 * @accessible: an #AtkObject
1062 * @name: a character string to be set as the accessible name
1064 * Sets the accessible name of the accessible. You can't set the name
1065 * to NULL. This is reserved for the initial value. In this aspect
1066 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
1067 * a empty value you can use "".
1070 atk_object_set_name (AtkObject *accessible,
1073 AtkObjectClass *klass;
1074 gboolean notify = FALSE;
1076 g_return_if_fail (ATK_IS_OBJECT (accessible));
1077 g_return_if_fail (name != NULL);
1079 klass = ATK_OBJECT_GET_CLASS (accessible);
1080 if (klass->set_name)
1082 /* Do not notify for initial name setting. See bug 665870 */
1083 notify = (accessible->name != NULL);
1085 (klass->set_name) (accessible, name);
1087 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1092 * atk_object_set_description:
1093 * @accessible: an #AtkObject
1094 * @description: a character string to be set as the accessible description
1096 * Sets the accessible description of the accessible. You can't set
1097 * the description to NULL. This is reserved for the initial value. In
1098 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
1099 * the name to a empty value you can use "".
1102 atk_object_set_description (AtkObject *accessible,
1103 const gchar *description)
1105 AtkObjectClass *klass;
1106 gboolean notify = FALSE;
1108 g_return_if_fail (ATK_IS_OBJECT (accessible));
1109 g_return_if_fail (description != NULL);
1111 klass = ATK_OBJECT_GET_CLASS (accessible);
1112 if (klass->set_description)
1114 /* Do not notify for initial name setting. See bug 665870 */
1115 notify = (accessible->description != NULL);
1117 (klass->set_description) (accessible, description);
1119 g_object_notify (G_OBJECT (accessible),
1120 atk_object_name_property_description);
1125 * atk_object_set_parent:
1126 * @accessible: an #AtkObject
1127 * @parent: an #AtkObject to be set as the accessible parent
1129 * Sets the accessible parent of the accessible. @parent can be NULL.
1132 atk_object_set_parent (AtkObject *accessible,
1135 AtkObjectClass *klass;
1137 g_return_if_fail (ATK_IS_OBJECT (accessible));
1139 klass = ATK_OBJECT_GET_CLASS (accessible);
1140 if (klass->set_parent)
1142 (klass->set_parent) (accessible, parent);
1143 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1148 * atk_object_set_role:
1149 * @accessible: an #AtkObject
1150 * @role: an #AtkRole to be set as the role
1152 * Sets the role of the accessible.
1155 atk_object_set_role (AtkObject *accessible,
1158 AtkObjectClass *klass;
1161 g_return_if_fail (ATK_IS_OBJECT (accessible));
1163 klass = ATK_OBJECT_GET_CLASS (accessible);
1164 if (klass->set_role)
1166 old_role = atk_object_get_role (accessible);
1167 if (old_role != role)
1169 (klass->set_role) (accessible, role);
1170 if (old_role != ATK_ROLE_UNKNOWN)
1171 /* Do not notify for initial role setting */
1172 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1178 * atk_object_connect_property_change_handler:
1179 * @accessible: an #AtkObject
1180 * @handler: a function to be called when a property changes its value
1182 * Deprecated: Since 2.12. Connect directly to property-change or
1185 * Returns: a #guint which is the handler id used in
1186 * atk_object_remove_property_change_handler()
1189 atk_object_connect_property_change_handler (AtkObject *accessible,
1190 AtkPropertyChangeHandler *handler)
1192 AtkObjectClass *klass;
1194 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1195 g_return_val_if_fail ((handler != NULL), 0);
1197 klass = ATK_OBJECT_GET_CLASS (accessible);
1198 if (klass->connect_property_change_handler)
1199 return (klass->connect_property_change_handler) (accessible, handler);
1205 * atk_object_remove_property_change_handler:
1206 * @accessible: an #AtkObject
1207 * @handler_id: a guint which identifies the handler to be removed.
1209 * Deprecated: Since 2.12.
1211 * Removes a property change handler.
1214 atk_object_remove_property_change_handler (AtkObject *accessible,
1217 AtkObjectClass *klass;
1219 g_return_if_fail (ATK_IS_OBJECT (accessible));
1221 klass = ATK_OBJECT_GET_CLASS (accessible);
1222 if (klass->remove_property_change_handler)
1223 (klass->remove_property_change_handler) (accessible, handler_id);
1227 * atk_object_notify_state_change:
1228 * @accessible: an #AtkObject
1229 * @state: an #AtkState whose state is changed
1230 * @value: a gboolean which indicates whether the state is being set on or off
1232 * Emits a state-change signal for the specified state.
1235 atk_object_notify_state_change (AtkObject *accessible,
1241 g_return_if_fail (ATK_IS_OBJECT (accessible));
1243 name = atk_state_type_get_name (state);
1244 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1245 g_quark_from_string (name),
1250 * atk_implementor_ref_accessible:
1251 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1252 * if a non-null return value is required.
1254 * Gets a reference to an object's #AtkObject implementation, if
1255 * the object implements #AtkObjectIface
1257 * Returns: (transfer full): a reference to an object's #AtkObject
1261 atk_implementor_ref_accessible (AtkImplementor *implementor)
1263 AtkImplementorIface *iface;
1264 AtkObject *accessible = NULL;
1266 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1268 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1271 accessible = iface->ref_accessible (implementor);
1273 g_return_val_if_fail ((accessible != NULL), NULL);
1280 * atk_object_get_attributes:
1281 * @accessible: An #AtkObject.
1283 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1284 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1285 * as distinct from strongly-typed object data available via other get/set methods.
1286 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1290 * Returns: (transfer full): an #AtkAttributeSet consisting of all
1291 * explicit properties/annotations applied to the object, or an empty
1292 * set if the object has no name-value pair attributes assigned to
1293 * it. This #atkattributeset should be freed by a call to
1294 * atk_attribute_set_free().
1297 atk_object_get_attributes (AtkObject *accessible)
1299 AtkObjectClass *klass;
1301 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1303 klass = ATK_OBJECT_GET_CLASS (accessible);
1304 if (klass->get_attributes)
1305 return (klass->get_attributes) (accessible);
1311 static AtkRelationSet*
1312 atk_object_real_ref_relation_set (AtkObject *accessible)
1314 g_return_val_if_fail (accessible->relation_set, NULL);
1315 g_object_ref (accessible->relation_set);
1317 return accessible->relation_set;
1321 atk_object_real_set_property (GObject *object,
1323 const GValue *value,
1326 AtkObject *accessible;
1328 accessible = ATK_OBJECT (object);
1333 atk_object_set_name (accessible, g_value_get_string (value));
1335 case PROP_DESCRIPTION:
1336 atk_object_set_description (accessible, g_value_get_string (value));
1339 atk_object_set_role (accessible, g_value_get_int (value));
1342 atk_object_set_parent (accessible, g_value_get_object (value));
1345 if (ATK_IS_VALUE (accessible))
1346 atk_value_set_current_value (ATK_VALUE (accessible), value);
1348 case PROP_TABLE_SUMMARY:
1349 if (ATK_IS_TABLE (accessible))
1350 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1352 case PROP_TABLE_CAPTION_OBJECT:
1353 if (ATK_IS_TABLE (accessible))
1354 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1362 atk_object_real_get_property (GObject *object,
1367 AtkObject *accessible;
1369 accessible = ATK_OBJECT (object);
1374 g_value_set_string (value, atk_object_get_name (accessible));
1376 case PROP_DESCRIPTION:
1377 g_value_set_string (value, atk_object_get_description (accessible));
1380 g_value_set_int (value, atk_object_get_role (accessible));
1383 if (ATK_IS_COMPONENT (accessible))
1384 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1386 case PROP_MDI_ZORDER:
1387 if (ATK_IS_COMPONENT (accessible))
1388 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1391 g_value_set_object (value, atk_object_get_parent (accessible));
1394 if (ATK_IS_VALUE (accessible))
1395 atk_value_get_current_value (ATK_VALUE (accessible), value);
1397 case PROP_TABLE_SUMMARY:
1398 if (ATK_IS_TABLE (accessible))
1399 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1401 case PROP_TABLE_CAPTION_OBJECT:
1402 if (ATK_IS_TABLE (accessible))
1403 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1405 case PROP_HYPERTEXT_NUM_LINKS:
1406 if (ATK_IS_HYPERTEXT (accessible))
1407 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1410 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1416 atk_object_finalize (GObject *object)
1418 AtkObject *accessible;
1420 g_return_if_fail (ATK_IS_OBJECT (object));
1422 accessible = ATK_OBJECT (object);
1424 g_free (accessible->name);
1425 g_free (accessible->description);
1428 * Free memory allocated for relation set if it have been allocated.
1430 if (accessible->relation_set)
1431 g_object_unref (accessible->relation_set);
1433 if (accessible->accessible_parent)
1434 g_object_unref (accessible->accessible_parent);
1436 G_OBJECT_CLASS (parent_class)->finalize (object);
1440 atk_object_real_get_name (AtkObject *object)
1442 return object->name;
1446 atk_object_real_get_description (AtkObject *object)
1448 return object->description;
1452 atk_object_real_get_parent (AtkObject *object)
1454 return atk_object_peek_parent (object);
1458 atk_object_real_get_role (AtkObject *object)
1460 return object->role;
1464 atk_object_real_get_layer (AtkObject *object)
1466 return object->layer;
1470 atk_object_real_ref_state_set (AtkObject *accessible)
1472 AtkStateSet *state_set;
1473 AtkObject *focus_object;
1475 state_set = atk_state_set_new ();
1477 focus_object = atk_get_focus_object ();
1478 if (focus_object == accessible)
1479 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1485 atk_object_real_set_name (AtkObject *object,
1488 g_free (object->name);
1489 object->name = g_strdup (name);
1493 atk_object_real_set_description (AtkObject *object,
1494 const gchar *description)
1496 g_free (object->description);
1497 object->description = g_strdup (description);
1501 atk_object_real_set_parent (AtkObject *object,
1504 if (object->accessible_parent)
1505 g_object_unref (object->accessible_parent);
1507 object->accessible_parent = parent;
1508 if (object->accessible_parent)
1509 g_object_ref (object->accessible_parent);
1513 atk_object_real_set_role (AtkObject *object,
1516 object->role = role;
1520 * atk_object_initialize:
1521 * @accessible: a #AtkObject
1522 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1524 * This function is called when implementing subclasses of #AtkObject.
1525 * It does initialization required for the new object. It is intended
1526 * that this function should called only in the ..._new() functions used
1527 * to create an instance of a subclass of #AtkObject
1530 atk_object_initialize (AtkObject *accessible,
1533 AtkObjectClass *klass;
1535 g_return_if_fail (ATK_IS_OBJECT (accessible));
1537 klass = ATK_OBJECT_GET_CLASS (accessible);
1538 if (klass->initialize)
1539 klass->initialize (accessible, data);
1543 * This function is a signal handler for notify signal which gets emitted
1544 * when a property changes value.
1546 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1547 * signal which causes the user specified AtkPropertyChangeHandler
1551 atk_object_notify (GObject *obj,
1554 AtkPropertyValues values = { NULL, };
1556 g_value_init (&values.new_value, pspec->value_type);
1557 g_object_get_property (obj, pspec->name, &values.new_value);
1558 values.property_name = pspec->name;
1559 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1560 g_quark_from_string (pspec->name),
1562 g_value_unset (&values.new_value);
1566 * atk_role_get_name:
1567 * @role: The #AtkRole whose name is required
1569 * Gets the description string describing the #AtkRole @role.
1571 * Returns: the string describing the AtkRole
1574 atk_role_get_name (AtkRole role)
1576 g_return_val_if_fail (role >= 0, NULL);
1579 initialize_role_names ();
1581 if (role < role_names->len)
1582 return g_ptr_array_index (role_names, role);
1588 * atk_role_get_localized_name:
1589 * @role: The #AtkRole whose localized name is required
1591 * Gets the localized description string describing the #AtkRole @role.
1593 * Returns: the localized string describing the AtkRole
1596 atk_role_get_localized_name (AtkRole role)
1598 _gettext_initialization ();
1600 return dgettext (GETTEXT_PACKAGE, atk_role_get_name (role));
1604 atk_object_real_get_object_locale (AtkObject *object)
1606 return setlocale (LC_MESSAGES, NULL);
1610 * atk_object_get_object_locale:
1611 * @accessible: an #AtkObject
1613 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
1618 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
1619 * locale of @accessible.
1622 atk_object_get_object_locale (AtkObject *accessible)
1624 AtkObjectClass *klass;
1626 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1628 klass = ATK_OBJECT_GET_CLASS (accessible);
1629 if (klass->get_object_locale)
1630 return (klass->get_object_locale) (accessible);
1637 * atk_role_for_name:
1638 * @name: a string which is the (non-localized) name of an ATK role.
1640 * Get the #AtkRole type corresponding to a rolew name.
1642 * Returns: the #AtkRole enumerated type corresponding to the specified name,
1643 * or #ATK_ROLE_INVALID if no matching role is found.
1646 atk_role_for_name (const gchar *name)
1648 AtkRole role = ATK_ROLE_INVALID;
1651 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1654 initialize_role_names ();
1656 for (i = 0; i < role_names->len; i++)
1658 gchar *role_name = (gchar *)g_ptr_array_index (role_names, i);
1660 g_return_val_if_fail (role_name, ATK_ROLE_INVALID);
1662 if (strcmp (name, role_name) == 0)
1673 * atk_object_add_relationship:
1674 * @object: The #AtkObject to which an AtkRelation is to be added.
1675 * @relationship: The #AtkRelationType of the relation
1676 * @target: The #AtkObject which is to be the target of the relation.
1678 * Adds a relationship of the specified type with the specified target.
1680 * Returns: TRUE if the relationship is added.
1683 atk_object_add_relationship (AtkObject *object,
1684 AtkRelationType relationship,
1687 AtkObject *array[1];
1688 AtkRelation *relation;
1690 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1691 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1693 if (atk_relation_set_contains_target (object->relation_set,
1694 relationship, target))
1698 relation = atk_relation_new (array, 1, relationship);
1699 atk_relation_set_add (object->relation_set, relation);
1700 g_object_unref (relation);
1706 * atk_object_remove_relationship:
1707 * @object: The #AtkObject from which an AtkRelation is to be removed.
1708 * @relationship: The #AtkRelationType of the relation
1709 * @target: The #AtkObject which is the target of the relation to be removed.
1711 * Removes a relationship of the specified type with the specified target.
1713 * Returns: TRUE if the relationship is removed.
1716 atk_object_remove_relationship (AtkObject *object,
1717 AtkRelationType relationship,
1720 gboolean ret = FALSE;
1721 AtkRelation *relation;
1724 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1725 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1727 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1731 ret = atk_relation_remove_target (relation, target);
1732 array = atk_relation_get_target (relation);
1733 if (!array || array->len == 0)
1734 atk_relation_set_remove (object->relation_set, relation);
1740 atk_object_real_initialize (AtkObject *accessible,