Added implementations for Accessibility_Component_getLayer and
[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 /* component.c : implements the Component interface */
24
25 #include <config.h>
26 #include <stdio.h>
27 #include <libspi/accessible.h>
28 #include <libspi/component.h>
29
30 /* Our parent Gtk object type */
31 #define PARENT_TYPE BONOBO_TYPE_OBJECT
32
33 /* A pointer to our parent object class */
34 static GObjectClass *spi_component_parent_class;
35
36 /*
37  * Implemented GObject::finalize
38  */
39 static void
40 accessibility_component_object_finalize (GObject *object)
41 {
42         SpiComponent *component = SPI_COMPONENT (object);
43
44         printf("spi_accessible_component_object_finalize called\n");
45         g_object_unref (component->atko);
46         component->atko = NULL;
47
48         printf("component atko freed, calling parent finalize\n");
49         spi_component_parent_class->finalize (object);
50 }
51
52 /*
53  * CORBA Accessibility::Component::contains method implementation
54  */
55 static CORBA_boolean
56 impl_accessibility_component_contains (PortableServer_Servant servant,
57                                        const CORBA_long x,
58                                        const CORBA_long y,
59                                        CORBA_short coord_type,
60                                        CORBA_Environment     *ev)
61 {
62   CORBA_boolean retval;
63   BonoboObject *obj;
64   SpiComponent *component;
65
66   obj = bonobo_object_from_servant (servant);
67   g_return_val_if_fail (IS_SPI_COMPONENT(obj), FALSE);
68   component = SPI_COMPONENT (obj);
69   g_return_val_if_fail (ATK_IS_COMPONENT(component->atko), FALSE);
70   retval = atk_component_contains (ATK_COMPONENT (component->atko), (gint) x, (gint) y,
71                                   (AtkCoordType) coord_type);
72   return retval;
73 }
74
75 /*
76  * CORBA Accessibility::Component::getAccessibleAtPoint method implementation
77  */
78 static Accessibility_Accessible
79 impl_accessibility_component_get_accessible_at_point (PortableServer_Servant servant,
80                                                       const CORBA_long x,
81                                                       const CORBA_long y,
82                                                       CORBA_short coord_type,
83                                                       CORBA_Environment     *ev)
84 {
85   BonoboObject *obj;
86   SpiComponent *component;
87   Accessibility_Accessible retval;
88   AtkObject *child;
89
90   obj = bonobo_object_from_servant (servant);
91   g_return_val_if_fail (IS_SPI_COMPONENT(obj), CORBA_OBJECT_NIL);
92   component = SPI_COMPONENT (obj);
93   g_return_val_if_fail (ATK_IS_COMPONENT(component->atko), CORBA_OBJECT_NIL);
94
95   child = atk_component_ref_accessible_at_point (ATK_COMPONENT (component->atko),
96                                                   (gint) x, (gint) y,
97                                                   (AtkCoordType) coord_type);
98   retval = bonobo_object_corba_objref (bonobo_object (spi_accessible_new (child)));
99   return CORBA_Object_duplicate (retval, ev);
100 }
101
102 /*
103  * CORBA Accessibility::Component::getExtents method implementation
104  */
105 static void
106 impl_accessibility_component_get_extents (PortableServer_Servant servant,
107                                           CORBA_long * x,
108                                           CORBA_long * y,
109                                           CORBA_long * width,
110                                           CORBA_long * height,
111                                           const CORBA_short coord_type,
112                                           CORBA_Environment     *ev)
113 {
114   BonoboObject *obj;
115   SpiComponent *component;
116   gint ix, iy, iw, ih;
117
118   obj = bonobo_object_from_servant (servant);
119   g_return_if_fail (IS_SPI_COMPONENT(obj));
120   component = SPI_COMPONENT (obj);
121   g_return_if_fail (ATK_IS_COMPONENT (component->atko));
122
123   atk_component_get_extents (ATK_COMPONENT (component->atko), &ix, &iy, &iw, &ih,
124                                   (AtkCoordType) coord_type);
125   *x = (CORBA_long) ix;
126   *y = (CORBA_long) iy;
127   *width = (CORBA_long) iw;
128   *height = (CORBA_long) ih;
129 }
130
131 /*
132  * CORBA Accessibility::Component::getPosition method implementation
133  */
134 static void
135 impl_accessibility_component_get_position (PortableServer_Servant servant,
136                                            CORBA_long * x,
137                                            CORBA_long * y,
138                                            const CORBA_short coord_type,
139                                            CORBA_Environment     *ev)
140 {
141   BonoboObject *obj = bonobo_object_from_servant (servant);
142   SpiComponent *component;
143   gint ix, iy;
144
145   g_return_if_fail (IS_SPI_COMPONENT(obj));
146   component = SPI_COMPONENT(obj);
147   g_return_if_fail (ATK_IS_COMPONENT(component->atko));
148
149   atk_component_get_position (ATK_COMPONENT (component->atko), &ix, &iy,
150                               (AtkCoordType) coord_type);
151   *x = (CORBA_long) ix;
152   *y = (CORBA_long) iy;
153 }
154
155 /*
156  * CORBA Accessibility::Component::getSize method implementation
157  */
158 static void
159 impl_accessibility_component_get_size (PortableServer_Servant servant,
160                                        CORBA_long * width,
161                                        CORBA_long * height,
162                                        CORBA_Environment     *ev)
163 {
164   SpiComponent *component;
165   BonoboObject *obj = bonobo_object_from_servant (servant);
166   gint iw, ih;
167
168   g_return_if_fail (IS_SPI_COMPONENT(obj));
169   component = SPI_COMPONENT(obj);
170   g_return_if_fail (ATK_IS_COMPONENT(component->atko));
171   atk_component_get_size (ATK_COMPONENT (component->atko), &iw, &ih);
172   *width = (CORBA_long) iw;
173   *height = (CORBA_long) ih;
174 }
175
176 static Accessibility_ComponentLayer
177 impl_accessibility_component_get_layer (PortableServer_Servant servant,
178                                         CORBA_Environment     *ev)
179 {
180   SpiComponent *component;
181   AtkLayer atklayer;
182   BonoboObject *obj = bonobo_object_from_servant (servant);
183
184   g_return_if_fail (IS_SPI_COMPONENT(obj));
185   component = SPI_COMPONENT(obj);
186   g_return_if_fail (ATK_IS_COMPONENT(component->atko));
187   atklayer = atk_object_get_layer (ATK_OBJECT (component->atko));
188   switch (atklayer)
189     {
190       case ATK_LAYER_BACKGROUND:
191         return Accessibility_LAYER_BACKGROUND;
192       case ATK_LAYER_CANVAS:
193         return Accessibility_LAYER_CANVAS;
194       case ATK_LAYER_WIDGET:
195         return Accessibility_LAYER_WIDGET;
196       case ATK_LAYER_MDI:
197         return Accessibility_LAYER_MDI;
198       case ATK_LAYER_POPUP:
199         return Accessibility_LAYER_POPUP;
200       case ATK_LAYER_OVERLAY:
201         return Accessibility_LAYER_OVERLAY;
202       default:
203         break;      
204     }
205   return Accessibility_LAYER_INVALID;
206 }
207
208 static CORBA_short
209 impl_accessibility_component_get_mdi_z_order (PortableServer_Servant servant,
210                                               CORBA_Environment     *ev)
211 {
212   SpiComponent *component;
213   BonoboObject *obj = bonobo_object_from_servant (servant);
214
215   g_return_if_fail (IS_SPI_COMPONENT(obj));
216   component = SPI_COMPONENT(obj);
217   g_return_if_fail (ATK_IS_COMPONENT(component->atko));
218   return (CORBA_short) atk_object_get_mdi_zorder (ATK_OBJECT (component->atko));
219 }
220
221 static void
222 spi_component_class_init (SpiComponentClass *klass)
223 {
224         GObjectClass * object_class = (GObjectClass *) klass;
225         POA_Accessibility_Component__epv *epv = &klass->epv;
226         spi_component_parent_class = g_type_class_peek_parent (klass);
227
228         object_class->finalize = accessibility_component_object_finalize;
229
230         epv->contains = impl_accessibility_component_contains;
231         epv->getAccessibleAtPoint = impl_accessibility_component_get_accessible_at_point;
232         epv->getExtents = impl_accessibility_component_get_extents;
233         epv->getPosition = impl_accessibility_component_get_position;
234         epv->getSize = impl_accessibility_component_get_size;
235         epv->getLayer = impl_accessibility_component_get_layer;
236         epv->getMDIZOrder = impl_accessibility_component_get_mdi_z_order;
237 }
238
239 static void
240 spi_component_init (SpiComponent *component)
241 {
242 }
243
244 BONOBO_TYPE_FUNC_FULL (SpiComponent,
245                        Accessibility_Component,
246                        PARENT_TYPE,
247                        spi_component);
248
249 SpiComponent *
250 spi_component_interface_new (AtkObject *o)
251 {
252     SpiComponent *retval = g_object_new (SPI_COMPONENT_TYPE, NULL);
253     retval->atko = o;
254     g_object_ref (o);
255     return retval;
256 }