2001-11-13 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / libspi / component.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Sun Microsystems Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /*
24  * component.c : bonobo wrapper for accessible component implementation
25  *
26  */
27 #include <config.h>
28 #include <bonobo/Bonobo.h>
29
30 #include <stdio.h>
31
32 /*
33  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
34  */
35 #include <libspi/Accessibility.h>
36
37 /*
38  * This pulls the definition for the BonoboObject (Gtk Type)
39  */
40 #include "component.h"
41 #include "accessible.h"
42
43 /*
44  * Our parent Gtk object type
45  */
46 #define PARENT_TYPE BONOBO_OBJECT_TYPE
47
48 /*
49  * A pointer to our parent object class
50  */
51 static GObjectClass *spi_component_parent_class;
52
53 /*
54  * Implemented GObject::finalize
55  */
56 static void
57 accessibility_component_object_finalize (GObject *object)
58 {
59         SpiComponent *component = SPI_COMPONENT (object);
60
61         printf("spi_accessible_component_object_finalize called\n");
62         g_object_unref (component->atko);
63         component->atko = NULL;
64
65         printf("component atko freed, calling parent finalize\n");
66         spi_component_parent_class->finalize (object);
67 }
68
69 /*
70  * CORBA Accessibility::Component::contains method implementation
71  */
72 static CORBA_boolean
73 impl_accessibility_component_contains (PortableServer_Servant servant,
74                                        const CORBA_long x,
75                                        const CORBA_long y,
76                                        CORBA_short coord_type,
77                                        CORBA_Environment     *ev)
78 {
79   CORBA_boolean retval;
80   BonoboObject *obj;
81   SpiComponent *component;
82
83   obj = bonobo_object_from_servant (servant);
84   g_return_val_if_fail (IS_SPI_COMPONENT(obj), FALSE);
85   component = SPI_COMPONENT (obj);
86   g_return_val_if_fail (ATK_IS_COMPONENT(component->atko), FALSE);
87   retval = atk_component_contains (ATK_COMPONENT (component->atko), (gint) x, (gint) y,
88                                   (AtkCoordType) coord_type);
89   return retval;
90 }
91
92 /*
93  * CORBA Accessibility::Component::getAccessibleAtPoint method implementation
94  */
95 static Accessibility_Accessible
96 impl_accessibility_component_get_accessible_at_point (PortableServer_Servant servant,
97                                                       const CORBA_long x,
98                                                       const CORBA_long y,
99                                                       CORBA_short coord_type,
100                                                       CORBA_Environment     *ev)
101 {
102   BonoboObject *obj;
103   SpiComponent *component;
104   Accessibility_Accessible retval;
105   AtkObject *child;
106
107   obj = bonobo_object_from_servant (servant);
108   g_return_val_if_fail (IS_SPI_COMPONENT(obj), CORBA_OBJECT_NIL);
109   component = SPI_COMPONENT (obj);
110   g_return_val_if_fail (ATK_IS_COMPONENT(component->atko), CORBA_OBJECT_NIL);
111
112   child = atk_component_ref_accessible_at_point (ATK_COMPONENT (component->atko),
113                                                   (gint) x, (gint) y,
114                                                   (AtkCoordType) coord_type);
115   retval = bonobo_object_corba_objref (bonobo_object (spi_accessible_new (child)));
116   return CORBA_Object_duplicate (retval, ev);
117 }
118
119 /*
120  * CORBA Accessibility::Component::getExtents method implementation
121  */
122 static void
123 impl_accessibility_component_get_extents (PortableServer_Servant servant,
124                                           CORBA_long * x,
125                                           CORBA_long * y,
126                                           CORBA_long * width,
127                                           CORBA_long * height,
128                                           const CORBA_short coord_type,
129                                           CORBA_Environment     *ev)
130 {
131   BonoboObject *obj;
132   SpiComponent *component;
133   gint ix, iy, iw, ih;
134
135   obj = bonobo_object_from_servant (servant);
136   g_return_if_fail (IS_SPI_COMPONENT(obj));
137   component = SPI_COMPONENT (obj);
138   g_return_if_fail (ATK_IS_COMPONENT (component->atko));
139
140   atk_component_get_extents (ATK_COMPONENT (component->atko), &ix, &iy, &iw, &ih,
141                                   (AtkCoordType) coord_type);
142   *x = (CORBA_long) ix;
143   *y = (CORBA_long) iy;
144   *width = (CORBA_long) iw;
145   *height = (CORBA_long) ih;
146 }
147
148 /*
149  * CORBA Accessibility::Component::getPosition method implementation
150  */
151 static void
152 impl_accessibility_component_get_position (PortableServer_Servant servant,
153                                            CORBA_long * x,
154                                            CORBA_long * y,
155                                            const CORBA_short coord_type,
156                                            CORBA_Environment     *ev)
157 {
158   BonoboObject *obj = bonobo_object_from_servant (servant);
159   SpiComponent *component;
160   gint ix, iy;
161
162   g_return_if_fail (IS_SPI_COMPONENT(obj));
163   component = SPI_COMPONENT(obj);
164   g_return_if_fail (ATK_IS_COMPONENT(component->atko));
165
166   atk_component_get_position (ATK_COMPONENT (component->atko), &ix, &iy,
167                               (AtkCoordType) coord_type);
168   *x = (CORBA_long) ix;
169   *y = (CORBA_long) iy;
170 }
171
172 /*
173  * CORBA Accessibility::Component::getSize method implementation
174  */
175 static void
176 impl_accessibility_component_get_size (PortableServer_Servant servant,
177                                        CORBA_long * width,
178                                        CORBA_long * height,
179                                        CORBA_Environment     *ev)
180 {
181   SpiComponent *component;
182   BonoboObject *obj = bonobo_object_from_servant (servant);
183   gint iw, ih;
184
185   g_return_if_fail (IS_SPI_COMPONENT(obj));
186   component = SPI_COMPONENT(obj);
187   g_return_if_fail (ATK_IS_COMPONENT(component->atko));
188   atk_component_get_size (ATK_COMPONENT (component->atko), &iw, &ih);
189   *width = (CORBA_long) iw;
190   *height = (CORBA_long) ih;
191 }
192
193 static void
194 accessibility_component_class_init (SpiComponentClass *klass)
195 {
196         GObjectClass * object_class = (GObjectClass *) klass;
197         POA_Accessibility_Component__epv *epv = &klass->epv;
198         spi_component_parent_class = g_type_class_peek_parent (klass);
199
200         object_class->finalize = accessibility_component_object_finalize;
201
202         epv->contains = impl_accessibility_component_contains;
203         epv->getAccessibleAtPoint = impl_accessibility_component_get_accessible_at_point;
204         epv->getExtents = impl_accessibility_component_get_extents;
205         epv->getPosition = impl_accessibility_component_get_position;
206         epv->getSize = impl_accessibility_component_get_size;
207 }
208
209 static void
210 accessibility_component_init (SpiComponent *component)
211 {
212 }
213
214 GType
215 accessibility_component_get_type (void)
216 {
217         static GType type = 0;
218
219         if (!type) {
220                 static const GTypeInfo tinfo = {
221                         sizeof (SpiComponentClass),
222                         (GBaseInitFunc) NULL,
223                         (GBaseFinalizeFunc) NULL,
224                         (GClassInitFunc) accessibility_component_class_init,
225                         (GClassFinalizeFunc) NULL,
226                         NULL, /* class data */
227                         sizeof (SpiComponent),
228                         0, /* n preallocs */
229                         (GInstanceInitFunc) accessibility_component_init,
230                         NULL /* value table */
231                 };
232                 /*
233                  * Bonobo_type_unique auto-generates a load of
234                  * CORBA structures for us. All derived types must
235                  * use bonobo_type_unique.
236                  */
237                 type = bonobo_type_unique (
238                         PARENT_TYPE,
239                         POA_Accessibility_Component__init,
240                         NULL,
241                         G_STRUCT_OFFSET (SpiComponentClass, epv),
242                         &tinfo,
243                         "SpiAccessibleComponent");
244         }
245
246         return type;
247 }
248
249 SpiComponent *
250 spi_component_interface_new (AtkObject *o)
251 {
252     SpiComponent *retval =
253                SPI_COMPONENT (g_object_new (accessibility_component_get_type (), NULL));
254     retval->atko = o;
255     g_object_ref (o);
256     return retval;
257 }