Added makefile support for cspi directory.
[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
74   int n;
75   int len;
76   VoidEventListenerCB cb;
77   AccessibleEventListener *listener = ACCESSIBLE_EVENT_LISTENER (
78                                        bonobo_object_from_servant (servant));
79   len = g_list_length (listener->callbacks);
80
81   for (n=0; n<len; ++n)
82     {
83       cb =  (VoidEventListenerCB) g_list_nth_data (listener->callbacks, n);
84       (*cb) (NULL);
85     }
86   bonobo_object_release_unref (e->target, ev);
87 }
88
89 static void
90 accessible_event_listener_class_init (AccessibleEventListenerClass *klass)
91 {
92         GObjectClass * object_class = (GObjectClass *) klass;
93         ListenerClass * listener_class = (ListenerClass *) klass;
94         POA_Accessibility_EventListener__epv *epv = &listener_class->epv;
95         accessible_event_listener_parent_class = g_type_class_ref (LISTENER_TYPE);
96
97         object_class->finalize = accessible_event_listener_object_finalize;
98
99         epv->notifyEvent = impl_accessible_event_notify_event;
100 }
101
102 static void
103 accessible_event_listener_init (Listener *listener)
104 {
105 }
106
107 GType
108 accessible_event_listener_get_type (void)
109 {
110         static GType type = 0;
111
112         if (!type) {
113                 static const GTypeInfo tinfo = {
114                         sizeof (AccessibleEventListenerClass),
115                         (GBaseInitFunc) NULL,
116                         (GBaseFinalizeFunc) NULL,
117                         (GClassInitFunc) accessible_event_listener_class_init,
118                         (GClassFinalizeFunc) NULL,
119                         NULL, /* class data */
120                         sizeof (Listener),
121                         0, /* n preallocs */
122                         (GInstanceInitFunc) accessible_event_listener_init,
123                         NULL /* value table */
124                 };
125                 /*
126                  *   Here we use bonobo_type_unique instead of
127                  * gtk_type_unique, this auto-generates a load of
128                  * CORBA structures for us. All derived types must
129                  * use bonobo_type_unique.
130                  */
131                 type = bonobo_type_unique (
132                         PARENT_TYPE,
133                         POA_Accessibility_EventListener__init,
134                         NULL,
135                         G_STRUCT_OFFSET (ListenerClass, epv),
136                         &tinfo,
137                         "AccessibleEventListener");
138         }
139
140         return type;
141 }
142
143 AccessibleEventListener *
144 accessible_event_listener_new ()
145 {
146     AccessibleEventListener *retval =
147                LISTENER (g_object_new (accessible_event_listener_get_type (), NULL));
148     return retval;
149 }
150
151 void   accessible_event_listener_add_callback (AccessibleEventListener *listener,
152                                                VoidEventListenerCB callback)
153 {
154   listener->callbacks = g_list_append (listener->callbacks, listener);
155 }
156
157 void   accessible_event_listener_remove_callback (AccessibleEventListener *listener,
158                                                   VoidEventListenerCB callback)
159 {
160   listener->callbacks = g_list_remove (listener->callbacks, listener);
161 }