2001-12-10 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 /* 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 SPI_TYPE_BASE
32
33 /* A pointer to our parent object class */
34 static GObjectClass *spi_component_parent_class;
35
36 static AtkComponent *
37 get_component_from_servant (PortableServer_Servant servant)
38 {
39   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
40   g_return_val_if_fail (object != NULL, NULL);
41   return ATK_COMPONENT (object->atko);
42 }
43
44 /*
45  * CORBA Accessibility::Component::contains method implementation
46  */
47 static CORBA_boolean
48 impl_accessibility_component_contains (PortableServer_Servant servant,
49                                        const CORBA_long x,
50                                        const CORBA_long y,
51                                        CORBA_short coord_type,
52                                        CORBA_Environment     *ev)
53 {
54   CORBA_boolean retval;
55   AtkComponent *component = get_component_from_servant (servant);
56
57   g_return_val_if_fail (component != NULL, FALSE);
58
59   retval = atk_component_contains (component, (gint) x, (gint) y,
60                                   (AtkCoordType) coord_type);
61   return retval;
62 }
63
64 /*
65  * CORBA Accessibility::Component::getAccessibleAtPoint method implementation
66  */
67 static Accessibility_Accessible
68 impl_accessibility_component_get_accessible_at_point (PortableServer_Servant servant,
69                                                       const CORBA_long x,
70                                                       const CORBA_long y,
71                                                       CORBA_short coord_type,
72                                                       CORBA_Environment     *ev)
73 {
74   AtkObject    *child;
75   AtkComponent *component = get_component_from_servant (servant);
76
77   g_return_val_if_fail (component != NULL, FALSE);
78
79   child = atk_component_ref_accessible_at_point (component,
80                                                  (gint) x, (gint) y,
81                                                  (AtkCoordType) coord_type);
82   return spi_accessible_new_return (child, TRUE, ev);
83 }
84
85 /*
86  * CORBA Accessibility::Component::getExtents method implementation
87  */
88 static Accessibility_BoundingBox
89 impl_accessibility_component_get_extents (PortableServer_Servant servant,
90                                           const CORBA_short      coord_type,
91                                           CORBA_Environment     *ev)
92 {
93   gint ix, iy, iw, ih;
94   Accessibility_BoundingBox retval;
95   AtkComponent *component = get_component_from_servant (servant);
96
97   atk_component_get_extents (component, &ix, &iy, &iw, &ih,
98                              (AtkCoordType) coord_type);
99
100   retval.x = ix;
101   retval.y = ix;
102   retval.width = iw;
103   retval.height = ih;
104
105   return retval;
106 }
107
108 /*
109  * CORBA Accessibility::Component::getPosition method implementation
110  */
111 static void
112 impl_accessibility_component_get_position (PortableServer_Servant servant,
113                                            CORBA_long * x,
114                                            CORBA_long * y,
115                                            const CORBA_short coord_type,
116                                            CORBA_Environment     *ev)
117 {
118   gint ix, iy;
119   AtkComponent *component = get_component_from_servant (servant);
120
121   g_return_if_fail (component != NULL);
122
123   atk_component_get_position (component, &ix, &iy,
124                               (AtkCoordType) coord_type);
125   *x = (CORBA_long) ix;
126   *y = (CORBA_long) iy;
127 }
128
129 /*
130  * CORBA Accessibility::Component::getSize method implementation
131  */
132 static void
133 impl_accessibility_component_get_size (PortableServer_Servant servant,
134                                        CORBA_long * width,
135                                        CORBA_long * height,
136                                        CORBA_Environment     *ev)
137 {
138   gint iw, ih;
139   AtkComponent *component = get_component_from_servant (servant);
140
141   g_return_if_fail (component != NULL);
142
143   atk_component_get_size (component, &iw, &ih);
144   *width = (CORBA_long) iw;
145   *height = (CORBA_long) ih;
146 }
147
148 static Accessibility_ComponentLayer
149 impl_accessibility_component_get_layer (PortableServer_Servant servant,
150                                         CORBA_Environment     *ev)
151 {
152   AtkLayer      atklayer;
153   AtkComponent *component = get_component_from_servant (servant);
154
155   g_return_val_if_fail (component != NULL, Accessibility_LAYER_INVALID);
156
157   atklayer = atk_object_get_layer (ATK_OBJECT (component));
158   switch (atklayer)
159     {
160       case ATK_LAYER_BACKGROUND:
161         return Accessibility_LAYER_BACKGROUND;
162       case ATK_LAYER_CANVAS:
163         return Accessibility_LAYER_CANVAS;
164       case ATK_LAYER_WIDGET:
165         return Accessibility_LAYER_WIDGET;
166       case ATK_LAYER_MDI:
167         return Accessibility_LAYER_MDI;
168       case ATK_LAYER_POPUP:
169         return Accessibility_LAYER_POPUP;
170       case ATK_LAYER_OVERLAY:
171         return Accessibility_LAYER_OVERLAY;
172       default:
173         break;      
174     }
175   return Accessibility_LAYER_INVALID;
176 }
177
178 static CORBA_short
179 impl_accessibility_component_get_mdi_z_order (PortableServer_Servant servant,
180                                               CORBA_Environment     *ev)
181 {
182   AtkComponent *component = get_component_from_servant (servant);
183
184   g_return_val_if_fail (component != NULL, -1);
185
186   return (CORBA_short) atk_object_get_mdi_zorder (ATK_OBJECT (component));
187 }
188
189 static void
190 spi_component_class_init (SpiComponentClass *klass)
191 {
192         POA_Accessibility_Component__epv *epv = &klass->epv;
193         spi_component_parent_class = g_type_class_peek_parent (klass);
194
195         epv->contains = impl_accessibility_component_contains;
196         epv->getAccessibleAtPoint = impl_accessibility_component_get_accessible_at_point;
197         epv->getExtents = impl_accessibility_component_get_extents;
198         epv->getPosition = impl_accessibility_component_get_position;
199         epv->getSize = impl_accessibility_component_get_size;
200         epv->getLayer = impl_accessibility_component_get_layer;
201         epv->getMDIZOrder = impl_accessibility_component_get_mdi_z_order;
202 }
203
204 static void
205 spi_component_init (SpiComponent *component)
206 {
207 }
208
209 BONOBO_TYPE_FUNC_FULL (SpiComponent,
210                        Accessibility_Component,
211                        PARENT_TYPE,
212                        spi_component);
213
214 SpiComponent *
215 spi_component_interface_new (AtkObject *o)
216 {
217     SpiComponent *retval = g_object_new (SPI_COMPONENT_TYPE, NULL);
218
219     spi_base_construct (SPI_BASE (retval), o);
220
221     return retval;
222 }