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