Commit 84a6f128b862cdb6e9c485c6eea804f1ccd64dd5

Authored by perry.werneck@gmail.com
1 parent bfffb7e5

Incluindo acerto dos cantos da area de selecao pelo mouse

Showing 1 changed file with 58 additions and 5 deletions   Show diff stats
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)
... ...