2 * $Id: demo_forms.c,v 1.3 2003/05/03 22:08:20 tom Exp $
4 * Demonstrate a variety of functions from the form library.
5 * Thomas Dickey - 2003/4/26
34 form_request_by_name -
50 set_fieldtype_choice -
60 #include <test.priv.h>
64 #include <edit_field.h>
67 make_label(int frow, int fcol, NCURSES_CONST char *label)
69 FIELD *f = new_field(1, strlen(label), frow, fcol, 0, 0);
72 set_field_buffer(f, 0, label);
73 set_field_opts(f, field_opts(f) & ~O_ACTIVE);
79 * Define each field with an extra one, for reflecting "actual" text.
82 make_field(int frow, int fcol, int rows, int cols)
84 FIELD *f = new_field(rows, cols, frow, fcol, 0, 1);
87 set_field_back(f, A_UNDERLINE);
88 set_field_userptr(f, (void *) 0);
94 display_form(FORM * f)
99 scale_form(f, &rows, &cols);
102 * Put the form at the upper-left corner of the display, with just a box
105 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
107 set_form_sub(f, derwin(w, rows, cols, 1, 2));
112 if (post_form(f) != E_OK)
119 WINDOW *w = form_win(f);
120 WINDOW *s = form_sub(f);
130 my_form_driver(FORM * form, int c)
133 case EDIT_FIELD('q'):
134 if (form_driver(form, REQ_VALIDATION) == E_OK)
137 case EDIT_FIELD('h'):
148 show_current_field(WINDOW *win, FORM * form)
156 wbkgd(win, COLOR_PAIR(1));
159 wprintw(win, "Cursor: %d,%d\n", form->currow, form->curcol);
160 if ((field = current_field(form)) != 0) {
161 wprintw(win, "Field %d:", field_index(field));
162 if ((type = field_type(field)) != 0) {
163 if (type == TYPE_ALNUM)
164 waddstr(win, "ALNUM");
165 else if (type == TYPE_ALPHA)
166 waddstr(win, "ALPHA");
167 else if (type == TYPE_ENUM)
168 waddstr(win, "ENUM");
169 else if (type == TYPE_INTEGER)
170 waddstr(win, "INTEGER");
171 else if (type == TYPE_NUMERIC)
172 waddstr(win, "NUMERIC");
173 else if (type == TYPE_REGEXP)
174 waddstr(win, "REGEXP");
176 waddstr(win, "other");
179 for (nbuf = 0; nbuf <= 2; ++nbuf) {
180 if ((buffer = field_buffer(field, nbuf)) != 0) {
181 wprintw(win, "buffer %d:", nbuf);
182 wattrset(win, A_REVERSE);
183 waddstr(win, buffer);
184 wattroff(win, A_REVERSE);
205 mvaddstr(4, 57, "Forms Entry Test");
209 /* describe the form */
210 for (pg = 0; pg < 3; ++pg) {
212 sprintf(label, "Sample Form Page %d", pg + 1);
213 f[n++] = make_label(0, 15, label);
214 set_new_page(f[n - 1], TRUE);
216 f[n++] = make_label(2, 0, "Last Name");
217 f[n++] = make_field(3, 0, 1, 18);
218 set_field_type(f[n - 1], TYPE_ALPHA, 1);
220 f[n++] = make_label(2, 20, "First Name");
221 f[n++] = make_field(3, 20, 1, 12);
222 set_field_type(f[n - 1], TYPE_ALPHA, 1);
224 f[n++] = make_label(2, 34, "Middle Name");
225 f[n++] = make_field(3, 34, 1, 12);
226 set_field_type(f[n - 1], TYPE_ALPHA, 1);
228 f[n++] = make_label(5, 0, "Comments");
229 f[n++] = make_field(6, 0, 4, 46);
232 f[n++] = (FIELD *) 0;
239 also = newwin(getmaxy(stdscr) - getmaxy(w), COLS, getmaxy(w), 0);
240 show_current_field(also, form);
243 switch (edit_field(form, &c)) {
246 case E_UNKNOWN_COMMAND:
247 finished = my_form_driver(form, c);
253 show_current_field(also, form);
259 for (c = 0; f[c] != 0; c++)
266 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
272 nonl(); /* lets us read ^M's */
273 intrflush(stdscr, FALSE);
274 keypad(stdscr, TRUE);
278 init_pair(1, COLOR_WHITE, COLOR_BLUE);
292 printf("This program requires the curses form library\n");
293 ExitProgram(EXIT_FAILURE);