Renamed "target" member of Event to "source".
[platform/core/uifw/at-spi2-atk.git] / libspi / accessibleeventlistener.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 /*
24  * accessibleeventlistener.c: bonobo implementation of Listener.idl,
25  *   with added ability to attach/remove in-process callbacks.
26  *
27  */
28
29 #ifdef SPI_DEBUG
30 #include <stdio.h>
31 #endif
32
33 #include <config.h>
34 #include <bonobo/Bonobo.h>
35 #include <libspi/Accessibility.h>
36
37 /*
38  * This pulls the definition for the BonoboObject (GType)
39  */
40 #include "accessibleeventlistener.h"
41
42 /*
43  * Our parent Gtk object type
44  */
45 #define PARENT_TYPE LISTENER_TYPE
46
47 /*
48  * A pointer to our parent object class
49  */
50 static ListenerClass *accessible_event_listener_parent_class;
51
52 /*
53  * Implemented GObject::finalize
54  */
55 static void
56 accessible_event_listener_object_finalize (GObject *object)
57 {
58 #ifdef SPI_DEBUG
59         fprintf(stderr, "listener_object_finalize called\n");
60 #endif
61         ((GObjectClass *) accessible_event_listener_parent_class)->finalize (object);
62 }
63
64 /*
65  * CORBA Accessibility::Listener::notifyEvent method implementation
66  */
67
68 static void
69 impl_accessible_event_notify_event (PortableServer_Servant     servant,
70                                     const Accessibility_Event *e,
71                                     CORBA_Environment         *ev)
72 {
73   int n;
74   int len;
75   VoidEventListenerCB cb;
76   AccessibleEventListener *listener = ACCESSIBLE_EVENT_LISTENER (
77                                        bonobo_object_from_servant (servant));
78   len = g_list_length (listener->callbacks);
79
80   for (n=0; n<len; ++n)
81     {
82       cb =  (VoidEventListenerCB) g_list_nth_data (listener->callbacks, n);
83       if (cb)
84         {
85           (*cb) (e);
86         }
87     }
88   bonobo_object_release_unref (e->source, ev);
89 }
90
91 static void
92 accessible_event_listener_class_init (AccessibleEventListenerClass *klass)
93 {
94         GObjectClass * object_class = (GObjectClass *) klass;
95         ListenerClass * listener_class = (ListenerClass *) klass;
96         POA_Accessibility_EventListener__epv *epv = &listener_class->epv;
97         accessible_event_listener_parent_class = g_type_class_ref (LISTENER_TYPE);
98
99         object_class->finalize = accessible_event_listener_object_finalize;
100
101         epv->notifyEvent = impl_accessible_event_notify_event;
102 }
103
104 static void
105 accessible_event_listener_init (Listener *listener)
106 {
107 }
108
109 GType
110 accessible_event_listener_get_type (void)
111 {
112         static GType type = 0;
113
114         if (!type) {
115                 static const GTypeInfo tinfo = {
116                         sizeof (AccessibleEventListenerClass),
117                         (GBaseInitFunc) NULL,
118                         (GBaseFinalizeFunc) NULL,
119                         (GClassInitFunc) accessible_event_listener_class_init,
120                         (GClassFinalizeFunc) NULL,
121                         NULL, /* class data */
122                         sizeof (Listener),
123                         0, /* n preallocs */
124                         (GInstanceInitFunc) accessible_event_listener_init,
125                         NULL /* value table */
126                 };
127                 /*
128                  *   Here we use bonobo_type_unique instead of
129                  * gtk_type_unique, this auto-generates a load of
130                  * CORBA structures for us. All derived types must
131                  * use bonobo_type_unique.
132                  */
133                 type = bonobo_type_unique (
134                         PARENT_TYPE,
135                         POA_Accessibility_EventListener__init,
136                         NULL,
137                         G_STRUCT_OFFSET (ListenerClass, epv),
138                         &tinfo,
139                         "AccessibleEventListener");
140         }
141
142         return type;
143 }
144
145 AccessibleEventListener *
146 accessible_event_listener_new ()
147 {
148     AccessibleEventListener *retval =
149     ACCESSIBLE_EVENT_LISTENER (g_object_new (accessible_event_listener_get_type (), NULL));
150     return retval;
151 }
152
153 void   accessible_event_listener_add_callback (AccessibleEventListener *listener,
154                                                VoidEventListenerCB callback)
155 {
156   listener->callbacks = g_list_append (listener->callbacks, callback);
157 }
158
159 void   accessible_event_listener_remove_callback (AccessibleEventListener *listener,
160                                                   VoidEventListenerCB callback)
161 {
162   listener->callbacks = g_list_remove (listener->callbacks, callback);
163 }