2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
23 /* keystrokelistener.c: implement the KeystrokeListener interface */
29 #include <libspi/listener.h>
30 #include <libspi/keystrokelistener.h>
32 /* Our parent Gtk object type */
33 #define PARENT_TYPE BONOBO_TYPE_OBJECT
35 /* A pointer to our parent object class */
36 static BonoboObjectClass *keystroke_listener_parent_class;
42 static guint signals [LAST_SIGNAL];
44 /* GObject::finalize */
46 spi_keystroke_listener_object_finalize (GObject *object)
48 SpiKeystrokeListener *listener = SPI_KEYSTROKE_LISTENER (object);
50 g_list_free (listener->callbacks);
52 fprintf(stderr, "keystroke_listener_object_finalize called\n");
54 ((GObjectClass *) keystroke_listener_parent_class)->finalize (object);
57 void spi_keystroke_listener_add_callback (SpiKeystrokeListener *listener,
58 BooleanKeystrokeListenerCB callback)
60 listener->callbacks = g_list_append (listener->callbacks, callback);
62 fprintf(stderr, "keystroke_listener_add_callback (%p) called\n",
68 spi_keystroke_listener_remove_callback (SpiKeystrokeListener *listener,
69 BooleanKeystrokeListenerCB callback)
71 listener->callbacks = g_list_remove (listener->callbacks, callback);
75 * CORBA Accessibility::KeystrokeListener::keyEvent method implementation
78 impl_key_event (PortableServer_Servant servant,
79 const Accessibility_KeyStroke *key,
80 CORBA_Environment *ev)
82 SpiKeystrokeListener *listener = SPI_KEYSTROKE_LISTENER (bonobo_object_from_servant (servant));
83 GList *callbacks = listener->callbacks;
84 gboolean was_consumed = FALSE;
86 g_signal_emit (G_OBJECT (listener), signals [KEY_EVENT], 0, key, &was_consumed);
92 #ifdef SPI_KEYEVENT_DEBUG
93 if (ev->_major != CORBA_NO_EXCEPTION) {
95 ("Accessibility app error: exception during keystroke notification: %s\n"),
96 CORBA_exception_id(ev));
100 fprintf(stderr, "%s%c",
101 (key->modifiers & SPI_KEYMASK_ALT)?"Alt-":"",
102 ((key->modifiers & SPI_KEYMASK_SHIFT)^(key->modifiers & SPI_KEYMASK_SHIFTLOCK))?
103 (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID));
106 /* TODO: convert from the CORBA-based struct to a c-type-based one ? */
107 #ifdef SPI_KEYSTROKE_DEBUG
108 fprintf (stderr, "Key:\tsym %ld\n\tmods %x\n\tcode %d\n\ttime %ld\n",
110 (unsigned int) key->modifiers,
112 (long int) key->timestamp);
116 BooleanKeystrokeListenerCB cb = (BooleanKeystrokeListenerCB) callbacks->data;
117 was_consumed = (*cb) (key) || was_consumed;
118 callbacks = g_list_next (callbacks);
125 boolean_handled_accumulator (GSignalInvocationHint *ihint,
127 const GValue *handler_return,
130 gboolean continue_emission;
131 gboolean signal_handled;
133 signal_handled = g_value_get_boolean (handler_return);
134 g_value_set_boolean (return_accu, signal_handled);
135 continue_emission = !signal_handled;
137 return continue_emission;
141 marshal_BOOLEAN__POINTER (GClosure *closure,
142 GValue *return_value,
143 guint n_param_values,
144 const GValue *param_values,
145 gpointer invocation_hint,
146 gpointer marshal_data)
148 typedef gboolean (*GMarshalFunc_BOOLEAN__POINTER) (gpointer data1,
151 register GMarshalFunc_BOOLEAN__POINTER callback;
152 register GCClosure *cc = (GCClosure*) closure;
153 register gpointer data1, data2;
156 g_return_if_fail (return_value != NULL);
157 g_return_if_fail (n_param_values == 2);
159 if (G_CCLOSURE_SWAP_DATA (closure))
161 data1 = closure->data;
162 data2 = g_value_peek_pointer (param_values + 0);
166 data1 = g_value_peek_pointer (param_values + 0);
167 data2 = closure->data;
169 callback = (GMarshalFunc_BOOLEAN__POINTER) (marshal_data ? marshal_data : cc->callback);
171 v_return = callback (data1,
172 g_value_get_pointer (param_values + 1),
175 g_value_set_boolean (return_value, v_return);
179 spi_keystroke_listener_class_init (SpiKeystrokeListenerClass *klass)
181 GObjectClass * object_class = (GObjectClass *) klass;
182 POA_Accessibility_KeystrokeListener__epv *epv = &klass->epv;
183 keystroke_listener_parent_class = g_type_class_peek_parent (klass);
185 signals [KEY_EVENT] = g_signal_new (
187 G_TYPE_FROM_CLASS (klass),
189 G_STRUCT_OFFSET (SpiKeystrokeListenerClass, key_event),
190 boolean_handled_accumulator, NULL,
191 marshal_BOOLEAN__POINTER,
192 G_TYPE_BOOLEAN, 1, G_TYPE_POINTER);
194 object_class->finalize = spi_keystroke_listener_object_finalize;
196 epv->keyEvent = impl_key_event;
200 spi_keystroke_listener_init (SpiKeystrokeListener *keystroke_listener)
202 keystroke_listener->callbacks = NULL;
205 BONOBO_TYPE_FUNC_FULL (SpiKeystrokeListener,
206 Accessibility_KeystrokeListener,
208 spi_keystroke_listener);
210 SpiKeystrokeListener *
211 spi_keystroke_listener_new (void)
213 SpiKeystrokeListener *retval = g_object_new (
214 SPI_KEYSTROKE_LISTENER_TYPE, NULL);