1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-16 10:20:30 +00:00

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
This commit is contained in:
Andrey A. Chernov 1995-05-08 01:43:52 +00:00
parent fccc689116
commit 883c5f31fa
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=8344
3 changed files with 42 additions and 90 deletions

View File

@ -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) void draw_shadow(WINDOW *win, int y, int x, int height, int width)
{ {
int i,sx,sy; int i,sx,sy;
WINDOW *newscr=win;
if (has_colors()) { /* Whether terminal supports color? */ if (has_colors()) { /* Whether terminal supports color? */
getbegyx(win,sy,sx); getbegyx(win,sy,sx);

View File

@ -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) * AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
* *
@ -22,13 +24,14 @@
#include <dialog.h> #include <dialog.h>
#include "dialog.priv.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 * 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 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; chtype old_attr;
static int input_x, scroll; static int input_x, scroll;
static unsigned char instr[MAX_LEN+1]; 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 - input_x;*/
scroll = (i > box_width) ? i - box_width + 1: 0; scroll = (i > box_width) ? i - box_width + 1: 0;
} }
wmove(dialog, box_y, box_x); redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
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]);
wmove(dialog, box_y, box_x + input_x);
for (;;) { for (;;) {
wattrset(dialog, attr); wattrset(dialog, attr);
wrefresh(dialog); 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 '\025':
case '\030': case '\030':
kill_it: 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 '\001':
case KEY_HOME: case KEY_HOME:
input_x = scroll = 0; input_x = scroll = 0;
wmove(dialog, box_y, box_x); redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
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);
continue; continue;
case '\005': case '\005':
case KEY_END: 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++; i++;
input_x = i % box_width; input_x = i % box_width;
scroll = i - input_x; scroll = i - input_x;
wmove(dialog, box_y, box_x); redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
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);
continue; continue;
case '\002': case '\002':
case KEY_LEFT: 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) { if (!input_x) {
int oldscroll = scroll; int oldscroll = scroll;
scroll = scroll < box_width-1 ? 0 : scroll-(box_width-1); 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; input_x = oldscroll - 1 - scroll;
} redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
else } else {
input_x--; input_x--;
wmove(dialog, box_y, input_x + box_x); wmove(dialog, box_y, input_x + box_x);
}
} else } else
beep(); beep();
continue; 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] = ' '; instr[scroll+input_x] = ' ';
if (input_x == box_width-1) { if (input_x == box_width-1) {
scroll++; scroll++;
wmove(dialog, box_y, box_x); redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
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);
} }
else { else {
wmove(dialog, box_y, input_x + box_x); 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; int oldscroll = scroll;
scroll = scroll < box_width-1 ? 0 : scroll-(box_width-1); scroll = scroll < box_width-1 ? 0 : scroll-(box_width-1);
input_x = oldscroll - 1 - scroll; input_x = oldscroll - 1 - scroll;
} } else
else
input_x--; input_x--;
wmove(dialog, box_y, box_x); redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
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);
} else } else
beep(); beep();
continue; continue;
@ -204,15 +163,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht
continue; continue;
} }
memmove(instr+scroll+input_x, instr+scroll+input_x+1, i-(scroll+input_x)); memmove(instr+scroll+input_x, instr+scroll+input_x+1, i-(scroll+input_x));
wmove(dialog, box_y, box_x); redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
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);
continue; continue;
default: default:
if (CCEQ(key, erase_char)) 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++; scroll++;
else else
input_x++; input_x++;
wmove(dialog, box_y, box_x); redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
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);
} else } else
beep(); /* Alarm user about overflow */ beep(); /* Alarm user about overflow */
continue; continue;
@ -247,13 +190,24 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht
} }
} }
ret: ret:
wattrset(dialog, old_attr); redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, TRUE);
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);
wrefresh(dialog); wrefresh(dialog);
strcpy(result, instr); strcpy(result, instr);
return key; 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);
}

View File

@ -653,12 +653,11 @@ static int get_search_term(WINDOW *win, unsigned char *search_term, int height,
waddstr(win, " Search "); waddstr(win, " Search ");
wattrset(win, dialog_attr); wattrset(win, dialog_attr);
box_width -= 2;
search_term[0] = '\0'; search_term[0] = '\0';
first = 1; first = 1;
while (key != ESC) { 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; first = 0;
switch (key) { switch (key) {
case '\n': case '\n':