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/keystrokelistener.h>
31 /* Our parent Gtk object type */
32 #define PARENT_TYPE BONOBO_TYPE_OBJECT
34 /* A pointer to our parent object class */
35 static GObjectClass *keystroke_listener_parent_class;
38 * Implemented GObject::finalize
41 keystroke_listener_object_finalize (GObject *object)
45 fprintf(stderr, "keystroke_listener_object_finalize called\n");
47 keystroke_listener_parent_class->finalize (object);
50 void spi_keystroke_listener_add_callback (SpiKeystrokeListener *listener,
51 BooleanKeystrokeListenerCB callback)
53 listener->callbacks = g_list_append (listener->callbacks, callback);
55 fprintf(stderr, "keystroke_listener_add_callback (%p) called\n",
60 void spi_keystroke_listener_remove_callback (SpiKeystrokeListener *listener,
61 BooleanKeystrokeListenerCB callback)
63 listener->callbacks = g_list_remove (listener->callbacks, callback);
67 * CORBA Accessibility::KeystrokeListener::keyEvent method implementation
70 impl_key_event (PortableServer_Servant servant,
71 const Accessibility_KeyStroke *key,
72 CORBA_Environment *ev)
74 SpiKeystrokeListener *listener = SPI_KEYSTROKE_LISTENER (bonobo_object_from_servant (servant));
75 GList *callbacks = listener->callbacks;
76 gboolean was_consumed = FALSE;
77 #ifdef SPI_KEYEVENT_DEBUG
78 if (ev->_major != CORBA_NO_EXCEPTION) {
80 ("Accessibility app error: exception during keystroke notification: %s\n"),
81 CORBA_exception_id(ev));
85 fprintf(stderr, "%s%c",
86 (key->modifiers & SPI_KEYMASK_ALT)?"Alt-":"",
87 ((key->modifiers & SPI_KEYMASK_SHIFT)^(key->modifiers & SPI_KEYMASK_SHIFTLOCK))?
88 (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID));
91 /* TODO: convert from the CORBA-based struct to a c-type-based one ? */
92 #ifdef SPI_KEYSTROKE_DEBUG
93 fprintf (stderr, "Key:\tsym %ld\n\tmods %x\n\tcode %d\n\ttime %ld\n",
95 (unsigned int) key->modifiers,
97 (long int) key->timestamp);
101 BooleanKeystrokeListenerCB cb = (BooleanKeystrokeListenerCB) callbacks->data;
102 was_consumed = (*cb) (key) || was_consumed;
103 callbacks = g_list_next (callbacks);
109 spi_keystroke_listener_class_init (SpiKeystrokeListenerClass *klass)
111 GObjectClass * object_class = (GObjectClass *) klass;
112 POA_Accessibility_KeystrokeListener__epv *epv = &klass->epv;
113 keystroke_listener_parent_class = g_type_class_peek_parent (klass);
115 object_class->finalize = keystroke_listener_object_finalize;
117 epv->keyEvent = impl_key_event;
121 spi_keystroke_listener_init (SpiKeystrokeListener *keystroke_listener)
123 keystroke_listener->callbacks = NULL;
126 BONOBO_TYPE_FUNC_FULL (SpiKeystrokeListener,
127 Accessibility_KeystrokeListener,
129 spi_keystroke_listener);
131 SpiKeystrokeListener *
132 spi_keystroke_listener_new (void)
134 SpiKeystrokeListener *retval = g_object_new (
135 SPI_KEYSTROKE_LISTENER_TYPE, NULL);