From efac1ab2bb04223c1fcf0c6a7b2eb991e0f8e343 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 27 Apr 2020 21:35:02 -0300 Subject: [PATCH] Refactoring keytable management. --- src/include/v3270/actions.h | 5 ++--- src/terminal/actions/internal.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/terminal/actions/table.c | 679 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/terminal/keyboard/init.c | 60 ++++++++++++++++++++++++++++++++---------------------------- src/testprogram/testprogram.c | 4 ++++ v3270.cbp | 3 +++ 6 files changed, 468 insertions(+), 414 deletions(-) create mode 100644 src/terminal/actions/internal.c diff --git a/src/include/v3270/actions.h b/src/include/v3270/actions.h index ca65b04..0888d51 100644 --- a/src/include/v3270/actions.h +++ b/src/include/v3270/actions.h @@ -54,11 +54,10 @@ V3270_ACTION_FLAGS flags; ///< @brief (The flags for activation). - guint key; - GdkModifierType mods; - int (*activate)(GtkWidget *widget, const V3270_ACTION *action); + const char *keys; ///< @brief Default accelerators (or NULL if no default). + }; diff --git a/src/terminal/actions/internal.c b/src/terminal/actions/internal.c new file mode 100644 index 0000000..d10146d --- /dev/null +++ b/src/terminal/actions/internal.c @@ -0,0 +1,131 @@ +/* + * "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 + #include + + #ifndef GDK_NUMLOCK_MASK + #define GDK_NUMLOCK_MASK GDK_MOD2_MASK + #endif + + #ifndef GDK_ALT_MASK + #define GDK_ALT_MASK GDK_MOD1_MASK + #endif + + #define LIB3270_TYPE_V3270_INTERNAL_ACTION (V270InternalAction_get_type()) + #define V3270_INTERNAL_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), LIB3270_TYPE_V3270_INTERNAL_ACTION, V270InternalAction)) + + #define GET_DESCRIPTOR(obj) ((const V3270_ACTION *) V3270_INTERNAL_ACTION(obj)->definition) + + typedef struct _V270InternalActionClass { + V3270ActionClass parent_class; + } V270InternalActionClass; + + typedef struct _V270InternalAction { + V3270Action parent; + const V3270_ACTION * definition; + } V270InternalAction; + + static void V270InternalAction_class_init(V270InternalActionClass *klass); + static void V270InternalAction_init(V270InternalAction *action); + + G_DEFINE_TYPE(V270InternalAction, V270InternalAction, V3270_TYPE_ACTION); + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + static const gchar * get_icon_name(GAction *action) { + return GET_DESCRIPTOR(action)->icon; + } + + static const gchar * get_label(GAction *action) { + return GET_DESCRIPTOR(action)->label; + } + + static const gchar * get_tooltip(GAction *action) { + return GET_DESCRIPTOR(action)->summary; + } + + static const gchar * get_name(GAction *action) { + return GET_DESCRIPTOR(action)->name; + } + + static void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { + + debug("Activating action \"%s\"",g_action_get_name(action)); + + const V3270_ACTION *descriptor = GET_DESCRIPTOR(action); + + descriptor->activate(terminal,descriptor); + + } + + static LIB3270_ACTION_GROUP get_action_group(GAction *action) { + return GET_DESCRIPTOR(action)->group; + } + + static void V270InternalAction_class_init(V270InternalActionClass *klass) { + + klass->parent_class.get_name = get_name; + klass->parent_class.get_icon_name = get_icon_name; + klass->parent_class.get_label = get_label; + klass->parent_class.get_tooltip = get_tooltip; + klass->parent_class.activate = activate; + klass->parent_class.get_action_group = get_action_group; + + } + + static void V270InternalAction_init(V270InternalAction G_GNUC_UNUSED(*action)) { + } + + void g_action_map_add_v3270_actions(GActionMap *action_map) { + + const V3270_ACTION * actions = v3270_get_actions(); + size_t ix; + + for(ix = 0; actions[ix].name; ix++) { + + V270InternalAction * action = V3270_INTERNAL_ACTION(g_object_new(LIB3270_TYPE_V3270_INTERNAL_ACTION, NULL)); + + action->definition = &actions[ix]; + action->parent.translation_domain = GETTEXT_PACKAGE; + + if(!g_action_get_name(G_ACTION(action))) { + g_warning("Action \"%s\" is invalid",actions[ix].name); + } else { + g_action_map_add_action(action_map,G_ACTION(action)); + } + + } + + } + diff --git a/src/terminal/actions/table.c b/src/terminal/actions/table.c index 565afcc..ece98c7 100644 --- a/src/terminal/actions/table.c +++ b/src/terminal/actions/table.c @@ -28,404 +28,317 @@ */ #include "private.h" - #include - #include #include - #include #include + #include + #include - #ifndef GDK_NUMLOCK_MASK - #define GDK_NUMLOCK_MASK GDK_MOD2_MASK - #endif - - #ifndef GDK_ALT_MASK - #define GDK_ALT_MASK GDK_MOD1_MASK - #endif - - #define LIB3270_TYPE_V3270_INTERNAL_ACTION (V270InternalAction_get_type()) - #define V3270_INTERNAL_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), LIB3270_TYPE_V3270_INTERNAL_ACTION, V270InternalAction)) - - #define GET_DESCRIPTOR(obj) ((const V3270_ACTION *) V3270_INTERNAL_ACTION(obj)->definition) - - typedef struct _V270InternalActionClass { - V3270ActionClass parent_class; - } V270InternalActionClass; - - typedef struct _V270InternalAction { - V3270Action parent; - const V3270_ACTION * definition; - } V270InternalAction; - - static void V270InternalAction_class_init(V270InternalActionClass *klass); - static void V270InternalAction_init(V270InternalAction *action); - - G_DEFINE_TYPE(V270InternalAction, V270InternalAction, V3270_TYPE_ACTION); - -/*--[ Globals ]--------------------------------------------------------------------------------------*/ - - static const V3270_ACTION actions[] = - { - { - .name = "keypad-add", - .group = LIB3270_ACTION_GROUP_ONLINE, - .key = GDK_KP_Add, - .mods = GDK_NUMLOCK_MASK, - .activate = fire_keypad_action - }, - { - .name = "keypad-subtract", - .group = LIB3270_ACTION_GROUP_ONLINE, - .key = GDK_KP_Subtract, - .mods = GDK_NUMLOCK_MASK, - .activate = fire_keypad_action - }, - - // Standard Clipboard actions - { - .flags = V3270_COPY_SMART, - .name = "copy", - .group = LIB3270_ACTION_GROUP_SELECTION, - .icon = "edit-copy", - .label = N_( "Copy" ), - .summary = N_("Copy selection to clipboard"), - .description = N_("Replace current clipboard contents with the selected area"), - .key = 'c', - .mods = GDK_CONTROL_MASK, - .activate = fire_copy_accelerator - }, - - { - .flags = V3270_COPY_APPEND, - .group = LIB3270_ACTION_GROUP_SELECTION, - .name = "copy-append", - .label = N_( "Add to copy" ), - .summary = N_("Append selection to clipboard"), - .description = N_("Append selected area to current clipboard contents"), - .key = 'c', - .mods = GDK_ALT_MASK, - .activate = fire_copy_accelerator - }, - - { - .flags = V3270_COPY_TEXT, - .group = LIB3270_ACTION_GROUP_SELECTION, - .name = "copy-text", - .icon = "edit-copy", - .label = N_( "Copy" ), - .summary = N_( "Copy as plain text" ), - .key = 'c', - .mods = GDK_SHIFT_MASK|GDK_CONTROL_MASK, - .activate = fire_copy_accelerator - }, - - { - .flags = V3270_COPY_TABLE, - .group = LIB3270_ACTION_GROUP_SELECTION, - .name = "copy-table", - .icon = "edit-copy", - .label = N_( "Copy as table" ), - .summary = N_( "Copy as table" ), - .key = 'c', - .mods = GDK_SHIFT_MASK|GDK_ALT_MASK, - .activate = fire_copy_accelerator - }, - - { - .flags = V3270_ACTION_FLAG_CUT|V3270_COPY_SMART, - .group = LIB3270_ACTION_GROUP_SELECTION, - .name = "cut", - .icon = "edit-cut", - .label = N_( "Cut" ), - .key = 'x', - .mods = GDK_CONTROL_MASK, - .activate = fire_copy_accelerator - }, - - { - .flags = V3270_ACTION_FLAG_CUT|V3270_COPY_APPEND, - .group = LIB3270_ACTION_GROUP_SELECTION, - .name = "cut-append", - .label = N_( "Cut" ), - .summary = N_( "Cut and append to copy" ), - .key = 'x', - .mods = GDK_ALT_MASK, - .activate = fire_copy_accelerator - }, - - { - .flags = V3270_ACTION_FLAG_CUT|V3270_COPY_TEXT, - .group = LIB3270_ACTION_GROUP_SELECTION, - .name = "cut-text", - .icon = "edit-cut", - .label = N_( "Cut" ), - .summary = N_( "Cut as plain text" ), - .key = 'x', - .mods = GDK_SHIFT_MASK|GDK_CONTROL_MASK, - .activate = fire_copy_accelerator - }, - - { - .flags = V3270_ACTION_FLAG_CUT|V3270_COPY_TABLE, - .group = LIB3270_ACTION_GROUP_SELECTION, - .name = "cut-table", - .icon = "edit-cut", - .label = N_( "Cut as table" ), - .summary = N_( "Cut as table" ), - .key = 'x', - .mods = GDK_SHIFT_MASK|GDK_ALT_MASK, - .activate = fire_copy_accelerator - }, - - { - .flags = 0, - .group = LIB3270_ACTION_GROUP_ONLINE, - .name = "paste", - .icon = "edit-paste", - .label = N_("Paste"), - .summary = N_("Paste clipboard contents"), - .description = N_("Input current clipboard contents to screen"), - .key = 'v', - .mods = GDK_CONTROL_MASK, - .activate = fire_paste_accelerator - }, - - { - .flags = 1, - .group = LIB3270_ACTION_GROUP_ONLINE, - .name = "paste-text", - .icon = "edit-paste", - .label = N_("Paste"), - .summary = N_("Paste as plain text"), - .key = 'v', - .mods = GDK_SHIFT_MASK|GDK_CONTROL_MASK, - .activate = fire_paste_accelerator - }, - - { - .flags = 2, - .group = LIB3270_ACTION_GROUP_ONLINE, - .name = "paste-file", - .label = N_("Paste file"), - .summary = N_("Paste from text file"), - .key = 'v', - .mods = GDK_ALT_MASK, - .activate = fire_paste_accelerator - }, - - { - .flags = 3, - .group = LIB3270_ACTION_GROUP_ONLINE, - .name = "paste-screen", - .label = N_("Paste formatted screen"), - .summary = N_("Paste similar screen from clipboard"), - .description = N_("Search clipboard for a similar screen, if found paste unprotected fields and restore cursor position"), - .key = 'v', - .mods = GDK_SHIFT_MASK|GDK_CONTROL_MASK|GDK_ALT_MASK, - .activate = fire_paste_accelerator - }, - - { - .flags = 0, - .group = LIB3270_ACTION_GROUP_ONLINE, - .name = "zoom-in", - .icon = "zoom-in", - .label = N_("Zoom in"), - .summary = N_("Increase the font size"), - .key = GDK_KP_Add, - .mods = GDK_CONTROL_MASK, - .activate = fire_zoom_action - }, - - { - .flags = 1, - .group = LIB3270_ACTION_GROUP_ONLINE, - .name = "zoom-out", - .label = N_("Zoom out"), - .summary = N_("decrease the font size"), - .icon = "zoom-out", - .key = GDK_KP_Subtract, - .mods = GDK_CONTROL_MASK, - .activate = fire_zoom_action - }, - - { - .flags = 2, - .group = LIB3270_ACTION_GROUP_ONLINE, - .name = "zoom-fit-best", - .label = N_("Fit best"), - .summary = N_("Set the font to the best size for window"), - .icon = "zoom-fit-best", - .key = '0', - .mods = GDK_CONTROL_MASK, - .activate = fire_zoom_action - }, - - // - // Save actions - // - { - .flags = -1, - .group = LIB3270_ACTION_GROUP_ONLINE, - .name = "save", - .icon = "document-save-as", - .label = N_("Save"), - .summary = N_("Save screen or selection"), - .activate = fire_save_action - - }, - - { - .flags = LIB3270_CONTENT_ALL, - .group = LIB3270_ACTION_GROUP_ONLINE, - .name = "save-all", - .label = N_("Save all"), - .icon = "document-save-as", - .summary = N_("Save screen"), - .activate = fire_save_action - - }, - - { - .flags = LIB3270_CONTENT_SELECTED, - .group = LIB3270_ACTION_GROUP_SELECTION, - .name = "save-selected", - .label = N_("Save selected"), - .icon = "document-save-as", - .summary = N_("Save selected area"), - .activate = fire_save_action - - }, - - { - .flags = LIB3270_CONTENT_COPY, - .group = LIB3270_ACTION_GROUP_COPY, - .name = "save-copy", - .label = N_("Save copy"), - .icon = "document-save-as", - .summary = N_("Save Copy"), - .activate = fire_save_action - - }, - - // - // Print actions - // - { - .flags = -1, - .group = LIB3270_ACTION_GROUP_ONLINE, - .name = "print", - .icon = "document-print", - .label = N_("Print"), - .summary = N_("Print screen or selection"), - .activate = fire_print_action - - }, - - { - .flags = LIB3270_CONTENT_ALL, - .group = LIB3270_ACTION_GROUP_ONLINE, - .name = "print-all", - .icon = "document-print", - .label = N_("Print screen"), - .summary = N_("Print the entire screen"), - .activate = fire_print_action - - }, - - { - .flags = LIB3270_CONTENT_SELECTED, - .group = LIB3270_ACTION_GROUP_SELECTION, - .name = "print-selected", - .icon = "document-print", - .label = N_("Print selected"), - .summary = N_("Print selected area"), - .activate = fire_print_action - - }, - - { - .flags = LIB3270_CONTENT_COPY, - .group = LIB3270_ACTION_GROUP_COPY, - .name = "print-copy", - .icon = "document-print", - .label = N_("Print Copy"), - .activate = fire_print_action - - }, - - { - .name = NULL - } - }; - - LIB3270_EXPORT const V3270_ACTION * v3270_get_actions() - { - return actions; - } - - static const gchar * get_icon_name(GAction *action) { - return GET_DESCRIPTOR(action)->icon; - } - - static const gchar * get_label(GAction *action) { - return GET_DESCRIPTOR(action)->label; - } - - static const gchar * get_tooltip(GAction *action) { - return GET_DESCRIPTOR(action)->summary; - } - - static const gchar * get_name(GAction *action) { - return GET_DESCRIPTOR(action)->name; - } - - static void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { - - debug("Activating action \"%s\"",g_action_get_name(action)); - - const V3270_ACTION *descriptor = GET_DESCRIPTOR(action); + static int fire_kp_add_action(GtkWidget *widget, const struct _v3270_action * action); + static int fire_kp_sub_action(GtkWidget *widget, const struct _v3270_action * action); + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + LIB3270_EXPORT const V3270_ACTION * v3270_get_actions() { + + static const V3270_ACTION actions[] = { + { + .name = "keypad-add", + .keys = "KP_Add", + .group = LIB3270_ACTION_GROUP_ONLINE, + .activate = fire_kp_add_action + }, + { + .name = "keypad-subtract", + .keys = "KP_Subtract", + .group = LIB3270_ACTION_GROUP_ONLINE, + .activate = fire_kp_sub_action + }, + + // Standard Clipboard actions + { + .flags = V3270_COPY_SMART, + .name = "copy", + .keys = "c", + .group = LIB3270_ACTION_GROUP_SELECTION, + .icon = "edit-copy", + .label = N_( "Copy" ), + .summary = N_("Copy selection to clipboard"), + .description = N_("Replace current clipboard contents with the selected area"), + .activate = fire_copy_accelerator + }, + + { + .name = "copy-append", + .keys = "c", + .flags = V3270_COPY_APPEND, + .group = LIB3270_ACTION_GROUP_SELECTION, + .label = N_( "Add to copy" ), + .summary = N_("Append selection to clipboard"), + .description = N_("Append selected area to current clipboard contents"), + .activate = fire_copy_accelerator + }, + + { + .name = "copy-text", + .keys = "c", + .flags = V3270_COPY_TEXT, + .group = LIB3270_ACTION_GROUP_SELECTION, + .icon = "edit-copy", + .label = N_( "Copy" ), + .summary = N_( "Copy as plain text" ), + .activate = fire_copy_accelerator + }, + + { + .name = "copy-table", + .keys = "c", + .flags = V3270_COPY_TABLE, + .group = LIB3270_ACTION_GROUP_SELECTION, + .icon = "edit-copy", + .label = N_( "Copy as table" ), + .summary = N_( "Copy as table" ), + .activate = fire_copy_accelerator + }, + + { + .name = "cut", + .keys = "x", + .flags = V3270_ACTION_FLAG_CUT|V3270_COPY_SMART, + .group = LIB3270_ACTION_GROUP_SELECTION, + .icon = "edit-cut", + .label = N_( "Cut" ), + .activate = fire_copy_accelerator + }, + + { + .name = "cut-append", + .keys = "x", + .flags = V3270_ACTION_FLAG_CUT|V3270_COPY_APPEND, + .group = LIB3270_ACTION_GROUP_SELECTION, + .label = N_( "Cut" ), + .summary = N_( "Cut and append to copy" ), + .activate = fire_copy_accelerator + }, + + { + .name = "cut-text", + .keys = "x", + .flags = V3270_ACTION_FLAG_CUT|V3270_COPY_TEXT, + .group = LIB3270_ACTION_GROUP_SELECTION, + .icon = "edit-cut", + .label = N_( "Cut" ), + .summary = N_( "Cut as plain text" ), + .activate = fire_copy_accelerator + }, + + { + .name = "cut-table", + .keys = "x", + .flags = V3270_ACTION_FLAG_CUT|V3270_COPY_TABLE, + .group = LIB3270_ACTION_GROUP_SELECTION, + .icon = "edit-cut", + .label = N_( "Cut as table" ), + .summary = N_( "Cut as table" ), + .activate = fire_copy_accelerator + }, + + { + .name = "paste", + .keys = "v", + .flags = 0, + .group = LIB3270_ACTION_GROUP_ONLINE, + .icon = "edit-paste", + .label = N_("Paste"), + .summary = N_("Paste clipboard contents"), + .description = N_("Input current clipboard contents to screen"), + .activate = fire_paste_accelerator + }, + + { + .name = "paste-text", + .keys = "v", + .flags = 1, + .group = LIB3270_ACTION_GROUP_ONLINE, + .icon = "edit-paste", + .label = N_("Paste"), + .summary = N_("Paste as plain text"), + .activate = fire_paste_accelerator + }, + + { + .name = "paste-file", + .keys = "v", + .flags = 2, + .group = LIB3270_ACTION_GROUP_ONLINE, + .label = N_("Paste file"), + .summary = N_("Paste from text file"), + .activate = fire_paste_accelerator + }, + + { + .name = "paste-screen", + .keys = "v", + .flags = 3, + .group = LIB3270_ACTION_GROUP_ONLINE, + .label = N_("Paste formatted screen"), + .summary = N_("Paste similar screen from clipboard"), + .description = N_("Search clipboard for a similar screen, if found paste unprotected fields and restore cursor position"), + .activate = fire_paste_accelerator + }, + + { + .name = "zoom-in", + .keys = "v", + .flags = 0, + .group = LIB3270_ACTION_GROUP_ONLINE, + .icon = "zoom-in", + .label = N_("Zoom in"), + .summary = N_("Increase the font size"), + .activate = fire_zoom_action + }, + + { + .name = "zoom-out", + .keys = "KP_Subtract", + .flags = 1, + .group = LIB3270_ACTION_GROUP_ONLINE, + .label = N_("Zoom out"), + .summary = N_("decrease the font size"), + .icon = "zoom-out", + .activate = fire_zoom_action + }, + + { + .name = "zoom-fit-best", + .keys = "0", + .flags = 2, + .group = LIB3270_ACTION_GROUP_ONLINE, + .label = N_("Fit best"), + .summary = N_("Set the font to the best size for window"), + .icon = "zoom-fit-best", + .activate = fire_zoom_action + }, + + // + // Save actions + // + { + .flags = -1, + .group = LIB3270_ACTION_GROUP_ONLINE, + .name = "save", + .icon = "document-save-as", + .label = N_("Save"), + .summary = N_("Save screen or selection"), + .activate = fire_save_action + + }, + + { + .flags = LIB3270_CONTENT_ALL, + .group = LIB3270_ACTION_GROUP_ONLINE, + .name = "save-all", + .label = N_("Save all"), + .icon = "document-save-as", + .summary = N_("Save screen"), + .activate = fire_save_action + + }, + + { + .flags = LIB3270_CONTENT_SELECTED, + .group = LIB3270_ACTION_GROUP_SELECTION, + .name = "save-selected", + .label = N_("Save selected"), + .icon = "document-save-as", + .summary = N_("Save selected area"), + .activate = fire_save_action + + }, + + { + .flags = LIB3270_CONTENT_COPY, + .group = LIB3270_ACTION_GROUP_COPY, + .name = "save-copy", + .label = N_("Save copy"), + .icon = "document-save-as", + .summary = N_("Save Copy"), + .activate = fire_save_action + + }, + + // + // Print actions + // + { + .flags = -1, + .group = LIB3270_ACTION_GROUP_ONLINE, + .name = "print", + .icon = "document-print", + .label = N_("Print"), + .summary = N_("Print screen or selection"), + .activate = fire_print_action + + }, + + { + .flags = LIB3270_CONTENT_ALL, + .group = LIB3270_ACTION_GROUP_ONLINE, + .name = "print-all", + .icon = "document-print", + .label = N_("Print screen"), + .summary = N_("Print the entire screen"), + .activate = fire_print_action + + }, + + { + .flags = LIB3270_CONTENT_SELECTED, + .group = LIB3270_ACTION_GROUP_SELECTION, + .name = "print-selected", + .icon = "document-print", + .label = N_("Print selected"), + .summary = N_("Print selected area"), + .activate = fire_print_action + + }, + + { + .flags = LIB3270_CONTENT_COPY, + .group = LIB3270_ACTION_GROUP_COPY, + .name = "print-copy", + .icon = "document-print", + .label = N_("Print Copy"), + .activate = fire_print_action + + }, + + { + .name = NULL + } + }; - descriptor->activate(terminal,descriptor); + return actions; } - static LIB3270_ACTION_GROUP get_action_group(GAction *action) { - return GET_DESCRIPTOR(action)->group; - } + int fire_kp_add_action(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { - static void V270InternalAction_class_init(V270InternalActionClass *klass) { + if(v3270_get_toggle(widget,LIB3270_TOGGLE_KP_ALTERNATIVE)) + return lib3270_nextfield(GTK_V3270(widget)->host); - klass->parent_class.get_name = get_name; - klass->parent_class.get_icon_name = get_icon_name; - klass->parent_class.get_label = get_label; - klass->parent_class.get_tooltip = get_tooltip; - klass->parent_class.activate = activate; - klass->parent_class.get_action_group = get_action_group; + v3270_set_string(widget, "+"); - } + return 0; - static void V270InternalAction_init(V270InternalAction G_GNUC_UNUSED(*action)) { } - void g_action_map_add_v3270_actions(GActionMap *action_map) { - - const V3270_ACTION * actions = v3270_get_actions(); - size_t ix; - - for(ix = 0; actions[ix].name; ix++) { + int fire_kp_sub_action(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { - V270InternalAction * action = V3270_INTERNAL_ACTION(g_object_new(LIB3270_TYPE_V3270_INTERNAL_ACTION, NULL)); + if(v3270_get_toggle(widget,LIB3270_TOGGLE_KP_ALTERNATIVE)) + return lib3270_previousfield(GTK_V3270(widget)->host); - action->definition = &actions[ix]; - action->parent.translation_domain = GETTEXT_PACKAGE; + v3270_set_string(widget, "-"); - if(!g_action_get_name(G_ACTION(action))) { - g_warning("Action \"%s\" is invalid",actions[ix].name); - } else { - g_action_map_add_action(action_map,G_ACTION(action)); - } - - } + return 0; } - diff --git a/src/terminal/keyboard/init.c b/src/terminal/keyboard/init.c index e5d0c24..5694978 100644 --- a/src/terminal/keyboard/init.c +++ b/src/terminal/keyboard/init.c @@ -68,27 +68,6 @@ return lib3270_toggle(v3270_get_session(widget),action->id); } - int fire_keypad_action(GtkWidget *widget, const struct _v3270_action * action) - { - int rc = 0; - debug("%s",__FUNCTION__); - - if(v3270_get_toggle(widget,LIB3270_TOGGLE_KP_ALTERNATIVE)) - { - if(action->key == GDK_KP_Add) - rc = lib3270_nextfield(GTK_V3270(widget)->host); - else - rc = lib3270_previousfield(GTK_V3270(widget)->host); - } - else - { - v3270_set_string(widget, action->key == GDK_KP_Add ? "+" : "-"); - } - - return rc; - - } - static int fire_pfkey_action(GtkWidget *widget, V3270PFKeyAccelerator *accel) { debug("%s accel=%p",__FUNCTION__,accel); @@ -175,17 +154,42 @@ for(ix = 0 ; actions[ix].name; ix++) { - V3270Accelerator * accelerator = g_new0(V3270Accelerator,1); + if(actions[ix].keys && *actions[ix].keys) + { + size_t key; - accelerator->type = V3270_ACCELERATOR_TYPE_INTERNAL; - accelerator->arg = (gconstpointer) &actions[ix]; - accelerator->activate = G_CALLBACK(actions[ix].activate); - accelerator->key = actions[ix].key; - accelerator->mods = actions[ix].mods; + gchar ** keys = g_strsplit(actions[ix].keys,",",-1); - widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); + for(key = 0; keys[key]; key++) + { + V3270Accelerator * accelerator = g_new0(V3270Accelerator,1); + accelerator->type = V3270_ACCELERATOR_TYPE_INTERNAL; + accelerator->arg = (gconstpointer) &actions[ix]; + accelerator->activate = G_CALLBACK(actions[ix].activate); + + gtk_accelerator_parse(keys[key],&accelerator->key,&accelerator->mods); + + widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); + + } + + g_strfreev(keys); + + } + else + { + V3270Accelerator * accelerator = g_new0(V3270Accelerator,1); + + accelerator->type = V3270_ACCELERATOR_TYPE_INTERNAL; + accelerator->arg = (gconstpointer) &actions[ix]; + accelerator->activate = G_CALLBACK(actions[ix].activate); + + widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); + + } } + } // Create PF-Key accelerators diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index ab9692b..24bafad 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -40,6 +40,7 @@ #include #include #include + #include #include #include #include @@ -130,6 +131,9 @@ GtkWidget * vBox = gtk_box_new(GTK_ORIENTATION_VERTICAL,2); GtkWidget * notebook = gtk_notebook_new(); + // Hack to speed up the tests. +// lib3270_disable_crl_download(v3270_get_session(terminal)); + gtk_box_pack_start(GTK_BOX(vBox),create_toolbar(terminal),FALSE,TRUE,0); gtk_box_pack_start(GTK_BOX(vBox),notebook,TRUE,TRUE,0); diff --git a/v3270.cbp b/v3270.cbp index fdeab59..99c6cbb 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -250,6 +250,9 @@ + + -- libgit2 0.21.2