diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 79bd5f9..cb8ec14 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -468,6 +468,7 @@ */ LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str); + LIB3270_EXPORT int lib3270_set_string_at(H3270 *h, int row, int col, const unsigned char *str); LIB3270_EXPORT void lib3270_input_string(H3270 *hSession, const unsigned char *str); /** @@ -481,6 +482,8 @@ */ LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *h, int baddr); + LIB3270_EXPORT int lib3270_set_cursor_position(H3270 *h, int row, int col); + /** * Move cursor * diff --git a/src/lib3270/paste.c b/src/lib3270/paste.c index 8cf93e5..2c79b1f 100644 --- a/src/lib3270/paste.c +++ b/src/lib3270/paste.c @@ -161,34 +161,18 @@ } return c; - } +} -/** - * Set string at cursor position. - * - * @param hSession Session handle. - * @param str String to set - * - * @return Number of characters inserted; <0 in case of error. - * - */ -LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str) +static int set_string(H3270 *hSession, const unsigned char *str) { PASTE_DATA data; unsigned char last = 1; - CHECK_SESSION_HANDLE(hSession); - memset(&data,0,sizeof(data)); data.row = BA_TO_ROW(hSession->cursor_addr); data.orig_addr = hSession->cursor_addr; data.orig_col = BA_TO_COL(hSession->cursor_addr); - if(hSession->kybdlock) - return -EINVAL; - - hSession->suspend(hSession); - while(*str && last && !hSession->kybdlock && hSession->cursor_addr >= data.orig_addr) { switch(*str) @@ -234,9 +218,61 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str) break; } + return data.qtd; +} + +LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, int row, int col, const unsigned char *str) +{ + int rc = -1; + + CHECK_SESSION_HANDLE(hSession); + + if(hSession->kybdlock) + return -EINVAL; + + if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) + lib3270_unselect(hSession); + + row--; + col--; + + if(row >= 0 && col >= 0 && row <= hSession->rows && col <= hSession->cols) + { + hSession->suspend(hSession); + + hSession->cursor_addr = (row * hSession->cols) + col; + rc = set_string(hSession, str); + + hSession->resume(hSession); + } + + return rc; +} + + +/** + * Set string at cursor position. + * + * @param hSession Session handle. + * @param str String to set + * + * @return Number of characters inserted; <0 in case of error. + * + */ +LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str) +{ + int rc; + + CHECK_SESSION_HANDLE(hSession); + + if(hSession->kybdlock) + return -EINVAL; + + hSession->suspend(hSession); + rc = set_string(hSession, str); hSession->resume(hSession); - return data.qtd; + return rc; } LIB3270_EXPORT int lib3270_paste(H3270 *h, const unsigned char *str) diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c index c7d23ff..c2a75cd 100644 --- a/src/lib3270/screen.c +++ b/src/lib3270/screen.c @@ -398,11 +398,36 @@ LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *h, int baddr) return cursor_move(h,baddr); } -int cursor_move(H3270 *h, int baddr) +LIB3270_EXPORT int lib3270_set_cursor_position(H3270 *h, int row, int col) { - int ret; + int baddr = -1; + + CHECK_SESSION_HANDLE(h); + + if(h->selected && !lib3270_get_toggle(h,LIB3270_TOGGLE_KEEP_SELECTED)) + lib3270_unselect(h); + + row--; + col--; + + if(row >= 0 && col >= 0 && row <= h->rows && col <= h->cols) + { + baddr = (row * h->cols) + col; - ret = h->cursor_addr; + if(baddr != h->cursor_addr) + { + h->cursor_addr = baddr; + h->update_cursor(h,(unsigned short) row,(unsigned short) col,h->text[baddr].chr,h->text[baddr].attr); + } + } + + return baddr; +} + + +int cursor_move(H3270 *h, int baddr) +{ + int ret = h->cursor_addr; if(ret == baddr) return ret; diff --git a/src/plugins/rx3270/pluginmain.cc b/src/plugins/rx3270/pluginmain.cc index 2f37440..a47f2a4 100644 --- a/src/plugins/rx3270/pluginmain.cc +++ b/src/plugins/rx3270/pluginmain.cc @@ -34,10 +34,12 @@ LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window) { + rx3270_set_mode(RX3270_MODE_PLUGIN); return 0; } LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window) { + rx3270_set_mode(RX3270_MODE_UNDEFINED); return 0; } diff --git a/src/plugins/rx3270/rx3270.h b/src/plugins/rx3270/rx3270.h index f83fe7c..a0f4d64 100644 --- a/src/plugins/rx3270/rx3270.h +++ b/src/plugins/rx3270/rx3270.h @@ -66,12 +66,19 @@ REXX_TYPED_ROUTINE_PROTOTYPE(rx3270IsTerminalReady); REXX_TYPED_ROUTINE_PROTOTYPE(rx3270ReadScreen); REXX_TYPED_ROUTINE_PROTOTYPE(rx3270queryStringAt); + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270SetStringAt); /*---[ Globals ]---------------------------------------------------------------------------------------------*/ - #define RX3270SESSION lib3270_get_default_session_handle() + enum rx3270mode + { + RX3270_MODE_STANDALONE, /**< Running outside pw3270's main process */ + RX3270_MODE_PLUGIN, /**< Running inside pw3270's main process */ + + RX3270_MODE_UNDEFINED + }; - char * get_contents(H3270 *hSession, int start, int sz); + #define RX3270SESSION lib3270_get_default_session_handle() #ifdef HAVE_ICONV extern iconv_t outputConv; @@ -80,4 +87,9 @@ /*--[ Prototipes ]-------------------------------------------------------------------------------------------*/ + char * get_contents(H3270 *hSession, int start, int sz); + char * set_contents(H3270 *hSession, const char *text); + + LIB3270_EXPORT void rx3270_set_mode(enum rx3270mode mode); + #endif // RX3270_H_INCLUDED diff --git a/src/plugins/rx3270/rxapimain.cc b/src/plugins/rx3270/rxapimain.cc index 8224ece..1a5f937 100644 --- a/src/plugins/rx3270/rxapimain.cc +++ b/src/plugins/rx3270/rxapimain.cc @@ -59,6 +59,8 @@ int librx3270_unloaded(void) __attribute__((destructor)); #endif + static enum rx3270mode active_mode = RX3270_MODE_UNDEFINED; + /*--[ Implement ]------------------------------------------------------------------------------------*/ #if defined WIN32 @@ -80,8 +82,15 @@ BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd) } #endif +void rx3270_set_mode(enum rx3270mode mode) +{ + active_mode = mode; +} + int librx3270_loaded(void) { + active_mode = RX3270_MODE_STANDALONE; + #ifdef HAVE_ICONV outputConv = iconv_open(REXX_DEFAULT_CHARSET, lib3270_get_default_charset()); inputConv = iconv_open(lib3270_get_default_charset(), REXX_DEFAULT_CHARSET); @@ -92,6 +101,8 @@ int librx3270_loaded(void) int librx3270_unloaded(void) { + active_mode = RX3270_MODE_UNDEFINED; + #ifdef HAVE_ICONV if(outputConv != (iconv_t) (-1)) @@ -104,42 +115,6 @@ int librx3270_unloaded(void) return 0; } - -/* -::method setStringAt - use arg row, col, str -return rx3270InputString(row,col,str) - -::method setCursorPosition - use arg row, col -return rx3270SetCursorPosition(row,col) - -::method RunMode -return rx3270QueryRunMode() - -::method 'encoding=' - use arg ptr -return rx3270SetCharset(ptr) - -::method sendfile - use arg from, tostrncasecmp - - status = rx3270BeginFileSend(from,to) - if status <> 0 - then return status - -return rx3270WaitForFTComplete() - -::method recvfile - use arg from, to - - status = rx3270BeginFileRecv(from,to) - if status <> 0 - then return status - -return rx3270WaitForFTComplete() -*/ - // now build the actual entry list RexxRoutineEntry rx3270_functions[] = { @@ -159,6 +134,7 @@ RexxRoutineEntry rx3270_functions[] = REXX_TYPED_ROUTINE(rx3270IsTerminalReady, rx3270IsTerminalReady), REXX_TYPED_ROUTINE(rx3270ReadScreen, rx3270ReadScreen), REXX_TYPED_ROUTINE(rx3270queryStringAt, rx3270queryStringAt), + REXX_TYPED_ROUTINE(rx3270SetStringAt, rx3270SetStringAt), REXX_LAST_METHOD() }; diff --git a/src/plugins/rx3270/text.cc b/src/plugins/rx3270/text.cc index d2c2fd0..711978d 100644 --- a/src/plugins/rx3270/text.cc +++ b/src/plugins/rx3270/text.cc @@ -79,3 +79,35 @@ char * get_contents(H3270 *hSession, int start, int sz) return strdup((char *) str); } +char * set_contents(H3270 *hSession, const char *str) +{ +#ifdef HAVE_ICONV + // Convert received string to 3270 encoding + if(inputConv != (iconv_t)(-1)) + { + size_t in = strlen(str); + size_t out = (in << 1); + char * ptr; + char * buffer = (char *) malloc(out); + char * ret; + + memset(ptr=buffer,0,out); + + iconv(inputConv,NULL,NULL,NULL,NULL); // Reset state + + if(iconv(inputConv,(char **) &str,&in,&ptr,&out) == ((size_t) -1)) + ret = strdup(str); + else + ret = strdup(buffer); + + free(buffer); + + return ret; + } +#endif // HAVE_ICONV + + return strdup((char *) str); + +} + + diff --git a/src/plugins/rx3270/typed_routines.cc b/src/plugins/rx3270/typed_routines.cc index 02838b7..bd4865f 100644 --- a/src/plugins/rx3270/typed_routines.cc +++ b/src/plugins/rx3270/typed_routines.cc @@ -242,3 +242,52 @@ RexxRoutine3(int, rx3270queryStringAt, int, row, int, col, CSTRING, key) return 0; } +RexxRoutine2(int, rx3270SetCursorPosition, int, row, int, col) +{ + return lib3270_set_cursor_position(RX3270SESSION,row,col); +} + +RexxRoutine3(int, rx3270SetStringAt, int, row, int, col, CSTRING, text) +{ + int rc; + H3270 * hSession = RX3270SESSION; + char * str = set_contents(hSession,text); + + if(str) + rc = lib3270_set_string_at(hSession,row,col,(const unsigned char *) str); + else + rc = -1; + + free(str); + + return rc; +} + +/* +::method RunMode +return rx3270QueryRunMode() + +::method 'encoding=' + use arg ptr +return rx3270SetCharset(ptr) + +::method sendfile + use arg from, tostrncasecmp + + status = rx3270BeginFileSend(from,to) + if status <> 0 + then return status + +return rx3270WaitForFTComplete() + +::method recvfile + use arg from, to + + status = rx3270BeginFileRecv(from,to) + if status <> 0 + then return status + +return rx3270WaitForFTComplete() +*/ + + -- libgit2 0.21.2