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 ",
187 g_object_class_install_property (gobject_class,
189 g_param_spec_double (atk_object_name_property_value,
191 "Is used to notify that the value has been changed ",
197 * The signal "children_changed" supports two details:
200 atk_object_signals[CHILDREN_CHANGED] =
201 g_signal_newc ("children_changed",
202 G_TYPE_FROM_CLASS (klass),
203 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
204 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
206 g_cclosure_marshal_VOID__UINT_POINTER,
208 2, G_TYPE_UINT, ATK_TYPE_OBJECT);
209 atk_object_signals[FOCUS_EVENT] =
210 g_signal_newc ("focus_event",
211 G_TYPE_FROM_CLASS (klass),
213 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
215 g_cclosure_marshal_VOID__BOOLEAN,
221 atk_object_init (AtkObject *accessible,
222 AtkObjectClass *klass)
227 atk_implementor_get_type (void)
229 static GType type = 0;
233 static const GTypeInfo typeInfo =
235 sizeof (AtkImplementorIface),
236 (GBaseInitFunc) NULL,
237 (GBaseFinalizeFunc) NULL,
240 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
247 * atk_object_get_name:
248 * @accessible: an #AtkObject
250 * Gets the accessible name of the accessible
252 * Returns: a character string representing the accessible name of the object.
254 G_CONST_RETURN gchar*
255 atk_object_get_name (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);
264 return (klass->get_name) (accessible);
270 * atk_object_get_description:
271 * @accessible: an #AtkObject
273 * Gets the accessible description of the accessible
275 * Returns: a character string representing the accessible description
279 G_CONST_RETURN gchar*
280 atk_object_get_description (AtkObject *accessible)
282 AtkObjectClass *klass;
284 g_return_val_if_fail (accessible != NULL, NULL);
285 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
287 klass = ATK_OBJECT_GET_CLASS (accessible);
288 if (klass->get_description)
289 return (klass->get_description) (accessible);
295 * atk_object_get_parent:
296 * @accessible: an #AtkObject
298 * Gets the accessible parent of the accessible
300 * Returns: a #AtkObject representing the accessible parent of the accessible
303 atk_object_get_parent (AtkObject *accessible)
305 AtkObjectClass *klass;
307 g_return_val_if_fail (accessible != NULL, NULL);
308 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
310 klass = ATK_OBJECT_GET_CLASS (accessible);
311 if (klass->get_parent)
312 return (klass->get_parent) (accessible);
318 * atk_object_get_n_accessible_children:
319 * @accessible: an #AtkObject
321 * Gets the number of accessible children of the accessible
323 * Returns: an integer representing the number of accessible children
327 atk_object_get_n_accessible_children (AtkObject *accessible)
329 AtkObjectClass *klass;
331 g_return_val_if_fail (accessible != NULL, 0);
332 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
334 klass = ATK_OBJECT_GET_CLASS (accessible);
335 if (klass->get_n_children)
336 return (klass->get_n_children) (accessible);
342 * atk_object_ref_accessible_child:
343 * @accessible: an #AtkObject
344 * @i: a gint representing the position of the child, starting from 0
346 * Gets a reference to the specified accessible child of the object.
347 * The accessible children are 0-based so the first accessible child is
348 * at index 0, the second at index 1 and so on.
350 * Returns: an #AtkObject representing the specified accessible child
354 atk_object_ref_accessible_child (AtkObject *accessible,
357 AtkObjectClass *klass;
359 g_return_val_if_fail (accessible != NULL, NULL);
360 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
362 klass = ATK_OBJECT_GET_CLASS (accessible);
363 if (klass->ref_child)
364 return (klass->ref_child) (accessible, i);
370 * atk_object_ref_relation_set:
371 * @accessible: an #AtkObject
373 * Gets the RelationSet associated with the object
375 * Returns: an #AtkRelationSet representing the relation set of the object.
378 atk_object_ref_relation_set (AtkObject *accessible)
380 AtkObjectClass *klass;
382 g_return_val_if_fail (accessible != NULL, NULL);
383 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
385 klass = ATK_OBJECT_GET_CLASS (accessible);
386 if (klass->ref_relation_set)
387 return (klass->ref_relation_set) (accessible);
394 * @name: a character string describing the new role.
396 * Returns: an #AtkRole for the new role.
399 atk_role_register (const gchar *name)
401 /* TODO: associate name with new type */
402 static guint type = ATK_ROLE_LAST_DEFINED;
407 * atk_object_get_role:
408 * @accessible: an #AtkObject
410 * Gets the role of the accessible
412 * Returns: an #AtkRole which is the role of the accessible
415 atk_object_get_role (AtkObject *accessible) {
416 AtkObjectClass *klass;
418 g_return_val_if_fail (accessible != NULL, ATK_ROLE_UNKNOWN);
419 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
421 klass = ATK_OBJECT_GET_CLASS (accessible);
423 return (klass->get_role) (accessible);
425 return ATK_ROLE_UNKNOWN;
429 * atk_object_ref_state_set:
430 * @accessible: an #AtkObject
432 * Gets a reference to the state set of the accessible; the caller should
435 * Returns: a reference to an #AtkStateSet which is the state
436 * set of the accessible
439 atk_object_ref_state_set (AtkObject *accessible) {
440 AtkObjectClass *klass;
442 g_return_val_if_fail (accessible != NULL, NULL);
443 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
445 klass = ATK_OBJECT_GET_CLASS (accessible);
446 if (klass->ref_state_set)
447 return (klass->ref_state_set) (accessible);
453 * atk_object_get_index_in_parent:
454 * @accessible: an #AtkObject
456 * Gets the 0-based index of this accessible in its parent; returns -1 if the
457 * accessible does not have an accessible parent.
459 * Returns: an integer which is the index of the accessible in its parent
462 atk_object_get_index_in_parent (AtkObject *accessible)
464 AtkObjectClass *klass;
466 g_return_val_if_fail (accessible != NULL, -1);
467 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
469 klass = ATK_OBJECT_GET_CLASS (accessible);
470 if (klass->get_index_in_parent)
471 return (klass->get_index_in_parent) (accessible);
477 * atk_object_set_name:
478 * @accessible: an #AtkObject
479 * @name: a character string to be set as the accessible name
481 * Sets the accessible name of the accessible
484 atk_object_set_name (AtkObject *accessible,
487 AtkObjectClass *klass;
489 g_return_if_fail (accessible != NULL);
490 g_return_if_fail (ATK_IS_OBJECT (accessible));
491 g_return_if_fail (name != NULL);
493 klass = ATK_OBJECT_GET_CLASS (accessible);
496 (klass->set_name) (accessible, name);
497 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
502 * atk_object_set_description:
503 * @accessible: an #AtkObject
504 * @description : a character string to be set as the accessible description
506 * Sets the accessible description of the accessible
509 atk_object_set_description (AtkObject *accessible,
510 const gchar *description)
512 AtkObjectClass *klass;
514 g_return_if_fail (accessible != NULL);
515 g_return_if_fail (ATK_IS_OBJECT (accessible));
516 g_return_if_fail (description != NULL);
518 klass = ATK_OBJECT_GET_CLASS (accessible);
519 if (klass->set_description)
521 (klass->set_description) (accessible, description);
522 g_object_notify (G_OBJECT (accessible), atk_object_name_property_description);
527 * atk_object_set_parent:
528 * @accessible: an #AtkObject
529 * @parent : an #AtkObject to be set as the accessible parent
531 * Sets the accessible parent of the accessible
534 atk_object_set_parent (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->set_parent)
544 (klass->set_parent) (accessible, parent);
548 * atk_object_set_role:
549 * @accessible: an #AtkObject
550 * @role : an #AtkRole to be set as the role
552 * Sets the role of the accessible
555 atk_object_set_role (AtkObject *accessible,
558 AtkObjectClass *klass;
560 g_return_if_fail (accessible != NULL);
561 g_return_if_fail (ATK_IS_OBJECT (accessible));
563 klass = ATK_OBJECT_GET_CLASS (accessible);
565 (klass->set_role) (accessible, role);
569 * atk_object_connect_property_change_handler:
570 * @accessible: an #AtkObject
571 * @handler : a function to be called when a property changes its value
573 * Specifies a function to be called when a property changes value.
575 * Returns: a #guint which is the handler id used in
576 * atk_object_remove_property_change_handler()
579 atk_object_connect_property_change_handler (AtkObject *accessible,
580 AtkPropertyChangeHandler *handler)
582 AtkObjectClass *klass;
584 g_return_val_if_fail (accessible != NULL, 0);
585 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
586 g_return_val_if_fail ((handler != NULL), 0);
588 klass = ATK_OBJECT_GET_CLASS (accessible);
589 if (klass->connect_property_change_handler)
590 return (klass->connect_property_change_handler) (accessible, handler);
596 * atk_object_remove_property_change_handler:
597 * @accessible: an #AtkObject
598 * @handler_id : a guint which identifies the handler to be removed.
600 * Removes a property change handler.
603 atk_object_remove_property_change_handler (AtkObject *accessible,
606 AtkObjectClass *klass;
608 g_return_if_fail (accessible != NULL);
609 g_return_if_fail (ATK_IS_OBJECT (accessible));
611 klass = ATK_OBJECT_GET_CLASS (accessible);
612 if (klass->remove_property_change_handler)
613 (klass->remove_property_change_handler) (accessible, handler_id);
617 * atk_implementor_ref_accessible:
618 * @implementor: The #GObject instance which should implement #AtkImplementorIface
619 * if a non-null return value is required.
621 * Gets a reference to an object's #AtkObject implementation, if
622 * the object implements #AtkObjectIface
624 * Returns: a reference to an object's #AtkObject implementation
627 atk_implementor_ref_accessible (AtkImplementor *object)
629 AtkImplementorIface *iface;
630 AtkObject *accessible = NULL;
632 g_return_val_if_fail (object != NULL, NULL);
633 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (object), NULL);
635 iface = ATK_IMPLEMENTOR_GET_IFACE (object);
638 accessible = iface->ref_accessible (object);
640 g_return_val_if_fail ((accessible != NULL), NULL);
645 static AtkRelationSet*
646 atk_object_real_ref_relation_set (AtkObject *accessible)
648 if (accessible->relation_set)
649 g_object_ref (accessible->relation_set);
651 return accessible->relation_set;
655 atk_object_real_set_property (GObject *object,
660 AtkObject *accessible;
662 accessible = ATK_OBJECT (object);
667 atk_object_set_name (accessible, g_value_get_string (value));
669 case PROP_DESCRIPTION:
670 atk_object_set_description (accessible, g_value_get_string (value));
673 g_print ("This interface does not support setting the state set of an accessible object\n");
676 if (ATK_IS_VALUE (accessible))
677 atk_value_set_current_value (ATK_VALUE (accessible), value);
685 atk_object_real_get_property (GObject *object,
690 AtkObject *accessible;
692 accessible = ATK_OBJECT (object);
697 g_value_set_string (value, atk_object_get_name (accessible));
699 case PROP_DESCRIPTION:
700 g_value_set_string (value, atk_object_get_description (accessible));
703 if (ATK_IS_VALUE (accessible))
704 atk_value_get_current_value (ATK_VALUE (accessible), value);
712 atk_object_finalize (GObject *object)
714 AtkObject *accessible;
716 g_return_if_fail (ATK_IS_OBJECT (object));
718 accessible = ATK_OBJECT (object);
720 g_free (accessible->name);
721 g_free (accessible->description);
724 * Free memory allocated for relation set if it have been allocated.
726 if (accessible->relation_set)
728 g_object_unref (accessible->relation_set);
731 G_OBJECT_CLASS (parent_class)->finalize (object);
735 atk_object_real_set_role (AtkObject *object,