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 const gchar* atk_object_real_get_name (AtkObject *object);
289 static const gchar* atk_object_real_get_description
291 static AtkObject* atk_object_real_get_parent (AtkObject *object);
292 static AtkRole atk_object_real_get_role (AtkObject *object);
293 static AtkLayer atk_object_real_get_layer (AtkObject *object);
294 static AtkStateSet* atk_object_real_ref_state_set
296 static void atk_object_real_set_name (AtkObject *object,
298 static void atk_object_real_set_description
300 const gchar *description);
301 static void atk_object_real_set_parent (AtkObject *object,
303 static void atk_object_real_set_role (AtkObject *object,
305 static guint atk_object_real_connect_property_change_handler
307 AtkPropertyChangeHandler
309 static void atk_object_real_remove_property_change_handler
312 static void atk_object_notify (GObject *obj,
316 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
318 static gpointer parent_class = NULL;
320 static const gchar* const atk_object_name_property_name = "accessible-name";
321 static const gchar* const atk_object_name_property_description = "accessible-description";
322 static const gchar* const atk_object_name_property_parent = "accessible-parent";
323 static const gchar* const atk_object_name_property_value = "accessible-value";
324 static const gchar* const atk_object_name_property_role = "accessible-role";
325 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
326 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
327 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
328 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
329 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
330 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
331 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
332 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
333 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
334 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
338 static HMODULE atk_dll;
341 DllMain (HINSTANCE hinstDLL,
347 case DLL_PROCESS_ATTACH:
348 atk_dll = (HMODULE) hinstDLL;
356 get_atk_locale_dir (void)
358 static gchar *atk_localedir = NULL;
365 /* ATK_LOCALEDIR might end in either /lib/locale or
366 * /share/locale. Scan for that slash.
368 p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
374 root = g_win32_get_package_installation_directory_of_module (atk_dll);
375 temp = g_build_filename (root, p, NULL);
378 /* atk_localedir is passed to bindtextdomain() which isn't
381 atk_localedir = g_win32_locale_filename_from_utf8 (temp);
384 return atk_localedir;
389 #define ATK_LOCALEDIR get_atk_locale_dir()
394 gettext_initialization (void)
397 static gboolean gettext_initialized = FALSE;
399 if (!gettext_initialized)
401 const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
403 gettext_initialized = TRUE;
407 bindtextdomain (GETTEXT_PACKAGE, dir);
408 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
409 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
416 atk_object_get_type (void)
418 static GType type = 0;
422 static const GTypeInfo typeInfo =
424 sizeof (AtkObjectClass),
425 (GBaseInitFunc) NULL,
426 (GBaseFinalizeFunc) NULL,
427 (GClassInitFunc) atk_object_class_init,
428 (GClassFinalizeFunc) NULL,
432 (GInstanceInitFunc) atk_object_init,
434 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
440 atk_object_class_init (AtkObjectClass *klass)
442 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
444 parent_class = g_type_class_peek_parent (klass);
446 gobject_class->set_property = atk_object_real_set_property;
447 gobject_class->get_property = atk_object_real_get_property;
448 gobject_class->finalize = atk_object_finalize;
449 gobject_class->notify = atk_object_notify;
451 klass->get_name = atk_object_real_get_name;
452 klass->get_description = atk_object_real_get_description;
453 klass->get_parent = atk_object_real_get_parent;
454 klass->get_n_children = NULL;
455 klass->ref_child = NULL;
456 klass->get_index_in_parent = NULL;
457 klass->ref_relation_set = atk_object_real_ref_relation_set;
458 klass->get_role = atk_object_real_get_role;
459 klass->get_layer = atk_object_real_get_layer;
460 klass->get_mdi_zorder = NULL;
461 klass->initialize = atk_object_real_initialize;
462 klass->ref_state_set = atk_object_real_ref_state_set;
463 klass->set_name = atk_object_real_set_name;
464 klass->set_description = atk_object_real_set_description;
465 klass->set_parent = atk_object_real_set_parent;
466 klass->set_role = atk_object_real_set_role;
467 klass->connect_property_change_handler =
468 atk_object_real_connect_property_change_handler;
469 klass->remove_property_change_handler =
470 atk_object_real_remove_property_change_handler;
473 * We do not define default signal handlers here
475 klass->children_changed = NULL;
476 klass->focus_event = NULL;
477 klass->property_change = NULL;
478 klass->visible_data_changed = NULL;
479 klass->active_descendant_changed = NULL;
481 gettext_initialization ();
483 g_object_class_install_property (gobject_class,
485 g_param_spec_string (atk_object_name_property_name,
486 _("Accessible Name"),
487 _("Object instance\'s name formatted for assistive technology access"),
490 g_object_class_install_property (gobject_class,
492 g_param_spec_string (atk_object_name_property_description,
493 _("Accessible Description"),
494 _("Description of an object, formatted for assistive technology access"),
497 g_object_class_install_property (gobject_class,
499 g_param_spec_object (atk_object_name_property_parent,
500 _("Accessible Parent"),
501 _("Is used to notify that the parent has changed"),
504 g_object_class_install_property (gobject_class,
506 g_param_spec_double (atk_object_name_property_value,
507 _("Accessible Value"),
508 _("Is used to notify that the value has changed"),
513 g_object_class_install_property (gobject_class,
515 g_param_spec_int (atk_object_name_property_role,
516 _("Accessible Role"),
517 _("The accessible role of this object"),
522 g_object_class_install_property (gobject_class,
524 g_param_spec_int (atk_object_name_property_component_layer,
525 _("Accessible Layer"),
526 _("The accessible layer of this object"),
531 g_object_class_install_property (gobject_class,
533 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
534 _("Accessible MDI Value"),
535 _("The accessible MDI value of this object"),
540 g_object_class_install_property (gobject_class,
542 g_param_spec_string (atk_object_name_property_table_caption,
543 _("Accessible Table Caption"),
544 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
547 g_object_class_install_property (gobject_class,
548 PROP_TABLE_COLUMN_HEADER,
549 g_param_spec_object (atk_object_name_property_table_column_header,
550 _("Accessible Table Column Header"),
551 _("Is used to notify that the table column header has changed"),
554 g_object_class_install_property (gobject_class,
555 PROP_TABLE_COLUMN_DESCRIPTION,
556 g_param_spec_string (atk_object_name_property_table_column_description,
557 _("Accessible Table Column Description"),
558 _("Is used to notify that the table column description has changed"),
561 g_object_class_install_property (gobject_class,
562 PROP_TABLE_ROW_HEADER,
563 g_param_spec_object (atk_object_name_property_table_row_header,
564 _("Accessible Table Row Header"),
565 _("Is used to notify that the table row header has changed"),
568 g_object_class_install_property (gobject_class,
569 PROP_TABLE_ROW_DESCRIPTION,
570 g_param_spec_string (atk_object_name_property_table_row_description,
571 _("Accessible Table Row Description"),
572 _("Is used to notify that the table row description has changed"),
575 g_object_class_install_property (gobject_class,
577 g_param_spec_object (atk_object_name_property_table_summary,
578 _("Accessible Table Summary"),
579 _("Is used to notify that the table summary has changed"),
582 g_object_class_install_property (gobject_class,
583 PROP_TABLE_CAPTION_OBJECT,
584 g_param_spec_object (atk_object_name_property_table_caption_object,
585 _("Accessible Table Caption Object"),
586 _("Is used to notify that the table caption has changed"),
589 g_object_class_install_property (gobject_class,
590 PROP_HYPERTEXT_NUM_LINKS,
591 g_param_spec_int (atk_object_name_property_hypertext_num_links,
592 _("Number of Accessible Hypertext Links"),
593 _("The number of links which the current AtkHypertext has"),
598 atk_object_signals[CHILDREN_CHANGED] =
599 g_signal_new ("children_changed",
600 G_TYPE_FROM_CLASS (klass),
601 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
602 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
604 g_cclosure_marshal_VOID__UINT_POINTER,
606 2, G_TYPE_UINT, G_TYPE_POINTER);
607 atk_object_signals[FOCUS_EVENT] =
608 g_signal_new ("focus_event",
609 G_TYPE_FROM_CLASS (klass),
611 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
613 g_cclosure_marshal_VOID__BOOLEAN,
616 atk_object_signals[PROPERTY_CHANGE] =
617 g_signal_new ("property_change",
618 G_TYPE_FROM_CLASS (klass),
619 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
620 G_STRUCT_OFFSET (AtkObjectClass, property_change),
621 (GSignalAccumulator) NULL, NULL,
622 g_cclosure_marshal_VOID__POINTER,
625 atk_object_signals[STATE_CHANGE] =
626 g_signal_new ("state_change",
627 G_TYPE_FROM_CLASS (klass),
628 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
629 G_STRUCT_OFFSET (AtkObjectClass, state_change),
630 (GSignalAccumulator) NULL, NULL,
631 atk_marshal_VOID__STRING_BOOLEAN,
635 atk_object_signals[VISIBLE_DATA_CHANGED] =
636 g_signal_new ("visible_data_changed",
637 G_TYPE_FROM_CLASS (klass),
639 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
640 (GSignalAccumulator) NULL, NULL,
641 g_cclosure_marshal_VOID__VOID,
643 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
644 g_signal_new ("active_descendant_changed",
645 G_TYPE_FROM_CLASS (klass),
646 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
647 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
649 g_cclosure_marshal_VOID__POINTER,
655 atk_object_init (AtkObject *accessible,
656 AtkObjectClass *klass)
658 accessible->name = NULL;
659 accessible->description = NULL;
660 accessible->accessible_parent = NULL;
661 accessible->relation_set = atk_relation_set_new();
662 accessible->role = ATK_ROLE_UNKNOWN;
666 atk_implementor_get_type (void)
668 static GType type = 0;
672 static const GTypeInfo typeInfo =
674 sizeof (AtkImplementorIface),
675 (GBaseInitFunc) NULL,
676 (GBaseFinalizeFunc) NULL,
679 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
686 * atk_object_get_name:
687 * @accessible: an #AtkObject
689 * Gets the accessible name of the accessible.
691 * Returns: a character string representing the accessible name of the object.
694 atk_object_get_name (AtkObject *accessible)
696 AtkObjectClass *klass;
698 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
700 klass = ATK_OBJECT_GET_CLASS (accessible);
702 return (klass->get_name) (accessible);
708 * atk_object_get_description:
709 * @accessible: an #AtkObject
711 * Gets the accessible description of the accessible.
713 * Returns: a character string representing the accessible description
718 atk_object_get_description (AtkObject *accessible)
720 AtkObjectClass *klass;
722 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
724 klass = ATK_OBJECT_GET_CLASS (accessible);
725 if (klass->get_description)
726 return (klass->get_description) (accessible);
732 * atk_object_get_parent:
733 * @accessible: an #AtkObject
735 * Gets the accessible parent of the accessible.
737 * Returns: (transfer none): a #AtkObject representing the accessible parent
741 atk_object_get_parent (AtkObject *accessible)
743 AtkObjectClass *klass;
745 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
747 klass = ATK_OBJECT_GET_CLASS (accessible);
748 if (klass->get_parent)
749 return (klass->get_parent) (accessible);
755 * atk_object_get_n_accessible_children:
756 * @accessible: an #AtkObject
758 * Gets the number of accessible children of the accessible.
760 * Returns: an integer representing the number of accessible children
764 atk_object_get_n_accessible_children (AtkObject *accessible)
766 AtkObjectClass *klass;
768 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
770 klass = ATK_OBJECT_GET_CLASS (accessible);
771 if (klass->get_n_children)
772 return (klass->get_n_children) (accessible);
778 * atk_object_ref_accessible_child:
779 * @accessible: an #AtkObject
780 * @i: a gint representing the position of the child, starting from 0
782 * Gets a reference to the specified accessible child of the object.
783 * The accessible children are 0-based so the first accessible child is
784 * at index 0, the second at index 1 and so on.
786 * Returns: (transfer full): an #AtkObject representing the specified
787 * accessible child of the accessible.
790 atk_object_ref_accessible_child (AtkObject *accessible,
793 AtkObjectClass *klass;
795 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
797 klass = ATK_OBJECT_GET_CLASS (accessible);
798 if (klass->ref_child)
799 return (klass->ref_child) (accessible, i);
805 * atk_object_ref_relation_set:
806 * @accessible: an #AtkObject
808 * Gets the #AtkRelationSet associated with the object.
810 * Returns: (transfer full): an #AtkRelationSet representing the relation set
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: (transfer full): 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,
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: (transfer full): a reference to an object's #AtkObject
1148 atk_implementor_ref_accessible (AtkImplementor *implementor)
1150 AtkImplementorIface *iface;
1151 AtkObject *accessible = NULL;
1153 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1155 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1158 accessible = iface->ref_accessible (implementor);
1160 g_return_val_if_fail ((accessible != NULL), NULL);
1167 * atk_object_get_attributes:
1168 * @accessible: An #AtkObject.
1170 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1171 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1172 * as distinct from strongly-typed object data available via other get/set methods.
1173 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1177 * Returns: (transfer none): an #AtkAttributeSet consisting of all explicit
1178 * properties/annotations applied to the object, or an empty set if the object
1179 * has no name-value pair attributes assigned to it.
1182 atk_object_get_attributes (AtkObject *accessible)
1184 AtkObjectClass *klass;
1186 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1188 klass = ATK_OBJECT_GET_CLASS (accessible);
1189 if (klass->get_attributes)
1190 return (klass->get_attributes) (accessible);
1196 static AtkRelationSet*
1197 atk_object_real_ref_relation_set (AtkObject *accessible)
1199 g_return_val_if_fail (accessible->relation_set, NULL);
1200 g_object_ref (accessible->relation_set);
1202 return accessible->relation_set;
1206 atk_object_real_set_property (GObject *object,
1208 const GValue *value,
1211 AtkObject *accessible;
1213 accessible = ATK_OBJECT (object);
1218 atk_object_set_name (accessible, g_value_get_string (value));
1220 case PROP_DESCRIPTION:
1221 atk_object_set_description (accessible, g_value_get_string (value));
1224 atk_object_set_role (accessible, g_value_get_int (value));
1227 atk_object_set_parent (accessible, g_value_get_object (value));
1230 if (ATK_IS_VALUE (accessible))
1231 atk_value_set_current_value (ATK_VALUE (accessible), value);
1233 case PROP_TABLE_SUMMARY:
1234 if (ATK_IS_TABLE (accessible))
1235 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1237 case PROP_TABLE_CAPTION_OBJECT:
1238 if (ATK_IS_TABLE (accessible))
1239 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1247 atk_object_real_get_property (GObject *object,
1252 AtkObject *accessible;
1254 accessible = ATK_OBJECT (object);
1259 g_value_set_string (value, atk_object_get_name (accessible));
1261 case PROP_DESCRIPTION:
1262 g_value_set_string (value, atk_object_get_description (accessible));
1265 g_value_set_int (value, atk_object_get_role (accessible));
1268 if (ATK_IS_COMPONENT (accessible))
1269 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1271 case PROP_MDI_ZORDER:
1272 if (ATK_IS_COMPONENT (accessible))
1273 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1276 g_value_set_object (value, atk_object_get_parent (accessible));
1279 if (ATK_IS_VALUE (accessible))
1280 atk_value_get_current_value (ATK_VALUE (accessible), value);
1282 case PROP_TABLE_SUMMARY:
1283 if (ATK_IS_TABLE (accessible))
1284 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1286 case PROP_TABLE_CAPTION_OBJECT:
1287 if (ATK_IS_TABLE (accessible))
1288 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1290 case PROP_HYPERTEXT_NUM_LINKS:
1291 if (ATK_IS_HYPERTEXT (accessible))
1292 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1295 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1301 atk_object_finalize (GObject *object)
1303 AtkObject *accessible;
1305 g_return_if_fail (ATK_IS_OBJECT (object));
1307 accessible = ATK_OBJECT (object);
1309 g_free (accessible->name);
1310 g_free (accessible->description);
1313 * Free memory allocated for relation set if it have been allocated.
1315 if (accessible->relation_set)
1316 g_object_unref (accessible->relation_set);
1318 if (accessible->accessible_parent)
1319 g_object_unref (accessible->accessible_parent);
1321 G_OBJECT_CLASS (parent_class)->finalize (object);
1325 atk_object_real_get_name (AtkObject *object)
1327 return object->name;
1331 atk_object_real_get_description (AtkObject *object)
1333 return object->description;
1337 atk_object_real_get_parent (AtkObject *object)
1339 return object->accessible_parent;
1343 atk_object_real_get_role (AtkObject *object)
1345 return object->role;
1349 atk_object_real_get_layer (AtkObject *object)
1351 return object->layer;
1355 atk_object_real_ref_state_set (AtkObject *accessible)
1357 AtkStateSet *state_set;
1359 AtkObject *focus_object;
1361 state_set = atk_state_set_new ();
1363 ap = atk_object_get_parent (accessible);
1365 if (ATK_IS_SELECTION (ap))
1369 atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
1371 i = atk_object_get_index_in_parent (accessible);
1373 if (atk_selection_is_child_selected(ATK_SELECTION (ap), i))
1374 atk_state_set_add_state (state_set, ATK_STATE_SELECTED);
1376 focus_object = atk_get_focus_object ();
1377 if (focus_object == accessible)
1378 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1384 atk_object_real_set_name (AtkObject *object,
1387 g_free (object->name);
1388 object->name = g_strdup (name);
1392 atk_object_real_set_description (AtkObject *object,
1393 const gchar *description)
1395 g_free (object->description);
1396 object->description = g_strdup (description);
1400 atk_object_real_set_parent (AtkObject *object,
1403 if (object->accessible_parent)
1404 g_object_unref (object->accessible_parent);
1406 object->accessible_parent = parent;
1407 if (object->accessible_parent)
1408 g_object_ref (object->accessible_parent);
1412 atk_object_real_set_role (AtkObject *object,
1415 object->role = role;
1419 atk_object_real_connect_property_change_handler (AtkObject *obj,
1420 AtkPropertyChangeHandler *handler)
1422 return g_signal_connect_closure_by_id (obj,
1423 atk_object_signals[PROPERTY_CHANGE],
1426 G_CALLBACK (handler), NULL,
1427 (GClosureNotify) NULL),
1432 atk_object_real_remove_property_change_handler (AtkObject *obj,
1435 g_signal_handler_disconnect (obj, handler_id);
1439 * atk_object_initialize:
1440 * @accessible: a #AtkObject
1441 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1443 * This function is called when implementing subclasses of #AtkObject.
1444 * It does initialization required for the new object. It is intended
1445 * that this function should called only in the ..._new() functions used
1446 * to create an instance of a subclass of #AtkObject
1449 atk_object_initialize (AtkObject *accessible,
1452 AtkObjectClass *klass;
1454 g_return_if_fail (ATK_IS_OBJECT (accessible));
1456 klass = ATK_OBJECT_GET_CLASS (accessible);
1457 if (klass->initialize)
1458 klass->initialize (accessible, data);
1462 * This function is a signal handler for notify signal which gets emitted
1463 * when a property changes value.
1465 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1466 * signal which causes the user specified AtkPropertyChangeHandler
1470 atk_object_notify (GObject *obj,
1473 AtkPropertyValues values = { NULL, };
1475 g_value_init (&values.new_value, pspec->value_type);
1476 g_object_get_property (obj, pspec->name, &values.new_value);
1477 values.property_name = pspec->name;
1478 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1479 g_quark_from_string (pspec->name),
1481 g_value_unset (&values.new_value);
1485 * atk_role_get_name:
1486 * @role: The #AtkRole whose name is required
1488 * Gets the description string describing the #AtkRole @role.
1490 * Returns: the string describing the AtkRole
1493 atk_role_get_name (AtkRole role)
1495 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1496 return roles + roles_offsets[role];
1502 n -= ATK_ROLE_LAST_DEFINED + 1;
1504 if (n >= 0 && n < extra_roles->len)
1505 return g_ptr_array_index (extra_roles, n);
1512 * atk_role_get_localized_name:
1513 * @role: The #AtkRole whose localized name is required
1515 * Gets the localized description string describing the #AtkRole @role.
1517 * Returns: the localized string describing the AtkRole
1520 atk_role_get_localized_name (AtkRole role)
1522 gettext_initialization ();
1524 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1525 return dgettext (GETTEXT_PACKAGE, roles + roles_offsets[role]);
1527 return atk_role_get_name (role);
1531 * atk_role_for_name:
1532 * @name: a string which is the (non-localized) name of an ATK role.
1534 * Get the #AtkRole type corresponding to a rolew name.
1536 * Returns: the #AtkRole enumerated type corresponding to the specified
1538 * or #ATK_ROLE_INVALID if no matching role is found.
1541 atk_role_for_name (const gchar *name)
1543 AtkRole role = ATK_ROLE_INVALID;
1546 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1548 for (i = 0; i < G_N_ELEMENTS (roles_offsets); i++)
1550 if (strcmp (name, roles + roles_offsets[i]) == 0)
1556 for (i = 0; i < extra_roles->len; i++)
1558 gchar *extra_role = (gchar *)g_ptr_array_index (extra_roles, i);
1560 g_return_val_if_fail (extra_role, ATK_ROLE_INVALID);
1562 if (strcmp (name, extra_role) == 0)
1564 role = i + 1 + ATK_ROLE_LAST_DEFINED;
1574 * atk_object_add_relationship:
1575 * @object: The #AtkObject to which an AtkRelation is to be added.
1576 * @relationship: The #AtkRelationType of the relation
1577 * @target: The #AtkObject which is to be the target of the relation.
1579 * Adds a relationship of the specified type with the specified target.
1581 * Returns TRUE if the relationship is added.
1584 atk_object_add_relationship (AtkObject *object,
1585 AtkRelationType relationship,
1588 AtkObject *array[1];
1589 AtkRelation *relation;
1591 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1592 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1594 if (atk_relation_set_contains (object->relation_set, relationship))
1598 relation = atk_relation_new (array, 1, relationship);
1599 atk_relation_set_add (object->relation_set, relation);
1600 g_object_unref (relation);
1606 * atk_object_remove_relationship:
1607 * @object: The #AtkObject from which an AtkRelation is to be removed.
1608 * @relationship: The #AtkRelationType of the relation
1609 * @target: The #AtkObject which is the target of the relation to be removed.
1611 * Removes a relationship of the specified type with the specified target.
1613 * Returns TRUE if the relationship is removed.
1616 atk_object_remove_relationship (AtkObject *object,
1617 AtkRelationType relationship,
1620 gboolean ret = FALSE;
1621 AtkRelation *relation;
1624 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1625 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1627 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1631 ret = atk_relation_remove_target (relation, target);
1632 array = atk_relation_get_target (relation);
1633 if (!array || array->len == 0)
1634 atk_relation_set_remove (object->relation_set, relation);
1640 atk_object_real_initialize (AtkObject *accessible,