From 925acbf87ecfe2ab76681ffb12b332eb5e4458eb Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Tue, 11 Jun 2013 13:24:27 +0000 Subject: [PATCH] Implementando métodos para que um script rexx possa alterar o clipboard salvo --- src/include/lib3270.h | 1 + src/include/pw3270/v3270.h | 1 + src/lib3270/util.c | 15 +++++++++++++++ src/plugins/rx3270/pluginmain.cc | 14 ++++++++++++++ src/plugins/rx3270/rx3270.cc | 11 +++++++++++ src/plugins/rx3270/rx3270.h | 3 +++ src/pw3270/v3270/selection.c | 35 +++++++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 0 deletions(-) diff --git a/src/include/lib3270.h b/src/include/lib3270.h index cf68b82..d67eb1a 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -960,6 +960,7 @@ LIB3270_EXPORT void * lib3270_malloc(int len); LIB3270_EXPORT void * lib3270_realloc(void *p, int len); LIB3270_EXPORT void * lib3270_replace(void **p, void *ptr); + LIB3270_EXPORT void * lib3270_strdup(const char *str); /** * Release allocated memory. diff --git a/src/include/pw3270/v3270.h b/src/include/pw3270/v3270.h index 92a0b4a..699ac4b 100644 --- a/src/include/pw3270/v3270.h +++ b/src/include/pw3270/v3270.h @@ -172,6 +172,7 @@ LIB3270_EXPORT void v3270_copy_append(GtkWidget *widget); LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut); LIB3270_EXPORT gchar * v3270_get_copy(GtkWidget *widget); + LIB3270_EXPORT void v3270_set_copy(GtkWidget *widget, const gchar *text); LIB3270_EXPORT int v3270_run_script(GtkWidget *widget, const gchar *script); diff --git a/src/lib3270/util.c b/src/lib3270/util.c index 5895599..99b552e 100644 --- a/src/lib3270/util.c +++ b/src/lib3270/util.c @@ -929,6 +929,21 @@ LIB3270_EXPORT void * lib3270_malloc(int len) return r; } +LIB3270_EXPORT void * lib3270_strdup(const char *str) +{ + char *r; + + r = strdup(str); + if (r == (char *)NULL) + { + Error(NULL,"Out of memory in %s",__FUNCTION__); + return 0; + } + + return r; +} + + LIB3270_EXPORT char * lib3270_get_resource_string(H3270 *hSession, const char *first_element, ...) { #ifdef ANDROID diff --git a/src/plugins/rx3270/pluginmain.cc b/src/plugins/rx3270/pluginmain.cc index a5a017b..a35ef06 100644 --- a/src/plugins/rx3270/pluginmain.cc +++ b/src/plugins/rx3270/pluginmain.cc @@ -94,6 +94,9 @@ int get_field_start(int baddr = -1); int get_field_len(int baddr = -1); + int set_copy(const char *text); + char * get_copy(void); + private: H3270 *hSession; @@ -244,6 +247,17 @@ return lib3270_get_field_len(hSession,baddr); } + int plugin::set_copy(const char *text) + { + v3270_set_copy(GTK_WIDGET(lib3270_get_widget(hSession)),text); + return 0; + } + + char * plugin::get_copy(void) + { + return v3270_get_copy(GTK_WIDGET(lib3270_get_widget(hSession))); + } + static int REXXENTRY Rexx_IO_exit(RexxExitContext *context, int exitnumber, int subfunction, PEXIT parmBlock) { trace("%s call with ExitNumber: %d Subfunction: %d",__FUNCTION__,(int) exitnumber, (int) subfunction); diff --git a/src/plugins/rx3270/rx3270.cc b/src/plugins/rx3270/rx3270.cc index 3cb61a1..2c1cdc8 100644 --- a/src/plugins/rx3270/rx3270.cc +++ b/src/plugins/rx3270/rx3270.cc @@ -154,6 +154,17 @@ void rx3270::set_plugin(void) plugin = true; } +int rx3270::set_copy(const char *text) +{ + return EINVAL; +} + +char * rx3270::get_copy(void) +{ + errno = EINVAL; + return NULL; +} + diff --git a/src/plugins/rx3270/rx3270.h b/src/plugins/rx3270/rx3270.h index 98c317a..94e4b02 100644 --- a/src/plugins/rx3270/rx3270.h +++ b/src/plugins/rx3270/rx3270.h @@ -171,6 +171,9 @@ virtual int get_field_start(int baddr = -1) = 0; virtual int get_field_len(int baddr = -1) = 0; + virtual int set_copy(const char *text); + virtual char * get_copy(void); + }; rx3270 * create_lib3270_instance(void); diff --git a/src/pw3270/v3270/selection.c b/src/pw3270/v3270/selection.c index c79f4a0..7beb3e4 100644 --- a/src/pw3270/v3270/selection.c +++ b/src/pw3270/v3270/selection.c @@ -244,6 +244,41 @@ gchar * v3270_get_copy(GtkWidget *widget) return NULL; } +void v3270_set_copy(GtkWidget *widget, const gchar *text) +{ + v3270 * terminal; + gchar * isotext; + + g_return_if_fail(GTK_IS_V3270(widget)); + + terminal = GTK_V3270(widget); + v3270_clear_clipboard(terminal); + + if(!text) + { + /* No string, signal clipboard clear and return */ + g_signal_emit(widget,v3270_widget_signal[SIGNAL_CLIPBOARD], 0, FALSE); + return; + } + + /* Received text, replace the selection buffer */ + terminal->table = 0; + isotext = g_convert(text, -1, lib3270_get_charset(terminal->host), "UTF-8", NULL, NULL, NULL); + + if(!isotext) + { + /* No string, signal clipboard clear and return */ + g_signal_emit(widget,v3270_widget_signal[SIGNAL_CLIPBOARD], 0, FALSE); + return; + } + + terminal->selection.text = lib3270_strdup(isotext); + + g_free(isotext); + + g_signal_emit(widget,v3270_widget_signal[SIGNAL_CLIPBOARD], 0, TRUE); +} + static void update_system_clipboard(GtkWidget *widget) { if(GTK_V3270(widget)->selection.text) -- libgit2 0.21.2