72f93142078c5413b4fcc17e87633fc012c98c43
[platform/core/uifw/at-spi2-atk.git] / cspi / spi_registry.c
1
2 /*
3  *
4  * Global functions serviced by the registry
5  *
6  */
7
8 /* static stuff used only by registry C bindings */
9 static GList *key_listeners = NULL;
10 static Display *display = NULL;
11
12 /**
13  * registerGlobalEventListener:
14  * @listener: the #AccessibleEventListener to be registered against an
15  *            event type.
16  * @eventType: a character string indicating the type of events for which
17  *            notification is requested.  Format is
18  *            EventClass:major_type:minor_type:detail
19  *            where all subfields other than EventClass are optional.
20  *            EventClasses include "Focus", "Window", "Mouse",
21  *            and toolkit events (e.g. "Gtk", "AWT").
22  *            Examples: "focus:", "Gtk:GtkWidget:button_press_event".
23  *
24  * NOTE: this string may be UTF-8, but should not contain byte value 56
25  *            (ascii ':'), except as a delimiter, since non-UTF-8 string
26  *            delimiting functions are used internally.
27  *            In general, listening to
28  *            toolkit-specific events is not recommended.
29  *
30  * Add an in-process callback function to an existing AccessibleEventListener.
31  *
32  * Returns: #TRUE if successful, otherwise #FALSE.
33  *
34  **/
35 boolean
36 registerGlobalEventListener (AccessibleEventListener *listener,
37                              char *eventType)
38 {
39   Accessibility_Registry_registerGlobalEventListener (
40                          registry,
41                          (Accessibility_EventListener)
42                             bonobo_object_corba_objref (bonobo_object (listener)),
43                          eventType,
44                          &ev);
45
46   if (ev._major != CORBA_NO_EXCEPTION)
47     {
48     return FALSE;
49     }
50   else
51     {
52       return TRUE;
53     }
54 }
55
56 /**
57  * deregisterGlobalEventListenerAll:
58  * @listener: the #AccessibleEventListener to be registered against
59  *            an event type.
60  *
61  * deregisters an AccessibleEventListener from the registry, for all
62  *            event types it may be listening to.
63  *
64  * Returns: #TRUE if successful, otherwise #FALSE.
65  *
66  **/
67 boolean
68 deregisterGlobalEventListenerAll (AccessibleEventListener *listener)
69 {
70   Accessibility_Registry_deregisterGlobalEventListenerAll (
71                          registry,
72                          (Accessibility_EventListener)
73                             CORBA_Object_duplicate (
74                                     bonobo_object_corba_objref (
75                                             bonobo_object (listener)), &ev),
76                          &ev);
77
78   if (ev._major != CORBA_NO_EXCEPTION)
79     {
80     return FALSE;
81     }
82   else
83     {
84       return TRUE;
85     }
86 }
87 /**
88  * deregisterGlobalEventListener:
89  * @listener: the #AccessibleEventListener registered against an event type.
90  * @eventType: a string specifying the event type for which this
91  *             listener is to be deregistered.
92  *
93  * deregisters an AccessibleEventListener from the registry, for a specific
94  *             event type.
95  *
96  * Returns: #TRUE if successful, otherwise #FALSE.
97  *
98  **/
99 boolean
100 deregisterGlobalEventListener (AccessibleEventListener *listener,
101                                char *eventType)
102 {
103   Accessibility_Registry_deregisterGlobalEventListener (
104           registry,
105           (Accessibility_EventListener)
106           CORBA_Object_duplicate (
107                   bonobo_object_corba_objref (bonobo_object (listener)), &ev),
108           (CORBA_char *) eventType,
109           &ev);
110
111   if (ev._major != CORBA_NO_EXCEPTION)
112     {
113     return FALSE;
114     }
115   else
116     {
117       return TRUE;
118     }
119 }
120
121 /**
122  * getDesktopCount:
123  *
124  * Get the number of virtual desktops.
125  * NOTE: currently multiple virtual desktops are not implemented, this
126  *       function always returns '1'.
127  *
128  * Returns: an integer indicating the number of active virtual desktops.
129  *
130  **/
131 int
132 getDesktopCount ()
133 {
134   return Accessibility_Registry_getDesktopCount (registry, &ev);
135 }
136
137 /**
138  * getDesktop:
139  * @i: an integer indicating which of the accessible desktops is to be returned.
140  *
141  * Get the virtual desktop indicated by index @i.
142  * NOTE: currently multiple virtual desktops are not implemented, this
143  *       function always returns '1'.
144  *
145  * Returns: a pointer to the 'i-th' virtual desktop's #Accessible representation.
146  *
147  **/
148 Accessible*
149 getDesktop (int i)
150 {
151   return Obj_Add (Accessibility_Registry_getDesktop (registry, (CORBA_short) i, &ev));
152 }
153
154 /**
155  * getDesktopList:
156  * @list: a pointer to an array of #Accessible objects.
157  *
158  * Get the list of virtual desktops.  On return, @list will point
159  *     to a newly-created array of virtual desktop pointers.
160  *     It is the responsibility of the caller to free this array when
161  *     it is no longer needed.
162  *
163  * Not Yet Implemented : this implementation always returns a single
164  * #Accessible desktop.
165  *
166  * Returns: an integer indicating how many virtual desktops have been
167  *          placed in the list pointed to by parameter @list.
168  **/
169 int
170 getDesktopList (Accessible **list)
171 {
172   *list = NULL;
173   return 0;
174 }
175
176 static gboolean
177 key_event_source_func (void *p)
178 {
179   GList *listeners = (GList *)p;
180   XEvent *x_event = g_new0 (XEvent, 1);
181   while (XPending (display))
182     {
183       XNextEvent (display, x_event);
184       while (listeners)
185         {
186         /* if the listener mask matches, notify it*/
187           if (1)
188             {
189               ;   
190             }
191         }
192     }
193   return TRUE;
194 }
195
196 /**
197  * registerAccessibleKeystrokeListener:
198  * @listener:  a pointer to the #AccessibleKeystrokeListener for which
199  *             keystroke events are requested.
200  * @keys:      a pointer to the #AccessibleKeySet indicating which
201  *             keystroke events are requested, or #SPI_KEYSET_ALL_KEYS.
202  * @modmask:   an #AccessibleKeyMaskType mask indicating which
203  *             key event modifiers must be set in combination with @keys,
204  *             events will only be reported for key events for which all
205  *             modifiers in @modmask are set.  If you wish to listen for
206  *             events with multiple modifier combinations you must call
207  *             registerAccessibleKeystrokeListener() once for each combination.
208  * @eventmask: an #AccessibleKeyMaskType mask indicating which
209  *             types of key events are requested (#SPI_KEY_PRESSED, etc.).
210  * @sync_type: a #AccessibleKeyListenerSyncType parameter indicating
211  *             the behavior of the notification/listener transaction.
212  *             
213  * Register a listener for keystroke events, either pre-emptively for
214  *             all windows (SPI_KEYLISTENER_ALL_WINDOWS), or
215  *             non-preemptively (SPI_KEYLISTENER_NOSYNC).
216  *             ( Other sync_type values may be available in the future.)
217  **/
218 void
219 registerAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
220                                      AccessibleKeySet *keys,
221                                      AccessibleKeyMaskType modmask,
222                                      AccessibleKeyEventMask eventmask,
223                                      AccessibleKeyListenerSyncType sync_type)
224 {
225   Accessibility_ControllerEventMask *controller_event_mask =
226           Accessibility_ControllerEventMask__alloc();
227   Accessibility_DeviceEventController device_event_controller = 
228           Accessibility_Registry_getDeviceEventController (registry, &ev);
229   Accessibility_KeySet *all_keys = Accessibility_KeySet__alloc();
230   Accessibility_KeyEventTypeSeq *key_events = Accessibility_KeyEventTypeSeq__alloc();
231   Accessibility_KeystrokeListener spi_listener_corba_ref;
232   Accessibility_DeviceEventController_ref (device_event_controller, &ev);
233   controller_event_mask->value = (CORBA_unsigned_long) modmask;
234   controller_event_mask->refcount = (CORBA_unsigned_short) 1;
235
236   spi_listener_corba_ref = (Accessibility_KeystrokeListener)
237           CORBA_Object_duplicate (bonobo_object_corba_objref (bonobo_object (listener)), &ev);
238   
239           Accessibility_DeviceEventController_registerKeystrokeListener (
240           device_event_controller,
241           spi_listener_corba_ref,
242           all_keys,
243           controller_event_mask,
244           key_events,
245           (CORBA_boolean) ((sync_type | SPI_KEYLISTENER_ALL_WINDOWS)!=0),
246           &ev);
247 }
248
249 /**
250  * deregisterAccessibleKeystrokeListener:
251  * @listener: a pointer to the #AccessibleKeystrokeListener for which
252  *            keystroke events are requested.
253  * @modmask:  the key modifier mask for which this listener is to be
254  *            'deregistered' (of type #AccessibleeyMaskType).
255  *
256  * Removes a keystroke event listener from the registry's listener queue,
257  *            ceasing notification of events with modifiers matching @modmask.
258  **/
259 void
260 deregisterAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
261                                        AccessibleKeyMaskType modmask)
262 {
263   Accessibility_ControllerEventMask *controller_event_mask =
264           Accessibility_ControllerEventMask__alloc();
265   Accessibility_DeviceEventController device_event_controller = 
266           Accessibility_Registry_getDeviceEventController (registry, &ev);
267   Accessibility_KeySet *all_keys = Accessibility_KeySet__alloc();
268   Accessibility_KeyEventTypeSeq *key_events = Accessibility_KeyEventTypeSeq__alloc();
269   Accessibility_KeystrokeListener spi_listener_corba_ref;
270   Accessibility_DeviceEventController_unref (device_event_controller, &ev);
271   controller_event_mask->value = (CORBA_unsigned_long) modmask;
272   controller_event_mask->refcount = (CORBA_unsigned_short) 1;
273
274   spi_listener_corba_ref = (Accessibility_KeystrokeListener)
275           CORBA_Object_duplicate (bonobo_object_corba_objref (bonobo_object (listener)), &ev);
276   
277   Accessibility_DeviceEventController_deregisterKeystrokeListener (
278           device_event_controller,
279           spi_listener_corba_ref,
280           all_keys,
281           controller_event_mask,
282           key_events,
283           (CORBA_boolean) TRUE,
284           &ev);
285 }
286
287 /**
288  * generateKeyEvent:
289  * @keyval: a long integer indicating the keycode or keysym of the key event
290  *           being synthesized.
291  * @synth_type: a #AccessibleKeySynthType flag indicating whether @keyval
292  *           is to be interpreted as a keysym rather than a keycode
293  *           (SPI_KEYSYM), or whether to synthesize
294  *           SPI_KEY_PRESS, SPI_KEY_RELEASE, or both (SPI_KEY_PRESSRELEASE).
295  *
296  * Synthesize a keyboard event (as if a hardware keyboard event occurred in the
297  * current UI context).
298  *
299  **/
300 void
301 generateKeyEvent (long int keyval, AccessibleKeySynthType synth_type)
302 {
303 /* TODO: check current modifier status and
304  *  send keycode to alter, if necessary
305  */
306   Accessibility_DeviceEventController device_event_controller = 
307           Accessibility_Registry_getDeviceEventController (registry, &ev);
308   Accessibility_DeviceEventController_generateKeyEvent (device_event_controller,
309                                                         keyval,
310                                                         (unsigned long) synth_type,
311                                                         &ev);
312 }
313
314 /**
315  * generateMouseEvent:
316  * @x: a #long indicating the screen x coordinate of the mouse event.
317  * @y: a #long indicating the screen y coordinate of the mouse event.
318  * @name: a string indicating which mouse event to be synthesized
319  *        (e.g. "button1", "button2", "mousemove").
320  *
321  * Synthesize a mouse event at a specific screen coordinate.
322  * Most AT clients should use the #AccessibleAction interface when
323  * tempted to generate mouse events, rather than this method.
324  * Not Yet Implemented.
325  *
326  **/
327 void
328 generateMouseEvent (long x, long y, char *name)
329 {
330   ;
331 }
332