X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=libspi%2Fkeystrokelistener.c;h=43f2cf0cefdfdc0f7973e2e779a8bdd7cd892c8e;hb=68b558bcef701bc71b1b7e53f68935f9c632fcdb;hp=3d8893b452b185b96bd8be391bd565f434cbc8d2;hpb=408978dd34f3338e49b6ace5f60b7606579ce7a9;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/libspi/keystrokelistener.c b/libspi/keystrokelistener.c index 3d8893b..43f2cf0 100644 --- a/libspi/keystrokelistener.c +++ b/libspi/keystrokelistener.c @@ -20,156 +20,126 @@ * Boston, MA 02111-1307, USA. */ -/* - * listener.c: test for accessibility implementation - * - */ - -#ifdef SPI_DEBUG -#include -#endif +/* keystrokelistener.c: implement the KeystrokeListener interface */ #include -#include -#include - -/* - * This pulls the definition for the BonoboObject (GType) - */ -#include "keystrokelistener.h" - -/* - * Our parent Gtk object type - */ -#define PARENT_TYPE BONOBO_OBJECT_TYPE - -/* - * A pointer to our parent object class - */ -static GObjectClass *keystroke_spi_listener_parent_class; - -/* - * Implemented GObject::finalize - */ -static void -keystroke_spi_listener_object_finalize (GObject *object) -{ -/* KeystrokeListener *keystroke_listener = KEYSTROKE_SPI_LISTENER (object); */ - #ifdef SPI_DEBUG - fprintf(stderr, "keystroke_spi_listener_object_finalize called\n"); +# include #endif - keystroke_spi_listener_parent_class->finalize (object); -} +#include +#include -void keystroke_spi_listener_add_callback (KeystrokeListener *listener, - BooleanKeystrokeListenerCB callback) -{ - listener->callbacks = g_list_append (listener->callbacks, callback); -#ifdef SPI_DEBUG - fprintf(stderr, "keystroke_spi_listener_add_callback (%p) called\n", - (gpointer) callback); -#endif -} +/* Our parent Gtk object type */ +#define PARENT_TYPE BONOBO_TYPE_OBJECT -void keystroke_spi_listener_remove_callback (KeystrokeListener *listener, - BooleanKeystrokeListenerCB callback) -{ - listener->callbacks = g_list_remove (listener->callbacks, callback); -} +enum { + KEY_EVENT, + LAST_SIGNAL +}; +static guint signals [LAST_SIGNAL]; /* * CORBA Accessibility::KeystrokeListener::keyEvent method implementation */ static CORBA_boolean -impl_key_event (PortableServer_Servant servant, +impl_key_event (PortableServer_Servant servant, const Accessibility_KeyStroke *key, - CORBA_Environment *ev) + CORBA_Environment *ev) { - KeystrokeListener *listener = KEYSTROKE_SPI_LISTENER (bonobo_object_from_servant (servant)); - GList *callbacks = listener->callbacks; gboolean was_consumed = FALSE; -#ifdef SPI_KEYEVENT_DEBUG - if (ev->_major != CORBA_NO_EXCEPTION) { - fprintf(stderr, - ("Accessibility app error: exception during keystroke notification: %s\n"), - CORBA_exception_id(ev)); - exit(-1); - } - else { - fprintf(stderr, "%s%c", - (key->modifiers & KEYMASK_ALT)?"Alt-":"", - ((key->modifiers & KEYMASK_SHIFT)^(key->modifiers & KEYMASK_SHIFTLOCK))? - (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID)); - } -#endif - while (callbacks) - { - BooleanKeystrokeListenerCB cb = (BooleanKeystrokeListenerCB) callbacks->data; - was_consumed = (*cb) (key) || was_consumed; - callbacks = g_list_next (callbacks); - } + SpiKeystrokeListener *listener = SPI_KEYSTROKE_LISTENER ( + bonobo_object_from_servant (servant)); + + g_signal_emit (G_OBJECT (listener), signals [KEY_EVENT], 0, key, &was_consumed); + return was_consumed; } -static void -keystroke_spi_listener_class_init (KeystrokeListenerClass *klass) +static gboolean +boolean_handled_accumulator (GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy) { - GObjectClass * object_class = (GObjectClass *) klass; - POA_Accessibility_KeystrokeListener__epv *epv = &klass->epv; - keystroke_spi_listener_parent_class = g_type_class_ref (BONOBO_OBJECT_TYPE); - - object_class->finalize = keystroke_spi_listener_object_finalize; + gboolean continue_emission; + gboolean signal_handled; + + signal_handled = g_value_get_boolean (handler_return); + g_value_set_boolean (return_accu, signal_handled); + continue_emission = !signal_handled; + + return continue_emission; +} - epv->keyEvent = impl_key_event; +void +marshal_BOOLEAN__POINTER (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef gboolean (*GMarshalFunc_BOOLEAN__POINTER) (gpointer data1, + gpointer arg_1, + gpointer data2); + register GMarshalFunc_BOOLEAN__POINTER callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + gboolean v_return; + + g_return_if_fail (return_value != NULL); + g_return_if_fail (n_param_values == 2); + + if (G_CCLOSURE_SWAP_DATA (closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer (param_values + 0); + } + else + { + data1 = g_value_peek_pointer (param_values + 0); + data2 = closure->data; + } + callback = (GMarshalFunc_BOOLEAN__POINTER) (marshal_data ? marshal_data : cc->callback); + + v_return = callback (data1, + g_value_get_pointer (param_values + 1), + data2); + + g_value_set_boolean (return_value, v_return); } static void -keystroke_spi_listener_init (KeystrokeListener *keystroke_listener) +spi_keystroke_listener_class_init (SpiKeystrokeListenerClass *klass) { - keystroke_listener->callbacks = NULL; + POA_Accessibility_KeystrokeListener__epv *epv = &klass->epv; + + signals [KEY_EVENT] = g_signal_new ( + "key_event", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (SpiKeystrokeListenerClass, key_event), + boolean_handled_accumulator, NULL, + marshal_BOOLEAN__POINTER, + G_TYPE_BOOLEAN, 1, G_TYPE_POINTER); + + epv->keyEvent = impl_key_event; } -GType -keystroke_spi_listener_get_type (void) +static void +spi_keystroke_listener_init (SpiKeystrokeListener *keystroke_listener) { - static GType type = 0; - - if (!type) { - static const GTypeInfo tinfo = { - sizeof (KeystrokeListenerClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) keystroke_spi_listener_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class data */ - sizeof (KeystrokeListener), - 0, /* n preallocs */ - (GInstanceInitFunc) keystroke_spi_listener_init, - NULL /* value table */ - }; - /* - * Here we use bonobo_type_unique instead of - * gtk_type_unique, this auto-generates a load of - * CORBA structures for us. All derived types must - * use bonobo_type_unique. - */ - type = bonobo_type_unique ( - PARENT_TYPE, - POA_Accessibility_KeystrokeListener__init, - NULL, - G_STRUCT_OFFSET (KeystrokeListenerClass, epv), - &tinfo, - "KeystrokeListener"); - } - - return type; } -KeystrokeListener * -keystroke_spi_listener_new (void) +BONOBO_TYPE_FUNC_FULL (SpiKeystrokeListener, + Accessibility_KeystrokeListener, + BONOBO_TYPE_OBJECT, + spi_keystroke_listener); + +SpiKeystrokeListener * +spi_keystroke_listener_new (void) { - KeystrokeListener *retval = - KEYSTROKE_SPI_LISTENER (g_object_new (keystroke_spi_listener_get_type (), NULL)); + SpiKeystrokeListener *retval = g_object_new ( + SPI_KEYSTROKE_LISTENER_TYPE, NULL); return retval; }