2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
24 * accessible.c: test for accessibility implementation
28 #include <bonobo/Bonobo.h>
33 * This pulls the CORBA definitions for the "Accessibility::Accessible" server
35 #include <libspi/Accessibility.h>
38 * This pulls the definition for the BonoboObject (Gtk Type)
40 #include "accessible.h"
41 #include "component.h"
42 #include "editabletext.h"
43 #include "hyperlink.h"
44 #include "hypertext.h"
46 #include "selection.h"
53 * Our parent Gtk object type
55 #define PARENT_TYPE BONOBO_OBJECT_TYPE
58 * A pointer to our parent object class
60 static GObjectClass *spi_accessible_parent_class;
63 * Implemented GObject::finalize
66 spi_accessible_object_finalize (GObject *object)
68 SpiAccessible *accessible = SPI_ACCESSIBLE (object);
70 printf("spi_accessible_object_finalize called\n");
71 ATK_OBJECT (accessible->atko); /* assertion */
72 g_object_unref (G_OBJECT(accessible->atko));
73 accessible->atko = NULL;
75 printf("atko freed, calling parent finalize\n");
76 spi_accessible_parent_class->finalize (object);
80 * CORBA Accessibility::Accessible::get_name method implementation
83 impl_accessibility_accessible_get_name (PortableServer_Servant servant,
84 CORBA_Environment *ev)
87 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
88 retval = (CORBA_char *) atk_object_get_name (accessible->atko);
90 retval = CORBA_string_dup (retval);
92 retval = CORBA_string_dup ("");
98 * CORBA Accessibility::Accessible::set_name method implementation
101 impl_accessibility_accessible_set_name (PortableServer_Servant servant,
102 const CORBA_char *name,
103 CORBA_Environment *ev)
105 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
106 atk_object_set_name (accessible->atko, name);
107 printf ("SpiAccessible set_name called: %s\n", name);
111 * CORBA Accessibility::Accessible::get_description method implementation
114 impl_accessibility_accessible_get_description (PortableServer_Servant servant,
115 CORBA_Environment *ev)
118 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
119 retval = CORBA_string_dup (atk_object_get_description (accessible->atko));
121 retval = CORBA_string_dup (retval);
123 retval = CORBA_string_dup ("");
129 * CORBA Accessibility::Accessible::set_description method implementation
132 impl_accessibility_accessible_set_description (PortableServer_Servant servant,
133 const CORBA_char *name,
134 CORBA_Environment *ev)
136 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
137 atk_object_set_description (accessible->atko, name);
138 printf ("SpiAccessible set_description called: %s\n", name);
142 * CORBA Accessibility::Accessible::get_parent method implementation
144 static Accessibility_Accessible
145 impl_accessibility_accessible_get_parent (PortableServer_Servant servant,
146 CORBA_Environment *ev)
148 Accessibility_Accessible retval;
149 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
152 parent = atk_object_get_parent (accessible->atko);
153 retval = BONOBO_OBJREF (spi_accessible_new (parent));
155 printf ("SpiAccessible get_parent called\n");
157 return CORBA_Object_duplicate (retval, ev);
161 * CORBA Accessibility::Accessible::get_IndexInParent method implementation
164 impl_accessibility_accessible_get_index_in_parent (PortableServer_Servant servant,
165 CORBA_Environment *ev)
168 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
169 retval = (CORBA_long) atk_object_get_index_in_parent (accessible->atko);
170 printf ("SpiAccessible get_index_in_parent called\n");
175 * CORBA Accessibility::Accessible::get_childCount method implementation
178 impl_accessibility_accessible_get_child_count (PortableServer_Servant servant,
179 CORBA_Environment *ev)
182 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
183 retval = (CORBA_long) atk_object_get_n_accessible_children (accessible->atko);
184 printf ("SpiAccessible get_childCount called: %d\n", (int) retval);
189 * CORBA Accessibility::Accessible::getChildAtIndex method implementation
191 static Accessibility_Accessible
192 impl_accessibility_accessible_get_child_at_index (PortableServer_Servant servant,
193 const CORBA_long index,
194 CORBA_Environment *ev)
196 Accessibility_Accessible retval;
197 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
198 AtkObject *child = atk_object_ref_accessible_child (accessible->atko, (gint) index);
199 retval = BONOBO_OBJREF (spi_accessible_new (child));
200 printf ("SpiAccessible get_child_at_index called.\n");
201 return CORBA_Object_duplicate (retval, ev);
205 * CORBA Accessibility::Accessible::getState method implementation
207 static Accessibility_StateSet
208 impl_accessibility_accessible_get_state (PortableServer_Servant servant,
209 CORBA_Environment *ev)
211 Accessibility_StateSet retval;
212 /* SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
213 AtkStateSet *state = atk_object_ref_state_set (accessible->atko); */
214 retval = CORBA_OBJECT_NIL;
215 printf ("SpiAccessible get_state.\n");
216 /* TODO: implement the bonobo stateset class */
217 return (Accessibility_StateSet) retval;
221 * CORBA Accessibility::Accessible::getRelationSet method implementation
223 static Accessibility_RelationSet *
224 impl_accessibility_accessible_get_relation_set (PortableServer_Servant servant,
225 CORBA_Environment *ev)
227 Accessibility_RelationSet *retval;
228 /* SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
229 AtkRelationSet *relation_set = atk_object_ref_relation_set (accessible->atko); */
230 retval = CORBA_sequence_Accessibility_Relation__alloc ();
232 * TODO: fill the sequence with relation set objects, themselves
233 * initialized from the AtkRelation object in the AtkRelationSet.
235 printf ("SpiAccessible get_relation_set.\n");
240 * CORBA Accessibility::Accessible::getRole method implementation
242 static Accessibility_Role
243 impl_accessibility_accessible_get_role (PortableServer_Servant servant,
244 CORBA_Environment *ev)
246 Accessibility_Role retval;
247 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
248 AtkRole role = atk_object_get_role (accessible->atko);
250 printf ("SpiAccessible get_role.\n");
251 return (Accessibility_Role) retval;
255 spi_accessible_class_init (SpiAccessibleClass *klass)
257 GObjectClass * object_class = (GObjectClass *) klass;
258 POA_Accessibility_Accessible__epv *epv = &klass->epv;
259 spi_accessible_parent_class = g_type_class_peek_parent (klass);
261 object_class->finalize = spi_accessible_object_finalize;
263 epv->_get_name = impl_accessibility_accessible_get_name;
264 epv->_set_name = impl_accessibility_accessible_set_name;
265 epv->_get_description = impl_accessibility_accessible_get_description;
266 epv->_set_description = impl_accessibility_accessible_set_description;
268 epv->_get_parent = impl_accessibility_accessible_get_parent;
269 epv->_get_childCount = impl_accessibility_accessible_get_child_count;
270 epv->getChildAtIndex = impl_accessibility_accessible_get_child_at_index;
271 epv->getIndexInParent = impl_accessibility_accessible_get_index_in_parent;
273 epv->getRelationSet = impl_accessibility_accessible_get_relation_set;
274 epv->getState = impl_accessibility_accessible_get_state;
275 epv->getRole = impl_accessibility_accessible_get_role;
279 spi_accessible_init (SpiAccessible *accessible)
284 spi_accessible_get_type (void)
286 static GType type = 0;
289 static const GTypeInfo tinfo = {
290 sizeof (SpiAccessibleClass),
291 (GBaseInitFunc) NULL,
292 (GBaseFinalizeFunc) NULL,
293 (GClassInitFunc) spi_accessible_class_init,
294 (GClassFinalizeFunc) NULL,
295 NULL, /* class data */
296 sizeof (SpiAccessible),
298 (GInstanceInitFunc) spi_accessible_init,
299 NULL /* value table */
302 * Bonobo_type_unique auto-generates a load of
303 * CORBA structures for us. All derived types must
304 * use bonobo_type_unique.
306 type = bonobo_type_unique (
308 POA_Accessibility_Accessible__init,
310 G_STRUCT_OFFSET (SpiAccessibleClass, epv),
319 spi_accessible_new (AtkObject *o)
321 SpiAccessible *retval =
322 SPI_ACCESSIBLE (g_object_new (spi_accessible_get_type (), NULL));
323 CORBA_Environment ev;
324 CORBA_exception_init (&ev);
326 retval->atko = ATK_OBJECT (o);
329 * TODO: add interface containers/constructors for SPI_EDITABLE_TEXT, SPI_HYPERTEXT,
330 * SPI_IMAGE, SPI_SELECTION, SPI_TABLE, SPI_TEXT, SPI_VALUE.
333 /* add appropriate ATK interfaces */
335 if (ATK_IS_ACTION (o))
337 bonobo_object_add_interface (bonobo_object (retval),
338 BONOBO_OBJECT (spi_action_interface_new (o)));
341 if (ATK_IS_COMPONENT (o))
343 bonobo_object_add_interface (bonobo_object (retval),
344 BONOBO_OBJECT (spi_component_interface_new (o)));
347 if (ATK_IS_EDITABLE_TEXT (o))
349 bonobo_object_add_interface (bonobo_object (retval),
350 BONOBO_OBJECT(spi_editable_text_interface_new (o)));
353 else if (ATK_IS_HYPERTEXT (o))
355 bonobo_object_add_interface (bonobo_object (retval),
356 BONOBO_OBJECT (spi_hypertext_interface_new (o)));
359 else if (ATK_IS_TEXT (o))
361 bonobo_object_add_interface (bonobo_object (retval),
362 BONOBO_OBJECT (spi_text_interface_new (o)));
365 if (ATK_IS_IMAGE (o))
367 bonobo_object_add_interface (bonobo_object (retval),
368 BONOBO_OBJECT (spi_image_interface_new (o)));
371 if (ATK_IS_SELECTION (o))
373 bonobo_object_add_interface (bonobo_object (retval),
374 BONOBO_OBJECT (spi_selection_interface_new (o)));
377 if (ATK_IS_TABLE (o))
379 bonobo_object_add_interface (bonobo_object (retval),
380 BONOBO_OBJECT (spi_table_interface_new (o)));
383 if (ATK_IS_VALUE (o))
385 bonobo_object_add_interface (bonobo_object (retval),
386 BONOBO_OBJECT (spi_value_interface_new (o)));