Visual Studio builds: Support Visual Studio 2017
[atk.git] / atk / atkgobjectaccessible.c
blob83cb45ebf9db85d4abf51cc1dc1a655385c06517
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_dispose (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 = g_object_get_qdata (obj,
92 quark_accessible_object);
94 if (!accessible)
96 AtkObjectFactory *factory;
97 AtkRegistry *default_registry;
99 default_registry = atk_get_default_registry ();
100 factory = atk_registry_get_factory (default_registry,
101 G_OBJECT_TYPE (obj));
102 accessible = atk_object_factory_create_accessible (factory,
103 obj);
104 if (!ATK_IS_GOBJECT_ACCESSIBLE (accessible))
107 * The AtkObject which was created was not a AtkGObjectAccessible
109 g_object_weak_ref (obj,
110 (GWeakNotify) g_object_unref,
111 accessible);
112 if (!quark_accessible_object)
113 quark_accessible_object = g_quark_from_static_string ("accessible-object");
115 g_object_set_qdata (obj, quark_accessible_object, accessible);
117 return accessible;
121 * atk_gobject_accessible_get_object:
122 * @obj: a #AtkGObjectAccessible
124 * Gets the GObject for which @obj is the accessible object.
126 * Returns: (transfer none): a #GObject which is the object for which @obj is
127 * the accessible object
129 GObject *
130 atk_gobject_accessible_get_object (AtkGObjectAccessible *obj)
132 g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (obj), NULL);
134 return g_object_get_qdata (G_OBJECT (obj), quark_object);
137 static void
138 atk_real_gobject_accessible_initialize (AtkObject *atk_obj,
139 gpointer data)
141 AtkGObjectAccessible *atk_gobj;
143 atk_gobj = ATK_GOBJECT_ACCESSIBLE (atk_obj);
145 g_object_set_qdata (G_OBJECT (atk_gobj), quark_object, data);
146 atk_obj->layer = ATK_LAYER_WIDGET;
148 g_object_weak_ref (data,
149 (GWeakNotify) atk_gobject_accessible_dispose,
150 atk_gobj);
153 static void
154 atk_gobject_accessible_dispose (gpointer data)
156 GObject *object;
158 g_return_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (data));
160 object = atk_gobject_accessible_get_object (data);
161 if (object)
162 g_object_set_qdata (object, quark_accessible_object, NULL);
164 g_object_set_qdata (G_OBJECT (data), quark_object, NULL);
165 atk_object_notify_state_change (ATK_OBJECT (data), ATK_STATE_DEFUNCT,
166 TRUE);
167 g_object_unref (data);
170 static void
171 atk_gobject_accessible_class_init (AtkGObjectAccessibleClass *klass)
173 AtkObjectClass *class;
175 class = ATK_OBJECT_CLASS (klass);
177 parent_class = g_type_class_peek_parent (klass);
179 class->initialize = atk_real_gobject_accessible_initialize;
181 if (!quark_accessible_object)
182 quark_accessible_object = g_quark_from_static_string ("accessible-object");
183 quark_object = g_quark_from_static_string ("object-for-accessible");