Updated FSF's address
[platform/upstream/atk.git] / atk / atkobjectfactory.c
1 /* ATK - Accessibility Toolkit
2  * Copyright 2001 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, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "atkobjectfactory.h"
19 #include "atknoopobjectfactory.h"
20
21 /**
22  * SECTION:atkobjectfactory
23  * @Short_description: The base object class for a factory used to
24  *  create accessible objects for objects of a specific GType.
25  * @Title:AtkObjectFactory
26  *
27  * This class is the base object class for a factory used to create an
28  * accessible object for a specific GType. The function
29  * atk_registry_set_factory_type() is normally called to store in the
30  * registry the factory type to be used to create an accessible of a
31  * particular GType.
32  */
33
34 static void atk_object_factory_class_init   (AtkObjectFactoryClass        *klass);
35
36 static gpointer    parent_class = NULL;
37
38 GType
39 atk_object_factory_get_type (void)
40 {
41   static GType type = 0;
42
43   if (!type) {
44     GTypeInfo tinfo =
45     {
46       sizeof (AtkObjectFactoryClass),
47       (GBaseInitFunc) NULL, /* base init */
48       (GBaseFinalizeFunc) NULL, /* base finalize */
49       (GClassInitFunc) atk_object_factory_class_init, /* class init */
50       (GClassFinalizeFunc) NULL, /* class finalize */
51       NULL, /* class data */
52       sizeof (AtkObjectFactory), /* instance size */
53       0, /* nb preallocs */
54       (GInstanceInitFunc) NULL, /* instance init */
55       NULL /* value table */
56     };
57
58     type = g_type_register_static (G_TYPE_OBJECT, "AtkObjectFactory", &tinfo, 0);
59   }
60   return type;
61 }
62
63 static void 
64 atk_object_factory_class_init (AtkObjectFactoryClass *klass)
65 {
66   parent_class = g_type_class_peek_parent (klass);
67
68 }
69
70 /**
71  * atk_object_factory_create_accessible:
72  * @factory: The #AtkObjectFactory associated with @obj's
73  * object type
74  * @obj: a #GObject 
75  * 
76  * Provides an #AtkObject that implements an accessibility interface 
77  * on behalf of @obj
78  *
79  * Returns: (transfer full): an #AtkObject that implements an accessibility
80  * interface on behalf of @obj
81  **/
82 AtkObject* 
83 atk_object_factory_create_accessible (AtkObjectFactory *factory,
84                                       GObject          *obj)
85 {
86   AtkObjectFactoryClass *klass;
87   AtkObject *accessible = NULL;
88
89   g_return_val_if_fail (ATK_IS_OBJECT_FACTORY (factory), NULL);
90   g_return_val_if_fail (G_IS_OBJECT (obj), NULL);
91
92   klass = ATK_OBJECT_FACTORY_GET_CLASS (factory);
93
94   if (klass->create_accessible)
95   {
96       accessible = klass->create_accessible (obj);
97   }
98   return accessible;
99
100
101 /**
102  * atk_object_factory_invalidate:
103  * @factory: an #AtkObjectFactory to invalidate
104  *
105  * Inform @factory that it is no longer being used to create
106  * accessibles. When called, @factory may need to inform
107  * #AtkObjects which it has created that they need to be re-instantiated.
108  * Note: primarily used for runtime replacement of #AtkObjectFactorys
109  * in object registries.
110  **/
111 void 
112 atk_object_factory_invalidate (AtkObjectFactory *factory)
113 {
114   AtkObjectFactoryClass *klass;
115
116   g_return_if_fail (ATK_OBJECT_FACTORY (factory));
117
118   klass = ATK_OBJECT_FACTORY_GET_CLASS (factory);
119   if (klass->invalidate)
120      (klass->invalidate) (factory);
121 }
122
123 /**
124  * atk_object_factory_get_accessible_type:
125  * @factory: an #AtkObjectFactory 
126  *
127  * Gets the GType of the accessible which is created by the factory. 
128  * Returns: the type of the accessible which is created by the @factory.
129  * The value G_TYPE_INVALID is returned if no type if found.
130  **/
131 GType
132 atk_object_factory_get_accessible_type (AtkObjectFactory *factory)
133 {
134   AtkObjectFactoryClass *klass;
135
136   g_return_val_if_fail (ATK_OBJECT_FACTORY (factory), G_TYPE_INVALID);
137
138   klass = ATK_OBJECT_FACTORY_GET_CLASS (factory);
139   if (klass->get_accessible_type)
140      return (klass->get_accessible_type) ();
141   else
142      return G_TYPE_INVALID;
143 }