1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 2007-2008,2009 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 * $Id: test_opaque.c,v 1.10 2020/02/02 23:34:34 tom Exp $
32 * Author: Thomas E Dickey
34 * Demonstrate the opaque functions from the curses library.
36 WINDOW * wgetparent (const WINDOW *);
37 bool is_cleared(const WINDOW *win);
38 bool is_idcok(const WINDOW *win);
39 bool is_idlok(const WINDOW *win);
40 bool is_immedok(const WINDOW *win);
41 bool is_keypad(const WINDOW *win);
42 bool is_leaveok(const WINDOW *win);
43 bool is_nodelay(const WINDOW *win);
44 bool is_notimeout(const WINDOW *win);
45 bool is_scrollok(const WINDOW *win);
46 bool is_syncok(const WINDOW *win);
47 int wgetscrreg (const WINDOW *, int *, int *);
50 #include <test.priv.h>
55 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20080119) && NCURSES_EXT_FUNCS
60 return (ch == 'q' || ch == QUIT || ch == ESCAPE);
63 typedef bool(*BoolOpaque) (WINDOW *, int);
66 test_opaque_cleared(WINDOW *win, int mode)
72 return is_cleared(win);
76 test_opaque_idcok(WINDOW *win, int mode)
85 test_opaque_idlok(WINDOW *win, int mode)
94 test_opaque_immedok(WINDOW *win, int mode)
99 return is_immedok(win);
103 test_opaque_keypad(WINDOW *win, int mode)
108 return is_keypad(win);
112 test_opaque_leaveok(WINDOW *win, int mode)
117 return is_leaveok(win);
121 test_opaque_nodelay(WINDOW *win, int mode)
126 return is_nodelay(win);
130 test_opaque_notimeout(WINDOW *win, int mode)
133 notimeout(win, mode);
135 return is_notimeout(win);
139 test_opaque_scrollok(WINDOW *win, int mode)
144 return is_scrollok(win);
148 test_opaque_syncok(WINDOW *win, int mode)
153 return is_syncok(win);
157 status_y(WINDOW *stswin, int cell)
159 return (cell % getmaxy(stswin));
163 status_x(WINDOW *stswin, int cell)
165 return (15 * (cell / getmaxy(stswin)));
169 to_keyword(WINDOW *stswin, int cell)
171 wmove(stswin, status_y(stswin, cell), status_x(stswin, cell));
175 to_result(WINDOW *stswin, int cell, bool before)
177 int y = status_y(stswin, cell);
178 int x = status_x(stswin, cell) + 11;
185 show_keyword(WINDOW *stswin, int cell, int active, const char *name)
187 to_keyword(stswin, cell);
189 (void) wstandout(stswin);
190 wprintw(stswin, "%s:", name);
192 (void) wstandend(stswin);
199 { "cleared", test_opaque_cleared },
200 { "idcok", test_opaque_idcok },
201 { "idlok", test_opaque_idlok },
202 { "immedok", test_opaque_immedok },
203 { "keypad", test_opaque_keypad },
204 { "leaveok", test_opaque_leaveok },
205 { "nodelay", test_opaque_nodelay },
206 { "notimeout", test_opaque_notimeout },
207 { "scrollok", test_opaque_scrollok },
208 { "syncok", test_opaque_syncok }
213 * Display and/or allow update for the properties accessed in the opaque
214 * window. Some may change state after refreshing the window, so we
215 * distinguish between them using the 'before' parameter.
218 show_opaque(WINDOW *stswin, WINDOW *txtwin, bool before, int active)
226 for (n = 0; n < (int) SIZEOF(bool_funcs); ++n) {
227 show_keyword(stswin, n, active, bool_funcs[n].name);
229 to_result(stswin, n, before);
230 wprintw(stswin, "%c", bool_funcs[n].func(txtwin, -1) ? 'T' : 'F');
233 show_keyword(stswin, n, active, "wgetparent");
234 to_result(stswin, n, TRUE);
235 wprintw(stswin, "%p", (void *) wgetparent(txtwin));
238 show_keyword(stswin, n, active, "wgetscrreg");
239 to_result(stswin, n, TRUE);
240 if (wgetscrreg(txtwin, &top, &bottom) == OK)
241 wprintw(stswin, "%d,%d", top, bottom);
243 wnoutrefresh(stswin);
248 test_opaque(int level, char **argv, WINDOW *stswin)
254 int txt_x = 0, txt_y = 0;
256 bool in_status = FALSE;
259 if (argv[level] == 0) {
265 txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
267 wnoutrefresh(txtbox);
269 txtwin = derwin(txtbox,
279 keypad(txtwin, TRUE); /* enable keyboard mapping */
280 (void) cbreak(); /* take input chars one at a time, no wait for \n */
281 (void) noecho(); /* don't echo input */
285 wmove(txtwin, txt_y, txt_x);
287 if ((fp = fopen(argv[level], "r")) != 0) {
288 while ((ch = fgetc(fp)) != EOF) {
289 if (waddch(txtwin, UChar(ch)) != OK) {
295 wprintw(txtwin, "Cannot open:\n%s", argv[1]);
300 to_keyword(stswin, active);
303 show_opaque(stswin, txtwin, TRUE, active);
313 if (active < (int) SIZEOF(bool_funcs) - 1)
326 bool_funcs[active].func(txtwin,
327 !bool_funcs[active].func(txtwin, -1));
333 show_opaque(stswin, txtwin, FALSE, in_status ? active : -1);
335 ch = mvwgetch(txtwin, txt_y, txt_x);
336 show_opaque(stswin, txtwin, TRUE, -1);
346 if (txt_y < getmaxy(txtwin) - 1)
367 if (txt_x < getmaxx(txtwin) - 1)
373 test_opaque(level + 1, argv, stswin);
376 wnoutrefresh(txtbox);
379 wnoutrefresh(txtwin);
388 show_opaque(stswin, txtwin, FALSE, -1);
399 test_set_escdelay(void)
401 set_escdelay((100 + ESCDELAY) / 2);
405 test_set_tabsize(void)
409 int save_tabsize = TABSIZE;
411 (void) cbreak(); /* take input chars one at a time, no wait for \n */
412 (void) noecho(); /* don't echo input */
414 for (y = 0; y < LINES; ++y) {
416 if (move(y, 0) == ERR)
418 for (x = 0; x < COLS;) {
420 if (addch('*') == ERR) {
423 getyx(stdscr, y0, x0);
424 if (y0 != y || x0 == x) {
432 set_tabsize(save_tabsize);
436 main(int argc, char *argv[])
441 setlocale(LC_ALL, "");
444 fprintf(stderr, "usage: %s file\n", argv[0]);
453 stsbox = derwin(stdscr, BASE_Y, COLS, 0, 0);
455 wnoutrefresh(stsbox);
457 stswin = derwin(stsbox, BASE_Y - 2, COLS - 2, 1, 1);
458 keypad(stswin, TRUE);
460 test_opaque(1, argv, stswin);
463 ExitProgram(EXIT_SUCCESS);
469 printf("This program requires the ncurses library\n");
470 ExitProgram(EXIT_FAILURE);