1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 2013-2014,2017 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 /****************************************************************************
31 * Author: Gaute Hope, 2013 *
32 ****************************************************************************/
35 * $Id: form_driver_w.c,v 1.16 2020/02/02 23:34:34 tom Exp $
37 * Test form_driver_w (int, int, wchar_t), a wide char aware
38 * replacement of form_driver.
41 #include <test.priv.h>
42 #include <popup_msg.h>
44 #if USE_WIDEC_SUPPORT && USE_LIBFORM && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH >= 20131207)
51 static const char *help[] =
54 " ^D,^Q,ESC - quit program",
55 " <Tab>,<Down> - move to next field",
56 " <BackTab>,<Up> - move to previous field",
61 #define MyRow(n) (4 + (n) * 2)
63 FIELD *field[NUM_FIELDS + 1];
68 setlocale(LC_ALL, "");
70 /* Initialize curses */
76 /* Initialize the fields */
77 for (n = 0; n < NUM_FIELDS; ++n) {
78 field[n] = new_field(1, 10, MyRow(n), 18, 0, 0);
79 set_field_back(field[n], A_UNDERLINE);
80 /* Print a line for the option */
81 field_opts_off(field[n], O_AUTOSKIP);
82 /* Don't go to next field when this is filled */
86 /* Create the form and post it */
87 my_form = new_form(field);
91 for (n = 0; n < NUM_FIELDS; ++n) {
92 mvprintw(MyRow(n), MyCol(n), "Value %d:", n + 1);
95 /* Loop through to get user requests */
98 int ret = get_wch(&ch);
100 mvprintw(MyRow(NUM_FIELDS),
102 "Got %d (%#x), type: %s",
105 (ret == KEY_CODE_YES)
118 /* Go to next field */
119 form_driver_w(my_form, KEY_CODE_YES, REQ_NEXT_FIELD);
120 /* Go to the end of the present buffer */
121 /* Leaves nicely at the last character */
122 form_driver_w(my_form, KEY_CODE_YES, REQ_END_LINE);
126 /* Go to previous field */
127 form_driver_w(my_form, KEY_CODE_YES, REQ_PREV_FIELD);
128 form_driver_w(my_form, KEY_CODE_YES, REQ_END_LINE);
142 form_driver_w(my_form, KEY_CODE_YES, REQ_NEXT_FIELD);
143 form_driver_w(my_form, KEY_CODE_YES, REQ_END_LINE);
146 popup_msg(form_win(my_form), help);
149 form_driver_w(my_form, OK, (wchar_t) ch);
156 /* Un post form and free the memory */
157 unpost_form(my_form);
159 for (n = 0; n < NUM_FIELDS; ++n) {
160 free_field(field[n]);
164 ExitProgram(EXIT_SUCCESS);
171 printf("This program requires the wide-ncurses and forms library\n");
172 ExitProgram(EXIT_FAILURE);
174 #endif /* USE_WIDEC_SUPPORT */