diff --git a/pw3270.cbp b/pw3270.cbp
index 018c87e..bcad69f 100644
--- a/pw3270.cbp
+++ b/pw3270.cbp
@@ -8,8 +8,8 @@
-
-
+
+
@@ -18,8 +18,8 @@
-
-
+
+
@@ -33,7 +33,7 @@
-
+
@@ -41,275 +41,284 @@
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
+
-
+
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
-
+
+
+
-
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
+
+
-
+
-
-
-
-
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
-
-
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/gtk/actions.c b/src/gtk/actions.c
index 0044912..be97a65 100644
--- a/src/gtk/actions.c
+++ b/src/gtk/actions.c
@@ -74,6 +74,11 @@ static void copy_action(GtkAction *action, GtkWidget *widget)
v3270_copy_clipboard(GTK_V3270(widget));
}
+static void paste_action(GtkAction *action, GtkWidget *widget)
+{
+ trace("Action %s activated on widget %p",gtk_action_get_name(action),widget);
+ v3270_paste_clipboard(GTK_V3270(widget));
+}
void ui_connect_action(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id)
{
@@ -110,6 +115,7 @@ void ui_connect_action(GtkAction *action, GtkWidget *widget, const gchar *name,
{ "connect", connect_action },
{ "copy", copy_action },
{ "disconnect", disconnect_action },
+ { "paste", paste_action },
};
int f;
diff --git a/src/gtk/mainwindow.c b/src/gtk/mainwindow.c
index d736d04..2821b16 100644
--- a/src/gtk/mainwindow.c
+++ b/src/gtk/mainwindow.c
@@ -118,14 +118,31 @@
static void disconnected(GtkWidget *widget, GtkActionGroup **group)
{
+ gtk_action_group_set_sensitive(group[ACTION_GROUP_PASTE],FALSE);
gtk_action_group_set_sensitive(group[ACTION_GROUP_ONLINE],FALSE);
gtk_action_group_set_sensitive(group[ACTION_GROUP_OFFLINE],TRUE);
}
+#ifndef WIN32
+ static void clipboard_text_check(GtkClipboard *clipboard, const gchar *text, GtkActionGroup **group)
+ {
+ trace("%s called with text=%p",__FUNCTION__,text);
+ gtk_action_group_set_sensitive(group[ACTION_GROUP_PASTE],text != NULL);
+ }
+#endif
+
static void connected(GtkWidget *widget, GtkActionGroup **group)
{
gtk_action_group_set_sensitive(group[ACTION_GROUP_ONLINE],TRUE);
gtk_action_group_set_sensitive(group[ACTION_GROUP_OFFLINE],FALSE);
+
+#ifdef WIN32
+ gtk_action_group_set_sensitive(group[ACTION_GROUP_PASTE],TRUE);
+#else
+ gtk_action_group_set_sensitive(group[ACTION_GROUP_PASTE],FALSE);
+ gtk_clipboard_request_text(gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD),clipboard_text_check,(gpointer) group);
+#endif
+
}
static void update_config(GtkWidget *widget, const gchar *name, const gchar *value)
diff --git a/src/gtk/v3270/clipboard.c b/src/gtk/v3270/clipboard.c
index a1ec62e..1a4667e 100644
--- a/src/gtk/v3270/clipboard.c
+++ b/src/gtk/v3270/clipboard.c
@@ -109,3 +109,174 @@ void v3270_copy_clipboard(v3270 *widget)
}
}
+static void paste_text(GtkWidget *widget, const gchar *text, const gchar *encoding)
+{
+ gchar *buffer = NULL;
+ gchar *ptr;
+ GError *error = NULL;
+ H3270 *session = v3270_get_session(widget);
+
+ if(!text)
+ return;
+
+ buffer = g_convert(text, -1, lib3270_get_charset(session), encoding, NULL, NULL, &error);
+
+ if(!buffer)
+ {
+ /* Falhou ao converter - Reajusta e tenta de novo */
+ int f;
+
+ static const struct _xlat
+ {
+ const gchar *from;
+ const gchar *to;
+ } xlat[] =
+ {
+ { "–", "-" },
+ { "→", "->" },
+ { "←", "<-" },
+ { "©", "(c)" },
+ { "↔", "<->" },
+ { "™", "(TM)" },
+ { "®", "(R)" },
+ { "“", "\"" },
+ { "”", "\"" },
+ { "…", "..." },
+ { "•", "*" },
+ { "․", "." },
+ { "·", "*" },
+
+ };
+
+ gchar *string = g_strdup(text);
+
+ if(error)
+ {
+ g_error_free(error);
+ error = NULL;
+ }
+
+ // FIXME (perry#1#): Is there any better way for a "sed" here?
+ for(f=0;fmessage ? error->message : N_( "Unexpected error" ), ln[f]);
+ g_error_free(error);
+ error = 0;
+ }
+ else
+ {
+ gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s", ln[f]);
+ }
+ gtk_dialog_run(GTK_DIALOG (dialog));
+ gtk_widget_destroy(dialog);
+ return;
+
+ }
+ else
+ {
+ g_free(str);
+ }
+ }
+
+ g_strfreev(ln);
+ g_free(string);
+ }
+
+ g_free(string);
+
+ if(error)
+ {
+ g_error_free(error);
+ error = 0;
+ }
+
+
+ if(!buffer)
+ {
+ GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW( gtk_widget_get_toplevel(widget)),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _( "Can't convert text from %s to %s" ), encoding, lib3270_get_charset(session));
+
+ gtk_window_set_title(GTK_WINDOW(dialog), _( "Charset error" ) );
+ if(error)
+ {
+ gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s", error->message ? error->message : N_( "Unexpected error" ));
+ g_error_free(error);
+ error = 0;
+ }
+ gtk_dialog_run(GTK_DIALOG (dialog));
+ gtk_widget_destroy(dialog);
+
+ return;
+ }
+ }
+
+ if(error)
+ g_error_free(error);
+
+ /* Remove TABS */
+ for(ptr = buffer;*ptr;ptr++)
+ {
+ if(*ptr == '\t')
+ *ptr = ' ';
+ }
+
+ trace("Received text:%p (%d bytes)",buffer,(int) strlen(buffer));
+
+// paste_string(buffer);
+
+ g_free(buffer);
+
+}
+
+static void text_received(GtkClipboard *clipboard, const gchar *text, GtkWidget *widget)
+{
+ paste_text(widget,text,"UTF-8");
+}
+
+void v3270_paste_clipboard(v3270 *widget)
+{
+ gtk_clipboard_request_text(gtk_widget_get_clipboard(GTK_WIDGET(widget),GDK_SELECTION_CLIPBOARD),(GtkClipboardTextReceivedFunc) text_received,(gpointer) widget);
+}
+
diff --git a/src/gtk/v3270/v3270.h b/src/gtk/v3270/v3270.h
index 1bbcacd..39f8d3c 100644
--- a/src/gtk/v3270/v3270.h
+++ b/src/gtk/v3270/v3270.h
@@ -200,7 +200,7 @@
int v3270_connect(GtkWidget *widget, const gchar *host);
void v3270_disconnect(GtkWidget *widget);
-// Clipboard
+ // Clipboard
void v3270_copy_clipboard(v3270 *widget);
void v3270_paste_clipboard(v3270 *widget);
diff --git a/src/include/lib3270.h b/src/include/lib3270.h
index 91b7194..0f51fa0 100644
--- a/src/include/lib3270.h
+++ b/src/include/lib3270.h
@@ -227,7 +227,7 @@
#define LIB3270_EXPORT __attribute__((visibility("default"))) extern
#else
-
+
#error Unable to set visibility attribute
#endif
@@ -636,8 +636,8 @@
LIB3270_EXPORT char * lib3270_get_selected(H3270 *h);
- LIB3270_EXPORT int lib3270_set_model(H3270 *session, int model);
- LIB3270_EXPORT int lib3270_get_model(H3270 *session);
+ LIB3270_EXPORT int lib3270_set_model(H3270 *session, int model);
+ LIB3270_EXPORT int lib3270_get_model(H3270 *session);
#ifdef __cplusplus
}
diff --git a/src/include/lib3270/popup.h b/src/include/lib3270/popup.h
index 1c55854..7b1eade 100644
--- a/src/include/lib3270/popup.h
+++ b/src/include/lib3270/popup.h
@@ -44,6 +44,7 @@
} LIB3270_NOTIFY;
LIB3270_EXPORT void lib3270_set_popup_handler(int (*popup_handler)(H3270 *, LIB3270_NOTIFY, const char *, const char *, const char *, va_list));
+ LIB3270_EXPORT lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...);
#endif // LIB3270_POPUP_INCLUDED
diff --git a/src/lib3270/paste.c b/src/lib3270/paste.c
index 0a77d48..d24a63e 100644
--- a/src/lib3270/paste.c
+++ b/src/lib3270/paste.c
@@ -32,14 +32,17 @@
#include "globals.h"
-#if defined(X3270_DISPLAY) /*[*/
-#include
+/*
+#if defined(X3270_DISPLAY)
+ #include
#endif
+*/
+
#define XK_3270
-#if defined(X3270_APL) /*[*/
-#define XK_APL
-#endif /*]*/
-//#include
+
+#if defined(X3270_APL)
+ #define XK_APL
+#endif
#include
#include "3270ds.h"
@@ -53,17 +56,18 @@
#include "ctlrc.h"
#include "ftc.h"
#include "hostc.h"
-// #include "idlec.h"
-// #include "keymapc.h"
#include "keypadc.h"
#include "kybdc.h"
-// #include "macrosc.h"
#include "popupsc.h"
#include "printc.h"
#include "screenc.h"
-// #if defined(X3270_DISPLAY) /*[*/
-// #include "selectc.h"
-// #endif /*]*/
+
+/*
+#if defined(X3270_DISPLAY)
+ #include "selectc.h"
+#endif
+*/
+
#include "statusc.h"
#include "tablesc.h"
#include "telnetc.h"
@@ -76,6 +80,8 @@
#endif /*]*/
#include "api.h"
+#include
+
/*---[ Struct ]-------------------------------------------------------------------------------------------------*/
typedef struct _paste_data
@@ -157,6 +163,15 @@
return c;
}
+/**
+ * Set string at cursor position.
+ *
+ * @param h Session handle.
+ * @param str String to set
+ *
+ * @return Number of characters inserted; <0 in case of error.
+ *
+ */
LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str)
{
PASTE_DATA data;
@@ -218,3 +233,62 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str)
screen_resume(h);
return data.qtd;
}
+
+LIB3270_EXPORT int lib3270_paste(H3270 *h, const char *str)
+{
+ int sz;
+ CHECK_SESSION_HANDLE(h);
+
+ if(!lib3270_connected(h))
+ {
+ lib3270_ring_bell(h);
+ return 0;
+ }
+
+ if(h->paste_buffer)
+ {
+ free(h->paste_buffer);
+ h->paste_buffer = NULL;
+ }
+
+ sz = lib3270_set_string(h,str);
+ if(sz < 0)
+ {
+ // Can´t paste
+ lib3270_popup_dialog(h,LIB3270_NOTIFY_WARNING,
+ _( "Action failed" ),
+ _( "Unable to paste text" ),
+ "%s", sz == -EINVAL ? _( "Keyboard is locked" ) : _( "Unexpected error" ) );
+ return 0;
+ }
+
+ if(strlen(str) > sz)
+ {
+ h->paste_buffer = strdup(str+sz);
+ return 1;
+ }
+
+ return 0;
+}
+
+LIB3270_EXPORT int lib3270_pastenext(H3270 *h)
+{
+ char * ptr;
+ int rc;
+
+ CHECK_SESSION_HANDLE(h);
+
+ if(!(lib3270_connected(h) && h->paste_buffer))
+ {
+ lib3270_ring_bell(h);
+ return 0;
+ }
+
+ ptr = h->paste_buffer;
+ h->paste_buffer = NULL;
+
+ rc = lib3270_paste(h,ptr);
+
+ free(ptr);
+ return rc;
+}
diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c
index 233e0c7..02e7793 100644
--- a/src/lib3270/screen.c
+++ b/src/lib3270/screen.c
@@ -787,3 +787,13 @@ LIB3270_EXPORT void lib3270_set_popup_handler(int (*handler)(H3270 *, LIB3270_NO
popup_handler = handler ? handler : logpopup;
}
+LIB3270_EXPORT lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...)
+{
+ va_list args;
+
+ CHECK_SESSION_HANDLE(session);
+
+ va_start(args, fmt);
+ popup_handler(session,id,title ? title : _( "3270 Error" ), message,fmt,args);
+ va_end(args);
+}
diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c
index 5e44745..27c4ae1 100644
--- a/src/lib3270/selection.c
+++ b/src/lib3270/selection.c
@@ -345,29 +345,3 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession)
return realloc(ret,sz+1);
}
-LIB3270_EXPORT int lib3270_paste(H3270 *h, const char *str)
-{
- CHECK_SESSION_HANDLE(h);
-
- if(!lib3270_connected(h))
- {
- lib3270_ring_bell(h);
- return 0;
- }
-
- return 0;
-}
-
-LIB3270_EXPORT int lib3270_pastenext(H3270 *h)
-{
- CHECK_SESSION_HANDLE(h);
-
- if(!(lib3270_connected(h) && h->paste_buffer))
- {
- lib3270_ring_bell(h);
- return 0;
- }
-
-
- return 0;
-}
--
libgit2 0.21.2