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