c035bed1735611553b5fa272c355c0340e16dbee
[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         component->atko = NULL;
63
64         printf("atko freed, calling parent finalize\n");
65         component_parent_class->finalize (object);
66 }
67
68 /*
69  * CORBA Accessibility::Component::contains method implementation
70  */
71 static CORBA_boolean
72 impl_accessibility_component_contains (PortableServer_Servant servant,
73                                        const CORBA_long x,
74                                        const CORBA_long y,
75                                        CORBA_short coord_type,
76                                        CORBA_Environment     *ev)
77 {
78   CORBA_boolean retval;
79   Component *component = COMPONENT (bonobo_object_from_servant (servant));
80   retval = atk_component_contains (ATK_COMPONENT (component->atko), (gint) x, (gint) y,
81                                   (AtkCoordType) coord_type);
82   fprintf (stderr, "Component contains() called: %s\n", retval ? "true" : "false" );
83   return retval;
84 }
85
86 /*
87  * CORBA Accessibility::Component::getAccessibleAtPoint method implementation
88  */
89 static Accessibility_Accessible
90 impl_accessibility_component_get_accessible_at_point (PortableServer_Servant servant,
91                                                       const CORBA_long x,
92                                                       const CORBA_long y,
93                                                       CORBA_short coord_type,
94                                                       CORBA_Environment     *ev)
95 {
96   Accessibility_Accessible retval;
97   Component *component = COMPONENT (bonobo_object_from_servant (servant));
98   AtkObject *child;
99   child = atk_component_ref_accessible_at_point (ATK_COMPONENT (component->atko),
100                                                   (gint) x, (gint) y,
101                                                   (AtkCoordType) coord_type);
102   retval = bonobo_object_corba_objref (bonobo_object (accessible_new (child)));
103   return retval;
104 }
105
106 /*
107  * CORBA Accessibility::Component::getExtents method implementation
108  */
109 static void
110 impl_accessibility_component_get_extents (PortableServer_Servant servant,
111                                           CORBA_long * x,
112                                           CORBA_long * y,
113                                           CORBA_long * width,
114                                           CORBA_long * height,
115                                           const CORBA_short coord_type,
116                                           CORBA_Environment     *ev)
117 {
118   Component *component = COMPONENT (bonobo_object_from_servant (servant));
119   gint ix, iy, iw, ih;
120   atk_component_get_extents (ATK_COMPONENT (component->atko), &ix, &iy, &iw, &ih,
121                                   (AtkCoordType) coord_type);
122   *x = (CORBA_long) ix;
123   *y = (CORBA_long) iy;
124   *width = (CORBA_long) iw;
125   *height = (CORBA_long) ih;
126 }
127
128 /*
129  * CORBA Accessibility::Component::getPosition method implementation
130  */
131 static void
132 impl_accessibility_component_get_position (PortableServer_Servant servant,
133                                            CORBA_long * x,
134                                            CORBA_long * y,
135                                            const CORBA_short coord_type,
136                                            CORBA_Environment     *ev)
137 {
138   Component *component = COMPONENT (bonobo_object_from_servant (servant));
139   gint ix, iy;
140   atk_component_get_position (ATK_COMPONENT (component->atko), &ix, &iy,
141                               (AtkCoordType) coord_type);
142   *x = (CORBA_long) ix;
143   *y = (CORBA_long) iy;
144 }
145
146 /*
147  * CORBA Accessibility::Component::getSize method implementation
148  */
149 static void
150 impl_accessibility_component_get_size (PortableServer_Servant servant,
151                                        CORBA_long * width,
152                                        CORBA_long * height,
153                                        CORBA_Environment     *ev)
154 {
155   Component *component = COMPONENT (bonobo_object_from_servant (servant));
156   gint iw, ih;
157   atk_component_get_size (ATK_COMPONENT (component->atko), &iw, &ih);
158   *width = (CORBA_long) iw;
159   *height = (CORBA_long) ih;
160 }
161
162 static void
163 accessibility_component_class_init (ComponentClass *klass)
164 {
165         GObjectClass * object_class = (GObjectClass *) klass;
166         POA_Accessibility_Component__epv *epv = &klass->epv;
167         component_parent_class = g_type_class_peek_parent (klass);
168
169         object_class->finalize = accessibility_component_object_finalize;
170
171         epv->contains = impl_accessibility_component_contains;
172         epv->getAccessibleAtPoint = impl_accessibility_component_get_accessible_at_point;
173         epv->getExtents = impl_accessibility_component_get_extents;
174         epv->getPosition = impl_accessibility_component_get_position;
175         epv->getSize = impl_accessibility_component_get_size;
176 }
177
178 static void
179 accessibility_component_init (Component *component)
180 {
181 }
182
183 GType
184 accessibility_component_get_type (void)
185 {
186         static GType type = 0;
187
188         if (!type) {
189                 static const GTypeInfo tinfo = {
190                         sizeof (ComponentClass),
191                         (GBaseInitFunc) NULL,
192                         (GBaseFinalizeFunc) NULL,
193                         (GClassInitFunc) accessibility_component_class_init,
194                         (GClassFinalizeFunc) NULL,
195                         NULL, /* class data */
196                         sizeof (Component),
197                         0, /* n preallocs */
198                         (GInstanceInitFunc) accessibility_component_init,
199                         NULL /* value table */
200                 };
201                 /*
202                  * Bonobo_type_unique auto-generates a load of
203                  * CORBA structures for us. All derived types must
204                  * use bonobo_type_unique.
205                  */
206                 type = bonobo_type_unique (
207                         PARENT_TYPE,
208                         POA_Accessibility_Component__init,
209                         NULL,
210                         G_STRUCT_OFFSET (ComponentClass, epv),
211                         &tinfo,
212                         "AccessibleComponent");
213         }
214
215         return type;
216 }
217
218 Component *
219 component_interface_new (AtkObject *o)
220 {
221     Component *retval =
222                COMPONENT (g_object_new (accessibility_component_get_type (), NULL));
223     /* don't increment AtkObject refcount, ref is held by containing Accessible instance */
224     retval->atko = ATK_OBJECT (o);
225     return retval;
226 }