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