1 /****************************************************************************
2 * Copyright (c) 2007 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 * $Id: test_opaque.c,v 1.4 2007/08/18 17:51:51 tom Exp $
31 * Author: Thomas E Dickey
33 * Demonstrate the opaque functions from the curses library.
35 WINDOW * wgetparent (const WINDOW *);
36 bool is_cleared(const WINDOW *win);
37 bool is_idcok(const WINDOW *win);
38 bool is_idlok(const WINDOW *win);
39 bool is_immedok(const WINDOW *win);
40 bool is_keypad(const WINDOW *win);
41 bool is_leaveok(const WINDOW *win);
42 bool is_nodelay(const WINDOW *win);
43 bool is_notimeout(const WINDOW *win);
44 bool is_scrollok(const WINDOW *win);
45 bool is_syncok(const WINDOW *win);
46 int wgetscrreg (const WINDOW *, int *, int *);
49 #include <test.priv.h>
57 return (ch == 'q' || ch == QUIT || ch == ESCAPE);
60 typedef bool(*BoolOpaque) (WINDOW *, int);
63 test_opaque_cleared(WINDOW *win, int mode)
69 return is_cleared(win);
73 test_opaque_idcok(WINDOW *win, int mode)
82 test_opaque_idlok(WINDOW *win, int mode)
91 test_opaque_immedok(WINDOW *win, int mode)
96 return is_immedok(win);
100 test_opaque_keypad(WINDOW *win, int mode)
105 return is_keypad(win);
109 test_opaque_leaveok(WINDOW *win, int mode)
114 return is_leaveok(win);
118 test_opaque_nodelay(WINDOW *win, int mode)
123 return is_nodelay(win);
127 test_opaque_notimeout(WINDOW *win, int mode)
130 notimeout(win, mode);
132 return is_notimeout(win);
136 test_opaque_scrollok(WINDOW *win, int mode)
141 return is_scrollok(win);
145 test_opaque_syncok(WINDOW *win, int mode)
150 return is_syncok(win);
154 status_y(WINDOW *stswin, int cell)
156 return (cell % getmaxy(stswin));
160 status_x(WINDOW *stswin, int cell)
162 return (15 * (cell / getmaxy(stswin)));
166 to_keyword(WINDOW *stswin, int cell)
168 wmove(stswin, status_y(stswin, cell), status_x(stswin, cell));
172 to_result(WINDOW *stswin, int cell, bool before)
174 int y = status_y(stswin, cell);
175 int x = status_x(stswin, cell) + 11;
182 show_keyword(WINDOW *stswin, int cell, int active, const char *name)
184 to_keyword(stswin, cell);
187 wprintw(stswin, "%s:", name);
196 { "cleared", test_opaque_cleared },
197 { "idcok", test_opaque_idcok },
198 { "idlok", test_opaque_idlok },
199 { "immedok", test_opaque_immedok },
200 { "keypad", test_opaque_keypad },
201 { "leaveok", test_opaque_leaveok },
202 { "nodelay", test_opaque_nodelay },
203 { "notimeout", test_opaque_notimeout },
204 { "scrollok", test_opaque_scrollok },
205 { "syncok", test_opaque_syncok }
210 * Display and/or allow update for the properties accessed in the opaque
211 * window. Some may change state after refreshing the window, so we
212 * distinguish between them using the 'before' parameter.
215 show_opaque(WINDOW *stswin, WINDOW *txtwin, bool before, int active)
223 for (n = 0; n < (int) SIZEOF(bool_funcs); ++n) {
224 show_keyword(stswin, n, active, bool_funcs[n].name);
226 to_result(stswin, n, before);
227 wprintw(stswin, "%c", bool_funcs[n].func(txtwin, -1) ? 'T' : 'F');
230 show_keyword(stswin, n, active, "wgetparent");
231 to_result(stswin, n, TRUE);
232 wprintw(stswin, "%p", wgetparent(txtwin));
235 show_keyword(stswin, n, active, "wgetscrreg");
236 to_result(stswin, n, TRUE);
237 if (wgetscrreg(txtwin, &top, &bottom) == OK)
238 wprintw(stswin, "%d,%d", top, bottom);
240 wnoutrefresh(stswin);
245 test_opaque(int level, char **argv, WINDOW *stswin)
251 int txt_x = 0, txt_y = 0;
253 bool in_status = FALSE;
256 if (argv[level] == 0) {
262 txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
264 wnoutrefresh(txtbox);
266 txtwin = derwin(txtbox,
276 keypad(txtwin, TRUE); /* enable keyboard mapping */
277 (void) cbreak(); /* take input chars one at a time, no wait for \n */
278 (void) noecho(); /* don't echo input */
282 wmove(txtwin, txt_y, txt_x);
284 if ((fp = fopen(argv[level], "r")) != 0) {
285 while ((ch = fgetc(fp)) != EOF) {
286 if (waddch(txtwin, UChar(ch)) != OK) {
292 wprintw(txtwin, "Cannot open:\n%s", argv[1]);
297 to_keyword(stswin, active);
300 show_opaque(stswin, txtwin, TRUE, active);
310 if (active < (int) SIZEOF(bool_funcs) - 1)
323 bool_funcs[active].func(txtwin,
324 !bool_funcs[active].func(txtwin, -1));
330 show_opaque(stswin, txtwin, FALSE, in_status ? active : -1);
332 ch = mvwgetch(txtwin, txt_y, txt_x);
333 show_opaque(stswin, txtwin, TRUE, -1);
343 if (txt_y < getmaxy(txtwin) - 1)
364 if (txt_x < getmaxx(txtwin) - 1)
370 test_opaque(level + 1, argv, stswin);
373 wnoutrefresh(txtbox);
376 wnoutrefresh(txtwin);
385 show_opaque(stswin, txtwin, FALSE, -1);
396 main(int argc, char *argv[])
401 setlocale(LC_ALL, "");
404 fprintf(stderr, "usage: %s file\n", argv[0]);
410 stsbox = derwin(stdscr, BASE_Y, COLS, 0, 0);
412 wnoutrefresh(stsbox);
414 stswin = derwin(stsbox, BASE_Y - 2, COLS - 2, 1, 1);
415 keypad(stswin, TRUE);
417 test_opaque(1, argv, stswin);
420 ExitProgram(EXIT_SUCCESS);