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.
22 #include <glib-object.h>
28 #undef FOCUS_EVENT /* <windows.h> pollutes the namespace
29 * like a six hundred pound gorilla */
33 #include "atkmarshal.h"
34 #include "atk-enum-types.h"
37 static GPtrArray *extra_roles = NULL;
41 PROP_0, /* gobject convention */
45 PROP_PARENT, /* ancestry has changed */
51 PROP_TABLE_COLUMN_DESCRIPTION,
52 PROP_TABLE_COLUMN_HEADER,
53 PROP_TABLE_ROW_DESCRIPTION,
54 PROP_TABLE_ROW_HEADER,
56 PROP_TABLE_CAPTION_OBJECT,
57 PROP_HYPERTEXT_NUM_LINKS,
58 PROP_LAST /* gobject convention */
67 ACTIVE_DESCENDANT_CHANGED,
72 /* These are listed here for extraction by intltool */
75 N_("accelerator label")
95 /* I know it looks wrong but that is what Java returns */
119 N_("radio menu item")
131 N_("table column header")
132 N_("table row header")
133 N_("tear off menu item")
151 N_("embedded component")
159 N_("redundant object")
162 N_("input method window")
165 N_("document spreadsheet")
166 N_("document presentation")
178 static const char roles[] =
180 "accelerator label\0"
235 "table column header\0"
237 "tear off menu item\0"
255 "embedded component\0"
266 "input method window\0"
269 "document spreadsheet\0"
270 "document presentation\0"
282 static const guint16 roles_offsets[] = {
283 0, 8, 26, 32, 42, 48, 57, 64,
284 74, 90, 104, 118, 128, 139, 152, 166,
285 171, 178, 193, 206, 219, 226, 238, 244,
286 255, 270, 275, 281, 296, 302, 315, 320,
287 330, 335, 344, 354, 366, 375, 389, 395,
288 409, 420, 433, 445, 458, 474, 484, 495,
289 506, 518, 528, 535, 546, 558, 568, 574,
290 585, 605, 622, 641, 650, 655, 669, 678,
291 687, 692, 703, 711, 720, 727, 734, 741,
292 751, 757, 769, 782, 791, 810, 816, 822,
293 830, 845, 853, 858, 866, 883, 888, 893,
294 913, 923, 933, 954, 976, 990, 1003, 1018,
295 1026, 1035, 1044, 1054, 1067, 1075
298 /* This is a static assertion */
299 typedef int _assert_roles_num[(G_N_ELEMENTS (roles_offsets) == ATK_ROLE_LAST_DEFINED) ? 1 : -1];
301 static void atk_object_class_init (AtkObjectClass *klass);
302 static void atk_object_init (AtkObject *accessible,
303 AtkObjectClass *klass);
304 static AtkRelationSet* atk_object_real_ref_relation_set
305 (AtkObject *accessible);
306 static void atk_object_real_initialize (AtkObject *accessible,
308 static void atk_object_real_set_property (GObject *object,
312 static void atk_object_real_get_property (GObject *object,
316 static void atk_object_finalize (GObject *object);
317 static const gchar* atk_object_real_get_name (AtkObject *object);
318 static const gchar* atk_object_real_get_description
320 static AtkObject* atk_object_real_get_parent (AtkObject *object);
321 static AtkRole atk_object_real_get_role (AtkObject *object);
322 static AtkLayer atk_object_real_get_layer (AtkObject *object);
323 static AtkStateSet* atk_object_real_ref_state_set
325 static void atk_object_real_set_name (AtkObject *object,
327 static void atk_object_real_set_description
329 const gchar *description);
330 static void atk_object_real_set_parent (AtkObject *object,
332 static void atk_object_real_set_role (AtkObject *object,
334 static guint atk_object_real_connect_property_change_handler
336 AtkPropertyChangeHandler
338 static void atk_object_real_remove_property_change_handler
341 static void atk_object_notify (GObject *obj,
345 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
347 static gpointer parent_class = NULL;
349 static const gchar* const atk_object_name_property_name = "accessible-name";
350 static const gchar* const atk_object_name_property_description = "accessible-description";
351 static const gchar* const atk_object_name_property_parent = "accessible-parent";
352 static const gchar* const atk_object_name_property_value = "accessible-value";
353 static const gchar* const atk_object_name_property_role = "accessible-role";
354 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
355 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
356 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
357 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
358 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
359 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
360 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
361 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
362 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
363 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
367 static HMODULE atk_dll;
370 DllMain (HINSTANCE hinstDLL,
376 case DLL_PROCESS_ATTACH:
377 atk_dll = (HMODULE) hinstDLL;
385 get_atk_locale_dir (void)
387 static gchar *atk_localedir = NULL;
394 /* ATK_LOCALEDIR might end in either /lib/locale or
395 * /share/locale. Scan for that slash.
397 p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
403 root = g_win32_get_package_installation_directory_of_module (atk_dll);
404 temp = g_build_filename (root, p, NULL);
407 /* atk_localedir is passed to bindtextdomain() which isn't
410 atk_localedir = g_win32_locale_filename_from_utf8 (temp);
413 return atk_localedir;
418 #define ATK_LOCALEDIR get_atk_locale_dir()
423 gettext_initialization (void)
426 static gboolean gettext_initialized = FALSE;
428 if (!gettext_initialized)
430 const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
432 gettext_initialized = TRUE;
436 bindtextdomain (GETTEXT_PACKAGE, dir);
437 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
438 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
445 atk_object_get_type (void)
447 static GType type = 0;
451 static const GTypeInfo typeInfo =
453 sizeof (AtkObjectClass),
454 (GBaseInitFunc) NULL,
455 (GBaseFinalizeFunc) NULL,
456 (GClassInitFunc) atk_object_class_init,
457 (GClassFinalizeFunc) NULL,
461 (GInstanceInitFunc) atk_object_init,
463 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
469 atk_object_class_init (AtkObjectClass *klass)
471 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
473 parent_class = g_type_class_peek_parent (klass);
475 gobject_class->set_property = atk_object_real_set_property;
476 gobject_class->get_property = atk_object_real_get_property;
477 gobject_class->finalize = atk_object_finalize;
478 gobject_class->notify = atk_object_notify;
480 klass->get_name = atk_object_real_get_name;
481 klass->get_description = atk_object_real_get_description;
482 klass->get_parent = atk_object_real_get_parent;
483 klass->get_n_children = NULL;
484 klass->ref_child = NULL;
485 klass->get_index_in_parent = NULL;
486 klass->ref_relation_set = atk_object_real_ref_relation_set;
487 klass->get_role = atk_object_real_get_role;
488 klass->get_layer = atk_object_real_get_layer;
489 klass->get_mdi_zorder = NULL;
490 klass->initialize = atk_object_real_initialize;
491 klass->ref_state_set = atk_object_real_ref_state_set;
492 klass->set_name = atk_object_real_set_name;
493 klass->set_description = atk_object_real_set_description;
494 klass->set_parent = atk_object_real_set_parent;
495 klass->set_role = atk_object_real_set_role;
496 klass->connect_property_change_handler =
497 atk_object_real_connect_property_change_handler;
498 klass->remove_property_change_handler =
499 atk_object_real_remove_property_change_handler;
502 * We do not define default signal handlers here
504 klass->children_changed = NULL;
505 klass->focus_event = NULL;
506 klass->property_change = NULL;
507 klass->visible_data_changed = NULL;
508 klass->active_descendant_changed = NULL;
510 gettext_initialization ();
512 g_object_class_install_property (gobject_class,
514 g_param_spec_string (atk_object_name_property_name,
515 _("Accessible Name"),
516 _("Object instance\'s name formatted for assistive technology access"),
519 g_object_class_install_property (gobject_class,
521 g_param_spec_string (atk_object_name_property_description,
522 _("Accessible Description"),
523 _("Description of an object, formatted for assistive technology access"),
526 g_object_class_install_property (gobject_class,
528 g_param_spec_object (atk_object_name_property_parent,
529 _("Accessible Parent"),
530 _("Is used to notify that the parent has changed"),
533 g_object_class_install_property (gobject_class,
535 g_param_spec_double (atk_object_name_property_value,
536 _("Accessible Value"),
537 _("Is used to notify that the value has changed"),
542 g_object_class_install_property (gobject_class,
544 g_param_spec_int (atk_object_name_property_role,
545 _("Accessible Role"),
546 _("The accessible role of this object"),
551 g_object_class_install_property (gobject_class,
553 g_param_spec_int (atk_object_name_property_component_layer,
554 _("Accessible Layer"),
555 _("The accessible layer of this object"),
560 g_object_class_install_property (gobject_class,
562 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
563 _("Accessible MDI Value"),
564 _("The accessible MDI value of this object"),
569 g_object_class_install_property (gobject_class,
571 g_param_spec_string (atk_object_name_property_table_caption,
572 _("Accessible Table Caption"),
573 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
576 g_object_class_install_property (gobject_class,
577 PROP_TABLE_COLUMN_HEADER,
578 g_param_spec_object (atk_object_name_property_table_column_header,
579 _("Accessible Table Column Header"),
580 _("Is used to notify that the table column header has changed"),
583 g_object_class_install_property (gobject_class,
584 PROP_TABLE_COLUMN_DESCRIPTION,
585 g_param_spec_string (atk_object_name_property_table_column_description,
586 _("Accessible Table Column Description"),
587 _("Is used to notify that the table column description has changed"),
590 g_object_class_install_property (gobject_class,
591 PROP_TABLE_ROW_HEADER,
592 g_param_spec_object (atk_object_name_property_table_row_header,
593 _("Accessible Table Row Header"),
594 _("Is used to notify that the table row header has changed"),
597 g_object_class_install_property (gobject_class,
598 PROP_TABLE_ROW_DESCRIPTION,
599 g_param_spec_string (atk_object_name_property_table_row_description,
600 _("Accessible Table Row Description"),
601 _("Is used to notify that the table row description has changed"),
604 g_object_class_install_property (gobject_class,
606 g_param_spec_object (atk_object_name_property_table_summary,
607 _("Accessible Table Summary"),
608 _("Is used to notify that the table summary has changed"),
611 g_object_class_install_property (gobject_class,
612 PROP_TABLE_CAPTION_OBJECT,
613 g_param_spec_object (atk_object_name_property_table_caption_object,
614 _("Accessible Table Caption Object"),
615 _("Is used to notify that the table caption has changed"),
618 g_object_class_install_property (gobject_class,
619 PROP_HYPERTEXT_NUM_LINKS,
620 g_param_spec_int (atk_object_name_property_hypertext_num_links,
621 _("Number of Accessible Hypertext Links"),
622 _("The number of links which the current AtkHypertext has"),
627 atk_object_signals[CHILDREN_CHANGED] =
628 g_signal_new ("children_changed",
629 G_TYPE_FROM_CLASS (klass),
630 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
631 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
633 g_cclosure_marshal_VOID__UINT_POINTER,
635 2, G_TYPE_UINT, G_TYPE_POINTER);
636 atk_object_signals[FOCUS_EVENT] =
637 g_signal_new ("focus_event",
638 G_TYPE_FROM_CLASS (klass),
640 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
642 g_cclosure_marshal_VOID__BOOLEAN,
645 atk_object_signals[PROPERTY_CHANGE] =
646 g_signal_new ("property_change",
647 G_TYPE_FROM_CLASS (klass),
648 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
649 G_STRUCT_OFFSET (AtkObjectClass, property_change),
650 (GSignalAccumulator) NULL, NULL,
651 g_cclosure_marshal_VOID__POINTER,
654 atk_object_signals[STATE_CHANGE] =
655 g_signal_new ("state_change",
656 G_TYPE_FROM_CLASS (klass),
657 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
658 G_STRUCT_OFFSET (AtkObjectClass, state_change),
659 (GSignalAccumulator) NULL, NULL,
660 atk_marshal_VOID__STRING_BOOLEAN,
664 atk_object_signals[VISIBLE_DATA_CHANGED] =
665 g_signal_new ("visible_data_changed",
666 G_TYPE_FROM_CLASS (klass),
668 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
669 (GSignalAccumulator) NULL, NULL,
670 g_cclosure_marshal_VOID__VOID,
672 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
673 g_signal_new ("active_descendant_changed",
674 G_TYPE_FROM_CLASS (klass),
675 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
676 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
678 g_cclosure_marshal_VOID__POINTER,
684 atk_object_init (AtkObject *accessible,
685 AtkObjectClass *klass)
687 accessible->name = NULL;
688 accessible->description = NULL;
689 accessible->accessible_parent = NULL;
690 accessible->relation_set = atk_relation_set_new();
691 accessible->role = ATK_ROLE_UNKNOWN;
695 atk_implementor_get_type (void)
697 static GType type = 0;
701 static const GTypeInfo typeInfo =
703 sizeof (AtkImplementorIface),
704 (GBaseInitFunc) NULL,
705 (GBaseFinalizeFunc) NULL,
708 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
715 * atk_object_get_name:
716 * @accessible: an #AtkObject
718 * Gets the accessible name of the accessible.
720 * Returns: a character string representing the accessible name of the object.
723 atk_object_get_name (AtkObject *accessible)
725 AtkObjectClass *klass;
727 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
729 klass = ATK_OBJECT_GET_CLASS (accessible);
731 return (klass->get_name) (accessible);
737 * atk_object_get_description:
738 * @accessible: an #AtkObject
740 * Gets the accessible description of the accessible.
742 * Returns: a character string representing the accessible description
747 atk_object_get_description (AtkObject *accessible)
749 AtkObjectClass *klass;
751 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
753 klass = ATK_OBJECT_GET_CLASS (accessible);
754 if (klass->get_description)
755 return (klass->get_description) (accessible);
761 * atk_object_get_parent:
762 * @accessible: an #AtkObject
764 * Gets the accessible parent of the accessible.
766 * Returns: (transfer none): a #AtkObject representing the accessible parent
770 atk_object_get_parent (AtkObject *accessible)
772 AtkObjectClass *klass;
774 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
776 klass = ATK_OBJECT_GET_CLASS (accessible);
777 if (klass->get_parent)
778 return (klass->get_parent) (accessible);
784 * atk_object_get_n_accessible_children:
785 * @accessible: an #AtkObject
787 * Gets the number of accessible children of the accessible.
789 * Returns: an integer representing the number of accessible children
793 atk_object_get_n_accessible_children (AtkObject *accessible)
795 AtkObjectClass *klass;
797 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
799 klass = ATK_OBJECT_GET_CLASS (accessible);
800 if (klass->get_n_children)
801 return (klass->get_n_children) (accessible);
807 * atk_object_ref_accessible_child:
808 * @accessible: an #AtkObject
809 * @i: a gint representing the position of the child, starting from 0
811 * Gets a reference to the specified accessible child of the object.
812 * The accessible children are 0-based so the first accessible child is
813 * at index 0, the second at index 1 and so on.
815 * Returns: (transfer full): an #AtkObject representing the specified
816 * accessible child of the accessible.
819 atk_object_ref_accessible_child (AtkObject *accessible,
822 AtkObjectClass *klass;
824 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
826 klass = ATK_OBJECT_GET_CLASS (accessible);
827 if (klass->ref_child)
828 return (klass->ref_child) (accessible, i);
834 * atk_object_ref_relation_set:
835 * @accessible: an #AtkObject
837 * Gets the #AtkRelationSet associated with the object.
839 * Returns: (transfer full): an #AtkRelationSet representing the relation set
843 atk_object_ref_relation_set (AtkObject *accessible)
845 AtkObjectClass *klass;
847 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
849 klass = ATK_OBJECT_GET_CLASS (accessible);
850 if (klass->ref_relation_set)
851 return (klass->ref_relation_set) (accessible);
858 * @name: a character string describing the new role.
860 * Registers the role specified by @name.
862 * Returns: an #AtkRole for the new role.
865 atk_role_register (const gchar *name)
868 extra_roles = g_ptr_array_new ();
870 g_ptr_array_add (extra_roles, g_strdup (name));
871 return extra_roles->len + ATK_ROLE_LAST_DEFINED;
875 * atk_object_get_role:
876 * @accessible: an #AtkObject
878 * Gets the role of the accessible.
880 * Returns: an #AtkRole which is the role of the accessible
883 atk_object_get_role (AtkObject *accessible)
885 AtkObjectClass *klass;
887 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
889 klass = ATK_OBJECT_GET_CLASS (accessible);
891 return (klass->get_role) (accessible);
893 return ATK_ROLE_UNKNOWN;
897 * atk_object_get_layer:
898 * @accessible: an #AtkObject
900 * Gets the layer of the accessible.
902 * Deprecated: Use atk_component_get_layer instead.
904 * Returns: an #AtkLayer which is the layer of the accessible
907 atk_object_get_layer (AtkObject *accessible)
909 AtkObjectClass *klass;
911 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
913 klass = ATK_OBJECT_GET_CLASS (accessible);
914 if (klass->get_layer)
915 return (klass->get_layer) (accessible);
917 return ATK_LAYER_INVALID;
921 * atk_object_get_mdi_zorder:
922 * @accessible: an #AtkObject
924 * Gets the zorder of the accessible. The value G_MININT will be returned
925 * if the layer of the accessible is not ATK_LAYER_MDI.
927 * Deprecated: Use atk_component_get_mdi_zorder instead.
929 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
930 * which the component is shown in relation to other components in the same
935 atk_object_get_mdi_zorder (AtkObject *accessible)
937 AtkObjectClass *klass;
939 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
941 klass = ATK_OBJECT_GET_CLASS (accessible);
942 if (klass->get_mdi_zorder)
943 return (klass->get_mdi_zorder) (accessible);
949 * atk_object_ref_state_set:
950 * @accessible: an #AtkObject
952 * Gets a reference to the state set of the accessible; the caller must
953 * unreference it when it is no longer needed.
955 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
956 * set of the accessible
959 atk_object_ref_state_set (AtkObject *accessible)
961 AtkObjectClass *klass;
963 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
965 klass = ATK_OBJECT_GET_CLASS (accessible);
966 if (klass->ref_state_set)
967 return (klass->ref_state_set) (accessible);
973 * atk_object_get_index_in_parent:
974 * @accessible: an #AtkObject
976 * Gets the 0-based index of this accessible in its parent; returns -1 if the
977 * accessible does not have an accessible parent.
979 * Returns: an integer which is the index of the accessible in its parent
982 atk_object_get_index_in_parent (AtkObject *accessible)
984 AtkObjectClass *klass;
986 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
988 klass = ATK_OBJECT_GET_CLASS (accessible);
989 if (klass->get_index_in_parent)
990 return (klass->get_index_in_parent) (accessible);
996 * atk_object_set_name:
997 * @accessible: an #AtkObject
998 * @name: a character string to be set as the accessible name
1000 * Sets the accessible name of the accessible. You can't set the name
1001 * to NULL. This is reserved for the initial value. In this aspect
1002 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
1003 * a empty value you can use "".
1006 atk_object_set_name (AtkObject *accessible,
1009 AtkObjectClass *klass;
1010 gboolean notify = FALSE;
1012 g_return_if_fail (ATK_IS_OBJECT (accessible));
1013 g_return_if_fail (name != NULL);
1015 klass = ATK_OBJECT_GET_CLASS (accessible);
1016 if (klass->set_name)
1018 /* Do not notify for initial name setting. See bug 665870 */
1019 notify = (accessible->name != NULL);
1021 (klass->set_name) (accessible, name);
1023 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1028 * atk_object_set_description:
1029 * @accessible: an #AtkObject
1030 * @description: a character string to be set as the accessible description
1032 * Sets the accessible description of the accessible. You can't set
1033 * the description to NULL. This is reserved for the initial value. In
1034 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
1035 * the name to a empty value you can use "".
1038 atk_object_set_description (AtkObject *accessible,
1039 const gchar *description)
1041 AtkObjectClass *klass;
1042 gboolean notify = FALSE;
1044 g_return_if_fail (ATK_IS_OBJECT (accessible));
1045 g_return_if_fail (description != NULL);
1047 klass = ATK_OBJECT_GET_CLASS (accessible);
1048 if (klass->set_description)
1050 /* Do not notify for initial name setting. See bug 665870 */
1051 notify = (accessible->description != NULL);
1053 (klass->set_description) (accessible, description);
1055 g_object_notify (G_OBJECT (accessible),
1056 atk_object_name_property_description);
1061 * atk_object_set_parent:
1062 * @accessible: an #AtkObject
1063 * @parent: an #AtkObject to be set as the accessible parent
1065 * Sets the accessible parent of the accessible.
1068 atk_object_set_parent (AtkObject *accessible,
1071 AtkObjectClass *klass;
1073 g_return_if_fail (ATK_IS_OBJECT (accessible));
1075 klass = ATK_OBJECT_GET_CLASS (accessible);
1076 if (klass->set_parent)
1078 (klass->set_parent) (accessible, parent);
1079 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1084 * atk_object_set_role:
1085 * @accessible: an #AtkObject
1086 * @role: an #AtkRole to be set as the role
1088 * Sets the role of the accessible.
1091 atk_object_set_role (AtkObject *accessible,
1094 AtkObjectClass *klass;
1097 g_return_if_fail (ATK_IS_OBJECT (accessible));
1099 klass = ATK_OBJECT_GET_CLASS (accessible);
1100 if (klass->set_role)
1102 old_role = atk_object_get_role (accessible);
1103 if (old_role != role)
1105 (klass->set_role) (accessible, role);
1106 if (old_role != ATK_ROLE_UNKNOWN)
1107 /* Do not notify for initial role setting */
1108 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1114 * atk_object_connect_property_change_handler:
1115 * @accessible: an #AtkObject
1116 * @handler: a function to be called when a property changes its value
1118 * Specifies a function to be called when a property changes value.
1120 * Returns: a #guint which is the handler id used in
1121 * atk_object_remove_property_change_handler()
1124 atk_object_connect_property_change_handler (AtkObject *accessible,
1125 AtkPropertyChangeHandler *handler)
1127 AtkObjectClass *klass;
1129 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1130 g_return_val_if_fail ((handler != NULL), 0);
1132 klass = ATK_OBJECT_GET_CLASS (accessible);
1133 if (klass->connect_property_change_handler)
1134 return (klass->connect_property_change_handler) (accessible, handler);
1140 * atk_object_remove_property_change_handler:
1141 * @accessible: an #AtkObject
1142 * @handler_id: a guint which identifies the handler to be removed.
1144 * Removes a property change handler.
1147 atk_object_remove_property_change_handler (AtkObject *accessible,
1150 AtkObjectClass *klass;
1152 g_return_if_fail (ATK_IS_OBJECT (accessible));
1154 klass = ATK_OBJECT_GET_CLASS (accessible);
1155 if (klass->remove_property_change_handler)
1156 (klass->remove_property_change_handler) (accessible, handler_id);
1160 * atk_object_notify_state_change:
1161 * @accessible: an #AtkObject
1162 * @state: an #AtkState whose state is changed
1163 * @value: a gboolean which indicates whether the state is being set on or off
1165 * Emits a state-change signal for the specified state.
1168 atk_object_notify_state_change (AtkObject *accessible,
1174 g_return_if_fail (ATK_IS_OBJECT (accessible));
1176 name = atk_state_type_get_name (state);
1177 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1178 g_quark_from_string (name),
1183 * atk_implementor_ref_accessible:
1184 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1185 * if a non-null return value is required.
1187 * Gets a reference to an object's #AtkObject implementation, if
1188 * the object implements #AtkObjectIface
1190 * Returns: (transfer full): a reference to an object's #AtkObject
1194 atk_implementor_ref_accessible (AtkImplementor *implementor)
1196 AtkImplementorIface *iface;
1197 AtkObject *accessible = NULL;
1199 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1201 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1204 accessible = iface->ref_accessible (implementor);
1206 g_return_val_if_fail ((accessible != NULL), NULL);
1213 * atk_object_get_attributes:
1214 * @accessible: An #AtkObject.
1216 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1217 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1218 * as distinct from strongly-typed object data available via other get/set methods.
1219 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1223 * Returns: (transfer none): an #AtkAttributeSet consisting of all explicit
1224 * properties/annotations applied to the object, or an empty set if the object
1225 * has no name-value pair attributes assigned to it.
1228 atk_object_get_attributes (AtkObject *accessible)
1230 AtkObjectClass *klass;
1232 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1234 klass = ATK_OBJECT_GET_CLASS (accessible);
1235 if (klass->get_attributes)
1236 return (klass->get_attributes) (accessible);
1242 static AtkRelationSet*
1243 atk_object_real_ref_relation_set (AtkObject *accessible)
1245 g_return_val_if_fail (accessible->relation_set, NULL);
1246 g_object_ref (accessible->relation_set);
1248 return accessible->relation_set;
1252 atk_object_real_set_property (GObject *object,
1254 const GValue *value,
1257 AtkObject *accessible;
1259 accessible = ATK_OBJECT (object);
1264 atk_object_set_name (accessible, g_value_get_string (value));
1266 case PROP_DESCRIPTION:
1267 atk_object_set_description (accessible, g_value_get_string (value));
1270 atk_object_set_role (accessible, g_value_get_int (value));
1273 atk_object_set_parent (accessible, g_value_get_object (value));
1276 if (ATK_IS_VALUE (accessible))
1277 atk_value_set_current_value (ATK_VALUE (accessible), value);
1279 case PROP_TABLE_SUMMARY:
1280 if (ATK_IS_TABLE (accessible))
1281 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1283 case PROP_TABLE_CAPTION_OBJECT:
1284 if (ATK_IS_TABLE (accessible))
1285 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1293 atk_object_real_get_property (GObject *object,
1298 AtkObject *accessible;
1300 accessible = ATK_OBJECT (object);
1305 g_value_set_string (value, atk_object_get_name (accessible));
1307 case PROP_DESCRIPTION:
1308 g_value_set_string (value, atk_object_get_description (accessible));
1311 g_value_set_int (value, atk_object_get_role (accessible));
1314 if (ATK_IS_COMPONENT (accessible))
1315 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1317 case PROP_MDI_ZORDER:
1318 if (ATK_IS_COMPONENT (accessible))
1319 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1322 g_value_set_object (value, atk_object_get_parent (accessible));
1325 if (ATK_IS_VALUE (accessible))
1326 atk_value_get_current_value (ATK_VALUE (accessible), value);
1328 case PROP_TABLE_SUMMARY:
1329 if (ATK_IS_TABLE (accessible))
1330 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1332 case PROP_TABLE_CAPTION_OBJECT:
1333 if (ATK_IS_TABLE (accessible))
1334 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1336 case PROP_HYPERTEXT_NUM_LINKS:
1337 if (ATK_IS_HYPERTEXT (accessible))
1338 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1341 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1347 atk_object_finalize (GObject *object)
1349 AtkObject *accessible;
1351 g_return_if_fail (ATK_IS_OBJECT (object));
1353 accessible = ATK_OBJECT (object);
1355 g_free (accessible->name);
1356 g_free (accessible->description);
1359 * Free memory allocated for relation set if it have been allocated.
1361 if (accessible->relation_set)
1362 g_object_unref (accessible->relation_set);
1364 if (accessible->accessible_parent)
1365 g_object_unref (accessible->accessible_parent);
1367 G_OBJECT_CLASS (parent_class)->finalize (object);
1371 atk_object_real_get_name (AtkObject *object)
1373 return object->name;
1377 atk_object_real_get_description (AtkObject *object)
1379 return object->description;
1383 atk_object_real_get_parent (AtkObject *object)
1385 return object->accessible_parent;
1389 atk_object_real_get_role (AtkObject *object)
1391 return object->role;
1395 atk_object_real_get_layer (AtkObject *object)
1397 return object->layer;
1401 atk_object_real_ref_state_set (AtkObject *accessible)
1403 AtkStateSet *state_set;
1404 AtkObject *focus_object;
1406 state_set = atk_state_set_new ();
1408 focus_object = atk_get_focus_object ();
1409 if (focus_object == accessible)
1410 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1416 atk_object_real_set_name (AtkObject *object,
1419 g_free (object->name);
1420 object->name = g_strdup (name);
1424 atk_object_real_set_description (AtkObject *object,
1425 const gchar *description)
1427 g_free (object->description);
1428 object->description = g_strdup (description);
1432 atk_object_real_set_parent (AtkObject *object,
1435 if (object->accessible_parent)
1436 g_object_unref (object->accessible_parent);
1438 object->accessible_parent = parent;
1439 if (object->accessible_parent)
1440 g_object_ref (object->accessible_parent);
1444 atk_object_real_set_role (AtkObject *object,
1447 object->role = role;
1451 atk_object_real_connect_property_change_handler (AtkObject *obj,
1452 AtkPropertyChangeHandler *handler)
1454 return g_signal_connect_closure_by_id (obj,
1455 atk_object_signals[PROPERTY_CHANGE],
1458 G_CALLBACK (handler), NULL,
1459 (GClosureNotify) NULL),
1464 atk_object_real_remove_property_change_handler (AtkObject *obj,
1467 g_signal_handler_disconnect (obj, handler_id);
1471 * atk_object_initialize:
1472 * @accessible: a #AtkObject
1473 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1475 * This function is called when implementing subclasses of #AtkObject.
1476 * It does initialization required for the new object. It is intended
1477 * that this function should called only in the ..._new() functions used
1478 * to create an instance of a subclass of #AtkObject
1481 atk_object_initialize (AtkObject *accessible,
1484 AtkObjectClass *klass;
1486 g_return_if_fail (ATK_IS_OBJECT (accessible));
1488 klass = ATK_OBJECT_GET_CLASS (accessible);
1489 if (klass->initialize)
1490 klass->initialize (accessible, data);
1494 * This function is a signal handler for notify signal which gets emitted
1495 * when a property changes value.
1497 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1498 * signal which causes the user specified AtkPropertyChangeHandler
1502 atk_object_notify (GObject *obj,
1505 AtkPropertyValues values = { NULL, };
1507 g_value_init (&values.new_value, pspec->value_type);
1508 g_object_get_property (obj, pspec->name, &values.new_value);
1509 values.property_name = pspec->name;
1510 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1511 g_quark_from_string (pspec->name),
1513 g_value_unset (&values.new_value);
1517 * atk_role_get_name:
1518 * @role: The #AtkRole whose name is required
1520 * Gets the description string describing the #AtkRole @role.
1522 * Returns: the string describing the AtkRole
1525 atk_role_get_name (AtkRole role)
1527 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1528 return roles + roles_offsets[role];
1534 n -= ATK_ROLE_LAST_DEFINED + 1;
1536 if (n >= 0 && n < extra_roles->len)
1537 return g_ptr_array_index (extra_roles, n);
1544 * atk_role_get_localized_name:
1545 * @role: The #AtkRole whose localized name is required
1547 * Gets the localized description string describing the #AtkRole @role.
1549 * Returns: the localized string describing the AtkRole
1552 atk_role_get_localized_name (AtkRole role)
1554 gettext_initialization ();
1556 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1557 return dgettext (GETTEXT_PACKAGE, roles + roles_offsets[role]);
1559 return atk_role_get_name (role);
1563 * atk_role_for_name:
1564 * @name: a string which is the (non-localized) name of an ATK role.
1566 * Get the #AtkRole type corresponding to a rolew name.
1568 * Returns: the #AtkRole enumerated type corresponding to the specified
1570 * or #ATK_ROLE_INVALID if no matching role is found.
1573 atk_role_for_name (const gchar *name)
1575 AtkRole role = ATK_ROLE_INVALID;
1578 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1580 for (i = 0; i < G_N_ELEMENTS (roles_offsets); i++)
1582 if (strcmp (name, roles + roles_offsets[i]) == 0)
1588 for (i = 0; i < extra_roles->len; i++)
1590 gchar *extra_role = (gchar *)g_ptr_array_index (extra_roles, i);
1592 g_return_val_if_fail (extra_role, ATK_ROLE_INVALID);
1594 if (strcmp (name, extra_role) == 0)
1596 role = i + 1 + ATK_ROLE_LAST_DEFINED;
1606 * atk_object_add_relationship:
1607 * @object: The #AtkObject to which an AtkRelation is to be added.
1608 * @relationship: The #AtkRelationType of the relation
1609 * @target: The #AtkObject which is to be the target of the relation.
1611 * Adds a relationship of the specified type with the specified target.
1613 * Returns TRUE if the relationship is added.
1616 atk_object_add_relationship (AtkObject *object,
1617 AtkRelationType relationship,
1620 AtkObject *array[1];
1621 AtkRelation *relation;
1623 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1624 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1626 if (atk_relation_set_contains_target (object->relation_set,
1627 relationship, target))
1631 relation = atk_relation_new (array, 1, relationship);
1632 atk_relation_set_add (object->relation_set, relation);
1633 g_object_unref (relation);
1639 * atk_object_remove_relationship:
1640 * @object: The #AtkObject from which an AtkRelation is to be removed.
1641 * @relationship: The #AtkRelationType of the relation
1642 * @target: The #AtkObject which is the target of the relation to be removed.
1644 * Removes a relationship of the specified type with the specified target.
1646 * Returns TRUE if the relationship is removed.
1649 atk_object_remove_relationship (AtkObject *object,
1650 AtkRelationType relationship,
1653 gboolean ret = FALSE;
1654 AtkRelation *relation;
1657 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1658 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1660 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1664 ret = atk_relation_remove_target (relation, target);
1665 array = atk_relation_get_target (relation);
1666 if (!array || array->len == 0)
1667 atk_relation_set_remove (object->relation_set, relation);
1673 atk_object_real_initialize (AtkObject *accessible,