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.
24 * listener.c: test for accessibility implementation
33 #include <bonobo/Bonobo.h>
34 #include <libspi/Accessibility.h>
37 * This pulls the definition for the BonoboObject (GType)
39 #include "keystrokelistener.h"
42 * Our parent Gtk object type
44 #define PARENT_TYPE BONOBO_OBJECT_TYPE
47 * A pointer to our parent object class
49 static GObjectClass *keystroke_listener_parent_class;
52 * Implemented GObject::finalize
55 keystroke_listener_object_finalize (GObject *object)
57 /* KeystrokeListener *keystroke_listener = KEYSTROKE_LISTENER (object); */
60 fprintf(stderr, "keystroke_listener_object_finalize called\n");
62 keystroke_listener_parent_class->finalize (object);
65 void keystroke_listener_add_callback (KeystrokeListener *listener,
66 BooleanKeystrokeListenerCB callback)
68 listener->callbacks = g_list_append (listener->callbacks, callback);
70 fprintf(stderr, "keystroke_listener_add_callback (%p) called\n",
75 void keystroke_listener_remove_callback (KeystrokeListener *listener,
76 BooleanKeystrokeListenerCB callback)
78 listener->callbacks = g_list_remove (listener->callbacks, callback);
82 * CORBA Accessibility::KeystrokeListener::keyEvent method implementation
85 impl_key_event (PortableServer_Servant servant,
86 const Accessibility_KeyStroke *key,
87 CORBA_Environment *ev)
89 KeystrokeListener *listener = KEYSTROKE_LISTENER (bonobo_object_from_servant (servant));
90 GList *callbacks = listener->callbacks;
91 gboolean was_consumed = FALSE;
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 & KEYMASK_ALT)?"Alt-":"",
102 ((key->modifiers & KEYMASK_SHIFT)^(key->modifiers & KEYMASK_SHIFTLOCK))?
103 (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID));
108 BooleanKeystrokeListenerCB cb = (BooleanKeystrokeListenerCB) callbacks->data;
109 was_consumed = (*cb) (key) || was_consumed;
110 callbacks = g_list_next (callbacks);
116 keystroke_listener_class_init (KeystrokeListenerClass *klass)
118 GObjectClass * object_class = (GObjectClass *) klass;
119 POA_Accessibility_KeystrokeListener__epv *epv = &klass->epv;
120 keystroke_listener_parent_class = g_type_class_ref (BONOBO_OBJECT_TYPE);
122 object_class->finalize = keystroke_listener_object_finalize;
124 epv->keyEvent = impl_key_event;
128 keystroke_listener_init (KeystrokeListener *keystroke_listener)
130 keystroke_listener->callbacks = NULL;
134 keystroke_listener_get_type (void)
136 static GType type = 0;
139 static const GTypeInfo tinfo = {
140 sizeof (KeystrokeListenerClass),
141 (GBaseInitFunc) NULL,
142 (GBaseFinalizeFunc) NULL,
143 (GClassInitFunc) keystroke_listener_class_init,
144 (GClassFinalizeFunc) NULL,
145 NULL, /* class data */
146 sizeof (KeystrokeListener),
148 (GInstanceInitFunc) keystroke_listener_init,
149 NULL /* value table */
152 * Here we use bonobo_type_unique instead of
153 * gtk_type_unique, this auto-generates a load of
154 * CORBA structures for us. All derived types must
155 * use bonobo_type_unique.
157 type = bonobo_type_unique (
159 POA_Accessibility_KeystrokeListener__init,
161 G_STRUCT_OFFSET (KeystrokeListenerClass, epv),
163 "KeystrokeListener");
170 keystroke_listener_new (void)
172 KeystrokeListener *retval =
173 KEYSTROKE_LISTENER (g_object_new (keystroke_listener_get_type (), NULL));