Merge branch 'master' of ssh://git.codethink.co.uk/git/atspi-dbus into mgorse
[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 "spi-common/spi-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 GArray *seq)
247 {
248     AccessibleAttributeSet *set = g_new0 (AccessibleAttributeSet, 1);
249     int i;
250
251     set->len = seq->len;
252     set->attributes = g_new0 (char *, set->len);
253     for (i = 0; i < set->len; ++i)
254     {
255         set->attributes[i] = g_array_index (seq, char *, i);
256     }
257
258   g_array_free (seq, TRUE);
259     return set;
260 }
261
262 /**
263  * AccessibleRole_getName:
264  * @role: an #AccessibleRole object to query.
265  *
266  * Get a localizeable string that indicates the name of an #AccessibleRole.
267  * <em>DEPRECATED.</em>
268  *
269  * Returns: a localizable string name for an #AccessibleRole enumerated type.
270  **/
271 char *
272 AccessibleRole_getName (AccessibleRole role)
273 {
274   if (role < MAX_ROLES && role_names [(int) role])
275     {
276       return g_strdup (role_names [(int) role]);
277     }
278   else
279     {
280       return g_strdup ("");
281     }
282 }
283
284 /**
285  * Accessible_ref:
286  * @obj: a pointer to the #Accessible object on which to operate.
287  *
288  * Increment the reference count for an #Accessible object.
289  **/
290 void
291 Accessible_ref (Accessible *obj)
292 {
293   cspi_object_ref (obj);
294 }
295
296 /**
297  * Accessible_unref:
298  * @obj: a pointer to the #Accessible object on which to operate.
299  *
300  * Decrement the reference count for an #Accessible object.
301  **/
302 void
303 Accessible_unref (Accessible *obj)
304 {
305   cspi_object_unref (obj);
306 }
307
308 /**
309  * Accessible_getName:
310  * @obj: a pointer to the #Accessible object on which to operate.
311  *
312  * Get the name of an #Accessible object.
313  *
314  * Returns: a UTF-8 string indicating the name of the #Accessible object.
315  * or NULL on exception
316  **/
317 char *
318 Accessible_getName (Accessible *obj)
319 {
320   cspi_return_val_if_fail (obj != NULL, NULL);
321   return g_strdup (obj->name);
322 }
323
324 /**
325  * Accessible_getDescription:
326  * @obj: a pointer to the #Accessible object on which to operate.
327  *
328  * Get the description of an #Accessible object.
329  *
330  * Returns: a UTF-8 string describing the #Accessible object.
331  * or NULL on exception
332  **/
333 char *
334 Accessible_getDescription (Accessible *obj)
335 {
336   cspi_return_val_if_fail (obj != NULL, NULL);
337
338   return g_strdup (obj->description);
339 }
340
341 /**
342  * Accessible_getParent:
343  * @obj: a pointer to the #Accessible object to query.
344  *
345  * Get an #Accessible object's parent container.
346  *
347  * Returns: a pointer tothe #Accessible object which contains the given
348  *          #Accessible instance, or NULL if the @obj has no parent container.
349  *
350  **/
351 Accessible *
352 Accessible_getParent (Accessible *obj)
353 {
354   cspi_return_val_if_fail (obj != NULL, NULL);
355
356   return cspi_object_add (obj->parent);
357 }
358
359 /**
360  * Accessible_getChildCount:
361  * @obj: a pointer to the #Accessible object on which to operate.
362  *
363  * Get the number of children contained by an #Accessible object.
364  *
365  * Returns: a #long indicating the number of #Accessible children
366  *          contained by an #Accessible object. or -1 on exception
367  *
368  **/
369 long
370 Accessible_getChildCount (Accessible *obj)
371 {
372   cspi_return_val_if_fail (obj != NULL, -1);
373
374   return g_list_length (obj->children);
375 }
376
377 /**
378  * Accessible_getChildAtIndex:
379  * @obj: a pointer to the #Accessible object on which to operate.
380  * @childIndex: a #long indicating which child is specified.
381  *
382  * Get the #Accessible child of an #Accessible object at a given index.
383  *
384  * Returns: a pointer to the #Accessible child object at index
385  *          @childIndex. or NULL on exception
386  **/
387 Accessible *
388 Accessible_getChildAtIndex (Accessible *obj,
389                             long int    childIndex)
390 {
391   Accessible *child;
392
393   cspi_return_val_if_fail (obj != NULL, NULL);
394
395   child = g_list_nth_data (obj->children, childIndex);
396   return cspi_object_add(child);
397 }
398
399 /**
400  * Accessible_getIndexInParent:
401  * @obj: a pointer to the #Accessible object on which to operate.
402  *
403  * Get the index of an #Accessible object in its containing #Accessible.
404  *
405  * Returns: a #long indicating the index of the #Accessible object
406  *          in its parent (i.e. containing) #Accessible instance,
407  *          or -1 if @obj has no containing parent or on exception.
408  **/
409 long
410 Accessible_getIndexInParent (Accessible *obj)
411 {
412   GList *l;
413   gint i;
414
415   cspi_return_val_if_fail (obj != NULL, -1);
416   if (!obj->parent) return -1;
417   l = obj->parent->children;
418   while (l)
419   {
420     if (l->data == obj) return i;
421     l = g_list_next (l);
422     i++;
423   }
424   return -1;
425 }
426
427 typedef struct
428 {
429   dbus_uint32_t type;
430   GArray *targets;
431 } Accessibility_Relation;
432
433 /**
434  * Accessible_getRelationSet:
435  * @obj: a pointer to the #Accessible object on which to operate.
436  *
437  * Get the set of #AccessibleRelation objects which describe this #Accessible object's
438  *       relationships with other #Accessible objects.
439  *
440  * Returns: an array of #AccessibleRelation pointers. or NULL on exception
441  **/
442 AccessibleRelation **
443 Accessible_getRelationSet (Accessible *obj)
444 {
445   int i;
446   int n_relations;
447   AccessibleRelation **relations;
448   GArray *relation_set;
449   DBusError error;
450
451   cspi_return_val_if_fail (obj != NULL, NULL);
452
453   g_assert (!cspi_exception ());
454
455   dbus_error_init (&error);
456   cspi_dbus_call (obj, spi_interface_accessible, "getAttributes", &error, "=>a(uao)", &relation_set);
457
458   cspi_return_val_if_ev ("getRelationSet", NULL); 
459   
460   n_relations = relation_set->len;
461   relations = malloc (sizeof (AccessibleRelation *) * (n_relations + 1));
462   
463   for (i = 0; i < n_relations; ++i)
464     {
465       Accessibility_Relation *r = g_array_index (relation_set, Accessibility_Relation *, i);
466       relations[i] = g_new (AccessibleRelation, 1);
467       if (!relations[i]) continue;
468       relations[i]->ref_count = 1;
469       relations[i]->type = r->type;
470       relations[i]->targets = r->targets;
471     }
472   relations[i] = NULL;
473
474   g_array_free (relation_set, TRUE);
475
476   return relations;
477 }
478
479 /**
480  * Accessible_getRole:
481  * @obj: a pointer to the #Accessible object on which to operate.
482  *
483  * Get the UI role of an #Accessible object.
484  * A UTF-8 string describing this role can be obtained via Accessible_getRoleName ().
485  *
486  * Returns: the #AccessibleRole of the object.
487  *
488  **/
489 AccessibleRole
490 Accessible_getRole (Accessible *obj)
491 {
492   cspi_return_val_if_fail (obj != NULL, SPI_ROLE_INVALID);
493
494   return obj->role;
495 }
496
497 /**
498  * Accessible_getRoleName:
499  * @obj: a pointer to the #Accessible object on which to operate.
500  *
501  * Get a UTF-8 string describing the role this object plays in the UI.
502  * This method will return useful values for roles that fall outside the
503  * enumeration used in Accessible_getRole ().
504  *
505  * Returns: a UTF-8 string specifying the role of this #Accessible object.
506  *
507  **/
508 char *
509 Accessible_getRoleName (Accessible *obj)
510 {
511   char *retval;
512
513   cspi_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
514
515   cspi_dbus_call (obj, spi_interface_accessible, "getRoleName", NULL, "=>s", &retval);
516
517   cspi_return_val_if_ev ("getRoleName", g_strdup ("invalid")); 
518
519   return retval;
520 }
521
522 /**
523  * Accessible_getLocalizedRoleName:
524  * @obj: a pointer to the #Accessible object on which to operate.
525  *
526  * Get a UTF-8 string describing the (localized) role this object plays in the UI.
527  * This method will return useful values for roles that fall outside the
528  * enumeration used in Accessible_getRole ().
529  *
530  * @Since: AT-SPI 1.4
531  *
532  * Returns: a UTF-8 string specifying the role of this #Accessible object.
533  *
534  **/
535 char *
536 Accessible_getLocalizedRoleName (Accessible *obj)
537 {
538   char *retval;
539
540   cspi_return_val_if_fail (obj != NULL, g_strdup ("invalid"));
541
542   cspi_dbus_call (obj, spi_interface_accessible, "getLocalizedRoleName", NULL, "=>s", &retval);
543
544   cspi_return_val_if_ev ("getLocalizedRoleName", g_strdup ("invalid")); 
545
546   return retval;
547 }
548
549 /**
550  * Accessible_getStateSet:
551  * @obj: a pointer to the #Accessible object on which to operate.
552  *
553  * Gets the current state of an object.
554  *
555  * Returns: a pointer to an #AccessibleStateSet representing the object's current state.
556  **/
557 AccessibleStateSet *
558 Accessible_getStateSet (Accessible *obj)
559 {
560   GArray *state_bitflags;
561   AccessibleStateSet *retval;
562
563   cspi_return_val_if_fail (obj != NULL, NULL);
564
565   cspi_dbus_call (obj, spi_interface_accessible, "getStateSet", NULL, "=>au", &state_bitflags);
566   cspi_return_val_if_ev ("getState", NULL);
567
568   retval = spi_state_set_cache_new (state_bitflags);
569
570   g_array_free (state_bitflags, TRUE);
571
572   return retval;
573 }
574
575 /**
576  * Accessible_getAttributes:
577  * @obj: The #Accessible being queried.
578  *
579  * Get the #AttributeSet representing any assigned 
580  * name-value pair attributes or annotations for this object.
581  * For typographic, textual, or textually-semantic attributes, see
582  * AccessibleText_getAttributes instead.
583  *
584  * Returns: The name-value-pair attributes assigned to this object.
585  */
586 AccessibleAttributeSet *
587 Accessible_getAttributes (Accessible *obj)
588 {
589     AccessibleAttributeSet *retval;
590   GArray *dbus_seq;
591
592     cspi_return_val_if_fail (obj != NULL, NULL);
593
594   cspi_dbus_call (obj, spi_interface_accessible, "getAttributes", NULL, "=>as", &dbus_seq);
595
596     cspi_return_val_if_ev ("getAttributes", NULL);
597     
598     retval = _cspi_attribute_set_from_sequence (dbus_seq);
599
600     return retval;
601 }
602
603 /**
604  * Accessible_getHostApplication:
605  * @obj: The #Accessible being queried.
606  *
607  * Get the containing #AccessibleApplication for an object.
608  *
609  * Returns: the containing AccessibleApplication instance for this object.
610  */
611 AccessibleApplication *
612 Accessible_getHostApplication (Accessible *obj)
613 {
614   while (obj->parent) obj = obj->parent;
615   return obj;
616 }
617
618 /* Interface query methods */
619
620 /**
621  * Accessible_isAction:
622  * @obj: a pointer to the #Accessible instance to query.
623  *
624  * Query whether the specified #Accessible implements #AccessibleAction.
625  *
626  * Returns: #TRUE if @obj implements the #AccessibleAction interface,
627  *          #FALSE otherwise.
628  **/
629 SPIBoolean
630 Accessible_isAction (Accessible *obj)
631 {
632   return cspi_accessible_is_a (obj,
633                               spi_interface_action);
634 }
635
636 /**
637  * Accessible_isApplication:
638  * @obj: a pointer to the #Accessible instance to query.
639  *
640  * Query whether the specified #Accessible implements #AccessibleApplication.
641  *
642  * Returns: #TRUE if @obj implements the #AccessibleApplication interface,
643  *          #FALSE otherwise.
644  **/
645 SPIBoolean
646 Accessible_isApplication (Accessible *obj)
647 {
648   return cspi_accessible_is_a (obj,
649                               spi_interface_application);
650 }
651
652 /**                      
653  * Accessible_isCollection:                                                                                                                                                                          * @obj: a pointer to the #Accessible instance to query.                                                                                                                                          
654  *                          
655  * Query whether the specified #Accessible implements #AccessibleCollection.    
656  * Returns: #TRUE if @obj implements the #AccessibleCollection interface,                                                                                                               
657  *          #FALSE otherwise.
658  **/
659
660 SPIBoolean
661 Accessible_isCollection (Accessible *obj)
662 {
663 #if 0
664      g_warning ("Collections not implemented");
665      return cspi_accessible_is_a (obj,
666                               spi_interface_collection);
667 #else
668      return FALSE;
669 #endif
670 }
671
672 /**
673  * Accessible_isComponent:
674  * @obj: a pointer to the #Accessible instance to query.
675  *
676  * Query whether the specified #Accessible implements #AccessibleComponent.
677  *
678  * Returns: #TRUE if @obj implements the #AccessibleComponent interface,
679  *          #FALSE otherwise.
680  **/
681 SPIBoolean
682 Accessible_isComponent (Accessible *obj)
683 {
684   return cspi_accessible_is_a (obj,
685                               spi_interface_component);
686 }
687
688 /**
689  * Accessible_isDocument:
690  * @obj: a pointer to the #Accessible instance to query.
691  *
692  * Query whether the specified #Accessible implements #AccessibleDocument.
693  *
694  * Returns: #TRUE if @obj implements the #AccessibleDocument interface,
695  *          #FALSE otherwise.
696  **/
697 SPIBoolean
698 Accessible_isDocument (Accessible *obj)
699 {
700   return cspi_accessible_is_a (obj,
701                               spi_interface_document);
702 }
703
704 /**
705  * Accessible_isEditableText:
706  * @obj: a pointer to the #Accessible instance to query.
707  *
708  * Query whether the specified #Accessible implements #AccessibleEditableText.
709  *
710  * Returns: #TRUE if @obj implements the #AccessibleEditableText interface,
711  *          #FALSE otherwise.
712  **/
713 SPIBoolean
714 Accessible_isEditableText (Accessible *obj)
715 {
716   return cspi_accessible_is_a (obj,
717                               spi_interface_editable_text);
718 }
719                                                                                                                                                                         
720 /**
721  * Accessible_isMatchRule:
722  * @obj: a pointer to the #Accessible instance to query.
723  *
724  * Query whether the specified #Accessible implements #AccessibleMatchRule.
725  *
726  * Returns: #TRUE if @obj implements the #AccessibleMatchRule interface,
727  *          #FALSE otherwise.
728  **/
729 SPIBoolean
730 Accessible_isMatchRule (Accessible *obj)
731 {
732 #if 0
733      return cspi_accessible_is_a (obj, 
734                                   spi_interface_match_rule);
735 #else
736      g_warning ("Match rules not implemented");
737      return FALSE;
738 #endif
739 }
740
741 /**
742  * Accessible_isHypertext:
743  * @obj: a pointer to the #Accessible instance to query.
744  *
745  * Query whether the specified #Accessible implements #AccessibleHypertext.
746  *
747  * Returns: #TRUE if @obj implements the #AccessibleHypertext interface,
748  *          #FALSE otherwise.
749  **/
750 SPIBoolean
751 Accessible_isHypertext (Accessible *obj)
752 {
753   return cspi_accessible_is_a (obj,
754                               spi_interface_hypertext);
755 }
756
757 /**
758  * Accessible_isImage:
759  * @obj: a pointer to the #Accessible instance to query.
760  *
761  * Query whether the specified #Accessible implements #AccessibleImage.
762  *
763  * Returns: #TRUE if @obj implements the #AccessibleImage interface,
764  *          #FALSE otherwise.
765 **/
766 SPIBoolean
767 Accessible_isImage (Accessible *obj)
768 {
769   return cspi_accessible_is_a (obj,
770                               spi_interface_image);
771 }
772
773 /**
774  * Accessible_isSelection:
775  * @obj: a pointer to the #Accessible instance to query.
776  *
777  * Query whether the specified #Accessible implements #AccessibleSelection.
778  *
779  * Returns: #TRUE if @obj implements the #AccessibleSelection interface,
780  *          #FALSE otherwise.
781 **/
782 SPIBoolean
783 Accessible_isSelection (Accessible *obj)
784 {
785   return cspi_accessible_is_a (obj,
786                               spi_interface_selection);
787 }
788
789 /**
790  * Accessible_isTable:
791  * @obj: a pointer to the #Accessible instance to query.
792  *
793  * Query whether the specified #Accessible implements #AccessibleTable.
794  *
795  * Returns: #TRUE if @obj implements the #AccessibleTable interface,
796  *          #FALSE otherwise.
797 **/
798 SPIBoolean
799 Accessible_isTable (Accessible *obj)
800 {
801   return cspi_accessible_is_a (obj,
802                               spi_interface_table);
803 }
804
805 /**
806  * Accessible_isStreamableContent:
807  * @obj: a pointer to the #Accessible instance to query.
808  *
809  * Query whether the specified #Accessible implements
810  *          #AccessibleStreamableContent.
811  *
812  * Returns: #TRUE if @obj implements the #AccessibleStreamableContent interface,
813  *          #FALSE otherwise.
814 **/
815 SPIBoolean
816 Accessible_isStreamableContent (Accessible *obj)
817 {
818 #if 0
819   return cspi_accessible_is_a (obj,
820                               spi_interface_streamable_content);
821 #else
822   g_warning ("Streamable content not implemented");
823   return FALSE;
824 #endif
825 }
826
827 /**
828  * Accessible_isText:
829  * @obj: a pointer to the #Accessible instance to query.
830  *
831  * Query whether the specified #Accessible implements #AccessibleText.
832  *
833  * Returns: #TRUE if @obj implements the #AccessibleText interface,
834  *          #FALSE otherwise.
835 **/
836 SPIBoolean
837 Accessible_isText (Accessible *obj)
838 {
839   return cspi_accessible_is_a (obj,
840                               spi_interface_text);
841 }
842
843 /**
844  * Accessible_isValue:
845  * @obj: a pointer to the #Accessible instance to query.
846  *
847  * Query whether the specified #Accessible implements #AccessibleValue.
848  *
849  * Returns: #TRUE if @obj implements the #AccessibleValue interface,
850  *          #FALSE otherwise.
851 **/
852 SPIBoolean
853 Accessible_isValue (Accessible *obj)
854 {
855   return cspi_accessible_is_a (obj,
856                               spi_interface_value);
857 }
858
859 /**
860  * Accessible_getApplication:
861  * @obj: a pointer to the #Accessible instance to query.
862  *
863  * Get the #AccessibleApplication interface for an #Accessible.
864  *
865  * Returns: a pointer to an #AccessibleApplication interface instance, or
866  *          NULL if @obj does not implement #AccessibleApplication.
867  **/
868 AccessibleApplication *
869 Accessible_getApplication (Accessible *obj)
870 {
871   return (AccessibleApplication *) Accessible_queryInterface (
872           obj, spi_interface_application);
873 }
874
875 /**
876  * Accessible_getAction:
877  * @obj: a pointer to the #Accessible instance to query.
878  *
879  * Get the #AccessibleAction interface for an #Accessible.
880  *
881  * Returns: a pointer to an #AccessibleAction interface instance, or
882  *          NULL if @obj does not implement #AccessibleAction.
883  **/
884 AccessibleAction *
885 Accessible_getAction (Accessible *obj)
886 {
887   return (AccessibleAction *) Accessible_queryInterface (
888           obj, spi_interface_action);
889 }
890
891
892 /**
893  * Accessible_getCollection:
894  * @obj: a pointer to the #Accessible instance to query.
895  *
896  * Get the #AccessibleCollection interface for an #Accessible.
897  *
898  * Returns: a pointer to an #AccessibleCollection interface instance, or
899  *          NULL if @obj does not implement #AccessibleCollection.
900  **/
901 AccessibleCollection *
902 Accessible_getCollection (Accessible *obj)
903 {
904 #if 0
905   return (AccessibleCollection *) Accessible_queryInterface (
906           obj, spi_interface_collection);
907 #else
908   g_warning ("Collections not implemented");
909 #endif
910 }
911
912 /**
913  * Accessible_getComponent:
914  * @obj: a pointer to the #Accessible instance to query.
915  *
916  * Get the #AccessibleComponent interface for an #Accessible.
917  *
918  * Returns: a pointer to an #AccessibleComponent interface instance, or
919  *          NULL if @obj does not implement #AccessibleComponent.
920  **/
921 AccessibleComponent *
922 Accessible_getComponent (Accessible *obj)
923 {
924   return (AccessibleComponent *) Accessible_queryInterface (
925           obj, spi_interface_component);
926 }
927
928 /**
929  * Accessible_getDocument:
930  * @obj: a pointer to the #Accessible instance to query.
931  *
932  * Get the #AccessibleDocument interface for an #Accessible.
933  *
934  * Returns: a pointer to an #AccessibleDocument interface instance, or
935  *          NULL if @obj does not implement #AccessibleDocument.
936  **/
937 AccessibleDocument *
938 Accessible_getDocument (Accessible *obj)
939 {
940   return (AccessibleDocument *) Accessible_queryInterface (
941           obj, spi_interface_document);
942 }
943
944 /**
945  * Accessible_getEditableText:
946  * @obj: a pointer to the #Accessible instance to query.
947  *
948  * Get the #AccessibleEditableText interface for an #Accessible.
949  *
950  * Returns: a pointer to an #AccessibleEditableText interface instance, or
951  *          NULL if @obj does not implement #AccessibleEditableText.
952  **/
953 AccessibleEditableText *
954 Accessible_getEditableText (Accessible *obj)
955 {
956   return (AccessibleEditableText *) Accessible_queryInterface (
957           obj, spi_interface_editable_text);
958 }
959
960
961 /**
962  * Accessible_getHypertext:
963  * @obj: a pointer to the #Accessible instance to query.
964  *
965  * Get the #AccessibleHypertext interface for an #Accessible.
966  *
967  * Returns: a pointer to an #AccessibleHypertext interface instance, or
968  *          NULL if @obj does not implement #AccessibleHypertext.
969  **/
970 AccessibleHypertext *
971 Accessible_getHypertext (Accessible *obj)
972 {
973   return (AccessibleHypertext *) Accessible_queryInterface (
974           obj, spi_interface_hypertext);
975 }
976
977
978
979 /**
980  * Accessible_getImage:
981  * @obj: a pointer to the #Accessible instance to query.
982  *
983  * Get the #AccessibleImage interface for an #Accessible.
984  *
985  * Returns: a pointer to an #AccessibleImage interface instance, or
986  *          NULL if @obj does not implement #AccessibleImage.
987  **/
988 AccessibleImage *
989 Accessible_getImage (Accessible *obj)
990 {
991   return (AccessibleImage *) Accessible_queryInterface (
992           obj, spi_interface_image);
993 }
994
995 /**
996  * Accessible_getMatchRule:
997  * @obj: a pointer to the #Accessible instance to query.
998  *
999  * Get the #AccessibleMatchRule interface for an #Accessible.
1000  *
1001  * Returns: a pointer to an #AccessibleMatchRule interface instance, or
1002  *          NULL if @obj does not implement #AccessibleMatchRule.
1003  **/
1004 AccessibleMatchRule *
1005 Accessible_getMatchRule (Accessible *obj)
1006 {
1007 #if 0
1008   return (AccessibleMatchRule *) Accessible_queryInterface (
1009           obj, spi_interface_match_rule);
1010 #else
1011   g_warning ("Match rules not supported");
1012 #endif
1013 }
1014
1015 /**
1016  * Accessible_getSelection:
1017  * @obj: a pointer to the #Accessible instance to query.
1018  *
1019  * Get the #AccessibleSelection interface for an #Accessible.
1020  *
1021  * Returns: a pointer to an #AccessibleSelection interface instance, or
1022  *          NULL if @obj does not implement #AccessibleSelection.
1023  **/
1024 AccessibleSelection *
1025 Accessible_getSelection (Accessible *obj)
1026 {
1027   return (AccessibleSelection *) Accessible_queryInterface (
1028           obj, spi_interface_selection);
1029 }
1030
1031
1032
1033 /**
1034  * Accessible_getStreamableContent:
1035  * @obj: a pointer to the #Accessible instance to query.
1036  *
1037  * Get the #AccessibleStreamableContent interface for an #Accessible.
1038  *
1039  * Returns: a pointer to an #AccessibleStreamableContent interface instance, or
1040  *          NULL if @obj does not implement #AccessibleStreamableContent.
1041  **/
1042 AccessibleStreamableContent *
1043 Accessible_getStreamableContent (Accessible *obj)
1044 {
1045 #if 0
1046   return (AccessibleStreamableContent *) Accessible_queryInterface (
1047           obj, spi_interface_streamable_content);
1048 #else
1049   g_warning ("Streamable content not supported");
1050 #endif
1051 }
1052
1053 /**
1054  * Accessible_getTable:
1055  * @obj: a pointer to the #Accessible instance to query.
1056  *
1057  * Get the #AccessibleTable interface for an #Accessible.
1058  *
1059  * Returns: a pointer to an #AccessibleTable interface instance, or
1060  *          NULL if @obj does not implement #AccessibleTable.
1061  **/
1062 AccessibleTable *
1063 Accessible_getTable (Accessible *obj)
1064 {
1065   return (AccessibleTable *) Accessible_queryInterface (
1066           obj, spi_interface_table);
1067 }
1068
1069 /**
1070  * Accessible_getText:
1071  * @obj: a pointer to the #Accessible instance to query.
1072  *
1073  * Get the #AccessibleText interface for an #Accessible.
1074  *
1075  * Returns: a pointer to an #AccessibleText interface instance, or
1076  *          NULL if @obj does not implement #AccessibleText.
1077  **/
1078 AccessibleText *
1079 Accessible_getText (Accessible *obj)
1080 {
1081   return (AccessibleText *) Accessible_queryInterface (
1082           obj, spi_interface_text);
1083 }
1084
1085
1086
1087 /**
1088  * Accessible_getValue:
1089  * @obj: a pointer to the #Accessible instance to query.
1090  *
1091  * Get the #AccessibleValue interface for an #Accessible.
1092  *
1093  * Returns: a pointer to an #AccessibleValue interface instance, or
1094  *          NULL if @obj does not implement #AccessibleValue.
1095  **/
1096 AccessibleValue *
1097 Accessible_getValue (Accessible *obj)
1098 {
1099   return (AccessibleValue *) Accessible_queryInterface (
1100           obj, spi_interface_value);
1101 }
1102
1103
1104
1105 /**
1106  * Accessible_queryInterface:
1107  * @obj: a pointer to the #Accessible instance to query.
1108  * @interface_name: a UTF-8 character string specifiying the requested interface.
1109  *
1110  * Query an #Accessible object to for a named interface.
1111  *
1112  * Returns: an instance of the named interface object, if it is implemented
1113  *          by @obj, or NULL otherwise.
1114  *
1115  **/
1116 AccessibleUnknown *
1117 Accessible_queryInterface (Accessible *obj,
1118                            const char *interface_name)
1119 {
1120   if (cspi_accessible_is_a (obj, interface_name))
1121   {
1122     /* The original code called cspi_object_add(obj) instead, but gok and
1123      * simple-at don't treat interfaces as references, so I'm confused
1124      * and not going to replicate this bit of code */
1125     return obj;
1126   }
1127   return NULL;
1128 }
1129
1130
1131 /**
1132  * AccessibleRelation_ref:
1133  * @obj: a pointer to the #AccessibleRelation object on which to operate.
1134  *
1135  * Increment the reference count for an #AccessibleRelation object.
1136  *
1137  **/
1138 void
1139 AccessibleRelation_ref (AccessibleRelation *obj)
1140 {
1141   obj->ref_count++;
1142 }
1143
1144 /**
1145  * AccessibleRelation_unref:
1146  * @obj: a pointer to the #AccessibleRelation object on which to operate.
1147  *
1148  * Decrement the reference count for an #AccessibleRelation object.
1149  *
1150  **/
1151 void
1152 AccessibleRelation_unref (AccessibleRelation *obj)
1153 {
1154   obj->ref_count--;
1155   if (obj->ref_count <= 0)
1156   {
1157     g_array_free (obj->targets, TRUE);
1158     g_free (obj);
1159   }
1160 }
1161
1162 static SPIBoolean
1163 cspi_init_relation_type_table (AccessibleRelationType *relation_type_table)
1164 {
1165   int i;
1166   for (i = 0; i < Accessibility_RELATION_LAST_DEFINED; ++i)
1167     {
1168       relation_type_table [i] = SPI_RELATION_NULL;
1169     }
1170   relation_type_table [Accessibility_RELATION_NULL] = SPI_RELATION_NULL;
1171   relation_type_table [Accessibility_RELATION_LABEL_FOR] = SPI_RELATION_LABEL_FOR;
1172   relation_type_table [Accessibility_RELATION_LABELLED_BY] = SPI_RELATION_LABELED_BY;
1173   relation_type_table [Accessibility_RELATION_CONTROLLER_FOR] = SPI_RELATION_CONTROLLER_FOR;
1174   relation_type_table [Accessibility_RELATION_CONTROLLED_BY] = SPI_RELATION_CONTROLLED_BY;
1175   relation_type_table [Accessibility_RELATION_MEMBER_OF] = SPI_RELATION_MEMBER_OF;
1176   relation_type_table [Accessibility_RELATION_TOOLTIP_FOR] = SPI_RELATION_NULL;
1177   relation_type_table [Accessibility_RELATION_NODE_CHILD_OF] = SPI_RELATION_NODE_CHILD_OF;
1178   relation_type_table [Accessibility_RELATION_EXTENDED] = SPI_RELATION_EXTENDED;
1179   relation_type_table [Accessibility_RELATION_FLOWS_TO] = SPI_RELATION_FLOWS_TO;
1180   relation_type_table [Accessibility_RELATION_FLOWS_FROM] = SPI_RELATION_FLOWS_FROM;
1181   relation_type_table [Accessibility_RELATION_SUBWINDOW_OF] = SPI_RELATION_SUBWINDOW_OF;
1182   relation_type_table [Accessibility_RELATION_EMBEDS] = SPI_RELATION_EMBEDS;
1183   relation_type_table [Accessibility_RELATION_EMBEDDED_BY] = SPI_RELATION_EMBEDDED_BY;
1184   relation_type_table [Accessibility_RELATION_POPUP_FOR] = SPI_RELATION_POPUP_FOR;
1185   relation_type_table [Accessibility_RELATION_PARENT_WINDOW_OF] = SPI_RELATION_PARENT_WINDOW_OF;
1186   relation_type_table [Accessibility_RELATION_DESCRIBED_BY] = SPI_RELATION_DESCRIBED_BY;
1187   relation_type_table [Accessibility_RELATION_DESCRIPTION_FOR] = SPI_RELATION_DESCRIPTION_FOR;
1188   return TRUE;
1189 }
1190
1191 static AccessibleRelationType
1192 cspi_relation_type_from_spi_relation_type (Accessibility_RelationType type)
1193 {
1194   /* array is sized according to IDL RelationType because IDL RelationTypes are the index */    
1195   static AccessibleRelationType cspi_relation_type_table [Accessibility_RELATION_LAST_DEFINED];
1196   static SPIBoolean is_initialized = FALSE;
1197   AccessibleRelationType cspi_type;
1198   if (!is_initialized)
1199     {
1200       is_initialized = cspi_init_relation_type_table (cspi_relation_type_table);            
1201     }
1202   if (type >= 0 && type < Accessibility_RELATION_LAST_DEFINED)
1203     {
1204       cspi_type = cspi_relation_type_table [type];          
1205     }
1206   else
1207     {
1208       cspi_type = SPI_RELATION_NULL;
1209     }
1210   return cspi_type; 
1211 }
1212 /**
1213  * AccessibleRelation_getRelationType:
1214  * @obj: a pointer to the #AccessibleRelation object to query.
1215  *
1216  * Get the type of relationship represented by an #AccessibleRelation.
1217  *
1218  * Returns: an #AccessibleRelationType indicating the type of relation
1219  *         encapsulated in this #AccessibleRelation object.
1220  *
1221  **/
1222 AccessibleRelationType
1223 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1224 {
1225   cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1226   return cspi_relation_type_from_spi_relation_type (obj->type);
1227 }
1228
1229 /**
1230  * AccessibleRelation_getNTargets:
1231  * @obj: a pointer to the #AccessibleRelation object to query.
1232  *
1233  * Get the number of objects which this relationship has as its
1234  *       target objects (the subject is the #Accessible from which this
1235  *       #AccessibleRelation originated).
1236  *
1237  * Returns: a short integer indicating how many target objects which the
1238  *       originating #Accessible object has the #AccessibleRelation
1239  *       relationship with.
1240  **/
1241 int
1242 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1243 {
1244   cspi_return_val_if_fail (obj, -1);
1245   return obj->targets->len;
1246 }
1247
1248 /**
1249  * AccessibleRelation_getTarget:
1250  * @obj: a pointer to the #AccessibleRelation object to query.
1251  * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1252  *
1253  * Get the @i-th target of a specified #AccessibleRelation relationship.
1254  *
1255  * Returns: an #Accessible which is the @i-th object with which the
1256  *      originating #Accessible has relationship specified in the
1257  *      #AccessibleRelation object.
1258  *
1259  **/
1260 Accessible *
1261 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1262 {
1263   cspi_return_val_if_fail (obj, NULL);
1264
1265   if (i < 0 || i >= obj->targets->len) return NULL;
1266   return cspi_object_add (
1267                          g_array_index (obj->targets, Accessible *, i));
1268 }
1269
1270 /**
1271  * AccessibleStateSet_ref:
1272  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1273  *
1274  * Increment the reference count for an #AccessibleStateSet object.
1275  *
1276  **/
1277 void
1278 AccessibleStateSet_ref (AccessibleStateSet *obj)
1279 {
1280   spi_state_set_cache_ref (obj);
1281 }
1282
1283 /**
1284  * AccessibleStateSet_unref:
1285  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1286  *
1287  * Decrement the reference count for an #AccessibleStateSet object.
1288  *
1289  **/
1290 void
1291 AccessibleStateSet_unref (AccessibleStateSet *obj)
1292 {
1293   spi_state_set_cache_unref (obj);
1294 }
1295
1296 static Accessibility_StateType
1297 spi_state_to_dbus (AccessibleState state)
1298 {
1299 #define MAP_STATE(a) \
1300   case SPI_STATE_##a: \
1301     return Accessibility_STATE_##a
1302
1303   switch (state)
1304     {
1305       MAP_STATE (INVALID);
1306       MAP_STATE (ACTIVE);
1307       MAP_STATE (ARMED);
1308       MAP_STATE (BUSY);
1309       MAP_STATE (CHECKED);
1310       MAP_STATE (DEFUNCT);
1311       MAP_STATE (EDITABLE);
1312       MAP_STATE (ENABLED);
1313       MAP_STATE (EXPANDABLE);
1314       MAP_STATE (EXPANDED);
1315       MAP_STATE (FOCUSABLE);
1316       MAP_STATE (FOCUSED);
1317       MAP_STATE (HORIZONTAL);
1318       MAP_STATE (ICONIFIED);
1319       MAP_STATE (MODAL);
1320       MAP_STATE (MULTI_LINE);
1321       MAP_STATE (MULTISELECTABLE);
1322       MAP_STATE (OPAQUE);
1323       MAP_STATE (PRESSED);
1324       MAP_STATE (RESIZABLE);
1325       MAP_STATE (SELECTABLE);
1326       MAP_STATE (SELECTED);
1327       MAP_STATE (SENSITIVE);
1328       MAP_STATE (SHOWING);
1329       MAP_STATE (SINGLE_LINE);
1330       MAP_STATE (STALE);
1331       MAP_STATE (TRANSIENT);
1332       MAP_STATE (VERTICAL);
1333       MAP_STATE (VISIBLE);
1334       MAP_STATE (MANAGES_DESCENDANTS);
1335       MAP_STATE (INDETERMINATE);
1336       MAP_STATE (TRUNCATED);
1337       MAP_STATE (REQUIRED);
1338       MAP_STATE (INVALID_ENTRY);
1339       MAP_STATE (SUPPORTS_AUTOCOMPLETION);
1340       MAP_STATE (SELECTABLE_TEXT);
1341       MAP_STATE (IS_DEFAULT);
1342       MAP_STATE (VISITED);
1343     default:
1344       return Accessibility_STATE_INVALID;
1345   }
1346 #undef MAP_STATE
1347 }             
1348
1349 /**
1350  * AccessibleStateSet_contains:
1351  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1352  * @state: an #AccessibleState for which the specified #AccessibleStateSet
1353  *       will be queried.
1354  *
1355  * Determine whether a given #AccessibleStateSet includes a given state; that is,
1356  *       whether @state is true for the stateset in question.
1357  *
1358  * Returns: #TRUE if @state is true/included in the given #AccessibleStateSet,
1359  *          otherwise #FALSE.
1360  *
1361  **/
1362 SPIBoolean
1363 AccessibleStateSet_contains (AccessibleStateSet *obj,
1364                              AccessibleState state)
1365 {
1366   return spi_state_set_cache_contains (obj, spi_state_to_dbus (state));
1367 }
1368
1369 /**
1370  * AccessibleStateSet_add:
1371  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1372  * @state: an #AccessibleState to be added to the specified #AccessibleStateSet
1373  *
1374  * Add a particular #AccessibleState to an #AccessibleStateSet (i.e. set the
1375  *       given state to #TRUE in the stateset.
1376  *
1377  **/
1378 void
1379 AccessibleStateSet_add (AccessibleStateSet *obj,
1380                         AccessibleState state)
1381 {
1382   spi_state_set_cache_add (obj, spi_state_to_dbus (state));
1383 }
1384
1385 /**
1386  * AccessibleStateSet_remove:
1387  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1388  * @state: an #AccessibleState to be removed from the specified #AccessibleStateSet
1389  *
1390  * Remove a particular #AccessibleState to an #AccessibleStateSet (i.e. set the
1391  *       given state to #FALSE in the stateset.)
1392  *
1393  **/
1394 void
1395 AccessibleStateSet_remove (AccessibleStateSet *obj,
1396                            AccessibleState state)
1397 {
1398   spi_state_set_cache_remove (obj, spi_state_to_dbus (state));
1399 }
1400
1401 /**
1402  * AccessibleStateSet_equals:
1403  * @obj: a pointer to the first #AccessibleStateSet object on which to operate.
1404  * @obj2: a pointer to the second #AccessibleStateSet object on which to operate.
1405  *
1406  * Determine whether two instances of #AccessibleStateSet are equivalent (i.e.
1407  *         consist of the same #AccessibleStates).  Useful for checking multiple
1408  *         state variables at once; construct the target state then compare against it.
1409  *
1410  * @see AccessibleStateSet_compare().
1411  *
1412  * Returns: #TRUE if the two #AccessibleStateSets are equivalent,
1413  *          otherwise #FALSE.
1414  *
1415  **/
1416 SPIBoolean
1417 AccessibleStateSet_equals (AccessibleStateSet *obj,
1418                            AccessibleStateSet *obj2)
1419 {
1420   SPIBoolean   eq;
1421   AtkStateSet *cmp;
1422
1423   if (obj == obj2)
1424     {
1425       return TRUE;
1426     }
1427
1428   cmp = spi_state_set_cache_xor (obj, obj2);
1429   eq = spi_state_set_cache_is_empty (cmp);
1430   spi_state_set_cache_unref (cmp);
1431
1432   return eq;
1433 }
1434
1435 /**
1436  * AccessibleStateSet_compare:
1437  * @obj: a pointer to the first #AccessibleStateSet object on which to operate.
1438  * @obj2: a pointer to the second #AccessibleStateSet object on which to operate.
1439  *
1440  * Determine the differences between two instances of #AccessibleStateSet.
1441  * Not Yet Implemented.
1442  *.
1443  * @see AccessibleStateSet_equals().
1444  *
1445  * Returns: an #AccessibleStateSet object containing all states contained on one of
1446  *          the two sets but not the other.
1447  *
1448  **/
1449 AccessibleStateSet *
1450 AccessibleStateSet_compare (AccessibleStateSet *obj,
1451                             AccessibleStateSet *obj2)
1452 {
1453   return spi_state_set_cache_xor (obj, obj2);
1454 }
1455
1456 /**
1457  * AccessibleStateSet_isEmpty:
1458  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1459  *
1460  * Determine whether a given #AccessibleStateSet is the empty set.
1461  *
1462  * Returns: #TRUE if the given #AccessibleStateSet contains no (true) states,
1463  *          otherwise #FALSE.
1464  *
1465  **/
1466 SPIBoolean
1467 AccessibleStateSet_isEmpty (AccessibleStateSet *obj)
1468 {
1469   return spi_state_set_cache_is_empty (obj);
1470 }
1471