/****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
Thomas E. Dickey (beginning revision 1.27 in 1996).
-$Id: ncurses.c,v 1.282 2007/03/03 21:26:24 tom Exp $
+$Id: ncurses.c,v 1.300 2008/01/19 23:10:59 tom Exp $
***************************************************************************/
#define NCURSES_CONST_PARAM const void
#ifdef TRACE
-static unsigned save_trace = TRACE_ORDINARY | TRACE_CALLS;
+static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
extern unsigned _nc_tracing;
#endif
winstack[level].frame = box_win;
}
+#if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
+static void
+slk_repaint(void)
+{
+ /* this chunk is now done in resize_term() */
+ slk_touch();
+ slk_clear();
+ slk_noutrefresh();
+}
+
+#else
+#define slk_repaint() /* nothing */
+#endif
+
/*
* For wgetch_test(), we create pairs of windows - one for a box, one for text.
* Resize both and paint the box in the parent.
touchwin(stdscr);
wnoutrefresh(stdscr);
-#if USE_SOFTKEYS
- /* FIXME: this chunk should be done in resizeterm() */
- slk_touch();
- slk_clear();
- slk_noutrefresh();
-#endif
+ slk_repaint();
for (n = 0; n < level; ++n) {
wresize(winstack[n].frame, high, wide);
getch_test(void)
{
int delay = begin_getch_test();
+
+ slk_restore();
wgetch_test(0, stdscr, delay);
forget_boxes();
finish_getch_test();
#if USE_WIDEC_SUPPORT
/*
- * For wgetch_test(), we create pairs of windows - one for a box, one for text.
+ * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
* Resize both and paint the box in the parent.
*/
-#ifdef KEY_RESIZE
+#if defined(KEY_RESIZE) && HAVE_WRESIZE
static void
resize_wide_boxes(unsigned level, WINDOW *win)
{
touchwin(stdscr);
wnoutrefresh(stdscr);
-#if USE_SOFTKEYS
- /* FIXME: this chunk should be done in resizeterm() */
- slk_touch();
- slk_clear();
- slk_noutrefresh();
-#endif
+ slk_repaint();
for (n = 0; n < level; ++n) {
wresize(winstack[n].frame, high, wide);
for (n = 0; (wchar_buf[n] = wint_buf[n]) != 0; ++n) ;
if ((temp = wcstos(wchar_buf)) != 0) {
wprintw(win, "I saw %d characters:\n\t`%s'.",
- wcslen(wchar_buf), temp);
+ (int) wcslen(wchar_buf), temp);
free(temp);
} else {
wprintw(win, "I saw %d characters (cannot convert).",
- wcslen(wchar_buf));
+ (int) wcslen(wchar_buf));
}
}
wclrtoeol(win);
} else
#endif /* NCURSES_MOUSE_VERSION */
if (code == KEY_CODE_YES) {
-#ifdef KEY_RESIZE
+#if defined(KEY_RESIZE) && HAVE_WRESIZE
if (c == KEY_RESIZE) {
resize_wide_boxes(level, win);
}
get_wch_test(void)
{
int delay = begin_getch_test();
+
+ slk_restore();
wget_wch_test(0, stdscr, delay);
forget_boxes();
finish_getch_test();
}
break;
#endif
+#if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
+ case KEY_RESIZE:
+ wnoutrefresh(stdscr);
+ break;
+#endif
default:
beep();
}
- } while
- ((c = Getchar()) != EOF);
+ } while (!isQuit(c = Getchar()));
done:
slk_clear();
call_slk_color(fg, bg);
}
break;
-
+#if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
+ case KEY_RESIZE:
+ wnoutrefresh(stdscr);
+ break;
+#endif
default:
beep();
}
- } while
- ((c = Getchar()) != EOF);
+ } while (!isQuit(c = Getchar()));
done:
slk_clear();
WINDOW *wind;
};
-#if defined(NCURSES_VERSION) && !NCURSES_OPAQUE
-#define keypad_active(win) (win)->_use_keypad
-#define scroll_active(win) (win)->_scroll
+#if defined(NCURSES_VERSION)
+#if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
+#define is_keypad(win) (win)->_use_keypad
+#define is_scrollok(win) (win)->_scroll
+#elif !defined(is_keypad)
+#define is_keypad(win) FALSE
+#define is_scrollok(win) FALSE
+#endif
#else
-#define keypad_active(win) FALSE
-#define scroll_active(win) FALSE
+#define is_keypad(win) FALSE
+#define is_scrollok(win) FALSE
#endif
/* We need to know if these flags are actually set, so don't look in FRAME.
HaveKeypad(FRAME * curp)
{
WINDOW *win = (curp ? curp->wind : stdscr);
- return keypad_active(win);
+ (void) win;
+ return is_keypad(win);
}
static bool
HaveScroll(FRAME * curp)
{
WINDOW *win = (curp ? curp->wind : stdscr);
- return scroll_active(win);
+ (void) win;
+ return is_scrollok(win);
}
static void
acs_and_scroll(void)
/* Demonstrate windows */
{
- int c, i;
+ int c;
FRAME *current = (FRAME *) 0, *neww;
WINDOW *usescr = stdscr;
#if HAVE_PUTWIN && HAVE_GETWIN
case CTRL('X'): /* resize window */
if (current) {
pair *tmp, ul, lr;
- int mx, my;
+ int i, mx, my;
move(0, 0);
clrtoeol();
{
wmove(stdscr, LINES - 1, 0);
wclrtoeol(stdscr);
- waddstr(stdscr, text);
+ if (text != 0 && *text != '\0') {
+ waddstr(stdscr, text);
+ waddstr(stdscr, "; ");
+ }
+ waddstr(stdscr, "press any key to continue");
} /* end of saywhat */
/*+-------------------------------------------------------------------------
/*+-------------------------------------------------------------------------
fill_panel(win)
--------------------------------------------------------------------------*/
+static void
+init_panel(void)
+{
+ register int y, x;
+
+ for (y = 0; y < LINES - 1; y++) {
+ for (x = 0; x < COLS; x++)
+ wprintw(stdscr, "%d", (y + x) % 10);
+ }
+}
+
static void
fill_panel(PANEL * pan)
{
waddch(win, UChar(num));
}
}
-} /* end of fill_panel */
+}
+#if USE_WIDEC_SUPPORT
static void
-demo_panels(void)
+make_fullwidth_digit(cchar_t *target, int digit)
{
- int itmp;
- register int y, x;
+ wchar_t source[2];
- refresh();
+ source[0] = digit + 0xff10;
+ source[1] = 0;
+ setcchar(target, source, A_NORMAL, 0, 0);
+}
- for (y = 0; y < LINES - 1; y++) {
- for (x = 0; x < COLS; x++)
- wprintw(stdscr, "%d", (y + x) % 10);
- }
- for (y = 0; y < 5; y++) {
- PANEL *p1;
- PANEL *p2;
- PANEL *p3;
- PANEL *p4;
- PANEL *p5;
-
- p1 = mkpanel(COLOR_RED,
- LINES / 2 - 2,
- COLS / 8 + 1,
- 0,
- 0);
- set_panel_userptr(p1, (NCURSES_CONST void *) "p1");
-
- p2 = mkpanel(COLOR_GREEN,
- LINES / 2 + 1,
- COLS / 7,
- LINES / 4,
- COLS / 10);
- set_panel_userptr(p2, (NCURSES_CONST void *) "p2");
-
- p3 = mkpanel(COLOR_YELLOW,
- LINES / 4,
- COLS / 10,
- LINES / 2,
- COLS / 9);
- set_panel_userptr(p3, (NCURSES_CONST void *) "p3");
-
- p4 = mkpanel(COLOR_BLUE,
- LINES / 2 - 2,
- COLS / 8,
- LINES / 2 - 2,
- COLS / 3);
- set_panel_userptr(p4, (NCURSES_CONST void *) "p4");
-
- p5 = mkpanel(COLOR_MAGENTA,
- LINES / 2 - 2,
- COLS / 8,
- LINES / 2,
- COLS / 2 - 2);
- set_panel_userptr(p5, (NCURSES_CONST void *) "p5");
-
- fill_panel(p1);
- fill_panel(p2);
- fill_panel(p3);
- fill_panel(p4);
- fill_panel(p5);
- hide_panel(p4);
- hide_panel(p5);
- pflush();
- saywhat("press any key to continue");
- wait_a_while(nap_msec);
+static void
+init_wide_panel(void)
+{
+ int digit;
+ cchar_t temp[10];
- saywhat("h3 s1 s2 s4 s5; press any key to continue");
- move_panel(p1, 0, 0);
- hide_panel(p3);
- show_panel(p1);
- show_panel(p2);
- show_panel(p4);
- show_panel(p5);
- pflush();
- wait_a_while(nap_msec);
+ for (digit = 0; digit < 10; ++digit)
+ make_fullwidth_digit(&temp[digit], digit);
- saywhat("s1; press any key to continue");
- show_panel(p1);
- pflush();
- wait_a_while(nap_msec);
+ do {
+ int y, x;
+ getyx(stdscr, y, x);
+ digit = (y + x / 2) % 10;
+ } while (add_wch(&temp[digit]) != ERR);
+}
- saywhat("s2; press any key to continue");
- show_panel(p2);
- pflush();
- wait_a_while(nap_msec);
+static void
+fill_wide_panel(PANEL * pan)
+{
+ WINDOW *win = panel_window(pan);
+ int num = ((const char *) panel_userptr(pan))[1];
+ int y, x;
- saywhat("m2; press any key to continue");
- move_panel(p2, LINES / 3 + 1, COLS / 8);
- pflush();
- wait_a_while(nap_msec);
+ wmove(win, 1, 1);
+ wprintw(win, "-pan%c-", num);
+ wclrtoeol(win);
+ box(win, 0, 0);
+ for (y = 2; y < getmaxy(win) - 1; y++) {
+ for (x = 1; x < getmaxx(win) - 1; x++) {
+ wmove(win, y, x);
+ waddch(win, UChar(num));
+ }
+ }
+}
+#endif
- saywhat("s3;");
- show_panel(p3);
- pflush();
- wait_a_while(nap_msec);
+#define MAX_PANELS 5
- saywhat("m3; press any key to continue");
- move_panel(p3, LINES / 4 + 1, COLS / 15);
- pflush();
- wait_a_while(nap_msec);
+static void
+canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
+{
+ int which = cmd[1] - '0';
- saywhat("b3; press any key to continue");
- bottom_panel(p3);
- pflush();
- wait_a_while(nap_msec);
+ saywhat(cmd);
+ switch (*cmd) {
+ case 'h':
+ hide_panel(px[which]);
+ break;
+ case 's':
+ show_panel(px[which]);
+ break;
+ case 't':
+ top_panel(px[which]);
+ break;
+ case 'b':
+ bottom_panel(px[which]);
+ break;
+ case 'd':
+ rmpanel(px[which]);
+ break;
+ }
+ pflush();
+ wait_a_while(nap_msec);
+}
- saywhat("s4; press any key to continue");
- show_panel(p4);
- pflush();
- wait_a_while(nap_msec);
+static void
+demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
+{
+ int count;
+ int itmp;
+ PANEL *px[MAX_PANELS + 1];
- saywhat("s5; press any key to continue");
- show_panel(p5);
- pflush();
- wait_a_while(nap_msec);
+ scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
+ refresh();
- saywhat("t3; press any key to continue");
- top_panel(p3);
+ InitPanel();
+ for (count = 0; count < 5; count++) {
+ px[1] = mkpanel(COLOR_RED,
+ LINES / 2 - 2,
+ COLS / 8 + 1,
+ 0,
+ 0);
+ set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
+
+ px[2] = mkpanel(COLOR_GREEN,
+ LINES / 2 + 1,
+ COLS / 7,
+ LINES / 4,
+ COLS / 10);
+ set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
+
+ px[3] = mkpanel(COLOR_YELLOW,
+ LINES / 4,
+ COLS / 10,
+ LINES / 2,
+ COLS / 9);
+ set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
+
+ px[4] = mkpanel(COLOR_BLUE,
+ LINES / 2 - 2,
+ COLS / 8,
+ LINES / 2 - 2,
+ COLS / 3);
+ set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
+
+ px[5] = mkpanel(COLOR_MAGENTA,
+ LINES / 2 - 2,
+ COLS / 8,
+ LINES / 2,
+ COLS / 2 - 2);
+ set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
+
+ FillPanel(px[1]);
+ FillPanel(px[2]);
+ FillPanel(px[3]);
+ FillPanel(px[4]);
+ FillPanel(px[5]);
+
+ hide_panel(px[4]);
+ hide_panel(px[5]);
pflush();
+ saywhat("");
wait_a_while(nap_msec);
- saywhat("t1; press any key to continue");
- top_panel(p1);
+ saywhat("h3 s1 s2 s4 s5");
+ move_panel(px[1], 0, 0);
+ hide_panel(px[3]);
+ show_panel(px[1]);
+ show_panel(px[2]);
+ show_panel(px[4]);
+ show_panel(px[5]);
pflush();
wait_a_while(nap_msec);
- saywhat("t2; press any key to continue");
- top_panel(p2);
- pflush();
- wait_a_while(nap_msec);
+ canned_panel(px, "s1");
+ canned_panel(px, "s2");
- saywhat("t3; press any key to continue");
- top_panel(p3);
+ saywhat("m2");
+ move_panel(px[2], LINES / 3 + 1, COLS / 8);
pflush();
wait_a_while(nap_msec);
- saywhat("t4; press any key to continue");
- top_panel(p4);
+ canned_panel(px, "s3");
+
+ saywhat("m3");
+ move_panel(px[3], LINES / 4 + 1, COLS / 15);
pflush();
wait_a_while(nap_msec);
+ canned_panel(px, "b3");
+ canned_panel(px, "s4");
+ canned_panel(px, "s5");
+ canned_panel(px, "t3");
+ canned_panel(px, "t1");
+ canned_panel(px, "t2");
+ canned_panel(px, "t3");
+ canned_panel(px, "t4");
+
for (itmp = 0; itmp < 6; itmp++) {
- WINDOW *w4 = panel_window(p4);
- WINDOW *w5 = panel_window(p5);
+ WINDOW *w4 = panel_window(px[4]);
+ WINDOW *w5 = panel_window(px[5]);
- saywhat("m4; press any key to continue");
+ saywhat("m4");
wmove(w4, LINES / 8, 1);
waddstr(w4, mod[itmp]);
- move_panel(p4, LINES / 6, itmp * (COLS / 8));
+ move_panel(px[4], LINES / 6, itmp * (COLS / 8));
wmove(w5, LINES / 6, 1);
waddstr(w5, mod[itmp]);
pflush();
wait_a_while(nap_msec);
- saywhat("m5; press any key to continue");
+ saywhat("m5");
wmove(w4, LINES / 6, 1);
waddstr(w4, mod[itmp]);
- move_panel(p5, LINES / 3 - 1, (itmp * 10) + 6);
+ move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
wmove(w5, LINES / 8, 1);
waddstr(w5, mod[itmp]);
pflush();
wait_a_while(nap_msec);
}
- saywhat("m4; press any key to continue");
- move_panel(p4, LINES / 6, itmp * (COLS / 8));
+ saywhat("m4");
+ move_panel(px[4], LINES / 6, itmp * (COLS / 8));
pflush();
wait_a_while(nap_msec);
- saywhat("t5; press any key to continue");
- top_panel(p5);
- pflush();
- wait_a_while(nap_msec);
-
- saywhat("t2; press any key to continue");
- top_panel(p2);
- pflush();
- wait_a_while(nap_msec);
-
- saywhat("t1; press any key to continue");
- top_panel(p1);
- pflush();
- wait_a_while(nap_msec);
-
- saywhat("d2; press any key to continue");
- rmpanel(p2);
- pflush();
- wait_a_while(nap_msec);
-
- saywhat("h3; press any key to continue");
- hide_panel(p3);
- pflush();
- wait_a_while(nap_msec);
-
- saywhat("d1; press any key to continue");
- rmpanel(p1);
- pflush();
- wait_a_while(nap_msec);
-
- saywhat("d4; press any key to continue");
- rmpanel(p4);
- pflush();
- wait_a_while(nap_msec);
-
- saywhat("d5; press any key to continue");
- rmpanel(p5);
- pflush();
-
- rmpanel(p3);
- pflush();
+ canned_panel(px, "t5");
+ canned_panel(px, "t2");
+ canned_panel(px, "t1");
+ canned_panel(px, "d2");
+ canned_panel(px, "h3");
+ canned_panel(px, "d1");
+ canned_panel(px, "d4");
+ canned_panel(px, "d5");
+ canned_panel(px, "d3");
wait_a_while(nap_msec);
if (nap_msec == 1)
int finished = 0, c;
unsigned n = 0;
+#ifdef NCURSES_MOUSE_VERSION
+ mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
+#endif
+
move(18, 0);
addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
addstr("^N -- go to next field ^P -- go to previous field\n");
free_fieldtype(fty_passwd);
noraw();
nl();
+
+#ifdef NCURSES_MOUSE_VERSION
+ mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
+#endif
}
#endif /* USE_LIBFORM */
#if USE_LIBPANEL
case 'o':
- demo_panels();
+ demo_panels(init_panel, fill_panel);
+ break;
+#endif
+
+#if USE_WIDEC_SUPPORT
+ case 'O':
+ demo_panels(init_wide_panel, fill_wide_panel);
break;
#endif
wbkgd(win, A_REVERSE);
werase(win);
wmove(win, 0, 0);
- wprintw(win, "footer: %d columns", cols);
+ wprintw(win, "footer: window %p, %d columns", win, cols);
wnoutrefresh(win);
return OK;
}
wbkgd(win, A_REVERSE);
werase(win);
wmove(win, 0, 0);
- wprintw(win, "header: %d columns", cols);
+ wprintw(win, "header: window %p, %d columns", win, cols);
wnoutrefresh(win);
return OK;
}
#endif
#if USE_LIBPANEL
(void) puts("o = exercise panels library");
+#if USE_WIDEC_SUPPORT
+ (void) puts("O = exercise panels with wide-characters");
+#endif
+#endif
(void) puts("p = exercise pad features");
(void) puts("q = quit");
-#endif
#if USE_LIBFORM
(void) puts("r = exercise forms code");
#endif
setlocale(LC_ALL, "");
- while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != EOF) {
+ while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != -1) {
switch (c) {
#ifdef NCURSES_VERSION
case 'a':