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