diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index 7250f26..c628e4e 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -2259,9 +2259,10 @@ static void ctlr_blanks(H3270 *session) } -/* - * Change a character in the 3270 buffer. - * Removes any field attribute defined at that location. +/** + * Change a character in the 3270 buffer, removes any field attribute defined at that location. + * + * */ void ctlr_add(H3270 *hSession, int baddr, unsigned char c, unsigned char cs) { @@ -2430,17 +2431,19 @@ void ctlr_bcopy(H3270 *hSession, int baddr_from, int baddr_to, int count, int mo } #if defined(X3270_ANSI) /*[*/ -/* - * Erase a region of the 3270 buffer, optionally clearing extended attributes - * as well. +/** + * Erase a region of the 3270 buffer, optionally clearing extended attributes as well. + * + * @param hSession Session handle + * */ -void ctlr_aclear(H3270 *session, int baddr, int count, int clear_ea) +void ctlr_aclear(H3270 *hSession, int baddr, int count, int clear_ea) { - if (memcmp((char *) &session->ea_buf[baddr], (char *) session->zero_buf, + if (memcmp((char *) &hSession->ea_buf[baddr], (char *) hSession->zero_buf, count * sizeof(struct lib3270_ea))) { - (void) memset((char *) &session->ea_buf[baddr], 0, + (void) memset((char *) &hSession->ea_buf[baddr], 0, count * sizeof(struct lib3270_ea)); - REGION_CHANGED(session,baddr, baddr + count); + REGION_CHANGED(hSession,baddr, baddr + count); } /* XXX: What about clear_ea? */ } diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index 368b54e..c8a4aea 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -532,6 +532,58 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) return get_text(hSession,0); } +static void copy_chr(H3270 *hSession, int from, int to) +{ + if(hSession->text[from].chr == hSession->text[to].chr) + return; + + hSession->text[to].chr = hSession->text[from].chr; + + memcpy(&hSession->ea_buf[to], &hSession->ea_buf[from],sizeof(struct lib3270_ea)); + hSession->ea_buf[from].fa = 0; + + hSession->update( hSession, + to, + hSession->text[to].chr, + hSession->text[to].attr, + to == hSession->cursor_addr ); +} + +static void clear_chr(H3270 *hSession, int baddr) +{ + hSession->text[baddr].chr = ' '; + + hSession->ea_buf[baddr].cc = EBC_null; + hSession->ea_buf[baddr].cs = 0; + + hSession->update( hSession, + baddr, + hSession->text[baddr].chr, + hSession->text[baddr].attr, + baddr == hSession->cursor_addr ); +} + +int cut_addr(H3270 *hSession, int daddr, int saddr, int maxlen, int *sattr) +{ + if(hSession->ea_buf[saddr].fa) + *sattr = hSession->ea_buf[saddr++].fa; + +/* + if(FA_IS_PROTECTED(*sattr)) + { + saddr = lib3270_get_next_unprotected(hSession,saddr); + *sattr = lib3270_field_attribute(hSession,saddr); + } +*/ + + if(FA_IS_PROTECTED(*sattr) || saddr >= maxlen) + clear_chr(hSession,daddr); + else + copy_chr(hSession,saddr++,daddr); + + return saddr; +} + LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) { @@ -559,10 +611,13 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) int saddr; /* Source addr (First field after the selected area) */ int sattr; /* Source addr attribute */ char *text; + size_t maxlen = hSession->rows * hSession->cols; int f; get_selected_addr(hSession,&daddr,&end); + lib3270_set_cursor_address(hSession,daddr); + if(daddr >= end) return NULL; @@ -583,36 +638,23 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) text[f] = hSession->text[daddr].chr; if(!FA_IS_PROTECTED(dattr)) - { - if(hSession->ea_buf[saddr].fa) - sattr = hSession->ea_buf[saddr].fa; - - if(FA_IS_PROTECTED(sattr)) - { - saddr = lib3270_get_next_unprotected(hSession,saddr); - sattr = lib3270_field_attribute(hSession,saddr); - } - - if(!FA_IS_PROTECTED(sattr)) - { - if(hSession->text[daddr].chr != hSession->text[saddr].chr) - { - hSession->text[daddr].chr = hSession->text[saddr].chr; - hSession->update(hSession,daddr,hSession->text[daddr].chr,hSession->text[daddr].attr,daddr == hSession->cursor_addr); - } - - if(hSession->text[saddr].chr != ' ') - { - hSession->text[saddr].chr = ' '; - hSession->update(hSession,saddr,hSession->text[saddr].chr,hSession->text[saddr].attr,saddr == hSession->cursor_addr); - } - - saddr++; - } - } + saddr = cut_addr(hSession,daddr,saddr,maxlen,&sattr); + + daddr++; + } + + // Move contents of the current field + while(daddr < (maxlen-1) && !hSession->ea_buf[daddr].fa) + { + saddr = cut_addr(hSession,daddr,saddr,maxlen,&sattr); daddr++; } + if(!hSession->ea_buf[daddr].fa) + clear_chr(hSession,daddr); + + hSession->changed(hSession,0,maxlen); + lib3270_unselect(hSession); return text; } diff --git a/ui/00default.xml b/ui/00default.xml index 7bfa3c4..1358d55 100644 --- a/ui/00default.xml +++ b/ui/00default.xml @@ -60,6 +60,7 @@