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.
22 #include <atk/atkgobjectaccessible.h>
23 #include <atk/atkregistry.h>
24 #include <atk/atkutil.h>
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
,
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
;
47 atk_gobject_accessible_get_type (void)
49 static GType type
= 0;
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
),
63 (GInstanceInitFunc
) NULL
, /* instance init */
64 NULL
/* value table */
67 type
= g_type_register_static (ATK_TYPE_OBJECT
,
68 "AtkGObjectAccessible", &tinfo
, 0);
75 * atk_gobject_accessible_for_object:
78 * Gets the accessible object for the specified @obj.
80 * Returns: (transfer none): a #AtkObject which is the accessible object for
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
;
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
,
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
,
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
);
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
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
);
137 atk_real_gobject_accessible_initialize (AtkObject
*atk_obj
,
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
,
153 atk_gobject_accessible_object_gone_cb (gpointer data
)
157 g_return_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (data
));
159 object
= atk_gobject_accessible_get_object (data
);
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
,
166 g_object_unref (data
);
170 atk_gobject_accessible_dispose (GObject
*atk_obj
)
172 GObject
*obj
= atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (atk_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
,
180 g_object_set_qdata (atk_obj
, quark_object
, NULL
);
181 atk_object_notify_state_change (ATK_OBJECT (atk_obj
), ATK_STATE_DEFUNCT
,
185 G_OBJECT_CLASS (parent_class
)->dispose (atk_obj
);
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");