1 /* ATK - Accessibility Toolkit
2 * Copyright 2001, 2002, 2003 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, see <http://www.gnu.org/licenses/>.
18 #include <atk/atkgobjectaccessible.h>
19 #include <atk/atkregistry.h>
20 #include <atk/atkutil.h>
23 * SECTION:atkgobjectaccessible
24 * @Short_description: This object class is derived from AtkObject and
25 * can be used as a basis implementing accessible objects.
26 * @Title:AtkGObjectAccessible
28 * This object class is derived from AtkObject. It can be used as a
29 * basis for implementing accessible objects for GObjects which are
30 * not derived from GtkWidget. One example of its use is in providing
31 * an accessible object for GnomeCanvasItem in the GAIL library.
33 static void atk_gobject_accessible_class_init (AtkGObjectAccessibleClass *klass);
34 static void atk_real_gobject_accessible_initialize (AtkObject *atk_obj,
36 static void atk_gobject_accessible_dispose (gpointer data);
38 static GQuark quark_accessible_object = 0;
39 static GQuark quark_object = 0;
40 static gpointer parent_class = NULL;
43 atk_gobject_accessible_get_type (void)
45 static GType type = 0;
49 static const GTypeInfo tinfo =
51 sizeof (AtkGObjectAccessibleClass),
52 (GBaseInitFunc) NULL, /* base init */
53 (GBaseFinalizeFunc) NULL, /* base finalize */
54 (GClassInitFunc) atk_gobject_accessible_class_init,
55 (GClassFinalizeFunc) NULL, /* class finalize */
56 NULL, /* class data */
57 sizeof (AtkGObjectAccessible),
59 (GInstanceInitFunc) NULL, /* instance init */
60 NULL /* value table */
63 type = g_type_register_static (ATK_TYPE_OBJECT,
64 "AtkGObjectAccessible", &tinfo, 0);
71 * atk_gobject_accessible_for_object:
74 * Gets the accessible object for the specified @obj.
76 * Returns: (transfer none): a #AtkObject which is the accessible object for
80 atk_gobject_accessible_for_object (GObject *obj)
82 AtkObject* accessible;
84 g_return_val_if_fail (G_IS_OBJECT (obj), NULL);
85 /* See if we have a cached accessible for this object */
87 accessible = g_object_get_qdata (obj,
88 quark_accessible_object);
92 AtkObjectFactory *factory;
93 AtkRegistry *default_registry;
95 default_registry = atk_get_default_registry ();
96 factory = atk_registry_get_factory (default_registry,
98 accessible = atk_object_factory_create_accessible (factory,
100 if (!ATK_IS_GOBJECT_ACCESSIBLE (accessible))
103 * The AtkObject which was created was not a AtkGObjectAccessible
105 g_object_weak_ref (obj,
106 (GWeakNotify) g_object_unref,
108 if (!quark_accessible_object)
109 quark_accessible_object = g_quark_from_static_string ("accessible-object");
111 g_object_set_qdata (obj, quark_accessible_object, accessible);
117 * atk_gobject_accessible_get_object:
118 * @obj: a #AtkGObjectAccessible
120 * Gets the GObject for which @obj is the accessible object.
122 * Returns: (transfer none): a #GObject which is the object for which @obj is
123 * the accessible object
126 atk_gobject_accessible_get_object (AtkGObjectAccessible *obj)
128 g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (obj), NULL);
130 return g_object_get_qdata (G_OBJECT (obj), quark_object);
134 atk_real_gobject_accessible_initialize (AtkObject *atk_obj,
137 AtkGObjectAccessible *atk_gobj;
139 atk_gobj = ATK_GOBJECT_ACCESSIBLE (atk_obj);
141 g_object_set_qdata (G_OBJECT (atk_gobj), quark_object, data);
142 atk_obj->layer = ATK_LAYER_WIDGET;
144 g_object_weak_ref (data,
145 (GWeakNotify) atk_gobject_accessible_dispose,
150 atk_gobject_accessible_dispose (gpointer data)
154 g_return_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (data));
156 object = atk_gobject_accessible_get_object (data);
158 g_object_set_qdata (object, quark_accessible_object, NULL);
160 g_object_set_qdata (G_OBJECT (data), quark_object, NULL);
161 atk_object_notify_state_change (ATK_OBJECT (data), ATK_STATE_DEFUNCT,
163 g_object_unref (data);
167 atk_gobject_accessible_class_init (AtkGObjectAccessibleClass *klass)
169 AtkObjectClass *class;
171 class = ATK_OBJECT_CLASS (klass);
173 parent_class = g_type_class_peek_parent (klass);
175 class->initialize = atk_real_gobject_accessible_initialize;
177 if (!quark_accessible_object)
178 quark_accessible_object = g_quark_from_static_string ("accessible-object");
179 quark_object = g_quark_from_static_string ("object-for-accessible");