10
static void * newtvwindow(char * title, char * button1, char * button2,
11
char * button3, char * message, va_list args) {
12
newtComponent b1, b2 = NULL, b3 = NULL, t, f, answer;
19
newtGrid grid, buttonGrid;
25
i = vsnprintf(buf, size, message, args);
26
} while (i >= size || i == -1);
28
flowedText = newtReflowText(buf, 35, 5, 5, &width, &height);
31
flowedText = newtReflowText(buf, 60, 5, 5, &width, &height);
37
scroll = NEWT_FLAG_SCROLL;
39
t = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP | scroll);
40
newtTextboxSetText(t, flowedText);
44
buttonGrid = newtButtonBar(button1, &b1, button2, &b2,
47
buttonGrid = newtButtonBar(button1, &b1, button2, &b2, NULL);
49
buttonGrid = newtButtonBar(button1, &b1, NULL);
52
newtGridSetField(buttonGrid, 0, 0, NEWT_GRID_COMPONENT, b1,
53
0, 0, button2 ? 1 : 0, 0, 0, 0);
55
grid = newtCreateGrid(1, 2);
56
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 0, 0, 0);
57
newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, buttonGrid,
58
0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
59
newtGridWrappedWindow(grid, title);
61
f = newtForm(NULL, NULL, 0);
62
newtFormAddComponents(f, t, b1, NULL);
65
newtFormAddComponent(f, b2);
67
newtFormAddComponent(f, b3);
69
answer = newtRunForm(f);
70
newtGridFree(grid, 1);
77
else if (answer == b1)
79
else if (answer == b2)
85
int newtWinChoice(char * title, char * button1, char * button2,
86
char * message, ...) {
90
va_start(args, message);
91
rc = newtvwindow(title, button1, button2, NULL, message, args);
96
else if (rc == button2)
102
void newtWinMessage(char * title, char * buttonText, char * text, ...) {
105
va_start(args, text);
106
newtvwindow(title, buttonText, NULL, NULL, text, args);
111
void newtWinMessagev(char * title, char * buttonText, char * text,
113
newtvwindow(title, buttonText, NULL, NULL, text, argv);
116
int newtWinTernary(char * title, char * button1, char * button2,
117
char * button3, char * message, ...) {
121
va_start(args, message);
122
rc = newtvwindow(title, button1, button2, button3, message, args);
127
else if (rc == button2)
129
else if (rc == button3)
135
/* only supports up to 50 buttons -- shucks! */
136
int newtWinMenu(char * title, char * text, int suggestedWidth, int flexDown,
137
int flexUp, int maxListHeight, char ** items, int * listItem,
138
char * button1, ...) {
139
newtComponent textbox, listbox, result, form;
141
newtComponent buttons[50];
142
newtGrid grid, buttonBar;
148
textbox = newtTextboxReflowed(-1, -1, text, suggestedWidth, flexDown,
151
for (i = 0; items[i]; i++) ;
152
if (i < maxListHeight) maxListHeight = i;
153
needScroll = i > maxListHeight;
155
listbox = newtListbox(-1, -1, maxListHeight,
156
(needScroll ? NEWT_FLAG_SCROLL : 0) | NEWT_FLAG_RETURNEXIT);
157
for (i = 0; items[i]; i++) {
158
newtListboxAddEntry(listbox, items[i], (void *) i);
161
newtListboxSetCurrent(listbox, *listItem);
163
buttonName = button1, numButtons = 0;
164
va_start(args, button1);
166
buttons[numButtons] = newtButton(-1, -1, buttonName);
168
buttonName = va_arg(args, char *);
173
buttonBar = newtCreateGrid(numButtons, 1);
174
for (i = 0; i < numButtons; i++) {
175
newtGridSetField(buttonBar, i, 0, NEWT_GRID_COMPONENT,
177
i ? 1 : 0, 0, 0, 0, 0, 0);
180
grid = newtGridSimpleWindow(textbox, listbox, buttonBar);
181
newtGridWrappedWindow(grid, title);
183
form = newtForm(NULL, 0, 0);
184
newtGridAddComponentsToForm(grid, form, 1);
185
newtGridFree(grid, 1);
187
result = newtRunForm(form);
189
*listItem = ((long) newtListboxGetCurrent(listbox));
191
for (rc = 0; result != buttons[rc] && rc < numButtons; rc++);
192
if (rc == numButtons)
193
rc = 0; /* F12 or return-on-exit (which are the same for us) */
197
newtFormDestroy(form);
203
/* only supports up to 50 buttons and entries -- shucks! */
204
int newtWinEntries(char * title, char * text, int suggestedWidth, int flexDown,
205
int flexUp, int dataWidth,
206
struct newtWinEntry * items, char * button1, ...) {
207
newtComponent buttons[50], result, form, textw;
208
newtGrid grid, buttonBar, subgrid;
215
textw = newtTextboxReflowed(-1, -1, text, suggestedWidth, flexDown,
218
for (numItems = 0; items[numItems].text; numItems++);
220
buttonName = button1, numButtons = 0;
221
va_start(args, button1);
223
buttons[numButtons] = newtButton(-1, -1, buttonName);
225
buttonName = va_arg(args, char *);
230
buttonBar = newtCreateGrid(numButtons, 1);
231
for (i = 0; i < numButtons; i++) {
232
newtGridSetField(buttonBar, i, 0, NEWT_GRID_COMPONENT,
234
i ? 1 : 0, 0, 0, 0, 0, 0);
237
subgrid = newtCreateGrid(2, numItems);
238
for (i = 0; i < numItems; i++) {
239
newtGridSetField(subgrid, 0, i, NEWT_GRID_COMPONENT,
240
newtLabel(-1, -1, items[i].text),
241
0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
242
newtGridSetField(subgrid, 1, i, NEWT_GRID_COMPONENT,
243
newtEntry(-1, -1, items[i].value ?
244
*items[i].value : NULL, dataWidth,
245
items[i].value, items[i].flags),
249
grid = newtCreateGrid(1, 3);
250
form = newtForm(NULL, 0, 0);
251
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, textw,
252
0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
253
newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid,
255
newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttonBar,
256
0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
257
newtGridAddComponentsToForm(grid, form, 1);
258
newtGridWrappedWindow(grid, title);
259
newtGridFree(grid, 1);
261
result = newtRunForm(form);
263
for (rc = 0; rc < numItems; rc++)
264
*items[rc].value = strdup(*items[rc].value);
266
for (rc = 0; result != buttons[rc] && rc < numButtons; rc++);
267
if (rc == numButtons)
272
newtFormDestroy(form);