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"
52 * Our parent Gtk object type
54 #define PARENT_TYPE BONOBO_OBJECT_TYPE
57 * A pointer to our parent object class
59 static GObjectClass *accessible_parent_class;
62 * Implemented GObject::finalize
65 accessible_object_finalize (GObject *object)
67 Accessible *accessible = ACCESSIBLE (object);
69 printf("accessible_object_finalize called\n");
70 g_object_unref (accessible->atko);
71 accessible->atko = NULL;
73 printf("atko freed, calling parent finalize\n");
74 accessible_parent_class->finalize (object);
78 * CORBA Accessibility::Accessible::get_name method implementation
81 impl_accessibility_accessible_get_name (PortableServer_Servant servant,
82 CORBA_Environment *ev)
85 Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
86 retval = (CORBA_char *) atk_object_get_name (accessible->atko);
88 retval = CORBA_string_dup (retval);
90 retval = CORBA_string_dup ("");
91 fprintf (stderr, "Accessible get_name called: %s\n", retval);
96 * CORBA Accessibility::Accessible::set_name method implementation
99 impl_accessibility_accessible_set_name (PortableServer_Servant servant,
100 const CORBA_char *name,
101 CORBA_Environment *ev)
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);
109 * CORBA Accessibility::Accessible::get_description method implementation
112 impl_accessibility_accessible_get_description (PortableServer_Servant servant,
113 CORBA_Environment *ev)
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);
123 * CORBA Accessibility::Accessible::set_description method implementation
126 impl_accessibility_accessible_set_description (PortableServer_Servant servant,
127 const CORBA_char *name,
128 CORBA_Environment *ev)
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);
136 * CORBA Accessibility::Accessible::get_parent method implementation
138 static Accessibility_Accessible
139 impl_accessibility_accessible_get_parent (PortableServer_Servant servant,
140 CORBA_Environment *ev)
142 Accessibility_Accessible retval;
143 Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
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");
152 * CORBA Accessibility::Accessible::get_IndexInParent method implementation
155 impl_accessibility_accessible_get_index_in_parent (PortableServer_Servant servant,
156 CORBA_Environment *ev)
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");
166 * CORBA Accessibility::Accessible::get_childCount method implementation
169 impl_accessibility_accessible_get_child_count (PortableServer_Servant servant,
170 CORBA_Environment *ev)
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);
180 * CORBA Accessibility::Accessible::getChildAtIndex method implementation
182 static Accessibility_Accessible
183 impl_accessibility_accessible_get_child_at_index (PortableServer_Servant servant,
184 const CORBA_long index,
185 CORBA_Environment *ev)
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");
196 * CORBA Accessibility::Accessible::getRole method implementation
198 static Accessibility_Role
199 impl_accessibility_accessible_get_role (PortableServer_Servant servant,
200 const CORBA_long index,
201 CORBA_Environment *ev)
203 Accessibility_Role retval;
204 Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
205 AtkRole role = atk_object_get_role (accessible->atko);
207 printf ("Accessible get_role.\n");
208 return (Accessibility_Role) retval;
212 accessible_class_init (AccessibleClass *klass)
214 GObjectClass * object_class = (GObjectClass *) klass;
215 POA_Accessibility_Accessible__epv *epv = &klass->epv;
216 accessible_parent_class = g_type_class_peek_parent (klass);
218 object_class->finalize = accessible_object_finalize;
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;
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;
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;
236 accessible_init (Accessible *accessible)
241 accessible_get_type (void)
243 static GType type = 0;
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 */
255 (GInstanceInitFunc) accessible_init,
256 NULL /* value table */
259 * Bonobo_type_unique auto-generates a load of
260 * CORBA structures for us. All derived types must
261 * use bonobo_type_unique.
263 type = bonobo_type_unique (
265 POA_Accessibility_Accessible__init,
267 G_STRUCT_OFFSET (AccessibleClass, epv),
276 accessible_new (AtkObject *o)
279 ACCESSIBLE (g_object_new (accessible_get_type (), NULL));
281 retval->atko = ATK_OBJECT (o);
284 * TODO: add interface containers/constructors for EDITABLE_TEXT, HYPERTEXT,
285 * IMAGE, SELECTION, TABLE, TEXT, VALUE.
288 /* add appropriate ATK interfaces */
290 if (ATK_IS_ACTION (o))
292 bonobo_object_add_interface (bonobo_object (retval),
293 BONOBO_OBJECT (action_interface_new (o)));
296 if (ATK_IS_COMPONENT (o))
298 bonobo_object_add_interface (bonobo_object (retval),
299 BONOBO_OBJECT (component_interface_new (o)));
302 if (ATK_IS_EDITABLE_TEXT (o))
304 bonobo_object_add_interface (bonobo_object (retval),
305 BONOBO_OBJECT(editable_text_interface_new (o)));
308 else if (ATK_IS_HYPERTEXT (o))
310 bonobo_object_add_interface (bonobo_object (retval),
311 BONOBO_OBJECT (hypertext_interface_new (o)));
314 else if (ATK_IS_TEXT (o))
316 bonobo_object_add_interface (bonobo_object (retval),
317 BONOBO_OBJECT (text_interface_new (o)));
320 if (ATK_IS_HYPERLINK (o))
322 bonobo_object_add_interface (bonobo_object (retval),
323 BONOBO_OBJECT (hyperlink_interface_new(o)));
326 if (ATK_IS_IMAGE (o))
328 bonobo_object_add_interface (bonobo_object (retval),
329 BONOBO_OBJECT (image_interface_new (o)));
332 if (ATK_IS_SELECTION (o))
334 bonobo_object_add_interface (bonobo_object (retval),
335 BONOBO_OBJECT (selection_interface_new (o)));
338 if (ATK_IS_TABLE (o))
340 bonobo_object_add_interface (bonobo_object (retval),
341 BONOBO_OBJECT (table_interface_new (o)));
344 if (ATK_IS_VALUE (o))
346 bonobo_object_add_interface (bonobo_object (retval),
347 BONOBO_OBJECT (value_interface_new (o)));