Updated Bulgarian translation by Alexander Shopov <ash@contact.bg>
[platform/upstream/atk.git] / atk / atkgobjectaccessible.c
1 /* ATK - Accessibility Toolkit
2  * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include <atk/atkgobjectaccessible.h>
21
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);
26
27 static GQuark quark_accessible_object = 0;
28 static GQuark quark_object = 0;
29 static gpointer parent_class = NULL;
30
31 GType
32 atk_gobject_accessible_get_type (void)
33 {
34   static GType type = 0;
35
36   if (!type)
37     {
38       static const GTypeInfo tinfo =
39       {
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 */
50       };
51
52       type = g_type_register_static (ATK_TYPE_OBJECT,
53                                      "AtkGObjectAccessible", &tinfo, 0);
54     }
55
56   return type;
57 }
58
59 /**
60  * atk_gobject_accessible_for_object:
61  * @obj: a #GObject
62  *
63  * Gets the accessible object for the specified @obj.
64  *
65  * Returns: a #AtkObject which is the accessible object for the @obj
66  **/
67 AtkObject*
68 atk_gobject_accessible_for_object (GObject *obj)
69 {
70   AtkObject* accessible;
71
72   g_return_val_if_fail (G_IS_OBJECT (obj), NULL);
73   /* See if we have a cached accessible for this object */
74
75   accessible = g_object_get_qdata (obj,
76                                    quark_accessible_object);
77
78   if (!accessible)
79     {
80       AtkObjectFactory *factory;
81       AtkRegistry *default_registry;
82
83       default_registry = atk_get_default_registry ();
84       factory = atk_registry_get_factory (default_registry, 
85                                           G_OBJECT_TYPE (obj));
86       accessible = atk_object_factory_create_accessible (factory,
87                                                          obj);
88       if (!ATK_IS_GOBJECT_ACCESSIBLE (accessible))
89         {
90           /*
91            * The AtkObject which was created was not a AtkGObjectAccessible
92            */
93           g_object_weak_ref (obj,
94                              (GWeakNotify) g_object_unref,
95                              accessible); 
96           if (!quark_accessible_object)
97             quark_accessible_object = g_quark_from_static_string ("accessible-object");
98         }
99       g_object_set_qdata (obj, quark_accessible_object, accessible);
100     }
101   return accessible;
102 }
103
104 /**
105  * atk_gobject_accessible_get_object:
106  * @obj: a #AtkObject
107  *
108  * Gets the GObject for which @obj is the accessible object.
109  *
110  * Returns: a #GObject which is the object for which @obj is the accessible objedct
111  **/
112 GObject *
113 atk_gobject_accessible_get_object (AtkGObjectAccessible *obj)
114 {
115   g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (obj), NULL);
116
117   return g_object_get_qdata (G_OBJECT (obj), quark_object);
118 }
119  
120 static void
121 atk_real_gobject_accessible_initialize (AtkObject  *atk_obj,
122                                         gpointer   data)
123 {
124   AtkGObjectAccessible *atk_gobj;
125
126   atk_gobj = ATK_GOBJECT_ACCESSIBLE (atk_obj);
127
128   g_object_set_qdata (G_OBJECT (atk_gobj), quark_object, data);
129   atk_obj->layer = ATK_LAYER_WIDGET;
130
131   g_object_weak_ref (data,
132                      (GWeakNotify) atk_gobject_accessible_dispose,
133                      atk_gobj);
134 }
135
136 static void
137 atk_gobject_accessible_dispose (gpointer  data)
138 {
139   g_return_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (data));
140
141   g_object_set_qdata (G_OBJECT (data), quark_object, NULL);
142   atk_object_notify_state_change (ATK_OBJECT (data), ATK_STATE_DEFUNCT,
143                                   TRUE); 
144   g_object_unref (data);
145 }
146
147 static void
148 atk_gobject_accessible_class_init (AtkGObjectAccessibleClass *klass)
149
150   AtkObjectClass *class;
151
152   class = ATK_OBJECT_CLASS (klass);
153
154   parent_class = g_type_class_peek_parent (klass);
155
156   class->initialize = atk_real_gobject_accessible_initialize;
157
158   if (!quark_accessible_object)
159     quark_accessible_object = g_quark_from_static_string ("accessible-object");
160   quark_object = g_quark_from_static_string ("object-for-accessible");
161 }