From 8df52aa9569ae235250d86857e7cd8b920ca0e3f Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 27 Nov 2019 10:28:29 -0300 Subject: [PATCH] Refactoring keyboard management engine. --- Makefile.in | 1 + src/include/internals.h | 5 ++++- src/include/terminal.h | 3 +++ src/include/v3270.h | 5 ----- src/include/v3270/actions.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/include/v3270/keyboard.h | 73 ------------------------------------------------------------------------- src/terminal/keyboard.c | 38 ++++++++++++++++++++++++++------------ src/terminal/keyboard/init.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/terminal/keyboard/private.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/terminal/widget.c | 9 +++++++++ v3270.cbp | 6 +++++- 11 files changed, 253 insertions(+), 92 deletions(-) create mode 100644 src/include/v3270/actions.h delete mode 100644 src/include/v3270/keyboard.h create mode 100644 src/terminal/keyboard/init.c create mode 100644 src/terminal/keyboard/private.h diff --git a/Makefile.in b/Makefile.in index 46191a7..8be7481 100644 --- a/Makefile.in +++ b/Makefile.in @@ -38,6 +38,7 @@ SOURCES= \ $(wildcard src/terminal/properties/*.c) \ $(wildcard src/terminal/drawing/*.c) \ $(wildcard src/terminal/font/*.c) \ + $(wildcard src/terminal/keyboard/*.c) \ $(wildcard src/filetransfer/*.c) \ $(wildcard src/selection/*.c) \ $(wildcard src/selection/@OSNAME@/*.c) \ diff --git a/src/include/internals.h b/src/include/internals.h index 042e6f6..dc8bbd7 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -309,7 +309,6 @@ G_GNUC_INTERNAL void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned G_GNUC_INTERNAL void v3270_blink_ssl(v3270 *terminal); - G_GNUC_INTERNAL void v3270_init_properties(GObjectClass * gobject_class); G_GNUC_INTERNAL void v3270_queue_draw_area(GtkWidget *widget, gint x, gint y, gint width, gint height); G_GNUC_INTERNAL void v3270_disable_updates(GtkWidget *widget); @@ -340,9 +339,13 @@ G_GNUC_INTERNAL void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned G_GNUC_INTERNAL gchar * v3270_translate_rgba_to_text(GdkRGBA *clr); // Properties + G_GNUC_INTERNAL void v3270_init_properties(GObjectClass * gobject_class); G_GNUC_INTERNAL gboolean v3270_update_associated_lu(v3270 *terminal); G_GNUC_INTERNAL void v3270_update_toggle(GtkWidget *widget, LIB3270_TOGGLE_ID id, unsigned char value, const char *name); + // Accelerators + G_GNUC_INTERNAL void v3270_init_accelerators(v3270 *widget); + G_END_DECLS #endif // V3270_INTERNALS_H_INCLUDED diff --git a/src/include/terminal.h b/src/include/terminal.h index 1bbc7c2..001781a 100644 --- a/src/include/terminal.h +++ b/src/include/terminal.h @@ -217,6 +217,9 @@ G_BEGIN_DECLS GtkWidget * trace; ///< @brief Trace window handle. + // Keyboard accelerators. + GSList * accelerators; ///< @brief Keyboard accelerators. + }; G_GNUC_INTERNAL void v3270_activate(GtkWidget *widget); diff --git a/src/include/v3270.h b/src/include/v3270.h index 0d6b4ea..c0006f1 100644 --- a/src/include/v3270.h +++ b/src/include/v3270.h @@ -273,11 +273,6 @@ LIB3270_EXPORT void v3270_set_remap_filename(GtkWidget *widget, const gchar *path); LIB3270_EXPORT const gchar * v3270_get_remap_filename(GtkWidget *widget); - // Actions - LIB3270_EXPORT void v3270_set_scroll_action(GtkWidget *widget, GdkScrollDirection direction, GtkAction *action) G_GNUC_DEPRECATED; - LIB3270_EXPORT void v3270_tab(GtkWidget *widget); - LIB3270_EXPORT void v3270_backtab(GtkWidget *widget); - // SSL & Security LIB3270_EXPORT const gchar * v3270_get_ssl_state_icon_name(GtkWidget *widget); LIB3270_EXPORT const gchar * v3270_get_ssl_state_message(GtkWidget *widget); diff --git a/src/include/v3270/actions.h b/src/include/v3270/actions.h new file mode 100644 index 0000000..8aa349b --- /dev/null +++ b/src/include/v3270/actions.h @@ -0,0 +1,50 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#ifndef V3270_ACTIONS_H_INCLUDED + + #define V3270_ACTIONS_H_INCLUDED 1 + + #include + + G_BEGIN_DECLS + + typedef struct _V3270Accelerator V3270Accelerator; + + LIB3270_EXPORT void v3270_set_scroll_action(GtkWidget *widget, GdkScrollDirection direction, GtkAction *action) G_GNUC_DEPRECATED; + LIB3270_EXPORT void v3270_tab(GtkWidget *widget); + LIB3270_EXPORT void v3270_backtab(GtkWidget *widget); + + LIB3270_EXPORT void v3270_accelerator_activate(V3270Accelerator * accell, GtkWidget *terminal); + LIB3270_EXPORT gboolean v3270_accelerator_compare(const V3270Accelerator * accell, const guint keyval, const GdkModifierType mods); + + + G_END_DECLS + +#endif // V3270_ACTIONS_H_INCLUDED diff --git a/src/include/v3270/keyboard.h b/src/include/v3270/keyboard.h deleted file mode 100644 index 1f799b8..0000000 --- a/src/include/v3270/keyboard.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como - e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - -#ifndef V3270_KEYBOARD_H_INCLUDED - - #define V3270_KEYBOARD_H_INCLUDED 1 - - #include - - G_BEGIN_DECLS - - #define GTK_TYPE_V3270_ACCELERATOR (V3270Accelerator_get_type ()) - #define GTK_V3270_ACCELERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270_ACCELERATOR, V3270Accelerator)) - #define GTK_V3270_ACCELERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270_ACCELERATOR, V3270AcceleratorClass)) - #define GTK_IS_V3270_ACCELERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_V3270_ACCELERATOR)) - #define GTK_IS_V3270_ACCELERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_V3270_ACCELERATOR)) - #define GTK_V3270_ACCELERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_V3270_ACCELERATOR, V3270AcceleratorClass)) - - typedef struct _V3270Accelerator - { - GObject parent; - guint accel_key; - GdkModifierType accel_mods; - } V3270Accelerator; - - typedef struct _V3270AcceleratorClass - { - GObjectClass parent_class; - - void (*activate)(GObject *accelerator, GtkWidget *widget); - const gchar * (*get_name)(GObject *accelerator); - - } V3270AcceleratorClass; - - LIB3270_EXPORT GType V3270Accelerator_get_type(void); - - LIB3270_EXPORT GObject * v3270_accelerator_new_from_lib3270_action(const LIB3270_ACTION *action); - - LIB3270_EXPORT void v3270_accelerator_activate(GtkWidget *widget); - LIB3270_EXPORT const gchar * v3270_accelerator_get_name(GObject *accelerator); - LIB3270_EXPORT void v3270_accelerator_parse(GObject *object, const gchar *accelerator); - - LIB3270_EXPORT void v3270_append_accelerator(GtkWidget *terminal, GObject *accelerator); - - G_END_DECLS - -#endif // V3270_DIALOGS_H_INCLUDED diff --git a/src/terminal/keyboard.c b/src/terminal/keyboard.c index cf647e5..37d90d0 100644 --- a/src/terminal/keyboard.c +++ b/src/terminal/keyboard.c @@ -32,6 +32,7 @@ #include #include + #include #include #include #include @@ -57,6 +58,7 @@ /*--[ Globals ]--------------------------------------------------------------------------------------*/ + /* static struct _keycode { guint keyval; @@ -64,20 +66,17 @@ int (*exec)(H3270 *session); } keycode[] = { - { GDK_Left, 0, lib3270_cursor_left }, - { GDK_Up, 0, lib3270_cursor_up }, - { GDK_Right, 0, lib3270_cursor_right }, - { GDK_Down, 0, lib3270_cursor_down }, - { GDK_Tab, 0, lib3270_nextfield }, - { GDK_ISO_Left_Tab, GDK_SHIFT_MASK, lib3270_previousfield }, + { GDK_Left, 0, lib3270_cursor_left }, // OK + { GDK_Up, 0, lib3270_cursor_up }, // OK + { GDK_Right, 0, lib3270_cursor_right }, // OK + { GDK_Down, 0, lib3270_cursor_down }, // OK + { GDK_Tab, 0, lib3270_nextfield }, // OK + { GDK_ISO_Left_Tab, GDK_SHIFT_MASK, lib3270_previousfield }, // OK { GDK_KP_Left, 0, lib3270_cursor_left }, { GDK_KP_Up, 0, lib3270_cursor_up }, { GDK_KP_Right, 0, lib3270_cursor_right }, { GDK_KP_Down, 0, lib3270_cursor_down }, -// { GDK_KP_Add, GDK_NUMLOCK_MASK, NULL }, -// { GDK_KP_Subtract, GDK_NUMLOCK_MASK, NULL }, - { GDK_3270_PrintScreen, 0, lib3270_print_all }, { GDK_P, GDK_CONTROL_MASK, lib3270_print_all }, @@ -85,14 +84,14 @@ { GDK_Print, GDK_CONTROL_MASK, lib3270_print_all }, { GDK_Print, GDK_SHIFT_MASK, lib3270_sysreq }, -// { GDK_Control_R, 0, NULL }, -// { GDK_Control_L, 0, NULL }, //#ifdef WIN32 // { GDK_Pause, 0, NULL }, //#endif + }; + */ /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -124,7 +123,7 @@ static gboolean check_keypress(v3270 *widget, GdkEventKey *event) { - int f; +// int f; GdkModifierType state = event->state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK|GDK_ALT_MASK); gboolean handled = FALSE; @@ -150,6 +149,19 @@ } #endif // DEBUG + // Check accelerator table. + GSList * acccelerator; + for(acccelerator = widget->accelerators; acccelerator; acccelerator = g_slist_next(acccelerator)) + { + if(v3270_accelerator_compare((V3270Accelerator *) acccelerator->data, event->keyval, state)) + { + v3270_accelerator_activate((V3270Accelerator *) acccelerator->data,GTK_WIDGET(widget)); + return TRUE; + } + + } + + // Check PFKeys if(event->keyval >= GDK_F1 && event->keyval <= GDK_F12 && !(state & (GDK_CONTROL_MASK|GDK_ALT_MASK))) { int pfcode = (event->keyval - GDK_F1) + ((state & GDK_SHIFT_MASK) ? 13 : 1); @@ -161,6 +173,7 @@ } } + /* for(f=0; f < (int) G_N_ELEMENTS(keycode);f++) { if(keycode[f].keyval == event->keyval && state == keycode[f].state) @@ -173,6 +186,7 @@ } } + */ return FALSE; } diff --git a/src/terminal/keyboard/init.c b/src/terminal/keyboard/init.c new file mode 100644 index 0000000..101a891 --- /dev/null +++ b/src/terminal/keyboard/init.c @@ -0,0 +1,109 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como properties.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include "private.h" + #include + #include + #include + #include + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + static int fire_lib3270_action(GtkWidget *widget, const LIB3270_ACTION * action) + { + int rc = EPERM; + + H3270 *hSession = v3270_get_session(widget); + + debug("%s(%s)",__FUNCTION__,action->name); + + if(action->activatable(hSession)) + rc = action->activate(hSession); + + debug("%s(%s)=%d %s",__FUNCTION__,action->name,rc,strerror(rc)); + return rc; + + } + + void v3270_init_accelerators(v3270 *widget) + { + size_t ix; + + // Create accelerators for lib3270 actions. + const LIB3270_ACTION * actions = lib3270_get_actions(); + + for(ix = 0; actions[ix].name; ix++) + { + if(actions[ix].keys) + { + size_t key; + + gchar ** keys = g_strsplit(actions[ix].keys,",",-1); + + for(key = 0; keys[key]; key++) + { + + V3270Accelerator * accelerator = g_new0(V3270Accelerator,1); + + accelerator->type = ACCELERATOR_TYPE_LIB3270_ACTION; + accelerator->arg = (gconstpointer) &actions[ix]; + accelerator->activate = G_CALLBACK(fire_lib3270_action); + + debug("%s=%s",actions[ix].name,keys[key]); + + gtk_accelerator_parse(keys[key],&accelerator->key,&accelerator->mods); + + widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); + + } + + g_strfreev(keys); + + } + + } + + + } + + gboolean v3270_accelerator_compare(const V3270Accelerator * accell, const guint keyval, const GdkModifierType mods) + { + return accell->key == keyval && accell->mods == mods; + } + + void v3270_accelerator_activate(V3270Accelerator * accell, GtkWidget *terminal) + { + int rc = ((int (*)(GtkWidget *, const void *)) accell->activate)(terminal,accell->arg); + + if(rc) + gdk_display_beep(gdk_display_get_default()); + + } + + diff --git a/src/terminal/keyboard/private.h b/src/terminal/keyboard/private.h new file mode 100644 index 0000000..bcfe51b --- /dev/null +++ b/src/terminal/keyboard/private.h @@ -0,0 +1,46 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include + #include + + enum + { + ACCELERATOR_TYPE_LIB3270_ACTION, ///< @brief Accelerator is a lib3270 action + }; + + struct _V3270Accelerator + { + unsigned short type; + guint key; + GdkModifierType mods; + gconstpointer arg; + GCallback activate; + }; diff --git a/src/terminal/widget.c b/src/terminal/widget.c index 7f1cebb..aca8dcb 100644 --- a/src/terminal/widget.c +++ b/src/terminal/widget.c @@ -180,6 +180,12 @@ static void finalize(GObject *object) terminal->host = NULL; } + if(terminal->accelerators) + { + g_slist_free_full(terminal->accelerators,g_free); + terminal->accelerators = NULL; + } + G_OBJECT_CLASS(v3270_parent_class)->finalize(object); } @@ -526,6 +532,9 @@ static void v3270_init(v3270 *widget) for(ix = 0; ix < G_N_ELEMENTS(widget->responses); ix++) widget->responses[ix] = GTK_RESPONSE_NONE; + // Init accelerators + v3270_init_accelerators(widget); + } LIB3270_EXPORT GtkWidget * v3270_new(void) diff --git a/v3270.cbp b/v3270.cbp index b88ec3a..a41801e 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -173,11 +173,11 @@ + - @@ -268,6 +268,10 @@ + + + -- libgit2 0.21.2