Cleaned up some suspect int* casts, and added assertions to text calls in libspi
[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 /*
24  * component.c : bonobo wrapper for accessible component implementation
25  *
26  */
27 #include <config.h>
28 #include <bonobo/Bonobo.h>
29
30 #include <stdio.h>
31
32 /*
33  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
34  */
35 #include <libspi/Accessibility.h>
36
37 /*
38  * This pulls the definition for the BonoboObject (Gtk Type)
39  */
40 #include "component.h"
41 #include "accessible.h"
42
43 /*
44  * Our parent Gtk object type
45  */
46 #define PARENT_TYPE BONOBO_OBJECT_TYPE
47
48 /*
49  * A pointer to our parent object class
50  */
51 static GObjectClass *component_parent_class;
52
53 /*
54  * Implemented GObject::finalize
55  */
56 static void
57 accessibility_component_object_finalize (GObject *object)
58 {
59         Component *component = COMPONENT (object);
60
61         printf("accessible_component_object_finalize called\n");
62         g_object_unref (component->atko);
63         component->atko = NULL;
64
65         printf("atko freed, calling parent finalize\n");
66         component_parent_class->finalize (object);
67 }
68
69 /*
70  * CORBA Accessibility::Component::contains method implementation
71  */
72 static CORBA_boolean
73 impl_accessibility_component_contains (PortableServer_Servant servant,
74                                        const CORBA_long x,
75                                        const CORBA_long y,
76                                        CORBA_short coord_type,
77                                        CORBA_Environment     *ev)
78 {
79   CORBA_boolean retval;
80   Component *component = COMPONENT (bonobo_object_from_servant (servant));
81   retval = atk_component_contains (ATK_COMPONENT (component->atko), (gint) x, (gint) y,
82                                   (AtkCoordType) coord_type);
83   fprintf (stderr, "Component contains() called: %s\n", retval ? "true" : "false" );
84   return retval;
85 }
86
87 /*
88  * CORBA Accessibility::Component::getAccessibleAtPoint method implementation
89  */
90 static Accessibility_Accessible
91 impl_accessibility_component_get_accessible_at_point (PortableServer_Servant servant,
92                                                       const CORBA_long x,
93                                                       const CORBA_long y,
94                                                       CORBA_short coord_type,
95                                                       CORBA_Environment     *ev)
96 {
97   Accessibility_Accessible retval;
98   Component *component = COMPONENT (bonobo_object_from_servant (servant));
99   AtkObject *child;
100   child = atk_component_ref_accessible_at_point (ATK_COMPONENT (component->atko),
101                                                   (gint) x, (gint) y,
102                                                   (AtkCoordType) coord_type);
103   retval = bonobo_object_corba_objref (bonobo_object (accessible_new (child)));
104   return retval;
105 }
106
107 /*
108  * CORBA Accessibility::Component::getExtents method implementation
109  */
110 static void
111 impl_accessibility_component_get_extents (PortableServer_Servant servant,
112                                           CORBA_long * x,
113                                           CORBA_long * y,
114                                           CORBA_long * width,
115                                           CORBA_long * height,
116                                           const CORBA_short coord_type,
117                                           CORBA_Environment     *ev)
118 {
119   Component *component = COMPONENT (bonobo_object_from_servant (servant));
120   gint ix, iy, iw, ih;
121   atk_component_get_extents (ATK_COMPONENT (component->atko), &ix, &iy, &iw, &ih,
122                                   (AtkCoordType) coord_type);
123   *x = (CORBA_long) ix;
124   *y = (CORBA_long) iy;
125   *width = (CORBA_long) iw;
126   *height = (CORBA_long) ih;
127 }
128
129 /*
130  * CORBA Accessibility::Component::getPosition method implementation
131  */
132 static void
133 impl_accessibility_component_get_position (PortableServer_Servant servant,
134                                            CORBA_long * x,
135                                            CORBA_long * y,
136                                            const CORBA_short coord_type,
137                                            CORBA_Environment     *ev)
138 {
139   Component *component = COMPONENT (bonobo_object_from_servant (servant));
140   gint ix, iy;
141   atk_component_get_position (ATK_COMPONENT (component->atko), &ix, &iy,
142                               (AtkCoordType) coord_type);
143   *x = (CORBA_long) ix;
144   *y = (CORBA_long) iy;
145 }
146
147 /*
148  * CORBA Accessibility::Component::getSize method implementation
149  */
150 static void
151 impl_accessibility_component_get_size (PortableServer_Servant servant,
152                                        CORBA_long * width,
153                                        CORBA_long * height,
154                                        CORBA_Environment     *ev)
155 {
156   Component *component = COMPONENT (bonobo_object_from_servant (servant));
157   gint iw, ih;
158   atk_component_get_size (ATK_COMPONENT (component->atko), &iw, &ih);
159   *width = (CORBA_long) iw;
160   *height = (CORBA_long) ih;
161 }
162
163 static void
164 accessibility_component_class_init (ComponentClass *klass)
165 {
166         GObjectClass * object_class = (GObjectClass *) klass;
167         POA_Accessibility_Component__epv *epv = &klass->epv;
168         component_parent_class = g_type_class_peek_parent (klass);
169
170         object_class->finalize = accessibility_component_object_finalize;
171
172         epv->contains = impl_accessibility_component_contains;
173         epv->getAccessibleAtPoint = impl_accessibility_component_get_accessible_at_point;
174         epv->getExtents = impl_accessibility_component_get_extents;
175         epv->getPosition = impl_accessibility_component_get_position;
176         epv->getSize = impl_accessibility_component_get_size;
177 }
178
179 static void
180 accessibility_component_init (Component *component)
181 {
182 }
183
184 GType
185 accessibility_component_get_type (void)
186 {
187         static GType type = 0;
188
189         if (!type) {
190                 static const GTypeInfo tinfo = {
191                         sizeof (ComponentClass),
192                         (GBaseInitFunc) NULL,
193                         (GBaseFinalizeFunc) NULL,
194                         (GClassInitFunc) accessibility_component_class_init,
195                         (GClassFinalizeFunc) NULL,
196                         NULL, /* class data */
197                         sizeof (Component),
198                         0, /* n preallocs */
199                         (GInstanceInitFunc) accessibility_component_init,
200                         NULL /* value table */
201                 };
202                 /*
203                  * Bonobo_type_unique auto-generates a load of
204                  * CORBA structures for us. All derived types must
205                  * use bonobo_type_unique.
206                  */
207                 type = bonobo_type_unique (
208                         PARENT_TYPE,
209                         POA_Accessibility_Component__init,
210                         NULL,
211                         G_STRUCT_OFFSET (ComponentClass, epv),
212                         &tinfo,
213                         "AccessibleComponent");
214         }
215
216         return type;
217 }
218
219 Component *
220 component_interface_new (AtkObject *o)
221 {
222     Component *retval =
223                COMPONENT (g_object_new (accessibility_component_get_type (), NULL));
224     retval->atko = o;
225     g_object_ref (o);
226 return retval;
227 }