Commit 07f4615716e34082467eee92f5ae17c4a9739450
1 parent
fb5ef91a
Exists in
master
and in
5 other branches
Implementação inicial do método "cut"
Showing
2 changed files
with
61 additions
and
2 deletions
Show diff stats
src/lib3270/selection.c
@@ -32,6 +32,7 @@ | @@ -32,6 +32,7 @@ | ||
32 | #include <lib3270.h> | 32 | #include <lib3270.h> |
33 | #include <lib3270/session.h> | 33 | #include <lib3270/session.h> |
34 | #include <lib3270/selection.h> | 34 | #include <lib3270/selection.h> |
35 | + #include "3270ds.h" | ||
35 | 36 | ||
36 | #define SELECTION_LEFT 0x01 | 37 | #define SELECTION_LEFT 0x01 |
37 | #define SELECTION_TOP 0x02 | 38 | #define SELECTION_TOP 0x02 |
@@ -529,12 +530,70 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) | @@ -529,12 +530,70 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) | ||
529 | 530 | ||
530 | LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | 531 | LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) |
531 | { | 532 | { |
533 | + | ||
534 | + CHECK_SESSION_HANDLE(hSession); | ||
535 | + | ||
532 | if(!hSession->selected || hSession->select.start == hSession->select.end) | 536 | if(!hSession->selected || hSession->select.start == hSession->select.end) |
533 | return NULL; | 537 | return NULL; |
534 | 538 | ||
535 | - if(!lib3270_connected(hSession)) | 539 | + if(!(lib3270_connected(hSession) && hSession->text)) |
536 | return NULL; | 540 | return NULL; |
537 | 541 | ||
542 | + trace("Rectangle select is %s",lib3270_get_toggle(hSession,LIB3270_TOGGLE_RECTANGLE_SELECT) ? "Active" : "Inactive"); | ||
543 | + | ||
544 | + if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_RECTANGLE_SELECT)) | ||
545 | + { | ||
546 | + // Rectangle cut is not implemented | ||
547 | + } | ||
548 | + else | ||
549 | + { | ||
550 | + int end; | ||
551 | + size_t szText; | ||
552 | + int baddr; | ||
553 | + int saddr; | ||
554 | + char *text; | ||
555 | + int f; | ||
556 | + | ||
557 | + get_selected_addr(hSession,&baddr,&end); | ||
558 | + | ||
559 | + if(baddr >= end) | ||
560 | + return NULL; | ||
561 | + | ||
562 | + szText = (end-baddr)+1; | ||
563 | + | ||
564 | + text = lib3270_malloc(szText+1); | ||
565 | + | ||
566 | + saddr = baddr+szText; | ||
567 | + | ||
568 | + for(f=0;f<szText;f++) | ||
569 | + { | ||
570 | + text[f] = hSession->text[baddr].chr; | ||
571 | + | ||
572 | + if(FA_IS_PROTECTED(hSession->ea_buf[saddr].fa)) | ||
573 | + saddr = lib3270_get_next_unprotected(hSession,saddr); | ||
574 | + | ||
575 | + if(!FA_IS_PROTECTED(hSession->ea_buf[saddr].fa)) | ||
576 | + { | ||
577 | + if(hSession->text[baddr].chr != hSession->text[saddr].chr) | ||
578 | + { | ||
579 | + hSession->text[baddr].chr = hSession->text[saddr].chr; | ||
580 | + hSession->update(hSession,baddr,hSession->text[baddr].chr,hSession->text[baddr].attr,baddr == hSession->cursor_addr); | ||
581 | + } | ||
582 | + | ||
583 | + if(hSession->text[saddr].chr != ' ') | ||
584 | + { | ||
585 | + hSession->text[saddr].chr = ' '; | ||
586 | + hSession->update(hSession,saddr,hSession->text[saddr].chr,hSession->text[saddr].attr,saddr == hSession->cursor_addr); | ||
587 | + } | ||
588 | + | ||
589 | + saddr++; | ||
590 | + } | ||
591 | + baddr++; | ||
592 | + } | ||
593 | + | ||
594 | + lib3270_unselect(hSession); | ||
595 | + return text; | ||
596 | + } | ||
538 | 597 | ||
539 | return NULL; | 598 | return NULL; |
540 | } | 599 | } |