Changes to introspection generation to remove DOCTYPE and XML
[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 <libspi/stateset.h>
26 #include <cspi/spi-private.h>
27
28 static const char *role_names [] =
29 {
30   "invalid",
31   "accel-label",
32   "alert",
33   "animation",
34   "arrow",
35   "calendar",
36   "canvas",
37   "check-box",
38   "check-menu-item",
39   "color-chooser",
40   "column-header",
41   "combo-box",
42   "date-editor",
43   "desktop-icon",
44   "desktop-frame",
45   "dial",
46   "dialog",
47   "directory-pane",
48   "drawing-area",
49   "file-chooser",
50   "filler",
51   "font-chooser",
52   "frame",
53   "glass-pane",
54   "html-container",
55   "icon",
56   "image",
57   "internalframe",
58   "label",
59   "layered-pane",
60   "list",
61   "list-item",
62   "menu",
63   "menu-bar",
64   "menu-item",
65   "option-pane",
66   "page-tab",
67   "page-tab-list",
68   "panel",
69   "password-text",
70   "popup-menu",
71   "progress-bar",
72   "push-button",
73   "radio-button",
74   "radio-menu-item",
75   "root-pane",
76   "row-header",
77   "scroll-bar",
78   "scroll-pane",
79   "separator",
80   "slider",
81   "spin-button",
82   "split-pane",
83   "statusbar",
84   "table",
85   "table-cell",
86   "table-column-header",
87   "table-row-header",
88   "tear-off-menu-item",
89   "terminal",
90   "text",
91   "toggle-button",
92   "tool-bar",
93   "tool-tip",
94   "tree",
95   "tree-table",
96   "unknown",
97   "viewport",
98   "window",
99   NULL,
100   "header",
101   "fooler",
102   "paragraph",
103   "ruler",
104   "application",
105   "autocomplete",
106   "editbar",
107   "embedded",
108   "entry",
109   "chart",
110   "caption",
111   "document_frame",
112   "heading",
113   "page",
114   "section",
115   "form",
116   "redundant object",
117   "link",
118   "input method window"
119 };
120
121 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
122
123 static SPIBoolean
124 cspi_init_role_table (AccessibleRole *role_table)
125 {
126   int i;
127   for (i = 0; i < Accessibility_ROLE_LAST_DEFINED; ++i)
128     {
129       role_table [i] = SPI_ROLE_UNKNOWN;
130     }
131   role_table [Accessibility_ROLE_INVALID] = SPI_ROLE_INVALID;
132   role_table [Accessibility_ROLE_ACCELERATOR_LABEL] = SPI_ROLE_ACCEL_LABEL;
133   role_table [Accessibility_ROLE_ALERT] = SPI_ROLE_ALERT;
134   role_table [Accessibility_ROLE_ANIMATION] = SPI_ROLE_ANIMATION;
135   role_table [Accessibility_ROLE_ARROW] = SPI_ROLE_ARROW;
136   role_table [Accessibility_ROLE_CALENDAR] = SPI_ROLE_CALENDAR;
137   role_table [Accessibility_ROLE_CANVAS] = SPI_ROLE_CANVAS;
138   role_table [Accessibility_ROLE_CHECK_BOX] = SPI_ROLE_CHECK_BOX;
139   role_table [Accessibility_ROLE_CHECK_MENU_ITEM] = SPI_ROLE_CHECK_MENU_ITEM;
140   role_table [Accessibility_ROLE_COLOR_CHOOSER] = SPI_ROLE_COLOR_CHOOSER;
141   role_table [Accessibility_ROLE_COLUMN_HEADER] = SPI_ROLE_COLUMN_HEADER;
142   role_table [Accessibility_ROLE_COMBO_BOX] = SPI_ROLE_COMBO_BOX;
143   role_table [Accessibility_ROLE_DATE_EDITOR] = SPI_ROLE_DATE_EDITOR;
144   role_table [Accessibility_ROLE_DESKTOP_ICON] = SPI_ROLE_DESKTOP_ICON;
145   role_table [Accessibility_ROLE_DESKTOP_FRAME] = SPI_ROLE_DESKTOP_FRAME;
146   role_table [Accessibility_ROLE_DIAL] = SPI_ROLE_DIAL;
147   role_table [Accessibility_ROLE_DIALOG] = SPI_ROLE_DIALOG;
148   role_table [Accessibility_ROLE_DIRECTORY_PANE] = SPI_ROLE_DIRECTORY_PANE;
149   role_table [Accessibility_ROLE_DRAWING_AREA] = SPI_ROLE_DRAWING_AREA;
150   role_table [Accessibility_ROLE_FILE_CHOOSER] = SPI_ROLE_FILE_CHOOSER;
151   role_table [Accessibility_ROLE_FILLER] = SPI_ROLE_FILLER;
152   role_table [Accessibility_ROLE_FONT_CHOOSER] = SPI_ROLE_FONT_CHOOSER;
153   role_table [Accessibility_ROLE_FRAME] = SPI_ROLE_FRAME;
154   role_table [Accessibility_ROLE_GLASS_PANE] = SPI_ROLE_GLASS_PANE;
155   role_table [Accessibility_ROLE_HTML_CONTAINER] = SPI_ROLE_HTML_CONTAINER;
156   role_table [Accessibility_ROLE_ICON] = SPI_ROLE_ICON;
157   role_table [Accessibility_ROLE_IMAGE] = SPI_ROLE_IMAGE;
158   role_table [Accessibility_ROLE_INTERNAL_FRAME] = SPI_ROLE_INTERNAL_FRAME;
159   role_table [Accessibility_ROLE_LABEL] = SPI_ROLE_LABEL;
160   role_table [Accessibility_ROLE_LAYERED_PANE] = SPI_ROLE_LAYERED_PANE;
161   role_table [Accessibility_ROLE_LIST] = SPI_ROLE_LIST;
162   role_table [Accessibility_ROLE_LIST_ITEM] = SPI_ROLE_LIST_ITEM;
163   role_table [Accessibility_ROLE_MENU] = SPI_ROLE_MENU;
164   role_table [Accessibility_ROLE_MENU_BAR] = SPI_ROLE_MENU_BAR;
165   role_table [Accessibility_ROLE_MENU_ITEM] = SPI_ROLE_MENU_ITEM;
166   role_table [Accessibility_ROLE_OPTION_PANE] = SPI_ROLE_OPTION_PANE;
167   role_table [Accessibility_ROLE_PAGE_TAB] = SPI_ROLE_PAGE_TAB;
168   role_table [Accessibility_ROLE_PAGE_TAB_LIST] = SPI_ROLE_PAGE_TAB_LIST;
169   role_table [Accessibility_ROLE_PANEL] = SPI_ROLE_PANEL;
170   role_table [Accessibility_ROLE_PASSWORD_TEXT] = SPI_ROLE_PASSWORD_TEXT;
171   role_table [Accessibility_ROLE_POPUP_MENU] = SPI_ROLE_POPUP_MENU;
172   role_table [Accessibility_ROLE_PROGRESS_BAR] = SPI_ROLE_PROGRESS_BAR;
173   role_table [Accessibility_ROLE_PUSH_BUTTON] = SPI_ROLE_PUSH_BUTTON;
174   role_table [Accessibility_ROLE_RADIO_BUTTON] = SPI_ROLE_RADIO_BUTTON;
175   role_table [Accessibility_ROLE_RADIO_MENU_ITEM] = SPI_ROLE_RADIO_MENU_ITEM;
176   role_table [Accessibility_ROLE_ROOT_PANE] = SPI_ROLE_ROOT_PANE;
177   role_table [Accessibility_ROLE_ROW_HEADER] = SPI_ROLE_ROW_HEADER;
178   role_table [Accessibility_ROLE_SCROLL_BAR] = SPI_ROLE_SCROLL_BAR;
179   role_table [Accessibility_ROLE_SCROLL_PANE] = SPI_ROLE_SCROLL_PANE;
180   role_table [Accessibility_ROLE_SEPARATOR] = SPI_ROLE_SEPARATOR;
181   role_table [Accessibility_ROLE_SLIDER] = SPI_ROLE_SLIDER;
182   role_table [Accessibility_ROLE_SPIN_BUTTON] = SPI_ROLE_SPIN_BUTTON;
183   role_table [Accessibility_ROLE_SPLIT_PANE] = SPI_ROLE_SPLIT_PANE;
184   role_table [Accessibility_ROLE_STATUS_BAR] = SPI_ROLE_STATUS_BAR;
185   role_table [Accessibility_ROLE_TABLE] = SPI_ROLE_TABLE;
186   role_table [Accessibility_ROLE_TABLE_CELL] = SPI_ROLE_TABLE_CELL;
187   role_table[Accessibility_ROLE_TABLE_COLUMN_HEADER] = SPI_ROLE_TABLE_COLUMN_HEADER;
188   role_table[Accessibility_ROLE_TABLE_ROW_HEADER] = SPI_ROLE_TABLE_ROW_HEADER;
189   role_table [Accessibility_ROLE_TEAROFF_MENU_ITEM] = SPI_ROLE_TEAROFF_MENU_ITEM;
190   role_table[Accessibility_ROLE_TERMINAL] = SPI_ROLE_TERMINAL;
191   role_table [Accessibility_ROLE_TEXT] = SPI_ROLE_TEXT;
192   role_table [Accessibility_ROLE_TOGGLE_BUTTON] = SPI_ROLE_TOGGLE_BUTTON;
193   role_table [Accessibility_ROLE_TOOL_BAR] = SPI_ROLE_TOOL_BAR;
194   role_table [Accessibility_ROLE_TOOL_TIP] = SPI_ROLE_TOOL_TIP;
195   role_table [Accessibility_ROLE_TREE] = SPI_ROLE_TREE;
196   role_table [Accessibility_ROLE_TREE_TABLE] = SPI_ROLE_TREE_TABLE;
197   role_table [Accessibility_ROLE_VIEWPORT] = SPI_ROLE_VIEWPORT;
198   role_table [Accessibility_ROLE_WINDOW] = SPI_ROLE_WINDOW;
199   role_table [Accessibility_ROLE_EXTENDED] = SPI_ROLE_EXTENDED;
200   role_table [Accessibility_ROLE_HEADER] = SPI_ROLE_HEADER;
201   role_table [Accessibility_ROLE_FOOTER] = SPI_ROLE_FOOTER;
202   role_table [Accessibility_ROLE_PARAGRAPH] = SPI_ROLE_PARAGRAPH;
203   role_table [Accessibility_ROLE_RULER] = SPI_ROLE_RULER;
204   role_table [Accessibility_ROLE_APPLICATION] = SPI_ROLE_APPLICATION;
205   role_table [Accessibility_ROLE_AUTOCOMPLETE] = SPI_ROLE_AUTOCOMPLETE;
206   role_table [Accessibility_ROLE_EDITBAR] = SPI_ROLE_EDITBAR;
207   role_table [Accessibility_ROLE_EMBEDDED] = SPI_ROLE_EMBEDDED;
208   role_table [Accessibility_ROLE_ENTRY] = SPI_ROLE_ENTRY;
209   role_table [Accessibility_ROLE_CHART] = SPI_ROLE_CHART;
210   role_table [Accessibility_ROLE_CAPTION] = SPI_ROLE_CAPTION;
211   role_table [Accessibility_ROLE_DOCUMENT_FRAME] = SPI_ROLE_DOCUMENT_FRAME;
212   role_table [Accessibility_ROLE_HEADING] = SPI_ROLE_HEADING;
213   role_table [Accessibility_ROLE_PAGE] = SPI_ROLE_PAGE;
214   role_table [Accessibility_ROLE_SECTION] = SPI_ROLE_SECTION;
215   role_table [Accessibility_ROLE_FORM] = SPI_ROLE_FORM;
216   role_table [Accessibility_ROLE_REDUNDANT_OBJECT] = SPI_ROLE_REDUNDANT_OBJECT;
217   role_table [Accessibility_ROLE_LINK] = SPI_ROLE_LINK;
218   role_table [Accessibility_ROLE_INPUT_METHOD_WINDOW] = SPI_ROLE_INPUT_METHOD_WINDOW;
219
220   return TRUE;
221 }
222
223 AccessibleRole
224 cspi_role_from_spi_role (Accessibility_Role role)
225 {
226   /* array is sized according to IDL roles because IDL roles are the index */   
227   static AccessibleRole cspi_role_table [Accessibility_ROLE_LAST_DEFINED];
228   static SPIBoolean is_initialized = FALSE;
229   AccessibleRole cspi_role;
230   if (!is_initialized)
231     {
232       is_initialized = cspi_init_role_table (cspi_role_table);      
233     }
234   if (role >= 0 && role < Accessibility_ROLE_LAST_DEFINED)
235     {
236       cspi_role = cspi_role_table [role];           
237     }
238   else
239     {
240       cspi_role = SPI_ROLE_EXTENDED;
241     }
242   return cspi_role; 
243 }
244
245 AccessibleAttributeSet *
246 _cspi_attribute_set_from_sequence (const Accessibility_AttributeSet *seq)
247 {
248     AccessibleAttributeSet *set = g_new0 (AccessibleAttributeSet, 1);
249     int i;
250
251     set->len = seq->_length;
252     set->attributes = g_new0 (char *, set->len);
253     for (i = 0; i < set->len; ++i)
254     {
255         set->attributes[i] = g_strdup (seq->_buffer [i]);
256     }
257     return set;
258 }
259
260 /**
261  * AccessibleRole_getName:
262  * @role: an #AccessibleRole object to query.
263  *
264  * Get a localizeable string that indicates the name of an #AccessibleRole.
265  * <em>DEPRECATED.</em>
266  *
267  * Returns: a localizable string name for an #AccessibleRole enumerated type.
268  **/
269 char *
270 AccessibleRole_getName (AccessibleRole role)
271 {
272   if (role < MAX_ROLES && role_names [(int) role])
273     {
274       return CORBA_string_dup (role_names [(int) role]);
275     }
276   else
277     {
278       return CORBA_string_dup ("");
279     }
280 }
281
282 /**
283  * Accessible_ref:
284  * @obj: a pointer to the #Accessible object on which to operate.
285  *
286  * Increment the reference count for an #Accessible object.
287  **/
288 void
289 Accessible_ref (Accessible *obj)
290 {
291   cspi_object_ref (obj);
292 }
293
294 /**
295  * Accessible_unref:
296  * @obj: a pointer to the #Accessible object on which to operate.
297  *
298  * Decrement the reference count for an #Accessible object.
299  **/
300 void
301 Accessible_unref (Accessible *obj)
302 {
303   cspi_object_unref (obj);
304 }
305
306 /**
307  * Accessible_getName:
308  * @obj: a pointer to the #Accessible object on which to operate.
309  *
310  * Get the name of an #Accessible object.
311  *
312  * Returns: a UTF-8 string indicating the name of the #Accessible object.
313  * or NULL on exception
314  **/
315 char *
316 Accessible_getName (Accessible *obj)
317 {
318   char *retval;
319
320   cspi_return_val_if_fail (obj != NULL, NULL);
321
322   retval = Accessibility_Accessible__get_name (CSPI_OBJREF (obj), cspi_ev ());
323
324   cspi_return_val_if_ev ("getName", NULL); 
325
326   return retval;
327 }
328
329 /**
330  * Accessible_getDescription:
331  * @obj: a pointer to the #Accessible object on which to operate.
332  *
333  * Get the description of an #Accessible object.
334  *
335  * Returns: a UTF-8 string describing the #Accessible object.
336  * or NULL on exception
337  **/
338 char *
339 Accessible_getDescription (Accessible *obj)
340 {
341   char *retval;
342
343   cspi_return_val_if_fail (obj != NULL, NULL);
344
345   retval = Accessibility_Accessible__get_description (CSPI_OBJREF (obj),
346                                                cspi_ev ());
347
348   cspi_return_val_if_ev ("getDescription", NULL); 
349
350   return retval;
351 }
352
353 /**
354  * Accessible_getParent:
355  * @obj: a pointer to the #Accessible object to query.
356  *
357  * Get an #Accessible object's parent container.
358  *
359  * Returns: a pointer tothe #Accessible object which contains the given
360  *          #Accessible instance, or NULL if the @obj has no parent container.
361  *
362  **/
363 Accessible *
364 Accessible_getParent (Accessible *obj)
365 {
366   Accessible *retval;
367
368   cspi_return_val_if_fail (obj != NULL, NULL);
369
370   retval = cspi_object_add (
371     Accessibility_Accessible__get_parent (CSPI_OBJREF (obj),
372                                           cspi_ev ()));
373
374   cspi_return_val_if_ev ("getParent", NULL); 
375
376   return retval;
377 }
378
379 /**
380  * Accessible_getChildCount:
381  * @obj: a pointer to the #Accessible object on which to operate.
382  *
383  * Get the number of children contained by an #Accessible object.
384  *
385  * Returns: a #long indicating the number of #Accessible children
386  *          contained by an #Accessible object. or -1 on exception
387  *
388  **/
389 long
390 Accessible_getChildCount (Accessible *obj)
391 {
392   long retval;
393
394   cspi_return_val_if_fail (obj != NULL, -1);
395
396   retval = Accessibility_Accessible__get_childCount (CSPI_OBJREF (obj),
397                                               cspi_ev ());
398
399   cspi_return_val_if_ev ("getChildCount", -1); 
400
401   return retval;
402 }
403
404 /**
405  * Accessible_getChildAtIndex:
406  * @obj: a pointer to the #Accessible object on which to operate.
407  * @childIndex: a #long indicating which child is specified.
408  *
409  * Get the #Accessible child of an #Accessible object at a given index.
410  *
411  * Returns: a pointer to the #Accessible child object at index
412  *          @childIndex. or NULL on exception
413  **/
414 Accessible *
415 Accessible_getChildAtIndex (Accessible *obj,
416                             long int    childIndex)
417 {
418   Accessible *retval;
419
420   cspi_return_val_if_fail (obj != NULL, NULL);
421
422   retval = cspi_object_add (
423     Accessibility_Accessible_getChildAtIndex (CSPI_OBJREF (obj),
424                                               childIndex, cspi_ev ()));
425
426   cspi_return_val_if_ev ("getChildAtIndex", NULL);
427   return retval;
428 }
429
430 /**
431  * Accessible_getIndexInParent:
432  * @obj: a pointer to the #Accessible object on which to operate.
433  *
434  * Get the index of an #Accessible object in its containing #Accessible.
435  *
436  * Returns: a #long indicating the index of the #Accessible object
437  *          in its parent (i.e. containing) #Accessible instance,
438  *          or -1 if @obj has no containing parent or on exception.
439  **/
440 long
441 Accessible_getIndexInParent (Accessible *obj)
442 {
443   long retval;
444
445   cspi_return_val_if_fail (obj != NULL, -1);
446
447   retval = Accessibility_Accessible_getIndexInParent (CSPI_OBJREF (obj), cspi_ev ());
448
449   cspi_return_val_if_ev ("getIndexInparent", -1); 
450   return retval;
451 }
452
453 /**
454  * Accessible_getRelationSet:
455  * @obj: a pointer to the #Accessible object on which to operate.
456  *
457  * Get the set of #AccessibleRelation objects which describe this #Accessible object's
458  *       relationships with other #Accessible objects.
459  *
460  * Returns: an array of #AccessibleRelation pointers. or NULL on exception
461  **/
462 AccessibleRelation **
463 Accessible_getRelationSet (Accessible *obj)
464 {
465   int i;
466   int n_relations;
467   AccessibleRelation **relations;
468   Accessibility_RelationSet *relation_set;
469
470   cspi_return_val_if_fail (obj != NULL, NULL);
471
472   g_assert (!cspi_exception ());
473
474   relation_set =
475     Accessibility_Accessible_getRelationSet (CSPI_OBJREF (obj), cspi_ev ());
476
477   cspi_return_val_if_ev ("getRelationSet", NULL); 
478   
479   n_relations = relation_set->_length;
480   relations = malloc (sizeof (AccessibleRelation *) * (n_relations + 1));
481   
482   for (i = 0; i < n_relations; ++i)
483     {
484       relations[i] = cspi_object_add (CORBA_Object_duplicate (
485               relation_set->_buffer[i], cspi_ev ()));
486     }
487   relations[i] = NULL;
488
489   CORBA_free (relation_set);
490
491   return relations;
492 }
493
494 /**
495  * Accessible_getRole:
496  * @obj: a pointer to the #Accessible object on which to operate.
497  *
498  * Get the UI role of an #Accessible object.
499  * A UTF-8 string describing this role can be obtained via Accessible_getRoleName ().
500  *
501  * Returns: the #AccessibleRole of the object.
502  *
503  **/
504 AccessibleRole
505 Accessible_getRole (Accessible *obj)
506 {
507   Accessibility_Role retval;
508
509   cspi_return_val_if_fail (obj != NULL, SPI_ROLE_INVALID);
510
511   retval = 
512     Accessibility_Accessible_getRole (CSPI_OBJREF (obj), cspi_ev ());
513
514   cspi_return_val_if_ev ("getRole", SPI_ROLE_INVALID); 
515
516   return cspi_role_from_spi_role (retval);
517 }
518
519 /**
520  * Accessible_getRoleName:
521  * @obj: a pointer to the #Accessible object on which to operate.
522  *
523  * Get a UTF-8 string describing the role this object plays in the UI.
524  * This method will return useful values for roles that fall outside the
525  * enumeration used in Accessible_getRole ().
526  *
527  * Returns: a UTF-8 string specifying the role of this #Accessible object.
528  *
529  **/
530 char *
531 Accessible_getRoleName (Accessible *obj)
532 {
533   char *retval;
534
535   cspi_return_val_if_fail (obj != NULL, CORBA_string_dup ("invalid"));
536
537   retval = 
538     Accessibility_Accessible_getRoleName (CSPI_OBJREF (obj), cspi_ev ());
539
540   cspi_return_val_if_ev ("getRoleName", CORBA_string_dup ("invalid")); 
541
542   return retval;
543 }
544
545 /**
546  * Accessible_getLocalizedRoleName:
547  * @obj: a pointer to the #Accessible object on which to operate.
548  *
549  * Get a UTF-8 string describing the (localized) role this object plays in the UI.
550  * This method will return useful values for roles that fall outside the
551  * enumeration used in Accessible_getRole ().
552  *
553  * @Since: AT-SPI 1.4
554  *
555  * Returns: a UTF-8 string specifying the role of this #Accessible object.
556  *
557  **/
558 char *
559 Accessible_getLocalizedRoleName (Accessible *obj)
560 {
561   char *retval;
562
563   cspi_return_val_if_fail (obj != NULL, CORBA_string_dup ("invalid"));
564
565   retval = 
566     Accessibility_Accessible_getLocalizedRoleName (CSPI_OBJREF (obj), cspi_ev ());
567
568   cspi_return_val_if_ev ("getLocalizedRoleName", CORBA_string_dup ("invalid")); 
569
570   return retval;
571 }
572
573 /**
574  * Accessible_getStateSet:
575  * @obj: a pointer to the #Accessible object on which to operate.
576  *
577  * Gets the current state of an object.
578  *
579  * Returns: a pointer to an #AccessibleStateSet representing the object's current state.
580  **/
581 AccessibleStateSet *
582 Accessible_getStateSet (Accessible *obj)
583 {
584   AccessibleStateSet *retval;
585   Accessibility_StateSet corba_stateset;
586   Accessibility_StateSeq *corba_seq;
587
588   cspi_return_val_if_fail (obj != NULL, NULL);
589
590   corba_stateset = Accessibility_Accessible_getState (
591           CSPI_OBJREF (obj), cspi_ev ());
592   cspi_return_val_if_ev ("getState", NULL);
593
594   cspi_return_val_if_fail (corba_stateset != CORBA_OBJECT_NIL, NULL);
595   cspi_return_val_if_fail (cspi_ping (corba_stateset), NULL);
596   corba_seq = Accessibility_StateSet_getStates (corba_stateset, cspi_ev ());
597   cspi_return_val_if_ev ("getState", NULL);
598
599   retval = spi_state_set_cache_new (corba_seq);
600
601   CORBA_free (corba_seq);
602   cspi_release_unref (corba_stateset);
603
604   return retval;
605 }
606
607 /**
608  * Accessible_getAttributes:
609  * @obj: The #Accessible being queried.
610  *
611  * Get the #AttributeSet representing any assigned 
612  * name-value pair attributes or annotations for this object.
613  * For typographic, textual, or textually-semantic attributes, see
614  * AccessibleText_getAttributes instead.
615  *
616  * Returns: The name-value-pair attributes assigned to this object.
617  */
618 AccessibleAttributeSet *
619 Accessible_getAttributes (Accessible *obj)
620 {
621     AccessibleAttributeSet *retval;
622     Accessibility_AttributeSet *corba_seq;
623
624     cspi_return_val_if_fail (obj != NULL, NULL);
625
626     corba_seq = Accessibility_Accessible_getAttributes (
627         CSPI_OBJREF (obj), cspi_ev ());
628     cspi_return_val_if_ev ("getAttributes", NULL);
629     
630     retval = _cspi_attribute_set_from_sequence (corba_seq);
631     CORBA_free (corba_seq);
632
633     return retval;
634 }
635
636 /**
637  * Accessible_getHostApplication:
638  * @obj: The #Accessible being queried.
639  *
640  * Get the containing #AccessibleApplication for an object.
641  *
642  * Returns: the containing AccessibleApplication instance for this object.
643  */
644 AccessibleApplication *
645 Accessible_getHostApplication (Accessible *obj)
646 {
647     AccessibleApplication *retval;
648
649     cspi_return_val_if_fail (obj != NULL, NULL);
650
651     retval = Accessible_getApplication (cspi_object_add (
652                                             Accessibility_Accessible_getApplication (CSPI_OBJREF (obj),
653                                                                                      cspi_ev ())));
654     cspi_return_val_if_ev ("getApplication", NULL);
655
656     return retval;
657 }
658
659 /* Interface query methods */
660
661 /**
662  * Accessible_isAction:
663  * @obj: a pointer to the #Accessible instance to query.
664  *
665  * Query whether the specified #Accessible implements #AccessibleAction.
666  *
667  * Returns: #TRUE if @obj implements the #AccessibleAction interface,
668  *          #FALSE otherwise.
669  **/
670 SPIBoolean
671 Accessible_isAction (Accessible *obj)
672 {
673   return cspi_accessible_is_a (obj,
674                               "IDL:Accessibility/Action:1.0");
675 }
676
677 /**
678  * Accessible_isApplication:
679  * @obj: a pointer to the #Accessible instance to query.
680  *
681  * Query whether the specified #Accessible implements #AccessibleApplication.
682  *
683  * Returns: #TRUE if @obj implements the #AccessibleApplication interface,
684  *          #FALSE otherwise.
685  **/
686 SPIBoolean
687 Accessible_isApplication (Accessible *obj)
688 {
689   return cspi_accessible_is_a (obj,
690                               "IDL:Accessibility/Application:1.0");
691 }
692
693 /**                      
694  * Accessible_isCollection:                                                                                                                                                                          * @obj: a pointer to the #Accessible instance to query.                                                                                                                                          
695  *                          
696  * Query whether the specified #Accessible implements #AccessibleCollection.    
697  * Returns: #TRUE if @obj implements the #AccessibleCollection interface,                                                                                                               
698  *          #FALSE otherwise.
699  **/
700
701 SPIBoolean
702 Accessible_isCollection (Accessible *obj)
703 {
704      return cspi_accessible_is_a (obj,
705                                   "IDL:Accessibility/Collection:1.0");
706 }
707
708 /**
709  * Accessible_isComponent:
710  * @obj: a pointer to the #Accessible instance to query.
711  *
712  * Query whether the specified #Accessible implements #AccessibleComponent.
713  *
714  * Returns: #TRUE if @obj implements the #AccessibleComponent interface,
715  *          #FALSE otherwise.
716  **/
717 SPIBoolean
718 Accessible_isComponent (Accessible *obj)
719 {
720   return cspi_accessible_is_a (obj,
721                               "IDL:Accessibility/Component:1.0");
722 }
723
724 /**
725  * Accessible_isDocument:
726  * @obj: a pointer to the #Accessible instance to query.
727  *
728  * Query whether the specified #Accessible implements #AccessibleDocument.
729  *
730  * Returns: #TRUE if @obj implements the #AccessibleDocument interface,
731  *          #FALSE otherwise.
732  **/
733 SPIBoolean
734 Accessible_isDocument (Accessible *obj)
735 {
736   return cspi_accessible_is_a (obj,
737                               "IDL:Accessibility/Document:1.0");
738 }
739
740 /**
741  * Accessible_isEditableText:
742  * @obj: a pointer to the #Accessible instance to query.
743  *
744  * Query whether the specified #Accessible implements #AccessibleEditableText.
745  *
746  * Returns: #TRUE if @obj implements the #AccessibleEditableText interface,
747  *          #FALSE otherwise.
748  **/
749 SPIBoolean
750 Accessible_isEditableText (Accessible *obj)
751 {
752   return cspi_accessible_is_a (obj,
753                               "IDL:Accessibility/EditableText:1.0");
754 }
755                                                                                                                                                                         
756 /**
757  * Accessible_isMatchRule:
758  * @obj: a pointer to the #Accessible instance to query.
759  *
760  * Query whether the specified #Accessible implements #AccessibleMatchRule.
761  *
762  * Returns: #TRUE if @obj implements the #AccessibleMatchRule interface,
763  *          #FALSE otherwise.
764  **/
765 SPIBoolean
766 Accessible_isMatchRule (Accessible *obj)
767 {
768      return cspi_accessible_is_a (obj, 
769                                   "IDL:Accessibility/MatchRule:1.0");
770 }
771
772 /**
773  * Accessible_isHypertext:
774  * @obj: a pointer to the #Accessible instance to query.
775  *
776  * Query whether the specified #Accessible implements #AccessibleHypertext.
777  *
778  * Returns: #TRUE if @obj implements the #AccessibleHypertext interface,
779  *          #FALSE otherwise.
780  **/
781 SPIBoolean
782 Accessible_isHypertext (Accessible *obj)
783 {
784   return cspi_accessible_is_a (obj,
785                               "IDL:Accessibility/Hypertext:1.0");
786 }
787
788 /**
789  * Accessible_isImage:
790  * @obj: a pointer to the #Accessible instance to query.
791  *
792  * Query whether the specified #Accessible implements #AccessibleImage.
793  *
794  * Returns: #TRUE if @obj implements the #AccessibleImage interface,
795  *          #FALSE otherwise.
796 **/
797 SPIBoolean
798 Accessible_isImage (Accessible *obj)
799 {
800   return cspi_accessible_is_a (obj,
801                               "IDL:Accessibility/Image:1.0");
802 }
803
804 /**
805  * Accessible_isSelection:
806  * @obj: a pointer to the #Accessible instance to query.
807  *
808  * Query whether the specified #Accessible implements #AccessibleSelection.
809  *
810  * Returns: #TRUE if @obj implements the #AccessibleSelection interface,
811  *          #FALSE otherwise.
812 **/
813 SPIBoolean
814 Accessible_isSelection (Accessible *obj)
815 {
816   return cspi_accessible_is_a (obj,
817                               "IDL:Accessibility/Selection:1.0");
818 }
819
820 /**
821  * Accessible_isTable:
822  * @obj: a pointer to the #Accessible instance to query.
823  *
824  * Query whether the specified #Accessible implements #AccessibleTable.
825  *
826  * Returns: #TRUE if @obj implements the #AccessibleTable interface,
827  *          #FALSE otherwise.
828 **/
829 SPIBoolean
830 Accessible_isTable (Accessible *obj)
831 {
832   return cspi_accessible_is_a (obj,
833                               "IDL:Accessibility/Table:1.0");
834 }
835
836 /**
837  * Accessible_isStreamableContent:
838  * @obj: a pointer to the #Accessible instance to query.
839  *
840  * Query whether the specified #Accessible implements
841  *          #AccessibleStreamableContent.
842  *
843  * Returns: #TRUE if @obj implements the #AccessibleStreamableContent interface,
844  *          #FALSE otherwise.
845 **/
846 SPIBoolean
847 Accessible_isStreamableContent (Accessible *obj)
848 {
849   return cspi_accessible_is_a (obj,
850                               "IDL:Accessibility/StreamableContent:1.0");
851 }
852
853 /**
854  * Accessible_isText:
855  * @obj: a pointer to the #Accessible instance to query.
856  *
857  * Query whether the specified #Accessible implements #AccessibleText.
858  *
859  * Returns: #TRUE if @obj implements the #AccessibleText interface,
860  *          #FALSE otherwise.
861 **/
862 SPIBoolean
863 Accessible_isText (Accessible *obj)
864 {
865   return cspi_accessible_is_a (obj,
866                               "IDL:Accessibility/Text:1.0");
867 }
868
869 /**
870  * Accessible_isValue:
871  * @obj: a pointer to the #Accessible instance to query.
872  *
873  * Query whether the specified #Accessible implements #AccessibleValue.
874  *
875  * Returns: #TRUE if @obj implements the #AccessibleValue interface,
876  *          #FALSE otherwise.
877 **/
878 SPIBoolean
879 Accessible_isValue (Accessible *obj)
880 {
881   return cspi_accessible_is_a (obj,
882                               "IDL:Accessibility/Value:1.0");
883 }
884
885 /**
886  * Accessible_getApplication:
887  * @obj: a pointer to the #Accessible instance to query.
888  *
889  * Get the #AccessibleApplication interface for an #Accessible.
890  *
891  * Returns: a pointer to an #AccessibleApplication interface instance, or
892  *          NULL if @obj does not implement #AccessibleApplication.
893  **/
894 AccessibleApplication *
895 Accessible_getApplication (Accessible *obj)
896 {
897   return (AccessibleApplication *) Accessible_queryInterface (
898           obj, "IDL:Accessibility/Application:1.0");
899 }
900
901 /**
902  * Accessible_getAction:
903  * @obj: a pointer to the #Accessible instance to query.
904  *
905  * Get the #AccessibleAction interface for an #Accessible.
906  *
907  * Returns: a pointer to an #AccessibleAction interface instance, or
908  *          NULL if @obj does not implement #AccessibleAction.
909  **/
910 AccessibleAction *
911 Accessible_getAction (Accessible *obj)
912 {
913   return (AccessibleAction *) Accessible_queryInterface (
914           obj, "IDL:Accessibility/Action:1.0");
915 }
916
917
918 /**
919  * Accessible_getCollection:
920  * @obj: a pointer to the #Accessible instance to query.
921  *
922  * Get the #AccessibleCollection interface for an #Accessible.
923  *
924  * Returns: a pointer to an #AccessibleCollection interface instance, or
925  *          NULL if @obj does not implement #AccessibleCollection.
926  **/
927 AccessibleCollection *
928 Accessible_getCollection (Accessible *obj)
929 {
930   return (AccessibleCollection *) Accessible_queryInterface (
931           obj, "IDL:Accessibility/Collection:1.0");
932 }
933
934 /**
935  * Accessible_getComponent:
936  * @obj: a pointer to the #Accessible instance to query.
937  *
938  * Get the #AccessibleComponent interface for an #Accessible.
939  *
940  * Returns: a pointer to an #AccessibleComponent interface instance, or
941  *          NULL if @obj does not implement #AccessibleComponent.
942  **/
943 AccessibleComponent *
944 Accessible_getComponent (Accessible *obj)
945 {
946   return (AccessibleComponent *) Accessible_queryInterface (
947           obj, "IDL:Accessibility/Component:1.0");
948 }
949 /**
950  * Accessible_getDocument:
951  * @obj: a pointer to the #Accessible instance to query.
952  *
953  * Get the #AccessibleDocument interface for an #Accessible.
954  *
955  * Returns: a pointer to an #AccessibleDocument interface instance, or
956  *          NULL if @obj does not implement #AccessibleDocument.
957  **/
958 AccessibleDocument *
959 Accessible_getDocument (Accessible *obj)
960 {
961   return (AccessibleDocument *) Accessible_queryInterface (
962           obj, "IDL:Accessibility/Document:1.0");
963 }
964
965 /**
966  * Accessible_getEditableText:
967  * @obj: a pointer to the #Accessible instance to query.
968  *
969  * Get the #AccessibleEditableText interface for an #Accessible.
970  *
971  * Returns: a pointer to an #AccessibleEditableText interface instance, or
972  *          NULL if @obj does not implement #AccessibleEditableText.
973  **/
974 AccessibleEditableText *
975 Accessible_getEditableText (Accessible *obj)
976 {
977   return (AccessibleEditableText *) Accessible_queryInterface (
978           obj, "IDL:Accessibility/EditableText:1.0");
979 }
980
981
982
983 /**
984  * Accessible_getHypertext:
985  * @obj: a pointer to the #Accessible instance to query.
986  *
987  * Get the #AccessibleHypertext interface for an #Accessible.
988  *
989  * Returns: a pointer to an #AccessibleHypertext interface instance, or
990  *          NULL if @obj does not implement #AccessibleHypertext.
991  **/
992 AccessibleHypertext *
993 Accessible_getHypertext (Accessible *obj)
994 {
995   return (AccessibleHypertext *) Accessible_queryInterface (
996           obj, "IDL:Accessibility/Hypertext:1.0");
997 }
998
999
1000
1001 /**
1002  * Accessible_getImage:
1003  * @obj: a pointer to the #Accessible instance to query.
1004  *
1005  * Get the #AccessibleImage interface for an #Accessible.
1006  *
1007  * Returns: a pointer to an #AccessibleImage interface instance, or
1008  *          NULL if @obj does not implement #AccessibleImage.
1009  **/
1010 AccessibleImage *
1011 Accessible_getImage (Accessible *obj)
1012 {
1013   return (AccessibleImage *) Accessible_queryInterface (
1014           obj, "IDL:Accessibility/Image:1.0");
1015 }
1016
1017 /**
1018  * Accessible_getMatchRule:
1019  * @obj: a pointer to the #Accessible instance to query.
1020  *
1021  * Get the #AccessibleMatchRule interface for an #Accessible.
1022  *
1023  * Returns: a pointer to an #AccessibleMatchRule interface instance, or
1024  *          NULL if @obj does not implement #AccessibleMatchRule.
1025  **/
1026 AccessibleMatchRule *
1027 Accessible_getMatchRule (Accessible *obj)
1028 {
1029   return (AccessibleMatchRule *) Accessible_queryInterface (
1030           obj, "IDL:Accessibility/MatchRule:1.0");
1031 }
1032
1033 /**
1034  * Accessible_getSelection:
1035  * @obj: a pointer to the #Accessible instance to query.
1036  *
1037  * Get the #AccessibleSelection interface for an #Accessible.
1038  *
1039  * Returns: a pointer to an #AccessibleSelection interface instance, or
1040  *          NULL if @obj does not implement #AccessibleSelection.
1041  **/
1042 AccessibleSelection *
1043 Accessible_getSelection (Accessible *obj)
1044 {
1045   return (AccessibleSelection *) Accessible_queryInterface (
1046           obj, "IDL:Accessibility/Selection:1.0");
1047 }
1048
1049
1050
1051 /**
1052  * Accessible_getStreamableContent:
1053  * @obj: a pointer to the #Accessible instance to query.
1054  *
1055  * Get the #AccessibleStreamableContent interface for an #Accessible.
1056  *
1057  * Returns: a pointer to an #AccessibleStreamableContent interface instance, or
1058  *          NULL if @obj does not implement #AccessibleStreamableContent.
1059  **/
1060 AccessibleStreamableContent *
1061 Accessible_getStreamableContent (Accessible *obj)
1062 {
1063   return (AccessibleStreamableContent *) Accessible_queryInterface (
1064           obj, "IDL:Accessibility/StreamableContent:1.0");
1065 }
1066
1067 /**
1068  * Accessible_getTable:
1069  * @obj: a pointer to the #Accessible instance to query.
1070  *
1071  * Get the #AccessibleTable interface for an #Accessible.
1072  *
1073  * Returns: a pointer to an #AccessibleTable interface instance, or
1074  *          NULL if @obj does not implement #AccessibleTable.
1075  **/
1076 AccessibleTable *
1077 Accessible_getTable (Accessible *obj)
1078 {
1079   return (AccessibleTable *) Accessible_queryInterface (
1080           obj, "IDL:Accessibility/Table:1.0");
1081 }
1082
1083 /**
1084  * Accessible_getText:
1085  * @obj: a pointer to the #Accessible instance to query.
1086  *
1087  * Get the #AccessibleText interface for an #Accessible.
1088  *
1089  * Returns: a pointer to an #AccessibleText interface instance, or
1090  *          NULL if @obj does not implement #AccessibleText.
1091  **/
1092 AccessibleText *
1093 Accessible_getText (Accessible *obj)
1094 {
1095   return (AccessibleText *) Accessible_queryInterface (
1096           obj, "IDL:Accessibility/Text:1.0");
1097 }
1098
1099
1100
1101 /**
1102  * Accessible_getValue:
1103  * @obj: a pointer to the #Accessible instance to query.
1104  *
1105  * Get the #AccessibleValue interface for an #Accessible.
1106  *
1107  * Returns: a pointer to an #AccessibleValue interface instance, or
1108  *          NULL if @obj does not implement #AccessibleValue.
1109  **/
1110 AccessibleValue *
1111 Accessible_getValue (Accessible *obj)
1112 {
1113   return (AccessibleValue *) Accessible_queryInterface (
1114           obj, "IDL:Accessibility/Value:1.0");
1115 }
1116
1117
1118
1119 /**
1120  * Accessible_queryInterface:
1121  * @obj: a pointer to the #Accessible instance to query.
1122  * @interface_name: a UTF-8 character string specifiying the requested interface.
1123  *
1124  * Query an #Accessible object to for a named interface.
1125  *
1126  * Returns: an instance of the named interface object, if it is implemented
1127  *          by @obj, or NULL otherwise.
1128  *
1129  **/
1130 AccessibleUnknown *
1131 Accessible_queryInterface (Accessible *obj,
1132                            const char *interface_name)
1133 {
1134   Bonobo_Unknown iface;
1135   
1136   if (!obj)
1137     {
1138       return NULL;
1139     }
1140
1141   iface = Accessibility_Accessible_queryInterface (CSPI_OBJREF (obj),
1142                                                    interface_name,
1143                                                    cspi_ev ());
1144
1145
1146   cspi_return_val_if_ev ("queryInterface", NULL); 
1147
1148   /*
1149    * FIXME: we need to be fairly sure that references are going
1150    * to mach up if we are going to expose QueryInterface, ie. we
1151    * can't allow people to do:
1152    * b = a.qi ("b"); b.unref, b.unref to release a's reference.
1153    * this should be no real problem though for this level of API
1154    * user.
1155    */
1156
1157   return cspi_object_add (iface);
1158 }
1159
1160
1161 /**
1162  * AccessibleRelation_ref:
1163  * @obj: a pointer to the #AccessibleRelation object on which to operate.
1164  *
1165  * Increment the reference count for an #AccessibleRelation object.
1166  *
1167  **/
1168 void
1169 AccessibleRelation_ref (AccessibleRelation *obj)
1170 {
1171   cspi_object_ref (obj);
1172 }
1173
1174 /**
1175  * AccessibleRelation_unref:
1176  * @obj: a pointer to the #AccessibleRelation object on which to operate.
1177  *
1178  * Decrement the reference count for an #AccessibleRelation object.
1179  *
1180  **/
1181 void
1182 AccessibleRelation_unref (AccessibleRelation *obj)
1183 {
1184   cspi_object_unref (obj);
1185 }
1186
1187 static SPIBoolean
1188 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
1189 {
1190   int i;
1191   for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
1192     {
1193       relation_type_table [i] = SPI_RELATION_NULL;
1194     }
1195   relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
1196   relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
1197   relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
1198   relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
1199   relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
1200   relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
1201   relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
1202   relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
1203   relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
1204   relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
1205   relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
1206   relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
1207   relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
1208   relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
1209   relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
1210   relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
1211   relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
1212   relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
1213   return TRUE;
1214 }
1215
1216 static AccessibleRelationType
1217 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
1218 {
1219   /* array is sized according to IDL RelationType because IDL RelationTypes are the index */    
1220   static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
1221   static SPIBoolean is_initialized = FALSE;
1222   AccessibleRelationType cspi_type;
1223   if (!is_initialized)
1224     {
1225       is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);            
1226     }
1227   if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
1228     {
1229       cspi_type = cspi_relation_type_table [type];          
1230     }
1231   else
1232     {
1233       cspi_type = SPI_RELATION_NULL;
1234     }
1235   return cspi_type; 
1236 }
1237 /**
1238  * AccessibleRelation_getRelationType:
1239  * @obj: a pointer to the #AccessibleRelation object to query.
1240  *
1241  * Get the type of relationship represented by an #AccessibleRelation.
1242  *
1243  * Returns: an #AccessibleRelationType indicating the type of relation
1244  *         encapsulated in this #AccessibleRelation object.
1245  *
1246  **/
1247 AccessibleRelationType
1248 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1249 {
1250   Accessibility_RelationType retval;
1251   
1252   cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1253   retval =
1254     Accessibility_Relation_getRelationType (CSPI_OBJREF (obj), cspi_ev());
1255   cspi_return_val_if_ev ("getRelationType", SPI_RELATION_NULL);
1256   return cspi_relation_type_from_spi_relation_type (retval);
1257 }
1258
1259 /**
1260  * AccessibleRelation_getNTargets:
1261  * @obj: a pointer to the #AccessibleRelation object to query.
1262  *
1263  * Get the number of objects which this relationship has as its
1264  *       target objects (the subject is the #Accessible from which this
1265  *       #AccessibleRelation originated).
1266  *
1267  * Returns: a short integer indicating how many target objects which the
1268  *       originating #Accessible object has the #AccessibleRelation
1269  *       relationship with.
1270  **/
1271 int
1272 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1273 {
1274   int retval;
1275   
1276   cspi_return_val_if_fail (obj, -1);
1277   retval = Accessibility_Relation_getNTargets (CSPI_OBJREF (obj), cspi_ev());
1278   cspi_return_val_if_ev ("getNTargets", -1);
1279   return retval;
1280 }
1281
1282 /**
1283  * AccessibleRelation_getTarget:
1284  * @obj: a pointer to the #AccessibleRelation object to query.
1285  * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1286  *
1287  * Get the @i-th target of a specified #AccessibleRelation relationship.
1288  *
1289  * Returns: an #Accessible which is the @i-th object with which the
1290  *      originating #Accessible has relationship specified in the
1291  *      #AccessibleRelation object.
1292  *
1293  **/
1294 Accessible *
1295 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1296 {
1297   Accessible *retval;
1298
1299   cspi_return_val_if_fail (obj, NULL);
1300
1301   retval = cspi_object_add (
1302                          Accessibility_Relation_getTarget (CSPI_OBJREF(obj),
1303                                                            i, cspi_ev()));
1304   cspi_return_val_if_ev ("getTarget", NULL);
1305   return retval;
1306 }
1307
1308 /**
1309  * AccessibleStateSet_ref:
1310  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1311  *
1312  * Increment the reference count for an #AccessibleStateSet object.
1313  *
1314  **/
1315 void
1316 AccessibleStateSet_ref (AccessibleStateSet *obj)
1317 {
1318   spi_state_set_cache_ref (obj);
1319 }
1320
1321 /**
1322  * AccessibleStateSet_unref:
1323  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1324  *
1325  * Decrement the reference count for an #AccessibleStateSet object.
1326  *
1327  **/
1328 void
1329 AccessibleStateSet_unref (AccessibleStateSet *obj)
1330 {
1331   spi_state_set_cache_unref (obj);
1332 }
1333
1334 static Accessibility_StateType
1335 spi_state_to_corba (AccessibleState state)
1336 {
1337 #define MAP_STATE(a) \
1338   case SPI_STATE_##a: \
1339     return Accessibility_STATE_##a
1340
1341   switch (state)
1342     {
1343       MAP_STATE (INVALID);
1344       MAP_STATE (ACTIVE);
1345       MAP_STATE (ARMED);
1346       MAP_STATE (BUSY);
1347       MAP_STATE (CHECKED);
1348       MAP_STATE (DEFUNCT);
1349       MAP_STATE (EDITABLE);
1350       MAP_STATE (ENABLED);
1351       MAP_STATE (EXPANDABLE);
1352       MAP_STATE (EXPANDED);
1353       MAP_STATE (FOCUSABLE);
1354       MAP_STATE (FOCUSED);
1355       MAP_STATE (HORIZONTAL);
1356       MAP_STATE (ICONIFIED);
1357       MAP_STATE (MODAL);
1358       MAP_STATE (MULTI_LINE);
1359       MAP_STATE (MULTISELECTABLE);
1360       MAP_STATE (OPAQUE);
1361       MAP_STATE (PRESSED);
1362       MAP_STATE (RESIZABLE);
1363       MAP_STATE (SELECTABLE);
1364       MAP_STATE (SELECTED);
1365       MAP_STATE (SENSITIVE);
1366       MAP_STATE (SHOWING);
1367       MAP_STATE (SINGLE_LINE);
1368       MAP_STATE (STALE);
1369       MAP_STATE (TRANSIENT);
1370       MAP_STATE (VERTICAL);
1371       MAP_STATE (VISIBLE);
1372       MAP_STATE (MANAGES_DESCENDANTS);
1373       MAP_STATE (INDETERMINATE);
1374       MAP_STATE (TRUNCATED);
1375       MAP_STATE (REQUIRED);
1376       MAP_STATE (INVALID_ENTRY);
1377       MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1378       MAP_STATE (SELECTABLE_TEXT);
1379       MAP_STATE (IS_DEFAULT);
1380       MAP_STATE (VISITED);
1381     default:
1382       return Accessibility_STATE_INVALID;
1383   }
1384 #undef MAP_STATE
1385 }             
1386
1387 /**
1388  * AccessibleStateSet_contains:
1389  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1390  * @state: an #AccessibleState for which the specified #AccessibleStateSet
1391  *       will be queried.
1392  *
1393  * Determine whether a given #AccessibleStateSet includes a given state; that is,
1394  *       whether @state is true for the stateset in question.
1395  *
1396  * Returns: #TRUE if @state is true/included in the given #AccessibleStateSet,
1397  *          otherwise #FALSE.
1398  *
1399  **/
1400 SPIBoolean
1401 AccessibleStateSet_contains (AccessibleStateSet *obj,
1402                              AccessibleState state)
1403 {
1404   return spi_state_set_cache_contains (obj, spi_state_to_corba (state));
1405 }
1406
1407 /**
1408  * AccessibleStateSet_add:
1409  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1410  * @state: an #AccessibleState to be added to the specified #AccessibleStateSet
1411  *
1412  * Add a particular #AccessibleState to an #AccessibleStateSet (i.e. set the
1413  *       given state to #TRUE in the stateset.
1414  *
1415  **/
1416 void
1417 AccessibleStateSet_add (AccessibleStateSet *obj,
1418                         AccessibleState state)
1419 {
1420   spi_state_set_cache_add (obj, spi_state_to_corba (state));
1421 }
1422
1423 /**
1424  * AccessibleStateSet_remove:
1425  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1426  * @state: an #AccessibleState to be removed from the specified #AccessibleStateSet
1427  *
1428  * Remove a particular #AccessibleState to an #AccessibleStateSet (i.e. set the
1429  *       given state to #FALSE in the stateset.)
1430  *
1431  **/
1432 void
1433 AccessibleStateSet_remove (AccessibleStateSet *obj,
1434                            AccessibleState state)
1435 {
1436   spi_state_set_cache_remove (obj, spi_state_to_corba (state));
1437 }
1438
1439 /**
1440  * AccessibleStateSet_equals:
1441  * @obj: a pointer to the first #AccessibleStateSet object on which to operate.
1442  * @obj2: a pointer to the second #AccessibleStateSet object on which to operate.
1443  *
1444  * Determine whether two instances of #AccessibleStateSet are equivalent (i.e.
1445  *         consist of the same #AccessibleStates).  Useful for checking multiple
1446  *         state variables at once; construct the target state then compare against it.
1447  *
1448  * @see AccessibleStateSet_compare().
1449  *
1450  * Returns: #TRUE if the two #AccessibleStateSets are equivalent,
1451  *          otherwise #FALSE.
1452  *
1453  **/
1454 SPIBoolean
1455 AccessibleStateSet_equals (AccessibleStateSet *obj,
1456                            AccessibleStateSet *obj2)
1457 {
1458   SPIBoolean   eq;
1459   AtkStateSet *cmp;
1460
1461   if (obj == obj2)
1462     {
1463       return TRUE;
1464     }
1465
1466   cmp = spi_state_set_cache_xor (obj, obj2);
1467   eq = spi_state_set_cache_is_empty (cmp);
1468   spi_state_set_cache_unref (cmp);
1469
1470   return eq;
1471 }
1472
1473 /**
1474  * AccessibleStateSet_compare:
1475  * @obj: a pointer to the first #AccessibleStateSet object on which to operate.
1476  * @obj2: a pointer to the second #AccessibleStateSet object on which to operate.
1477  *
1478  * Determine the differences between two instances of #AccessibleStateSet.
1479  * Not Yet Implemented.
1480  *.
1481  * @see AccessibleStateSet_equals().
1482  *
1483  * Returns: an #AccessibleStateSet object containing all states contained on one of
1484  *          the two sets but not the other.
1485  *
1486  **/
1487 AccessibleStateSet *
1488 AccessibleStateSet_compare (AccessibleStateSet *obj,
1489                             AccessibleStateSet *obj2)
1490 {
1491   return spi_state_set_cache_xor (obj, obj2);
1492 }
1493
1494 /**
1495  * AccessibleStateSet_isEmpty:
1496  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1497  *
1498  * Determine whether a given #AccessibleStateSet is the empty set.
1499  *
1500  * Returns: #TRUE if the given #AccessibleStateSet contains no (true) states,
1501  *          otherwise #FALSE.
1502  *
1503  **/
1504 SPIBoolean
1505 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1506 {
1507   return spi_state_set_cache_is_empty (obj);
1508 }
1509
1510