Enable the building of introspection files for Visual C++ builds
[atk.git] / atk / atkobject.c
blobea0df36cdac4edd7aad339327d442396c4e578ce
1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include <string.h>
21 #include <locale.h>
23 #include <glib-object.h>
25 #ifdef G_OS_WIN32
26 #define STRICT
27 #include <windows.h>
28 #undef STRICT
29 #undef FOCUS_EVENT /* <windows.h> pollutes the namespace
30 * like a six hundred pound gorilla */
31 #endif
33 #include "atk.h"
34 #include "atkmarshal.h"
35 #include "atk-enum-types.h"
36 #include "atkintl.h"
38 static GPtrArray *extra_roles = NULL;
40 enum
42 PROP_0, /* gobject convention */
44 PROP_NAME,
45 PROP_DESCRIPTION,
46 PROP_PARENT, /* ancestry has changed */
47 PROP_VALUE,
48 PROP_ROLE,
49 PROP_LAYER,
50 PROP_MDI_ZORDER,
51 PROP_TABLE_CAPTION,
52 PROP_TABLE_COLUMN_DESCRIPTION,
53 PROP_TABLE_COLUMN_HEADER,
54 PROP_TABLE_ROW_DESCRIPTION,
55 PROP_TABLE_ROW_HEADER,
56 PROP_TABLE_SUMMARY,
57 PROP_TABLE_CAPTION_OBJECT,
58 PROP_HYPERTEXT_NUM_LINKS,
59 PROP_LAST /* gobject convention */
62 enum {
63 CHILDREN_CHANGED,
64 FOCUS_EVENT,
65 PROPERTY_CHANGE,
66 STATE_CHANGE,
67 VISIBLE_DATA_CHANGED,
68 ACTIVE_DESCENDANT_CHANGED,
70 LAST_SIGNAL
73 /* These are listed here for extraction by intltool */
74 #if 0
75 N_("invalid")
76 N_("accelerator label")
77 N_("alert")
78 N_("animation")
79 N_("arrow")
80 N_("calendar")
81 N_("canvas")
82 N_("check box")
83 N_("check menu item")
84 N_("color chooser")
85 N_("column header")
86 N_("combo box")
87 N_("dateeditor")
88 N_("desktop icon")
89 N_("desktop frame")
90 N_("dial")
91 N_("dialog")
92 N_("directory pane")
93 N_("drawing area")
94 N_("file chooser")
95 N_("filler")
96 /* I know it looks wrong but that is what Java returns */
97 N_("fontchooser")
98 N_("frame")
99 N_("glass pane")
100 N_("html container")
101 N_("icon")
102 N_("image")
103 N_("internal frame")
104 N_("label")
105 N_("layered pane")
106 N_("list")
107 N_("list item")
108 N_("menu")
109 N_("menu bar")
110 N_("menu item")
111 N_("option pane")
112 N_("page tab")
113 N_("page tab list")
114 N_("panel")
115 N_("password text")
116 N_("popup menu")
117 N_("progress bar")
118 N_("push button")
119 N_("radio button")
120 N_("radio menu item")
121 N_("root pane")
122 N_("row header")
123 N_("scroll bar")
124 N_("scroll pane")
125 N_("separator")
126 N_("slider")
127 N_("split pane")
128 N_("spin button")
129 N_("statusbar")
130 N_("table")
131 N_("table cell")
132 N_("table column header")
133 N_("table row header")
134 N_("tear off menu item")
135 N_("terminal")
136 N_("text")
137 N_("toggle button")
138 N_("tool bar")
139 N_("tool tip")
140 N_("tree")
141 N_("tree table")
142 N_("unknown")
143 N_("viewport")
144 N_("window")
145 N_("header")
146 N_("footer")
147 N_("paragraph")
148 N_("ruler")
149 N_("application")
150 N_("autocomplete")
151 N_("edit bar")
152 N_("embedded component")
153 N_("entry")
154 N_("chart")
155 N_("caption")
156 N_("document frame")
157 N_("heading")
158 N_("page")
159 N_("section")
160 N_("redundant object")
161 N_("form")
162 N_("link")
163 N_("input method window")
164 N_("table row")
165 N_("tree item")
166 N_("document spreadsheet")
167 N_("document presentation")
168 N_("document text")
169 N_("document web")
170 N_("document email")
171 N_("comment")
172 N_("list box")
173 N_("grouping")
174 N_("image map")
175 N_("notification")
176 N_("info bar")
177 #endif /* 0 */
179 static const char roles[] =
180 "invalid\0"
181 "accelerator label\0"
182 "alert\0"
183 "animation\0"
184 "arrow\0"
185 "calendar\0"
186 "canvas\0"
187 "check box\0"
188 "check menu item\0"
189 "color chooser\0"
190 "column header\0"
191 "combo box\0"
192 "dateeditor\0"
193 "desktop icon\0"
194 "desktop frame\0"
195 "dial\0"
196 "dialog\0"
197 "directory pane\0"
198 "drawing area\0"
199 "file chooser\0"
200 "filler\0"
201 "fontchooser\0"
202 "frame\0"
203 "glass pane\0"
204 "html container\0"
205 "icon\0"
206 "image\0"
207 "internal frame\0"
208 "label\0"
209 "layered pane\0"
210 "list\0"
211 "list item\0"
212 "menu\0"
213 "menu bar\0"
214 "menu item\0"
215 "option pane\0"
216 "page tab\0"
217 "page tab list\0"
218 "panel\0"
219 "password text\0"
220 "popup menu\0"
221 "progress bar\0"
222 "push button\0"
223 "radio button\0"
224 "radio menu item\0"
225 "root pane\0"
226 "row header\0"
227 "scroll bar\0"
228 "scroll pane\0"
229 "separator\0"
230 "slider\0"
231 "split pane\0"
232 "spin button\0"
233 "statusbar\0"
234 "table\0"
235 "table cell\0"
236 "table column header\0"
237 "table row header\0"
238 "tear off menu item\0"
239 "terminal\0"
240 "text\0"
241 "toggle button\0"
242 "tool bar\0"
243 "tool tip\0"
244 "tree\0"
245 "tree table\0"
246 "unknown\0"
247 "viewport\0"
248 "window\0"
249 "header\0"
250 "footer\0"
251 "paragraph\0"
252 "ruler\0"
253 "application\0"
254 "autocomplete\0"
255 "edit bar\0"
256 "embedded component\0"
257 "entry\0"
258 "chart\0"
259 "caption\0"
260 "document frame\0"
261 "heading\0"
262 "page\0"
263 "section\0"
264 "redundant object\0"
265 "form\0"
266 "link\0"
267 "input method window\0"
268 "table row\0"
269 "tree item\0"
270 "document spreadsheet\0"
271 "document presentation\0"
272 "document text\0"
273 "document web\0"
274 "document email\0"
275 "comment\0"
276 "list box\0"
277 "grouping\0"
278 "image map\0"
279 "notification\0"
280 "info bar\0"
281 "level bar\0";
283 static const guint16 roles_offsets[] = {
284 0, 8, 26, 32, 42, 48, 57, 64,
285 74, 90, 104, 118, 128, 139, 152, 166,
286 171, 178, 193, 206, 219, 226, 238, 244,
287 255, 270, 275, 281, 296, 302, 315, 320,
288 330, 335, 344, 354, 366, 375, 389, 395,
289 409, 420, 433, 445, 458, 474, 484, 495,
290 506, 518, 528, 535, 546, 558, 568, 574,
291 585, 605, 622, 641, 650, 655, 669, 678,
292 687, 692, 703, 711, 720, 727, 734, 741,
293 751, 757, 769, 782, 791, 810, 816, 822,
294 830, 845, 853, 858, 866, 883, 888, 893,
295 913, 923, 933, 954, 976, 990, 1003, 1018,
296 1026, 1035, 1044, 1054, 1067, 1075
299 /* This is a static assertion */
300 typedef int _assert_roles_num[(G_N_ELEMENTS (roles_offsets) == ATK_ROLE_LAST_DEFINED) ? 1 : -1];
302 static void atk_object_class_init (AtkObjectClass *klass);
303 static void atk_object_init (AtkObject *accessible,
304 AtkObjectClass *klass);
305 static AtkRelationSet* atk_object_real_ref_relation_set
306 (AtkObject *accessible);
307 static void atk_object_real_initialize (AtkObject *accessible,
308 gpointer data);
309 static void atk_object_real_set_property (GObject *object,
310 guint prop_id,
311 const GValue *value,
312 GParamSpec *pspec);
313 static void atk_object_real_get_property (GObject *object,
314 guint prop_id,
315 GValue *value,
316 GParamSpec *pspec);
317 static void atk_object_finalize (GObject *object);
318 static const gchar* atk_object_real_get_name (AtkObject *object);
319 static const gchar* atk_object_real_get_description
320 (AtkObject *object);
321 static AtkObject* atk_object_real_get_parent (AtkObject *object);
322 static AtkRole atk_object_real_get_role (AtkObject *object);
323 static AtkLayer atk_object_real_get_layer (AtkObject *object);
324 static AtkStateSet* atk_object_real_ref_state_set
325 (AtkObject *object);
326 static void atk_object_real_set_name (AtkObject *object,
327 const gchar *name);
328 static void atk_object_real_set_description
329 (AtkObject *object,
330 const gchar *description);
331 static void atk_object_real_set_parent (AtkObject *object,
332 AtkObject *parent);
333 static void atk_object_real_set_role (AtkObject *object,
334 AtkRole role);
335 static guint atk_object_real_connect_property_change_handler
336 (AtkObject *obj,
337 AtkPropertyChangeHandler
338 *handler);
339 static void atk_object_real_remove_property_change_handler
340 (AtkObject *obj,
341 guint handler_id);
342 static void atk_object_notify (GObject *obj,
343 GParamSpec *pspec);
344 static const gchar* atk_object_real_get_object_locale
345 (AtkObject *object);
347 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
349 static gpointer parent_class = NULL;
351 static const gchar* const atk_object_name_property_name = "accessible-name";
352 static const gchar* const atk_object_name_property_description = "accessible-description";
353 static const gchar* const atk_object_name_property_parent = "accessible-parent";
354 static const gchar* const atk_object_name_property_value = "accessible-value";
355 static const gchar* const atk_object_name_property_role = "accessible-role";
356 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
357 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
358 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
359 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
360 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
361 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
362 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
363 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
364 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
365 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
367 #ifdef G_OS_WIN32
369 static HMODULE atk_dll;
371 BOOL WINAPI
372 DllMain (HINSTANCE hinstDLL,
373 DWORD fdwReason,
374 LPVOID lpvReserved)
376 switch (fdwReason)
378 case DLL_PROCESS_ATTACH:
379 atk_dll = (HMODULE) hinstDLL;
380 break;
383 return TRUE;
386 static const char *
387 get_atk_locale_dir (void)
389 static gchar *atk_localedir = NULL;
391 if (!atk_localedir)
393 const gchar *p;
394 gchar *root, *temp;
396 /* ATK_LOCALEDIR might end in either /lib/locale or
397 * /share/locale. Scan for that slash.
399 p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
400 while (*--p != '/')
402 while (*--p != '/')
405 root = g_win32_get_package_installation_directory_of_module (atk_dll);
406 temp = g_build_filename (root, p, NULL);
407 g_free (root);
409 /* atk_localedir is passed to bindtextdomain() which isn't
410 * UTF-8-aware.
412 atk_localedir = g_win32_locale_filename_from_utf8 (temp);
413 g_free (temp);
415 return atk_localedir;
418 #undef ATK_LOCALEDIR
420 #define ATK_LOCALEDIR get_atk_locale_dir()
422 #endif
424 static void
425 gettext_initialization (void)
427 #ifdef ENABLE_NLS
428 static gboolean gettext_initialized = FALSE;
430 if (!gettext_initialized)
432 const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
434 gettext_initialized = TRUE;
435 if (dir == NULL)
436 dir = ATK_LOCALEDIR;
438 bindtextdomain (GETTEXT_PACKAGE, dir);
439 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
440 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
441 #endif
443 #endif
446 GType
447 atk_object_get_type (void)
449 static GType type = 0;
451 if (!type)
453 static const GTypeInfo typeInfo =
455 sizeof (AtkObjectClass),
456 (GBaseInitFunc) NULL,
457 (GBaseFinalizeFunc) NULL,
458 (GClassInitFunc) atk_object_class_init,
459 (GClassFinalizeFunc) NULL,
460 NULL,
461 sizeof (AtkObject),
463 (GInstanceInitFunc) atk_object_init,
465 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
467 return type;
470 static void
471 atk_object_class_init (AtkObjectClass *klass)
473 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
475 parent_class = g_type_class_peek_parent (klass);
477 gobject_class->set_property = atk_object_real_set_property;
478 gobject_class->get_property = atk_object_real_get_property;
479 gobject_class->finalize = atk_object_finalize;
480 gobject_class->notify = atk_object_notify;
482 klass->get_name = atk_object_real_get_name;
483 klass->get_description = atk_object_real_get_description;
484 klass->get_parent = atk_object_real_get_parent;
485 klass->get_n_children = NULL;
486 klass->ref_child = NULL;
487 klass->get_index_in_parent = NULL;
488 klass->ref_relation_set = atk_object_real_ref_relation_set;
489 klass->get_role = atk_object_real_get_role;
490 klass->get_layer = atk_object_real_get_layer;
491 klass->get_mdi_zorder = NULL;
492 klass->initialize = atk_object_real_initialize;
493 klass->ref_state_set = atk_object_real_ref_state_set;
494 klass->set_name = atk_object_real_set_name;
495 klass->set_description = atk_object_real_set_description;
496 klass->set_parent = atk_object_real_set_parent;
497 klass->set_role = atk_object_real_set_role;
498 klass->connect_property_change_handler =
499 atk_object_real_connect_property_change_handler;
500 klass->remove_property_change_handler =
501 atk_object_real_remove_property_change_handler;
502 klass->get_object_locale = atk_object_real_get_object_locale;
505 * We do not define default signal handlers here
507 klass->children_changed = NULL;
508 klass->focus_event = NULL;
509 klass->property_change = NULL;
510 klass->visible_data_changed = NULL;
511 klass->active_descendant_changed = NULL;
513 gettext_initialization ();
515 g_object_class_install_property (gobject_class,
516 PROP_NAME,
517 g_param_spec_string (atk_object_name_property_name,
518 _("Accessible Name"),
519 _("Object instance\'s name formatted for assistive technology access"),
520 NULL,
521 G_PARAM_READWRITE));
522 g_object_class_install_property (gobject_class,
523 PROP_DESCRIPTION,
524 g_param_spec_string (atk_object_name_property_description,
525 _("Accessible Description"),
526 _("Description of an object, formatted for assistive technology access"),
527 NULL,
528 G_PARAM_READWRITE));
529 g_object_class_install_property (gobject_class,
530 PROP_PARENT,
531 g_param_spec_object (atk_object_name_property_parent,
532 _("Accessible Parent"),
533 _("Is used to notify that the parent has changed"),
534 ATK_TYPE_OBJECT,
535 G_PARAM_READWRITE));
536 g_object_class_install_property (gobject_class,
537 PROP_VALUE,
538 g_param_spec_double (atk_object_name_property_value,
539 _("Accessible Value"),
540 _("Is used to notify that the value has changed"),
541 0.0,
542 G_MAXDOUBLE,
543 0.0,
544 G_PARAM_READWRITE));
545 g_object_class_install_property (gobject_class,
546 PROP_ROLE,
547 g_param_spec_int (atk_object_name_property_role,
548 _("Accessible Role"),
549 _("The accessible role of this object"),
551 G_MAXINT,
552 ATK_ROLE_UNKNOWN,
553 G_PARAM_READWRITE));
554 g_object_class_install_property (gobject_class,
555 PROP_LAYER,
556 g_param_spec_int (atk_object_name_property_component_layer,
557 _("Accessible Layer"),
558 _("The accessible layer of this object"),
560 G_MAXINT,
562 G_PARAM_READABLE));
563 g_object_class_install_property (gobject_class,
564 PROP_MDI_ZORDER,
565 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
566 _("Accessible MDI Value"),
567 _("The accessible MDI value of this object"),
568 G_MININT,
569 G_MAXINT,
570 G_MININT,
571 G_PARAM_READABLE));
572 g_object_class_install_property (gobject_class,
573 PROP_TABLE_CAPTION,
574 g_param_spec_string (atk_object_name_property_table_caption,
575 _("Accessible Table Caption"),
576 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
577 NULL,
578 G_PARAM_READWRITE));
579 g_object_class_install_property (gobject_class,
580 PROP_TABLE_COLUMN_HEADER,
581 g_param_spec_object (atk_object_name_property_table_column_header,
582 _("Accessible Table Column Header"),
583 _("Is used to notify that the table column header has changed"),
584 ATK_TYPE_OBJECT,
585 G_PARAM_READWRITE));
586 g_object_class_install_property (gobject_class,
587 PROP_TABLE_COLUMN_DESCRIPTION,
588 g_param_spec_string (atk_object_name_property_table_column_description,
589 _("Accessible Table Column Description"),
590 _("Is used to notify that the table column description has changed"),
591 NULL,
592 G_PARAM_READWRITE));
593 g_object_class_install_property (gobject_class,
594 PROP_TABLE_ROW_HEADER,
595 g_param_spec_object (atk_object_name_property_table_row_header,
596 _("Accessible Table Row Header"),
597 _("Is used to notify that the table row header has changed"),
598 ATK_TYPE_OBJECT,
599 G_PARAM_READWRITE));
600 g_object_class_install_property (gobject_class,
601 PROP_TABLE_ROW_DESCRIPTION,
602 g_param_spec_string (atk_object_name_property_table_row_description,
603 _("Accessible Table Row Description"),
604 _("Is used to notify that the table row description has changed"),
605 NULL,
606 G_PARAM_READWRITE));
607 g_object_class_install_property (gobject_class,
608 PROP_TABLE_SUMMARY,
609 g_param_spec_object (atk_object_name_property_table_summary,
610 _("Accessible Table Summary"),
611 _("Is used to notify that the table summary has changed"),
612 ATK_TYPE_OBJECT,
613 G_PARAM_READWRITE));
614 g_object_class_install_property (gobject_class,
615 PROP_TABLE_CAPTION_OBJECT,
616 g_param_spec_object (atk_object_name_property_table_caption_object,
617 _("Accessible Table Caption Object"),
618 _("Is used to notify that the table caption has changed"),
619 ATK_TYPE_OBJECT,
620 G_PARAM_READWRITE));
621 g_object_class_install_property (gobject_class,
622 PROP_HYPERTEXT_NUM_LINKS,
623 g_param_spec_int (atk_object_name_property_hypertext_num_links,
624 _("Number of Accessible Hypertext Links"),
625 _("The number of links which the current AtkHypertext has"),
627 G_MAXINT,
629 G_PARAM_READABLE));
630 atk_object_signals[CHILDREN_CHANGED] =
631 g_signal_new ("children_changed",
632 G_TYPE_FROM_CLASS (klass),
633 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
634 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
635 NULL, NULL,
636 g_cclosure_marshal_VOID__UINT_POINTER,
637 G_TYPE_NONE,
638 2, G_TYPE_UINT, G_TYPE_POINTER);
639 atk_object_signals[FOCUS_EVENT] =
640 g_signal_new ("focus_event",
641 G_TYPE_FROM_CLASS (klass),
642 G_SIGNAL_RUN_LAST,
643 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
644 NULL, NULL,
645 g_cclosure_marshal_VOID__BOOLEAN,
646 G_TYPE_NONE,
647 1, G_TYPE_BOOLEAN);
648 atk_object_signals[PROPERTY_CHANGE] =
649 g_signal_new ("property_change",
650 G_TYPE_FROM_CLASS (klass),
651 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
652 G_STRUCT_OFFSET (AtkObjectClass, property_change),
653 (GSignalAccumulator) NULL, NULL,
654 g_cclosure_marshal_VOID__POINTER,
655 G_TYPE_NONE, 1,
656 G_TYPE_POINTER);
657 atk_object_signals[STATE_CHANGE] =
658 g_signal_new ("state_change",
659 G_TYPE_FROM_CLASS (klass),
660 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
661 G_STRUCT_OFFSET (AtkObjectClass, state_change),
662 (GSignalAccumulator) NULL, NULL,
663 atk_marshal_VOID__STRING_BOOLEAN,
664 G_TYPE_NONE, 2,
665 G_TYPE_STRING,
666 G_TYPE_BOOLEAN);
667 atk_object_signals[VISIBLE_DATA_CHANGED] =
668 g_signal_new ("visible_data_changed",
669 G_TYPE_FROM_CLASS (klass),
670 G_SIGNAL_RUN_LAST,
671 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
672 (GSignalAccumulator) NULL, NULL,
673 g_cclosure_marshal_VOID__VOID,
674 G_TYPE_NONE, 0);
675 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
676 g_signal_new ("active_descendant_changed",
677 G_TYPE_FROM_CLASS (klass),
678 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
679 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
680 NULL, NULL,
681 g_cclosure_marshal_VOID__POINTER,
682 G_TYPE_NONE,
683 1, G_TYPE_POINTER);
686 static void
687 atk_object_init (AtkObject *accessible,
688 AtkObjectClass *klass)
690 accessible->name = NULL;
691 accessible->description = NULL;
692 accessible->accessible_parent = NULL;
693 accessible->relation_set = atk_relation_set_new();
694 accessible->role = ATK_ROLE_UNKNOWN;
697 GType
698 atk_implementor_get_type (void)
700 static GType type = 0;
702 if (!type)
704 static const GTypeInfo typeInfo =
706 sizeof (AtkImplementorIface),
707 (GBaseInitFunc) NULL,
708 (GBaseFinalizeFunc) NULL,
711 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
714 return type;
718 * atk_object_get_name:
719 * @accessible: an #AtkObject
721 * Gets the accessible name of the accessible.
723 * Returns: a character string representing the accessible name of the object.
725 const gchar*
726 atk_object_get_name (AtkObject *accessible)
728 AtkObjectClass *klass;
730 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
732 klass = ATK_OBJECT_GET_CLASS (accessible);
733 if (klass->get_name)
734 return (klass->get_name) (accessible);
735 else
736 return NULL;
740 * atk_object_get_description:
741 * @accessible: an #AtkObject
743 * Gets the accessible description of the accessible.
745 * Returns: a character string representing the accessible description
746 * of the accessible.
749 const gchar*
750 atk_object_get_description (AtkObject *accessible)
752 AtkObjectClass *klass;
754 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
756 klass = ATK_OBJECT_GET_CLASS (accessible);
757 if (klass->get_description)
758 return (klass->get_description) (accessible);
759 else
760 return NULL;
764 * atk_object_get_parent:
765 * @accessible: an #AtkObject
767 * Gets the accessible parent of the accessible.
769 * Returns: (transfer none): a #AtkObject representing the accessible parent
770 * of the accessible
772 AtkObject*
773 atk_object_get_parent (AtkObject *accessible)
775 AtkObjectClass *klass;
777 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
779 klass = ATK_OBJECT_GET_CLASS (accessible);
780 if (klass->get_parent)
781 return (klass->get_parent) (accessible);
782 else
783 return NULL;
787 * atk_object_get_n_accessible_children:
788 * @accessible: an #AtkObject
790 * Gets the number of accessible children of the accessible.
792 * Returns: an integer representing the number of accessible children
793 * of the accessible.
795 gint
796 atk_object_get_n_accessible_children (AtkObject *accessible)
798 AtkObjectClass *klass;
800 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
802 klass = ATK_OBJECT_GET_CLASS (accessible);
803 if (klass->get_n_children)
804 return (klass->get_n_children) (accessible);
805 else
806 return 0;
810 * atk_object_ref_accessible_child:
811 * @accessible: an #AtkObject
812 * @i: a gint representing the position of the child, starting from 0
814 * Gets a reference to the specified accessible child of the object.
815 * The accessible children are 0-based so the first accessible child is
816 * at index 0, the second at index 1 and so on.
818 * Returns: (transfer full): an #AtkObject representing the specified
819 * accessible child of the accessible.
821 AtkObject*
822 atk_object_ref_accessible_child (AtkObject *accessible,
823 gint i)
825 AtkObjectClass *klass;
827 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
829 klass = ATK_OBJECT_GET_CLASS (accessible);
830 if (klass->ref_child)
831 return (klass->ref_child) (accessible, i);
832 else
833 return NULL;
837 * atk_object_ref_relation_set:
838 * @accessible: an #AtkObject
840 * Gets the #AtkRelationSet associated with the object.
842 * Returns: (transfer full): an #AtkRelationSet representing the relation set
843 * of the object.
845 AtkRelationSet*
846 atk_object_ref_relation_set (AtkObject *accessible)
848 AtkObjectClass *klass;
850 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
852 klass = ATK_OBJECT_GET_CLASS (accessible);
853 if (klass->ref_relation_set)
854 return (klass->ref_relation_set) (accessible);
855 else
856 return NULL;
860 * atk_role_register:
861 * @name: a character string describing the new role.
863 * Registers the role specified by @name.
865 * Returns: an #AtkRole for the new role.
867 AtkRole
868 atk_role_register (const gchar *name)
870 if (!extra_roles)
871 extra_roles = g_ptr_array_new ();
873 g_ptr_array_add (extra_roles, g_strdup (name));
874 return extra_roles->len + ATK_ROLE_LAST_DEFINED;
878 * atk_object_get_role:
879 * @accessible: an #AtkObject
881 * Gets the role of the accessible.
883 * Returns: an #AtkRole which is the role of the accessible
885 AtkRole
886 atk_object_get_role (AtkObject *accessible)
888 AtkObjectClass *klass;
890 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
892 klass = ATK_OBJECT_GET_CLASS (accessible);
893 if (klass->get_role)
894 return (klass->get_role) (accessible);
895 else
896 return ATK_ROLE_UNKNOWN;
900 * atk_object_get_layer:
901 * @accessible: an #AtkObject
903 * Gets the layer of the accessible.
905 * Deprecated: Use atk_component_get_layer instead.
907 * Returns: an #AtkLayer which is the layer of the accessible
909 AtkLayer
910 atk_object_get_layer (AtkObject *accessible)
912 AtkObjectClass *klass;
914 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
916 klass = ATK_OBJECT_GET_CLASS (accessible);
917 if (klass->get_layer)
918 return (klass->get_layer) (accessible);
919 else
920 return ATK_LAYER_INVALID;
924 * atk_object_get_mdi_zorder:
925 * @accessible: an #AtkObject
927 * Gets the zorder of the accessible. The value G_MININT will be returned
928 * if the layer of the accessible is not ATK_LAYER_MDI.
930 * Deprecated: Use atk_component_get_mdi_zorder instead.
932 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
933 * which the component is shown in relation to other components in the same
934 * container.
937 gint
938 atk_object_get_mdi_zorder (AtkObject *accessible)
940 AtkObjectClass *klass;
942 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
944 klass = ATK_OBJECT_GET_CLASS (accessible);
945 if (klass->get_mdi_zorder)
946 return (klass->get_mdi_zorder) (accessible);
947 else
948 return G_MININT;
952 * atk_object_ref_state_set:
953 * @accessible: an #AtkObject
955 * Gets a reference to the state set of the accessible; the caller must
956 * unreference it when it is no longer needed.
958 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
959 * set of the accessible
961 AtkStateSet*
962 atk_object_ref_state_set (AtkObject *accessible)
964 AtkObjectClass *klass;
966 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
968 klass = ATK_OBJECT_GET_CLASS (accessible);
969 if (klass->ref_state_set)
970 return (klass->ref_state_set) (accessible);
971 else
972 return NULL;
976 * atk_object_get_index_in_parent:
977 * @accessible: an #AtkObject
979 * Gets the 0-based index of this accessible in its parent; returns -1 if the
980 * accessible does not have an accessible parent.
982 * Returns: an integer which is the index of the accessible in its parent
984 gint
985 atk_object_get_index_in_parent (AtkObject *accessible)
987 AtkObjectClass *klass;
989 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
991 klass = ATK_OBJECT_GET_CLASS (accessible);
992 if (klass->get_index_in_parent)
993 return (klass->get_index_in_parent) (accessible);
994 else
995 return -1;
999 * atk_object_set_name:
1000 * @accessible: an #AtkObject
1001 * @name: a character string to be set as the accessible name
1003 * Sets the accessible name of the accessible. You can't set the name
1004 * to NULL. This is reserved for the initial value. In this aspect
1005 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
1006 * a empty value you can use "".
1008 void
1009 atk_object_set_name (AtkObject *accessible,
1010 const gchar *name)
1012 AtkObjectClass *klass;
1013 gboolean notify = FALSE;
1015 g_return_if_fail (ATK_IS_OBJECT (accessible));
1016 g_return_if_fail (name != NULL);
1018 klass = ATK_OBJECT_GET_CLASS (accessible);
1019 if (klass->set_name)
1021 /* Do not notify for initial name setting. See bug 665870 */
1022 notify = (accessible->name != NULL);
1024 (klass->set_name) (accessible, name);
1025 if (notify)
1026 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1031 * atk_object_set_description:
1032 * @accessible: an #AtkObject
1033 * @description: a character string to be set as the accessible description
1035 * Sets the accessible description of the accessible. You can't set
1036 * the description to NULL. This is reserved for the initial value. In
1037 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
1038 * the name to a empty value you can use "".
1040 void
1041 atk_object_set_description (AtkObject *accessible,
1042 const gchar *description)
1044 AtkObjectClass *klass;
1045 gboolean notify = FALSE;
1047 g_return_if_fail (ATK_IS_OBJECT (accessible));
1048 g_return_if_fail (description != NULL);
1050 klass = ATK_OBJECT_GET_CLASS (accessible);
1051 if (klass->set_description)
1053 /* Do not notify for initial name setting. See bug 665870 */
1054 notify = (accessible->description != NULL);
1056 (klass->set_description) (accessible, description);
1057 if (notify)
1058 g_object_notify (G_OBJECT (accessible),
1059 atk_object_name_property_description);
1064 * atk_object_set_parent:
1065 * @accessible: an #AtkObject
1066 * @parent: an #AtkObject to be set as the accessible parent
1068 * Sets the accessible parent of the accessible.
1070 void
1071 atk_object_set_parent (AtkObject *accessible,
1072 AtkObject *parent)
1074 AtkObjectClass *klass;
1076 g_return_if_fail (ATK_IS_OBJECT (accessible));
1078 klass = ATK_OBJECT_GET_CLASS (accessible);
1079 if (klass->set_parent)
1081 (klass->set_parent) (accessible, parent);
1082 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1087 * atk_object_set_role:
1088 * @accessible: an #AtkObject
1089 * @role: an #AtkRole to be set as the role
1091 * Sets the role of the accessible.
1093 void
1094 atk_object_set_role (AtkObject *accessible,
1095 AtkRole role)
1097 AtkObjectClass *klass;
1098 AtkRole old_role;
1100 g_return_if_fail (ATK_IS_OBJECT (accessible));
1102 klass = ATK_OBJECT_GET_CLASS (accessible);
1103 if (klass->set_role)
1105 old_role = atk_object_get_role (accessible);
1106 if (old_role != role)
1108 (klass->set_role) (accessible, role);
1109 if (old_role != ATK_ROLE_UNKNOWN)
1110 /* Do not notify for initial role setting */
1111 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1117 * atk_object_connect_property_change_handler:
1118 * @accessible: an #AtkObject
1119 * @handler: a function to be called when a property changes its value
1121 * Specifies a function to be called when a property changes value.
1123 * Returns: a #guint which is the handler id used in
1124 * atk_object_remove_property_change_handler()
1126 guint
1127 atk_object_connect_property_change_handler (AtkObject *accessible,
1128 AtkPropertyChangeHandler *handler)
1130 AtkObjectClass *klass;
1132 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1133 g_return_val_if_fail ((handler != NULL), 0);
1135 klass = ATK_OBJECT_GET_CLASS (accessible);
1136 if (klass->connect_property_change_handler)
1137 return (klass->connect_property_change_handler) (accessible, handler);
1138 else
1139 return 0;
1143 * atk_object_remove_property_change_handler:
1144 * @accessible: an #AtkObject
1145 * @handler_id: a guint which identifies the handler to be removed.
1147 * Removes a property change handler.
1149 void
1150 atk_object_remove_property_change_handler (AtkObject *accessible,
1151 guint handler_id)
1153 AtkObjectClass *klass;
1155 g_return_if_fail (ATK_IS_OBJECT (accessible));
1157 klass = ATK_OBJECT_GET_CLASS (accessible);
1158 if (klass->remove_property_change_handler)
1159 (klass->remove_property_change_handler) (accessible, handler_id);
1163 * atk_object_notify_state_change:
1164 * @accessible: an #AtkObject
1165 * @state: an #AtkState whose state is changed
1166 * @value: a gboolean which indicates whether the state is being set on or off
1168 * Emits a state-change signal for the specified state.
1170 void
1171 atk_object_notify_state_change (AtkObject *accessible,
1172 AtkState state,
1173 gboolean value)
1175 const gchar* name;
1177 g_return_if_fail (ATK_IS_OBJECT (accessible));
1179 name = atk_state_type_get_name (state);
1180 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1181 g_quark_from_string (name),
1182 name, value, NULL);
1186 * atk_implementor_ref_accessible:
1187 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1188 * if a non-null return value is required.
1190 * Gets a reference to an object's #AtkObject implementation, if
1191 * the object implements #AtkObjectIface
1193 * Returns: (transfer full): a reference to an object's #AtkObject
1194 * implementation
1196 AtkObject *
1197 atk_implementor_ref_accessible (AtkImplementor *implementor)
1199 AtkImplementorIface *iface;
1200 AtkObject *accessible = NULL;
1202 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1204 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1206 if (iface != NULL)
1207 accessible = iface->ref_accessible (implementor);
1209 g_return_val_if_fail ((accessible != NULL), NULL);
1211 return accessible;
1216 * atk_object_get_attributes:
1217 * @accessible: An #AtkObject.
1219 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1220 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1221 * as distinct from strongly-typed object data available via other get/set methods.
1222 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1224 * Since: 1.12
1226 * Returns: (transfer none): an #AtkAttributeSet consisting of all explicit
1227 * properties/annotations applied to the object, or an empty set if the object
1228 * has no name-value pair attributes assigned to it.
1230 AtkAttributeSet *
1231 atk_object_get_attributes (AtkObject *accessible)
1233 AtkObjectClass *klass;
1235 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1237 klass = ATK_OBJECT_GET_CLASS (accessible);
1238 if (klass->get_attributes)
1239 return (klass->get_attributes) (accessible);
1240 else
1241 return NULL;
1245 static AtkRelationSet*
1246 atk_object_real_ref_relation_set (AtkObject *accessible)
1248 g_return_val_if_fail (accessible->relation_set, NULL);
1249 g_object_ref (accessible->relation_set);
1251 return accessible->relation_set;
1254 static void
1255 atk_object_real_set_property (GObject *object,
1256 guint prop_id,
1257 const GValue *value,
1258 GParamSpec *pspec)
1260 AtkObject *accessible;
1262 accessible = ATK_OBJECT (object);
1264 switch (prop_id)
1266 case PROP_NAME:
1267 atk_object_set_name (accessible, g_value_get_string (value));
1268 break;
1269 case PROP_DESCRIPTION:
1270 atk_object_set_description (accessible, g_value_get_string (value));
1271 break;
1272 case PROP_ROLE:
1273 atk_object_set_role (accessible, g_value_get_int (value));
1274 break;
1275 case PROP_PARENT:
1276 atk_object_set_parent (accessible, g_value_get_object (value));
1277 break;
1278 case PROP_VALUE:
1279 if (ATK_IS_VALUE (accessible))
1280 atk_value_set_current_value (ATK_VALUE (accessible), value);
1281 break;
1282 case PROP_TABLE_SUMMARY:
1283 if (ATK_IS_TABLE (accessible))
1284 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1285 break;
1286 case PROP_TABLE_CAPTION_OBJECT:
1287 if (ATK_IS_TABLE (accessible))
1288 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1289 break;
1290 default:
1291 break;
1295 static void
1296 atk_object_real_get_property (GObject *object,
1297 guint prop_id,
1298 GValue *value,
1299 GParamSpec *pspec)
1301 AtkObject *accessible;
1303 accessible = ATK_OBJECT (object);
1305 switch (prop_id)
1307 case PROP_NAME:
1308 g_value_set_string (value, atk_object_get_name (accessible));
1309 break;
1310 case PROP_DESCRIPTION:
1311 g_value_set_string (value, atk_object_get_description (accessible));
1312 break;
1313 case PROP_ROLE:
1314 g_value_set_int (value, atk_object_get_role (accessible));
1315 break;
1316 case PROP_LAYER:
1317 if (ATK_IS_COMPONENT (accessible))
1318 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1319 break;
1320 case PROP_MDI_ZORDER:
1321 if (ATK_IS_COMPONENT (accessible))
1322 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1323 break;
1324 case PROP_PARENT:
1325 g_value_set_object (value, atk_object_get_parent (accessible));
1326 break;
1327 case PROP_VALUE:
1328 if (ATK_IS_VALUE (accessible))
1329 atk_value_get_current_value (ATK_VALUE (accessible), value);
1330 break;
1331 case PROP_TABLE_SUMMARY:
1332 if (ATK_IS_TABLE (accessible))
1333 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1334 break;
1335 case PROP_TABLE_CAPTION_OBJECT:
1336 if (ATK_IS_TABLE (accessible))
1337 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1338 break;
1339 case PROP_HYPERTEXT_NUM_LINKS:
1340 if (ATK_IS_HYPERTEXT (accessible))
1341 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1342 break;
1343 default:
1344 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1345 break;
1349 static void
1350 atk_object_finalize (GObject *object)
1352 AtkObject *accessible;
1354 g_return_if_fail (ATK_IS_OBJECT (object));
1356 accessible = ATK_OBJECT (object);
1358 g_free (accessible->name);
1359 g_free (accessible->description);
1362 * Free memory allocated for relation set if it have been allocated.
1364 if (accessible->relation_set)
1365 g_object_unref (accessible->relation_set);
1367 if (accessible->accessible_parent)
1368 g_object_unref (accessible->accessible_parent);
1370 G_OBJECT_CLASS (parent_class)->finalize (object);
1373 static const gchar*
1374 atk_object_real_get_name (AtkObject *object)
1376 return object->name;
1379 static const gchar*
1380 atk_object_real_get_description (AtkObject *object)
1382 return object->description;
1385 static AtkObject*
1386 atk_object_real_get_parent (AtkObject *object)
1388 return object->accessible_parent;
1391 static AtkRole
1392 atk_object_real_get_role (AtkObject *object)
1394 return object->role;
1397 static AtkLayer
1398 atk_object_real_get_layer (AtkObject *object)
1400 return object->layer;
1403 static AtkStateSet*
1404 atk_object_real_ref_state_set (AtkObject *accessible)
1406 AtkStateSet *state_set;
1407 AtkObject *focus_object;
1409 state_set = atk_state_set_new ();
1411 focus_object = atk_get_focus_object ();
1412 if (focus_object == accessible)
1413 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1415 return state_set;
1418 static void
1419 atk_object_real_set_name (AtkObject *object,
1420 const gchar *name)
1422 g_free (object->name);
1423 object->name = g_strdup (name);
1426 static void
1427 atk_object_real_set_description (AtkObject *object,
1428 const gchar *description)
1430 g_free (object->description);
1431 object->description = g_strdup (description);
1434 static void
1435 atk_object_real_set_parent (AtkObject *object,
1436 AtkObject *parent)
1438 if (object->accessible_parent)
1439 g_object_unref (object->accessible_parent);
1441 object->accessible_parent = parent;
1442 if (object->accessible_parent)
1443 g_object_ref (object->accessible_parent);
1446 static void
1447 atk_object_real_set_role (AtkObject *object,
1448 AtkRole role)
1450 object->role = role;
1453 static guint
1454 atk_object_real_connect_property_change_handler (AtkObject *obj,
1455 AtkPropertyChangeHandler *handler)
1457 return g_signal_connect_closure_by_id (obj,
1458 atk_object_signals[PROPERTY_CHANGE],
1460 g_cclosure_new (
1461 G_CALLBACK (handler), NULL,
1462 (GClosureNotify) NULL),
1463 FALSE);
1466 static void
1467 atk_object_real_remove_property_change_handler (AtkObject *obj,
1468 guint handler_id)
1470 g_signal_handler_disconnect (obj, handler_id);
1474 * atk_object_initialize:
1475 * @accessible: a #AtkObject
1476 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1478 * This function is called when implementing subclasses of #AtkObject.
1479 * It does initialization required for the new object. It is intended
1480 * that this function should called only in the ..._new() functions used
1481 * to create an instance of a subclass of #AtkObject
1483 void
1484 atk_object_initialize (AtkObject *accessible,
1485 gpointer data)
1487 AtkObjectClass *klass;
1489 g_return_if_fail (ATK_IS_OBJECT (accessible));
1491 klass = ATK_OBJECT_GET_CLASS (accessible);
1492 if (klass->initialize)
1493 klass->initialize (accessible, data);
1497 * This function is a signal handler for notify signal which gets emitted
1498 * when a property changes value.
1500 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1501 * signal which causes the user specified AtkPropertyChangeHandler
1502 * to be called.
1504 static void
1505 atk_object_notify (GObject *obj,
1506 GParamSpec *pspec)
1508 AtkPropertyValues values = { NULL, };
1510 g_value_init (&values.new_value, pspec->value_type);
1511 g_object_get_property (obj, pspec->name, &values.new_value);
1512 values.property_name = pspec->name;
1513 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1514 g_quark_from_string (pspec->name),
1515 &values, NULL);
1516 g_value_unset (&values.new_value);
1520 * atk_role_get_name:
1521 * @role: The #AtkRole whose name is required
1523 * Gets the description string describing the #AtkRole @role.
1525 * Returns: the string describing the AtkRole
1527 const gchar*
1528 atk_role_get_name (AtkRole role)
1530 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1531 return roles + roles_offsets[role];
1533 if (extra_roles)
1535 gint n = role;
1537 n -= ATK_ROLE_LAST_DEFINED + 1;
1539 if (n >= 0 && n < extra_roles->len)
1540 return g_ptr_array_index (extra_roles, n);
1543 return NULL;
1547 * atk_role_get_localized_name:
1548 * @role: The #AtkRole whose localized name is required
1550 * Gets the localized description string describing the #AtkRole @role.
1552 * Returns: the localized string describing the AtkRole
1554 const gchar*
1555 atk_role_get_localized_name (AtkRole role)
1557 gettext_initialization ();
1559 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1560 return dgettext (GETTEXT_PACKAGE, roles + roles_offsets[role]);
1562 return atk_role_get_name (role);
1565 static const gchar*
1566 atk_object_real_get_object_locale (AtkObject *object)
1568 return setlocale (LC_MESSAGES, NULL);
1572 * atk_object_get_object_locale:
1573 * @accessible: an #AtkObject
1575 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
1576 * of @accessible.
1578 * Since: 2.7.90
1580 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
1581 * locale of @accessible.
1583 const gchar*
1584 atk_object_get_object_locale (AtkObject *accessible)
1586 AtkObjectClass *klass;
1588 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1590 klass = ATK_OBJECT_GET_CLASS (accessible);
1591 if (klass->get_object_locale)
1592 return (klass->get_object_locale) (accessible);
1593 else
1594 return NULL;
1599 * atk_role_for_name:
1600 * @name: a string which is the (non-localized) name of an ATK role.
1602 * Get the #AtkRole type corresponding to a rolew name.
1604 * Returns: the #AtkRole enumerated type corresponding to the specified
1605 name,
1606 * or #ATK_ROLE_INVALID if no matching role is found.
1608 AtkRole
1609 atk_role_for_name (const gchar *name)
1611 AtkRole role = ATK_ROLE_INVALID;
1612 gint i;
1614 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1616 for (i = 0; i < G_N_ELEMENTS (roles_offsets); i++)
1618 if (strcmp (name, roles + roles_offsets[i]) == 0)
1619 return (AtkRole) i;
1622 if (extra_roles)
1624 for (i = 0; i < extra_roles->len; i++)
1626 gchar *extra_role = (gchar *)g_ptr_array_index (extra_roles, i);
1628 g_return_val_if_fail (extra_role, ATK_ROLE_INVALID);
1630 if (strcmp (name, extra_role) == 0)
1632 role = i + 1 + ATK_ROLE_LAST_DEFINED;
1633 break;
1638 return role;
1642 * atk_object_add_relationship:
1643 * @object: The #AtkObject to which an AtkRelation is to be added.
1644 * @relationship: The #AtkRelationType of the relation
1645 * @target: The #AtkObject which is to be the target of the relation.
1647 * Adds a relationship of the specified type with the specified target.
1649 * Returns TRUE if the relationship is added.
1651 gboolean
1652 atk_object_add_relationship (AtkObject *object,
1653 AtkRelationType relationship,
1654 AtkObject *target)
1656 AtkObject *array[1];
1657 AtkRelation *relation;
1659 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1660 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1662 if (atk_relation_set_contains_target (object->relation_set,
1663 relationship, target))
1664 return FALSE;
1666 array[0] = target;
1667 relation = atk_relation_new (array, 1, relationship);
1668 atk_relation_set_add (object->relation_set, relation);
1669 g_object_unref (relation);
1671 return TRUE;
1675 * atk_object_remove_relationship:
1676 * @object: The #AtkObject from which an AtkRelation is to be removed.
1677 * @relationship: The #AtkRelationType of the relation
1678 * @target: The #AtkObject which is the target of the relation to be removed.
1680 * Removes a relationship of the specified type with the specified target.
1682 * Returns TRUE if the relationship is removed.
1684 gboolean
1685 atk_object_remove_relationship (AtkObject *object,
1686 AtkRelationType relationship,
1687 AtkObject *target)
1689 gboolean ret = FALSE;
1690 AtkRelation *relation;
1691 GPtrArray *array;
1693 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1694 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1696 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1698 if (relation)
1700 ret = atk_relation_remove_target (relation, target);
1701 array = atk_relation_get_target (relation);
1702 if (!array || array->len == 0)
1703 atk_relation_set_remove (object->relation_set, relation);
1705 return ret;
1708 static void
1709 atk_object_real_initialize (AtkObject *accessible,
1710 gpointer data)
1712 return;