Do not notify accessible-name/description for initial setting
[atk.git] / atk / atkobject.c
blob23e4605a65745f6c1389ef2f5b52489e806edeb3
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>
22 #include <glib-object.h>
24 #ifdef G_OS_WIN32
25 #define STRICT
26 #include <windows.h>
27 #undef STRICT
28 #undef FOCUS_EVENT /* <windows.h> pollutes the namespace
29 * like a six hundred pound gorilla */
30 #endif
32 #include "atk.h"
33 #include "atkmarshal.h"
34 #include "atk-enum-types.h"
35 #include "atkintl.h"
37 static GPtrArray *extra_roles = NULL;
39 enum
41 PROP_0, /* gobject convention */
43 PROP_NAME,
44 PROP_DESCRIPTION,
45 PROP_PARENT, /* ancestry has changed */
46 PROP_VALUE,
47 PROP_ROLE,
48 PROP_LAYER,
49 PROP_MDI_ZORDER,
50 PROP_TABLE_CAPTION,
51 PROP_TABLE_COLUMN_DESCRIPTION,
52 PROP_TABLE_COLUMN_HEADER,
53 PROP_TABLE_ROW_DESCRIPTION,
54 PROP_TABLE_ROW_HEADER,
55 PROP_TABLE_SUMMARY,
56 PROP_TABLE_CAPTION_OBJECT,
57 PROP_HYPERTEXT_NUM_LINKS,
58 PROP_LAST /* gobject convention */
61 enum {
62 CHILDREN_CHANGED,
63 FOCUS_EVENT,
64 PROPERTY_CHANGE,
65 STATE_CHANGE,
66 VISIBLE_DATA_CHANGED,
67 ACTIVE_DESCENDANT_CHANGED,
69 LAST_SIGNAL
72 /* These are listed here for extraction by intltool */
73 #if 0
74 N_("invalid")
75 N_("accelerator label")
76 N_("alert")
77 N_("animation")
78 N_("arrow")
79 N_("calendar")
80 N_("canvas")
81 N_("check box")
82 N_("check menu item")
83 N_("color chooser")
84 N_("column header")
85 N_("combo box")
86 N_("dateeditor")
87 N_("desktop icon")
88 N_("desktop frame")
89 N_("dial")
90 N_("dialog")
91 N_("directory pane")
92 N_("drawing area")
93 N_("file chooser")
94 N_("filler")
95 /* I know it looks wrong but that is what Java returns */
96 N_("fontchooser")
97 N_("frame")
98 N_("glass pane")
99 N_("html container")
100 N_("icon")
101 N_("image")
102 N_("internal frame")
103 N_("label")
104 N_("layered pane")
105 N_("list")
106 N_("list item")
107 N_("menu")
108 N_("menu bar")
109 N_("menu item")
110 N_("option pane")
111 N_("page tab")
112 N_("page tab list")
113 N_("panel")
114 N_("password text")
115 N_("popup menu")
116 N_("progress bar")
117 N_("push button")
118 N_("radio button")
119 N_("radio menu item")
120 N_("root pane")
121 N_("row header")
122 N_("scroll bar")
123 N_("scroll pane")
124 N_("separator")
125 N_("slider")
126 N_("split pane")
127 N_("spin button")
128 N_("statusbar")
129 N_("table")
130 N_("table cell")
131 N_("table column header")
132 N_("table row header")
133 N_("tear off menu item")
134 N_("terminal")
135 N_("text")
136 N_("toggle button")
137 N_("tool bar")
138 N_("tool tip")
139 N_("tree")
140 N_("tree table")
141 N_("unknown")
142 N_("viewport")
143 N_("window")
144 N_("header")
145 N_("footer")
146 N_("paragraph")
147 N_("ruler")
148 N_("application")
149 N_("autocomplete")
150 N_("edit bar")
151 N_("embedded component")
152 N_("entry")
153 N_("chart")
154 N_("caption")
155 N_("document frame")
156 N_("heading")
157 N_("page")
158 N_("section")
159 N_("redundant object")
160 N_("form")
161 N_("link")
162 N_("input method window")
163 N_("table row")
164 N_("tree item")
165 N_("document spreadsheet")
166 N_("document presentation")
167 N_("document text")
168 N_("document web")
169 N_("document email")
170 N_("comment")
171 N_("list box")
172 N_("grouping")
173 N_("image map")
174 N_("notification")
175 N_("info bar")
176 #endif /* 0 */
178 static const char roles[] =
179 "invalid\0"
180 "accelerator label\0"
181 "alert\0"
182 "animation\0"
183 "arrow\0"
184 "calendar\0"
185 "canvas\0"
186 "check box\0"
187 "check menu item\0"
188 "color chooser\0"
189 "column header\0"
190 "combo box\0"
191 "dateeditor\0"
192 "desktop icon\0"
193 "desktop frame\0"
194 "dial\0"
195 "dialog\0"
196 "directory pane\0"
197 "drawing area\0"
198 "file chooser\0"
199 "filler\0"
200 "fontchooser\0"
201 "frame\0"
202 "glass pane\0"
203 "html container\0"
204 "icon\0"
205 "image\0"
206 "internal frame\0"
207 "label\0"
208 "layered pane\0"
209 "list\0"
210 "list item\0"
211 "menu\0"
212 "menu bar\0"
213 "menu item\0"
214 "option pane\0"
215 "page tab\0"
216 "page tab list\0"
217 "panel\0"
218 "password text\0"
219 "popup menu\0"
220 "progress bar\0"
221 "push button\0"
222 "radio button\0"
223 "radio menu item\0"
224 "root pane\0"
225 "row header\0"
226 "scroll bar\0"
227 "scroll pane\0"
228 "separator\0"
229 "slider\0"
230 "split pane\0"
231 "spin button\0"
232 "statusbar\0"
233 "table\0"
234 "table cell\0"
235 "table column header\0"
236 "table row header\0"
237 "tear off menu item\0"
238 "terminal\0"
239 "text\0"
240 "toggle button\0"
241 "tool bar\0"
242 "tool tip\0"
243 "tree\0"
244 "tree table\0"
245 "unknown\0"
246 "viewport\0"
247 "window\0"
248 "header\0"
249 "footer\0"
250 "paragraph\0"
251 "ruler\0"
252 "application\0"
253 "autocomplete\0"
254 "edit bar\0"
255 "embedded component\0"
256 "entry\0"
257 "chart\0"
258 "caption\0"
259 "document frame\0"
260 "heading\0"
261 "page\0"
262 "section\0"
263 "redundant object\0"
264 "form\0"
265 "link\0"
266 "input method window\0"
267 "table row\0"
268 "tree item\0"
269 "document spreadsheet\0"
270 "document presentation\0"
271 "document text\0"
272 "document web\0"
273 "document email\0"
274 "comment\0"
275 "list box\0"
276 "grouping\0"
277 "image map\0"
278 "notification\0"
279 "info bar\0";
281 static const guint16 roles_offsets[] = {
282 0, 8, 26, 32, 42, 48, 57, 64,
283 74, 90, 104, 118, 128, 139, 152, 166,
284 171, 178, 193, 206, 219, 226, 238, 244,
285 255, 270, 275, 281, 296, 302, 315, 320,
286 330, 335, 344, 354, 366, 375, 389, 395,
287 409, 420, 433, 445, 458, 474, 484, 495,
288 506, 518, 528, 535, 546, 558, 568, 574,
289 585, 605, 622, 641, 650, 655, 669, 678,
290 687, 692, 703, 711, 720, 727, 734, 741,
291 751, 757, 769, 782, 791, 810, 816, 822,
292 830, 845, 853, 858, 866, 883, 888, 893,
293 913, 923, 933, 954, 976, 990, 1003, 1018,
294 1026, 1035, 1044, 1054, 1067
297 /* This is a static assertion */
298 typedef int _assert_roles_num[(G_N_ELEMENTS (roles_offsets) == ATK_ROLE_LAST_DEFINED) ? 1 : -1];
300 static void atk_object_class_init (AtkObjectClass *klass);
301 static void atk_object_init (AtkObject *accessible,
302 AtkObjectClass *klass);
303 static AtkRelationSet* atk_object_real_ref_relation_set
304 (AtkObject *accessible);
305 static void atk_object_real_initialize (AtkObject *accessible,
306 gpointer data);
307 static void atk_object_real_set_property (GObject *object,
308 guint prop_id,
309 const GValue *value,
310 GParamSpec *pspec);
311 static void atk_object_real_get_property (GObject *object,
312 guint prop_id,
313 GValue *value,
314 GParamSpec *pspec);
315 static void atk_object_finalize (GObject *object);
316 static const gchar* atk_object_real_get_name (AtkObject *object);
317 static const gchar* atk_object_real_get_description
318 (AtkObject *object);
319 static AtkObject* atk_object_real_get_parent (AtkObject *object);
320 static AtkRole atk_object_real_get_role (AtkObject *object);
321 static AtkLayer atk_object_real_get_layer (AtkObject *object);
322 static AtkStateSet* atk_object_real_ref_state_set
323 (AtkObject *object);
324 static void atk_object_real_set_name (AtkObject *object,
325 const gchar *name);
326 static void atk_object_real_set_description
327 (AtkObject *object,
328 const gchar *description);
329 static void atk_object_real_set_parent (AtkObject *object,
330 AtkObject *parent);
331 static void atk_object_real_set_role (AtkObject *object,
332 AtkRole role);
333 static guint atk_object_real_connect_property_change_handler
334 (AtkObject *obj,
335 AtkPropertyChangeHandler
336 *handler);
337 static void atk_object_real_remove_property_change_handler
338 (AtkObject *obj,
339 guint handler_id);
340 static void atk_object_notify (GObject *obj,
341 GParamSpec *pspec);
344 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
346 static gpointer parent_class = NULL;
348 static const gchar* const atk_object_name_property_name = "accessible-name";
349 static const gchar* const atk_object_name_property_description = "accessible-description";
350 static const gchar* const atk_object_name_property_parent = "accessible-parent";
351 static const gchar* const atk_object_name_property_value = "accessible-value";
352 static const gchar* const atk_object_name_property_role = "accessible-role";
353 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
354 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
355 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
356 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
357 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
358 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
359 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
360 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
361 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
362 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
364 #ifdef G_OS_WIN32
366 static HMODULE atk_dll;
368 BOOL WINAPI
369 DllMain (HINSTANCE hinstDLL,
370 DWORD fdwReason,
371 LPVOID lpvReserved)
373 switch (fdwReason)
375 case DLL_PROCESS_ATTACH:
376 atk_dll = (HMODULE) hinstDLL;
377 break;
380 return TRUE;
383 static const char *
384 get_atk_locale_dir (void)
386 static gchar *atk_localedir = NULL;
388 if (!atk_localedir)
390 const gchar *p;
391 gchar *root, *temp;
393 /* ATK_LOCALEDIR might end in either /lib/locale or
394 * /share/locale. Scan for that slash.
396 p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
397 while (*--p != '/')
399 while (*--p != '/')
402 root = g_win32_get_package_installation_directory_of_module (atk_dll);
403 temp = g_build_filename (root, p, NULL);
404 g_free (root);
406 /* atk_localedir is passed to bindtextdomain() which isn't
407 * UTF-8-aware.
409 atk_localedir = g_win32_locale_filename_from_utf8 (temp);
410 g_free (temp);
412 return atk_localedir;
415 #undef ATK_LOCALEDIR
417 #define ATK_LOCALEDIR get_atk_locale_dir()
419 #endif
421 static void
422 gettext_initialization (void)
424 #ifdef ENABLE_NLS
425 static gboolean gettext_initialized = FALSE;
427 if (!gettext_initialized)
429 const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
431 gettext_initialized = TRUE;
432 if (dir == NULL)
433 dir = ATK_LOCALEDIR;
435 bindtextdomain (GETTEXT_PACKAGE, dir);
436 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
437 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
438 #endif
440 #endif
443 GType
444 atk_object_get_type (void)
446 static GType type = 0;
448 if (!type)
450 static const GTypeInfo typeInfo =
452 sizeof (AtkObjectClass),
453 (GBaseInitFunc) NULL,
454 (GBaseFinalizeFunc) NULL,
455 (GClassInitFunc) atk_object_class_init,
456 (GClassFinalizeFunc) NULL,
457 NULL,
458 sizeof (AtkObject),
460 (GInstanceInitFunc) atk_object_init,
462 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
464 return type;
467 static void
468 atk_object_class_init (AtkObjectClass *klass)
470 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
472 parent_class = g_type_class_peek_parent (klass);
474 gobject_class->set_property = atk_object_real_set_property;
475 gobject_class->get_property = atk_object_real_get_property;
476 gobject_class->finalize = atk_object_finalize;
477 gobject_class->notify = atk_object_notify;
479 klass->get_name = atk_object_real_get_name;
480 klass->get_description = atk_object_real_get_description;
481 klass->get_parent = atk_object_real_get_parent;
482 klass->get_n_children = NULL;
483 klass->ref_child = NULL;
484 klass->get_index_in_parent = NULL;
485 klass->ref_relation_set = atk_object_real_ref_relation_set;
486 klass->get_role = atk_object_real_get_role;
487 klass->get_layer = atk_object_real_get_layer;
488 klass->get_mdi_zorder = NULL;
489 klass->initialize = atk_object_real_initialize;
490 klass->ref_state_set = atk_object_real_ref_state_set;
491 klass->set_name = atk_object_real_set_name;
492 klass->set_description = atk_object_real_set_description;
493 klass->set_parent = atk_object_real_set_parent;
494 klass->set_role = atk_object_real_set_role;
495 klass->connect_property_change_handler =
496 atk_object_real_connect_property_change_handler;
497 klass->remove_property_change_handler =
498 atk_object_real_remove_property_change_handler;
501 * We do not define default signal handlers here
503 klass->children_changed = NULL;
504 klass->focus_event = NULL;
505 klass->property_change = NULL;
506 klass->visible_data_changed = NULL;
507 klass->active_descendant_changed = NULL;
509 gettext_initialization ();
511 g_object_class_install_property (gobject_class,
512 PROP_NAME,
513 g_param_spec_string (atk_object_name_property_name,
514 _("Accessible Name"),
515 _("Object instance\'s name formatted for assistive technology access"),
516 NULL,
517 G_PARAM_READWRITE));
518 g_object_class_install_property (gobject_class,
519 PROP_DESCRIPTION,
520 g_param_spec_string (atk_object_name_property_description,
521 _("Accessible Description"),
522 _("Description of an object, formatted for assistive technology access"),
523 NULL,
524 G_PARAM_READWRITE));
525 g_object_class_install_property (gobject_class,
526 PROP_PARENT,
527 g_param_spec_object (atk_object_name_property_parent,
528 _("Accessible Parent"),
529 _("Is used to notify that the parent has changed"),
530 ATK_TYPE_OBJECT,
531 G_PARAM_READWRITE));
532 g_object_class_install_property (gobject_class,
533 PROP_VALUE,
534 g_param_spec_double (atk_object_name_property_value,
535 _("Accessible Value"),
536 _("Is used to notify that the value has changed"),
537 0.0,
538 G_MAXDOUBLE,
539 0.0,
540 G_PARAM_READWRITE));
541 g_object_class_install_property (gobject_class,
542 PROP_ROLE,
543 g_param_spec_int (atk_object_name_property_role,
544 _("Accessible Role"),
545 _("The accessible role of this object"),
547 G_MAXINT,
549 G_PARAM_READWRITE));
550 g_object_class_install_property (gobject_class,
551 PROP_LAYER,
552 g_param_spec_int (atk_object_name_property_component_layer,
553 _("Accessible Layer"),
554 _("The accessible layer of this object"),
556 G_MAXINT,
558 G_PARAM_READABLE));
559 g_object_class_install_property (gobject_class,
560 PROP_MDI_ZORDER,
561 g_param_spec_int (atk_object_name_property_component_mdi_zorder,
562 _("Accessible MDI Value"),
563 _("The accessible MDI value of this object"),
564 G_MININT,
565 G_MAXINT,
566 G_MININT,
567 G_PARAM_READABLE));
568 g_object_class_install_property (gobject_class,
569 PROP_TABLE_CAPTION,
570 g_param_spec_string (atk_object_name_property_table_caption,
571 _("Accessible Table Caption"),
572 _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
573 NULL,
574 G_PARAM_READWRITE));
575 g_object_class_install_property (gobject_class,
576 PROP_TABLE_COLUMN_HEADER,
577 g_param_spec_object (atk_object_name_property_table_column_header,
578 _("Accessible Table Column Header"),
579 _("Is used to notify that the table column header has changed"),
580 ATK_TYPE_OBJECT,
581 G_PARAM_READWRITE));
582 g_object_class_install_property (gobject_class,
583 PROP_TABLE_COLUMN_DESCRIPTION,
584 g_param_spec_string (atk_object_name_property_table_column_description,
585 _("Accessible Table Column Description"),
586 _("Is used to notify that the table column description has changed"),
587 NULL,
588 G_PARAM_READWRITE));
589 g_object_class_install_property (gobject_class,
590 PROP_TABLE_ROW_HEADER,
591 g_param_spec_object (atk_object_name_property_table_row_header,
592 _("Accessible Table Row Header"),
593 _("Is used to notify that the table row header has changed"),
594 ATK_TYPE_OBJECT,
595 G_PARAM_READWRITE));
596 g_object_class_install_property (gobject_class,
597 PROP_TABLE_ROW_DESCRIPTION,
598 g_param_spec_string (atk_object_name_property_table_row_description,
599 _("Accessible Table Row Description"),
600 _("Is used to notify that the table row description has changed"),
601 NULL,
602 G_PARAM_READWRITE));
603 g_object_class_install_property (gobject_class,
604 PROP_TABLE_SUMMARY,
605 g_param_spec_object (atk_object_name_property_table_summary,
606 _("Accessible Table Summary"),
607 _("Is used to notify that the table summary has changed"),
608 ATK_TYPE_OBJECT,
609 G_PARAM_READWRITE));
610 g_object_class_install_property (gobject_class,
611 PROP_TABLE_CAPTION_OBJECT,
612 g_param_spec_object (atk_object_name_property_table_caption_object,
613 _("Accessible Table Caption Object"),
614 _("Is used to notify that the table caption has changed"),
615 ATK_TYPE_OBJECT,
616 G_PARAM_READWRITE));
617 g_object_class_install_property (gobject_class,
618 PROP_HYPERTEXT_NUM_LINKS,
619 g_param_spec_int (atk_object_name_property_hypertext_num_links,
620 _("Number of Accessible Hypertext Links"),
621 _("The number of links which the current AtkHypertext has"),
623 G_MAXINT,
625 G_PARAM_READABLE));
626 atk_object_signals[CHILDREN_CHANGED] =
627 g_signal_new ("children_changed",
628 G_TYPE_FROM_CLASS (klass),
629 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
630 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
631 NULL, NULL,
632 g_cclosure_marshal_VOID__UINT_POINTER,
633 G_TYPE_NONE,
634 2, G_TYPE_UINT, G_TYPE_POINTER);
635 atk_object_signals[FOCUS_EVENT] =
636 g_signal_new ("focus_event",
637 G_TYPE_FROM_CLASS (klass),
638 G_SIGNAL_RUN_LAST,
639 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
640 NULL, NULL,
641 g_cclosure_marshal_VOID__BOOLEAN,
642 G_TYPE_NONE,
643 1, G_TYPE_BOOLEAN);
644 atk_object_signals[PROPERTY_CHANGE] =
645 g_signal_new ("property_change",
646 G_TYPE_FROM_CLASS (klass),
647 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
648 G_STRUCT_OFFSET (AtkObjectClass, property_change),
649 (GSignalAccumulator) NULL, NULL,
650 g_cclosure_marshal_VOID__POINTER,
651 G_TYPE_NONE, 1,
652 G_TYPE_POINTER);
653 atk_object_signals[STATE_CHANGE] =
654 g_signal_new ("state_change",
655 G_TYPE_FROM_CLASS (klass),
656 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
657 G_STRUCT_OFFSET (AtkObjectClass, state_change),
658 (GSignalAccumulator) NULL, NULL,
659 atk_marshal_VOID__STRING_BOOLEAN,
660 G_TYPE_NONE, 2,
661 G_TYPE_STRING,
662 G_TYPE_BOOLEAN);
663 atk_object_signals[VISIBLE_DATA_CHANGED] =
664 g_signal_new ("visible_data_changed",
665 G_TYPE_FROM_CLASS (klass),
666 G_SIGNAL_RUN_LAST,
667 G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
668 (GSignalAccumulator) NULL, NULL,
669 g_cclosure_marshal_VOID__VOID,
670 G_TYPE_NONE, 0);
671 atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
672 g_signal_new ("active_descendant_changed",
673 G_TYPE_FROM_CLASS (klass),
674 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
675 G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
676 NULL, NULL,
677 g_cclosure_marshal_VOID__POINTER,
678 G_TYPE_NONE,
679 1, G_TYPE_POINTER);
682 static void
683 atk_object_init (AtkObject *accessible,
684 AtkObjectClass *klass)
686 accessible->name = NULL;
687 accessible->description = NULL;
688 accessible->accessible_parent = NULL;
689 accessible->relation_set = atk_relation_set_new();
690 accessible->role = ATK_ROLE_UNKNOWN;
693 GType
694 atk_implementor_get_type (void)
696 static GType type = 0;
698 if (!type)
700 static const GTypeInfo typeInfo =
702 sizeof (AtkImplementorIface),
703 (GBaseInitFunc) NULL,
704 (GBaseFinalizeFunc) NULL,
707 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
710 return type;
714 * atk_object_get_name:
715 * @accessible: an #AtkObject
717 * Gets the accessible name of the accessible.
719 * Returns: a character string representing the accessible name of the object.
721 const gchar*
722 atk_object_get_name (AtkObject *accessible)
724 AtkObjectClass *klass;
726 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
728 klass = ATK_OBJECT_GET_CLASS (accessible);
729 if (klass->get_name)
730 return (klass->get_name) (accessible);
731 else
732 return NULL;
736 * atk_object_get_description:
737 * @accessible: an #AtkObject
739 * Gets the accessible description of the accessible.
741 * Returns: a character string representing the accessible description
742 * of the accessible.
745 const gchar*
746 atk_object_get_description (AtkObject *accessible)
748 AtkObjectClass *klass;
750 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
752 klass = ATK_OBJECT_GET_CLASS (accessible);
753 if (klass->get_description)
754 return (klass->get_description) (accessible);
755 else
756 return NULL;
760 * atk_object_get_parent:
761 * @accessible: an #AtkObject
763 * Gets the accessible parent of the accessible.
765 * Returns: (transfer none): a #AtkObject representing the accessible parent
766 * of the accessible
768 AtkObject*
769 atk_object_get_parent (AtkObject *accessible)
771 AtkObjectClass *klass;
773 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
775 klass = ATK_OBJECT_GET_CLASS (accessible);
776 if (klass->get_parent)
777 return (klass->get_parent) (accessible);
778 else
779 return NULL;
783 * atk_object_get_n_accessible_children:
784 * @accessible: an #AtkObject
786 * Gets the number of accessible children of the accessible.
788 * Returns: an integer representing the number of accessible children
789 * of the accessible.
791 gint
792 atk_object_get_n_accessible_children (AtkObject *accessible)
794 AtkObjectClass *klass;
796 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
798 klass = ATK_OBJECT_GET_CLASS (accessible);
799 if (klass->get_n_children)
800 return (klass->get_n_children) (accessible);
801 else
802 return 0;
806 * atk_object_ref_accessible_child:
807 * @accessible: an #AtkObject
808 * @i: a gint representing the position of the child, starting from 0
810 * Gets a reference to the specified accessible child of the object.
811 * The accessible children are 0-based so the first accessible child is
812 * at index 0, the second at index 1 and so on.
814 * Returns: (transfer full): an #AtkObject representing the specified
815 * accessible child of the accessible.
817 AtkObject*
818 atk_object_ref_accessible_child (AtkObject *accessible,
819 gint i)
821 AtkObjectClass *klass;
823 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
825 klass = ATK_OBJECT_GET_CLASS (accessible);
826 if (klass->ref_child)
827 return (klass->ref_child) (accessible, i);
828 else
829 return NULL;
833 * atk_object_ref_relation_set:
834 * @accessible: an #AtkObject
836 * Gets the #AtkRelationSet associated with the object.
838 * Returns: (transfer full): an #AtkRelationSet representing the relation set
839 * of the object.
841 AtkRelationSet*
842 atk_object_ref_relation_set (AtkObject *accessible)
844 AtkObjectClass *klass;
846 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
848 klass = ATK_OBJECT_GET_CLASS (accessible);
849 if (klass->ref_relation_set)
850 return (klass->ref_relation_set) (accessible);
851 else
852 return NULL;
856 * atk_role_register:
857 * @name: a character string describing the new role.
859 * Registers the role specified by @name.
861 * Returns: an #AtkRole for the new role.
863 AtkRole
864 atk_role_register (const gchar *name)
866 if (!extra_roles)
867 extra_roles = g_ptr_array_new ();
869 g_ptr_array_add (extra_roles, g_strdup (name));
870 return extra_roles->len + ATK_ROLE_LAST_DEFINED;
874 * atk_object_get_role:
875 * @accessible: an #AtkObject
877 * Gets the role of the accessible.
879 * Returns: an #AtkRole which is the role of the accessible
881 AtkRole
882 atk_object_get_role (AtkObject *accessible)
884 AtkObjectClass *klass;
886 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
888 klass = ATK_OBJECT_GET_CLASS (accessible);
889 if (klass->get_role)
890 return (klass->get_role) (accessible);
891 else
892 return ATK_ROLE_UNKNOWN;
896 * atk_object_get_layer:
897 * @accessible: an #AtkObject
899 * Gets the layer of the accessible.
901 * Deprecated: Use atk_component_get_layer instead.
903 * Returns: an #AtkLayer which is the layer of the accessible
905 AtkLayer
906 atk_object_get_layer (AtkObject *accessible)
908 AtkObjectClass *klass;
910 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
912 klass = ATK_OBJECT_GET_CLASS (accessible);
913 if (klass->get_layer)
914 return (klass->get_layer) (accessible);
915 else
916 return ATK_LAYER_INVALID;
920 * atk_object_get_mdi_zorder:
921 * @accessible: an #AtkObject
923 * Gets the zorder of the accessible. The value G_MININT will be returned
924 * if the layer of the accessible is not ATK_LAYER_MDI.
926 * Deprecated: Use atk_component_get_mdi_zorder instead.
928 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
929 * which the component is shown in relation to other components in the same
930 * container.
933 gint
934 atk_object_get_mdi_zorder (AtkObject *accessible)
936 AtkObjectClass *klass;
938 g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
940 klass = ATK_OBJECT_GET_CLASS (accessible);
941 if (klass->get_mdi_zorder)
942 return (klass->get_mdi_zorder) (accessible);
943 else
944 return G_MININT;
948 * atk_object_ref_state_set:
949 * @accessible: an #AtkObject
951 * Gets a reference to the state set of the accessible; the caller must
952 * unreference it when it is no longer needed.
954 * Returns: (transfer full): a reference to an #AtkStateSet which is the state
955 * set of the accessible
957 AtkStateSet*
958 atk_object_ref_state_set (AtkObject *accessible)
960 AtkObjectClass *klass;
962 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
964 klass = ATK_OBJECT_GET_CLASS (accessible);
965 if (klass->ref_state_set)
966 return (klass->ref_state_set) (accessible);
967 else
968 return NULL;
972 * atk_object_get_index_in_parent:
973 * @accessible: an #AtkObject
975 * Gets the 0-based index of this accessible in its parent; returns -1 if the
976 * accessible does not have an accessible parent.
978 * Returns: an integer which is the index of the accessible in its parent
980 gint
981 atk_object_get_index_in_parent (AtkObject *accessible)
983 AtkObjectClass *klass;
985 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
987 klass = ATK_OBJECT_GET_CLASS (accessible);
988 if (klass->get_index_in_parent)
989 return (klass->get_index_in_parent) (accessible);
990 else
991 return -1;
995 * atk_object_set_name:
996 * @accessible: an #AtkObject
997 * @name: a character string to be set as the accessible name
999 * Sets the accessible name of the accessible.
1001 void
1002 atk_object_set_name (AtkObject *accessible,
1003 const gchar *name)
1005 AtkObjectClass *klass;
1006 gboolean notify = FALSE;
1008 g_return_if_fail (ATK_IS_OBJECT (accessible));
1009 g_return_if_fail (name != NULL);
1011 klass = ATK_OBJECT_GET_CLASS (accessible);
1012 if (klass->set_name)
1014 /* Do not notify for initial name setting. See bug 665870 */
1015 notify = (accessible->name != NULL);
1017 (klass->set_name) (accessible, name);
1018 if (notify)
1019 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1024 * atk_object_set_description:
1025 * @accessible: an #AtkObject
1026 * @description: a character string to be set as the accessible description
1028 * Sets the accessible description of the accessible.
1030 void
1031 atk_object_set_description (AtkObject *accessible,
1032 const gchar *description)
1034 AtkObjectClass *klass;
1035 gboolean notify = FALSE;
1037 g_return_if_fail (ATK_IS_OBJECT (accessible));
1038 g_return_if_fail (description != NULL);
1040 klass = ATK_OBJECT_GET_CLASS (accessible);
1041 if (klass->set_description)
1043 /* Do not notify for initial name setting. See bug 665870 */
1044 notify = (accessible->description != NULL);
1046 (klass->set_description) (accessible, description);
1047 if (notify)
1048 g_object_notify (G_OBJECT (accessible),
1049 atk_object_name_property_description);
1054 * atk_object_set_parent:
1055 * @accessible: an #AtkObject
1056 * @parent: an #AtkObject to be set as the accessible parent
1058 * Sets the accessible parent of the accessible.
1060 void
1061 atk_object_set_parent (AtkObject *accessible,
1062 AtkObject *parent)
1064 AtkObjectClass *klass;
1066 g_return_if_fail (ATK_IS_OBJECT (accessible));
1068 klass = ATK_OBJECT_GET_CLASS (accessible);
1069 if (klass->set_parent)
1071 (klass->set_parent) (accessible, parent);
1072 g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1077 * atk_object_set_role:
1078 * @accessible: an #AtkObject
1079 * @role: an #AtkRole to be set as the role
1081 * Sets the role of the accessible.
1083 void
1084 atk_object_set_role (AtkObject *accessible,
1085 AtkRole role)
1087 AtkObjectClass *klass;
1088 AtkRole old_role;
1090 g_return_if_fail (ATK_IS_OBJECT (accessible));
1092 klass = ATK_OBJECT_GET_CLASS (accessible);
1093 if (klass->set_role)
1095 old_role = atk_object_get_role (accessible);
1096 if (old_role != role)
1098 (klass->set_role) (accessible, role);
1099 if (old_role != ATK_ROLE_UNKNOWN)
1100 /* Do not notify for initial role setting */
1101 g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1107 * atk_object_connect_property_change_handler:
1108 * @accessible: an #AtkObject
1109 * @handler: a function to be called when a property changes its value
1111 * Specifies a function to be called when a property changes value.
1113 * Returns: a #guint which is the handler id used in
1114 * atk_object_remove_property_change_handler()
1116 guint
1117 atk_object_connect_property_change_handler (AtkObject *accessible,
1118 AtkPropertyChangeHandler *handler)
1120 AtkObjectClass *klass;
1122 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1123 g_return_val_if_fail ((handler != NULL), 0);
1125 klass = ATK_OBJECT_GET_CLASS (accessible);
1126 if (klass->connect_property_change_handler)
1127 return (klass->connect_property_change_handler) (accessible, handler);
1128 else
1129 return 0;
1133 * atk_object_remove_property_change_handler:
1134 * @accessible: an #AtkObject
1135 * @handler_id: a guint which identifies the handler to be removed.
1137 * Removes a property change handler.
1139 void
1140 atk_object_remove_property_change_handler (AtkObject *accessible,
1141 guint handler_id)
1143 AtkObjectClass *klass;
1145 g_return_if_fail (ATK_IS_OBJECT (accessible));
1147 klass = ATK_OBJECT_GET_CLASS (accessible);
1148 if (klass->remove_property_change_handler)
1149 (klass->remove_property_change_handler) (accessible, handler_id);
1153 * atk_object_notify_state_change:
1154 * @accessible: an #AtkObject
1155 * @state: an #AtkState whose state is changed
1156 * @value: a gboolean which indicates whether the state is being set on or off
1158 * Emits a state-change signal for the specified state.
1160 void
1161 atk_object_notify_state_change (AtkObject *accessible,
1162 AtkState state,
1163 gboolean value)
1165 const gchar* name;
1167 g_return_if_fail (ATK_IS_OBJECT (accessible));
1169 name = atk_state_type_get_name (state);
1170 g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1171 g_quark_from_string (name),
1172 name, value, NULL);
1176 * atk_implementor_ref_accessible:
1177 * @implementor: The #GObject instance which should implement #AtkImplementorIface
1178 * if a non-null return value is required.
1180 * Gets a reference to an object's #AtkObject implementation, if
1181 * the object implements #AtkObjectIface
1183 * Returns: (transfer full): a reference to an object's #AtkObject
1184 * implementation
1186 AtkObject *
1187 atk_implementor_ref_accessible (AtkImplementor *implementor)
1189 AtkImplementorIface *iface;
1190 AtkObject *accessible = NULL;
1192 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1194 iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1196 if (iface != NULL)
1197 accessible = iface->ref_accessible (implementor);
1199 g_return_val_if_fail ((accessible != NULL), NULL);
1201 return accessible;
1206 * atk_object_get_attributes:
1207 * @accessible: An #AtkObject.
1209 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
1210 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
1211 * as distinct from strongly-typed object data available via other get/set methods.
1212 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1214 * Since: 1.12
1216 * Returns: (transfer none): an #AtkAttributeSet consisting of all explicit
1217 * properties/annotations applied to the object, or an empty set if the object
1218 * has no name-value pair attributes assigned to it.
1220 AtkAttributeSet *
1221 atk_object_get_attributes (AtkObject *accessible)
1223 AtkObjectClass *klass;
1225 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1227 klass = ATK_OBJECT_GET_CLASS (accessible);
1228 if (klass->get_attributes)
1229 return (klass->get_attributes) (accessible);
1230 else
1231 return NULL;
1235 static AtkRelationSet*
1236 atk_object_real_ref_relation_set (AtkObject *accessible)
1238 g_return_val_if_fail (accessible->relation_set, NULL);
1239 g_object_ref (accessible->relation_set);
1241 return accessible->relation_set;
1244 static void
1245 atk_object_real_set_property (GObject *object,
1246 guint prop_id,
1247 const GValue *value,
1248 GParamSpec *pspec)
1250 AtkObject *accessible;
1252 accessible = ATK_OBJECT (object);
1254 switch (prop_id)
1256 case PROP_NAME:
1257 atk_object_set_name (accessible, g_value_get_string (value));
1258 break;
1259 case PROP_DESCRIPTION:
1260 atk_object_set_description (accessible, g_value_get_string (value));
1261 break;
1262 case PROP_ROLE:
1263 atk_object_set_role (accessible, g_value_get_int (value));
1264 break;
1265 case PROP_PARENT:
1266 atk_object_set_parent (accessible, g_value_get_object (value));
1267 break;
1268 case PROP_VALUE:
1269 if (ATK_IS_VALUE (accessible))
1270 atk_value_set_current_value (ATK_VALUE (accessible), value);
1271 break;
1272 case PROP_TABLE_SUMMARY:
1273 if (ATK_IS_TABLE (accessible))
1274 atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1275 break;
1276 case PROP_TABLE_CAPTION_OBJECT:
1277 if (ATK_IS_TABLE (accessible))
1278 atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1279 break;
1280 default:
1281 break;
1285 static void
1286 atk_object_real_get_property (GObject *object,
1287 guint prop_id,
1288 GValue *value,
1289 GParamSpec *pspec)
1291 AtkObject *accessible;
1293 accessible = ATK_OBJECT (object);
1295 switch (prop_id)
1297 case PROP_NAME:
1298 g_value_set_string (value, atk_object_get_name (accessible));
1299 break;
1300 case PROP_DESCRIPTION:
1301 g_value_set_string (value, atk_object_get_description (accessible));
1302 break;
1303 case PROP_ROLE:
1304 g_value_set_int (value, atk_object_get_role (accessible));
1305 break;
1306 case PROP_LAYER:
1307 if (ATK_IS_COMPONENT (accessible))
1308 g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1309 break;
1310 case PROP_MDI_ZORDER:
1311 if (ATK_IS_COMPONENT (accessible))
1312 g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1313 break;
1314 case PROP_PARENT:
1315 g_value_set_object (value, atk_object_get_parent (accessible));
1316 break;
1317 case PROP_VALUE:
1318 if (ATK_IS_VALUE (accessible))
1319 atk_value_get_current_value (ATK_VALUE (accessible), value);
1320 break;
1321 case PROP_TABLE_SUMMARY:
1322 if (ATK_IS_TABLE (accessible))
1323 g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1324 break;
1325 case PROP_TABLE_CAPTION_OBJECT:
1326 if (ATK_IS_TABLE (accessible))
1327 g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1328 break;
1329 case PROP_HYPERTEXT_NUM_LINKS:
1330 if (ATK_IS_HYPERTEXT (accessible))
1331 g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1332 break;
1333 default:
1334 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1335 break;
1339 static void
1340 atk_object_finalize (GObject *object)
1342 AtkObject *accessible;
1344 g_return_if_fail (ATK_IS_OBJECT (object));
1346 accessible = ATK_OBJECT (object);
1348 g_free (accessible->name);
1349 g_free (accessible->description);
1352 * Free memory allocated for relation set if it have been allocated.
1354 if (accessible->relation_set)
1355 g_object_unref (accessible->relation_set);
1357 if (accessible->accessible_parent)
1358 g_object_unref (accessible->accessible_parent);
1360 G_OBJECT_CLASS (parent_class)->finalize (object);
1363 static const gchar*
1364 atk_object_real_get_name (AtkObject *object)
1366 return object->name;
1369 static const gchar*
1370 atk_object_real_get_description (AtkObject *object)
1372 return object->description;
1375 static AtkObject*
1376 atk_object_real_get_parent (AtkObject *object)
1378 return object->accessible_parent;
1381 static AtkRole
1382 atk_object_real_get_role (AtkObject *object)
1384 return object->role;
1387 static AtkLayer
1388 atk_object_real_get_layer (AtkObject *object)
1390 return object->layer;
1393 static AtkStateSet*
1394 atk_object_real_ref_state_set (AtkObject *accessible)
1396 AtkStateSet *state_set;
1397 AtkObject *ap;
1398 AtkObject *focus_object;
1400 state_set = atk_state_set_new ();
1402 ap = atk_object_get_parent (accessible);
1403 if (ap)
1404 if (ATK_IS_SELECTION (ap))
1406 int i;
1408 atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
1410 i = atk_object_get_index_in_parent (accessible);
1411 if (i >= 0)
1412 if (atk_selection_is_child_selected(ATK_SELECTION (ap), i))
1413 atk_state_set_add_state (state_set, ATK_STATE_SELECTED);
1415 focus_object = atk_get_focus_object ();
1416 if (focus_object == accessible)
1417 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1419 return state_set;
1422 static void
1423 atk_object_real_set_name (AtkObject *object,
1424 const gchar *name)
1426 g_free (object->name);
1427 object->name = g_strdup (name);
1430 static void
1431 atk_object_real_set_description (AtkObject *object,
1432 const gchar *description)
1434 g_free (object->description);
1435 object->description = g_strdup (description);
1438 static void
1439 atk_object_real_set_parent (AtkObject *object,
1440 AtkObject *parent)
1442 if (object->accessible_parent)
1443 g_object_unref (object->accessible_parent);
1445 object->accessible_parent = parent;
1446 if (object->accessible_parent)
1447 g_object_ref (object->accessible_parent);
1450 static void
1451 atk_object_real_set_role (AtkObject *object,
1452 AtkRole role)
1454 object->role = role;
1457 static guint
1458 atk_object_real_connect_property_change_handler (AtkObject *obj,
1459 AtkPropertyChangeHandler *handler)
1461 return g_signal_connect_closure_by_id (obj,
1462 atk_object_signals[PROPERTY_CHANGE],
1464 g_cclosure_new (
1465 G_CALLBACK (handler), NULL,
1466 (GClosureNotify) NULL),
1467 FALSE);
1470 static void
1471 atk_object_real_remove_property_change_handler (AtkObject *obj,
1472 guint handler_id)
1474 g_signal_handler_disconnect (obj, handler_id);
1478 * atk_object_initialize:
1479 * @accessible: a #AtkObject
1480 * @data: a #gpointer which identifies the object for which the AtkObject was created.
1482 * This function is called when implementing subclasses of #AtkObject.
1483 * It does initialization required for the new object. It is intended
1484 * that this function should called only in the ..._new() functions used
1485 * to create an instance of a subclass of #AtkObject
1487 void
1488 atk_object_initialize (AtkObject *accessible,
1489 gpointer data)
1491 AtkObjectClass *klass;
1493 g_return_if_fail (ATK_IS_OBJECT (accessible));
1495 klass = ATK_OBJECT_GET_CLASS (accessible);
1496 if (klass->initialize)
1497 klass->initialize (accessible, data);
1501 * This function is a signal handler for notify signal which gets emitted
1502 * when a property changes value.
1504 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1505 * signal which causes the user specified AtkPropertyChangeHandler
1506 * to be called.
1508 static void
1509 atk_object_notify (GObject *obj,
1510 GParamSpec *pspec)
1512 AtkPropertyValues values = { NULL, };
1514 g_value_init (&values.new_value, pspec->value_type);
1515 g_object_get_property (obj, pspec->name, &values.new_value);
1516 values.property_name = pspec->name;
1517 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1518 g_quark_from_string (pspec->name),
1519 &values, NULL);
1520 g_value_unset (&values.new_value);
1524 * atk_role_get_name:
1525 * @role: The #AtkRole whose name is required
1527 * Gets the description string describing the #AtkRole @role.
1529 * Returns: the string describing the AtkRole
1531 const gchar*
1532 atk_role_get_name (AtkRole role)
1534 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1535 return roles + roles_offsets[role];
1537 if (extra_roles)
1539 gint n = role;
1541 n -= ATK_ROLE_LAST_DEFINED + 1;
1543 if (n >= 0 && n < extra_roles->len)
1544 return g_ptr_array_index (extra_roles, n);
1547 return NULL;
1551 * atk_role_get_localized_name:
1552 * @role: The #AtkRole whose localized name is required
1554 * Gets the localized description string describing the #AtkRole @role.
1556 * Returns: the localized string describing the AtkRole
1558 const gchar*
1559 atk_role_get_localized_name (AtkRole role)
1561 gettext_initialization ();
1563 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
1564 return dgettext (GETTEXT_PACKAGE, roles + roles_offsets[role]);
1566 return atk_role_get_name (role);
1570 * atk_role_for_name:
1571 * @name: a string which is the (non-localized) name of an ATK role.
1573 * Get the #AtkRole type corresponding to a rolew name.
1575 * Returns: the #AtkRole enumerated type corresponding to the specified
1576 name,
1577 * or #ATK_ROLE_INVALID if no matching role is found.
1579 AtkRole
1580 atk_role_for_name (const gchar *name)
1582 AtkRole role = ATK_ROLE_INVALID;
1583 gint i;
1585 g_return_val_if_fail (name, ATK_ROLE_INVALID);
1587 for (i = 0; i < G_N_ELEMENTS (roles_offsets); i++)
1589 if (strcmp (name, roles + roles_offsets[i]) == 0)
1590 return (AtkRole) i;
1593 if (extra_roles)
1595 for (i = 0; i < extra_roles->len; i++)
1597 gchar *extra_role = (gchar *)g_ptr_array_index (extra_roles, i);
1599 g_return_val_if_fail (extra_role, ATK_ROLE_INVALID);
1601 if (strcmp (name, extra_role) == 0)
1603 role = i + 1 + ATK_ROLE_LAST_DEFINED;
1604 break;
1609 return role;
1613 * atk_object_add_relationship:
1614 * @object: The #AtkObject to which an AtkRelation is to be added.
1615 * @relationship: The #AtkRelationType of the relation
1616 * @target: The #AtkObject which is to be the target of the relation.
1618 * Adds a relationship of the specified type with the specified target.
1620 * Returns TRUE if the relationship is added.
1622 gboolean
1623 atk_object_add_relationship (AtkObject *object,
1624 AtkRelationType relationship,
1625 AtkObject *target)
1627 AtkObject *array[1];
1628 AtkRelation *relation;
1630 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1631 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1633 if (atk_relation_set_contains (object->relation_set, relationship))
1634 return FALSE;
1636 array[0] = target;
1637 relation = atk_relation_new (array, 1, relationship);
1638 atk_relation_set_add (object->relation_set, relation);
1639 g_object_unref (relation);
1641 return TRUE;
1645 * atk_object_remove_relationship:
1646 * @object: The #AtkObject from which an AtkRelation is to be removed.
1647 * @relationship: The #AtkRelationType of the relation
1648 * @target: The #AtkObject which is the target of the relation to be removed.
1650 * Removes a relationship of the specified type with the specified target.
1652 * Returns TRUE if the relationship is removed.
1654 gboolean
1655 atk_object_remove_relationship (AtkObject *object,
1656 AtkRelationType relationship,
1657 AtkObject *target)
1659 gboolean ret = FALSE;
1660 AtkRelation *relation;
1661 GPtrArray *array;
1663 g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1664 g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1666 relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1668 if (relation)
1670 ret = atk_relation_remove_target (relation, target);
1671 array = atk_relation_get_target (relation);
1672 if (!array || array->len == 0)
1673 atk_relation_set_remove (object->relation_set, relation);
1675 return ret;
1678 static void
1679 atk_object_real_initialize (AtkObject *accessible,
1680 gpointer data)
1682 return;