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, /* 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 */
40 PROP_LAST /* gobject convention */
49 static void atk_object_class_init (AtkObjectClass *klass);
50 static void atk_object_init (AtkObject *accessible,
51 AtkObjectClass *klass);
52 static AtkRelationSet* atk_object_real_ref_relation_set (AtkObject *accessible);
54 static void atk_object_real_set_property(GObject *object,
58 static void atk_object_real_get_property(GObject *object,
62 static void atk_object_finalize (GObject *object);
63 static void atk_object_real_set_role (AtkObject *object,
66 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
68 static gpointer parent_class = NULL;
70 static const gchar* atk_object_name_property_name = "accessible-name";
71 static const gchar* atk_object_name_property_state = "accessible-state";
72 static const gchar* atk_object_name_property_description = "accessible-description";
73 static const gchar* atk_object_name_property_child = "accessible-child";
74 static const gchar* atk_object_name_property_parent = "accessible-parent";
75 static const gchar* atk_object_name_property_text = "accessible-text";
76 static const gchar* atk_object_name_property_caret = "accessible-caret";
77 static const gchar* atk_object_name_property_selection = "accessible-selection";
78 static const gchar* atk_object_name_property_value = "accessible-value";
81 atk_object_get_type (void)
83 static GType type = 0;
87 static const GTypeInfo typeInfo =
89 sizeof (AtkObjectClass),
91 (GBaseFinalizeFunc) NULL,
92 (GClassInitFunc) atk_object_class_init,
93 (GClassFinalizeFunc) NULL,
97 (GInstanceInitFunc) atk_object_init,
99 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
105 atk_object_class_init (AtkObjectClass *klass)
107 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
109 parent_class = g_type_class_ref (G_TYPE_OBJECT);
111 gobject_class->set_property = atk_object_real_set_property;
112 gobject_class->get_property = atk_object_real_get_property;
113 gobject_class->finalize = atk_object_finalize;
115 klass->ref_relation_set = atk_object_real_ref_relation_set;
116 klass->set_role = atk_object_real_set_role;
119 * We do not define default signal handlers here
121 klass->focus_event = NULL;
122 klass->children_changed = NULL;
124 g_object_class_install_property (gobject_class,
126 g_param_spec_string (atk_object_name_property_name,
128 "Object instance\'s name formatted for "
129 "assistive technology access",
132 g_object_class_install_property (gobject_class,
134 g_param_spec_string (atk_object_name_property_description,
135 "Accessible Description",
136 "Description of an object, formatted for "
137 "assistive technology access",
140 g_object_class_install_property (gobject_class,
142 g_param_spec_int (atk_object_name_property_state,
143 "Accessible State Set",
144 "The accessible state set of this object "
145 "or its UI component",
150 g_object_class_install_property (gobject_class,
152 g_param_spec_object (atk_object_name_property_child,
154 "Is used to notify that a child has been added or removed ",
157 g_object_class_install_property (gobject_class,
159 g_param_spec_object (atk_object_name_property_parent,
161 "Is used to notify that the parent has been changed ",
164 g_object_class_install_property (gobject_class,
166 g_param_spec_object (atk_object_name_property_text,
168 "Is used to notify that the text has been changed ",
171 g_object_class_install_property (gobject_class,
173 g_param_spec_int (atk_object_name_property_caret,
175 "Is used to notify that the caret position has been changed ",
180 g_object_class_install_property (gobject_class,
182 g_param_spec_object (atk_object_name_property_selection,
183 "Accessible Selection",
184 "Is used to notify that the selection has been changed ",
188 * XXX We need to reconsider the value type for this
190 g_object_class_install_property (gobject_class,
192 g_param_spec_int (atk_object_name_property_value,
194 "Is used to notify that the value has been changed ",
200 * The signal "children_changed" supports two details:
203 atk_object_signals[CHILDREN_CHANGED] =
204 g_signal_newc ("children_changed",
205 G_TYPE_FROM_CLASS (klass),
206 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
207 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
209 g_cclosure_marshal_VOID__UINT_POINTER,
211 2, G_TYPE_UINT, ATK_TYPE_OBJECT);
212 atk_object_signals[FOCUS_EVENT] =
213 g_signal_newc ("focus_event",
214 G_TYPE_FROM_CLASS (klass),
216 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
218 g_cclosure_marshal_VOID__BOOLEAN,
224 atk_object_init (AtkObject *accessible,
225 AtkObjectClass *klass)
230 atk_implementor_get_type (void)
232 static GType type = 0;
236 static const GTypeInfo typeInfo =
238 sizeof (AtkImplementorIface),
239 (GBaseInitFunc) NULL,
240 (GBaseFinalizeFunc) NULL,
243 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
250 * atk_object_get_name:
251 * @accessible: an #AtkObject
253 * Gets the accessible name of the accessible
255 * Returns: a character string representing the accessible name of the object.
257 G_CONST_RETURN gchar*
258 atk_object_get_name (AtkObject *accessible)
260 AtkObjectClass *klass;
262 g_return_val_if_fail (accessible != NULL, NULL);
263 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
265 klass = ATK_OBJECT_GET_CLASS (accessible);
267 return (klass->get_name) (accessible);
273 * atk_object_get_description:
274 * @accessible: an #AtkObject
276 * Gets the accessible description of the accessible
278 * Returns: a character string representing the accessible description
282 G_CONST_RETURN gchar*
283 atk_object_get_description (AtkObject *accessible)
285 AtkObjectClass *klass;
287 g_return_val_if_fail (accessible != NULL, NULL);
288 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
290 klass = ATK_OBJECT_GET_CLASS (accessible);
291 if (klass->get_description)
292 return (klass->get_description) (accessible);
298 * atk_object_get_parent:
299 * @accessible: an #AtkObject
301 * Gets the accessible parent of the accessible
303 * Returns: a #AtkObject representing the accessible parent of the accessible
306 atk_object_get_parent (AtkObject *accessible)
308 AtkObjectClass *klass;
310 g_return_val_if_fail (accessible != NULL, NULL);
311 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
313 klass = ATK_OBJECT_GET_CLASS (accessible);
314 if (klass->get_parent)
315 return (klass->get_parent) (accessible);
321 * atk_object_get_n_accessible_children:
322 * @accessible: an #AtkObject
324 * Gets the number of accessible children of the accessible
326 * Returns: an integer representing the number of accessible children
330 atk_object_get_n_accessible_children (AtkObject *accessible)
332 AtkObjectClass *klass;
334 g_return_val_if_fail (accessible != NULL, 0);
335 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
337 klass = ATK_OBJECT_GET_CLASS (accessible);
338 if (klass->get_n_children)
339 return (klass->get_n_children) (accessible);
345 * atk_object_ref_accessible_child:
346 * @accessible: an #AtkObject
347 * @i: a gint representing the position of the child, starting from 0
349 * Gets a reference to the specified accessible child of the object.
350 * The accessible children are 0-based so the first accessible child is
351 * at index 0, the second at index 1 and so on.
353 * Returns: an #AtkObject representing the specified accessible child
357 atk_object_ref_accessible_child (AtkObject *accessible,
360 AtkObjectClass *klass;
362 g_return_val_if_fail (accessible != NULL, NULL);
363 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
365 klass = ATK_OBJECT_GET_CLASS (accessible);
366 if (klass->ref_child)
367 return (klass->ref_child) (accessible, i);
373 * atk_object_ref_relation_set:
374 * @accessible: an #AtkObject
376 * Gets the RelationSet associated with the object
378 * Returns: an #AtkRelationSet representing the relation set of the object.
381 atk_object_ref_relation_set (AtkObject *accessible)
383 AtkObjectClass *klass;
385 g_return_val_if_fail (accessible != NULL, NULL);
386 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
388 klass = ATK_OBJECT_GET_CLASS (accessible);
389 if (klass->ref_relation_set)
390 return (klass->ref_relation_set) (accessible);
397 * @name: a character string describing the new role.
399 * Returns: an #AtkRole for the new role.
402 atk_role_register (const gchar *name)
404 /* TODO: associate name with new type */
405 static guint type = ATK_ROLE_LAST_DEFINED;
410 * atk_object_get_role:
411 * @accessible: an #AtkObject
413 * Gets the role of the accessible
415 * Returns: an #AtkRole which is the role of the accessible
418 atk_object_get_role (AtkObject *accessible) {
419 AtkObjectClass *klass;
421 g_return_val_if_fail (accessible != NULL, ATK_ROLE_UNKNOWN);
422 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
424 klass = ATK_OBJECT_GET_CLASS (accessible);
426 return (klass->get_role) (accessible);
428 return ATK_ROLE_UNKNOWN;
432 * atk_object_ref_state_set:
433 * @accessible: an #AtkObject
435 * Gets a reference to the state set of the accessible; the caller should
438 * Returns: a reference to an #AtkStateSet which is the state
439 * set of the accessible
442 atk_object_ref_state_set (AtkObject *accessible) {
443 AtkObjectClass *klass;
445 g_return_val_if_fail (accessible != NULL, NULL);
446 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
448 klass = ATK_OBJECT_GET_CLASS (accessible);
449 if (klass->ref_state_set)
450 return (klass->ref_state_set) (accessible);
456 * atk_object_get_index_in_parent:
457 * @accessible: an #AtkObject
459 * Gets the 0-based index of this accessible in its parent; returns -1 if the
460 * accessible does not have an accessible parent.
462 * Returns: an integer which is the index of the accessible in its parent
465 atk_object_get_index_in_parent (AtkObject *accessible)
467 AtkObjectClass *klass;
469 g_return_val_if_fail (accessible != NULL, -1);
470 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
472 klass = ATK_OBJECT_GET_CLASS (accessible);
473 if (klass->get_index_in_parent)
474 return (klass->get_index_in_parent) (accessible);
480 * atk_object_set_name:
481 * @accessible: an #AtkObject
482 * @name: a character string to be set as the accessible name
484 * Sets the accessible name of the accessible
487 atk_object_set_name (AtkObject *accessible,
490 AtkObjectClass *klass;
492 g_return_if_fail (accessible != NULL);
493 g_return_if_fail (ATK_IS_OBJECT (accessible));
494 g_return_if_fail (name != NULL);
496 klass = ATK_OBJECT_GET_CLASS (accessible);
499 (klass->set_name) (accessible, name);
500 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
505 * atk_object_set_description:
506 * @accessible: an #AtkObject
507 * @description : a character string to be set as the accessible description
509 * Sets the accessible description of the accessible
512 atk_object_set_description (AtkObject *accessible,
513 const gchar *description)
515 AtkObjectClass *klass;
517 g_return_if_fail (accessible != NULL);
518 g_return_if_fail (ATK_IS_OBJECT (accessible));
519 g_return_if_fail (description != NULL);
521 klass = ATK_OBJECT_GET_CLASS (accessible);
522 if (klass->set_description)
524 (klass->set_description) (accessible, description);
525 g_object_notify (G_OBJECT (accessible), atk_object_name_property_description);
530 * atk_object_set_parent:
531 * @accessible: an #AtkObject
532 * @parent : an #AtkObject to be set as the accessible parent
534 * Sets the accessible parent of the accessible
537 atk_object_set_parent (AtkObject *accessible,
540 AtkObjectClass *klass;
542 g_return_if_fail (accessible != NULL);
543 g_return_if_fail (ATK_IS_OBJECT (accessible));
545 klass = ATK_OBJECT_GET_CLASS (accessible);
546 if (klass->set_parent)
547 (klass->set_parent) (accessible, parent);
551 * atk_object_set_role:
552 * @accessible: an #AtkObject
553 * @role : an #AtkRole to be set as the role
555 * Sets the role of the accessible
558 atk_object_set_role (AtkObject *accessible,
561 AtkObjectClass *klass;
563 g_return_if_fail (accessible != NULL);
564 g_return_if_fail (ATK_IS_OBJECT (accessible));
566 klass = ATK_OBJECT_GET_CLASS (accessible);
568 (klass->set_role) (accessible, role);
572 * atk_object_connect_property_change_handler:
573 * @accessible: an #AtkObject
574 * @handler : a function to be called when a property changes its value
576 * Specifies a function to be called when a property changes value.
578 * Returns: a #guint which is the handler id used in
579 * atk_object_remove_property_change_handler()
582 atk_object_connect_property_change_handler (AtkObject *accessible,
583 AtkPropertyChangeHandler *handler)
585 AtkObjectClass *klass;
587 g_return_val_if_fail (accessible != NULL, 0);
588 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
589 g_return_val_if_fail ((handler != NULL), 0);
591 klass = ATK_OBJECT_GET_CLASS (accessible);
592 if (klass->connect_property_change_handler)
593 return (klass->connect_property_change_handler) (accessible, handler);
599 * atk_object_remove_property_change_handler:
600 * @accessible: an #AtkObject
601 * @handler_id : a guint which identifies the handler to be removed.
603 * Removes a property change handler.
606 atk_object_remove_property_change_handler (AtkObject *accessible,
609 AtkObjectClass *klass;
611 g_return_if_fail (accessible != NULL);
612 g_return_if_fail (ATK_IS_OBJECT (accessible));
614 klass = ATK_OBJECT_GET_CLASS (accessible);
615 if (klass->remove_property_change_handler)
616 (klass->remove_property_change_handler) (accessible, handler_id);
620 * atk_implementor_ref_accessible:
621 * @implementor: The #GObject instance which should implement #AtkImplementorIface
622 * if a non-null return value is required.
624 * Gets a reference to an object's #AtkObject implementation, if
625 * the object implements #AtkObjectIface
627 * Returns: a reference to an object's #AtkObject implementation
630 atk_implementor_ref_accessible (AtkImplementor *object)
632 AtkImplementorIface *iface;
633 AtkObject *accessible = NULL;
635 g_return_val_if_fail (object != NULL, NULL);
636 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (object), NULL);
638 iface = ATK_IMPLEMENTOR_GET_IFACE (object);
641 accessible = iface->ref_accessible (object);
643 g_return_val_if_fail ((accessible != NULL), NULL);
648 static AtkRelationSet*
649 atk_object_real_ref_relation_set (AtkObject *accessible)
651 if (accessible->relation_set)
652 g_object_ref (accessible->relation_set);
654 return accessible->relation_set;
658 atk_object_real_set_property (GObject *object,
663 AtkObject *accessible;
665 accessible = ATK_OBJECT (object);
670 atk_object_set_name (accessible, g_value_get_string (value));
672 case PROP_DESCRIPTION:
673 atk_object_set_description (accessible, g_value_get_string (value));
676 g_print ("This interface does not support setting the state set of an accessible object\n");
684 atk_object_real_get_property (GObject *object,
689 AtkObject *accessible;
691 accessible = ATK_OBJECT (object);
696 g_value_set_string (value, atk_object_get_name (accessible));
698 case PROP_DESCRIPTION:
699 g_value_set_string (value, atk_object_get_description (accessible));
707 atk_object_finalize (GObject *object)
709 AtkObject *accessible;
711 g_return_if_fail (ATK_IS_OBJECT (object));
713 accessible = ATK_OBJECT (object);
715 g_free (accessible->name);
716 g_free (accessible->description);
719 * Free memory allocated for relation set if it have been allocated.
721 if (accessible->relation_set)
723 g_object_unref (accessible->relation_set);
726 G_OBJECT_CLASS (parent_class)->finalize (object);
730 atk_object_real_set_role (AtkObject *object,