From 9d289f73759f8666f5d9d7558ca500a7cd52c257 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Fri, 16 Mar 2012 00:10:03 +0000 Subject: [PATCH] Implementando "paste" --- paste.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ screen.c | 10 ++++++++++ selection.c | 26 -------------------------- 3 files changed, 96 insertions(+), 38 deletions(-) diff --git a/paste.c b/paste.c index 0a77d48..d24a63e 100644 --- a/paste.c +++ b/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/screen.c b/screen.c index 233e0c7..02e7793 100644 --- a/screen.c +++ b/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/selection.c b/selection.c index 5e44745..27c4ae1 100644 --- a/selection.c +++ b/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