Remove all instances of g_return_if_fail (foo != NULL); that are
[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
22 #include <glib-object.h>
23
24 #include "atk.h"
25
26 /* New GObject properties registered by AtkObject */
27 enum
28 {
29   PROP_0,  /* gobject convention */
30
31   PROP_NAME,
32   PROP_DESCRIPTION,
33   PROP_PARENT,      /* ancestry has changed */
34   PROP_CHILD,       /* a child has been added or removed */
35   PROP_STATE,       /* AtkStateSet for the object has changed */
36   PROP_TEXT,        /* Used only by AtkText implementors */
37   PROP_CARET,       /* Used only by AtkText implementors */
38   PROP_SELECTION,
39   PROP_VALUE,
40   PROP_VISIBLE_DATA,
41   PROP_ROLE,
42   PROP_TABLE_CAPTION,
43   PROP_TABLE_COLUMN_DESCRIPTION,
44   PROP_TABLE_COLUMN_HEADER,
45   PROP_TABLE_ROW_DESCRIPTION,
46   PROP_TABLE_ROW_HEADER,
47   PROP_TABLE_SUMMARY,
48   PROP_MODEL,
49   PROP_LAST         /* gobject convention */
50 };
51
52 enum {
53   CHILDREN_CHANGED,
54   FOCUS_EVENT,
55   PROPERTY_CHANGE,
56
57   LAST_SIGNAL
58 };
59
60 static void            atk_object_class_init        (AtkObjectClass  *klass);
61 static void            atk_object_init              (AtkObject       *accessible,
62                                                      AtkObjectClass  *klass);
63 static AtkRelationSet* atk_object_real_ref_relation_set 
64                                                     (AtkObject       *accessible);
65
66 static void            atk_object_real_set_property (GObject         *object,
67                                                      guint            prop_id,
68                                                      const GValue    *value,
69                                                      GParamSpec      *pspec);
70 static void            atk_object_real_get_property (GObject         *object,
71                                                      guint            prop_id,
72                                                      GValue          *value,
73                                                      GParamSpec      *pspec);
74 static void            atk_object_finalize          (GObject         *object);
75 static G_CONST_RETURN gchar*
76                        atk_object_real_get_name     (AtkObject       *object);
77 static G_CONST_RETURN gchar*
78                        atk_object_real_get_description    
79                                                    (AtkObject       *object);
80 static AtkObject*      atk_object_real_get_parent  (AtkObject       *object);
81 static AtkRole         atk_object_real_get_role    (AtkObject       *object);
82 static void            atk_object_real_set_name    (AtkObject       *object,
83                                                     const gchar     *name);
84 static void            atk_object_real_set_description
85                                                    (AtkObject       *object,
86                                                     const gchar     *description);
87 static void            atk_object_real_set_parent  (AtkObject       *object,
88                                                     AtkObject       *parent);
89 static void            atk_object_real_set_role    (AtkObject       *object,
90                                                     AtkRole         role);
91 static guint           atk_object_real_connect_property_change_handler
92                                                    (AtkObject       *obj,
93                                                     AtkPropertyChangeHandler
94                                                                     *handler);
95 static void            atk_object_real_remove_property_change_handler
96                                                    (AtkObject       *obj,
97                                                     guint           handler_id);
98 static void            atk_object_notify           (GObject         *obj,
99                                                     GParamSpec      *pspec);
100
101
102 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
103
104 static gpointer parent_class = NULL;
105
106 static const gchar* atk_object_name_property_name = "accessible-name";
107 static const gchar* atk_object_name_property_state = "accessible-state";
108 static const gchar* atk_object_name_property_description = "accessible-description";
109 static const gchar* atk_object_name_property_child = "accessible-child";
110 static const gchar* atk_object_name_property_parent = "accessible-parent";
111 static const gchar* atk_object_name_property_text = "accessible-text";
112 static const gchar* atk_object_name_property_caret = "accessible-caret";
113 static const gchar* atk_object_name_property_selection = "accessible-selection";
114 static const gchar* atk_object_name_property_value = "accessible-value";
115 static const gchar* atk_object_name_property_visible = "accessible-visible-data";
116 static const gchar* atk_object_name_property_role = "accessible-role";
117 static const gchar* atk_object_name_property_table_caption = "accessible-table-caption";
118 static const gchar* atk_object_name_property_table_column_description = "accessible-table-column-description";
119 static const gchar* atk_object_name_property_table_column_header = "accessible-table-column-header";
120 static const gchar* atk_object_name_property_table_row_description = "accessible-table-row-description";
121 static const gchar* atk_object_name_property_table_row_header = "accessible-table-row-header";
122 static const gchar* atk_object_name_property_table_summary = "accessible-table-summary";
123 static const gchar* atk_object_name_property_model = "accessible-model";
124
125 GType
126 atk_object_get_type (void)
127 {
128   static GType type = 0;
129
130   if (!type)
131     {
132       static const GTypeInfo typeInfo =
133       {
134         sizeof (AtkObjectClass),
135         (GBaseInitFunc) NULL,
136         (GBaseFinalizeFunc) NULL,
137         (GClassInitFunc) atk_object_class_init,
138         (GClassFinalizeFunc) NULL,
139         NULL,
140         sizeof (AtkObject),
141         0,
142         (GInstanceInitFunc) atk_object_init,
143       } ;
144       type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
145     }
146   return type;
147 }
148
149 static void
150 atk_object_class_init (AtkObjectClass *klass)
151 {
152   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
153
154   parent_class = g_type_class_ref (G_TYPE_OBJECT);
155
156   gobject_class->set_property = atk_object_real_set_property;
157   gobject_class->get_property = atk_object_real_get_property;
158   gobject_class->finalize = atk_object_finalize;
159   gobject_class->notify = atk_object_notify;
160
161   klass->get_name = atk_object_real_get_name;
162   klass->get_description = atk_object_real_get_description;
163   klass->get_parent = atk_object_real_get_parent;
164   klass->get_n_children = NULL;
165   klass->ref_child = NULL;
166   klass->get_index_in_parent = NULL;
167   klass->ref_relation_set = atk_object_real_ref_relation_set;
168   klass->get_role = atk_object_real_get_role;
169   klass->ref_state_set = NULL;
170   klass->set_name = atk_object_real_set_name;
171   klass->set_description = atk_object_real_set_description;
172   klass->set_parent = atk_object_real_set_parent;
173   klass->set_role = atk_object_real_set_role;
174   klass->connect_property_change_handler = 
175          atk_object_real_connect_property_change_handler;
176   klass->remove_property_change_handler = 
177          atk_object_real_remove_property_change_handler;
178
179   /*
180    * We do not define default signal handlers here
181    */
182   klass->children_changed = NULL;
183   klass->focus_event = NULL;
184   klass->property_change = NULL;
185
186   g_object_class_install_property (gobject_class,
187                                    PROP_NAME,
188                                    g_param_spec_string (atk_object_name_property_name,
189                                                         "Accessible Name",
190                                                         "Object instance\'s name formatted for "
191                                                            "assistive technology access",
192                                                         NULL,
193                                                         G_PARAM_READWRITE));
194   g_object_class_install_property (gobject_class,
195                                    PROP_DESCRIPTION,
196                                    g_param_spec_string (atk_object_name_property_description,
197                                                         "Accessible Description",
198                                                         "Description of an object, formatted for "
199                                                         "assistive technology access",
200                                                         NULL,
201                                                         G_PARAM_READWRITE));
202   g_object_class_install_property (gobject_class,
203                                    PROP_STATE,
204                                    g_param_spec_int    (atk_object_name_property_state,
205                                                         "Accessible State Set",
206                                                         "The accessible state set of this object "
207                                                         "or its UI component",
208                                                         0,
209                                                         G_MAXINT,
210                                                         0,
211                                                         G_PARAM_READWRITE));
212   g_object_class_install_property (gobject_class,
213                                    PROP_CHILD,
214                                    g_param_spec_object (atk_object_name_property_child,
215                                                         "Accessible Child",
216                                                         "Is used to notify that a child has been added or removed ",
217                                                         ATK_TYPE_OBJECT,
218                                                         G_PARAM_READWRITE));
219   g_object_class_install_property (gobject_class,
220                                    PROP_PARENT,
221                                    g_param_spec_object (atk_object_name_property_parent,
222                                                         "Accessible Parent",
223                                                         "Is used to notify that the parent has changed ",
224                                                         ATK_TYPE_OBJECT,
225                                                         G_PARAM_READWRITE));
226   g_object_class_install_property (gobject_class,
227                                    PROP_TEXT,
228                                    g_param_spec_object (atk_object_name_property_text,
229                                                         "Accessible Text",
230                                                         "Is used to notify that the text has changed ",
231                                                         ATK_TYPE_OBJECT,
232                                                         G_PARAM_READWRITE));
233   g_object_class_install_property (gobject_class,
234                                    PROP_CARET,
235                                    g_param_spec_int    (atk_object_name_property_caret,
236                                                         "Accessible Caret",
237                                                         "Is used to notify that the caret position has changed ",
238                                                         0,
239                                                         G_MAXINT,
240                                                         0,
241                                                         G_PARAM_READWRITE));
242   g_object_class_install_property (gobject_class,
243                                    PROP_SELECTION,
244                                    g_param_spec_object (atk_object_name_property_selection,
245                                                         "Accessible Selection",
246                                                         "Is used to notify that the selection has changed ",
247                                                         ATK_TYPE_OBJECT,
248                                                         G_PARAM_READWRITE));
249   g_object_class_install_property (gobject_class,
250                                    PROP_VALUE,
251                                    g_param_spec_double (atk_object_name_property_value,
252                                                         "Accessible Value",
253                                                         "Is used to notify that the value has changed ",
254                                                         0.0,
255                                                         G_MAXDOUBLE,
256                                                         0.0,
257                                                         G_PARAM_READWRITE));
258   g_object_class_install_property (gobject_class,
259                                    PROP_VISIBLE_DATA,
260                                    g_param_spec_object (atk_object_name_property_visible,
261                                                         "Accessible Visible Data",
262                                                         "Is used to notify that the visual appearance of the object has changed ",
263                                                         ATK_TYPE_OBJECT,
264                                                         G_PARAM_READWRITE));
265   g_object_class_install_property (gobject_class,
266                                    PROP_ROLE,
267                                    g_param_spec_int    (atk_object_name_property_role,
268                                                         "Accessible Role",
269                                                         "The accessible role this object ",
270                                                         0,
271                                                         G_MAXINT,
272                                                         0,
273                                                         G_PARAM_READWRITE));
274   g_object_class_install_property (gobject_class,
275                                    PROP_TABLE_CAPTION,
276                                    g_param_spec_object (atk_object_name_property_table_caption,
277                                                         "Accessible Table Caption",
278                                                         "Is used to notify that the table caption has changed ",
279                                                         ATK_TYPE_OBJECT,
280                                                         G_PARAM_READWRITE));
281   g_object_class_install_property (gobject_class,
282                                    PROP_TABLE_COLUMN_HEADER,
283                                    g_param_spec_object (atk_object_name_property_table_column_header,
284                                                         "Accessible Table Column Header",
285                                                         "Is used to notify that the table column header has changed ",
286                                                         ATK_TYPE_OBJECT,
287                                                         G_PARAM_READWRITE));
288   g_object_class_install_property (gobject_class,
289                                    PROP_TABLE_COLUMN_DESCRIPTION,
290                                    g_param_spec_int    (atk_object_name_property_table_column_description,
291                                                         "Accessible Table Column Description",
292                                                         "Is used to notify that the table columnscription has changed ",
293                                                         0,
294                                                         G_MAXINT,
295                                                         0,
296                                                         G_PARAM_READWRITE));
297   g_object_class_install_property (gobject_class,
298                                    PROP_TABLE_ROW_HEADER,
299                                    g_param_spec_object (atk_object_name_property_table_row_header,
300                                                         "Accessible Table Row Header",
301                                                         "Is used to notify that the table row header has changed ",
302                                                         ATK_TYPE_OBJECT,
303                                                         G_PARAM_READWRITE));
304   g_object_class_install_property (gobject_class,
305                                    PROP_TABLE_ROW_DESCRIPTION,
306                                    g_param_spec_int    (atk_object_name_property_table_row_description,
307                                                         "Accessible Table Row Description",
308                                                         "Is used to notify that the table row description has changed ",
309                                                         0,
310                                                         G_MAXINT,
311                                                         0,
312                                                         G_PARAM_READWRITE));
313   g_object_class_install_property (gobject_class,
314                                    PROP_TABLE_SUMMARY,
315                                    g_param_spec_object (atk_object_name_property_table_summary,
316                                                         "Accessible Table Summary",
317                                                         "Is used to notify that the table summary has changed ",
318                                                         ATK_TYPE_OBJECT,
319                                                         G_PARAM_READWRITE));
320   g_object_class_install_property (gobject_class,
321                                    PROP_MODEL,
322                                    g_param_spec_object (atk_object_name_property_model,
323                                                         "Accessible Model",
324                                                         "Is used to notify that the model for Table or Tree has changed ",
325                                                         ATK_TYPE_OBJECT,
326                                                         G_PARAM_READWRITE));
327   /*
328    * The signal "children_changed" supports two details:
329    * "add" and "remove"
330    */
331   atk_object_signals[CHILDREN_CHANGED] =
332     g_signal_new ("children_changed",
333                   G_TYPE_FROM_CLASS (klass),
334                   G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
335                   G_STRUCT_OFFSET (AtkObjectClass, children_changed),
336                   NULL, NULL,
337                   g_cclosure_marshal_VOID__UINT_POINTER,
338                   G_TYPE_NONE,
339                   2, G_TYPE_UINT, G_TYPE_POINTER);
340   atk_object_signals[FOCUS_EVENT] =
341     g_signal_new ("focus_event",
342                   G_TYPE_FROM_CLASS (klass),
343                   G_SIGNAL_RUN_LAST,
344                   G_STRUCT_OFFSET (AtkObjectClass, focus_event), 
345                   NULL, NULL,
346                   g_cclosure_marshal_VOID__BOOLEAN,
347                   G_TYPE_NONE,
348                   1, G_TYPE_BOOLEAN);
349   atk_object_signals[PROPERTY_CHANGE] =
350     g_signal_new ("property_change",
351                   G_TYPE_FROM_CLASS (klass),
352                   G_SIGNAL_RUN_LAST,
353                   G_STRUCT_OFFSET (AtkObjectClass, property_change),
354                   (GSignalAccumulator) NULL, NULL,
355                   g_cclosure_marshal_VOID__POINTER,
356                   G_TYPE_NONE, 1,
357                   G_TYPE_POINTER);
358 }
359
360 static void
361 atk_object_init  (AtkObject        *accessible,
362                   AtkObjectClass   *klass)
363 {
364   accessible->name = NULL;
365   accessible->description = NULL;
366   accessible->accessible_parent = NULL;
367   accessible->relation_set = NULL;
368   accessible->role = ATK_ROLE_UNKNOWN;
369 }
370
371 GType
372 atk_implementor_get_type (void)
373 {
374   static GType type = 0;
375
376   if (!type)
377     {
378       static const GTypeInfo typeInfo =
379       {
380         sizeof (AtkImplementorIface),
381         (GBaseInitFunc) NULL,
382         (GBaseFinalizeFunc) NULL,
383       } ;
384
385       type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
386     }
387
388   return type;
389 }
390
391 /**
392  * atk_object_get_name:
393  * @accessible: an #AtkObject
394  *
395  * Gets the accessible name of the accessible.
396  *
397  * Returns: a character string representing the accessible name of the object.
398  **/
399 G_CONST_RETURN gchar*
400 atk_object_get_name (AtkObject *accessible)
401 {
402   AtkObjectClass *klass;
403
404   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
405
406   klass = ATK_OBJECT_GET_CLASS (accessible);
407   if (klass->get_name)
408     return (klass->get_name) (accessible);
409   else
410     return NULL;
411 }
412
413 /**
414  * atk_object_get_description:
415  * @accessible: an #AtkObject
416  *
417  * Gets the accessible description of the accessible.
418  *
419  * Returns: a character string representing the accessible description
420  * of the accessible.
421  *
422  **/
423 G_CONST_RETURN gchar*
424 atk_object_get_description (AtkObject *accessible)
425 {
426   AtkObjectClass *klass;
427
428   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
429
430   klass = ATK_OBJECT_GET_CLASS (accessible);
431   if (klass->get_description)
432     return (klass->get_description) (accessible);
433   else
434     return NULL;
435 }
436
437 /**
438  * atk_object_get_parent:
439  * @accessible: an #AtkObject
440  *
441  * Gets the accessible parent of the accessible.
442  *
443  * Returns: a #AtkObject representing the accessible parent of the accessible
444  **/
445 AtkObject*
446 atk_object_get_parent (AtkObject *accessible)
447 {
448   AtkObjectClass *klass;
449
450   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
451
452   klass = ATK_OBJECT_GET_CLASS (accessible);
453   if (klass->get_parent)
454     return (klass->get_parent) (accessible);
455   else
456     return NULL;
457 }
458
459 /**
460  * atk_object_get_n_accessible_children:
461  * @accessible: an #AtkObject
462  *
463  * Gets the number of accessible children of the accessible.
464  *
465  * Returns: an integer representing the number of accessible children
466  * of the accessible.
467  **/
468 gint
469 atk_object_get_n_accessible_children (AtkObject *accessible)
470 {
471   AtkObjectClass *klass;
472
473   g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
474
475   klass = ATK_OBJECT_GET_CLASS (accessible);
476   if (klass->get_n_children)
477     return (klass->get_n_children) (accessible);
478   else
479     return 0;
480 }
481
482 /**
483  * atk_object_ref_accessible_child:
484  * @accessible: an #AtkObject
485  * @i: a gint representing the position of the child, starting from 0
486  *
487  * Gets a reference to the specified accessible child of the object.
488  * The accessible children are 0-based so the first accessible child is
489  * at index 0, the second at index 1 and so on.
490  *
491  * Returns: an #AtkObject representing the specified accessible child
492  * of the accessible.
493  **/
494 AtkObject*
495 atk_object_ref_accessible_child (AtkObject   *accessible,
496                                  gint        i)
497 {
498   AtkObjectClass *klass;
499
500   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
501
502   klass = ATK_OBJECT_GET_CLASS (accessible);
503   if (klass->ref_child)
504     return (klass->ref_child) (accessible, i);
505   else
506     return NULL;
507 }
508
509 /**
510  * atk_object_ref_relation_set:
511  * @accessible: an #AtkObject
512  *
513  * Gets the #AtkRelationSet associated with the object.
514  *
515  * Returns: an #AtkRelationSet representing the relation set of the object.
516  **/
517 AtkRelationSet*
518 atk_object_ref_relation_set (AtkObject *accessible)
519 {
520   AtkObjectClass *klass;
521
522   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
523
524   klass = ATK_OBJECT_GET_CLASS (accessible);
525   if (klass->ref_relation_set)
526     return (klass->ref_relation_set) (accessible);
527   else
528     return NULL;
529 }
530
531 /**
532  * atk_role_register:
533  * @name: a character string describing the new role.
534  *
535  * Registers the role specified by @name.
536  *
537  * Returns: an #AtkRole for the new role.
538  **/
539 AtkRole
540 atk_role_register (const gchar *name)
541 {
542   /* TODO: associate name with new type */
543   static guint type = ATK_ROLE_LAST_DEFINED;
544   return (++type);
545 }
546
547 /**
548  * atk_object_get_role:
549  * @accessible: an #AtkObject
550  *
551  * Gets the role of the accessible.
552  *
553  * Returns: an #AtkRole which is the role of the accessible
554  **/
555 AtkRole
556 atk_object_get_role (AtkObject *accessible) {
557   AtkObjectClass *klass;
558
559   g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
560
561   klass = ATK_OBJECT_GET_CLASS (accessible);
562   if (klass->get_role)
563     return (klass->get_role) (accessible);
564   else
565     return ATK_ROLE_UNKNOWN;
566 }
567
568 /**
569  * atk_object_ref_state_set:
570  * @accessible: an #AtkObject
571  *
572  * Gets a reference to the state set of the accessible; the caller must
573  * unreference it when it is no longer needed.
574  *
575  * Returns: a reference to an #AtkStateSet which is the state
576  * set of the accessible
577  **/
578 AtkStateSet*
579 atk_object_ref_state_set (AtkObject *accessible) {
580   AtkObjectClass *klass;
581
582   g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
583
584   klass = ATK_OBJECT_GET_CLASS (accessible);
585   if (klass->ref_state_set)
586     return (klass->ref_state_set) (accessible);
587   else
588     return NULL;
589 }
590
591 /**
592  * atk_object_get_index_in_parent:
593  * @accessible: an #AtkObject
594  *
595  * Gets the 0-based index of this accessible in its parent; returns -1 if the
596  * accessible does not have an accessible parent.
597  *
598  * Returns: an integer which is the index of the accessible in its parent
599  **/
600 gint
601 atk_object_get_index_in_parent (AtkObject *accessible)
602 {
603   AtkObjectClass *klass;
604
605   g_return_val_if_fail (ATK_OBJECT (accessible), -1);
606
607   klass = ATK_OBJECT_GET_CLASS (accessible);
608   if (klass->get_index_in_parent)
609     return (klass->get_index_in_parent) (accessible);
610   else
611     return -1;
612 }
613
614 /**
615  * atk_object_set_name:
616  * @accessible: an #AtkObject
617  * @name: a character string to be set as the accessible name
618  *
619  * Sets the accessible name of the accessible.
620  **/
621 void
622 atk_object_set_name (AtkObject    *accessible,
623                      const gchar  *name)
624 {
625   AtkObjectClass *klass;
626
627   g_return_if_fail (ATK_IS_OBJECT (accessible));
628   g_return_if_fail (name != NULL);
629
630   klass = ATK_OBJECT_GET_CLASS (accessible);
631   if (klass->set_name)
632   {
633     (klass->set_name) (accessible, name);
634     g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
635   }
636 }
637
638 /**
639  * atk_object_set_description:
640  * @accessible: an #AtkObject
641  * @description : a character string to be set as the accessible description
642  *
643  * Sets the accessible description of the accessible.
644  **/
645 void
646 atk_object_set_description (AtkObject   *accessible,
647                             const gchar *description)
648 {
649   AtkObjectClass *klass;
650
651   g_return_if_fail (ATK_IS_OBJECT (accessible));
652   g_return_if_fail (description != NULL);
653
654   klass = ATK_OBJECT_GET_CLASS (accessible);
655   if (klass->set_description)
656   {
657     (klass->set_description) (accessible, description);
658     g_object_notify (G_OBJECT (accessible), atk_object_name_property_description);
659   }
660 }
661
662 /**
663  * atk_object_set_parent:
664  * @accessible: an #AtkObject
665  * @parent : an #AtkObject to be set as the accessible parent
666  *
667  * Sets the accessible parent of the accessible.
668  **/
669 void
670 atk_object_set_parent (AtkObject *accessible,
671                        AtkObject *parent)
672 {
673   AtkObjectClass *klass;
674
675   g_return_if_fail (ATK_IS_OBJECT (accessible));
676
677   klass = ATK_OBJECT_GET_CLASS (accessible);
678   if (klass->set_parent)
679     (klass->set_parent) (accessible, parent);
680 }
681
682 /**
683  * atk_object_set_role:
684  * @accessible: an #AtkObject
685  * @role : an #AtkRole to be set as the role
686  *
687  * Sets the role of the accessible.
688  **/
689 void
690 atk_object_set_role (AtkObject *accessible, 
691                      AtkRole   role)
692 {
693   AtkObjectClass *klass;
694
695   g_return_if_fail (ATK_IS_OBJECT (accessible));
696
697   klass = ATK_OBJECT_GET_CLASS (accessible);
698   if (klass->set_role)
699     (klass->set_role) (accessible, role);
700 }
701
702 /**
703  * atk_object_connect_property_change_handler:
704  * @accessible: an #AtkObject
705  * @handler : a function to be called when a property changes its value
706  *
707  * Specifies a function to be called when a property changes value.
708  *
709  * Returns: a #guint which is the handler id used in 
710  * atk_object_remove_property_change_handler()
711  **/
712 guint
713 atk_object_connect_property_change_handler (AtkObject *accessible,
714                                             AtkPropertyChangeHandler *handler)
715 {
716   AtkObjectClass *klass;
717
718   g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
719   g_return_val_if_fail ((handler != NULL), 0);
720
721   klass = ATK_OBJECT_GET_CLASS (accessible);
722   if (klass->connect_property_change_handler)
723     return (klass->connect_property_change_handler) (accessible, handler);
724   else
725     return 0;
726 }
727
728 /**
729  * atk_object_remove_property_change_handler:
730  * @accessible: an #AtkObject
731  * @handler_id : a guint which identifies the handler to be removed.
732  * 
733  * Removes a property change handler.
734  **/
735 void
736 atk_object_remove_property_change_handler  (AtkObject *accessible,
737                                             guint      handler_id)
738 {
739   AtkObjectClass *klass;
740
741   g_return_if_fail (ATK_IS_OBJECT (accessible));
742
743   klass = ATK_OBJECT_GET_CLASS (accessible);
744   if (klass->remove_property_change_handler)
745     (klass->remove_property_change_handler) (accessible, handler_id);
746 }
747
748 /**
749  * atk_implementor_ref_accessible:
750  * @implementor: The #GObject instance which should implement #AtkImplementorIface
751  * if a non-null return value is required.
752  * 
753  * Gets a reference to an object's #AtkObject implementation, if
754  * the object implements #AtkObjectIface
755  *
756  * Returns: a reference to an object's #AtkObject implementation
757  */
758 AtkObject *
759 atk_implementor_ref_accessible (AtkImplementor *object)
760 {
761   AtkImplementorIface *iface;
762   AtkObject           *accessible = NULL;
763
764   g_return_val_if_fail (ATK_IS_IMPLEMENTOR (object), NULL);
765
766   iface = ATK_IMPLEMENTOR_GET_IFACE (object);
767
768   if (iface != NULL) 
769     accessible =  iface->ref_accessible (object);
770
771   g_return_val_if_fail ((accessible != NULL), NULL);
772
773   return accessible;
774 }
775
776 static AtkRelationSet*
777 atk_object_real_ref_relation_set (AtkObject *accessible)
778 {
779   if (accessible->relation_set)
780     g_object_ref (accessible->relation_set); 
781
782   return accessible->relation_set;
783 }
784
785 static void
786 atk_object_real_set_property (GObject      *object,
787                               guint         prop_id,
788                               const GValue *value,
789                               GParamSpec   *pspec)
790 {
791   AtkObject *accessible;
792
793   accessible = ATK_OBJECT (object);
794
795   switch (prop_id)
796   {
797     case PROP_NAME:
798       atk_object_set_name (accessible, g_value_get_string (value));
799       break;
800     case PROP_DESCRIPTION:
801       atk_object_set_description (accessible, g_value_get_string (value));
802       break;
803     case PROP_STATE:
804       g_print ("This interface does not support setting the state set of an accessible object\n");
805       break;
806     case PROP_VALUE:
807       if (ATK_IS_VALUE (accessible))
808         atk_value_set_current_value (ATK_VALUE (accessible), value);
809       break;
810     default:
811       break;
812   }
813 }
814
815 static void
816 atk_object_real_get_property (GObject      *object,
817                               guint         prop_id,
818                               GValue       *value,
819                               GParamSpec   *pspec)
820 {
821   AtkObject *accessible;
822
823   accessible = ATK_OBJECT (object);
824
825   switch (prop_id)
826   {
827     case PROP_NAME:
828       g_value_set_string (value, atk_object_get_name (accessible));
829       break;
830     case PROP_DESCRIPTION:
831       g_value_set_string (value, atk_object_get_description (accessible));
832       break;
833     case PROP_VALUE:
834       if (ATK_IS_VALUE (accessible))
835         atk_value_get_current_value (ATK_VALUE (accessible), value);
836       break;
837     default:
838       break;
839   }
840 }
841
842 static void
843 atk_object_finalize (GObject *object)
844 {
845   AtkObject        *accessible;
846
847   g_return_if_fail (ATK_IS_OBJECT (object));
848
849   accessible = ATK_OBJECT (object);
850
851   g_free (accessible->name);
852   g_free (accessible->description);
853
854   /*
855    * Free memory allocated for relation set if it have been allocated.
856    */
857   if (accessible->relation_set)
858   {
859     g_object_unref (accessible->relation_set);
860   }
861
862   G_OBJECT_CLASS (parent_class)->finalize (object);
863 }
864
865 static G_CONST_RETURN gchar*
866 atk_object_real_get_name (AtkObject *object)
867 {
868   return object->name;
869 }
870
871 static G_CONST_RETURN gchar*
872 atk_object_real_get_description (AtkObject *object)
873 {
874   return object->description;
875 }
876
877 static AtkObject*
878 atk_object_real_get_parent (AtkObject       *object)
879 {
880   return object->accessible_parent;
881 }
882
883 static AtkRole
884 atk_object_real_get_role (AtkObject       *object)
885 {
886   return object->role;
887 }
888
889 static void
890 atk_object_real_set_name (AtkObject       *object,
891                           const gchar     *name)
892 {
893   g_free (object->name);
894   object->name = g_strdup (name);
895 }
896
897 static void
898 atk_object_real_set_description (AtkObject       *object,
899                                  const gchar     *description)
900 {
901   g_free (object->description);
902   object->description = g_strdup (description);
903 }
904
905 static void
906 atk_object_real_set_parent (AtkObject       *object,
907                             AtkObject       *parent)
908 {
909   object->accessible_parent = parent;
910
911 }
912
913 static void
914 atk_object_real_set_role (AtkObject *object,
915                           AtkRole   role)
916 {
917   object->role = role;
918 }
919
920 static guint
921 atk_object_real_connect_property_change_handler (AtkObject                *obj,
922                                                  AtkPropertyChangeHandler *handler)
923 {
924   return g_signal_connect_closure_by_id (obj,
925                                          atk_object_signals[PROPERTY_CHANGE],
926                                          0,
927                                          g_cclosure_new (
928                                          G_CALLBACK (handler), NULL,
929                                          (GClosureNotify) NULL),
930                                          FALSE);
931 }
932
933 static void
934 atk_object_real_remove_property_change_handler (AtkObject           *obj,
935                                           guint               handler_id)
936 {
937   g_signal_handler_disconnect (obj, handler_id);
938 }
939
940 /*
941  * This function is a signal handler for notify signal which gets emitted
942  * when a property changes value.
943  *
944  * It constructs an AtkPropertyValues structure and emits a "property_changed"
945  * signal which causes the user specified AtkPropertyChangeHandler
946  * to be called.
947  */
948 static void
949 atk_object_notify (GObject     *obj,
950                    GParamSpec  *pspec)
951 {
952   AtkPropertyValues values;
953
954   memset (&values.old_value, 0, sizeof (GValue));
955   memset (&values.new_value, 0, sizeof (GValue));
956   g_value_init (&values.new_value, pspec->value_type);
957   g_object_get_property(obj, pspec->name, &values.new_value);
958   values.property_name = pspec->name;
959   g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE], 0,
960                  &values, NULL);
961 }
962