From ce603b9a7ea8ec5efeec015bea3a42e7956ca7d1 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Thu, 15 Mar 2012 19:59:54 +0000 Subject: [PATCH] Iniciando inclusao das funções para paste direto pela biblioteca --- src/gtk/actions.c | 2 +- src/include/lib3270/selection.h | 26 ++++++++++++++++++++++++++ src/include/lib3270/session.h | 1 + src/lib3270/glue.c | 9 ++++----- src/lib3270/selection.c | 27 +++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/gtk/actions.c b/src/gtk/actions.c index 1913127..0044912 100644 --- a/src/gtk/actions.c +++ b/src/gtk/actions.c @@ -210,7 +210,7 @@ void ui_connect_pakey(GtkAction *action, GtkWidget *widget, const gchar *name, c void ui_connect_index_action(GtkAction *action, GtkWidget *widget, int ix, GtkAction **lst) { - trace("action(%d): %p",ix,action); +// trace("action(%d): %p",ix,action); switch(ix) { diff --git a/src/include/lib3270/selection.h b/src/include/lib3270/selection.h index ee02895..30b07ca 100644 --- a/src/include/lib3270/selection.h +++ b/src/include/lib3270/selection.h @@ -38,4 +38,30 @@ LIB3270_EXPORT void lib3270_select_word(H3270 *session, int baddr); LIB3270_EXPORT int lib3270_select_field_at(H3270 *session, int baddr); + /** + * "Paste" supplied string. + * + * @param h Session handle. + * @param str String to paste. + * + * @see lib3270_pastenext. + * + * @return Non 0 if there's more to paste with lib3270_pastenext + * + */ + LIB3270_EXPORT int lib3270_paste(H3270 *h, const char *str); + + /** + * Paste remaining string. + * + * @param h Session handle. + * + * @see lib3270_paste. + * + * @return Non 0 if there's more to paste. + * + */ + LIB3270_EXPORT int lib3270_pastenext(H3270 *h); + + #endif // LIB3270_SELECTION_H_INCLUDED diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index cd4964e..da36944 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -123,6 +123,7 @@ void * widget; // selection + char * paste_buffer; struct { int begin; diff --git a/src/lib3270/glue.c b/src/lib3270/glue.c index 7e17b5f..37e3804 100644 --- a/src/lib3270/glue.c +++ b/src/lib3270/glue.c @@ -139,11 +139,10 @@ void lib3270_session_free(H3270 *h) } // Release memory - if(h->charset) - { - free(h->charset); - h->charset = NULL; - } + #define RELEASE_BUFFER(x) if(x) { free(x); x = NULL; } + + RELEASE_BUFFER(h->charset); + RELEASE_BUFFER(h->paste_buffer); } diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index fe243fd..5e44745 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -344,3 +344,30 @@ 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