Commit 757cb72fd488760b57a38d17d104defeb8e43aab
1 parent
1c28a0e5
Exists in
master
and in
5 other branches
Incluindo acerto dos cantos da area de selecao pelo mouse
Showing
3 changed files
with
83 additions
and
15 deletions
Show diff stats
src/gtk/v3270/mouse.c
| ... | ... | @@ -180,7 +180,7 @@ gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) |
| 180 | 180 | else if(terminal->moving) |
| 181 | 181 | { |
| 182 | 182 | // Move selected area |
| 183 | - terminal->selection_addr = lib3270_move_selected_area(terminal->host,terminal->selection_addr,baddr); | |
| 183 | + terminal->selection_addr = lib3270_drag_selection(terminal->host,terminal->pointer,terminal->selection_addr,baddr); | |
| 184 | 184 | } |
| 185 | 185 | else if(terminal->pointer_id == LIB3270_CURSOR_NORMAL) |
| 186 | 186 | { |
| ... | ... | @@ -190,41 +190,41 @@ gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) |
| 190 | 190 | GdkWindow *window = gtk_widget_get_window(widget); |
| 191 | 191 | trace("Pointer changes to %04x",new_pointer); |
| 192 | 192 | |
| 193 | - switch(new_pointer & 0x1F) | |
| 193 | + switch(new_pointer & 0x0F) | |
| 194 | 194 | { |
| 195 | 195 | case 0x00: |
| 196 | 196 | gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_NORMAL]); |
| 197 | 197 | break; |
| 198 | 198 | |
| 199 | - case 0x05: | |
| 199 | + case 0x02: | |
| 200 | 200 | gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP]); |
| 201 | 201 | break; |
| 202 | 202 | |
| 203 | - case 0x0d: | |
| 203 | + case 0x06: | |
| 204 | 204 | gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP_RIGHT]); |
| 205 | 205 | break; |
| 206 | 206 | |
| 207 | - case 0x09: | |
| 207 | + case 0x04: | |
| 208 | 208 | gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_RIGHT]); |
| 209 | 209 | break; |
| 210 | 210 | |
| 211 | - case 0x03: | |
| 211 | + case 0x01: | |
| 212 | 212 | gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_LEFT]); |
| 213 | 213 | break; |
| 214 | 214 | |
| 215 | - case 0x13: | |
| 215 | + case 0x09: | |
| 216 | 216 | gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM_LEFT]); |
| 217 | 217 | break; |
| 218 | 218 | |
| 219 | - case 0x11: | |
| 219 | + case 0x08: | |
| 220 | 220 | gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM]); |
| 221 | 221 | break; |
| 222 | 222 | |
| 223 | - case 0x19: | |
| 223 | + case 0x0c: | |
| 224 | 224 | gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_BOTTOM_RIGHT]); |
| 225 | 225 | break; |
| 226 | 226 | |
| 227 | - case 0x07: | |
| 227 | + case 0x03: | |
| 228 | 228 | gdk_window_set_cursor(window,v3270_cursor[V3270_CURSOR_SELECTION_TOP_LEFT]); |
| 229 | 229 | break; |
| 230 | 230 | ... | ... |
src/include/lib3270/selection.h
| ... | ... | @@ -86,6 +86,21 @@ |
| 86 | 86 | LIB3270_EXPORT int lib3270_move_selected_area(H3270 *h, int from, int to); |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | + * Drag selected region. | |
| 90 | + * | |
| 91 | + * Move or resize selected box according to the selection flags. | |
| 92 | + * | |
| 93 | + * @param h Session handle. | |
| 94 | + * @param flag Selection flag. | |
| 95 | + * @param origin Reference position (got from mouse button down or other move action). | |
| 96 | + * @param baddr New position. | |
| 97 | + * | |
| 98 | + * @return The new reference position. | |
| 99 | + * | |
| 100 | + */ | |
| 101 | + LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int origin, int baddr); | |
| 102 | + | |
| 103 | + /** | |
| 89 | 104 | * Get addresses of selected area. |
| 90 | 105 | * |
| 91 | 106 | * @param h Session handle. | ... | ... |
src/lib3270/selection.c
| ... | ... | @@ -34,6 +34,12 @@ |
| 34 | 34 | #include <lib3270/session.h> |
| 35 | 35 | #include <lib3270/selection.h> |
| 36 | 36 | |
| 37 | + #define SELECTION_LEFT 0x01 | |
| 38 | + #define SELECTION_TOP 0x02 | |
| 39 | + #define SELECTION_RIGHT 0x04 | |
| 40 | + #define SELECTION_BOTTOM 0x08 | |
| 41 | + #define SELECTION_ACTIVE 0x10 | |
| 42 | + | |
| 37 | 43 | static void update_selection(H3270 *session); |
| 38 | 44 | |
| 39 | 45 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| ... | ... | @@ -240,19 +246,19 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba |
| 240 | 246 | |
| 241 | 247 | row = baddr / hSession->cols; |
| 242 | 248 | col = baddr % hSession->cols; |
| 243 | - rc |= 0x01; | |
| 249 | + rc |= SELECTION_ACTIVE; | |
| 244 | 250 | |
| 245 | 251 | if( (col == 0) || !(hSession->text[baddr-1].attr & LIB3270_ATTR_SELECTED) ) |
| 246 | - rc |= 0x02; | |
| 252 | + rc |= SELECTION_LEFT; | |
| 247 | 253 | |
| 248 | 254 | if( (row == 0) || !(hSession->text[baddr-hSession->cols].attr & LIB3270_ATTR_SELECTED) ) |
| 249 | - rc |= 0x04; | |
| 255 | + rc |= SELECTION_TOP; | |
| 250 | 256 | |
| 251 | 257 | if( (col == hSession->cols) || !(hSession->text[baddr+1].attr & LIB3270_ATTR_SELECTED) ) |
| 252 | - rc |= 0x08; | |
| 258 | + rc |= SELECTION_RIGHT; | |
| 253 | 259 | |
| 254 | 260 | if( (row == hSession->rows) || !(hSession->text[baddr+hSession->cols].attr & LIB3270_ATTR_SELECTED) ) |
| 255 | - rc |= 0x10; | |
| 261 | + rc |= SELECTION_BOTTOM; | |
| 256 | 262 | |
| 257 | 263 | return rc; |
| 258 | 264 | } |
| ... | ... | @@ -475,6 +481,53 @@ LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) |
| 475 | 481 | return from+step; |
| 476 | 482 | } |
| 477 | 483 | |
| 484 | +LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int origin, int baddr) | |
| 485 | +{ | |
| 486 | + int first, last, row, col; | |
| 487 | + | |
| 488 | + if(lib3270_get_selected_addr(h,&first,&last)) | |
| 489 | + return origin; | |
| 490 | + | |
| 491 | + flag &= 0x1f; | |
| 492 | + | |
| 493 | + if(!flag) | |
| 494 | + return origin; | |
| 495 | + else if(flag == SELECTION_ACTIVE) | |
| 496 | + return lib3270_move_selected_area(h,origin,baddr); | |
| 497 | + | |
| 498 | + row = baddr/h->cols; | |
| 499 | + col = baddr%h->cols; | |
| 500 | + | |
| 501 | + if(flag & SELECTION_LEFT) // Update left margin | |
| 502 | + origin = first = ((first/h->cols)*h->cols) + col; | |
| 503 | + | |
| 504 | + if(flag & SELECTION_TOP) // Update top margin | |
| 505 | + origin = first = (row*h->cols) + (first%h->cols); | |
| 506 | + | |
| 507 | + if(flag & SELECTION_RIGHT) // Update right margin | |
| 508 | + origin = last = ((last/h->cols)*h->cols) + col; | |
| 509 | + | |
| 510 | + if(flag & SELECTION_BOTTOM) // Update bottom margin | |
| 511 | + origin = last = (row*h->cols) + (last%h->cols); | |
| 512 | + | |
| 513 | + if(h->select.begin < h->select.end) | |
| 514 | + { | |
| 515 | + h->select.begin = first; | |
| 516 | + h->select.end = last; | |
| 517 | + } | |
| 518 | + else | |
| 519 | + { | |
| 520 | + h->select.begin = last; | |
| 521 | + h->select.end = first; | |
| 522 | + } | |
| 523 | + | |
| 524 | + update_selection(h); | |
| 525 | + lib3270_set_cursor_address(h,h->select.end); | |
| 526 | + | |
| 527 | + return origin; | |
| 528 | +} | |
| 529 | + | |
| 530 | + | |
| 478 | 531 | LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir) |
| 479 | 532 | { |
| 480 | 533 | if(!hSession->selected || hSession->select.begin == hSession->select.end) | ... | ... |