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 static const char roles[] =
167 "accelerator label\0"
222 "table column header\0"
224 "tear off menu item\0"
242 "embedded component\0"
253 "input method window";
255 static const guint16 roles_offsets[] = {
256 0, 8, 26, 32, 42, 48, 57, 64,
257 74, 90, 104, 118, 128, 139, 152, 166,
258 171, 178, 193, 206, 219, 226, 238, 244,
259 255, 270, 275, 281, 296, 302, 315, 320,
260 330, 335, 344, 354, 366, 375, 389, 395,
261 409, 420, 433, 445, 458, 474, 484, 495,
262 506, 518, 528, 535, 546, 558, 568, 574,
263 585, 605, 622, 641, 650, 655, 669, 678,
264 687, 692, 703, 711, 720, 727, 734, 741,
265 751, 757, 769, 782, 791, 810, 816, 822,
266 830, 845, 853, 858, 866, 883, 888, 893
269 /* This is a static assertion */
270 typedef int _assert_roles_num[(G_N_ELEMENTS (roles_offsets) == ATK_ROLE_LAST_DEFINED) ? 1 : -1];
272 static void atk_object_class_init (AtkObjectClass *klass);
273 static void atk_object_init (AtkObject *accessible,
274 AtkObjectClass *klass);
275 static AtkRelationSet* atk_object_real_ref_relation_set
276 (AtkObject *accessible);
277 static void atk_object_real_initialize (AtkObject *accessible,
279 static void atk_object_real_set_property (GObject *object,
283 static void atk_object_real_get_property (GObject *object,
287 static void atk_object_finalize (GObject *object);
288 static G_CONST_RETURN gchar*
289 atk_object_real_get_name (AtkObject *object);
290 static G_CONST_RETURN gchar*
291 atk_object_real_get_description
293 static AtkObject* atk_object_real_get_parent (AtkObject *object);
294 static AtkRole atk_object_real_get_role (AtkObject *object);
295 static AtkLayer atk_object_real_get_layer (AtkObject *object);
296 static AtkStateSet* atk_object_real_ref_state_set
298 static void atk_object_real_set_name (AtkObject *object,
300 static void atk_object_real_set_description
302 const gchar *description);
303 static void atk_object_real_set_parent (AtkObject *object,
305 static void atk_object_real_set_role (AtkObject *object,
307 static guint atk_object_real_connect_property_change_handler
309 AtkPropertyChangeHandler
311 static void atk_object_real_remove_property_change_handler
314 static void atk_object_notify (GObject *obj,
318 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
320 static gpointer parent_class = NULL;
322 static const gchar* const atk_object_name_property_name = "accessible-name";
323 static const gchar* const atk_object_name_property_description = "accessible-description";
324 static const gchar* const atk_object_name_property_parent = "accessible-parent";
325 static const gchar* const atk_object_name_property_value = "accessible-value";
326 static const gchar* const atk_object_name_property_role = "accessible-role";
327 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
328 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
329 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
330 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
331 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
332 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
333 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
334 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
335 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
336 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
340 static HMODULE atk_dll;
343 DllMain (HINSTANCE hinstDLL,
349 case DLL_PROCESS_ATTACH:
350 atk_dll = (HMODULE) hinstDLL;
358 get_atk_locale_dir (void)
360 static gchar *atk_localedir = NULL;
367 /* ATK_LOCALEDIR might end in either /lib/locale or
368 * /share/locale. Scan for that slash.
370 p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
376 root = g_win32_get_package_installation_directory_of_module (atk_dll);
377 temp = g_build_filename (root, p, NULL);
380 /* atk_localedir is passed to bindtextdomain() which isn't
383 atk_localedir = g_win32_locale_filename_from_utf8 (temp);
386 return atk_localedir;
391 #define ATK_LOCALEDIR get_atk_locale_dir()
396 gettext_initialization (void)
399 static gboolean gettext_initialized = FALSE;
401 if (!gettext_initialized)
403 const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
405 gettext_initialized = TRUE;
409 bindtextdomain (GETTEXT_PACKAGE, dir);
410 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
411 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
418 atk_object_get_type (void)
420 static GType type = 0;
424 static const GTypeInfo typeInfo =
426 sizeof (AtkObjectClass),
427 (GBaseInitFunc) NULL,
428 (GBaseFinalizeFunc) NULL,
429 (GClassInitFunc) atk_object_class_init,
430 (GClassFinalizeFunc) NULL,
434 (GInstanceInitFunc) atk_object_init,
436 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
442 atk_object_class_init (AtkObjectClass *klass)
444 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
446 parent_class = g_type_class_peek_parent (klass);
448 gobject_class->set_property = atk_object_real_set_property;
449 gobject_class->get_property = atk_object_real_get_property;
450 gobject_class->finalize = atk_object_finalize;
451 gobject_class->notify = atk_object_notify;
453 klass->get_name = atk_object_real_get_name;
454 klass->get_description = atk_object_real_get_description;
455 klass->get_parent = atk_object_real_get_parent;
456 klass->get_n_children = NULL;
457 klass->ref_child = NULL;
458 klass->get_index_in_parent = NULL;
459 klass->ref_relation_set = atk_object_real_ref_relation_set;
460 klass->get_role = atk_object_real_get_role;
461 klass->get_layer = atk_object_real_get_layer;
462 klass->get_mdi_zorder = NULL;
463 klass->initialize = atk_object_real_initialize;
464 klass->ref_state_set = atk_object_real_ref_state_set;
465 klass->set_name = atk_object_real_set_name;
466 klass->set_description = atk_object_real_set_description;
467 klass->set_parent = atk_object_real_set_parent;
468 klass->set_role = atk_object_real_set_role;
469 klass->connect_property_change_handler =
470 atk_object_real_connect_property_change_handler;
471 klass->remove_property_change_handler =
472 atk_object_real_remove_property_change_handler;
475 * We do not define default signal handlers here
477 klass->children_changed = NULL;
478 klass->focus_event = NULL;
479 klass->property_change = NULL;
480 klass->visible_data_changed = NULL;
481 klass->active_descendant_changed = NULL;
483 gettext_initialization ();
485 g_object_class_install_property (gobject_class,
487 g_param_spec_string (atk_object_name_property_name,
488 _("Accessible Name"),
489 _("Object instance\'s name formatted for assistive technology access"),
492 g_object_class_install_property (gobject_class,
494 g_param_spec_string (atk_object_name_property_description,
495 _("Accessible Description"),
496 _("Description of an object, formatted for assistive technology access"),
499 g_object_class_install_property (gobject_class,
501 g_param_spec_object (atk_object_name_property_parent,
502 _("Accessible Parent"),
503 _("Is used to notify that the parent has changed"),
506 g_object_class_install_property (gobject_class,
508 g_param_spec_double (atk_object_name_property_value,
509 _("Accessible Value"),
510 _("Is used to notify that the value has changed"),
515 g_object_class_install_property (gobject_class,
517 g_param_spec_int (atk_object_name_property_role,
518 _("Accessible Role"),
519 _("The accessible role of this object"),
524 g_object_class_install_property (gobject_class,
526 g_param_spec_int (atk_object_name_property_component_layer,
527 _("Accessible Layer"),
528 _("The accessible layer of this object"),
533 g_object_class_install_property (gobject_class,
535 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
536 _("Accessible MDI Value"),
537 _("The accessible MDI value of this object"),
542 g_object_class_install_property (gobject_class,
544 g_param_spec_string (atk_object_name_property_table_caption,
545 _("Accessible Table Caption"),
546 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
549 g_object_class_install_property (gobject_class,
550 PROP_TABLE_COLUMN_HEADER,
551 g_param_spec_object (atk_object_name_property_table_column_header,
552 _("Accessible Table Column Header"),
553 _("Is used to notify that the table column header has changed"),
556 g_object_class_install_property (gobject_class,
557 PROP_TABLE_COLUMN_DESCRIPTION,
558 g_param_spec_string (atk_object_name_property_table_column_description,
559 _("Accessible Table Column Description"),
560 _("Is used to notify that the table column description has changed"),
563 g_object_class_install_property (gobject_class,
564 PROP_TABLE_ROW_HEADER,
565 g_param_spec_object (atk_object_name_property_table_row_header,
566 _("Accessible Table Row Header"),
567 _("Is used to notify that the table row header has changed"),
570 g_object_class_install_property (gobject_class,
571 PROP_TABLE_ROW_DESCRIPTION,
572 g_param_spec_string (atk_object_name_property_table_row_description,
573 _("Accessible Table Row Description"),
574 _("Is used to notify that the table row description has changed"),
577 g_object_class_install_property (gobject_class,
579 g_param_spec_object (atk_object_name_property_table_summary,
580 _("Accessible Table Summary"),
581 _("Is used to notify that the table summary has changed"),
584 g_object_class_install_property (gobject_class,
585 PROP_TABLE_CAPTION_OBJECT,
586 g_param_spec_object (atk_object_name_property_table_caption_object,
587 _("Accessible Table Caption Object"),
588 _("Is used to notify that the table caption has changed"),
591 g_object_class_install_property (gobject_class,
592 PROP_HYPERTEXT_NUM_LINKS,
593 g_param_spec_int (atk_object_name_property_hypertext_num_links,
594 _("Number of Accessible Hypertext Links"),
595 _("The number of links which the current AtkHypertext has"),
600 atk_object_signals[CHILDREN_CHANGED] =
601 g_signal_new ("children_changed",
602 G_TYPE_FROM_CLASS (klass),
603 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
604 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
606 g_cclosure_marshal_VOID__UINT_POINTER,
608 2, G_TYPE_UINT, G_TYPE_POINTER);
609 atk_object_signals[FOCUS_EVENT] =
610 g_signal_new ("focus_event",
611 G_TYPE_FROM_CLASS (klass),
613 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
615 g_cclosure_marshal_VOID__BOOLEAN,
618 atk_object_signals[PROPERTY_CHANGE] =
619 g_signal_new ("property_change",
620 G_TYPE_FROM_CLASS (klass),
621 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
622 G_STRUCT_OFFSET (AtkObjectClass, property_change),
623 (GSignalAccumulator) NULL, NULL,
624 g_cclosure_marshal_VOID__POINTER,
627 atk_object_signals[STATE_CHANGE] =
628 g_signal_new ("state_change",
629 G_TYPE_FROM_CLASS (klass),
630 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
631 G_STRUCT_OFFSET (AtkObjectClass, state_change),
632 (GSignalAccumulator) NULL, NULL,
633 atk_marshal_VOID__STRING_BOOLEAN,
637 atk_object_signals[VISIBLE_DATA_CHANGED] =
638 g_signal_new ("visible_data_changed",
639 G_TYPE_FROM_CLASS (klass),
641 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
642 (GSignalAccumulator) NULL, NULL,
643 g_cclosure_marshal_VOID__VOID,
645 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
646 g_signal_new ("active_descendant_changed",
647 G_TYPE_FROM_CLASS (klass),
648 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
649 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
651 g_cclosure_marshal_VOID__POINTER,
657 atk_object_init (AtkObject *accessible,
658 AtkObjectClass *klass)
660 accessible->name = NULL;
661 accessible->description = NULL;
662 accessible->accessible_parent = NULL;
663 accessible->relation_set = atk_relation_set_new();
664 accessible->role = ATK_ROLE_UNKNOWN;
668 atk_implementor_get_type (void)
670 static GType type = 0;
674 static const GTypeInfo typeInfo =
676 sizeof (AtkImplementorIface),
677 (GBaseInitFunc) NULL,
678 (GBaseFinalizeFunc) NULL,
681 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
688 * atk_object_get_name:
689 * @accessible: an #AtkObject
691 * Gets the accessible name of the accessible.
693 * Returns: a character string representing the accessible name of the object.
695 G_CONST_RETURN gchar*
696 atk_object_get_name (AtkObject *accessible)
698 AtkObjectClass *klass;
700 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
702 klass = ATK_OBJECT_GET_CLASS (accessible);
704 return (klass->get_name) (accessible);
710 * atk_object_get_description:
711 * @accessible: an #AtkObject
713 * Gets the accessible description of the accessible.
715 * Returns: a character string representing the accessible description
719 G_CONST_RETURN gchar*
720 atk_object_get_description (AtkObject *accessible)
722 AtkObjectClass *klass;
724 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
726 klass = ATK_OBJECT_GET_CLASS (accessible);
727 if (klass->get_description)
728 return (klass->get_description) (accessible);
734 * atk_object_get_parent:
735 * @accessible: an #AtkObject
737 * Gets the accessible parent of the accessible.
739 * Returns: a #AtkObject representing the accessible parent of the accessible
742 atk_object_get_parent (AtkObject *accessible)
744 AtkObjectClass *klass;
746 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
748 klass = ATK_OBJECT_GET_CLASS (accessible);
749 if (klass->get_parent)
750 return (klass->get_parent) (accessible);
756 * atk_object_get_n_accessible_children:
757 * @accessible: an #AtkObject
759 * Gets the number of accessible children of the accessible.
761 * Returns: an integer representing the number of accessible children
765 atk_object_get_n_accessible_children (AtkObject *accessible)
767 AtkObjectClass *klass;
769 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
771 klass = ATK_OBJECT_GET_CLASS (accessible);
772 if (klass->get_n_children)
773 return (klass->get_n_children) (accessible);
779 * atk_object_ref_accessible_child:
780 * @accessible: an #AtkObject
781 * @i: a gint representing the position of the child, starting from 0
783 * Gets a reference to the specified accessible child of the object.
784 * The accessible children are 0-based so the first accessible child is
785 * at index 0, the second at index 1 and so on.
787 * Returns: an #AtkObject representing the specified accessible child
791 atk_object_ref_accessible_child (AtkObject *accessible,
794 AtkObjectClass *klass;
796 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
798 klass = ATK_OBJECT_GET_CLASS (accessible);
799 if (klass->ref_child)
800 return (klass->ref_child) (accessible, i);
806 * atk_object_ref_relation_set:
807 * @accessible: an #AtkObject
809 * Gets the #AtkRelationSet associated with the object.
811 * Returns: an #AtkRelationSet representing the relation set of the object.
814 atk_object_ref_relation_set (AtkObject *accessible)
816 AtkObjectClass *klass;
818 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
820 klass = ATK_OBJECT_GET_CLASS (accessible);
821 if (klass->ref_relation_set)
822 return (klass->ref_relation_set) (accessible);
829 * @name: a character string describing the new role.
831 * Registers the role specified by @name.
833 * Returns: an #AtkRole for the new role.
836 atk_role_register (const gchar *name)
839 extra_roles = g_ptr_array_new ();
841 g_ptr_array_add (extra_roles, g_strdup (name));
842 return extra_roles->len + ATK_ROLE_LAST_DEFINED;
846 * atk_object_get_role:
847 * @accessible: an #AtkObject
849 * Gets the role of the accessible.
851 * Returns: an #AtkRole which is the role of the accessible
854 atk_object_get_role (AtkObject *accessible)
856 AtkObjectClass *klass;
858 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
860 klass = ATK_OBJECT_GET_CLASS (accessible);
862 return (klass->get_role) (accessible);
864 return ATK_ROLE_UNKNOWN;
868 * atk_object_get_layer:
869 * @accessible: an #AtkObject
871 * Gets the layer of the accessible.
873 * Deprecated: Use atk_component_get_layer instead.
875 * Returns: an #AtkLayer which is the layer of the accessible
878 atk_object_get_layer (AtkObject *accessible)
880 AtkObjectClass *klass;
882 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
884 klass = ATK_OBJECT_GET_CLASS (accessible);
885 if (klass->get_layer)
886 return (klass->get_layer) (accessible);
888 return ATK_LAYER_INVALID;
892 * atk_object_get_mdi_zorder:
893 * @accessible: an #AtkObject
895 * Gets the zorder of the accessible. The value G_MININT will be returned
896 * if the layer of the accessible is not ATK_LAYER_MDI.
898 * Deprecated: Use atk_component_get_mdi_zorder instead.
900 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
901 * which the component is shown in relation to other components in the same
906 atk_object_get_mdi_zorder (AtkObject *accessible)
908 AtkObjectClass *klass;
910 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
912 klass = ATK_OBJECT_GET_CLASS (accessible);
913 if (klass->get_mdi_zorder)
914 return (klass->get_mdi_zorder) (accessible);
920 * atk_object_ref_state_set:
921 * @accessible: an #AtkObject
923 * Gets a reference to the state set of the accessible; the caller must
924 * unreference it when it is no longer needed.
926 * Returns: a reference to an #AtkStateSet which is the state
927 * set of the accessible
930 atk_object_ref_state_set (AtkObject *accessible)
932 AtkObjectClass *klass;
934 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
936 klass = ATK_OBJECT_GET_CLASS (accessible);
937 if (klass->ref_state_set)
938 return (klass->ref_state_set) (accessible);
944 * atk_object_get_index_in_parent:
945 * @accessible: an #AtkObject
947 * Gets the 0-based index of this accessible in its parent; returns -1 if the
948 * accessible does not have an accessible parent.
950 * Returns: an integer which is the index of the accessible in its parent
953 atk_object_get_index_in_parent (AtkObject *accessible)
955 AtkObjectClass *klass;
957 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
959 klass = ATK_OBJECT_GET_CLASS (accessible);
960 if (klass->get_index_in_parent)
961 return (klass->get_index_in_parent) (accessible);
967 * atk_object_set_name:
968 * @accessible: an #AtkObject
969 * @name: a character string to be set as the accessible name
971 * Sets the accessible name of the accessible.
974 atk_object_set_name (AtkObject *accessible,
977 AtkObjectClass *klass;
979 g_return_if_fail (ATK_IS_OBJECT (accessible));
980 g_return_if_fail (name != NULL);
982 klass = ATK_OBJECT_GET_CLASS (accessible);
985 (klass->set_name) (accessible, name);
986 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
991 * atk_object_set_description:
992 * @accessible: an #AtkObject
993 * @description : a character string to be set as the accessible description
995 * Sets the accessible description of the accessible.
998 atk_object_set_description (AtkObject *accessible,
999 const gchar *description)
1001 AtkObjectClass *klass;
1003 g_return_if_fail (ATK_IS_OBJECT (accessible));
1004 g_return_if_fail (description != NULL);
1006 klass = ATK_OBJECT_GET_CLASS (accessible);
1007 if (klass->set_description)
1009 (klass->set_description) (accessible, description);
1010 g_object_notify (G_OBJECT (accessible), atk_object_name_property_description);
1015 * atk_object_set_parent:
1016 * @accessible: an #AtkObject
1017 * @parent : an #AtkObject to be set as the accessible parent
1019 * Sets the accessible parent of the accessible.
1022 atk_object_set_parent (AtkObject *accessible,
1025 AtkObjectClass *klass;
1027 g_return_if_fail (ATK_IS_OBJECT (accessible));
1029 klass = ATK_OBJECT_GET_CLASS (accessible);
1030 if (klass->set_parent)
1032 (klass->set_parent) (accessible, parent);
1033 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1038 * atk_object_set_role:
1039 * @accessible: an #AtkObject
1040 * @role : an #AtkRole to be set as the role
1042 * Sets the role of the accessible.
1045 atk_object_set_role (AtkObject *accessible,
1048 AtkObjectClass *klass;
1051 g_return_if_fail (ATK_IS_OBJECT (accessible));
1053 klass = ATK_OBJECT_GET_CLASS (accessible);
1054 if (klass->set_role)
1056 old_role = atk_object_get_role (accessible);
1057 if (old_role != role)
1059 (klass->set_role) (accessible, role);
1060 if (old_role != ATK_ROLE_UNKNOWN)
1061 /* Do not notify for initial role setting */
1062 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1068 * atk_object_connect_property_change_handler:
1069 * @accessible: an #AtkObject
1070 * @handler : a function to be called when a property changes its value
1072 * Specifies a function to be called when a property changes value.
1074 * Returns: a #guint which is the handler id used in
1075 * atk_object_remove_property_change_handler()
1078 atk_object_connect_property_change_handler (AtkObject *accessible,
1079 AtkPropertyChangeHandler *handler)
1081 AtkObjectClass *klass;
1083 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1084 g_return_val_if_fail ((handler != NULL), 0);
1086 klass = ATK_OBJECT_GET_CLASS (accessible);
1087 if (klass->connect_property_change_handler)
1088 return (klass->connect_property_change_handler) (accessible, handler);
1094 * atk_object_remove_property_change_handler:
1095 * @accessible: an #AtkObject
1096 * @handler_id : a guint which identifies the handler to be removed.
1098 * Removes a property change handler.
1101 atk_object_remove_property_change_handler (AtkObject *accessible,
1104 AtkObjectClass *klass;
1106 g_return_if_fail (ATK_IS_OBJECT (accessible));
1108 klass = ATK_OBJECT_GET_CLASS (accessible);
1109 if (klass->remove_property_change_handler)
1110 (klass->remove_property_change_handler) (accessible, handler_id);
1114 * atk_object_notify_state_change:
1115 * @accessible: an #AtkObject
1116 * @state: an #AtkState whose state is changed
1117 * @value : a gboolean which indicates whether the state is being set on or off
1119 * Emits a state-change signal for the specified state.
1122 atk_object_notify_state_change (AtkObject *accessible,
1126 G_CONST_RETURN gchar* name;
1128 g_return_if_fail (ATK_IS_OBJECT (accessible));
1130 name = atk_state_type_get_name (state);
1131 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1132 g_quark_from_string (name),
1137 * atk_implementor_ref_accessible:
1138 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1139 * if a non-null return value is required.
1141 * Gets a reference to an object's #AtkObject implementation, if
1142 * the object implements #AtkObjectIface
1144 * Returns: a reference to an object's #AtkObject implementation
1147 atk_implementor_ref_accessible (AtkImplementor *implementor)
1149 AtkImplementorIface *iface;
1150 AtkObject *accessible = NULL;
1152 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1154 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1157 accessible = iface->ref_accessible (implementor);
1159 g_return_val_if_fail ((accessible != NULL), NULL);
1166 * atk_object_get_attributes:
1167 * @accessible: An #AtkObject.
1169 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1170 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1171 * as distinct from strongly-typed object data available via other get/set methods.
1172 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1176 * Returns: an #AtkAttributeSet consisting of all explicit properties/annotations applied to
1177 * the object, or an empty set if the object has no name-value pair attributes assigned to it.
1180 atk_object_get_attributes (AtkObject *accessible)
1182 AtkObjectClass *klass;
1184 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1186 klass = ATK_OBJECT_GET_CLASS (accessible);
1187 if (klass->get_attributes)
1188 return (klass->get_attributes) (accessible);
1194 static AtkRelationSet*
1195 atk_object_real_ref_relation_set (AtkObject *accessible)
1197 g_return_val_if_fail (accessible->relation_set, NULL);
1198 g_object_ref (accessible->relation_set);
1200 return accessible->relation_set;
1204 atk_object_real_set_property (GObject *object,
1206 const GValue *value,
1209 AtkObject *accessible;
1211 accessible = ATK_OBJECT (object);
1216 atk_object_set_name (accessible, g_value_get_string (value));
1218 case PROP_DESCRIPTION:
1219 atk_object_set_description (accessible, g_value_get_string (value));
1222 atk_object_set_role (accessible, g_value_get_int (value));
1225 atk_object_set_parent (accessible, g_value_get_object (value));
1228 if (ATK_IS_VALUE (accessible))
1229 atk_value_set_current_value (ATK_VALUE (accessible), value);
1231 case PROP_TABLE_SUMMARY:
1232 if (ATK_IS_TABLE (accessible))
1233 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1235 case PROP_TABLE_CAPTION_OBJECT:
1236 if (ATK_IS_TABLE (accessible))
1237 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1245 atk_object_real_get_property (GObject *object,
1250 AtkObject *accessible;
1252 accessible = ATK_OBJECT (object);
1257 g_value_set_string (value, atk_object_get_name (accessible));
1259 case PROP_DESCRIPTION:
1260 g_value_set_string (value, atk_object_get_description (accessible));
1263 g_value_set_int (value, atk_object_get_role (accessible));
1266 if (ATK_IS_COMPONENT (accessible))
1267 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1269 case PROP_MDI_ZORDER:
1270 if (ATK_IS_COMPONENT (accessible))
1271 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1274 g_value_set_object (value, atk_object_get_parent (accessible));
1277 if (ATK_IS_VALUE (accessible))
1278 atk_value_get_current_value (ATK_VALUE (accessible), value);
1280 case PROP_TABLE_SUMMARY:
1281 if (ATK_IS_TABLE (accessible))
1282 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1284 case PROP_TABLE_CAPTION_OBJECT:
1285 if (ATK_IS_TABLE (accessible))
1286 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1288 case PROP_HYPERTEXT_NUM_LINKS:
1289 if (ATK_IS_HYPERTEXT (accessible))
1290 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1293 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1299 atk_object_finalize (GObject *object)
1301 AtkObject *accessible;
1303 g_return_if_fail (ATK_IS_OBJECT (object));
1305 accessible = ATK_OBJECT (object);
1307 g_free (accessible->name);
1308 g_free (accessible->description);
1311 * Free memory allocated for relation set if it have been allocated.
1313 if (accessible->relation_set)
1314 g_object_unref (accessible->relation_set);
1316 if (accessible->accessible_parent)
1317 g_object_unref (accessible->accessible_parent);
1319 G_OBJECT_CLASS (parent_class)->finalize (object);
1322 static G_CONST_RETURN gchar*
1323 atk_object_real_get_name (AtkObject *object)
1325 return object->name;
1328 static G_CONST_RETURN gchar*
1329 atk_object_real_get_description (AtkObject *object)
1331 return object->description;
1335 atk_object_real_get_parent (AtkObject *object)
1337 return object->accessible_parent;
1341 atk_object_real_get_role (AtkObject *object)
1343 return object->role;
1347 atk_object_real_get_layer (AtkObject *object)
1349 return object->layer;
1353 atk_object_real_ref_state_set (AtkObject *accessible)
1355 AtkStateSet *state_set;
1357 AtkObject *focus_object;
1359 state_set = atk_state_set_new ();
1361 ap = atk_object_get_parent (accessible);
1363 if (ATK_IS_SELECTION (ap))
1367 atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
1369 i = atk_object_get_index_in_parent (accessible);
1371 if (atk_selection_is_child_selected(ATK_SELECTION (ap), i))
1372 atk_state_set_add_state (state_set, ATK_STATE_SELECTED);
1374 focus_object = atk_get_focus_object ();
1375 if (focus_object == accessible)
1376 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1382 atk_object_real_set_name (AtkObject *object,
1385 g_free (object->name);
1386 object->name = g_strdup (name);
1390 atk_object_real_set_description (AtkObject *object,
1391 const gchar *description)
1393 g_free (object->description);
1394 object->description = g_strdup (description);
1398 atk_object_real_set_parent (AtkObject *object,
1401 if (object->accessible_parent)
1402 g_object_unref (object->accessible_parent);
1404 object->accessible_parent = parent;
1405 if (object->accessible_parent)
1406 g_object_ref (object->accessible_parent);
1410 atk_object_real_set_role (AtkObject *object,
1413 object->role = role;
1417 atk_object_real_connect_property_change_handler (AtkObject *obj,
1418 AtkPropertyChangeHandler *handler)
1420 return g_signal_connect_closure_by_id (obj,
1421 atk_object_signals[PROPERTY_CHANGE],
1424 G_CALLBACK (handler), NULL,
1425 (GClosureNotify) NULL),
1430 atk_object_real_remove_property_change_handler (AtkObject *obj,
1433 g_signal_handler_disconnect (obj, handler_id);
1437 * atk_object_initialize:
1438 * @accessible: a #AtkObject
1439 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1441 * This function is called when implementing subclasses of #AtkObject.
1442 * It does initialization required for the new object. It is intended
1443 * that this function should called only in the ..._new() functions used
1444 * to create an instance of a subclass of #AtkObject
1447 atk_object_initialize (AtkObject *accessible,
1450 AtkObjectClass *klass;
1452 g_return_if_fail (ATK_IS_OBJECT (accessible));
1454 klass = ATK_OBJECT_GET_CLASS (accessible);
1455 if (klass->initialize)
1456 klass->initialize (accessible, data);
1460 * This function is a signal handler for notify signal which gets emitted
1461 * when a property changes value.
1463 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1464 * signal which causes the user specified AtkPropertyChangeHandler
1468 atk_object_notify (GObject *obj,
1471 AtkPropertyValues values = { NULL, };
1473 g_value_init (&values.new_value, pspec->value_type);
1474 g_object_get_property (obj, pspec->name, &values.new_value);
1475 values.property_name = pspec->name;
1476 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1477 g_quark_from_string (pspec->name),
1479 g_value_unset (&values.new_value);
1483 * atk_role_get_name:
1484 * @role: The #AtkRole whose name is required
1486 * Gets the description string describing the #AtkRole @role.
1488 * Returns: the string describing the AtkRole
1490 G_CONST_RETURN gchar*
1491 atk_role_get_name (AtkRole role)
1493 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1494 return roles + roles_offsets[role];
1500 n -= ATK_ROLE_LAST_DEFINED + 1;
1502 if (n >= 0 && n < extra_roles->len)
1503 return g_ptr_array_index (extra_roles, n);
1510 * atk_role_get_localized_name:
1511 * @role: The #AtkRole whose localized name is required
1513 * Gets the localized description string describing the #AtkRole @role.
1515 * Returns: the localized string describing the AtkRole
1517 G_CONST_RETURN gchar*
1518 atk_role_get_localized_name (AtkRole role)
1520 gettext_initialization ();
1522 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1523 return dgettext (GETTEXT_PACKAGE, roles + roles_offsets[role]);
1525 return atk_role_get_name (role);
1529 * atk_role_for_name:
1530 * @name: a string which is the (non-localized) name of an ATK role.
1532 * Get the #AtkRole type corresponding to a rolew name.
1534 * Returns: the #AtkRole enumerated type corresponding to the specified
1536 * or #ATK_ROLE_INVALID if no matching role is found.
1539 atk_role_for_name (const gchar *name)
1541 AtkRole role = ATK_ROLE_INVALID;
1544 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1546 for (i = 0; i < G_N_ELEMENTS (roles_offsets); i++)
1548 if (strcmp (name, roles + roles_offsets[i]) == 0)
1554 for (i = 0; i < extra_roles->len; i++)
1556 gchar *extra_role = (gchar *)g_ptr_array_index (extra_roles, i);
1558 g_return_val_if_fail (extra_role, ATK_ROLE_INVALID);
1560 if (strcmp (name, extra_role) == 0)
1562 role = i + 1 + ATK_ROLE_LAST_DEFINED;
1572 * atk_object_add_relationship:
1573 * @object: The #AtkObject to which an AtkRelation is to be added.
1574 * @relationship: The #AtkRelationType of the relation
1575 * @target: The #AtkObject which is to be the target of the relation.
1577 * Adds a relationship of the specified type with the specified target.
1579 * Returns TRUE if the relationship is added.
1582 atk_object_add_relationship (AtkObject *object,
1583 AtkRelationType relationship,
1586 AtkObject *array[1];
1587 AtkRelation *relation;
1589 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1590 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1593 relation = atk_relation_new (array, 1, relationship);
1594 atk_relation_set_add (object->relation_set, relation);
1595 g_object_unref (relation);
1601 * atk_object_remove_relationship:
1602 * @object: The #AtkObject from which an AtkRelation is to be removed.
1603 * @relationship: The #AtkRelationType of the relation
1604 * @target: The #AtkObject which is the target of the relation to be removed.
1606 * Removes a relationship of the specified type with the specified target.
1608 * Returns TRUE if the relationship is removed.
1611 atk_object_remove_relationship (AtkObject *object,
1612 AtkRelationType relationship,
1615 gboolean ret = FALSE;
1616 AtkRelation *relation;
1619 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1620 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1622 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1626 ret = atk_relation_remove_target (relation, target);
1627 array = atk_relation_get_target (relation);
1628 if (!array || array->len == 0)
1629 atk_relation_set_remove (object->relation_set, relation);
1635 atk_object_real_initialize (AtkObject *accessible,