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.
23 /* accessible.c: the core of the accessibility implementation */
27 #include <libspi/libspi.h>
29 /* Our parent Gtk object type */
30 #define PARENT_TYPE BONOBO_TYPE_OBJECT
32 /* A pointer to our parent object class */
33 static GObjectClass *spi_accessible_parent_class;
36 * Implemented GObject::finalize
39 spi_accessible_object_finalize (GObject *object)
41 SpiAccessible *accessible = SPI_ACCESSIBLE (object);
43 ATK_OBJECT (accessible->atko); /* assertion */
44 g_object_unref (G_OBJECT(accessible->atko));
45 accessible->atko = NULL;
47 spi_accessible_parent_class->finalize (object);
51 * CORBA Accessibility::Accessible::get_name method implementation
54 impl_accessibility_accessible_get_name (PortableServer_Servant servant,
55 CORBA_Environment *ev)
58 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
59 retval = (CORBA_char *) atk_object_get_name (accessible->atko);
61 retval = CORBA_string_dup (retval);
63 retval = CORBA_string_dup ("");
69 * CORBA Accessibility::Accessible::set_name method implementation
72 impl_accessibility_accessible_set_name (PortableServer_Servant servant,
73 const CORBA_char *name,
74 CORBA_Environment *ev)
76 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
77 atk_object_set_name (accessible->atko, name);
78 printf ("SpiAccessible set_name called: %s\n", name);
82 * CORBA Accessibility::Accessible::get_description method implementation
85 impl_accessibility_accessible_get_description (PortableServer_Servant servant,
86 CORBA_Environment *ev)
89 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
90 retval = CORBA_string_dup (atk_object_get_description (accessible->atko));
92 retval = CORBA_string_dup (retval);
94 retval = CORBA_string_dup ("");
100 * CORBA Accessibility::Accessible::set_description method implementation
103 impl_accessibility_accessible_set_description (PortableServer_Servant servant,
104 const CORBA_char *name,
105 CORBA_Environment *ev)
107 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
108 atk_object_set_description (accessible->atko, name);
109 printf ("SpiAccessible set_description called: %s\n", name);
113 * CORBA Accessibility::Accessible::get_parent method implementation
115 static Accessibility_Accessible
116 impl_accessibility_accessible_get_parent (PortableServer_Servant servant,
117 CORBA_Environment *ev)
119 Accessibility_Accessible retval;
120 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
123 parent = atk_object_get_parent (accessible->atko);
124 retval = BONOBO_OBJREF (spi_accessible_new (parent));
126 return bonobo_object_dup_ref (retval, ev);
130 * CORBA Accessibility::Accessible::get_IndexInParent method implementation
133 impl_accessibility_accessible_get_index_in_parent (PortableServer_Servant servant,
134 CORBA_Environment *ev)
137 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
138 retval = (CORBA_long) atk_object_get_index_in_parent (accessible->atko);
139 printf ("SpiAccessible get_index_in_parent called\n");
144 * CORBA Accessibility::Accessible::get_childCount method implementation
147 impl_accessibility_accessible_get_child_count (PortableServer_Servant servant,
148 CORBA_Environment *ev)
151 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
152 retval = (CORBA_long) atk_object_get_n_accessible_children (accessible->atko);
153 printf ("SpiAccessible get_childCount called: %d\n", (int) retval);
158 * CORBA Accessibility::Accessible::getChildAtIndex method implementation
160 static Accessibility_Accessible
161 impl_accessibility_accessible_get_child_at_index (PortableServer_Servant servant,
162 const CORBA_long index,
163 CORBA_Environment *ev)
165 Accessibility_Accessible retval;
166 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
167 AtkObject *child = atk_object_ref_accessible_child (accessible->atko, (gint) index);
168 retval = BONOBO_OBJREF (spi_accessible_new (child));
169 return bonobo_object_dup_ref (retval, ev);
173 * CORBA Accessibility::Accessible::getState method implementation
175 static Accessibility_StateSet
176 impl_accessibility_accessible_get_state (PortableServer_Servant servant,
177 CORBA_Environment *ev)
179 Accessibility_StateSet retval;
180 /* SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
181 AtkStateSet *state = atk_object_ref_state_set (accessible->atko); */
182 retval = CORBA_OBJECT_NIL;
183 printf ("SpiAccessible get_state.\n");
184 /* TODO: implement the bonobo stateset class */
185 return (Accessibility_StateSet) retval;
189 * CORBA Accessibility::Accessible::getRelationSet method implementation
191 static Accessibility_RelationSet *
192 impl_accessibility_accessible_get_relation_set (PortableServer_Servant servant,
193 CORBA_Environment *ev)
195 Accessibility_RelationSet *retval;
198 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
199 AtkRelationSet *relation_set = atk_object_ref_relation_set (accessible->atko);
200 n_relations = atk_relation_set_get_n_relations (relation_set);
201 retval = CORBA_sequence_Accessibility_Relation__alloc ();
202 CORBA_sequence_Accessibility_Relation_allocbuf (n_relations);
204 for (i=0; i<n_relations; ++i)
207 bonobo_object_dup_ref (bonobo_object_corba_objref (
208 BONOBO_OBJECT (spi_relation_new (atk_relation_set_get_relation (relation_set, i)))),
212 printf ("SpiAccessible get_relation_set.\n");
217 * CORBA Accessibility::Accessible::getRole method implementation
219 static Accessibility_Role
220 impl_accessibility_accessible_get_role (PortableServer_Servant servant,
221 CORBA_Environment *ev)
223 Accessibility_Role retval;
224 SpiAccessible *accessible = SPI_ACCESSIBLE (bonobo_object_from_servant (servant));
225 AtkRole role = atk_object_get_role (accessible->atko);
226 retval = role; /* relies on ability to cast these back and forth */
227 printf ("SpiAccessible get_role.\n");
228 return (Accessibility_Role) retval;
232 spi_accessible_class_init (SpiAccessibleClass *klass)
234 GObjectClass * object_class = (GObjectClass *) klass;
235 POA_Accessibility_Accessible__epv *epv = &klass->epv;
236 spi_accessible_parent_class = g_type_class_peek_parent (klass);
238 object_class->finalize = spi_accessible_object_finalize;
240 epv->_get_name = impl_accessibility_accessible_get_name;
241 epv->_set_name = impl_accessibility_accessible_set_name;
242 epv->_get_description = impl_accessibility_accessible_get_description;
243 epv->_set_description = impl_accessibility_accessible_set_description;
245 epv->_get_parent = impl_accessibility_accessible_get_parent;
246 epv->_get_childCount = impl_accessibility_accessible_get_child_count;
247 epv->getChildAtIndex = impl_accessibility_accessible_get_child_at_index;
248 epv->getIndexInParent = impl_accessibility_accessible_get_index_in_parent;
250 epv->getRelationSet = impl_accessibility_accessible_get_relation_set;
251 epv->getState = impl_accessibility_accessible_get_state;
252 epv->getRole = impl_accessibility_accessible_get_role;
256 spi_accessible_init (SpiAccessible *accessible)
260 BONOBO_TYPE_FUNC_FULL (SpiAccessible,
261 Accessibility_Accessible,
266 spi_accessible_new (AtkObject *o)
268 SpiAccessible *retval = g_object_new (SPI_ACCESSIBLE_TYPE, NULL);
269 CORBA_Environment ev;
270 CORBA_exception_init (&ev);
272 retval->atko = ATK_OBJECT (o);
274 /* aggregate appropriate SPI interfaces based on ATK interfaces */
276 if (ATK_IS_ACTION (o))
278 bonobo_object_add_interface (bonobo_object (retval),
279 BONOBO_OBJECT (spi_action_interface_new (o)));
282 if (ATK_IS_COMPONENT (o))
284 bonobo_object_add_interface (bonobo_object (retval),
285 BONOBO_OBJECT (spi_component_interface_new (o)));
288 if (ATK_IS_EDITABLE_TEXT (o))
290 bonobo_object_add_interface (bonobo_object (retval),
291 BONOBO_OBJECT(spi_editable_text_interface_new (o)));
294 else if (ATK_IS_HYPERTEXT (o))
296 bonobo_object_add_interface (bonobo_object (retval),
297 BONOBO_OBJECT (spi_hypertext_interface_new (o)));
300 else if (ATK_IS_TEXT (o))
302 bonobo_object_add_interface (bonobo_object (retval),
303 BONOBO_OBJECT (spi_text_interface_new (o)));
306 if (ATK_IS_IMAGE (o))
308 bonobo_object_add_interface (bonobo_object (retval),
309 BONOBO_OBJECT (spi_image_interface_new (o)));
312 if (ATK_IS_SELECTION (o))
314 bonobo_object_add_interface (bonobo_object (retval),
315 BONOBO_OBJECT (spi_selection_interface_new (o)));
318 if (ATK_IS_TABLE (o))
320 bonobo_object_add_interface (bonobo_object (retval),
321 BONOBO_OBJECT (spi_table_interface_new (o)));
324 if (ATK_IS_VALUE (o))
326 bonobo_object_add_interface (bonobo_object (retval),
327 BONOBO_OBJECT (spi_value_interface_new (o)));