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