From 4e287678326bc8c79f6445ebcf8dfa01bed50907 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Wed, 24 Jul 2013 11:52:28 +0000 Subject: [PATCH] Corrigindo erro ao arrastar uma caixa de seleção que ocupe toda a tela do terminal --- src/include/lib3270/action_table.h | 4 ++-- src/include/lib3270/selection.h | 4 +++- src/lib3270/selection.c | 19 ++++++++++++------- src/pw3270/actions.c | 5 +++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/include/lib3270/action_table.h b/src/include/lib3270/action_table.h index 6970008..23dd668 100644 --- a/src/include/lib3270/action_table.h +++ b/src/include/lib3270/action_table.h @@ -56,8 +56,8 @@ DECLARE_LIB3270_ACTION( clear ) DECLARE_LIB3270_ACTION( eraseinput ) - DECLARE_LIB3270_ACTION( selectfield ) - DECLARE_LIB3270_ACTION( selectall ) + DECLARE_LIB3270_ACTION( select_field ) + DECLARE_LIB3270_ACTION( select_all ) DECLARE_LIB3270_ACTION( unselect ) DECLARE_LIB3270_ACTION( reselect ) diff --git a/src/include/lib3270/selection.h b/src/include/lib3270/selection.h index 63f4697..9d86a89 100644 --- a/src/include/lib3270/selection.h +++ b/src/include/lib3270/selection.h @@ -33,10 +33,12 @@ #define LIB3270_SELECTION_H_INCLUDED 1 - LIB3270_EXPORT void lib3270_clear_selection(H3270 *session); + LIB3270_EXPORT int lib3270_unselect(H3270 *session); LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr); LIB3270_EXPORT int lib3270_select_word_at(H3270 *session, int baddr); LIB3270_EXPORT int lib3270_select_field_at(H3270 *session, int baddr); + LIB3270_EXPORT int lib3270_select_field(H3270 *session); + LIB3270_EXPORT int lib3270_select_all(H3270 *session); /** * "Paste" supplied string. diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index 2cdbcfb..3db20fd 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -176,7 +176,7 @@ void toggle_rectselect(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_ update_selected_region(session); } -LIB3270_ACTION(unselect) +LIB3270_EXPORT int lib3270_unselect(H3270 *hSession) { int a; @@ -242,11 +242,14 @@ LIB3270_EXPORT void lib3270_select_region(H3270 *h, int start, int end) static void do_select(H3270 *h, int start, int end, int rect) { + if(start < 0 || end > (h->rows * h->cols)) + return; // Do we really need to change selection? if(start == h->select.start && end == h->select.end && h->selected) return; + // Start address is inside the screen? h->select.start = start; h->select.end = end; @@ -340,20 +343,18 @@ LIB3270_EXPORT int lib3270_select_field_at(H3270 *session, int baddr) return 0; } -LIB3270_ACTION( selectfield ) +LIB3270_EXPORT int lib3270_select_field(H3270 *hSession) { CHECK_SESSION_HANDLE(hSession); lib3270_select_field_at(hSession,hSession->cursor_addr); return 0; } -LIB3270_ACTION( selectall ) +LIB3270_EXPORT int lib3270_select_all(H3270 * hSession) { -// int len, baddr; - CHECK_SESSION_HANDLE(hSession); - do_select(hSession,0,hSession->rows*hSession->cols,0); + do_select(hSession,0,(hSession->rows*hSession->cols)-1,0); return 0; } @@ -764,7 +765,9 @@ LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) { int pos[2]; int rows, cols, f, step; - // , start, end; + + if(from == to) + return from; if(!lib3270_get_selection_bounds(hSession,&pos[0],&pos[1])) return from; @@ -835,6 +838,8 @@ LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int orig if(flag & SELECTION_BOTTOM) // Update bottom margin origin = last = (row*h->cols) + (last%h->cols); + trace("origin=%d first=%d last=%d",origin,first,last); + if(first < last) do_select(h,first,last,h->rectsel); else diff --git a/src/pw3270/actions.c b/src/pw3270/actions.c index f471225..5ade997 100644 --- a/src/pw3270/actions.c +++ b/src/pw3270/actions.c @@ -398,12 +398,13 @@ static void action_reset_toggle(GtkAction *action, GtkWidget *widget) static void action_select_all(GtkAction *action, GtkWidget *widget) { - lib3270_selectall(v3270_get_session(widget)); + lib3270_trace_event(v3270_get_session(widget),"Action %s activated on widget %p\n",gtk_action_get_name(action),widget); + lib3270_select_all(v3270_get_session(widget)); } static void action_select_field(GtkAction *action, GtkWidget *widget) { - lib3270_selectfield(v3270_get_session(widget)); + lib3270_select_field(v3270_get_session(widget)); } static void action_select_none(GtkAction *action, GtkWidget *widget) -- libgit2 0.21.2