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,
343 static const gchar* atk_object_real_get_object_locale
346 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
348 static gpointer parent_class = NULL;
350 static const gchar* const atk_object_name_property_name = "accessible-name";
351 static const gchar* const atk_object_name_property_description = "accessible-description";
352 static const gchar* const atk_object_name_property_parent = "accessible-parent";
353 static const gchar* const atk_object_name_property_value = "accessible-value";
354 static const gchar* const atk_object_name_property_role = "accessible-role";
355 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
356 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
357 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
358 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
359 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
360 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
361 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
362 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
363 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
364 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
368 static HMODULE atk_dll;
371 DllMain (HINSTANCE hinstDLL,
377 case DLL_PROCESS_ATTACH:
378 atk_dll = (HMODULE) hinstDLL;
386 get_atk_locale_dir (void)
388 static gchar *atk_localedir = NULL;
395 /* ATK_LOCALEDIR might end in either /lib/locale or
396 * /share/locale. Scan for that slash.
398 p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
404 root = g_win32_get_package_installation_directory_of_module (atk_dll);
405 temp = g_build_filename (root, p, NULL);
408 /* atk_localedir is passed to bindtextdomain() which isn't
411 atk_localedir = g_win32_locale_filename_from_utf8 (temp);
414 return atk_localedir;
419 #define ATK_LOCALEDIR get_atk_locale_dir()
424 gettext_initialization (void)
427 static gboolean gettext_initialized = FALSE;
429 if (!gettext_initialized)
431 const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
433 gettext_initialized = TRUE;
437 bindtextdomain (GETTEXT_PACKAGE, dir);
438 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
439 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
446 atk_object_get_type (void)
448 static GType type = 0;
452 static const GTypeInfo typeInfo =
454 sizeof (AtkObjectClass),
455 (GBaseInitFunc) NULL,
456 (GBaseFinalizeFunc) NULL,
457 (GClassInitFunc) atk_object_class_init,
458 (GClassFinalizeFunc) NULL,
462 (GInstanceInitFunc) atk_object_init,
464 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
470 atk_object_class_init (AtkObjectClass *klass)
472 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
474 parent_class = g_type_class_peek_parent (klass);
476 gobject_class->set_property = atk_object_real_set_property;
477 gobject_class->get_property = atk_object_real_get_property;
478 gobject_class->finalize = atk_object_finalize;
479 gobject_class->notify = atk_object_notify;
481 klass->get_name = atk_object_real_get_name;
482 klass->get_description = atk_object_real_get_description;
483 klass->get_parent = atk_object_real_get_parent;
484 klass->get_n_children = NULL;
485 klass->ref_child = NULL;
486 klass->get_index_in_parent = NULL;
487 klass->ref_relation_set = atk_object_real_ref_relation_set;
488 klass->get_role = atk_object_real_get_role;
489 klass->get_layer = atk_object_real_get_layer;
490 klass->get_mdi_zorder = NULL;
491 klass->initialize = atk_object_real_initialize;
492 klass->ref_state_set = atk_object_real_ref_state_set;
493 klass->set_name = atk_object_real_set_name;
494 klass->set_description = atk_object_real_set_description;
495 klass->set_parent = atk_object_real_set_parent;
496 klass->set_role = atk_object_real_set_role;
497 klass->connect_property_change_handler =
498 atk_object_real_connect_property_change_handler;
499 klass->remove_property_change_handler =
500 atk_object_real_remove_property_change_handler;
501 klass->get_object_locale = atk_object_real_get_object_locale;
504 * We do not define default signal handlers here
506 klass->children_changed = NULL;
507 klass->focus_event = NULL;
508 klass->property_change = NULL;
509 klass->visible_data_changed = NULL;
510 klass->active_descendant_changed = NULL;
512 gettext_initialization ();
514 g_object_class_install_property (gobject_class,
516 g_param_spec_string (atk_object_name_property_name,
517 _("Accessible Name"),
518 _("Object instance\'s name formatted for assistive technology access"),
521 g_object_class_install_property (gobject_class,
523 g_param_spec_string (atk_object_name_property_description,
524 _("Accessible Description"),
525 _("Description of an object, formatted for assistive technology access"),
528 g_object_class_install_property (gobject_class,
530 g_param_spec_object (atk_object_name_property_parent,
531 _("Accessible Parent"),
532 _("Is used to notify that the parent has changed"),
535 g_object_class_install_property (gobject_class,
537 g_param_spec_double (atk_object_name_property_value,
538 _("Accessible Value"),
539 _("Is used to notify that the value has changed"),
544 g_object_class_install_property (gobject_class,
546 g_param_spec_int (atk_object_name_property_role,
547 _("Accessible Role"),
548 _("The accessible role of this object"),
553 g_object_class_install_property (gobject_class,
555 g_param_spec_int (atk_object_name_property_component_layer,
556 _("Accessible Layer"),
557 _("The accessible layer of this object"),
562 g_object_class_install_property (gobject_class,
564 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
565 _("Accessible MDI Value"),
566 _("The accessible MDI value of this object"),
571 g_object_class_install_property (gobject_class,
573 g_param_spec_string (atk_object_name_property_table_caption,
574 _("Accessible Table Caption"),
575 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
578 g_object_class_install_property (gobject_class,
579 PROP_TABLE_COLUMN_HEADER,
580 g_param_spec_object (atk_object_name_property_table_column_header,
581 _("Accessible Table Column Header"),
582 _("Is used to notify that the table column header has changed"),
585 g_object_class_install_property (gobject_class,
586 PROP_TABLE_COLUMN_DESCRIPTION,
587 g_param_spec_string (atk_object_name_property_table_column_description,
588 _("Accessible Table Column Description"),
589 _("Is used to notify that the table column description has changed"),
592 g_object_class_install_property (gobject_class,
593 PROP_TABLE_ROW_HEADER,
594 g_param_spec_object (atk_object_name_property_table_row_header,
595 _("Accessible Table Row Header"),
596 _("Is used to notify that the table row header has changed"),
599 g_object_class_install_property (gobject_class,
600 PROP_TABLE_ROW_DESCRIPTION,
601 g_param_spec_string (atk_object_name_property_table_row_description,
602 _("Accessible Table Row Description"),
603 _("Is used to notify that the table row description has changed"),
606 g_object_class_install_property (gobject_class,
608 g_param_spec_object (atk_object_name_property_table_summary,
609 _("Accessible Table Summary"),
610 _("Is used to notify that the table summary has changed"),
613 g_object_class_install_property (gobject_class,
614 PROP_TABLE_CAPTION_OBJECT,
615 g_param_spec_object (atk_object_name_property_table_caption_object,
616 _("Accessible Table Caption Object"),
617 _("Is used to notify that the table caption has changed"),
620 g_object_class_install_property (gobject_class,
621 PROP_HYPERTEXT_NUM_LINKS,
622 g_param_spec_int (atk_object_name_property_hypertext_num_links,
623 _("Number of Accessible Hypertext Links"),
624 _("The number of links which the current AtkHypertext has"),
629 atk_object_signals[CHILDREN_CHANGED] =
630 g_signal_new ("children_changed",
631 G_TYPE_FROM_CLASS (klass),
632 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
633 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
635 g_cclosure_marshal_VOID__UINT_POINTER,
637 2, G_TYPE_UINT, G_TYPE_POINTER);
638 atk_object_signals[FOCUS_EVENT] =
639 g_signal_new ("focus_event",
640 G_TYPE_FROM_CLASS (klass),
642 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
644 g_cclosure_marshal_VOID__BOOLEAN,
647 atk_object_signals[PROPERTY_CHANGE] =
648 g_signal_new ("property_change",
649 G_TYPE_FROM_CLASS (klass),
650 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
651 G_STRUCT_OFFSET (AtkObjectClass, property_change),
652 (GSignalAccumulator) NULL, NULL,
653 g_cclosure_marshal_VOID__POINTER,
656 atk_object_signals[STATE_CHANGE] =
657 g_signal_new ("state_change",
658 G_TYPE_FROM_CLASS (klass),
659 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
660 G_STRUCT_OFFSET (AtkObjectClass, state_change),
661 (GSignalAccumulator) NULL, NULL,
662 atk_marshal_VOID__STRING_BOOLEAN,
666 atk_object_signals[VISIBLE_DATA_CHANGED] =
667 g_signal_new ("visible_data_changed",
668 G_TYPE_FROM_CLASS (klass),
670 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
671 (GSignalAccumulator) NULL, NULL,
672 g_cclosure_marshal_VOID__VOID,
674 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
675 g_signal_new ("active_descendant_changed",
676 G_TYPE_FROM_CLASS (klass),
677 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
678 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
680 g_cclosure_marshal_VOID__POINTER,
686 atk_object_init (AtkObject *accessible,
687 AtkObjectClass *klass)
689 accessible->name = NULL;
690 accessible->description = NULL;
691 accessible->accessible_parent = NULL;
692 accessible->relation_set = atk_relation_set_new();
693 accessible->role = ATK_ROLE_UNKNOWN;
697 atk_implementor_get_type (void)
699 static GType type = 0;
703 static const GTypeInfo typeInfo =
705 sizeof (AtkImplementorIface),
706 (GBaseInitFunc) NULL,
707 (GBaseFinalizeFunc) NULL,
710 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
717 * atk_object_get_name:
718 * @accessible: an #AtkObject
720 * Gets the accessible name of the accessible.
722 * Returns: a character string representing the accessible name of the object.
725 atk_object_get_name (AtkObject *accessible)
727 AtkObjectClass *klass;
729 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
731 klass = ATK_OBJECT_GET_CLASS (accessible);
733 return (klass->get_name) (accessible);
739 * atk_object_get_description:
740 * @accessible: an #AtkObject
742 * Gets the accessible description of the accessible.
744 * Returns: a character string representing the accessible description
749 atk_object_get_description (AtkObject *accessible)
751 AtkObjectClass *klass;
753 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
755 klass = ATK_OBJECT_GET_CLASS (accessible);
756 if (klass->get_description)
757 return (klass->get_description) (accessible);
763 * atk_object_get_parent:
764 * @accessible: an #AtkObject
766 * Gets the accessible parent of the accessible.
768 * Returns: (transfer none): a #AtkObject representing the accessible parent
772 atk_object_get_parent (AtkObject *accessible)
774 AtkObjectClass *klass;
776 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
778 klass = ATK_OBJECT_GET_CLASS (accessible);
779 if (klass->get_parent)
780 return (klass->get_parent) (accessible);
786 * atk_object_get_n_accessible_children:
787 * @accessible: an #AtkObject
789 * Gets the number of accessible children of the accessible.
791 * Returns: an integer representing the number of accessible children
795 atk_object_get_n_accessible_children (AtkObject *accessible)
797 AtkObjectClass *klass;
799 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
801 klass = ATK_OBJECT_GET_CLASS (accessible);
802 if (klass->get_n_children)
803 return (klass->get_n_children) (accessible);
809 * atk_object_ref_accessible_child:
810 * @accessible: an #AtkObject
811 * @i: a gint representing the position of the child, starting from 0
813 * Gets a reference to the specified accessible child of the object.
814 * The accessible children are 0-based so the first accessible child is
815 * at index 0, the second at index 1 and so on.
817 * Returns: (transfer full): an #AtkObject representing the specified
818 * accessible child of the accessible.
821 atk_object_ref_accessible_child (AtkObject *accessible,
824 AtkObjectClass *klass;
826 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
828 klass = ATK_OBJECT_GET_CLASS (accessible);
829 if (klass->ref_child)
830 return (klass->ref_child) (accessible, i);
836 * atk_object_ref_relation_set:
837 * @accessible: an #AtkObject
839 * Gets the #AtkRelationSet associated with the object.
841 * Returns: (transfer full): an #AtkRelationSet representing the relation set
845 atk_object_ref_relation_set (AtkObject *accessible)
847 AtkObjectClass *klass;
849 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
851 klass = ATK_OBJECT_GET_CLASS (accessible);
852 if (klass->ref_relation_set)
853 return (klass->ref_relation_set) (accessible);
860 * @name: a character string describing the new role.
862 * Registers the role specified by @name.
864 * Returns: an #AtkRole for the new role.
867 atk_role_register (const gchar *name)
870 extra_roles = g_ptr_array_new ();
872 g_ptr_array_add (extra_roles, g_strdup (name));
873 return extra_roles->len + ATK_ROLE_LAST_DEFINED;
877 * atk_object_get_role:
878 * @accessible: an #AtkObject
880 * Gets the role of the accessible.
882 * Returns: an #AtkRole which is the role of the accessible
885 atk_object_get_role (AtkObject *accessible)
887 AtkObjectClass *klass;
889 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
891 klass = ATK_OBJECT_GET_CLASS (accessible);
893 return (klass->get_role) (accessible);
895 return ATK_ROLE_UNKNOWN;
899 * atk_object_get_layer:
900 * @accessible: an #AtkObject
902 * Gets the layer of the accessible.
904 * Deprecated: Use atk_component_get_layer instead.
906 * Returns: an #AtkLayer which is the layer of the accessible
909 atk_object_get_layer (AtkObject *accessible)
911 AtkObjectClass *klass;
913 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
915 klass = ATK_OBJECT_GET_CLASS (accessible);
916 if (klass->get_layer)
917 return (klass->get_layer) (accessible);
919 return ATK_LAYER_INVALID;
923 * atk_object_get_mdi_zorder:
924 * @accessible: an #AtkObject
926 * Gets the zorder of the accessible. The value G_MININT will be returned
927 * if the layer of the accessible is not ATK_LAYER_MDI.
929 * Deprecated: Use atk_component_get_mdi_zorder instead.
931 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
932 * which the component is shown in relation to other components in the same
937 atk_object_get_mdi_zorder (AtkObject *accessible)
939 AtkObjectClass *klass;
941 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
943 klass = ATK_OBJECT_GET_CLASS (accessible);
944 if (klass->get_mdi_zorder)
945 return (klass->get_mdi_zorder) (accessible);
951 * atk_object_ref_state_set:
952 * @accessible: an #AtkObject
954 * Gets a reference to the state set of the accessible; the caller must
955 * unreference it when it is no longer needed.
957 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
958 * set of the accessible
961 atk_object_ref_state_set (AtkObject *accessible)
963 AtkObjectClass *klass;
965 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
967 klass = ATK_OBJECT_GET_CLASS (accessible);
968 if (klass->ref_state_set)
969 return (klass->ref_state_set) (accessible);
975 * atk_object_get_index_in_parent:
976 * @accessible: an #AtkObject
978 * Gets the 0-based index of this accessible in its parent; returns -1 if the
979 * accessible does not have an accessible parent.
981 * Returns: an integer which is the index of the accessible in its parent
984 atk_object_get_index_in_parent (AtkObject *accessible)
986 AtkObjectClass *klass;
988 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
990 klass = ATK_OBJECT_GET_CLASS (accessible);
991 if (klass->get_index_in_parent)
992 return (klass->get_index_in_parent) (accessible);
998 * atk_object_set_name:
999 * @accessible: an #AtkObject
1000 * @name: a character string to be set as the accessible name
1002 * Sets the accessible name of the accessible. You can't set the name
1003 * to NULL. This is reserved for the initial value. In this aspect
1004 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
1005 * a empty value you can use "".
1008 atk_object_set_name (AtkObject *accessible,
1011 AtkObjectClass *klass;
1012 gboolean notify = FALSE;
1014 g_return_if_fail (ATK_IS_OBJECT (accessible));
1015 g_return_if_fail (name != NULL);
1017 klass = ATK_OBJECT_GET_CLASS (accessible);
1018 if (klass->set_name)
1020 /* Do not notify for initial name setting. See bug 665870 */
1021 notify = (accessible->name != NULL);
1023 (klass->set_name) (accessible, name);
1025 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1030 * atk_object_set_description:
1031 * @accessible: an #AtkObject
1032 * @description: a character string to be set as the accessible description
1034 * Sets the accessible description of the accessible. You can't set
1035 * the description to NULL. This is reserved for the initial value. In
1036 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
1037 * the name to a empty value you can use "".
1040 atk_object_set_description (AtkObject *accessible,
1041 const gchar *description)
1043 AtkObjectClass *klass;
1044 gboolean notify = FALSE;
1046 g_return_if_fail (ATK_IS_OBJECT (accessible));
1047 g_return_if_fail (description != NULL);
1049 klass = ATK_OBJECT_GET_CLASS (accessible);
1050 if (klass->set_description)
1052 /* Do not notify for initial name setting. See bug 665870 */
1053 notify = (accessible->description != NULL);
1055 (klass->set_description) (accessible, description);
1057 g_object_notify (G_OBJECT (accessible),
1058 atk_object_name_property_description);
1063 * atk_object_set_parent:
1064 * @accessible: an #AtkObject
1065 * @parent: an #AtkObject to be set as the accessible parent
1067 * Sets the accessible parent of the accessible.
1070 atk_object_set_parent (AtkObject *accessible,
1073 AtkObjectClass *klass;
1075 g_return_if_fail (ATK_IS_OBJECT (accessible));
1077 klass = ATK_OBJECT_GET_CLASS (accessible);
1078 if (klass->set_parent)
1080 (klass->set_parent) (accessible, parent);
1081 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1086 * atk_object_set_role:
1087 * @accessible: an #AtkObject
1088 * @role: an #AtkRole to be set as the role
1090 * Sets the role of the accessible.
1093 atk_object_set_role (AtkObject *accessible,
1096 AtkObjectClass *klass;
1099 g_return_if_fail (ATK_IS_OBJECT (accessible));
1101 klass = ATK_OBJECT_GET_CLASS (accessible);
1102 if (klass->set_role)
1104 old_role = atk_object_get_role (accessible);
1105 if (old_role != role)
1107 (klass->set_role) (accessible, role);
1108 if (old_role != ATK_ROLE_UNKNOWN)
1109 /* Do not notify for initial role setting */
1110 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1116 * atk_object_connect_property_change_handler:
1117 * @accessible: an #AtkObject
1118 * @handler: a function to be called when a property changes its value
1120 * Specifies a function to be called when a property changes value.
1122 * Returns: a #guint which is the handler id used in
1123 * atk_object_remove_property_change_handler()
1126 atk_object_connect_property_change_handler (AtkObject *accessible,
1127 AtkPropertyChangeHandler *handler)
1129 AtkObjectClass *klass;
1131 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1132 g_return_val_if_fail ((handler != NULL), 0);
1134 klass = ATK_OBJECT_GET_CLASS (accessible);
1135 if (klass->connect_property_change_handler)
1136 return (klass->connect_property_change_handler) (accessible, handler);
1142 * atk_object_remove_property_change_handler:
1143 * @accessible: an #AtkObject
1144 * @handler_id: a guint which identifies the handler to be removed.
1146 * Removes a property change handler.
1149 atk_object_remove_property_change_handler (AtkObject *accessible,
1152 AtkObjectClass *klass;
1154 g_return_if_fail (ATK_IS_OBJECT (accessible));
1156 klass = ATK_OBJECT_GET_CLASS (accessible);
1157 if (klass->remove_property_change_handler)
1158 (klass->remove_property_change_handler) (accessible, handler_id);
1162 * atk_object_notify_state_change:
1163 * @accessible: an #AtkObject
1164 * @state: an #AtkState whose state is changed
1165 * @value: a gboolean which indicates whether the state is being set on or off
1167 * Emits a state-change signal for the specified state.
1170 atk_object_notify_state_change (AtkObject *accessible,
1176 g_return_if_fail (ATK_IS_OBJECT (accessible));
1178 name = atk_state_type_get_name (state);
1179 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1180 g_quark_from_string (name),
1185 * atk_implementor_ref_accessible:
1186 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1187 * if a non-null return value is required.
1189 * Gets a reference to an object's #AtkObject implementation, if
1190 * the object implements #AtkObjectIface
1192 * Returns: (transfer full): a reference to an object's #AtkObject
1196 atk_implementor_ref_accessible (AtkImplementor *implementor)
1198 AtkImplementorIface *iface;
1199 AtkObject *accessible = NULL;
1201 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1203 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1206 accessible = iface->ref_accessible (implementor);
1208 g_return_val_if_fail ((accessible != NULL), NULL);
1215 * atk_object_get_attributes:
1216 * @accessible: An #AtkObject.
1218 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1219 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1220 * as distinct from strongly-typed object data available via other get/set methods.
1221 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1225 * Returns: (transfer none): an #AtkAttributeSet consisting of all explicit
1226 * properties/annotations applied to the object, or an empty set if the object
1227 * has no name-value pair attributes assigned to it.
1230 atk_object_get_attributes (AtkObject *accessible)
1232 AtkObjectClass *klass;
1234 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1236 klass = ATK_OBJECT_GET_CLASS (accessible);
1237 if (klass->get_attributes)
1238 return (klass->get_attributes) (accessible);
1244 static AtkRelationSet*
1245 atk_object_real_ref_relation_set (AtkObject *accessible)
1247 g_return_val_if_fail (accessible->relation_set, NULL);
1248 g_object_ref (accessible->relation_set);
1250 return accessible->relation_set;
1254 atk_object_real_set_property (GObject *object,
1256 const GValue *value,
1259 AtkObject *accessible;
1261 accessible = ATK_OBJECT (object);
1266 atk_object_set_name (accessible, g_value_get_string (value));
1268 case PROP_DESCRIPTION:
1269 atk_object_set_description (accessible, g_value_get_string (value));
1272 atk_object_set_role (accessible, g_value_get_int (value));
1275 atk_object_set_parent (accessible, g_value_get_object (value));
1278 if (ATK_IS_VALUE (accessible))
1279 atk_value_set_current_value (ATK_VALUE (accessible), value);
1281 case PROP_TABLE_SUMMARY:
1282 if (ATK_IS_TABLE (accessible))
1283 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1285 case PROP_TABLE_CAPTION_OBJECT:
1286 if (ATK_IS_TABLE (accessible))
1287 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1295 atk_object_real_get_property (GObject *object,
1300 AtkObject *accessible;
1302 accessible = ATK_OBJECT (object);
1307 g_value_set_string (value, atk_object_get_name (accessible));
1309 case PROP_DESCRIPTION:
1310 g_value_set_string (value, atk_object_get_description (accessible));
1313 g_value_set_int (value, atk_object_get_role (accessible));
1316 if (ATK_IS_COMPONENT (accessible))
1317 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1319 case PROP_MDI_ZORDER:
1320 if (ATK_IS_COMPONENT (accessible))
1321 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1324 g_value_set_object (value, atk_object_get_parent (accessible));
1327 if (ATK_IS_VALUE (accessible))
1328 atk_value_get_current_value (ATK_VALUE (accessible), value);
1330 case PROP_TABLE_SUMMARY:
1331 if (ATK_IS_TABLE (accessible))
1332 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1334 case PROP_TABLE_CAPTION_OBJECT:
1335 if (ATK_IS_TABLE (accessible))
1336 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1338 case PROP_HYPERTEXT_NUM_LINKS:
1339 if (ATK_IS_HYPERTEXT (accessible))
1340 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1343 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1349 atk_object_finalize (GObject *object)
1351 AtkObject *accessible;
1353 g_return_if_fail (ATK_IS_OBJECT (object));
1355 accessible = ATK_OBJECT (object);
1357 g_free (accessible->name);
1358 g_free (accessible->description);
1361 * Free memory allocated for relation set if it have been allocated.
1363 if (accessible->relation_set)
1364 g_object_unref (accessible->relation_set);
1366 if (accessible->accessible_parent)
1367 g_object_unref (accessible->accessible_parent);
1369 G_OBJECT_CLASS (parent_class)->finalize (object);
1373 atk_object_real_get_name (AtkObject *object)
1375 return object->name;
1379 atk_object_real_get_description (AtkObject *object)
1381 return object->description;
1385 atk_object_real_get_parent (AtkObject *object)
1387 return object->accessible_parent;
1391 atk_object_real_get_role (AtkObject *object)
1393 return object->role;
1397 atk_object_real_get_layer (AtkObject *object)
1399 return object->layer;
1403 atk_object_real_ref_state_set (AtkObject *accessible)
1405 AtkStateSet *state_set;
1406 AtkObject *focus_object;
1408 state_set = atk_state_set_new ();
1410 focus_object = atk_get_focus_object ();
1411 if (focus_object == accessible)
1412 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1418 atk_object_real_set_name (AtkObject *object,
1421 g_free (object->name);
1422 object->name = g_strdup (name);
1426 atk_object_real_set_description (AtkObject *object,
1427 const gchar *description)
1429 g_free (object->description);
1430 object->description = g_strdup (description);
1434 atk_object_real_set_parent (AtkObject *object,
1437 if (object->accessible_parent)
1438 g_object_unref (object->accessible_parent);
1440 object->accessible_parent = parent;
1441 if (object->accessible_parent)
1442 g_object_ref (object->accessible_parent);
1446 atk_object_real_set_role (AtkObject *object,
1449 object->role = role;
1453 atk_object_real_connect_property_change_handler (AtkObject *obj,
1454 AtkPropertyChangeHandler *handler)
1456 return g_signal_connect_closure_by_id (obj,
1457 atk_object_signals[PROPERTY_CHANGE],
1460 G_CALLBACK (handler), NULL,
1461 (GClosureNotify) NULL),
1466 atk_object_real_remove_property_change_handler (AtkObject *obj,
1469 g_signal_handler_disconnect (obj, handler_id);
1473 * atk_object_initialize:
1474 * @accessible: a #AtkObject
1475 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1477 * This function is called when implementing subclasses of #AtkObject.
1478 * It does initialization required for the new object. It is intended
1479 * that this function should called only in the ..._new() functions used
1480 * to create an instance of a subclass of #AtkObject
1483 atk_object_initialize (AtkObject *accessible,
1486 AtkObjectClass *klass;
1488 g_return_if_fail (ATK_IS_OBJECT (accessible));
1490 klass = ATK_OBJECT_GET_CLASS (accessible);
1491 if (klass->initialize)
1492 klass->initialize (accessible, data);
1496 * This function is a signal handler for notify signal which gets emitted
1497 * when a property changes value.
1499 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1500 * signal which causes the user specified AtkPropertyChangeHandler
1504 atk_object_notify (GObject *obj,
1507 AtkPropertyValues values = { NULL, };
1509 g_value_init (&values.new_value, pspec->value_type);
1510 g_object_get_property (obj, pspec->name, &values.new_value);
1511 values.property_name = pspec->name;
1512 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1513 g_quark_from_string (pspec->name),
1515 g_value_unset (&values.new_value);
1519 * atk_role_get_name:
1520 * @role: The #AtkRole whose name is required
1522 * Gets the description string describing the #AtkRole @role.
1524 * Returns: the string describing the AtkRole
1527 atk_role_get_name (AtkRole role)
1529 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1530 return roles + roles_offsets[role];
1536 n -= ATK_ROLE_LAST_DEFINED + 1;
1538 if (n >= 0 && n < extra_roles->len)
1539 return g_ptr_array_index (extra_roles, n);
1546 * atk_role_get_localized_name:
1547 * @role: The #AtkRole whose localized name is required
1549 * Gets the localized description string describing the #AtkRole @role.
1551 * Returns: the localized string describing the AtkRole
1554 atk_role_get_localized_name (AtkRole role)
1556 gettext_initialization ();
1558 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1559 return dgettext (GETTEXT_PACKAGE, roles + roles_offsets[role]);
1561 return atk_role_get_name (role);
1565 atk_object_real_get_object_locale (AtkObject *object)
1567 return setlocale (LC_MESSAGES, NULL);
1571 * atk_object_get_object_locale:
1572 * @accessible: an #AtkObject
1574 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
1579 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
1580 * locale of @accessible.
1583 atk_object_get_object_locale (AtkObject *accessible)
1585 AtkObjectClass *klass;
1587 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1589 klass = ATK_OBJECT_GET_CLASS (accessible);
1590 if (klass->get_object_locale)
1591 return (klass->get_object_locale) (accessible);
1598 * atk_role_for_name:
1599 * @name: a string which is the (non-localized) name of an ATK role.
1601 * Get the #AtkRole type corresponding to a rolew name.
1603 * Returns: the #AtkRole enumerated type corresponding to the specified
1605 * or #ATK_ROLE_INVALID if no matching role is found.
1608 atk_role_for_name (const gchar *name)
1610 AtkRole role = ATK_ROLE_INVALID;
1613 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1615 for (i = 0; i < G_N_ELEMENTS (roles_offsets); i++)
1617 if (strcmp (name, roles + roles_offsets[i]) == 0)
1623 for (i = 0; i < extra_roles->len; i++)
1625 gchar *extra_role = (gchar *)g_ptr_array_index (extra_roles, i);
1627 g_return_val_if_fail (extra_role, ATK_ROLE_INVALID);
1629 if (strcmp (name, extra_role) == 0)
1631 role = i + 1 + ATK_ROLE_LAST_DEFINED;
1641 * atk_object_add_relationship:
1642 * @object: The #AtkObject to which an AtkRelation is to be added.
1643 * @relationship: The #AtkRelationType of the relation
1644 * @target: The #AtkObject which is to be the target of the relation.
1646 * Adds a relationship of the specified type with the specified target.
1648 * Returns TRUE if the relationship is added.
1651 atk_object_add_relationship (AtkObject *object,
1652 AtkRelationType relationship,
1655 AtkObject *array[1];
1656 AtkRelation *relation;
1658 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1659 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1661 if (atk_relation_set_contains_target (object->relation_set,
1662 relationship, target))
1666 relation = atk_relation_new (array, 1, relationship);
1667 atk_relation_set_add (object->relation_set, relation);
1668 g_object_unref (relation);
1674 * atk_object_remove_relationship:
1675 * @object: The #AtkObject from which an AtkRelation is to be removed.
1676 * @relationship: The #AtkRelationType of the relation
1677 * @target: The #AtkObject which is the target of the relation to be removed.
1679 * Removes a relationship of the specified type with the specified target.
1681 * Returns TRUE if the relationship is removed.
1684 atk_object_remove_relationship (AtkObject *object,
1685 AtkRelationType relationship,
1688 gboolean ret = FALSE;
1689 AtkRelation *relation;
1692 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1693 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1695 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1699 ret = atk_relation_remove_target (relation, target);
1700 array = atk_relation_get_target (relation);
1701 if (!array || array->len == 0)
1702 atk_relation_set_remove (object->relation_set, relation);
1708 atk_object_real_initialize (AtkObject *accessible,