From e035bbac37a61991708d89122811309186d33dd7 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 24 Jan 2019 14:37:13 -0200 Subject: [PATCH] Adding print methods in the main library. --- src/include/lib3270.h | 21 +++++++++++++++++++-- src/include/lib3270/session.h | 3 +-- src/lib3270/session.c | 4 ++-- src/lib3270/util.c | 22 ++++++++++++++++++---- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/include/lib3270.h b/src/include/lib3270.h index fb5e1af..27b0a7a 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -82,6 +82,17 @@ #define LIB3270_LUNAME_LENGTH 16 /** + * @brief Print modes. + * + */ + typedef enum _lib3270_print_mode + { + LIB3270_PRINT_ALL, + LIB3270_PRINT_SELECTED, + LIB3270_PRINT_COPY + } LIB3270_PRINT_MODE; + + /** * @brief Character attributes. */ typedef enum _lib3270_attr @@ -720,15 +731,21 @@ */ LIB3270_EXPORT int lib3270_move_cursor(H3270 *h, LIB3270_DIRECTION dir, unsigned char sel); + /** * @brief Print page * - * @param h Session Handle. + * @param hSession Session Handle. + * @param mode Print mode. * * @return 0 if ok, error code if not. * */ - LIB3270_EXPORT int lib3270_print(H3270 *h); + LIB3270_EXPORT int lib3270_print(H3270 *hSession, LIB3270_PRINT_MODE mode); + + LIB3270_EXPORT int lib3270_print_all(H3270 *hSession); + LIB3270_EXPORT int lib3270_print_selected(H3270 *hSession); + LIB3270_EXPORT int lib3270_print_copy(H3270 *hSession); /** * @brief Get buffer contents. diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index 10f147d..3b4efa1 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -74,8 +74,7 @@ void (*set_selection)(H3270 *session, unsigned char on); void (*ctlr_done)(H3270 *session); void (*autostart)(H3270 *session); - int (*print)(H3270 *session); - + int (*print)(H3270 *session, LIB3270_PRINT_MODE mode); void (*message)(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text); void (*popup)(H3270 *session, LIB3270_NOTIFY id, const char *title, const char *msg, const char *fmt, va_list); diff --git a/src/lib3270/session.c b/src/lib3270/session.c index 45eefd3..897dbf2 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -185,10 +185,10 @@ static void set_cursor(H3270 *session unused, LIB3270_POINTER id unused) { } -static int print(H3270 *session) +static int print(H3270 *session, LIB3270_PRINT_MODE mode unused) { lib3270_write_log(session, "print", "%s", "Printing is unavailable"); - return -1; + return errno = ENOTSUP; } static void message(H3270 *session, LIB3270_NOTIFY id unused, const char *title, const char *msg, const char *text) diff --git a/src/lib3270/util.c b/src/lib3270/util.c index eaed157..c18caf9 100644 --- a/src/lib3270/util.c +++ b/src/lib3270/util.c @@ -592,13 +592,27 @@ void lib3270_popup_an_errno(H3270 *hSession, int errn, const char *fmt, ...) } -LIB3270_EXPORT int lib3270_print(H3270 *h) +LIB3270_EXPORT int lib3270_print(H3270 *hSession, LIB3270_PRINT_MODE mode) { - CHECK_SESSION_HANDLE(h); - trace("%s(%p)",__FUNCTION__,h); - return h->cbk.print(h); + return hSession->cbk.print(hSession, mode); } +LIB3270_EXPORT int lib3270_print_all(H3270 *hSession) +{ + return lib3270_print(hSession,LIB3270_PRINT_ALL); +} + +LIB3270_EXPORT int lib3270_print_selected(H3270 *hSession) +{ + if(lib3270_has_selection(hSession)) + return lib3270_print(hSession,LIB3270_PRINT_SELECTED); + return errno = ENODATA; +} + +LIB3270_EXPORT int lib3270_print_copy(H3270 *hSession) +{ + return lib3270_print(hSession,LIB3270_PRINT_COPY); +} LIB3270_EXPORT LIB3270_POINTER lib3270_get_pointer(H3270 *hSession, int baddr) { -- libgit2 0.21.2