From 06f4b00a3546162c12fe77edc6665200d6f2287a Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 28 Nov 2019 10:03:55 -0300 Subject: [PATCH] Implementing keyboard actions. --- src/selection/linux/paste.c | 2 ++ src/terminal/keyboard/accelerator.c | 13 ++++--------- src/terminal/keyboard/clipboard.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/terminal/keyboard/init.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- src/terminal/keyboard/private.h | 19 ++++++++++++++++--- src/testprogram/testprogram.c | 4 ++-- v3270.cbp | 3 +++ 7 files changed, 164 insertions(+), 23 deletions(-) create mode 100644 src/terminal/keyboard/clipboard.c diff --git a/src/selection/linux/paste.c b/src/selection/linux/paste.c index 8f5bc4f..30a2257 100644 --- a/src/selection/linux/paste.c +++ b/src/selection/linux/paste.c @@ -240,11 +240,13 @@ LIB3270_EXPORT void v3270_clipboard_get_from_url(GtkWidget *widget, const gchar LIB3270_EXPORT void v3270_paste(GtkWidget *widget) { + debug("%s",__FUNCTION__); v3270_clipboard_get_from_url(widget,NULL); } LIB3270_EXPORT void v3270_paste_text(GtkWidget *widget) { + debug("%s",__FUNCTION__); v3270_clipboard_get_from_url(widget,"text://"); } diff --git a/src/terminal/keyboard/accelerator.c b/src/terminal/keyboard/accelerator.c index ea274da..66515bf 100644 --- a/src/terminal/keyboard/accelerator.c +++ b/src/terminal/keyboard/accelerator.c @@ -81,16 +81,8 @@ { GSList * ix; - debug("%s: %u %u",__FUNCTION__,(unsigned int) keyval, (unsigned int) state); - for(ix = GTK_V3270(widget)->accelerators; ix; ix = g_slist_next(ix)) { - debug( - "%s: %u %u", - v3270_accelerator_get_name((V3270Accelerator *) ix->data), - (unsigned int) ((V3270Accelerator *) ix->data)->key, - (unsigned int) ((V3270Accelerator *) ix->data)->mods - ); if(v3270_accelerator_compare((V3270Accelerator *) ix->data, keyval, state)) return (V3270Accelerator *) ix->data; } @@ -119,7 +111,10 @@ switch(accel->type) { case V3270_ACCELERATOR_TYPE_LIB3270_ACTION: - return gettext(((LIB3270_ACTION *) accel->arg)->name); + return ((LIB3270_ACTION *) accel->arg)->name; + + case V3270_ACCELERATOR_TYPE_INTERNAL: + return ((struct InternalAction *) accel->arg)->name; case V3270_ACCELERATOR_TYPE_CUSTOM: return ((V3270CustomAccelerator *) accel)->name; diff --git a/src/terminal/keyboard/clipboard.c b/src/terminal/keyboard/clipboard.c new file mode 100644 index 0000000..b9b2362 --- /dev/null +++ b/src/terminal/keyboard/clipboard.c @@ -0,0 +1,74 @@ +/* + * "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 + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + int fire_copy_accelerator(GtkWidget *widget, const struct InternalAction * action) { + + debug("%s",__FUNCTION__); + + v3270_clipboard_set( + widget, + (action->operation & 0x0F), + (action->operation & ACCEL_OPERATION_CUT) != 0 + ); + + return EINVAL; + } + + int fire_paste_accelerator(GtkWidget *widget, const struct InternalAction * action) { + + + switch(action->operation) + { + case 0: // Default paste. + v3270_clipboard_get_from_url(widget,NULL); + break; + + case 1: // Text paste. + v3270_clipboard_get_from_url(widget,"text://"); + break; + + case 2: // File paste. + v3270_clipboard_get_from_url(widget,"file://"); + break; + + default: + g_warning("Unexpected paste operation %u",(unsigned int) action->operation); + } + + return 0; + } + + diff --git a/src/terminal/keyboard/init.c b/src/terminal/keyboard/init.c index 6ca44c0..3583f23 100644 --- a/src/terminal/keyboard/init.c +++ b/src/terminal/keyboard/init.c @@ -46,15 +46,71 @@ static const struct InternalAction InternalActions[] = { { - GDK_KP_Add, - GDK_NUMLOCK_MASK, - G_CALLBACK(fire_keypad_action) + .name = "keypad-add", + .key = GDK_KP_Add, + .mods = GDK_NUMLOCK_MASK, + .activate = G_CALLBACK(fire_keypad_action) }, { - GDK_KP_Subtract, - GDK_NUMLOCK_MASK, - G_CALLBACK(fire_keypad_action) - } + .name = "keypad-subtract", + .key = GDK_KP_Subtract, + .mods = GDK_NUMLOCK_MASK, + .activate = G_CALLBACK(fire_keypad_action) + }, + + // Standard Clipboard actions + { + .operation = V3270_COPY_DEFAULT, + .name = "copy", + .key = 'c', + .mods = GDK_CONTROL_MASK, + .activate = G_CALLBACK(fire_copy_accelerator) + }, + + /* + { + .operation = V3270_COPY_APPEND, + .name = "copy-append", + .key = 'c', + .mods = GDK_CONTROL_MASK|GDK_ALT_MASK, + .activate = G_CALLBACK(fire_copy_accelerator) + }, + */ + + { + .operation = V3270_COPY_TEXT, + .name = "copy-text", + .key = 'c', + .mods = GDK_SHIFT_MASK|GDK_CONTROL_MASK, + .activate = G_CALLBACK(fire_copy_accelerator) + }, + + { + .operation = ACCEL_OPERATION_CUT|V3270_COPY_DEFAULT, + .name = "cut", + .key = 'x', + .mods = GDK_CONTROL_MASK, + .activate = G_CALLBACK(fire_copy_accelerator) + }, + + /* + { + .operation = ACCEL_OPERATION_CUT|V3270_COPY_APPEND, + .name = "cut-append", + .key = 0, + .mods = 0, + .activate = G_CALLBACK(fire_copy_accelerator) + }, + */ + + { + .operation = ACCEL_OPERATION_DEFAULT, + .name = "paste", + .key = 'v', + .mods = GDK_CONTROL_MASK, + .activate = G_CALLBACK(fire_paste_accelerator) + }, + }; /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -160,5 +216,3 @@ } - - diff --git a/src/terminal/keyboard/private.h b/src/terminal/keyboard/private.h index 7e9e581..21d2aec 100644 --- a/src/terminal/keyboard/private.h +++ b/src/terminal/keyboard/private.h @@ -32,12 +32,25 @@ #include #include + enum + { + ACCEL_OPERATION_DEFAULT = 0x00000000, + ACCEL_OPERATION_CUT = 0x10000000, + }; + + #define ACCEL_OPERATION_MASK (ACCEL_OPERATION_CUT|ACCEL_OPERATION_APPEND) + struct InternalAction { - guint key; - GdkModifierType mods; - GCallback activate; + unsigned int operation; + const gchar * name; + guint key; + GdkModifierType mods; + GCallback activate; }; G_GNUC_INTERNAL void v3270_accelerator_map_sort(v3270 *widget); + G_GNUC_INTERNAL int fire_copy_accelerator(GtkWidget *widget, const struct InternalAction * action); + G_GNUC_INTERNAL int fire_paste_accelerator(GtkWidget *widget, const struct InternalAction * action); + diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index f13791f..a4bdcef 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -174,8 +174,8 @@ } // Set accelerators - v3270_accelerator_map_add_entry(terminal, "copy", 'c', GDK_CONTROL_MASK, G_CALLBACK(accel_copy), window); - v3270_accelerator_map_add_entry(terminal, "paste", 'v', GDK_CONTROL_MASK, G_CALLBACK(accel_paste), window); + // v3270_accelerator_map_add_entry(terminal, "copy", 'c', GDK_CONTROL_MASK, G_CALLBACK(accel_copy), window); + // v3270_accelerator_map_add_entry(terminal, "paste", 'v', GDK_CONTROL_MASK, G_CALLBACK(accel_paste), window); // Create trace window v3270_set_trace(terminal,TRUE); diff --git a/v3270.cbp b/v3270.cbp index 8027aed..3387c03 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -271,6 +271,9 @@ + + -- libgit2 0.21.2