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.
22 #include <glib-object.h>
26 /* New GObject properties registered by AtkObject */
29 PROP_0, /* gobject convention */
33 PROP_PARENT, /* ancestry has changed */
34 PROP_CHILD, /* children have changed in number or identity */
35 PROP_ROLE, /* AtkRole has changed */
36 PROP_STATE, /* AtkState has changed */
37 PROP_TEXT, /* Used only by AtkText implementors */
38 PROP_CARET, /* Used only by AtkText implementors */
39 PROP_LAST /* gobject convention */
47 static void atk_object_class_init (AtkObjectClass *klass);
48 static void atk_object_init (AtkObject *accessible,
49 AtkObjectClass *klass);
50 static AtkRelationSet* atk_object_real_ref_relation_set (AtkObject *accessible);
52 static void atk_object_real_set_property(GObject *object,
56 static void atk_object_real_get_property(GObject *object,
60 static void atk_object_finalize (GObject *object);
63 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
66 static gpointer parent_class = NULL;
68 static const gchar* atk_object_name_property_name = "accessible-name";
69 static const gchar* atk_object_name_property_state = "accessible-state";
70 static const gchar* atk_object_name_property_description = "accessible-description";
73 atk_object_get_type (void)
75 static GType type = 0;
79 static const GTypeInfo typeInfo =
81 sizeof (AtkObjectClass),
83 (GBaseFinalizeFunc) NULL,
84 (GClassInitFunc) atk_object_class_init,
85 (GClassFinalizeFunc) NULL,
89 (GInstanceInitFunc) atk_object_init,
91 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
97 atk_object_class_init (AtkObjectClass *klass)
99 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
101 parent_class = g_type_class_ref (G_TYPE_OBJECT);
103 gobject_class->set_property = atk_object_real_set_property;
104 gobject_class->get_property = atk_object_real_get_property;
105 gobject_class->finalize = atk_object_finalize;
107 klass->ref_relation_set = atk_object_real_ref_relation_set;
109 klass->children_changed = NULL;
111 g_object_class_install_property (gobject_class,
113 g_param_spec_string (atk_object_name_property_name,
115 "Object instance\'s name formatted for "
116 "assistive technology access",
119 g_object_class_install_property (gobject_class,
121 g_param_spec_string (atk_object_name_property_description,
122 "Accessible Description",
123 "Description of an object, formatted for "
124 "assistive technology access",
127 g_object_class_install_property (gobject_class,
129 g_param_spec_int (atk_object_name_property_state,
131 "The current state of this object "
132 "or its UI component",
138 /* register some properties - these could be change signals instead */
139 g_object_class_install_property (gobject_class,
141 g_param_spec_ccallback ("accessible_parent", "Accessible Parent",
142 "First accessible ancestor (container or object) "
143 "which this object is a descendant of",
147 g_object_class_install_property (gobject_class,
149 g_param_spec_ccallback ("accessible_role", "Accessible Role",
150 "The user-interface role of this object",
152 g_object_class_install_property (gobject_class,
154 g_param_spec_ccallback ("accessible_state", "Accessible State",
155 "The current state of this object "
156 "or its UI component",
158 g_object_class_install_property (gobject_class,
160 g_param_spec_ccallback ("accessible_text", "Accessible Text",
161 "This object\'s accessible text contents",
163 g_object_class_install_property (gobject_class,
165 g_param_spec_ccallback ("accessible_caret", "Accessible Text Caret",
166 "The current text caret state and position "
167 "for this component",
169 gaccessible_signals[CHILDREN_CHANGED] =
170 g_signal_newc ("accessible_children_changed",
171 G_TYPE_FROM_CLASS (klass),
173 G_STRUCT_OFFSET (AtkObjectClass, children_changed), /* still need to declare and define this func */
175 g_cclosure_marshal_VOID__UINT_POINTER,
177 2, G_TYPE_UINT, ATK_TYPE_OBJECT);
182 atk_object_init (AtkObject *accessible,
183 AtkObjectClass *klass)
188 atk_implementor_get_type (void)
190 static GType type = 0;
194 static const GTypeInfo typeInfo =
196 sizeof (AtkImplementorIface),
197 (GBaseInitFunc) NULL,
198 (GBaseFinalizeFunc) NULL,
201 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
208 * atk_object_get_name
209 * @accessible: a #AtkObject
210 * return values: a character string representing the accessible name of the object.
212 * Gets the accessible name of the accessible
214 G_CONST_RETURN gchar*
215 atk_object_get_name (AtkObject *accessible)
217 AtkObjectClass *klass;
219 g_return_val_if_fail (accessible != NULL, NULL);
220 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
222 klass = ATK_OBJECT_GET_CLASS (accessible);
224 return (klass->get_name) (accessible);
230 * atk_object_get_description
231 * @accessible: a #AtkObject
232 * return values: a character string representing the accessible description of the accessible.
234 * Gets the accessible description of the accessible
236 G_CONST_RETURN gchar*
237 atk_object_get_description (AtkObject *accessible)
239 AtkObjectClass *klass;
241 g_return_val_if_fail (accessible != NULL, NULL);
242 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
244 klass = ATK_OBJECT_GET_CLASS (accessible);
245 if (klass->get_description)
246 return (klass->get_description) (accessible);
252 * atk_object_get_parent
253 * @accessible: a #AtkObject
254 * return values: a #AtkObject representing the accessible parent of the accessible.
256 * Gets the accessible description of the accessible
259 atk_object_get_parent (AtkObject *accessible)
261 AtkObjectClass *klass;
263 g_return_val_if_fail (accessible != NULL, NULL);
264 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
266 klass = ATK_OBJECT_GET_CLASS (accessible);
267 if (klass->get_parent)
268 return (klass->get_parent) (accessible);
274 * atk_object_get_n_accessible_children
275 * @accessible: a #AtkObject
276 * return values: a gint representing the number of accessible children of the accessible.
278 * Gets the number of accessible children of the accessible
281 atk_object_get_n_accessible_children (AtkObject *accessible)
283 AtkObjectClass *klass;
285 g_return_val_if_fail (accessible != NULL, 0);
286 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
288 klass = ATK_OBJECT_GET_CLASS (accessible);
289 if (klass->get_n_children)
290 return (klass->get_n_children) (accessible);
296 * atk_object_ref_accessible_child
297 * @accessible: a #AtkObject
298 * @i: a gint representing the position of the child, starting from 0
299 * return values: a #AtkObject representing the specified accessible child of the accessible.
301 * Returns a reference to the specified accessible child of the object.
302 * The accessible children are 0-based so the first accessible child is
303 * at index 0, the second at index 1 and so on.
306 atk_object_ref_accessible_child (AtkObject *accessible,
309 AtkObjectClass *klass;
311 g_return_val_if_fail (accessible != NULL, NULL);
312 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
314 klass = ATK_OBJECT_GET_CLASS (accessible);
315 if (klass->ref_child)
316 return (klass->ref_child) (accessible, i);
322 * atk_object_ref_accessible_child
323 * @accessible: a #AtkObject
324 * return values: a #AtkRelationSet representing the relation set of the object.
326 * Returns a relation to the relation set associated of the accessible.
329 atk_object_ref_relation_set (AtkObject *accessible)
331 AtkObjectClass *klass;
333 g_return_val_if_fail (accessible != NULL, NULL);
334 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
336 klass = ATK_OBJECT_GET_CLASS (accessible);
337 if (klass->ref_relation_set)
338 return (klass->ref_relation_set) (accessible);
345 * @name: a character string describing the new role.
346 * return values: a #AtkRole value for the new role.
348 * Returns a #AtkRole value for the new role.
351 atk_role_register (const gchar *name)
353 /* TODO: associate name with new type */
354 static guint type = ATK_ROLE_LAST_DEFINED;
359 * atk_object_get_role
360 * @accessible: a #AtkObject
361 * return values: a #AtkRole which is the role of the accessible
363 * Gets the role of the accessible
366 atk_object_get_role (AtkObject *accessible) {
367 AtkObjectClass *klass;
369 g_return_val_if_fail (accessible != NULL, ATK_ROLE_UNKNOWN);
370 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
372 klass = ATK_OBJECT_GET_CLASS (accessible);
374 return (klass->get_role) (accessible);
376 return ATK_ROLE_UNKNOWN;
380 * atk_object_ref_state_set
381 * @accessible: a #AtkObject
382 * return values: a reference to a #AtkStateSet which is the state set of the accessible
384 * returns a reference to the state set of the accessible; the caller should
388 atk_object_ref_state_set (AtkObject *accessible) {
389 AtkObjectClass *klass;
391 g_return_val_if_fail (accessible != NULL, NULL);
392 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
394 klass = ATK_OBJECT_GET_CLASS (accessible);
395 if (klass->ref_state_set)
396 return (klass->ref_state_set) (accessible);
402 * atk_object_get_index_in_parent
403 * @accessible: a #AtkObject
404 * return values: a gint which is the index of the accessible in its parent
406 * Gets the 0-based index of this accessible in its parent; returns -1 if the
407 * accessible does not have an accessible parent.
410 atk_object_get_index_in_parent (AtkObject *accessible)
412 AtkObjectClass *klass;
414 g_return_val_if_fail (accessible != NULL, -1);
415 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
417 klass = ATK_OBJECT_GET_CLASS (accessible);
418 if (klass->get_index_in_parent)
419 return (klass->get_index_in_parent) (accessible);
425 * atk_object_set_name
426 * @accessible: a #AtkObject
427 * @name : a character string to be set as the accessible name
429 * Sets the accessible name of the accessible
432 atk_object_set_name (AtkObject *accessible,
435 AtkObjectClass *klass;
437 g_return_if_fail (accessible != NULL);
438 g_return_if_fail (ATK_IS_OBJECT (accessible));
439 g_return_if_fail (name != NULL);
441 klass = ATK_OBJECT_GET_CLASS (accessible);
444 (klass->set_name) (accessible, name);
445 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
450 * atk_object_set_name
451 * @accessible: a #AtkObject
452 * @description : a character string to be set as the accessible description
454 * Sets the accessible description of the accessible
457 atk_object_set_description (AtkObject *accessible,
458 const gchar *description)
460 AtkObjectClass *klass;
462 g_return_if_fail (accessible != NULL);
463 g_return_if_fail (ATK_IS_OBJECT (accessible));
464 g_return_if_fail (description != NULL);
466 klass = ATK_OBJECT_GET_CLASS (accessible);
467 if (klass->set_description)
469 (klass->set_description) (accessible, description);
470 g_object_notify (G_OBJECT (accessible), atk_object_name_property_description);
475 * atk_object_set_name
476 * @accessible: a #AtkObject
477 * @parent : a #AtkObject to be set as the accessible parent
479 * Sets the accessible parent of the accessible
482 atk_object_set_parent (AtkObject *accessible,
485 AtkObjectClass *klass;
487 g_return_if_fail (accessible != NULL);
488 g_return_if_fail (ATK_IS_OBJECT (accessible));
490 klass = ATK_OBJECT_GET_CLASS (accessible);
491 if (klass->set_parent)
492 (klass->set_parent) (accessible, parent);
496 * atk_object_set_name
497 * @accessible: a #AtkObject
498 * @role : a #AtkRole to be set as the role
500 * Sets the role of the accessible
503 atk_object_set_role (AtkObject *accessible,
506 AtkObjectClass *klass;
508 g_return_if_fail (accessible != NULL);
509 g_return_if_fail (ATK_IS_OBJECT (accessible));
511 klass = ATK_OBJECT_GET_CLASS (accessible);
513 (klass->set_role) (accessible, role);
517 atk_object_connect_property_change_handler (AtkObject *accessible,
518 AtkPropertyChangeHandler *handler)
520 AtkObjectClass *klass;
522 g_return_val_if_fail (accessible != NULL, 0);
523 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
524 g_return_val_if_fail ((handler != NULL), 0);
526 klass = ATK_OBJECT_GET_CLASS (accessible);
527 if (klass->connect_property_change_handler)
528 return (klass->connect_property_change_handler) (accessible, handler);
534 atk_object_remove_property_change_handler (AtkObject *accessible,
537 AtkObjectClass *klass;
539 g_return_if_fail (accessible != NULL);
540 g_return_if_fail (ATK_IS_OBJECT (accessible));
542 klass = ATK_OBJECT_GET_CLASS (accessible);
543 if (klass->remove_property_change_handler)
544 (klass->remove_property_change_handler) (accessible, handler_id);
548 * atk_implementor_ref_accessible
549 * @object: The GObject instance which should implement #AtkImplementorIface
550 * if a non-null return value is required.
551 * Return a reference to an object's AtkObject implementation, if
552 * the object implements AtkObjectIface.
555 atk_implementor_ref_accessible (AtkImplementor *object)
557 AtkImplementorIface *iface;
558 AtkObject *accessible = NULL;
560 g_return_val_if_fail (object != NULL, NULL);
561 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (object), NULL);
563 iface = ATK_IMPLEMENTOR_GET_IFACE (object);
566 accessible = iface->ref_accessible (object);
568 g_return_val_if_fail ((accessible != NULL), NULL);
573 static AtkRelationSet*
574 atk_object_real_ref_relation_set (AtkObject *accessible)
576 if (accessible->relation_set)
577 g_object_ref (accessible->relation_set);
579 return accessible->relation_set;
583 atk_object_real_set_property (GObject *object,
588 AtkObject *accessible;
590 accessible = ATK_OBJECT (object);
595 atk_object_set_name (accessible, g_value_get_string (value));
597 case PROP_DESCRIPTION:
598 atk_object_set_description (accessible, g_value_get_string (value));
601 g_print ("This interface does not support setting the state of an accessible object\n");
609 atk_object_real_get_property (GObject *object,
614 AtkObject *accessible;
616 accessible = ATK_OBJECT (object);
621 g_value_set_string (value, atk_object_get_name (accessible));
623 case PROP_DESCRIPTION:
624 g_value_set_string (value, atk_object_get_description (accessible));
632 atk_object_finalize (GObject *object)
634 AtkObject *accessible;
636 g_return_if_fail (ATK_IS_OBJECT (object));
638 accessible = ATK_OBJECT (object);
640 g_free (accessible->name);
641 g_free (accessible->description);
644 * Free memory allocated for relation set if it have been allocated.
646 if (accessible->relation_set)
648 g_object_unref (accessible->relation_set);
651 G_OBJECT_CLASS (parent_class)->finalize (object);