aboutsummaryrefslogtreecommitdiff
path: root/contrib/ncurses/test/ncurses.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ncurses/test/ncurses.c')
-rw-r--r--contrib/ncurses/test/ncurses.c157
1 files changed, 137 insertions, 20 deletions
diff --git a/contrib/ncurses/test/ncurses.c b/contrib/ncurses/test/ncurses.c
index 0782d4071073..3d2101dbc904 100644
--- a/contrib/ncurses/test/ncurses.c
+++ b/contrib/ncurses/test/ncurses.c
@@ -40,7 +40,7 @@ AUTHOR
Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
Thomas E. Dickey (beginning revision 1.27 in 1996).
-$Id: ncurses.c,v 1.170 2002/04/21 21:08:07 tom Exp $
+$Id: ncurses.c,v 1.173 2002/06/16 00:29:27 tom Exp $
***************************************************************************/
@@ -104,13 +104,13 @@ extern int _nc_tracing;
#define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
#define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
#else
-#define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
-#define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
-#define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
-#define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
-#define ACS_PI (A_ALTCHARSET + '{') /* Pi */
-#define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
-#define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
+#define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
+#define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
+#define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
+#define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
+#define ACS_PI (A_ALTCHARSET + '{') /* Pi */
+#define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
+#define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
#endif
#ifdef CURSES_WACS_ARRAY
@@ -358,12 +358,78 @@ wgetch_wrap(WINDOW *win, int first_y)
wclrtoeol(win);
}
+#if defined(NCURSES_VERSION) && defined(KEY_RESIZE)
+typedef struct {
+ WINDOW *text;
+ WINDOW *frame;
+} WINSTACK;
+
+static WINSTACK *winstack = 0;
+static unsigned len_winstack = 0;
+
+static void
+remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
+{
+ unsigned need = (level + 1) * 2;
+
+ if (winstack == 0) {
+ len_winstack = 20;
+ winstack = malloc(len_winstack * sizeof(WINSTACK));
+ } else if (need >= len_winstack) {
+ len_winstack = need;
+ winstack = realloc(winstack, len_winstack * sizeof(WINSTACK));
+ }
+ winstack[level].text = txt_win;
+ winstack[level].frame = box_win;
+}
+
+/*
+ * For wgetch_test(), we create pairs of windows - one for a box, one for text.
+ * Resize both and paint the box in the parent.
+ */
static void
-wgetch_test(WINDOW *win, int delay)
+resize_boxes(int level, WINDOW *win)
+{
+ unsigned n;
+ int base = 5;
+ int high = LINES - base;
+ int wide = COLS;
+
+ touchwin(stdscr);
+ wnoutrefresh(stdscr);
+
+ /* FIXME: this chunk should be done in resizeterm() */
+ slk_touch();
+ slk_clear();
+ slk_noutrefresh();
+
+ for (n = 0; (int) n < level; ++n) {
+ wresize(winstack[n].frame, high, wide);
+ wresize(winstack[n].text, high - 2, wide - 2);
+ high -= 2;
+ wide -= 2;
+ werase(winstack[n].text);
+ box(winstack[n].frame, 0, 0);
+ wnoutrefresh(winstack[n].frame);
+ wprintw(winstack[n].text,
+ "size %dx%d\n",
+ getmaxy(winstack[n].text),
+ getmaxx(winstack[n].text));
+ wnoutrefresh(winstack[n].text);
+ if (winstack[n].text == win)
+ break;
+ }
+ doupdate();
+}
+#else
+#define remember_boxes(level,text,frame) /* nothing */
+#endif
+
+static void
+wgetch_test(int level, WINDOW *win, int delay)
{
char buf[BUFSIZ];
int first_y, first_x;
- int last_y = getmaxy(win) - 1;
int c;
int incount = 0;
bool flags[256];
@@ -378,7 +444,7 @@ wgetch_test(WINDOW *win, int delay)
getyx(win, first_y, first_x);
wgetch_help(win, flags);
- wsetscrreg(win, first_y, last_y);
+ wsetscrreg(win, first_y, getmaxy(win) - 1);
scrollok(win, TRUE);
for (;;) {
@@ -420,7 +486,7 @@ wgetch_test(WINDOW *win, int delay)
} else if (c == 's') {
ShellOut(TRUE);
} else if (c == 'w') {
- int high = last_y - first_y + 1;
+ int high = getmaxy(win) - 1 - first_y + 1;
int wide = getmaxx(win) - first_x;
int old_y, old_x;
int new_y = first_y + getbegy(win);
@@ -434,7 +500,8 @@ wgetch_test(WINDOW *win, int delay)
box(wb, 0, 0);
wrefresh(wb);
wmove(wi, 0, 0);
- wgetch_test(wi, delay);
+ remember_boxes(level, wi, wb);
+ wgetch_test(level + 1, wi, delay);
delwin(wi);
delwin(wb);
@@ -442,6 +509,7 @@ wgetch_test(WINDOW *win, int delay)
wmove(win, old_y, old_x);
touchwin(win);
wrefresh(win);
+ doupdate();
}
#ifdef SIGTSTP
} else if (c == 'z') {
@@ -462,6 +530,11 @@ wgetch_test(WINDOW *win, int delay)
} else
#endif /* NCURSES_MOUSE_VERSION */
if (c >= KEY_MIN) {
+#if defined(NCURSES_VERSION) && defined(KEY_RESIZE)
+ if (c == KEY_RESIZE) {
+ resize_boxes(level, win);
+ }
+#endif
(void) waddstr(win, keyname(c));
} else if (c > 0x80) {
int c2 = (c & 0x7f);
@@ -528,17 +601,55 @@ static void
getch_test(void)
{
int delay = begin_getch_test();
- wgetch_test(stdscr, delay);
+ wgetch_test(0, stdscr, delay);
finish_getch_test();
}
#if USE_WIDEC_SUPPORT
+/*
+ * For wgetch_test(), we create pairs of windows - one for a box, one for text.
+ * Resize both and paint the box in the parent.
+ */
+static void
+resize_wide_boxes(int level, WINDOW *win)
+{
+ unsigned n;
+ int base = 5;
+ int high = LINES - base;
+ int wide = COLS;
+
+ touchwin(stdscr);
+ wnoutrefresh(stdscr);
+
+ /* FIXME: this chunk should be done in resizeterm() */
+ slk_touch();
+ slk_clear();
+ slk_noutrefresh();
+
+ for (n = 0; (int) n < level; ++n) {
+ wresize(winstack[n].frame, high, wide);
+ wresize(winstack[n].text, high - 2, wide - 2);
+ high -= 2;
+ wide -= 2;
+ werase(winstack[n].text);
+ box_set(winstack[n].frame, 0, 0);
+ wnoutrefresh(winstack[n].frame);
+ wprintw(winstack[n].text,
+ "size %dx%d\n",
+ getmaxy(winstack[n].text),
+ getmaxx(winstack[n].text));
+ wnoutrefresh(winstack[n].text);
+ if (winstack[n].text == win)
+ break;
+ }
+ doupdate();
+}
+
static void
-wget_wch_test(WINDOW *win, int delay)
+wget_wch_test(int level, WINDOW *win, int delay)
{
char buf[BUFSIZ];
int first_y, first_x;
- int last_y = getmaxy(win) - 1;
wint_t c;
int incount = 0;
bool flags[256];
@@ -553,7 +664,7 @@ wget_wch_test(WINDOW *win, int delay)
getyx(win, first_y, first_x);
wgetch_help(win, flags);
- wsetscrreg(win, first_y, last_y);
+ wsetscrreg(win, first_y, getmaxy(win) - 1);
scrollok(win, TRUE);
for (;;) {
@@ -595,7 +706,7 @@ wget_wch_test(WINDOW *win, int delay)
} else if (c == 's') {
ShellOut(TRUE);
} else if (c == 'w') {
- int high = last_y - first_y + 1;
+ int high = getmaxy(win) - 1 - first_y + 1;
int wide = getmaxx(win) - first_x;
int old_y, old_x;
int new_y = first_y + getbegy(win);
@@ -609,7 +720,8 @@ wget_wch_test(WINDOW *win, int delay)
box_set(wb, 0, 0);
wrefresh(wb);
wmove(wi, 0, 0);
- wget_wch_test(wi, delay);
+ remember_boxes(level, wi, wb);
+ wget_wch_test(level + 1, wi, delay);
delwin(wi);
delwin(wb);
@@ -637,6 +749,11 @@ wget_wch_test(WINDOW *win, int delay)
} else
#endif /* NCURSES_MOUSE_VERSION */
if (code == KEY_CODE_YES) {
+#ifdef KEY_RESIZE
+ if (c == KEY_RESIZE) {
+ resize_wide_boxes(level, win);
+ }
+#endif
(void) waddstr(win, key_name(c));
} else {
if (c < 256 && iscntrl(c)) {
@@ -658,7 +775,7 @@ static void
get_wch_test(void)
{
int delay = begin_getch_test();
- wget_wch_test(stdscr, delay);
+ wget_wch_test(0, stdscr, delay);
finish_getch_test();
}
#endif