From 757cb72fd488760b57a38d17d104defeb8e43aab Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Tue, 3 Apr 2012 00:45:41 +0000 Subject: [PATCH] Incluindo acerto dos cantos da area de selecao pelo mouse --- src/gtk/v3270/mouse.c | 20 ++++++++++---------- src/include/lib3270/selection.h | 15 +++++++++++++++ src/lib3270/selection.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 83 insertions(+), 15 deletions(-) diff --git a/src/gtk/v3270/mouse.c b/src/gtk/v3270/mouse.c index 2fa5bd1..84c965e 100644 --- a/src/gtk/v3270/mouse.c +++ b/src/gtk/v3270/mouse.c @@ -180,7 +180,7 @@ gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) else if(terminal->moving) { // Move selected area - terminal->selection_addr = lib3270_move_selected_area(terminal->host,terminal->selection_addr,baddr); + terminal->selection_addr = lib3270_drag_selection(terminal->host,terminal->pointer,terminal->selection_addr,baddr); } else if(terminal->pointer_id == LIB3270_CURSOR_NORMAL) { @@ -190,41 +190,41 @@ gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) GdkWindow *window = gtk_widget_get_window(widget); trace("Pointer changes to %04x",new_pointer); - switch(new_pointer & 0x1F) + switch(new_pointer & 0x0F) { case 0x00: gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_NORMAL]); break; - case 0x05: + case 0x02: gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP]); break; - case 0x0d: + case 0x06: gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP_RIGHT]); break; - case 0x09: + case 0x04: gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_RIGHT]); break; - case 0x03: + case 0x01: gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_LEFT]); break; - case 0x13: + case 0x09: gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM_LEFT]); break; - case 0x11: + case 0x08: gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM]); break; - case 0x19: + case 0x0c: gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM_RIGHT]); break; - case 0x07: + case 0x03: gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP_LEFT]); break; diff --git a/src/include/lib3270/selection.h b/src/include/lib3270/selection.h index af1ef8a..b12ed80 100644 --- a/src/include/lib3270/selection.h +++ b/src/include/lib3270/selection.h @@ -86,6 +86,21 @@ LIB3270_EXPORT int lib3270_move_selected_area(H3270 *h, int from, int to); /** + * Drag selected region. + * + * Move or resize selected box according to the selection flags. + * + * @param h Session handle. + * @param flag Selection flag. + * @param origin Reference position (got from mouse button down or other move action). + * @param baddr New position. + * + * @return The new reference position. + * + */ + LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int origin, int baddr); + + /** * Get addresses of selected area. * * @param h Session handle. diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index 4d10daf..a66d9a7 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -34,6 +34,12 @@ #include #include + #define SELECTION_LEFT 0x01 + #define SELECTION_TOP 0x02 + #define SELECTION_RIGHT 0x04 + #define SELECTION_BOTTOM 0x08 + #define SELECTION_ACTIVE 0x10 + static void update_selection(H3270 *session); /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -240,19 +246,19 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba row = baddr / hSession->cols; col = baddr % hSession->cols; - rc |= 0x01; + rc |= SELECTION_ACTIVE; if( (col == 0) || !(hSession->text[baddr-1].attr & LIB3270_ATTR_SELECTED) ) - rc |= 0x02; + rc |= SELECTION_LEFT; if( (row == 0) || !(hSession->text[baddr-hSession->cols].attr & LIB3270_ATTR_SELECTED) ) - rc |= 0x04; + rc |= SELECTION_TOP; if( (col == hSession->cols) || !(hSession->text[baddr+1].attr & LIB3270_ATTR_SELECTED) ) - rc |= 0x08; + rc |= SELECTION_RIGHT; if( (row == hSession->rows) || !(hSession->text[baddr+hSession->cols].attr & LIB3270_ATTR_SELECTED) ) - rc |= 0x10; + rc |= SELECTION_BOTTOM; return rc; } @@ -475,6 +481,53 @@ LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) return from+step; } +LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int origin, int baddr) +{ + int first, last, row, col; + + if(lib3270_get_selected_addr(h,&first,&last)) + return origin; + + flag &= 0x1f; + + if(!flag) + return origin; + else if(flag == SELECTION_ACTIVE) + return lib3270_move_selected_area(h,origin,baddr); + + row = baddr/h->cols; + col = baddr%h->cols; + + if(flag & SELECTION_LEFT) // Update left margin + origin = first = ((first/h->cols)*h->cols) + col; + + if(flag & SELECTION_TOP) // Update top margin + origin = first = (row*h->cols) + (first%h->cols); + + if(flag & SELECTION_RIGHT) // Update right margin + origin = last = ((last/h->cols)*h->cols) + col; + + if(flag & SELECTION_BOTTOM) // Update bottom margin + origin = last = (row*h->cols) + (last%h->cols); + + if(h->select.begin < h->select.end) + { + h->select.begin = first; + h->select.end = last; + } + else + { + h->select.begin = last; + h->select.end = first; + } + + update_selection(h); + lib3270_set_cursor_address(h,h->select.end); + + return origin; +} + + LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir) { if(!hSession->selected || hSession->select.begin == hSession->select.end) -- libgit2 0.21.2