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 "config.h"
21

            
22
#include "atknoopobjectfactory.h"
23
#include "atkobjectfactory.h"
24

            
25
/**
26
 * AtkObjectFactory:
27
 *
28
 * The base object class for a factory used to
29
 *  create accessible objects for objects of a specific GType.
30
 *
31
 * This class is the base object class for a factory used to create an
32
 * accessible object for a specific GType. The function
33
 * atk_registry_set_factory_type() is normally called to store in the
34
 * registry the factory type to be used to create an accessible of a
35
 * particular GType.
36
 */
37

            
38
static void atk_object_factory_class_init (AtkObjectFactoryClass *klass);
39

            
40
static gpointer parent_class = NULL;
41

            
42
GType
43
atk_object_factory_get_type (void)
44
{
45
  static GType type = 0;
46

            
47
  if (!type)
48
    {
49
      GTypeInfo tinfo = {
50
        sizeof (AtkObjectFactoryClass),
51
        (GBaseInitFunc) NULL,                           /* base init */
52
        (GBaseFinalizeFunc) NULL,                       /* base finalize */
53
        (GClassInitFunc) atk_object_factory_class_init, /* class init */
54
        (GClassFinalizeFunc) NULL,                      /* class finalize */
55
        NULL,                                           /* class data */
56
        sizeof (AtkObjectFactory),                      /* instance size */
57
        0,                                              /* nb preallocs */
58
        (GInstanceInitFunc) NULL,                       /* instance init */
59
        NULL                                            /* value table */
60
      };
61

            
62
      type = g_type_register_static (G_TYPE_OBJECT, "AtkObjectFactory", &tinfo, 0);
63
    }
64
  return type;
65
}
66

            
67
static void
68
atk_object_factory_class_init (AtkObjectFactoryClass *klass)
69
{
70
  parent_class = g_type_class_peek_parent (klass);
71
}
72

            
73
/**
74
 * atk_object_factory_create_accessible:
75
 * @factory: The #AtkObjectFactory associated with @obj's
76
 * object type
77
 * @obj: a #GObject
78
 *
79
 * Provides an #AtkObject that implements an accessibility interface
80
 * on behalf of @obj
81
 *
82
 * Returns: (transfer full): an #AtkObject that implements an accessibility
83
 * interface on behalf of @obj
84
 **/
85
AtkObject *
86
atk_object_factory_create_accessible (AtkObjectFactory *factory,
87
                                      GObject *obj)
88
{
89
  AtkObjectFactoryClass *klass;
90
  AtkObject *accessible = NULL;
91

            
92
  g_return_val_if_fail (ATK_IS_OBJECT_FACTORY (factory), NULL);
93
  g_return_val_if_fail (G_IS_OBJECT (obj), NULL);
94

            
95
  klass = ATK_OBJECT_FACTORY_GET_CLASS (factory);
96

            
97
  if (klass->create_accessible)
98
    {
99
      accessible = klass->create_accessible (obj);
100
    }
101
  return accessible;
102
}
103

            
104
/**
105
 * atk_object_factory_invalidate:
106
 * @factory: an #AtkObjectFactory to invalidate
107
 *
108
 * Inform @factory that it is no longer being used to create
109
 * accessibles. When called, @factory may need to inform
110
 * #AtkObjects which it has created that they need to be re-instantiated.
111
 * Note: primarily used for runtime replacement of #AtkObjectFactorys
112
 * in object registries.
113
 **/
114
void
115
atk_object_factory_invalidate (AtkObjectFactory *factory)
116
{
117
  AtkObjectFactoryClass *klass;
118

            
119
  g_return_if_fail (ATK_OBJECT_FACTORY (factory));
120

            
121
  klass = ATK_OBJECT_FACTORY_GET_CLASS (factory);
122
  if (klass->invalidate)
123
    (klass->invalidate) (factory);
124
}
125

            
126
/**
127
 * atk_object_factory_get_accessible_type:
128
 * @factory: an #AtkObjectFactory
129
 *
130
 * Gets the GType of the accessible which is created by the factory.
131
 * Returns: the type of the accessible which is created by the @factory.
132
 * The value G_TYPE_INVALID is returned if no type if found.
133
 **/
134
GType
135
atk_object_factory_get_accessible_type (AtkObjectFactory *factory)
136
{
137
  AtkObjectFactoryClass *klass;
138

            
139
  g_return_val_if_fail (ATK_OBJECT_FACTORY (factory), G_TYPE_INVALID);
140

            
141
  klass = ATK_OBJECT_FACTORY_GET_CLASS (factory);
142
  if (klass->get_accessible_type)
143
    return (klass->get_accessible_type) ();
144
  else
145
    return G_TYPE_INVALID;
146
}