* cspi/spi-accessible.c: Correct names of roles returned by
[platform/core/uifw/at-spi2-atk.git] / cspi / spi_accessible.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include <stdlib.h> /* for malloc */
25 #include <cspi/spi-private.h>
26
27 static const char *role_names [] =
28 {
29   "invalid",
30   "accel-label",
31   "alert",
32   "animation",
33   "arrow",
34   "calendar",
35   "canvas",
36   "check-box",
37   "check-menu-item",
38   "color-chooser",
39   "column-header",
40   "combo-box",
41   "date-editor",
42   "desktop-icon",
43   "desktop-frame",
44   "dial",
45   "dialog",
46   "directory-pane",
47   "drawing-area",
48   "file-chooser",
49   "filler",
50   "font-chooser",
51   "frame",
52   "glass-pane",
53   "html-container",
54   "icon",
55   "image",
56   "internalframe",
57   "label",
58   "layered-pane",
59   "list",
60   "list-item",
61   "menu",
62   "menu-bar",
63   "menu-item",
64   "option-pane",
65   "page-tab",
66   "page-tab-list",
67   "panel",
68   "password-text",
69   "popup-menu",
70   "progress-bar",
71   "push-button",
72   "radio-button",
73   "radio-menu-item",
74   "root-pane",
75   "row-header",
76   "scroll-bar",
77   "scroll-pane",
78   "separator",
79   "slider",
80   "spin-button",
81   "split-pane",
82   "statusbar",
83   "table",
84   "table-cell",
85   "table-column-header",
86   "table-row-header",
87   "tear-off-menu-item",
88   "terminal",
89   "text",
90   "toggle-button",
91   "tool-bar",
92   "tool-tip",
93   "tree",
94   "tree-table",
95   "unknown",
96   "viewport",
97   "window",
98
99 };
100
101 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
102
103 static SPIBoolean
104 cspi_init_role_table (AccessibleRole *role_table)
105 {
106   int i;
107   for (i = 0; i < Accessibility_ROLE_LAST_DEFINED; ++i)
108     {
109       role_table [i] = SPI_ROLE_UNKNOWN;
110     }
111   role_table [Accessibility_ROLE_INVALID] = SPI_ROLE_INVALID;
112   role_table [Accessibility_ROLE_ACCELERATOR_LABEL] = SPI_ROLE_ACCEL_LABEL;
113   role_table [Accessibility_ROLE_ALERT] = SPI_ROLE_ALERT;
114   role_table [Accessibility_ROLE_ANIMATION] = SPI_ROLE_ANIMATION;
115   role_table [Accessibility_ROLE_ARROW] = SPI_ROLE_ARROW;
116   role_table [Accessibility_ROLE_CALENDAR] = SPI_ROLE_CALENDAR;
117   role_table [Accessibility_ROLE_CANVAS] = SPI_ROLE_CANVAS;
118   role_table [Accessibility_ROLE_CHECK_BOX] = SPI_ROLE_CHECK_BOX;
119   role_table [Accessibility_ROLE_CHECK_MENU_ITEM] = SPI_ROLE_CHECK_MENU_ITEM;
120   role_table [Accessibility_ROLE_COLOR_CHOOSER] = SPI_ROLE_COLOR_CHOOSER;
121   role_table [Accessibility_ROLE_COLUMN_HEADER] = SPI_ROLE_COLUMN_HEADER;
122   role_table [Accessibility_ROLE_COMBO_BOX] = SPI_ROLE_COMBO_BOX;
123   role_table [Accessibility_ROLE_DATE_EDITOR] = SPI_ROLE_DATE_EDITOR;
124   role_table [Accessibility_ROLE_DESKTOP_ICON] = SPI_ROLE_DESKTOP_ICON;
125   role_table [Accessibility_ROLE_DESKTOP_FRAME] = SPI_ROLE_DESKTOP_FRAME;
126   role_table [Accessibility_ROLE_DIAL] = SPI_ROLE_DIAL;
127   role_table [Accessibility_ROLE_DIALOG] = SPI_ROLE_DIALOG;
128   role_table [Accessibility_ROLE_DIRECTORY_PANE] = SPI_ROLE_DIRECTORY_PANE;
129   role_table [Accessibility_ROLE_DRAWING_AREA] = SPI_ROLE_DRAWING_AREA;
130   role_table [Accessibility_ROLE_FILE_CHOOSER] = SPI_ROLE_FILE_CHOOSER;
131   role_table [Accessibility_ROLE_FILLER] = SPI_ROLE_FILLER;
132   role_table [Accessibility_ROLE_FONT_CHOOSER] = SPI_ROLE_FONT_CHOOSER;
133   role_table [Accessibility_ROLE_FRAME] = SPI_ROLE_FRAME;
134   role_table [Accessibility_ROLE_GLASS_PANE] = SPI_ROLE_GLASS_PANE;
135   role_table [Accessibility_ROLE_HTML_CONTAINER] = SPI_ROLE_HTML_CONTAINER;
136   role_table [Accessibility_ROLE_ICON] = SPI_ROLE_ICON;
137   role_table [Accessibility_ROLE_IMAGE] = SPI_ROLE_IMAGE;
138   role_table [Accessibility_ROLE_INTERNAL_FRAME] = SPI_ROLE_INTERNAL_FRAME;
139   role_table [Accessibility_ROLE_LABEL] = SPI_ROLE_LABEL;
140   role_table [Accessibility_ROLE_LAYERED_PANE] = SPI_ROLE_LAYERED_PANE;
141   role_table [Accessibility_ROLE_LIST] = SPI_ROLE_LIST;
142   role_table [Accessibility_ROLE_LIST_ITEM] = SPI_ROLE_LIST_ITEM;
143   role_table [Accessibility_ROLE_MENU] = SPI_ROLE_MENU;
144   role_table [Accessibility_ROLE_MENU_BAR] = SPI_ROLE_MENU_BAR;
145   role_table [Accessibility_ROLE_MENU_ITEM] = SPI_ROLE_MENU_ITEM;
146   role_table [Accessibility_ROLE_OPTION_PANE] = SPI_ROLE_OPTION_PANE;
147   role_table [Accessibility_ROLE_PAGE_TAB] = SPI_ROLE_PAGE_TAB;
148   role_table [Accessibility_ROLE_PAGE_TAB_LIST] = SPI_ROLE_PAGE_TAB_LIST;
149   role_table [Accessibility_ROLE_PANEL] = SPI_ROLE_PANEL;
150   role_table [Accessibility_ROLE_PASSWORD_TEXT] = SPI_ROLE_PASSWORD_TEXT;
151   role_table [Accessibility_ROLE_POPUP_MENU] = SPI_ROLE_POPUP_MENU;
152   role_table [Accessibility_ROLE_PROGRESS_BAR] = SPI_ROLE_PROGRESS_BAR;
153   role_table [Accessibility_ROLE_PUSH_BUTTON] = SPI_ROLE_PUSH_BUTTON;
154   role_table [Accessibility_ROLE_RADIO_BUTTON] = SPI_ROLE_RADIO_BUTTON;
155   role_table [Accessibility_ROLE_RADIO_MENU_ITEM] = SPI_ROLE_RADIO_MENU_ITEM;
156   role_table [Accessibility_ROLE_ROOT_PANE] = SPI_ROLE_ROOT_PANE;
157   role_table [Accessibility_ROLE_ROW_HEADER] = SPI_ROLE_ROW_HEADER;
158   role_table [Accessibility_ROLE_SCROLL_BAR] = SPI_ROLE_SCROLL_BAR;
159   role_table [Accessibility_ROLE_SCROLL_PANE] = SPI_ROLE_SCROLL_PANE;
160   role_table [Accessibility_ROLE_SEPARATOR] = SPI_ROLE_SEPARATOR;
161   role_table [Accessibility_ROLE_SLIDER] = SPI_ROLE_SLIDER;
162   role_table [Accessibility_ROLE_SPIN_BUTTON] = SPI_ROLE_SPIN_BUTTON;
163   role_table [Accessibility_ROLE_SPLIT_PANE] = SPI_ROLE_SPLIT_PANE;
164   role_table [Accessibility_ROLE_STATUS_BAR] = SPI_ROLE_STATUS_BAR;
165   role_table [Accessibility_ROLE_TABLE] = SPI_ROLE_TABLE;
166   role_table [Accessibility_ROLE_TABLE_CELL] = SPI_ROLE_TABLE_CELL;
167   role_table[Accessibility_ROLE_TABLE_COLUMN_HEADER] = SPI_ROLE_TABLE_COLUMN_HEADER;
168   role_table[Accessibility_ROLE_TABLE_ROW_HEADER] = SPI_ROLE_TABLE_ROW_HEADER;
169   role_table [Accessibility_ROLE_TEAROFF_MENU_ITEM] = SPI_ROLE_TEAROFF_MENU_ITEM;
170   role_table[Accessibility_ROLE_TERMINAL] = SPI_ROLE_TERMINAL;
171   role_table [Accessibility_ROLE_TEXT] = SPI_ROLE_TEXT;
172   role_table [Accessibility_ROLE_TOGGLE_BUTTON] = SPI_ROLE_TOGGLE_BUTTON;
173   role_table [Accessibility_ROLE_TOOL_BAR] = SPI_ROLE_TOOL_BAR;
174   role_table [Accessibility_ROLE_TOOL_TIP] = SPI_ROLE_TOOL_TIP;
175   role_table [Accessibility_ROLE_TREE] = SPI_ROLE_TREE;
176   role_table [Accessibility_ROLE_TREE_TABLE] = SPI_ROLE_TREE_TABLE;
177   role_table [Accessibility_ROLE_VIEWPORT] = SPI_ROLE_VIEWPORT;
178   role_table [Accessibility_ROLE_WINDOW] = SPI_ROLE_WINDOW;
179   role_table [Accessibility_ROLE_EXTENDED] = SPI_ROLE_EXTENDED;
180   role_table [Accessibility_ROLE_LAST_DEFINED] = SPI_ROLE_EXTENDED;
181
182   return TRUE;
183 }
184
185 static AccessibleRole
186 cspi_role_from_spi_role (Accessibility_Role role)
187 {
188   /* array is sized according to IDL roles because IDL roles are the index */   
189   static AccessibleRole cspi_role_table [Accessibility_ROLE_LAST_DEFINED];
190   static SPIBoolean is_initialized = FALSE;
191   AccessibleRole cspi_role;
192   if (!is_initialized)
193     {
194       is_initialized = cspi_init_role_table (cspi_role_table);      
195     }
196   if (role >= 0 && role < Accessibility_ROLE_LAST_DEFINED)
197     {
198       cspi_role = cspi_role_table [role];           
199     }
200   else
201     {
202       cspi_role = SPI_ROLE_EXTENDED;
203     }
204   return cspi_role; 
205 }
206
207 static SPIBoolean
208 init_state_table (Accessibility_StateType *state_table)
209 {
210   int i;
211
212   for (i = 0; i < Accessibility_STATE_LAST_DEFINED; i++)
213     state_table[i] = SPI_STATE_INVALID;
214
215   state_table[SPI_STATE_ACTIVE] = Accessibility_STATE_ACTIVE;
216   state_table[SPI_STATE_ARMED] = Accessibility_STATE_ARMED;
217   state_table[SPI_STATE_BUSY] = Accessibility_STATE_BUSY;
218   state_table[SPI_STATE_CHECKED] = Accessibility_STATE_CHECKED;
219   state_table[SPI_STATE_DEFUNCT] = Accessibility_STATE_DEFUNCT;
220   state_table[SPI_STATE_EDITABLE] = Accessibility_STATE_EDITABLE;
221   state_table[SPI_STATE_ENABLED] = Accessibility_STATE_ENABLED;
222   state_table[SPI_STATE_EXPANDABLE] = Accessibility_STATE_EXPANDABLE;
223   state_table[SPI_STATE_EXPANDED] = Accessibility_STATE_EXPANDED;
224   state_table[SPI_STATE_FOCUSABLE] = Accessibility_STATE_FOCUSABLE;
225   state_table[SPI_STATE_FOCUSED] = Accessibility_STATE_FOCUSED;
226   state_table[SPI_STATE_HORIZONTAL] = Accessibility_STATE_HORIZONTAL;
227   state_table[SPI_STATE_ICONIFIED] = Accessibility_STATE_ICONIFIED;
228   state_table[SPI_STATE_MODAL] = Accessibility_STATE_MODAL;
229   state_table[SPI_STATE_MULTI_LINE] = Accessibility_STATE_MULTI_LINE;
230   state_table[SPI_STATE_MULTISELECTABLE] = Accessibility_STATE_MULTISELECTABLE;
231   state_table[SPI_STATE_OPAQUE] = Accessibility_STATE_OPAQUE;
232   state_table[SPI_STATE_PRESSED] = Accessibility_STATE_PRESSED;
233   state_table[SPI_STATE_RESIZABLE] = Accessibility_STATE_RESIZABLE;
234   state_table[SPI_STATE_SELECTABLE] = Accessibility_STATE_SELECTABLE;
235   state_table[SPI_STATE_SELECTED] = Accessibility_STATE_SELECTED;
236   state_table[SPI_STATE_SENSITIVE] = Accessibility_STATE_SENSITIVE;
237   state_table[SPI_STATE_SHOWING] = Accessibility_STATE_SHOWING;
238   state_table[SPI_STATE_SINGLE_LINE] = Accessibility_STATE_SINGLE_LINE;
239   state_table[SPI_STATE_STALE] = Accessibility_STATE_STALE;
240   state_table[SPI_STATE_TRANSIENT] = Accessibility_STATE_TRANSIENT;
241   state_table[SPI_STATE_VERTICAL] = Accessibility_STATE_VERTICAL;
242   state_table[SPI_STATE_VISIBLE] = Accessibility_STATE_VISIBLE;
243
244   return TRUE;
245 }
246
247
248
249 static Accessibility_StateType
250 spi_state_type_from_accessible_state (AccessibleState type)
251 {
252   static Accessibility_StateType state_table[Accessibility_STATE_LAST_DEFINED];
253   static SPIBoolean table_initialized = FALSE;
254   Accessibility_StateType rv;
255   
256   if (!table_initialized)
257     table_initialized = init_state_table (state_table);  
258   if (type > SPI_STATE_INVALID && type < SPI_STATE_LAST_DEFINED)
259     rv = state_table[type];
260   else
261     rv = Accessibility_STATE_INVALID;
262   return rv;
263 }
264
265
266
267
268 /**
269  * AccessibleRole_getName:
270  * @role: an #AccessibleRole object to query.
271  *
272  * Get a localizeable string that indicates the name of an #AccessibleRole.
273  * <em>DEPRECATED.</em>
274  *
275  * Returns: a localizable string name for an #AccessibleRole enumerated type.
276  **/
277 char *
278 AccessibleRole_getName (AccessibleRole role)
279 {
280   if (role < MAX_ROLES)
281     {
282       return CORBA_string_dup (role_names [(int) role]);
283     }
284   else
285     {
286       return g_strdup ("");
287     }
288 }
289
290 /**
291  * Accessible_ref:
292  * @obj: a pointer to the #Accessible object on which to operate.
293  *
294  * Increment the reference count for an #Accessible object.
295  **/
296 void
297 Accessible_ref (Accessible *obj)
298 {
299   cspi_object_ref (obj);
300 }
301
302 /**
303  * Accessible_unref:
304  * @obj: a pointer to the #Accessible object on which to operate.
305  *
306  * Decrement the reference count for an #Accessible object.
307  **/
308 void
309 Accessible_unref (Accessible *obj)
310 {
311   cspi_object_unref (obj);
312 }
313
314 /**
315  * Accessible_getName:
316  * @obj: a pointer to the #Accessible object on which to operate.
317  *
318  * Get the name of an #Accessible object.
319  *
320  * Returns: a UTF-8 string indicating the name of the #Accessible object.
321  * or NULL on exception
322  **/
323 char *
324 Accessible_getName (Accessible *obj)
325 {
326   char *retval;
327
328   cspi_return_val_if_fail (obj != NULL, NULL);
329
330   retval = Accessibility_Accessible__get_name (CSPI_OBJREF (obj), cspi_ev ());
331
332   cspi_return_val_if_ev ("getName", NULL); 
333
334   return retval;
335 }
336
337 /**
338  * Accessible_getDescription:
339  * @obj: a pointer to the #Accessible object on which to operate.
340  *
341  * Get the description of an #Accessible object.
342  *
343  * Returns: a UTF-8 string describing the #Accessible object.
344  * or NULL on exception
345  **/
346 char *
347 Accessible_getDescription (Accessible *obj)
348 {
349   char *retval;
350
351   cspi_return_val_if_fail (obj != NULL, NULL);
352
353   retval = Accessibility_Accessible__get_description (CSPI_OBJREF (obj),
354                                                cspi_ev ());
355
356   cspi_return_val_if_ev ("getDescription", NULL); 
357
358   return retval;
359 }
360
361 /**
362  * Accessible_getParent:
363  * @obj: a pointer to the #Accessible object to query.
364  *
365  * Get an #Accessible object's parent container.
366  *
367  * Returns: a pointer tothe #Accessible object which contains the given
368  *          #Accessible instance, or NULL if the @obj has no parent container.
369  *
370  **/
371 Accessible *
372 Accessible_getParent (Accessible *obj)
373 {
374   Accessible *retval;
375
376   cspi_return_val_if_fail (obj != NULL, NULL);
377
378   retval = cspi_object_add (
379     Accessibility_Accessible__get_parent (CSPI_OBJREF (obj),
380                                           cspi_ev ()));
381
382   cspi_return_val_if_ev ("getParent", NULL); 
383
384   return retval;
385 }
386
387 /**
388  * Accessible_getChildCount:
389  * @obj: a pointer to the #Accessible object on which to operate.
390  *
391  * Get the number of children contained by an #Accessible object.
392  *
393  * Returns: a #long indicating the number of #Accessible children
394  *          contained by an #Accessible object. or -1 on exception
395  *
396  **/
397 long
398 Accessible_getChildCount (Accessible *obj)
399 {
400   long retval;
401
402   cspi_return_val_if_fail (obj != NULL, -1);
403
404   retval = Accessibility_Accessible__get_childCount (CSPI_OBJREF (obj),
405                                               cspi_ev ());
406
407   cspi_return_val_if_ev ("getChildCount", -1); 
408
409   return retval;
410 }
411
412 /**
413  * Accessible_getChildAtIndex:
414  * @obj: a pointer to the #Accessible object on which to operate.
415  * @childIndex: a #long indicating which child is specified.
416  *
417  * Get the #Accessible child of an #Accessible object at a given index.
418  *
419  * Returns: a pointer to the #Accessible child object at index
420  *          @childIndex. or NULL on exception
421  **/
422 Accessible *
423 Accessible_getChildAtIndex (Accessible *obj,
424                             long int    childIndex)
425 {
426   Accessible *retval;
427
428   cspi_return_val_if_fail (obj != NULL, NULL);
429
430   retval = cspi_object_add (
431     Accessibility_Accessible_getChildAtIndex (CSPI_OBJREF (obj),
432                                               childIndex, cspi_ev ()));
433
434   cspi_return_val_if_ev ("getChildAtIndex", NULL);
435   return retval;
436 }
437
438 /**
439  * Accessible_getIndexInParent:
440  * @obj: a pointer to the #Accessible object on which to operate.
441  *
442  * Get the index of an #Accessible object in its containing #Accessible.
443  *
444  * Returns: a #long indicating the index of the #Accessible object
445  *          in its parent (i.e. containing) #Accessible instance,
446  *          or -1 if @obj has no containing parent or on exception.
447  **/
448 long
449 Accessible_getIndexInParent (Accessible *obj)
450 {
451   long retval;
452
453   cspi_return_val_if_fail (obj != NULL, -1);
454
455   retval = Accessibility_Accessible_getIndexInParent (CSPI_OBJREF (obj), cspi_ev ());
456
457   cspi_return_val_if_ev ("getIndexInparent", -1); 
458   return retval;
459 }
460
461 /**
462  * Accessible_getRelationSet:
463  * @obj: a pointer to the #Accessible object on which to operate.
464  *
465  * Get the set of #AccessibleRelation objects which describe this #Accessible object's
466  *       relationships with other #Accessible objects.
467  *
468  * Returns: an array of #AccessibleRelation pointers. or NULL on exception
469  **/
470 AccessibleRelation **
471 Accessible_getRelationSet (Accessible *obj)
472 {
473   int i;
474   int n_relations;
475   AccessibleRelation **relations;
476   Accessibility_RelationSet *relation_set;
477
478   cspi_return_val_if_fail (obj != NULL, NULL);
479
480   relation_set =
481     Accessibility_Accessible_getRelationSet (CSPI_OBJREF (obj), cspi_ev ());
482
483   cspi_return_val_if_ev ("getRelationSet", NULL); 
484   
485   n_relations = relation_set->_length;
486   relations = malloc (sizeof (AccessibleRelation *) * (n_relations + 1));
487   
488   for (i = 0; i < n_relations; ++i)
489     {
490       relations[i] = cspi_object_add (CORBA_Object_duplicate (
491               relation_set->_buffer[i], cspi_ev ()));
492     }
493   relations[i] = NULL;
494
495   CORBA_free (relation_set);
496
497   return relations;
498 }
499
500 /**
501  * Accessible_getRole:
502  * @obj: a pointer to the #Accessible object on which to operate.
503  *
504  * Get the UI role of an #Accessible object.
505  * A UTF-8 string describing this role can be obtained via Accessible_getRoleName ().
506  *
507  * Returns: the #AccessibleRole of the object.
508  *
509  **/
510 AccessibleRole
511 Accessible_getRole (Accessible *obj)
512 {
513   AccessibleRole retval;
514
515   cspi_return_val_if_fail (obj != NULL, SPI_ROLE_INVALID);
516
517   retval = 
518     Accessibility_Accessible_getRole (CSPI_OBJREF (obj), cspi_ev ());
519
520   cspi_return_val_if_ev ("getRole", SPI_ROLE_INVALID); 
521
522   return cspi_role_from_spi_role (retval);
523 }
524
525 /**
526  * Accessible_getRoleName:
527  * @obj: a pointer to the #Accessible object on which to operate.
528  *
529  * Get a UTF-8 string describing the role this object plays in the UI.
530  * This method will return useful values for roles that fall outside the
531  * enumeration used in Accessible_getRole ().
532  *
533  * Returns: a UTF-8 string specifying the role of this #Accessible object.
534  *
535  **/
536 char *
537 Accessible_getRoleName (Accessible *obj)
538 {
539   char *retval;
540
541   cspi_return_val_if_fail (obj != NULL, CORBA_string_dup ("invalid"));
542
543   retval = 
544     Accessibility_Accessible_getRoleName (CSPI_OBJREF (obj), cspi_ev ());
545
546   cspi_return_val_if_ev ("getRoleName", CORBA_string_dup ("invalid")); 
547
548   return retval;
549 }
550
551 /**
552  * Accessible_getStateSet:
553  * @obj: a pointer to the #Accessible object on which to operate.
554  *
555  * Not Yet Implemented.
556  *
557  * Returns: a pointer to an #AccessibleStateSet representing the object's current state.
558  **/
559 AccessibleStateSet *
560 Accessible_getStateSet (Accessible *obj)
561 {
562   AccessibleStateSet *retval;
563
564   cspi_return_val_if_fail (obj != NULL, NULL);
565
566   retval = cspi_object_add (
567     Accessibility_Accessible_getState (CSPI_OBJREF (obj),
568                                           cspi_ev ()));
569
570   cspi_return_val_if_ev ("getState", NULL);
571   return retval;
572 }
573
574 /* Interface query methods */
575
576 /**
577  * Accessible_isAction:
578  * @obj: a pointer to the #Accessible instance to query.
579  *
580  * Query whether the specified #Accessible implements #AccessibleAction.
581  *
582  * Returns: #TRUE if @obj implements the #AccessibleAction interface,
583  *          #FALSE otherwise.
584  **/
585 SPIBoolean
586 Accessible_isAction (Accessible *obj)
587 {
588   return cspi_accessible_is_a (obj,
589                               "IDL:Accessibility/Action:1.0");
590 }
591
592 /**
593  * Accessible_isApplication:
594  * @obj: a pointer to the #Accessible instance to query.
595  *
596  * Query whether the specified #Accessible implements #AccessibleApplication.
597  *
598  * Returns: #TRUE if @obj implements the #AccessibleApplication interface,
599  *          #FALSE otherwise.
600  **/
601 SPIBoolean
602 Accessible_isApplication (Accessible *obj)
603 {
604   return cspi_accessible_is_a (obj,
605                               "IDL:Accessibility/Application:1.0");
606 }
607
608 /**
609  * Accessible_isComponent:
610  * @obj: a pointer to the #Accessible instance to query.
611  *
612  * Query whether the specified #Accessible implements #AccessibleComponent.
613  *
614  * Returns: #TRUE if @obj implements the #AccessibleComponent interface,
615  *          #FALSE otherwise.
616  **/
617 SPIBoolean
618 Accessible_isComponent (Accessible *obj)
619 {
620   return cspi_accessible_is_a (obj,
621                               "IDL:Accessibility/Component:1.0");
622 }
623
624 /**
625  * Accessible_isEditableText:
626  * @obj: a pointer to the #Accessible instance to query.
627  *
628  * Query whether the specified #Accessible implements #AccessibleEditableText.
629  *
630  * Returns: #TRUE if @obj implements the #AccessibleEditableText interface,
631  *          #FALSE otherwise.
632  **/
633 SPIBoolean
634 Accessible_isEditableText (Accessible *obj)
635 {
636   return cspi_accessible_is_a (obj,
637                               "IDL:Accessibility/EditableText:1.0");
638 }
639
640 /**
641  * Accessible_isHypertext:
642  * @obj: a pointer to the #Accessible instance to query.
643  *
644  * Query whether the specified #Accessible implements #AccessibleHypertext.
645  *
646  * Returns: #TRUE if @obj implements the #AccessibleHypertext interface,
647  *          #FALSE otherwise.
648  **/
649 SPIBoolean
650 Accessible_isHypertext (Accessible *obj)
651 {
652   return cspi_accessible_is_a (obj,
653                               "IDL:Accessibility/Hypertext:1.0");
654 }
655
656 /**
657  * Accessible_isImage:
658  * @obj: a pointer to the #Accessible instance to query.
659  *
660  * Query whether the specified #Accessible implements #AccessibleImage.
661  *
662  * Returns: #TRUE if @obj implements the #AccessibleImage interface,
663  *          #FALSE otherwise.
664 **/
665 SPIBoolean
666 Accessible_isImage (Accessible *obj)
667 {
668   return cspi_accessible_is_a (obj,
669                               "IDL:Accessibility/Image:1.0");
670 }
671
672 /**
673  * Accessible_isSelection:
674  * @obj: a pointer to the #Accessible instance to query.
675  *
676  * Query whether the specified #Accessible implements #AccessibleSelection.
677  *
678  * Returns: #TRUE if @obj implements the #AccessibleSelection interface,
679  *          #FALSE otherwise.
680 **/
681 SPIBoolean
682 Accessible_isSelection (Accessible *obj)
683 {
684   return cspi_accessible_is_a (obj,
685                               "IDL:Accessibility/Selection:1.0");
686 }
687
688 /**
689  * Accessible_isTable:
690  * @obj: a pointer to the #Accessible instance to query.
691  *
692  * Query whether the specified #Accessible implements #AccessibleTable.
693  *
694  * Returns: #TRUE if @obj implements the #AccessibleTable interface,
695  *          #FALSE otherwise.
696 **/
697 SPIBoolean
698 Accessible_isTable (Accessible *obj)
699 {
700   return cspi_accessible_is_a (obj,
701                               "IDL:Accessibility/Table:1.0");
702 }
703
704 /**
705  * Accessible_isStreamableContent:
706  * @obj: a pointer to the #Accessible instance to query.
707  *
708  * Query whether the specified #Accessible implements
709  *          #AccessibleStreamableContent.
710  *
711  * Returns: #TRUE if @obj implements the #AccessibleStreamableContent interface,
712  *          #FALSE otherwise.
713 **/
714 SPIBoolean
715 Accessible_isStreamableContent (Accessible *obj)
716 {
717   return cspi_accessible_is_a (obj,
718                               "IDL:Accessibility/StreamableContent:1.0");
719 }
720
721 /**
722  * Accessible_isText:
723  * @obj: a pointer to the #Accessible instance to query.
724  *
725  * Query whether the specified #Accessible implements #AccessibleText.
726  *
727  * Returns: #TRUE if @obj implements the #AccessibleText interface,
728  *          #FALSE otherwise.
729 **/
730 SPIBoolean
731 Accessible_isText (Accessible *obj)
732 {
733   return cspi_accessible_is_a (obj,
734                               "IDL:Accessibility/Text:1.0");
735 }
736
737 /**
738  * Accessible_isValue:
739  * @obj: a pointer to the #Accessible instance to query.
740  *
741  * Query whether the specified #Accessible implements #AccessibleValue.
742  *
743  * Returns: #TRUE if @obj implements the #AccessibleValue interface,
744  *          #FALSE otherwise.
745 **/
746 SPIBoolean
747 Accessible_isValue (Accessible *obj)
748 {
749   return cspi_accessible_is_a (obj,
750                               "IDL:Accessibility/Value:1.0");
751 }
752
753 /**
754  * Accessible_getApplication:
755  * @obj: a pointer to the #Accessible instance to query.
756  *
757  * Get the #AccessibleApplication interface for an #Accessible.
758  *
759  * Returns: a pointer to an #AccessibleApplication interface instance, or
760  *          NULL if @obj does not implement #AccessibleApplication.
761  **/
762 AccessibleApplication *
763 Accessible_getApplication (Accessible *obj)
764 {
765   return (AccessibleApplication *) Accessible_queryInterface (
766           obj, "IDL:Accessibility/Application:1.0");
767 }
768
769 /**
770  * Accessible_getAction:
771  * @obj: a pointer to the #Accessible instance to query.
772  *
773  * Get the #AccessibleAction interface for an #Accessible.
774  *
775  * Returns: a pointer to an #AccessibleAction interface instance, or
776  *          NULL if @obj does not implement #AccessibleAction.
777  **/
778 AccessibleAction *
779 Accessible_getAction (Accessible *obj)
780 {
781   return (AccessibleAction *) Accessible_queryInterface (
782           obj, "IDL:Accessibility/Action:1.0");
783 }
784
785 /**
786  * Accessible_getComponent:
787  * @obj: a pointer to the #Accessible instance to query.
788  *
789  * Get the #AccessibleComponent interface for an #Accessible.
790  *
791  * Returns: a pointer to an #AccessibleComponent interface instance, or
792  *          NULL if @obj does not implement #AccessibleComponent.
793  **/
794 AccessibleComponent *
795 Accessible_getComponent (Accessible *obj)
796 {
797   return (AccessibleComponent *) Accessible_queryInterface (
798           obj, "IDL:Accessibility/Component:1.0");
799 }
800
801 /**
802  * Accessible_getEditableText:
803  * @obj: a pointer to the #Accessible instance to query.
804  *
805  * Get the #AccessibleEditableText interface for an #Accessible.
806  *
807  * Returns: a pointer to an #AccessibleEditableText interface instance, or
808  *          NULL if @obj does not implement #AccessibleEditableText.
809  **/
810 AccessibleEditableText *
811 Accessible_getEditableText (Accessible *obj)
812 {
813   return (AccessibleEditableText *) Accessible_queryInterface (
814           obj, "IDL:Accessibility/EditableText:1.0");
815 }
816
817
818
819 /**
820  * Accessible_getHypertext:
821  * @obj: a pointer to the #Accessible instance to query.
822  *
823  * Get the #AccessibleHypertext interface for an #Accessible.
824  *
825  * Returns: a pointer to an #AccessibleHypertext interface instance, or
826  *          NULL if @obj does not implement #AccessibleHypertext.
827  **/
828 AccessibleHypertext *
829 Accessible_getHypertext (Accessible *obj)
830 {
831   return (AccessibleHypertext *) Accessible_queryInterface (
832           obj, "IDL:Accessibility/Hypertext:1.0");
833 }
834
835
836
837 /**
838  * Accessible_getImage:
839  * @obj: a pointer to the #Accessible instance to query.
840  *
841  * Get the #AccessibleImage interface for an #Accessible.
842  *
843  * Returns: a pointer to an #AccessibleImage interface instance, or
844  *          NULL if @obj does not implement #AccessibleImage.
845  **/
846 AccessibleImage *
847 Accessible_getImage (Accessible *obj)
848 {
849   return (AccessibleImage *) Accessible_queryInterface (
850           obj, "IDL:Accessibility/Image:1.0");
851 }
852
853
854
855 /**
856  * Accessible_getSelection:
857  * @obj: a pointer to the #Accessible instance to query.
858  *
859  * Get the #AccessibleSelection interface for an #Accessible.
860  *
861  * Returns: a pointer to an #AccessibleSelection interface instance, or
862  *          NULL if @obj does not implement #AccessibleSelection.
863  **/
864 AccessibleSelection *
865 Accessible_getSelection (Accessible *obj)
866 {
867   return (AccessibleSelection *) Accessible_queryInterface (
868           obj, "IDL:Accessibility/Selection:1.0");
869 }
870
871
872
873 /**
874  * Accessible_getStreamableContent:
875  * @obj: a pointer to the #Accessible instance to query.
876  *
877  * Get the #AccessibleStreamableContent interface for an #Accessible.
878  *
879  * Returns: a pointer to an #AccessibleStreamableContent interface instance, or
880  *          NULL if @obj does not implement #AccessibleStreamableContent.
881  **/
882 AccessibleStreamableContent *
883 Accessible_getStreamableContent (Accessible *obj)
884 {
885   return (AccessibleStreamableContent *) Accessible_queryInterface (
886           obj, "IDL:Accessibility/StreamableContent:1.0");
887 }
888
889 /**
890  * Accessible_getTable:
891  * @obj: a pointer to the #Accessible instance to query.
892  *
893  * Get the #AccessibleTable interface for an #Accessible.
894  *
895  * Returns: a pointer to an #AccessibleTable interface instance, or
896  *          NULL if @obj does not implement #AccessibleTable.
897  **/
898 AccessibleTable *
899 Accessible_getTable (Accessible *obj)
900 {
901   return (AccessibleTable *) Accessible_queryInterface (
902           obj, "IDL:Accessibility/Table:1.0");
903 }
904
905 /**
906  * Accessible_getText:
907  * @obj: a pointer to the #Accessible instance to query.
908  *
909  * Get the #AccessibleText interface for an #Accessible.
910  *
911  * Returns: a pointer to an #AccessibleText interface instance, or
912  *          NULL if @obj does not implement #AccessibleText.
913  **/
914 AccessibleText *
915 Accessible_getText (Accessible *obj)
916 {
917   return (AccessibleText *) Accessible_queryInterface (
918           obj, "IDL:Accessibility/Text:1.0");
919 }
920
921
922
923 /**
924  * Accessible_getValue:
925  * @obj: a pointer to the #Accessible instance to query.
926  *
927  * Get the #AccessibleValue interface for an #Accessible.
928  *
929  * Returns: a pointer to an #AccessibleValue interface instance, or
930  *          NULL if @obj does not implement #AccessibleValue.
931  **/
932 AccessibleValue *
933 Accessible_getValue (Accessible *obj)
934 {
935   return (AccessibleValue *) Accessible_queryInterface (
936           obj, "IDL:Accessibility/Value:1.0");
937 }
938
939
940
941 /**
942  * Accessible_queryInterface:
943  * @obj: a pointer to the #Accessible instance to query.
944  * @interface_name: a UTF-8 character string specifiying the requested interface.
945  *
946  * Query an #Accessible object to for a named interface.
947  *
948  * Returns: an instance of the named interface object, if it is implemented
949  *          by @obj, or NULL otherwise.
950  *
951  **/
952 AccessibleUnknown *
953 Accessible_queryInterface (Accessible *obj,
954                            const char *interface_name)
955 {
956   Bonobo_Unknown iface;
957   
958   if (!obj)
959     {
960       return NULL;
961     }
962
963   iface = Accessibility_Accessible_queryInterface (CSPI_OBJREF (obj),
964                                                    interface_name,
965                                                    cspi_ev ());
966
967
968   cspi_return_val_if_ev ("queryInterface", NULL); 
969
970   /*
971    * FIXME: we need to be fairly sure that references are going
972    * to mach up if we are going to expose QueryInterface, ie. we
973    * can't allow people to do:
974    * b = a.qi ("b"); b.unref, b.unref to release a's reference.
975    * this should be no real problem though for this level of API
976    * user.
977    */
978
979   return cspi_object_add (iface);
980 }
981
982
983 /**
984  * AccessibleRelation_ref:
985  * @obj: a pointer to the #AccessibleRelation object on which to operate.
986  *
987  * Increment the reference count for an #AccessibleRelation object.
988  *
989  **/
990 void
991 AccessibleRelation_ref (AccessibleRelation *obj)
992 {
993   cspi_object_ref (obj);
994 }
995
996 /**
997  * AccessibleRelation_unref:
998  * @obj: a pointer to the #AccessibleRelation object on which to operate.
999  *
1000  * Decrement the reference count for an #AccessibleRelation object.
1001  *
1002  **/
1003 void
1004 AccessibleRelation_unref (AccessibleRelation *obj)
1005 {
1006   cspi_object_unref (obj);
1007 }
1008
1009 /**
1010  * AccessibleRelation_getRelationType:
1011  * @obj: a pointer to the #AccessibleRelation object to query.
1012  *
1013  * Get the type of relationship represented by an #AccessibleRelation.
1014  *
1015  * Returns: an #AccessibleRelationType indicating the type of relation
1016  *         encapsulated in this #AccessibleRelation object.
1017  *
1018  **/
1019 AccessibleRelationType
1020 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1021 {
1022   AccessibleRelationType retval;
1023   
1024   cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1025   retval =
1026     Accessibility_Relation_getRelationType (CSPI_OBJREF (obj), cspi_ev());
1027   cspi_return_val_if_ev ("getRelationType", SPI_RELATION_NULL);
1028   return retval;
1029 }
1030
1031 /**
1032  * AccessibleRelation_getNTargets:
1033  * @obj: a pointer to the #AccessibleRelation object to query.
1034  *
1035  * Get the number of objects which this relationship has as its
1036  *       target objects (the subject is the #Accessible from which this
1037  *       #AccessibleRelation originated).
1038  *
1039  * Returns: a short integer indicating how many target objects which the
1040  *       originating #Accessible object has the #AccessibleRelation
1041  *       relationship with.
1042  **/
1043 int
1044 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1045 {
1046   int retval;
1047   
1048   cspi_return_val_if_fail (obj, -1);
1049   retval = Accessibility_Relation_getNTargets (CSPI_OBJREF (obj), cspi_ev());
1050   cspi_return_val_if_ev ("getNTargets", -1);
1051   return retval;
1052 }
1053
1054 /**
1055  * AccessibleRelation_getTarget:
1056  * @obj: a pointer to the #AccessibleRelation object to query.
1057  * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1058  *
1059  * Get the @i-th target of a specified #AccessibleRelation relationship.
1060  *
1061  * Returns: an #Accessible which is the @i-th object with which the
1062  *      originating #Accessible has relationship specified in the
1063  *      #AccessibleRelation object.
1064  *
1065  **/
1066 Accessible *
1067 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1068 {
1069   Accessible *retval;
1070
1071   cspi_return_val_if_fail (obj, NULL);
1072
1073   retval = cspi_object_add (
1074                          Accessibility_Relation_getTarget (CSPI_OBJREF(obj),
1075                                                            i, cspi_ev()));
1076   cspi_return_val_if_ev ("getTarget", NULL);
1077   return retval;
1078 }
1079
1080 /**
1081  * AccessibleStateSet_ref:
1082  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1083  *
1084  * Increment the reference count for an #AccessibleStateSet object.
1085  *
1086  **/
1087 void
1088 AccessibleStateSet_ref (AccessibleStateSet *obj)
1089 {
1090   cspi_object_ref (obj);
1091 }
1092
1093 /**
1094  * AccessibleStateSet_unref:
1095  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1096  *
1097  * Decrement the reference count for an #AccessibleStateSet object.
1098  *
1099  **/
1100 void
1101 AccessibleStateSet_unref (AccessibleStateSet *obj)
1102 {
1103   cspi_object_unref (obj);
1104 }
1105
1106 /**
1107  * AccessibleStateSet_contains:
1108  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1109  * @state: an #AccessibleState for which the specified #AccessibleStateSet
1110  *       will be queried.
1111  *
1112  * Determine whether a given #AccessibleStateSet includes a given state; that is,
1113  *       whether @state is true for the stateset in question.
1114  *
1115  * Returns: #TRUE if @state is true/included in the given #AccessibleStateSet,
1116  *          otherwise #FALSE.
1117  *
1118  **/
1119 SPIBoolean
1120 AccessibleStateSet_contains (AccessibleStateSet *obj,
1121                              AccessibleState state)
1122 {
1123   CORBA_boolean retval;
1124   Accessibility_StateType spi_state;
1125   
1126   cspi_return_val_if_fail (obj != NULL, FALSE);
1127
1128   spi_state = spi_state_type_from_accessible_state (state);
1129   retval = Accessibility_StateSet_contains (CSPI_OBJREF (obj),
1130                                             spi_state, cspi_ev ());
1131
1132   cspi_return_val_if_ev ("contains", FALSE);
1133
1134   return retval;
1135 }
1136
1137 /**
1138  * AccessibleStateSet_add:
1139  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1140  * @state: an #AccessibleState to be added to the specified #AccessibleStateSet
1141  *
1142  * Add a particular #AccessibleState to an #AccessibleStateSet (i.e. set the
1143  *       given state to #TRUE in the stateset.
1144  *
1145  **/
1146 void
1147 AccessibleStateSet_add (AccessibleStateSet *obj,
1148                         AccessibleState state)
1149 {
1150   Accessibility_StateType spi_state;
1151
1152   cspi_return_if_fail (obj != NULL);
1153
1154   spi_state = spi_state_type_from_accessible_state (state);
1155   Accessibility_StateSet_add (CSPI_OBJREF (obj), spi_state, cspi_ev ());
1156   cspi_check_ev ("StateSet_add");
1157 }
1158
1159 /**
1160  * AccessibleStateSet_remove:
1161  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1162  * @state: an #AccessibleState to be removed from the specified #AccessibleStateSet
1163  *
1164  * Remove a particular #AccessibleState to an #AccessibleStateSet (i.e. set the
1165  *       given state to #FALSE in the stateset.)
1166  *
1167  **/
1168 void
1169 AccessibleStateSet_remove (AccessibleStateSet *obj,
1170                            AccessibleState state)
1171 {
1172   Accessibility_StateType spi_state;
1173
1174   cspi_return_if_fail (obj != NULL);
1175
1176   spi_state = spi_state_type_from_accessible_state (state);
1177   Accessibility_StateSet_remove (CSPI_OBJREF (obj), spi_state, cspi_ev ());
1178   cspi_check_ev ("StateSet_remove");
1179 }
1180
1181 /**
1182  * AccessibleStateSet_equals:
1183  * @obj: a pointer to the first #AccessibleStateSet object on which to operate.
1184  * @obj2: a pointer to the second #AccessibleStateSet object on which to operate.
1185  *
1186  * Determine whether two instances of #AccessibleStateSet are equivalent (i.e.
1187  *         consist of the same #AccessibleStates).  Useful for checking multiple
1188  *         state variables at once; construct the target state then compare against it.
1189  *
1190  * @see AccessibleStateSet_compare().
1191  *
1192  * Returns: #TRUE if the two #AccessibleStateSets are equivalent,
1193  *          otherwise #FALSE.
1194  *
1195  **/
1196 SPIBoolean
1197 AccessibleStateSet_equals (AccessibleStateSet *obj,
1198                            AccessibleStateSet *obj2)
1199 {
1200   if (obj == obj2)
1201     {
1202       return TRUE;
1203     }
1204
1205   cspi_return_val_if_fail (obj != NULL, FALSE);
1206   cspi_return_val_if_fail (obj2 != NULL, FALSE);
1207
1208   return Accessibility_StateSet_equals (CSPI_OBJREF (obj),
1209                                         CSPI_OBJREF (obj2), cspi_ev ());
1210 }
1211
1212 /**
1213  * AccessibleStateSet_compare:
1214  * @obj: a pointer to the first #AccessibleStateSet object on which to operate.
1215  * @obj2: a pointer to the second #AccessibleStateSet object on which to operate.
1216  *
1217  * Determine the differences between two instances of #AccessibleStateSet.
1218  * Not Yet Implemented.
1219  *.
1220  * @see AccessibleStateSet_equals().
1221  *
1222  * Returns: an #AccessibleStateSet object containing all states contained on one of
1223  *          the two sets but not the other.
1224  *
1225  **/
1226 AccessibleStateSet *
1227 AccessibleStateSet_compare (AccessibleStateSet *obj,
1228                             AccessibleStateSet *obj2)
1229 {
1230   AccessibleStateSet *retval;
1231
1232   cspi_return_val_if_fail (obj != NULL, NULL);
1233   cspi_return_val_if_fail (obj2 != NULL, NULL);
1234   retval = cspi_object_add (
1235                          Accessibility_StateSet_compare (CSPI_OBJREF(obj), CSPI_OBJREF(obj2), cspi_ev ()));
1236
1237   cspi_return_val_if_ev ("compare", NULL);
1238   return retval;
1239 }
1240
1241 /**
1242  * AccessibleStateSet_isEmpty:
1243  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1244  *
1245  * Determine whether a given #AccessibleStateSet is the empty set.
1246  *
1247  * Returns: #TRUE if the given #AccessibleStateSet contains no (true) states,
1248  *          otherwise #FALSE.
1249  *
1250  **/
1251 SPIBoolean
1252 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1253 {
1254   CORBA_boolean retval;
1255
1256   cspi_return_val_if_fail (obj != NULL, FALSE);
1257   retval = Accessibility_StateSet_isEmpty (CSPI_OBJREF (obj), cspi_ev ());
1258
1259   cspi_return_val_if_ev ("isEmpty", TRUE);
1260   return retval;
1261 }
1262
1263