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