diff --git a/pw3270.cbp b/pw3270.cbp
index 71601d1..0e4dde3 100644
--- a/pw3270.cbp
+++ b/pw3270.cbp
@@ -290,6 +290,7 @@
+
diff --git a/src/plugins/dbus3270/gobject.c b/src/plugins/dbus3270/gobject.c
index 899d358..09114a3 100644
--- a/src/plugins/dbus3270/gobject.c
+++ b/src/plugins/dbus3270/gobject.c
@@ -326,7 +326,7 @@ void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *cont
dbus_g_method_return(context,lib3270_get_field_start(pw3270_dbus_get_session_handle(object),baddr));
}
-void pw3270_dbus_get_field_len(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context)
+void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context)
{
trace("%s object=%p context=%p",__FUNCTION__,object,context);
dbus_g_method_return(context,lib3270_get_field_len(pw3270_dbus_get_session_handle(object),baddr));
diff --git a/src/plugins/rx3270/local.cc b/src/plugins/rx3270/local.cc
index 1012543..17f8c0d 100644
--- a/src/plugins/rx3270/local.cc
+++ b/src/plugins/rx3270/local.cc
@@ -123,6 +123,7 @@
rx3270 * rx3270::create_local(void)
{
+ trace("%s",__FUNCTION__);
return new dynamic();
}
@@ -362,6 +363,8 @@ dynamic::~dynamic()
{
static void (*session_free)(void *h);
+ trace("%s",__FUNCTION__);
+
if(!hModule)
return;
diff --git a/src/plugins/rx3270/pluginmain.cc b/src/plugins/rx3270/pluginmain.cc
index a35ef06..e6179a8 100644
--- a/src/plugins/rx3270/pluginmain.cc
+++ b/src/plugins/rx3270/pluginmain.cc
@@ -64,6 +64,9 @@
{
public:
plugin(H3270 *hSession);
+ virtual ~plugin();
+
+ void free(char *ptr);
char * get_version(void);
LIB3270_CSTATE get_cstate(void);
@@ -97,37 +100,41 @@
int set_copy(const char *text);
char * get_copy(void);
+ char * get_clipboard(void);
+
+ protected:
+
private:
- H3270 *hSession;
+ H3270 * hSession;
};
/*--[ Globals ]--------------------------------------------------------------------------------------*/
- static plugin * session = NULL;
#if GTK_CHECK_VERSION(2,32,0)
+#if GTK_CHECK_VERSION(2,32,0)
static GMutex mutex;
#else
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
#endif // GTK_CHECK_VERSION
/*--[ Implement ]------------------------------------------------------------------------------------*/
- LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window)
+ static rx3270 * factory(const char *name)
{
+ return new plugin(lib3270_get_default_session_handle());
+ }
+
+ LIB3270_EXPORT int pw3270_plugin_start(GtkWidget *window)
+ {
+ trace("%s",__FUNCTION__);
#if GTK_CHECK_VERSION(2,32,0)
g_mutex_init(&mutex);
#endif // GTK_CHECK_VERSION
- session = new plugin(lib3270_get_default_session_handle());
- session->set_plugin();
- trace("%s: Rexx object is %p",__FUNCTION__,session);
+ rx3270::set_plugin(factory);
return 0;
}
- LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window)
+ LIB3270_EXPORT int pw3270_plugin_stop(GtkWidget *window)
{
- if(session)
- {
- delete session;
- session = NULL;
- }
#if GTK_CHECK_VERSION(2,32,0)
g_mutex_clear(&mutex);
#endif // GTK_CHECK_VERSION
+ trace("%s",__FUNCTION__);
return 0;
}
@@ -136,6 +143,12 @@
this->hSession = hSession;
}
+ plugin::~plugin()
+ {
+ trace("%s",__FUNCTION__);
+ }
+
+
char * plugin::get_version(void)
{
return strdup(lib3270_get_version());
@@ -258,6 +271,17 @@
return v3270_get_copy(GTK_WIDGET(lib3270_get_widget(hSession)));
}
+ char * plugin::get_clipboard(void)
+ {
+ trace("%s toplevel=%p",__FUNCTION__,pw3270_get_toplevel());
+ return gtk_clipboard_wait_for_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD));
+ }
+
+ void plugin::free(char *ptr)
+ {
+ g_free(ptr);
+ }
+
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);
@@ -324,6 +348,8 @@
{
RexxArrayObject rxArgs;
+ trace("%s start",__FUNCTION__);
+
if(args)
{
gchar **arg = g_strsplit(args,",",-1);
@@ -381,6 +407,8 @@
}
instance->Terminate();
+
+ trace("%s ends",__FUNCTION__);
}
}
diff --git a/src/plugins/rx3270/rexx_methods.cc b/src/plugins/rx3270/rexx_methods.cc
index 036d433..56603b3 100644
--- a/src/plugins/rx3270/rexx_methods.cc
+++ b/src/plugins/rx3270/rexx_methods.cc
@@ -49,8 +49,13 @@ RexxMethod1(int, rx3270_method_init, CSTRING, type)
RexxMethod1(int, rx3270_method_uninit, CSELF, sessionPtr)
{
rx3270 *hSession = (rx3270 *) sessionPtr;
+
+ trace("rx3270_method_uninit hSession=%p",hSession);
+
if(hSession)
delete hSession;
+
+ trace("%s","rx3270_method_uninit");
return 0;
}
@@ -373,3 +378,61 @@ RexxMethod2(int, rx3270_method_get_field_start, CSELF, sessionPtr, OPTIONAL_int,
return -1;
return hSession->get_field_start(baddr);
}
+
+RexxMethod1(RexxStringObject, rx3270_method_get_selection, CSELF, sessionPtr)
+{
+ rx3270 * hSession = (rx3270 *) sessionPtr;
+
+ if(hSession)
+ {
+ char *str = hSession->get_copy();
+ if(str)
+ {
+ char * text = hSession->get_local_string(str);
+ RexxStringObject ret = context->String((CSTRING) text);
+ free(str);
+ free(text);
+ return ret;
+ }
+ }
+
+ return context->String("");
+}
+
+RexxMethod2(int, rx3270_method_set_selection, CSELF, sessionPtr, CSTRING, text)
+{
+ rx3270 * session = (rx3270 *) sessionPtr;
+
+ if(session)
+ {
+ char * str = session->get_3270_string(text);
+ int rc;
+ rc = session->set_copy(str);
+ free(str);
+ return rc;
+ }
+ return -1;
+}
+
+RexxMethod1(RexxStringObject, rx3270_method_get_clipboard, CSELF, sessionPtr)
+{
+ rx3270 * hSession = (rx3270 *) sessionPtr;
+
+ if(hSession)
+ {
+ char *str = hSession->get_clipboard();
+
+ trace("str=%p (%s)",str,str);
+
+ if(str)
+ {
+ RexxStringObject ret = context->String((CSTRING) str);
+ hSession->free(str);
+ return ret;
+ }
+ }
+
+ trace("%s","rx3270_method_get_clipboard: Clipboard is empty");
+ return context->String("");
+}
+
diff --git a/src/plugins/rx3270/rx3270.cc b/src/plugins/rx3270/rx3270.cc
index 2c1cdc8..1dcc9b1 100644
--- a/src/plugins/rx3270/rx3270.cc
+++ b/src/plugins/rx3270/rx3270.cc
@@ -45,10 +45,13 @@
#include
+
+ static rx3270 * factory_default(const char *type);
+
/*--[ Globals ]--------------------------------------------------------------------------------------*/
- static bool plugin = false;
- static rx3270 * defSession = NULL;
+ static rx3270 * defSession = NULL;
+ static rx3270 * (*factory)(const char *type) = factory_default;
/*--[ Implement ]------------------------------------------------------------------------------------*/
@@ -86,13 +89,21 @@ rx3270::~rx3270()
if(defSession == this)
defSession = NULL;
+
+ trace("%s",__FUNCTION__);
}
-rx3270 * rx3270::create(const char *name)
+static rx3270 * factory_default(const char *type)
{
- if(name && *name)
- return create_remote(name);
- return create_local();
+ trace("%s",__FUNCTION__);
+ if(type && *type)
+ return rx3270::create_remote(type);
+ return rx3270::create_local();
+}
+
+rx3270 * rx3270::create(const char *type)
+{
+ return factory(type);
}
char * rx3270::get_version(void)
@@ -149,9 +160,15 @@ int rx3270::wait_for_text_at(int row, int col, const char *key, int timeout)
return ETIMEDOUT;
}
-void rx3270::set_plugin(void)
+void rx3270::set_plugin(rx3270 * (*ptr)(const char *name))
{
- plugin = true;
+ trace("%s factory=%p",__FUNCTION__,ptr);
+
+ if(ptr)
+ factory = ptr;
+ else
+ factory = factory_default;
+
}
int rx3270::set_copy(const char *text)
@@ -165,6 +182,15 @@ char * rx3270::get_copy(void)
return NULL;
}
+char * rx3270::get_clipboard(void)
+{
+ errno = EINVAL;
+ return NULL;
+}
+void rx3270::free(char *ptr)
+{
+ free(ptr);
+}
diff --git a/src/plugins/rx3270/rx3270.cls b/src/plugins/rx3270/rx3270.cls
index f7a1596..6f7a46b 100644
--- a/src/plugins/rx3270/rx3270.cls
+++ b/src/plugins/rx3270/rx3270.cls
@@ -33,7 +33,6 @@
::class rx3270 public subclass object
-
::METHOD INIT EXTERNAL "LIBRARY rx3270 rx3270_method_init"
::METHOD UNINIT EXTERNAL "LIBRARY rx3270 rx3270_method_uninit"
@@ -71,15 +70,10 @@
::METHOD GETFIELDSTART EXTERNAL "LIBRARY rx3270 rx3270_method_get_field_start"
::METHOD GETFIELDLEN EXTERNAL "LIBRARY rx3270 rx3270_method_get_field_len"
-/*
-getConnectionState
-waitForEvents
-RunMode
-
-::method isConnected
-return self~getConnectionState() = "CONNECTED_TN3270E"
+::METHOD GETSELECTION EXTERNAL "LIBRARY rx3270 rx3270_method_get_selection"
+::METHOD SETSELECTION EXTERNAL "LIBRARY rx3270 rx3270_method_set_selection"
-*/
+::METHOD GETCLIPBOARD EXTERNAL "LIBRARY rx3270 rx3270_method_get_clipboard"
::method waitForStringAt
use arg row, col, key, timeout
diff --git a/src/plugins/rx3270/rx3270.h b/src/plugins/rx3270/rx3270.h
index 94e4b02..64ad9bd 100644
--- a/src/plugins/rx3270/rx3270.h
+++ b/src/plugins/rx3270/rx3270.h
@@ -105,6 +105,12 @@
REXX_METHOD_PROTOTYPE(rx3270_method_set_option);
REXX_METHOD_PROTOTYPE(rx3270_method_test);
REXX_METHOD_PROTOTYPE(rx3270_method_wait_for_text_at);
+ REXX_METHOD_PROTOTYPE(rx3270_method_get_field_len);
+ REXX_METHOD_PROTOTYPE(rx3270_method_get_field_start);
+ REXX_METHOD_PROTOTYPE(rx3270_method_get_selection);
+ REXX_METHOD_PROTOTYPE(rx3270_method_set_selection);
+ REXX_METHOD_PROTOTYPE(rx3270_method_get_clipboard);
+
/*---[ Globals ]---------------------------------------------------------------------------------------------*/
@@ -131,12 +137,15 @@
virtual ~rx3270();
+ virtual void free(char *ptr);
+
+
static rx3270 * create(const char *name = NULL);
static rx3270 * create_remote(const char *name);
static rx3270 * create_local(void);
static rx3270 * get_default(void);
- static void set_plugin(void);
+ static void set_plugin(rx3270 * (*factory)(const char *name));
char * get_3270_string(const char *str);
char * get_local_string(const char *str);
@@ -174,6 +183,8 @@
virtual int set_copy(const char *text);
virtual char * get_copy(void);
+ virtual char * get_clipboard(void);
+
};
rx3270 * create_lib3270_instance(void);
diff --git a/src/plugins/rx3270/rxapimain.cc b/src/plugins/rx3270/rxapimain.cc
index ad59951..1a95842 100644
--- a/src/plugins/rx3270/rxapimain.cc
+++ b/src/plugins/rx3270/rxapimain.cc
@@ -143,6 +143,12 @@ RexxMethodEntry rx3270_methods[] =
REXX_METHOD(rx3270_method_test, rx3270_method_test ),
REXX_METHOD(rx3270_method_wait_for_text_at, rx3270_method_wait_for_text_at ),
+ REXX_METHOD(rx3270_method_get_field_len, rx3270_method_get_field_len ),
+ REXX_METHOD(rx3270_method_get_field_start, rx3270_method_get_field_start ),
+ REXX_METHOD(rx3270_method_get_selection, rx3270_method_get_selection ),
+ REXX_METHOD(rx3270_method_set_selection, rx3270_method_set_selection ),
+ REXX_METHOD(rx3270_method_get_clipboard, rx3270_method_get_clipboard ),
+
REXX_LAST_METHOD()
};
diff --git a/src/plugins/rx3270/sample/clipboard.rex b/src/plugins/rx3270/sample/clipboard.rex
new file mode 100644
index 0000000..672c5d3
--- /dev/null
+++ b/src/plugins/rx3270/sample/clipboard.rex
@@ -0,0 +1,25 @@
+/*
+ * Sample rexx code to justified paste the clipboard contents.
+ *
+ * Autor: Perry Werneck
+ *
+ */
+
+ host = .rx3270~new("")
+
+ text = host~GetClipboard()
+ if text = "" then
+ do
+ say "Clipboard is empty"
+ return 0
+ end
+
+ say "["||text||"]"
+
+
+return 0
+
+::requires "rx3270.cls"
+
+
+
diff --git a/src/pw3270/v3270/selection.c b/src/pw3270/v3270/selection.c
index 7beb3e4..cfaf05e 100644
--- a/src/pw3270/v3270/selection.c
+++ b/src/pw3270/v3270/selection.c
@@ -236,7 +236,10 @@ gchar * v3270_get_copy(GtkWidget *widget)
const char *text;
g_return_val_if_fail(GTK_IS_V3270(widget),NULL);
- text = update_selected_text(widget,FALSE);
+ text = GTK_V3270(widget)->selection.text;
+
+ if(!text)
+ text = update_selected_text(widget,FALSE);
if(text)
return g_convert(text, -1, "UTF-8", lib3270_get_charset(GTK_V3270(widget)->host), NULL, NULL, NULL);
--
libgit2 0.21.2