e811ef41cb9d4beb3ca25c9257726dee09eafb06
[platform/core/uifw/at-spi2-atk.git] / libspi / accessible.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  * accessible.c: test for accessibility 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 "accessible.h"
41
42 /*
43  * Our parent Gtk object type
44  */
45 #define PARENT_TYPE BONOBO_OBJECT_TYPE
46
47 /*
48  * A pointer to our parent object class
49  */
50 static GObjectClass *accessible_parent_class;
51
52 /*
53  * Implemented GObject::finalize
54  */
55 static void
56 accessible_object_finalize (GObject *object)
57 {
58         Accessible *accessible = ACCESSIBLE (object);
59
60         printf("accessible_object_finalize called\n");
61         g_object_unref (accessible->atko);
62         accessible->atko = NULL;
63
64         printf("atko freed, calling parent finalize\n");
65         accessible_parent_class->finalize (object);
66 }
67
68 /*
69  * CORBA Accessibility::Accessible::get_name method implementation
70  */
71 static CORBA_char *
72 impl_accessibility_accessible_get_name (PortableServer_Servant servant,
73                                         CORBA_Environment     *ev)
74 {
75   CORBA_char * retval;
76   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
77   retval = atk_object_get_name (accessible->atko);
78   if (retval )
79     retval = CORBA_string_dup (retval);
80   else
81     retval = CORBA_string_dup ("");
82   fprintf (stderr, "Accessible get_name called: %s\n", retval);
83   return retval;
84 }
85
86 /*
87  * CORBA Accessibility::Accessible::set_name method implementation
88  */
89 static void
90 impl_accessibility_accessible_set_name (PortableServer_Servant servant,
91                                         const CORBA_char      *name,
92                                         CORBA_Environment     *ev)
93 {
94   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
95   atk_object_set_name (accessible->atko, name);
96   printf ("Accessible set_name called: %s\n", name);
97 }
98
99 /*
100  * CORBA Accessibility::Accessible::get_description method implementation
101  */
102 static CORBA_char *
103 impl_accessibility_accessible_get_description (PortableServer_Servant servant,
104                                                CORBA_Environment     *ev)
105 {
106   CORBA_char * retval;
107   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
108   retval = CORBA_string_dup (atk_object_get_description (accessible->atko));
109   fprintf (stderr, "Accessible get_description called: %s\n", retval);
110   return retval;
111 }
112
113 /*
114  * CORBA Accessibility::Accessible::set_description method implementation
115  */
116 static void
117 impl_accessibility_accessible_set_description (PortableServer_Servant servant,
118                                                const CORBA_char      *name,
119                                                CORBA_Environment     *ev)
120 {
121   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
122   atk_object_set_description (accessible->atko, name);
123   printf ("Accessible set_description called: %s\n", name);
124 }
125
126 /*
127  * CORBA Accessibility::Accessible::get_parent method implementation
128  */
129 static Accessibility_Accessible
130 impl_accessibility_accessible_get_parent (PortableServer_Servant servant,
131                                           CORBA_Environment     *ev)
132 {
133   Accessibility_Accessible retval;
134   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
135   AtkObject *parent;
136   parent = atk_object_get_parent (accessible->atko);
137   retval = bonobo_object_corba_objref (bonobo_object (accessible_new (parent)));
138   printf ("Accessible get_parent called\n");
139   return retval;
140 }
141
142 /*
143  * CORBA Accessibility::Accessible::get_IndexInParent method implementation
144  */
145 static CORBA_long
146 impl_accessibility_accessible_get_index_in_parent (PortableServer_Servant servant,
147                                                    CORBA_Environment     *ev)
148 {
149   CORBA_long retval;
150   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
151   retval = (CORBA_long) atk_object_get_index_in_parent (accessible->atko);
152   printf ("Accessible get_index_in_parent called\n");
153   return retval;
154 }
155
156 /*
157  * CORBA Accessibility::Accessible::get_childCount method implementation
158  */
159 static CORBA_long
160 impl_accessibility_accessible_get_child_count (PortableServer_Servant servant,
161                                                CORBA_Environment     *ev)
162 {
163   CORBA_long retval;
164   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
165   retval = (CORBA_long) atk_object_get_n_accessible_children (accessible->atko);
166   printf ("Accessible get_childCount called: %d\n", (int) retval);
167   return retval;
168 }
169
170 /*
171  * CORBA Accessibility::Accessible::getChildAtIndex method implementation
172  */
173 static Accessibility_Accessible
174 impl_accessibility_accessible_get_child_at_index (PortableServer_Servant servant,
175                                                   const CORBA_long      index,
176                                                   CORBA_Environment     *ev)
177 {
178   Accessibility_Accessible retval;
179   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
180   AtkObject *child = atk_object_ref_accessible_child (accessible->atko, (gint) index);
181   retval = bonobo_object_corba_objref ( bonobo_object (accessible_new (child)));
182   printf ("Accessible get_child_at_index called.\n");
183   return retval;
184 }
185
186 static void
187 accessible_class_init (AccessibleClass *klass)
188 {
189         GObjectClass * object_class = (GObjectClass *) klass;
190         POA_Accessibility_Accessible__epv *epv = &klass->epv;
191         accessible_parent_class = g_type_class_peek_parent (klass);
192
193         object_class->finalize = accessible_object_finalize;
194
195         epv->_get_name = impl_accessibility_accessible_get_name;
196         epv->_set_name = impl_accessibility_accessible_set_name;
197         epv->_get_description = impl_accessibility_accessible_get_description;
198         epv->_set_description = impl_accessibility_accessible_set_description;
199
200         epv->_get_parent = impl_accessibility_accessible_get_parent;
201         epv->_get_childCount = impl_accessibility_accessible_get_child_count;
202         epv->getChildAtIndex = impl_accessibility_accessible_get_child_at_index;
203         epv->getIndexInParent = impl_accessibility_accessible_get_index_in_parent;
204
205         /* epv->getRelationSet = impl_accessibility_accessible_get_relation_set;      */
206         /* epv->getState = impl_accessibility_accessible_get_state;                   */
207         /* epv->getRole = impl_accessibility_accessible_get_role;                     */
208 }
209
210 static void
211 accessible_init (Accessible *accessible)
212 {
213 }
214
215 GType
216 accessible_get_type (void)
217 {
218         static GType type = 0;
219
220         if (!type) {
221                 static const GTypeInfo tinfo = {
222                         sizeof (AccessibleClass),
223                         (GBaseInitFunc) NULL,
224                         (GBaseFinalizeFunc) NULL,
225                         (GClassInitFunc) accessible_class_init,
226                         (GClassFinalizeFunc) NULL,
227                         NULL, /* class data */
228                         sizeof (Accessible),
229                         0, /* n preallocs */
230                         (GInstanceInitFunc) accessible_init,
231                         NULL /* value table */
232                 };
233                 /*
234                  * Bonobo_type_unique auto-generates a load of
235                  * CORBA structures for us. All derived types must
236                  * use bonobo_type_unique.
237                  */
238                 type = bonobo_type_unique (
239                         PARENT_TYPE,
240                         POA_Accessibility_Accessible__init,
241                         NULL,
242                         G_STRUCT_OFFSET (AccessibleClass, epv),
243                         &tinfo,
244                         "Accessible");
245         }
246
247         return type;
248 }
249
250 Accessible *
251 accessible_new (AtkObject *o)
252 {
253     Accessible *retval =
254                ACCESSIBLE (g_object_new (accessible_get_type (), NULL));
255     g_object_ref (o);
256     retval->atko = ATK_OBJECT (o);
257
258     /*
259      * TODO: add interface containers/constructors for EDITABLE_TEXT, HYPERTEXT,
260      *  IMAGE, SELECTION, TABLE, TEXT, VALUE.
261      */
262
263     /* add appropriate ATK interfaces */
264
265     if (ATK_IS_ACTION (o))
266       {
267         bonobo_object_add_interface (bonobo_object (retval),
268                                      bonobo_object (action_new (ATK_ACTION(o))));
269       }
270
271     if (ATK_IS_COMPONENT (o))
272       {
273         bonobo_object_add_interface (bonobo_object (retval),
274                                      bonobo_object (component_interface_new (o)));
275       }
276
277     if (ATK_IS_EDITABLE_TEXT (o))
278       {
279         bonobo_object_add_interface (bonobo_object (retval),
280                                      bonobo_object (editable_text_new (ATK_EDITABLE_TEXT(o))));
281       }
282
283     else if (ATK_IS_HYPERTEXT (o))
284       {
285         bonobo_object_add_interface (bonobo_object (retval),
286                                      bonobo_object (hypertext_new (o)));
287       }
288
289     else if (ATK_IS_TEXT (o))
290       {
291         bonobo_object_add_interface (bonobo_object (retval),
292                                      bonobo_object (text_new (o)));
293       }
294
295     if (ATK_IS_HYPERLINK (o))
296       {
297         bonobo_object_add_interface (bonobo_object (retval),
298                                      bonobo_object (hyperlink_new(ATK_HYPERLINK(o))));
299       }
300
301     if (ATK_IS_IMAGE (o))
302       {
303         bonobo_object_add_interface (bonobo_object (retval),
304                                      bonobo_object (image_new (o)));
305       }
306
307     if (ATK_IS_SELECTION (o))
308       {
309         bonobo_object_add_interface (bonobo_object (retval),
310                                      bonobo_object (selection_new (o)));
311       }
312
313     if (ATK_IS_TABLE (o))
314       {
315         bonobo_object_add_interface (bonobo_object (retval),
316                                      bonobo_object (table_new (o)));
317       }
318
319     /* if (ATK_IS_VALUE (o))
320       {
321         bonobo_object_add_interface (bonobo_object (retval),
322                                      bonobo_object (value_interface_new (o)));
323       }
324
325     */
326
327     return retval;
328 }