X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Ftestcurs.c;h=a1f00576e8befc9b73fdcbbb5fec2fcfdded1ca2;hp=e8ec4ce7b7d2b8039f7efa9de9e8d68b13690de6;hb=0266ec751090f9523ae676f357095176e293fb16;hpb=92e187a3459ab7ce1613a3684ca6642447c73620 diff --git a/test/testcurs.c b/test/testcurs.c index e8ec4ce7..a1f00576 100644 --- a/test/testcurs.c +++ b/test/testcurs.c @@ -1,5 +1,4 @@ /* - * * This is a test program for the PDCurses screen package for IBM PC type * machines. * @@ -7,7 +6,7 @@ * wrs(5/28/93) -- modified to be consistent (perform identically) with either * PDCurses or under Unix System V, R4 * - * $Id: testcurs.c,v 1.42 2010/05/01 19:23:19 tom Exp $ + * $Id: testcurs.c,v 1.49 2014/07/27 00:25:14 tom Exp $ */ #include @@ -46,18 +45,6 @@ static const COMMAND command[] = }; #define MAX_OPTIONS (int) SIZEOF(command) -#if !HAVE_STRDUP -#define strdup my_strdup -static char * -strdup(char *s) -{ - char *p = typeMalloc(char, strlen(s) + 1); - if (p) - strcpy(p, s); - return (p); -} -#endif /* not HAVE_STRDUP */ - static int width, height; int @@ -86,7 +73,7 @@ main( #ifdef A_COLOR if (has_colors()) { init_pair(1, COLOR_WHITE, COLOR_BLUE); - wbkgd(win, COLOR_PAIR(1)); + wbkgd(win, (chtype) COLOR_PAIR(1)); } else wbkgd(win, A_REVERSE); #else @@ -299,7 +286,7 @@ inputTest(WINDOW *win) #ifdef A_COLOR if (has_colors()) { init_pair(2, COLOR_WHITE, COLOR_RED); - wbkgd(subWin, COLOR_PAIR(2) | A_BOLD); + wbkgd(subWin, (chtype) COLOR_PAIR(2) | A_BOLD); } else wbkgd(subWin, A_BOLD); #else @@ -354,6 +341,9 @@ inputTest(WINDOW *win) typeahead(-1); #endif +#ifdef NCURSES_MOUSE_VERSION + mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0); +#endif #if defined(PDCURSES) mouse_set(ALL_MOUSE_EVENTS); #endif @@ -368,8 +358,38 @@ inputTest(WINDOW *win) wprintw(win, "Key Pressed: %c", c); else wprintw(win, "Key Pressed: %s", unctrl(UChar(c))); -#if defined(PDCURSES) +#ifdef KEY_MOUSE if (c == KEY_MOUSE) { +#if defined(NCURSES_MOUSE_VERSION) +#define ButtonChanged(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, 037)) +#define ButtonPressed(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED)) +#define ButtonDouble(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED)) +#define ButtonTriple(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED)) +#define ButtonRelease(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED)) + MEVENT event; + int button = 0; + + getmouse(&event); + if (ButtonChanged(1)) + button = 1; + else if (ButtonChanged(2)) + button = 2; + else if (ButtonChanged(3)) + button = 3; + else + button = 0; + wmove(win, 4, 18); + wprintw(win, "Button %d: ", button); + if (ButtonPressed(button)) + wprintw(win, "pressed: "); + else if (ButtonDouble(button)) + wprintw(win, "double: "); + else if (ButtonTriple(button)) + wprintw(win, "triple: "); + else + wprintw(win, "released: "); + wprintw(win, " Position: Y: %d X: %d", event.y, event.x); +#elif defined(PDCURSES) int button = 0; request_mouse_pos(); if (BUTTON_CHANGED(1)) @@ -391,8 +411,9 @@ inputTest(WINDOW *win) else wprintw(win, "released: "); wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); +#endif /* NCURSES_VERSION vs PDCURSES */ } -#endif +#endif /* KEY_MOUSE */ wrefresh(win); if (c == ' ') break; @@ -416,7 +437,7 @@ inputTest(WINDOW *win) "%d %[][a-zA-Z]s", "%d %[^0-9]" }; - const char *format = fmt[repeat % SIZEOF(fmt)]; + const char *format = fmt[(unsigned) repeat % SIZEOF(fmt)]; wclear(win); MvWAddStr(win, 3, 2, "The window should have moved"); @@ -492,7 +513,7 @@ outputTest(WINDOW *win) #ifdef A_COLOR if (has_colors()) { init_pair(3, COLOR_BLUE, COLOR_WHITE); - wbkgd(win1, COLOR_PAIR(3)); + wbkgd(win1, (chtype) COLOR_PAIR(3)); } else wbkgd(win1, A_NORMAL); #else @@ -694,9 +715,11 @@ padTest(WINDOW *dummy GCC_UNUSED) raw(); wgetch(pad); - spad = subpad(pad, 12, 25, 6, 52); - MvWAddStr(spad, 2, 2, "This is a new subpad"); - box(spad, 0, 0); + if ((spad = subpad(pad, 12, 25, 6, 52)) != 0) { + MvWAddStr(spad, 2, 2, "This is a new subpad"); + box(spad, 0, 0); + delwin(spad); + } prefresh(pad, 0, 0, 0, 0, 15, 75); keypad(pad, TRUE); raw();