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