Added partial implementation of AccessibleComponent to libspi and
[platform/core/uifw/at-spi2-atk.git] / cspi / spi_main.c
1 #include <libbonobo.h>
2 #include <stdio.h>
3 #include "spi.h"
4
5 static CORBA_Environment ev;
6 static AccessibilityRegistry registry;
7
8 static Accessible *
9 Obj_Add (Accessible object)
10 {
11   /* TODO: keep list of live object refs */
12   Accessible *oref = g_malloc (sizeof (Accessible));
13   *oref = object;
14   return oref;
15 }
16
17 /*
18  *
19  * Basic SPI initialization and event loop function prototypes
20  *
21  */
22
23 int
24 SPI_init (void)
25 {
26   int argc = 0;
27   CORBA_Object oclient;
28   char *obj_id;
29
30   CORBA_exception_init(&ev);
31
32   if (!bonobo_init (&argc, NULL))
33     {
34       g_error ("Could not initialize Bonobo");
35     }
36
37   obj_id = "OAFIID:Accessibility_Registry:proto0.1";
38
39   oclient = bonobo_activation_activate_from_id (obj_id, 0, NULL, &ev);
40   if (ev._major != CORBA_NO_EXCEPTION) {
41     fprintf (stderr,
42             ("AT-SPI error: during registry activation: %s\n"),
43             CORBA_exception_id(&ev));
44     CORBA_exception_free(&ev);
45     exit(-1);
46   }
47
48   if (CORBA_Object_is_nil (oclient, &ev))
49     {
50       g_error ("Could not locate registry");
51       exit(-1);
52     }
53
54   registry = (Accessibility_Registry) oclient;
55
56   bonobo_activate ();
57
58   return 0;
59 }
60
61 void
62 SPI_event_main (boolean isGNOMEApp)
63 {
64   if (isGNOMEApp) bonobo_main();
65   else CORBA_ORB_run (bonobo_orb(), &ev);
66 }
67
68 /* Not Yet Implemented */
69 boolean
70 SPI_eventIsReady ()
71 {
72   return FALSE;
73 }
74
75 /* Not Yet Implemented */
76 AccessibleEvent *
77 SPI_nextEvent (boolean waitForEvent)
78 {
79   return NULL;
80 }
81
82 void
83 SPI_exit (void)
84 {
85   exit(0);
86 }
87
88 AccessibleEventListener *
89 createEventListener (AccessibleEventListenerCB callback)
90 {
91   AccessibleEventListener *listener = accessible_event_listener_new ();
92   if (callback)
93     {
94       accessible_event_listener_add_callback (listener, callback);
95     }
96   return listener;
97 }
98
99 boolean
100 EventListener_addCallback (AccessibleEventListener *listener,
101                            AccessibleEventListenerCB callback)
102 {
103   accessible_event_listener_add_callback (listener, callback);
104   return TRUE;
105 }
106
107 boolean
108 EventListener_removeCallback (AccessibleEventListener *listener,
109                            AccessibleEventListenerCB callback)
110 {
111   accessible_event_listener_remove_callback (listener, callback);
112   return TRUE;
113 }
114
115 /*
116  *
117  * Global functions serviced by the registry
118  *
119  */
120
121 boolean
122 registerGlobalEventListener (AccessibleEventListener *listener,
123                              char *eventType)
124 {
125   Accessibility_Registry_registerGlobalEventListener (
126                          registry,
127                          (Accessibility_EventListener)
128                             bonobo_object_corba_objref (bonobo_object (listener)),
129                          eventType,
130                          &ev);
131
132   if (ev._major != CORBA_NO_EXCEPTION)
133     {
134     return FALSE;
135     }
136   else
137     {
138       return TRUE;
139     }
140 }
141
142 int
143 getDesktopCount ()
144 {
145   return Accessibility_Registry_getDesktopCount (registry, &ev);
146 }
147
148 Accessible*
149 getDesktop (int n)
150 {
151   return Obj_Add (Accessibility_Registry_getDesktop (registry, (CORBA_short) n, &ev));
152 }
153
154 int
155 getDesktopList (Accessible **list)
156 {
157   *list = NULL;
158   return 0;
159 }
160
161 /* Not Yet Implemented */
162 void
163 registerKeystrokeListener (KeystrokeListener *listener)
164 {
165   ;
166 }
167
168 /* Not Yet Implemented */
169 void
170 generateKeyEvent (long keyCode, long meta)
171 {
172   ;
173 }
174
175 /* Not Yet Implemented */
176 void
177 generateMouseEvent (long x, long y, char *name)
178 {
179   ;
180 }
181
182 /*
183  *
184  * Accessible function prototypes
185  *
186  */
187
188 int
189 Accessible_ref (Accessible *obj)
190 {
191   Accessibility_Accessible_ref (*obj, &ev);
192   return 0;
193 }
194
195
196 int
197 Accessible_unref (Accessible *obj)
198 {
199   Accessibility_Accessible_unref (*obj, &ev);
200   return 0;
201 }
202
203 char *
204 Accessible_getName (Accessible *obj)
205 {
206   return Accessibility_Accessible__get_name (*obj, &ev);
207 }
208
209 char *
210 Accessible_getDescription (Accessible *obj)
211 {
212   return Accessibility_Accessible__get_description (*obj, &ev);
213 }
214
215 Accessible *
216 Accessible_getParent (Accessible *obj)
217 {
218   return Obj_Add (Accessibility_Accessible__get_parent (*obj, &ev));
219 }
220
221 long
222 Accessible_getChildCount (Accessible *obj)
223 {
224   return Accessibility_Accessible__get_childCount (*obj, &ev);
225 }
226
227 Accessible *
228 Accessible_getChildAtIndex (Accessible *obj,
229                             long childIndex)
230 {
231   return Obj_Add (Accessibility_Accessible_getChildAtIndex (*obj, childIndex, &ev));
232 }
233
234 long
235 Accessible_getIndexInParent (Accessible *obj)
236 {
237   return Accessibility_Accessible_getIndexInParent (*obj, &ev);
238 }
239
240 /* Not Yet Implemented */
241 AccessibleRelation **
242 Accessible_getRelationSet (Accessible *obj)
243 {
244   return NULL;
245 }
246
247 /* Not Yet Implemented */
248 char *
249 Accessible_getRole (Accessible *obj)
250 {
251   return "";
252 }
253
254 /* Not Yet Implemented */
255 AccessibleStateSet *
256 Accessible_getStateSet (Accessible *obj)
257 {
258   return NULL;
259 }
260
261 /* Interface query methods */
262
263 boolean
264 Accessible_isComponent (Accessible *obj)
265 {
266   Bonobo_Unknown iface =
267     Accessibility_Accessible_queryInterface (*obj,
268                                              "IDL:Accessibility/Component:1.0",
269                                              &ev);
270   return (iface != NULL) ? TRUE : FALSE;
271 }
272
273 AccessibleComponent *
274 Accessible_getComponent (Accessible *obj)
275 {
276   AccessibleComponent iface =
277     Accessibility_Accessible_queryInterface (*obj,
278                                              "IDL:Accessibility/Component:1.0",
279                                              &ev);
280   return Obj_Add (iface);
281 }
282
283 GenericInterface *
284 Accessible_queryInterface (Accessible *obj, char *interface_name)
285 {
286   GenericInterface iface;
287   iface = Accessibility_Accessible_queryInterface (*obj,
288                                                     interface_name,
289                                                     &ev);
290   return (iface != NULL) ? Obj_Add (iface) : NULL;
291 }
292
293 /*
294  *
295  * AccessibleApplication function prototypes
296  *
297  */
298
299 int
300 AccessibleApplication_ref (AccessibleApplication *obj)
301 {
302   Accessibility_Application_ref (*obj, &ev);
303   return 0;
304 }
305
306 int
307 AccessibleApplication_unref (AccessibleApplication *obj)
308 {
309   Accessibility_Application_unref (*obj, &ev);
310   return 0;
311 }
312
313 char *
314 AccessibleApplication_getToolkitName (AccessibleApplication *obj)
315 {
316   return Accessibility_Application__get_toolkitName (*obj, &ev);
317 }
318
319 char *
320 AccessibleApplication_getVersion (AccessibleApplication *obj)
321 {
322   return Accessibility_Application__get_version (*obj, &ev);
323 }
324
325 long
326 AccessibleApplication_getID (AccessibleApplication *obj)
327 {
328   return Accessibility_Application__get_id (*obj, &ev);
329 }
330
331 /* Not Yet Implemented */
332 boolean
333 AccessibleApplication_pause (AccessibleApplication *obj)
334 {
335   return FALSE;
336 }
337
338 /* Not Yet Implemented */
339 boolean
340 AccessibleApplication_resume (AccessibleApplication *obj)
341 {
342   return FALSE;
343 }
344
345 /*
346  *
347  * AccessibleComponent function implementations
348  *
349  */
350
351 int
352 AccessibleComponent_ref (AccessibleComponent *obj)
353 {
354   Accessibility_Component_ref (*obj, &ev);
355   return 0;
356 }
357
358 int
359 AccessibleComponent_unref (AccessibleComponent *obj)
360 {
361   Accessibility_Component_unref (*obj, &ev);
362   return 0;
363 }
364
365 boolean
366 AccessibleComponent_contains (AccessibleComponent *obj,
367                               long x,
368                               long y,
369                               AccessibleCoordType ctype)
370 {
371   return Accessibility_Component_contains (*obj,
372                                            (CORBA_long) x,
373                                            (CORBA_long) y,
374                                            ctype,
375                                            &ev);
376 }
377
378 Accessible *
379 AccessibleComponent_getAccessibleAtPoint (AccessibleComponent *obj,
380                                           long x,
381                                           long y,
382                                           AccessibleCoordType ctype)
383 {
384   Accessible child;
385   child = Accessibility_Component_getAccessibleAtPoint(*obj,
386                                                        (CORBA_long) x,
387                                                        (CORBA_long) y,
388                                                        ctype,
389                                                        &ev);
390   return (child != NULL) ? Obj_Add (child) : NULL;
391 }
392
393 void
394 AccessibleComponent_getExtents (AccessibleComponent *obj,
395                                 long *x,
396                                 long *y,
397                                 long *width,
398                                 long *height,
399                                 AccessibleCoordType ctype)
400 {
401   /* TODO: remove assumption that CORBA_long == long in typecast */
402   Accessibility_Component_getExtents (*obj,
403                                      (CORBA_long *) x,
404                                      (CORBA_long *) y,
405                                      (CORBA_long *) width,
406                                      (CORBA_long *) height,
407                                      ctype,
408                                      &ev);
409 }
410
411 void
412 AccessibleComponent_getPosition (AccessibleComponent *obj,
413                                  long *x,
414                                  long *y,
415                                  AccessibleCoordType ctype)
416 {
417   Accessibility_Component_getPosition (*obj,
418                                        (CORBA_long *) x,
419                                        (CORBA_long *) y,
420                                        ctype,
421                                        &ev);
422 }
423
424 void
425 AccessibleComponent_getSize (AccessibleComponent *obj,
426                              long *width,
427                              long *height)
428 {
429   Accessibility_Component_getSize (*obj,
430                                    (CORBA_long *) width,
431                                    (CORBA_long *) height,
432                                    &ev);
433 }
434
435 /* Not Yet Implemented */
436 void
437 AccessibleComponent_grabFocus (AccessibleComponent *obj)
438 {
439   ;
440 }