diff options
author | ache <ache@FreeBSD.org> | 1995-05-08 01:43:52 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1995-05-08 01:43:52 +0000 |
commit | 3aa0d024e865f17a08c5a46b95e339d986c5aa5c (patch) | |
tree | 8edbbb735af26ba43b28e795b909e5ea7f2c8c1f | |
parent | 6228dff953209276c8daa85b754f9103e8eae81c (diff) | |
download | FreeBSD-src-3aa0d024e865f17a08c5a46b95e339d986c5aa5c.zip FreeBSD-src-3aa0d024e865f17a08c5a46b95e339d986c5aa5c.tar.gz |
Fix nasty shadow bug sneaked in Marc's commit.
Implement ^K and KEY_EOL as clear end of line
Move common code from line_edit to static function
Cosmetique changes in textbox
-rw-r--r-- | gnu/lib/libdialog/kernel.c | 1 | ||||
-rw-r--r-- | gnu/lib/libdialog/lineedit.c | 128 | ||||
-rw-r--r-- | gnu/lib/libdialog/textbox.c | 3 |
3 files changed, 42 insertions, 90 deletions
diff --git a/gnu/lib/libdialog/kernel.c b/gnu/lib/libdialog/kernel.c index 08652fe..2afae58 100644 --- a/gnu/lib/libdialog/kernel.c +++ b/gnu/lib/libdialog/kernel.c @@ -378,7 +378,6 @@ void draw_box(WINDOW *win, int y, int x, int height, int width, chtype box, chty void draw_shadow(WINDOW *win, int y, int x, int height, int width) { int i,sx,sy; - WINDOW *newscr=win; if (has_colors()) { /* Whether terminal supports color? */ getbegyx(win,sy,sx); diff --git a/gnu/lib/libdialog/lineedit.c b/gnu/lib/libdialog/lineedit.c index f643bf4..8c33e8b 100644 --- a/gnu/lib/libdialog/lineedit.c +++ b/gnu/lib/libdialog/lineedit.c @@ -1,5 +1,7 @@ /* - * inputbox.c -- implements the input box + * Changes Copyright (C) 1995 by Andrey A. Chernov, Moscow + * + * Original Copyright: * * AUTHOR: Savio Lam (lam836@cs.cuhk.hk) * @@ -22,13 +24,14 @@ #include <dialog.h> #include "dialog.priv.h" +static void redraw_field(WINDOW *dialog, int box_y, int box_x, int flen, int box_width, unsigned char instr[], int input_x, int scroll, chtype attr, chtype old_attr, int fexit); /* * Line editor */ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, chtype attr, int first, unsigned char *result) { - int i, key, len, max_len, fix_len; + int i, key; chtype old_attr; static int input_x, scroll; static unsigned char instr[MAX_LEN+1]; @@ -50,18 +53,8 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht /* scroll = i - input_x;*/ scroll = (i > box_width) ? i - box_width + 1: 0; } - wmove(dialog, box_y, box_x); - wattrset(dialog, attr); - fix_len = flen >= 0 ? MIN(flen-scroll,box_width) : box_width; - for (i = 0; i < fix_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - len = strlen(instr); - wattrset(dialog, old_attr); - max_len = MIN(len-scroll,box_width); - for ( ; i < max_len; i++) - waddch(dialog, instr[scroll+i]); + redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE); - wmove(dialog, box_y, box_x + input_x); for (;;) { wattrset(dialog, attr); wrefresh(dialog); @@ -88,19 +81,17 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht case '\025': case '\030': kill_it: - memset(instr, 0, sizeof(instr)); + input_x = scroll = 0; + /* fall through */ + case '\013': + case KEY_EOL: + memset(instr + scroll + input_x, '\0', sizeof(instr) - scroll - input_x); + redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE); + continue; case '\001': case KEY_HOME: input_x = scroll = 0; - wmove(dialog, box_y, box_x); - fix_len = flen >= 0 ? MIN(flen,box_width) : box_width; - for (i = 0; i < fix_len; i++) - waddch(dialog, instr[i] ? instr[i] : ' '); - wattrset(dialog, old_attr); - max_len = MIN(len,box_width); - for ( ; i < max_len; i++) - waddch(dialog, instr[i] ? instr[i] : ' '); - wmove(dialog, box_y, box_x); + redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE); continue; case '\005': case KEY_END: @@ -109,15 +100,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht i++; input_x = i % box_width; scroll = i - input_x; - wmove(dialog, box_y, box_x); - fix_len = flen >= 0 ? MIN(flen-scroll,box_width) : box_width; - for (i = 0; i < fix_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wattrset(dialog, old_attr); - max_len = MIN(len-scroll,box_width); - for ( ; i < max_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wmove(dialog, box_y, input_x + box_x); + redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE); continue; case '\002': case KEY_LEFT: @@ -125,19 +108,12 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht if (!input_x) { int oldscroll = scroll; scroll = scroll < box_width-1 ? 0 : scroll-(box_width-1); - wmove(dialog, box_y, box_x); - fix_len = flen >= 0 ? MIN(flen-scroll,box_width) : box_width; - for (i = 0; i < fix_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wattrset(dialog, old_attr); - max_len = MIN(len-scroll,box_width); - for ( ; i < max_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); input_x = oldscroll - 1 - scroll; - } - else + redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE); + } else { input_x--; - wmove(dialog, box_y, input_x + box_x); + wmove(dialog, box_y, input_x + box_x); + } } else beep(); continue; @@ -150,15 +126,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht instr[scroll+input_x] = ' '; if (input_x == box_width-1) { scroll++; - wmove(dialog, box_y, box_x); - fix_len = flen >= 0 ? MIN(flen-scroll,box_width) : box_width; - for (i = 0; i < fix_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wattrset(dialog, old_attr); - max_len = MIN(len-scroll,box_width); - for ( ; i < max_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wmove(dialog, box_y, box_x + box_width - 1); + redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE); } else { wmove(dialog, box_y, input_x + box_x); @@ -179,18 +147,9 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht int oldscroll = scroll; scroll = scroll < box_width-1 ? 0 : scroll-(box_width-1); input_x = oldscroll - 1 - scroll; - } - else + } else input_x--; - wmove(dialog, box_y, box_x); - fix_len = flen >= 0 ? MIN(flen-scroll,box_width) : box_width; - for (i = 0; i < fix_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wattrset(dialog, old_attr); - max_len = MIN(len-scroll,box_width); - for ( ; i < max_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wmove(dialog, box_y, input_x + box_x); + redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE); } else beep(); continue; @@ -204,15 +163,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht continue; } memmove(instr+scroll+input_x, instr+scroll+input_x+1, i-(scroll+input_x)); - wmove(dialog, box_y, box_x); - fix_len = flen >= 0 ? MIN(flen-scroll,box_width) : box_width; - for (i = 0; i < fix_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wattrset(dialog, old_attr); - max_len = MIN(len-scroll,box_width); - for ( ; i < max_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wmove(dialog, box_y, input_x + box_x); + redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE); continue; default: if (CCEQ(key, erase_char)) @@ -231,15 +182,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht scroll++; else input_x++; - wmove(dialog, box_y, box_x); - fix_len = flen >= 0 ? MIN(flen-scroll,box_width) : box_width; - for (i = 0; i < fix_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wattrset(dialog, old_attr); - max_len = MIN(len-scroll,box_width); - for ( ; i < max_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wmove(dialog, box_y, input_x + box_x); + redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE); } else beep(); /* Alarm user about overflow */ continue; @@ -247,13 +190,24 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht } } ret: - wattrset(dialog, old_attr); - wmove(dialog, box_y, box_x); - max_len = MIN(len-scroll,box_width); - for (i = 0; i < max_len; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wmove(dialog, box_y, input_x + box_x); + redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, TRUE); wrefresh(dialog); strcpy(result, instr); return key; } + +static void +redraw_field(WINDOW *dialog, int box_y, int box_x, int flen, int box_width, unsigned char instr[], int input_x, int scroll, chtype attr, chtype old_attr, int fexit) +{ + int i, fix_len; + + wattrset(dialog, fexit ? old_attr : attr); + wmove(dialog, box_y, box_x); + fix_len = flen >= 0 ? MIN(flen-scroll,box_width) : box_width; + for (i = 0; i < fix_len; i++) + waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); + wattrset(dialog, old_attr); + for ( ; i < box_width; i++) + waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); + wmove(dialog, box_y, input_x + box_x); +} diff --git a/gnu/lib/libdialog/textbox.c b/gnu/lib/libdialog/textbox.c index a5fdedb..b466f79 100644 --- a/gnu/lib/libdialog/textbox.c +++ b/gnu/lib/libdialog/textbox.c @@ -653,12 +653,11 @@ static int get_search_term(WINDOW *win, unsigned char *search_term, int height, waddstr(win, " Search "); wattrset(win, dialog_attr); - box_width -= 2; search_term[0] = '\0'; first = 1; while (key != ESC) { - key = line_edit(win, y+1, x+1, -1, box_width, searchbox_attr, first, search_term); + key = line_edit(win, y+1, x+1, -1, box_width-2, searchbox_attr, first, search_term); first = 0; switch (key) { case '\n': |