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 <bonobo/bonobo-exception.h>
29 #include <libspi/libspi.h>
31 /* Our parent Gtk object type */
32 #define PARENT_TYPE SPI_TYPE_BASE
35 get_accessible_from_servant (PortableServer_Servant servant)
37 SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
48 * CORBA Accessibility::Accessible::get_name method implementation
51 impl_accessibility_accessible_get_name (PortableServer_Servant servant,
52 CORBA_Environment *ev)
56 AtkObject *object = get_accessible_from_servant (servant);
58 g_return_val_if_fail (object != NULL, CORBA_string_dup (""));
60 name = atk_object_get_name (object);
64 retval = CORBA_string_dup (name);
68 retval = CORBA_string_dup ("");
75 * CORBA Accessibility::Accessible::set_name method implementation
78 impl_accessibility_accessible_set_name (PortableServer_Servant servant,
79 const CORBA_char *name,
80 CORBA_Environment *ev)
82 AtkObject *object = get_accessible_from_servant (servant);
84 g_return_if_fail (object != NULL);
86 atk_object_set_name (object, name);
90 * CORBA Accessibility::Accessible::get_description method implementation
93 impl_accessibility_accessible_get_description (PortableServer_Servant servant,
94 CORBA_Environment *ev)
98 AtkObject *object = get_accessible_from_servant (servant);
100 g_return_val_if_fail (object != NULL, CORBA_string_dup (""));
102 descr = atk_object_get_description (object);
106 retval = CORBA_string_dup (descr);
110 retval = CORBA_string_dup ("");
117 * CORBA Accessibility::Accessible::set_description method implementation
120 impl_accessibility_accessible_set_description (PortableServer_Servant servant,
121 const CORBA_char *descr,
122 CORBA_Environment *ev)
124 AtkObject *object = get_accessible_from_servant (servant);
126 g_return_if_fail (object != NULL);
128 atk_object_set_description (object, descr);
132 * CORBA Accessibility::Accessible::get_parent method implementation
134 static Accessibility_Accessible
135 impl_accessibility_accessible_get_parent (PortableServer_Servant servant,
136 CORBA_Environment *ev)
139 AtkObject *object = get_accessible_from_servant (servant);
141 g_return_val_if_fail (object != NULL, CORBA_OBJECT_NIL);
143 parent = atk_object_get_parent (object);
145 return spi_accessible_new_return (parent, FALSE, ev);
149 * CORBA Accessibility::Accessible::get_IndexInParent method implementation
152 impl_accessibility_accessible_get_index_in_parent (PortableServer_Servant servant,
153 CORBA_Environment *ev)
155 AtkObject *object = get_accessible_from_servant (servant);
157 g_return_val_if_fail (object != NULL, -1);
159 return atk_object_get_index_in_parent (object);
163 * CORBA Accessibility::Accessible::get_childCount method implementation
166 impl_accessibility_accessible_get_child_count (PortableServer_Servant servant,
167 CORBA_Environment *ev)
169 AtkObject *object = get_accessible_from_servant (servant);
171 g_return_val_if_fail (object != NULL, 0);
173 return atk_object_get_n_accessible_children (object);
177 * CORBA Accessibility::Accessible::getChildAtIndex method implementation
179 static Accessibility_Accessible
180 impl_accessibility_accessible_get_child_at_index (PortableServer_Servant servant,
181 const CORBA_long index,
182 CORBA_Environment *ev)
185 AtkObject *object = get_accessible_from_servant (servant);
187 g_return_val_if_fail (object != NULL, 0);
189 child = atk_object_ref_accessible_child (object, index);
191 return spi_accessible_new_return (child, TRUE, ev);
195 * CORBA Accessibility::Accessible::getState method implementation
197 static Accessibility_StateSet
198 impl_accessibility_accessible_get_state (PortableServer_Servant servant,
199 CORBA_Environment *ev)
201 AtkObject *object = get_accessible_from_servant (servant);
203 bonobo_return_val_if_fail (object != NULL, NULL, ev);
205 printf ("SpiAccessible get_state.\n");
207 /* TODO: implement the bonobo stateset class */
208 return (Accessibility_StateSet) NULL;
212 * CORBA Accessibility::Accessible::getRelationSet method implementation
214 static Accessibility_RelationSet *
215 impl_accessibility_accessible_get_relation_set (PortableServer_Servant servant,
216 CORBA_Environment *ev)
218 Accessibility_RelationSet *retval;
221 AtkRelationSet *relation_set;
222 AtkObject *object = get_accessible_from_servant (servant);
224 bonobo_return_val_if_fail (object != NULL, NULL, ev);
226 relation_set = atk_object_ref_relation_set (object);
228 n_relations = atk_relation_set_get_n_relations (relation_set);
229 retval = CORBA_sequence_Accessibility_Relation__alloc ();
230 CORBA_sequence_Accessibility_Relation_allocbuf (n_relations);
232 for (i = 0; i < n_relations; ++i)
235 bonobo_object_dup_ref (
237 spi_relation_new (atk_relation_set_get_relation (relation_set, i))),
241 printf ("SpiAccessible get_relation_set.\n");
246 * CORBA Accessibility::Accessible::getRole method implementation
248 static Accessibility_Role
249 impl_accessibility_accessible_get_role (PortableServer_Servant servant,
250 CORBA_Environment *ev)
253 Accessibility_Role retval;
254 AtkObject *object = get_accessible_from_servant (servant);
256 g_return_val_if_fail (object != NULL, 0);
258 role = atk_object_get_role (object);
259 retval = role; /* FIXME: relies on ability to cast these back and forth */
265 spi_accessible_class_init (SpiAccessibleClass *klass)
267 POA_Accessibility_Accessible__epv *epv = &klass->epv;
269 epv->_get_name = impl_accessibility_accessible_get_name;
270 epv->_set_name = impl_accessibility_accessible_set_name;
271 epv->_get_description = impl_accessibility_accessible_get_description;
272 epv->_set_description = impl_accessibility_accessible_set_description;
274 epv->_get_parent = impl_accessibility_accessible_get_parent;
275 epv->_get_childCount = impl_accessibility_accessible_get_child_count;
276 epv->getChildAtIndex = impl_accessibility_accessible_get_child_at_index;
277 epv->getIndexInParent = impl_accessibility_accessible_get_index_in_parent;
279 epv->getRelationSet = impl_accessibility_accessible_get_relation_set;
280 epv->getState = impl_accessibility_accessible_get_state;
281 epv->getRole = impl_accessibility_accessible_get_role;
285 spi_accessible_init (SpiAccessible *accessible)
289 BONOBO_TYPE_FUNC_FULL (SpiAccessible,
290 Accessibility_Accessible,
294 static GHashTable *public_corba_refs = NULL;
297 get_public_refs (void)
299 if (!public_corba_refs)
301 public_corba_refs = g_hash_table_new (NULL, NULL);
303 return public_corba_refs;
307 de_register_public_ref (SpiBase *object)
309 g_hash_table_remove (get_public_refs (), object->atko);
313 spi_accessible_new (AtkObject *o)
315 SpiAccessible *retval;
316 CORBA_Environment ev;
318 CORBA_exception_init (&ev);
320 if ((retval = g_hash_table_lookup (get_public_refs (), o)))
322 bonobo_object_ref (BONOBO_OBJECT (retval));
326 retval = g_object_new (SPI_ACCESSIBLE_TYPE, NULL);
328 spi_base_construct (SPI_BASE (retval), o);
330 g_hash_table_insert (get_public_refs (), o, retval);
331 g_signal_connect (G_OBJECT (retval), "destroy",
332 G_CALLBACK (de_register_public_ref),
335 /* aggregate appropriate SPI interfaces based on ATK interfaces */
337 if (ATK_IS_ACTION (o))
339 bonobo_object_add_interface (bonobo_object (retval),
340 BONOBO_OBJECT (spi_action_interface_new (o)));
343 if (ATK_IS_COMPONENT (o))
345 bonobo_object_add_interface (bonobo_object (retval),
346 BONOBO_OBJECT (spi_component_interface_new (o)));
349 if (ATK_IS_EDITABLE_TEXT (o))
351 bonobo_object_add_interface (bonobo_object (retval),
352 BONOBO_OBJECT(spi_editable_text_interface_new (o)));
355 else if (ATK_IS_HYPERTEXT (o))
357 bonobo_object_add_interface (bonobo_object (retval),
358 BONOBO_OBJECT (spi_hypertext_interface_new (o)));
361 else if (ATK_IS_TEXT (o))
363 bonobo_object_add_interface (bonobo_object (retval),
364 BONOBO_OBJECT (spi_text_interface_new (o)));
367 if (ATK_IS_IMAGE (o))
369 bonobo_object_add_interface (bonobo_object (retval),
370 BONOBO_OBJECT (spi_image_interface_new (o)));
373 if (ATK_IS_SELECTION (o))
375 bonobo_object_add_interface (bonobo_object (retval),
376 BONOBO_OBJECT (spi_selection_interface_new (o)));
379 if (ATK_IS_TABLE (o))
381 bonobo_object_add_interface (bonobo_object (retval),
382 BONOBO_OBJECT (spi_table_interface_new (o)));
385 if (ATK_IS_VALUE (o))
387 bonobo_object_add_interface (bonobo_object (retval),
388 BONOBO_OBJECT (spi_value_interface_new (o)));
395 * spi_accessible_new_return:
396 * @o: an AtkObject or NULL
397 * @release_ref: whether to unref this AtkObject before return
398 * @ev: a CORBA environment
400 * A helper function to instantiate a CORBA accessiblility
401 * proxy from an AtkObject.
403 * Return value: the proxy or CORBA_OBJECT_NIL
405 Accessibility_Accessible
406 spi_accessible_new_return (AtkObject *o,
407 gboolean release_ref,
408 CORBA_Environment *ev)
410 SpiAccessible *accessible;
414 return CORBA_OBJECT_NIL;
417 accessible = spi_accessible_new (o);
421 g_object_unref (G_OBJECT (o));
424 return CORBA_Object_duplicate (BONOBO_OBJREF (accessible), ev);