atktext: Fixing some typos on atk_text_get_text_at_offset deprecation
[atk.git] / atk / atkobject.c
blobe809e4885455b9006a6e4e4f02ef532823d0998b
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.
20 #include <string.h>
21 #include <locale.h>
23 #include <glib-object.h>
25 #ifdef G_OS_WIN32
26 #define STRICT
27 #include <windows.h>
28 #undef STRICT
29 #undef FOCUS_EVENT /* <windows.h> pollutes the namespace
30 * like a six hundred pound gorilla */
31 #endif
33 #include "atk.h"
34 #include "atkmarshal.h"
35 #include "atk-enum-types.h"
36 #include "atkintl.h"
38 /**
39 * SECTION:atkobject
40 * @Short_description: The base object class for the Accessibility Toolkit API.
41 * @Title:AtkObject
43 * This class is the primary class for accessibility support via the
44 * Accessibility ToolKit (ATK). Objects which are instances of
45 * #AtkObject (or instances of AtkObject-derived types) are queried
46 * for properties which relate basic (and generic) properties of a UI
47 * component such as name and description. Instances of #AtkObject
48 * may also be queried as to whether they implement other ATK
49 * interfaces (e.g. #AtkAction, #AtkComponent, etc.), as appropriate
50 * to the role which a given UI component plays in a user interface.
52 * All UI components in an application which provide useful
53 * information or services to the user must provide corresponding
54 * #AtkObject instances on request (in GTK+, for instance, usually on
55 * a call to #gtk_widget_get_accessible ()), either via ATK support
56 * built into the toolkit for the widget class or ancestor class, or
57 * in the case of custom widgets, if the inherited #AtkObject
58 * implementation is insufficient, via instances of a new #AtkObject
59 * subclass.
61 * See also: #AtkObjectFactory, #AtkRegistry. (GTK+ users see also
62 * #GtkAccessible).
66 static GPtrArray *role_names = NULL;
68 enum
70 PROP_0, /* gobject convention */
72 PROP_NAME,
73 PROP_DESCRIPTION,
74 PROP_PARENT, /* ancestry has changed */
75 PROP_VALUE,
76 PROP_ROLE,
77 PROP_LAYER,
78 PROP_MDI_ZORDER,
79 PROP_TABLE_CAPTION,
80 PROP_TABLE_COLUMN_DESCRIPTION,
81 PROP_TABLE_COLUMN_HEADER,
82 PROP_TABLE_ROW_DESCRIPTION,
83 PROP_TABLE_ROW_HEADER,
84 PROP_TABLE_SUMMARY,
85 PROP_TABLE_CAPTION_OBJECT,
86 PROP_HYPERTEXT_NUM_LINKS,
87 PROP_LAST /* gobject convention */
90 enum {
91 CHILDREN_CHANGED,
92 FOCUS_EVENT,
93 PROPERTY_CHANGE,
94 STATE_CHANGE,
95 VISIBLE_DATA_CHANGED,
96 ACTIVE_DESCENDANT_CHANGED,
98 LAST_SIGNAL
101 /* These are listed here for extraction by intltool */
102 #if 0
103 N_("invalid")
104 N_("accelerator label")
105 N_("alert")
106 N_("animation")
107 N_("arrow")
108 N_("calendar")
109 N_("canvas")
110 N_("check box")
111 N_("check menu item")
112 N_("color chooser")
113 N_("column header")
114 N_("combo box")
115 N_("dateeditor")
116 N_("desktop icon")
117 N_("desktop frame")
118 N_("dial")
119 N_("dialog")
120 N_("directory pane")
121 N_("drawing area")
122 N_("file chooser")
123 N_("filler")
124 /* I know it looks wrong but that is what Java returns */
125 N_("fontchooser")
126 N_("frame")
127 N_("glass pane")
128 N_("html container")
129 N_("icon")
130 N_("image")
131 N_("internal frame")
132 N_("label")
133 N_("layered pane")
134 N_("list")
135 N_("list item")
136 N_("menu")
137 N_("menu bar")
138 N_("menu item")
139 N_("option pane")
140 N_("page tab")
141 N_("page tab list")
142 N_("panel")
143 N_("password text")
144 N_("popup menu")
145 N_("progress bar")
146 N_("push button")
147 N_("radio button")
148 N_("radio menu item")
149 N_("root pane")
150 N_("row header")
151 N_("scroll bar")
152 N_("scroll pane")
153 N_("separator")
154 N_("slider")
155 N_("split pane")
156 N_("spin button")
157 N_("statusbar")
158 N_("table")
159 N_("table cell")
160 N_("table column header")
161 N_("table row header")
162 N_("tear off menu item")
163 N_("terminal")
164 N_("text")
165 N_("toggle button")
166 N_("tool bar")
167 N_("tool tip")
168 N_("tree")
169 N_("tree table")
170 N_("unknown")
171 N_("viewport")
172 N_("window")
173 N_("header")
174 N_("footer")
175 N_("paragraph")
176 N_("ruler")
177 N_("application")
178 N_("autocomplete")
179 N_("edit bar")
180 N_("embedded component")
181 N_("entry")
182 N_("chart")
183 N_("caption")
184 N_("document frame")
185 N_("heading")
186 N_("page")
187 N_("section")
188 N_("redundant object")
189 N_("form")
190 N_("link")
191 N_("input method window")
192 N_("table row")
193 N_("tree item")
194 N_("document spreadsheet")
195 N_("document presentation")
196 N_("document text")
197 N_("document web")
198 N_("document email")
199 N_("comment")
200 N_("list box")
201 N_("grouping")
202 N_("image map")
203 N_("notification")
204 N_("info bar")
205 #endif /* 0 */
207 static void atk_object_class_init (AtkObjectClass *klass);
208 static void atk_object_init (AtkObject *accessible,
209 AtkObjectClass *klass);
210 static AtkRelationSet* atk_object_real_ref_relation_set
211 (AtkObject *accessible);
212 static void atk_object_real_initialize (AtkObject *accessible,
213 gpointer data);
214 static void atk_object_real_set_property (GObject *object,
215 guint prop_id,
216 const GValue *value,
217 GParamSpec *pspec);
218 static void atk_object_real_get_property (GObject *object,
219 guint prop_id,
220 GValue *value,
221 GParamSpec *pspec);
222 static void atk_object_finalize (GObject *object);
223 static const gchar* atk_object_real_get_name (AtkObject *object);
224 static const gchar* atk_object_real_get_description
225 (AtkObject *object);
226 static AtkObject* atk_object_real_get_parent (AtkObject *object);
227 static AtkRole atk_object_real_get_role (AtkObject *object);
228 static AtkLayer atk_object_real_get_layer (AtkObject *object);
229 static AtkStateSet* atk_object_real_ref_state_set
230 (AtkObject *object);
231 static void atk_object_real_set_name (AtkObject *object,
232 const gchar *name);
233 static void atk_object_real_set_description
234 (AtkObject *object,
235 const gchar *description);
236 static void atk_object_real_set_parent (AtkObject *object,
237 AtkObject *parent);
238 static void atk_object_real_set_role (AtkObject *object,
239 AtkRole role);
240 static guint atk_object_real_connect_property_change_handler
241 (AtkObject *obj,
242 AtkPropertyChangeHandler
243 *handler);
244 static void atk_object_real_remove_property_change_handler
245 (AtkObject *obj,
246 guint handler_id);
247 static void atk_object_notify (GObject *obj,
248 GParamSpec *pspec);
249 static const gchar* atk_object_real_get_object_locale
250 (AtkObject *object);
252 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
254 static gpointer parent_class = NULL;
256 static const gchar* const atk_object_name_property_name = "accessible-name";
257 static const gchar* const atk_object_name_property_description = "accessible-description";
258 static const gchar* const atk_object_name_property_parent = "accessible-parent";
259 static const gchar* const atk_object_name_property_value = "accessible-value";
260 static const gchar* const atk_object_name_property_role = "accessible-role";
261 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
262 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
263 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
264 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
265 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
266 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
267 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
268 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
269 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
270 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
272 #ifdef G_OS_WIN32
274 static HMODULE atk_dll;
276 BOOL WINAPI
277 DllMain (HINSTANCE hinstDLL,
278 DWORD fdwReason,
279 LPVOID lpvReserved)
281 switch (fdwReason)
283 case DLL_PROCESS_ATTACH:
284 atk_dll = (HMODULE) hinstDLL;
285 break;
288 return TRUE;
291 static const char *
292 get_atk_locale_dir (void)
294 static gchar *atk_localedir = NULL;
296 if (!atk_localedir)
298 const gchar *p;
299 gchar *root, *temp;
301 /* ATK_LOCALEDIR might end in either /lib/locale or
302 * /share/locale. Scan for that slash.
304 p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
305 while (*--p != '/')
307 while (*--p != '/')
310 root = g_win32_get_package_installation_directory_of_module (atk_dll);
311 temp = g_build_filename (root, p, NULL);
312 g_free (root);
314 /* atk_localedir is passed to bindtextdomain() which isn't
315 * UTF-8-aware.
317 atk_localedir = g_win32_locale_filename_from_utf8 (temp);
318 g_free (temp);
320 return atk_localedir;
323 #undef ATK_LOCALEDIR
325 #define ATK_LOCALEDIR get_atk_locale_dir()
327 #endif
329 static void
330 gettext_initialization (void)
332 #ifdef ENABLE_NLS
333 static gboolean gettext_initialized = FALSE;
335 if (!gettext_initialized)
337 const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
339 gettext_initialized = TRUE;
340 if (dir == NULL)
341 dir = ATK_LOCALEDIR;
343 bindtextdomain (GETTEXT_PACKAGE, dir);
344 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
345 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
346 #endif
348 #endif
351 static void
352 compact_role_name (gchar *role_name)
354 gchar *p = role_name;
356 while (*p)
358 if (*p == '-')
359 *p = ' ';
360 p++;
364 static void
365 initialize_role_names ()
367 GTypeClass *enum_class;
368 GEnumValue *enum_value;
369 int i;
370 gchar *role_name = NULL;
372 if (role_names)
373 return;
375 role_names = g_ptr_array_new ();
376 enum_class = g_type_class_ref (ATK_TYPE_ROLE);
377 if (!G_IS_ENUM_CLASS(enum_class))
378 return;
380 for (i = 0; i < ATK_ROLE_LAST_DEFINED; i++)
382 enum_value = g_enum_get_value (G_ENUM_CLASS (enum_class), i);
383 role_name = g_strdup (enum_value->value_nick);
384 // We want the role names to be in the format "check button" and not "check-button"
385 compact_role_name (role_name);
386 g_ptr_array_add (role_names, role_name);
389 g_type_class_unref (enum_class);
393 GType
394 atk_object_get_type (void)
396 static GType type = 0;
398 if (!type)
400 static const GTypeInfo typeInfo =
402 sizeof (AtkObjectClass),
403 (GBaseInitFunc) NULL,
404 (GBaseFinalizeFunc) NULL,
405 (GClassInitFunc) atk_object_class_init,
406 (GClassFinalizeFunc) NULL,
407 NULL,
408 sizeof (AtkObject),
410 (GInstanceInitFunc) atk_object_init,
412 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
414 return type;
417 static void
418 atk_object_class_init (AtkObjectClass *klass)
420 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
422 parent_class = g_type_class_peek_parent (klass);
424 gobject_class->set_property = atk_object_real_set_property;
425 gobject_class->get_property = atk_object_real_get_property;
426 gobject_class->finalize = atk_object_finalize;
427 gobject_class->notify = atk_object_notify;
429 klass->get_name = atk_object_real_get_name;
430 klass->get_description = atk_object_real_get_description;
431 klass->get_parent = atk_object_real_get_parent;
432 klass->get_n_children = NULL;
433 klass->ref_child = NULL;
434 klass->get_index_in_parent = NULL;
435 klass->ref_relation_set = atk_object_real_ref_relation_set;
436 klass->get_role = atk_object_real_get_role;
437 klass->get_layer = atk_object_real_get_layer;
438 klass->get_mdi_zorder = NULL;
439 klass->initialize = atk_object_real_initialize;
440 klass->ref_state_set = atk_object_real_ref_state_set;
441 klass->set_name = atk_object_real_set_name;
442 klass->set_description = atk_object_real_set_description;
443 klass->set_parent = atk_object_real_set_parent;
444 klass->set_role = atk_object_real_set_role;
445 klass->connect_property_change_handler =
446 atk_object_real_connect_property_change_handler;
447 klass->remove_property_change_handler =
448 atk_object_real_remove_property_change_handler;
449 klass->get_object_locale = atk_object_real_get_object_locale;
452 * We do not define default signal handlers here
454 klass->children_changed = NULL;
455 klass->focus_event = NULL;
456 klass->property_change = NULL;
457 klass->visible_data_changed = NULL;
458 klass->active_descendant_changed = NULL;
460 gettext_initialization ();
462 g_object_class_install_property (gobject_class,
463 PROP_NAME,
464 g_param_spec_string (atk_object_name_property_name,
465 _("Accessible Name"),
466 _("Object instance\'s name formatted for assistive technology access"),
467 NULL,
468 G_PARAM_READWRITE));
469 g_object_class_install_property (gobject_class,
470 PROP_DESCRIPTION,
471 g_param_spec_string (atk_object_name_property_description,
472 _("Accessible Description"),
473 _("Description of an object, formatted for assistive technology access"),
474 NULL,
475 G_PARAM_READWRITE));
476 g_object_class_install_property (gobject_class,
477 PROP_PARENT,
478 g_param_spec_object (atk_object_name_property_parent,
479 _("Accessible Parent"),
480 _("Is used to notify that the parent has changed"),
481 ATK_TYPE_OBJECT,
482 G_PARAM_READWRITE));
483 g_object_class_install_property (gobject_class,
484 PROP_VALUE,
485 g_param_spec_double (atk_object_name_property_value,
486 _("Accessible Value"),
487 _("Is used to notify that the value has changed"),
488 0.0,
489 G_MAXDOUBLE,
490 0.0,
491 G_PARAM_READWRITE));
492 g_object_class_install_property (gobject_class,
493 PROP_ROLE,
494 g_param_spec_int (atk_object_name_property_role,
495 _("Accessible Role"),
496 _("The accessible role of this object"),
498 G_MAXINT,
499 ATK_ROLE_UNKNOWN,
500 G_PARAM_READWRITE));
501 g_object_class_install_property (gobject_class,
502 PROP_LAYER,
503 g_param_spec_int (atk_object_name_property_component_layer,
504 _("Accessible Layer"),
505 _("The accessible layer of this object"),
507 G_MAXINT,
509 G_PARAM_READABLE));
510 g_object_class_install_property (gobject_class,
511 PROP_MDI_ZORDER,
512 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
513 _("Accessible MDI Value"),
514 _("The accessible MDI value of this object"),
515 G_MININT,
516 G_MAXINT,
517 G_MININT,
518 G_PARAM_READABLE));
519 g_object_class_install_property (gobject_class,
520 PROP_TABLE_CAPTION,
521 g_param_spec_string (atk_object_name_property_table_caption,
522 _("Accessible Table Caption"),
523 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
524 NULL,
525 G_PARAM_READWRITE));
526 g_object_class_install_property (gobject_class,
527 PROP_TABLE_COLUMN_HEADER,
528 g_param_spec_object (atk_object_name_property_table_column_header,
529 _("Accessible Table Column Header"),
530 _("Is used to notify that the table column header has changed"),
531 ATK_TYPE_OBJECT,
532 G_PARAM_READWRITE));
533 g_object_class_install_property (gobject_class,
534 PROP_TABLE_COLUMN_DESCRIPTION,
535 g_param_spec_string (atk_object_name_property_table_column_description,
536 _("Accessible Table Column Description"),
537 _("Is used to notify that the table column description has changed"),
538 NULL,
539 G_PARAM_READWRITE));
540 g_object_class_install_property (gobject_class,
541 PROP_TABLE_ROW_HEADER,
542 g_param_spec_object (atk_object_name_property_table_row_header,
543 _("Accessible Table Row Header"),
544 _("Is used to notify that the table row header has changed"),
545 ATK_TYPE_OBJECT,
546 G_PARAM_READWRITE));
547 g_object_class_install_property (gobject_class,
548 PROP_TABLE_ROW_DESCRIPTION,
549 g_param_spec_string (atk_object_name_property_table_row_description,
550 _("Accessible Table Row Description"),
551 _("Is used to notify that the table row description has changed"),
552 NULL,
553 G_PARAM_READWRITE));
554 g_object_class_install_property (gobject_class,
555 PROP_TABLE_SUMMARY,
556 g_param_spec_object (atk_object_name_property_table_summary,
557 _("Accessible Table Summary"),
558 _("Is used to notify that the table summary has changed"),
559 ATK_TYPE_OBJECT,
560 G_PARAM_READWRITE));
561 g_object_class_install_property (gobject_class,
562 PROP_TABLE_CAPTION_OBJECT,
563 g_param_spec_object (atk_object_name_property_table_caption_object,
564 _("Accessible Table Caption Object"),
565 _("Is used to notify that the table caption has changed"),
566 ATK_TYPE_OBJECT,
567 G_PARAM_READWRITE));
568 g_object_class_install_property (gobject_class,
569 PROP_HYPERTEXT_NUM_LINKS,
570 g_param_spec_int (atk_object_name_property_hypertext_num_links,
571 _("Number of Accessible Hypertext Links"),
572 _("The number of links which the current AtkHypertext has"),
574 G_MAXINT,
576 G_PARAM_READABLE));
579 * AtkObject::children-changed:
580 * @atkobject: the object which received the signal.
581 * @arg1: The index of the added or removed child
582 * @arg2: A gpointer to the child AtkObject which was added or removed
584 * The signal "children-changed" is emitted when a child is added or
585 * removed form an object. It supports two details: "add" and
586 * "remove"
588 atk_object_signals[CHILDREN_CHANGED] =
589 g_signal_new ("children_changed",
590 G_TYPE_FROM_CLASS (klass),
591 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
592 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
593 NULL, NULL,
594 g_cclosure_marshal_VOID__UINT_POINTER,
595 G_TYPE_NONE,
596 2, G_TYPE_UINT, G_TYPE_POINTER);
599 * AtkObject::focus-event:
600 * @atkobject: the object which received the signal
601 * @arg1: a boolean value which indicates whether the object gained
602 * or lost focus.
604 * The signal "focus-event" is emitted when an object gained or lost
605 * focus.
607 * Deprecated: Since 2.9.4. Use #AtkObject::state-change signal instead.
609 atk_object_signals[FOCUS_EVENT] =
610 g_signal_new ("focus_event",
611 G_TYPE_FROM_CLASS (klass),
612 G_SIGNAL_RUN_LAST,
613 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
614 NULL, NULL,
615 g_cclosure_marshal_VOID__BOOLEAN,
616 G_TYPE_NONE,
617 1, G_TYPE_BOOLEAN);
619 * AtkObject::property-change:
620 * @atkobject: the object which received the signal.
621 * @arg1: The new value of the property which changed.
623 * The signal "property-change" is emitted when an object's property
624 * value changes. The detail identifies the name of the property
625 * whose value has changed.
627 atk_object_signals[PROPERTY_CHANGE] =
628 g_signal_new ("property_change",
629 G_TYPE_FROM_CLASS (klass),
630 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
631 G_STRUCT_OFFSET (AtkObjectClass, property_change),
632 (GSignalAccumulator) NULL, NULL,
633 g_cclosure_marshal_VOID__POINTER,
634 G_TYPE_NONE, 1,
635 G_TYPE_POINTER);
638 * AtkObject::state-change:
639 * @atkobject: the object which received the signal.
640 * @arg1: The name of the state which has changed
641 * @arg2: A boolean which indicates whether the state has been set or unset.
643 * The "state-change" signal is emitted when an object's state
644 * changes. The detail value identifies the state type which has
645 * changed.
647 atk_object_signals[STATE_CHANGE] =
648 g_signal_new ("state_change",
649 G_TYPE_FROM_CLASS (klass),
650 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
651 G_STRUCT_OFFSET (AtkObjectClass, state_change),
652 (GSignalAccumulator) NULL, NULL,
653 atk_marshal_VOID__STRING_BOOLEAN,
654 G_TYPE_NONE, 2,
655 G_TYPE_STRING,
656 G_TYPE_BOOLEAN);
659 * AtkObject::visible-data-changed:
660 * @atkobject: the object which received the signal.
662 * The "visible-data-changed" signal is emitted when the visual
663 * appearance of the object changed.
665 atk_object_signals[VISIBLE_DATA_CHANGED] =
666 g_signal_new ("visible_data_changed",
667 G_TYPE_FROM_CLASS (klass),
668 G_SIGNAL_RUN_LAST,
669 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
670 (GSignalAccumulator) NULL, NULL,
671 g_cclosure_marshal_VOID__VOID,
672 G_TYPE_NONE, 0);
675 * AtkObject::active-descendant-changed:
676 * @atkobject: the object which received the signal.
677 * @arg1: the newly focused object.
679 * The "active-descendant-changed" signal is emitted by an object
680 * which has the state ATK_STATE_MANAGES_DESCENDANTS when the focus
681 * object in the object changes. For instance, a table will emit the
682 * signal when the cell in the table which has focus changes.
684 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
685 g_signal_new ("active_descendant_changed",
686 G_TYPE_FROM_CLASS (klass),
687 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
688 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
689 NULL, NULL,
690 g_cclosure_marshal_VOID__POINTER,
691 G_TYPE_NONE,
692 1, G_TYPE_POINTER);
695 static void
696 atk_object_init (AtkObject *accessible,
697 AtkObjectClass *klass)
699 accessible->name = NULL;
700 accessible->description = NULL;
701 accessible->accessible_parent = NULL;
702 accessible->relation_set = atk_relation_set_new();
703 accessible->role = ATK_ROLE_UNKNOWN;
706 GType
707 atk_implementor_get_type (void)
709 static GType type = 0;
711 if (!type)
713 static const GTypeInfo typeInfo =
715 sizeof (AtkImplementorIface),
716 (GBaseInitFunc) NULL,
717 (GBaseFinalizeFunc) NULL,
720 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
723 return type;
727 * atk_object_get_name:
728 * @accessible: an #AtkObject
730 * Gets the accessible name of the accessible.
732 * Returns: a character string representing the accessible name of the object.
734 const gchar*
735 atk_object_get_name (AtkObject *accessible)
737 AtkObjectClass *klass;
739 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
741 klass = ATK_OBJECT_GET_CLASS (accessible);
742 if (klass->get_name)
743 return (klass->get_name) (accessible);
744 else
745 return NULL;
749 * atk_object_get_description:
750 * @accessible: an #AtkObject
752 * Gets the accessible description of the accessible.
754 * Returns: a character string representing the accessible description
755 * of the accessible.
758 const gchar*
759 atk_object_get_description (AtkObject *accessible)
761 AtkObjectClass *klass;
763 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
765 klass = ATK_OBJECT_GET_CLASS (accessible);
766 if (klass->get_description)
767 return (klass->get_description) (accessible);
768 else
769 return NULL;
773 * atk_object_get_parent:
774 * @accessible: an #AtkObject
776 * Gets the accessible parent of the accessible.
778 * Returns: (transfer none): a #AtkObject representing the accessible parent
779 * of the accessible
781 AtkObject*
782 atk_object_get_parent (AtkObject *accessible)
784 AtkObjectClass *klass;
786 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
788 klass = ATK_OBJECT_GET_CLASS (accessible);
789 if (klass->get_parent)
790 return (klass->get_parent) (accessible);
791 else
792 return NULL;
796 * atk_object_get_n_accessible_children:
797 * @accessible: an #AtkObject
799 * Gets the number of accessible children of the accessible.
801 * Returns: an integer representing the number of accessible children
802 * of the accessible.
804 gint
805 atk_object_get_n_accessible_children (AtkObject *accessible)
807 AtkObjectClass *klass;
809 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
811 klass = ATK_OBJECT_GET_CLASS (accessible);
812 if (klass->get_n_children)
813 return (klass->get_n_children) (accessible);
814 else
815 return 0;
819 * atk_object_ref_accessible_child:
820 * @accessible: an #AtkObject
821 * @i: a gint representing the position of the child, starting from 0
823 * Gets a reference to the specified accessible child of the object.
824 * The accessible children are 0-based so the first accessible child is
825 * at index 0, the second at index 1 and so on.
827 * Returns: (transfer full): an #AtkObject representing the specified
828 * accessible child of the accessible.
830 AtkObject*
831 atk_object_ref_accessible_child (AtkObject *accessible,
832 gint i)
834 AtkObjectClass *klass;
836 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
838 klass = ATK_OBJECT_GET_CLASS (accessible);
839 if (klass->ref_child)
840 return (klass->ref_child) (accessible, i);
841 else
842 return NULL;
846 * atk_object_ref_relation_set:
847 * @accessible: an #AtkObject
849 * Gets the #AtkRelationSet associated with the object.
851 * Returns: (transfer full): an #AtkRelationSet representing the relation set
852 * of the object.
854 AtkRelationSet*
855 atk_object_ref_relation_set (AtkObject *accessible)
857 AtkObjectClass *klass;
859 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
861 klass = ATK_OBJECT_GET_CLASS (accessible);
862 if (klass->ref_relation_set)
863 return (klass->ref_relation_set) (accessible);
864 else
865 return NULL;
869 * atk_role_register:
870 * @name: a character string describing the new role.
872 * Registers the role specified by @name.
874 * Returns: an #AtkRole for the new role.
876 AtkRole
877 atk_role_register (const gchar *name)
879 if (!role_names)
880 initialize_role_names ();
882 g_ptr_array_add (role_names, g_strdup (name));
883 return role_names->len - 1;
887 * atk_object_get_role:
888 * @accessible: an #AtkObject
890 * Gets the role of the accessible.
892 * Returns: an #AtkRole which is the role of the accessible
894 AtkRole
895 atk_object_get_role (AtkObject *accessible)
897 AtkObjectClass *klass;
899 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
901 klass = ATK_OBJECT_GET_CLASS (accessible);
902 if (klass->get_role)
903 return (klass->get_role) (accessible);
904 else
905 return ATK_ROLE_UNKNOWN;
909 * atk_object_get_layer:
910 * @accessible: an #AtkObject
912 * Gets the layer of the accessible.
914 * Deprecated: Use atk_component_get_layer instead.
916 * Returns: an #AtkLayer which is the layer of the accessible
918 AtkLayer
919 atk_object_get_layer (AtkObject *accessible)
921 AtkObjectClass *klass;
923 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
925 klass = ATK_OBJECT_GET_CLASS (accessible);
926 if (klass->get_layer)
927 return (klass->get_layer) (accessible);
928 else
929 return ATK_LAYER_INVALID;
933 * atk_object_get_mdi_zorder:
934 * @accessible: an #AtkObject
936 * Gets the zorder of the accessible. The value G_MININT will be returned
937 * if the layer of the accessible is not ATK_LAYER_MDI.
939 * Deprecated: Use atk_component_get_mdi_zorder instead.
941 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
942 * which the component is shown in relation to other components in the same
943 * container.
946 gint
947 atk_object_get_mdi_zorder (AtkObject *accessible)
949 AtkObjectClass *klass;
951 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
953 klass = ATK_OBJECT_GET_CLASS (accessible);
954 if (klass->get_mdi_zorder)
955 return (klass->get_mdi_zorder) (accessible);
956 else
957 return G_MININT;
961 * atk_object_ref_state_set:
962 * @accessible: an #AtkObject
964 * Gets a reference to the state set of the accessible; the caller must
965 * unreference it when it is no longer needed.
967 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
968 * set of the accessible
970 AtkStateSet*
971 atk_object_ref_state_set (AtkObject *accessible)
973 AtkObjectClass *klass;
975 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
977 klass = ATK_OBJECT_GET_CLASS (accessible);
978 if (klass->ref_state_set)
979 return (klass->ref_state_set) (accessible);
980 else
981 return NULL;
985 * atk_object_get_index_in_parent:
986 * @accessible: an #AtkObject
988 * Gets the 0-based index of this accessible in its parent; returns -1 if the
989 * accessible does not have an accessible parent.
991 * Returns: an integer which is the index of the accessible in its parent
993 gint
994 atk_object_get_index_in_parent (AtkObject *accessible)
996 AtkObjectClass *klass;
998 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
1000 klass = ATK_OBJECT_GET_CLASS (accessible);
1001 if (klass->get_index_in_parent)
1002 return (klass->get_index_in_parent) (accessible);
1003 else
1004 return -1;
1008 * atk_object_set_name:
1009 * @accessible: an #AtkObject
1010 * @name: a character string to be set as the accessible name
1012 * Sets the accessible name of the accessible. You can't set the name
1013 * to NULL. This is reserved for the initial value. In this aspect
1014 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
1015 * a empty value you can use "".
1017 void
1018 atk_object_set_name (AtkObject *accessible,
1019 const gchar *name)
1021 AtkObjectClass *klass;
1022 gboolean notify = FALSE;
1024 g_return_if_fail (ATK_IS_OBJECT (accessible));
1025 g_return_if_fail (name != NULL);
1027 klass = ATK_OBJECT_GET_CLASS (accessible);
1028 if (klass->set_name)
1030 /* Do not notify for initial name setting. See bug 665870 */
1031 notify = (accessible->name != NULL);
1033 (klass->set_name) (accessible, name);
1034 if (notify)
1035 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1040 * atk_object_set_description:
1041 * @accessible: an #AtkObject
1042 * @description: a character string to be set as the accessible description
1044 * Sets the accessible description of the accessible. You can't set
1045 * the description to NULL. This is reserved for the initial value. In
1046 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
1047 * the name to a empty value you can use "".
1049 void
1050 atk_object_set_description (AtkObject *accessible,
1051 const gchar *description)
1053 AtkObjectClass *klass;
1054 gboolean notify = FALSE;
1056 g_return_if_fail (ATK_IS_OBJECT (accessible));
1057 g_return_if_fail (description != NULL);
1059 klass = ATK_OBJECT_GET_CLASS (accessible);
1060 if (klass->set_description)
1062 /* Do not notify for initial name setting. See bug 665870 */
1063 notify = (accessible->description != NULL);
1065 (klass->set_description) (accessible, description);
1066 if (notify)
1067 g_object_notify (G_OBJECT (accessible),
1068 atk_object_name_property_description);
1073 * atk_object_set_parent:
1074 * @accessible: an #AtkObject
1075 * @parent: an #AtkObject to be set as the accessible parent
1077 * Sets the accessible parent of the accessible.
1079 void
1080 atk_object_set_parent (AtkObject *accessible,
1081 AtkObject *parent)
1083 AtkObjectClass *klass;
1085 g_return_if_fail (ATK_IS_OBJECT (accessible));
1087 klass = ATK_OBJECT_GET_CLASS (accessible);
1088 if (klass->set_parent)
1090 (klass->set_parent) (accessible, parent);
1091 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1096 * atk_object_set_role:
1097 * @accessible: an #AtkObject
1098 * @role: an #AtkRole to be set as the role
1100 * Sets the role of the accessible.
1102 void
1103 atk_object_set_role (AtkObject *accessible,
1104 AtkRole role)
1106 AtkObjectClass *klass;
1107 AtkRole old_role;
1109 g_return_if_fail (ATK_IS_OBJECT (accessible));
1111 klass = ATK_OBJECT_GET_CLASS (accessible);
1112 if (klass->set_role)
1114 old_role = atk_object_get_role (accessible);
1115 if (old_role != role)
1117 (klass->set_role) (accessible, role);
1118 if (old_role != ATK_ROLE_UNKNOWN)
1119 /* Do not notify for initial role setting */
1120 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1126 * atk_object_connect_property_change_handler:
1127 * @accessible: an #AtkObject
1128 * @handler: a function to be called when a property changes its value
1130 * Specifies a function to be called when a property changes value.
1132 * Returns: a #guint which is the handler id used in
1133 * atk_object_remove_property_change_handler()
1135 guint
1136 atk_object_connect_property_change_handler (AtkObject *accessible,
1137 AtkPropertyChangeHandler *handler)
1139 AtkObjectClass *klass;
1141 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1142 g_return_val_if_fail ((handler != NULL), 0);
1144 klass = ATK_OBJECT_GET_CLASS (accessible);
1145 if (klass->connect_property_change_handler)
1146 return (klass->connect_property_change_handler) (accessible, handler);
1147 else
1148 return 0;
1152 * atk_object_remove_property_change_handler:
1153 * @accessible: an #AtkObject
1154 * @handler_id: a guint which identifies the handler to be removed.
1156 * Removes a property change handler.
1158 void
1159 atk_object_remove_property_change_handler (AtkObject *accessible,
1160 guint handler_id)
1162 AtkObjectClass *klass;
1164 g_return_if_fail (ATK_IS_OBJECT (accessible));
1166 klass = ATK_OBJECT_GET_CLASS (accessible);
1167 if (klass->remove_property_change_handler)
1168 (klass->remove_property_change_handler) (accessible, handler_id);
1172 * atk_object_notify_state_change:
1173 * @accessible: an #AtkObject
1174 * @state: an #AtkState whose state is changed
1175 * @value: a gboolean which indicates whether the state is being set on or off
1177 * Emits a state-change signal for the specified state.
1179 void
1180 atk_object_notify_state_change (AtkObject *accessible,
1181 AtkState state,
1182 gboolean value)
1184 const gchar* name;
1186 g_return_if_fail (ATK_IS_OBJECT (accessible));
1188 name = atk_state_type_get_name (state);
1189 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1190 g_quark_from_string (name),
1191 name, value, NULL);
1195 * atk_implementor_ref_accessible:
1196 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1197 * if a non-null return value is required.
1199 * Gets a reference to an object's #AtkObject implementation, if
1200 * the object implements #AtkObjectIface
1202 * Returns: (transfer full): a reference to an object's #AtkObject
1203 * implementation
1205 AtkObject *
1206 atk_implementor_ref_accessible (AtkImplementor *implementor)
1208 AtkImplementorIface *iface;
1209 AtkObject *accessible = NULL;
1211 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1213 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1215 if (iface != NULL)
1216 accessible = iface->ref_accessible (implementor);
1218 g_return_val_if_fail ((accessible != NULL), NULL);
1220 return accessible;
1225 * atk_object_get_attributes:
1226 * @accessible: An #AtkObject.
1228 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1229 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1230 * as distinct from strongly-typed object data available via other get/set methods.
1231 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1233 * Since: 1.12
1235 * Returns: (transfer full): an #AtkAttributeSet consisting of all
1236 * explicit properties/annotations applied to the object, or an empty
1237 * set if the object has no name-value pair attributes assigned to
1238 * it. This #atkattributeset should be freed by a call to
1239 * atk_attribute_set_free().
1241 AtkAttributeSet *
1242 atk_object_get_attributes (AtkObject *accessible)
1244 AtkObjectClass *klass;
1246 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1248 klass = ATK_OBJECT_GET_CLASS (accessible);
1249 if (klass->get_attributes)
1250 return (klass->get_attributes) (accessible);
1251 else
1252 return NULL;
1256 static AtkRelationSet*
1257 atk_object_real_ref_relation_set (AtkObject *accessible)
1259 g_return_val_if_fail (accessible->relation_set, NULL);
1260 g_object_ref (accessible->relation_set);
1262 return accessible->relation_set;
1265 static void
1266 atk_object_real_set_property (GObject *object,
1267 guint prop_id,
1268 const GValue *value,
1269 GParamSpec *pspec)
1271 AtkObject *accessible;
1273 accessible = ATK_OBJECT (object);
1275 switch (prop_id)
1277 case PROP_NAME:
1278 atk_object_set_name (accessible, g_value_get_string (value));
1279 break;
1280 case PROP_DESCRIPTION:
1281 atk_object_set_description (accessible, g_value_get_string (value));
1282 break;
1283 case PROP_ROLE:
1284 atk_object_set_role (accessible, g_value_get_int (value));
1285 break;
1286 case PROP_PARENT:
1287 atk_object_set_parent (accessible, g_value_get_object (value));
1288 break;
1289 case PROP_VALUE:
1290 if (ATK_IS_VALUE (accessible))
1291 atk_value_set_current_value (ATK_VALUE (accessible), value);
1292 break;
1293 case PROP_TABLE_SUMMARY:
1294 if (ATK_IS_TABLE (accessible))
1295 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1296 break;
1297 case PROP_TABLE_CAPTION_OBJECT:
1298 if (ATK_IS_TABLE (accessible))
1299 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1300 break;
1301 default:
1302 break;
1306 static void
1307 atk_object_real_get_property (GObject *object,
1308 guint prop_id,
1309 GValue *value,
1310 GParamSpec *pspec)
1312 AtkObject *accessible;
1314 accessible = ATK_OBJECT (object);
1316 switch (prop_id)
1318 case PROP_NAME:
1319 g_value_set_string (value, atk_object_get_name (accessible));
1320 break;
1321 case PROP_DESCRIPTION:
1322 g_value_set_string (value, atk_object_get_description (accessible));
1323 break;
1324 case PROP_ROLE:
1325 g_value_set_int (value, atk_object_get_role (accessible));
1326 break;
1327 case PROP_LAYER:
1328 if (ATK_IS_COMPONENT (accessible))
1329 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1330 break;
1331 case PROP_MDI_ZORDER:
1332 if (ATK_IS_COMPONENT (accessible))
1333 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1334 break;
1335 case PROP_PARENT:
1336 g_value_set_object (value, atk_object_get_parent (accessible));
1337 break;
1338 case PROP_VALUE:
1339 if (ATK_IS_VALUE (accessible))
1340 atk_value_get_current_value (ATK_VALUE (accessible), value);
1341 break;
1342 case PROP_TABLE_SUMMARY:
1343 if (ATK_IS_TABLE (accessible))
1344 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1345 break;
1346 case PROP_TABLE_CAPTION_OBJECT:
1347 if (ATK_IS_TABLE (accessible))
1348 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1349 break;
1350 case PROP_HYPERTEXT_NUM_LINKS:
1351 if (ATK_IS_HYPERTEXT (accessible))
1352 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1353 break;
1354 default:
1355 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1356 break;
1360 static void
1361 atk_object_finalize (GObject *object)
1363 AtkObject *accessible;
1365 g_return_if_fail (ATK_IS_OBJECT (object));
1367 accessible = ATK_OBJECT (object);
1369 g_free (accessible->name);
1370 g_free (accessible->description);
1373 * Free memory allocated for relation set if it have been allocated.
1375 if (accessible->relation_set)
1376 g_object_unref (accessible->relation_set);
1378 if (accessible->accessible_parent)
1379 g_object_unref (accessible->accessible_parent);
1381 G_OBJECT_CLASS (parent_class)->finalize (object);
1384 static const gchar*
1385 atk_object_real_get_name (AtkObject *object)
1387 return object->name;
1390 static const gchar*
1391 atk_object_real_get_description (AtkObject *object)
1393 return object->description;
1396 static AtkObject*
1397 atk_object_real_get_parent (AtkObject *object)
1399 return object->accessible_parent;
1402 static AtkRole
1403 atk_object_real_get_role (AtkObject *object)
1405 return object->role;
1408 static AtkLayer
1409 atk_object_real_get_layer (AtkObject *object)
1411 return object->layer;
1414 static AtkStateSet*
1415 atk_object_real_ref_state_set (AtkObject *accessible)
1417 AtkStateSet *state_set;
1418 AtkObject *focus_object;
1420 state_set = atk_state_set_new ();
1422 focus_object = atk_get_focus_object ();
1423 if (focus_object == accessible)
1424 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1426 return state_set;
1429 static void
1430 atk_object_real_set_name (AtkObject *object,
1431 const gchar *name)
1433 g_free (object->name);
1434 object->name = g_strdup (name);
1437 static void
1438 atk_object_real_set_description (AtkObject *object,
1439 const gchar *description)
1441 g_free (object->description);
1442 object->description = g_strdup (description);
1445 static void
1446 atk_object_real_set_parent (AtkObject *object,
1447 AtkObject *parent)
1449 if (object->accessible_parent)
1450 g_object_unref (object->accessible_parent);
1452 object->accessible_parent = parent;
1453 if (object->accessible_parent)
1454 g_object_ref (object->accessible_parent);
1457 static void
1458 atk_object_real_set_role (AtkObject *object,
1459 AtkRole role)
1461 object->role = role;
1464 static guint
1465 atk_object_real_connect_property_change_handler (AtkObject *obj,
1466 AtkPropertyChangeHandler *handler)
1468 return g_signal_connect_closure_by_id (obj,
1469 atk_object_signals[PROPERTY_CHANGE],
1471 g_cclosure_new (
1472 G_CALLBACK (handler), NULL,
1473 (GClosureNotify) NULL),
1474 FALSE);
1477 static void
1478 atk_object_real_remove_property_change_handler (AtkObject *obj,
1479 guint handler_id)
1481 g_signal_handler_disconnect (obj, handler_id);
1485 * atk_object_initialize:
1486 * @accessible: a #AtkObject
1487 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1489 * This function is called when implementing subclasses of #AtkObject.
1490 * It does initialization required for the new object. It is intended
1491 * that this function should called only in the ..._new() functions used
1492 * to create an instance of a subclass of #AtkObject
1494 void
1495 atk_object_initialize (AtkObject *accessible,
1496 gpointer data)
1498 AtkObjectClass *klass;
1500 g_return_if_fail (ATK_IS_OBJECT (accessible));
1502 klass = ATK_OBJECT_GET_CLASS (accessible);
1503 if (klass->initialize)
1504 klass->initialize (accessible, data);
1508 * This function is a signal handler for notify signal which gets emitted
1509 * when a property changes value.
1511 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1512 * signal which causes the user specified AtkPropertyChangeHandler
1513 * to be called.
1515 static void
1516 atk_object_notify (GObject *obj,
1517 GParamSpec *pspec)
1519 AtkPropertyValues values = { NULL, };
1521 g_value_init (&values.new_value, pspec->value_type);
1522 g_object_get_property (obj, pspec->name, &values.new_value);
1523 values.property_name = pspec->name;
1524 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1525 g_quark_from_string (pspec->name),
1526 &values, NULL);
1527 g_value_unset (&values.new_value);
1531 * atk_role_get_name:
1532 * @role: The #AtkRole whose name is required
1534 * Gets the description string describing the #AtkRole @role.
1536 * Returns: the string describing the AtkRole
1538 const gchar*
1539 atk_role_get_name (AtkRole role)
1541 g_return_val_if_fail (role >= 0, NULL);
1543 if (!role_names)
1544 initialize_role_names ();
1546 if (role < role_names->len)
1547 return g_ptr_array_index (role_names, role);
1549 return NULL;
1553 * atk_role_get_localized_name:
1554 * @role: The #AtkRole whose localized name is required
1556 * Gets the localized description string describing the #AtkRole @role.
1558 * Returns: the localized string describing the AtkRole
1560 const gchar*
1561 atk_role_get_localized_name (AtkRole role)
1563 gettext_initialization ();
1565 return dgettext (GETTEXT_PACKAGE, atk_role_get_name (role));
1568 static const gchar*
1569 atk_object_real_get_object_locale (AtkObject *object)
1571 return setlocale (LC_MESSAGES, NULL);
1575 * atk_object_get_object_locale:
1576 * @accessible: an #AtkObject
1578 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
1579 * of @accessible.
1581 * Since: 2.7.90
1583 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
1584 * locale of @accessible.
1586 const gchar*
1587 atk_object_get_object_locale (AtkObject *accessible)
1589 AtkObjectClass *klass;
1591 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1593 klass = ATK_OBJECT_GET_CLASS (accessible);
1594 if (klass->get_object_locale)
1595 return (klass->get_object_locale) (accessible);
1596 else
1597 return NULL;
1602 * atk_role_for_name:
1603 * @name: a string which is the (non-localized) name of an ATK role.
1605 * Get the #AtkRole type corresponding to a rolew name.
1607 * Returns: the #AtkRole enumerated type corresponding to the specified name,
1608 * or #ATK_ROLE_INVALID if no matching role is found.
1610 AtkRole
1611 atk_role_for_name (const gchar *name)
1613 AtkRole role = ATK_ROLE_INVALID;
1614 gint i;
1616 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1618 if (!role_names)
1619 initialize_role_names ();
1621 for (i = 0; i < role_names->len; i++)
1623 gchar *role_name = (gchar *)g_ptr_array_index (role_names, i);
1625 g_return_val_if_fail (role_name, ATK_ROLE_INVALID);
1627 if (strcmp (name, role_name) == 0)
1629 role = i;
1630 break;
1634 return role;
1638 * atk_object_add_relationship:
1639 * @object: The #AtkObject to which an AtkRelation is to be added.
1640 * @relationship: The #AtkRelationType of the relation
1641 * @target: The #AtkObject which is to be the target of the relation.
1643 * Adds a relationship of the specified type with the specified target.
1645 * Returns: TRUE if the relationship is added.
1647 gboolean
1648 atk_object_add_relationship (AtkObject *object,
1649 AtkRelationType relationship,
1650 AtkObject *target)
1652 AtkObject *array[1];
1653 AtkRelation *relation;
1655 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1656 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1658 if (atk_relation_set_contains_target (object->relation_set,
1659 relationship, target))
1660 return FALSE;
1662 array[0] = target;
1663 relation = atk_relation_new (array, 1, relationship);
1664 atk_relation_set_add (object->relation_set, relation);
1665 g_object_unref (relation);
1667 return TRUE;
1671 * atk_object_remove_relationship:
1672 * @object: The #AtkObject from which an AtkRelation is to be removed.
1673 * @relationship: The #AtkRelationType of the relation
1674 * @target: The #AtkObject which is the target of the relation to be removed.
1676 * Removes a relationship of the specified type with the specified target.
1678 * Returns: TRUE if the relationship is removed.
1680 gboolean
1681 atk_object_remove_relationship (AtkObject *object,
1682 AtkRelationType relationship,
1683 AtkObject *target)
1685 gboolean ret = FALSE;
1686 AtkRelation *relation;
1687 GPtrArray *array;
1689 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1690 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1692 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1694 if (relation)
1696 ret = atk_relation_remove_target (relation, target);
1697 array = atk_relation_get_target (relation);
1698 if (!array || array->len == 0)
1699 atk_relation_set_remove (object->relation_set, relation);
1701 return ret;
1704 static void
1705 atk_object_real_initialize (AtkObject *accessible,
1706 gpointer data)
1708 return;