1 /****************************************************************************
2 * Copyright (c) 2007-2008,2009 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.9 2009/10/24 21:21:29 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>
54 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20080119) && NCURSES_EXT_FUNCS
59 return (ch
== 'q' || ch
== QUIT
|| ch
== ESCAPE
);
62 typedef bool(*BoolOpaque
) (WINDOW
*, int);
65 test_opaque_cleared(WINDOW
*win
, int mode
)
71 return is_cleared(win
);
75 test_opaque_idcok(WINDOW
*win
, int mode
)
84 test_opaque_idlok(WINDOW
*win
, int mode
)
93 test_opaque_immedok(WINDOW
*win
, int mode
)
98 return is_immedok(win
);
102 test_opaque_keypad(WINDOW
*win
, int mode
)
107 return is_keypad(win
);
111 test_opaque_leaveok(WINDOW
*win
, int mode
)
116 return is_leaveok(win
);
120 test_opaque_nodelay(WINDOW
*win
, int mode
)
125 return is_nodelay(win
);
129 test_opaque_notimeout(WINDOW
*win
, int mode
)
132 notimeout(win
, mode
);
134 return is_notimeout(win
);
138 test_opaque_scrollok(WINDOW
*win
, int mode
)
143 return is_scrollok(win
);
147 test_opaque_syncok(WINDOW
*win
, int mode
)
152 return is_syncok(win
);
156 status_y(WINDOW
*stswin
, int cell
)
158 return (cell
% getmaxy(stswin
));
162 status_x(WINDOW
*stswin
, int cell
)
164 return (15 * (cell
/ getmaxy(stswin
)));
168 to_keyword(WINDOW
*stswin
, int cell
)
170 wmove(stswin
, status_y(stswin
, cell
), status_x(stswin
, cell
));
174 to_result(WINDOW
*stswin
, int cell
, bool before
)
176 int y
= status_y(stswin
, cell
);
177 int x
= status_x(stswin
, cell
) + 11;
184 show_keyword(WINDOW
*stswin
, int cell
, int active
, const char *name
)
186 to_keyword(stswin
, cell
);
188 (void) wstandout(stswin
);
189 wprintw(stswin
, "%s:", name
);
191 (void) wstandend(stswin
);
198 { "cleared", test_opaque_cleared
},
199 { "idcok", test_opaque_idcok
},
200 { "idlok", test_opaque_idlok
},
201 { "immedok", test_opaque_immedok
},
202 { "keypad", test_opaque_keypad
},
203 { "leaveok", test_opaque_leaveok
},
204 { "nodelay", test_opaque_nodelay
},
205 { "notimeout", test_opaque_notimeout
},
206 { "scrollok", test_opaque_scrollok
},
207 { "syncok", test_opaque_syncok
}
212 * Display and/or allow update for the properties accessed in the opaque
213 * window. Some may change state after refreshing the window, so we
214 * distinguish between them using the 'before' parameter.
217 show_opaque(WINDOW
*stswin
, WINDOW
*txtwin
, bool before
, int active
)
225 for (n
= 0; n
< (int) SIZEOF(bool_funcs
); ++n
) {
226 show_keyword(stswin
, n
, active
, bool_funcs
[n
].name
);
228 to_result(stswin
, n
, before
);
229 wprintw(stswin
, "%c", bool_funcs
[n
].func(txtwin
, -1) ? 'T' : 'F');
232 show_keyword(stswin
, n
, active
, "wgetparent");
233 to_result(stswin
, n
, TRUE
);
234 wprintw(stswin
, "%p", (void *) wgetparent(txtwin
));
237 show_keyword(stswin
, n
, active
, "wgetscrreg");
238 to_result(stswin
, n
, TRUE
);
239 if (wgetscrreg(txtwin
, &top
, &bottom
) == OK
)
240 wprintw(stswin
, "%d,%d", top
, bottom
);
242 wnoutrefresh(stswin
);
247 test_opaque(int level
, char **argv
, WINDOW
*stswin
)
253 int txt_x
= 0, txt_y
= 0;
255 bool in_status
= FALSE
;
258 if (argv
[level
] == 0) {
264 txtbox
= newwin(LINES
- BASE_Y
, COLS
- level
, BASE_Y
, level
);
266 wnoutrefresh(txtbox
);
268 txtwin
= derwin(txtbox
,
278 keypad(txtwin
, TRUE
); /* enable keyboard mapping */
279 (void) cbreak(); /* take input chars one at a time, no wait for \n */
280 (void) noecho(); /* don't echo input */
284 wmove(txtwin
, txt_y
, txt_x
);
286 if ((fp
= fopen(argv
[level
], "r")) != 0) {
287 while ((ch
= fgetc(fp
)) != EOF
) {
288 if (waddch(txtwin
, UChar(ch
)) != OK
) {
294 wprintw(txtwin
, "Cannot open:\n%s", argv
[1]);
299 to_keyword(stswin
, active
);
302 show_opaque(stswin
, txtwin
, TRUE
, active
);
312 if (active
< (int) SIZEOF(bool_funcs
) - 1)
325 bool_funcs
[active
].func(txtwin
,
326 !bool_funcs
[active
].func(txtwin
, -1));
332 show_opaque(stswin
, txtwin
, FALSE
, in_status
? active
: -1);
334 ch
= mvwgetch(txtwin
, txt_y
, txt_x
);
335 show_opaque(stswin
, txtwin
, TRUE
, -1);
345 if (txt_y
< getmaxy(txtwin
) - 1)
366 if (txt_x
< getmaxx(txtwin
) - 1)
372 test_opaque(level
+ 1, argv
, stswin
);
375 wnoutrefresh(txtbox
);
378 wnoutrefresh(txtwin
);
387 show_opaque(stswin
, txtwin
, FALSE
, -1);
398 test_set_escdelay(void)
400 set_escdelay((100 + ESCDELAY
) / 2);
404 test_set_tabsize(void)
408 int save_tabsize
= TABSIZE
;
410 (void) cbreak(); /* take input chars one at a time, no wait for \n */
411 (void) noecho(); /* don't echo input */
413 for (y
= 0; y
< LINES
; ++y
) {
415 if (move(y
, 0) == ERR
)
417 for (x
= 0; x
< COLS
;) {
419 if (addch('*') == ERR
) {
422 getyx(stdscr
, y0
, x0
);
423 if (y0
!= y
|| x0
== x
) {
431 set_tabsize(save_tabsize
);
435 main(int argc
, char *argv
[])
440 setlocale(LC_ALL
, "");
443 fprintf(stderr
, "usage: %s file\n", argv
[0]);
452 stsbox
= derwin(stdscr
, BASE_Y
, COLS
, 0, 0);
454 wnoutrefresh(stsbox
);
456 stswin
= derwin(stsbox
, BASE_Y
- 2, COLS
- 2, 1, 1);
457 keypad(stswin
, TRUE
);
459 test_opaque(1, argv
, stswin
);
462 ExitProgram(EXIT_SUCCESS
);
468 printf("This program requires the ncurses library\n");
469 ExitProgram(EXIT_FAILURE
);