]>
git.ipfire.org Git - thirdparty/newt.git/blob - windows.c
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
;
24 va_copy(argscopy
, args
);
28 i
= vsnprintf(buf
, size
, message
, argscopy
);
30 } while (i
>= size
|| i
== -1);
32 flowedText
= newtReflowText(buf
, 35, 5, 5, &width
, &height
);
35 flowedText
= newtReflowText(buf
, 60, 5, 5, &width
, &height
);
41 scroll
= NEWT_FLAG_SCROLL
;
43 t
= newtTextbox(-1, -1, width
, height
, NEWT_TEXTBOX_WRAP
| scroll
);
44 newtTextboxSetText(t
, flowedText
);
48 buttonGrid
= newtButtonBar(button1
, &b1
, button2
, &b2
,
51 buttonGrid
= newtButtonBar(button1
, &b1
, button2
, &b2
, NULL
);
53 buttonGrid
= newtButtonBar(button1
, &b1
, NULL
);
56 newtGridSetField(buttonGrid
, 0, 0, NEWT_GRID_COMPONENT
, b1
,
57 0, 0, button2
? 1 : 0, 0, 0, 0);
59 grid
= newtCreateGrid(1, 2);
60 newtGridSetField(grid
, 0, 0, NEWT_GRID_COMPONENT
, t
, 0, 0, 0, 0, 0, 0);
61 newtGridSetField(grid
, 0, 1, NEWT_GRID_SUBGRID
, buttonGrid
,
62 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX
);
63 newtGridWrappedWindow(grid
, title
);
65 f
= newtForm(NULL
, NULL
, 0);
66 newtFormAddComponents(f
, t
, b1
, NULL
);
69 newtFormAddComponent(f
, b2
);
71 newtFormAddComponent(f
, b3
);
73 answer
= newtRunForm(f
);
74 newtGridFree(grid
, 1);
81 else if (answer
== b1
)
83 else if (answer
== b2
)
89 int newtWinChoice(char * title
, char * button1
, char * button2
,
90 char * message
, ...) {
94 va_start(args
, message
);
95 rc
= newtvwindow(title
, button1
, button2
, NULL
, message
, args
);
100 else if (rc
== button2
)
106 void newtWinMessage(char * title
, char * buttonText
, char * text
, ...) {
109 va_start(args
, text
);
110 newtvwindow(title
, buttonText
, NULL
, NULL
, text
, args
);
114 void newtWinMessagev(char * title
, char * buttonText
, char * text
,
116 newtvwindow(title
, buttonText
, NULL
, NULL
, text
, argv
);
119 int newtWinTernary(char * title
, char * button1
, char * button2
,
120 char * button3
, char * message
, ...) {
124 va_start(args
, message
);
125 rc
= newtvwindow(title
, button1
, button2
, button3
, message
, args
);
130 else if (rc
== button2
)
132 else if (rc
== button3
)
138 int newtWinMenu(char * title
, char * text
, int suggestedWidth
, int flexDown
,
139 int flexUp
, int maxListHeight
, char ** items
, int * listItem
,
140 char * button1
, ...) {
141 newtComponent textbox
, listbox
, result
, form
;
143 newtComponent
*buttons
= NULL
;
144 newtGrid grid
, buttonBar
;
145 size_t totalButtons
= 0, numButtons
= 0;
150 textbox
= newtTextboxReflowed(-1, -1, text
, suggestedWidth
, flexDown
,
153 for (i
= 0; items
[i
]; i
++) ;
154 if (i
< maxListHeight
) maxListHeight
= i
;
155 needScroll
= i
> maxListHeight
;
157 listbox
= newtListbox(-1, -1, maxListHeight
,
158 (needScroll
? NEWT_FLAG_SCROLL
: 0) | NEWT_FLAG_RETURNEXIT
);
159 for (i
= 0; items
[i
]; i
++) {
160 newtListboxAddEntry(listbox
, items
[i
], (void *)(long) i
);
163 newtListboxSetCurrent(listbox
, *listItem
);
165 va_start(args
, button1
);
166 for (buttonName
= button1
; buttonName
; buttonName
= va_arg(args
, char *))
170 buttons
= (newtComponent
*)alloca(sizeof(newtComponent
)*(totalButtons
));
171 va_start(args
, button1
);
172 for (buttonName
= button1
; buttonName
; buttonName
= va_arg(args
, char *))
173 buttons
[numButtons
++] = newtButton(-1, -1, buttonName
);
176 buttonBar
= newtCreateGrid(numButtons
? numButtons
: 1, 1);
177 for (i
= 0; i
< numButtons
; i
++) {
178 newtGridSetField(buttonBar
, i
, 0, NEWT_GRID_COMPONENT
,
180 i
? 1 : 0, 0, 0, 0, 0, 0);
183 grid
= newtGridSimpleWindow(textbox
, listbox
, buttonBar
);
184 newtGridWrappedWindow(grid
, title
);
186 form
= newtForm(NULL
, 0, 0);
187 newtGridAddComponentsToForm(grid
, form
, 1);
188 newtGridFree(grid
, 1);
190 result
= newtRunForm(form
);
192 *listItem
= ((long) newtListboxGetCurrent(listbox
));
194 for (rc
= 0; rc
< numButtons
&& result
!= buttons
[rc
]; rc
++)
196 if (rc
== numButtons
)
197 rc
= 0; /* F12 or return-on-exit (which are the same for us) */
201 newtFormDestroy(form
);
207 int newtWinEntries(char * title
, char * text
, int suggestedWidth
, int flexDown
,
208 int flexUp
, int dataWidth
,
209 struct newtWinEntry
* items
, char * button1
, ...) {
210 newtComponent
*buttons
, result
, form
, textw
;
211 newtGrid grid
, buttonBar
, subgrid
;
214 size_t numButtons
= 0, totalButtons
= 0;
218 textw
= newtTextboxReflowed(-1, -1, text
, suggestedWidth
, flexDown
,
221 for (numItems
= 0; items
[numItems
].text
; numItems
++);
223 va_start(args
, button1
);
224 for (buttonName
= button1
; buttonName
; buttonName
= va_arg(args
, char *))
228 buttons
= (newtComponent
*)alloca(sizeof(newtComponent
)*(totalButtons
));
229 va_start(args
, button1
);
230 for (buttonName
= button1
; buttonName
; buttonName
= va_arg(args
, char *))
231 buttons
[numButtons
++] = newtButton(-1, -1, buttonName
);
234 buttonBar
= newtCreateGrid(numButtons
? numButtons
: 1, 1);
235 for (i
= 0; i
< numButtons
; i
++) {
236 newtGridSetField(buttonBar
, i
, 0, NEWT_GRID_COMPONENT
,
238 i
? 1 : 0, 0, 0, 0, 0, 0);
241 subgrid
= newtCreateGrid(2, numItems
? numItems
: 1);
242 for (i
= 0; i
< numItems
; i
++) {
243 newtGridSetField(subgrid
, 0, i
, NEWT_GRID_COMPONENT
,
244 newtLabel(-1, -1, items
[i
].text
),
245 0, 0, 0, 0, NEWT_ANCHOR_LEFT
, 0);
246 newtGridSetField(subgrid
, 1, i
, NEWT_GRID_COMPONENT
,
247 newtEntry(-1, -1, items
[i
].value
?
248 *items
[i
].value
: NULL
, dataWidth
,
249 (const char **)items
[i
].value
, items
[i
].flags
),
253 grid
= newtCreateGrid(1, 3);
254 form
= newtForm(NULL
, 0, 0);
255 newtGridSetField(grid
, 0, 0, NEWT_GRID_COMPONENT
, textw
,
256 0, 0, 0, 0, NEWT_ANCHOR_LEFT
, 0);
257 newtGridSetField(grid
, 0, 1, NEWT_GRID_SUBGRID
, subgrid
,
259 newtGridSetField(grid
, 0, 2, NEWT_GRID_SUBGRID
, buttonBar
,
260 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX
);
261 newtGridAddComponentsToForm(grid
, form
, 1);
262 newtGridWrappedWindow(grid
, title
);
263 newtGridFree(grid
, 1);
265 result
= newtRunForm(form
);
267 for (rc
= 0; rc
< numItems
; rc
++)
268 *items
[rc
].value
= strdup(*items
[rc
].value
);
270 for (rc
= 0; rc
< numButtons
&& result
!= buttons
[rc
]; rc
++)
272 if (rc
== numButtons
)
277 newtFormDestroy(form
);