From 3cfc57fa111a84644deea68629e27d8af635c89e Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Mon, 2 Apr 2012 18:16:59 +0000 Subject: [PATCH] Removendo campos sem uso, incluindo suporte a auto-reconnect, iniciando reinclusao de movimentação da seleção por mouse --- src/gtk/dialog.c | 4 ---- src/gtk/globals.h | 2 +- src/gtk/main.c | 7 ++++--- src/gtk/mainwindow.c | 20 ++++++++++++++++++-- src/gtk/v3270/mouse.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/gtk/v3270/private.h | 19 ++++++++++++++++++- src/gtk/v3270/v3270.h | 10 ++++++++-- src/gtk/v3270/widget.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------- src/include/lib3270.h | 26 +++++++++++++++++++++++--- src/include/lib3270/selection.h | 23 +++++++++++++++++++++++ src/include/lib3270/session.h | 1 - src/lib3270/api.h | 2 +- src/lib3270/globals.h | 6 ++++-- src/lib3270/host.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- src/lib3270/selection.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib3270/telnet.c | 30 ++++++++++++++++++++---------- 16 files changed, 385 insertions(+), 90 deletions(-) diff --git a/src/gtk/dialog.c b/src/gtk/dialog.c index d1b766a..48a795a 100644 --- a/src/gtk/dialog.c +++ b/src/gtk/dialog.c @@ -364,11 +364,7 @@ ); if(!lib3270_connect(v3270_get_session(widget),hostname,1)) - { - // Connection OK - set_string_to_config("host","uri","%s",hostname); again = FALSE; - } g_free(hostname); break; diff --git a/src/gtk/globals.h b/src/gtk/globals.h index 6d71dc6..00d55bc 100644 --- a/src/gtk/globals.h +++ b/src/gtk/globals.h @@ -58,7 +58,7 @@ #include "common/common.h" - G_GNUC_INTERNAL GtkWidget * create_main_window(void); + G_GNUC_INTERNAL GtkWidget * create_main_window(const gchar *uri); G_GNUC_INTERNAL void setup_font_list(GtkWidget *widget, GtkWidget *obj); G_GNUC_INTERNAL void load_color_schemes(GtkWidget *widget, gchar *active); G_GNUC_INTERNAL GtkWidget * color_scheme_new(const GdkColor *current); diff --git a/src/gtk/main.c b/src/gtk/main.c index 9047b27..578cb36 100644 --- a/src/gtk/main.c +++ b/src/gtk/main.c @@ -106,14 +106,15 @@ static int initialize(void) int main(int argc, char *argv[]) { static const gchar * appname = PACKAGE_NAME; + static const gchar * host = NULL; int rc = 0; // Process command-line options { static const GOptionEntry app_options[] = { - { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, - + { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, + { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, { NULL } }; @@ -152,7 +153,7 @@ int main(int argc, char *argv[]) { configuration_init(); - toplevel = create_main_window(); + toplevel = create_main_window(host); if(toplevel) { diff --git a/src/gtk/mainwindow.c b/src/gtk/mainwindow.c index 67b5c98..c74ea83 100644 --- a/src/gtk/mainwindow.c +++ b/src/gtk/mainwindow.c @@ -133,6 +133,7 @@ static void connected(GtkWidget *widget, const gchar *host, GtkActionGroup **group) { + set_string_to_config("host","uri","%s",host); gtk_window_set_title(GTK_WINDOW(gtk_widget_get_toplevel(widget)),host); gtk_action_group_set_sensitive(group[ACTION_GROUP_ONLINE],TRUE); gtk_action_group_set_sensitive(group[ACTION_GROUP_OFFLINE],FALSE); @@ -251,7 +252,7 @@ } - GtkWidget * create_main_window(void) + GtkWidget * create_main_window(const gchar *uri) { static const UI_WIDGET_SETUP widget_setup[] = { @@ -280,6 +281,18 @@ GtkWidget **popup; int f; + if(uri) + { + lib3270_set_host(host,uri); + } + else + { + gchar *ptr = get_string_from_config("host","uri",""); + if(*ptr) + lib3270_set_host(host,ptr); + g_free(ptr); + } + g_object_set_data_full(G_OBJECT(terminal),"toggle_actions",g_new0(GtkAction *,LIB3270_TOGGLE_COUNT),g_free); g_object_set_data_full(G_OBJECT(terminal),"named_actions",(gpointer) action, (GDestroyNotify) g_free); @@ -352,7 +365,6 @@ g_signal_connect(terminal,"has_text",G_CALLBACK(has_text),group); g_free(path); -// gtk_widget_grab_focus(terminal); if(lib3270_get_toggle(host,LIB3270_TOGGLE_FULL_SCREEN)) gtk_window_fullscreen(GTK_WINDOW(window)); @@ -363,6 +375,10 @@ trace("%s ends",__FUNCTION__); gtk_window_set_focus(GTK_WINDOW(window),terminal); + + if(lib3270_get_toggle(host,LIB3270_TOGGLE_CONNECT_ON_STARTUP)) + lib3270_connect(host,NULL,0); + return window; } diff --git a/src/gtk/v3270/mouse.c b/src/gtk/v3270/mouse.c index 8ef9b0a..2fa5bd1 100644 --- a/src/gtk/v3270/mouse.c +++ b/src/gtk/v3270/mouse.c @@ -53,15 +53,34 @@ static int decode_position(v3270 *widget, gdouble x, gdouble y) return -1; } -static void button_1_press(GtkWidget *widget, GdkEventType type, int baddr) +static void single_click(v3270 *widget, int baddr) { - GTK_V3270(widget)->selecting = 1; + switch(lib3270_get_selection_flags(widget->host,baddr)) + { + case 0x00: + // Unselected area, move cursor and remove selection + lib3270_set_cursor_address(widget->host,baddr); + lib3270_unselect(widget->host); + widget->selecting = 1; + break; + + + default: + // Move selected area + trace("%s: default action",__FUNCTION__); + widget->selection_addr = baddr; + widget->moving = 1; + } + +} + +static void button_1_press(GtkWidget *widget, GdkEventType type, int baddr) +{ switch(type) { - case GDK_BUTTON_PRESS: // Single click - Just move cursor - lib3270_set_cursor_address(GTK_V3270(widget)->host,baddr); - lib3270_unselect(GTK_V3270(widget)->host); + case GDK_BUTTON_PRESS: // Single click - set mode + single_click(GTK_V3270(widget),baddr); break; case GDK_2BUTTON_PRESS: // Double click - Select word @@ -132,6 +151,8 @@ gboolean v3270_button_release_event(GtkWidget *widget, GdkEventButton*event) { case 1: GTK_V3270(widget)->selecting = 0; + GTK_V3270(widget)->moving = 0; + GTK_V3270(widget)->resizing = 0; break; default: @@ -145,13 +166,76 @@ gboolean v3270_button_release_event(GtkWidget *widget, GdkEventButton*event) gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) { - int baddr = decode_position(GTK_V3270(widget),event->x,event->y); + v3270 * terminal = GTK_V3270(widget); + int baddr = decode_position(terminal,event->x,event->y); if(baddr < 0) return FALSE; - if(GTK_V3270(widget)->selecting) - lib3270_select_to(GTK_V3270(widget)->host,baddr); + if(terminal->selecting) + { + // Select area + lib3270_select_to(terminal->host,baddr); + } + else if(terminal->moving) + { + // Move selected area + terminal->selection_addr = lib3270_move_selected_area(terminal->host,terminal->selection_addr,baddr); + } + else if(terminal->pointer_id == LIB3270_CURSOR_NORMAL) + { + unsigned char new_pointer = lib3270_get_selection_flags(terminal->host,baddr); + if(new_pointer != terminal->pointer) + { + GdkWindow *window = gtk_widget_get_window(widget); + trace("Pointer changes to %04x",new_pointer); + + switch(new_pointer & 0x1F) + { + case 0x00: + gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_NORMAL]); + break; + + case 0x05: + gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP]); + break; + + case 0x0d: + gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP_RIGHT]); + break; + + case 0x09: + gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_RIGHT]); + break; + + case 0x03: + gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_LEFT]); + break; + + case 0x13: + gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM_LEFT]); + break; + + case 0x11: + gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM]); + break; + + case 0x19: + gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM_RIGHT]); + break; + + case 0x07: + gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP_LEFT]); + break; + + default: + gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_MOVE_SELECTION]); + + } + + terminal->pointer = new_pointer; + } + } return FALSE; } diff --git a/src/gtk/v3270/private.h b/src/gtk/v3270/private.h index 77848b8..da335e6 100644 --- a/src/gtk/v3270/private.h +++ b/src/gtk/v3270/private.h @@ -82,7 +82,24 @@ G_BEGIN_DECLS /*--[ Globals ]--------------------------------------------------------------------------------------*/ - G_GNUC_INTERNAL guint v3270_widget_signal[LAST_SIGNAL]; + #define V3270_CURSOR_NORMAL LIB3270_CURSOR_NORMAL + #define V3270_CURSOR_WAITING LIB3270_CURSOR_WAITING + #define V3270_CURSOR_LOCKED LIB3270_CURSOR_LOCKED + + #define V3270_CURSOR_MOVE_SELECTION LIB3270_CURSOR_USER + #define V3270_CURSOR_SELECTION_TOP_LEFT LIB3270_CURSOR_USER+1 + #define V3270_CURSOR_SELECTION_TOP_RIGHT LIB3270_CURSOR_USER+2 + #define V3270_CURSOR_SELECTION_TOP LIB3270_CURSOR_USER+3 + #define V3270_CURSOR_SELECTION_BOTTOM_LEFT LIB3270_CURSOR_USER+4 + #define V3270_CURSOR_SELECTION_BOTTOM_RIGHT LIB3270_CURSOR_USER+5 + #define V3270_CURSOR_SELECTION_BOTTOM LIB3270_CURSOR_USER+6 + #define V3270_CURSOR_SELECTION_LEFT LIB3270_CURSOR_USER+7 + #define V3270_CURSOR_SELECTION_RIGHT LIB3270_CURSOR_USER+8 + + #define V3270_CURSOR_COUNT LIB3270_CURSOR_USER+9 + + G_GNUC_INTERNAL guint v3270_widget_signal[LAST_SIGNAL]; + G_GNUC_INTERNAL GdkCursor * v3270_cursor[V3270_CURSOR_COUNT]; /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ diff --git a/src/gtk/v3270/v3270.h b/src/gtk/v3270/v3270.h index 0dd7b0a..387354c 100644 --- a/src/gtk/v3270/v3270.h +++ b/src/gtk/v3270/v3270.h @@ -146,7 +146,9 @@ GtkWidget parent; /* private */ - int selecting : 1; + int selecting : 1; /**< Selecting region */ + int moving : 1; /**< Moving selected region */ + int resizing : 1; /**< Resizing selected region */ #if GTK_CHECK_VERSION(3,0,0) @@ -158,7 +160,11 @@ GSource * timer; GtkIMContext * input_method; unsigned short keyflags; - gchar * clipboard; /**< Clipboard contents (text only) */ + gchar * clipboard; /**< Clipboard contents (text only) */ + + LIB3270_CURSOR pointer_id; + unsigned char pointer; /** Mouse pointer ID */ + int selection_addr; /** Selection addr */ /* Font info */ gchar * font_family; diff --git a/src/gtk/v3270/widget.c b/src/gtk/v3270/widget.c index c6816ad..6613c00 100644 --- a/src/gtk/v3270/widget.c +++ b/src/gtk/v3270/widget.c @@ -50,8 +50,8 @@ /*--[ Globals ]--------------------------------------------------------------------------------------*/ - guint v3270_widget_signal[LAST_SIGNAL] = { 0 }; - static GdkCursor * v3270_cursor[LIB3270_CURSOR_USER] = { 0 }; + guint v3270_widget_signal[LAST_SIGNAL] = { 0 }; + GdkCursor * v3270_cursor[V3270_CURSOR_COUNT] = { 0 }; /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ @@ -262,9 +262,58 @@ static void v3270_class_init(v3270Class *klass) v3270_register_io_handlers(klass); // Cursors - v3270_cursor[LIB3270_CURSOR_NORMAL] = gdk_cursor_new(GDK_XTERM); - v3270_cursor[LIB3270_CURSOR_WAITING] = gdk_cursor_new(GDK_WATCH); - v3270_cursor[LIB3270_CURSOR_LOCKED] = gdk_cursor_new(GDK_X_CURSOR); + { +#ifdef WIN32 + static const gchar * cr[V3270_CURSOR_COUNT] = + { + "arrow", + "wait", + "arrow", + "sizeall", + "sizenwse", // Top-left + "sizenesw", // Top-right + "sizens", // Top + "sizenesw", // Bottom-left + "sizenwse", // Bottom-right + "sizens", // Bottom + "sizewe", // Left + "sizewe", // Right + } +#else + static const int cr[V3270_CURSOR_COUNT] = + { + GDK_XTERM, + GDK_WATCH, + GDK_X_CURSOR, + GDK_FLEUR, + GDK_TOP_LEFT_CORNER, // Top-left + GDK_TOP_RIGHT_CORNER, // Top-right + GDK_TOP_SIDE, // Top + GDK_BOTTOM_LEFT_CORNER, // Bottom-left + GDK_BOTTOM_RIGHT_CORNER, // Bottom-right + GDK_BOTTOM_SIDE, // Bottom + GDK_LEFT_SIDE, // Left + GDK_RIGHT_SIDE, // Right + }; +#endif // WIN32 + + int f; + + for(f=0;factivate_signal = @@ -513,6 +562,7 @@ static void select_cursor(H3270 *session, LIB3270_CURSOR id) if(gtk_widget_get_realized(widget) && gtk_widget_get_has_window(widget)) { + GTK_V3270(widget)->pointer_id = id; gdk_window_set_cursor(gtk_widget_get_window(widget),v3270_cursor[id]); } } @@ -989,25 +1039,9 @@ int v3270_connect(GtkWidget *widget, const gchar *host) g_return_val_if_fail(GTK_IS_V3270(widget),EINVAL); - terminal = GTK_V3270(widget); - if(host) - { - set_string_to_config("host","uri","%s",host); - rc = lib3270_connect(terminal->host,host,0); - } - else - { - gchar *hs = get_string_from_config("host","uri",""); - - trace("[%s]",hs); - - if(*hs) - rc = lib3270_connect(terminal->host,hs,0); - - g_free(hs); - } + rc = lib3270_connect(terminal->host,host,0); trace("%s exits with rc=%d (%s)",__FUNCTION__,rc,strerror(rc)); @@ -1040,8 +1074,10 @@ static void v3270_activate(GtkWidget *widget) if(lib3270_connected(terminal->host)) lib3270_enter(terminal->host); - else + else if(lib3270_get_host(terminal->host)) v3270_connect(widget,NULL); + else + g_warning("Terminal widget %p activated without connection or valid hostname",terminal); } const GtkWidgetClass * v3270_get_parent_class(void) diff --git a/src/include/lib3270.h b/src/include/lib3270.h index ec31e2f..c450778 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -300,6 +300,28 @@ */ LIB3270_EXPORT void lib3270_register_schange(H3270 *h,LIB3270_STATE tx, void (*func)(H3270 *, int, void *),void *data); + + /** + * Set host id for the connect/reconnect operations. + * + * @param h Session handle. + * @param n Host ID to set. + * + * @return Pointer to host id set (internal data, do not change it) + * + */ + LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n); + + /** + * Get host id for the connect/reconnect operations. + * + * @param h Session handle. + * + * @return Pointer to host id set (internal data, do not change it) + * + */ + LIB3270_EXPORT const char * lib3270_get_host(H3270 *h); + /** * Network connect operation, keep main loop running * @@ -307,7 +329,7 @@ * side-effects. * * @param h Session handle. - * @param n Host ID + * @param n Host ID (NULL to use the last one) * @param wait Non zero to wait for connection to be ok. * * @return 0 for success, EAGAIN if auto-reconnect is in progress, EBUSY if connected, ENOTCONN if connection has failed, -1 on unexpected failure. @@ -544,8 +566,6 @@ */ LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h); - LIB3270_EXPORT const char * lib3270_get_host(H3270 *h); - #define lib3270_has_printer_session(h) (h->oia_flag[LIB3270_FLAG_PRINTER] != 0) #define lib3270_has_active_script(h) (h->oia_flag[LIB3270_FLAG_SCRIPT] != 0) #define lib3270_get_typeahead(h) (h->oia_flag[LIB3270_FLAG_TYPEAHEAD] != 0) diff --git a/src/include/lib3270/selection.h b/src/include/lib3270/selection.h index 63a5da1..af1ef8a 100644 --- a/src/include/lib3270/selection.h +++ b/src/include/lib3270/selection.h @@ -74,6 +74,18 @@ LIB3270_EXPORT int lib3270_move_selection(H3270 *h, LIB3270_DIRECTION dir); /** + * Move selected box. + * + * @param h Session handle. + * @param from Address of origin position inside the selected buffer. + * @param to Address of the new origin position. + * + * @return The new origin position. + * + */ + LIB3270_EXPORT int lib3270_move_selected_area(H3270 *h, int from, int to); + + /** * Get addresses of selected area. * * @param h Session handle. @@ -85,5 +97,16 @@ */ LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end); + /** + * Get bitmasked flag for the current selection. + * + * Calculate flags to help drawing of the correct mouse pointer over a selection. + * + * @param h Session handle. + * @param baddr Position. + * + * @return bitmask for mouse pointer. + */ + LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *h, int baddr); #endif // LIB3270_SELECTION_H_INCLUDED diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index b17fa50..1329c32 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -93,7 +93,6 @@ char * current_host; /**< the hostname part, stripped of qualifiers, luname and port number */ char * full_current_host; /**< the entire string, for use in reconnecting */ - char * reconnect_host; char * qualified_host; char auto_reconnect_inprogress; diff --git a/src/lib3270/api.h b/src/lib3270/api.h index cc0b8d4..e026cc5 100644 --- a/src/lib3270/api.h +++ b/src/lib3270/api.h @@ -379,7 +379,7 @@ /* Get connection info */ #define get_connected_lu(h) lib3270_get_luname(h) - #define get_current_host(h) lib3270_get_host(h) +// #define get_current_host(h) lib3270_get_host(h) LOCAL_EXTERN SCRIPT_STATE status_script(SCRIPT_STATE state); diff --git a/src/lib3270/globals.h b/src/lib3270/globals.h index 2c22294..bddca25 100644 --- a/src/lib3270/globals.h +++ b/src/lib3270/globals.h @@ -212,9 +212,11 @@ LIB3270_INTERNAL char *hostname; #endif /*]*/ -#if defined(LOCAL_PROCESS) /*[*/ +/* +#if defined(LOCAL_PROCESS) LIB3270_INTERNAL Boolean local_process; -#endif /*]*/ +#endif +*/ // LIB3270_INTERNAL int maxCOLS; // LIB3270_INTERNAL int maxROWS; diff --git a/src/lib3270/host.c b/src/lib3270/host.c index 9bd48a7..ebc9450 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -194,8 +194,9 @@ hostfile_lookup(const char *name, char **hostname, char **loginstring) } */ -#if defined(LOCAL_PROCESS) /*[*/ -/* Recognize and translate "-e" options. */ +/* +#if defined(LOCAL_PROCESS) +// Recognize and translate "-e" options. static const char * parse_localprocess(const char *s) { @@ -216,7 +217,8 @@ parse_localprocess(const char *s) } return CN; } -#endif /*]*/ +#endif +*/ /* * Strip qualifiers from a hostname. @@ -480,16 +482,18 @@ static int do_connect(H3270 *hSession, const char *n) Boolean resolving; Boolean pending; static Boolean ansi_host; - const char *localprocess_cmd = NULL; +// const char *localprocess_cmd = NULL; Boolean has_colons = False; - if (CONNECTED || hSession->auto_reconnect_inprogress) - return 0; + if (lib3270_connected(hSession) || hSession->auto_reconnect_inprogress) + return EBUSY; /* Skip leading blanks. */ while (*n == ' ') n++; - if (!*n) { + + if (!*n) + { popup_an_error(hSession,_( "Invalid (empty) hostname" )); return -1; } @@ -503,19 +507,16 @@ static int do_connect(H3270 *hSession, const char *n) *s-- = '\0'; /* Remember this hostname, as the last hostname we connected to. */ - Replace(hSession->reconnect_host, NewString(nb)); + lib3270_set_host(hSession,nb); -// #if defined(X3270_DISPLAY) -// /* Remember this hostname in the recent connection list and file. */ -// save_recent(nb); -// #endif - -#if defined(LOCAL_PROCESS) /*[*/ +/* +#if defined(LOCAL_PROCESS) if ((localprocess_cmd = parse_localprocess(nb)) != CN) { chost = localprocess_cmd; port = appres.port; } else -#endif /*]*/ +#endif +*/ { Boolean needed; @@ -541,12 +542,12 @@ static int do_connect(H3270 *hSession, const char *n) * full_current_host is the entire string, for use in reconnecting */ if (n != hSession->full_current_host) - { - Replace(hSession->full_current_host, NewString(n)); - } + lib3270_set_host(hSession,n); Replace(hSession->current_host, CN); +/* + if (localprocess_cmd != CN) { if (hSession->full_current_host[strlen(OptLocalProcess)] != '\0') hSession->current_host = NewString(hSession->full_current_host + strlen(OptLocalProcess) + 1); @@ -555,6 +556,7 @@ static int do_connect(H3270 *hSession, const char *n) } else { hSession->current_host = s; } +*/ has_colons = (strchr(chost, ':') != NULL); @@ -569,7 +571,7 @@ static int do_connect(H3270 *hSession, const char *n) /* Attempt contact. */ hSession->ever_3270 = False; - hSession->net_sock = net_connect(hSession, chost, port, localprocess_cmd != CN, &resolving,&pending); + hSession->net_sock = net_connect(hSession, chost, port, 0, &resolving,&pending); if (hSession->net_sock < 0 && !resolving) { @@ -612,6 +614,16 @@ static int do_connect(H3270 *hSession, const char *n) return 0; } +/** + * Connect to selected host. + * + * @param h Session handle. + * @param n Hostname (null to reconnect to the last one; + * @param wait Wait for connection ok before return. + * + * @return 0 if the connection was ok, non zero on error. + * + */ int lib3270_connect(H3270 *h, const char *n, int wait) { int rc; @@ -627,7 +639,11 @@ int lib3270_connect(H3270 *h, const char *n, int wait) return EBUSY; if(!n) - return ENOENT; + { + n = h->full_current_host; + if(!n) + return EINVAL; + } rc = do_connect(h,n); if(rc) @@ -654,7 +670,7 @@ int lib3270_connect(H3270 *h, const char *n, int wait) */ static void try_reconnect(H3270 *session) { - WriteLog("3270","Starting auto-reconnect (Host: %s)",session->reconnect_host ? session->reconnect_host : "-"); + WriteLog("3270","Starting auto-reconnect (Host: %s)",session->full_current_host ? session->full_current_host : "-"); session->auto_reconnect_inprogress = False; lib3270_reconnect(session,0); } @@ -758,6 +774,29 @@ void lib3270_st_changed(H3270 *h, int tx, int mode) } } +LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n) +{ + CHECK_SESSION_HANDLE(h); + + Trace("%s: %p",__FUNCTION__,n); + + if(!n) + return NULL; + + if(h->full_current_host) + free(h->full_current_host); + + h->full_current_host = strdup(n); + + return h->full_current_host; +} + +LIB3270_EXPORT const char * lib3270_get_host(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return h->full_current_host; +} + LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait) { int rc; @@ -767,13 +806,13 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait) if (CONNECTED || HALF_CONNECTED) return EBUSY; - if (h->current_host == CN) - return ENOENT; + if (h->full_current_host == CN) + return EINVAL; if (h->auto_reconnect_inprogress) return EBUSY; - rc = lib3270_connect(h,h->reconnect_host,wait); + rc = lib3270_connect(h,h->full_current_host,wait); if(rc) { @@ -790,8 +829,3 @@ LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h) return h->connected_lu; } -LIB3270_EXPORT const char * lib3270_get_host(H3270 *h) -{ - CHECK_SESSION_HANDLE(h); - return h->current_host; -} diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index f383202..434ef69 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -71,6 +71,20 @@ static void update_selected_rectangle(H3270 *session) p[1].row = (end/session->cols); p[1].col = (end%session->cols); + if(p[0].row > p[1].row) + { + int swp = p[0].row; + p[0].row = p[1].row; + p[1].row = swp; + } + + if(p[0].col > p[1].col) + { + int swp = p[0].col; + p[0].col = p[1].col; + p[1].col = swp; + } + // First remove unselected areas baddr = 0; for(row=0;row < session->rows;row++) @@ -214,6 +228,35 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) } +LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int baddr) +{ + int row,col; + unsigned char rc = 0; + + CHECK_SESSION_HANDLE(hSession); + + if(!(lib3270_connected(hSession) && (hSession->text[baddr].attr & LIB3270_ATTR_SELECTED))) + return rc; + + row = baddr / hSession->cols; + col = baddr % hSession->cols; + rc |= 0x01; + + if( (col == 0) || !(hSession->text[baddr-1].attr & LIB3270_ATTR_SELECTED) ) + rc |= 0x02; + + if( (row == 0) || !(hSession->text[baddr-hSession->cols].attr & LIB3270_ATTR_SELECTED) ) + rc |= 0x04; + + if( (col == hSession->cols) || !(hSession->text[baddr+1].attr & LIB3270_ATTR_SELECTED) ) + rc |= 0x08; + + if( (row == hSession->rows) || !(hSession->text[baddr+hSession->cols].attr & LIB3270_ATTR_SELECTED) ) + rc |= 0x10; + + return rc; +} + LIB3270_EXPORT void lib3270_select_word(H3270 *session, int baddr) { int pos, len; @@ -373,6 +416,8 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end) { + CHECK_SESSION_HANDLE(hSession); + if(!hSession->selected || hSession->select.begin == hSession->select.end) return -1; @@ -390,6 +435,12 @@ LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *e return 0; } +LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) +{ + + + return from; +} LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir) { diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index 602492b..b06a741 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -111,6 +111,7 @@ int ns_rsent; unsigned char *obuf; /* 3270 output buffer */ unsigned char *obptr = (unsigned char *) NULL; int linemode = 1; + /* #if defined(LOCAL_PROCESS) Boolean local_process = False; @@ -1010,10 +1011,11 @@ void net_input(H3270 *session) ns_brcvd += nr; for (cp = netrbuf; cp < (netrbuf + nr); cp++) { -#if defined(LOCAL_PROCESS) /*[*/ +/* +#if defined(LOCAL_PROCESS) if (local_process) { - /* More to do here, probably. */ - if (IN_NEITHER) { /* now can assume ANSI mode */ + // More to do here, probably. + if (IN_NEITHER) { // now can assume ANSI mode host_in3270(CONNECTED_ANSI); hisopts[TELOPT_ECHO] = 1; check_linemode(False); @@ -1023,7 +1025,8 @@ void net_input(H3270 *session) } ansi_process((unsigned int) *cp); } else { -#endif /*]*/ +#endif +*/ if (telnet_fsm(*cp)) { (void) ctlr_dbcs_postprocess(); host_disconnect(&h3270,True); @@ -1891,11 +1894,13 @@ process_eor(void) */ void net_exception(H3270 *session) { -#if defined(LOCAL_PROCESS) /*[*/ +/* +#if defined(LOCAL_PROCESS) if (local_process) { trace_dsn("RCVD exception\n"); } else -#endif /*[*/ +#endif +*/ { trace_dsn("RCVD urgent data indication\n"); if (!syncing) { @@ -1953,11 +1958,14 @@ net_rawout(unsigned const char *buf, int len) nw = SSL_write(ssl_con, (const char *) buf, n2w); else #endif /*]*/ -#if defined(LOCAL_PROCESS) /*[*/ + +/* +#if defined(LOCAL_PROCESS) if (local_process) nw = write(sock, (const char *) buf, n2w); else -#endif /*]*/ +#endif +*/ nw = send(h3270.sock, (const char *) buf, n2w, 0); if (nw < 0) { #if defined(HAVE_LIBSSL) /*[*/ @@ -2791,9 +2799,11 @@ void net_sendc(char c) { if (c == '\r' && !linemode -#if defined(LOCAL_PROCESS) /*[*/ +/* +#if defined(LOCAL_PROCESS) && !local_process -#endif /*]*/ +#endif +*/ ) { /* CR must be quoted */ net_cookout("\r\0", 2); -- libgit2 0.21.2