fix tyop
[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 = (char *)
330     Accessibility_Accessible__get_name (CSPI_OBJREF (obj), cspi_ev ());
331
332   cspi_return_val_if_ev ("getName", NULL); 
333
334   return retval;
335 }
336
337 /**
338  * Accessible_getDescription:
339  * @obj: a pointer to the #Accessible object on which to operate.
340  *
341  * Get the description of an #Accessible object.
342  *
343  * Returns: a UTF-8 string describing the #Accessible object.
344  * or NULL on exception
345  **/
346 char *
347 Accessible_getDescription (Accessible *obj)
348 {
349   char *retval;
350
351   cspi_return_val_if_fail (obj != NULL, NULL);
352
353   retval = (char *)
354     Accessibility_Accessible__get_description (CSPI_OBJREF (obj),
355                                                cspi_ev ());
356
357   cspi_return_val_if_ev ("getDescription", NULL); 
358
359   return retval;
360 }
361
362 /**
363  * Accessible_getParent:
364  * @obj: a pointer to the #Accessible object to query.
365  *
366  * Get an #Accessible object's parent container.
367  *
368  * Returns: a pointer tothe #Accessible object which contains the given
369  *          #Accessible instance, or NULL if the @obj has no parent container.
370  *
371  **/
372 Accessible *
373 Accessible_getParent (Accessible *obj)
374 {
375   Accessible *retval;
376
377   cspi_return_val_if_fail (obj != NULL, NULL);
378
379   retval = cspi_object_add (
380     Accessibility_Accessible__get_parent (CSPI_OBJREF (obj),
381                                           cspi_ev ()));
382
383   cspi_return_val_if_ev ("getParent", NULL); 
384
385   return retval;
386 }
387
388 /**
389  * Accessible_getChildCount:
390  * @obj: a pointer to the #Accessible object on which to operate.
391  *
392  * Get the number of children contained by an #Accessible object.
393  *
394  * Returns: a #long indicating the number of #Accessible children
395  *          contained by an #Accessible object. or -1 on exception
396  *
397  **/
398 long
399 Accessible_getChildCount (Accessible *obj)
400 {
401   long retval;
402
403   cspi_return_val_if_fail (obj != NULL, -1);
404
405   retval = (long) 
406     Accessibility_Accessible__get_childCount (CSPI_OBJREF (obj),
407                                               cspi_ev ());
408
409   cspi_return_val_if_ev ("getChildCount", -1); 
410
411   return retval;
412 }
413
414 /**
415  * Accessible_getChildAtIndex:
416  * @obj: a pointer to the #Accessible object on which to operate.
417  * @childIndex: a #long indicating which child is specified.
418  *
419  * Get the #Accessible child of an #Accessible object at a given index.
420  *
421  * Returns: a pointer to the #Accessible child object at index
422  *          @childIndex. or NULL on exception
423  **/
424 Accessible *
425 Accessible_getChildAtIndex (Accessible *obj,
426                             long int    childIndex)
427 {
428   Accessible *retval;
429
430   cspi_return_val_if_fail (obj != NULL, NULL);
431
432   retval = cspi_object_add (
433     Accessibility_Accessible_getChildAtIndex (CSPI_OBJREF (obj),
434                                               childIndex, cspi_ev ()));
435
436   return retval;
437 }
438
439 /**
440  * Accessible_getIndexInParent:
441  * @obj: a pointer to the #Accessible object on which to operate.
442  *
443  * Get the index of an #Accessible object in its containing #Accessible.
444  *
445  * Returns: a #long indicating the index of the #Accessible object
446  *          in its parent (i.e. containing) #Accessible instance,
447  *          or -1 if @obj has no containing parent or on exception.
448  **/
449 long
450 Accessible_getIndexInParent (Accessible *obj)
451 {
452   long retval;
453
454   cspi_return_val_if_fail (obj != NULL, -1);
455
456   retval = (long)
457     Accessibility_Accessible_getIndexInParent (CSPI_OBJREF (obj), cspi_ev ());
458
459   cspi_return_val_if_ev ("getIndexInparent", -1); 
460   return retval;
461 }
462
463 /**
464  * Accessible_getRelationSet:
465  * @obj: a pointer to the #Accessible object on which to operate.
466  *
467  * Get the set of #AccessibleRelation objects which describe this #Accessible object's
468  *       relationships with other #Accessible objects.
469  *
470  * Returns: an array of #AccessibleRelation pointers. or NULL on exception
471  **/
472 AccessibleRelation **
473 Accessible_getRelationSet (Accessible *obj)
474 {
475   int i;
476   int n_relations;
477   AccessibleRelation **relations;
478   Accessibility_RelationSet *relation_set;
479
480   cspi_return_val_if_fail (obj != NULL, NULL);
481
482   relation_set =
483     Accessibility_Accessible_getRelationSet (CSPI_OBJREF (obj), cspi_ev ());
484
485   cspi_return_val_if_ev ("getRelationSet", NULL); 
486   
487   n_relations = relation_set->_length;
488   relations = malloc (sizeof (AccessibleRelation *) * (n_relations + 1));
489   
490   for (i = 0; i < n_relations; ++i)
491     {
492       relations[i] = cspi_object_add (CORBA_Object_duplicate (
493               relation_set->_buffer[i], cspi_ev ()));
494     }
495   relations[i] = NULL;
496
497   CORBA_free (relation_set);
498
499   return relations;
500 }
501
502 /**
503  * Accessible_getRole:
504  * @obj: a pointer to the #Accessible object on which to operate.
505  *
506  * Get the UI role of an #Accessible object.
507  * A UTF-8 string describing this role can be obtained via Accessible_getRoleName ().
508  *
509  * Returns: the #AccessibleRole of the object.
510  *
511  **/
512 AccessibleRole
513 Accessible_getRole (Accessible *obj)
514 {
515   AccessibleRole retval;
516
517   cspi_return_val_if_fail (obj != NULL, SPI_ROLE_INVALID);
518
519   retval = 
520     Accessibility_Accessible_getRole (CSPI_OBJREF (obj), cspi_ev ());
521
522   cspi_return_val_if_ev ("getRole", SPI_ROLE_INVALID); 
523
524   return cspi_role_from_spi_role (retval);
525 }
526
527 /**
528  * Accessible_getRoleName:
529  * @obj: a pointer to the #Accessible object on which to operate.
530  *
531  * Get a UTF-8 string describing the role this object plays in the UI.
532  * This method will return useful values for roles that fall outside the
533  * enumeration used in Accessible_getRole ().
534  *
535  * Returns: a UTF-8 string specifying the role of this #Accessible object.
536  *
537  **/
538 char *
539 Accessible_getRoleName (Accessible *obj)
540 {
541   char *retval;
542
543   cspi_return_val_if_fail (obj != NULL, CORBA_string_dup ("invalid"));
544
545   retval = 
546     Accessibility_Accessible_getRoleName (CSPI_OBJREF (obj), cspi_ev ());
547
548   cspi_return_val_if_ev ("getRoleName", CORBA_string_dup ("invalid")); 
549
550   return retval;
551 }
552
553 /**
554  * Accessible_getStateSet:
555  * @obj: a pointer to the #Accessible object on which to operate.
556  *
557  * Not Yet Implemented.
558  *
559  * Returns: a pointer to an #AccessibleStateSet representing the object's current state.
560  **/
561 AccessibleStateSet *
562 Accessible_getStateSet (Accessible *obj)
563 {
564   AccessibleStateSet *retval;
565
566   cspi_return_val_if_fail (obj != NULL, NULL);
567
568   retval = cspi_object_add (
569     Accessibility_Accessible_getState (CSPI_OBJREF (obj),
570                                           cspi_ev ()));
571
572   return retval;
573 }
574
575 /* Interface query methods */
576
577 /**
578  * Accessible_isAction:
579  * @obj: a pointer to the #Accessible instance to query.
580  *
581  * Query whether the specified #Accessible implements #AccessibleAction.
582  *
583  * Returns: #TRUE if @obj implements the #AccessibleAction interface,
584  *          #FALSE otherwise.
585  **/
586 SPIBoolean
587 Accessible_isAction (Accessible *obj)
588 {
589   return cspi_accessible_is_a (obj,
590                               "IDL:Accessibility/Action:1.0");
591 }
592
593 /**
594  * Accessible_isApplication:
595  * @obj: a pointer to the #Accessible instance to query.
596  *
597  * Query whether the specified #Accessible implements #AccessibleApplication.
598  *
599  * Returns: #TRUE if @obj implements the #AccessibleApplication interface,
600  *          #FALSE otherwise.
601  **/
602 SPIBoolean
603 Accessible_isApplication (Accessible *obj)
604 {
605   return cspi_accessible_is_a (obj,
606                               "IDL:Accessibility/Application:1.0");
607 }
608
609 /**
610  * Accessible_isComponent:
611  * @obj: a pointer to the #Accessible instance to query.
612  *
613  * Query whether the specified #Accessible implements #AccessibleComponent.
614  *
615  * Returns: #TRUE if @obj implements the #AccessibleComponent interface,
616  *          #FALSE otherwise.
617  **/
618 SPIBoolean
619 Accessible_isComponent (Accessible *obj)
620 {
621   return cspi_accessible_is_a (obj,
622                               "IDL:Accessibility/Component:1.0");
623 }
624
625 /**
626  * Accessible_isEditableText:
627  * @obj: a pointer to the #Accessible instance to query.
628  *
629  * Query whether the specified #Accessible implements #AccessibleEditableText.
630  *
631  * Returns: #TRUE if @obj implements the #AccessibleEditableText interface,
632  *          #FALSE otherwise.
633  **/
634 SPIBoolean
635 Accessible_isEditableText (Accessible *obj)
636 {
637   return cspi_accessible_is_a (obj,
638                               "IDL:Accessibility/EditableText:1.0");
639 }
640
641 /**
642  * Accessible_isHypertext:
643  * @obj: a pointer to the #Accessible instance to query.
644  *
645  * Query whether the specified #Accessible implements #AccessibleHypertext.
646  *
647  * Returns: #TRUE if @obj implements the #AccessibleHypertext interface,
648  *          #FALSE otherwise.
649  **/
650 SPIBoolean
651 Accessible_isHypertext (Accessible *obj)
652 {
653   return cspi_accessible_is_a (obj,
654                               "IDL:Accessibility/Hypertext:1.0");
655 }
656
657 /**
658  * Accessible_isImage:
659  * @obj: a pointer to the #Accessible instance to query.
660  *
661  * Query whether the specified #Accessible implements #AccessibleImage.
662  *
663  * Returns: #TRUE if @obj implements the #AccessibleImage interface,
664  *          #FALSE otherwise.
665 **/
666 SPIBoolean
667 Accessible_isImage (Accessible *obj)
668 {
669   return cspi_accessible_is_a (obj,
670                               "IDL:Accessibility/Image:1.0");
671 }
672
673 /**
674  * Accessible_isSelection:
675  * @obj: a pointer to the #Accessible instance to query.
676  *
677  * Query whether the specified #Accessible implements #AccessibleSelection.
678  *
679  * Returns: #TRUE if @obj implements the #AccessibleSelection interface,
680  *          #FALSE otherwise.
681 **/
682 SPIBoolean
683 Accessible_isSelection (Accessible *obj)
684 {
685   return cspi_accessible_is_a (obj,
686                               "IDL:Accessibility/Selection:1.0");
687 }
688
689 /**
690  * Accessible_isTable:
691  * @obj: a pointer to the #Accessible instance to query.
692  *
693  * Query whether the specified #Accessible implements #AccessibleTable.
694  *
695  * Returns: #TRUE if @obj implements the #AccessibleTable interface,
696  *          #FALSE otherwise.
697 **/
698 SPIBoolean
699 Accessible_isTable (Accessible *obj)
700 {
701   return cspi_accessible_is_a (obj,
702                               "IDL:Accessibility/Table:1.0");
703 }
704
705 /**
706  * Accessible_isStreamableContent:
707  * @obj: a pointer to the #Accessible instance to query.
708  *
709  * Query whether the specified #Accessible implements
710  *          #AccessibleStreamableContent.
711  *
712  * Returns: #TRUE if @obj implements the #AccessibleStreamableContent interface,
713  *          #FALSE otherwise.
714 **/
715 SPIBoolean
716 Accessible_isStreamableContent (Accessible *obj)
717 {
718   return cspi_accessible_is_a (obj,
719                               "IDL:Accessibility/StreamableContent:1.0");
720 }
721
722 /**
723  * Accessible_isText:
724  * @obj: a pointer to the #Accessible instance to query.
725  *
726  * Query whether the specified #Accessible implements #AccessibleText.
727  *
728  * Returns: #TRUE if @obj implements the #AccessibleText interface,
729  *          #FALSE otherwise.
730 **/
731 SPIBoolean
732 Accessible_isText (Accessible *obj)
733 {
734   return cspi_accessible_is_a (obj,
735                               "IDL:Accessibility/Text:1.0");
736 }
737
738 /**
739  * Accessible_isValue:
740  * @obj: a pointer to the #Accessible instance to query.
741  *
742  * Query whether the specified #Accessible implements #AccessibleValue.
743  *
744  * Returns: #TRUE if @obj implements the #AccessibleValue interface,
745  *          #FALSE otherwise.
746 **/
747 SPIBoolean
748 Accessible_isValue (Accessible *obj)
749 {
750   return cspi_accessible_is_a (obj,
751                               "IDL:Accessibility/Value:1.0");
752 }
753
754 /**
755  * Accessible_getApplication:
756  * @obj: a pointer to the #Accessible instance to query.
757  *
758  * Get the #AccessibleApplication interface for an #Accessible.
759  *
760  * Returns: a pointer to an #AccessibleApplication interface instance, or
761  *          NULL if @obj does not implement #AccessibleApplication.
762  **/
763 AccessibleApplication *
764 Accessible_getApplication (Accessible *obj)
765 {
766   return (AccessibleApplication *) Accessible_queryInterface (
767           obj, "IDL:Accessibility/Application:1.0");
768 }
769
770 /**
771  * Accessible_getAction:
772  * @obj: a pointer to the #Accessible instance to query.
773  *
774  * Get the #AccessibleAction interface for an #Accessible.
775  *
776  * Returns: a pointer to an #AccessibleAction interface instance, or
777  *          NULL if @obj does not implement #AccessibleAction.
778  **/
779 AccessibleAction *
780 Accessible_getAction (Accessible *obj)
781 {
782   return (AccessibleAction *) Accessible_queryInterface (
783           obj, "IDL:Accessibility/Action:1.0");
784 }
785
786 /**
787  * Accessible_getComponent:
788  * @obj: a pointer to the #Accessible instance to query.
789  *
790  * Get the #AccessibleComponent interface for an #Accessible.
791  *
792  * Returns: a pointer to an #AccessibleComponent interface instance, or
793  *          NULL if @obj does not implement #AccessibleComponent.
794  **/
795 AccessibleComponent *
796 Accessible_getComponent (Accessible *obj)
797 {
798   return (AccessibleComponent *) Accessible_queryInterface (
799           obj, "IDL:Accessibility/Component:1.0");
800 }
801
802 /**
803  * Accessible_getEditableText:
804  * @obj: a pointer to the #Accessible instance to query.
805  *
806  * Get the #AccessibleEditableText interface for an #Accessible.
807  *
808  * Returns: a pointer to an #AccessibleEditableText interface instance, or
809  *          NULL if @obj does not implement #AccessibleEditableText.
810  **/
811 AccessibleEditableText *
812 Accessible_getEditableText (Accessible *obj)
813 {
814   return (AccessibleEditableText *) Accessible_queryInterface (
815           obj, "IDL:Accessibility/EditableText:1.0");
816 }
817
818
819
820 /**
821  * Accessible_getHypertext:
822  * @obj: a pointer to the #Accessible instance to query.
823  *
824  * Get the #AccessibleHypertext interface for an #Accessible.
825  *
826  * Returns: a pointer to an #AccessibleHypertext interface instance, or
827  *          NULL if @obj does not implement #AccessibleHypertext.
828  **/
829 AccessibleHypertext *
830 Accessible_getHypertext (Accessible *obj)
831 {
832   return (AccessibleHypertext *) Accessible_queryInterface (
833           obj, "IDL:Accessibility/Hypertext:1.0");
834 }
835
836
837
838 /**
839  * Accessible_getImage:
840  * @obj: a pointer to the #Accessible instance to query.
841  *
842  * Get the #AccessibleImage interface for an #Accessible.
843  *
844  * Returns: a pointer to an #AccessibleImage interface instance, or
845  *          NULL if @obj does not implement #AccessibleImage.
846  **/
847 AccessibleImage *
848 Accessible_getImage (Accessible *obj)
849 {
850   return (AccessibleImage *) Accessible_queryInterface (
851           obj, "IDL:Accessibility/Image:1.0");
852 }
853
854
855
856 /**
857  * Accessible_getSelection:
858  * @obj: a pointer to the #Accessible instance to query.
859  *
860  * Get the #AccessibleSelection interface for an #Accessible.
861  *
862  * Returns: a pointer to an #AccessibleSelection interface instance, or
863  *          NULL if @obj does not implement #AccessibleSelection.
864  **/
865 AccessibleSelection *
866 Accessible_getSelection (Accessible *obj)
867 {
868   return (AccessibleSelection *) Accessible_queryInterface (
869           obj, "IDL:Accessibility/Selection:1.0");
870 }
871
872
873
874 /**
875  * Accessible_getStreamableContent:
876  * @obj: a pointer to the #Accessible instance to query.
877  *
878  * Get the #AccessibleStreamableContent interface for an #Accessible.
879  *
880  * Returns: a pointer to an #AccessibleStreamableContent interface instance, or
881  *          NULL if @obj does not implement #AccessibleStreamableContent.
882  **/
883 AccessibleStreamableContent *
884 Accessible_getStreamableContent (Accessible *obj)
885 {
886   return (AccessibleStreamableContent *) Accessible_queryInterface (
887           obj, "IDL:Accessibility/StreamableContent:1.0");
888 }
889
890 /**
891  * Accessible_getTable:
892  * @obj: a pointer to the #Accessible instance to query.
893  *
894  * Get the #AccessibleTable interface for an #Accessible.
895  *
896  * Returns: a pointer to an #AccessibleTable interface instance, or
897  *          NULL if @obj does not implement #AccessibleTable.
898  **/
899 AccessibleTable *
900 Accessible_getTable (Accessible *obj)
901 {
902   return (AccessibleTable *) Accessible_queryInterface (
903           obj, "IDL:Accessibility/Table:1.0");
904 }
905
906 /**
907  * Accessible_getText:
908  * @obj: a pointer to the #Accessible instance to query.
909  *
910  * Get the #AccessibleText interface for an #Accessible.
911  *
912  * Returns: a pointer to an #AccessibleText interface instance, or
913  *          NULL if @obj does not implement #AccessibleText.
914  **/
915 AccessibleText *
916 Accessible_getText (Accessible *obj)
917 {
918   return (AccessibleText *) Accessible_queryInterface (
919           obj, "IDL:Accessibility/Text:1.0");
920 }
921
922
923
924 /**
925  * Accessible_getValue:
926  * @obj: a pointer to the #Accessible instance to query.
927  *
928  * Get the #AccessibleValue interface for an #Accessible.
929  *
930  * Returns: a pointer to an #AccessibleValue interface instance, or
931  *          NULL if @obj does not implement #AccessibleValue.
932  **/
933 AccessibleValue *
934 Accessible_getValue (Accessible *obj)
935 {
936   return (AccessibleValue *) Accessible_queryInterface (
937           obj, "IDL:Accessibility/Value:1.0");
938 }
939
940
941
942 /**
943  * Accessible_queryInterface:
944  * @obj: a pointer to the #Accessible instance to query.
945  * @interface_name: a UTF-8 character string specifiying the requested interface.
946  *
947  * Query an #Accessible object to for a named interface.
948  *
949  * Returns: an instance of the named interface object, if it is implemented
950  *          by @obj, or NULL otherwise.
951  *
952  **/
953 AccessibleUnknown *
954 Accessible_queryInterface (Accessible *obj,
955                            const char *interface_name)
956 {
957   Bonobo_Unknown iface;
958   
959   if (!obj)
960     {
961       return NULL;
962     }
963
964   iface = Accessibility_Accessible_queryInterface (CSPI_OBJREF (obj),
965                                                    interface_name,
966                                                    cspi_ev ());
967
968
969   cspi_return_val_if_ev ("queryInterface", NULL); 
970
971   /*
972    * FIXME: we need to be fairly sure that references are going
973    * to mach up if we are going to expose QueryInterface, ie. we
974    * can't allow people to do:
975    * b = a.qi ("b"); b.unref, b.unref to release a's reference.
976    * this should be no real problem though for this level of API
977    * user.
978    */
979
980   return cspi_object_add (iface);
981 }
982
983
984 /**
985  * AccessibleRelation_ref:
986  * @obj: a pointer to the #AccessibleRelation object on which to operate.
987  *
988  * Increment the reference count for an #AccessibleRelation object.
989  *
990  **/
991 void
992 AccessibleRelation_ref (AccessibleRelation *obj)
993 {
994   cspi_object_ref (obj);
995 }
996
997 /**
998  * AccessibleRelation_unref:
999  * @obj: a pointer to the #AccessibleRelation object on which to operate.
1000  *
1001  * Decrement the reference count for an #AccessibleRelation object.
1002  *
1003  **/
1004 void
1005 AccessibleRelation_unref (AccessibleRelation *obj)
1006 {
1007   cspi_object_unref (obj);
1008 }
1009
1010 /**
1011  * AccessibleRelation_getRelationType:
1012  * @obj: a pointer to the #AccessibleRelation object to query.
1013  *
1014  * Get the type of relationship represented by an #AccessibleRelation.
1015  *
1016  * Returns: an #AccessibleRelationType indicating the type of relation
1017  *         encapsulated in this #AccessibleRelation object.
1018  *
1019  **/
1020 AccessibleRelationType
1021 AccessibleRelation_getRelationType (AccessibleRelation *obj)
1022 {
1023   AccessibleRelationType retval;
1024   
1025   cspi_return_val_if_fail (obj, SPI_RELATION_NULL);
1026   retval =
1027     Accessibility_Relation_getRelationType (CSPI_OBJREF (obj), cspi_ev());
1028   cspi_return_val_if_ev ("getRelationType", SPI_RELATION_NULL);
1029   return retval;
1030 }
1031
1032 /**
1033  * AccessibleRelation_getNTargets:
1034  * @obj: a pointer to the #AccessibleRelation object to query.
1035  *
1036  * Get the number of objects which this relationship has as its
1037  *       target objects (the subject is the #Accessible from which this
1038  *       #AccessibleRelation originated).
1039  *
1040  * Returns: a short integer indicating how many target objects which the
1041  *       originating #Accessible object has the #AccessibleRelation
1042  *       relationship with.
1043  **/
1044 int
1045 AccessibleRelation_getNTargets (AccessibleRelation *obj)
1046 {
1047   int retval;
1048   
1049   cspi_return_val_if_fail (obj, -1);
1050   retval = (int)
1051     Accessibility_Relation_getNTargets (CSPI_OBJREF (obj), cspi_ev());
1052   cspi_return_val_if_ev ("getNTargets", -1);
1053   return retval;
1054 }
1055
1056 /**
1057  * AccessibleRelation_getTarget:
1058  * @obj: a pointer to the #AccessibleRelation object to query.
1059  * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
1060  *
1061  * Get the @i-th target of a specified #AccessibleRelation relationship.
1062  *
1063  * Returns: an #Accessible which is the @i-th object with which the
1064  *      originating #Accessible has relationship specified in the
1065  *      #AccessibleRelation object.
1066  *
1067  **/
1068 Accessible *
1069 AccessibleRelation_getTarget (AccessibleRelation *obj, int i)
1070 {
1071   Accessible *retval;
1072
1073   cspi_return_val_if_fail (obj, NULL);
1074
1075   retval = cspi_object_add (
1076                          Accessibility_Relation_getTarget (CSPI_OBJREF(obj),
1077                                                            (CORBA_short) i, cspi_ev()));
1078   cspi_return_val_if_ev ("getTarget", NULL);
1079   return retval;
1080 }
1081
1082 /**
1083  * AccessibleStateSet_ref:
1084  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1085  *
1086  * Increment the reference count for an #AccessibleStateSet object.
1087  *
1088  **/
1089 void
1090 AccessibleStateSet_ref (AccessibleStateSet *obj)
1091 {
1092   cspi_object_ref (obj);
1093 }
1094
1095 /**
1096  * AccessibleStateSet_unref:
1097  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1098  *
1099  * Decrement the reference count for an #AccessibleStateSet object.
1100  *
1101  **/
1102 void
1103 AccessibleStateSet_unref (AccessibleStateSet *obj)
1104 {
1105   cspi_object_unref (obj);
1106 }
1107
1108 /**
1109  * AccessibleStateSet_contains:
1110  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1111  * @state: an #AccessibleState for which the specified #AccessibleStateSet
1112  *       will be queried.
1113  *
1114  * Determine whether a given #AccessibleStateSet includes a given state; that is,
1115  *       whether @state is true for the stateset in question.
1116  *
1117  * Returns: #TRUE if @state is true/included in the given #AccessibleStateSet,
1118  *          otherwise #FALSE.
1119  *
1120  **/
1121 SPIBoolean
1122 AccessibleStateSet_contains (AccessibleStateSet *obj,
1123                              AccessibleState state)
1124 {
1125   CORBA_boolean retval;
1126   Accessibility_StateType spi_state;
1127   
1128   cspi_return_val_if_fail (obj != NULL, FALSE);
1129
1130   spi_state = spi_state_type_from_accessible_state (state);
1131   retval = Accessibility_StateSet_contains (CSPI_OBJREF (obj),
1132                                             spi_state, cspi_ev ());
1133
1134   cspi_return_val_if_ev ("contains", FALSE);
1135
1136   return (SPIBoolean) retval;
1137 }
1138
1139 /**
1140  * AccessibleStateSet_add:
1141  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1142  * @state: an #AccessibleState to be added to the specified #AccessibleStateSet
1143  *
1144  * Add a particular #AccessibleState to an #AccessibleStateSet (i.e. set the
1145  *       given state to #TRUE in the stateset.
1146  *
1147  **/
1148 void
1149 AccessibleStateSet_add (AccessibleStateSet *obj,
1150                         AccessibleState state)
1151 {
1152   Accessibility_StateType spi_state;
1153
1154   cspi_return_if_fail (obj != NULL);
1155
1156   spi_state = spi_state_type_from_accessible_state (state);
1157   Accessibility_StateSet_add (CSPI_OBJREF (obj), spi_state, cspi_ev ());
1158   cspi_check_ev ("add");
1159 }
1160
1161 /**
1162  * AccessibleStateSet_remove:
1163  * @obj: a pointer to the #AccessibleStateSet object on which to operate.
1164  * @state: an #AccessibleState to be removed from the specified #AccessibleStateSet
1165  *
1166  * Remove a particular #AccessibleState to an #AccessibleStateSet (i.e. set the
1167  *       given state to #FALSE in the stateset.)
1168  *
1169  **/
1170 void
1171 AccessibleStateSet_remove (AccessibleStateSet *obj,
1172                            AccessibleState state)
1173 {
1174   Accessibility_StateType spi_state;
1175
1176   cspi_return_if_fail (obj != NULL);
1177
1178   spi_state = spi_state_type_from_accessible_state (state);
1179   Accessibility_StateSet_remove (CSPI_OBJREF (obj), spi_state, cspi_ev ());
1180   cspi_check_ev ("remove");
1181 }
1182
1183 /**
1184  * AccessibleStateSet_equals:
1185  * @obj: a pointer to the first #AccessibleStateSet object on which to operate.
1186  * @obj2: a pointer to the second #AccessibleStateSet object on which to operate.
1187  *
1188  * Determine whether two instances of #AccessibleStateSet are equivalent (i.e.
1189  *         consist of the same #AccessibleStates).  Useful for checking multiple
1190  *         state variables at once; construct the target state then compare against it.
1191  *
1192  * @see AccessibleStateSet_compare().
1193  *
1194  * Returns: #TRUE if the two #AccessibleStateSets are equivalent,
1195  *          otherwise #FALSE.
1196  *
1197  **/
1198 SPIBoolean
1199 AccessibleStateSet_equals (AccessibleStateSet *obj,
1200                            AccessibleStateSet *obj2)
1201 {
1202   if (obj == obj2)
1203     {
1204       return TRUE;
1205     }
1206
1207   cspi_return_val_if_fail (obj != NULL, FALSE);
1208   cspi_return_val_if_fail (obj2 != NULL, FALSE);
1209
1210   return Accessibility_StateSet_equals (CSPI_OBJREF (obj),
1211                                         CSPI_OBJREF (obj2), cspi_ev ());
1212 }
1213
1214 /**
1215  * AccessibleStateSet_compare:
1216  * @obj: a pointer to the first #AccessibleStateSet object on which to operate.
1217  * @obj2: a pointer to the second #AccessibleStateSet object on which to operate.
1218  *
1219  * Determine the differences between two instances of #AccessibleStateSet.
1220  * Not Yet Implemented.
1221  *.
1222  * @see AccessibleStateSet_equals().
1223  *
1224  * Returns: an #AccessibleStateSet object containing all states contained on one of
1225  *          the two sets but not the other.
1226  *
1227  **/
1228 AccessibleStateSet *
1229 AccessibleStateSet_compare (AccessibleStateSet *obj,
1230                             AccessibleStateSet *obj2)
1231 {
1232   Accessibility_StateSet retval;
1233
1234   cspi_return_val_if_fail (obj != NULL, NULL);
1235   cspi_return_val_if_fail (obj2 != NULL, NULL);
1236   retval = Accessibility_StateSet_compare (CSPI_OBJREF(obj), CSPI_OBJREF(obj2), cspi_ev ());
1237   return NULL;  
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   return (SPIBoolean) retval;
1258 }
1259
1260