summaryrefslogtreecommitdiff
path: root/test/form_driver_w.c
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2020-02-12 02:21:21 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2020-02-12 02:21:21 +0000
commitff448436b2b70771d09b8d5ff34a509dcf02f81b (patch)
tree2f7abbba7198a4e1c4a23955bc3a539db5a7d999 /test/form_driver_w.c
parentf6d73a10a980bc78969c3af93665cbe7d06c3646 (diff)
downloadncurses-ff448436b2b70771d09b8d5ff34a509dcf02f81b.tar.gz
ncurses-6.2ncurses-6.2
Diffstat (limited to 'test/form_driver_w.c')
-rw-r--r--test/form_driver_w.c66
1 files changed, 45 insertions, 21 deletions
diff --git a/test/form_driver_w.c b/test/form_driver_w.c
index 3e928af..dd7ea68 100644
--- a/test/form_driver_w.c
+++ b/test/form_driver_w.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 2013,2014 Free Software Foundation, Inc. *
+ * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2013-2014,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -31,15 +32,14 @@
****************************************************************************/
/*
- * $Id: form_driver_w.c,v 1.13 2014/08/02 17:24:55 tom Exp $
+ * $Id: form_driver_w.c,v 1.16 2020/02/02 23:34:34 tom Exp $
*
* Test form_driver_w (int, int, wchar_t), a wide char aware
* replacement of form_driver.
*/
-#include <locale.h>
-
#include <test.priv.h>
+#include <popup_msg.h>
#if USE_WIDEC_SUPPORT && USE_LIBFORM && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH >= 20131207)
@@ -48,9 +48,22 @@
int
main(void)
{
- FIELD *field[3];
+ static const char *help[] =
+ {
+ "Commands:",
+ " ^D,^Q,ESC - quit program",
+ " <Tab>,<Down> - move to next field",
+ " <BackTab>,<Up> - move to previous field",
+ 0
+ };
+
+#define NUM_FIELDS 3
+#define MyRow(n) (4 + (n) * 2)
+#define MyCol(n) 10
+ FIELD *field[NUM_FIELDS + 1];
FORM *my_form;
bool done = FALSE;
+ int n;
setlocale(LC_ALL, "");
@@ -61,32 +74,34 @@ main(void)
keypad(stdscr, TRUE);
/* Initialize the fields */
- field[0] = new_field(1, 10, 4, 18, 0, 0);
- field[1] = new_field(1, 10, 6, 18, 0, 0);
- field[2] = NULL;
-
- /* Set field options */
- set_field_back(field[0], A_UNDERLINE); /* Print a line for the option */
- field_opts_off(field[0], O_AUTOSKIP); /* Don't go to next field when this */
- /* Field is filled up */
- set_field_back(field[1], A_UNDERLINE);
- field_opts_off(field[1], O_AUTOSKIP);
+ for (n = 0; n < NUM_FIELDS; ++n) {
+ field[n] = new_field(1, 10, MyRow(n), 18, 0, 0);
+ set_field_back(field[n], A_UNDERLINE);
+ /* Print a line for the option */
+ field_opts_off(field[n], O_AUTOSKIP);
+ /* Don't go to next field when this is filled */
+ }
+ field[n] = NULL;
/* Create the form and post it */
my_form = new_form(field);
post_form(my_form);
refresh();
- mvprintw(4, 10, "Value 1:");
- mvprintw(6, 10, "Value 2:");
- refresh();
+ for (n = 0; n < NUM_FIELDS; ++n) {
+ mvprintw(MyRow(n), MyCol(n), "Value %d:", n + 1);
+ }
/* Loop through to get user requests */
while (!done) {
wint_t ch;
int ret = get_wch(&ch);
- mvprintw(8, 10, "Got %d (%#x), type: %s", (int) ch, (int) ch,
+ mvprintw(MyRow(NUM_FIELDS),
+ MyCol(NUM_FIELDS),
+ "Got %d (%#x), type: %s",
+ (int) ch,
+ (int) ch,
(ret == KEY_CODE_YES)
? "KEY_CODE_YES"
: ((ret == OK)
@@ -106,6 +121,7 @@ main(void)
/* Leaves nicely at the last character */
form_driver_w(my_form, KEY_CODE_YES, REQ_END_LINE);
break;
+ case KEY_BTAB:
case KEY_UP:
/* Go to previous field */
form_driver_w(my_form, KEY_CODE_YES, REQ_PREV_FIELD);
@@ -122,6 +138,13 @@ main(void)
case ESCAPE:
done = TRUE;
break;
+ case '\t':
+ form_driver_w(my_form, KEY_CODE_YES, REQ_NEXT_FIELD);
+ form_driver_w(my_form, KEY_CODE_YES, REQ_END_LINE);
+ break;
+ case HELP_KEY_1:
+ popup_msg(form_win(my_form), help);
+ break;
default:
form_driver_w(my_form, OK, (wchar_t) ch);
break;
@@ -133,8 +156,9 @@ main(void)
/* Un post form and free the memory */
unpost_form(my_form);
free_form(my_form);
- free_field(field[0]);
- free_field(field[1]);
+ for (n = 0; n < NUM_FIELDS; ++n) {
+ free_field(field[n]);
+ }
endwin();
ExitProgram(EXIT_SUCCESS);