Bug 640574: gobject-introspection annotation and documentation fixes
[atk.git] / atk / atkgobjectaccessible.c
blobe9ba0f3f57a7d57f5bf1b6fa04cf858568e487e3
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 <atk/atkgobjectaccessible.h>
22 static void atk_gobject_accessible_class_init (AtkGObjectAccessibleClass *klass);
23 static void atk_real_gobject_accessible_initialize (AtkObject *atk_obj,
24 gpointer data);
25 static void atk_gobject_accessible_dispose (gpointer data);
27 static GQuark quark_accessible_object = 0;
28 static GQuark quark_object = 0;
29 static gpointer parent_class = NULL;
31 GType
32 atk_gobject_accessible_get_type (void)
34 static GType type = 0;
36 if (!type)
38 static const GTypeInfo tinfo =
40 sizeof (AtkGObjectAccessibleClass),
41 (GBaseInitFunc) NULL, /* base init */
42 (GBaseFinalizeFunc) NULL, /* base finalize */
43 (GClassInitFunc) atk_gobject_accessible_class_init,
44 (GClassFinalizeFunc) NULL, /* class finalize */
45 NULL, /* class data */
46 sizeof (AtkGObjectAccessible),
47 0, /* nb preallocs */
48 (GInstanceInitFunc) NULL, /* instance init */
49 NULL /* value table */
52 type = g_type_register_static (ATK_TYPE_OBJECT,
53 "AtkGObjectAccessible", &tinfo, 0);
56 return type;
59 /**
60 * atk_gobject_accessible_for_object:
61 * @obj: a #GObject
63 * Gets the accessible object for the specified @obj.
65 * Returns: (transfer none): a #AtkObject which is the accessible object for
66 * the @obj
67 **/
68 AtkObject*
69 atk_gobject_accessible_for_object (GObject *obj)
71 AtkObject* accessible;
73 g_return_val_if_fail (G_IS_OBJECT (obj), NULL);
74 /* See if we have a cached accessible for this object */
76 accessible = g_object_get_qdata (obj,
77 quark_accessible_object);
79 if (!accessible)
81 AtkObjectFactory *factory;
82 AtkRegistry *default_registry;
84 default_registry = atk_get_default_registry ();
85 factory = atk_registry_get_factory (default_registry,
86 G_OBJECT_TYPE (obj));
87 accessible = atk_object_factory_create_accessible (factory,
88 obj);
89 if (!ATK_IS_GOBJECT_ACCESSIBLE (accessible))
92 * The AtkObject which was created was not a AtkGObjectAccessible
94 g_object_weak_ref (obj,
95 (GWeakNotify) g_object_unref,
96 accessible);
97 if (!quark_accessible_object)
98 quark_accessible_object = g_quark_from_static_string ("accessible-object");
100 g_object_set_qdata (obj, quark_accessible_object, accessible);
102 return accessible;
106 * atk_gobject_accessible_get_object:
107 * @obj: a #AtkGObjectAccessible
109 * Gets the GObject for which @obj is the accessible object.
111 * Returns: (transfer none): a #GObject which is the object for which @obj is
112 * the accessible object
114 GObject *
115 atk_gobject_accessible_get_object (AtkGObjectAccessible *obj)
117 g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (obj), NULL);
119 return g_object_get_qdata (G_OBJECT (obj), quark_object);
122 static void
123 atk_real_gobject_accessible_initialize (AtkObject *atk_obj,
124 gpointer data)
126 AtkGObjectAccessible *atk_gobj;
128 atk_gobj = ATK_GOBJECT_ACCESSIBLE (atk_obj);
130 g_object_set_qdata (G_OBJECT (atk_gobj), quark_object, data);
131 atk_obj->layer = ATK_LAYER_WIDGET;
133 g_object_weak_ref (data,
134 (GWeakNotify) atk_gobject_accessible_dispose,
135 atk_gobj);
138 static void
139 atk_gobject_accessible_dispose (gpointer data)
141 g_return_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (data));
143 g_object_set_qdata (G_OBJECT (data), quark_object, NULL);
144 atk_object_notify_state_change (ATK_OBJECT (data), ATK_STATE_DEFUNCT,
145 TRUE);
146 g_object_unref (data);
149 static void
150 atk_gobject_accessible_class_init (AtkGObjectAccessibleClass *klass)
152 AtkObjectClass *class;
154 class = ATK_OBJECT_CLASS (klass);
156 parent_class = g_type_class_peek_parent (klass);
158 class->initialize = atk_real_gobject_accessible_initialize;
160 if (!quark_accessible_object)
161 quark_accessible_object = g_quark_from_static_string ("accessible-object");
162 quark_object = g_quark_from_static_string ("object-for-accessible");