From 2083e8680040715339f8c93883df51ba054df13b Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Thu, 12 Apr 2012 14:28:40 +0000 Subject: [PATCH] Acessibilidade, incluindo limpeza da area selecionada ao mover o cursor, incluindo tratamento multi-sessao em mais métodos de biblioteca --- ansi.c | 42 +++++++++++++++++++++--------------------- api.h | 5 ----- ctlr.c | 12 ++++++------ globals.h | 11 +++++++---- glue.c | 2 +- init.c | 25 +++++++++++++++---------- kybd.c | 281 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- paste.c | 6 +++--- screen.c | 12 ++++++++++-- selection.c | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------ sf.c | 2 +- 11 files changed, 267 insertions(+), 358 deletions(-) diff --git a/ansi.c b/ansi.c index f8dc50a..3f2d24f 100644 --- a/ansi.c +++ b/ansi.c @@ -520,7 +520,7 @@ dec_restore_cursor(int ig1 unused, int ig2 unused) fg = saved_fg; bg = saved_bg; gr = saved_gr; - cursor_move(saved_cursor); + cursor_move(&h3270,saved_cursor); held_wrap = False; return DATA; } @@ -530,10 +530,10 @@ ansi_newline(int ig1 unused, int ig2 unused) { int nc; - cursor_move(h3270.cursor_addr - (h3270.cursor_addr % h3270.cols)); + cursor_move(&h3270,h3270.cursor_addr - (h3270.cursor_addr % h3270.cols)); nc = h3270.cursor_addr + h3270.cols; if (nc < scroll_bottom * h3270.cols) - cursor_move(nc); + cursor_move(&h3270,nc); else ansi_scroll(); held_wrap = False; @@ -549,9 +549,9 @@ ansi_cursor_up(int nn, int ig2 unused) nn = 1; rr = h3270.cursor_addr / h3270.cols; if (rr - nn < 0) - cursor_move(h3270.cursor_addr % h3270.cols); + cursor_move(&h3270, h3270.cursor_addr % h3270.cols); else - cursor_move(h3270.cursor_addr - (nn * h3270.cols)); + cursor_move(&h3270, h3270.cursor_addr - (nn * h3270.cols)); held_wrap = False; return DATA; } @@ -647,9 +647,9 @@ ansi_cursor_down(int nn, int ig2 unused) nn = 1; rr = h3270.cursor_addr / h3270.cols; if (rr + nn >= h3270.cols) - cursor_move((h3270.cols-1)*h3270.cols + (h3270.cursor_addr%h3270.cols)); + cursor_move(&h3270,(h3270.cols-1)*h3270.cols + (h3270.cursor_addr%h3270.cols)); else - cursor_move(h3270.cursor_addr + (nn * h3270.cols)); + cursor_move(&h3270,h3270.cursor_addr + (nn * h3270.cols)); held_wrap = False; return DATA; } @@ -666,7 +666,7 @@ ansi_cursor_right(int nn, int ig2 unused) return DATA; if (cc + nn >= h3270.cols) nn = h3270.cols - 1 - cc; - cursor_move(h3270.cursor_addr + nn); + cursor_move(&h3270,h3270.cursor_addr + nn); held_wrap = False; return DATA; } @@ -687,7 +687,7 @@ ansi_cursor_left(int nn, int ig2 unused) return DATA; if (nn > cc) nn = cc; - cursor_move(h3270.cursor_addr - nn); + cursor_move(&h3270,h3270.cursor_addr - nn); return DATA; } @@ -698,7 +698,7 @@ ansi_cursor_motion(int n1, int n2) if (n1 > h3270.rows) n1 = h3270.rows; if (n2 < 1) n2 = 1; if (n2 > h3270.cols) n2 = h3270.cols; - cursor_move((n1 - 1) * h3270.cols + (n2 - 1)); + cursor_move(&h3270,(n1 - 1) * h3270.cols + (n2 - 1)); held_wrap = False; return DATA; } @@ -936,10 +936,10 @@ ansi_backspace(int ig1 unused, int ig2 unused) } if (rev_wraparound_mode) { if (h3270.cursor_addr > (scroll_top - 1) * h3270.cols) - cursor_move(h3270.cursor_addr - 1); + cursor_move(&h3270,h3270.cursor_addr - 1); } else { if (h3270.cursor_addr % h3270.cols) - cursor_move(h3270.cursor_addr - 1); + cursor_move(&h3270,h3270.cursor_addr - 1); } return DATA; } @@ -948,7 +948,7 @@ static enum state ansi_cr(int ig1 unused, int ig2 unused) { if (h3270.cursor_addr % h3270.cols) - cursor_move(h3270.cursor_addr - (h3270.cursor_addr % h3270.cols)); + cursor_move(&h3270,h3270.cursor_addr - (h3270.cursor_addr % h3270.cols)); if (auto_newline_mode) (void) ansi_lf(0, 0); held_wrap = False; @@ -965,12 +965,12 @@ ansi_lf(int ig1 unused, int ig2 unused) /* If we're below the scrolling region, don't scroll. */ if ((h3270.cursor_addr / h3270.cols) >= scroll_bottom) { if (nc < h3270.rows * h3270.cols) - cursor_move(nc); + cursor_move(&h3270,nc); return DATA; } if (nc < scroll_bottom * h3270.cols) - cursor_move(nc); + cursor_move(&h3270,nc); else ansi_scroll(); return DATA; @@ -988,7 +988,7 @@ ansi_htab(int ig1 unused, int ig2 unused) for (i = col+1; i < h3270.cols-1; i++) if (tabs[i/8] & 1<<(i%8)) break; - cursor_move(h3270.cursor_addr - col + i); + cursor_move(&h3270,h3270.cursor_addr - col + i); return DATA; } @@ -1007,13 +1007,13 @@ ansi_nop(int ig1 unused, int ig2 unused) #define PWRAP { \ nc = h3270.cursor_addr + 1; \ if (nc < scroll_bottom * h3270.cols) \ - cursor_move(nc); \ + cursor_move(&h3270,nc); \ else { \ if (h3270.cursor_addr / h3270.cols >= scroll_bottom) \ - cursor_move(h3270.cursor_addr / h3270.cols * h3270.cols); \ + cursor_move(&h3270,h3270.cursor_addr / h3270.cols * h3270.cols); \ else { \ ansi_scroll(); \ - cursor_move(nc - h3270.cols); \ + cursor_move(&h3270,nc - h3270.cols); \ } \ } \ } @@ -1188,7 +1188,7 @@ ansi_printing(int ig1 unused, int ig2 unused) } } else { if ((h3270.cursor_addr % h3270.cols) != (h3270.cols - 1)) - cursor_move(h3270.cursor_addr + 1); + cursor_move(&h3270,h3270.cursor_addr + 1); } return DATA; } @@ -1554,7 +1554,7 @@ dec_scrolling_region(int top, int bottom) if (top <= bottom && (top > 1 || bottom < h3270.rows)) { scroll_top = top; scroll_bottom = bottom; - cursor_move(0); + cursor_move(&h3270,0); } else { scroll_top = 1; scroll_bottom = h3270.rows; diff --git a/api.h b/api.h index f0a8497..43ee5a1 100644 --- a/api.h +++ b/api.h @@ -399,11 +399,6 @@ // LOCAL_EXTERN void screen_suspend(H3270 *session); LOCAL_EXTERN void screen_disp(H3270 *session); - /* Cursor calls */ - #define cursor_get_addr(void) lib3270_get_cursor_address(NULL) - #define cursor_set_addr(x) lib3270_set_cursor_address(NULL,x) - #define cursor_move(x) lib3270_set_cursor_address(NULL,x) - #include #define host_connect(n,wait) lib3270_connect(NULL,n,wait) diff --git a/ctlr.c b/ctlr.c index 3d453b1..1e7a737 100644 --- a/ctlr.c +++ b/ctlr.c @@ -1093,7 +1093,7 @@ ctlr_erase_all_unprotected(void) do { INC_BA(baddr); if (!f) { - cursor_move(baddr); + cursor_move(&h3270,baddr); f = True; } if (!h3270.ea_buf[baddr].fa) { @@ -1108,7 +1108,7 @@ ctlr_erase_all_unprotected(void) } } while (baddr != sbaddr); if (!f) - cursor_move(0); + cursor_move(&h3270,0); } else { ctlr_clear(&h3270,True); } @@ -1264,7 +1264,7 @@ ctlr_write(unsigned char buf[], int buflen, Boolean erase) if (previous != SBA) trace_ds("%s",rcba(buffer_addr)); previous = ORDER; - cursor_move(h3270.buffer_addr); + cursor_move(&h3270,h3270.buffer_addr); last_cmd = True; last_zpt = False; break; @@ -1989,7 +1989,7 @@ ctlr_write_sscp_lu(unsigned char buf[], int buflen) break; } } - cursor_move(h3270.buffer_addr); + cursor_move(&h3270,h3270.buffer_addr); sscp_start = h3270.buffer_addr; /* Unlock the keyboard. */ @@ -2337,7 +2337,7 @@ ctlr_clear(H3270 *session, Boolean can_snap) /* Clear the screen. */ (void) memset((char *)session->ea_buf, 0, session->rows*session->cols*sizeof(struct ea)); - cursor_move(0); + cursor_move(&h3270,0); session->buffer_addr = 0; lib3270_unselect(session); session->formatted = False; @@ -2364,7 +2364,7 @@ ctlr_blanks(void) if (!h3270.ea_buf[baddr].fa) h3270.ea_buf[baddr].cc = EBC_space; } - cursor_move(0); + cursor_move(&h3270,0); h3270.buffer_addr = 0; lib3270_unselect(&h3270); h3270.formatted = False; diff --git a/globals.h b/globals.h index 06475f7..d04b42e 100644 --- a/globals.h +++ b/globals.h @@ -246,7 +246,8 @@ LIB3270_INTERNAL Widget toplevel; LIB3270_INTERNAL Boolean visible_control; LIB3270_INTERNAL int *xtra_width; -#if defined(X3270_DISPLAY) /*[*/ +/* +#if defined(X3270_DISPLAY) LIB3270_INTERNAL Atom a_delete_me; LIB3270_INTERNAL Atom a_save_yourself; LIB3270_INTERNAL Atom a_state; @@ -257,7 +258,8 @@ LIB3270_INTERNAL int *xtra_width; LIB3270_INTERNAL Window root_window; LIB3270_INTERNAL char *user_title; LIB3270_INTERNAL unsigned char xk_selector; -#endif /*]*/ +#endif +*/ /* Connection state */ LIB3270_INTERNAL enum ft_state ft_state; @@ -372,6 +374,7 @@ enum keytype /* Library internal calls */ -void key_ACharacter(unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped); -void lib3270_initialize(void); +LIB3270_INTERNAL void key_ACharacter(unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped); +LIB3270_INTERNAL void lib3270_initialize(void); +LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr); diff --git a/glue.c b/glue.c index ce012ca..fdf0769 100644 --- a/glue.c +++ b/glue.c @@ -126,7 +126,7 @@ static void initialize(void) #endif h3270.selected = 0; - h3270.select.begin = h3270.select.end = 0; + h3270.select.start = h3270.select.end = 0; // initialize_toggles(&h3270); #if defined(_WIN32) diff --git a/init.c b/init.c index 2884655..05ff9c8 100644 --- a/init.c +++ b/init.c @@ -103,6 +103,10 @@ static void update_oia(H3270 *session, LIB3270_FLAG id, unsigned char on) { } +static void update_selection(H3270 *session, int start, int end) +{ +} + static void lib3270_session_init(H3270 *hSession, const char *model) { int ovc, ovr; @@ -116,16 +120,17 @@ static void lib3270_session_init(H3270 *hSession, const char *model) initialize_toggles(hSession); // Dummy calls to avoid "ifs" - hSession->update = update_char; - hSession->update_model = update_model; - hSession->update_cursor = update_cursor; - hSession->set_selection = nop_char; - hSession->ctlr_done = nop; - hSession->changed = changed; - hSession->erase = screen_disp; - hSession->suspend = nop; - hSession->resume = screen_disp; - hSession->update_oia = update_oia; + hSession->update = update_char; + hSession->update_model = update_model; + hSession->update_cursor = update_cursor; + hSession->set_selection = nop_char; + hSession->ctlr_done = nop; + hSession->changed = changed; + hSession->erase = screen_disp; + hSession->suspend = nop; + hSession->resume = screen_disp; + hSession->update_oia = update_oia; + hSession->update_selection = update_selection; hSession->sock = -1; hSession->model_num = -1; diff --git a/kybd.c b/kybd.c index bb610f8..35d7ae3 100644 --- a/kybd.c +++ b/kybd.c @@ -966,7 +966,7 @@ static Boolean key_Character(int code, Boolean with_ge, Boolean pasting, Boolean else INC_BA(baddr); } - cursor_move(baddr); + cursor_move(&h3270,baddr); } (void) ctlr_dbcs_postprocess(); @@ -1387,7 +1387,7 @@ LIB3270_KEY_ACTION( tab ) return 0; } #endif /*]*/ - cursor_move(next_unprotected(h3270.cursor_addr)); + cursor_move(&h3270,next_unprotected(h3270.cursor_addr)); return 0; } @@ -1427,12 +1427,12 @@ LIB3270_KEY_ACTION( backtab ) break; DEC_BA(baddr); if (baddr == sbaddr) { - cursor_move(0); + cursor_move(&h3270,0); return 0; } } INC_BA(baddr); - cursor_move(baddr); + cursor_move(&h3270,baddr); return 0; } @@ -1546,11 +1546,11 @@ LIB3270_ACTION( firstfield ) return 0; } #endif /*]*/ - if (!h3270.formatted) { - cursor_move(0); + if (!hSession->formatted) { + cursor_move(hSession,0); return 0; } - cursor_move(next_unprotected(h3270.rows*h3270.cols-1)); + cursor_move(hSession,next_unprotected(hSession->rows*hSession->cols-1)); return 0; } @@ -1570,7 +1570,7 @@ do_left(void) d = ctlr_dbcs_state(baddr); if (IS_LEFT(d)) DEC_BA(baddr); - cursor_move(baddr); + cursor_move(&h3270,baddr); } /* @@ -1603,7 +1603,7 @@ LIB3270_CURSOR_ACTION( left ) } #endif /*]*/ - if (!h3270.flipped) + if (!hSession->flipped) { do_left(); } @@ -1611,10 +1611,10 @@ LIB3270_CURSOR_ACTION( left ) { register int baddr; - baddr = h3270.cursor_addr; + baddr = hSession->cursor_addr; INC_BA(baddr); /* XXX: DBCS? */ - cursor_move(baddr); + lib3270_set_cursor_address(hSession,baddr); } return 0; } @@ -1720,7 +1720,7 @@ LIB3270_ACTION( delete ) DEC_BA(baddr); if (!hSession->ea_buf[baddr].fa) - cursor_move(baddr); + cursor_move(hSession,baddr); } screen_disp(hSession); return 0; @@ -1745,16 +1745,16 @@ LIB3270_ACTION( backspace ) #endif /*]*/ if (reverse) (void) do_delete(); - else if (!h3270.flipped) + else if (!hSession->flipped) do_left(); else { register int baddr; - baddr = h3270.cursor_addr; + baddr = hSession->cursor_addr; DEC_BA(baddr); - cursor_move(baddr); + cursor_move(hSession,baddr); } - screen_disp(&h3270); + screen_disp(hSession); return 0; } @@ -1784,7 +1784,7 @@ do_erase(void) if (h3270.ea_buf[h3270.cursor_addr].cc == EBC_si) { baddr = h3270.cursor_addr; DEC_BA(baddr); - cursor_move(baddr); + cursor_move(&h3270,baddr); } /* @@ -1797,7 +1797,7 @@ do_erase(void) if (IS_RIGHT(d)) { baddr = h3270.cursor_addr; DEC_BA(baddr); - cursor_move(baddr); + cursor_move(&h3270,baddr); } /* @@ -1813,7 +1813,7 @@ do_erase(void) baddr = h3270.cursor_addr; DEC_BA(baddr); if (h3270.ea_buf[baddr].cc == EBC_so && h3270.ea_buf[h3270.cursor_addr].cc == EBC_si) { - cursor_move(baddr); + cursor_move(&h3270,baddr); (void) do_delete(); } screen_disp(&h3270); @@ -1863,14 +1863,14 @@ LIB3270_CURSOR_ACTION( right ) return 0; } #endif /*]*/ - if (!h3270.flipped) + if (!hSession->flipped) { - baddr = h3270.cursor_addr; + baddr = hSession->cursor_addr; INC_BA(baddr); d = ctlr_dbcs_state(baddr); if (IS_RIGHT(d)) INC_BA(baddr); - cursor_move(baddr); + lib3270_set_cursor_address(hSession,baddr); } else { @@ -1937,30 +1937,30 @@ LIB3270_ACTION( previousword ) if (IN_ANSI) return 0; #endif /*]*/ - if (!h3270.formatted) + if (!hSession->formatted) return 0; - baddr = h3270.cursor_addr; - prot = FA_IS_PROTECTED(get_field_attribute(&h3270,baddr)); + baddr = hSession->cursor_addr; + prot = FA_IS_PROTECTED(get_field_attribute(hSession,baddr)); /* Skip to before this word, if in one now. */ if (!prot) { - c = h3270.ea_buf[baddr].cc; - while (!h3270.ea_buf[baddr].fa && c != EBC_space && c != EBC_null) { + c = hSession->ea_buf[baddr].cc; + while (!hSession->ea_buf[baddr].fa && c != EBC_space && c != EBC_null) { DEC_BA(baddr); - if (baddr == h3270.cursor_addr) + if (baddr == hSession->cursor_addr) return 0; - c = h3270.ea_buf[baddr].cc; + c = hSession->ea_buf[baddr].cc; } } baddr0 = baddr; /* Find the end of the preceding word. */ do { - c = h3270.ea_buf[baddr].cc; - if (h3270.ea_buf[baddr].fa) { + c = hSession->ea_buf[baddr].cc; + if (hSession->ea_buf[baddr].fa) { DEC_BA(baddr); - prot = FA_IS_PROTECTED(get_field_attribute(&h3270,baddr)); + prot = FA_IS_PROTECTED(get_field_attribute(hSession,baddr)); continue; } if (!prot && c != EBC_space && c != EBC_null) @@ -1974,13 +1974,13 @@ LIB3270_ACTION( previousword ) /* Go it its front. */ for (;;) { DEC_BA(baddr); - c = h3270.ea_buf[baddr].cc; - if (h3270.ea_buf[baddr].fa || c == EBC_space || c == EBC_null) { + c = hSession->ea_buf[baddr].cc; + if (hSession->ea_buf[baddr].fa || c == EBC_space || c == EBC_null) { break; } } INC_BA(baddr); - cursor_move(baddr); + cursor_move(hSession,baddr); return 0; } @@ -2088,62 +2088,54 @@ LIB3270_ACTION( nextword ) if (IN_ANSI) return 0; #endif /*]*/ - if (!h3270.formatted) + if (!hSession->formatted) return 0; /* If not in an unprotected field, go to the next unprotected word. */ - if (h3270.ea_buf[h3270.cursor_addr].fa || - FA_IS_PROTECTED(get_field_attribute(&h3270,h3270.cursor_addr))) { - baddr = nu_word(h3270.cursor_addr); + if (hSession->ea_buf[hSession->cursor_addr].fa || + FA_IS_PROTECTED(get_field_attribute(hSession,hSession->cursor_addr))) { + baddr = nu_word(hSession->cursor_addr); if (baddr != -1) - cursor_move(baddr); + cursor_move(hSession,baddr); return 0; } /* If there's another word in this field, go to it. */ - baddr = nt_word(h3270.cursor_addr); + baddr = nt_word(hSession->cursor_addr); if (baddr != -1) { - cursor_move(baddr); + cursor_move(hSession,baddr); return 0; } /* If in a word, go to just after its end. */ - c = h3270.ea_buf[h3270.cursor_addr].cc; + c = hSession->ea_buf[hSession->cursor_addr].cc; if (c != EBC_space && c != EBC_null) { - baddr = h3270.cursor_addr; + baddr = hSession->cursor_addr; do { - c = h3270.ea_buf[baddr].cc; + c = hSession->ea_buf[baddr].cc; if (c == EBC_space || c == EBC_null) { - cursor_move(baddr); + cursor_move(hSession,baddr); return 0; - } else if (h3270.ea_buf[baddr].fa) { + } else if (hSession->ea_buf[baddr].fa) { baddr = nu_word(baddr); if (baddr != -1) - cursor_move(baddr); + cursor_move(hSession,baddr); return 0; } INC_BA(baddr); - } while (baddr != h3270.cursor_addr); + } while (baddr != hSession->cursor_addr); } /* Otherwise, go to the next unprotected word. */ else { - baddr = nu_word(h3270.cursor_addr); + baddr = nu_word(hSession->cursor_addr); if (baddr != -1) - cursor_move(baddr); + cursor_move(hSession,baddr); } return 0; } -/* - * Cursor up 1 position. - */ /* -void Up_action(Widget w unused, XEvent *event, String *params, Cardinal *num_params) -{ - action_CursorUp(); -} -*/ /** * Cursor up 1 position. @@ -2175,24 +2167,13 @@ LIB3270_CURSOR_ACTION( up ) return 0; } #endif /*]*/ - baddr = h3270.cursor_addr - h3270.cols; + baddr = hSession->cursor_addr - hSession->cols; if (baddr < 0) - baddr = (h3270.cursor_addr + (h3270.rows * h3270.cols)) - h3270.cols; - cursor_move(baddr); + baddr = (hSession->cursor_addr + (hSession->rows * hSession->cols)) - hSession->cols; + lib3270_set_cursor_address(hSession,baddr); return 0; } - -/* - * Cursor down 1 position. - */ /* -void -Down_action(Widget w unused, XEvent *event, String *params, Cardinal *num_params) -{ - action_CursorDown(); -} -*/ - /** * Cursor down 1 position. * @@ -2224,8 +2205,8 @@ LIB3270_CURSOR_ACTION( down ) return 0; } #endif /*]*/ - baddr = (h3270.cursor_addr + h3270.cols) % (h3270.cols * h3270.rows); - cursor_move(baddr); + baddr = (hSession->cursor_addr + hSession->cols) % (hSession->cols * hSession->rows); + lib3270_set_cursor_address(hSession,baddr); return 0; } @@ -2252,14 +2233,14 @@ LIB3270_CURSOR_ACTION( newline ) return 0; } #endif /*]*/ - baddr = (h3270.cursor_addr + h3270.cols) % (h3270.cols * h3270.rows); /* down */ - baddr = (baddr / h3270.cols) * h3270.cols; /* 1st col */ - faddr = find_field_attribute(&h3270,baddr); - fa = h3270.ea_buf[faddr].fa; + baddr = (hSession->cursor_addr + hSession->cols) % (hSession->cols * hSession->rows); /* down */ + baddr = (baddr / hSession->cols) * hSession->cols; /* 1st col */ + faddr = find_field_attribute(hSession,baddr); + fa = hSession->ea_buf[faddr].fa; if (faddr != baddr && !FA_IS_PROTECTED(fa)) - cursor_move(baddr); + cursor_move(hSession,baddr); else - cursor_move(next_unprotected(baddr)); + cursor_move(hSession,next_unprotected(baddr)); return 0; } @@ -2282,7 +2263,7 @@ LIB3270_ACTION( dup ) if (key_Character(EBC_dup, False, False, NULL)) { screen_disp(hSession); - cursor_move(next_unprotected(hSession->cursor_addr)); + cursor_move(hSession,next_unprotected(hSession->cursor_addr)); } } @@ -2369,8 +2350,8 @@ LIB3270_ACTION( clear ) } #endif /*]*/ h3270.buffer_addr = 0; - ctlr_clear(&h3270,True); - cursor_move(0); + ctlr_clear(hSession,True); + cursor_move(hSession,0); if (CONNECTED) key_AID(AID_CLEAR); return 0; @@ -2626,37 +2607,37 @@ LIB3270_ACTION( eraseinput ) /* find first field attribute */ baddr = 0; do { - if (h3270.ea_buf[baddr].fa) + if (hSession->ea_buf[baddr].fa) break; INC_BA(baddr); } while (baddr != 0); sbaddr = baddr; f = False; do { - fa = h3270.ea_buf[baddr].fa; + fa = hSession->ea_buf[baddr].fa; if (!FA_IS_PROTECTED(fa)) { mdt_clear(baddr); do { INC_BA(baddr); if (!f) { - cursor_move(baddr); + cursor_move(hSession,baddr); f = True; } - if (!h3270.ea_buf[baddr].fa) { + if (!hSession->ea_buf[baddr].fa) { ctlr_add(baddr, EBC_null, 0); } - } while (!h3270.ea_buf[baddr].fa); + } while (!hSession->ea_buf[baddr].fa); } else { /* skip protected */ do { INC_BA(baddr); - } while (!h3270.ea_buf[baddr].fa); + } while (!hSession->ea_buf[baddr].fa); } } while (baddr != sbaddr); if (!f) - cursor_move(0); + cursor_move(hSession,0); } else { ctlr_clear(hSession,True); - cursor_move(0); + cursor_move(hSession,0); } screen_disp(hSession); return 0; @@ -2768,7 +2749,7 @@ LIB3270_ACTION( deletefield ) DEC_BA(baddr); INC_BA(baddr); mdt_set(hSession->cursor_addr); - cursor_move(baddr); + cursor_move(hSession,baddr); while (!hSession->ea_buf[baddr].fa) { ctlr_add(baddr, EBC_null, 0); INC_BA(baddr); @@ -2883,10 +2864,10 @@ LIB3270_ACTION( fieldend ) } else { baddr = last_nonblank; INC_BA(baddr); - if (h3270.ea_buf[baddr].fa) + if (hSession->ea_buf[baddr].fa) baddr = last_nonblank; } - cursor_move(baddr); + cursor_move(hSession,baddr); return 0; } @@ -2956,7 +2937,7 @@ remargin(int lmargin) } } - cursor_move(baddr); + cursor_move(&h3270,baddr); return True; } @@ -3347,112 +3328,6 @@ LIB3270_EXPORT int lib3270_emulate_input(H3270 *session, char *s, int len, int p return len; } -/* - * Pretend that a sequence of hexadecimal characters was entered at the - * keyboard. The input is a sequence of hexadecimal bytes, 2 characters - * per byte. If connected in ANSI mode, these are treated as ASCII - * characters; if in 3270 mode, they are considered EBCDIC. - * - * Graphic Escapes are handled as \E. - */ /* -void -hex_input(char *s) -{ - char *t; - Boolean escaped; -#if defined(X3270_ANSI) - unsigned char *xbuf = (unsigned char *)NULL; - unsigned char *tbuf = (unsigned char *)NULL; - int nbytes = 0; -#endif - - // Validate the string. - if (strlen(s) % 2) { - popup_an_error("%s: Odd number of characters in specification", - action_name(HexString_action)); -// cancel_if_idle_command(); - return; - } - t = s; - escaped = False; - while (*t) { - if (isxdigit(*t) && isxdigit(*(t + 1))) { - escaped = False; -#if defined(X3270_ANSI) - nbytes++; -#endif - } else if (!strncmp(t, "\\E", 2) || !strncmp(t, "\\e", 2)) { - if (escaped) { - popup_an_error("%s: Double \\E", - action_name(HexString_action)); -// cancel_if_idle_command(); - return; - } - if (!IN_3270) { - popup_an_error("%s: \\E in ANSI mode", - action_name(HexString_action)); -// cancel_if_idle_command(); - return; - } - escaped = True; - } else { - popup_an_error("%s: Illegal character in specification", - action_name(HexString_action)); -// cancel_if_idle_command(); - return; - } - t += 2; - } - if (escaped) { - popup_an_error("%s: Nothing follows \\E", - action_name(HexString_action)); -// cancel_if_idle_command(); - return; - } - -#if defined(X3270_ANSI) - // Allocate a temporary buffer. - if (!IN_3270 && nbytes) - tbuf = xbuf = (unsigned char *)Malloc(nbytes); -#endif - - // Pump it in. - t = s; - escaped = False; - while (*t) { - if (isxdigit(*t) && isxdigit(*(t + 1))) { - unsigned c; - - c = (FROM_HEX(*t) * 16) + FROM_HEX(*(t + 1)); - if (IN_3270) - key_Character(c, escaped, True, NULL); -#if defined(X3270_ANSI) - else - *tbuf++ = (unsigned char)c; -#endif - escaped = False; - } else if (!strncmp(t, "\\E", 2) || !strncmp(t, "\\e", 2)) { - escaped = True; - } - t += 2; - } -#if defined(X3270_ANSI) - if (!IN_3270 && nbytes) { - net_hexansi_out(xbuf, nbytes); - Free(xbuf); - } -#endif -} -*/ - -/* -void -ignore_action(Widget w unused, XEvent *event, String *params, Cardinal *num_params) -{ -// reset_idle_timer(); -} -*/ - #if defined(X3270_FT) /*[*/ /* * Set up the cursor and input field for command input. @@ -3496,7 +3371,7 @@ kybd_prime(void) } /* Move the cursor to the beginning of the field. */ - cursor_move(baddr); + cursor_move(&h3270,baddr); /* Erase it. */ while (!h3270.ea_buf[baddr].fa) { diff --git a/paste.c b/paste.c index 8dc868e..e7b99ec 100644 --- a/paste.c +++ b/paste.c @@ -128,7 +128,7 @@ } } - cursor_move(baddr); + cursor_move(session,baddr); } return -1; @@ -210,9 +210,9 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str) faddr = find_field_attribute(h,baddr); fa = h->ea_buf[faddr].fa; if (faddr != baddr && !FA_IS_PROTECTED(fa)) - cursor_move(baddr); + cursor_move(h,baddr); else - cursor_move(next_unprotected(baddr)); + cursor_move(h,next_unprotected(baddr)); data.row = BA_TO_ROW(h->cursor_addr); } last = ' '; diff --git a/screen.c b/screen.c index d841221..f839a1a 100644 --- a/screen.c +++ b/screen.c @@ -376,10 +376,18 @@ LIB3270_EXPORT int lib3270_get_cursor_address(H3270 *h) LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *h, int baddr) { - int ret; - CHECK_SESSION_HANDLE(h); + if(h->selected && !lib3270_get_toggle(h,LIB3270_TOGGLE_KEEP_SELECTED)) + lib3270_unselect(h); + + return cursor_move(h,baddr); +} + +int cursor_move(H3270 *h, int baddr) +{ + int ret; + ret = h->cursor_addr; if(ret == baddr) diff --git a/selection.c b/selection.c index 6a2c92c..e167894 100644 --- a/selection.c +++ b/selection.c @@ -40,20 +40,20 @@ #define SELECTION_BOTTOM 0x08 #define SELECTION_ACTIVE 0x10 - static void update_selection(H3270 *session); + static void select_region(H3270 *h, int start, int end); -/*--[ Implement ]------------------------------------------------------------------------------------*/ + /*--[ Implement ]------------------------------------------------------------------------------------*/ -static void get_selected_addr(H3270 *session, int *begin, int *end) +static void get_selected_addr(H3270 *session, int *start, int *end) { - if(session->select.begin > session->select.end) + if(session->select.start > session->select.end) { - *end = session->select.begin; - *begin = session->select.end; + *end = session->select.start; + *start = session->select.end; } else { - *begin = session->select.begin; + *start = session->select.start; *end = session->select.end; } } @@ -161,23 +161,6 @@ static void update_selected_region(H3270 *session) } -void update_selection(H3270 *session) -{ - if(lib3270_get_toggle(session,LIB3270_TOGGLE_RECTANGLE_SELECT)) - update_selected_rectangle(session); - else - update_selected_region(session); -} - -static void set_selected(H3270 *session) -{ - if(session->selected) - return; - - session->selected = 1; - session->set_selection(session,1); -} - void toggle_rectselect(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE tt) { if(!session->selected) @@ -195,42 +178,86 @@ LIB3270_ACTION(unselect) CHECK_SESSION_HANDLE(hSession); - if(!hSession->selected) - return 0; - - hSession->selected = 0; - - for(a = 0; a < hSession->rows*hSession->cols; a++) + if(hSession->selected) { - if(hSession->text[a].attr & LIB3270_ATTR_SELECTED) + hSession->selected = 0; + + for(a = 0; a < hSession->rows*hSession->cols; a++) { - hSession->text[a].attr &= ~LIB3270_ATTR_SELECTED; - if(hSession->update) - hSession->update(hSession,a,hSession->text[a].chr,hSession->text[a].attr,a == hSession->cursor_addr); + if(hSession->text[a].attr & LIB3270_ATTR_SELECTED) + { + hSession->text[a].attr &= ~LIB3270_ATTR_SELECTED; + if(hSession->update) + hSession->update(hSession,a,hSession->text[a].chr,hSession->text[a].attr,a == hSession->cursor_addr); + } } - } - hSession->set_selection(hSession,0); + hSession->set_selection(hSession,0); + hSession->update_selection(hSession,-1,-1); + } return 0; } LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) { + int start, end; + CHECK_SESSION_HANDLE(session); if(!lib3270_connected(session)) return; - if(!session->selected) + start = session->selected ? session->select.start : session->cursor_addr; + + cursor_move(session,end = baddr); + + select_region(session,start,end); + +} + +LIB3270_EXPORT void lib3270_select_region(H3270 *h, int start, int end) +{ + int maxlen; + + CHECK_SESSION_HANDLE(h); + + if(!lib3270_connected(h)) + return; + + maxlen = (h->rows * h->cols); + + // Check bounds + if(start < 0 || start > maxlen || end < 0 || end > maxlen || start > end) + return; + + select_region(h,start,end); + cursor_move(h,h->select.end); + +} + +static void select_region(H3270 *h, int start, int end) +{ + + // Do we really need to change selection? + if(start == h->select.start && end == h->select.end && h->selected) + return; + + h->select.start = start; + h->select.end = end; + + if(lib3270_get_toggle(h,LIB3270_TOGGLE_RECTANGLE_SELECT)) + update_selected_rectangle(h); + else + update_selected_region(h); + + if(!h->selected) { - session->select.begin = session->cursor_addr; - set_selected(session); + h->selected = 1; + h->set_selection(h,1); } - lib3270_set_cursor_address(session,session->select.end = baddr); - - update_selection(session); + h->update_selection(h,start,end); } @@ -265,7 +292,7 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba LIB3270_EXPORT void lib3270_select_word(H3270 *session, int baddr) { - int pos, len; + int pos, len, start, end; CHECK_SESSION_HANDLE(session); @@ -275,20 +302,20 @@ LIB3270_EXPORT void lib3270_select_word(H3270 *session, int baddr) return; } + start = session->select.start; for(pos = baddr; pos > 0 && !isspace(session->text[pos].chr);pos--); - session->select.begin = pos > 0 ? pos+1 : 0; + start = pos > 0 ? pos+1 : 0; len = session->rows * session->cols; for(pos = baddr; pos < len && !isspace(session->text[pos].chr);pos++); - session->select.end = pos < len ? pos-1 : len; + end = pos < len ? pos-1 : len; - set_selected(session); - update_selected_region(session); + select_region(session,start,end); } LIB3270_EXPORT int lib3270_select_field_at(H3270 *session, int baddr) { - int start,len; + int start, end,len; CHECK_SESSION_HANDLE(session); @@ -306,16 +333,14 @@ LIB3270_EXPORT int lib3270_select_field_at(H3270 *session, int baddr) return -1; } - session->select.begin = (start+1); + start++; len = (session->rows * session->cols)-1; + end = start + lib3270_field_length(session,start); + if(end > len) + end = len; - session->select.end = start + lib3270_field_length(session,start); - if(session->select.end > len) - session->select.end = len; - - set_selected(session); - update_selected_region(session); + select_region(session,start,end); return 0; } @@ -332,9 +357,11 @@ LIB3270_ACTION( selectall ) int len, baddr; CHECK_SESSION_HANDLE(hSession); + + select_region(hSession,0,hSession->rows*hSession->cols); +/* len = hSession->rows*hSession->cols; - // First remove unselected areas for(baddr = 0; baddr < len; baddr++) { if(!(hSession->text[baddr].attr & LIB3270_ATTR_SELECTED)) @@ -345,19 +372,20 @@ LIB3270_ACTION( selectall ) } set_selected(hSession); - +*/ return 0; } LIB3270_ACTION( reselect ) { + int start, end; + CHECK_SESSION_HANDLE(hSession); - if(!lib3270_connected(hSession) || hSession->select.begin == hSession->select.end || hSession->selected) + if(!lib3270_connected(hSession) || hSession->select.start == hSession->select.end || hSession->selected) return 0; - update_selection(hSession); - set_selected(hSession); + select_region(hSession, hSession->select.start,hSession->select.end); return 0; } @@ -463,7 +491,7 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) buffer = malloc(len+1); ptr = buffer; - trace("len=%d buffer=%p",len,buffer); +// trace("len=%d buffer=%p",len,buffer); while(len > 0) { @@ -484,7 +512,7 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) len--; } } - trace("len=%d buffer=%p pos=%d",len,buffer,ptr-buffer); +// trace("len=%d buffer=%p pos=%d",len,buffer,ptr-buffer); *ptr = 0; @@ -493,7 +521,7 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) { - if(!hSession->selected || hSession->select.begin == hSession->select.end) + if(!hSession->selected || hSession->select.start == hSession->select.end) return NULL; if(!lib3270_connected(hSession)) @@ -509,18 +537,18 @@ LIB3270_EXPORT int lib3270_get_selection_bounds(H3270 *hSession, int *start, int CHECK_SESSION_HANDLE(hSession); - if(!hSession->selected || hSession->select.begin == hSession->select.end) + if(!hSession->selected || hSession->select.start == hSession->select.end) return 0; - if(hSession->select.end > hSession->select.begin) + if(hSession->select.end > hSession->select.start) { - first = hSession->select.begin; + first = hSession->select.start; last = hSession->select.end; } else { first = hSession->select.end; - last = hSession->select.begin; + last = hSession->select.start; } if(start) @@ -535,7 +563,7 @@ LIB3270_EXPORT int lib3270_get_selection_bounds(H3270 *hSession, int *start, int LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) { int pos[2]; - int rows, cols, f, step; + int rows, cols, f, step, start, end; if(!lib3270_get_selection_bounds(hSession,&pos[0],&pos[1])) return from; @@ -561,13 +589,10 @@ LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) cols = hSession->cols - ((pos[f] % hSession->cols)+1); } - step = (rows * hSession->cols) + cols; + step = (rows * hSession->cols) + cols; - hSession->select.begin += step; - hSession->select.end += step; - - update_selection(hSession); - lib3270_set_cursor_address(hSession,hSession->select.end); + select_region(hSession,hSession->select.start + step,hSession->select.end + step); + cursor_move(hSession,hSession->select.end); return from+step; } @@ -601,19 +626,12 @@ LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int orig if(flag & SELECTION_BOTTOM) // Update bottom margin origin = last = (row*h->cols) + (last%h->cols); - if(h->select.begin < h->select.end) - { - h->select.begin = first; - h->select.end = last; - } + if(first < last) + select_region(h,first,last); else - { - h->select.begin = last; - h->select.end = first; - } + select_region(h,last,first); - update_selection(h); - lib3270_set_cursor_address(h,h->select.end); + cursor_move(h,h->select.end); return origin; } @@ -621,45 +639,50 @@ LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int orig LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir) { - if(!hSession->selected || hSession->select.begin == hSession->select.end) + int start, end; + + if(!hSession->selected || hSession->select.start == hSession->select.end) return ENOENT; + start = hSession->select.start; + end = hSession->select.end; + switch(dir) { case LIB3270_DIR_UP: - if(hSession->select.begin <= hSession->cols) + if(start <= hSession->cols) return EINVAL; - hSession->select.begin -= hSession->cols; - hSession->select.end -= hSession->cols; + start -= hSession->cols; + end -= hSession->cols; break; case LIB3270_DIR_DOWN: - if(hSession->select.end >= (hSession->cols * (hSession->rows-1))) + if(end >= (hSession->cols * (hSession->rows-1))) return EINVAL; - hSession->select.begin += hSession->cols; - hSession->select.end += hSession->cols; + start += hSession->cols; + end += hSession->cols; break; case LIB3270_DIR_LEFT: - if( (hSession->select.begin % hSession->cols) < 1) + if( (start % hSession->cols) < 1) return EINVAL; - hSession->select.begin--; - hSession->select.end--; + start--; + end--; break; case LIB3270_DIR_RIGHT: - if( (hSession->select.end % hSession->cols) >= (hSession->cols-1)) + if( (end % hSession->cols) >= (hSession->cols-1)) return EINVAL; - hSession->select.begin++; - hSession->select.end++; + start++; + end++; break; default: return -1; } - update_selection(hSession); - lib3270_set_cursor_address(hSession,hSession->select.end); + select_region(hSession,start,end); + cursor_move(hSession,hSession->select.end); return 0; } @@ -704,6 +727,6 @@ LIB3270_EXPORT int lib3270_move_cursor(H3270 *hSession, LIB3270_DIRECTION dir, u if(sel) lib3270_select_to(hSession,cursor_addr); else - lib3270_set_cursor_address(hSession,cursor_addr); - + cursor_move(hSession,cursor_addr); } + diff --git a/sf.c b/sf.c index f79eaa4..2dbf3e3 100644 --- a/sf.c +++ b/sf.c @@ -572,7 +572,7 @@ sf_create_partition(unsigned char buf[], int buflen) ph = *char_height; trace_ds(")\n"); - cursor_move(0); + cursor_move(&h3270,0); h3270.buffer_addr = 0; return PDS_OKAY_NO_OUTPUT; -- libgit2 0.21.2