atkimplementor: use the G_DEFINE_INTERFACE macro to declare it as interface in the...
[atk.git] / atk / atkobject.c
blobc3f3c7097a72a21267609c31eb000bf2defee00d
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 typedef AtkImplementorIface AtkImplementorInterface;
61 G_DEFINE_INTERFACE (AtkImplementor, atk_implementor, G_TYPE_OBJECT)
63 static GPtrArray *role_names = NULL;
65 enum
67 PROP_0, /* gobject convention */
69 PROP_NAME,
70 PROP_DESCRIPTION,
71 PROP_PARENT, /* ancestry has changed */
72 PROP_VALUE,
73 PROP_ROLE,
74 PROP_LAYER,
75 PROP_MDI_ZORDER,
76 PROP_TABLE_CAPTION,
77 PROP_TABLE_COLUMN_DESCRIPTION,
78 PROP_TABLE_COLUMN_HEADER,
79 PROP_TABLE_ROW_DESCRIPTION,
80 PROP_TABLE_ROW_HEADER,
81 PROP_TABLE_SUMMARY,
82 PROP_TABLE_CAPTION_OBJECT,
83 PROP_HYPERTEXT_NUM_LINKS,
84 PROP_LAST /* gobject convention */
87 enum {
88 CHILDREN_CHANGED,
89 FOCUS_EVENT,
90 PROPERTY_CHANGE,
91 STATE_CHANGE,
92 VISIBLE_DATA_CHANGED,
93 ACTIVE_DESCENDANT_CHANGED,
95 LAST_SIGNAL
98 /* These are listed here for extraction by intltool */
99 #if 0
100 N_("invalid")
101 N_("accelerator label")
102 N_("alert")
103 N_("animation")
104 N_("arrow")
105 N_("calendar")
106 N_("canvas")
107 N_("check box")
108 N_("check menu item")
109 N_("color chooser")
110 N_("column header")
111 N_("combo box")
112 N_("dateeditor")
113 N_("desktop icon")
114 N_("desktop frame")
115 N_("dial")
116 N_("dialog")
117 N_("directory pane")
118 N_("drawing area")
119 N_("file chooser")
120 N_("filler")
121 /* I know it looks wrong but that is what Java returns */
122 N_("fontchooser")
123 N_("frame")
124 N_("glass pane")
125 N_("html container")
126 N_("icon")
127 N_("image")
128 N_("internal frame")
129 N_("label")
130 N_("layered pane")
131 N_("list")
132 N_("list item")
133 N_("menu")
134 N_("menu bar")
135 N_("menu item")
136 N_("option pane")
137 N_("page tab")
138 N_("page tab list")
139 N_("panel")
140 N_("password text")
141 N_("popup menu")
142 N_("progress bar")
143 N_("push button")
144 N_("radio button")
145 N_("radio menu item")
146 N_("root pane")
147 N_("row header")
148 N_("scroll bar")
149 N_("scroll pane")
150 N_("separator")
151 N_("slider")
152 N_("split pane")
153 N_("spin button")
154 N_("statusbar")
155 N_("table")
156 N_("table cell")
157 N_("table column header")
158 N_("table row header")
159 N_("tear off menu item")
160 N_("terminal")
161 N_("text")
162 N_("toggle button")
163 N_("tool bar")
164 N_("tool tip")
165 N_("tree")
166 N_("tree table")
167 N_("unknown")
168 N_("viewport")
169 N_("window")
170 N_("header")
171 N_("footer")
172 N_("paragraph")
173 N_("ruler")
174 N_("application")
175 N_("autocomplete")
176 N_("edit bar")
177 N_("embedded component")
178 N_("entry")
179 N_("chart")
180 N_("caption")
181 N_("document frame")
182 N_("heading")
183 N_("page")
184 N_("section")
185 N_("redundant object")
186 N_("form")
187 N_("link")
188 N_("input method window")
189 N_("table row")
190 N_("tree item")
191 N_("document spreadsheet")
192 N_("document presentation")
193 N_("document text")
194 N_("document web")
195 N_("document email")
196 N_("comment")
197 N_("list box")
198 N_("grouping")
199 N_("image map")
200 N_("notification")
201 N_("info bar")
202 N_("level bar")
203 N_("title bar")
204 N_("block quote")
205 N_("audio")
206 N_("video")
207 N_("definition")
208 N_("article")
209 N_("landmark")
210 N_("log")
211 N_("marquee")
212 N_("math")
213 N_("rating")
214 N_("timer")
215 N_("description list")
216 N_("description term")
217 N_("description value")
218 #endif /* 0 */
220 static void atk_object_class_init (AtkObjectClass *klass);
221 static void atk_object_init (AtkObject *accessible,
222 AtkObjectClass *klass);
223 static AtkRelationSet* atk_object_real_ref_relation_set
224 (AtkObject *accessible);
225 static void atk_object_real_initialize (AtkObject *accessible,
226 gpointer data);
227 static void atk_object_real_set_property (GObject *object,
228 guint prop_id,
229 const GValue *value,
230 GParamSpec *pspec);
231 static void atk_object_real_get_property (GObject *object,
232 guint prop_id,
233 GValue *value,
234 GParamSpec *pspec);
235 static void atk_object_finalize (GObject *object);
236 static const gchar* atk_object_real_get_name (AtkObject *object);
237 static const gchar* atk_object_real_get_description
238 (AtkObject *object);
239 static AtkObject* atk_object_real_get_parent (AtkObject *object);
240 static AtkRole atk_object_real_get_role (AtkObject *object);
241 static AtkLayer atk_object_real_get_layer (AtkObject *object);
242 static AtkStateSet* atk_object_real_ref_state_set
243 (AtkObject *object);
244 static void atk_object_real_set_name (AtkObject *object,
245 const gchar *name);
246 static void atk_object_real_set_description
247 (AtkObject *object,
248 const gchar *description);
249 static void atk_object_real_set_parent (AtkObject *object,
250 AtkObject *parent);
251 static void atk_object_real_set_role (AtkObject *object,
252 AtkRole role);
253 static void atk_object_notify (GObject *obj,
254 GParamSpec *pspec);
255 static const gchar* atk_object_real_get_object_locale
256 (AtkObject *object);
258 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
260 static gpointer parent_class = NULL;
262 static const gchar* const atk_object_name_property_name = "accessible-name";
263 static const gchar* const atk_object_name_property_description = "accessible-description";
264 static const gchar* const atk_object_name_property_parent = "accessible-parent";
265 static const gchar* const atk_object_name_property_value = "accessible-value";
266 static const gchar* const atk_object_name_property_role = "accessible-role";
267 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
268 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
269 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
270 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
271 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
272 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
273 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
274 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
275 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
276 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
278 static void
279 initialize_role_names ()
281 GTypeClass *enum_class;
282 GEnumValue *enum_value;
283 int i;
284 gchar *role_name = NULL;
286 if (role_names)
287 return;
289 role_names = g_ptr_array_new ();
290 enum_class = g_type_class_ref (ATK_TYPE_ROLE);
291 if (!G_IS_ENUM_CLASS(enum_class))
292 return;
294 for (i = 0; i < ATK_ROLE_LAST_DEFINED; i++)
296 enum_value = g_enum_get_value (G_ENUM_CLASS (enum_class), i);
297 role_name = g_strdup (enum_value->value_nick);
298 // We want the role names to be in the format "check button" and not "check-button"
299 _compact_name (role_name);
300 g_ptr_array_add (role_names, role_name);
303 g_type_class_unref (enum_class);
307 GType
308 atk_object_get_type (void)
310 static GType type = 0;
312 if (!type)
314 static const GTypeInfo typeInfo =
316 sizeof (AtkObjectClass),
317 (GBaseInitFunc) NULL,
318 (GBaseFinalizeFunc) NULL,
319 (GClassInitFunc) atk_object_class_init,
320 (GClassFinalizeFunc) NULL,
321 NULL,
322 sizeof (AtkObject),
324 (GInstanceInitFunc) atk_object_init,
326 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
328 return type;
331 static void
332 atk_object_class_init (AtkObjectClass *klass)
334 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
336 parent_class = g_type_class_peek_parent (klass);
338 gobject_class->set_property = atk_object_real_set_property;
339 gobject_class->get_property = atk_object_real_get_property;
340 gobject_class->finalize = atk_object_finalize;
341 gobject_class->notify = atk_object_notify;
343 klass->get_name = atk_object_real_get_name;
344 klass->get_description = atk_object_real_get_description;
345 klass->get_parent = atk_object_real_get_parent;
346 klass->get_n_children = NULL;
347 klass->ref_child = NULL;
348 klass->get_index_in_parent = NULL;
349 klass->ref_relation_set = atk_object_real_ref_relation_set;
350 klass->get_role = atk_object_real_get_role;
351 klass->get_layer = atk_object_real_get_layer;
352 klass->get_mdi_zorder = NULL;
353 klass->initialize = atk_object_real_initialize;
354 klass->ref_state_set = atk_object_real_ref_state_set;
355 klass->set_name = atk_object_real_set_name;
356 klass->set_description = atk_object_real_set_description;
357 klass->set_parent = atk_object_real_set_parent;
358 klass->set_role = atk_object_real_set_role;
359 klass->get_object_locale = atk_object_real_get_object_locale;
362 * We do not define default signal handlers here
364 klass->children_changed = NULL;
365 klass->focus_event = NULL;
366 klass->property_change = NULL;
367 klass->visible_data_changed = NULL;
368 klass->active_descendant_changed = NULL;
370 _gettext_initialization ();
372 g_object_class_install_property (gobject_class,
373 PROP_NAME,
374 g_param_spec_string (atk_object_name_property_name,
375 _("Accessible Name"),
376 _("Object instance’s name formatted for assistive technology access"),
377 NULL,
378 G_PARAM_READWRITE));
379 g_object_class_install_property (gobject_class,
380 PROP_DESCRIPTION,
381 g_param_spec_string (atk_object_name_property_description,
382 _("Accessible Description"),
383 _("Description of an object, formatted for assistive technology access"),
384 NULL,
385 G_PARAM_READWRITE));
386 g_object_class_install_property (gobject_class,
387 PROP_PARENT,
388 g_param_spec_object (atk_object_name_property_parent,
389 _("Accessible Parent"),
390 _("Parent of the current accessible as returned by atk_object_get_parent()"),
391 ATK_TYPE_OBJECT,
392 G_PARAM_READWRITE));
395 * AtkObject:accessible-value:
397 * Numeric value of this object, in case being and AtkValue.
399 * Deprecated: Since 2.12. Use atk_value_get_value_and_text() to get
400 * the value, and value-changed signal to be notified on their value
401 * changes.
403 g_object_class_install_property (gobject_class,
404 PROP_VALUE,
405 g_param_spec_double (atk_object_name_property_value,
406 _("Accessible Value"),
407 _("Is used to notify that the value has changed"),
408 0.0,
409 G_MAXDOUBLE,
410 0.0,
411 G_PARAM_READWRITE));
412 g_object_class_install_property (gobject_class,
413 PROP_ROLE,
414 g_param_spec_enum (atk_object_name_property_role,
415 _("Accessible Role"),
416 _("The accessible role of this object"),
417 ATK_TYPE_ROLE,
418 ATK_ROLE_UNKNOWN,
419 G_PARAM_READWRITE));
420 g_object_class_install_property (gobject_class,
421 PROP_LAYER,
422 g_param_spec_int (atk_object_name_property_component_layer,
423 _("Accessible Layer"),
424 _("The accessible layer of this object"),
426 G_MAXINT,
428 G_PARAM_READABLE));
429 g_object_class_install_property (gobject_class,
430 PROP_MDI_ZORDER,
431 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
432 _("Accessible MDI Value"),
433 _("The accessible MDI value of this object"),
434 G_MININT,
435 G_MAXINT,
436 G_MININT,
437 G_PARAM_READABLE));
440 * AtkObject:accessible-table-caption:
442 * Table caption.
444 * Deprecated: Since 1.3. Use table-caption-object instead.
446 g_object_class_install_property (gobject_class,
447 PROP_TABLE_CAPTION,
448 g_param_spec_string (atk_object_name_property_table_caption,
449 _("Accessible Table Caption"),
450 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
451 NULL,
452 G_PARAM_READWRITE));
454 * AtkObject:accessible-table-column-header:
456 * Accessible table column header.
458 * Deprecated: Since 2.12. Use atk_table_get_column_header() and
459 * atk_table_set_column_header() instead.
461 g_object_class_install_property (gobject_class,
462 PROP_TABLE_COLUMN_HEADER,
463 g_param_spec_object (atk_object_name_property_table_column_header,
464 _("Accessible Table Column Header"),
465 _("Is used to notify that the table column header has changed"),
466 ATK_TYPE_OBJECT,
467 G_PARAM_READWRITE));
470 * AtkObject:accessible-table-column-description:
472 * Accessible table column description.
474 * Deprecated: Since 2.12. Use atk_table_get_column_description()
475 * and atk_table_set_column_description() instead.
477 g_object_class_install_property (gobject_class,
478 PROP_TABLE_COLUMN_DESCRIPTION,
479 g_param_spec_string (atk_object_name_property_table_column_description,
480 _("Accessible Table Column Description"),
481 _("Is used to notify that the table column description has changed"),
482 NULL,
483 G_PARAM_READWRITE));
486 * AtkObject:accessible-table-row-header:
488 * Accessible table row header.
490 * Deprecated: Since 2.12. Use atk_table_get_row_header() and
491 * atk_table_set_row_header() instead.
493 g_object_class_install_property (gobject_class,
494 PROP_TABLE_ROW_HEADER,
495 g_param_spec_object (atk_object_name_property_table_row_header,
496 _("Accessible Table Row Header"),
497 _("Is used to notify that the table row header has changed"),
498 ATK_TYPE_OBJECT,
499 G_PARAM_READWRITE));
501 * AtkObject:accessible-table-row-description:
503 * Accessible table row description.
505 * Deprecated: Since 2.12. Use atk_table_get_row_description() and
506 * atk_table_set_row_description() instead.
508 g_object_class_install_property (gobject_class,
509 PROP_TABLE_ROW_DESCRIPTION,
510 g_param_spec_string (atk_object_name_property_table_row_description,
511 _("Accessible Table Row Description"),
512 _("Is used to notify that the table row description has changed"),
513 NULL,
514 G_PARAM_READWRITE));
515 g_object_class_install_property (gobject_class,
516 PROP_TABLE_SUMMARY,
517 g_param_spec_object (atk_object_name_property_table_summary,
518 _("Accessible Table Summary"),
519 _("Is used to notify that the table summary has changed"),
520 ATK_TYPE_OBJECT,
521 G_PARAM_READWRITE));
522 g_object_class_install_property (gobject_class,
523 PROP_TABLE_CAPTION_OBJECT,
524 g_param_spec_object (atk_object_name_property_table_caption_object,
525 _("Accessible Table Caption Object"),
526 _("Is used to notify that the table caption has changed"),
527 ATK_TYPE_OBJECT,
528 G_PARAM_READWRITE));
529 g_object_class_install_property (gobject_class,
530 PROP_HYPERTEXT_NUM_LINKS,
531 g_param_spec_int (atk_object_name_property_hypertext_num_links,
532 _("Number of Accessible Hypertext Links"),
533 _("The number of links which the current AtkHypertext has"),
535 G_MAXINT,
537 G_PARAM_READABLE));
540 * AtkObject::children-changed:
541 * @atkobject: the object which received the signal.
542 * @arg1: The index of the added or removed child. The value can be
543 * -1. This is used if the value is not known by the implementor
544 * when the child is added/removed or irrelevant.
545 * @arg2: A gpointer to the child AtkObject which was added or
546 * removed. If the child was removed, it is possible that it is not
547 * available for the implementor. In that case this pointer can be
548 * NULL.
550 * The signal "children-changed" is emitted when a child is added or
551 * removed form an object. It supports two details: "add" and
552 * "remove"
554 atk_object_signals[CHILDREN_CHANGED] =
555 g_signal_new ("children_changed",
556 G_TYPE_FROM_CLASS (klass),
557 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
558 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
559 NULL, NULL,
560 g_cclosure_marshal_VOID__UINT_POINTER,
561 G_TYPE_NONE,
562 2, G_TYPE_UINT, G_TYPE_POINTER);
565 * AtkObject::focus-event:
566 * @atkobject: the object which received the signal
567 * @arg1: a boolean value which indicates whether the object gained
568 * or lost focus.
570 * The signal "focus-event" is emitted when an object gained or lost
571 * focus.
573 * Deprecated: 2.9.4: Use the #AtkObject::state-change signal instead.
575 atk_object_signals[FOCUS_EVENT] =
576 g_signal_new ("focus_event",
577 G_TYPE_FROM_CLASS (klass),
578 G_SIGNAL_RUN_LAST,
579 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
580 NULL, NULL,
581 g_cclosure_marshal_VOID__BOOLEAN,
582 G_TYPE_NONE,
583 1, G_TYPE_BOOLEAN);
585 * AtkObject::property-change:
586 * @atkobject: the object which received the signal.
587 * @arg1: an #AtkPropertyValues containing the new value of the
588 * property which changed.
590 * The signal "property-change" is emitted when an object's property
591 * value changes. @arg1 contains an #AtkPropertyValues with the name
592 * and the new value of the property whose value has changed. Note
593 * that, as with GObject notify, getting this signal does not
594 * guarantee that the value of the property has actually changed; it
595 * may also be emitted when the setter of the property is called to
596 * reinstate the previous value.
598 * Toolkit implementor note: ATK implementors should use
599 * g_object_notify() to emit property-changed
600 * notifications. #AtkObject::property-changed is needed by the
601 * implementation of atk_add_global_event_listener() because GObject
602 * notify doesn't support emission hooks.
604 atk_object_signals[PROPERTY_CHANGE] =
605 g_signal_new ("property_change",
606 G_TYPE_FROM_CLASS (klass),
607 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
608 G_STRUCT_OFFSET (AtkObjectClass, property_change),
609 (GSignalAccumulator) NULL, NULL,
610 g_cclosure_marshal_VOID__POINTER,
611 G_TYPE_NONE, 1,
612 G_TYPE_POINTER);
615 * AtkObject::state-change:
616 * @atkobject: the object which received the signal.
617 * @arg1: The name of the state which has changed
618 * @arg2: A boolean which indicates whether the state has been set or unset.
620 * The "state-change" signal is emitted when an object's state
621 * changes. The detail value identifies the state type which has
622 * changed.
624 atk_object_signals[STATE_CHANGE] =
625 g_signal_new ("state_change",
626 G_TYPE_FROM_CLASS (klass),
627 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
628 G_STRUCT_OFFSET (AtkObjectClass, state_change),
629 (GSignalAccumulator) NULL, NULL,
630 atk_marshal_VOID__STRING_BOOLEAN,
631 G_TYPE_NONE, 2,
632 G_TYPE_STRING,
633 G_TYPE_BOOLEAN);
636 * AtkObject::visible-data-changed:
637 * @atkobject: the object which received the signal.
639 * The "visible-data-changed" signal is emitted when the visual
640 * appearance of the object changed.
642 atk_object_signals[VISIBLE_DATA_CHANGED] =
643 g_signal_new ("visible_data_changed",
644 G_TYPE_FROM_CLASS (klass),
645 G_SIGNAL_RUN_LAST,
646 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
647 (GSignalAccumulator) NULL, NULL,
648 g_cclosure_marshal_VOID__VOID,
649 G_TYPE_NONE, 0);
652 * AtkObject::active-descendant-changed:
653 * @atkobject: the object which received the signal.
654 * @arg1: the newly focused object.
656 * The "active-descendant-changed" signal is emitted by an object
657 * which has the state ATK_STATE_MANAGES_DESCENDANTS when the focus
658 * object in the object changes. For instance, a table will emit the
659 * signal when the cell in the table which has focus changes.
661 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
662 g_signal_new ("active_descendant_changed",
663 G_TYPE_FROM_CLASS (klass),
664 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
665 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
666 NULL, NULL,
667 g_cclosure_marshal_VOID__POINTER,
668 G_TYPE_NONE,
669 1, G_TYPE_POINTER);
672 static void
673 atk_object_init (AtkObject *accessible,
674 AtkObjectClass *klass)
676 accessible->name = NULL;
677 accessible->description = NULL;
678 accessible->accessible_parent = NULL;
679 accessible->relation_set = atk_relation_set_new();
680 accessible->role = ATK_ROLE_UNKNOWN;
683 static void
684 atk_implementor_default_init (AtkImplementorInterface *iface)
689 * atk_object_get_name:
690 * @accessible: an #AtkObject
692 * Gets the accessible name of the accessible.
694 * Returns: a character string representing the accessible name of the object.
696 const gchar*
697 atk_object_get_name (AtkObject *accessible)
699 AtkObjectClass *klass;
701 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
703 klass = ATK_OBJECT_GET_CLASS (accessible);
704 if (klass->get_name)
705 return (klass->get_name) (accessible);
706 else
707 return NULL;
711 * atk_object_get_description:
712 * @accessible: an #AtkObject
714 * Gets the accessible description of the accessible.
716 * Returns: a character string representing the accessible description
717 * of the accessible.
720 const gchar*
721 atk_object_get_description (AtkObject *accessible)
723 AtkObjectClass *klass;
725 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
727 klass = ATK_OBJECT_GET_CLASS (accessible);
728 if (klass->get_description)
729 return (klass->get_description) (accessible);
730 else
731 return NULL;
735 * atk_object_get_parent:
736 * @accessible: an #AtkObject
738 * Gets the accessible parent of the accessible. By default this is
739 * the one assigned with atk_object_set_parent(), but it is assumed
740 * that ATK implementors have ways to get the parent of the object
741 * without the need of assigning it manually with
742 * atk_object_set_parent(), and will return it with this method.
744 * If you are only interested on the parent assigned with
745 * atk_object_set_parent(), use atk_object_peek_parent().
747 * Returns: (transfer none): an #AtkObject representing the accessible
748 * parent of the accessible
750 AtkObject*
751 atk_object_get_parent (AtkObject *accessible)
753 AtkObjectClass *klass;
755 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
757 klass = ATK_OBJECT_GET_CLASS (accessible);
758 if (klass->get_parent)
759 return (klass->get_parent) (accessible);
760 else
761 return NULL;
765 * atk_object_peek_parent:
766 * @accessible: an #AtkObject
768 * Gets the accessible parent of the accessible, if it has been
769 * manually assigned with atk_object_set_parent. Otherwise, this
770 * function returns %NULL.
772 * This method is intended as an utility for ATK implementors, and not
773 * to be exposed to accessible tools. See atk_object_get_parent() for
774 * further reference.
776 * Returns: (transfer none): an #AtkObject representing the accessible
777 * parent of the accessible if assigned
779 AtkObject*
780 atk_object_peek_parent (AtkObject *accessible)
782 return accessible->accessible_parent;
786 * atk_object_get_n_accessible_children:
787 * @accessible: an #AtkObject
789 * Gets the number of accessible children of the accessible.
791 * Returns: an integer representing the number of accessible children
792 * of the accessible.
794 gint
795 atk_object_get_n_accessible_children (AtkObject *accessible)
797 AtkObjectClass *klass;
799 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
801 klass = ATK_OBJECT_GET_CLASS (accessible);
802 if (klass->get_n_children)
803 return (klass->get_n_children) (accessible);
804 else
805 return 0;
809 * atk_object_ref_accessible_child:
810 * @accessible: an #AtkObject
811 * @i: a gint representing the position of the child, starting from 0
813 * Gets a reference to the specified accessible child of the object.
814 * The accessible children are 0-based so the first accessible child is
815 * at index 0, the second at index 1 and so on.
817 * Returns: (transfer full): an #AtkObject representing the specified
818 * accessible child of the accessible.
820 AtkObject*
821 atk_object_ref_accessible_child (AtkObject *accessible,
822 gint i)
824 AtkObjectClass *klass;
826 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
828 klass = ATK_OBJECT_GET_CLASS (accessible);
829 if (klass->ref_child)
830 return (klass->ref_child) (accessible, i);
831 else
832 return NULL;
836 * atk_object_ref_relation_set:
837 * @accessible: an #AtkObject
839 * Gets the #AtkRelationSet associated with the object.
841 * Returns: (transfer full): an #AtkRelationSet representing the relation set
842 * of the object.
844 AtkRelationSet*
845 atk_object_ref_relation_set (AtkObject *accessible)
847 AtkObjectClass *klass;
849 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
851 klass = ATK_OBJECT_GET_CLASS (accessible);
852 if (klass->ref_relation_set)
853 return (klass->ref_relation_set) (accessible);
854 else
855 return NULL;
859 * atk_role_register:
860 * @name: a character string describing the new role.
862 * Registers the role specified by @name. @name must be a meaningful
863 * name. So it should not be empty, or consisting on whitespaces.
865 * Deprecated: Since 2.12. If your application/toolkit doesn't find a
866 * suitable role for a specific object defined at #AtkRole, please
867 * submit a bug in order to add a new role to the specification.
869 * Returns: an #AtkRole for the new role if added
870 * properly. ATK_ROLE_INVALID in case of error.
872 AtkRole
873 atk_role_register (const gchar *name)
875 gboolean valid = FALSE;
876 gint i = 0;
877 glong length = g_utf8_strlen (name, -1);
879 for (i=0; i < length; i++) {
880 if (name[i]!=' ') {
881 valid = TRUE;
882 break;
886 if (!valid)
887 return ATK_ROLE_INVALID;
889 if (!role_names)
890 initialize_role_names ();
892 g_ptr_array_add (role_names, g_strdup (name));
893 return role_names->len - 1;
897 * atk_object_get_role:
898 * @accessible: an #AtkObject
900 * Gets the role of the accessible.
902 * Returns: an #AtkRole which is the role of the accessible
904 AtkRole
905 atk_object_get_role (AtkObject *accessible)
907 AtkObjectClass *klass;
909 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
911 klass = ATK_OBJECT_GET_CLASS (accessible);
912 if (klass->get_role)
913 return (klass->get_role) (accessible);
914 else
915 return ATK_ROLE_UNKNOWN;
919 * atk_object_get_layer:
920 * @accessible: an #AtkObject
922 * Gets the layer of the accessible.
924 * Deprecated: Use atk_component_get_layer instead.
926 * Returns: an #AtkLayer which is the layer of the accessible
928 AtkLayer
929 atk_object_get_layer (AtkObject *accessible)
931 AtkObjectClass *klass;
933 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
935 klass = ATK_OBJECT_GET_CLASS (accessible);
936 if (klass->get_layer)
937 return (klass->get_layer) (accessible);
938 else
939 return ATK_LAYER_INVALID;
943 * atk_object_get_mdi_zorder:
944 * @accessible: an #AtkObject
946 * Gets the zorder of the accessible. The value G_MININT will be returned
947 * if the layer of the accessible is not ATK_LAYER_MDI.
949 * Deprecated: Use atk_component_get_mdi_zorder instead.
951 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
952 * which the component is shown in relation to other components in the same
953 * container.
956 gint
957 atk_object_get_mdi_zorder (AtkObject *accessible)
959 AtkObjectClass *klass;
961 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
963 klass = ATK_OBJECT_GET_CLASS (accessible);
964 if (klass->get_mdi_zorder)
965 return (klass->get_mdi_zorder) (accessible);
966 else
967 return G_MININT;
971 * atk_object_ref_state_set:
972 * @accessible: an #AtkObject
974 * Gets a reference to the state set of the accessible; the caller must
975 * unreference it when it is no longer needed.
977 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
978 * set of the accessible
980 AtkStateSet*
981 atk_object_ref_state_set (AtkObject *accessible)
983 AtkObjectClass *klass;
985 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
987 klass = ATK_OBJECT_GET_CLASS (accessible);
988 if (klass->ref_state_set)
989 return (klass->ref_state_set) (accessible);
990 else
991 return NULL;
995 * atk_object_get_index_in_parent:
996 * @accessible: an #AtkObject
998 * Gets the 0-based index of this accessible in its parent; returns -1 if the
999 * accessible does not have an accessible parent.
1001 * Returns: an integer which is the index of the accessible in its parent
1003 gint
1004 atk_object_get_index_in_parent (AtkObject *accessible)
1006 AtkObjectClass *klass;
1008 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
1010 klass = ATK_OBJECT_GET_CLASS (accessible);
1011 if (klass->get_index_in_parent)
1012 return (klass->get_index_in_parent) (accessible);
1013 else
1014 return -1;
1018 * atk_object_set_name:
1019 * @accessible: an #AtkObject
1020 * @name: a character string to be set as the accessible name
1022 * Sets the accessible name of the accessible. You can't set the name
1023 * to NULL. This is reserved for the initial value. In this aspect
1024 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
1025 * a empty value you can use "".
1027 void
1028 atk_object_set_name (AtkObject *accessible,
1029 const gchar *name)
1031 AtkObjectClass *klass;
1032 gboolean notify = FALSE;
1034 g_return_if_fail (ATK_IS_OBJECT (accessible));
1035 g_return_if_fail (name != NULL);
1037 klass = ATK_OBJECT_GET_CLASS (accessible);
1038 if (klass->set_name)
1040 /* Do not notify for initial name setting. See bug 665870 */
1041 notify = (accessible->name != NULL);
1043 (klass->set_name) (accessible, name);
1044 if (notify)
1045 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1050 * atk_object_set_description:
1051 * @accessible: an #AtkObject
1052 * @description: a character string to be set as the accessible description
1054 * Sets the accessible description of the accessible. You can't set
1055 * the description to NULL. This is reserved for the initial value. In
1056 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
1057 * the name to a empty value you can use "".
1059 void
1060 atk_object_set_description (AtkObject *accessible,
1061 const gchar *description)
1063 AtkObjectClass *klass;
1064 gboolean notify = FALSE;
1066 g_return_if_fail (ATK_IS_OBJECT (accessible));
1067 g_return_if_fail (description != NULL);
1069 klass = ATK_OBJECT_GET_CLASS (accessible);
1070 if (klass->set_description)
1072 /* Do not notify for initial name setting. See bug 665870 */
1073 notify = (accessible->description != NULL);
1075 (klass->set_description) (accessible, description);
1076 if (notify)
1077 g_object_notify (G_OBJECT (accessible),
1078 atk_object_name_property_description);
1083 * atk_object_set_parent:
1084 * @accessible: an #AtkObject
1085 * @parent: an #AtkObject to be set as the accessible parent
1087 * Sets the accessible parent of the accessible. @parent can be NULL.
1089 void
1090 atk_object_set_parent (AtkObject *accessible,
1091 AtkObject *parent)
1093 AtkObjectClass *klass;
1095 g_return_if_fail (ATK_IS_OBJECT (accessible));
1097 klass = ATK_OBJECT_GET_CLASS (accessible);
1098 if (klass->set_parent)
1100 (klass->set_parent) (accessible, parent);
1101 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1106 * atk_object_set_role:
1107 * @accessible: an #AtkObject
1108 * @role: an #AtkRole to be set as the role
1110 * Sets the role of the accessible.
1112 void
1113 atk_object_set_role (AtkObject *accessible,
1114 AtkRole role)
1116 AtkObjectClass *klass;
1117 AtkRole old_role;
1119 g_return_if_fail (ATK_IS_OBJECT (accessible));
1121 klass = ATK_OBJECT_GET_CLASS (accessible);
1122 if (klass->set_role)
1124 old_role = atk_object_get_role (accessible);
1125 if (old_role != role)
1127 (klass->set_role) (accessible, role);
1128 if (old_role != ATK_ROLE_UNKNOWN)
1129 /* Do not notify for initial role setting */
1130 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1136 * atk_object_connect_property_change_handler: (skip)
1137 * @accessible: an #AtkObject
1138 * @handler: a function to be called when a property changes its value
1140 * Deprecated: Since 2.12. Connect directly to property-change or
1141 * notify signals.
1143 * Returns: a #guint which is the handler id used in
1144 * atk_object_remove_property_change_handler()
1146 guint
1147 atk_object_connect_property_change_handler (AtkObject *accessible,
1148 AtkPropertyChangeHandler *handler)
1150 AtkObjectClass *klass;
1152 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1153 g_return_val_if_fail ((handler != NULL), 0);
1155 klass = ATK_OBJECT_GET_CLASS (accessible);
1156 if (klass->connect_property_change_handler)
1157 return (klass->connect_property_change_handler) (accessible, handler);
1158 else
1159 return 0;
1163 * atk_object_remove_property_change_handler:
1164 * @accessible: an #AtkObject
1165 * @handler_id: a guint which identifies the handler to be removed.
1167 * Deprecated: Since 2.12.
1169 * Removes a property change handler.
1171 void
1172 atk_object_remove_property_change_handler (AtkObject *accessible,
1173 guint handler_id)
1175 AtkObjectClass *klass;
1177 g_return_if_fail (ATK_IS_OBJECT (accessible));
1179 klass = ATK_OBJECT_GET_CLASS (accessible);
1180 if (klass->remove_property_change_handler)
1181 (klass->remove_property_change_handler) (accessible, handler_id);
1185 * atk_object_notify_state_change:
1186 * @accessible: an #AtkObject
1187 * @state: an #AtkState whose state is changed
1188 * @value: a gboolean which indicates whether the state is being set on or off
1190 * Emits a state-change signal for the specified state.
1192 * Note that as a general rule when the state of an existing object changes,
1193 * emitting a notification is expected.
1195 void
1196 atk_object_notify_state_change (AtkObject *accessible,
1197 AtkState state,
1198 gboolean value)
1200 const gchar* name;
1202 g_return_if_fail (ATK_IS_OBJECT (accessible));
1204 name = atk_state_type_get_name (state);
1205 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1206 g_quark_from_string (name),
1207 name, value, NULL);
1211 * atk_implementor_ref_accessible:
1212 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1213 * if a non-null return value is required.
1215 * Gets a reference to an object's #AtkObject implementation, if
1216 * the object implements #AtkObjectIface
1218 * Returns: (transfer full): a reference to an object's #AtkObject
1219 * implementation
1221 AtkObject *
1222 atk_implementor_ref_accessible (AtkImplementor *implementor)
1224 AtkImplementorIface *iface;
1225 AtkObject *accessible = NULL;
1227 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1229 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1231 if (iface != NULL)
1232 accessible = iface->ref_accessible (implementor);
1234 g_return_val_if_fail ((accessible != NULL), NULL);
1236 return accessible;
1241 * atk_object_get_attributes:
1242 * @accessible: An #AtkObject.
1244 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1245 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1246 * as distinct from strongly-typed object data available via other get/set methods.
1247 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1249 * Since: 1.12
1251 * Returns: (transfer full): an #AtkAttributeSet consisting of all
1252 * explicit properties/annotations applied to the object, or an empty
1253 * set if the object has no name-value pair attributes assigned to
1254 * it. This #atkattributeset should be freed by a call to
1255 * atk_attribute_set_free().
1257 AtkAttributeSet *
1258 atk_object_get_attributes (AtkObject *accessible)
1260 AtkObjectClass *klass;
1262 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1264 klass = ATK_OBJECT_GET_CLASS (accessible);
1265 if (klass->get_attributes)
1266 return (klass->get_attributes) (accessible);
1267 else
1268 return NULL;
1272 static AtkRelationSet*
1273 atk_object_real_ref_relation_set (AtkObject *accessible)
1275 g_return_val_if_fail (accessible->relation_set, NULL);
1276 g_object_ref (accessible->relation_set);
1278 return accessible->relation_set;
1281 static void
1282 atk_object_real_set_property (GObject *object,
1283 guint prop_id,
1284 const GValue *value,
1285 GParamSpec *pspec)
1287 AtkObject *accessible;
1289 accessible = ATK_OBJECT (object);
1291 switch (prop_id)
1293 case PROP_NAME:
1294 atk_object_set_name (accessible, g_value_get_string (value));
1295 break;
1296 case PROP_DESCRIPTION:
1297 atk_object_set_description (accessible, g_value_get_string (value));
1298 break;
1299 case PROP_ROLE:
1300 atk_object_set_role (accessible, g_value_get_enum (value));
1301 break;
1302 case PROP_PARENT:
1303 atk_object_set_parent (accessible, g_value_get_object (value));
1304 break;
1305 case PROP_VALUE:
1306 if (ATK_IS_VALUE (accessible))
1307 atk_value_set_current_value (ATK_VALUE (accessible), value);
1308 break;
1309 case PROP_TABLE_SUMMARY:
1310 if (ATK_IS_TABLE (accessible))
1311 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1312 break;
1313 case PROP_TABLE_CAPTION_OBJECT:
1314 if (ATK_IS_TABLE (accessible))
1315 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1316 break;
1317 default:
1318 break;
1322 static void
1323 atk_object_real_get_property (GObject *object,
1324 guint prop_id,
1325 GValue *value,
1326 GParamSpec *pspec)
1328 AtkObject *accessible;
1330 accessible = ATK_OBJECT (object);
1332 switch (prop_id)
1334 case PROP_NAME:
1335 g_value_set_string (value, atk_object_get_name (accessible));
1336 break;
1337 case PROP_DESCRIPTION:
1338 g_value_set_string (value, atk_object_get_description (accessible));
1339 break;
1340 case PROP_ROLE:
1341 g_value_set_enum (value, atk_object_get_role (accessible));
1342 break;
1343 case PROP_LAYER:
1344 if (ATK_IS_COMPONENT (accessible))
1345 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1346 break;
1347 case PROP_MDI_ZORDER:
1348 if (ATK_IS_COMPONENT (accessible))
1349 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1350 break;
1351 case PROP_PARENT:
1352 g_value_set_object (value, atk_object_get_parent (accessible));
1353 break;
1354 case PROP_VALUE:
1355 if (ATK_IS_VALUE (accessible))
1356 atk_value_get_current_value (ATK_VALUE (accessible), value);
1357 break;
1358 case PROP_TABLE_SUMMARY:
1359 if (ATK_IS_TABLE (accessible))
1360 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1361 break;
1362 case PROP_TABLE_CAPTION_OBJECT:
1363 if (ATK_IS_TABLE (accessible))
1364 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1365 break;
1366 case PROP_HYPERTEXT_NUM_LINKS:
1367 if (ATK_IS_HYPERTEXT (accessible))
1368 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1369 break;
1370 default:
1371 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1372 break;
1376 static void
1377 atk_object_finalize (GObject *object)
1379 AtkObject *accessible;
1381 g_return_if_fail (ATK_IS_OBJECT (object));
1383 accessible = ATK_OBJECT (object);
1385 g_free (accessible->name);
1386 g_free (accessible->description);
1389 * Free memory allocated for relation set if it have been allocated.
1391 if (accessible->relation_set)
1392 g_object_unref (accessible->relation_set);
1394 if (accessible->accessible_parent)
1395 g_object_unref (accessible->accessible_parent);
1397 G_OBJECT_CLASS (parent_class)->finalize (object);
1400 static const gchar*
1401 atk_object_real_get_name (AtkObject *object)
1403 return object->name;
1406 static const gchar*
1407 atk_object_real_get_description (AtkObject *object)
1409 return object->description;
1412 static AtkObject*
1413 atk_object_real_get_parent (AtkObject *object)
1415 return atk_object_peek_parent (object);
1418 static AtkRole
1419 atk_object_real_get_role (AtkObject *object)
1421 return object->role;
1424 static AtkLayer
1425 atk_object_real_get_layer (AtkObject *object)
1427 return object->layer;
1430 static AtkStateSet*
1431 atk_object_real_ref_state_set (AtkObject *accessible)
1433 AtkStateSet *state_set;
1434 AtkObject *focus_object;
1436 state_set = atk_state_set_new ();
1438 focus_object = atk_get_focus_object ();
1439 if (focus_object == accessible)
1440 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1442 return state_set;
1445 static void
1446 atk_object_real_set_name (AtkObject *object,
1447 const gchar *name)
1449 g_free (object->name);
1450 object->name = g_strdup (name);
1453 static void
1454 atk_object_real_set_description (AtkObject *object,
1455 const gchar *description)
1457 g_free (object->description);
1458 object->description = g_strdup (description);
1461 static void
1462 atk_object_real_set_parent (AtkObject *object,
1463 AtkObject *parent)
1465 if (object->accessible_parent)
1466 g_object_unref (object->accessible_parent);
1468 object->accessible_parent = parent;
1469 if (object->accessible_parent)
1470 g_object_ref (object->accessible_parent);
1473 static void
1474 atk_object_real_set_role (AtkObject *object,
1475 AtkRole role)
1477 object->role = role;
1481 * atk_object_initialize:
1482 * @accessible: a #AtkObject
1483 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1485 * This function is called when implementing subclasses of #AtkObject.
1486 * It does initialization required for the new object. It is intended
1487 * that this function should called only in the ..._new() functions used
1488 * to create an instance of a subclass of #AtkObject
1490 void
1491 atk_object_initialize (AtkObject *accessible,
1492 gpointer data)
1494 AtkObjectClass *klass;
1496 g_return_if_fail (ATK_IS_OBJECT (accessible));
1498 klass = ATK_OBJECT_GET_CLASS (accessible);
1499 if (klass->initialize)
1500 klass->initialize (accessible, data);
1504 * This function is a signal handler for notify signal which gets emitted
1505 * when a property changes value.
1507 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1508 * signal which causes the user specified AtkPropertyChangeHandler
1509 * to be called.
1511 static void
1512 atk_object_notify (GObject *obj,
1513 GParamSpec *pspec)
1515 AtkPropertyValues values = { NULL, };
1517 g_value_init (&values.new_value, pspec->value_type);
1518 g_object_get_property (obj, pspec->name, &values.new_value);
1519 values.property_name = pspec->name;
1520 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1521 g_quark_from_string (pspec->name),
1522 &values, NULL);
1523 g_value_unset (&values.new_value);
1527 * atk_role_get_name:
1528 * @role: The #AtkRole whose name is required
1530 * Gets the description string describing the #AtkRole @role.
1532 * Returns: the string describing the AtkRole
1534 const gchar*
1535 atk_role_get_name (AtkRole role)
1537 g_return_val_if_fail (role >= 0, NULL);
1539 if (!role_names)
1540 initialize_role_names ();
1542 if (role < role_names->len)
1543 return g_ptr_array_index (role_names, role);
1545 return NULL;
1549 * atk_role_get_localized_name:
1550 * @role: The #AtkRole whose localized name is required
1552 * Gets the localized description string describing the #AtkRole @role.
1554 * Returns: the localized string describing the AtkRole
1556 const gchar*
1557 atk_role_get_localized_name (AtkRole role)
1559 _gettext_initialization ();
1561 return dgettext (GETTEXT_PACKAGE, atk_role_get_name (role));
1564 static const gchar*
1565 atk_object_real_get_object_locale (AtkObject *object)
1567 return setlocale (LC_MESSAGES, NULL);
1571 * atk_object_get_object_locale:
1572 * @accessible: an #AtkObject
1574 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
1575 * of @accessible.
1577 * Since: 2.8
1579 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
1580 * locale of @accessible.
1582 const gchar*
1583 atk_object_get_object_locale (AtkObject *accessible)
1585 AtkObjectClass *klass;
1587 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1589 klass = ATK_OBJECT_GET_CLASS (accessible);
1590 if (klass->get_object_locale)
1591 return (klass->get_object_locale) (accessible);
1592 else
1593 return NULL;
1598 * atk_role_for_name:
1599 * @name: a string which is the (non-localized) name of an ATK role.
1601 * Get the #AtkRole type corresponding to a rolew name.
1603 * Returns: the #AtkRole enumerated type corresponding to the specified name,
1604 * or #ATK_ROLE_INVALID if no matching role is found.
1606 AtkRole
1607 atk_role_for_name (const gchar *name)
1609 AtkRole role = ATK_ROLE_INVALID;
1610 gint i;
1612 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1614 if (!role_names)
1615 initialize_role_names ();
1617 for (i = 0; i < role_names->len; i++)
1619 gchar *role_name = (gchar *)g_ptr_array_index (role_names, i);
1621 g_return_val_if_fail (role_name, ATK_ROLE_INVALID);
1623 if (strcmp (name, role_name) == 0)
1625 role = i;
1626 break;
1630 return role;
1634 * atk_object_add_relationship:
1635 * @object: The #AtkObject to which an AtkRelation is to be added.
1636 * @relationship: The #AtkRelationType of the relation
1637 * @target: The #AtkObject which is to be the target of the relation.
1639 * Adds a relationship of the specified type with the specified target.
1641 * Returns: TRUE if the relationship is added.
1643 gboolean
1644 atk_object_add_relationship (AtkObject *object,
1645 AtkRelationType relationship,
1646 AtkObject *target)
1648 AtkObject *array[1];
1649 AtkRelation *relation;
1651 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1652 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1654 if (atk_relation_set_contains_target (object->relation_set,
1655 relationship, target))
1656 return FALSE;
1658 array[0] = target;
1659 relation = atk_relation_new (array, 1, relationship);
1660 atk_relation_set_add (object->relation_set, relation);
1661 g_object_unref (relation);
1663 return TRUE;
1667 * atk_object_remove_relationship:
1668 * @object: The #AtkObject from which an AtkRelation is to be removed.
1669 * @relationship: The #AtkRelationType of the relation
1670 * @target: The #AtkObject which is the target of the relation to be removed.
1672 * Removes a relationship of the specified type with the specified target.
1674 * Returns: TRUE if the relationship is removed.
1676 gboolean
1677 atk_object_remove_relationship (AtkObject *object,
1678 AtkRelationType relationship,
1679 AtkObject *target)
1681 gboolean ret = FALSE;
1682 AtkRelation *relation;
1683 GPtrArray *array;
1685 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1686 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1688 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1690 if (relation)
1692 ret = atk_relation_remove_target (relation, target);
1693 array = atk_relation_get_target (relation);
1694 if (!array || array->len == 0)
1695 atk_relation_set_remove (object->relation_set, relation);
1697 return ret;
1700 static void
1701 atk_object_real_initialize (AtkObject *accessible,
1702 gpointer data)
1704 return;