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 */
38 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);
61 static void atk_object_real_set_role (AtkObject *object,
63 static void atk_object_focus_event_unimplemented
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";
78 atk_object_get_type (void)
80 static GType type = 0;
84 static const GTypeInfo typeInfo =
86 sizeof (AtkObjectClass),
88 (GBaseFinalizeFunc) NULL,
89 (GClassInitFunc) atk_object_class_init,
90 (GClassFinalizeFunc) NULL,
94 (GInstanceInitFunc) atk_object_init,
96 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
102 atk_object_class_init (AtkObjectClass *klass)
104 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
106 parent_class = g_type_class_ref (G_TYPE_OBJECT);
108 gobject_class->set_property = atk_object_real_set_property;
109 gobject_class->get_property = atk_object_real_get_property;
110 gobject_class->finalize = atk_object_finalize;
112 klass->ref_relation_set = atk_object_real_ref_relation_set;
113 klass->set_role = atk_object_real_set_role;
114 klass->focus_event = atk_object_focus_event_unimplemented;
116 klass->children_changed = NULL;
118 g_object_class_install_property (gobject_class,
120 g_param_spec_string (atk_object_name_property_name,
122 "Object instance\'s name formatted for "
123 "assistive technology access",
126 g_object_class_install_property (gobject_class,
128 g_param_spec_string (atk_object_name_property_description,
129 "Accessible Description",
130 "Description of an object, formatted for "
131 "assistive technology access",
134 g_object_class_install_property (gobject_class,
136 g_param_spec_int (atk_object_name_property_state,
137 "Accessible State Set",
138 "The accessible state set of this object "
139 "or its UI component",
144 g_object_class_install_property (gobject_class,
146 g_param_spec_object (atk_object_name_property_child,
148 "Is used to notify that a child has been added or removed ",
151 g_object_class_install_property (gobject_class,
153 g_param_spec_object (atk_object_name_property_parent,
155 "Is used to notify that the parent has been changed ",
159 g_object_class_install_property (gobject_class,
161 g_param_spec_ccallback ("accessible_text", "Accessible Text",
162 "This object\'s accessible text contents",
164 g_object_class_install_property (gobject_class,
166 g_param_spec_ccallback ("accessible_caret", "Accessible Text Caret",
167 "The current text caret state and position "
168 "for this component",
171 atk_object_signals[CHILDREN_CHANGED] =
172 g_signal_newc ("accessible_children_changed",
173 G_TYPE_FROM_CLASS (klass),
175 G_STRUCT_OFFSET (AtkObjectClass, children_changed), /* still need to declare and define this func */
177 g_cclosure_marshal_VOID__UINT_POINTER,
179 2, G_TYPE_UINT, ATK_TYPE_OBJECT);
180 atk_object_signals[FOCUS_EVENT] =
181 g_signal_newc ("focus_event",
182 G_TYPE_FROM_CLASS (klass),
184 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
186 g_cclosure_marshal_VOID__BOOLEAN,
192 atk_object_init (AtkObject *accessible,
193 AtkObjectClass *klass)
198 *atk_implementor_get_type:
203 atk_implementor_get_type (void)
205 static GType type = 0;
209 static const GTypeInfo typeInfo =
211 sizeof (AtkImplementorIface),
212 (GBaseInitFunc) NULL,
213 (GBaseFinalizeFunc) NULL,
216 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
223 * atk_object_get_name:
224 * @accessible: a #AtkObject
226 * Gets the accessible name of the accessible
228 * Returns: a character string representing the accessible name of the object.
230 G_CONST_RETURN gchar*
231 atk_object_get_name (AtkObject *accessible)
233 AtkObjectClass *klass;
235 g_return_val_if_fail (accessible != NULL, NULL);
236 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
238 klass = ATK_OBJECT_GET_CLASS (accessible);
240 return (klass->get_name) (accessible);
246 * atk_object_get_description:
247 * @accessible: a #AtkObject
249 * Gets the accessible description of the accessible
251 * Returns: a character string representing the accessible description of the accessible.
254 G_CONST_RETURN gchar*
255 atk_object_get_description (AtkObject *accessible)
257 AtkObjectClass *klass;
259 g_return_val_if_fail (accessible != NULL, NULL);
260 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
262 klass = ATK_OBJECT_GET_CLASS (accessible);
263 if (klass->get_description)
264 return (klass->get_description) (accessible);
270 * atk_object_get_parent:
271 * @accessible: a #AtkObject
273 * Gets the accessible description of the accessible
275 * Returns: a #AtkObject representing the accessible parent of the accessible.
278 atk_object_get_parent (AtkObject *accessible)
280 AtkObjectClass *klass;
282 g_return_val_if_fail (accessible != NULL, NULL);
283 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
285 klass = ATK_OBJECT_GET_CLASS (accessible);
286 if (klass->get_parent)
287 return (klass->get_parent) (accessible);
293 * atk_object_get_n_accessible_children:
294 * @accessible: a #AtkObject
296 * Gets the number of accessible children of the accessible
298 * Returns: a gint representing the number of accessible children of the accessible.
301 atk_object_get_n_accessible_children (AtkObject *accessible)
303 AtkObjectClass *klass;
305 g_return_val_if_fail (accessible != NULL, 0);
306 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
308 klass = ATK_OBJECT_GET_CLASS (accessible);
309 if (klass->get_n_children)
310 return (klass->get_n_children) (accessible);
316 * atk_object_ref_accessible_child:
317 * @accessible: a #AtkObject
318 * @i: a gint representing the position of the child, starting from 0
320 * Gets a reference to the specified accessible child of the object.
321 * The accessible children are 0-based so the first accessible child is
322 * at index 0, the second at index 1 and so on.
324 * Returns: a #AtkObject representing the specified accessible child of the accessible.
327 atk_object_ref_accessible_child (AtkObject *accessible,
330 AtkObjectClass *klass;
332 g_return_val_if_fail (accessible != NULL, NULL);
333 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
335 klass = ATK_OBJECT_GET_CLASS (accessible);
336 if (klass->ref_child)
337 return (klass->ref_child) (accessible, i);
343 * atk_object_ref_relation_set:
344 * @accessible: a #AtkObject
346 * Gets the RelationSet associated with the object
348 * Returns: a #AtkRelationSet representing the relation set of the object.
351 atk_object_ref_relation_set (AtkObject *accessible)
353 AtkObjectClass *klass;
355 g_return_val_if_fail (accessible != NULL, NULL);
356 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
358 klass = ATK_OBJECT_GET_CLASS (accessible);
359 if (klass->ref_relation_set)
360 return (klass->ref_relation_set) (accessible);
367 * @name: a character string describing the new role.
369 * Returns: a #AtkRole value for the new role.
372 atk_role_register (const gchar *name)
374 /* TODO: associate name with new type */
375 static guint type = ATK_ROLE_LAST_DEFINED;
380 * atk_object_get_role:
381 * @accessible: a #AtkObject
383 * Gets the role of the accessible
385 * Returns: a #AtkRole which is the role of the accessible
388 atk_object_get_role (AtkObject *accessible) {
389 AtkObjectClass *klass;
391 g_return_val_if_fail (accessible != NULL, ATK_ROLE_UNKNOWN);
392 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
394 klass = ATK_OBJECT_GET_CLASS (accessible);
396 return (klass->get_role) (accessible);
398 return ATK_ROLE_UNKNOWN;
402 * atk_object_ref_state_set:
403 * @accessible: a #AtkObject
405 * Gets a reference to the state set of the accessible; the caller should
408 * Returns: a reference to a #AtkStateSet which is the state set of the accessible
411 atk_object_ref_state_set (AtkObject *accessible) {
412 AtkObjectClass *klass;
414 g_return_val_if_fail (accessible != NULL, NULL);
415 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
417 klass = ATK_OBJECT_GET_CLASS (accessible);
418 if (klass->ref_state_set)
419 return (klass->ref_state_set) (accessible);
425 * atk_object_get_index_in_parent:
426 * @accessible: a #AtkObject
428 * Gets the 0-based index of this accessible in its parent; returns -1 if the
429 * accessible does not have an accessible parent.
431 * Returns: a gint which is the index of the accessible in its parent
434 atk_object_get_index_in_parent (AtkObject *accessible)
436 AtkObjectClass *klass;
438 g_return_val_if_fail (accessible != NULL, -1);
439 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
441 klass = ATK_OBJECT_GET_CLASS (accessible);
442 if (klass->get_index_in_parent)
443 return (klass->get_index_in_parent) (accessible);
449 * atk_object_set_name:
450 * @accessible: a #AtkObject
451 * @name: a character string to be set as the accessible name
453 * Sets the accessible name of the accessible
456 atk_object_set_name (AtkObject *accessible,
459 AtkObjectClass *klass;
461 g_return_if_fail (accessible != NULL);
462 g_return_if_fail (ATK_IS_OBJECT (accessible));
463 g_return_if_fail (name != NULL);
465 klass = ATK_OBJECT_GET_CLASS (accessible);
468 (klass->set_name) (accessible, name);
469 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
474 * atk_object_set_description:
475 * @accessible: a #AtkObject
476 * @description : a character string to be set as the accessible description
478 * Sets the accessible description of the accessible
481 atk_object_set_description (AtkObject *accessible,
482 const gchar *description)
484 AtkObjectClass *klass;
486 g_return_if_fail (accessible != NULL);
487 g_return_if_fail (ATK_IS_OBJECT (accessible));
488 g_return_if_fail (description != NULL);
490 klass = ATK_OBJECT_GET_CLASS (accessible);
491 if (klass->set_description)
493 (klass->set_description) (accessible, description);
494 g_object_notify (G_OBJECT (accessible), atk_object_name_property_description);
499 * atk_object_set_parent:
500 * @accessible: a #AtkObject
501 * @parent : a #AtkObject to be set as the accessible parent
503 * Sets the accessible parent of the accessible
506 atk_object_set_parent (AtkObject *accessible,
509 AtkObjectClass *klass;
511 g_return_if_fail (accessible != NULL);
512 g_return_if_fail (ATK_IS_OBJECT (accessible));
514 klass = ATK_OBJECT_GET_CLASS (accessible);
515 if (klass->set_parent)
516 (klass->set_parent) (accessible, parent);
520 * atk_object_set_role:
521 * @accessible: a #AtkObject
522 * @role : a #AtkRole to be set as the role
524 * Sets the role of the accessible
527 atk_object_set_role (AtkObject *accessible,
530 AtkObjectClass *klass;
532 g_return_if_fail (accessible != NULL);
533 g_return_if_fail (ATK_IS_OBJECT (accessible));
535 klass = ATK_OBJECT_GET_CLASS (accessible);
537 (klass->set_role) (accessible, role);
541 * atk_object_connect_property_change_handler:
542 * @accessible: a #AtkObject
543 * @handler : a #AtkPropertyChangeHandler, a function to be called when a property changes its value
545 * Specifies a function to be called when a property changes value.
547 * Returns: a guint which is the handler id used in atk_object_remove_property_change_handler
550 atk_object_connect_property_change_handler (AtkObject *accessible,
551 AtkPropertyChangeHandler *handler)
553 AtkObjectClass *klass;
555 g_return_val_if_fail (accessible != NULL, 0);
556 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
557 g_return_val_if_fail ((handler != NULL), 0);
559 klass = ATK_OBJECT_GET_CLASS (accessible);
560 if (klass->connect_property_change_handler)
561 return (klass->connect_property_change_handler) (accessible, handler);
567 * atk_object_remove_property_change_handler:
568 * @accessible: a #AtkObject
569 * @handler_id : a guint which identifies the handler to be removed.
571 * Removes a property change handler.
574 atk_object_remove_property_change_handler (AtkObject *accessible,
577 AtkObjectClass *klass;
579 g_return_if_fail (accessible != NULL);
580 g_return_if_fail (ATK_IS_OBJECT (accessible));
582 klass = ATK_OBJECT_GET_CLASS (accessible);
583 if (klass->remove_property_change_handler)
584 (klass->remove_property_change_handler) (accessible, handler_id);
588 * atk_implementor_ref_accessible:
589 * @implementor: The GObject instance which should implement #AtkImplementorIface
590 * if a non-null return value is required.
592 * Returns a reference to an object's #AtkObject implementation, if
593 * the object implements #AtkObjectIface
595 * Returns: a reference to an object's #AtkObject implementation, if
596 * the object implements #AtkObjectIface
599 atk_implementor_ref_accessible (AtkImplementor *object)
601 AtkImplementorIface *iface;
602 AtkObject *accessible = NULL;
604 g_return_val_if_fail (object != NULL, NULL);
605 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (object), NULL);
607 iface = ATK_IMPLEMENTOR_GET_IFACE (object);
610 accessible = iface->ref_accessible (object);
612 g_return_val_if_fail ((accessible != NULL), NULL);
617 static AtkRelationSet*
618 atk_object_real_ref_relation_set (AtkObject *accessible)
620 if (accessible->relation_set)
621 g_object_ref (accessible->relation_set);
623 return accessible->relation_set;
627 atk_object_real_set_property (GObject *object,
632 AtkObject *accessible;
634 accessible = ATK_OBJECT (object);
639 atk_object_set_name (accessible, g_value_get_string (value));
641 case PROP_DESCRIPTION:
642 atk_object_set_description (accessible, g_value_get_string (value));
645 g_print ("This interface does not support setting the state set of an accessible object\n");
653 atk_object_real_get_property (GObject *object,
658 AtkObject *accessible;
660 accessible = ATK_OBJECT (object);
665 g_value_set_string (value, atk_object_get_name (accessible));
667 case PROP_DESCRIPTION:
668 g_value_set_string (value, atk_object_get_description (accessible));
676 atk_object_finalize (GObject *object)
678 AtkObject *accessible;
680 g_return_if_fail (ATK_IS_OBJECT (object));
682 accessible = ATK_OBJECT (object);
684 g_free (accessible->name);
685 g_free (accessible->description);
688 * Free memory allocated for relation set if it have been allocated.
690 if (accessible->relation_set)
692 g_object_unref (accessible->relation_set);
695 G_OBJECT_CLASS (parent_class)->finalize (object);
699 atk_object_real_set_role (AtkObject *object,
706 atk_object_focus_event_unimplemented (AtkObject *object,
709 g_warning ("AtkObjectClass::focus_event not implemented for `%s'",
710 g_type_name (G_OBJECT_TYPE (object)));