1848fb3ce07822381abb1273df080bfa8d0bb5f8
[platform/upstream/atk.git] / atk / atkobject.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include <string.h>
21 #include <locale.h>
22
23 #include <glib-object.h>
24
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
32
33 #include "atk.h"
34 #include "atkmarshal.h"
35 #include "atk-enum-types.h"
36 #include "atkintl.h"
37
38 /**
39  * SECTION:atkobject
40  * @Short_description: The base object class for the Accessibility Toolkit API.
41  * @Title:AtkObject
42  *
43  * This class is the primary class for accessibility support via the
44  * Accessibility ToolKit (ATK).  Objects which are instances of
45  * #AtkObject (or instances of AtkObject-derived types) are queried
46  * for properties which relate basic (and generic) properties of a UI
47  * component such as name and description.  Instances of #AtkObject
48  * may also be queried as to whether they implement other ATK
49  * interfaces (e.g. #AtkAction, #AtkComponent, etc.), as appropriate
50  * to the role which a given UI component plays in a user interface.
51  *
52  * All UI components in an application which provide useful
53  * information or services to the user must provide corresponding
54  * #AtkObject instances on request (in GTK+, for instance, usually on
55  * a call to #gtk_widget_get_accessible ()), either via ATK support
56  * built into the toolkit for the widget class or ancestor class, or
57  * in the case of custom widgets, if the inherited #AtkObject
58  * implementation is insufficient, via instances of a new #AtkObject
59  * subclass.
60  *
61  * See also: #AtkObjectFactory, #AtkRegistry.  (GTK+ users see also
62  * #GtkAccessible).
63  *
64  */
65
66 static GPtrArray *role_names = NULL;
67
68 enum
69 {
70   PROP_0,  /* gobject convention */
71
72   PROP_NAME,
73   PROP_DESCRIPTION,
74   PROP_PARENT,      /* ancestry has changed */
75   PROP_VALUE,
76   PROP_ROLE,
77   PROP_LAYER,
78   PROP_MDI_ZORDER,
79   PROP_TABLE_CAPTION,
80   PROP_TABLE_COLUMN_DESCRIPTION,
81   PROP_TABLE_COLUMN_HEADER,
82   PROP_TABLE_ROW_DESCRIPTION,
83   PROP_TABLE_ROW_HEADER,
84   PROP_TABLE_SUMMARY,
85   PROP_TABLE_CAPTION_OBJECT,
86   PROP_HYPERTEXT_NUM_LINKS,
87   PROP_LAST         /* gobject convention */
88 };
89
90 enum {
91   CHILDREN_CHANGED,
92   FOCUS_EVENT,
93   PROPERTY_CHANGE,
94   STATE_CHANGE,
95   VISIBLE_DATA_CHANGED,
96   ACTIVE_DESCENDANT_CHANGED,
97   
98   LAST_SIGNAL
99 };
100
101 /* These are listed here for extraction by intltool */
102 #if 0
103   N_("invalid")
104   N_("accelerator label")
105   N_("alert")
106   N_("animation")
107   N_("arrow")
108   N_("calendar")
109   N_("canvas")
110   N_("check box")
111   N_("check menu item")
112   N_("color chooser")
113   N_("column header")
114   N_("combo box")
115   N_("dateeditor")
116   N_("desktop icon")
117   N_("desktop frame")
118   N_("dial")
119   N_("dialog")
120   N_("directory pane")
121   N_("drawing area")
122   N_("file chooser")
123   N_("filler")
124   /* I know it looks wrong but that is what Java returns */
125   N_("fontchooser")
126   N_("frame")
127   N_("glass pane")
128   N_("html container")
129   N_("icon")
130   N_("image")
131   N_("internal frame")
132   N_("label")
133   N_("layered pane")
134   N_("list")
135   N_("list item")
136   N_("menu")
137   N_("menu bar")
138   N_("menu item")
139   N_("option pane")
140   N_("page tab")
141   N_("page tab list")
142   N_("panel")
143   N_("password text")
144   N_("popup menu")
145   N_("progress bar")
146   N_("push button")
147   N_("radio button")
148   N_("radio menu item")
149   N_("root pane")
150   N_("row header")
151   N_("scroll bar")
152   N_("scroll pane")
153   N_("separator")
154   N_("slider")
155   N_("split pane")
156   N_("spin button")
157   N_("statusbar")
158   N_("table")
159   N_("table cell")
160   N_("table column header")
161   N_("table row header")
162   N_("tear off menu item")
163   N_("terminal")
164   N_("text")
165   N_("toggle button")
166   N_("tool bar")
167   N_("tool tip")
168   N_("tree")
169   N_("tree table")
170   N_("unknown")
171   N_("viewport")
172   N_("window")
173   N_("header")
174   N_("footer")
175   N_("paragraph")
176   N_("ruler")
177   N_("application")
178   N_("autocomplete")
179   N_("edit bar")
180   N_("embedded component")
181   N_("entry")
182   N_("chart")
183   N_("caption")
184   N_("document frame")
185   N_("heading")
186   N_("page")
187   N_("section")
188   N_("redundant object")
189   N_("form")
190   N_("link")
191   N_("input method window")
192   N_("table row")
193   N_("tree item")
194   N_("document spreadsheet")
195   N_("document presentation")
196   N_("document text")
197   N_("document web")
198   N_("document email")
199   N_("comment")
200   N_("list box")
201   N_("grouping")
202   N_("image map")
203   N_("notification")
204   N_("info bar")
205   N_("level bar")
206   N_("title bar")
207   N_("block quote")
208   N_("audio")
209   N_("video")
210 #endif /* 0 */
211
212 static void            atk_object_class_init        (AtkObjectClass  *klass);
213 static void            atk_object_init              (AtkObject       *accessible,
214                                                      AtkObjectClass  *klass);
215 static AtkRelationSet* atk_object_real_ref_relation_set 
216                                                     (AtkObject       *accessible);
217 static void            atk_object_real_initialize   (AtkObject       *accessible,
218                                                      gpointer        data);
219 static void            atk_object_real_set_property (GObject         *object,
220                                                      guint            prop_id,
221                                                      const GValue    *value,
222                                                      GParamSpec      *pspec);
223 static void            atk_object_real_get_property (GObject         *object,
224                                                      guint            prop_id,
225                                                      GValue          *value,
226                                                      GParamSpec      *pspec);
227 static void            atk_object_finalize          (GObject         *object);
228 static const gchar*    atk_object_real_get_name     (AtkObject       *object);
229 static const gchar*    atk_object_real_get_description
230                                                    (AtkObject       *object);
231 static AtkObject*      atk_object_real_get_parent  (AtkObject       *object);
232 static AtkRole         atk_object_real_get_role    (AtkObject       *object);
233 static AtkLayer        atk_object_real_get_layer   (AtkObject       *object);
234 static AtkStateSet*    atk_object_real_ref_state_set
235                                                    (AtkObject       *object);
236 static void            atk_object_real_set_name    (AtkObject       *object,
237                                                     const gchar     *name);
238 static void            atk_object_real_set_description
239                                                    (AtkObject       *object,
240                                                     const gchar     *description);
241 static void            atk_object_real_set_parent  (AtkObject       *object,
242                                                     AtkObject       *parent);
243 static void            atk_object_real_set_role    (AtkObject       *object,
244                                                     AtkRole         role);
245 static void            atk_object_notify           (GObject         *obj,
246                                                     GParamSpec      *pspec);
247 static const gchar*    atk_object_real_get_object_locale
248                                                    (AtkObject       *object);
249
250 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
251
252 static gpointer parent_class = NULL;
253
254 static const gchar* const atk_object_name_property_name = "accessible-name";
255 static const gchar* const atk_object_name_property_description = "accessible-description";
256 static const gchar* const atk_object_name_property_parent = "accessible-parent";
257 static const gchar* const atk_object_name_property_value = "accessible-value";
258 static const gchar* const atk_object_name_property_role = "accessible-role";
259 static const gchar* const atk_object_name_property_component_layer = "accessible-component-layer";
260 static const gchar* const atk_object_name_property_component_mdi_zorder = "accessible-component-mdi-zorder";
261 static const gchar* const atk_object_name_property_table_caption = "accessible-table-caption";
262 static const gchar* const atk_object_name_property_table_column_description = "accessible-table-column-description";
263 static const gchar* const atk_object_name_property_table_column_header = "accessible-table-column-header";
264 static const gchar* const atk_object_name_property_table_row_description = "accessible-table-row-description";
265 static const gchar* const atk_object_name_property_table_row_header = "accessible-table-row-header";
266 static const gchar* const atk_object_name_property_table_summary = "accessible-table-summary";
267 static const gchar* const atk_object_name_property_table_caption_object = "accessible-table-caption-object";
268 static const gchar* const atk_object_name_property_hypertext_num_links = "accessible-hypertext-nlinks";
269
270 #ifdef G_OS_WIN32
271
272 static HMODULE atk_dll;
273
274 BOOL WINAPI
275 DllMain (HINSTANCE hinstDLL,
276          DWORD     fdwReason,
277          LPVOID    lpvReserved)
278 {
279   switch (fdwReason)
280     {
281     case DLL_PROCESS_ATTACH:
282       atk_dll = (HMODULE) hinstDLL;
283       break;
284     }
285
286   return TRUE;
287 }
288
289 static const char *
290 get_atk_locale_dir (void)
291 {
292   static gchar *atk_localedir = NULL;
293
294   if (!atk_localedir)
295     {
296       const gchar *p;
297       gchar *root, *temp;
298       
299       /* ATK_LOCALEDIR might end in either /lib/locale or
300        * /share/locale. Scan for that slash.
301        */
302       p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
303       while (*--p != '/')
304         ;
305       while (*--p != '/')
306         ;
307
308       root = g_win32_get_package_installation_directory_of_module (atk_dll);
309       temp = g_build_filename (root, p, NULL);
310       g_free (root);
311
312       /* atk_localedir is passed to bindtextdomain() which isn't
313        * UTF-8-aware.
314        */
315       atk_localedir = g_win32_locale_filename_from_utf8 (temp);
316       g_free (temp);
317     }
318   return atk_localedir;
319 }
320
321 #undef ATK_LOCALEDIR
322
323 #define ATK_LOCALEDIR get_atk_locale_dir()
324
325 #endif
326
327 static void
328 gettext_initialization (void)
329 {
330 #ifdef ENABLE_NLS
331   static gboolean gettext_initialized = FALSE;
332
333   if (!gettext_initialized)
334     {
335       const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
336
337       gettext_initialized = TRUE;
338       if (dir == NULL)
339         dir = ATK_LOCALEDIR;
340
341       bindtextdomain (GETTEXT_PACKAGE, dir);
342 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
343       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
344 #endif
345     }
346 #endif
347 }
348
349 static void
350 compact_role_name (gchar *role_name)
351 {
352   gchar *p = role_name;
353
354   while (*p)
355     {
356       if (*p == '-')
357         *p = ' ';
358       p++;
359     }
360 }
361
362 static void
363 initialize_role_names ()
364 {
365   GTypeClass *enum_class;
366   GEnumValue *enum_value;
367   int i;
368   gchar *role_name = NULL;
369
370   if (role_names)
371     return;
372
373   role_names = g_ptr_array_new ();
374   enum_class = g_type_class_ref (ATK_TYPE_ROLE);
375   if (!G_IS_ENUM_CLASS(enum_class))
376     return;
377
378   for (i = 0; i < ATK_ROLE_LAST_DEFINED; i++)
379     {
380       enum_value = g_enum_get_value (G_ENUM_CLASS (enum_class), i);
381       role_name = g_strdup (enum_value->value_nick);
382       // We want the role names to be in the format "check button" and not "check-button"
383       compact_role_name (role_name);
384       g_ptr_array_add (role_names, role_name);
385     }
386
387   g_type_class_unref (enum_class);
388
389 }
390
391 GType
392 atk_object_get_type (void)
393 {
394   static GType type = 0;
395
396   if (!type)
397     {
398       static const GTypeInfo typeInfo =
399       {
400         sizeof (AtkObjectClass),
401         (GBaseInitFunc) NULL,
402         (GBaseFinalizeFunc) NULL,
403         (GClassInitFunc) atk_object_class_init,
404         (GClassFinalizeFunc) NULL,
405         NULL,
406         sizeof (AtkObject),
407         0,
408         (GInstanceInitFunc) atk_object_init,
409       } ;
410       type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
411     }
412   return type;
413 }
414
415 static void
416 atk_object_class_init (AtkObjectClass *klass)
417 {
418   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
419
420   parent_class = g_type_class_peek_parent (klass);
421
422   gobject_class->set_property = atk_object_real_set_property;
423   gobject_class->get_property = atk_object_real_get_property;
424   gobject_class->finalize = atk_object_finalize;
425   gobject_class->notify = atk_object_notify;
426
427   klass->get_name = atk_object_real_get_name;
428   klass->get_description = atk_object_real_get_description;
429   klass->get_parent = atk_object_real_get_parent;
430   klass->get_n_children = NULL;
431   klass->ref_child = NULL;
432   klass->get_index_in_parent = NULL;
433   klass->ref_relation_set = atk_object_real_ref_relation_set;
434   klass->get_role = atk_object_real_get_role;
435   klass->get_layer = atk_object_real_get_layer;
436   klass->get_mdi_zorder = NULL;
437   klass->initialize = atk_object_real_initialize;
438   klass->ref_state_set = atk_object_real_ref_state_set;
439   klass->set_name = atk_object_real_set_name;
440   klass->set_description = atk_object_real_set_description;
441   klass->set_parent = atk_object_real_set_parent;
442   klass->set_role = atk_object_real_set_role;
443   klass->get_object_locale = atk_object_real_get_object_locale;
444
445   /*
446    * We do not define default signal handlers here
447    */
448   klass->children_changed = NULL;
449   klass->focus_event = NULL;
450   klass->property_change = NULL;
451   klass->visible_data_changed = NULL;
452   klass->active_descendant_changed = NULL;
453
454   gettext_initialization ();
455
456   g_object_class_install_property (gobject_class,
457                                    PROP_NAME,
458                                    g_param_spec_string (atk_object_name_property_name,
459                                                         _("Accessible Name"),
460                                                         _("Object instance\'s name formatted for assistive technology access"),
461                                                         NULL,
462                                                         G_PARAM_READWRITE));
463   g_object_class_install_property (gobject_class,
464                                    PROP_DESCRIPTION,
465                                    g_param_spec_string (atk_object_name_property_description,
466                                                         _("Accessible Description"),
467                                                         _("Description of an object, formatted for assistive technology access"),
468                                                         NULL,
469                                                         G_PARAM_READWRITE));
470   g_object_class_install_property (gobject_class,
471                                    PROP_PARENT,
472                                    g_param_spec_object (atk_object_name_property_parent,
473                                                         _("Accessible Parent"),
474                                                         _("Parent of the current accessible as returned by atk_object_get_parent()"),
475                                                         ATK_TYPE_OBJECT,
476                                                         G_PARAM_READWRITE));
477   g_object_class_install_property (gobject_class,
478                                    PROP_VALUE,
479                                    g_param_spec_double (atk_object_name_property_value,
480                                                         _("Accessible Value"),
481                                                         _("Is used to notify that the value has changed"),
482                                                         0.0,
483                                                         G_MAXDOUBLE,
484                                                         0.0,
485                                                         G_PARAM_READWRITE));
486   g_object_class_install_property (gobject_class,
487                                    PROP_ROLE,
488                                    g_param_spec_int    (atk_object_name_property_role,
489                                                         _("Accessible Role"),
490                                                         _("The accessible role of this object"),
491                                                         0,
492                                                         G_MAXINT,
493                                                         ATK_ROLE_UNKNOWN,
494                                                         G_PARAM_READWRITE));
495   g_object_class_install_property (gobject_class,
496                                    PROP_LAYER,
497                                    g_param_spec_int    (atk_object_name_property_component_layer,
498                                                         _("Accessible Layer"),
499                                                         _("The accessible layer of this object"),
500                                                         0,
501                                                         G_MAXINT,
502                                                         0,
503                                                         G_PARAM_READABLE));
504   g_object_class_install_property (gobject_class,
505                                    PROP_MDI_ZORDER,
506                                    g_param_spec_int    (atk_object_name_property_component_mdi_zorder,
507                                                         _("Accessible MDI Value"),
508                                                         _("The accessible MDI value of this object"),
509                                                         G_MININT,
510                                                         G_MAXINT,
511                                                         G_MININT,
512                                                         G_PARAM_READABLE));
513   g_object_class_install_property (gobject_class,
514                                    PROP_TABLE_CAPTION,
515                                    g_param_spec_string (atk_object_name_property_table_caption,
516                                                         _("Accessible Table Caption"),
517                                                         _("Is used to notify that the table caption has changed; this property should not be used. accessible-table-caption-object should be used instead"),
518                                                         NULL,
519                                                         G_PARAM_READWRITE));
520   g_object_class_install_property (gobject_class,
521                                    PROP_TABLE_COLUMN_HEADER,
522                                    g_param_spec_object (atk_object_name_property_table_column_header,
523                                                         _("Accessible Table Column Header"),
524                                                         _("Is used to notify that the table column header has changed"),
525                                                         ATK_TYPE_OBJECT,
526                                                         G_PARAM_READWRITE));
527   g_object_class_install_property (gobject_class,
528                                    PROP_TABLE_COLUMN_DESCRIPTION,
529                                    g_param_spec_string (atk_object_name_property_table_column_description,
530                                                         _("Accessible Table Column Description"),
531                                                         _("Is used to notify that the table column description has changed"),
532                                                         NULL,
533                                                         G_PARAM_READWRITE));
534   g_object_class_install_property (gobject_class,
535                                    PROP_TABLE_ROW_HEADER,
536                                    g_param_spec_object (atk_object_name_property_table_row_header,
537                                                         _("Accessible Table Row Header"),
538                                                         _("Is used to notify that the table row header has changed"),
539                                                         ATK_TYPE_OBJECT,
540                                                         G_PARAM_READWRITE));
541   g_object_class_install_property (gobject_class,
542                                    PROP_TABLE_ROW_DESCRIPTION,
543                                    g_param_spec_string (atk_object_name_property_table_row_description,
544                                                         _("Accessible Table Row Description"),
545                                                         _("Is used to notify that the table row description has changed"),
546                                                         NULL,
547                                                         G_PARAM_READWRITE));
548   g_object_class_install_property (gobject_class,
549                                    PROP_TABLE_SUMMARY,
550                                    g_param_spec_object (atk_object_name_property_table_summary,
551                                                         _("Accessible Table Summary"),
552                                                         _("Is used to notify that the table summary has changed"),
553                                                         ATK_TYPE_OBJECT,
554                                                         G_PARAM_READWRITE));
555   g_object_class_install_property (gobject_class,
556                                    PROP_TABLE_CAPTION_OBJECT,
557                                    g_param_spec_object (atk_object_name_property_table_caption_object,
558                                                         _("Accessible Table Caption Object"),
559                                                         _("Is used to notify that the table caption has changed"),
560                                                         ATK_TYPE_OBJECT,
561                                                         G_PARAM_READWRITE));
562   g_object_class_install_property (gobject_class,
563                                    PROP_HYPERTEXT_NUM_LINKS,
564                                    g_param_spec_int    (atk_object_name_property_hypertext_num_links,
565                                                         _("Number of Accessible Hypertext Links"),
566                                                         _("The number of links which the current AtkHypertext has"),
567                                                         0,
568                                                         G_MAXINT,
569                                                         0,
570                                                         G_PARAM_READABLE));
571
572   /**
573    * AtkObject::children-changed:
574    * @atkobject: the object which received the signal.
575    * @arg1: The index of the added or removed child. The value can be
576    * -1. This is used if the value is not known by the implementor
577    * when the child is added/removed or irrelevant.
578    * @arg2: A gpointer to the child AtkObject which was added or
579    * removed. If the child was removed, it is possible that it is not
580    * available for the implementor. In that case this pointer can be
581    * NULL.
582    *
583    * The signal "children-changed" is emitted when a child is added or
584    * removed form an object. It supports two details: "add" and
585    * "remove"
586    */
587   atk_object_signals[CHILDREN_CHANGED] =
588     g_signal_new ("children_changed",
589                   G_TYPE_FROM_CLASS (klass),
590                   G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
591                   G_STRUCT_OFFSET (AtkObjectClass, children_changed),
592                   NULL, NULL,
593                   g_cclosure_marshal_VOID__UINT_POINTER,
594                   G_TYPE_NONE,
595                   2, G_TYPE_UINT, G_TYPE_POINTER);
596
597   /**
598    * AtkObject::focus-event:
599    * @atkobject: the object which received the signal
600    * @arg1: a boolean value which indicates whether the object gained
601    * or lost focus.
602    *
603    * The signal "focus-event" is emitted when an object gained or lost
604    * focus.
605    *
606    * Deprecated: Since 2.9.4. Use #AtkObject::state-change signal instead.
607    */
608   atk_object_signals[FOCUS_EVENT] =
609     g_signal_new ("focus_event",
610                   G_TYPE_FROM_CLASS (klass),
611                   G_SIGNAL_RUN_LAST,
612                   G_STRUCT_OFFSET (AtkObjectClass, focus_event), 
613                   NULL, NULL,
614                   g_cclosure_marshal_VOID__BOOLEAN,
615                   G_TYPE_NONE,
616                   1, G_TYPE_BOOLEAN);
617   /**
618    * AtkObject::property-change:
619    * @atkobject: the object which received the signal.
620    * @arg1: The new value of the property which changed.
621    *
622    * The signal "property-change" is emitted when an object's property
623    * value changes. The detail identifies the name of the property
624    * whose value has changed.
625    */
626   atk_object_signals[PROPERTY_CHANGE] =
627     g_signal_new ("property_change",
628                   G_TYPE_FROM_CLASS (klass),
629                   G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
630                   G_STRUCT_OFFSET (AtkObjectClass, property_change),
631                   (GSignalAccumulator) NULL, NULL,
632                   g_cclosure_marshal_VOID__POINTER,
633                   G_TYPE_NONE, 1,
634                   G_TYPE_POINTER);
635
636   /**
637    * AtkObject::state-change:
638    * @atkobject: the object which received the signal.
639    * @arg1: The name of the state which has changed
640    * @arg2: A boolean which indicates whether the state has been set or unset.
641    *
642    * The "state-change" signal is emitted when an object's state
643    * changes.  The detail value identifies the state type which has
644    * changed.
645    */
646   atk_object_signals[STATE_CHANGE] =
647     g_signal_new ("state_change",
648                   G_TYPE_FROM_CLASS (klass),
649                   G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
650                   G_STRUCT_OFFSET (AtkObjectClass, state_change),
651                   (GSignalAccumulator) NULL, NULL,
652                   atk_marshal_VOID__STRING_BOOLEAN,
653                   G_TYPE_NONE, 2,
654                   G_TYPE_STRING,
655                   G_TYPE_BOOLEAN);
656
657   /**
658    * AtkObject::visible-data-changed:
659    * @atkobject: the object which received the signal.
660    *
661    * The "visible-data-changed" signal is emitted when the visual
662    * appearance of the object changed.
663    */
664   atk_object_signals[VISIBLE_DATA_CHANGED] =
665     g_signal_new ("visible_data_changed",
666                   G_TYPE_FROM_CLASS (klass),
667                   G_SIGNAL_RUN_LAST,
668                   G_STRUCT_OFFSET (AtkObjectClass, visible_data_changed),
669                   (GSignalAccumulator) NULL, NULL,
670                   g_cclosure_marshal_VOID__VOID,
671                   G_TYPE_NONE, 0);
672
673   /**
674    * AtkObject::active-descendant-changed:
675    * @atkobject: the object which received the signal.
676    * @arg1: the newly focused object.
677    *
678    * The "active-descendant-changed" signal is emitted by an object
679    * which has the state ATK_STATE_MANAGES_DESCENDANTS when the focus
680    * object in the object changes. For instance, a table will emit the
681    * signal when the cell in the table which has focus changes.
682    */
683   atk_object_signals[ACTIVE_DESCENDANT_CHANGED] =
684     g_signal_new ("active_descendant_changed",
685                   G_TYPE_FROM_CLASS (klass),
686                   G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
687                   G_STRUCT_OFFSET (AtkObjectClass, active_descendant_changed),
688                   NULL, NULL,
689                   g_cclosure_marshal_VOID__POINTER,
690                   G_TYPE_NONE,
691                   1, G_TYPE_POINTER);
692 }
693
694 static void
695 atk_object_init  (AtkObject        *accessible,
696                   AtkObjectClass   *klass)
697 {
698   accessible->name = NULL;
699   accessible->description = NULL;
700   accessible->accessible_parent = NULL;
701   accessible->relation_set = atk_relation_set_new();
702   accessible->role = ATK_ROLE_UNKNOWN;
703 }
704
705 GType
706 atk_implementor_get_type (void)
707 {
708   static GType type = 0;
709
710   if (!type)
711     {
712       static const GTypeInfo typeInfo =
713       {
714         sizeof (AtkImplementorIface),
715         (GBaseInitFunc) NULL,
716         (GBaseFinalizeFunc) NULL,
717       } ;
718
719       type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
720     }
721
722   return type;
723 }
724
725 /**
726  * atk_object_get_name:
727  * @accessible: an #AtkObject
728  *
729  * Gets the accessible name of the accessible.
730  *
731  * Returns: a character string representing the accessible name of the object.
732  **/
733 const gchar*
734 atk_object_get_name (AtkObject *accessible)
735 {
736   AtkObjectClass *klass;
737
738   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
739
740   klass = ATK_OBJECT_GET_CLASS (accessible);
741   if (klass->get_name)
742     return (klass->get_name) (accessible);
743   else
744     return NULL;
745 }
746
747 /**
748  * atk_object_get_description:
749  * @accessible: an #AtkObject
750  *
751  * Gets the accessible description of the accessible.
752  *
753  * Returns: a character string representing the accessible description
754  * of the accessible.
755  *
756  **/
757 const gchar*
758 atk_object_get_description (AtkObject *accessible)
759 {
760   AtkObjectClass *klass;
761
762   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
763
764   klass = ATK_OBJECT_GET_CLASS (accessible);
765   if (klass->get_description)
766     return (klass->get_description) (accessible);
767   else
768     return NULL;
769 }
770
771 /**
772  * atk_object_get_parent:
773  * @accessible: an #AtkObject
774  *
775  * Gets the accessible parent of the accessible. By default this is
776  * the one assigned with atk_object_set_parent(), but it is assumed
777  * that ATK implementors have ways to get the parent of the object
778  * without the need of assigning it manually with
779  * atk_object_set_parent(), and will return it with this method.
780  *
781  * If you are only interested on the parent assigned with
782  * atk_object_set_parent(), use atk_object_peek_parent().
783  *
784  * Returns: (transfer none): an #AtkObject representing the accessible
785  * parent of the accessible
786  **/
787 AtkObject*
788 atk_object_get_parent (AtkObject *accessible)
789 {
790   AtkObjectClass *klass;
791
792   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
793
794   klass = ATK_OBJECT_GET_CLASS (accessible);
795   if (klass->get_parent)
796     return (klass->get_parent) (accessible);
797   else
798     return NULL;
799 }
800
801 /**
802  * atk_object_peek_parent:
803  * @accessible: an #AtkObject
804  *
805  * Gets the accessible parent of the accessible, if it has been
806  * manually assigned with atk_object_set_parent. Otherwise, this
807  * function returns %NULL.
808  *
809  * This method is intended as an utility for ATK implementors, and not
810  * to be exposed to accessible tools. See atk_object_get_parent() for
811  * further reference.
812  *
813  * Returns: (transfer none): an #AtkObject representing the accessible
814  * parent of the accessible if assigned
815  **/
816 AtkObject*
817 atk_object_peek_parent (AtkObject *accessible)
818 {
819   return accessible->accessible_parent;
820 }
821
822 /**
823  * atk_object_get_n_accessible_children:
824  * @accessible: an #AtkObject
825  *
826  * Gets the number of accessible children of the accessible.
827  *
828  * Returns: an integer representing the number of accessible children
829  * of the accessible.
830  **/
831 gint
832 atk_object_get_n_accessible_children (AtkObject *accessible)
833 {
834   AtkObjectClass *klass;
835
836   g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
837
838   klass = ATK_OBJECT_GET_CLASS (accessible);
839   if (klass->get_n_children)
840     return (klass->get_n_children) (accessible);
841   else
842     return 0;
843 }
844
845 /**
846  * atk_object_ref_accessible_child:
847  * @accessible: an #AtkObject
848  * @i: a gint representing the position of the child, starting from 0
849  *
850  * Gets a reference to the specified accessible child of the object.
851  * The accessible children are 0-based so the first accessible child is
852  * at index 0, the second at index 1 and so on.
853  *
854  * Returns: (transfer full): an #AtkObject representing the specified
855  * accessible child of the accessible.
856  **/
857 AtkObject*
858 atk_object_ref_accessible_child (AtkObject   *accessible,
859                                  gint        i)
860 {
861   AtkObjectClass *klass;
862
863   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
864
865   klass = ATK_OBJECT_GET_CLASS (accessible);
866   if (klass->ref_child)
867     return (klass->ref_child) (accessible, i);
868   else
869     return NULL;
870 }
871
872 /**
873  * atk_object_ref_relation_set:
874  * @accessible: an #AtkObject
875  *
876  * Gets the #AtkRelationSet associated with the object.
877  *
878  * Returns: (transfer full): an #AtkRelationSet representing the relation set
879  * of the object.
880  **/
881 AtkRelationSet*
882 atk_object_ref_relation_set (AtkObject *accessible)
883 {
884   AtkObjectClass *klass;
885
886   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
887
888   klass = ATK_OBJECT_GET_CLASS (accessible);
889   if (klass->ref_relation_set)
890     return (klass->ref_relation_set) (accessible);
891   else
892     return NULL;
893 }
894
895 /**
896  * atk_role_register:
897  * @name: a character string describing the new role.
898  *
899  * Registers the role specified by @name.
900  *
901  * Returns: an #AtkRole for the new role.
902  **/
903 AtkRole
904 atk_role_register (const gchar *name)
905 {
906   if (!role_names)
907     initialize_role_names ();
908
909   g_ptr_array_add (role_names, g_strdup (name));
910   return role_names->len - 1;
911 }
912
913 /**
914  * atk_object_get_role:
915  * @accessible: an #AtkObject
916  *
917  * Gets the role of the accessible.
918  *
919  * Returns: an #AtkRole which is the role of the accessible
920  **/
921 AtkRole
922 atk_object_get_role (AtkObject *accessible) 
923 {
924   AtkObjectClass *klass;
925
926   g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
927
928   klass = ATK_OBJECT_GET_CLASS (accessible);
929   if (klass->get_role)
930     return (klass->get_role) (accessible);
931   else
932     return ATK_ROLE_UNKNOWN;
933 }
934
935 /**
936  * atk_object_get_layer:
937  * @accessible: an #AtkObject
938  *
939  * Gets the layer of the accessible.
940  *
941  * Deprecated: Use atk_component_get_layer instead.
942  *
943  * Returns: an #AtkLayer which is the layer of the accessible
944  **/
945 AtkLayer
946 atk_object_get_layer (AtkObject *accessible) 
947 {
948   AtkObjectClass *klass;
949
950   g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_LAYER_INVALID);
951
952   klass = ATK_OBJECT_GET_CLASS (accessible);
953   if (klass->get_layer)
954     return (klass->get_layer) (accessible);
955   else
956     return ATK_LAYER_INVALID;
957 }
958
959 /**
960  * atk_object_get_mdi_zorder:
961  * @accessible: an #AtkObject
962  *
963  * Gets the zorder of the accessible. The value G_MININT will be returned 
964  * if the layer of the accessible is not ATK_LAYER_MDI.
965  *
966  * Deprecated: Use atk_component_get_mdi_zorder instead.
967  *
968  * Returns: a gint which is the zorder of the accessible, i.e. the depth at 
969  * which the component is shown in relation to other components in the same 
970  * container.
971  *
972  **/
973 gint
974 atk_object_get_mdi_zorder (AtkObject *accessible) 
975 {
976   AtkObjectClass *klass;
977
978   g_return_val_if_fail (ATK_IS_OBJECT (accessible), G_MININT);
979
980   klass = ATK_OBJECT_GET_CLASS (accessible);
981   if (klass->get_mdi_zorder)
982     return (klass->get_mdi_zorder) (accessible);
983   else
984     return G_MININT;
985 }
986
987 /**
988  * atk_object_ref_state_set:
989  * @accessible: an #AtkObject
990  *
991  * Gets a reference to the state set of the accessible; the caller must
992  * unreference it when it is no longer needed.
993  *
994  * Returns: (transfer full): a reference to an #AtkStateSet which is the state
995  * set of the accessible
996  **/
997 AtkStateSet*
998 atk_object_ref_state_set (AtkObject *accessible) 
999 {
1000   AtkObjectClass *klass;
1001
1002   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1003
1004   klass = ATK_OBJECT_GET_CLASS (accessible);
1005   if (klass->ref_state_set)
1006     return (klass->ref_state_set) (accessible);
1007   else
1008     return NULL;
1009 }
1010
1011 /**
1012  * atk_object_get_index_in_parent:
1013  * @accessible: an #AtkObject
1014  *
1015  * Gets the 0-based index of this accessible in its parent; returns -1 if the
1016  * accessible does not have an accessible parent.
1017  *
1018  * Returns: an integer which is the index of the accessible in its parent
1019  **/
1020 gint
1021 atk_object_get_index_in_parent (AtkObject *accessible)
1022 {
1023   AtkObjectClass *klass;
1024
1025   g_return_val_if_fail (ATK_OBJECT (accessible), -1);
1026
1027   klass = ATK_OBJECT_GET_CLASS (accessible);
1028   if (klass->get_index_in_parent)
1029     return (klass->get_index_in_parent) (accessible);
1030   else
1031     return -1;
1032 }
1033
1034 /**
1035  * atk_object_set_name:
1036  * @accessible: an #AtkObject
1037  * @name: a character string to be set as the accessible name
1038  *
1039  * Sets the accessible name of the accessible. You can't set the name
1040  * to NULL. This is reserved for the initial value. In this aspect
1041  * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
1042  * a empty value you can use "".
1043  **/
1044 void
1045 atk_object_set_name (AtkObject    *accessible,
1046                      const gchar  *name)
1047 {
1048   AtkObjectClass *klass;
1049   gboolean notify = FALSE;
1050
1051   g_return_if_fail (ATK_IS_OBJECT (accessible));
1052   g_return_if_fail (name != NULL);
1053
1054   klass = ATK_OBJECT_GET_CLASS (accessible);
1055   if (klass->set_name)
1056     {
1057       /* Do not notify for initial name setting. See bug 665870 */
1058       notify = (accessible->name != NULL);
1059
1060       (klass->set_name) (accessible, name);
1061       if (notify)
1062         g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
1063     }
1064 }
1065
1066 /**
1067  * atk_object_set_description:
1068  * @accessible: an #AtkObject
1069  * @description: a character string to be set as the accessible description
1070  *
1071  * Sets the accessible description of the accessible. You can't set
1072  * the description to NULL. This is reserved for the initial value. In
1073  * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
1074  * the name to a empty value you can use "".
1075  **/
1076 void
1077 atk_object_set_description (AtkObject   *accessible,
1078                             const gchar *description)
1079 {
1080   AtkObjectClass *klass;
1081   gboolean notify = FALSE;
1082
1083   g_return_if_fail (ATK_IS_OBJECT (accessible));
1084   g_return_if_fail (description != NULL);
1085
1086   klass = ATK_OBJECT_GET_CLASS (accessible);
1087   if (klass->set_description)
1088     {
1089       /* Do not notify for initial name setting. See bug 665870 */
1090       notify = (accessible->description != NULL);
1091
1092       (klass->set_description) (accessible, description);
1093       if (notify)
1094         g_object_notify (G_OBJECT (accessible),
1095                          atk_object_name_property_description);
1096     }
1097 }
1098
1099 /**
1100  * atk_object_set_parent:
1101  * @accessible: an #AtkObject
1102  * @parent: an #AtkObject to be set as the accessible parent
1103  *
1104  * Sets the accessible parent of the accessible. @parent can be NULL.
1105  **/
1106 void
1107 atk_object_set_parent (AtkObject *accessible,
1108                        AtkObject *parent)
1109 {
1110   AtkObjectClass *klass;
1111
1112   g_return_if_fail (ATK_IS_OBJECT (accessible));
1113
1114   klass = ATK_OBJECT_GET_CLASS (accessible);
1115   if (klass->set_parent)
1116     {
1117       (klass->set_parent) (accessible, parent);
1118       g_object_notify (G_OBJECT (accessible), atk_object_name_property_parent);
1119     }
1120 }
1121
1122 /**
1123  * atk_object_set_role:
1124  * @accessible: an #AtkObject
1125  * @role: an #AtkRole to be set as the role
1126  *
1127  * Sets the role of the accessible.
1128  **/
1129 void
1130 atk_object_set_role (AtkObject *accessible, 
1131                      AtkRole   role)
1132 {
1133   AtkObjectClass *klass;
1134   AtkRole old_role;
1135
1136   g_return_if_fail (ATK_IS_OBJECT (accessible));
1137
1138   klass = ATK_OBJECT_GET_CLASS (accessible);
1139   if (klass->set_role)
1140     {
1141       old_role = atk_object_get_role (accessible);
1142       if (old_role != role)
1143         {
1144           (klass->set_role) (accessible, role);
1145           if (old_role != ATK_ROLE_UNKNOWN)
1146           /* Do not notify for initial role setting */
1147             g_object_notify (G_OBJECT (accessible), atk_object_name_property_role);
1148         }
1149     }
1150 }
1151
1152 /**
1153  * atk_object_connect_property_change_handler:
1154  * @accessible: an #AtkObject
1155  * @handler: a function to be called when a property changes its value
1156  *
1157  * Deprecated: Since 2.12. Connect directly to property-change or
1158  * notify signals.
1159  *
1160  * Returns: a #guint which is the handler id used in 
1161  * atk_object_remove_property_change_handler()
1162  **/
1163 guint
1164 atk_object_connect_property_change_handler (AtkObject *accessible,
1165                                             AtkPropertyChangeHandler *handler)
1166 {
1167   AtkObjectClass *klass;
1168
1169   g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
1170   g_return_val_if_fail ((handler != NULL), 0);
1171
1172   klass = ATK_OBJECT_GET_CLASS (accessible);
1173   if (klass->connect_property_change_handler)
1174     return (klass->connect_property_change_handler) (accessible, handler);
1175   else
1176     return 0;
1177 }
1178
1179 /**
1180  * atk_object_remove_property_change_handler:
1181  * @accessible: an #AtkObject
1182  * @handler_id: a guint which identifies the handler to be removed.
1183  *
1184  * Deprecated: Since 2.12.
1185  *
1186  * Removes a property change handler.
1187  **/
1188 void
1189 atk_object_remove_property_change_handler  (AtkObject *accessible,
1190                                             guint      handler_id)
1191 {
1192   AtkObjectClass *klass;
1193
1194   g_return_if_fail (ATK_IS_OBJECT (accessible));
1195
1196   klass = ATK_OBJECT_GET_CLASS (accessible);
1197   if (klass->remove_property_change_handler)
1198     (klass->remove_property_change_handler) (accessible, handler_id);
1199 }
1200
1201 /**
1202  * atk_object_notify_state_change:
1203  * @accessible: an #AtkObject
1204  * @state: an #AtkState whose state is changed
1205  * @value: a gboolean which indicates whether the state is being set on or off
1206  * 
1207  * Emits a state-change signal for the specified state. 
1208  **/
1209 void
1210 atk_object_notify_state_change (AtkObject *accessible,
1211                                 AtkState  state,
1212                                 gboolean  value)
1213 {
1214   const gchar* name;
1215
1216   g_return_if_fail (ATK_IS_OBJECT (accessible));
1217
1218   name = atk_state_type_get_name (state);
1219   g_signal_emit (accessible, atk_object_signals[STATE_CHANGE],
1220                  g_quark_from_string (name),
1221                  name, value, NULL);
1222 }
1223
1224 /**
1225  * atk_implementor_ref_accessible:
1226  * @implementor: The #GObject instance which should implement #AtkImplementorIface
1227  * if a non-null return value is required.
1228  * 
1229  * Gets a reference to an object's #AtkObject implementation, if
1230  * the object implements #AtkObjectIface
1231  *
1232  * Returns: (transfer full): a reference to an object's #AtkObject
1233  * implementation
1234  */
1235 AtkObject *
1236 atk_implementor_ref_accessible (AtkImplementor *implementor)
1237 {
1238   AtkImplementorIface *iface;
1239   AtkObject           *accessible = NULL;
1240
1241   g_return_val_if_fail (ATK_IS_IMPLEMENTOR (implementor), NULL);
1242
1243   iface = ATK_IMPLEMENTOR_GET_IFACE (implementor);
1244
1245   if (iface != NULL) 
1246     accessible =  iface->ref_accessible (implementor);
1247
1248   g_return_val_if_fail ((accessible != NULL), NULL);
1249
1250   return accessible;
1251 }
1252
1253         
1254 /**
1255  * atk_object_get_attributes:
1256  * @accessible: An #AtkObject.
1257  *
1258  * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of 
1259  * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations, 
1260  * as distinct from strongly-typed object data available via other get/set methods.
1261  * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
1262  *
1263  * Since: 1.12
1264  *
1265  * Returns: (transfer full): an #AtkAttributeSet consisting of all
1266  * explicit properties/annotations applied to the object, or an empty
1267  * set if the object has no name-value pair attributes assigned to
1268  * it. This #atkattributeset should be freed by a call to
1269  * atk_attribute_set_free().
1270  */
1271 AtkAttributeSet *
1272 atk_object_get_attributes (AtkObject                  *accessible)
1273 {
1274   AtkObjectClass *klass;
1275
1276   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1277
1278   klass = ATK_OBJECT_GET_CLASS (accessible);
1279   if (klass->get_attributes)
1280     return (klass->get_attributes) (accessible); 
1281   else 
1282     return NULL;
1283         
1284 }
1285
1286 static AtkRelationSet*
1287 atk_object_real_ref_relation_set (AtkObject *accessible)
1288 {
1289   g_return_val_if_fail (accessible->relation_set, NULL);
1290   g_object_ref (accessible->relation_set); 
1291
1292   return accessible->relation_set;
1293 }
1294
1295 static void
1296 atk_object_real_set_property (GObject      *object,
1297                               guint         prop_id,
1298                               const GValue *value,
1299                               GParamSpec   *pspec)
1300 {
1301   AtkObject *accessible;
1302
1303   accessible = ATK_OBJECT (object);
1304
1305   switch (prop_id)
1306     {
1307     case PROP_NAME:
1308       atk_object_set_name (accessible, g_value_get_string (value));
1309       break;
1310     case PROP_DESCRIPTION:
1311       atk_object_set_description (accessible, g_value_get_string (value));
1312       break;
1313     case PROP_ROLE:
1314       atk_object_set_role (accessible, g_value_get_int (value));
1315       break;
1316     case PROP_PARENT:
1317       atk_object_set_parent (accessible, g_value_get_object (value));
1318       break;
1319     case PROP_VALUE:
1320       if (ATK_IS_VALUE (accessible))
1321         atk_value_set_current_value (ATK_VALUE (accessible), value);
1322       break;
1323     case PROP_TABLE_SUMMARY:
1324       if (ATK_IS_TABLE (accessible))
1325         atk_table_set_summary (ATK_TABLE (accessible), g_value_get_object (value));
1326       break;
1327     case PROP_TABLE_CAPTION_OBJECT:
1328       if (ATK_IS_TABLE (accessible))
1329         atk_table_set_caption (ATK_TABLE (accessible), g_value_get_object (value));
1330       break;
1331     default:
1332       break;
1333     }
1334 }
1335
1336 static void
1337 atk_object_real_get_property (GObject      *object,
1338                               guint         prop_id,
1339                               GValue       *value,
1340                               GParamSpec   *pspec)
1341 {
1342   AtkObject *accessible;
1343
1344   accessible = ATK_OBJECT (object);
1345
1346   switch (prop_id)
1347     {
1348     case PROP_NAME:
1349       g_value_set_string (value, atk_object_get_name (accessible));
1350       break;
1351     case PROP_DESCRIPTION:
1352       g_value_set_string (value, atk_object_get_description (accessible));
1353       break;
1354     case PROP_ROLE:
1355       g_value_set_int (value, atk_object_get_role (accessible));
1356       break;
1357     case PROP_LAYER:
1358       if (ATK_IS_COMPONENT (accessible))
1359         g_value_set_int (value, atk_component_get_layer (ATK_COMPONENT (accessible)));
1360       break;
1361     case PROP_MDI_ZORDER:
1362       if (ATK_IS_COMPONENT (accessible))
1363         g_value_set_int (value, atk_component_get_mdi_zorder (ATK_COMPONENT (accessible)));
1364       break;
1365     case PROP_PARENT:
1366       g_value_set_object (value, atk_object_get_parent (accessible));
1367       break;
1368     case PROP_VALUE:
1369       if (ATK_IS_VALUE (accessible))
1370         atk_value_get_current_value (ATK_VALUE (accessible), value);
1371       break;
1372     case PROP_TABLE_SUMMARY:
1373       if (ATK_IS_TABLE (accessible))
1374         g_value_set_object (value, atk_table_get_summary (ATK_TABLE (accessible)));
1375       break;
1376     case PROP_TABLE_CAPTION_OBJECT:
1377       if (ATK_IS_TABLE (accessible))
1378         g_value_set_object (value, atk_table_get_caption (ATK_TABLE (accessible)));
1379       break;
1380     case PROP_HYPERTEXT_NUM_LINKS:
1381       if (ATK_IS_HYPERTEXT (accessible))
1382         g_value_set_int (value, atk_hypertext_get_n_links (ATK_HYPERTEXT (accessible)));
1383       break;
1384     default:
1385       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1386       break;
1387     }
1388 }
1389
1390 static void
1391 atk_object_finalize (GObject *object)
1392 {
1393   AtkObject        *accessible;
1394
1395   g_return_if_fail (ATK_IS_OBJECT (object));
1396
1397   accessible = ATK_OBJECT (object);
1398
1399   g_free (accessible->name);
1400   g_free (accessible->description);
1401
1402   /*
1403    * Free memory allocated for relation set if it have been allocated.
1404    */
1405   if (accessible->relation_set)
1406     g_object_unref (accessible->relation_set);
1407
1408   if (accessible->accessible_parent)
1409     g_object_unref (accessible->accessible_parent);
1410
1411   G_OBJECT_CLASS (parent_class)->finalize (object);
1412 }
1413
1414 static const gchar*
1415 atk_object_real_get_name (AtkObject *object)
1416 {
1417   return object->name;
1418 }
1419
1420 static const gchar*
1421 atk_object_real_get_description (AtkObject *object)
1422 {
1423   return object->description;
1424 }
1425
1426 static AtkObject*
1427 atk_object_real_get_parent (AtkObject       *object)
1428 {
1429   return atk_object_peek_parent (object);
1430 }
1431
1432 static AtkRole
1433 atk_object_real_get_role (AtkObject       *object)
1434 {
1435   return object->role;
1436 }
1437
1438 static AtkLayer
1439 atk_object_real_get_layer (AtkObject       *object)
1440 {
1441   return object->layer;
1442 }
1443
1444 static AtkStateSet*
1445 atk_object_real_ref_state_set (AtkObject *accessible) 
1446 {
1447   AtkStateSet *state_set;
1448   AtkObject *focus_object;
1449
1450   state_set = atk_state_set_new ();
1451
1452   focus_object = atk_get_focus_object ();
1453   if (focus_object == accessible)
1454     atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
1455
1456   return state_set; 
1457 }
1458
1459 static void
1460 atk_object_real_set_name (AtkObject       *object,
1461                           const gchar     *name)
1462 {
1463   g_free (object->name);
1464   object->name = g_strdup (name);
1465 }
1466
1467 static void
1468 atk_object_real_set_description (AtkObject       *object,
1469                                  const gchar     *description)
1470 {
1471   g_free (object->description);
1472   object->description = g_strdup (description);
1473 }
1474
1475 static void
1476 atk_object_real_set_parent (AtkObject       *object,
1477                             AtkObject       *parent)
1478 {
1479   if (object->accessible_parent)
1480     g_object_unref (object->accessible_parent);
1481
1482   object->accessible_parent = parent;
1483   if (object->accessible_parent)
1484     g_object_ref (object->accessible_parent);
1485 }
1486
1487 static void
1488 atk_object_real_set_role (AtkObject *object,
1489                           AtkRole   role)
1490 {
1491   object->role = role;
1492 }
1493
1494 /**
1495  * atk_object_initialize:
1496  * @accessible: a #AtkObject
1497  * @data: a #gpointer which identifies the object for which the AtkObject was created.
1498  *
1499  * This function is called when implementing subclasses of #AtkObject.
1500  * It does initialization required for the new object. It is intended
1501  * that this function should called only in the ..._new() functions used
1502  * to create an instance of a subclass of #AtkObject
1503  **/
1504 void
1505 atk_object_initialize (AtkObject  *accessible,
1506                        gpointer   data)
1507 {
1508   AtkObjectClass *klass;
1509
1510   g_return_if_fail (ATK_IS_OBJECT (accessible));
1511
1512   klass = ATK_OBJECT_GET_CLASS (accessible);
1513   if (klass->initialize)
1514     klass->initialize (accessible, data);
1515 }
1516
1517 /*
1518  * This function is a signal handler for notify signal which gets emitted
1519  * when a property changes value.
1520  *
1521  * It constructs an AtkPropertyValues structure and emits a "property_changed"
1522  * signal which causes the user specified AtkPropertyChangeHandler
1523  * to be called.
1524  */
1525 static void
1526 atk_object_notify (GObject     *obj,
1527                    GParamSpec  *pspec)
1528 {
1529   AtkPropertyValues values = { NULL, };
1530
1531   g_value_init (&values.new_value, pspec->value_type);
1532   g_object_get_property (obj, pspec->name, &values.new_value);
1533   values.property_name = pspec->name;
1534   g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE],
1535                  g_quark_from_string (pspec->name),
1536                  &values, NULL);
1537   g_value_unset (&values.new_value);
1538 }
1539
1540 /**
1541  * atk_role_get_name:
1542  * @role: The #AtkRole whose name is required
1543  *
1544  * Gets the description string describing the #AtkRole @role.
1545  *
1546  * Returns: the string describing the AtkRole
1547  */
1548 const gchar*
1549 atk_role_get_name (AtkRole role)
1550 {
1551   g_return_val_if_fail (role >= 0, NULL);
1552
1553   if (!role_names)
1554     initialize_role_names ();
1555
1556   if (role < role_names->len)
1557     return g_ptr_array_index (role_names, role);
1558
1559   return NULL;
1560 }
1561
1562 /**
1563  * atk_role_get_localized_name:
1564  * @role: The #AtkRole whose localized name is required
1565  *
1566  * Gets the localized description string describing the #AtkRole @role.
1567  *
1568  * Returns: the localized string describing the AtkRole
1569  **/
1570 const gchar*
1571 atk_role_get_localized_name (AtkRole role)
1572 {
1573   gettext_initialization ();
1574
1575   return dgettext (GETTEXT_PACKAGE, atk_role_get_name (role));
1576 }
1577
1578 static const gchar*
1579 atk_object_real_get_object_locale (AtkObject *object)
1580 {
1581   return setlocale (LC_MESSAGES, NULL);
1582 }
1583
1584 /**
1585  * atk_object_get_object_locale:
1586  * @accessible: an #AtkObject
1587  *
1588  * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
1589  * of @accessible.
1590  *
1591  * Since: 2.7.90
1592  *
1593  * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
1594  *          locale of @accessible.
1595  **/
1596 const gchar*
1597 atk_object_get_object_locale (AtkObject *accessible)
1598 {
1599   AtkObjectClass *klass;
1600
1601   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
1602
1603   klass = ATK_OBJECT_GET_CLASS (accessible);
1604   if (klass->get_object_locale)
1605     return (klass->get_object_locale) (accessible);
1606   else
1607     return NULL;
1608 }
1609
1610
1611 /**
1612  * atk_role_for_name:
1613  * @name: a string which is the (non-localized) name of an ATK role.
1614  *
1615  * Get the #AtkRole type corresponding to a rolew name.
1616  *
1617  * Returns: the #AtkRole enumerated type corresponding to the specified name,
1618  *          or #ATK_ROLE_INVALID if no matching role is found.
1619  **/
1620 AtkRole
1621 atk_role_for_name (const gchar *name)
1622 {
1623   AtkRole role = ATK_ROLE_INVALID;
1624   gint i;
1625
1626   g_return_val_if_fail (name, ATK_ROLE_INVALID);
1627
1628   if (!role_names)
1629     initialize_role_names ();
1630
1631   for (i = 0; i < role_names->len; i++)
1632     {
1633       gchar *role_name = (gchar *)g_ptr_array_index (role_names, i);
1634
1635       g_return_val_if_fail (role_name, ATK_ROLE_INVALID);
1636
1637       if (strcmp (name, role_name) == 0)
1638         {
1639           role = i;
1640           break;
1641         }
1642     }
1643
1644   return role;
1645 }
1646
1647 /**
1648  * atk_object_add_relationship:
1649  * @object: The #AtkObject to which an AtkRelation is to be added. 
1650  * @relationship: The #AtkRelationType of the relation
1651  * @target: The #AtkObject which is to be the target of the relation.
1652  *
1653  * Adds a relationship of the specified type with the specified target.
1654  *
1655  * Returns: TRUE if the relationship is added.
1656  **/
1657 gboolean
1658 atk_object_add_relationship (AtkObject       *object,
1659                              AtkRelationType relationship,
1660                              AtkObject       *target)
1661 {
1662   AtkObject *array[1];
1663   AtkRelation *relation;
1664
1665   g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1666   g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1667
1668   if (atk_relation_set_contains_target (object->relation_set,
1669                                         relationship, target))
1670     return FALSE;
1671
1672   array[0] = target;
1673   relation = atk_relation_new (array, 1, relationship);
1674   atk_relation_set_add (object->relation_set, relation);
1675   g_object_unref (relation);
1676
1677   return TRUE;
1678 }
1679
1680 /**
1681  * atk_object_remove_relationship:
1682  * @object: The #AtkObject from which an AtkRelation is to be removed. 
1683  * @relationship: The #AtkRelationType of the relation
1684  * @target: The #AtkObject which is the target of the relation to be removed.
1685  *
1686  * Removes a relationship of the specified type with the specified target.
1687  *
1688  * Returns: TRUE if the relationship is removed.
1689  **/
1690 gboolean
1691 atk_object_remove_relationship (AtkObject       *object,
1692                                 AtkRelationType relationship,
1693                                 AtkObject       *target)
1694 {
1695   gboolean ret = FALSE;
1696   AtkRelation *relation;
1697   GPtrArray *array;
1698
1699   g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
1700   g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
1701
1702   relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
1703
1704   if (relation)
1705     {
1706       ret = atk_relation_remove_target (relation, target);
1707       array = atk_relation_get_target (relation);
1708       if (!array || array->len == 0)
1709         atk_relation_set_remove (object->relation_set, relation);
1710     }
1711   return ret;
1712 }
1713
1714 static void
1715 atk_object_real_initialize (AtkObject *accessible,
1716                             gpointer  data)
1717 {
1718   return;
1719 }