Commit 7c8e110b28c52dbb54f2b5d52b7d700b52288f30

Authored by perry.werneck@gmail.com
1 parent 05e7e63d

Iniciando implementação de seleção acessível

Showing 1 changed file with 52 additions and 9 deletions   Show diff stats
@@ -407,6 +407,41 @@ static char * get_text(H3270 *hSession,unsigned char all) @@ -407,6 +407,41 @@ static char * get_text(H3270 *hSession,unsigned char all)
407 return ret; 407 return ret;
408 } 408 }
409 409
  410 +LIB3270_EXPORT char * lib3270_get_region(H3270 *h, int start_pos, int end_pos, unsigned char all)
  411 +{
  412 + char * text;
  413 + int maxlen;
  414 + int sz = 0;
  415 + int baddr;
  416 +
  417 + CHECK_SESSION_HANDLE(h);
  418 +
  419 + if(!lib3270_connected(h))
  420 + return NULL;
  421 +
  422 + maxlen = h->rows * (h->cols+1);
  423 +
  424 + if(start_pos < 0 || start_pos > maxlen || end_pos < 0 || end_pos > maxlen || end_pos < start_pos)
  425 + return NULL;
  426 +
  427 + text = malloc(maxlen);
  428 +
  429 + for(baddr=start_pos;baddr<end_pos;baddr++)
  430 + {
  431 + if(all || h->text[baddr].attr & LIB3270_ATTR_SELECTED)
  432 + text[sz++] = (h->text[baddr].attr & LIB3270_ATTR_CG) ? ' ' : h->text[baddr].chr;
  433 +
  434 + if((baddr%h->cols) == 0 && sz > 0)
  435 + text[sz++] = '\n';
  436 + }
  437 + text[sz++] = 0;
  438 +
  439 + return realloc(text,sz);
  440 +}
  441 +
  442 +
  443 +
  444 +
410 LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) 445 LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len)
411 { 446 {
412 char * buffer; 447 char * buffer;
@@ -468,25 +503,33 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) @@ -468,25 +503,33 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession)
468 return get_text(hSession,0); 503 return get_text(hSession,0);
469 } 504 }
470 505
471 -LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end) 506 +LIB3270_EXPORT int lib3270_get_selection_bounds(H3270 *hSession, int *start, int *end)
472 { 507 {
  508 + int first, last;
  509 +
473 CHECK_SESSION_HANDLE(hSession); 510 CHECK_SESSION_HANDLE(hSession);
474 511
475 if(!hSession->selected || hSession->select.begin == hSession->select.end) 512 if(!hSession->selected || hSession->select.begin == hSession->select.end)
476 - return -1; 513 + return 0;
477 514
478 if(hSession->select.end > hSession->select.begin) 515 if(hSession->select.end > hSession->select.begin)
479 { 516 {
480 - *begin = hSession->select.begin;  
481 - *end = hSession->select.end; 517 + first = hSession->select.begin;
  518 + last = hSession->select.end;
482 } 519 }
483 else 520 else
484 { 521 {
485 - *begin = hSession->select.end;  
486 - *end = hSession->select.begin; 522 + first = hSession->select.end;
  523 + last = hSession->select.begin;
487 } 524 }
488 525
489 - return 0; 526 + if(start)
  527 + *start = first;
  528 +
  529 + if(end)
  530 + *end = last;
  531 +
  532 + return 1;
490 } 533 }
491 534
492 LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) 535 LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to)
@@ -494,7 +537,7 @@ LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) @@ -494,7 +537,7 @@ LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to)
494 int pos[2]; 537 int pos[2];
495 int rows, cols, f, step; 538 int rows, cols, f, step;
496 539
497 - if(lib3270_get_selected_addr(hSession,&pos[0],&pos[1])) 540 + if(!lib3270_get_selection_bounds(hSession,&pos[0],&pos[1]))
498 return from; 541 return from;
499 542
500 rows = (to / hSession->cols) - (from / hSession->cols); 543 rows = (to / hSession->cols) - (from / hSession->cols);
@@ -533,7 +576,7 @@ LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int orig @@ -533,7 +576,7 @@ LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int orig
533 { 576 {
534 int first, last, row, col; 577 int first, last, row, col;
535 578
536 - if(lib3270_get_selected_addr(h,&first,&last)) 579 + if(!lib3270_get_selection_bounds(h,&first,&last))
537 return origin; 580 return origin;
538 581
539 flag &= 0x1f; 582 flag &= 0x1f;