Move DllMain() to atkprivate.c
[atk.git] / atk / atkobject.c
blobf381df1e0ebb928abda9af33a42a3694baad8ba4
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_int (atk_object_name_property_role,
412 _("Accessible Role"),
413 _("The accessible role of this object"),
415 G_MAXINT,
416 ATK_ROLE_UNKNOWN,
417 G_PARAM_READWRITE));
418 g_object_class_install_property (gobject_class,
419 PROP_LAYER,
420 g_param_spec_int (atk_object_name_property_component_layer,
421 _("Accessible Layer"),
422 _("The accessible layer of this object"),
424 G_MAXINT,
426 G_PARAM_READABLE));
427 g_object_class_install_property (gobject_class,
428 PROP_MDI_ZORDER,
429 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
430 _("Accessible MDI Value"),
431 _("The accessible MDI value of this object"),
432 G_MININT,
433 G_MAXINT,
434 G_MININT,
435 G_PARAM_READABLE));
438 * AtkObject:accessible-table-caption:
440 * Table caption.
442 * Deprecated: Since 1.3. Use table-caption-object instead.
444 g_object_class_install_property (gobject_class,
445 PROP_TABLE_CAPTION,
446 g_param_spec_string (atk_object_name_property_table_caption,
447 _("Accessible Table Caption"),
448 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
449 NULL,
450 G_PARAM_READWRITE));
452 * AtkObject:accessible-table-column-header:
454 * Accessible table column header.
456 * Deprecated: Since 2.12. Use atk_table_get_column_header() and
457 * atk_table_set_column_header() instead.
459 g_object_class_install_property (gobject_class,
460 PROP_TABLE_COLUMN_HEADER,
461 g_param_spec_object (atk_object_name_property_table_column_header,
462 _("Accessible Table Column Header"),
463 _("Is used to notify that the table column header has changed"),
464 ATK_TYPE_OBJECT,
465 G_PARAM_READWRITE));
468 * AtkObject:accessible-table-column-description:
470 * Accessible table column description.
472 * Deprecated: Since 2.12. Use atk_table_get_column_description()
473 * and atk_table_set_column_description() instead.
475 g_object_class_install_property (gobject_class,
476 PROP_TABLE_COLUMN_DESCRIPTION,
477 g_param_spec_string (atk_object_name_property_table_column_description,
478 _("Accessible Table Column Description"),
479 _("Is used to notify that the table column description has changed"),
480 NULL,
481 G_PARAM_READWRITE));
484 * AtkObject:accessible-table-row-header:
486 * Accessible table row header.
488 * Deprecated: Since 2.12. Use atk_table_get_row_header() and
489 * atk_table_set_row_header() instead.
491 g_object_class_install_property (gobject_class,
492 PROP_TABLE_ROW_HEADER,
493 g_param_spec_object (atk_object_name_property_table_row_header,
494 _("Accessible Table Row Header"),
495 _("Is used to notify that the table row header has changed"),
496 ATK_TYPE_OBJECT,
497 G_PARAM_READWRITE));
499 * AtkObject:accessible-table-row-description:
501 * Accessible table row description.
503 * Deprecated: Since 2.12. Use atk_table_get_row_description() and
504 * atk_table_set_row_description() instead.
506 g_object_class_install_property (gobject_class,
507 PROP_TABLE_ROW_DESCRIPTION,
508 g_param_spec_string (atk_object_name_property_table_row_description,
509 _("Accessible Table Row Description"),
510 _("Is used to notify that the table row description has changed"),
511 NULL,
512 G_PARAM_READWRITE));
513 g_object_class_install_property (gobject_class,
514 PROP_TABLE_SUMMARY,
515 g_param_spec_object (atk_object_name_property_table_summary,
516 _("Accessible Table Summary"),
517 _("Is used to notify that the table summary has changed"),
518 ATK_TYPE_OBJECT,
519 G_PARAM_READWRITE));
520 g_object_class_install_property (gobject_class,
521 PROP_TABLE_CAPTION_OBJECT,
522 g_param_spec_object (atk_object_name_property_table_caption_object,
523 _("Accessible Table Caption Object"),
524 _("Is used to notify that the table caption has changed"),
525 ATK_TYPE_OBJECT,
526 G_PARAM_READWRITE));
527 g_object_class_install_property (gobject_class,
528 PROP_HYPERTEXT_NUM_LINKS,
529 g_param_spec_int (atk_object_name_property_hypertext_num_links,
530 _("Number of Accessible Hypertext Links"),
531 _("The number of links which the current AtkHypertext has"),
533 G_MAXINT,
535 G_PARAM_READABLE));
538 * AtkObject::children-changed:
539 * @atkobject: the object which received the signal.
540 * @arg1: The index of the added or removed child. The value can be
541 * -1. This is used if the value is not known by the implementor
542 * when the child is added/removed or irrelevant.
543 * @arg2: A gpointer to the child AtkObject which was added or
544 * removed. If the child was removed, it is possible that it is not
545 * available for the implementor. In that case this pointer can be
546 * NULL.
548 * The signal "children-changed" is emitted when a child is added or
549 * removed form an object. It supports two details: "add" and
550 * "remove"
552 atk_object_signals[CHILDREN_CHANGED] =
553 g_signal_new ("children_changed",
554 G_TYPE_FROM_CLASS (klass),
555 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
556 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
557 NULL, NULL,
558 g_cclosure_marshal_VOID__UINT_POINTER,
559 G_TYPE_NONE,
560 2, G_TYPE_UINT, G_TYPE_POINTER);
563 * AtkObject::focus-event:
564 * @atkobject: the object which received the signal
565 * @arg1: a boolean value which indicates whether the object gained
566 * or lost focus.
568 * The signal "focus-event" is emitted when an object gained or lost
569 * focus.
571 * Deprecated: Since 2.9.4. Use #AtkObject::state-change signal instead.
573 atk_object_signals[FOCUS_EVENT] =
574 g_signal_new ("focus_event",
575 G_TYPE_FROM_CLASS (klass),
576 G_SIGNAL_RUN_LAST,
577 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
578 NULL, NULL,
579 g_cclosure_marshal_VOID__BOOLEAN,
580 G_TYPE_NONE,
581 1, G_TYPE_BOOLEAN);
583 * AtkObject::property-change:
584 * @atkobject: the object which received the signal.
585 * @arg1: an #AtkPropertyValues containing the new value of the
586 * property which changed.
588 * The signal "property-change" is emitted when an object's property
589 * value changes. @arg1 contains an #AtkPropertyValues with the name
590 * and the new value of the property whose value has changed. Note
591 * that, as with GObject notify, getting this signal does not
592 * guarantee that the value of the property has actually changed; it
593 * may also be emitted when the setter of the property is called to
594 * reinstate the previous value.
596 * Toolkit implementor note: ATK implementors should use
597 * g_object_notify() to emit property-changed
598 * notifications. #AtkObject::property-changed is needed by the
599 * implementation of atk_add_global_event_listener() because GObject
600 * notify doesn't support emission hooks.
602 atk_object_signals[PROPERTY_CHANGE] =
603 g_signal_new ("property_change",
604 G_TYPE_FROM_CLASS (klass),
605 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
606 G_STRUCT_OFFSET (AtkObjectClass, property_change),
607 (GSignalAccumulator) NULL, NULL,
608 g_cclosure_marshal_VOID__POINTER,
609 G_TYPE_NONE, 1,
610 G_TYPE_POINTER);
613 * AtkObject::state-change:
614 * @atkobject: the object which received the signal.
615 * @arg1: The name of the state which has changed
616 * @arg2: A boolean which indicates whether the state has been set or unset.
618 * The "state-change" signal is emitted when an object's state
619 * changes. The detail value identifies the state type which has
620 * changed.
622 atk_object_signals[STATE_CHANGE] =
623 g_signal_new ("state_change",
624 G_TYPE_FROM_CLASS (klass),
625 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
626 G_STRUCT_OFFSET (AtkObjectClass, state_change),
627 (GSignalAccumulator) NULL, NULL,
628 atk_marshal_VOID__STRING_BOOLEAN,
629 G_TYPE_NONE, 2,
630 G_TYPE_STRING,
631 G_TYPE_BOOLEAN);
634 * AtkObject::visible-data-changed:
635 * @atkobject: the object which received the signal.
637 * The "visible-data-changed" signal is emitted when the visual
638 * appearance of the object changed.
640 atk_object_signals[VISIBLE_DATA_CHANGED] =
641 g_signal_new ("visible_data_changed",
642 G_TYPE_FROM_CLASS (klass),
643 G_SIGNAL_RUN_LAST,
644 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
645 (GSignalAccumulator) NULL, NULL,
646 g_cclosure_marshal_VOID__VOID,
647 G_TYPE_NONE, 0);
650 * AtkObject::active-descendant-changed:
651 * @atkobject: the object which received the signal.
652 * @arg1: the newly focused object.
654 * The "active-descendant-changed" signal is emitted by an object
655 * which has the state ATK_STATE_MANAGES_DESCENDANTS when the focus
656 * object in the object changes. For instance, a table will emit the
657 * signal when the cell in the table which has focus changes.
659 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
660 g_signal_new ("active_descendant_changed",
661 G_TYPE_FROM_CLASS (klass),
662 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
663 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
664 NULL, NULL,
665 g_cclosure_marshal_VOID__POINTER,
666 G_TYPE_NONE,
667 1, G_TYPE_POINTER);
670 static void
671 atk_object_init (AtkObject *accessible,
672 AtkObjectClass *klass)
674 accessible->name = NULL;
675 accessible->description = NULL;
676 accessible->accessible_parent = NULL;
677 accessible->relation_set = atk_relation_set_new();
678 accessible->role = ATK_ROLE_UNKNOWN;
681 GType
682 atk_implementor_get_type (void)
684 static GType type = 0;
686 if (!type)
688 static const GTypeInfo typeInfo =
690 sizeof (AtkImplementorIface),
691 (GBaseInitFunc) NULL,
692 (GBaseFinalizeFunc) NULL,
695 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
698 return type;
702 * atk_object_get_name:
703 * @accessible: an #AtkObject
705 * Gets the accessible name of the accessible.
707 * Returns: a character string representing the accessible name of the object.
709 const gchar*
710 atk_object_get_name (AtkObject *accessible)
712 AtkObjectClass *klass;
714 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
716 klass = ATK_OBJECT_GET_CLASS (accessible);
717 if (klass->get_name)
718 return (klass->get_name) (accessible);
719 else
720 return NULL;
724 * atk_object_get_description:
725 * @accessible: an #AtkObject
727 * Gets the accessible description of the accessible.
729 * Returns: a character string representing the accessible description
730 * of the accessible.
733 const gchar*
734 atk_object_get_description (AtkObject *accessible)
736 AtkObjectClass *klass;
738 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
740 klass = ATK_OBJECT_GET_CLASS (accessible);
741 if (klass->get_description)
742 return (klass->get_description) (accessible);
743 else
744 return NULL;
748 * atk_object_get_parent:
749 * @accessible: an #AtkObject
751 * Gets the accessible parent of the accessible. By default this is
752 * the one assigned with atk_object_set_parent(), but it is assumed
753 * that ATK implementors have ways to get the parent of the object
754 * without the need of assigning it manually with
755 * atk_object_set_parent(), and will return it with this method.
757 * If you are only interested on the parent assigned with
758 * atk_object_set_parent(), use atk_object_peek_parent().
760 * Returns: (transfer none): an #AtkObject representing the accessible
761 * parent of the accessible
763 AtkObject*
764 atk_object_get_parent (AtkObject *accessible)
766 AtkObjectClass *klass;
768 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
770 klass = ATK_OBJECT_GET_CLASS (accessible);
771 if (klass->get_parent)
772 return (klass->get_parent) (accessible);
773 else
774 return NULL;
778 * atk_object_peek_parent:
779 * @accessible: an #AtkObject
781 * Gets the accessible parent of the accessible, if it has been
782 * manually assigned with atk_object_set_parent. Otherwise, this
783 * function returns %NULL.
785 * This method is intended as an utility for ATK implementors, and not
786 * to be exposed to accessible tools. See atk_object_get_parent() for
787 * further reference.
789 * Returns: (transfer none): an #AtkObject representing the accessible
790 * parent of the accessible if assigned
792 AtkObject*
793 atk_object_peek_parent (AtkObject *accessible)
795 return accessible->accessible_parent;
799 * atk_object_get_n_accessible_children:
800 * @accessible: an #AtkObject
802 * Gets the number of accessible children of the accessible.
804 * Returns: an integer representing the number of accessible children
805 * of the accessible.
807 gint
808 atk_object_get_n_accessible_children (AtkObject *accessible)
810 AtkObjectClass *klass;
812 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
814 klass = ATK_OBJECT_GET_CLASS (accessible);
815 if (klass->get_n_children)
816 return (klass->get_n_children) (accessible);
817 else
818 return 0;
822 * atk_object_ref_accessible_child:
823 * @accessible: an #AtkObject
824 * @i: a gint representing the position of the child, starting from 0
826 * Gets a reference to the specified accessible child of the object.
827 * The accessible children are 0-based so the first accessible child is
828 * at index 0, the second at index 1 and so on.
830 * Returns: (transfer full): an #AtkObject representing the specified
831 * accessible child of the accessible.
833 AtkObject*
834 atk_object_ref_accessible_child (AtkObject *accessible,
835 gint i)
837 AtkObjectClass *klass;
839 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
841 klass = ATK_OBJECT_GET_CLASS (accessible);
842 if (klass->ref_child)
843 return (klass->ref_child) (accessible, i);
844 else
845 return NULL;
849 * atk_object_ref_relation_set:
850 * @accessible: an #AtkObject
852 * Gets the #AtkRelationSet associated with the object.
854 * Returns: (transfer full): an #AtkRelationSet representing the relation set
855 * of the object.
857 AtkRelationSet*
858 atk_object_ref_relation_set (AtkObject *accessible)
860 AtkObjectClass *klass;
862 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
864 klass = ATK_OBJECT_GET_CLASS (accessible);
865 if (klass->ref_relation_set)
866 return (klass->ref_relation_set) (accessible);
867 else
868 return NULL;
872 * atk_role_register:
873 * @name: a character string describing the new role.
875 * Registers the role specified by @name. @name must be a meaningful
876 * name. So it should not be empty, or consisting on whitespaces.
878 * Deprecated: Since 2.12. If your application/toolkit doesn't find a
879 * suitable role for a specific object defined at #AtkRole, please
880 * submit a bug in order to add a new role to the specification.
882 * Returns: an #AtkRole for the new role if added
883 * properly. ATK_ROLE_INVALID in case of error.
885 AtkRole
886 atk_role_register (const gchar *name)
888 gboolean valid = FALSE;
889 gint i = 0;
890 glong length = g_utf8_strlen (name, -1);
892 for (i=0; i < length; i++) {
893 if (name[i]!=' ') {
894 valid = TRUE;
895 break;
899 if (!valid)
900 return ATK_ROLE_INVALID;
902 if (!role_names)
903 initialize_role_names ();
905 g_ptr_array_add (role_names, g_strdup (name));
906 return role_names->len - 1;
910 * atk_object_get_role:
911 * @accessible: an #AtkObject
913 * Gets the role of the accessible.
915 * Returns: an #AtkRole which is the role of the accessible
917 AtkRole
918 atk_object_get_role (AtkObject *accessible)
920 AtkObjectClass *klass;
922 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
924 klass = ATK_OBJECT_GET_CLASS (accessible);
925 if (klass->get_role)
926 return (klass->get_role) (accessible);
927 else
928 return ATK_ROLE_UNKNOWN;
932 * atk_object_get_layer:
933 * @accessible: an #AtkObject
935 * Gets the layer of the accessible.
937 * Deprecated: Use atk_component_get_layer instead.
939 * Returns: an #AtkLayer which is the layer of the accessible
941 AtkLayer
942 atk_object_get_layer (AtkObject *accessible)
944 AtkObjectClass *klass;
946 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
948 klass = ATK_OBJECT_GET_CLASS (accessible);
949 if (klass->get_layer)
950 return (klass->get_layer) (accessible);
951 else
952 return ATK_LAYER_INVALID;
956 * atk_object_get_mdi_zorder:
957 * @accessible: an #AtkObject
959 * Gets the zorder of the accessible. The value G_MININT will be returned
960 * if the layer of the accessible is not ATK_LAYER_MDI.
962 * Deprecated: Use atk_component_get_mdi_zorder instead.
964 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
965 * which the component is shown in relation to other components in the same
966 * container.
969 gint
970 atk_object_get_mdi_zorder (AtkObject *accessible)
972 AtkObjectClass *klass;
974 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
976 klass = ATK_OBJECT_GET_CLASS (accessible);
977 if (klass->get_mdi_zorder)
978 return (klass->get_mdi_zorder) (accessible);
979 else
980 return G_MININT;
984 * atk_object_ref_state_set:
985 * @accessible: an #AtkObject
987 * Gets a reference to the state set of the accessible; the caller must
988 * unreference it when it is no longer needed.
990 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
991 * set of the accessible
993 AtkStateSet*
994 atk_object_ref_state_set (AtkObject *accessible)
996 AtkObjectClass *klass;
998 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1000 klass = ATK_OBJECT_GET_CLASS (accessible);
1001 if (klass->ref_state_set)
1002 return (klass->ref_state_set) (accessible);
1003 else
1004 return NULL;
1008 * atk_object_get_index_in_parent:
1009 * @accessible: an #AtkObject
1011 * Gets the 0-based index of this accessible in its parent; returns -1 if the
1012 * accessible does not have an accessible parent.
1014 * Returns: an integer which is the index of the accessible in its parent
1016 gint
1017 atk_object_get_index_in_parent (AtkObject *accessible)
1019 AtkObjectClass *klass;
1021 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
1023 klass = ATK_OBJECT_GET_CLASS (accessible);
1024 if (klass->get_index_in_parent)
1025 return (klass->get_index_in_parent) (accessible);
1026 else
1027 return -1;
1031 * atk_object_set_name:
1032 * @accessible: an #AtkObject
1033 * @name: a character string to be set as the accessible name
1035 * Sets the accessible name of the accessible. You can't set the name
1036 * to NULL. This is reserved for the initial value. In this aspect
1037 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
1038 * a empty value you can use "".
1040 void
1041 atk_object_set_name (AtkObject *accessible,
1042 const gchar *name)
1044 AtkObjectClass *klass;
1045 gboolean notify = FALSE;
1047 g_return_if_fail (ATK_IS_OBJECT (accessible));
1048 g_return_if_fail (name != NULL);
1050 klass = ATK_OBJECT_GET_CLASS (accessible);
1051 if (klass->set_name)
1053 /* Do not notify for initial name setting. See bug 665870 */
1054 notify = (accessible->name != NULL);
1056 (klass->set_name) (accessible, name);
1057 if (notify)
1058 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1063 * atk_object_set_description:
1064 * @accessible: an #AtkObject
1065 * @description: a character string to be set as the accessible description
1067 * Sets the accessible description of the accessible. You can't set
1068 * the description to NULL. This is reserved for the initial value. In
1069 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
1070 * the name to a empty value you can use "".
1072 void
1073 atk_object_set_description (AtkObject *accessible,
1074 const gchar *description)
1076 AtkObjectClass *klass;
1077 gboolean notify = FALSE;
1079 g_return_if_fail (ATK_IS_OBJECT (accessible));
1080 g_return_if_fail (description != NULL);
1082 klass = ATK_OBJECT_GET_CLASS (accessible);
1083 if (klass->set_description)
1085 /* Do not notify for initial name setting. See bug 665870 */
1086 notify = (accessible->description != NULL);
1088 (klass->set_description) (accessible, description);
1089 if (notify)
1090 g_object_notify (G_OBJECT (accessible),
1091 atk_object_name_property_description);
1096 * atk_object_set_parent:
1097 * @accessible: an #AtkObject
1098 * @parent: an #AtkObject to be set as the accessible parent
1100 * Sets the accessible parent of the accessible. @parent can be NULL.
1102 void
1103 atk_object_set_parent (AtkObject *accessible,
1104 AtkObject *parent)
1106 AtkObjectClass *klass;
1108 g_return_if_fail (ATK_IS_OBJECT (accessible));
1110 klass = ATK_OBJECT_GET_CLASS (accessible);
1111 if (klass->set_parent)
1113 (klass->set_parent) (accessible, parent);
1114 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1119 * atk_object_set_role:
1120 * @accessible: an #AtkObject
1121 * @role: an #AtkRole to be set as the role
1123 * Sets the role of the accessible.
1125 void
1126 atk_object_set_role (AtkObject *accessible,
1127 AtkRole role)
1129 AtkObjectClass *klass;
1130 AtkRole old_role;
1132 g_return_if_fail (ATK_IS_OBJECT (accessible));
1134 klass = ATK_OBJECT_GET_CLASS (accessible);
1135 if (klass->set_role)
1137 old_role = atk_object_get_role (accessible);
1138 if (old_role != role)
1140 (klass->set_role) (accessible, role);
1141 if (old_role != ATK_ROLE_UNKNOWN)
1142 /* Do not notify for initial role setting */
1143 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1149 * atk_object_connect_property_change_handler:
1150 * @accessible: an #AtkObject
1151 * @handler: a function to be called when a property changes its value
1153 * Deprecated: Since 2.12. Connect directly to property-change or
1154 * notify signals.
1156 * Returns: a #guint which is the handler id used in
1157 * atk_object_remove_property_change_handler()
1159 guint
1160 atk_object_connect_property_change_handler (AtkObject *accessible,
1161 AtkPropertyChangeHandler *handler)
1163 AtkObjectClass *klass;
1165 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1166 g_return_val_if_fail ((handler != NULL), 0);
1168 klass = ATK_OBJECT_GET_CLASS (accessible);
1169 if (klass->connect_property_change_handler)
1170 return (klass->connect_property_change_handler) (accessible, handler);
1171 else
1172 return 0;
1176 * atk_object_remove_property_change_handler:
1177 * @accessible: an #AtkObject
1178 * @handler_id: a guint which identifies the handler to be removed.
1180 * Deprecated: Since 2.12.
1182 * Removes a property change handler.
1184 void
1185 atk_object_remove_property_change_handler (AtkObject *accessible,
1186 guint handler_id)
1188 AtkObjectClass *klass;
1190 g_return_if_fail (ATK_IS_OBJECT (accessible));
1192 klass = ATK_OBJECT_GET_CLASS (accessible);
1193 if (klass->remove_property_change_handler)
1194 (klass->remove_property_change_handler) (accessible, handler_id);
1198 * atk_object_notify_state_change:
1199 * @accessible: an #AtkObject
1200 * @state: an #AtkState whose state is changed
1201 * @value: a gboolean which indicates whether the state is being set on or off
1203 * Emits a state-change signal for the specified state.
1205 void
1206 atk_object_notify_state_change (AtkObject *accessible,
1207 AtkState state,
1208 gboolean value)
1210 const gchar* name;
1212 g_return_if_fail (ATK_IS_OBJECT (accessible));
1214 name = atk_state_type_get_name (state);
1215 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1216 g_quark_from_string (name),
1217 name, value, NULL);
1221 * atk_implementor_ref_accessible:
1222 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1223 * if a non-null return value is required.
1225 * Gets a reference to an object's #AtkObject implementation, if
1226 * the object implements #AtkObjectIface
1228 * Returns: (transfer full): a reference to an object's #AtkObject
1229 * implementation
1231 AtkObject *
1232 atk_implementor_ref_accessible (AtkImplementor *implementor)
1234 AtkImplementorIface *iface;
1235 AtkObject *accessible = NULL;
1237 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1239 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1241 if (iface != NULL)
1242 accessible = iface->ref_accessible (implementor);
1244 g_return_val_if_fail ((accessible != NULL), NULL);
1246 return accessible;
1251 * atk_object_get_attributes:
1252 * @accessible: An #AtkObject.
1254 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1255 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1256 * as distinct from strongly-typed object data available via other get/set methods.
1257 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1259 * Since: 1.12
1261 * Returns: (transfer full): an #AtkAttributeSet consisting of all
1262 * explicit properties/annotations applied to the object, or an empty
1263 * set if the object has no name-value pair attributes assigned to
1264 * it. This #atkattributeset should be freed by a call to
1265 * atk_attribute_set_free().
1267 AtkAttributeSet *
1268 atk_object_get_attributes (AtkObject *accessible)
1270 AtkObjectClass *klass;
1272 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1274 klass = ATK_OBJECT_GET_CLASS (accessible);
1275 if (klass->get_attributes)
1276 return (klass->get_attributes) (accessible);
1277 else
1278 return NULL;
1282 static AtkRelationSet*
1283 atk_object_real_ref_relation_set (AtkObject *accessible)
1285 g_return_val_if_fail (accessible->relation_set, NULL);
1286 g_object_ref (accessible->relation_set);
1288 return accessible->relation_set;
1291 static void
1292 atk_object_real_set_property (GObject *object,
1293 guint prop_id,
1294 const GValue *value,
1295 GParamSpec *pspec)
1297 AtkObject *accessible;
1299 accessible = ATK_OBJECT (object);
1301 switch (prop_id)
1303 case PROP_NAME:
1304 atk_object_set_name (accessible, g_value_get_string (value));
1305 break;
1306 case PROP_DESCRIPTION:
1307 atk_object_set_description (accessible, g_value_get_string (value));
1308 break;
1309 case PROP_ROLE:
1310 atk_object_set_role (accessible, g_value_get_int (value));
1311 break;
1312 case PROP_PARENT:
1313 atk_object_set_parent (accessible, g_value_get_object (value));
1314 break;
1315 case PROP_VALUE:
1316 if (ATK_IS_VALUE (accessible))
1317 atk_value_set_current_value (ATK_VALUE (accessible), value);
1318 break;
1319 case PROP_TABLE_SUMMARY:
1320 if (ATK_IS_TABLE (accessible))
1321 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1322 break;
1323 case PROP_TABLE_CAPTION_OBJECT:
1324 if (ATK_IS_TABLE (accessible))
1325 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1326 break;
1327 default:
1328 break;
1332 static void
1333 atk_object_real_get_property (GObject *object,
1334 guint prop_id,
1335 GValue *value,
1336 GParamSpec *pspec)
1338 AtkObject *accessible;
1340 accessible = ATK_OBJECT (object);
1342 switch (prop_id)
1344 case PROP_NAME:
1345 g_value_set_string (value, atk_object_get_name (accessible));
1346 break;
1347 case PROP_DESCRIPTION:
1348 g_value_set_string (value, atk_object_get_description (accessible));
1349 break;
1350 case PROP_ROLE:
1351 g_value_set_int (value, atk_object_get_role (accessible));
1352 break;
1353 case PROP_LAYER:
1354 if (ATK_IS_COMPONENT (accessible))
1355 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1356 break;
1357 case PROP_MDI_ZORDER:
1358 if (ATK_IS_COMPONENT (accessible))
1359 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1360 break;
1361 case PROP_PARENT:
1362 g_value_set_object (value, atk_object_get_parent (accessible));
1363 break;
1364 case PROP_VALUE:
1365 if (ATK_IS_VALUE (accessible))
1366 atk_value_get_current_value (ATK_VALUE (accessible), value);
1367 break;
1368 case PROP_TABLE_SUMMARY:
1369 if (ATK_IS_TABLE (accessible))
1370 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1371 break;
1372 case PROP_TABLE_CAPTION_OBJECT:
1373 if (ATK_IS_TABLE (accessible))
1374 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1375 break;
1376 case PROP_HYPERTEXT_NUM_LINKS:
1377 if (ATK_IS_HYPERTEXT (accessible))
1378 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1379 break;
1380 default:
1381 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1382 break;
1386 static void
1387 atk_object_finalize (GObject *object)
1389 AtkObject *accessible;
1391 g_return_if_fail (ATK_IS_OBJECT (object));
1393 accessible = ATK_OBJECT (object);
1395 g_free (accessible->name);
1396 g_free (accessible->description);
1399 * Free memory allocated for relation set if it have been allocated.
1401 if (accessible->relation_set)
1402 g_object_unref (accessible->relation_set);
1404 if (accessible->accessible_parent)
1405 g_object_unref (accessible->accessible_parent);
1407 G_OBJECT_CLASS (parent_class)->finalize (object);
1410 static const gchar*
1411 atk_object_real_get_name (AtkObject *object)
1413 return object->name;
1416 static const gchar*
1417 atk_object_real_get_description (AtkObject *object)
1419 return object->description;
1422 static AtkObject*
1423 atk_object_real_get_parent (AtkObject *object)
1425 return atk_object_peek_parent (object);
1428 static AtkRole
1429 atk_object_real_get_role (AtkObject *object)
1431 return object->role;
1434 static AtkLayer
1435 atk_object_real_get_layer (AtkObject *object)
1437 return object->layer;
1440 static AtkStateSet*
1441 atk_object_real_ref_state_set (AtkObject *accessible)
1443 AtkStateSet *state_set;
1444 AtkObject *focus_object;
1446 state_set = atk_state_set_new ();
1448 focus_object = atk_get_focus_object ();
1449 if (focus_object == accessible)
1450 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1452 return state_set;
1455 static void
1456 atk_object_real_set_name (AtkObject *object,
1457 const gchar *name)
1459 g_free (object->name);
1460 object->name = g_strdup (name);
1463 static void
1464 atk_object_real_set_description (AtkObject *object,
1465 const gchar *description)
1467 g_free (object->description);
1468 object->description = g_strdup (description);
1471 static void
1472 atk_object_real_set_parent (AtkObject *object,
1473 AtkObject *parent)
1475 if (object->accessible_parent)
1476 g_object_unref (object->accessible_parent);
1478 object->accessible_parent = parent;
1479 if (object->accessible_parent)
1480 g_object_ref (object->accessible_parent);
1483 static void
1484 atk_object_real_set_role (AtkObject *object,
1485 AtkRole role)
1487 object->role = role;
1491 * atk_object_initialize:
1492 * @accessible: a #AtkObject
1493 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1495 * This function is called when implementing subclasses of #AtkObject.
1496 * It does initialization required for the new object. It is intended
1497 * that this function should called only in the ..._new() functions used
1498 * to create an instance of a subclass of #AtkObject
1500 void
1501 atk_object_initialize (AtkObject *accessible,
1502 gpointer data)
1504 AtkObjectClass *klass;
1506 g_return_if_fail (ATK_IS_OBJECT (accessible));
1508 klass = ATK_OBJECT_GET_CLASS (accessible);
1509 if (klass->initialize)
1510 klass->initialize (accessible, data);
1514 * This function is a signal handler for notify signal which gets emitted
1515 * when a property changes value.
1517 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1518 * signal which causes the user specified AtkPropertyChangeHandler
1519 * to be called.
1521 static void
1522 atk_object_notify (GObject *obj,
1523 GParamSpec *pspec)
1525 AtkPropertyValues values = { NULL, };
1527 g_value_init (&values.new_value, pspec->value_type);
1528 g_object_get_property (obj, pspec->name, &values.new_value);
1529 values.property_name = pspec->name;
1530 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1531 g_quark_from_string (pspec->name),
1532 &values, NULL);
1533 g_value_unset (&values.new_value);
1537 * atk_role_get_name:
1538 * @role: The #AtkRole whose name is required
1540 * Gets the description string describing the #AtkRole @role.
1542 * Returns: the string describing the AtkRole
1544 const gchar*
1545 atk_role_get_name (AtkRole role)
1547 g_return_val_if_fail (role >= 0, NULL);
1549 if (!role_names)
1550 initialize_role_names ();
1552 if (role < role_names->len)
1553 return g_ptr_array_index (role_names, role);
1555 return NULL;
1559 * atk_role_get_localized_name:
1560 * @role: The #AtkRole whose localized name is required
1562 * Gets the localized description string describing the #AtkRole @role.
1564 * Returns: the localized string describing the AtkRole
1566 const gchar*
1567 atk_role_get_localized_name (AtkRole role)
1569 _gettext_initialization ();
1571 return dgettext (GETTEXT_PACKAGE, atk_role_get_name (role));
1574 static const gchar*
1575 atk_object_real_get_object_locale (AtkObject *object)
1577 return setlocale (LC_MESSAGES, NULL);
1581 * atk_object_get_object_locale:
1582 * @accessible: an #AtkObject
1584 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
1585 * of @accessible.
1587 * Since: 2.8
1589 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
1590 * locale of @accessible.
1592 const gchar*
1593 atk_object_get_object_locale (AtkObject *accessible)
1595 AtkObjectClass *klass;
1597 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1599 klass = ATK_OBJECT_GET_CLASS (accessible);
1600 if (klass->get_object_locale)
1601 return (klass->get_object_locale) (accessible);
1602 else
1603 return NULL;
1608 * atk_role_for_name:
1609 * @name: a string which is the (non-localized) name of an ATK role.
1611 * Get the #AtkRole type corresponding to a rolew name.
1613 * Returns: the #AtkRole enumerated type corresponding to the specified name,
1614 * or #ATK_ROLE_INVALID if no matching role is found.
1616 AtkRole
1617 atk_role_for_name (const gchar *name)
1619 AtkRole role = ATK_ROLE_INVALID;
1620 gint i;
1622 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1624 if (!role_names)
1625 initialize_role_names ();
1627 for (i = 0; i < role_names->len; i++)
1629 gchar *role_name = (gchar *)g_ptr_array_index (role_names, i);
1631 g_return_val_if_fail (role_name, ATK_ROLE_INVALID);
1633 if (strcmp (name, role_name) == 0)
1635 role = i;
1636 break;
1640 return role;
1644 * atk_object_add_relationship:
1645 * @object: The #AtkObject to which an AtkRelation is to be added.
1646 * @relationship: The #AtkRelationType of the relation
1647 * @target: The #AtkObject which is to be the target of the relation.
1649 * Adds a relationship of the specified type with the specified target.
1651 * Returns: TRUE if the relationship is added.
1653 gboolean
1654 atk_object_add_relationship (AtkObject *object,
1655 AtkRelationType relationship,
1656 AtkObject *target)
1658 AtkObject *array[1];
1659 AtkRelation *relation;
1661 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1662 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1664 if (atk_relation_set_contains_target (object->relation_set,
1665 relationship, target))
1666 return FALSE;
1668 array[0] = target;
1669 relation = atk_relation_new (array, 1, relationship);
1670 atk_relation_set_add (object->relation_set, relation);
1671 g_object_unref (relation);
1673 return TRUE;
1677 * atk_object_remove_relationship:
1678 * @object: The #AtkObject from which an AtkRelation is to be removed.
1679 * @relationship: The #AtkRelationType of the relation
1680 * @target: The #AtkObject which is the target of the relation to be removed.
1682 * Removes a relationship of the specified type with the specified target.
1684 * Returns: TRUE if the relationship is removed.
1686 gboolean
1687 atk_object_remove_relationship (AtkObject *object,
1688 AtkRelationType relationship,
1689 AtkObject *target)
1691 gboolean ret = FALSE;
1692 AtkRelation *relation;
1693 GPtrArray *array;
1695 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1696 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1698 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1700 if (relation)
1702 ret = atk_relation_remove_target (relation, target);
1703 array = atk_relation_get_target (relation);
1704 if (!array || array->len == 0)
1705 atk_relation_set_remove (object->relation_set, relation);
1707 return ret;
1710 static void
1711 atk_object_real_initialize (AtkObject *accessible,
1712 gpointer data)
1714 return;