X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=libspi%2Fkeystrokelistener.c;h=43f2cf0cefdfdc0f7973e2e779a8bdd7cd892c8e;hb=68b558bcef701bc71b1b7e53f68935f9c632fcdb;hp=68736c9f3553c87312e1cb39e0580f5775012116;hpb=e5a9e644107d0a366d8f4036fc8d363a4ff82255;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/libspi/keystrokelistener.c b/libspi/keystrokelistener.c index 68736c9..43f2cf0 100644 --- a/libspi/keystrokelistener.c +++ b/libspi/keystrokelistener.c @@ -20,147 +20,126 @@ * Boston, MA 02111-1307, USA. */ -/* - * listener.c: test for accessibility implementation - * - */ +/* keystrokelistener.c: implement the KeystrokeListener interface */ +#include #ifdef SPI_DEBUG -#include +# include #endif +#include +#include -#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 +/* Our parent Gtk object type */ +#define PARENT_TYPE BONOBO_TYPE_OBJECT -/* - * A pointer to our parent object class - */ -static GObjectClass *keystroke_listener_parent_class; +enum { + KEY_EVENT, + LAST_SIGNAL +}; +static guint signals [LAST_SIGNAL]; /* - * Implemented GObject::finalize + * CORBA Accessibility::KeystrokeListener::keyEvent method implementation */ -static void -keystroke_listener_object_finalize (GObject *object) +static CORBA_boolean +impl_key_event (PortableServer_Servant servant, + const Accessibility_KeyStroke *key, + CORBA_Environment *ev) { -/* KeystrokeListener *keystroke_listener = KEYSTROKE_LISTENER (object); */ + gboolean was_consumed = FALSE; + SpiKeystrokeListener *listener = SPI_KEYSTROKE_LISTENER ( + bonobo_object_from_servant (servant)); -#ifdef SPI_DEBUG - fprintf(stderr, "keystroke_listener_object_finalize called\n"); -#endif - keystroke_listener_parent_class->finalize (object); -} + g_signal_emit (G_OBJECT (listener), signals [KEY_EVENT], 0, key, &was_consumed); -void keystroke_listener_add_callback (KeystrokeListener *listener, - BooleanKeystrokeListenerCB callback) -{ - listener->callbacks = g_list_append (listener->callbacks, callback); -#ifdef SPI_DEBUG - fprintf(stderr, "keystroke_listener_add_callback (%p) called\n", - (gpointer) callback); -#endif + return was_consumed; } -void keystroke_listener_remove_callback (KeystrokeListener *listener, - BooleanKeystrokeListenerCB callback) +static gboolean +boolean_handled_accumulator (GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy) { - listener->callbacks = g_list_remove (listener->callbacks, callback); + 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; } -/* - * CORBA Accessibility::KeystrokeListener::keyEvent method implementation - */ - -static CORBA_boolean -impl_key_event (PortableServer_Servant servant, - const Accessibility_KeyStroke *key, - CORBA_Environment *ev) +void +marshal_BOOLEAN__POINTER (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) { -#ifdef SPI_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 + 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_listener_class_init (KeystrokeListenerClass *klass) +spi_keystroke_listener_class_init (SpiKeystrokeListenerClass *klass) { - GObjectClass * object_class = (GObjectClass *) klass; - POA_Accessibility_KeystrokeListener__epv *epv = &klass->epv; - keystroke_listener_parent_class = g_type_class_ref (BONOBO_OBJECT_TYPE); - - object_class->finalize = keystroke_listener_object_finalize; - - epv->keyEvent = impl_key_event; + 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; } static void -keystroke_listener_init (KeystrokeListener *keystroke_listener) +spi_keystroke_listener_init (SpiKeystrokeListener *keystroke_listener) { - keystroke_listener->callbacks = NULL; } -GType -keystroke_listener_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo tinfo = { - sizeof (KeystrokeListenerClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) keystroke_listener_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class data */ - sizeof (KeystrokeListener), - 0, /* n preallocs */ - (GInstanceInitFunc) keystroke_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; -} +BONOBO_TYPE_FUNC_FULL (SpiKeystrokeListener, + Accessibility_KeystrokeListener, + BONOBO_TYPE_OBJECT, + spi_keystroke_listener); -KeystrokeListener * -keystroke_listener_new (void) +SpiKeystrokeListener * +spi_keystroke_listener_new (void) { - KeystrokeListener *retval = - KEYSTROKE_LISTENER (g_object_new (keystroke_listener_get_type (), NULL)); + SpiKeystrokeListener *retval = g_object_new ( + SPI_KEYSTROKE_LISTENER_TYPE, NULL); return retval; }