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