2 * $Id: mixedform.c,v 1.13 2018/06/15 01:23:33 tom Exp $
4 * mixedform.c -- implements the mixed form (i.e, typed pairs label/editbox)
6 * Copyright 2007-2013,2018 Thomas E. Dickey
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to
19 * Free Software Foundation, Inc.
20 * 51 Franklin St., Fifth Floor
21 * Boston, MA 02110, USA.
23 * This is inspired by a patch from Kiran Cherupally
24 * (but different interface design).
29 #define LLEN(n) ((n) * MIXEDFORM_TAGS)
31 #define ItemName(i) items[LLEN(i) + 0]
32 #define ItemNameY(i) items[LLEN(i) + 1]
33 #define ItemNameX(i) items[LLEN(i) + 2]
34 #define ItemText(i) items[LLEN(i) + 3]
35 #define ItemTextY(i) items[LLEN(i) + 4]
36 #define ItemTextX(i) items[LLEN(i) + 5]
37 #define ItemTextFLen(i) items[LLEN(i) + 6]
38 #define ItemTextILen(i) items[LLEN(i) + 7]
39 #define ItemTypep(i) items[LLEN(i) + 8]
40 #define ItemHelp(i) (dialog_vars.item_help ? items[LLEN(i) + 9] : dlg_strempty())
43 dialog_mixedform(const char *title,
54 DIALOG_FORMITEM *listitems;
55 DIALOG_VARS save_vars;
56 bool show_status = FALSE;
59 dlg_save_vars(&save_vars);
60 dialog_vars.separate_output = TRUE;
62 listitems = dlg_calloc(DIALOG_FORMITEM, (size_t) item_no + 1);
63 assert_ptr(listitems, "dialog_mixedform");
65 for (i = 0; i < item_no; ++i) {
66 listitems[i].type = dialog_vars.formitem_type;
67 listitems[i].name = ItemName(i);
68 listitems[i].name_len = (int) strlen(ItemName(i));
69 listitems[i].name_y = dlg_ordinate(ItemNameY(i));
70 listitems[i].name_x = dlg_ordinate(ItemNameX(i));
71 listitems[i].text = ItemText(i);
72 listitems[i].text_len = (int) strlen(ItemText(i));
73 listitems[i].text_y = dlg_ordinate(ItemTextY(i));
74 listitems[i].text_x = dlg_ordinate(ItemTextX(i));
75 listitems[i].text_flen = atoi(ItemTextFLen(i));
76 listitems[i].text_ilen = atoi(ItemTextILen(i));
77 listitems[i].help = (dialog_vars.item_help ? ItemHelp(i) :
79 listitems[i].type = (unsigned) atoi(ItemTypep(i));
82 result = dlg_form(title,
92 case DLG_EXIT_OK: /* FALLTHRU */
97 dlg_add_help_formitem(&result, &help_result, &listitems[choice]);
98 show_status = dialog_vars.help_status;
99 dlg_add_string(help_result);
105 for (i = 0; i < item_no; i++) {
106 if (listitems[i].text_flen > 0) {
107 dlg_add_string(listitems[i].text);
111 dlg_add_last_key(-1);
114 dlg_free_formitems(listitems);
115 dlg_restore_vars(&save_vars);