Started fixing IDL docs.
[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 void
177 spi_component_class_init (SpiComponentClass *klass)
178 {
179         GObjectClass * object_class = (GObjectClass *) klass;
180         POA_Accessibility_Component__epv *epv = &klass->epv;
181         spi_component_parent_class = g_type_class_peek_parent (klass);
182
183         object_class->finalize = accessibility_component_object_finalize;
184
185         epv->contains = impl_accessibility_component_contains;
186         epv->getAccessibleAtPoint = impl_accessibility_component_get_accessible_at_point;
187         epv->getExtents = impl_accessibility_component_get_extents;
188         epv->getPosition = impl_accessibility_component_get_position;
189         epv->getSize = impl_accessibility_component_get_size;
190 }
191
192 static void
193 spi_component_init (SpiComponent *component)
194 {
195 }
196
197 BONOBO_TYPE_FUNC_FULL (SpiComponent,
198                        Accessibility_Component,
199                        PARENT_TYPE,
200                        spi_component);
201
202 SpiComponent *
203 spi_component_interface_new (AtkObject *o)
204 {
205     SpiComponent *retval = g_object_new (SPI_COMPONENT_TYPE, NULL);
206     retval->atko = o;
207     g_object_ref (o);
208     return retval;
209 }