*** empty log message ***
[platform/core/uifw/at-spi2-atk.git] / cspi / spi_event.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002, 2003 Sun Microsystems Inc.,
6  * Copyright 2001, 2002, 2003 Ximian, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include <cspi/spi-private.h>
25 #include <cspi/bonobo/cspi-bonobo-listener.h>
26
27 static GSList *_cspi_event_queue = NULL;
28
29 /**
30  * SPI_freeAccessibleKeySet:
31  * @keyset: An AccessibleKeyset to free.
32  *
33  * Release the memory used by an AccessibleKeySet.
34  *
35  **/
36 void
37 SPI_freeAccessibleKeySet (AccessibleKeySet *keyset)
38 {
39   int i = 0;    
40   g_free (keyset->keysyms);
41   g_free (keyset->keycodes);
42   while (keyset->keystrings [i])
43     {
44       g_free (keyset->keystrings [i++]);
45     }
46   g_free (keyset->keystrings);
47   g_free (keyset);
48 }
49
50 /**
51  * SPI_createAccessibleKeySet:
52  * @len: the number of key values in the key set.
53  * @keysyms: a UTF-8 string containing symbolic key values to be matched, or NULL if
54  *           matching is performed against other key values instead.
55  * @keycodes: an array of unsigned short values which are the hardware keycodes
56  *           to be matched, or NULL if the keyset is specified solely by keysyms
57  *           and/or keystrings.
58  * @keystrings: an array of null-terminated character strings which specify key
59  *             name values to match, or NULL if the keyset is specified solely by
60  *             keycodes and/or keysyms.
61  *
62  * Create a new #AccessibleKeySet of a specified length.
63  * A KeySet is used typically to match key event values, and a matches are made
64  * using the following criteria: a match exists with a key event if all non-null
65  * i-th members of the keyset match the key event.
66  * If both keystring and keysym values are NULL, a keycode value match is
67  * forced, thus the match for keysym=0, keycode=0, keystring=NULL is
68  * keycode 0.
69  *
70  * Returns: a pointer to a newly-created #AccessibleKeySet.
71  *
72  **/
73 AccessibleKeySet *
74 SPI_createAccessibleKeySet (int len, const char *keysyms, short *keycodes,
75                             const char **keystrings)
76 {
77   AccessibleKeySet *keyset = g_new0 (AccessibleKeySet, 1);
78   int i, keysym_len = 0;
79   const char *keysym_ptr = keysyms;
80   keyset->len = len;
81   keyset->keysyms = g_new0 (unsigned long, len);
82   keyset->keycodes = g_new0 (unsigned short, len);
83   keyset->keystrings = g_new0 (char *, len);
84   if (keysyms)
85     {
86       keysym_len = g_utf8_strlen (keysyms, -1);
87     }
88   for (i = 0; i < len; ++i)
89     {
90       if (i < keysym_len)
91         {
92           keyset->keysyms [i] = (unsigned long) g_utf8_get_char (keysym_ptr);
93           keysym_ptr = g_utf8_find_next_char (keysym_ptr, NULL);
94         }
95       else
96         {
97           keyset->keysyms [i] = 0;
98         }
99       if (keycodes)
100         {
101           keyset->keycodes [i] = keycodes [i];
102         }
103       if (keystrings)
104         {
105           keyset->keystrings [i] = g_strdup (keystrings [i]);
106         }
107     }
108   return keyset;        
109 }
110
111 /**
112  * SPI_createAccessibleEventListener:
113  * @callback : an #AccessibleEventListenerCB callback function, or NULL.
114  * @user_data: a pointer to data which will be passed to the callback when invoked.
115  *
116  * Create a new #AccessibleEventListener with a specified (in-process) callback function.
117  *
118  * Returns: a pointer to a newly-created #AccessibleEventListener.
119  *
120  **/
121 AccessibleEventListener *
122 SPI_createAccessibleEventListener (AccessibleEventListenerCB callback,
123                                    void                     *user_data)
124 {
125   AccessibleEventListener *listener = cspi_event_listener_new ();
126   if (callback)
127     {
128       AccessibleEventListener_addCallback (listener, callback, user_data);
129     }
130   return listener;
131 }
132
133 /**
134  * AccessibleEventListener_addCallback:
135  * @listener: the #AccessibleEventListener instance to modify.
136  * @callback: an #AccessibleEventListenerCB function pointer.
137  * @user_data: a pointer to data which will be passed to the callback when invoked.
138  *
139  * Add an in-process callback function to an existing AccessibleEventListener.
140  * Note that the callback function must live in the same address
141  * space as the AccessibleEventListener implementation code, thus one should not
142  * use this function to attach callbacks to a 'remote' event listener
143  * (that is, one that was not created by a client call to
144  * createAccessibleEventListener ();
145  *
146  * Returns: #TRUE if successful, otherwise #FALSE.
147  *
148  **/
149 SPIBoolean
150 AccessibleEventListener_addCallback (AccessibleEventListener *listener,
151                                      AccessibleEventListenerCB callback,
152                                      void                     *user_data)
153 {
154   cspi_event_listener_add_cb (listener, callback, user_data);
155   return TRUE;
156 }
157
158 /**
159  * AccessibleEventListener_unref:
160  * @listener: a pointer to the #AccessibleEventListener being operated on.
161  *
162  * Decrements an #AccessibleEventListener's reference count.
163  **/
164 void
165 AccessibleEventListener_unref (AccessibleEventListener *listener)
166 {
167   cspi_event_listener_unref (listener);
168 }
169
170 /**
171  * AccessibleEventListener_removeCallback:
172  * @listener: the #AccessibleEventListener instance to modify.
173  * @callback: an #AccessibleEventListenerCB function pointer.
174  *
175  * Remove an in-process callback function from an existing AccessibleEventListener.
176  *
177  * Returns: #TRUE if successful, otherwise #FALSE.
178  *
179  **/
180 SPIBoolean
181 AccessibleEventListener_removeCallback (AccessibleEventListener  *listener,
182                                         AccessibleEventListenerCB callback)
183 {
184   cspi_event_listener_remove_cb (listener, callback);
185   return TRUE;
186 }
187
188 /**
189  * SPI_createAccessibleKeystrokeListener:
190  * @callback : an #AccessibleKeystrokeListenerCB callback function, or NULL.
191  * @user_data: a pointer to data which will be passed to the callback when invoked.
192  *
193  * Create a new #AccessibleKeystrokeListener with a specified callback function.
194  *
195  * Returns: a pointer to a newly-created #AccessibleKeystrokeListener.
196  *
197  **/
198 AccessibleKeystrokeListener *
199 SPI_createAccessibleKeystrokeListener (AccessibleKeystrokeListenerCB callback,
200                                        void                         *user_data)
201 {
202   AccessibleDeviceListener *listener = cspi_device_listener_new ();
203   if (callback)
204     {
205       AccessibleDeviceListener_addCallback (listener, callback, user_data);
206     }
207   return listener;
208 }
209
210 /**
211  * AccessibleKeystrokeListener_addCallback:
212  * @listener: the #AccessibleKeystrokeListener instance to modify.
213  * @callback: an #AccessibleKeystrokeListenerCB function pointer.
214  * @user_data: a pointer to data which will be passed to the callback when invoked.
215  *
216  * Add an in-process callback function to an existing #AccessibleKeystrokeListener.
217  *
218  * Returns: #TRUE if successful, otherwise #FALSE.
219  *
220  **/
221 SPIBoolean
222 AccessibleKeystrokeListener_addCallback (AccessibleKeystrokeListener *listener,
223                                          AccessibleKeystrokeListenerCB callback,
224                                          void                         *user_data)
225 {
226   cspi_device_listener_add_cb (listener, callback, user_data);
227   return TRUE;
228 }
229
230 /**
231  * AccessibleKeystrokeListener_removeCallback:
232  * @listener: the #AccessibleKeystrokeListener instance to modify.
233  * @callback: an #AccessibleKeystrokeListenerCB function pointer.
234  *
235  * Remove an in-process callback function from an existing #AccessibleKeystrokeListener.
236  *
237  * Returns: #TRUE if successful, otherwise #FALSE.
238  *
239  **/
240 SPIBoolean
241 AccessibleKeystrokeListener_removeCallback (AccessibleKeystrokeListener *listener,
242                                             AccessibleKeystrokeListenerCB callback)
243 {
244   cspi_device_listener_remove_cb (listener, callback);
245   return TRUE;
246 }
247
248 /**
249  * AccessibleKeystrokeListener_unref:
250  * @listener: a pointer to the #AccessibleKeystrokeListener being operated on.
251  *
252  * Decrements an #AccessibleKeystrokeListener's reference count.
253  **/
254 void
255 AccessibleKeystrokeListener_unref (AccessibleKeystrokeListener *listener)
256 {
257   cspi_device_listener_unref (listener);
258 }
259
260 /**
261  * SPI_createAccessibleDeviceListener:
262  * @callback : an #AccessibleDeviceListenerCB callback function, or NULL.
263  * @user_data: a pointer to data which will be passed to the callback when invoked.
264  *
265  * Create a new #AccessibleDeviceListener with a specified callback function.
266  *
267  * Returns: a pointer to a newly-created #AccessibleDeviceListener.
268  *
269  **/
270 AccessibleDeviceListener *
271 SPI_createAccessibleDeviceListener (AccessibleDeviceListenerCB callback,
272                                        void                         *user_data)
273 {
274   AccessibleDeviceListener *listener = cspi_device_listener_new ();
275   if (callback)
276     {
277       AccessibleDeviceListener_addCallback (listener, callback, user_data);
278     }
279   return listener;
280 }
281
282 /**
283  * AccessibleDeviceListener_addCallback:
284  * @listener: the #AccessibleDeviceListener instance to modify.
285  * @callback: an #AccessibleDeviceListenerCB function pointer.
286  * @user_data: a pointer to data which will be passed to the callback when invoked.
287  *
288  * Add an in-process callback function to an existing #AccessibleDeviceListener.
289  *
290  * Returns: #TRUE if successful, otherwise #FALSE.
291  *
292  **/
293 SPIBoolean
294 AccessibleDeviceListener_addCallback (AccessibleDeviceListener *listener,
295                                          AccessibleDeviceListenerCB callback,
296                                          void                         *user_data)
297 {
298   cspi_device_listener_add_cb (listener, callback, user_data);
299   return TRUE;
300 }
301
302 /**
303  * AccessibleDeviceListener_removeCallback:
304  * @listener: the #AccessibleDeviceListener instance to modify.
305  * @callback: an #AccessibleDeviceListenerCB function pointer.
306  *
307  * Remove an in-process callback function from an existing #AccessibleDeviceListener.
308  *
309  * Returns: #TRUE if successful, otherwise #FALSE.
310  *
311  **/
312 SPIBoolean
313 AccessibleDeviceListener_removeCallback (AccessibleDeviceListener *listener,
314                                             AccessibleDeviceListenerCB callback)
315 {
316   cspi_device_listener_remove_cb (listener, callback);
317   return TRUE;
318 }
319
320 /**
321  * AccessibleDeviceListener_unref:
322  * @listener: a pointer to the #AccessibleDeviceListener being operated on.
323  *
324  * Decrements an #AccessibleDeviceListener's reference count.
325  **/
326 void
327 AccessibleDeviceListener_unref (AccessibleDeviceListener *listener)
328 {
329   cspi_device_listener_unref (listener);
330 }
331
332 static char *
333 cspi_internal_event_get_text (const InternalEvent *e)
334 {
335   CORBA_any *any;
336   g_return_val_if_fail (e, NULL);
337   g_return_val_if_fail (e->data, NULL);
338   any = (CORBA_any *) e->data;
339   if (CORBA_TypeCode_equivalent (any->_type, TC_CORBA_string, NULL)) 
340     {
341       return CORBA_string_dup (* (char **) any->_value);
342     } 
343   else
344     {
345 #ifdef EVENT_CONTEXT_DEBUG
346       fprintf (stderr, "requested string, TC is not TC_CORBA_string! (%u)\n",
347                (unsigned) any->_type);
348 #endif
349       return NULL;
350     }
351 }
352
353 static Accessible *
354 cspi_internal_event_get_object (const InternalEvent *e)
355 {
356   CORBA_any *any;
357
358   g_return_val_if_fail (e, NULL);
359   g_return_val_if_fail (e->data, NULL);
360
361   any = (CORBA_any *) e->data;
362   if (CORBA_TypeCode_equal (any->_type, TC_CORBA_Object, cspi_ev()))
363     return cspi_object_take (* (CORBA_Object *) any->_value);
364   else 
365     return NULL;
366 }
367
368 static SPIRect *
369 cspi_internal_event_get_rect (const InternalEvent *e)
370 {
371   CORBA_any *any;
372   g_return_val_if_fail (e, NULL);
373   g_return_val_if_fail (e->data, NULL);
374   any = (CORBA_any *) e->data;
375   if (CORBA_TypeCode_equivalent (any->_type, TC_Accessibility_BoundingBox, NULL)) 
376     {
377       SPIRect *rect = g_new (SPIRect, 1);
378       Accessibility_BoundingBox *bounds = (Accessibility_BoundingBox *) any->_value;
379       rect->x = bounds->x;
380       rect->y = bounds->y;
381       rect->width = bounds->width;
382       rect->height = bounds->height;
383       return rect;
384     } 
385   else
386     {
387 #ifdef EVENT_CONTEXT_DEBUG
388       fprintf (stderr, "requested string, TC is not TC_Accessible_RectBounds! (%u)\n",
389                (unsigned) any->_type);
390 #endif
391       return NULL;
392     }
393 }
394
395 /**
396  * AccessibleTextChangedEvent_getChangeString:
397  * @e: a pointer to the #AccessibleEvent being queried.
398  *
399  * Queries an #AccessibleEvent of type "object:text-changed", 
400  *         returning the text inserted or deleted.
401  *
402  * Returns: a UTF-8 text string indicating the text inserted,
403  *          deleted, or substituted by this event.
404  **/
405 char *
406 AccessibleTextChangedEvent_getChangeString (const AccessibleEvent *e)
407 {
408   const InternalEvent *foo = (InternalEvent *) e;
409   /* TODO: check the event type. */
410   return cspi_internal_event_get_text (foo);
411 }
412
413 /**
414  * AccessibleTextSelectionChangedEvent_getSelectionString:
415  * @e: a pointer to the #AccessibleEvent being queried.
416  *
417  * Queries an #AccessibleEvent of type "object:text-selection-changed", 
418  *         returning the newly added, removed, or modified selection string.
419  *
420  * Returns: a UTF-8 text string indicating the recently changed selection.
421  **/
422 char *
423 AccessibleTextSelectionChangedEvent_getSelectionString (const AccessibleEvent *e)
424 {
425   const InternalEvent *foo = (InternalEvent *) e;
426   /* TODO: check the event type. */
427   return cspi_internal_event_get_text (foo);
428 }
429
430 /**
431  * AccessibleWindowEvent_getTitleString:
432  * @e: a pointer to the #AccessibleEvent being queried.
433  *
434  * Queries an #AccessibleEvent of type "window:", 
435  *         returning the window title.
436  *
437  * Returns: a UTF-8 text string representing the title of the 
438  *         recently changed window.
439  **/
440 char *
441 AccessibleWindowEvent_getTitleString (const AccessibleEvent *e)
442 {
443   const InternalEvent *foo = (InternalEvent *) e;
444   /* TODO: check the event type. */
445   return cspi_internal_event_get_text (foo);
446 }
447
448 /**
449  * AccessibleChildChangedEvent_getChildAccessible:
450  * @e: a pointer to the #AccessibleEvent being queried.
451  *
452  * Queries an #AccessibleEvent of type "object:children_changed"
453  *         to get a reference to the changed #Accessible.
454  *         Note that context #Accessibles are not guaranteed to outlive
455  *         event delivery, in which case this call may return %NULL
456  *         even if the object existed at the time of dispatch.
457  *
458  * Returns: the context #Accessible for the event, or %NULL if
459  *          there is no longer a valid context #Accessible 
460  *          object for the event.
461  **/
462 Accessible *
463 AccessibleChildChangedEvent_getChildAccessible (const AccessibleEvent *e)
464 {
465   const InternalEvent *foo = (InternalEvent *) e;
466   return (Accessible *) cspi_internal_event_get_object (foo);
467 }
468
469 /**
470  * AccessibleParentChangedEvent_getParentAccessible:
471  * @e: a pointer to the #AccessibleEvent being queried.
472  *
473  * Queries an #AccessibleEvent of type "object:property-change:accessible-parent"
474  *         to get a reference to the changed #Accessible.
475  *         Note that context #Accessibles are not guaranteed to outlive
476  *         event delivery, in which case this call may return %NULL
477  *         even if the object existed at the time of dispatch.
478  *
479  * Returns: an #Accessible pointer representing the new parent object.
480  **/
481 Accessible *
482 AccessibleParentChangedEvent_getParentAccessible (const AccessibleEvent *e)
483 {
484   const InternalEvent *foo = (InternalEvent *) e;
485   return (Accessible *) cspi_internal_event_get_object (foo);
486 }
487
488 /**
489  * AccessibleActiveDescendantChangedEvent_getActiveDescendant:
490  * @e: a pointer to the #AccessibleEvent being queried.
491  *
492  * Queries an #AccessibleEvent of type "object:active-descendant-changed"
493  *         to get a reference to the changed #Accessible.
494  *         Note that context #Accessibles are not guaranteed to outlive
495  *         event delivery, in which case this call may return %NULL
496  *         even if the object existed at the time of dispatch.
497  *
498  * Returns: an #Accessible pointer representing the new active descendant.
499  **/
500 Accessible *
501 AccessibleActiveDescendantChangedEvent_getActiveDescendant (const AccessibleEvent *e) 
502 {
503   const InternalEvent *foo = (InternalEvent *) e;
504   return (Accessible *) cspi_internal_event_get_object (foo);
505 }
506
507 /**
508  * AccessibleTableSummaryChangedEvent_getSummaryAccessible:
509  * @e: a pointer to the #AccessibleEvent being queried.
510  *
511  * Queries an #AccessibleEvent of type "object:property-changed:accessible-table-summary"
512  *         to get a reference to the changed #Accessible.
513  *         Note that context #Accessibles are not guaranteed to outlive
514  *         event delivery, in which case this call may return %NULL
515  *         even if the object existed at the time of dispatch.
516  *
517  * Returns: an #Accessible pointer representing the new table summary.
518  **/
519 Accessible *
520 AccessibleTableSummaryChangedEvent_getSummaryAccessible (const AccessibleEvent *e) 
521 {
522   const InternalEvent *foo = (InternalEvent *) e;
523   return (Accessible *) cspi_internal_event_get_object (foo);
524 }
525
526 /**
527  * AccessibleTableHeaderChangedEvent_getHeaderAccessible:
528  * @e: a pointer to the #AccessibleEvent being queried.
529  *
530  * Queries an #AccessibleEvent of type 
531  *         "object:property-changed:accessible-table-row-header" or
532  *         "object:property-changed:accessible-table-column-header"
533  *         to get a reference to the changed #Accessible.
534  *         Note that context #Accessibles are not guaranteed to outlive
535  *         event delivery, in which case this call may return %NULL
536  *         even if the object existed at the time of dispatch.
537  *
538  * Returns: an #Accessible pointer representing the new table header.
539  **/
540 Accessible *
541 AccessibleTableHeaderChangedEvent_getHeaderAccessible (const AccessibleEvent *e)
542 {
543   const InternalEvent *foo = (InternalEvent *) e;
544   return (Accessible *) cspi_internal_event_get_object (foo);
545 }
546
547
548 /**
549  * AccessibleTableCaptionChangedEvent_getCaptionString:
550  * @e: a pointer to the #AccessibleEvent being queried.
551  *
552  * Queries an #AccessibleEvent of type 
553  *         "object:property-changed:accessible-table-caption-object" 
554  *         returning the text in the caption, if present.
555  *
556  * Returns: a UTF-8 text string indicating the text in the caption.
557  **/
558 char *
559 AccessibleTableCaptionChangedEvent_getCaptionString (const AccessibleEvent *e)
560 {
561   const InternalEvent *foo = (InternalEvent *) e;
562   /* TODO: check the event type. */
563   return cspi_internal_event_get_text (foo);
564 }
565
566 /**
567  * AccessibleTableRowDescriptionChangedEvent_getDescriptionString:
568  * @e: a pointer to the #AccessibleEvent being queried.
569  *
570  * Queries an #AccessibleEvent of type 
571  *         "object:property-changed:accessible-table-row-description" 
572  *         returning the new table row description.
573  *
574  * Returns: a UTF-8 text string representing the recently changed
575  *         table row description 
576  **/
577 char *
578 AccessibleTableRowDescriptionChangedEvent_getDescriptionString (const AccessibleEvent *e)
579 {
580   const InternalEvent *foo = (InternalEvent *) e;
581   /* TODO: check the event type. */
582   return cspi_internal_event_get_text (foo);
583 }
584
585 /**
586  * AccessibleTableColumnDescriptionChangedEvent_getDescriptionString:
587  * @e: a pointer to the #AccessibleEvent being queried.
588  *
589  * Queries an #AccessibleEvent of type 
590  *         "object:property-changed:accessible-table-column-description" 
591  *         returning the new table column description.
592  *
593  * Returns: a UTF-8 text string representing the recently changed
594  *         table column description 
595  **/
596 char *
597 AccessibleTableColumnDescriptionChangedEvent_getDescriptionString (const AccessibleEvent *e)
598 {
599   const InternalEvent *foo = (InternalEvent *) e;
600   /* TODO: check the event type. */
601   return cspi_internal_event_get_text (foo);
602 }
603
604 /**
605  * AccessibleDescriptionChangedEvent_getDescriptionString:
606  * @e: a pointer to the #AccessibleEvent being queried.
607  *
608  * Queries an #AccessibleEvent of type 
609  *         "object:property-changed:accessible-description" 
610  *         returning the new description.
611  *
612  * Returns: a UTF-8 text string representing the recently changed
613  *         description 
614  **/
615 char *
616 AccessibleDescriptionChangedEvent_getDescriptionString (const AccessibleEvent *e)
617 {
618   const InternalEvent *foo = (InternalEvent *) e;
619   /* TODO: check the event type. */
620   return cspi_internal_event_get_text (foo);
621 }
622
623 /**
624  * AccessibleBoundsChangedEvent_getNewBounds:
625  * @e: a pointer to the #AccessibleEvent being queried.
626  *
627  * Queries an #AccessibleEvent of type "object:bounds-changed", 
628  *         returning a pointer to an SPIRect structure containing the
629  *         new bounds, or NULL on error.
630  *         The returned structure should be freed with SPI_freeRect when 
631  *         the caller has finished referencing it.
632  *
633  * Returns: a pointer to an SPIRect defining the new object bounds.
634  **/
635 SPIRect *
636 AccessibleBoundsChangedEvent_getNewBounds (const AccessibleEvent *e)
637 {
638   const InternalEvent *foo = (InternalEvent *) e;
639   /* TODO: check the event type. */
640   return cspi_internal_event_get_rect (foo);
641 }
642
643 static gint
644 cspi_event_compare (gconstpointer p1, gconstpointer p2)
645 {
646   const InternalEvent *e1 = p1, *e2 = p2;
647   return (gint) ((long) e2->id  - (long) e1->id);
648 }
649
650 static InternalEvent *
651 cspi_internal_event_lookup (const InternalEvent *e)
652 {
653   InternalEvent *internal = NULL;
654   GSList *p =
655     g_slist_find_custom (_cspi_event_queue, e, cspi_event_compare);
656   if (p)
657     internal = p->data;
658   return internal;
659 }
660
661 static const InternalEvent *
662 cspi_internal_event_check (const AccessibleEvent *e)
663 {
664   InternalEvent *internal = (InternalEvent *) e;
665   if (internal->magic == SPI_INTERNAL_EVENT_MAGIC) 
666     return internal;
667   else
668     return NULL;
669 }
670
671 static InternalEvent *
672 cspi_internal_event_add (const InternalEvent *e)
673 {
674   _cspi_event_queue = g_slist_prepend (_cspi_event_queue, (gpointer) e);
675   return (InternalEvent *) e;
676 }
677
678 static void
679 cspi_internal_event_remove (const InternalEvent *e)
680 {
681   GSList *link = g_slist_find_custom (_cspi_event_queue, e, cspi_event_compare);
682   if (link)
683     _cspi_event_queue = g_slist_remove_link (_cspi_event_queue, link);
684 }
685
686 /**
687  * AccessibleNameChangedEvent_getNameString:
688  * @e: a pointer to the #AccessibleEvent being queried.
689  *
690  * Queries an #AccessibleEvent of type "object:property-change:accessible_name:", 
691  *         returning the name.
692  *
693  * Returns: a UTF-8 text string representing the name of the 
694  *         object which recently changed.
695  **/
696 char *
697 AccessibleNameChangedEvent_getNameString (const AccessibleEvent *e)
698 {
699   const InternalEvent *foo = (InternalEvent *) e;
700   return cspi_internal_event_get_text (foo);
701 }
702
703 /**
704  * AccessibleEvent_ref:
705  * @e: a pointer to the #AccessibleEvent being referenced.
706  *
707  * Increments by 1 the reference count of the event
708  *
709  * Returns: TRUE if the function succeeded; FALSE if the pointer is not a
710  *         valid event.
711  **/
712 SPIBoolean
713 AccessibleEvent_ref (const AccessibleEvent *e)
714 {
715   const InternalEvent *private = cspi_internal_event_check (e);
716   if (private)
717     {
718       InternalEvent *event = cspi_internal_event_lookup (private);
719       /* 
720        * put event in the cache if it's not there already, 
721        * and increment refcount 
722        */
723       if (!event)
724         {
725           event = cspi_internal_event_add (private);
726         }
727       event->ref_count++;
728       return TRUE;
729     }
730   else
731     return FALSE;
732 }
733
734 /**
735  * AccessibleEvent_unref:
736  * @e: a pointer to the #AccessibleEvent being referenced.
737  *
738  * Decrements by 1 the reference count of the event. The event is destroyed
739  * when the reference count recahes zero.
740  *
741  **/
742 void
743 AccessibleEvent_unref (const AccessibleEvent *e)
744 {
745   const InternalEvent *private = cspi_internal_event_check (e);
746   /* decrement refcount and remove if appropriate */
747   if (private)
748     {
749       InternalEvent *event = cspi_internal_event_lookup (private);
750       if (event) 
751         {
752           event->ref_count--;
753           if (event->ref_count < 1)
754             {
755               cspi_internal_event_remove (event);
756               g_free ((gpointer)e->type);
757               Accessible_unref (e->source);
758               CORBA_free (event->data);
759               g_free ((gpointer)e);
760             }
761         }
762     }
763 }