d927aca156996a3695aeba56a2bab8835fb38b91
[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_HEADER] = SPI_ROLE_HEADER;
181   role_table [Accessibility_ROLE_FOOTER] = SPI_ROLE_FOOTER;
182   role_table [Accessibility_ROLE_PARAGRAPH] = SPI_ROLE_PARAGRAPH;
183   role_table [Accessibility_ROLE_RULER] = SPI_ROLE_RULER;
184
185   return TRUE;
186 }
187
188 static AccessibleRole
189 cspi_role_from_spi_role (Accessibility_Role role)
190 {
191   /* array is sized according to IDL roles because IDL roles are the index */   
192   static AccessibleRole cspi_role_table [Accessibility_ROLE_LAST_DEFINED];
193   static SPIBoolean is_initialized = FALSE;
194   AccessibleRole cspi_role;
195   if (!is_initialized)
196     {
197       is_initialized = cspi_init_role_table (cspi_role_table);      
198     }
199   if (role >= 0 && role < Accessibility_ROLE_LAST_DEFINED)
200     {
201       cspi_role = cspi_role_table [role];           
202     }
203   else
204     {
205       cspi_role = SPI_ROLE_EXTENDED;
206     }
207   return cspi_role; 
208 }
209
210 static SPIBoolean
211 init_state_table (Accessibility_StateType *state_table)
212 {
213   int i;
214
215   for (i = 0; i < Accessibility_STATE_LAST_DEFINED; i++)
216     state_table[i] = SPI_STATE_INVALID;
217
218   state_table[SPI_STATE_ACTIVE] = Accessibility_STATE_ACTIVE;
219   state_table[SPI_STATE_ARMED] = Accessibility_STATE_ARMED;
220   state_table[SPI_STATE_BUSY] = Accessibility_STATE_BUSY;
221   state_table[SPI_STATE_CHECKED] = Accessibility_STATE_CHECKED;
222   state_table[SPI_STATE_DEFUNCT] = Accessibility_STATE_DEFUNCT;
223   state_table[SPI_STATE_EDITABLE] = Accessibility_STATE_EDITABLE;
224   state_table[SPI_STATE_ENABLED] = Accessibility_STATE_ENABLED;
225   state_table[SPI_STATE_EXPANDABLE] = Accessibility_STATE_EXPANDABLE;
226   state_table[SPI_STATE_EXPANDED] = Accessibility_STATE_EXPANDED;
227   state_table[SPI_STATE_FOCUSABLE] = Accessibility_STATE_FOCUSABLE;
228   state_table[SPI_STATE_FOCUSED] = Accessibility_STATE_FOCUSED;
229   state_table[SPI_STATE_HORIZONTAL] = Accessibility_STATE_HORIZONTAL;
230   state_table[SPI_STATE_ICONIFIED] = Accessibility_STATE_ICONIFIED;
231   state_table[SPI_STATE_MODAL] = Accessibility_STATE_MODAL;
232   state_table[SPI_STATE_MULTI_LINE] = Accessibility_STATE_MULTI_LINE;
233   state_table[SPI_STATE_MULTISELECTABLE] = Accessibility_STATE_MULTISELECTABLE;
234   state_table[SPI_STATE_OPAQUE] = Accessibility_STATE_OPAQUE;
235   state_table[SPI_STATE_PRESSED] = Accessibility_STATE_PRESSED;
236   state_table[SPI_STATE_RESIZABLE] = Accessibility_STATE_RESIZABLE;
237   state_table[SPI_STATE_SELECTABLE] = Accessibility_STATE_SELECTABLE;
238   state_table[SPI_STATE_SELECTED] = Accessibility_STATE_SELECTED;
239   state_table[SPI_STATE_SENSITIVE] = Accessibility_STATE_SENSITIVE;
240   state_table[SPI_STATE_SHOWING] = Accessibility_STATE_SHOWING;
241   state_table[SPI_STATE_SINGLE_LINE] = Accessibility_STATE_SINGLE_LINE;
242   state_table[SPI_STATE_STALE] = Accessibility_STATE_STALE;
243   state_table[SPI_STATE_TRANSIENT] = Accessibility_STATE_TRANSIENT;
244   state_table[SPI_STATE_VERTICAL] = Accessibility_STATE_VERTICAL;
245   state_table[SPI_STATE_VISIBLE] = Accessibility_STATE_VISIBLE;
246   state_table[SPI_STATE_MANAGES_DESCENDANTS] = Accessibility_STATE_MANAGES_DESCENDANTS;
247
248   return TRUE;
249 }
250
251
252
253 static Accessibility_StateType
254 spi_state_type_from_accessible_state (AccessibleState type)
255 {
256   static Accessibility_StateType state_table[Accessibility_STATE_LAST_DEFINED];
257   static SPIBoolean table_initialized = FALSE;
258   Accessibility_StateType rv;
259   
260   if (!table_initialized)
261     table_initialized = init_state_table (state_table);  
262   if (type > SPI_STATE_INVALID && type < SPI_STATE_LAST_DEFINED)
263     rv = state_table[type];
264   else
265     rv = Accessibility_STATE_INVALID;
266   return rv;
267 }
268
269
270
271
272 /**
273  * AccessibleRole_getName:
274  * @role: an #AccessibleRole object to query.
275  *
276  * Get a localizeable string that indicates the name of an #AccessibleRole.
277  * <em>DEPRECATED.</em>
278  *
279  * Returns: a localizable string name for an #AccessibleRole enumerated type.
280  **/
281 char *
282 AccessibleRole_getName (AccessibleRole role)
283 {
284   if (role < MAX_ROLES)
285     {
286       return CORBA_string_dup (role_names [(int) role]);
287     }
288   else
289     {
290       return g_strdup ("");
291     }
292 }
293
294 /**
295  * Accessible_ref:
296  * @obj: a pointer to the #Accessible object on which to operate.
297  *
298  * Increment the reference count for an #Accessible object.
299  **/
300 void
301 Accessible_ref (Accessible *obj)
302 {
303   cspi_object_ref (obj);
304 }
305
306 /**
307  * Accessible_unref:
308  * @obj: a pointer to the #Accessible object on which to operate.
309  *
310  * Decrement the reference count for an #Accessible object.
311  **/
312 void
313 Accessible_unref (Accessible *obj)
314 {
315   cspi_object_unref (obj);
316 }
317
318 /**
319  * Accessible_getName:
320  * @obj: a pointer to the #Accessible object on which to operate.
321  *
322  * Get the name of an #Accessible object.
323  *
324  * Returns: a UTF-8 string indicating the name of the #Accessible object.
325  * or NULL on exception
326  **/
327 char *
328 Accessible_getName (Accessible *obj)
329 {
330   char *retval;
331
332   cspi_return_val_if_fail (obj != NULL, NULL);
333
334   retval = Accessibility_Accessible__get_name (CSPI_OBJREF (obj), cspi_ev ());
335
336   cspi_return_val_if_ev ("getName", NULL); 
337
338   return retval;
339 }
340
341 /**
342  * Accessible_getDescription:
343  * @obj: a pointer to the #Accessible object on which to operate.
344  *
345  * Get the description of an #Accessible object.
346  *
347  * Returns: a UTF-8 string describing the #Accessible object.
348  * or NULL on exception
349  **/
350 char *
351 Accessible_getDescription (Accessible *obj)
352 {
353   char *retval;
354
355   cspi_return_val_if_fail (obj != NULL, NULL);
356
357   retval = Accessibility_Accessible__get_description (CSPI_OBJREF (obj),
358                                                cspi_ev ());
359
360   cspi_return_val_if_ev ("getDescription", NULL); 
361
362   return retval;
363 }
364
365 /**
366  * Accessible_getParent:
367  * @obj: a pointer to the #Accessible object to query.
368  *
369  * Get an #Accessible object's parent container.
370  *
371  * Returns: a pointer tothe #Accessible object which contains the given
372  *          #Accessible instance, or NULL if the @obj has no parent container.
373  *
374  **/
375 Accessible *
376 Accessible_getParent (Accessible *obj)
377 {
378   Accessible *retval;
379
380   cspi_return_val_if_fail (obj != NULL, NULL);
381
382   retval = cspi_object_add (
383     Accessibility_Accessible__get_parent (CSPI_OBJREF (obj),
384                                           cspi_ev ()));
385
386   cspi_return_val_if_ev ("getParent", NULL); 
387
388   return retval;
389 }
390
391 /**
392  * Accessible_getChildCount:
393  * @obj: a pointer to the #Accessible object on which to operate.
394  *
395  * Get the number of children contained by an #Accessible object.
396  *
397  * Returns: a #long indicating the number of #Accessible children
398  *          contained by an #Accessible object. or -1 on exception
399  *
400  **/
401 long
402 Accessible_getChildCount (Accessible *obj)
403 {
404   long retval;
405
406   cspi_return_val_if_fail (obj != NULL, -1);
407
408   retval = Accessibility_Accessible__get_childCount (CSPI_OBJREF (obj),
409                                               cspi_ev ());
410
411   cspi_return_val_if_ev ("getChildCount", -1); 
412
413   return retval;
414 }
415
416 /**
417  * Accessible_getChildAtIndex:
418  * @obj: a pointer to the #Accessible object on which to operate.
419  * @childIndex: a #long indicating which child is specified.
420  *
421  * Get the #Accessible child of an #Accessible object at a given index.
422  *
423  * Returns: a pointer to the #Accessible child object at index
424  *          @childIndex. or NULL on exception
425  **/
426 Accessible *
427 Accessible_getChildAtIndex (Accessible *obj,
428                             long int    childIndex)
429 {
430   Accessible *retval;
431
432   cspi_return_val_if_fail (obj != NULL, NULL);
433
434   retval = cspi_object_add (
435     Accessibility_Accessible_getChildAtIndex (CSPI_OBJREF (obj),
436                                               childIndex, cspi_ev ()));
437
438   cspi_return_val_if_ev ("getChildAtIndex", NULL);
439   return retval;
440 }
441
442 /**
443  * Accessible_getIndexInParent:
444  * @obj: a pointer to the #Accessible object on which to operate.
445  *
446  * Get the index of an #Accessible object in its containing #Accessible.
447  *
448  * Returns: a #long indicating the index of the #Accessible object
449  *          in its parent (i.e. containing) #Accessible instance,
450  *          or -1 if @obj has no containing parent or on exception.
451  **/
452 long
453 Accessible_getIndexInParent (Accessible *obj)
454 {
455   long retval;
456
457   cspi_return_val_if_fail (obj != NULL, -1);
458
459   retval = Accessibility_Accessible_getIndexInParent (CSPI_OBJREF (obj), cspi_ev ());
460
461   cspi_return_val_if_ev ("getIndexInparent", -1); 
462   return retval;
463 }
464
465 /**
466  * Accessible_getRelationSet:
467  * @obj: a pointer to the #Accessible object on which to operate.
468  *
469  * Get the set of #AccessibleRelation objects which describe this #Accessible object's
470  *       relationships with other #Accessible objects.
471  *
472  * Returns: an array of #AccessibleRelation pointers. or NULL on exception
473  **/
474 AccessibleRelation **
475 Accessible_getRelationSet (Accessible *obj)
476 {
477   int i;
478   int n_relations;
479   AccessibleRelation **relations;
480   Accessibility_RelationSet *relation_set;
481
482   cspi_return_val_if_fail (obj != NULL, NULL);
483
484   relation_set =
485     Accessibility_Accessible_getRelationSet (CSPI_OBJREF (obj), cspi_ev ());
486
487   cspi_return_val_if_ev ("getRelationSet", NULL); 
488   
489   n_relations = relation_set->_length;
490   relations = malloc (sizeof (AccessibleRelation *) * (n_relations + 1));
491   
492   for (i = 0; i < n_relations; ++i)
493     {
494       relations[i] = cspi_object_add (CORBA_Object_duplicate (
495               relation_set->_buffer[i], cspi_ev ()));
496     }
497   relations[i] = NULL;
498
499   CORBA_free (relation_set);
500
501   return relations;
502 }
503
504 /**
505  * Accessible_getRole:
506  * @obj: a pointer to the #Accessible object on which to operate.
507  *
508  * Get the UI role of an #Accessible object.
509  * A UTF-8 string describing this role can be obtained via Accessible_getRoleName ().
510  *
511  * Returns: the #AccessibleRole of the object.
512  *
513  **/
514 AccessibleRole
515 Accessible_getRole (Accessible *obj)
516 {
517   Accessibility_Role retval;
518
519   cspi_return_val_if_fail (obj != NULL, SPI_ROLE_INVALID);
520
521   retval = 
522     Accessibility_Accessible_getRole (CSPI_OBJREF (obj), cspi_ev ());
523
524   cspi_return_val_if_ev ("getRole", SPI_ROLE_INVALID); 
525
526   return cspi_role_from_spi_role (retval);
527 }
528
529 /**
530  * Accessible_getRoleName:
531  * @obj: a pointer to the #Accessible object on which to operate.
532  *
533  * Get a UTF-8 string describing the role this object plays in the UI.
534  * This method will return useful values for roles that fall outside the
535  * enumeration used in Accessible_getRole ().
536  *
537  * Returns: a UTF-8 string specifying the role of this #Accessible object.
538  *
539  **/
540 char *
541 Accessible_getRoleName (Accessible *obj)
542 {
543   char *retval;
544
545   cspi_return_val_if_fail (obj != NULL, CORBA_string_dup ("invalid"));
546
547   retval = 
548     Accessibility_Accessible_getRoleName (CSPI_OBJREF (obj), cspi_ev ());
549
550   cspi_return_val_if_ev ("getRoleName", CORBA_string_dup ("invalid")); 
551
552   return retval;
553 }
554
555 /**
556  * Accessible_getStateSet:
557  * @obj: a pointer to the #Accessible object on which to operate.
558  *
559  * Not Yet Implemented.
560  *
561  * Returns: a pointer to an #AccessibleStateSet representing the object's current state.
562  **/
563 AccessibleStateSet *
564 Accessible_getStateSet (Accessible *obj)
565 {
566   AccessibleStateSet *retval;
567
568   cspi_return_val_if_fail (obj != NULL, NULL);
569
570   retval = cspi_object_add (
571     Accessibility_Accessible_getState (CSPI_OBJREF (obj),
572                                           cspi_ev ()));
573
574   cspi_return_val_if_ev ("getState", NULL);
575   return retval;
576 }
577
578 /* Interface query methods */
579
580 /**
581  * Accessible_isAction:
582  * @obj: a pointer to the #Accessible instance to query.
583  *
584  * Query whether the specified #Accessible implements #AccessibleAction.
585  *
586  * Returns: #TRUE if @obj implements the #AccessibleAction interface,
587  *          #FALSE otherwise.
588  **/
589 SPIBoolean
590 Accessible_isAction (Accessible *obj)
591 {
592   return cspi_accessible_is_a (obj,
593                               "IDL:Accessibility/Action:1.0");
594 }
595
596 /**
597  * Accessible_isApplication:
598  * @obj: a pointer to the #Accessible instance to query.
599  *
600  * Query whether the specified #Accessible implements #AccessibleApplication.
601  *
602  * Returns: #TRUE if @obj implements the #AccessibleApplication interface,
603  *          #FALSE otherwise.
604  **/
605 SPIBoolean
606 Accessible_isApplication (Accessible *obj)
607 {
608   return cspi_accessible_is_a (obj,
609                               "IDL:Accessibility/Application:1.0");
610 }
611
612 /**
613  * Accessible_isComponent:
614  * @obj: a pointer to the #Accessible instance to query.
615  *
616  * Query whether the specified #Accessible implements #AccessibleComponent.
617  *
618  * Returns: #TRUE if @obj implements the #AccessibleComponent interface,
619  *          #FALSE otherwise.
620  **/
621 SPIBoolean
622 Accessible_isComponent (Accessible *obj)
623 {
624   return cspi_accessible_is_a (obj,
625                               "IDL:Accessibility/Component:1.0");
626 }
627
628 /**
629  * Accessible_isEditableText:
630  * @obj: a pointer to the #Accessible instance to query.
631  *
632  * Query whether the specified #Accessible implements #AccessibleEditableText.
633  *
634  * Returns: #TRUE if @obj implements the #AccessibleEditableText interface,
635  *          #FALSE otherwise.
636  **/
637 SPIBoolean
638 Accessible_isEditableText (Accessible *obj)
639 {
640   return cspi_accessible_is_a (obj,
641                               "IDL:Accessibility/EditableText:1.0");
642 }
643
644 /**
645  * Accessible_isHypertext:
646  * @obj: a pointer to the #Accessible instance to query.
647  *
648  * Query whether the specified #Accessible implements #AccessibleHypertext.
649  *
650  * Returns: #TRUE if @obj implements the #AccessibleHypertext interface,
651  *          #FALSE otherwise.
652  **/
653 SPIBoolean
654 Accessible_isHypertext (Accessible *obj)
655 {
656   return cspi_accessible_is_a (obj,
657                               "IDL:Accessibility/Hypertext:1.0");
658 }
659
660 /**
661  * Accessible_isImage:
662  * @obj: a pointer to the #Accessible instance to query.
663  *
664  * Query whether the specified #Accessible implements #AccessibleImage.
665  *
666  * Returns: #TRUE if @obj implements the #AccessibleImage interface,
667  *          #FALSE otherwise.
668 **/
669 SPIBoolean
670 Accessible_isImage (Accessible *obj)
671 {
672   return cspi_accessible_is_a (obj,
673                               "IDL:Accessibility/Image:1.0");
674 }
675
676 /**
677  * Accessible_isSelection:
678  * @obj: a pointer to the #Accessible instance to query.
679  *
680  * Query whether the specified #Accessible implements #AccessibleSelection.
681  *
682  * Returns: #TRUE if @obj implements the #AccessibleSelection interface,
683  *          #FALSE otherwise.
684 **/
685 SPIBoolean
686 Accessible_isSelection (Accessible *obj)
687 {
688   return cspi_accessible_is_a (obj,
689                               "IDL:Accessibility/Selection:1.0");
690 }
691
692 /**
693  * Accessible_isTable:
694  * @obj: a pointer to the #Accessible instance to query.
695  *
696  * Query whether the specified #Accessible implements #AccessibleTable.
697  *
698  * Returns: #TRUE if @obj implements the #AccessibleTable interface,
699  *          #FALSE otherwise.
700 **/
701 SPIBoolean
702 Accessible_isTable (Accessible *obj)
703 {
704   return cspi_accessible_is_a (obj,
705                               "IDL:Accessibility/Table:1.0");
706 }
707
708 /**
709  * Accessible_isStreamableContent:
710  * @obj: a pointer to the #Accessible instance to query.
711  *
712  * Query whether the specified #Accessible implements
713  *          #AccessibleStreamableContent.
714  *
715  * Returns: #TRUE if @obj implements the #AccessibleStreamableContent interface,
716  *          #FALSE otherwise.
717 **/
718 SPIBoolean
719 Accessible_isStreamableContent (Accessible *obj)
720 {
721   return cspi_accessible_is_a (obj,
722                               "IDL:Accessibility/StreamableContent:1.0");
723 }
724
725 /**
726  * Accessible_isText:
727  * @obj: a pointer to the #Accessible instance to query.
728  *
729  * Query whether the specified #Accessible implements #AccessibleText.
730  *
731  * Returns: #TRUE if @obj implements the #AccessibleText interface,
732  *          #FALSE otherwise.
733 **/
734 SPIBoolean
735 Accessible_isText (Accessible *obj)
736 {
737   return cspi_accessible_is_a (obj,
738                               "IDL:Accessibility/Text:1.0");
739 }
740
741 /**
742  * Accessible_isValue:
743  * @obj: a pointer to the #Accessible instance to query.
744  *
745  * Query whether the specified #Accessible implements #AccessibleValue.
746  *
747  * Returns: #TRUE if @obj implements the #AccessibleValue interface,
748  *          #FALSE otherwise.
749 **/
750 SPIBoolean
751 Accessible_isValue (Accessible *obj)
752 {
753   return cspi_accessible_is_a (obj,
754                               "IDL:Accessibility/Value:1.0");
755 }
756
757 /**
758  * Accessible_getApplication:
759  * @obj: a pointer to the #Accessible instance to query.
760  *
761  * Get the #AccessibleApplication interface for an #Accessible.
762  *
763  * Returns: a pointer to an #AccessibleApplication interface instance, or
764  *          NULL if @obj does not implement #AccessibleApplication.
765  **/
766 AccessibleApplication *
767 Accessible_getApplication (Accessible *obj)
768 {
769   return (AccessibleApplication *) Accessible_queryInterface (
770           obj, "IDL:Accessibility/Application:1.0");
771 }
772
773 /**
774  * Accessible_getAction:
775  * @obj: a pointer to the #Accessible instance to query.
776  *
777  * Get the #AccessibleAction interface for an #Accessible.
778  *
779  * Returns: a pointer to an #AccessibleAction interface instance, or
780  *          NULL if @obj does not implement #AccessibleAction.
781  **/
782 AccessibleAction *
783 Accessible_getAction (Accessible *obj)
784 {
785   return (AccessibleAction *) Accessible_queryInterface (
786           obj, "IDL:Accessibility/Action:1.0");
787 }
788
789 /**
790  * Accessible_getComponent:
791  * @obj: a pointer to the #Accessible instance to query.
792  *
793  * Get the #AccessibleComponent interface for an #Accessible.
794  *
795  * Returns: a pointer to an #AccessibleComponent interface instance, or
796  *          NULL if @obj does not implement #AccessibleComponent.
797  **/
798 AccessibleComponent *
799 Accessible_getComponent (Accessible *obj)
800 {
801   return (AccessibleComponent *) Accessible_queryInterface (
802           obj, "IDL:Accessibility/Component:1.0");
803 }
804
805 /**
806  * Accessible_getEditableText:
807  * @obj: a pointer to the #Accessible instance to query.
808  *
809  * Get the #AccessibleEditableText interface for an #Accessible.
810  *
811  * Returns: a pointer to an #AccessibleEditableText interface instance, or
812  *          NULL if @obj does not implement #AccessibleEditableText.
813  **/
814 AccessibleEditableText *
815 Accessible_getEditableText (Accessible *obj)
816 {
817   return (AccessibleEditableText *) Accessible_queryInterface (
818           obj, "IDL:Accessibility/EditableText:1.0");
819 }
820
821
822
823 /**
824  * Accessible_getHypertext:
825  * @obj: a pointer to the #Accessible instance to query.
826  *
827  * Get the #AccessibleHypertext interface for an #Accessible.
828  *
829  * Returns: a pointer to an #AccessibleHypertext interface instance, or
830  *          NULL if @obj does not implement #AccessibleHypertext.
831  **/
832 AccessibleHypertext *
833 Accessible_getHypertext (Accessible *obj)
834 {
835   return (AccessibleHypertext *) Accessible_queryInterface (
836           obj, "IDL:Accessibility/Hypertext:1.0");
837 }
838
839
840
841 /**
842  * Accessible_getImage:
843  * @obj: a pointer to the #Accessible instance to query.
844  *
845  * Get the #AccessibleImage interface for an #Accessible.
846  *
847  * Returns: a pointer to an #AccessibleImage interface instance, or
848  *          NULL if @obj does not implement #AccessibleImage.
849  **/
850 AccessibleImage *
851 Accessible_getImage (Accessible *obj)
852 {
853   return (AccessibleImage *) Accessible_queryInterface (
854           obj, "IDL:Accessibility/Image:1.0");
855 }
856
857
858
859 /**
860  * Accessible_getSelection:
861  * @obj: a pointer to the #Accessible instance to query.
862  *
863  * Get the #AccessibleSelection interface for an #Accessible.
864  *
865  * Returns: a pointer to an #AccessibleSelection interface instance, or
866  *          NULL if @obj does not implement #AccessibleSelection.
867  **/
868 AccessibleSelection *
869 Accessible_getSelection (Accessible *obj)
870 {
871   return (AccessibleSelection *) Accessible_queryInterface (
872           obj, "IDL:Accessibility/Selection:1.0");
873 }
874
875
876
877 /**
878  * Accessible_getStreamableContent:
879  * @obj: a pointer to the #Accessible instance to query.
880  *
881  * Get the #AccessibleStreamableContent interface for an #Accessible.
882  *
883  * Returns: a pointer to an #AccessibleStreamableContent interface instance, or
884  *          NULL if @obj does not implement #AccessibleStreamableContent.
885  **/
886 AccessibleStreamableContent *
887 Accessible_getStreamableContent (Accessible *obj)
888 {
889   return (AccessibleStreamableContent *) Accessible_queryInterface (
890           obj, "IDL:Accessibility/StreamableContent:1.0");
891 }
892
893 /**
894  * Accessible_getTable:
895  * @obj: a pointer to the #Accessible instance to query.
896  *
897  * Get the #AccessibleTable interface for an #Accessible.
898  *
899  * Returns: a pointer to an #AccessibleTable interface instance, or
900  *          NULL if @obj does not implement #AccessibleTable.
901  **/
902 AccessibleTable *
903 Accessible_getTable (Accessible *obj)
904 {
905   return (AccessibleTable *) Accessible_queryInterface (
906           obj, "IDL:Accessibility/Table:1.0");
907 }
908
909 /**
910  * Accessible_getText:
911  * @obj: a pointer to the #Accessible instance to query.
912  *
913  * Get the #AccessibleText interface for an #Accessible.
914  *
915  * Returns: a pointer to an #AccessibleText interface instance, or
916  *          NULL if @obj does not implement #AccessibleText.
917  **/
918 AccessibleText *
919 Accessible_getText (Accessible *obj)
920 {
921   return (AccessibleText *) Accessible_queryInterface (
922           obj, "IDL:Accessibility/Text:1.0");
923 }
924
925
926
927 /**
928  * Accessible_getValue:
929  * @obj: a pointer to the #Accessible instance to query.
930  *
931  * Get the #AccessibleValue interface for an #Accessible.
932  *
933  * Returns: a pointer to an #AccessibleValue interface instance, or
934  *          NULL if @obj does not implement #AccessibleValue.
935  **/
936 AccessibleValue *
937 Accessible_getValue (Accessible *obj)
938 {
939   return (AccessibleValue *) Accessible_queryInterface (
940           obj, "IDL:Accessibility/Value:1.0");
941 }
942
943
944
945 /**
946  * Accessible_queryInterface:
947  * @obj: a pointer to the #Accessible instance to query.
948  * @interface_name: a UTF-8 character string specifiying the requested interface.
949  *
950  * Query an #Accessible object to for a named interface.
951  *
952  * Returns: an instance of the named interface object, if it is implemented
953  *          by @obj, or NULL otherwise.
954  *
955  **/
956 AccessibleUnknown *
957 Accessible_queryInterface (Accessible *obj,
958                            const char *interface_name)
959 {
960   Bonobo_Unknown iface;
961   
962   if (!obj)
963     {
964       return NULL;
965     }
966
967   iface = Accessibility_Accessible_queryInterface (CSPI_OBJREF (obj),
968                                                    interface_name,
969                                                    cspi_ev ());
970
971
972   cspi_return_val_if_ev ("queryInterface", NULL); 
973
974   /*
975    * FIXME: we need to be fairly sure that references are going
976    * to mach up if we are going to expose QueryInterface, ie. we
977    * can't allow people to do:
978    * b = a.qi ("b"); b.unref, b.unref to release a's reference.
979    * this should be no real problem though for this level of API
980    * user.
981    */
982
983   return cspi_object_add (iface);
984 }
985
986
987 /**
988  * AccessibleRelation_ref:
989  * @obj: a pointer to the #AccessibleRelation object on which to operate.
990  *
991  * Increment the reference count for an #AccessibleRelation object.
992  *
993  **/
994 void
995 AccessibleRelation_ref (AccessibleRelation *obj)
996 {
997   cspi_object_ref (obj);
998 }
999
1000 /**
1001  * AccessibleRelation_unref:
1002  * @obj: a pointer to the #AccessibleRelation object on which to operate.
1003  *
1004  * Decrement the reference count for an #AccessibleRelation object.
1005  *
1006  **/
1007 void
1008 AccessibleRelation_unref (AccessibleRelation *obj)
1009 {
1010   cspi_object_unref (obj);
1011 }
1012
1013 /**
1014  * AccessibleRelation_getRelationType:
1015  * @obj: a pointer to the #AccessibleRelation object to query.
1016  *
1017  * Get the type of relationship represented by an #AccessibleRelation.
1018  *
1019  * Returns: an #AccessibleRelationType indicating the type of relation
1020  *         encapsulated in this #AccessibleRelation object.
1021  *
1022  **/
1023 AccessibleRelationType
1024 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1025 {
1026   AccessibleRelationType retval;
1027   
1028   cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1029   retval =
1030     Accessibility_Relation_getRelationType (CSPI_OBJREF (obj), cspi_ev());
1031   cspi_return_val_if_ev ("getRelationType", SPI_RELATION_NULL);
1032   return retval;
1033 }
1034
1035 /**
1036  * AccessibleRelation_getNTargets:
1037  * @obj: a pointer to the #AccessibleRelation object to query.
1038  *
1039  * Get the number of objects which this relationship has as its
1040  *       target objects (the subject is the #Accessible from which this
1041  *       #AccessibleRelation originated).
1042  *
1043  * Returns: a short integer indicating how many target objects which the
1044  *       originating #Accessible object has the #AccessibleRelation
1045  *       relationship with.
1046  **/
1047 int
1048 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1049 {
1050   int retval;
1051   
1052   cspi_return_val_if_fail (obj, -1);
1053   retval = Accessibility_Relation_getNTargets (CSPI_OBJREF (obj), cspi_ev());
1054   cspi_return_val_if_ev ("getNTargets", -1);
1055   return retval;
1056 }
1057
1058 /**
1059  * AccessibleRelation_getTarget:
1060  * @obj: a pointer to the #AccessibleRelation object to query.
1061  * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1062  *
1063  * Get the @i-th target of a specified #AccessibleRelation relationship.
1064  *
1065  * Returns: an #Accessible which is the @i-th object with which the
1066  *      originating #Accessible has relationship specified in the
1067  *      #AccessibleRelation object.
1068  *
1069  **/
1070 Accessible *
1071 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1072 {
1073   Accessible *retval;
1074
1075   cspi_return_val_if_fail (obj, NULL);
1076
1077   retval = cspi_object_add (
1078                          Accessibility_Relation_getTarget (CSPI_OBJREF(obj),
1079                                                            i, cspi_ev()));
1080   cspi_return_val_if_ev ("getTarget", NULL);
1081   return retval;
1082 }
1083
1084 /**
1085  * AccessibleStateSet_ref:
1086  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1087  *
1088  * Increment the reference count for an #AccessibleStateSet object.
1089  *
1090  **/
1091 void
1092 AccessibleStateSet_ref (AccessibleStateSet *obj)
1093 {
1094   cspi_object_ref (obj);
1095 }
1096
1097 /**
1098  * AccessibleStateSet_unref:
1099  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1100  *
1101  * Decrement the reference count for an #AccessibleStateSet object.
1102  *
1103  **/
1104 void
1105 AccessibleStateSet_unref (AccessibleStateSet *obj)
1106 {
1107   cspi_object_unref (obj);
1108 }
1109
1110 /**
1111  * AccessibleStateSet_contains:
1112  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1113  * @state: an #AccessibleState for which the specified #AccessibleStateSet
1114  *       will be queried.
1115  *
1116  * Determine whether a given #AccessibleStateSet includes a given state; that is,
1117  *       whether @state is true for the stateset in question.
1118  *
1119  * Returns: #TRUE if @state is true/included in the given #AccessibleStateSet,
1120  *          otherwise #FALSE.
1121  *
1122  **/
1123 SPIBoolean
1124 AccessibleStateSet_contains (AccessibleStateSet *obj,
1125                              AccessibleState state)
1126 {
1127   CORBA_boolean retval;
1128   Accessibility_StateType spi_state;
1129   
1130   cspi_return_val_if_fail (obj != NULL, FALSE);
1131
1132   spi_state = spi_state_type_from_accessible_state (state);
1133   retval = Accessibility_StateSet_contains (CSPI_OBJREF (obj),
1134                                             spi_state, cspi_ev ());
1135
1136   cspi_return_val_if_ev ("contains", FALSE);
1137
1138   return retval;
1139 }
1140
1141 /**
1142  * AccessibleStateSet_add:
1143  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1144  * @state: an #AccessibleState to be added to the specified #AccessibleStateSet
1145  *
1146  * Add a particular #AccessibleState to an #AccessibleStateSet (i.e. set the
1147  *       given state to #TRUE in the stateset.
1148  *
1149  **/
1150 void
1151 AccessibleStateSet_add (AccessibleStateSet *obj,
1152                         AccessibleState state)
1153 {
1154   Accessibility_StateType spi_state;
1155
1156   cspi_return_if_fail (obj != NULL);
1157
1158   spi_state = spi_state_type_from_accessible_state (state);
1159   Accessibility_StateSet_add (CSPI_OBJREF (obj), spi_state, cspi_ev ());
1160   cspi_check_ev ("StateSet_add");
1161 }
1162
1163 /**
1164  * AccessibleStateSet_remove:
1165  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1166  * @state: an #AccessibleState to be removed from the specified #AccessibleStateSet
1167  *
1168  * Remove a particular #AccessibleState to an #AccessibleStateSet (i.e. set the
1169  *       given state to #FALSE in the stateset.)
1170  *
1171  **/
1172 void
1173 AccessibleStateSet_remove (AccessibleStateSet *obj,
1174                            AccessibleState state)
1175 {
1176   Accessibility_StateType spi_state;
1177
1178   cspi_return_if_fail (obj != NULL);
1179
1180   spi_state = spi_state_type_from_accessible_state (state);
1181   Accessibility_StateSet_remove (CSPI_OBJREF (obj), spi_state, cspi_ev ());
1182   cspi_check_ev ("StateSet_remove");
1183 }
1184
1185 /**
1186  * AccessibleStateSet_equals:
1187  * @obj: a pointer to the first #AccessibleStateSet object on which to operate.
1188  * @obj2: a pointer to the second #AccessibleStateSet object on which to operate.
1189  *
1190  * Determine whether two instances of #AccessibleStateSet are equivalent (i.e.
1191  *         consist of the same #AccessibleStates).  Useful for checking multiple
1192  *         state variables at once; construct the target state then compare against it.
1193  *
1194  * @see AccessibleStateSet_compare().
1195  *
1196  * Returns: #TRUE if the two #AccessibleStateSets are equivalent,
1197  *          otherwise #FALSE.
1198  *
1199  **/
1200 SPIBoolean
1201 AccessibleStateSet_equals (AccessibleStateSet *obj,
1202                            AccessibleStateSet *obj2)
1203 {
1204   if (obj == obj2)
1205     {
1206       return TRUE;
1207     }
1208
1209   cspi_return_val_if_fail (obj != NULL, FALSE);
1210   cspi_return_val_if_fail (obj2 != NULL, FALSE);
1211
1212   return Accessibility_StateSet_equals (CSPI_OBJREF (obj),
1213                                         CSPI_OBJREF (obj2), cspi_ev ());
1214 }
1215
1216 /**
1217  * AccessibleStateSet_compare:
1218  * @obj: a pointer to the first #AccessibleStateSet object on which to operate.
1219  * @obj2: a pointer to the second #AccessibleStateSet object on which to operate.
1220  *
1221  * Determine the differences between two instances of #AccessibleStateSet.
1222  * Not Yet Implemented.
1223  *.
1224  * @see AccessibleStateSet_equals().
1225  *
1226  * Returns: an #AccessibleStateSet object containing all states contained on one of
1227  *          the two sets but not the other.
1228  *
1229  **/
1230 AccessibleStateSet *
1231 AccessibleStateSet_compare (AccessibleStateSet *obj,
1232                             AccessibleStateSet *obj2)
1233 {
1234   AccessibleStateSet *retval;
1235
1236   cspi_return_val_if_fail (obj != NULL, NULL);
1237   cspi_return_val_if_fail (obj2 != NULL, NULL);
1238   retval = cspi_object_add (
1239                          Accessibility_StateSet_compare (CSPI_OBJREF(obj), CSPI_OBJREF(obj2), cspi_ev ()));
1240
1241   cspi_return_val_if_ev ("compare", NULL);
1242   return retval;
1243 }
1244
1245 /**
1246  * AccessibleStateSet_isEmpty:
1247  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1248  *
1249  * Determine whether a given #AccessibleStateSet is the empty set.
1250  *
1251  * Returns: #TRUE if the given #AccessibleStateSet contains no (true) states,
1252  *          otherwise #FALSE.
1253  *
1254  **/
1255 SPIBoolean
1256 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1257 {
1258   CORBA_boolean retval;
1259
1260   cspi_return_val_if_fail (obj != NULL, FALSE);
1261   retval = Accessibility_StateSet_isEmpty (CSPI_OBJREF (obj), cspi_ev ());
1262
1263   cspi_return_val_if_ev ("isEmpty", TRUE);
1264   return retval;
1265 }
1266
1267