1 /****************************************************************************
2 * Copyright (c) 2013-2014,2017 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 /****************************************************************************
30 * Author: Gaute Hope, 2013 *
31 ****************************************************************************/
34 * $Id: form_driver_w.c,v 1.15 2017/04/15 20:41:35 tom Exp $
36 * Test form_driver_w (int, int, wchar_t), a wide char aware
37 * replacement of form_driver.
40 #include <test.priv.h>
41 #include <popup_msg.h>
43 #if USE_WIDEC_SUPPORT && USE_LIBFORM && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH >= 20131207)
50 static const char *help[] =
53 " ^D,^Q,ESC - quit program",
54 " <Tab>,<Down> - move to next field",
55 " <BackTab>,<Up> - move to previous field",
60 #define MyRow(n) (4 + (n) * 2)
62 FIELD *field[NUM_FIELDS + 1];
67 setlocale(LC_ALL, "");
69 /* Initialize curses */
75 /* Initialize the fields */
76 for (n = 0; n < NUM_FIELDS; ++n) {
77 field[n] = new_field(1, 10, MyRow(n), 18, 0, 0);
78 set_field_back(field[n], A_UNDERLINE);
79 /* Print a line for the option */
80 field_opts_off(field[n], O_AUTOSKIP);
81 /* Don't go to next field when this is filled */
85 /* Create the form and post it */
86 my_form = new_form(field);
90 for (n = 0; n < NUM_FIELDS; ++n) {
91 mvprintw(MyRow(n), MyCol(n), "Value %d:", n + 1);
94 /* Loop through to get user requests */
97 int ret = get_wch(&ch);
99 mvprintw(MyRow(NUM_FIELDS),
101 "Got %d (%#x), type: %s",
104 (ret == KEY_CODE_YES)
117 /* Go to next field */
118 form_driver_w(my_form, KEY_CODE_YES, REQ_NEXT_FIELD);
119 /* Go to the end of the present buffer */
120 /* Leaves nicely at the last character */
121 form_driver_w(my_form, KEY_CODE_YES, REQ_END_LINE);
125 /* Go to previous field */
126 form_driver_w(my_form, KEY_CODE_YES, REQ_PREV_FIELD);
127 form_driver_w(my_form, KEY_CODE_YES, REQ_END_LINE);
141 form_driver_w(my_form, KEY_CODE_YES, REQ_NEXT_FIELD);
142 form_driver_w(my_form, KEY_CODE_YES, REQ_END_LINE);
145 popup_msg(form_win(my_form), help);
148 form_driver_w(my_form, OK, (wchar_t) ch);
155 /* Un post form and free the memory */
156 unpost_form(my_form);
158 for (n = 0; n < NUM_FIELDS; ++n) {
159 free_field(field[n]);
163 ExitProgram(EXIT_SUCCESS);
170 printf("This program requires the wide-ncurses and forms library\n");
171 ExitProgram(EXIT_FAILURE);
173 #endif /* USE_WIDEC_SUPPORT */