"Unfixed" some things :-). cleaned up and made some of the namespace changes more...
[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 event type.
15  * @callback: a character string indicating the type of events for which
16  *            notification is requested.  Format is
17  *            EventClass:major_type:minor_type:detail
18  *            where all subfields other than EventClass are optional.
19  *            EventClasses include "Focus", "Window", "Mouse",
20  *            and toolkit events (e.g. "Gtk", "AWT").
21  *            Examples: "focus:", "Gtk:GtkWidget:button_press_event".
22  *
23  * NOTE: this string may be UTF-8, but should not contain byte value 56 (ascii ':'),
24  *            except as a delimiter, since non-UTF-8 string delimiting
25  *            functions are used internally.  In general, listening to
26  *            toolkit-specific events is not recommended.
27  *
28  * Add an in-process callback function to an existing AccessibleEventListener.
29  *
30  * Returns: #TRUE if successful, otherwise #FALSE.
31  *
32  **/
33 boolean
34 registerGlobalEventListener (AccessibleEventListener *listener,
35                              char *eventType)
36 {
37   Accessibility_Registry_registerGlobalEventListener (
38                          registry,
39                          (Accessibility_EventListener)
40                             bonobo_object_corba_objref (bonobo_object (listener)),
41                          eventType,
42                          &ev);
43
44   if (ev._major != CORBA_NO_EXCEPTION)
45     {
46     return FALSE;
47     }
48   else
49     {
50       return TRUE;
51     }
52 }
53
54 /**
55  * deregisterGlobalEventListener:
56  * @listener: the #AccessibleEventListener to be registered against an event type.
57  *
58  * deregisters an AccessibleEventListener from the registry, for all event types it may be listening to.
59  *
60  * Returns: #TRUE if successful, otherwise #FALSE.
61  *
62  **/
63 boolean
64 deregisterGlobalEventListenerAll (AccessibleEventListener *listener)
65 {
66   Accessibility_Registry_deregisterGlobalEventListenerAll (
67                          registry,
68                          (Accessibility_EventListener)
69                             CORBA_Object_duplicate (bonobo_object_corba_objref (bonobo_object (listener)), &ev),
70                          &ev);
71
72   if (ev._major != CORBA_NO_EXCEPTION)
73     {
74     return FALSE;
75     }
76   else
77     {
78       return TRUE;
79     }
80 }
81
82 /**
83  * getDesktopCount:
84  *
85  * Get the number of virtual desktops.
86  * NOTE: currently multiple virtual desktops are not implemented, this
87  *       function always returns '1'.
88  *
89  * Returns: an integer indicating the number of active virtual desktops.
90  *
91  **/
92 int
93 getDesktopCount ()
94 {
95   return Accessibility_Registry_getDesktopCount (registry, &ev);
96 }
97
98 /**
99  * getDesktop:
100  * @i: an integer indicating which of the accessible desktops is to be returned.
101  *
102  * Get the virtual desktop indicated by index @i.
103  * NOTE: currently multiple virtual desktops are not implemented, this
104  *       function always returns '1'.
105  *
106  * Returns: a pointer to the 'i-th' virtual desktop's #Accessible representation.
107  *
108  **/
109 Accessible*
110 getDesktop (int n)
111 {
112   return Obj_Add (Accessibility_Registry_getDesktop (registry, (CORBA_short) n, &ev));
113 }
114
115 /**
116  * getDesktopList:
117  * @list: a pointer to an array of #Accessible objects.
118  *
119  * Get the list of virtual desktops.  On return, @list will point
120  *     to a newly-created array of virtual desktop pointers.
121  *     It is the responsibility of the caller to free this array when
122  *     it is no longer needed.
123  *
124  * Not Yet Implemented.
125  *
126  * Returns: an integer indicating how many virtual desktops have been
127  *          placed in the list pointed to by parameter @list.
128  **/
129 int
130 getDesktopList (Accessible **list)
131 {
132   *list = NULL;
133   return 0;
134 }
135
136 static gboolean
137 key_event_source_func (void *p)
138 {
139   GList *listeners = (GList *)p;
140   XEvent *x_event = g_new0 (XEvent, 1);
141   while (XPending (display))
142     {
143       XNextEvent (display, x_event);
144       while (listeners)
145         {
146         /* if the listener mask matches, notify it*/
147           if (1)
148             {
149               ;   
150             }
151         }
152     }
153   return TRUE;
154 }
155
156 /**
157  * registerAccessibleKeystrokeListener:
158  * @listener: a pointer to the #AccessibleKeystrokeListener for which
159  *            keystroke events are requested.
160  *
161  **/
162 void
163 registerAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
164                                      AccessibleKeySet *keys,
165                                      AccessibleKeyMaskType modmask,
166                                      AccessibleKeyEventMask eventmask,
167                                      AccessibleKeyListenerSyncType sync_type)
168 {
169   Accessibility_ControllerEventMask *controller_event_mask =
170           Accessibility_ControllerEventMask__alloc();
171   Accessibility_DeviceEventController device_event_controller = 
172           Accessibility_Registry_getDeviceEventController (registry, &ev);
173   Accessibility_KeySet *all_keys = Accessibility_KeySet__alloc();
174   Accessibility_KeyEventTypeSeq *key_events = Accessibility_KeyEventTypeSeq__alloc();
175   Accessibility_KeystrokeListener spi_listener_corba_ref;
176   Accessibility_DeviceEventController_ref (device_event_controller, &ev);
177   controller_event_mask->value = (CORBA_unsigned_long) modmask;
178   controller_event_mask->refcount = (CORBA_unsigned_short) 1;
179
180   spi_listener_corba_ref = (Accessibility_KeystrokeListener)
181           CORBA_Object_duplicate (bonobo_object_corba_objref (bonobo_object (listener)), &ev);
182   
183           Accessibility_DeviceEventController_registerKeystrokeListener (
184           device_event_controller,
185           spi_listener_corba_ref,
186           all_keys,
187           controller_event_mask,
188           key_events,
189           (CORBA_boolean) ((sync_type | SPI_KEYLISTENER_ALL_WINDOWS)!=0),
190           &ev);
191 }
192
193 /**
194  * deregisterAccessibleKeystrokeListener:
195  * @listener: a pointer to the #AccessibleKeystrokeListener for which
196  *            keystroke events are requested.
197  *
198  **/
199 void
200 deregisterAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener, AccessibleKeyMaskType keymask)
201 {
202   Accessibility_ControllerEventMask *controller_event_mask =
203           Accessibility_ControllerEventMask__alloc();
204   Accessibility_DeviceEventController device_event_controller = 
205           Accessibility_Registry_getDeviceEventController (registry, &ev);
206   Accessibility_KeySet *all_keys = Accessibility_KeySet__alloc();
207   Accessibility_KeyEventTypeSeq *key_events = Accessibility_KeyEventTypeSeq__alloc();
208   Accessibility_KeystrokeListener spi_listener_corba_ref;
209   Accessibility_DeviceEventController_unref (device_event_controller, &ev);
210   controller_event_mask->value = (CORBA_unsigned_long) keymask;
211   controller_event_mask->refcount = (CORBA_unsigned_short) 1;
212
213   spi_listener_corba_ref = (Accessibility_KeystrokeListener)
214           CORBA_Object_duplicate (bonobo_object_corba_objref (bonobo_object (listener)), &ev);
215   
216   Accessibility_DeviceEventController_deregisterKeystrokeListener (
217           device_event_controller,
218           spi_listener_corba_ref,
219           all_keys,
220           controller_event_mask,
221           key_events,
222           (CORBA_boolean) TRUE,
223           &ev);
224 }
225
226 /**
227  * generateKeyEvent:
228  * @keycode: a #long indicating the keycode of the key event
229  *           being synthesized.
230  * @meta: a #long indicating the key modifiers to be sent
231  *        with the event, if any.
232  *
233  * Synthesize a keyboard event (as if a hardware keyboard event occurred in the
234  * current UI context).
235  * Not Yet Implemented.
236  *
237  **/
238 void
239 generateKeyEvent (long keyval, AccessibleKeySynthType type)
240 {
241 /* TODO: check current modifier status and
242  *  send keycode to alter, if necessary
243  */
244   Accessibility_DeviceEventController device_event_controller = 
245           Accessibility_Registry_getDeviceEventController (registry, &ev);
246   Accessibility_DeviceEventController_generateKeyEvent (device_event_controller,
247                                                         keyval,
248                                                         (unsigned long) type,
249                                                         &ev);
250 }
251
252 /**
253  * generateMouseEvent:
254  * @x: a #long indicating the screen x coordinate of the mouse event.
255  * @y: a #long indicating the screen y coordinate of the mouse event.
256  * @name: a string indicating which mouse event to be synthesized
257  *        (e.g. "button1", "button2", "mousemove").
258  *
259  * Synthesize a mouse event at a specific screen coordinate.
260  * Not Yet Implemented.
261  *
262  **/
263 void
264 generateMouseEvent (long x, long y, char *name)
265 {
266   ;
267 }
268