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 */
41 PROP_LAST /* gobject convention */
50 static void atk_object_class_init (AtkObjectClass *klass);
51 static void atk_object_init (AtkObject *accessible,
52 AtkObjectClass *klass);
53 static AtkRelationSet* atk_object_real_ref_relation_set (AtkObject *accessible);
55 static void atk_object_real_set_property(GObject *object,
59 static void atk_object_real_get_property(GObject *object,
63 static void atk_object_finalize (GObject *object);
64 static void atk_object_real_set_role (AtkObject *object,
67 static guint atk_object_signals[LAST_SIGNAL] = { 0, };
69 static gpointer parent_class = NULL;
71 static const gchar* atk_object_name_property_name = "accessible-name";
72 static const gchar* atk_object_name_property_state = "accessible-state";
73 static const gchar* atk_object_name_property_description = "accessible-description";
74 static const gchar* atk_object_name_property_child = "accessible-child";
75 static const gchar* atk_object_name_property_parent = "accessible-parent";
76 static const gchar* atk_object_name_property_text = "accessible-text";
77 static const gchar* atk_object_name_property_caret = "accessible-caret";
78 static const gchar* atk_object_name_property_selection = "accessible-selection";
79 static const gchar* atk_object_name_property_value = "accessible-value";
80 static const gchar* atk_object_name_property_visible = "accessible-visible-data";
83 atk_object_get_type (void)
85 static GType type = 0;
89 static const GTypeInfo typeInfo =
91 sizeof (AtkObjectClass),
93 (GBaseFinalizeFunc) NULL,
94 (GClassInitFunc) atk_object_class_init,
95 (GClassFinalizeFunc) NULL,
99 (GInstanceInitFunc) atk_object_init,
101 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
107 atk_object_class_init (AtkObjectClass *klass)
109 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
111 parent_class = g_type_class_ref (G_TYPE_OBJECT);
113 gobject_class->set_property = atk_object_real_set_property;
114 gobject_class->get_property = atk_object_real_get_property;
115 gobject_class->finalize = atk_object_finalize;
117 klass->ref_relation_set = atk_object_real_ref_relation_set;
118 klass->set_role = atk_object_real_set_role;
121 * We do not define default signal handlers here
123 klass->focus_event = NULL;
124 klass->children_changed = NULL;
126 g_object_class_install_property (gobject_class,
128 g_param_spec_string (atk_object_name_property_name,
130 "Object instance\'s name formatted for "
131 "assistive technology access",
134 g_object_class_install_property (gobject_class,
136 g_param_spec_string (atk_object_name_property_description,
137 "Accessible Description",
138 "Description of an object, formatted for "
139 "assistive technology access",
142 g_object_class_install_property (gobject_class,
144 g_param_spec_int (atk_object_name_property_state,
145 "Accessible State Set",
146 "The accessible state set of this object "
147 "or its UI component",
152 g_object_class_install_property (gobject_class,
154 g_param_spec_object (atk_object_name_property_child,
156 "Is used to notify that a child has been added or removed ",
159 g_object_class_install_property (gobject_class,
161 g_param_spec_object (atk_object_name_property_parent,
163 "Is used to notify that the parent has changed ",
166 g_object_class_install_property (gobject_class,
168 g_param_spec_object (atk_object_name_property_text,
170 "Is used to notify that the text has changed ",
173 g_object_class_install_property (gobject_class,
175 g_param_spec_int (atk_object_name_property_caret,
177 "Is used to notify that the caret position has changed ",
182 g_object_class_install_property (gobject_class,
184 g_param_spec_object (atk_object_name_property_selection,
185 "Accessible Selection",
186 "Is used to notify that the selection has changed ",
189 g_object_class_install_property (gobject_class,
191 g_param_spec_double (atk_object_name_property_value,
193 "Is used to notify that the value has changed ",
198 g_object_class_install_property (gobject_class,
200 g_param_spec_object (atk_object_name_property_visible,
201 "Accessible Visible Data",
202 "Is used to notify that the visual appearance of the object has changed ",
206 * The signal "children_changed" supports two details:
209 atk_object_signals[CHILDREN_CHANGED] =
210 g_signal_newc ("children_changed",
211 G_TYPE_FROM_CLASS (klass),
212 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
213 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
215 g_cclosure_marshal_VOID__UINT_POINTER,
217 2, G_TYPE_UINT, ATK_TYPE_OBJECT);
218 atk_object_signals[FOCUS_EVENT] =
219 g_signal_newc ("focus_event",
220 G_TYPE_FROM_CLASS (klass),
222 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
224 g_cclosure_marshal_VOID__BOOLEAN,
230 atk_object_init (AtkObject *accessible,
231 AtkObjectClass *klass)
236 atk_implementor_get_type (void)
238 static GType type = 0;
242 static const GTypeInfo typeInfo =
244 sizeof (AtkImplementorIface),
245 (GBaseInitFunc) NULL,
246 (GBaseFinalizeFunc) NULL,
249 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
256 * atk_object_get_name:
257 * @accessible: an #AtkObject
259 * Gets the accessible name of the accessible
261 * Returns: a character string representing the accessible name of the object.
263 G_CONST_RETURN gchar*
264 atk_object_get_name (AtkObject *accessible)
266 AtkObjectClass *klass;
268 g_return_val_if_fail (accessible != NULL, NULL);
269 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
271 klass = ATK_OBJECT_GET_CLASS (accessible);
273 return (klass->get_name) (accessible);
279 * atk_object_get_description:
280 * @accessible: an #AtkObject
282 * Gets the accessible description of the accessible
284 * Returns: a character string representing the accessible description
288 G_CONST_RETURN gchar*
289 atk_object_get_description (AtkObject *accessible)
291 AtkObjectClass *klass;
293 g_return_val_if_fail (accessible != NULL, NULL);
294 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
296 klass = ATK_OBJECT_GET_CLASS (accessible);
297 if (klass->get_description)
298 return (klass->get_description) (accessible);
304 * atk_object_get_parent:
305 * @accessible: an #AtkObject
307 * Gets the accessible parent of the accessible
309 * Returns: a #AtkObject representing the accessible parent of the accessible
312 atk_object_get_parent (AtkObject *accessible)
314 AtkObjectClass *klass;
316 g_return_val_if_fail (accessible != NULL, NULL);
317 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
319 klass = ATK_OBJECT_GET_CLASS (accessible);
320 if (klass->get_parent)
321 return (klass->get_parent) (accessible);
327 * atk_object_get_n_accessible_children:
328 * @accessible: an #AtkObject
330 * Gets the number of accessible children of the accessible
332 * Returns: an integer representing the number of accessible children
336 atk_object_get_n_accessible_children (AtkObject *accessible)
338 AtkObjectClass *klass;
340 g_return_val_if_fail (accessible != NULL, 0);
341 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
343 klass = ATK_OBJECT_GET_CLASS (accessible);
344 if (klass->get_n_children)
345 return (klass->get_n_children) (accessible);
351 * atk_object_ref_accessible_child:
352 * @accessible: an #AtkObject
353 * @i: a gint representing the position of the child, starting from 0
355 * Gets a reference to the specified accessible child of the object.
356 * The accessible children are 0-based so the first accessible child is
357 * at index 0, the second at index 1 and so on.
359 * Returns: an #AtkObject representing the specified accessible child
363 atk_object_ref_accessible_child (AtkObject *accessible,
366 AtkObjectClass *klass;
368 g_return_val_if_fail (accessible != NULL, NULL);
369 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
371 klass = ATK_OBJECT_GET_CLASS (accessible);
372 if (klass->ref_child)
373 return (klass->ref_child) (accessible, i);
379 * atk_object_ref_relation_set:
380 * @accessible: an #AtkObject
382 * Gets the RelationSet associated with the object
384 * Returns: an #AtkRelationSet representing the relation set of the object.
387 atk_object_ref_relation_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_relation_set)
396 return (klass->ref_relation_set) (accessible);
403 * @name: a character string describing the new role.
405 * Returns: an #AtkRole for the new role.
408 atk_role_register (const gchar *name)
410 /* TODO: associate name with new type */
411 static guint type = ATK_ROLE_LAST_DEFINED;
416 * atk_object_get_role:
417 * @accessible: an #AtkObject
419 * Gets the role of the accessible
421 * Returns: an #AtkRole which is the role of the accessible
424 atk_object_get_role (AtkObject *accessible) {
425 AtkObjectClass *klass;
427 g_return_val_if_fail (accessible != NULL, ATK_ROLE_UNKNOWN);
428 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
430 klass = ATK_OBJECT_GET_CLASS (accessible);
432 return (klass->get_role) (accessible);
434 return ATK_ROLE_UNKNOWN;
438 * atk_object_ref_state_set:
439 * @accessible: an #AtkObject
441 * Gets a reference to the state set of the accessible; the caller should
444 * Returns: a reference to an #AtkStateSet which is the state
445 * set of the accessible
448 atk_object_ref_state_set (AtkObject *accessible) {
449 AtkObjectClass *klass;
451 g_return_val_if_fail (accessible != NULL, NULL);
452 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
454 klass = ATK_OBJECT_GET_CLASS (accessible);
455 if (klass->ref_state_set)
456 return (klass->ref_state_set) (accessible);
462 * atk_object_get_index_in_parent:
463 * @accessible: an #AtkObject
465 * Gets the 0-based index of this accessible in its parent; returns -1 if the
466 * accessible does not have an accessible parent.
468 * Returns: an integer which is the index of the accessible in its parent
471 atk_object_get_index_in_parent (AtkObject *accessible)
473 AtkObjectClass *klass;
475 g_return_val_if_fail (accessible != NULL, -1);
476 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
478 klass = ATK_OBJECT_GET_CLASS (accessible);
479 if (klass->get_index_in_parent)
480 return (klass->get_index_in_parent) (accessible);
486 * atk_object_set_name:
487 * @accessible: an #AtkObject
488 * @name: a character string to be set as the accessible name
490 * Sets the accessible name of the accessible
493 atk_object_set_name (AtkObject *accessible,
496 AtkObjectClass *klass;
498 g_return_if_fail (accessible != NULL);
499 g_return_if_fail (ATK_IS_OBJECT (accessible));
500 g_return_if_fail (name != NULL);
502 klass = ATK_OBJECT_GET_CLASS (accessible);
505 (klass->set_name) (accessible, name);
506 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
511 * atk_object_set_description:
512 * @accessible: an #AtkObject
513 * @description : a character string to be set as the accessible description
515 * Sets the accessible description of the accessible
518 atk_object_set_description (AtkObject *accessible,
519 const gchar *description)
521 AtkObjectClass *klass;
523 g_return_if_fail (accessible != NULL);
524 g_return_if_fail (ATK_IS_OBJECT (accessible));
525 g_return_if_fail (description != NULL);
527 klass = ATK_OBJECT_GET_CLASS (accessible);
528 if (klass->set_description)
530 (klass->set_description) (accessible, description);
531 g_object_notify (G_OBJECT (accessible), atk_object_name_property_description);
536 * atk_object_set_parent:
537 * @accessible: an #AtkObject
538 * @parent : an #AtkObject to be set as the accessible parent
540 * Sets the accessible parent of the accessible
543 atk_object_set_parent (AtkObject *accessible,
546 AtkObjectClass *klass;
548 g_return_if_fail (accessible != NULL);
549 g_return_if_fail (ATK_IS_OBJECT (accessible));
551 klass = ATK_OBJECT_GET_CLASS (accessible);
552 if (klass->set_parent)
553 (klass->set_parent) (accessible, parent);
557 * atk_object_set_role:
558 * @accessible: an #AtkObject
559 * @role : an #AtkRole to be set as the role
561 * Sets the role of the accessible
564 atk_object_set_role (AtkObject *accessible,
567 AtkObjectClass *klass;
569 g_return_if_fail (accessible != NULL);
570 g_return_if_fail (ATK_IS_OBJECT (accessible));
572 klass = ATK_OBJECT_GET_CLASS (accessible);
574 (klass->set_role) (accessible, role);
578 * atk_object_connect_property_change_handler:
579 * @accessible: an #AtkObject
580 * @handler : a function to be called when a property changes its value
582 * Specifies a function to be called when a property changes value.
584 * Returns: a #guint which is the handler id used in
585 * atk_object_remove_property_change_handler()
588 atk_object_connect_property_change_handler (AtkObject *accessible,
589 AtkPropertyChangeHandler *handler)
591 AtkObjectClass *klass;
593 g_return_val_if_fail (accessible != NULL, 0);
594 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
595 g_return_val_if_fail ((handler != NULL), 0);
597 klass = ATK_OBJECT_GET_CLASS (accessible);
598 if (klass->connect_property_change_handler)
599 return (klass->connect_property_change_handler) (accessible, handler);
605 * atk_object_remove_property_change_handler:
606 * @accessible: an #AtkObject
607 * @handler_id : a guint which identifies the handler to be removed.
609 * Removes a property change handler.
612 atk_object_remove_property_change_handler (AtkObject *accessible,
615 AtkObjectClass *klass;
617 g_return_if_fail (accessible != NULL);
618 g_return_if_fail (ATK_IS_OBJECT (accessible));
620 klass = ATK_OBJECT_GET_CLASS (accessible);
621 if (klass->remove_property_change_handler)
622 (klass->remove_property_change_handler) (accessible, handler_id);
626 * atk_implementor_ref_accessible:
627 * @implementor: The #GObject instance which should implement #AtkImplementorIface
628 * if a non-null return value is required.
630 * Gets a reference to an object's #AtkObject implementation, if
631 * the object implements #AtkObjectIface
633 * Returns: a reference to an object's #AtkObject implementation
636 atk_implementor_ref_accessible (AtkImplementor *object)
638 AtkImplementorIface *iface;
639 AtkObject *accessible = NULL;
641 g_return_val_if_fail (object != NULL, NULL);
642 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (object), NULL);
644 iface = ATK_IMPLEMENTOR_GET_IFACE (object);
647 accessible = iface->ref_accessible (object);
649 g_return_val_if_fail ((accessible != NULL), NULL);
654 static AtkRelationSet*
655 atk_object_real_ref_relation_set (AtkObject *accessible)
657 if (accessible->relation_set)
658 g_object_ref (accessible->relation_set);
660 return accessible->relation_set;
664 atk_object_real_set_property (GObject *object,
669 AtkObject *accessible;
671 accessible = ATK_OBJECT (object);
676 atk_object_set_name (accessible, g_value_get_string (value));
678 case PROP_DESCRIPTION:
679 atk_object_set_description (accessible, g_value_get_string (value));
682 g_print ("This interface does not support setting the state set of an accessible object\n");
685 if (ATK_IS_VALUE (accessible))
686 atk_value_set_current_value (ATK_VALUE (accessible), value);
694 atk_object_real_get_property (GObject *object,
699 AtkObject *accessible;
701 accessible = ATK_OBJECT (object);
706 g_value_set_string (value, atk_object_get_name (accessible));
708 case PROP_DESCRIPTION:
709 g_value_set_string (value, atk_object_get_description (accessible));
712 if (ATK_IS_VALUE (accessible))
713 atk_value_get_current_value (ATK_VALUE (accessible), value);
721 atk_object_finalize (GObject *object)
723 AtkObject *accessible;
725 g_return_if_fail (ATK_IS_OBJECT (object));
727 accessible = ATK_OBJECT (object);
729 g_free (accessible->name);
730 g_free (accessible->description);
733 * Free memory allocated for relation set if it have been allocated.
735 if (accessible->relation_set)
737 g_object_unref (accessible->relation_set);
740 G_OBJECT_CLASS (parent_class)->finalize (object);
744 atk_object_real_set_role (AtkObject *object,