win32: remove specific win32 build configuration files
[atk.git] / atk / atkobject.c
blob9dbd44389073073ae3caaeeb5fd7a722456bdfd6
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 "config.h"
22 #include <string.h>
23 #include <locale.h>
25 #include <glib-object.h>
26 #include <glib/gi18n-lib.h>
28 #include "atk.h"
29 #include "atkmarshal.h"
30 #include "atkprivate.h"
32 /**
33 * SECTION:atkobject
34 * @Short_description: The base object class for the Accessibility Toolkit API.
35 * @Title:AtkObject
37 * This class is the primary class for accessibility support via the
38 * Accessibility ToolKit (ATK). Objects which are instances of
39 * #AtkObject (or instances of AtkObject-derived types) are queried
40 * for properties which relate basic (and generic) properties of a UI
41 * component such as name and description. Instances of #AtkObject
42 * may also be queried as to whether they implement other ATK
43 * interfaces (e.g. #AtkAction, #AtkComponent, etc.), as appropriate
44 * to the role which a given UI component plays in a user interface.
46 * All UI components in an application which provide useful
47 * information or services to the user must provide corresponding
48 * #AtkObject instances on request (in GTK+, for instance, usually on
49 * a call to #gtk_widget_get_accessible ()), either via ATK support
50 * built into the toolkit for the widget class or ancestor class, or
51 * in the case of custom widgets, if the inherited #AtkObject
52 * implementation is insufficient, via instances of a new #AtkObject
53 * subclass.
55 * See also: #AtkObjectFactory, #AtkRegistry. (GTK+ users see also
56 * #GtkAccessible).
60 static GPtrArray *role_names = NULL;
62 enum
64 PROP_0, /* gobject convention */
66 PROP_NAME,
67 PROP_DESCRIPTION,
68 PROP_PARENT, /* ancestry has changed */
69 PROP_VALUE,
70 PROP_ROLE,
71 PROP_LAYER,
72 PROP_MDI_ZORDER,
73 PROP_TABLE_CAPTION,
74 PROP_TABLE_COLUMN_DESCRIPTION,
75 PROP_TABLE_COLUMN_HEADER,
76 PROP_TABLE_ROW_DESCRIPTION,
77 PROP_TABLE_ROW_HEADER,
78 PROP_TABLE_SUMMARY,
79 PROP_TABLE_CAPTION_OBJECT,
80 PROP_HYPERTEXT_NUM_LINKS,
81 PROP_LAST /* gobject convention */
84 enum {
85 CHILDREN_CHANGED,
86 FOCUS_EVENT,
87 PROPERTY_CHANGE,
88 STATE_CHANGE,
89 VISIBLE_DATA_CHANGED,
90 ACTIVE_DESCENDANT_CHANGED,
92 LAST_SIGNAL
95 /* These are listed here for extraction by intltool */
96 #if 0
97 N_("invalid")
98 N_("accelerator label")
99 N_("alert")
100 N_("animation")
101 N_("arrow")
102 N_("calendar")
103 N_("canvas")
104 N_("check box")
105 N_("check menu item")
106 N_("color chooser")
107 N_("column header")
108 N_("combo box")
109 N_("dateeditor")
110 N_("desktop icon")
111 N_("desktop frame")
112 N_("dial")
113 N_("dialog")
114 N_("directory pane")
115 N_("drawing area")
116 N_("file chooser")
117 N_("filler")
118 /* I know it looks wrong but that is what Java returns */
119 N_("fontchooser")
120 N_("frame")
121 N_("glass pane")
122 N_("html container")
123 N_("icon")
124 N_("image")
125 N_("internal frame")
126 N_("label")
127 N_("layered pane")
128 N_("list")
129 N_("list item")
130 N_("menu")
131 N_("menu bar")
132 N_("menu item")
133 N_("option pane")
134 N_("page tab")
135 N_("page tab list")
136 N_("panel")
137 N_("password text")
138 N_("popup menu")
139 N_("progress bar")
140 N_("push button")
141 N_("radio button")
142 N_("radio menu item")
143 N_("root pane")
144 N_("row header")
145 N_("scroll bar")
146 N_("scroll pane")
147 N_("separator")
148 N_("slider")
149 N_("split pane")
150 N_("spin button")
151 N_("statusbar")
152 N_("table")
153 N_("table cell")
154 N_("table column header")
155 N_("table row header")
156 N_("tear off menu item")
157 N_("terminal")
158 N_("text")
159 N_("toggle button")
160 N_("tool bar")
161 N_("tool tip")
162 N_("tree")
163 N_("tree table")
164 N_("unknown")
165 N_("viewport")
166 N_("window")
167 N_("header")
168 N_("footer")
169 N_("paragraph")
170 N_("ruler")
171 N_("application")
172 N_("autocomplete")
173 N_("edit bar")
174 N_("embedded component")
175 N_("entry")
176 N_("chart")
177 N_("caption")
178 N_("document frame")
179 N_("heading")
180 N_("page")
181 N_("section")
182 N_("redundant object")
183 N_("form")
184 N_("link")
185 N_("input method window")
186 N_("table row")
187 N_("tree item")
188 N_("document spreadsheet")
189 N_("document presentation")
190 N_("document text")
191 N_("document web")
192 N_("document email")
193 N_("comment")
194 N_("list box")
195 N_("grouping")
196 N_("image map")
197 N_("notification")
198 N_("info bar")
199 N_("level bar")
200 N_("title bar")
201 N_("block quote")
202 N_("audio")
203 N_("video")
204 N_("definition")
205 N_("article")
206 N_("landmark")
207 N_("log")
208 N_("marquee")
209 N_("math")
210 N_("rating")
211 N_("timer")
212 N_("description list")
213 N_("description term")
214 N_("description value")
215 #endif /* 0 */
217 static void atk_object_class_init (AtkObjectClass *klass);
218 static void atk_object_init (AtkObject *accessible,
219 AtkObjectClass *klass);
220 static AtkRelationSet* atk_object_real_ref_relation_set
221 (AtkObject *accessible);
222 static void atk_object_real_initialize (AtkObject *accessible,
223 gpointer data);
224 static void atk_object_real_set_property (GObject *object,
225 guint prop_id,
226 const GValue *value,
227 GParamSpec *pspec);
228 static void atk_object_real_get_property (GObject *object,
229 guint prop_id,
230 GValue *value,
231 GParamSpec *pspec);
232 static void atk_object_finalize (GObject *object);
233 static const gchar* atk_object_real_get_name (AtkObject *object);
234 static const gchar* atk_object_real_get_description
235 (AtkObject *object);
236 static AtkObject* atk_object_real_get_parent (AtkObject *object);
237 static AtkRole atk_object_real_get_role (AtkObject *object);
238 static AtkLayer atk_object_real_get_layer (AtkObject *object);
239 static AtkStateSet* atk_object_real_ref_state_set
240 (AtkObject *object);
241 static void atk_object_real_set_name (AtkObject *object,
242 const gchar *name);
243 static void atk_object_real_set_description
244 (AtkObject *object,
245 const gchar *description);
246 static void atk_object_real_set_parent (AtkObject *object,
247 AtkObject *parent);
248 static void atk_object_real_set_role (AtkObject *object,
249 AtkRole role);
250 static void atk_object_notify (GObject *obj,
251 GParamSpec *pspec);
252 static const gchar* atk_object_real_get_object_locale
253 (AtkObject *object);
255 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
257 static gpointer parent_class = NULL;
259 static const gchar* const atk_object_name_property_name = "accessible-name";
260 static const gchar* const atk_object_name_property_description = "accessible-description";
261 static const gchar* const atk_object_name_property_parent = "accessible-parent";
262 static const gchar* const atk_object_name_property_value = "accessible-value";
263 static const gchar* const atk_object_name_property_role = "accessible-role";
264 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
265 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
266 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
267 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
268 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
269 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
270 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
271 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
272 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
273 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
275 static void
276 initialize_role_names ()
278 GTypeClass *enum_class;
279 GEnumValue *enum_value;
280 int i;
281 gchar *role_name = NULL;
283 if (role_names)
284 return;
286 role_names = g_ptr_array_new ();
287 enum_class = g_type_class_ref (ATK_TYPE_ROLE);
288 if (!G_IS_ENUM_CLASS(enum_class))
289 return;
291 for (i = 0; i < ATK_ROLE_LAST_DEFINED; i++)
293 enum_value = g_enum_get_value (G_ENUM_CLASS (enum_class), i);
294 role_name = g_strdup (enum_value->value_nick);
295 // We want the role names to be in the format "check button" and not "check-button"
296 _compact_name (role_name);
297 g_ptr_array_add (role_names, role_name);
300 g_type_class_unref (enum_class);
304 GType
305 atk_object_get_type (void)
307 static GType type = 0;
309 if (!type)
311 static const GTypeInfo typeInfo =
313 sizeof (AtkObjectClass),
314 (GBaseInitFunc) NULL,
315 (GBaseFinalizeFunc) NULL,
316 (GClassInitFunc) atk_object_class_init,
317 (GClassFinalizeFunc) NULL,
318 NULL,
319 sizeof (AtkObject),
321 (GInstanceInitFunc) atk_object_init,
323 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
325 return type;
328 static void
329 atk_object_class_init (AtkObjectClass *klass)
331 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
333 parent_class = g_type_class_peek_parent (klass);
335 gobject_class->set_property = atk_object_real_set_property;
336 gobject_class->get_property = atk_object_real_get_property;
337 gobject_class->finalize = atk_object_finalize;
338 gobject_class->notify = atk_object_notify;
340 klass->get_name = atk_object_real_get_name;
341 klass->get_description = atk_object_real_get_description;
342 klass->get_parent = atk_object_real_get_parent;
343 klass->get_n_children = NULL;
344 klass->ref_child = NULL;
345 klass->get_index_in_parent = NULL;
346 klass->ref_relation_set = atk_object_real_ref_relation_set;
347 klass->get_role = atk_object_real_get_role;
348 klass->get_layer = atk_object_real_get_layer;
349 klass->get_mdi_zorder = NULL;
350 klass->initialize = atk_object_real_initialize;
351 klass->ref_state_set = atk_object_real_ref_state_set;
352 klass->set_name = atk_object_real_set_name;
353 klass->set_description = atk_object_real_set_description;
354 klass->set_parent = atk_object_real_set_parent;
355 klass->set_role = atk_object_real_set_role;
356 klass->get_object_locale = atk_object_real_get_object_locale;
359 * We do not define default signal handlers here
361 klass->children_changed = NULL;
362 klass->focus_event = NULL;
363 klass->property_change = NULL;
364 klass->visible_data_changed = NULL;
365 klass->active_descendant_changed = NULL;
367 _gettext_initialization ();
369 g_object_class_install_property (gobject_class,
370 PROP_NAME,
371 g_param_spec_string (atk_object_name_property_name,
372 _("Accessible Name"),
373 _("Object instance’s name formatted for assistive technology access"),
374 NULL,
375 G_PARAM_READWRITE));
376 g_object_class_install_property (gobject_class,
377 PROP_DESCRIPTION,
378 g_param_spec_string (atk_object_name_property_description,
379 _("Accessible Description"),
380 _("Description of an object, formatted for assistive technology access"),
381 NULL,
382 G_PARAM_READWRITE));
383 g_object_class_install_property (gobject_class,
384 PROP_PARENT,
385 g_param_spec_object (atk_object_name_property_parent,
386 _("Accessible Parent"),
387 _("Parent of the current accessible as returned by atk_object_get_parent()"),
388 ATK_TYPE_OBJECT,
389 G_PARAM_READWRITE));
392 * AtkObject:accessible-value:
394 * Numeric value of this object, in case being and AtkValue.
396 * Deprecated: Since 2.12. Use atk_value_get_value_and_text() to get
397 * the value, and value-changed signal to be notified on their value
398 * changes.
400 g_object_class_install_property (gobject_class,
401 PROP_VALUE,
402 g_param_spec_double (atk_object_name_property_value,
403 _("Accessible Value"),
404 _("Is used to notify that the value has changed"),
405 0.0,
406 G_MAXDOUBLE,
407 0.0,
408 G_PARAM_READWRITE));
409 g_object_class_install_property (gobject_class,
410 PROP_ROLE,
411 g_param_spec_enum (atk_object_name_property_role,
412 _("Accessible Role"),
413 _("The accessible role of this object"),
414 ATK_TYPE_ROLE,
415 ATK_ROLE_UNKNOWN,
416 G_PARAM_READWRITE));
417 g_object_class_install_property (gobject_class,
418 PROP_LAYER,
419 g_param_spec_int (atk_object_name_property_component_layer,
420 _("Accessible Layer"),
421 _("The accessible layer of this object"),
423 G_MAXINT,
425 G_PARAM_READABLE));
426 g_object_class_install_property (gobject_class,
427 PROP_MDI_ZORDER,
428 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
429 _("Accessible MDI Value"),
430 _("The accessible MDI value of this object"),
431 G_MININT,
432 G_MAXINT,
433 G_MININT,
434 G_PARAM_READABLE));
437 * AtkObject:accessible-table-caption:
439 * Table caption.
441 * Deprecated: Since 1.3. Use table-caption-object instead.
443 g_object_class_install_property (gobject_class,
444 PROP_TABLE_CAPTION,
445 g_param_spec_string (atk_object_name_property_table_caption,
446 _("Accessible Table Caption"),
447 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
448 NULL,
449 G_PARAM_READWRITE));
451 * AtkObject:accessible-table-column-header:
453 * Accessible table column header.
455 * Deprecated: Since 2.12. Use atk_table_get_column_header() and
456 * atk_table_set_column_header() instead.
458 g_object_class_install_property (gobject_class,
459 PROP_TABLE_COLUMN_HEADER,
460 g_param_spec_object (atk_object_name_property_table_column_header,
461 _("Accessible Table Column Header"),
462 _("Is used to notify that the table column header has changed"),
463 ATK_TYPE_OBJECT,
464 G_PARAM_READWRITE));
467 * AtkObject:accessible-table-column-description:
469 * Accessible table column description.
471 * Deprecated: Since 2.12. Use atk_table_get_column_description()
472 * and atk_table_set_column_description() instead.
474 g_object_class_install_property (gobject_class,
475 PROP_TABLE_COLUMN_DESCRIPTION,
476 g_param_spec_string (atk_object_name_property_table_column_description,
477 _("Accessible Table Column Description"),
478 _("Is used to notify that the table column description has changed"),
479 NULL,
480 G_PARAM_READWRITE));
483 * AtkObject:accessible-table-row-header:
485 * Accessible table row header.
487 * Deprecated: Since 2.12. Use atk_table_get_row_header() and
488 * atk_table_set_row_header() instead.
490 g_object_class_install_property (gobject_class,
491 PROP_TABLE_ROW_HEADER,
492 g_param_spec_object (atk_object_name_property_table_row_header,
493 _("Accessible Table Row Header"),
494 _("Is used to notify that the table row header has changed"),
495 ATK_TYPE_OBJECT,
496 G_PARAM_READWRITE));
498 * AtkObject:accessible-table-row-description:
500 * Accessible table row description.
502 * Deprecated: Since 2.12. Use atk_table_get_row_description() and
503 * atk_table_set_row_description() instead.
505 g_object_class_install_property (gobject_class,
506 PROP_TABLE_ROW_DESCRIPTION,
507 g_param_spec_string (atk_object_name_property_table_row_description,
508 _("Accessible Table Row Description"),
509 _("Is used to notify that the table row description has changed"),
510 NULL,
511 G_PARAM_READWRITE));
512 g_object_class_install_property (gobject_class,
513 PROP_TABLE_SUMMARY,
514 g_param_spec_object (atk_object_name_property_table_summary,
515 _("Accessible Table Summary"),
516 _("Is used to notify that the table summary has changed"),
517 ATK_TYPE_OBJECT,
518 G_PARAM_READWRITE));
519 g_object_class_install_property (gobject_class,
520 PROP_TABLE_CAPTION_OBJECT,
521 g_param_spec_object (atk_object_name_property_table_caption_object,
522 _("Accessible Table Caption Object"),
523 _("Is used to notify that the table caption has changed"),
524 ATK_TYPE_OBJECT,
525 G_PARAM_READWRITE));
526 g_object_class_install_property (gobject_class,
527 PROP_HYPERTEXT_NUM_LINKS,
528 g_param_spec_int (atk_object_name_property_hypertext_num_links,
529 _("Number of Accessible Hypertext Links"),
530 _("The number of links which the current AtkHypertext has"),
532 G_MAXINT,
534 G_PARAM_READABLE));
537 * AtkObject::children-changed:
538 * @atkobject: the object which received the signal.
539 * @arg1: The index of the added or removed child. The value can be
540 * -1. This is used if the value is not known by the implementor
541 * when the child is added/removed or irrelevant.
542 * @arg2: A gpointer to the child AtkObject which was added or
543 * removed. If the child was removed, it is possible that it is not
544 * available for the implementor. In that case this pointer can be
545 * NULL.
547 * The signal "children-changed" is emitted when a child is added or
548 * removed form an object. It supports two details: "add" and
549 * "remove"
551 atk_object_signals[CHILDREN_CHANGED] =
552 g_signal_new ("children_changed",
553 G_TYPE_FROM_CLASS (klass),
554 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
555 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
556 NULL, NULL,
557 g_cclosure_marshal_VOID__UINT_POINTER,
558 G_TYPE_NONE,
559 2, G_TYPE_UINT, G_TYPE_POINTER);
562 * AtkObject::focus-event:
563 * @atkobject: the object which received the signal
564 * @arg1: a boolean value which indicates whether the object gained
565 * or lost focus.
567 * The signal "focus-event" is emitted when an object gained or lost
568 * focus.
570 * Deprecated: 2.9.4: Use the #AtkObject::state-change signal instead.
572 atk_object_signals[FOCUS_EVENT] =
573 g_signal_new ("focus_event",
574 G_TYPE_FROM_CLASS (klass),
575 G_SIGNAL_RUN_LAST,
576 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
577 NULL, NULL,
578 g_cclosure_marshal_VOID__BOOLEAN,
579 G_TYPE_NONE,
580 1, G_TYPE_BOOLEAN);
582 * AtkObject::property-change:
583 * @atkobject: the object which received the signal.
584 * @arg1: an #AtkPropertyValues containing the new value of the
585 * property which changed.
587 * The signal "property-change" is emitted when an object's property
588 * value changes. @arg1 contains an #AtkPropertyValues with the name
589 * and the new value of the property whose value has changed. Note
590 * that, as with GObject notify, getting this signal does not
591 * guarantee that the value of the property has actually changed; it
592 * may also be emitted when the setter of the property is called to
593 * reinstate the previous value.
595 * Toolkit implementor note: ATK implementors should use
596 * g_object_notify() to emit property-changed
597 * notifications. #AtkObject::property-changed is needed by the
598 * implementation of atk_add_global_event_listener() because GObject
599 * notify doesn't support emission hooks.
601 atk_object_signals[PROPERTY_CHANGE] =
602 g_signal_new ("property_change",
603 G_TYPE_FROM_CLASS (klass),
604 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
605 G_STRUCT_OFFSET (AtkObjectClass, property_change),
606 (GSignalAccumulator) NULL, NULL,
607 g_cclosure_marshal_VOID__POINTER,
608 G_TYPE_NONE, 1,
609 G_TYPE_POINTER);
612 * AtkObject::state-change:
613 * @atkobject: the object which received the signal.
614 * @arg1: The name of the state which has changed
615 * @arg2: A boolean which indicates whether the state has been set or unset.
617 * The "state-change" signal is emitted when an object's state
618 * changes. The detail value identifies the state type which has
619 * changed.
621 atk_object_signals[STATE_CHANGE] =
622 g_signal_new ("state_change",
623 G_TYPE_FROM_CLASS (klass),
624 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
625 G_STRUCT_OFFSET (AtkObjectClass, state_change),
626 (GSignalAccumulator) NULL, NULL,
627 atk_marshal_VOID__STRING_BOOLEAN,
628 G_TYPE_NONE, 2,
629 G_TYPE_STRING,
630 G_TYPE_BOOLEAN);
633 * AtkObject::visible-data-changed:
634 * @atkobject: the object which received the signal.
636 * The "visible-data-changed" signal is emitted when the visual
637 * appearance of the object changed.
639 atk_object_signals[VISIBLE_DATA_CHANGED] =
640 g_signal_new ("visible_data_changed",
641 G_TYPE_FROM_CLASS (klass),
642 G_SIGNAL_RUN_LAST,
643 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
644 (GSignalAccumulator) NULL, NULL,
645 g_cclosure_marshal_VOID__VOID,
646 G_TYPE_NONE, 0);
649 * AtkObject::active-descendant-changed:
650 * @atkobject: the object which received the signal.
651 * @arg1: the newly focused object.
653 * The "active-descendant-changed" signal is emitted by an object
654 * which has the state ATK_STATE_MANAGES_DESCENDANTS when the focus
655 * object in the object changes. For instance, a table will emit the
656 * signal when the cell in the table which has focus changes.
658 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
659 g_signal_new ("active_descendant_changed",
660 G_TYPE_FROM_CLASS (klass),
661 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
662 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
663 NULL, NULL,
664 g_cclosure_marshal_VOID__POINTER,
665 G_TYPE_NONE,
666 1, G_TYPE_POINTER);
669 static void
670 atk_object_init (AtkObject *accessible,
671 AtkObjectClass *klass)
673 accessible->name = NULL;
674 accessible->description = NULL;
675 accessible->accessible_parent = NULL;
676 accessible->relation_set = atk_relation_set_new();
677 accessible->role = ATK_ROLE_UNKNOWN;
680 GType
681 atk_implementor_get_type (void)
683 static GType type = 0;
685 if (!type)
687 static const GTypeInfo typeInfo =
689 sizeof (AtkImplementorIface),
690 (GBaseInitFunc) NULL,
691 (GBaseFinalizeFunc) NULL,
694 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
697 return type;
701 * atk_object_get_name:
702 * @accessible: an #AtkObject
704 * Gets the accessible name of the accessible.
706 * Returns: a character string representing the accessible name of the object.
708 const gchar*
709 atk_object_get_name (AtkObject *accessible)
711 AtkObjectClass *klass;
713 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
715 klass = ATK_OBJECT_GET_CLASS (accessible);
716 if (klass->get_name)
717 return (klass->get_name) (accessible);
718 else
719 return NULL;
723 * atk_object_get_description:
724 * @accessible: an #AtkObject
726 * Gets the accessible description of the accessible.
728 * Returns: a character string representing the accessible description
729 * of the accessible.
732 const gchar*
733 atk_object_get_description (AtkObject *accessible)
735 AtkObjectClass *klass;
737 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
739 klass = ATK_OBJECT_GET_CLASS (accessible);
740 if (klass->get_description)
741 return (klass->get_description) (accessible);
742 else
743 return NULL;
747 * atk_object_get_parent:
748 * @accessible: an #AtkObject
750 * Gets the accessible parent of the accessible. By default this is
751 * the one assigned with atk_object_set_parent(), but it is assumed
752 * that ATK implementors have ways to get the parent of the object
753 * without the need of assigning it manually with
754 * atk_object_set_parent(), and will return it with this method.
756 * If you are only interested on the parent assigned with
757 * atk_object_set_parent(), use atk_object_peek_parent().
759 * Returns: (transfer none): an #AtkObject representing the accessible
760 * parent of the accessible
762 AtkObject*
763 atk_object_get_parent (AtkObject *accessible)
765 AtkObjectClass *klass;
767 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
769 klass = ATK_OBJECT_GET_CLASS (accessible);
770 if (klass->get_parent)
771 return (klass->get_parent) (accessible);
772 else
773 return NULL;
777 * atk_object_peek_parent:
778 * @accessible: an #AtkObject
780 * Gets the accessible parent of the accessible, if it has been
781 * manually assigned with atk_object_set_parent. Otherwise, this
782 * function returns %NULL.
784 * This method is intended as an utility for ATK implementors, and not
785 * to be exposed to accessible tools. See atk_object_get_parent() for
786 * further reference.
788 * Returns: (transfer none): an #AtkObject representing the accessible
789 * parent of the accessible if assigned
791 AtkObject*
792 atk_object_peek_parent (AtkObject *accessible)
794 return accessible->accessible_parent;
798 * atk_object_get_n_accessible_children:
799 * @accessible: an #AtkObject
801 * Gets the number of accessible children of the accessible.
803 * Returns: an integer representing the number of accessible children
804 * of the accessible.
806 gint
807 atk_object_get_n_accessible_children (AtkObject *accessible)
809 AtkObjectClass *klass;
811 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
813 klass = ATK_OBJECT_GET_CLASS (accessible);
814 if (klass->get_n_children)
815 return (klass->get_n_children) (accessible);
816 else
817 return 0;
821 * atk_object_ref_accessible_child:
822 * @accessible: an #AtkObject
823 * @i: a gint representing the position of the child, starting from 0
825 * Gets a reference to the specified accessible child of the object.
826 * The accessible children are 0-based so the first accessible child is
827 * at index 0, the second at index 1 and so on.
829 * Returns: (transfer full): an #AtkObject representing the specified
830 * accessible child of the accessible.
832 AtkObject*
833 atk_object_ref_accessible_child (AtkObject *accessible,
834 gint i)
836 AtkObjectClass *klass;
838 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
840 klass = ATK_OBJECT_GET_CLASS (accessible);
841 if (klass->ref_child)
842 return (klass->ref_child) (accessible, i);
843 else
844 return NULL;
848 * atk_object_ref_relation_set:
849 * @accessible: an #AtkObject
851 * Gets the #AtkRelationSet associated with the object.
853 * Returns: (transfer full): an #AtkRelationSet representing the relation set
854 * of the object.
856 AtkRelationSet*
857 atk_object_ref_relation_set (AtkObject *accessible)
859 AtkObjectClass *klass;
861 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
863 klass = ATK_OBJECT_GET_CLASS (accessible);
864 if (klass->ref_relation_set)
865 return (klass->ref_relation_set) (accessible);
866 else
867 return NULL;
871 * atk_role_register:
872 * @name: a character string describing the new role.
874 * Registers the role specified by @name. @name must be a meaningful
875 * name. So it should not be empty, or consisting on whitespaces.
877 * Deprecated: Since 2.12. If your application/toolkit doesn't find a
878 * suitable role for a specific object defined at #AtkRole, please
879 * submit a bug in order to add a new role to the specification.
881 * Returns: an #AtkRole for the new role if added
882 * properly. ATK_ROLE_INVALID in case of error.
884 AtkRole
885 atk_role_register (const gchar *name)
887 gboolean valid = FALSE;
888 gint i = 0;
889 glong length = g_utf8_strlen (name, -1);
891 for (i=0; i < length; i++) {
892 if (name[i]!=' ') {
893 valid = TRUE;
894 break;
898 if (!valid)
899 return ATK_ROLE_INVALID;
901 if (!role_names)
902 initialize_role_names ();
904 g_ptr_array_add (role_names, g_strdup (name));
905 return role_names->len - 1;
909 * atk_object_get_role:
910 * @accessible: an #AtkObject
912 * Gets the role of the accessible.
914 * Returns: an #AtkRole which is the role of the accessible
916 AtkRole
917 atk_object_get_role (AtkObject *accessible)
919 AtkObjectClass *klass;
921 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
923 klass = ATK_OBJECT_GET_CLASS (accessible);
924 if (klass->get_role)
925 return (klass->get_role) (accessible);
926 else
927 return ATK_ROLE_UNKNOWN;
931 * atk_object_get_layer:
932 * @accessible: an #AtkObject
934 * Gets the layer of the accessible.
936 * Deprecated: Use atk_component_get_layer instead.
938 * Returns: an #AtkLayer which is the layer of the accessible
940 AtkLayer
941 atk_object_get_layer (AtkObject *accessible)
943 AtkObjectClass *klass;
945 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
947 klass = ATK_OBJECT_GET_CLASS (accessible);
948 if (klass->get_layer)
949 return (klass->get_layer) (accessible);
950 else
951 return ATK_LAYER_INVALID;
955 * atk_object_get_mdi_zorder:
956 * @accessible: an #AtkObject
958 * Gets the zorder of the accessible. The value G_MININT will be returned
959 * if the layer of the accessible is not ATK_LAYER_MDI.
961 * Deprecated: Use atk_component_get_mdi_zorder instead.
963 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
964 * which the component is shown in relation to other components in the same
965 * container.
968 gint
969 atk_object_get_mdi_zorder (AtkObject *accessible)
971 AtkObjectClass *klass;
973 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
975 klass = ATK_OBJECT_GET_CLASS (accessible);
976 if (klass->get_mdi_zorder)
977 return (klass->get_mdi_zorder) (accessible);
978 else
979 return G_MININT;
983 * atk_object_ref_state_set:
984 * @accessible: an #AtkObject
986 * Gets a reference to the state set of the accessible; the caller must
987 * unreference it when it is no longer needed.
989 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
990 * set of the accessible
992 AtkStateSet*
993 atk_object_ref_state_set (AtkObject *accessible)
995 AtkObjectClass *klass;
997 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
999 klass = ATK_OBJECT_GET_CLASS (accessible);
1000 if (klass->ref_state_set)
1001 return (klass->ref_state_set) (accessible);
1002 else
1003 return NULL;
1007 * atk_object_get_index_in_parent:
1008 * @accessible: an #AtkObject
1010 * Gets the 0-based index of this accessible in its parent; returns -1 if the
1011 * accessible does not have an accessible parent.
1013 * Returns: an integer which is the index of the accessible in its parent
1015 gint
1016 atk_object_get_index_in_parent (AtkObject *accessible)
1018 AtkObjectClass *klass;
1020 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
1022 klass = ATK_OBJECT_GET_CLASS (accessible);
1023 if (klass->get_index_in_parent)
1024 return (klass->get_index_in_parent) (accessible);
1025 else
1026 return -1;
1030 * atk_object_set_name:
1031 * @accessible: an #AtkObject
1032 * @name: a character string to be set as the accessible name
1034 * Sets the accessible name of the accessible. You can't set the name
1035 * to NULL. This is reserved for the initial value. In this aspect
1036 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
1037 * a empty value you can use "".
1039 void
1040 atk_object_set_name (AtkObject *accessible,
1041 const gchar *name)
1043 AtkObjectClass *klass;
1044 gboolean notify = FALSE;
1046 g_return_if_fail (ATK_IS_OBJECT (accessible));
1047 g_return_if_fail (name != NULL);
1049 klass = ATK_OBJECT_GET_CLASS (accessible);
1050 if (klass->set_name)
1052 /* Do not notify for initial name setting. See bug 665870 */
1053 notify = (accessible->name != NULL);
1055 (klass->set_name) (accessible, name);
1056 if (notify)
1057 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1062 * atk_object_set_description:
1063 * @accessible: an #AtkObject
1064 * @description: a character string to be set as the accessible description
1066 * Sets the accessible description of the accessible. You can't set
1067 * the description to NULL. This is reserved for the initial value. In
1068 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
1069 * the name to a empty value you can use "".
1071 void
1072 atk_object_set_description (AtkObject *accessible,
1073 const gchar *description)
1075 AtkObjectClass *klass;
1076 gboolean notify = FALSE;
1078 g_return_if_fail (ATK_IS_OBJECT (accessible));
1079 g_return_if_fail (description != NULL);
1081 klass = ATK_OBJECT_GET_CLASS (accessible);
1082 if (klass->set_description)
1084 /* Do not notify for initial name setting. See bug 665870 */
1085 notify = (accessible->description != NULL);
1087 (klass->set_description) (accessible, description);
1088 if (notify)
1089 g_object_notify (G_OBJECT (accessible),
1090 atk_object_name_property_description);
1095 * atk_object_set_parent:
1096 * @accessible: an #AtkObject
1097 * @parent: an #AtkObject to be set as the accessible parent
1099 * Sets the accessible parent of the accessible. @parent can be NULL.
1101 void
1102 atk_object_set_parent (AtkObject *accessible,
1103 AtkObject *parent)
1105 AtkObjectClass *klass;
1107 g_return_if_fail (ATK_IS_OBJECT (accessible));
1109 klass = ATK_OBJECT_GET_CLASS (accessible);
1110 if (klass->set_parent)
1112 (klass->set_parent) (accessible, parent);
1113 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1118 * atk_object_set_role:
1119 * @accessible: an #AtkObject
1120 * @role: an #AtkRole to be set as the role
1122 * Sets the role of the accessible.
1124 void
1125 atk_object_set_role (AtkObject *accessible,
1126 AtkRole role)
1128 AtkObjectClass *klass;
1129 AtkRole old_role;
1131 g_return_if_fail (ATK_IS_OBJECT (accessible));
1133 klass = ATK_OBJECT_GET_CLASS (accessible);
1134 if (klass->set_role)
1136 old_role = atk_object_get_role (accessible);
1137 if (old_role != role)
1139 (klass->set_role) (accessible, role);
1140 if (old_role != ATK_ROLE_UNKNOWN)
1141 /* Do not notify for initial role setting */
1142 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1148 * atk_object_connect_property_change_handler: (skip)
1149 * @accessible: an #AtkObject
1150 * @handler: a function to be called when a property changes its value
1152 * Deprecated: Since 2.12. Connect directly to property-change or
1153 * notify signals.
1155 * Returns: a #guint which is the handler id used in
1156 * atk_object_remove_property_change_handler()
1158 guint
1159 atk_object_connect_property_change_handler (AtkObject *accessible,
1160 AtkPropertyChangeHandler *handler)
1162 AtkObjectClass *klass;
1164 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1165 g_return_val_if_fail ((handler != NULL), 0);
1167 klass = ATK_OBJECT_GET_CLASS (accessible);
1168 if (klass->connect_property_change_handler)
1169 return (klass->connect_property_change_handler) (accessible, handler);
1170 else
1171 return 0;
1175 * atk_object_remove_property_change_handler:
1176 * @accessible: an #AtkObject
1177 * @handler_id: a guint which identifies the handler to be removed.
1179 * Deprecated: Since 2.12.
1181 * Removes a property change handler.
1183 void
1184 atk_object_remove_property_change_handler (AtkObject *accessible,
1185 guint handler_id)
1187 AtkObjectClass *klass;
1189 g_return_if_fail (ATK_IS_OBJECT (accessible));
1191 klass = ATK_OBJECT_GET_CLASS (accessible);
1192 if (klass->remove_property_change_handler)
1193 (klass->remove_property_change_handler) (accessible, handler_id);
1197 * atk_object_notify_state_change:
1198 * @accessible: an #AtkObject
1199 * @state: an #AtkState whose state is changed
1200 * @value: a gboolean which indicates whether the state is being set on or off
1202 * Emits a state-change signal for the specified state.
1204 * Note that as a general rule when the state of an existing object changes,
1205 * emitting a notification is expected.
1207 void
1208 atk_object_notify_state_change (AtkObject *accessible,
1209 AtkState state,
1210 gboolean value)
1212 const gchar* name;
1214 g_return_if_fail (ATK_IS_OBJECT (accessible));
1216 name = atk_state_type_get_name (state);
1217 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1218 g_quark_from_string (name),
1219 name, value, NULL);
1223 * atk_implementor_ref_accessible:
1224 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1225 * if a non-null return value is required.
1227 * Gets a reference to an object's #AtkObject implementation, if
1228 * the object implements #AtkObjectIface
1230 * Returns: (transfer full): a reference to an object's #AtkObject
1231 * implementation
1233 AtkObject *
1234 atk_implementor_ref_accessible (AtkImplementor *implementor)
1236 AtkImplementorIface *iface;
1237 AtkObject *accessible = NULL;
1239 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1241 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1243 if (iface != NULL)
1244 accessible = iface->ref_accessible (implementor);
1246 g_return_val_if_fail ((accessible != NULL), NULL);
1248 return accessible;
1253 * atk_object_get_attributes:
1254 * @accessible: An #AtkObject.
1256 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1257 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1258 * as distinct from strongly-typed object data available via other get/set methods.
1259 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1261 * Since: 1.12
1263 * Returns: (transfer full): an #AtkAttributeSet consisting of all
1264 * explicit properties/annotations applied to the object, or an empty
1265 * set if the object has no name-value pair attributes assigned to
1266 * it. This #atkattributeset should be freed by a call to
1267 * atk_attribute_set_free().
1269 AtkAttributeSet *
1270 atk_object_get_attributes (AtkObject *accessible)
1272 AtkObjectClass *klass;
1274 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1276 klass = ATK_OBJECT_GET_CLASS (accessible);
1277 if (klass->get_attributes)
1278 return (klass->get_attributes) (accessible);
1279 else
1280 return NULL;
1284 static AtkRelationSet*
1285 atk_object_real_ref_relation_set (AtkObject *accessible)
1287 g_return_val_if_fail (accessible->relation_set, NULL);
1288 g_object_ref (accessible->relation_set);
1290 return accessible->relation_set;
1293 static void
1294 atk_object_real_set_property (GObject *object,
1295 guint prop_id,
1296 const GValue *value,
1297 GParamSpec *pspec)
1299 AtkObject *accessible;
1301 accessible = ATK_OBJECT (object);
1303 switch (prop_id)
1305 case PROP_NAME:
1306 atk_object_set_name (accessible, g_value_get_string (value));
1307 break;
1308 case PROP_DESCRIPTION:
1309 atk_object_set_description (accessible, g_value_get_string (value));
1310 break;
1311 case PROP_ROLE:
1312 atk_object_set_role (accessible, g_value_get_enum (value));
1313 break;
1314 case PROP_PARENT:
1315 atk_object_set_parent (accessible, g_value_get_object (value));
1316 break;
1317 case PROP_VALUE:
1318 if (ATK_IS_VALUE (accessible))
1319 atk_value_set_current_value (ATK_VALUE (accessible), value);
1320 break;
1321 case PROP_TABLE_SUMMARY:
1322 if (ATK_IS_TABLE (accessible))
1323 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1324 break;
1325 case PROP_TABLE_CAPTION_OBJECT:
1326 if (ATK_IS_TABLE (accessible))
1327 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1328 break;
1329 default:
1330 break;
1334 static void
1335 atk_object_real_get_property (GObject *object,
1336 guint prop_id,
1337 GValue *value,
1338 GParamSpec *pspec)
1340 AtkObject *accessible;
1342 accessible = ATK_OBJECT (object);
1344 switch (prop_id)
1346 case PROP_NAME:
1347 g_value_set_string (value, atk_object_get_name (accessible));
1348 break;
1349 case PROP_DESCRIPTION:
1350 g_value_set_string (value, atk_object_get_description (accessible));
1351 break;
1352 case PROP_ROLE:
1353 g_value_set_enum (value, atk_object_get_role (accessible));
1354 break;
1355 case PROP_LAYER:
1356 if (ATK_IS_COMPONENT (accessible))
1357 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1358 break;
1359 case PROP_MDI_ZORDER:
1360 if (ATK_IS_COMPONENT (accessible))
1361 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1362 break;
1363 case PROP_PARENT:
1364 g_value_set_object (value, atk_object_get_parent (accessible));
1365 break;
1366 case PROP_VALUE:
1367 if (ATK_IS_VALUE (accessible))
1368 atk_value_get_current_value (ATK_VALUE (accessible), value);
1369 break;
1370 case PROP_TABLE_SUMMARY:
1371 if (ATK_IS_TABLE (accessible))
1372 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1373 break;
1374 case PROP_TABLE_CAPTION_OBJECT:
1375 if (ATK_IS_TABLE (accessible))
1376 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1377 break;
1378 case PROP_HYPERTEXT_NUM_LINKS:
1379 if (ATK_IS_HYPERTEXT (accessible))
1380 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1381 break;
1382 default:
1383 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1384 break;
1388 static void
1389 atk_object_finalize (GObject *object)
1391 AtkObject *accessible;
1393 g_return_if_fail (ATK_IS_OBJECT (object));
1395 accessible = ATK_OBJECT (object);
1397 g_free (accessible->name);
1398 g_free (accessible->description);
1401 * Free memory allocated for relation set if it have been allocated.
1403 if (accessible->relation_set)
1404 g_object_unref (accessible->relation_set);
1406 if (accessible->accessible_parent)
1407 g_object_unref (accessible->accessible_parent);
1409 G_OBJECT_CLASS (parent_class)->finalize (object);
1412 static const gchar*
1413 atk_object_real_get_name (AtkObject *object)
1415 return object->name;
1418 static const gchar*
1419 atk_object_real_get_description (AtkObject *object)
1421 return object->description;
1424 static AtkObject*
1425 atk_object_real_get_parent (AtkObject *object)
1427 return atk_object_peek_parent (object);
1430 static AtkRole
1431 atk_object_real_get_role (AtkObject *object)
1433 return object->role;
1436 static AtkLayer
1437 atk_object_real_get_layer (AtkObject *object)
1439 return object->layer;
1442 static AtkStateSet*
1443 atk_object_real_ref_state_set (AtkObject *accessible)
1445 AtkStateSet *state_set;
1446 AtkObject *focus_object;
1448 state_set = atk_state_set_new ();
1450 focus_object = atk_get_focus_object ();
1451 if (focus_object == accessible)
1452 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1454 return state_set;
1457 static void
1458 atk_object_real_set_name (AtkObject *object,
1459 const gchar *name)
1461 g_free (object->name);
1462 object->name = g_strdup (name);
1465 static void
1466 atk_object_real_set_description (AtkObject *object,
1467 const gchar *description)
1469 g_free (object->description);
1470 object->description = g_strdup (description);
1473 static void
1474 atk_object_real_set_parent (AtkObject *object,
1475 AtkObject *parent)
1477 if (object->accessible_parent)
1478 g_object_unref (object->accessible_parent);
1480 object->accessible_parent = parent;
1481 if (object->accessible_parent)
1482 g_object_ref (object->accessible_parent);
1485 static void
1486 atk_object_real_set_role (AtkObject *object,
1487 AtkRole role)
1489 object->role = role;
1493 * atk_object_initialize:
1494 * @accessible: a #AtkObject
1495 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1497 * This function is called when implementing subclasses of #AtkObject.
1498 * It does initialization required for the new object. It is intended
1499 * that this function should called only in the ..._new() functions used
1500 * to create an instance of a subclass of #AtkObject
1502 void
1503 atk_object_initialize (AtkObject *accessible,
1504 gpointer data)
1506 AtkObjectClass *klass;
1508 g_return_if_fail (ATK_IS_OBJECT (accessible));
1510 klass = ATK_OBJECT_GET_CLASS (accessible);
1511 if (klass->initialize)
1512 klass->initialize (accessible, data);
1516 * This function is a signal handler for notify signal which gets emitted
1517 * when a property changes value.
1519 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1520 * signal which causes the user specified AtkPropertyChangeHandler
1521 * to be called.
1523 static void
1524 atk_object_notify (GObject *obj,
1525 GParamSpec *pspec)
1527 AtkPropertyValues values = { NULL, };
1529 g_value_init (&values.new_value, pspec->value_type);
1530 g_object_get_property (obj, pspec->name, &values.new_value);
1531 values.property_name = pspec->name;
1532 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1533 g_quark_from_string (pspec->name),
1534 &values, NULL);
1535 g_value_unset (&values.new_value);
1539 * atk_role_get_name:
1540 * @role: The #AtkRole whose name is required
1542 * Gets the description string describing the #AtkRole @role.
1544 * Returns: the string describing the AtkRole
1546 const gchar*
1547 atk_role_get_name (AtkRole role)
1549 g_return_val_if_fail (role >= 0, NULL);
1551 if (!role_names)
1552 initialize_role_names ();
1554 if (role < role_names->len)
1555 return g_ptr_array_index (role_names, role);
1557 return NULL;
1561 * atk_role_get_localized_name:
1562 * @role: The #AtkRole whose localized name is required
1564 * Gets the localized description string describing the #AtkRole @role.
1566 * Returns: the localized string describing the AtkRole
1568 const gchar*
1569 atk_role_get_localized_name (AtkRole role)
1571 _gettext_initialization ();
1573 return dgettext (GETTEXT_PACKAGE, atk_role_get_name (role));
1576 static const gchar*
1577 atk_object_real_get_object_locale (AtkObject *object)
1579 return setlocale (LC_MESSAGES, NULL);
1583 * atk_object_get_object_locale:
1584 * @accessible: an #AtkObject
1586 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
1587 * of @accessible.
1589 * Since: 2.8
1591 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
1592 * locale of @accessible.
1594 const gchar*
1595 atk_object_get_object_locale (AtkObject *accessible)
1597 AtkObjectClass *klass;
1599 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1601 klass = ATK_OBJECT_GET_CLASS (accessible);
1602 if (klass->get_object_locale)
1603 return (klass->get_object_locale) (accessible);
1604 else
1605 return NULL;
1610 * atk_role_for_name:
1611 * @name: a string which is the (non-localized) name of an ATK role.
1613 * Get the #AtkRole type corresponding to a rolew name.
1615 * Returns: the #AtkRole enumerated type corresponding to the specified name,
1616 * or #ATK_ROLE_INVALID if no matching role is found.
1618 AtkRole
1619 atk_role_for_name (const gchar *name)
1621 AtkRole role = ATK_ROLE_INVALID;
1622 gint i;
1624 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1626 if (!role_names)
1627 initialize_role_names ();
1629 for (i = 0; i < role_names->len; i++)
1631 gchar *role_name = (gchar *)g_ptr_array_index (role_names, i);
1633 g_return_val_if_fail (role_name, ATK_ROLE_INVALID);
1635 if (strcmp (name, role_name) == 0)
1637 role = i;
1638 break;
1642 return role;
1646 * atk_object_add_relationship:
1647 * @object: The #AtkObject to which an AtkRelation is to be added.
1648 * @relationship: The #AtkRelationType of the relation
1649 * @target: The #AtkObject which is to be the target of the relation.
1651 * Adds a relationship of the specified type with the specified target.
1653 * Returns: TRUE if the relationship is added.
1655 gboolean
1656 atk_object_add_relationship (AtkObject *object,
1657 AtkRelationType relationship,
1658 AtkObject *target)
1660 AtkObject *array[1];
1661 AtkRelation *relation;
1663 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1664 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1666 if (atk_relation_set_contains_target (object->relation_set,
1667 relationship, target))
1668 return FALSE;
1670 array[0] = target;
1671 relation = atk_relation_new (array, 1, relationship);
1672 atk_relation_set_add (object->relation_set, relation);
1673 g_object_unref (relation);
1675 return TRUE;
1679 * atk_object_remove_relationship:
1680 * @object: The #AtkObject from which an AtkRelation is to be removed.
1681 * @relationship: The #AtkRelationType of the relation
1682 * @target: The #AtkObject which is the target of the relation to be removed.
1684 * Removes a relationship of the specified type with the specified target.
1686 * Returns: TRUE if the relationship is removed.
1688 gboolean
1689 atk_object_remove_relationship (AtkObject *object,
1690 AtkRelationType relationship,
1691 AtkObject *target)
1693 gboolean ret = FALSE;
1694 AtkRelation *relation;
1695 GPtrArray *array;
1697 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1698 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1700 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1702 if (relation)
1704 ret = atk_relation_remove_target (relation, target);
1705 array = atk_relation_get_target (relation);
1706 if (!array || array->len == 0)
1707 atk_relation_set_remove (object->relation_set, relation);
1709 return ret;
1712 static void
1713 atk_object_real_initialize (AtkObject *accessible,
1714 gpointer data)
1716 return;