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"
281 static const guint16 roles_offsets[] = {
282 0, 8, 26, 32, 42, 48, 57, 64,
283 74, 90, 104, 118, 128, 139, 152, 166,
284 171, 178, 193, 206, 219, 226, 238, 244,
285 255, 270, 275, 281, 296, 302, 315, 320,
286 330, 335, 344, 354, 366, 375, 389, 395,
287 409, 420, 433, 445, 458, 474, 484, 495,
288 506, 518, 528, 535, 546, 558, 568, 574,
289 585, 605, 622, 641, 650, 655, 669, 678,
290 687, 692, 703, 711, 720, 727, 734, 741,
291 751, 757, 769, 782, 791, 810, 816, 822,
292 830, 845, 853, 858, 866, 883, 888, 893,
293 913, 923, 933, 954, 976, 990, 1003, 1018,
294 1026, 1035, 1044, 1054, 1067
297 /* This is a static assertion */
298 typedef int _assert_roles_num[(G_N_ELEMENTS (roles_offsets) == ATK_ROLE_LAST_DEFINED) ? 1 : -1];
300 static void atk_object_class_init (AtkObjectClass *klass);
301 static void atk_object_init (AtkObject *accessible,
302 AtkObjectClass *klass);
303 static AtkRelationSet* atk_object_real_ref_relation_set
304 (AtkObject *accessible);
305 static void atk_object_real_initialize (AtkObject *accessible,
307 static void atk_object_real_set_property (GObject *object,
311 static void atk_object_real_get_property (GObject *object,
315 static void atk_object_finalize (GObject *object);
316 static const gchar* atk_object_real_get_name (AtkObject *object);
317 static const gchar* atk_object_real_get_description
319 static AtkObject* atk_object_real_get_parent (AtkObject *object);
320 static AtkRole atk_object_real_get_role (AtkObject *object);
321 static AtkLayer atk_object_real_get_layer (AtkObject *object);
322 static AtkStateSet* atk_object_real_ref_state_set
324 static void atk_object_real_set_name (AtkObject *object,
326 static void atk_object_real_set_description
328 const gchar *description);
329 static void atk_object_real_set_parent (AtkObject *object,
331 static void atk_object_real_set_role (AtkObject *object,
333 static guint atk_object_real_connect_property_change_handler
335 AtkPropertyChangeHandler
337 static void atk_object_real_remove_property_change_handler
340 static void atk_object_notify (GObject *obj,
344 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
346 static gpointer parent_class = NULL;
348 static const gchar* const atk_object_name_property_name = "accessible-name";
349 static const gchar* const atk_object_name_property_description = "accessible-description";
350 static const gchar* const atk_object_name_property_parent = "accessible-parent";
351 static const gchar* const atk_object_name_property_value = "accessible-value";
352 static const gchar* const atk_object_name_property_role = "accessible-role";
353 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
354 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
355 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
356 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
357 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
358 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
359 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
360 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
361 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
362 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
366 static HMODULE atk_dll;
369 DllMain (HINSTANCE hinstDLL,
375 case DLL_PROCESS_ATTACH:
376 atk_dll = (HMODULE) hinstDLL;
384 get_atk_locale_dir (void)
386 static gchar *atk_localedir = NULL;
393 /* ATK_LOCALEDIR might end in either /lib/locale or
394 * /share/locale. Scan for that slash.
396 p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
402 root = g_win32_get_package_installation_directory_of_module (atk_dll);
403 temp = g_build_filename (root, p, NULL);
406 /* atk_localedir is passed to bindtextdomain() which isn't
409 atk_localedir = g_win32_locale_filename_from_utf8 (temp);
412 return atk_localedir;
417 #define ATK_LOCALEDIR get_atk_locale_dir()
422 gettext_initialization (void)
425 static gboolean gettext_initialized = FALSE;
427 if (!gettext_initialized)
429 const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
431 gettext_initialized = TRUE;
435 bindtextdomain (GETTEXT_PACKAGE, dir);
436 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
437 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
444 atk_object_get_type (void)
446 static GType type = 0;
450 static const GTypeInfo typeInfo =
452 sizeof (AtkObjectClass),
453 (GBaseInitFunc) NULL,
454 (GBaseFinalizeFunc) NULL,
455 (GClassInitFunc) atk_object_class_init,
456 (GClassFinalizeFunc) NULL,
460 (GInstanceInitFunc) atk_object_init,
462 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
468 atk_object_class_init (AtkObjectClass *klass)
470 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
472 parent_class = g_type_class_peek_parent (klass);
474 gobject_class->set_property = atk_object_real_set_property;
475 gobject_class->get_property = atk_object_real_get_property;
476 gobject_class->finalize = atk_object_finalize;
477 gobject_class->notify = atk_object_notify;
479 klass->get_name = atk_object_real_get_name;
480 klass->get_description = atk_object_real_get_description;
481 klass->get_parent = atk_object_real_get_parent;
482 klass->get_n_children = NULL;
483 klass->ref_child = NULL;
484 klass->get_index_in_parent = NULL;
485 klass->ref_relation_set = atk_object_real_ref_relation_set;
486 klass->get_role = atk_object_real_get_role;
487 klass->get_layer = atk_object_real_get_layer;
488 klass->get_mdi_zorder = NULL;
489 klass->initialize = atk_object_real_initialize;
490 klass->ref_state_set = atk_object_real_ref_state_set;
491 klass->set_name = atk_object_real_set_name;
492 klass->set_description = atk_object_real_set_description;
493 klass->set_parent = atk_object_real_set_parent;
494 klass->set_role = atk_object_real_set_role;
495 klass->connect_property_change_handler =
496 atk_object_real_connect_property_change_handler;
497 klass->remove_property_change_handler =
498 atk_object_real_remove_property_change_handler;
501 * We do not define default signal handlers here
503 klass->children_changed = NULL;
504 klass->focus_event = NULL;
505 klass->property_change = NULL;
506 klass->visible_data_changed = NULL;
507 klass->active_descendant_changed = NULL;
509 gettext_initialization ();
511 g_object_class_install_property (gobject_class,
513 g_param_spec_string (atk_object_name_property_name,
514 _("Accessible Name"),
515 _("Object instance\'s name formatted for assistive technology access"),
518 g_object_class_install_property (gobject_class,
520 g_param_spec_string (atk_object_name_property_description,
521 _("Accessible Description"),
522 _("Description of an object, formatted for assistive technology access"),
525 g_object_class_install_property (gobject_class,
527 g_param_spec_object (atk_object_name_property_parent,
528 _("Accessible Parent"),
529 _("Is used to notify that the parent has changed"),
532 g_object_class_install_property (gobject_class,
534 g_param_spec_double (atk_object_name_property_value,
535 _("Accessible Value"),
536 _("Is used to notify that the value has changed"),
541 g_object_class_install_property (gobject_class,
543 g_param_spec_int (atk_object_name_property_role,
544 _("Accessible Role"),
545 _("The accessible role of this object"),
550 g_object_class_install_property (gobject_class,
552 g_param_spec_int (atk_object_name_property_component_layer,
553 _("Accessible Layer"),
554 _("The accessible layer of this object"),
559 g_object_class_install_property (gobject_class,
561 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
562 _("Accessible MDI Value"),
563 _("The accessible MDI value of this object"),
568 g_object_class_install_property (gobject_class,
570 g_param_spec_string (atk_object_name_property_table_caption,
571 _("Accessible Table Caption"),
572 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
575 g_object_class_install_property (gobject_class,
576 PROP_TABLE_COLUMN_HEADER,
577 g_param_spec_object (atk_object_name_property_table_column_header,
578 _("Accessible Table Column Header"),
579 _("Is used to notify that the table column header has changed"),
582 g_object_class_install_property (gobject_class,
583 PROP_TABLE_COLUMN_DESCRIPTION,
584 g_param_spec_string (atk_object_name_property_table_column_description,
585 _("Accessible Table Column Description"),
586 _("Is used to notify that the table column description has changed"),
589 g_object_class_install_property (gobject_class,
590 PROP_TABLE_ROW_HEADER,
591 g_param_spec_object (atk_object_name_property_table_row_header,
592 _("Accessible Table Row Header"),
593 _("Is used to notify that the table row header has changed"),
596 g_object_class_install_property (gobject_class,
597 PROP_TABLE_ROW_DESCRIPTION,
598 g_param_spec_string (atk_object_name_property_table_row_description,
599 _("Accessible Table Row Description"),
600 _("Is used to notify that the table row description has changed"),
603 g_object_class_install_property (gobject_class,
605 g_param_spec_object (atk_object_name_property_table_summary,
606 _("Accessible Table Summary"),
607 _("Is used to notify that the table summary has changed"),
610 g_object_class_install_property (gobject_class,
611 PROP_TABLE_CAPTION_OBJECT,
612 g_param_spec_object (atk_object_name_property_table_caption_object,
613 _("Accessible Table Caption Object"),
614 _("Is used to notify that the table caption has changed"),
617 g_object_class_install_property (gobject_class,
618 PROP_HYPERTEXT_NUM_LINKS,
619 g_param_spec_int (atk_object_name_property_hypertext_num_links,
620 _("Number of Accessible Hypertext Links"),
621 _("The number of links which the current AtkHypertext has"),
626 atk_object_signals[CHILDREN_CHANGED] =
627 g_signal_new ("children_changed",
628 G_TYPE_FROM_CLASS (klass),
629 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
630 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
632 g_cclosure_marshal_VOID__UINT_POINTER,
634 2, G_TYPE_UINT, G_TYPE_POINTER);
635 atk_object_signals[FOCUS_EVENT] =
636 g_signal_new ("focus_event",
637 G_TYPE_FROM_CLASS (klass),
639 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
641 g_cclosure_marshal_VOID__BOOLEAN,
644 atk_object_signals[PROPERTY_CHANGE] =
645 g_signal_new ("property_change",
646 G_TYPE_FROM_CLASS (klass),
647 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
648 G_STRUCT_OFFSET (AtkObjectClass, property_change),
649 (GSignalAccumulator) NULL, NULL,
650 g_cclosure_marshal_VOID__POINTER,
653 atk_object_signals[STATE_CHANGE] =
654 g_signal_new ("state_change",
655 G_TYPE_FROM_CLASS (klass),
656 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
657 G_STRUCT_OFFSET (AtkObjectClass, state_change),
658 (GSignalAccumulator) NULL, NULL,
659 atk_marshal_VOID__STRING_BOOLEAN,
663 atk_object_signals[VISIBLE_DATA_CHANGED] =
664 g_signal_new ("visible_data_changed",
665 G_TYPE_FROM_CLASS (klass),
667 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
668 (GSignalAccumulator) NULL, NULL,
669 g_cclosure_marshal_VOID__VOID,
671 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
672 g_signal_new ("active_descendant_changed",
673 G_TYPE_FROM_CLASS (klass),
674 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
675 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
677 g_cclosure_marshal_VOID__POINTER,
683 atk_object_init (AtkObject *accessible,
684 AtkObjectClass *klass)
686 accessible->name = NULL;
687 accessible->description = NULL;
688 accessible->accessible_parent = NULL;
689 accessible->relation_set = atk_relation_set_new();
690 accessible->role = ATK_ROLE_UNKNOWN;
694 atk_implementor_get_type (void)
696 static GType type = 0;
700 static const GTypeInfo typeInfo =
702 sizeof (AtkImplementorIface),
703 (GBaseInitFunc) NULL,
704 (GBaseFinalizeFunc) NULL,
707 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
714 * atk_object_get_name:
715 * @accessible: an #AtkObject
717 * Gets the accessible name of the accessible.
719 * Returns: a character string representing the accessible name of the object.
722 atk_object_get_name (AtkObject *accessible)
724 AtkObjectClass *klass;
726 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
728 klass = ATK_OBJECT_GET_CLASS (accessible);
730 return (klass->get_name) (accessible);
736 * atk_object_get_description:
737 * @accessible: an #AtkObject
739 * Gets the accessible description of the accessible.
741 * Returns: a character string representing the accessible description
746 atk_object_get_description (AtkObject *accessible)
748 AtkObjectClass *klass;
750 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
752 klass = ATK_OBJECT_GET_CLASS (accessible);
753 if (klass->get_description)
754 return (klass->get_description) (accessible);
760 * atk_object_get_parent:
761 * @accessible: an #AtkObject
763 * Gets the accessible parent of the accessible.
765 * Returns: (transfer none): a #AtkObject representing the accessible parent
769 atk_object_get_parent (AtkObject *accessible)
771 AtkObjectClass *klass;
773 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
775 klass = ATK_OBJECT_GET_CLASS (accessible);
776 if (klass->get_parent)
777 return (klass->get_parent) (accessible);
783 * atk_object_get_n_accessible_children:
784 * @accessible: an #AtkObject
786 * Gets the number of accessible children of the accessible.
788 * Returns: an integer representing the number of accessible children
792 atk_object_get_n_accessible_children (AtkObject *accessible)
794 AtkObjectClass *klass;
796 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
798 klass = ATK_OBJECT_GET_CLASS (accessible);
799 if (klass->get_n_children)
800 return (klass->get_n_children) (accessible);
806 * atk_object_ref_accessible_child:
807 * @accessible: an #AtkObject
808 * @i: a gint representing the position of the child, starting from 0
810 * Gets a reference to the specified accessible child of the object.
811 * The accessible children are 0-based so the first accessible child is
812 * at index 0, the second at index 1 and so on.
814 * Returns: (transfer full): an #AtkObject representing the specified
815 * accessible child of the accessible.
818 atk_object_ref_accessible_child (AtkObject *accessible,
821 AtkObjectClass *klass;
823 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
825 klass = ATK_OBJECT_GET_CLASS (accessible);
826 if (klass->ref_child)
827 return (klass->ref_child) (accessible, i);
833 * atk_object_ref_relation_set:
834 * @accessible: an #AtkObject
836 * Gets the #AtkRelationSet associated with the object.
838 * Returns: (transfer full): an #AtkRelationSet representing the relation set
842 atk_object_ref_relation_set (AtkObject *accessible)
844 AtkObjectClass *klass;
846 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
848 klass = ATK_OBJECT_GET_CLASS (accessible);
849 if (klass->ref_relation_set)
850 return (klass->ref_relation_set) (accessible);
857 * @name: a character string describing the new role.
859 * Registers the role specified by @name.
861 * Returns: an #AtkRole for the new role.
864 atk_role_register (const gchar *name)
867 extra_roles = g_ptr_array_new ();
869 g_ptr_array_add (extra_roles, g_strdup (name));
870 return extra_roles->len + ATK_ROLE_LAST_DEFINED;
874 * atk_object_get_role:
875 * @accessible: an #AtkObject
877 * Gets the role of the accessible.
879 * Returns: an #AtkRole which is the role of the accessible
882 atk_object_get_role (AtkObject *accessible)
884 AtkObjectClass *klass;
886 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
888 klass = ATK_OBJECT_GET_CLASS (accessible);
890 return (klass->get_role) (accessible);
892 return ATK_ROLE_UNKNOWN;
896 * atk_object_get_layer:
897 * @accessible: an #AtkObject
899 * Gets the layer of the accessible.
901 * Deprecated: Use atk_component_get_layer instead.
903 * Returns: an #AtkLayer which is the layer of the accessible
906 atk_object_get_layer (AtkObject *accessible)
908 AtkObjectClass *klass;
910 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
912 klass = ATK_OBJECT_GET_CLASS (accessible);
913 if (klass->get_layer)
914 return (klass->get_layer) (accessible);
916 return ATK_LAYER_INVALID;
920 * atk_object_get_mdi_zorder:
921 * @accessible: an #AtkObject
923 * Gets the zorder of the accessible. The value G_MININT will be returned
924 * if the layer of the accessible is not ATK_LAYER_MDI.
926 * Deprecated: Use atk_component_get_mdi_zorder instead.
928 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
929 * which the component is shown in relation to other components in the same
934 atk_object_get_mdi_zorder (AtkObject *accessible)
936 AtkObjectClass *klass;
938 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
940 klass = ATK_OBJECT_GET_CLASS (accessible);
941 if (klass->get_mdi_zorder)
942 return (klass->get_mdi_zorder) (accessible);
948 * atk_object_ref_state_set:
949 * @accessible: an #AtkObject
951 * Gets a reference to the state set of the accessible; the caller must
952 * unreference it when it is no longer needed.
954 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
955 * set of the accessible
958 atk_object_ref_state_set (AtkObject *accessible)
960 AtkObjectClass *klass;
962 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
964 klass = ATK_OBJECT_GET_CLASS (accessible);
965 if (klass->ref_state_set)
966 return (klass->ref_state_set) (accessible);
972 * atk_object_get_index_in_parent:
973 * @accessible: an #AtkObject
975 * Gets the 0-based index of this accessible in its parent; returns -1 if the
976 * accessible does not have an accessible parent.
978 * Returns: an integer which is the index of the accessible in its parent
981 atk_object_get_index_in_parent (AtkObject *accessible)
983 AtkObjectClass *klass;
985 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
987 klass = ATK_OBJECT_GET_CLASS (accessible);
988 if (klass->get_index_in_parent)
989 return (klass->get_index_in_parent) (accessible);
995 * atk_object_set_name:
996 * @accessible: an #AtkObject
997 * @name: a character string to be set as the accessible name
999 * Sets the accessible name of the accessible. You can't set the name
1000 * to NULL. This is reserved for the initial value. In this aspect
1001 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
1002 * a empty value you can use "".
1005 atk_object_set_name (AtkObject *accessible,
1008 AtkObjectClass *klass;
1009 gboolean notify = FALSE;
1011 g_return_if_fail (ATK_IS_OBJECT (accessible));
1012 g_return_if_fail (name != NULL);
1014 klass = ATK_OBJECT_GET_CLASS (accessible);
1015 if (klass->set_name)
1017 /* Do not notify for initial name setting. See bug 665870 */
1018 notify = (atk_object_get_name (accessible) != NULL);
1020 (klass->set_name) (accessible, name);
1022 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1027 * atk_object_set_description:
1028 * @accessible: an #AtkObject
1029 * @description: a character string to be set as the accessible description
1031 * Sets the accessible description of the accessible. You can't set
1032 * the description to NULL. This is reserved for the initial value. In
1033 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
1034 * the name to a empty value you can use "".
1037 atk_object_set_description (AtkObject *accessible,
1038 const gchar *description)
1040 AtkObjectClass *klass;
1041 gboolean notify = FALSE;
1043 g_return_if_fail (ATK_IS_OBJECT (accessible));
1044 g_return_if_fail (description != NULL);
1046 klass = ATK_OBJECT_GET_CLASS (accessible);
1047 if (klass->set_description)
1049 /* Do not notify for initial name setting. See bug 665870 */
1050 notify = (accessible->description != NULL);
1052 (klass->set_description) (accessible, description);
1054 g_object_notify (G_OBJECT (accessible),
1055 atk_object_name_property_description);
1060 * atk_object_set_parent:
1061 * @accessible: an #AtkObject
1062 * @parent: an #AtkObject to be set as the accessible parent
1064 * Sets the accessible parent of the accessible.
1067 atk_object_set_parent (AtkObject *accessible,
1070 AtkObjectClass *klass;
1072 g_return_if_fail (ATK_IS_OBJECT (accessible));
1074 klass = ATK_OBJECT_GET_CLASS (accessible);
1075 if (klass->set_parent)
1077 (klass->set_parent) (accessible, parent);
1078 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1083 * atk_object_set_role:
1084 * @accessible: an #AtkObject
1085 * @role: an #AtkRole to be set as the role
1087 * Sets the role of the accessible.
1090 atk_object_set_role (AtkObject *accessible,
1093 AtkObjectClass *klass;
1096 g_return_if_fail (ATK_IS_OBJECT (accessible));
1098 klass = ATK_OBJECT_GET_CLASS (accessible);
1099 if (klass->set_role)
1101 old_role = atk_object_get_role (accessible);
1102 if (old_role != role)
1104 (klass->set_role) (accessible, role);
1105 if (old_role != ATK_ROLE_UNKNOWN)
1106 /* Do not notify for initial role setting */
1107 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1113 * atk_object_connect_property_change_handler:
1114 * @accessible: an #AtkObject
1115 * @handler: a function to be called when a property changes its value
1117 * Specifies a function to be called when a property changes value.
1119 * Returns: a #guint which is the handler id used in
1120 * atk_object_remove_property_change_handler()
1123 atk_object_connect_property_change_handler (AtkObject *accessible,
1124 AtkPropertyChangeHandler *handler)
1126 AtkObjectClass *klass;
1128 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1129 g_return_val_if_fail ((handler != NULL), 0);
1131 klass = ATK_OBJECT_GET_CLASS (accessible);
1132 if (klass->connect_property_change_handler)
1133 return (klass->connect_property_change_handler) (accessible, handler);
1139 * atk_object_remove_property_change_handler:
1140 * @accessible: an #AtkObject
1141 * @handler_id: a guint which identifies the handler to be removed.
1143 * Removes a property change handler.
1146 atk_object_remove_property_change_handler (AtkObject *accessible,
1149 AtkObjectClass *klass;
1151 g_return_if_fail (ATK_IS_OBJECT (accessible));
1153 klass = ATK_OBJECT_GET_CLASS (accessible);
1154 if (klass->remove_property_change_handler)
1155 (klass->remove_property_change_handler) (accessible, handler_id);
1159 * atk_object_notify_state_change:
1160 * @accessible: an #AtkObject
1161 * @state: an #AtkState whose state is changed
1162 * @value: a gboolean which indicates whether the state is being set on or off
1164 * Emits a state-change signal for the specified state.
1167 atk_object_notify_state_change (AtkObject *accessible,
1173 g_return_if_fail (ATK_IS_OBJECT (accessible));
1175 name = atk_state_type_get_name (state);
1176 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1177 g_quark_from_string (name),
1182 * atk_implementor_ref_accessible:
1183 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1184 * if a non-null return value is required.
1186 * Gets a reference to an object's #AtkObject implementation, if
1187 * the object implements #AtkObjectIface
1189 * Returns: (transfer full): a reference to an object's #AtkObject
1193 atk_implementor_ref_accessible (AtkImplementor *implementor)
1195 AtkImplementorIface *iface;
1196 AtkObject *accessible = NULL;
1198 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1200 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1203 accessible = iface->ref_accessible (implementor);
1205 g_return_val_if_fail ((accessible != NULL), NULL);
1212 * atk_object_get_attributes:
1213 * @accessible: An #AtkObject.
1215 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1216 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1217 * as distinct from strongly-typed object data available via other get/set methods.
1218 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1222 * Returns: (transfer none): an #AtkAttributeSet consisting of all explicit
1223 * properties/annotations applied to the object, or an empty set if the object
1224 * has no name-value pair attributes assigned to it.
1227 atk_object_get_attributes (AtkObject *accessible)
1229 AtkObjectClass *klass;
1231 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1233 klass = ATK_OBJECT_GET_CLASS (accessible);
1234 if (klass->get_attributes)
1235 return (klass->get_attributes) (accessible);
1241 static AtkRelationSet*
1242 atk_object_real_ref_relation_set (AtkObject *accessible)
1244 g_return_val_if_fail (accessible->relation_set, NULL);
1245 g_object_ref (accessible->relation_set);
1247 return accessible->relation_set;
1251 atk_object_real_set_property (GObject *object,
1253 const GValue *value,
1256 AtkObject *accessible;
1258 accessible = ATK_OBJECT (object);
1263 atk_object_set_name (accessible, g_value_get_string (value));
1265 case PROP_DESCRIPTION:
1266 atk_object_set_description (accessible, g_value_get_string (value));
1269 atk_object_set_role (accessible, g_value_get_int (value));
1272 atk_object_set_parent (accessible, g_value_get_object (value));
1275 if (ATK_IS_VALUE (accessible))
1276 atk_value_set_current_value (ATK_VALUE (accessible), value);
1278 case PROP_TABLE_SUMMARY:
1279 if (ATK_IS_TABLE (accessible))
1280 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1282 case PROP_TABLE_CAPTION_OBJECT:
1283 if (ATK_IS_TABLE (accessible))
1284 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1292 atk_object_real_get_property (GObject *object,
1297 AtkObject *accessible;
1299 accessible = ATK_OBJECT (object);
1304 g_value_set_string (value, atk_object_get_name (accessible));
1306 case PROP_DESCRIPTION:
1307 g_value_set_string (value, atk_object_get_description (accessible));
1310 g_value_set_int (value, atk_object_get_role (accessible));
1313 if (ATK_IS_COMPONENT (accessible))
1314 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1316 case PROP_MDI_ZORDER:
1317 if (ATK_IS_COMPONENT (accessible))
1318 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1321 g_value_set_object (value, atk_object_get_parent (accessible));
1324 if (ATK_IS_VALUE (accessible))
1325 atk_value_get_current_value (ATK_VALUE (accessible), value);
1327 case PROP_TABLE_SUMMARY:
1328 if (ATK_IS_TABLE (accessible))
1329 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1331 case PROP_TABLE_CAPTION_OBJECT:
1332 if (ATK_IS_TABLE (accessible))
1333 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1335 case PROP_HYPERTEXT_NUM_LINKS:
1336 if (ATK_IS_HYPERTEXT (accessible))
1337 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1340 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1346 atk_object_finalize (GObject *object)
1348 AtkObject *accessible;
1350 g_return_if_fail (ATK_IS_OBJECT (object));
1352 accessible = ATK_OBJECT (object);
1354 g_free (accessible->name);
1355 g_free (accessible->description);
1358 * Free memory allocated for relation set if it have been allocated.
1360 if (accessible->relation_set)
1361 g_object_unref (accessible->relation_set);
1363 if (accessible->accessible_parent)
1364 g_object_unref (accessible->accessible_parent);
1366 G_OBJECT_CLASS (parent_class)->finalize (object);
1370 atk_object_real_get_name (AtkObject *object)
1372 return object->name;
1376 atk_object_real_get_description (AtkObject *object)
1378 return object->description;
1382 atk_object_real_get_parent (AtkObject *object)
1384 return object->accessible_parent;
1388 atk_object_real_get_role (AtkObject *object)
1390 return object->role;
1394 atk_object_real_get_layer (AtkObject *object)
1396 return object->layer;
1400 atk_object_real_ref_state_set (AtkObject *accessible)
1402 AtkStateSet *state_set;
1404 AtkObject *focus_object;
1406 state_set = atk_state_set_new ();
1408 ap = atk_object_get_parent (accessible);
1410 if (ATK_IS_SELECTION (ap))
1414 atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
1416 i = atk_object_get_index_in_parent (accessible);
1418 if (atk_selection_is_child_selected(ATK_SELECTION (ap), i))
1419 atk_state_set_add_state (state_set, ATK_STATE_SELECTED);
1421 focus_object = atk_get_focus_object ();
1422 if (focus_object == accessible)
1423 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1429 atk_object_real_set_name (AtkObject *object,
1432 g_free (object->name);
1433 object->name = g_strdup (name);
1437 atk_object_real_set_description (AtkObject *object,
1438 const gchar *description)
1440 g_free (object->description);
1441 object->description = g_strdup (description);
1445 atk_object_real_set_parent (AtkObject *object,
1448 if (object->accessible_parent)
1449 g_object_unref (object->accessible_parent);
1451 object->accessible_parent = parent;
1452 if (object->accessible_parent)
1453 g_object_ref (object->accessible_parent);
1457 atk_object_real_set_role (AtkObject *object,
1460 object->role = role;
1464 atk_object_real_connect_property_change_handler (AtkObject *obj,
1465 AtkPropertyChangeHandler *handler)
1467 return g_signal_connect_closure_by_id (obj,
1468 atk_object_signals[PROPERTY_CHANGE],
1471 G_CALLBACK (handler), NULL,
1472 (GClosureNotify) NULL),
1477 atk_object_real_remove_property_change_handler (AtkObject *obj,
1480 g_signal_handler_disconnect (obj, handler_id);
1484 * atk_object_initialize:
1485 * @accessible: a #AtkObject
1486 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1488 * This function is called when implementing subclasses of #AtkObject.
1489 * It does initialization required for the new object. It is intended
1490 * that this function should called only in the ..._new() functions used
1491 * to create an instance of a subclass of #AtkObject
1494 atk_object_initialize (AtkObject *accessible,
1497 AtkObjectClass *klass;
1499 g_return_if_fail (ATK_IS_OBJECT (accessible));
1501 klass = ATK_OBJECT_GET_CLASS (accessible);
1502 if (klass->initialize)
1503 klass->initialize (accessible, data);
1507 * This function is a signal handler for notify signal which gets emitted
1508 * when a property changes value.
1510 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1511 * signal which causes the user specified AtkPropertyChangeHandler
1515 atk_object_notify (GObject *obj,
1518 AtkPropertyValues values = { NULL, };
1520 g_value_init (&values.new_value, pspec->value_type);
1521 g_object_get_property (obj, pspec->name, &values.new_value);
1522 values.property_name = pspec->name;
1523 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1524 g_quark_from_string (pspec->name),
1526 g_value_unset (&values.new_value);
1530 * atk_role_get_name:
1531 * @role: The #AtkRole whose name is required
1533 * Gets the description string describing the #AtkRole @role.
1535 * Returns: the string describing the AtkRole
1538 atk_role_get_name (AtkRole role)
1540 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1541 return roles + roles_offsets[role];
1547 n -= ATK_ROLE_LAST_DEFINED + 1;
1549 if (n >= 0 && n < extra_roles->len)
1550 return g_ptr_array_index (extra_roles, n);
1557 * atk_role_get_localized_name:
1558 * @role: The #AtkRole whose localized name is required
1560 * Gets the localized description string describing the #AtkRole @role.
1562 * Returns: the localized string describing the AtkRole
1565 atk_role_get_localized_name (AtkRole role)
1567 gettext_initialization ();
1569 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1570 return dgettext (GETTEXT_PACKAGE, roles + roles_offsets[role]);
1572 return atk_role_get_name (role);
1576 * atk_role_for_name:
1577 * @name: a string which is the (non-localized) name of an ATK role.
1579 * Get the #AtkRole type corresponding to a rolew name.
1581 * Returns: the #AtkRole enumerated type corresponding to the specified
1583 * or #ATK_ROLE_INVALID if no matching role is found.
1586 atk_role_for_name (const gchar *name)
1588 AtkRole role = ATK_ROLE_INVALID;
1591 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1593 for (i = 0; i < G_N_ELEMENTS (roles_offsets); i++)
1595 if (strcmp (name, roles + roles_offsets[i]) == 0)
1601 for (i = 0; i < extra_roles->len; i++)
1603 gchar *extra_role = (gchar *)g_ptr_array_index (extra_roles, i);
1605 g_return_val_if_fail (extra_role, ATK_ROLE_INVALID);
1607 if (strcmp (name, extra_role) == 0)
1609 role = i + 1 + ATK_ROLE_LAST_DEFINED;
1619 * atk_object_add_relationship:
1620 * @object: The #AtkObject to which an AtkRelation is to be added.
1621 * @relationship: The #AtkRelationType of the relation
1622 * @target: The #AtkObject which is to be the target of the relation.
1624 * Adds a relationship of the specified type with the specified target.
1626 * Returns TRUE if the relationship is added.
1629 atk_object_add_relationship (AtkObject *object,
1630 AtkRelationType relationship,
1633 AtkObject *array[1];
1634 AtkRelation *relation;
1636 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1637 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1639 if (atk_relation_set_contains (object->relation_set, relationship))
1643 relation = atk_relation_new (array, 1, relationship);
1644 atk_relation_set_add (object->relation_set, relation);
1645 g_object_unref (relation);
1651 * atk_object_remove_relationship:
1652 * @object: The #AtkObject from which an AtkRelation is to be removed.
1653 * @relationship: The #AtkRelationType of the relation
1654 * @target: The #AtkObject which is the target of the relation to be removed.
1656 * Removes a relationship of the specified type with the specified target.
1658 * Returns TRUE if the relationship is removed.
1661 atk_object_remove_relationship (AtkObject *object,
1662 AtkRelationType relationship,
1665 gboolean ret = FALSE;
1666 AtkRelation *relation;
1669 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1670 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1672 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1676 ret = atk_relation_remove_target (relation, target);
1677 array = atk_relation_get_target (relation);
1678 if (!array || array->len == 0)
1679 atk_relation_set_remove (object->relation_set, relation);
1685 atk_object_real_initialize (AtkObject *accessible,