Started fixing IDL docs.
[platform/core/uifw/at-spi2-atk.git] / libspi / eventlistener.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Sun Microsystems Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /* accessibleeventlistener.c: implementation of SpiListener.idl */
24
25 #include <config.h>
26 #ifdef SPI_DEBUG
27 #include <stdio.h>
28 #endif
29 #include <libspi/accessibleeventlistener.h>
30
31 /* Our parent Gtk object type */
32 #define PARENT_TYPE SPI_LISTENER_TYPE
33
34 /* A pointer to our parent object class */
35 static SpiListenerClass *spi_event_listener_parent_class;
36
37 /*
38  * Implemented GObject::finalize
39  */
40 static void
41 spi_event_listener_object_finalize (GObject *object)
42 {
43 #ifdef SPI_DEBUG
44         fprintf(stderr, "spi_listener_object_finalize called\n");
45 #endif
46         ((GObjectClass *) spi_event_listener_parent_class)->finalize (object);
47 }
48
49 /*
50  * CORBA Accessibility::Listener::notifyEvent method implementation
51  */
52
53 static void
54 impl_accessible_event_notify_event (PortableServer_Servant     servant,
55                                     const Accessibility_Event *e,
56                                     CORBA_Environment         *ev)
57 {
58   int n;
59   int len;
60   VoidSpiEventListenerCB cb;
61   SpiEventListener *listener = SPI_ACCESSIBLE_EVENT_SPI_LISTENER (
62                                        bonobo_object_from_servant (servant));
63   len = g_list_length (listener->callbacks);
64
65   for (n=0; n<len; ++n)
66     {
67       cb =  (VoidSpiEventListenerCB) g_list_nth_data (listener->callbacks, n);
68       if (cb)
69         {
70           (*cb) (e);
71         }
72     }
73   /* Accessibility_Accessible_unref (e->source, ev); */
74 }
75
76 static void
77 spi_event_listener_class_init (SpiEventListenerClass *klass)
78 {
79         GObjectClass * object_class = (GObjectClass *) klass;
80         SpiListenerClass * spi_listener_class = (SpiListenerClass *) klass;
81         POA_Accessibility_EventListener__epv *epv = &spi_listener_class->epv;
82         spi_event_listener_parent_class = g_type_class_ref (SPI_LISTENER_TYPE);
83
84         object_class->finalize = spi_event_listener_object_finalize;
85
86         epv->notifyEvent = impl_accessible_event_notify_event;
87 }
88
89 static void
90 spi_event_listener_init (SpiEventListener *listener)
91 {
92         listener->callbacks = NULL;
93 }
94
95 BONOBO_TYPE_FUNC (SpiEventListener,
96                   PARENT_TYPE,
97                   spi_event_listener);
98
99 SpiEventListener *
100 spi_event_listener_new ()
101 {
102     SpiEventListener *retval = g_object_new (
103             SPI_ACCESSIBLE_EVENT_SPI_LISTENER_TYPE, NULL);
104     return retval;
105 }
106
107 void
108 spi_event_listener_add_callback (SpiEventListener *listener,
109                                  VoidSpiEventListenerCB callback)
110 {
111   listener->callbacks = g_list_append (listener->callbacks, callback);
112 }
113
114 void
115 spi_event_listener_remove_callback (SpiEventListener *listener,
116                                     VoidSpiEventListenerCB callback)
117 {
118   listener->callbacks = g_list_remove (listener->callbacks, callback);
119 }