5 * Jordan Hubbard. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * verbatim and that no modifications are made prior to this
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 static Boolean exited;
40 dmenuDisplayFile(dialogMenuItem *tmp)
42 systemDisplayHelp((char *)tmp->data);
47 dmenuSubmenu(dialogMenuItem *tmp)
49 return (dmenuOpenSimple((DMenu *)(tmp->data), FALSE) ? DITEM_SUCCESS : DITEM_FAILURE);
53 dmenuSystemCommand(dialogMenuItem *self)
55 WINDOW *w = NULL; /* Keep lint happy */
57 /* If aux is set, the command is known not to produce any screen-spoiling output */
60 systemExecute((char *)self->data);
67 dmenuSystemCommandBox(dialogMenuItem *tmp)
69 WINDOW *w = savescr();
72 use_helpline("Select OK to dismiss this dialog");
73 dialog_prgbox(tmp->title, (char *)tmp->data, 22, 76, 1, 1);
79 dmenuExit(dialogMenuItem *tmp)
82 return DITEM_LEAVE_MENU;
86 dmenuSetVariable(dialogMenuItem *tmp)
88 variable_set((char *)tmp->data, *((char *)tmp->data) != '_');
93 dmenuSetVariables(dialogMenuItem *tmp)
96 char *copy = strdup((char *)tmp->data);
98 for (cp1 = copy; cp1 != NULL;) {
99 cp2 = index(cp1, ',');
100 if (cp2 != NULL) *cp2++ = '\0';
101 variable_set(cp1, *cp1 != '_');
105 return DITEM_SUCCESS;
109 dmenuToggleVariable(dialogMenuItem *tmp)
114 if (!(var = strdup((char *)tmp->data))) {
115 msgConfirm("Incorrect data field for `%s'!", tmp->title);
116 return DITEM_FAILURE;
118 if (!(cp = index(var, '='))) {
119 msgConfirm("Data field for %s is not in var=value format!", tmp->title);
120 return DITEM_FAILURE;
122 status = variable_check(var);
124 variable_set2(var, status ? "NO" : "YES", *var != '_');
126 return DITEM_SUCCESS;
130 dmenuISetVariable(dialogMenuItem *tmp)
134 if (!(var = (char *)tmp->data)) {
135 msgConfirm("Incorrect data field for `%s'!", tmp->title);
136 return DITEM_FAILURE;
138 ans = msgGetInput(variable_get(var), tmp->title, 1);
140 return DITEM_FAILURE;
144 variable_set2(var, ans, *var != '_');
145 return DITEM_SUCCESS;
149 dmenuSetFlag(dialogMenuItem *tmp)
151 if (*((unsigned int *)tmp->data) & tmp->aux)
152 *((unsigned int *)tmp->data) &= ~tmp->aux;
154 *((unsigned int *)tmp->data) |= tmp->aux;
155 return DITEM_SUCCESS;
159 dmenuSetValue(dialogMenuItem *tmp)
161 *((unsigned int *)tmp->data) = tmp->aux;
162 return DITEM_SUCCESS;
165 /* Traverse menu but give user no control over positioning */
167 dmenuOpenSimple(DMenu *menu, Boolean buttons)
169 int choice, scroll, curr, max;
171 choice = scroll = curr = max = 0;
172 return dmenuOpen(menu, &choice, &scroll, &curr, &max, buttons);
175 /* Work functions for the state hook */
177 dmenuFlagCheck(dialogMenuItem *item)
179 return (*((unsigned int *)item->data) & item->aux);
183 dmenuVarCheck(dialogMenuItem *item)
187 w = (char *)item->aux;
189 w = (char *)item->data;
190 return variable_check(w);
194 dmenuVarsCheck(dialogMenuItem *item)
200 w = (char *)item->aux;
202 w = (char *)item->data;
209 for (cp1 = copy; cp1 != NULL;) {
211 cp2 = index(cp1, ',');
214 res = res && variable_check(cp1);
222 dmenuRadioCheck(dialogMenuItem *item)
224 return (*((long *)item->data) == item->aux);
228 menu_height(DMenu *menu, int n)
235 max += StatusLine - 24;
236 for (t = menu->prompt; *t; t++) {
240 return n > max ? max : n;
243 /* Traverse over an internal menu */
245 dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons)
248 dialogMenuItem *items;
253 /* Count up all the items */
254 for (n = 0; items[n].title; n++);
257 char buf[FILENAME_MAX];
258 WINDOW *w = savescr();
260 /* Any helpful hints, put 'em up! */
261 use_helpline(menu->helpline);
262 use_helpfile(systemHelpFile(menu->helpfile, buf));
263 dialog_clear_norefresh();
264 /* Pop up that dialog! */
265 if (menu->type & DMENU_NORMAL_TYPE)
266 rval = dialog_menu((u_char *)menu->title, (u_char *)menu->prompt,
267 -1, -1, menu_height(menu, n), -n, items,
268 (char *)(uintptr_t)buttons, choice, scroll);
270 else if (menu->type & DMENU_RADIO_TYPE)
271 rval = dialog_radiolist((u_char *)menu->title,
272 (u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n,
273 items, (char *)(uintptr_t)buttons);
275 else if (menu->type & DMENU_CHECKLIST_TYPE)
276 rval = dialog_checklist((u_char *)menu->title,
277 (u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n,
278 items, (char *)(uintptr_t)buttons);
280 msgFatal("Menu: `%s' is of an unknown type\n", menu->title);
290 else if (menu->type & DMENU_SELECTION_RETURNS) {