b519286f4707407ea87361d4e782571be13919a2
[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   g_return_if_fail (component != NULL);
98
99   atk_component_get_extents (component, &ix, &iy, &iw, &ih,
100                              (AtkCoordType) coord_type);
101
102   retval.x = ix;
103   retval.y = ix;
104   retval.width = iw;
105   retval.height = ih;
106
107   return retval;
108 }
109
110 /*
111  * CORBA Accessibility::Component::getPosition method implementation
112  */
113 static void
114 impl_accessibility_component_get_position (PortableServer_Servant servant,
115                                            CORBA_long * x,
116                                            CORBA_long * y,
117                                            const CORBA_short coord_type,
118                                            CORBA_Environment     *ev)
119 {
120   gint ix, iy;
121   AtkComponent *component = get_component_from_servant (servant);
122
123   g_return_if_fail (component != NULL);
124
125   atk_component_get_position (component, &ix, &iy,
126                               (AtkCoordType) coord_type);
127   *x = (CORBA_long) ix;
128   *y = (CORBA_long) iy;
129 }
130
131 /*
132  * CORBA Accessibility::Component::getSize method implementation
133  */
134 static void
135 impl_accessibility_component_get_size (PortableServer_Servant servant,
136                                        CORBA_long * width,
137                                        CORBA_long * height,
138                                        CORBA_Environment     *ev)
139 {
140   gint iw, ih;
141   AtkComponent *component = get_component_from_servant (servant);
142
143   g_return_if_fail (component != NULL);
144
145   atk_component_get_size (component, &iw, &ih);
146   *width = (CORBA_long) iw;
147   *height = (CORBA_long) ih;
148 }
149
150 static Accessibility_ComponentLayer
151 impl_accessibility_component_get_layer (PortableServer_Servant servant,
152                                         CORBA_Environment     *ev)
153 {
154   AtkLayer      atklayer;
155   AtkComponent *component = get_component_from_servant (servant);
156
157   g_return_val_if_fail (component != NULL, Accessibility_LAYER_INVALID);
158
159   atklayer = atk_object_get_layer (ATK_OBJECT (component));
160   switch (atklayer)
161     {
162       case ATK_LAYER_BACKGROUND:
163         return Accessibility_LAYER_BACKGROUND;
164       case ATK_LAYER_CANVAS:
165         return Accessibility_LAYER_CANVAS;
166       case ATK_LAYER_WIDGET:
167         return Accessibility_LAYER_WIDGET;
168       case ATK_LAYER_MDI:
169         return Accessibility_LAYER_MDI;
170       case ATK_LAYER_POPUP:
171         return Accessibility_LAYER_POPUP;
172       case ATK_LAYER_OVERLAY:
173         return Accessibility_LAYER_OVERLAY;
174       default:
175         break;      
176     }
177   return Accessibility_LAYER_INVALID;
178 }
179
180 static CORBA_short
181 impl_accessibility_component_get_mdi_z_order (PortableServer_Servant servant,
182                                               CORBA_Environment     *ev)
183 {
184   AtkComponent *component = get_component_from_servant (servant);
185
186   g_return_val_if_fail (component != NULL, -1);
187
188   return (CORBA_short) atk_object_get_mdi_zorder (ATK_OBJECT (component));
189 }
190
191 static void
192 spi_component_class_init (SpiComponentClass *klass)
193 {
194         POA_Accessibility_Component__epv *epv = &klass->epv;
195         spi_component_parent_class = g_type_class_peek_parent (klass);
196
197         epv->contains = impl_accessibility_component_contains;
198         epv->getAccessibleAtPoint = impl_accessibility_component_get_accessible_at_point;
199         epv->getExtents = impl_accessibility_component_get_extents;
200         epv->getPosition = impl_accessibility_component_get_position;
201         epv->getSize = impl_accessibility_component_get_size;
202         epv->getLayer = impl_accessibility_component_get_layer;
203         epv->getMDIZOrder = impl_accessibility_component_get_mdi_z_order;
204 }
205
206 static void
207 spi_component_init (SpiComponent *component)
208 {
209 }
210
211 BONOBO_TYPE_FUNC_FULL (SpiComponent,
212                        Accessibility_Component,
213                        PARENT_TYPE,
214                        spi_component);
215
216 SpiComponent *
217 spi_component_interface_new (AtkObject *o)
218 {
219     SpiComponent *retval = g_object_new (SPI_COMPONENT_TYPE, NULL);
220
221     spi_base_construct (SPI_BASE (retval), o);
222
223     return retval;
224 }