2001-11-13 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / cspi / spi_accessible.c
1 #define MAX_ROLES 100
2
3 static char *role_names [MAX_ROLES] =
4 {
5   " ",
6   "accelerator label",
7   "alert",
8   "animation",
9   "arrow",
10   "calendar",
11   "canvas",
12   "check box",
13   "menu item",
14   "color chooser",
15   "column header",
16   "combo box",
17   "date editor",
18   "desktop icon",
19   "desktop frame",
20   "dial",
21   "dialog",
22   "directory pane",
23   "drawing area",
24   "file chooser",
25   "filler",
26   "font chooser",
27   "frame",
28   "glass pane",
29   "HTML container",
30   "icon",
31   "image",
32   "internal frame",
33   "label",
34   "layered pane",
35   "list",
36   "list item",
37   "menu",
38   "menubar",
39   "menu item",
40   "option pane",
41   "page tab",
42   "page tab list",
43   "panel",
44   "password text",
45   "popup menu",
46   "progress bar",
47   "pushbutton",
48   "radiobutton",
49   "radio menu item",
50   "root pane",
51   "row header",
52   "scrollbar",
53   "scrollpane",
54   "separator",
55   "slider",
56   "split pane",
57   "spin button",
58   "status bar",
59   "table",
60   "table cell",
61   "table column header",
62   "table row header",
63   "tearoff menu item",
64   "text",
65   "toggle button",
66   "toolbar",
67   "tooltip",
68   "tree",
69   " ",
70   "viewport",
71   "window",
72 };
73
74 /*
75  * Returns a localizable string name for an AtkRole enumerated type.
76  */
77 char*
78 SpiAccessible_Role_getName (Accessibility_Role role)
79 {
80   if (role < MAX_ROLES) return role_names [(int) role];
81   else return "";
82 }
83
84
85
86 /**
87  * SpiAccessible_ref:
88  * @obj: a pointer to the #Accessible object on which to operate.
89  *
90  * Increment the reference count for an #Accessible object.
91  *
92  * Returns: (no return code implemented yet).
93  *
94  **/
95 int
96 SpiAccessible_ref (SpiAccessible *obj)
97 {
98   Accessibility_Accessible_ref (*obj, &ev);
99   spi_check_ev (&ev, "ref");
100   return 0;
101 }
102
103
104 /**
105  * SpiAccessible_unref:
106  * @obj: a pointer to the #Accessible object on which to operate.
107  *
108  * Decrement the reference count for an #Accessible object.
109  *
110  * Returns: (no return code implemented yet).
111  *
112  **/
113 int
114 SpiAccessible_unref (SpiAccessible *obj)
115 {
116   Accessibility_Accessible_unref (*obj, &ev);
117   spi_check_ev (&ev, "unref");
118   return 0;
119 }
120
121 /**
122  * SpiAccessible_getName:
123  * @obj: a pointer to the #Accessible object on which to operate.
124  *
125  * Get the name of an #Accessible object.
126  *
127  * Returns: a UTF-8 string indicating the name of the #Accessible object.
128  *
129  **/
130 char *
131 SpiAccessible_getName (SpiAccessible *obj)
132 {
133   char *retval = 
134     (char *)
135     Accessibility_Accessible__get_name (*obj, &ev);
136   spi_check_ev (&ev, "getName"); 
137   return retval;
138 }
139
140 /**
141  * SpiAccessible_getDescription:
142  * @obj: a pointer to the #Accessible object on which to operate.
143  *
144  * Get the description of an #Accessible object.
145  *
146  * Returns: a UTF-8 string describing the #Accessible object.
147  *
148  **/
149 char *
150 SpiAccessible_getDescription (SpiAccessible *obj)
151 {
152   char *retval = (char *)
153     Accessibility_Accessible__get_description (*obj, &ev);
154   spi_check_ev (&ev, "getDescription");
155   return retval;
156 }
157
158 /**
159  * SpiAccessible_getParent:
160  * @obj: a pointer to the #Accessible object to query.
161  *
162  * Get an #Accessible object's parent container.
163  *
164  * Returns: a pointer tothe #Accessible object which contains the given
165  *          #Accessible instance, or NULL if the @obj has no parent container.
166  *
167  **/
168 SpiAccessible *
169 SpiAccessible_getParent (SpiAccessible *obj)
170 {
171   SpiAccessible *retval = 
172       Obj_Add (Accessibility_Accessible__get_parent (*obj, &ev));
173   spi_check_ev (&ev, "getParent");
174   return retval;
175 }
176
177 /**
178  * SpiAccessible_getChildCount:
179  *
180  * @obj: a pointer to the #Accessible object on which to operate.
181  *
182  * Get the number of children contained by an #Accessible object.
183  *
184  * Returns: a #long indicating the number of #Accessible children
185  *          contained by an #Accessible object.
186  *
187  **/
188 long
189 SpiAccessible_getChildCount (SpiAccessible *obj)
190 {
191   long retval = (long) Accessibility_Accessible__get_childCount (*obj, &ev);
192   spi_check_ev (&ev, "getChildCount");
193   return retval;
194 }
195
196 /**
197  * SpiAccessible_getChildAtIndex:
198  *
199  * @obj: a pointer to the #Accessible object on which to operate.
200  * @childIndex: a #long indicating which child is specified.
201  *
202  * Get the #Accessible child of an #Accessible object at a given index.
203  *
204  * Returns: a pointer to the #Accessible child object at index
205  *          @childIndex.
206  *
207  **/
208 SpiAccessible *
209 SpiAccessible_getChildAtIndex (SpiAccessible *obj,
210                             long childIndex)
211 {
212   SpiAccessible *retval = Obj_Add (Accessibility_Accessible_getChildAtIndex (*obj, childIndex, &ev));
213   spi_check_ev (&ev, "getChildAtIndex");
214   return retval;
215 }
216
217 /**
218  * SpiAccessible_getIndexInParent:
219  *
220  * @obj: a pointer to the #Accessible object on which to operate.
221  *
222  * Get the index of an #Accessible object in its containing #Accessible.
223  *
224  * Returns: a #long indicating the index of the #Accessible object
225  *          in its parent (i.e. containing) #Accessible instance,
226  *          or -1 if @obj has no containing parent.
227  *
228  **/
229 long
230 SpiAccessible_getIndexInParent (SpiAccessible *obj)
231 {
232   long retval = (long) Accessibility_Accessible_getIndexInParent (*obj, &ev);
233   spi_check_ev (&ev, "getIndexInParent");
234   return retval;
235 }
236
237 /**
238  * SpiAccessible_getRelationSet:
239  *
240  * Not Yet Implemented.
241  *
242  * Returns: a pointer to an array of #AccessibleRelations.
243  *
244  **/
245 SpiAccessibleRelation **
246 SpiAccessible_getRelationSet (SpiAccessible *obj)
247 {
248   return NULL;
249 }
250
251 /**
252  * SpiAccessible_getRole:
253  * @obj: a pointer to the #Accessible object on which to operate.
254  *
255  * Get the UI role of an #Accessible object.
256  *
257  * Returns: a UTF-8 string indicating the UI role of the #Accessible object.
258  *
259  **/
260 char *
261 SpiAccessible_getRole (SpiAccessible *obj)
262 {
263   char *retval = SpiAccessible_Role_getName (
264                   Accessibility_Accessible_getRole (*obj, &ev));
265   spi_check_ev (&ev, "getRole");
266   return retval;
267 }
268
269 /**
270  * SpiAccessible_getStateSet:
271  *
272  * Not Yet Implemented.
273  *
274  * Returns: a pointer to an #AccessibleStateSet representing the object's current state.
275  **/
276 SpiAccessibleStateSet *
277 SpiAccessible_getStateSet (SpiAccessible *obj)
278 {
279   return NULL;
280 }
281
282 /* Interface query methods */
283
284 /**
285  * SpiAccessible_isAction:
286  * @obj: a pointer to the #Accessible instance to query.
287  *
288  * Query whether the specified #Accessible implements #AccessibleAction.
289  * Not Yet Implemented.
290  *
291  * Returns: #TRUE if @obj implements the #AccessibleAction interface,
292  *          #FALSE otherwise.
293  **/
294 boolean
295 SpiAccessible_isAction (SpiAccessible *obj)
296 {
297   Bonobo_Unknown iface =
298     Accessibility_Accessible_queryInterface (*obj,
299                                              "IDL:Accessibility/Action:1.0",
300                                              &ev);
301   spi_warn_ev (&ev, "isAction");
302
303   return (CORBA_Object_is_nil (iface, &ev)) ? FALSE : TRUE;
304 }
305
306 /**
307  * SpiAccessible_isComponent:
308  * @obj: a pointer to the #Accessible instance to query.
309  *
310  * Query whether the specified #Accessible implements #AccessibleComponent.
311  *
312  * Returns: #TRUE if @obj implements the #AccessibleComponent interface,
313  *          #FALSE otherwise.
314  **/
315 boolean
316 SpiAccessible_isComponent (SpiAccessible *obj)
317 {
318   Bonobo_Unknown iface =
319     Accessibility_Accessible_queryInterface (*obj,
320                                              "IDL:Accessibility/Component:1.0",
321                                              &ev);
322   spi_warn_ev (&ev, "isComponent");
323
324   return (CORBA_Object_is_nil (iface, &ev)) ? FALSE : TRUE;
325 }
326
327 /**
328  * SpiAccessible_isEditableText:
329  * @obj: a pointer to the #Accessible instance to query.
330  *
331  * Query whether the specified #Accessible implements #AccessibleEditableText.
332  * Not Yet Implemented.
333  *
334  * Returns: #TRUE if @obj implements the #AccessibleEditableText interface,
335  *          #FALSE otherwise.
336  **/
337 boolean
338 SpiAccessible_isEditableText (SpiAccessible *obj)
339 {
340   Bonobo_Unknown iface =
341     Accessibility_Accessible_queryInterface (*obj,
342                                              "IDL:Accessibility/EditableText:1.0",
343                                              &ev);
344   spi_check_ev (&ev, "isEditableText");
345
346   return (CORBA_Object_is_nil (iface, &ev)) ? FALSE : TRUE;
347 }
348
349 /**
350  * SpiAccessible_isHypertext:
351  * @obj: a pointer to the #Accessible instance to query.
352  *
353  * Query whether the specified #Accessible implements #AccessibleHypertext.
354  * Not Yet Implemented.
355  *
356  * Returns: #TRUE if @obj implements the #AccessibleHypertext interface,
357  *          #FALSE otherwise.
358  **/
359 boolean
360 SpiAccessible_isHypertext (SpiAccessible *obj)
361 {
362   Bonobo_Unknown iface =
363     Accessibility_Accessible_queryInterface (*obj,
364                                              "IDL:Accessibility/Hypertext:1.0",
365                                              &ev);
366
367   spi_check_ev (&ev, "isHypertext");
368
369   return (CORBA_Object_is_nil (iface, &ev)) ? FALSE : TRUE;
370 }
371
372 /**
373  * SpiAccessible_isImage:
374  * @obj: a pointer to the #Accessible instance to query.
375  *
376  * Query whether the specified #Accessible implements #AccessibleImage.
377  * Not Yet Implemented.
378  *
379  * Returns: #TRUE if @obj implements the #AccessibleImage interface,
380  *          #FALSE otherwise.
381 **/
382 boolean
383 SpiAccessible_isImage (SpiAccessible *obj)
384 {
385   Bonobo_Unknown iface =
386     Accessibility_Accessible_queryInterface (*obj,
387                                              "IDL:Accessibility/Image:1.0",
388                                              &ev);
389   spi_check_ev (&ev, "isImage");
390
391   return (CORBA_Object_is_nil (iface, &ev)) ? FALSE : TRUE;
392 }
393
394 /**
395   * SpiAccessible_isSelection:
396  * @obj: a pointer to the #Accessible instance to query.
397  *
398  * Query whether the specified #Accessible implements #AccessibleSelection.
399  * Not Yet Implemented.
400  *
401  * Returns: #TRUE if @obj implements the #AccessibleSelection interface,
402  *          #FALSE otherwise.
403 **/
404 boolean
405 SpiAccessible_isSelection (SpiAccessible *obj)
406 {
407   Bonobo_Unknown iface =
408     Accessibility_Accessible_queryInterface (*obj,
409                                              "IDL:Accessibility/Selection:1.0",
410                                              &ev);
411   spi_warn_ev (&ev, "isSelection");
412
413   return (CORBA_Object_is_nil (iface, &ev)) ? FALSE : TRUE;
414
415 }
416
417 /**
418  * SpiAccessible_isTable:
419  * @obj: a pointer to the #Accessible instance to query.
420  *
421  * Query whether the specified #Accessible implements #AccessibleTable.
422  * Not Yet Implemented.
423  *
424  * Returns: #TRUE if @obj implements the #AccessibleTable interface,
425  *          #FALSE otherwise.
426 **/
427 boolean
428 SpiAccessible_isTable (SpiAccessible *obj)
429 {
430   Bonobo_Unknown iface =
431     Accessibility_Accessible_queryInterface (*obj,
432                                              "IDL:Accessibility/Table:1.0",
433                                              &ev);
434   spi_check_ev (&ev, "isTable");
435
436   return (CORBA_Object_is_nil (iface, &ev)) ? FALSE : TRUE;
437
438 }
439
440 /**
441  * SpiAccessible_isText:
442  * @obj: a pointer to the #Accessible instance to query.
443  *
444  * Query whether the specified #Accessible implements #AccessibleText.
445  * Not Yet Implemented.
446  *
447  * Returns: #TRUE if @obj implements the #AccessibleText interface,
448  *          #FALSE otherwise.
449 **/
450 boolean
451 SpiAccessible_isText (SpiAccessible *obj)
452 {
453   Bonobo_Unknown iface =
454     Accessibility_Accessible_queryInterface (*obj,
455                                              "IDL:Accessibility/Text:1.0",
456                                              &ev);
457   spi_warn_ev (&ev, "isText");
458
459   return (CORBA_Object_is_nil (iface, &ev)) ? FALSE : TRUE;
460 }
461
462 /**
463  * SpiAccessible_isValue:
464  * @obj: a pointer to the #Accessible instance to query.
465  *
466  * Query whether the specified #Accessible implements #AccessibleValue.
467  * Not Yet Implemented.
468  *
469  * Returns: #TRUE if @obj implements the #AccessibleValue interface,
470  *          #FALSE otherwise.
471 **/
472 boolean
473 SpiAccessible_isValue (SpiAccessible *obj)
474 {
475   Bonobo_Unknown iface =
476     Accessibility_Accessible_queryInterface (*obj,
477                                              "IDL:Accessibility/Value:1.0",
478                                              &ev);
479   spi_check_ev (&ev, "isValue");
480
481   return (CORBA_Object_is_nil (iface, &ev)) ? FALSE : TRUE;
482 }
483
484 /**
485  * SpiAccessible_getAction:
486  *
487  * Not Yet Implemented.
488  *
489  **/
490 SpiAccessibleAction *
491 SpiAccessible_getAction (SpiAccessible *obj)
492 {
493   Bonobo_Unknown iface =
494     Accessibility_Accessible_queryInterface (*obj,
495                                              "IDL:Accessibility/Action:1.0",
496                                              &ev);
497   spi_check_ev (&ev, "getAction");
498
499   return (SpiAccessibleAction *)
500           ((CORBA_Object_is_nil (iface, &ev)) ? 0 : Obj_Add (iface));
501 }
502
503 /**
504  * SpiAccessible_getComponent:
505  * @obj: a pointer to the #Accessible instance to query.
506  *
507  * Get the #AccessibleComponent interface for an #Accessible.
508  *
509  * Returns: a pointer to an #AccessibleComponent interface instance, or
510  *          NULL if @obj does not implement #AccessibleComponent.
511  **/
512 SpiAccessibleComponent *
513 SpiAccessible_getComponent (SpiAccessible *obj)
514 {
515   Bonobo_Unknown iface =
516     Accessibility_Accessible_queryInterface (*obj,
517                                              "IDL:Accessibility/Component:1.0",
518                                              &ev);
519   spi_check_ev (&ev, "getComponent");
520
521   return (SpiAccessibleComponent *) ((CORBA_Object_is_nil (iface, &ev)) ? 0 : Obj_Add (iface));
522 }
523
524 SpiAccessibleEditableText *
525 SpiAccessible_getEditableText (SpiAccessible *obj)
526 {
527   Bonobo_Unknown iface =
528     Accessibility_Accessible_queryInterface (*obj,
529                                              "IDL:Accessibility/EditableText:1.0",
530                                              &ev);
531   spi_check_ev (&ev, "getEditableText");
532
533   return (SpiAccessibleEditableText *)
534           ((CORBA_Object_is_nil (iface, &ev)) ? 0 : Obj_Add (iface));
535 }
536
537
538
539 SpiAccessibleHypertext *
540 SpiAccessible_getHypertext (SpiAccessible *obj)
541 {
542   Bonobo_Unknown iface =
543     Accessibility_Accessible_queryInterface (*obj,
544                                              "IDL:Accessibility/Hypertext:1.0",
545                                              &ev);
546   spi_check_ev (&ev, "getHypertext");
547
548   return (SpiAccessibleHypertext *)
549           ((CORBA_Object_is_nil (iface, &ev)) ? 0 : Obj_Add (iface));
550 }
551
552
553
554 SpiAccessibleImage *
555 SpiAccessible_getImage (SpiAccessible *obj)
556 {
557   Bonobo_Unknown iface =
558     Accessibility_Accessible_queryInterface (*obj,
559                                              "IDL:Accessibility/Image:1.0",
560                                              &ev);
561   spi_check_ev (&ev, "getImage");
562
563   return (SpiAccessibleImage *)
564           ((CORBA_Object_is_nil (iface, &ev)) ? 0 : Obj_Add (iface));
565 }
566
567
568
569 SpiAccessibleSelection *
570 SpiAccessible_getSelection (SpiAccessible *obj)
571 {
572   Bonobo_Unknown iface =
573     Accessibility_Accessible_queryInterface (*obj,
574                                              "IDL:Accessibility/Selection:1.0",
575                                              &ev);
576   spi_warn_ev (&ev, "getSelection");
577
578   return (SpiAccessibleSelection *)
579           ((CORBA_Object_is_nil (iface, &ev)) ? 0 : Obj_Add (iface));
580 }
581
582
583
584 SpiAccessibleTable *
585 SpiAccessible_getTable (SpiAccessible *obj)
586 {
587   Bonobo_Unknown iface =
588     Accessibility_Accessible_queryInterface (*obj,
589                                              "IDL:Accessibility/Table:1.0",
590                                              &ev);
591   spi_check_ev (&ev, "getTable");
592
593   return (SpiAccessibleTable *)
594           ((CORBA_Object_is_nil (iface, &ev)) ? 0 : Obj_Add (iface));
595 }
596
597 SpiAccessibleText *
598 SpiAccessible_getText (SpiAccessible *obj)
599 {
600   Bonobo_Unknown iface =
601     Accessibility_Accessible_queryInterface (*obj,
602                                              "IDL:Accessibility/Text:1.0",
603                                              &ev);
604
605   spi_check_ev (&ev, "getText"); 
606
607   return (SpiAccessibleText *)
608           ((CORBA_Object_is_nil (iface, &ev)) ? 0 : Obj_Add (iface));
609 }
610
611
612
613 SpiAccessibleValue *
614 SpiAccessible_getValue (SpiAccessible *obj)
615 {
616   Bonobo_Unknown iface =
617     Accessibility_Accessible_queryInterface (*obj,
618                                              "IDL:Accessibility/Value:1.0",
619                                              &ev);
620   return (SpiAccessibleValue *)
621           ((CORBA_Object_is_nil (iface, &ev)) ? 0 : Obj_Add (iface));
622 }
623
624
625
626 /**
627  * SpiAccessible_queryInterface:
628  * @obj: a pointer to the #Accessible instance to query.
629  * @interface_name: a UTF-8 character string specifiying the requested interface.
630  *
631  * Query an #Accessible object to for a named interface.
632  *
633  * Returns: an instance of the named interface object, if it is implemented
634  *          by @obj, or NULL otherwise.
635  *
636  **/
637 GenericInterface *
638 SpiAccessible_queryInterface (SpiAccessible *obj, char *interface_name)
639 {
640   GenericInterface iface;
641   iface = Accessibility_Accessible_queryInterface (*obj,
642                                                     interface_name,
643                                                     &ev);
644   return (iface != NULL) ? Obj_Add (iface) : NULL;
645 }
646