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