gobject-introspection: fix virtual annotations and missing type descriptions
[atk.git] / atk / atkgobjectaccessible.c
blobd651c4393468553e5d99cf7bbf30ac09a5acf1e3
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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include "config.h"
22 #include <atk/atkgobjectaccessible.h>
23 #include <atk/atkregistry.h>
24 #include <atk/atkutil.h>
26 /**
27 * SECTION:atkgobjectaccessible
28 * @Short_description: This object class is derived from AtkObject and
29 * can be used as a basis implementing accessible objects.
30 * @Title:AtkGObjectAccessible
32 * This object class is derived from AtkObject. It can be used as a
33 * basis for implementing accessible objects for GObjects which are
34 * not derived from GtkWidget. One example of its use is in providing
35 * an accessible object for GnomeCanvasItem in the GAIL library.
37 static void atk_gobject_accessible_class_init (AtkGObjectAccessibleClass *klass);
38 static void atk_real_gobject_accessible_initialize (AtkObject *atk_obj,
39 gpointer data);
40 static void atk_gobject_accessible_object_gone_cb (gpointer data);
42 static GQuark quark_accessible_object = 0;
43 static GQuark quark_object = 0;
44 static gpointer parent_class = NULL;
46 GType
47 atk_gobject_accessible_get_type (void)
49 static GType type = 0;
51 if (!type)
53 static const GTypeInfo tinfo =
55 sizeof (AtkGObjectAccessibleClass),
56 (GBaseInitFunc) NULL, /* base init */
57 (GBaseFinalizeFunc) NULL, /* base finalize */
58 (GClassInitFunc) atk_gobject_accessible_class_init,
59 (GClassFinalizeFunc) NULL, /* class finalize */
60 NULL, /* class data */
61 sizeof (AtkGObjectAccessible),
62 0, /* nb preallocs */
63 (GInstanceInitFunc) NULL, /* instance init */
64 NULL /* value table */
67 type = g_type_register_static (ATK_TYPE_OBJECT,
68 "AtkGObjectAccessible", &tinfo, 0);
71 return type;
74 /**
75 * atk_gobject_accessible_for_object:
76 * @obj: a #GObject
78 * Gets the accessible object for the specified @obj.
80 * Returns: (transfer none): a #AtkObject which is the accessible object for
81 * the @obj
82 **/
83 AtkObject*
84 atk_gobject_accessible_for_object (GObject *obj)
86 AtkObject* accessible;
88 g_return_val_if_fail (G_IS_OBJECT (obj), NULL);
89 /* See if we have a cached accessible for this object */
91 accessible = quark_accessible_object ? g_object_get_qdata (obj, quark_accessible_object) : NULL;
93 if (!accessible)
95 AtkObjectFactory *factory;
96 AtkRegistry *default_registry;
98 default_registry = atk_get_default_registry ();
99 factory = atk_registry_get_factory (default_registry,
100 G_OBJECT_TYPE (obj));
101 accessible = atk_object_factory_create_accessible (factory,
102 obj);
103 if (!ATK_IS_GOBJECT_ACCESSIBLE (accessible))
106 * The AtkObject which was created was not a AtkGObjectAccessible
108 g_object_weak_ref (obj,
109 (GWeakNotify) g_object_unref,
110 accessible);
111 if (!quark_accessible_object)
112 quark_accessible_object = g_quark_from_static_string ("accessible-object");
114 g_object_set_qdata (obj, quark_accessible_object, accessible);
116 return accessible;
120 * atk_gobject_accessible_get_object:
121 * @obj: a #AtkGObjectAccessible
123 * Gets the GObject for which @obj is the accessible object.
125 * Returns: (transfer none): a #GObject which is the object for which @obj is
126 * the accessible object
128 GObject *
129 atk_gobject_accessible_get_object (AtkGObjectAccessible *obj)
131 g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (obj), NULL);
133 return g_object_get_qdata (G_OBJECT (obj), quark_object);
136 static void
137 atk_real_gobject_accessible_initialize (AtkObject *atk_obj,
138 gpointer data)
140 AtkGObjectAccessible *atk_gobj;
142 atk_gobj = ATK_GOBJECT_ACCESSIBLE (atk_obj);
144 g_object_set_qdata (G_OBJECT (atk_gobj), quark_object, data);
145 atk_obj->layer = ATK_LAYER_WIDGET;
147 g_object_weak_ref (data,
148 (GWeakNotify) atk_gobject_accessible_object_gone_cb,
149 atk_gobj);
152 static void
153 atk_gobject_accessible_object_gone_cb (gpointer data)
155 GObject *object;
157 g_return_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (data));
159 object = atk_gobject_accessible_get_object (data);
160 if (object)
161 g_object_set_qdata (object, quark_accessible_object, NULL);
163 g_object_set_qdata (G_OBJECT (data), quark_object, NULL);
164 atk_object_notify_state_change (ATK_OBJECT (data), ATK_STATE_DEFUNCT,
165 TRUE);
166 g_object_unref (data);
169 static void
170 atk_gobject_accessible_dispose (GObject *atk_obj)
172 GObject *obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (atk_obj));
174 if (obj) {
175 g_object_set_qdata (obj, quark_accessible_object, NULL);
176 g_object_weak_unref (obj,
177 (GWeakNotify) atk_gobject_accessible_object_gone_cb,
178 atk_obj);
180 g_object_set_qdata (atk_obj, quark_object, NULL);
181 atk_object_notify_state_change (ATK_OBJECT (atk_obj), ATK_STATE_DEFUNCT,
182 TRUE);
185 G_OBJECT_CLASS (parent_class)->dispose (atk_obj);
188 static void
189 atk_gobject_accessible_class_init (AtkGObjectAccessibleClass *klass)
191 AtkObjectClass *class;
192 GObjectClass *object_class;
194 class = ATK_OBJECT_CLASS (klass);
196 parent_class = g_type_class_peek_parent (klass);
198 class->initialize = atk_real_gobject_accessible_initialize;
200 object_class = G_OBJECT_CLASS (klass);
201 object_class->dispose = atk_gobject_accessible_dispose;
203 if (!quark_accessible_object)
204 quark_accessible_object = g_quark_from_static_string ("accessible-object");
205 quark_object = g_quark_from_static_string ("object-for-accessible");