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,
64 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";
71 static const gchar* atk_object_name_property_child = "accessible-child";
72 static const gchar* atk_object_name_property_parent = "accessible-parent";
75 atk_object_get_type (void)
77 static GType type = 0;
81 static const GTypeInfo typeInfo =
83 sizeof (AtkObjectClass),
85 (GBaseFinalizeFunc) NULL,
86 (GClassInitFunc) atk_object_class_init,
87 (GClassFinalizeFunc) NULL,
91 (GInstanceInitFunc) atk_object_init,
93 type = g_type_register_static (G_TYPE_OBJECT, "AtkObject", &typeInfo, 0) ;
99 atk_object_class_init (AtkObjectClass *klass)
101 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
103 parent_class = g_type_class_ref (G_TYPE_OBJECT);
105 gobject_class->set_property = atk_object_real_set_property;
106 gobject_class->get_property = atk_object_real_get_property;
107 gobject_class->finalize = atk_object_finalize;
109 klass->ref_relation_set = atk_object_real_ref_relation_set;
110 klass->set_role = atk_object_real_set_role;
113 * We do not define default signal handlers here
115 klass->focus_event = NULL;
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",
172 * The signal "children_changed" supports two details:
175 atk_object_signals[CHILDREN_CHANGED] =
176 g_signal_newc ("children_changed",
177 G_TYPE_FROM_CLASS (klass),
178 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
179 G_STRUCT_OFFSET (AtkObjectClass, children_changed),
181 g_cclosure_marshal_VOID__UINT_POINTER,
183 2, G_TYPE_UINT, ATK_TYPE_OBJECT);
184 atk_object_signals[FOCUS_EVENT] =
185 g_signal_newc ("focus_event",
186 G_TYPE_FROM_CLASS (klass),
188 G_STRUCT_OFFSET (AtkObjectClass, focus_event),
190 g_cclosure_marshal_VOID__BOOLEAN,
196 atk_object_init (AtkObject *accessible,
197 AtkObjectClass *klass)
202 atk_implementor_get_type (void)
204 static GType type = 0;
208 static const GTypeInfo typeInfo =
210 sizeof (AtkImplementorIface),
211 (GBaseInitFunc) NULL,
212 (GBaseFinalizeFunc) NULL,
215 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImplementorIface", &typeInfo, 0) ;
222 * atk_object_get_name:
223 * @accessible: an #AtkObject
225 * Gets the accessible name of the accessible
227 * Returns: a character string representing the accessible name of the object.
229 G_CONST_RETURN gchar*
230 atk_object_get_name (AtkObject *accessible)
232 AtkObjectClass *klass;
234 g_return_val_if_fail (accessible != NULL, NULL);
235 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
237 klass = ATK_OBJECT_GET_CLASS (accessible);
239 return (klass->get_name) (accessible);
245 * atk_object_get_description:
246 * @accessible: an #AtkObject
248 * Gets the accessible description of the accessible
250 * Returns: a character string representing the accessible description
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: an #AtkObject
273 * Gets the accessible parent 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: an #AtkObject
296 * Gets the number of accessible children of the accessible
298 * Returns: an integer representing the number of accessible children
302 atk_object_get_n_accessible_children (AtkObject *accessible)
304 AtkObjectClass *klass;
306 g_return_val_if_fail (accessible != NULL, 0);
307 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
309 klass = ATK_OBJECT_GET_CLASS (accessible);
310 if (klass->get_n_children)
311 return (klass->get_n_children) (accessible);
317 * atk_object_ref_accessible_child:
318 * @accessible: an #AtkObject
319 * @i: a gint representing the position of the child, starting from 0
321 * Gets a reference to the specified accessible child of the object.
322 * The accessible children are 0-based so the first accessible child is
323 * at index 0, the second at index 1 and so on.
325 * Returns: an #AtkObject representing the specified accessible child
329 atk_object_ref_accessible_child (AtkObject *accessible,
332 AtkObjectClass *klass;
334 g_return_val_if_fail (accessible != NULL, NULL);
335 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
337 klass = ATK_OBJECT_GET_CLASS (accessible);
338 if (klass->ref_child)
339 return (klass->ref_child) (accessible, i);
345 * atk_object_ref_relation_set:
346 * @accessible: an #AtkObject
348 * Gets the RelationSet associated with the object
350 * Returns: an #AtkRelationSet representing the relation set of the object.
353 atk_object_ref_relation_set (AtkObject *accessible)
355 AtkObjectClass *klass;
357 g_return_val_if_fail (accessible != NULL, NULL);
358 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
360 klass = ATK_OBJECT_GET_CLASS (accessible);
361 if (klass->ref_relation_set)
362 return (klass->ref_relation_set) (accessible);
369 * @name: a character string describing the new role.
371 * Returns: an #AtkRole for the new role.
374 atk_role_register (const gchar *name)
376 /* TODO: associate name with new type */
377 static guint type = ATK_ROLE_LAST_DEFINED;
382 * atk_object_get_role:
383 * @accessible: an #AtkObject
385 * Gets the role of the accessible
387 * Returns: an #AtkRole which is the role of the accessible
390 atk_object_get_role (AtkObject *accessible) {
391 AtkObjectClass *klass;
393 g_return_val_if_fail (accessible != NULL, ATK_ROLE_UNKNOWN);
394 g_return_val_if_fail (ATK_IS_OBJECT (accessible), ATK_ROLE_UNKNOWN);
396 klass = ATK_OBJECT_GET_CLASS (accessible);
398 return (klass->get_role) (accessible);
400 return ATK_ROLE_UNKNOWN;
404 * atk_object_ref_state_set:
405 * @accessible: an #AtkObject
407 * Gets a reference to the state set of the accessible; the caller should
410 * Returns: a reference to an #AtkStateSet which is the state
411 * set of the accessible
414 atk_object_ref_state_set (AtkObject *accessible) {
415 AtkObjectClass *klass;
417 g_return_val_if_fail (accessible != NULL, NULL);
418 g_return_val_if_fail (ATK_IS_OBJECT (accessible), NULL);
420 klass = ATK_OBJECT_GET_CLASS (accessible);
421 if (klass->ref_state_set)
422 return (klass->ref_state_set) (accessible);
428 * atk_object_get_index_in_parent:
429 * @accessible: an #AtkObject
431 * Gets the 0-based index of this accessible in its parent; returns -1 if the
432 * accessible does not have an accessible parent.
434 * Returns: an integer which is the index of the accessible in its parent
437 atk_object_get_index_in_parent (AtkObject *accessible)
439 AtkObjectClass *klass;
441 g_return_val_if_fail (accessible != NULL, -1);
442 g_return_val_if_fail (ATK_OBJECT (accessible), -1);
444 klass = ATK_OBJECT_GET_CLASS (accessible);
445 if (klass->get_index_in_parent)
446 return (klass->get_index_in_parent) (accessible);
452 * atk_object_set_name:
453 * @accessible: an #AtkObject
454 * @name: a character string to be set as the accessible name
456 * Sets the accessible name of the accessible
459 atk_object_set_name (AtkObject *accessible,
462 AtkObjectClass *klass;
464 g_return_if_fail (accessible != NULL);
465 g_return_if_fail (ATK_IS_OBJECT (accessible));
466 g_return_if_fail (name != NULL);
468 klass = ATK_OBJECT_GET_CLASS (accessible);
471 (klass->set_name) (accessible, name);
472 g_object_notify (G_OBJECT (accessible), atk_object_name_property_name);
477 * atk_object_set_description:
478 * @accessible: an #AtkObject
479 * @description : a character string to be set as the accessible description
481 * Sets the accessible description of the accessible
484 atk_object_set_description (AtkObject *accessible,
485 const gchar *description)
487 AtkObjectClass *klass;
489 g_return_if_fail (accessible != NULL);
490 g_return_if_fail (ATK_IS_OBJECT (accessible));
491 g_return_if_fail (description != NULL);
493 klass = ATK_OBJECT_GET_CLASS (accessible);
494 if (klass->set_description)
496 (klass->set_description) (accessible, description);
497 g_object_notify (G_OBJECT (accessible), atk_object_name_property_description);
502 * atk_object_set_parent:
503 * @accessible: an #AtkObject
504 * @parent : an #AtkObject to be set as the accessible parent
506 * Sets the accessible parent of the accessible
509 atk_object_set_parent (AtkObject *accessible,
512 AtkObjectClass *klass;
514 g_return_if_fail (accessible != NULL);
515 g_return_if_fail (ATK_IS_OBJECT (accessible));
517 klass = ATK_OBJECT_GET_CLASS (accessible);
518 if (klass->set_parent)
519 (klass->set_parent) (accessible, parent);
523 * atk_object_set_role:
524 * @accessible: an #AtkObject
525 * @role : an #AtkRole to be set as the role
527 * Sets the role of the accessible
530 atk_object_set_role (AtkObject *accessible,
533 AtkObjectClass *klass;
535 g_return_if_fail (accessible != NULL);
536 g_return_if_fail (ATK_IS_OBJECT (accessible));
538 klass = ATK_OBJECT_GET_CLASS (accessible);
540 (klass->set_role) (accessible, role);
544 * atk_object_connect_property_change_handler:
545 * @accessible: an #AtkObject
546 * @handler : a function to be called when a property changes its value
548 * Specifies a function to be called when a property changes value.
550 * Returns: a #guint which is the handler id used in
551 * atk_object_remove_property_change_handler()
554 atk_object_connect_property_change_handler (AtkObject *accessible,
555 AtkPropertyChangeHandler *handler)
557 AtkObjectClass *klass;
559 g_return_val_if_fail (accessible != NULL, 0);
560 g_return_val_if_fail (ATK_IS_OBJECT (accessible), 0);
561 g_return_val_if_fail ((handler != NULL), 0);
563 klass = ATK_OBJECT_GET_CLASS (accessible);
564 if (klass->connect_property_change_handler)
565 return (klass->connect_property_change_handler) (accessible, handler);
571 * atk_object_remove_property_change_handler:
572 * @accessible: an #AtkObject
573 * @handler_id : a guint which identifies the handler to be removed.
575 * Removes a property change handler.
578 atk_object_remove_property_change_handler (AtkObject *accessible,
581 AtkObjectClass *klass;
583 g_return_if_fail (accessible != NULL);
584 g_return_if_fail (ATK_IS_OBJECT (accessible));
586 klass = ATK_OBJECT_GET_CLASS (accessible);
587 if (klass->remove_property_change_handler)
588 (klass->remove_property_change_handler) (accessible, handler_id);
592 * atk_implementor_ref_accessible:
593 * @implementor: The #GObject instance which should implement #AtkImplementorIface
594 * if a non-null return value is required.
596 * Gets a reference to an object's #AtkObject implementation, if
597 * the object implements #AtkObjectIface
599 * Returns: a reference to an object's #AtkObject implementation
602 atk_implementor_ref_accessible (AtkImplementor *object)
604 AtkImplementorIface *iface;
605 AtkObject *accessible = NULL;
607 g_return_val_if_fail (object != NULL, NULL);
608 g_return_val_if_fail (ATK_IS_IMPLEMENTOR (object), NULL);
610 iface = ATK_IMPLEMENTOR_GET_IFACE (object);
613 accessible = iface->ref_accessible (object);
615 g_return_val_if_fail ((accessible != NULL), NULL);
620 static AtkRelationSet*
621 atk_object_real_ref_relation_set (AtkObject *accessible)
623 if (accessible->relation_set)
624 g_object_ref (accessible->relation_set);
626 return accessible->relation_set;
630 atk_object_real_set_property (GObject *object,
635 AtkObject *accessible;
637 accessible = ATK_OBJECT (object);
642 atk_object_set_name (accessible, g_value_get_string (value));
644 case PROP_DESCRIPTION:
645 atk_object_set_description (accessible, g_value_get_string (value));
648 g_print ("This interface does not support setting the state set of an accessible object\n");
656 atk_object_real_get_property (GObject *object,
661 AtkObject *accessible;
663 accessible = ATK_OBJECT (object);
668 g_value_set_string (value, atk_object_get_name (accessible));
670 case PROP_DESCRIPTION:
671 g_value_set_string (value, atk_object_get_description (accessible));
679 atk_object_finalize (GObject *object)
681 AtkObject *accessible;
683 g_return_if_fail (ATK_IS_OBJECT (object));
685 accessible = ATK_OBJECT (object);
687 g_free (accessible->name);
688 g_free (accessible->description);
691 * Free memory allocated for relation set if it have been allocated.
693 if (accessible->relation_set)
695 g_object_unref (accessible->relation_set);
698 G_OBJECT_CLASS (parent_class)->finalize (object);
702 atk_object_real_set_role (AtkObject *object,