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