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