Swap height and width arguments to atk_image_get_image_size Swap height
[atk.git] / atk / atkobject.c
blobcf856f166a8804d57a15a5d345725023dc929124
1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include <string.h>
22 #include <glib-object.h>
24 #include "atk.h"
26 /* New GObject properties registered by AtkObject */
27 enum
29 PROP_0, /* gobject convention */
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 */
52 enum {
53 CHILDREN_CHANGED,
54 FOCUS_EVENT,
55 PROPERTY_CHANGE,
57 LAST_SIGNAL
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);
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 AtkStateSet* atk_object_real_ref_state_set
83 (AtkObject *object);
84 static void atk_object_real_set_name (AtkObject *object,
85 const gchar *name);
86 static void atk_object_real_set_description
87 (AtkObject *object,
88 const gchar *description);
89 static void atk_object_real_set_parent (AtkObject *object,
90 AtkObject *parent);
91 static void atk_object_real_set_role (AtkObject *object,
92 AtkRole role);
93 static guint atk_object_real_connect_property_change_handler
94 (AtkObject *obj,
95 AtkPropertyChangeHandler
96 *handler);
97 static void atk_object_real_remove_property_change_handler
98 (AtkObject *obj,
99 guint handler_id);
100 static void atk_object_notify (GObject *obj,
101 GParamSpec *pspec);
104 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
106 static gpointer parent_class = NULL;
108 static const gchar* atk_object_name_property_name = "accessible-name";
109 static const gchar* atk_object_name_property_state = "accessible-state";
110 static const gchar* atk_object_name_property_description = "accessible-description";
111 static const gchar* atk_object_name_property_child = "accessible-child";
112 static const gchar* atk_object_name_property_parent = "accessible-parent";
113 static const gchar* atk_object_name_property_text = "accessible-text";
114 static const gchar* atk_object_name_property_caret = "accessible-caret";
115 static const gchar* atk_object_name_property_selection = "accessible-selection";
116 static const gchar* atk_object_name_property_value = "accessible-value";
117 static const gchar* atk_object_name_property_visible = "accessible-visible-data";
118 static const gchar* atk_object_name_property_role = "accessible-role";
119 static const gchar* atk_object_name_property_table_caption = "accessible-table-caption";
120 static const gchar* atk_object_name_property_table_column_description = "accessible-table-column-description";
121 static const gchar* atk_object_name_property_table_column_header = "accessible-table-column-header";
122 static const gchar* atk_object_name_property_table_row_description = "accessible-table-row-description";
123 static const gchar* atk_object_name_property_table_row_header = "accessible-table-row-header";
124 static const gchar* atk_object_name_property_table_summary = "accessible-table-summary";
125 static const gchar* atk_object_name_property_model = "accessible-model";
127 GType
128 atk_object_get_type (void)
130 static GType type = 0;
132 if (!type)
134 static const GTypeInfo typeInfo =
136 sizeof (AtkObjectClass),
137 (GBaseInitFunc) NULL,
138 (GBaseFinalizeFunc) NULL,
139 (GClassInitFunc) atk_object_class_init,
140 (GClassFinalizeFunc) NULL,
141 NULL,
142 sizeof (AtkObject),
144 (GInstanceInitFunc) atk_object_init,
146 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
148 return type;
151 static void
152 atk_object_class_init (AtkObjectClass *klass)
154 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
156 parent_class = g_type_class_ref (G_TYPE_OBJECT);
158 gobject_class->set_property = atk_object_real_set_property;
159 gobject_class->get_property = atk_object_real_get_property;
160 gobject_class->finalize = atk_object_finalize;
161 gobject_class->notify = atk_object_notify;
163 klass->get_name = atk_object_real_get_name;
164 klass->get_description = atk_object_real_get_description;
165 klass->get_parent = atk_object_real_get_parent;
166 klass->get_n_children = NULL;
167 klass->ref_child = NULL;
168 klass->get_index_in_parent = NULL;
169 klass->ref_relation_set = atk_object_real_ref_relation_set;
170 klass->get_role = atk_object_real_get_role;
171 klass->ref_state_set = atk_object_real_ref_state_set;
172 klass->set_name = atk_object_real_set_name;
173 klass->set_description = atk_object_real_set_description;
174 klass->set_parent = atk_object_real_set_parent;
175 klass->set_role = atk_object_real_set_role;
176 klass->connect_property_change_handler =
177 atk_object_real_connect_property_change_handler;
178 klass->remove_property_change_handler =
179 atk_object_real_remove_property_change_handler;
182 * We do not define default signal handlers here
184 klass->children_changed = NULL;
185 klass->focus_event = NULL;
186 klass->property_change = NULL;
188 g_object_class_install_property (gobject_class,
189 PROP_NAME,
190 g_param_spec_string (atk_object_name_property_name,
191 "Accessible Name",
192 "Object instance\'s name formatted for "
193 "assistive technology access",
194 NULL,
195 G_PARAM_READWRITE));
196 g_object_class_install_property (gobject_class,
197 PROP_DESCRIPTION,
198 g_param_spec_string (atk_object_name_property_description,
199 "Accessible Description",
200 "Description of an object, formatted for "
201 "assistive technology access",
202 NULL,
203 G_PARAM_READWRITE));
204 g_object_class_install_property (gobject_class,
205 PROP_STATE,
206 g_param_spec_int (atk_object_name_property_state,
207 "Accessible State Set",
208 "The accessible state set of this object "
209 "or its UI component",
211 G_MAXINT,
213 G_PARAM_READWRITE));
214 g_object_class_install_property (gobject_class,
215 PROP_CHILD,
216 g_param_spec_object (atk_object_name_property_child,
217 "Accessible Child",
218 "Is used to notify that a child has been added or removed ",
219 ATK_TYPE_OBJECT,
220 G_PARAM_READWRITE));
221 g_object_class_install_property (gobject_class,
222 PROP_PARENT,
223 g_param_spec_object (atk_object_name_property_parent,
224 "Accessible Parent",
225 "Is used to notify that the parent has changed ",
226 ATK_TYPE_OBJECT,
227 G_PARAM_READWRITE));
228 g_object_class_install_property (gobject_class,
229 PROP_TEXT,
230 g_param_spec_object (atk_object_name_property_text,
231 "Accessible Text",
232 "Is used to notify that the text has changed ",
233 ATK_TYPE_OBJECT,
234 G_PARAM_READWRITE));
235 g_object_class_install_property (gobject_class,
236 PROP_CARET,
237 g_param_spec_int (atk_object_name_property_caret,
238 "Accessible Caret",
239 "Is used to notify that the caret position has changed ",
241 G_MAXINT,
243 G_PARAM_READWRITE));
244 g_object_class_install_property (gobject_class,
245 PROP_SELECTION,
246 g_param_spec_object (atk_object_name_property_selection,
247 "Accessible Selection",
248 "Is used to notify that the selection has changed ",
249 ATK_TYPE_OBJECT,
250 G_PARAM_READWRITE));
251 g_object_class_install_property (gobject_class,
252 PROP_VALUE,
253 g_param_spec_double (atk_object_name_property_value,
254 "Accessible Value",
255 "Is used to notify that the value has changed ",
256 0.0,
257 G_MAXDOUBLE,
258 0.0,
259 G_PARAM_READWRITE));
260 g_object_class_install_property (gobject_class,
261 PROP_VISIBLE_DATA,
262 g_param_spec_object (atk_object_name_property_visible,
263 "Accessible Visible Data",
264 "Is used to notify that the visual appearance of the object has changed ",
265 ATK_TYPE_OBJECT,
266 G_PARAM_READWRITE));
267 g_object_class_install_property (gobject_class,
268 PROP_ROLE,
269 g_param_spec_int (atk_object_name_property_role,
270 "Accessible Role",
271 "The accessible role this object ",
273 G_MAXINT,
275 G_PARAM_READWRITE));
276 g_object_class_install_property (gobject_class,
277 PROP_TABLE_CAPTION,
278 g_param_spec_object (atk_object_name_property_table_caption,
279 "Accessible Table Caption",
280 "Is used to notify that the table caption has changed ",
281 ATK_TYPE_OBJECT,
282 G_PARAM_READWRITE));
283 g_object_class_install_property (gobject_class,
284 PROP_TABLE_COLUMN_HEADER,
285 g_param_spec_object (atk_object_name_property_table_column_header,
286 "Accessible Table Column Header",
287 "Is used to notify that the table column header has changed ",
288 ATK_TYPE_OBJECT,
289 G_PARAM_READWRITE));
290 g_object_class_install_property (gobject_class,
291 PROP_TABLE_COLUMN_DESCRIPTION,
292 g_param_spec_int (atk_object_name_property_table_column_description,
293 "Accessible Table Column Description",
294 "Is used to notify that the table columnscription has changed ",
296 G_MAXINT,
298 G_PARAM_READWRITE));
299 g_object_class_install_property (gobject_class,
300 PROP_TABLE_ROW_HEADER,
301 g_param_spec_object (atk_object_name_property_table_row_header,
302 "Accessible Table Row Header",
303 "Is used to notify that the table row header has changed ",
304 ATK_TYPE_OBJECT,
305 G_PARAM_READWRITE));
306 g_object_class_install_property (gobject_class,
307 PROP_TABLE_ROW_DESCRIPTION,
308 g_param_spec_int (atk_object_name_property_table_row_description,
309 "Accessible Table Row Description",
310 "Is used to notify that the table row description has changed ",
312 G_MAXINT,
314 G_PARAM_READWRITE));
315 g_object_class_install_property (gobject_class,
316 PROP_TABLE_SUMMARY,
317 g_param_spec_object (atk_object_name_property_table_summary,
318 "Accessible Table Summary",
319 "Is used to notify that the table summary has changed ",
320 ATK_TYPE_OBJECT,
321 G_PARAM_READWRITE));
322 g_object_class_install_property (gobject_class,
323 PROP_MODEL,
324 g_param_spec_object (atk_object_name_property_model,
325 "Accessible Model",
326 "Is used to notify that the model for Table or Tree has changed ",
327 ATK_TYPE_OBJECT,
328 G_PARAM_READWRITE));
330 * The signal "children_changed" supports two details:
331 * "add" and "remove"
333 atk_object_signals[CHILDREN_CHANGED] =
334 g_signal_new ("children_changed",
335 G_TYPE_FROM_CLASS (klass),
336 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
337 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
338 NULL, NULL,
339 g_cclosure_marshal_VOID__UINT_POINTER,
340 G_TYPE_NONE,
341 2, G_TYPE_UINT, G_TYPE_POINTER);
342 atk_object_signals[FOCUS_EVENT] =
343 g_signal_new ("focus_event",
344 G_TYPE_FROM_CLASS (klass),
345 G_SIGNAL_RUN_LAST,
346 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
347 NULL, NULL,
348 g_cclosure_marshal_VOID__BOOLEAN,
349 G_TYPE_NONE,
350 1, G_TYPE_BOOLEAN);
351 atk_object_signals[PROPERTY_CHANGE] =
352 g_signal_new ("property_change",
353 G_TYPE_FROM_CLASS (klass),
354 G_SIGNAL_RUN_LAST,
355 G_STRUCT_OFFSET (AtkObjectClass, property_change),
356 (GSignalAccumulator) NULL, NULL,
357 g_cclosure_marshal_VOID__POINTER,
358 G_TYPE_NONE, 1,
359 G_TYPE_POINTER);
362 static void
363 atk_object_init (AtkObject *accessible,
364 AtkObjectClass *klass)
366 accessible->name = NULL;
367 accessible->description = NULL;
368 accessible->accessible_parent = NULL;
369 accessible->relation_set = atk_relation_set_new();
370 accessible->role = ATK_ROLE_UNKNOWN;
373 GType
374 atk_implementor_get_type (void)
376 static GType type = 0;
378 if (!type)
380 static const GTypeInfo typeInfo =
382 sizeof (AtkImplementorIface),
383 (GBaseInitFunc) NULL,
384 (GBaseFinalizeFunc) NULL,
387 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
390 return type;
394 * atk_object_get_name:
395 * @accessible: an #AtkObject
397 * Gets the accessible name of the accessible.
399 * Returns: a character string representing the accessible name of the object.
401 G_CONST_RETURN gchar*
402 atk_object_get_name (AtkObject *accessible)
404 AtkObjectClass *klass;
406 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
408 klass = ATK_OBJECT_GET_CLASS (accessible);
409 if (klass->get_name)
410 return (klass->get_name) (accessible);
411 else
412 return NULL;
416 * atk_object_get_description:
417 * @accessible: an #AtkObject
419 * Gets the accessible description of the accessible.
421 * Returns: a character string representing the accessible description
422 * of the accessible.
425 G_CONST_RETURN gchar*
426 atk_object_get_description (AtkObject *accessible)
428 AtkObjectClass *klass;
430 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
432 klass = ATK_OBJECT_GET_CLASS (accessible);
433 if (klass->get_description)
434 return (klass->get_description) (accessible);
435 else
436 return NULL;
440 * atk_object_get_parent:
441 * @accessible: an #AtkObject
443 * Gets the accessible parent of the accessible.
445 * Returns: a #AtkObject representing the accessible parent of the accessible
447 AtkObject*
448 atk_object_get_parent (AtkObject *accessible)
450 AtkObjectClass *klass;
452 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
454 klass = ATK_OBJECT_GET_CLASS (accessible);
455 if (klass->get_parent)
456 return (klass->get_parent) (accessible);
457 else
458 return NULL;
462 * atk_object_get_n_accessible_children:
463 * @accessible: an #AtkObject
465 * Gets the number of accessible children of the accessible.
467 * Returns: an integer representing the number of accessible children
468 * of the accessible.
470 gint
471 atk_object_get_n_accessible_children (AtkObject *accessible)
473 AtkObjectClass *klass;
475 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
477 klass = ATK_OBJECT_GET_CLASS (accessible);
478 if (klass->get_n_children)
479 return (klass->get_n_children) (accessible);
480 else
481 return 0;
485 * atk_object_ref_accessible_child:
486 * @accessible: an #AtkObject
487 * @i: a gint representing the position of the child, starting from 0
489 * Gets a reference to the specified accessible child of the object.
490 * The accessible children are 0-based so the first accessible child is
491 * at index 0, the second at index 1 and so on.
493 * Returns: an #AtkObject representing the specified accessible child
494 * of the accessible.
496 AtkObject*
497 atk_object_ref_accessible_child (AtkObject *accessible,
498 gint i)
500 AtkObjectClass *klass;
502 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
504 klass = ATK_OBJECT_GET_CLASS (accessible);
505 if (klass->ref_child)
506 return (klass->ref_child) (accessible, i);
507 else
508 return NULL;
512 * atk_object_ref_relation_set:
513 * @accessible: an #AtkObject
515 * Gets the #AtkRelationSet associated with the object.
517 * Returns: an #AtkRelationSet representing the relation set of the object.
519 AtkRelationSet*
520 atk_object_ref_relation_set (AtkObject *accessible)
522 AtkObjectClass *klass;
524 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
526 klass = ATK_OBJECT_GET_CLASS (accessible);
527 if (klass->ref_relation_set)
528 return (klass->ref_relation_set) (accessible);
529 else
530 return NULL;
534 * atk_role_register:
535 * @name: a character string describing the new role.
537 * Registers the role specified by @name.
539 * Returns: an #AtkRole for the new role.
541 AtkRole
542 atk_role_register (const gchar *name)
544 /* TODO: associate name with new type */
545 static guint type = ATK_ROLE_LAST_DEFINED;
546 return (++type);
550 * atk_object_get_role:
551 * @accessible: an #AtkObject
553 * Gets the role of the accessible.
555 * Returns: an #AtkRole which is the role of the accessible
557 AtkRole
558 atk_object_get_role (AtkObject *accessible)
560 AtkObjectClass *klass;
562 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
564 klass = ATK_OBJECT_GET_CLASS (accessible);
565 if (klass->get_role)
566 return (klass->get_role) (accessible);
567 else
568 return ATK_ROLE_UNKNOWN;
572 * atk_object_ref_state_set:
573 * @accessible: an #AtkObject
575 * Gets a reference to the state set of the accessible; the caller must
576 * unreference it when it is no longer needed.
578 * Returns: a reference to an #AtkStateSet which is the state
579 * set of the accessible
581 AtkStateSet*
582 atk_object_ref_state_set (AtkObject *accessible)
584 AtkObjectClass *klass;
586 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
588 klass = ATK_OBJECT_GET_CLASS (accessible);
589 if (klass->ref_state_set)
590 return (klass->ref_state_set) (accessible);
591 else
592 return NULL;
596 * atk_object_get_index_in_parent:
597 * @accessible: an #AtkObject
599 * Gets the 0-based index of this accessible in its parent; returns -1 if the
600 * accessible does not have an accessible parent.
602 * Returns: an integer which is the index of the accessible in its parent
604 gint
605 atk_object_get_index_in_parent (AtkObject *accessible)
607 AtkObjectClass *klass;
609 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
611 klass = ATK_OBJECT_GET_CLASS (accessible);
612 if (klass->get_index_in_parent)
613 return (klass->get_index_in_parent) (accessible);
614 else
615 return -1;
619 * atk_object_set_name:
620 * @accessible: an #AtkObject
621 * @name: a character string to be set as the accessible name
623 * Sets the accessible name of the accessible.
625 void
626 atk_object_set_name (AtkObject *accessible,
627 const gchar *name)
629 AtkObjectClass *klass;
631 g_return_if_fail (ATK_IS_OBJECT (accessible));
632 g_return_if_fail (name != NULL);
634 klass = ATK_OBJECT_GET_CLASS (accessible);
635 if (klass->set_name)
637 (klass->set_name) (accessible, name);
638 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
643 * atk_object_set_description:
644 * @accessible: an #AtkObject
645 * @description : a character string to be set as the accessible description
647 * Sets the accessible description of the accessible.
649 void
650 atk_object_set_description (AtkObject *accessible,
651 const gchar *description)
653 AtkObjectClass *klass;
655 g_return_if_fail (ATK_IS_OBJECT (accessible));
656 g_return_if_fail (description != NULL);
658 klass = ATK_OBJECT_GET_CLASS (accessible);
659 if (klass->set_description)
661 (klass->set_description) (accessible, description);
662 g_object_notify (G_OBJECT (accessible), atk_object_name_property_description);
667 * atk_object_set_parent:
668 * @accessible: an #AtkObject
669 * @parent : an #AtkObject to be set as the accessible parent
671 * Sets the accessible parent of the accessible.
673 void
674 atk_object_set_parent (AtkObject *accessible,
675 AtkObject *parent)
677 AtkObjectClass *klass;
679 g_return_if_fail (ATK_IS_OBJECT (accessible));
681 klass = ATK_OBJECT_GET_CLASS (accessible);
682 if (klass->set_parent)
683 (klass->set_parent) (accessible, parent);
687 * atk_object_set_role:
688 * @accessible: an #AtkObject
689 * @role : an #AtkRole to be set as the role
691 * Sets the role of the accessible.
693 void
694 atk_object_set_role (AtkObject *accessible,
695 AtkRole role)
697 AtkObjectClass *klass;
699 g_return_if_fail (ATK_IS_OBJECT (accessible));
701 klass = ATK_OBJECT_GET_CLASS (accessible);
702 if (klass->set_role)
703 (klass->set_role) (accessible, role);
707 * atk_object_connect_property_change_handler:
708 * @accessible: an #AtkObject
709 * @handler : a function to be called when a property changes its value
711 * Specifies a function to be called when a property changes value.
713 * Returns: a #guint which is the handler id used in
714 * atk_object_remove_property_change_handler()
716 guint
717 atk_object_connect_property_change_handler (AtkObject *accessible,
718 AtkPropertyChangeHandler *handler)
720 AtkObjectClass *klass;
722 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
723 g_return_val_if_fail ((handler != NULL), 0);
725 klass = ATK_OBJECT_GET_CLASS (accessible);
726 if (klass->connect_property_change_handler)
727 return (klass->connect_property_change_handler) (accessible, handler);
728 else
729 return 0;
733 * atk_object_remove_property_change_handler:
734 * @accessible: an #AtkObject
735 * @handler_id : a guint which identifies the handler to be removed.
737 * Removes a property change handler.
739 void
740 atk_object_remove_property_change_handler (AtkObject *accessible,
741 guint handler_id)
743 AtkObjectClass *klass;
745 g_return_if_fail (ATK_IS_OBJECT (accessible));
747 klass = ATK_OBJECT_GET_CLASS (accessible);
748 if (klass->remove_property_change_handler)
749 (klass->remove_property_change_handler) (accessible, handler_id);
753 * atk_implementor_ref_accessible:
754 * @implementor: The #GObject instance which should implement #AtkImplementorIface
755 * if a non-null return value is required.
757 * Gets a reference to an object's #AtkObject implementation, if
758 * the object implements #AtkObjectIface
760 * Returns: a reference to an object's #AtkObject implementation
762 AtkObject *
763 atk_implementor_ref_accessible (AtkImplementor *object)
765 AtkImplementorIface *iface;
766 AtkObject *accessible = NULL;
768 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (object), NULL);
770 iface = ATK_IMPLEMENTOR_GET_IFACE (object);
772 if (iface != NULL)
773 accessible = iface->ref_accessible (object);
775 g_return_val_if_fail ((accessible != NULL), NULL);
777 return accessible;
780 static AtkRelationSet*
781 atk_object_real_ref_relation_set (AtkObject *accessible)
783 g_return_val_if_fail (accessible->relation_set, NULL);
784 g_object_ref (accessible->relation_set);
786 return accessible->relation_set;
789 static void
790 atk_object_real_set_property (GObject *object,
791 guint prop_id,
792 const GValue *value,
793 GParamSpec *pspec)
795 AtkObject *accessible;
797 accessible = ATK_OBJECT (object);
799 switch (prop_id)
801 case PROP_NAME:
802 atk_object_set_name (accessible, g_value_get_string (value));
803 break;
804 case PROP_DESCRIPTION:
805 atk_object_set_description (accessible, g_value_get_string (value));
806 break;
807 case PROP_STATE:
808 g_print ("This interface does not support setting the state set of an accessible object\n");
809 break;
810 case PROP_VALUE:
811 if (ATK_IS_VALUE (accessible))
812 atk_value_set_current_value (ATK_VALUE (accessible), value);
813 break;
814 default:
815 break;
819 static void
820 atk_object_real_get_property (GObject *object,
821 guint prop_id,
822 GValue *value,
823 GParamSpec *pspec)
825 AtkObject *accessible;
827 accessible = ATK_OBJECT (object);
829 switch (prop_id)
831 case PROP_NAME:
832 g_value_set_string (value, atk_object_get_name (accessible));
833 break;
834 case PROP_DESCRIPTION:
835 g_value_set_string (value, atk_object_get_description (accessible));
836 break;
837 case PROP_VALUE:
838 if (ATK_IS_VALUE (accessible))
839 atk_value_get_current_value (ATK_VALUE (accessible), value);
840 break;
841 default:
842 break;
846 static void
847 atk_object_finalize (GObject *object)
849 AtkObject *accessible;
851 g_return_if_fail (ATK_IS_OBJECT (object));
853 accessible = ATK_OBJECT (object);
855 g_free (accessible->name);
856 g_free (accessible->description);
859 * Free memory allocated for relation set if it have been allocated.
861 if (accessible->relation_set)
863 g_object_unref (accessible->relation_set);
866 G_OBJECT_CLASS (parent_class)->finalize (object);
869 static G_CONST_RETURN gchar*
870 atk_object_real_get_name (AtkObject *object)
872 return object->name;
875 static G_CONST_RETURN gchar*
876 atk_object_real_get_description (AtkObject *object)
878 return object->description;
881 static AtkObject*
882 atk_object_real_get_parent (AtkObject *object)
884 return object->accessible_parent;
887 static AtkRole
888 atk_object_real_get_role (AtkObject *object)
890 return object->role;
893 static AtkStateSet*
894 atk_object_real_ref_state_set (AtkObject *accessible)
896 AtkStateSet *state_set;
897 AtkObject *ap;
899 state_set = atk_state_set_new ();
901 ap = atk_object_get_parent (accessible);
902 if (ap)
904 if (ATK_IS_SELECTION (ap))
906 int i;
908 atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
910 i = atk_object_get_index_in_parent (accessible);
911 if (i >= 0)
913 if (atk_selection_is_child_selected(ATK_SELECTION (ap), i))
915 atk_state_set_add_state (state_set, ATK_STATE_SELECTED);
920 return state_set;
923 static void
924 atk_object_real_set_name (AtkObject *object,
925 const gchar *name)
927 g_free (object->name);
928 object->name = g_strdup (name);
931 static void
932 atk_object_real_set_description (AtkObject *object,
933 const gchar *description)
935 g_free (object->description);
936 object->description = g_strdup (description);
939 static void
940 atk_object_real_set_parent (AtkObject *object,
941 AtkObject *parent)
943 object->accessible_parent = parent;
947 static void
948 atk_object_real_set_role (AtkObject *object,
949 AtkRole role)
951 object->role = role;
954 static guint
955 atk_object_real_connect_property_change_handler (AtkObject *obj,
956 AtkPropertyChangeHandler *handler)
958 return g_signal_connect_closure_by_id (obj,
959 atk_object_signals[PROPERTY_CHANGE],
961 g_cclosure_new (
962 G_CALLBACK (handler), NULL,
963 (GClosureNotify) NULL),
964 FALSE);
967 static void
968 atk_object_real_remove_property_change_handler (AtkObject *obj,
969 guint handler_id)
971 g_signal_handler_disconnect (obj, handler_id);
975 * This function is a signal handler for notify signal which gets emitted
976 * when a property changes value.
978 * It constructs an AtkPropertyValues structure and emits a "property_changed"
979 * signal which causes the user specified AtkPropertyChangeHandler
980 * to be called.
982 static void
983 atk_object_notify (GObject *obj,
984 GParamSpec *pspec)
986 AtkPropertyValues values;
988 memset (&values.old_value, 0, sizeof (GValue));
989 memset (&values.new_value, 0, sizeof (GValue));
990 g_value_init (&values.new_value, pspec->value_type);
991 g_object_get_property(obj, pspec->name, &values.new_value);
992 values.property_name = pspec->name;
993 g_signal_emit (obj, atk_object_signals[PROPERTY_CHANGE], 0,
994 &values, NULL);