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.
23 #include <glib-object.h>
29 #undef FOCUS_EVENT /* <windows.h> pollutes the namespace
30 * like a six hundred pound gorilla */
34 #include "atkmarshal.h"
35 #include "atk-enum-types.h"
38 static GPtrArray *role_names = NULL;
42 PROP_0, /* gobject convention */
46 PROP_PARENT, /* ancestry has changed */
52 PROP_TABLE_COLUMN_DESCRIPTION,
53 PROP_TABLE_COLUMN_HEADER,
54 PROP_TABLE_ROW_DESCRIPTION,
55 PROP_TABLE_ROW_HEADER,
57 PROP_TABLE_CAPTION_OBJECT,
58 PROP_HYPERTEXT_NUM_LINKS,
59 PROP_LAST /* gobject convention */
68 ACTIVE_DESCENDANT_CHANGED,
73 /* These are listed here for extraction by intltool */
76 N_("accelerator label")
96 /* I know it looks wrong but that is what Java returns */
120 N_("radio menu item")
132 N_("table column header")
133 N_("table row header")
134 N_("tear off menu item")
152 N_("embedded component")
160 N_("redundant object")
163 N_("input method window")
166 N_("document spreadsheet")
167 N_("document presentation")
179 static void atk_object_class_init (AtkObjectClass *klass);
180 static void atk_object_init (AtkObject *accessible,
181 AtkObjectClass *klass);
182 static AtkRelationSet* atk_object_real_ref_relation_set
183 (AtkObject *accessible);
184 static void atk_object_real_initialize (AtkObject *accessible,
186 static void atk_object_real_set_property (GObject *object,
190 static void atk_object_real_get_property (GObject *object,
194 static void atk_object_finalize (GObject *object);
195 static const gchar* atk_object_real_get_name (AtkObject *object);
196 static const gchar* atk_object_real_get_description
198 static AtkObject* atk_object_real_get_parent (AtkObject *object);
199 static AtkRole atk_object_real_get_role (AtkObject *object);
200 static AtkLayer atk_object_real_get_layer (AtkObject *object);
201 static AtkStateSet* atk_object_real_ref_state_set
203 static void atk_object_real_set_name (AtkObject *object,
205 static void atk_object_real_set_description
207 const gchar *description);
208 static void atk_object_real_set_parent (AtkObject *object,
210 static void atk_object_real_set_role (AtkObject *object,
212 static guint atk_object_real_connect_property_change_handler
214 AtkPropertyChangeHandler
216 static void atk_object_real_remove_property_change_handler
219 static void atk_object_notify (GObject *obj,
221 static const gchar* atk_object_real_get_object_locale
224 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
226 static gpointer parent_class = NULL;
228 static const gchar* const atk_object_name_property_name = "accessible-name";
229 static const gchar* const atk_object_name_property_description = "accessible-description";
230 static const gchar* const atk_object_name_property_parent = "accessible-parent";
231 static const gchar* const atk_object_name_property_value = "accessible-value";
232 static const gchar* const atk_object_name_property_role = "accessible-role";
233 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
234 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
235 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
236 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
237 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
238 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
239 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
240 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
241 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
242 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
246 static HMODULE atk_dll;
249 DllMain (HINSTANCE hinstDLL,
255 case DLL_PROCESS_ATTACH:
256 atk_dll = (HMODULE) hinstDLL;
264 get_atk_locale_dir (void)
266 static gchar *atk_localedir = NULL;
273 /* ATK_LOCALEDIR might end in either /lib/locale or
274 * /share/locale. Scan for that slash.
276 p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
282 root = g_win32_get_package_installation_directory_of_module (atk_dll);
283 temp = g_build_filename (root, p, NULL);
286 /* atk_localedir is passed to bindtextdomain() which isn't
289 atk_localedir = g_win32_locale_filename_from_utf8 (temp);
292 return atk_localedir;
297 #define ATK_LOCALEDIR get_atk_locale_dir()
302 gettext_initialization (void)
305 static gboolean gettext_initialized = FALSE;
307 if (!gettext_initialized)
309 const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
311 gettext_initialized = TRUE;
315 bindtextdomain (GETTEXT_PACKAGE, dir);
316 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
317 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
324 compact_role_name (gchar *role_name)
326 gchar *p = role_name;
337 initialize_role_names ()
339 GTypeClass *enum_class;
340 GEnumValue *enum_value;
342 gchar *role_name = NULL;
347 role_names = g_ptr_array_new ();
348 enum_class = g_type_class_ref (ATK_TYPE_ROLE);
349 if (!G_IS_ENUM_CLASS(enum_class))
352 for (i = 0; i < ATK_ROLE_LAST_DEFINED; i++)
354 enum_value = g_enum_get_value (G_ENUM_CLASS (enum_class), i);
355 role_name = g_strdup (enum_value->value_nick);
356 // We want the role names to be in the format "check button" and not "check-button"
357 compact_role_name (role_name);
358 g_ptr_array_add (role_names, role_name);
361 g_type_class_unref (enum_class);
366 atk_object_get_type (void)
368 static GType type = 0;
372 static const GTypeInfo typeInfo =
374 sizeof (AtkObjectClass),
375 (GBaseInitFunc) NULL,
376 (GBaseFinalizeFunc) NULL,
377 (GClassInitFunc) atk_object_class_init,
378 (GClassFinalizeFunc) NULL,
382 (GInstanceInitFunc) atk_object_init,
384 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
390 atk_object_class_init (AtkObjectClass *klass)
392 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
394 parent_class = g_type_class_peek_parent (klass);
396 gobject_class->set_property = atk_object_real_set_property;
397 gobject_class->get_property = atk_object_real_get_property;
398 gobject_class->finalize = atk_object_finalize;
399 gobject_class->notify = atk_object_notify;
401 klass->get_name = atk_object_real_get_name;
402 klass->get_description = atk_object_real_get_description;
403 klass->get_parent = atk_object_real_get_parent;
404 klass->get_n_children = NULL;
405 klass->ref_child = NULL;
406 klass->get_index_in_parent = NULL;
407 klass->ref_relation_set = atk_object_real_ref_relation_set;
408 klass->get_role = atk_object_real_get_role;
409 klass->get_layer = atk_object_real_get_layer;
410 klass->get_mdi_zorder = NULL;
411 klass->initialize = atk_object_real_initialize;
412 klass->ref_state_set = atk_object_real_ref_state_set;
413 klass->set_name = atk_object_real_set_name;
414 klass->set_description = atk_object_real_set_description;
415 klass->set_parent = atk_object_real_set_parent;
416 klass->set_role = atk_object_real_set_role;
417 klass->connect_property_change_handler =
418 atk_object_real_connect_property_change_handler;
419 klass->remove_property_change_handler =
420 atk_object_real_remove_property_change_handler;
421 klass->get_object_locale = atk_object_real_get_object_locale;
424 * We do not define default signal handlers here
426 klass->children_changed = NULL;
427 klass->focus_event = NULL;
428 klass->property_change = NULL;
429 klass->visible_data_changed = NULL;
430 klass->active_descendant_changed = NULL;
432 gettext_initialization ();
434 g_object_class_install_property (gobject_class,
436 g_param_spec_string (atk_object_name_property_name,
437 _("Accessible Name"),
438 _("Object instance\'s name formatted for assistive technology access"),
441 g_object_class_install_property (gobject_class,
443 g_param_spec_string (atk_object_name_property_description,
444 _("Accessible Description"),
445 _("Description of an object, formatted for assistive technology access"),
448 g_object_class_install_property (gobject_class,
450 g_param_spec_object (atk_object_name_property_parent,
451 _("Accessible Parent"),
452 _("Is used to notify that the parent has changed"),
455 g_object_class_install_property (gobject_class,
457 g_param_spec_double (atk_object_name_property_value,
458 _("Accessible Value"),
459 _("Is used to notify that the value has changed"),
464 g_object_class_install_property (gobject_class,
466 g_param_spec_int (atk_object_name_property_role,
467 _("Accessible Role"),
468 _("The accessible role of this object"),
473 g_object_class_install_property (gobject_class,
475 g_param_spec_int (atk_object_name_property_component_layer,
476 _("Accessible Layer"),
477 _("The accessible layer of this object"),
482 g_object_class_install_property (gobject_class,
484 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
485 _("Accessible MDI Value"),
486 _("The accessible MDI value of this object"),
491 g_object_class_install_property (gobject_class,
493 g_param_spec_string (atk_object_name_property_table_caption,
494 _("Accessible Table Caption"),
495 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
498 g_object_class_install_property (gobject_class,
499 PROP_TABLE_COLUMN_HEADER,
500 g_param_spec_object (atk_object_name_property_table_column_header,
501 _("Accessible Table Column Header"),
502 _("Is used to notify that the table column header has changed"),
505 g_object_class_install_property (gobject_class,
506 PROP_TABLE_COLUMN_DESCRIPTION,
507 g_param_spec_string (atk_object_name_property_table_column_description,
508 _("Accessible Table Column Description"),
509 _("Is used to notify that the table column description has changed"),
512 g_object_class_install_property (gobject_class,
513 PROP_TABLE_ROW_HEADER,
514 g_param_spec_object (atk_object_name_property_table_row_header,
515 _("Accessible Table Row Header"),
516 _("Is used to notify that the table row header has changed"),
519 g_object_class_install_property (gobject_class,
520 PROP_TABLE_ROW_DESCRIPTION,
521 g_param_spec_string (atk_object_name_property_table_row_description,
522 _("Accessible Table Row Description"),
523 _("Is used to notify that the table row description has changed"),
526 g_object_class_install_property (gobject_class,
528 g_param_spec_object (atk_object_name_property_table_summary,
529 _("Accessible Table Summary"),
530 _("Is used to notify that the table summary has changed"),
533 g_object_class_install_property (gobject_class,
534 PROP_TABLE_CAPTION_OBJECT,
535 g_param_spec_object (atk_object_name_property_table_caption_object,
536 _("Accessible Table Caption Object"),
537 _("Is used to notify that the table caption has changed"),
540 g_object_class_install_property (gobject_class,
541 PROP_HYPERTEXT_NUM_LINKS,
542 g_param_spec_int (atk_object_name_property_hypertext_num_links,
543 _("Number of Accessible Hypertext Links"),
544 _("The number of links which the current AtkHypertext has"),
549 atk_object_signals[CHILDREN_CHANGED] =
550 g_signal_new ("children_changed",
551 G_TYPE_FROM_CLASS (klass),
552 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
553 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
555 g_cclosure_marshal_VOID__UINT_POINTER,
557 2, G_TYPE_UINT, G_TYPE_POINTER);
558 atk_object_signals[FOCUS_EVENT] =
559 g_signal_new ("focus_event",
560 G_TYPE_FROM_CLASS (klass),
562 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
564 g_cclosure_marshal_VOID__BOOLEAN,
567 atk_object_signals[PROPERTY_CHANGE] =
568 g_signal_new ("property_change",
569 G_TYPE_FROM_CLASS (klass),
570 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
571 G_STRUCT_OFFSET (AtkObjectClass, property_change),
572 (GSignalAccumulator) NULL, NULL,
573 g_cclosure_marshal_VOID__POINTER,
576 atk_object_signals[STATE_CHANGE] =
577 g_signal_new ("state_change",
578 G_TYPE_FROM_CLASS (klass),
579 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
580 G_STRUCT_OFFSET (AtkObjectClass, state_change),
581 (GSignalAccumulator) NULL, NULL,
582 atk_marshal_VOID__STRING_BOOLEAN,
586 atk_object_signals[VISIBLE_DATA_CHANGED] =
587 g_signal_new ("visible_data_changed",
588 G_TYPE_FROM_CLASS (klass),
590 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
591 (GSignalAccumulator) NULL, NULL,
592 g_cclosure_marshal_VOID__VOID,
594 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
595 g_signal_new ("active_descendant_changed",
596 G_TYPE_FROM_CLASS (klass),
597 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
598 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
600 g_cclosure_marshal_VOID__POINTER,
606 atk_object_init (AtkObject *accessible,
607 AtkObjectClass *klass)
609 accessible->name = NULL;
610 accessible->description = NULL;
611 accessible->accessible_parent = NULL;
612 accessible->relation_set = atk_relation_set_new();
613 accessible->role = ATK_ROLE_UNKNOWN;
617 atk_implementor_get_type (void)
619 static GType type = 0;
623 static const GTypeInfo typeInfo =
625 sizeof (AtkImplementorIface),
626 (GBaseInitFunc) NULL,
627 (GBaseFinalizeFunc) NULL,
630 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
637 * atk_object_get_name:
638 * @accessible: an #AtkObject
640 * Gets the accessible name of the accessible.
642 * Returns: a character string representing the accessible name of the object.
645 atk_object_get_name (AtkObject *accessible)
647 AtkObjectClass *klass;
649 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
651 klass = ATK_OBJECT_GET_CLASS (accessible);
653 return (klass->get_name) (accessible);
659 * atk_object_get_description:
660 * @accessible: an #AtkObject
662 * Gets the accessible description of the accessible.
664 * Returns: a character string representing the accessible description
669 atk_object_get_description (AtkObject *accessible)
671 AtkObjectClass *klass;
673 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
675 klass = ATK_OBJECT_GET_CLASS (accessible);
676 if (klass->get_description)
677 return (klass->get_description) (accessible);
683 * atk_object_get_parent:
684 * @accessible: an #AtkObject
686 * Gets the accessible parent of the accessible.
688 * Returns: (transfer none): a #AtkObject representing the accessible parent
692 atk_object_get_parent (AtkObject *accessible)
694 AtkObjectClass *klass;
696 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
698 klass = ATK_OBJECT_GET_CLASS (accessible);
699 if (klass->get_parent)
700 return (klass->get_parent) (accessible);
706 * atk_object_get_n_accessible_children:
707 * @accessible: an #AtkObject
709 * Gets the number of accessible children of the accessible.
711 * Returns: an integer representing the number of accessible children
715 atk_object_get_n_accessible_children (AtkObject *accessible)
717 AtkObjectClass *klass;
719 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
721 klass = ATK_OBJECT_GET_CLASS (accessible);
722 if (klass->get_n_children)
723 return (klass->get_n_children) (accessible);
729 * atk_object_ref_accessible_child:
730 * @accessible: an #AtkObject
731 * @i: a gint representing the position of the child, starting from 0
733 * Gets a reference to the specified accessible child of the object.
734 * The accessible children are 0-based so the first accessible child is
735 * at index 0, the second at index 1 and so on.
737 * Returns: (transfer full): an #AtkObject representing the specified
738 * accessible child of the accessible.
741 atk_object_ref_accessible_child (AtkObject *accessible,
744 AtkObjectClass *klass;
746 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
748 klass = ATK_OBJECT_GET_CLASS (accessible);
749 if (klass->ref_child)
750 return (klass->ref_child) (accessible, i);
756 * atk_object_ref_relation_set:
757 * @accessible: an #AtkObject
759 * Gets the #AtkRelationSet associated with the object.
761 * Returns: (transfer full): an #AtkRelationSet representing the relation set
765 atk_object_ref_relation_set (AtkObject *accessible)
767 AtkObjectClass *klass;
769 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
771 klass = ATK_OBJECT_GET_CLASS (accessible);
772 if (klass->ref_relation_set)
773 return (klass->ref_relation_set) (accessible);
780 * @name: a character string describing the new role.
782 * Registers the role specified by @name.
784 * Returns: an #AtkRole for the new role.
787 atk_role_register (const gchar *name)
790 initialize_role_names ();
792 g_ptr_array_add (role_names, g_strdup (name));
793 return role_names->len - 1;
797 * atk_object_get_role:
798 * @accessible: an #AtkObject
800 * Gets the role of the accessible.
802 * Returns: an #AtkRole which is the role of the accessible
805 atk_object_get_role (AtkObject *accessible)
807 AtkObjectClass *klass;
809 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
811 klass = ATK_OBJECT_GET_CLASS (accessible);
813 return (klass->get_role) (accessible);
815 return ATK_ROLE_UNKNOWN;
819 * atk_object_get_layer:
820 * @accessible: an #AtkObject
822 * Gets the layer of the accessible.
824 * Deprecated: Use atk_component_get_layer instead.
826 * Returns: an #AtkLayer which is the layer of the accessible
829 atk_object_get_layer (AtkObject *accessible)
831 AtkObjectClass *klass;
833 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
835 klass = ATK_OBJECT_GET_CLASS (accessible);
836 if (klass->get_layer)
837 return (klass->get_layer) (accessible);
839 return ATK_LAYER_INVALID;
843 * atk_object_get_mdi_zorder:
844 * @accessible: an #AtkObject
846 * Gets the zorder of the accessible. The value G_MININT will be returned
847 * if the layer of the accessible is not ATK_LAYER_MDI.
849 * Deprecated: Use atk_component_get_mdi_zorder instead.
851 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
852 * which the component is shown in relation to other components in the same
857 atk_object_get_mdi_zorder (AtkObject *accessible)
859 AtkObjectClass *klass;
861 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
863 klass = ATK_OBJECT_GET_CLASS (accessible);
864 if (klass->get_mdi_zorder)
865 return (klass->get_mdi_zorder) (accessible);
871 * atk_object_ref_state_set:
872 * @accessible: an #AtkObject
874 * Gets a reference to the state set of the accessible; the caller must
875 * unreference it when it is no longer needed.
877 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
878 * set of the accessible
881 atk_object_ref_state_set (AtkObject *accessible)
883 AtkObjectClass *klass;
885 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
887 klass = ATK_OBJECT_GET_CLASS (accessible);
888 if (klass->ref_state_set)
889 return (klass->ref_state_set) (accessible);
895 * atk_object_get_index_in_parent:
896 * @accessible: an #AtkObject
898 * Gets the 0-based index of this accessible in its parent; returns -1 if the
899 * accessible does not have an accessible parent.
901 * Returns: an integer which is the index of the accessible in its parent
904 atk_object_get_index_in_parent (AtkObject *accessible)
906 AtkObjectClass *klass;
908 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
910 klass = ATK_OBJECT_GET_CLASS (accessible);
911 if (klass->get_index_in_parent)
912 return (klass->get_index_in_parent) (accessible);
918 * atk_object_set_name:
919 * @accessible: an #AtkObject
920 * @name: a character string to be set as the accessible name
922 * Sets the accessible name of the accessible. You can't set the name
923 * to NULL. This is reserved for the initial value. In this aspect
924 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
925 * a empty value you can use "".
928 atk_object_set_name (AtkObject *accessible,
931 AtkObjectClass *klass;
932 gboolean notify = FALSE;
934 g_return_if_fail (ATK_IS_OBJECT (accessible));
935 g_return_if_fail (name != NULL);
937 klass = ATK_OBJECT_GET_CLASS (accessible);
940 /* Do not notify for initial name setting. See bug 665870 */
941 notify = (accessible->name != NULL);
943 (klass->set_name) (accessible, name);
945 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
950 * atk_object_set_description:
951 * @accessible: an #AtkObject
952 * @description: a character string to be set as the accessible description
954 * Sets the accessible description of the accessible. You can't set
955 * the description to NULL. This is reserved for the initial value. In
956 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
957 * the name to a empty value you can use "".
960 atk_object_set_description (AtkObject *accessible,
961 const gchar *description)
963 AtkObjectClass *klass;
964 gboolean notify = FALSE;
966 g_return_if_fail (ATK_IS_OBJECT (accessible));
967 g_return_if_fail (description != NULL);
969 klass = ATK_OBJECT_GET_CLASS (accessible);
970 if (klass->set_description)
972 /* Do not notify for initial name setting. See bug 665870 */
973 notify = (accessible->description != NULL);
975 (klass->set_description) (accessible, description);
977 g_object_notify (G_OBJECT (accessible),
978 atk_object_name_property_description);
983 * atk_object_set_parent:
984 * @accessible: an #AtkObject
985 * @parent: an #AtkObject to be set as the accessible parent
987 * Sets the accessible parent of the accessible.
990 atk_object_set_parent (AtkObject *accessible,
993 AtkObjectClass *klass;
995 g_return_if_fail (ATK_IS_OBJECT (accessible));
997 klass = ATK_OBJECT_GET_CLASS (accessible);
998 if (klass->set_parent)
1000 (klass->set_parent) (accessible, parent);
1001 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1006 * atk_object_set_role:
1007 * @accessible: an #AtkObject
1008 * @role: an #AtkRole to be set as the role
1010 * Sets the role of the accessible.
1013 atk_object_set_role (AtkObject *accessible,
1016 AtkObjectClass *klass;
1019 g_return_if_fail (ATK_IS_OBJECT (accessible));
1021 klass = ATK_OBJECT_GET_CLASS (accessible);
1022 if (klass->set_role)
1024 old_role = atk_object_get_role (accessible);
1025 if (old_role != role)
1027 (klass->set_role) (accessible, role);
1028 if (old_role != ATK_ROLE_UNKNOWN)
1029 /* Do not notify for initial role setting */
1030 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1036 * atk_object_connect_property_change_handler:
1037 * @accessible: an #AtkObject
1038 * @handler: a function to be called when a property changes its value
1040 * Specifies a function to be called when a property changes value.
1042 * Returns: a #guint which is the handler id used in
1043 * atk_object_remove_property_change_handler()
1046 atk_object_connect_property_change_handler (AtkObject *accessible,
1047 AtkPropertyChangeHandler *handler)
1049 AtkObjectClass *klass;
1051 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1052 g_return_val_if_fail ((handler != NULL), 0);
1054 klass = ATK_OBJECT_GET_CLASS (accessible);
1055 if (klass->connect_property_change_handler)
1056 return (klass->connect_property_change_handler) (accessible, handler);
1062 * atk_object_remove_property_change_handler:
1063 * @accessible: an #AtkObject
1064 * @handler_id: a guint which identifies the handler to be removed.
1066 * Removes a property change handler.
1069 atk_object_remove_property_change_handler (AtkObject *accessible,
1072 AtkObjectClass *klass;
1074 g_return_if_fail (ATK_IS_OBJECT (accessible));
1076 klass = ATK_OBJECT_GET_CLASS (accessible);
1077 if (klass->remove_property_change_handler)
1078 (klass->remove_property_change_handler) (accessible, handler_id);
1082 * atk_object_notify_state_change:
1083 * @accessible: an #AtkObject
1084 * @state: an #AtkState whose state is changed
1085 * @value: a gboolean which indicates whether the state is being set on or off
1087 * Emits a state-change signal for the specified state.
1090 atk_object_notify_state_change (AtkObject *accessible,
1096 g_return_if_fail (ATK_IS_OBJECT (accessible));
1098 name = atk_state_type_get_name (state);
1099 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1100 g_quark_from_string (name),
1105 * atk_implementor_ref_accessible:
1106 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1107 * if a non-null return value is required.
1109 * Gets a reference to an object's #AtkObject implementation, if
1110 * the object implements #AtkObjectIface
1112 * Returns: (transfer full): a reference to an object's #AtkObject
1116 atk_implementor_ref_accessible (AtkImplementor *implementor)
1118 AtkImplementorIface *iface;
1119 AtkObject *accessible = NULL;
1121 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1123 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1126 accessible = iface->ref_accessible (implementor);
1128 g_return_val_if_fail ((accessible != NULL), NULL);
1135 * atk_object_get_attributes:
1136 * @accessible: An #AtkObject.
1138 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1139 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1140 * as distinct from strongly-typed object data available via other get/set methods.
1141 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1145 * Returns: (transfer full): an #AtkAttributeSet consisting of all
1146 * explicit properties/annotations applied to the object, or an empty
1147 * set if the object has no name-value pair attributes assigned to
1148 * it. This #atkattributeset should be freed by a call to
1149 * atk_attribute_set_free().
1152 atk_object_get_attributes (AtkObject *accessible)
1154 AtkObjectClass *klass;
1156 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1158 klass = ATK_OBJECT_GET_CLASS (accessible);
1159 if (klass->get_attributes)
1160 return (klass->get_attributes) (accessible);
1166 static AtkRelationSet*
1167 atk_object_real_ref_relation_set (AtkObject *accessible)
1169 g_return_val_if_fail (accessible->relation_set, NULL);
1170 g_object_ref (accessible->relation_set);
1172 return accessible->relation_set;
1176 atk_object_real_set_property (GObject *object,
1178 const GValue *value,
1181 AtkObject *accessible;
1183 accessible = ATK_OBJECT (object);
1188 atk_object_set_name (accessible, g_value_get_string (value));
1190 case PROP_DESCRIPTION:
1191 atk_object_set_description (accessible, g_value_get_string (value));
1194 atk_object_set_role (accessible, g_value_get_int (value));
1197 atk_object_set_parent (accessible, g_value_get_object (value));
1200 if (ATK_IS_VALUE (accessible))
1201 atk_value_set_current_value (ATK_VALUE (accessible), value);
1203 case PROP_TABLE_SUMMARY:
1204 if (ATK_IS_TABLE (accessible))
1205 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1207 case PROP_TABLE_CAPTION_OBJECT:
1208 if (ATK_IS_TABLE (accessible))
1209 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1217 atk_object_real_get_property (GObject *object,
1222 AtkObject *accessible;
1224 accessible = ATK_OBJECT (object);
1229 g_value_set_string (value, atk_object_get_name (accessible));
1231 case PROP_DESCRIPTION:
1232 g_value_set_string (value, atk_object_get_description (accessible));
1235 g_value_set_int (value, atk_object_get_role (accessible));
1238 if (ATK_IS_COMPONENT (accessible))
1239 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1241 case PROP_MDI_ZORDER:
1242 if (ATK_IS_COMPONENT (accessible))
1243 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1246 g_value_set_object (value, atk_object_get_parent (accessible));
1249 if (ATK_IS_VALUE (accessible))
1250 atk_value_get_current_value (ATK_VALUE (accessible), value);
1252 case PROP_TABLE_SUMMARY:
1253 if (ATK_IS_TABLE (accessible))
1254 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1256 case PROP_TABLE_CAPTION_OBJECT:
1257 if (ATK_IS_TABLE (accessible))
1258 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1260 case PROP_HYPERTEXT_NUM_LINKS:
1261 if (ATK_IS_HYPERTEXT (accessible))
1262 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1265 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1271 atk_object_finalize (GObject *object)
1273 AtkObject *accessible;
1275 g_return_if_fail (ATK_IS_OBJECT (object));
1277 accessible = ATK_OBJECT (object);
1279 g_free (accessible->name);
1280 g_free (accessible->description);
1283 * Free memory allocated for relation set if it have been allocated.
1285 if (accessible->relation_set)
1286 g_object_unref (accessible->relation_set);
1288 if (accessible->accessible_parent)
1289 g_object_unref (accessible->accessible_parent);
1291 G_OBJECT_CLASS (parent_class)->finalize (object);
1295 atk_object_real_get_name (AtkObject *object)
1297 return object->name;
1301 atk_object_real_get_description (AtkObject *object)
1303 return object->description;
1307 atk_object_real_get_parent (AtkObject *object)
1309 return object->accessible_parent;
1313 atk_object_real_get_role (AtkObject *object)
1315 return object->role;
1319 atk_object_real_get_layer (AtkObject *object)
1321 return object->layer;
1325 atk_object_real_ref_state_set (AtkObject *accessible)
1327 AtkStateSet *state_set;
1328 AtkObject *focus_object;
1330 state_set = atk_state_set_new ();
1332 focus_object = atk_get_focus_object ();
1333 if (focus_object == accessible)
1334 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1340 atk_object_real_set_name (AtkObject *object,
1343 g_free (object->name);
1344 object->name = g_strdup (name);
1348 atk_object_real_set_description (AtkObject *object,
1349 const gchar *description)
1351 g_free (object->description);
1352 object->description = g_strdup (description);
1356 atk_object_real_set_parent (AtkObject *object,
1359 if (object->accessible_parent)
1360 g_object_unref (object->accessible_parent);
1362 object->accessible_parent = parent;
1363 if (object->accessible_parent)
1364 g_object_ref (object->accessible_parent);
1368 atk_object_real_set_role (AtkObject *object,
1371 object->role = role;
1375 atk_object_real_connect_property_change_handler (AtkObject *obj,
1376 AtkPropertyChangeHandler *handler)
1378 return g_signal_connect_closure_by_id (obj,
1379 atk_object_signals[PROPERTY_CHANGE],
1382 G_CALLBACK (handler), NULL,
1383 (GClosureNotify) NULL),
1388 atk_object_real_remove_property_change_handler (AtkObject *obj,
1391 g_signal_handler_disconnect (obj, handler_id);
1395 * atk_object_initialize:
1396 * @accessible: a #AtkObject
1397 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1399 * This function is called when implementing subclasses of #AtkObject.
1400 * It does initialization required for the new object. It is intended
1401 * that this function should called only in the ..._new() functions used
1402 * to create an instance of a subclass of #AtkObject
1405 atk_object_initialize (AtkObject *accessible,
1408 AtkObjectClass *klass;
1410 g_return_if_fail (ATK_IS_OBJECT (accessible));
1412 klass = ATK_OBJECT_GET_CLASS (accessible);
1413 if (klass->initialize)
1414 klass->initialize (accessible, data);
1418 * This function is a signal handler for notify signal which gets emitted
1419 * when a property changes value.
1421 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1422 * signal which causes the user specified AtkPropertyChangeHandler
1426 atk_object_notify (GObject *obj,
1429 AtkPropertyValues values = { NULL, };
1431 g_value_init (&values.new_value, pspec->value_type);
1432 g_object_get_property (obj, pspec->name, &values.new_value);
1433 values.property_name = pspec->name;
1434 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1435 g_quark_from_string (pspec->name),
1437 g_value_unset (&values.new_value);
1441 * atk_role_get_name:
1442 * @role: The #AtkRole whose name is required
1444 * Gets the description string describing the #AtkRole @role.
1446 * Returns: the string describing the AtkRole
1449 atk_role_get_name (AtkRole role)
1451 g_return_val_if_fail (role >= 0, NULL);
1454 initialize_role_names ();
1456 if (role < role_names->len)
1457 return g_ptr_array_index (role_names, role);
1463 * atk_role_get_localized_name:
1464 * @role: The #AtkRole whose localized name is required
1466 * Gets the localized description string describing the #AtkRole @role.
1468 * Returns: the localized string describing the AtkRole
1471 atk_role_get_localized_name (AtkRole role)
1473 gettext_initialization ();
1475 return dgettext (GETTEXT_PACKAGE, atk_role_get_name (role));
1479 atk_object_real_get_object_locale (AtkObject *object)
1481 return setlocale (LC_MESSAGES, NULL);
1485 * atk_object_get_object_locale:
1486 * @accessible: an #AtkObject
1488 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
1493 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
1494 * locale of @accessible.
1497 atk_object_get_object_locale (AtkObject *accessible)
1499 AtkObjectClass *klass;
1501 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1503 klass = ATK_OBJECT_GET_CLASS (accessible);
1504 if (klass->get_object_locale)
1505 return (klass->get_object_locale) (accessible);
1512 * atk_role_for_name:
1513 * @name: a string which is the (non-localized) name of an ATK role.
1515 * Get the #AtkRole type corresponding to a rolew name.
1517 * Returns: the #AtkRole enumerated type corresponding to the specified name,
1518 * or #ATK_ROLE_INVALID if no matching role is found.
1521 atk_role_for_name (const gchar *name)
1523 AtkRole role = ATK_ROLE_INVALID;
1526 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1529 initialize_role_names ();
1531 for (i = 0; i < role_names->len; i++)
1533 gchar *role_name = (gchar *)g_ptr_array_index (role_names, i);
1535 g_return_val_if_fail (role_name, ATK_ROLE_INVALID);
1537 if (strcmp (name, role_name) == 0)
1548 * atk_object_add_relationship:
1549 * @object: The #AtkObject to which an AtkRelation is to be added.
1550 * @relationship: The #AtkRelationType of the relation
1551 * @target: The #AtkObject which is to be the target of the relation.
1553 * Adds a relationship of the specified type with the specified target.
1555 * Returns TRUE if the relationship is added.
1558 atk_object_add_relationship (AtkObject *object,
1559 AtkRelationType relationship,
1562 AtkObject *array[1];
1563 AtkRelation *relation;
1565 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1566 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1568 if (atk_relation_set_contains_target (object->relation_set,
1569 relationship, target))
1573 relation = atk_relation_new (array, 1, relationship);
1574 atk_relation_set_add (object->relation_set, relation);
1575 g_object_unref (relation);
1581 * atk_object_remove_relationship:
1582 * @object: The #AtkObject from which an AtkRelation is to be removed.
1583 * @relationship: The #AtkRelationType of the relation
1584 * @target: The #AtkObject which is the target of the relation to be removed.
1586 * Removes a relationship of the specified type with the specified target.
1588 * Returns TRUE if the relationship is removed.
1591 atk_object_remove_relationship (AtkObject *object,
1592 AtkRelationType relationship,
1595 gboolean ret = FALSE;
1596 AtkRelation *relation;
1599 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1600 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1602 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1606 ret = atk_relation_remove_target (relation, target);
1607 array = atk_relation_get_target (relation);
1608 if (!array || array->len == 0)
1609 atk_relation_set_remove (object->relation_set, relation);
1615 atk_object_real_initialize (AtkObject *accessible,