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_get_wstr.c,v 1.5 2007/08/11 17:01:43 tom Exp $
31
* Author: Thomas E Dickey
33
* Demonstrate the get_wstr functions from the curses library.
35
int get_wstr(wint_t *wstr);
36
int getn_wstr(wint_t *wstr, int n);
37
int wget_wstr(WINDOW *win, wint_t *wstr);
38
int wgetn_wstr(WINDOW *win, wint_t *wstr, int n);
39
int mvget_wstr(int y, int x, wint_t *wstr);
40
int mvgetn_wstr(int y, int x, wint_t *wstr, int n);
41
int mvwget_wstr(WINDOW *win, int y, int x, wint_t *wstr);
42
int mvwgetn_wstr(WINDOW *win, int y, int x, wint_t *wstr, int n);
45
#include <test.priv.h>
63
return (ch == ERR || ch == 'q' || ch == QUIT || ch == ESCAPE);
67
Remainder(WINDOW *txtwin)
69
int result = getmaxx(txtwin) - getcurx(txtwin);
70
return (result > 0) ? result : 0;
74
* Show a highlighted line in the place where input will happen.
77
ShowPrompt(WINDOW *txtwin, int limit)
79
wchgat(txtwin, limit, A_REVERSE, 0, NULL);
84
MovePrompt(WINDOW *txtwin, int limit, int y, int x)
86
wchgat(txtwin, Remainder(txtwin), A_NORMAL, 0, NULL);
88
ShowPrompt(txtwin, limit);
92
ShowFlavor(WINDOW *strwin, WINDOW *txtwin, int flavor, int limit)
94
const char *name = "?";
96
bool wins = (txtwin != stdscr);
101
name = wins ? "wget_wstr" : "get_wstr";
105
name = wins ? "wgetn_wstr" : "getn_wstr";
108
name = wins ? "mvwget_wstr" : "mvget_wstr";
112
name = wins ? "mvwgetn_wstr" : "mvgetn_wstr";
122
wprintw(strwin, "%s(%d):", name, limit);
124
wprintw(strwin, "%s:", name);
126
result = limited ? limit : Remainder(txtwin);
127
ShowPrompt(txtwin, result);
129
wnoutrefresh(strwin);
134
test_get_wstr(int level, char **argv, WINDOW *strwin)
141
int txt_x = 0, txt_y = 0;
144
int limit = getmaxx(strwin) - 5;
146
wint_t buffer[MAX_COLS];
148
if (argv[level] == 0) {
154
txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
156
wnoutrefresh(txtbox);
158
txtwin = derwin(txtbox,
168
keypad(txtwin, TRUE); /* enable keyboard mapping */
169
(void) cbreak(); /* take input chars one at a time, no wait for \n */
170
(void) noecho(); /* don't echo input */
174
wmove(txtwin, txt_y, txt_x);
176
if ((fp = fopen(argv[level], "r")) != 0) {
177
while ((ch = fgetc(fp)) != EOF) {
178
if (waddch(txtwin, UChar(ch)) != OK) {
184
wprintw(txtwin, "Cannot open:\n%s", argv[1]);
187
wmove(txtwin, txt_y, txt_x);
188
actual = ShowFlavor(strwin, txtwin, flavor, limit);
189
while (!Quit(ch = mvwgetch(txtwin, txt_y, txt_x))) {
193
if (txt_y < getmaxy(txtwin) - 1) {
194
MovePrompt(txtwin, actual, ++txt_y, txt_x);
201
if (txt_y > base_y) {
202
MovePrompt(txtwin, actual, --txt_y, txt_x);
210
MovePrompt(txtwin, actual, txt_y, --txt_x);
217
if (txt_x < getmaxx(txtwin) - 1) {
218
MovePrompt(txtwin, actual, txt_y, ++txt_x);
225
test_get_wstr(level + 1, argv, strwin);
228
wnoutrefresh(txtbox);
231
wnoutrefresh(txtwin);
237
actual = ShowFlavor(strwin, txtwin, flavor, --limit);
238
MovePrompt(txtwin, actual, txt_y, txt_x);
245
actual = ShowFlavor(strwin, txtwin, flavor, ++limit);
246
MovePrompt(txtwin, actual, txt_y, txt_x);
251
actual = ShowFlavor(strwin, txtwin, --flavor, limit);
252
MovePrompt(txtwin, actual, txt_y, txt_x);
259
if (flavor + 1 < eMaxFlavor) {
260
actual = ShowFlavor(strwin, txtwin, ++flavor, limit);
261
MovePrompt(txtwin, actual, txt_y, txt_x);
268
actual = ShowFlavor(strwin, txtwin, flavor, limit);
272
wattrset(txtwin, A_REVERSE);
275
if (txtwin != stdscr) {
276
wmove(txtwin, txt_y, txt_x);
277
rc = wget_wstr(txtwin, buffer);
280
rc = get_wstr(buffer);
284
if (txtwin != stdscr) {
285
wmove(txtwin, txt_y, txt_x);
286
rc = wgetn_wstr(txtwin, buffer, limit);
289
rc = getn_wstr(buffer, limit);
293
if (txtwin != stdscr) {
294
rc = mvwget_wstr(txtwin, txt_y, txt_x, buffer);
296
rc = mvget_wstr(txt_y, txt_x, buffer);
300
if (txtwin != stdscr) {
301
rc = mvwgetn_wstr(txtwin, txt_y, txt_x, buffer, limit);
303
rc = mvgetn_wstr(txt_y, txt_x, buffer, limit);
310
wattrset(txtwin, A_NORMAL);
311
wprintw(strwin, "%d", rc);
312
waddwstr(strwin, (wchar_t *) buffer);
313
wnoutrefresh(strwin);
329
main(int argc, char *argv[])
334
setlocale(LC_ALL, "");
337
fprintf(stderr, "usage: %s file\n", argv[0]);
343
chrbox = derwin(stdscr, BASE_Y, COLS, 0, 0);
345
wnoutrefresh(chrbox);
347
strwin = derwin(chrbox, 4, COLS - 2, 1, 1);
349
test_get_wstr(1, argv, strwin);
352
ExitProgram(EXIT_SUCCESS);
358
printf("This program requires the wide-ncurses library\n");
359
ExitProgram(EXIT_FAILURE);