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
34 static gboolean spi_init_role_lookup_table (Accessibility_Role *role_table);
35 static Accessibility_Role spi_role_from_atk_role (AtkRole role);
38 spi_init_role_lookup_table (Accessibility_Role *role_table)
41 /* if it's not in the list below, dunno what it is */
42 for (i = 0; i < ATK_ROLE_LAST_DEFINED; ++i)
44 role_table [i] = Accessibility_ROLE_UNKNOWN;
47 role_table [ATK_ROLE_INVALID] = Accessibility_ROLE_INVALID;
48 role_table [ATK_ROLE_ACCEL_LABEL] = Accessibility_ROLE_ACCELERATOR_LABEL;
49 role_table [ATK_ROLE_ALERT] = Accessibility_ROLE_ALERT;
50 role_table [ATK_ROLE_ANIMATION] = Accessibility_ROLE_ANIMATION;
51 role_table [ATK_ROLE_ARROW] = Accessibility_ROLE_ARROW;
52 role_table [ATK_ROLE_CALENDAR] = Accessibility_ROLE_CALENDAR;
53 role_table [ATK_ROLE_CANVAS] = Accessibility_ROLE_CANVAS;
54 role_table [ATK_ROLE_CHECK_BOX] = Accessibility_ROLE_CHECK_BOX;
55 role_table [ATK_ROLE_CHECK_MENU_ITEM] = Accessibility_ROLE_CHECK_MENU_ITEM;
56 role_table [ATK_ROLE_COLOR_CHOOSER] = Accessibility_ROLE_COLOR_CHOOSER;
57 role_table [ATK_ROLE_COLUMN_HEADER] = Accessibility_ROLE_COLUMN_HEADER;
58 role_table [ATK_ROLE_COMBO_BOX] = Accessibility_ROLE_COMBO_BOX;
59 role_table [ATK_ROLE_DATE_EDITOR] = Accessibility_ROLE_DATE_EDITOR;
60 role_table [ATK_ROLE_DESKTOP_ICON] = Accessibility_ROLE_DESKTOP_ICON;
61 role_table [ATK_ROLE_DESKTOP_FRAME] = Accessibility_ROLE_DESKTOP_FRAME;
62 role_table [ATK_ROLE_DIAL] = Accessibility_ROLE_DIAL;
63 role_table [ATK_ROLE_DIALOG] = Accessibility_ROLE_DIALOG;
64 role_table [ATK_ROLE_DIRECTORY_PANE] = Accessibility_ROLE_DIRECTORY_PANE;
65 role_table [ATK_ROLE_FILE_CHOOSER] = Accessibility_ROLE_FILE_CHOOSER;
66 role_table [ATK_ROLE_FILLER] = Accessibility_ROLE_FILLER;
67 role_table [ATK_ROLE_FONT_CHOOSER] = Accessibility_ROLE_FONT_CHOOSER;
68 role_table [ATK_ROLE_FRAME] = Accessibility_ROLE_FRAME;
69 role_table [ATK_ROLE_GLASS_PANE] = Accessibility_ROLE_GLASS_PANE;
70 role_table [ATK_ROLE_HTML_CONTAINER] = Accessibility_ROLE_HTML_CONTAINER;
71 role_table [ATK_ROLE_ICON] = Accessibility_ROLE_ICON;
72 role_table [ATK_ROLE_IMAGE] = Accessibility_ROLE_IMAGE;
73 role_table [ATK_ROLE_INTERNAL_FRAME] = Accessibility_ROLE_INTERNAL_FRAME;
74 role_table [ATK_ROLE_LABEL] = Accessibility_ROLE_LABEL;
75 role_table [ATK_ROLE_LAYERED_PANE] = Accessibility_ROLE_LAYERED_PANE;
76 role_table [ATK_ROLE_LIST] = Accessibility_ROLE_LIST;
77 role_table [ATK_ROLE_LIST_ITEM] = Accessibility_ROLE_LIST_ITEM;
78 role_table [ATK_ROLE_MENU] = Accessibility_ROLE_MENU;
79 role_table [ATK_ROLE_MENU_BAR] = Accessibility_ROLE_MENU_BAR;
80 role_table [ATK_ROLE_MENU_ITEM] = Accessibility_ROLE_MENU_ITEM;
81 role_table [ATK_ROLE_OPTION_PANE] = Accessibility_ROLE_OPTION_PANE;
82 role_table [ATK_ROLE_PAGE_TAB] = Accessibility_ROLE_PAGE_TAB;
83 role_table [ATK_ROLE_PAGE_TAB_LIST] = Accessibility_ROLE_PAGE_TAB_LIST;
84 role_table [ATK_ROLE_PANEL] = Accessibility_ROLE_PANEL;
85 role_table [ATK_ROLE_PASSWORD_TEXT] = Accessibility_ROLE_PASSWORD_TEXT;
86 role_table [ATK_ROLE_POPUP_MENU] = Accessibility_ROLE_POPUP_MENU;
87 role_table [ATK_ROLE_PROGRESS_BAR] = Accessibility_ROLE_PROGRESS_BAR;
88 role_table [ATK_ROLE_PUSH_BUTTON] = Accessibility_ROLE_PUSH_BUTTON;
89 role_table [ATK_ROLE_RADIO_BUTTON] = Accessibility_ROLE_RADIO_BUTTON;
90 role_table [ATK_ROLE_RADIO_MENU_ITEM] = Accessibility_ROLE_RADIO_MENU_ITEM;
91 role_table [ATK_ROLE_ROOT_PANE] = Accessibility_ROLE_ROOT_PANE;
92 role_table [ATK_ROLE_ROW_HEADER] = Accessibility_ROLE_ROW_HEADER;
93 role_table [ATK_ROLE_SCROLL_BAR] = Accessibility_ROLE_SCROLL_BAR;
94 role_table [ATK_ROLE_SCROLL_PANE] = Accessibility_ROLE_SCROLL_PANE;
95 role_table [ATK_ROLE_SEPARATOR] = Accessibility_ROLE_SEPARATOR;
96 role_table [ATK_ROLE_SLIDER] = Accessibility_ROLE_SLIDER;
97 role_table [ATK_ROLE_SPLIT_PANE] = Accessibility_ROLE_SPLIT_PANE;
98 role_table [ATK_ROLE_SPIN_BUTTON] = Accessibility_ROLE_SPIN_BUTTON;
99 role_table [ATK_ROLE_STATUSBAR] = Accessibility_ROLE_STATUS_BAR;
100 role_table [ATK_ROLE_TABLE] = Accessibility_ROLE_TABLE;
101 role_table [ATK_ROLE_TABLE_CELL] = Accessibility_ROLE_TABLE_CELL;
102 role_table [ATK_ROLE_TABLE_COLUMN_HEADER] =
103 Accessibility_ROLE_COLUMN_HEADER;
104 role_table [ATK_ROLE_TABLE_ROW_HEADER] = Accessibility_ROLE_ROW_HEADER;
105 role_table [ATK_ROLE_TEAR_OFF_MENU_ITEM] =
106 Accessibility_ROLE_TEAROFF_MENU_ITEM;
107 role_table [ATK_ROLE_TERMINAL] = Accessibility_ROLE_TERMINAL;
108 role_table [ATK_ROLE_TEXT] = Accessibility_ROLE_TEXT;
109 role_table [ATK_ROLE_TOGGLE_BUTTON] = Accessibility_ROLE_TOGGLE_BUTTON;
110 role_table [ATK_ROLE_TOOL_BAR] = Accessibility_ROLE_TOOL_BAR;
111 role_table [ATK_ROLE_TOOL_TIP] = Accessibility_ROLE_TOOL_TIP;
112 role_table [ATK_ROLE_TREE] = Accessibility_ROLE_TREE;
113 role_table [ATK_ROLE_TREE_TABLE] = Accessibility_ROLE_TREE_TABLE;
114 role_table [ATK_ROLE_UNKNOWN] = Accessibility_ROLE_UNKNOWN;
115 role_table [ATK_ROLE_VIEWPORT] = Accessibility_ROLE_VIEWPORT;
116 role_table [ATK_ROLE_WINDOW] = Accessibility_ROLE_WINDOW;
117 role_table [ATK_ROLE_LAST_DEFINED] = Accessibility_ROLE_EXTENDED;
122 static Accessibility_Role
123 spi_role_from_atk_role (AtkRole role)
125 static gboolean is_initialized = FALSE;
126 static Accessibility_Role spi_role_table [ATK_ROLE_LAST_DEFINED];
127 Accessibility_Role spi_role;
131 is_initialized = spi_init_role_lookup_table (spi_role_table);
134 if (role >= 0 && role < ATK_ROLE_LAST_DEFINED)
136 spi_role = spi_role_table [role];
140 spi_role = Accessibility_ROLE_EXTENDED;
146 get_atkobject_from_servant (PortableServer_Servant servant)
148 SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
150 g_return_val_if_fail (object, NULL);
151 g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
152 return ATK_OBJECT(object->gobj);
156 * CORBA Accessibility::Accessible::get_name method implementation
159 impl_accessibility_accessible_get_name (PortableServer_Servant servant,
160 CORBA_Environment *ev)
164 AtkObject *object = get_atkobject_from_servant (servant);
166 g_return_val_if_fail (object != NULL, CORBA_string_dup (""));
168 name = atk_object_get_name (object);
172 retval = CORBA_string_dup (name);
176 retval = CORBA_string_dup ("");
183 * CORBA Accessibility::Accessible::set_name method implementation
186 impl_accessibility_accessible_set_name (PortableServer_Servant servant,
187 const CORBA_char *name,
188 CORBA_Environment *ev)
190 AtkObject *object = get_atkobject_from_servant (servant);
192 g_return_if_fail (object != NULL);
194 atk_object_set_name (object, name);
198 * CORBA Accessibility::Accessible::get_description method implementation
201 impl_accessibility_accessible_get_description (PortableServer_Servant servant,
202 CORBA_Environment *ev)
206 AtkObject *object = get_atkobject_from_servant (servant);
208 g_return_val_if_fail (object != NULL, CORBA_string_dup (""));
210 descr = atk_object_get_description (object);
214 retval = CORBA_string_dup (descr);
218 retval = CORBA_string_dup ("");
225 * CORBA Accessibility::Accessible::set_description method implementation
228 impl_accessibility_accessible_set_description (PortableServer_Servant servant,
229 const CORBA_char *descr,
230 CORBA_Environment *ev)
232 AtkObject *object = get_atkobject_from_servant (servant);
234 g_return_if_fail (object != NULL);
236 atk_object_set_description (object, descr);
240 * CORBA Accessibility::Accessible::get_parent method implementation
242 static Accessibility_Accessible
243 impl_accessibility_accessible_get_parent (PortableServer_Servant servant,
244 CORBA_Environment *ev)
247 AtkObject *object = get_atkobject_from_servant (servant);
249 g_return_val_if_fail (object != NULL, CORBA_OBJECT_NIL);
251 parent = atk_object_get_parent (object);
253 return spi_accessible_new_return (parent, FALSE, ev);
257 * CORBA Accessibility::Accessible::get_IndexInParent method implementation
260 impl_accessibility_accessible_get_index_in_parent (PortableServer_Servant servant,
261 CORBA_Environment *ev)
263 AtkObject *object = get_atkobject_from_servant (servant);
265 g_return_val_if_fail (object != NULL, -1);
267 return atk_object_get_index_in_parent (object);
271 * CORBA Accessibility::Accessible::get_childCount method implementation
274 impl_accessibility_accessible_get_child_count (PortableServer_Servant servant,
275 CORBA_Environment *ev)
277 AtkObject *object = get_atkobject_from_servant (servant);
279 g_return_val_if_fail (object != NULL, 0);
281 return atk_object_get_n_accessible_children (object);
285 * CORBA Accessibility::Accessible::getChildAtIndex method implementation
287 static Accessibility_Accessible
288 impl_accessibility_accessible_get_child_at_index (PortableServer_Servant servant,
289 const CORBA_long index,
290 CORBA_Environment *ev)
293 AtkObject *object = get_atkobject_from_servant (servant);
295 g_return_val_if_fail (object != NULL, 0);
297 child = atk_object_ref_accessible_child (object, index);
299 return spi_accessible_new_return (child, TRUE, ev);
303 * CORBA Accessibility::Accessible::getState method implementation
305 static Accessibility_StateSet
306 impl_accessibility_accessible_get_state (PortableServer_Servant servant,
307 CORBA_Environment *ev)
309 AtkObject *object = get_atkobject_from_servant (servant);
311 bonobo_return_val_if_fail (object != NULL, NULL, ev);
313 printf ("SpiAccessible get_state.\n");
315 /* TODO: implement the bonobo stateset class */
316 return (Accessibility_StateSet) NULL;
320 * CORBA Accessibility::Accessible::getRelationSet method implementation
322 static Accessibility_RelationSet *
323 impl_accessibility_accessible_get_relation_set (PortableServer_Servant servant,
324 CORBA_Environment *ev)
326 Accessibility_RelationSet *retval;
329 AtkRelationSet *relation_set;
330 AtkObject *object = get_atkobject_from_servant (servant);
332 bonobo_return_val_if_fail (object != NULL, NULL, ev);
334 relation_set = atk_object_ref_relation_set (object);
336 n_relations = atk_relation_set_get_n_relations (relation_set);
337 retval = CORBA_sequence_Accessibility_Relation__alloc ();
338 CORBA_sequence_Accessibility_Relation_allocbuf (n_relations);
340 for (i = 0; i < n_relations; ++i)
343 bonobo_object_dup_ref (
345 spi_relation_new (atk_relation_set_get_relation (relation_set, i))),
349 printf ("SpiAccessible get_relation_set.\n");
354 * CORBA Accessibility::Accessible::getRole method implementation
356 static Accessibility_Role
357 impl_accessibility_accessible_get_role (PortableServer_Servant servant,
358 CORBA_Environment *ev)
361 Accessibility_Role retval;
362 AtkObject *object = get_atkobject_from_servant (servant);
364 g_return_val_if_fail (object != NULL, 0);
366 role = atk_object_get_role (object);
367 retval = spi_role_from_atk_role (role);
373 * CORBA Accessibility::Accessible::getRole method implementation
376 impl_accessibility_accessible_get_role_name (PortableServer_Servant servant,
377 CORBA_Environment *ev)
380 Accessibility_Role retval;
381 AtkObject *object = get_atkobject_from_servant (servant);
383 g_return_val_if_fail (object != NULL, 0);
385 role = atk_object_get_role (object);
387 return CORBA_string_dup (atk_role_get_name (role));
391 spi_accessible_class_init (SpiAccessibleClass *klass)
393 POA_Accessibility_Accessible__epv *epv = &klass->epv;
395 epv->_get_name = impl_accessibility_accessible_get_name;
396 epv->_set_name = impl_accessibility_accessible_set_name;
397 epv->_get_description = impl_accessibility_accessible_get_description;
398 epv->_set_description = impl_accessibility_accessible_set_description;
400 epv->_get_parent = impl_accessibility_accessible_get_parent;
401 epv->_get_childCount = impl_accessibility_accessible_get_child_count;
402 epv->getChildAtIndex = impl_accessibility_accessible_get_child_at_index;
403 epv->getIndexInParent = impl_accessibility_accessible_get_index_in_parent;
405 epv->getRelationSet = impl_accessibility_accessible_get_relation_set;
406 epv->getState = impl_accessibility_accessible_get_state;
407 epv->getRole = impl_accessibility_accessible_get_role;
408 epv->getRoleName = impl_accessibility_accessible_get_role_name;
412 spi_accessible_init (SpiAccessible *accessible)
416 BONOBO_TYPE_FUNC_FULL (SpiAccessible,
417 Accessibility_Accessible,
421 static GHashTable *public_corba_refs = NULL;
424 get_public_refs (void)
426 if (!public_corba_refs)
428 public_corba_refs = g_hash_table_new (NULL, NULL);
430 return public_corba_refs;
434 de_register_public_ref (SpiBase *object)
436 g_hash_table_remove (get_public_refs (), object->gobj);
440 spi_accessible_new (AtkObject *o)
442 SpiAccessible *retval;
443 CORBA_Environment ev;
445 CORBA_exception_init (&ev);
449 if ((retval = g_hash_table_lookup (get_public_refs (), o)))
451 bonobo_object_ref (BONOBO_OBJECT (retval));
457 retval = g_object_new (SPI_ACCESSIBLE_TYPE, NULL);
459 spi_base_construct (SPI_BASE (retval), G_OBJECT(o));
461 /* aggregate appropriate SPI interfaces based on ATK interfaces */
463 if (ATK_IS_ACTION (o))
465 bonobo_object_add_interface (bonobo_object (retval),
466 BONOBO_OBJECT (spi_action_interface_new (o)));
469 if (ATK_IS_COMPONENT (o))
471 bonobo_object_add_interface (bonobo_object (retval),
472 BONOBO_OBJECT (spi_component_interface_new (o)));
475 if (ATK_IS_EDITABLE_TEXT (o))
477 bonobo_object_add_interface (bonobo_object (retval),
478 BONOBO_OBJECT(spi_editable_text_interface_new (o)));
481 else if (ATK_IS_TEXT (o))
483 bonobo_object_add_interface (bonobo_object (retval),
484 BONOBO_OBJECT (spi_text_interface_new (o)));
487 if (ATK_IS_HYPERTEXT (o))
489 bonobo_object_add_interface (bonobo_object (retval),
490 BONOBO_OBJECT (spi_hypertext_interface_new (o)));
493 if (ATK_IS_IMAGE (o))
495 bonobo_object_add_interface (bonobo_object (retval),
496 BONOBO_OBJECT (spi_image_interface_new (o)));
499 if (ATK_IS_SELECTION (o))
501 bonobo_object_add_interface (bonobo_object (retval),
502 BONOBO_OBJECT (spi_selection_interface_new (o)));
505 if (ATK_IS_TABLE (o))
507 bonobo_object_add_interface (bonobo_object (retval),
508 BONOBO_OBJECT (spi_table_interface_new (o)));
511 if (ATK_IS_VALUE (o))
513 bonobo_object_add_interface (bonobo_object (retval),
514 BONOBO_OBJECT (spi_value_interface_new (o)));
518 g_hash_table_insert (get_public_refs (), o, retval);
519 g_signal_connect (G_OBJECT (retval), "destroy",
520 G_CALLBACK (de_register_public_ref),
526 * spi_accessible_new_return:
527 * @o: an AtkObject or NULL
528 * @release_ref: whether to unref this AtkObject before return
529 * @ev: a CORBA environment
531 * A helper function to instantiate a CORBA accessiblility
532 * proxy from an AtkObject.
534 * Return value: the proxy or CORBA_OBJECT_NIL
536 Accessibility_Accessible
537 spi_accessible_new_return (AtkObject *o,
538 gboolean release_ref,
539 CORBA_Environment *ev)
541 SpiAccessible *accessible;
542 Accessibility_Accessible retval;
546 return CORBA_OBJECT_NIL;
548 else if (SPI_IS_REMOTE_OBJECT (o))
550 retval = spi_remote_object_get_accessible (SPI_REMOTE_OBJECT (o));
554 accessible = spi_accessible_new (o);
555 retval = CORBA_Object_duplicate (BONOBO_OBJREF (accessible), ev);
560 g_object_unref (G_OBJECT (o));