2 * $Id: mixedform.c,v 1.8 2010/04/28 20:54:11 tom Exp $
4 * formbox.c -- implements the form (i.e, some pairs label/editbox)
6 * Copyright 2007-2008,2010 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;
58 dlg_save_vars(&save_vars);
59 dialog_vars.separate_output = TRUE;
61 listitems = dlg_calloc(DIALOG_FORMITEM, (size_t) item_no + 1);
62 assert_ptr(listitems, "dialog_mixedform");
64 for (i = 0; i < item_no; ++i) {
65 listitems[i].type = dialog_vars.formitem_type;
66 listitems[i].name = ItemName(i);
67 listitems[i].name_len = (int) strlen(ItemName(i));
68 listitems[i].name_y = dlg_ordinate(ItemNameY(i));
69 listitems[i].name_x = dlg_ordinate(ItemNameX(i));
70 listitems[i].text = ItemText(i);
71 listitems[i].text_len = (int) strlen(ItemText(i));
72 listitems[i].text_y = dlg_ordinate(ItemTextY(i));
73 listitems[i].text_x = dlg_ordinate(ItemTextX(i));
74 listitems[i].text_flen = atoi(ItemTextFLen(i));
75 listitems[i].text_ilen = atoi(ItemTextILen(i));
76 listitems[i].help = (dialog_vars.item_help ? ItemHelp(i) :
78 listitems[i].type = (unsigned) atoi(ItemTypep(i));
81 result = dlg_form(title,
91 case DLG_EXIT_OK: /* FALLTHRU */
96 dlg_add_result("HELP ");
97 show_status = dialog_vars.help_status;
98 if (USE_ITEM_HELP(listitems[choice].help)) {
99 dlg_add_string(listitems[choice].help);
100 result = DLG_EXIT_ITEM_HELP;
102 dlg_add_string(listitems[choice].name);
109 for (i = 0; i < item_no; i++) {
110 if (listitems[i].text_flen > 0) {
111 dlg_add_string(listitems[i].text);
117 dlg_free_formitems(listitems);
118 dlg_restore_vars(&save_vars);