X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fncurses.c;h=91acade3c8daea53b3edaf1c2f0adfd82aa73f3c;hp=f6090f43823455ddc627400b6b5874dc561bbaf9;hb=8144a95f5729b46a1ad4f4c3c4ba29800304e4c0;hpb=7eb4be765b131f00ac3da7ce8cfd3bc6759d26c5 diff --git a/test/ncurses.c b/test/ncurses.c index f6090f43..91acade3 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -40,7 +40,7 @@ AUTHOR Author: Eric S. Raymond 1993 Thomas E. Dickey (beginning revision 1.27 in 1996). -$Id: ncurses.c,v 1.281 2007/01/06 23:32:00 tom Exp $ +$Id: ncurses.c,v 1.296 2007/12/29 21:05:43 tom Exp $ ***************************************************************************/ @@ -608,6 +608,20 @@ remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win) winstack[level].frame = box_win; } +#if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) +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. @@ -623,12 +637,7 @@ resize_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); @@ -829,6 +838,8 @@ static void getch_test(void) { int delay = begin_getch_test(); + + slk_restore(); wgetch_test(0, stdscr, delay); forget_boxes(); finish_getch_test(); @@ -836,7 +847,7 @@ getch_test(void) #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 @@ -851,12 +862,7 @@ 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); @@ -955,11 +961,11 @@ wget_wch_test(unsigned level, WINDOW *win, int delay) 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); @@ -1044,6 +1050,8 @@ static void get_wch_test(void) { int delay = begin_getch_test(); + + slk_restore(); wget_wch_test(0, stdscr, delay); forget_boxes(); finish_getch_test(); @@ -2515,12 +2523,15 @@ slk_test(void) } break; #endif +#if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE + case KEY_RESIZE: + break; +#endif default: beep(); } - } while - ((c = Getchar()) != EOF); + } while (!isQuit(c = Getchar())); done: slk_clear(); @@ -2642,12 +2653,14 @@ wide_slk_test(void) call_slk_color(fg, bg); } break; - +#if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE + case KEY_RESIZE: + break; +#endif default: beep(); } - } while - ((c = Getchar()) != EOF); + } while (!isQuit(c = Getchar())); done: slk_clear(); @@ -3379,12 +3392,14 @@ FRAME WINDOW *wind; }; -#ifdef NCURSES_VERSION -#define keypad_active(win) (win)->_use_keypad -#define scroll_active(win) (win)->_scroll +#if defined(NCURSES_VERSION) +#if NCURSES_VERSION_PATCH < 20070331 +#define is_keypad(win) (win)->_use_keypad +#define is_scrollok(win) (win)->_scroll +#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. @@ -3395,14 +3410,16 @@ static bool 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 @@ -3945,7 +3962,11 @@ saywhat(NCURSES_CONST char *text) { 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 */ /*+------------------------------------------------------------------------- @@ -3997,6 +4018,17 @@ pflush(void) /*+------------------------------------------------------------------------- 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) { @@ -4014,217 +4046,214 @@ 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) @@ -5389,6 +5418,10 @@ demo_forms(void) 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"); @@ -5462,6 +5495,10 @@ demo_forms(void) free_fieldtype(fty_passwd); noraw(); nl(); + +#ifdef NCURSES_MOUSE_VERSION + mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0); +#endif } #endif /* USE_LIBFORM */ @@ -5884,7 +5921,13 @@ do_single_test(const char c) #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 @@ -5996,7 +6039,7 @@ rip_footer(WINDOW *win, int cols) 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; } @@ -6007,7 +6050,7 @@ rip_header(WINDOW *win, int cols) 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; } @@ -6052,9 +6095,12 @@ main_menu(bool top) #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 @@ -6143,7 +6189,7 @@ main(int argc, char *argv[]) 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':