1 /****************************************************************************
2 * Copyright 2020,2022 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.17 2022/12/10 23:31:31 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 *msg[] =
53 "Usage: form_driver_w [options]"
59 for (n = 0; n < SIZEOF(msg); n++)
60 fprintf(stderr, "%s\n", msg[n]);
62 ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
69 main(int argc, char *argv[])
71 static const char *help[] =
74 " ^D,^Q,ESC - quit program",
75 " <Tab>,<Down> - move to next field",
76 " <BackTab>,<Up> - move to previous field",
81 #define MyRow(n) (4 + (n) * 2)
83 FIELD *field[NUM_FIELDS + 1];
89 while ((ch = getopt(argc, argv, OPTS_COMMON)) != -1) {
93 ExitProgram(EXIT_SUCCESS);
95 usage(ch == OPTS_USAGE);
102 setlocale(LC_ALL, "");
104 /* Initialize curses */
108 keypad(stdscr, TRUE);
110 /* Initialize the fields */
111 for (n = 0; n < NUM_FIELDS; ++n) {
112 field[n] = new_field(1, 10, MyRow(n), 18, 0, 0);
113 set_field_back(field[n], A_UNDERLINE);
114 /* Print a line for the option */
115 field_opts_off(field[n], O_AUTOSKIP);
116 /* Don't go to next field when this is filled */
120 /* Create the form and post it */
121 my_form = new_form(field);
125 for (n = 0; n < NUM_FIELDS; ++n) {
126 mvprintw(MyRow(n), MyCol(n), "Value %d:", n + 1);
129 /* Loop through to get user requests */
132 int ret = get_wch(&c2);
134 mvprintw(MyRow(NUM_FIELDS),
136 "Got %d (%#x), type: %s",
139 (ret == KEY_CODE_YES)
152 /* Go to next field */
153 form_driver_w(my_form, KEY_CODE_YES, REQ_NEXT_FIELD);
154 /* Go to the end of the present buffer */
155 /* Leaves nicely at the last character */
156 form_driver_w(my_form, KEY_CODE_YES, REQ_END_LINE);
160 /* Go to previous field */
161 form_driver_w(my_form, KEY_CODE_YES, REQ_PREV_FIELD);
162 form_driver_w(my_form, KEY_CODE_YES, REQ_END_LINE);
176 form_driver_w(my_form, KEY_CODE_YES, REQ_NEXT_FIELD);
177 form_driver_w(my_form, KEY_CODE_YES, REQ_END_LINE);
180 popup_msg(form_win(my_form), help);
183 form_driver_w(my_form, OK, (wchar_t) c2);
190 /* Un post form and free the memory */
191 unpost_form(my_form);
193 for (n = 0; n < NUM_FIELDS; ++n) {
194 free_field(field[n]);
198 ExitProgram(EXIT_SUCCESS);
205 printf("This program requires the wide-ncurses and forms library\n");
206 ExitProgram(EXIT_FAILURE);
208 #endif /* USE_WIDEC_SUPPORT */