1
diff -ruN newt-0.51.6-old/dialogboxes.c newt-0.51.6/dialogboxes.c
2
--- newt-0.51.6-old/dialogboxes.c 2004-03-09 12:38:14.000000000 +0000
3
+++ newt-0.51.6/dialogboxes.c 2004-03-09 12:38:15.000000000 +0000
11
#include "dialogboxes.h"
15
static int buttonHeight = 1;
17
+int max (int a, int b)
19
+ return (a > b) ? a : b;
22
+int min (int a, int b)
24
+ return ( a < b) ? a : b ;
27
static newtComponent (*makeButton)(int left, int right, const char * text) =
34
- char buf[MAXBUF], format[MAXFOTMAT];
35
+ char buf[MAXBUF], format[MAXFORMAT];
40
+ int lineWidth, textWidth, tagWidth;
48
- listBox = newtListbox(3 + ((width - 10 - maxTagWidth - maxTextWidth - i)
50
- top + 1, listHeight,
51
- NEWT_FLAG_RETURNEXIT | scrollFlag);
53
- snprintf(format, MAXFORMAT, "%%-%ds %%s", maxTagWidth);
54
- for (i = 0; i < numItems; i++) {
55
- snprintf(buf, MAXBUF, format, itemInfo[i].tag, itemInfo[i].text);
56
- newtListboxAddEntry(listBox, buf, (void *) i);
58
+ lineWidth = min(maxTagWidth + maxTextWidth + i, SLtt_Screen_Cols - 10);
59
+ listBox = newtListbox( (width - lineWidth) / 2 , top + 1, listHeight,
60
+ NEWT_FLAG_RETURNEXIT | scrollFlag);
62
+ textWidth = maxTextWidth;
63
+ tagWidth = maxTagWidth;
64
+ if (maxTextWidth == 0) {
65
+ tagWidth = lineWidth;
67
+ if (maxTextWidth + maxTagWidth + i > lineWidth)
68
+ tagWidth = textWidth = (lineWidth / 2) - 2;
75
+ if (!(flags & FLAG_NOTAGS)) {
76
+ snprintf(format, MAXFORMAT, "%%-%d.%ds %%.%ds",tagWidth, tagWidth, textWidth );
77
+ for (i = 0; i < numItems; i++) {
78
+ snprintf(buf, MAXBUF, format, itemInfo[i].tag, itemInfo[i].text);
79
+ newtListboxAddEntry(listBox, buf, (void *) i);
82
+ for (i = 0; i < numItems; i++) {
83
+ snprintf(buf, MAXBUF, "%s", itemInfo[i].text);
84
+ newtListboxAddEntry(listBox, buf, (void *) i);
89
newtListboxSetCurrent (listBox, defItem);
90
diff -ruN newt-0.51.6-old/dialogboxes.h newt-0.51.6/dialogboxes.h
91
--- newt-0.51.6-old/dialogboxes.h 2004-03-09 12:38:14.000000000 +0000
92
+++ newt-0.51.6/dialogboxes.h 2004-03-09 12:38:15.000000000 +0000
97
+int min(int a, int b);
98
+int max(int a, int b);
100
int messageBox(const char * text, int height, int width, int type, int flags);
101
int checkList(const char * text, int height, int width, poptContext optCon,
102
int useRadio, int flags, const char *** selections);
103
diff -ruN newt-0.51.6-old/whiptail.c newt-0.51.6/whiptail.c
104
--- newt-0.51.6-old/whiptail.c 2004-03-09 12:38:14.000000000 +0000
105
+++ newt-0.51.6/whiptail.c 2004-03-09 12:38:15.000000000 +0000
107
-/* a reasonable dialog */
119
#include "dialogboxes.h"
124
+/* FIXME Copied from newt.c
125
+ * Place somewhere better -- dialogboxes? -- amck
127
+int wstrlen(const char *str, int len) {
132
+ if (!str) return 0;
133
+ if (!len) return 0;
134
+ if (len < 0) len = strlen(str);
135
+ memset(&ps,0,sizeof(mbstate_t));
139
+ x = mbrtowc(&tmp,str,len,&ps);
152
+ * The value of *width is increased if it is not as large as the width of
155
+static const char * lineWidth(int * width, const char * line, int *chrs)
157
+ const char * s = line;
159
+ if ( line == NULL )
162
+ while ( *s != '\0' && *s != '\n' )
168
+ *chrs = wstrlen (line, s - line );
169
+ *width = max(*width, *chrs);
177
+ * Handle newlines in text. Hack.
179
+void cleanNewlines (char *text)
183
+ if ((*p == '\\') && (*(p+1) == 'n')) {
193
+ * The height of a text string is added to height, and width is increased
194
+ * if it is not big enough to store the text string.
196
+static const char * textSize(int * height, int * width,
205
+ if ( text == NULL )
208
+ while ( *text != '\0' ) {
210
+ text = lineWidth(width, text, &chrs);
211
+ /* Allow for text overflowing. May overestimate a bit */
212
+ h += chrs / maxWidth;
221
+ *width = min(*width, maxWidth);
226
+ * Add space for buttons.
227
+ * NOTE: when this is internationalized, the button width might change.
229
+static void spaceForButtons(int * height, int * width, int count, int full) {
230
+ /* Make space for the buttons */
234
+ *width = max(*width, 7);
236
+ *width = max(*width, 20);
241
+ *width = max(*width, 7);
243
+ *width = max(*width, 19);
247
+static int menuSize(int * height, int * width, enum mode mode,
248
+ poptContext options) {
249
+ char ** argv = poptGetArgs(options);
250
+ char * * items = argv;
253
+ int descriptionWidth = 0;
255
+ static char buf[20];
257
+ if ( argv == 0 || *argv == 0 )
261
+ if ( mode == MODE_MENU )
264
+ while ( argv[0] != 0 && argv[1] ) {
265
+ tagWidth = max(tagWidth, strlen(argv[0]));
266
+ descriptionWidth = max(descriptionWidth, strlen(argv[1]));
268
+ if ( mode == MODE_MENU )
275
+ *width = max(*width, tagWidth + descriptionWidth + overhead);
276
+ *width = min(*width, SLtt_Screen_Cols);
278
+ h = min(h, SLtt_Screen_Rows - *height - 4);
279
+ *height = *height + h + 1;
280
+ sprintf(buf, "%d", h);
286
+ * Guess the size of a window, given what will be displayed within it.
288
+static void guessSize(int * height, int * width, enum mode mode,
289
+ int * flags, int fullButtons,
290
+ const char * title, const char * text,
291
+ poptContext options) {
293
+ int w = 0, h = 0, chrs = 0;
295
+ textSize(&h, &w, SLtt_Screen_Cols -4 , text); /* Width and height for text */
296
+ lineWidth(&w, title, &chrs); /* Width for title */
302
+ case MODE_CHECKLIST:
303
+ case MODE_RADIOLIST:
305
+ spaceForButtons(&h, &w, *flags & FLAG_NOCANCEL ? 1 : 2,
307
+ menuSize(&h, &w, mode, options);
311
+ spaceForButtons(&h, &w, 1, fullButtons);
313
+ case MODE_INPUTBOX:
314
+ spaceForButtons(&h, &w, *flags & FLAG_NOCANCEL ? 1 : 2,
328
+ * Fixed window-border overhead.
329
+ * NOTE: This will change if we add a way to turn off drop-shadow and/or
330
+ * box borders. That would be desirable for display-sized screens.
335
+ if ( h > SLtt_Screen_Rows - 1 ) {
336
+ h = SLtt_Screen_Rows - 1;
337
+ *flags |= FLAG_SCROLL_TEXT;
338
+ w += 2; /* Add width of slider - is this right? */
341
+ *width = min(max(*width, w), SLtt_Screen_Cols);
342
+ *height = max(*height, h);
346
readTextFile(const char * filename)
351
int separateOutput = 0;
352
+ int fullButtons = 0;
354
FILE *output = stderr;
359
case OPT_FULLBUTTONS:
366
if (!(text = poptGetArg(optCon))) usage();
368
- if ( mode == MODE_TEXTBOX ) text = readTextFile(text);
369
+ if (mode == MODE_TEXTBOX ) text = readTextFile(text);
371
if (!(nextArg = poptGetArg(optCon))) usage();
372
height = strtoul(nextArg, &end, 10);
373
@@ -213,10 +435,18 @@
378
+ cleanNewlines(text);
380
+ if ( height <= 0 || width <= 0 )
381
+ guessSize(&height, &width, mode, &flags, fullButtons, title, text,
386
- newtOpenWindow((80 - width) / 2, (24 - height) / 2, width, height, title);
388
+ newtOpenWindow((SLtt_Screen_Cols - width) / 2,
389
+ (SLtt_Screen_Rows - height) / 2, width, height, title);
391
newtDrawRootText(0, 0, backtitle);