xref: /freebsd-src/contrib/dialog/mixedgauge.c (revision a96ef4501919d7ac08e94e98dc34b0bdd744802b)
14c8945a0SNathan Whitehorn /*
2*a96ef450SBaptiste Daroussin  *  $Id: mixedgauge.c,v 1.37 2021/01/16 17:19:15 tom Exp $
34c8945a0SNathan Whitehorn  *
44c8945a0SNathan Whitehorn  *  mixedgauge.c -- implements the mixedgauge dialog
54c8945a0SNathan Whitehorn  *
6*a96ef450SBaptiste Daroussin  *  Copyright 2007-2020,2021	Thomas E. Dickey
74c8945a0SNathan Whitehorn  *
84c8945a0SNathan Whitehorn  *  This program is free software; you can redistribute it and/or modify
94c8945a0SNathan Whitehorn  *  it under the terms of the GNU Lesser General Public License, version 2.1
104c8945a0SNathan Whitehorn  *  as published by the Free Software Foundation.
114c8945a0SNathan Whitehorn  *
124c8945a0SNathan Whitehorn  *  This program is distributed in the hope that it will be useful, but
134c8945a0SNathan Whitehorn  *  WITHOUT ANY WARRANTY; without even the implied warranty of
144c8945a0SNathan Whitehorn  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
154c8945a0SNathan Whitehorn  *  Lesser General Public License for more details.
164c8945a0SNathan Whitehorn  *
174c8945a0SNathan Whitehorn  *  You should have received a copy of the GNU Lesser General Public
184c8945a0SNathan Whitehorn  *  License along with this program; if not, write to
194c8945a0SNathan Whitehorn  *	Free Software Foundation, Inc.
204c8945a0SNathan Whitehorn  *	51 Franklin St., Fifth Floor
214c8945a0SNathan Whitehorn  *	Boston, MA 02110, USA.
224c8945a0SNathan Whitehorn  *
234c8945a0SNathan Whitehorn  *  This is inspired by a patch from Kiran Cherupally
244c8945a0SNathan Whitehorn  *  (but different interface design).
254c8945a0SNathan Whitehorn  */
264c8945a0SNathan Whitehorn 
274c8945a0SNathan Whitehorn #include <dialog.h>
284c8945a0SNathan Whitehorn 
294c8945a0SNathan Whitehorn #define LLEN(n) ((n) * MIXEDGAUGE_TAGS)
304c8945a0SNathan Whitehorn #define ItemData(i)    &items[LLEN(i)]
314c8945a0SNathan Whitehorn #define ItemName(i)    items[LLEN(i)]
324c8945a0SNathan Whitehorn #define ItemText(i)    items[LLEN(i) + 1]
334c8945a0SNathan Whitehorn 
344c8945a0SNathan Whitehorn #define MIN_HIGH (4)
354c8945a0SNathan Whitehorn #define MIN_WIDE (10 + 2 * (2 + MARGIN))
364c8945a0SNathan Whitehorn 
374c8945a0SNathan Whitehorn typedef struct {
384c8945a0SNathan Whitehorn     WINDOW *dialog;
394c8945a0SNathan Whitehorn     WINDOW *caption;
404c8945a0SNathan Whitehorn     const char *title;
414c8945a0SNathan Whitehorn     char *prompt;
424c8945a0SNathan Whitehorn     int height, old_height, min_height;
434c8945a0SNathan Whitehorn     int width, old_width, min_width;
444c8945a0SNathan Whitehorn     int len_name, len_text;
454c8945a0SNathan Whitehorn     int item_no;
464c8945a0SNathan Whitehorn     DIALOG_LISTITEM *list;
474c8945a0SNathan Whitehorn } DIALOG_MIXEDGAUGE;
484c8945a0SNathan Whitehorn 
494c8945a0SNathan Whitehorn static const char *
status_string(char * given,char ** freeMe)504c8945a0SNathan Whitehorn status_string(char *given, char **freeMe)
514c8945a0SNathan Whitehorn {
524c8945a0SNathan Whitehorn     const char *result;
534c8945a0SNathan Whitehorn 
544c8945a0SNathan Whitehorn     *freeMe = 0;
554c8945a0SNathan Whitehorn     if (isdigit(UCH(*given))) {
564c8945a0SNathan Whitehorn 	switch (*given) {
574c8945a0SNathan Whitehorn 	case '0':
584c8945a0SNathan Whitehorn 	    result = _("Succeeded");
594c8945a0SNathan Whitehorn 	    break;
604c8945a0SNathan Whitehorn 	case '1':
614c8945a0SNathan Whitehorn 	    result = _("Failed");
624c8945a0SNathan Whitehorn 	    break;
634c8945a0SNathan Whitehorn 	case '2':
644c8945a0SNathan Whitehorn 	    result = _("Passed");
654c8945a0SNathan Whitehorn 	    break;
664c8945a0SNathan Whitehorn 	case '3':
674c8945a0SNathan Whitehorn 	    result = _("Completed");
684c8945a0SNathan Whitehorn 	    break;
694c8945a0SNathan Whitehorn 	case '4':
704c8945a0SNathan Whitehorn 	    result = _("Checked");
714c8945a0SNathan Whitehorn 	    break;
724c8945a0SNathan Whitehorn 	case '5':
734c8945a0SNathan Whitehorn 	    result = _("Done");
744c8945a0SNathan Whitehorn 	    break;
754c8945a0SNathan Whitehorn 	case '6':
764c8945a0SNathan Whitehorn 	    result = _("Skipped");
774c8945a0SNathan Whitehorn 	    break;
784c8945a0SNathan Whitehorn 	case '7':
794c8945a0SNathan Whitehorn 	    result = _("In Progress");
804c8945a0SNathan Whitehorn 	    break;
814c8945a0SNathan Whitehorn 	case '8':
824c8945a0SNathan Whitehorn 	    result = "";
834c8945a0SNathan Whitehorn 	    break;
844c8945a0SNathan Whitehorn 	case '9':
854c8945a0SNathan Whitehorn 	    result = _("N/A");
864c8945a0SNathan Whitehorn 	    break;
874c8945a0SNathan Whitehorn 	default:
884c8945a0SNathan Whitehorn 	    result = "?";
894c8945a0SNathan Whitehorn 	    break;
904c8945a0SNathan Whitehorn 	}
914c8945a0SNathan Whitehorn     } else if (*given == '-') {
92f4f33ea0SBaptiste Daroussin 	size_t need = strlen(++given) + 4;
934c8945a0SNathan Whitehorn 	char *temp = dlg_malloc(char, need);
944c8945a0SNathan Whitehorn 	*freeMe = temp;
954c8945a0SNathan Whitehorn 	sprintf(temp, "%3s%%", given);
964c8945a0SNathan Whitehorn 	result = temp;
974c8945a0SNathan Whitehorn     } else if (!isspace(UCH(*given))) {
984c8945a0SNathan Whitehorn 	result = given;
994c8945a0SNathan Whitehorn     } else {
1004c8945a0SNathan Whitehorn 	result = 0;
1014c8945a0SNathan Whitehorn     }
1024c8945a0SNathan Whitehorn     return result;
1034c8945a0SNathan Whitehorn }
1044c8945a0SNathan Whitehorn 
1054c8945a0SNathan Whitehorn /* This function displays status messages */
1064c8945a0SNathan Whitehorn static void
myprint_status(DIALOG_MIXEDGAUGE * dlg)1074c8945a0SNathan Whitehorn myprint_status(DIALOG_MIXEDGAUGE * dlg)
1084c8945a0SNathan Whitehorn {
1094c8945a0SNathan Whitehorn     WINDOW *win = dlg->dialog;
1104c8945a0SNathan Whitehorn     int limit_y = dlg->height;
1114c8945a0SNathan Whitehorn     int limit_x = dlg->width;
1124c8945a0SNathan Whitehorn 
1134c8945a0SNathan Whitehorn     int item;
1144c8945a0SNathan Whitehorn     int cells = dlg->len_text - 2;
1154c8945a0SNathan Whitehorn     int lm = limit_x - dlg->len_text - 1;
1164c8945a0SNathan Whitehorn     int bm = limit_y;		/* bottom margin */
1174c8945a0SNathan Whitehorn     int last_y = 0, last_x = 0;
1184c8945a0SNathan Whitehorn     int j, xxx;
1194c8945a0SNathan Whitehorn     float percent;
1204c8945a0SNathan Whitehorn     char *freeMe = 0;
1214c8945a0SNathan Whitehorn 
1224c8945a0SNathan Whitehorn     bm -= (2 * MARGIN);
1234c8945a0SNathan Whitehorn     getyx(win, last_y, last_x);
1244c8945a0SNathan Whitehorn     for (item = 0; item < dlg->item_no; ++item) {
125*a96ef450SBaptiste Daroussin 	const char *status = "";
1264c8945a0SNathan Whitehorn 	chtype attr = A_NORMAL;
127*a96ef450SBaptiste Daroussin 	int y = item + MARGIN + 1;
1284c8945a0SNathan Whitehorn 
1294c8945a0SNathan Whitehorn 	if (y > bm)
1304c8945a0SNathan Whitehorn 	    break;
1314c8945a0SNathan Whitehorn 
1324c8945a0SNathan Whitehorn 	status = status_string(dlg->list[item].text, &freeMe);
133*a96ef450SBaptiste Daroussin 	if (status == 0 || *status == 0) {
134*a96ef450SBaptiste Daroussin 	    free(freeMe);
1354c8945a0SNathan Whitehorn 	    continue;
136*a96ef450SBaptiste Daroussin 	}
1374c8945a0SNathan Whitehorn 
1384c8945a0SNathan Whitehorn 	(void) wmove(win, y, 2 * MARGIN);
139f4f33ea0SBaptiste Daroussin 	dlg_attrset(win, dialog_attr);
1404c8945a0SNathan Whitehorn 	dlg_print_text(win, dlg->list[item].name, lm, &attr);
1414c8945a0SNathan Whitehorn 
1424c8945a0SNathan Whitehorn 	(void) wmove(win, y, lm);
1434c8945a0SNathan Whitehorn 	(void) waddch(win, '[');
1444c8945a0SNathan Whitehorn 	(void) wmove(win, y, lm + (cells - (int) strlen(status)) / 2);
1454c8945a0SNathan Whitehorn 	if (freeMe) {
1464c8945a0SNathan Whitehorn 	    (void) wmove(win, y, lm + 1);
147f4f33ea0SBaptiste Daroussin 	    dlg_attrset(win, title_attr);
1484c8945a0SNathan Whitehorn 	    for (j = 0; j < cells; j++)
1494c8945a0SNathan Whitehorn 		(void) waddch(win, ' ');
1504c8945a0SNathan Whitehorn 
1514c8945a0SNathan Whitehorn 	    (void) wmove(win, y, lm + (cells - (int) strlen(status)) / 2);
1524c8945a0SNathan Whitehorn 	    (void) waddstr(win, status);
1534c8945a0SNathan Whitehorn 
1544c8945a0SNathan Whitehorn 	    if ((title_attr & A_REVERSE) != 0) {
155f4f33ea0SBaptiste Daroussin 		dlg_attroff(win, A_REVERSE);
1564c8945a0SNathan Whitehorn 	    } else {
157f4f33ea0SBaptiste Daroussin 		dlg_attrset(win, A_REVERSE);
1584c8945a0SNathan Whitehorn 	    }
1594c8945a0SNathan Whitehorn 	    (void) wmove(win, y, lm + 1);
1604c8945a0SNathan Whitehorn 
1614c8945a0SNathan Whitehorn 	    if (sscanf(status, "%f%%", &percent) != 1)
1624c8945a0SNathan Whitehorn 		percent = 0.0;
1634c8945a0SNathan Whitehorn 	    xxx = (int) ((cells * (percent + 0.5)) / 100.0);
1644c8945a0SNathan Whitehorn 	    for (j = 0; j < xxx; j++) {
1654c8945a0SNathan Whitehorn 		chtype ch1 = winch(win);
1664c8945a0SNathan Whitehorn 		if (title_attr & A_REVERSE) {
1674c8945a0SNathan Whitehorn 		    ch1 &= ~A_REVERSE;
1684c8945a0SNathan Whitehorn 		}
1694c8945a0SNathan Whitehorn 		(void) waddch(win, ch1);
1704c8945a0SNathan Whitehorn 	    }
1714c8945a0SNathan Whitehorn 	    free(freeMe);
1724c8945a0SNathan Whitehorn 
1734c8945a0SNathan Whitehorn 	} else {
1744c8945a0SNathan Whitehorn 	    (void) wmove(win, y, lm + (cells - (int) strlen(status)) / 2);
1754c8945a0SNathan Whitehorn 	    (void) waddstr(win, status);
1764c8945a0SNathan Whitehorn 	}
1774c8945a0SNathan Whitehorn 	(void) wmove(win, y, limit_x - 3);
178f4f33ea0SBaptiste Daroussin 	dlg_attrset(win, dialog_attr);
1794c8945a0SNathan Whitehorn 	(void) waddch(win, ']');
1804c8945a0SNathan Whitehorn 	(void) wnoutrefresh(win);
1814c8945a0SNathan Whitehorn     }
1822a3e3873SBaptiste Daroussin     if (win != 0)
1832a3e3873SBaptiste Daroussin 	wmove(win, last_y, last_x);
1844c8945a0SNathan Whitehorn }
1854c8945a0SNathan Whitehorn 
1864c8945a0SNathan Whitehorn static void
mydraw_mixed_box(WINDOW * win,int y,int x,int height,int width,chtype boxchar,chtype borderchar)1874c8945a0SNathan Whitehorn mydraw_mixed_box(WINDOW *win, int y, int x, int height, int width,
1884c8945a0SNathan Whitehorn 		 chtype boxchar, chtype borderchar)
1894c8945a0SNathan Whitehorn {
1904c8945a0SNathan Whitehorn     dlg_draw_box(win, y, x, height, width, boxchar, borderchar);
1914c8945a0SNathan Whitehorn     {
1924c8945a0SNathan Whitehorn 	chtype attr = A_NORMAL;
1937a1c0d96SNathan Whitehorn 	const char *message = _("Overall Progress");
1947a1c0d96SNathan Whitehorn 	chtype save2 = dlg_get_attrs(win);
195f4f33ea0SBaptiste Daroussin 	dlg_attrset(win, title_attr);
1964c8945a0SNathan Whitehorn 	(void) wmove(win, y, x + 2);
1974c8945a0SNathan Whitehorn 	dlg_print_text(win, message, width, &attr);
198f4f33ea0SBaptiste Daroussin 	dlg_attrset(win, save2);
1994c8945a0SNathan Whitehorn     }
2004c8945a0SNathan Whitehorn }
2014c8945a0SNathan Whitehorn 
2024c8945a0SNathan Whitehorn static char *
clean_copy(const char * string)2034c8945a0SNathan Whitehorn clean_copy(const char *string)
2044c8945a0SNathan Whitehorn {
2054c8945a0SNathan Whitehorn     char *result = dlg_strclone(string);
2064c8945a0SNathan Whitehorn 
2074c8945a0SNathan Whitehorn     dlg_trim_string(result);
2084c8945a0SNathan Whitehorn     dlg_tab_correct_str(result);
2094c8945a0SNathan Whitehorn     return result;
2104c8945a0SNathan Whitehorn }
2114c8945a0SNathan Whitehorn 
2124c8945a0SNathan Whitehorn /*
2134c8945a0SNathan Whitehorn  * Update mixed-gauge dialog (may be from pipe, may be via direct calls).
2144c8945a0SNathan Whitehorn  */
2154c8945a0SNathan Whitehorn static void
dlg_update_mixedgauge(DIALOG_MIXEDGAUGE * dlg,int percent)2164c8945a0SNathan Whitehorn dlg_update_mixedgauge(DIALOG_MIXEDGAUGE * dlg, int percent)
2174c8945a0SNathan Whitehorn {
2184c8945a0SNathan Whitehorn     int i, x;
2194c8945a0SNathan Whitehorn 
2204c8945a0SNathan Whitehorn     /*
2214c8945a0SNathan Whitehorn      * Clear the area for the progress bar by filling it with spaces
2224c8945a0SNathan Whitehorn      * in the title-attribute, and write the percentage with that
2234c8945a0SNathan Whitehorn      * attribute.
2244c8945a0SNathan Whitehorn      */
2254c8945a0SNathan Whitehorn     (void) wmove(dlg->dialog, dlg->height - 3, 4);
226f4f33ea0SBaptiste Daroussin     dlg_attrset(dlg->dialog, gauge_attr);
2274c8945a0SNathan Whitehorn 
2284c8945a0SNathan Whitehorn     for (i = 0; i < (dlg->width - 2 * (3 + MARGIN)); i++)
2294c8945a0SNathan Whitehorn 	(void) waddch(dlg->dialog, ' ');
2304c8945a0SNathan Whitehorn 
2314c8945a0SNathan Whitehorn     (void) wmove(dlg->dialog, dlg->height - 3, (dlg->width / 2) - 2);
2324c8945a0SNathan Whitehorn     (void) wprintw(dlg->dialog, "%3d%%", percent);
2334c8945a0SNathan Whitehorn 
2344c8945a0SNathan Whitehorn     /*
2354c8945a0SNathan Whitehorn      * Now draw a bar in reverse, relative to the background.
2364c8945a0SNathan Whitehorn      * The window attribute was useful for painting the background,
2374c8945a0SNathan Whitehorn      * but requires some tweaks to reverse it.
2384c8945a0SNathan Whitehorn      */
2394c8945a0SNathan Whitehorn     x = (percent * (dlg->width - 2 * (3 + MARGIN))) / 100;
2404c8945a0SNathan Whitehorn     if ((title_attr & A_REVERSE) != 0) {
241f4f33ea0SBaptiste Daroussin 	dlg_attroff(dlg->dialog, A_REVERSE);
2424c8945a0SNathan Whitehorn     } else {
243f4f33ea0SBaptiste Daroussin 	dlg_attrset(dlg->dialog, A_REVERSE);
2444c8945a0SNathan Whitehorn     }
2454c8945a0SNathan Whitehorn     (void) wmove(dlg->dialog, dlg->height - 3, 4);
2464c8945a0SNathan Whitehorn     for (i = 0; i < x; i++) {
2474c8945a0SNathan Whitehorn 	chtype ch = winch(dlg->dialog);
2484c8945a0SNathan Whitehorn 	if (title_attr & A_REVERSE) {
2494c8945a0SNathan Whitehorn 	    ch &= ~A_REVERSE;
2504c8945a0SNathan Whitehorn 	}
2514c8945a0SNathan Whitehorn 	(void) waddch(dlg->dialog, ch);
2524c8945a0SNathan Whitehorn     }
2534c8945a0SNathan Whitehorn     myprint_status(dlg);
2542a3e3873SBaptiste Daroussin     dlg_trace_win(dlg->dialog);
2554c8945a0SNathan Whitehorn }
2564c8945a0SNathan Whitehorn 
2574c8945a0SNathan Whitehorn /*
2584c8945a0SNathan Whitehorn  * Setup dialog.
2594c8945a0SNathan Whitehorn  */
2604c8945a0SNathan Whitehorn static void
dlg_begin_mixedgauge(DIALOG_MIXEDGAUGE * dlg,int * began,const char * aTitle,const char * aPrompt,int aHeight,int aWidth,int aItemNo,char ** items)2614c8945a0SNathan Whitehorn dlg_begin_mixedgauge(DIALOG_MIXEDGAUGE * dlg,
2624c8945a0SNathan Whitehorn 		     int *began,
2634c8945a0SNathan Whitehorn 		     const char *aTitle,
2644c8945a0SNathan Whitehorn 		     const char *aPrompt,
2654c8945a0SNathan Whitehorn 		     int aHeight,
2664c8945a0SNathan Whitehorn 		     int aWidth,
2674c8945a0SNathan Whitehorn 		     int aItemNo,
2684c8945a0SNathan Whitehorn 		     char **items)
2694c8945a0SNathan Whitehorn {
270*a96ef450SBaptiste Daroussin     int y, x;
2714c8945a0SNathan Whitehorn 
2724c8945a0SNathan Whitehorn     if (!*began) {
273*a96ef450SBaptiste Daroussin 	int n;
274*a96ef450SBaptiste Daroussin 
2754c8945a0SNathan Whitehorn 	curs_set(0);
2764c8945a0SNathan Whitehorn 
2774c8945a0SNathan Whitehorn 	memset(dlg, 0, sizeof(*dlg));
2784c8945a0SNathan Whitehorn 	dlg->title = aTitle;
2794c8945a0SNathan Whitehorn 	dlg->prompt = clean_copy(aPrompt);
2804c8945a0SNathan Whitehorn 	dlg->height = dlg->old_height = aHeight;
2814c8945a0SNathan Whitehorn 	dlg->width = dlg->old_width = aWidth;
2824c8945a0SNathan Whitehorn 	dlg->item_no = aItemNo;
2834c8945a0SNathan Whitehorn 
2844c8945a0SNathan Whitehorn 	dlg->list = dlg_calloc(DIALOG_LISTITEM, (size_t) aItemNo);
2854c8945a0SNathan Whitehorn 	assert_ptr(dlg->list, "dialog_mixedgauge");
2864c8945a0SNathan Whitehorn 
2874c8945a0SNathan Whitehorn 	dlg->len_name = 0;
2884c8945a0SNathan Whitehorn 	dlg->len_text = 15;
2894c8945a0SNathan Whitehorn 
2904c8945a0SNathan Whitehorn 	for (n = 0; n < aItemNo; ++n) {
2914c8945a0SNathan Whitehorn 	    int thisWidth = (int) strlen(ItemName(n));
2924c8945a0SNathan Whitehorn 	    if (dlg->len_name < thisWidth)
2934c8945a0SNathan Whitehorn 		dlg->len_name = thisWidth;
2944c8945a0SNathan Whitehorn 	    dlg->list[n].name = ItemName(n);
2954c8945a0SNathan Whitehorn 	    dlg->list[n].text = ItemText(n);
2964c8945a0SNathan Whitehorn 	}
2974c8945a0SNathan Whitehorn 
2984c8945a0SNathan Whitehorn 	dlg->min_height = MIN_HIGH + aItemNo;
2994c8945a0SNathan Whitehorn 	dlg->min_width = MIN_WIDE + dlg->len_name + GUTTER + dlg->len_text;
3004c8945a0SNathan Whitehorn 
3014c8945a0SNathan Whitehorn 	if (dlg->prompt != 0 && *(dlg->prompt) != 0)
3024c8945a0SNathan Whitehorn 	    dlg->min_height += (2 * MARGIN);
3034c8945a0SNathan Whitehorn #ifdef KEY_RESIZE
3044c8945a0SNathan Whitehorn 	nodelay(stdscr, TRUE);
3054c8945a0SNathan Whitehorn #endif
3064c8945a0SNathan Whitehorn     }
3074c8945a0SNathan Whitehorn #ifdef KEY_RESIZE
3084c8945a0SNathan Whitehorn     else {
3094c8945a0SNathan Whitehorn 	dlg_del_window(dlg->dialog);
3104c8945a0SNathan Whitehorn 	dlg->height = dlg->old_height;
3114c8945a0SNathan Whitehorn 	dlg->width = dlg->old_width;
3124c8945a0SNathan Whitehorn     }
3134c8945a0SNathan Whitehorn #endif
3144c8945a0SNathan Whitehorn 
3154c8945a0SNathan Whitehorn     dlg_auto_size(dlg->title, dlg->prompt,
3164c8945a0SNathan Whitehorn 		  &(dlg->height),
3174c8945a0SNathan Whitehorn 		  &(dlg->width),
3184c8945a0SNathan Whitehorn 		  dlg->min_height,
3194c8945a0SNathan Whitehorn 		  dlg->min_width);
3204c8945a0SNathan Whitehorn     dlg_print_size(dlg->height, dlg->width);
3214c8945a0SNathan Whitehorn     dlg_ctl_size(dlg->height, dlg->width);
3224c8945a0SNathan Whitehorn 
3234c8945a0SNathan Whitehorn     /* center dialog box on screen */
3244c8945a0SNathan Whitehorn     x = dlg_box_x_ordinate(dlg->width);
3254c8945a0SNathan Whitehorn     y = dlg_box_y_ordinate(dlg->height);
3264c8945a0SNathan Whitehorn 
3274c8945a0SNathan Whitehorn     dlg->dialog = dlg_new_window(dlg->height, dlg->width, y, x);
3284c8945a0SNathan Whitehorn 
3294c8945a0SNathan Whitehorn     (void) werase(dlg->dialog);
3302a3e3873SBaptiste Daroussin     dlg_draw_box2(dlg->dialog,
3314c8945a0SNathan Whitehorn 		  0, 0,
3324c8945a0SNathan Whitehorn 		  dlg->height,
3334c8945a0SNathan Whitehorn 		  dlg->width,
3342a3e3873SBaptiste Daroussin 		  dialog_attr, border_attr, border2_attr);
3354c8945a0SNathan Whitehorn 
3364c8945a0SNathan Whitehorn     dlg_draw_title(dlg->dialog, dlg->title);
337682c9e0fSNathan Whitehorn     dlg_draw_helpline(dlg->dialog, FALSE);
3384c8945a0SNathan Whitehorn 
3394c8945a0SNathan Whitehorn     if ((dlg->prompt != 0 && *(dlg->prompt) != 0)
3404c8945a0SNathan Whitehorn 	&& wmove(dlg->dialog, dlg->item_no, 0) != ERR) {
3414c8945a0SNathan Whitehorn 	dlg->caption = dlg_sub_window(dlg->dialog,
3424c8945a0SNathan Whitehorn 				      dlg->height - dlg->item_no - (2 * MARGIN),
3434c8945a0SNathan Whitehorn 				      dlg->width,
3444c8945a0SNathan Whitehorn 				      y + dlg->item_no + (2 * MARGIN),
3454c8945a0SNathan Whitehorn 				      x);
346f4f33ea0SBaptiste Daroussin 	dlg_attrset(dlg->caption, dialog_attr);
3474c8945a0SNathan Whitehorn 	dlg_print_autowrap(dlg->caption, dlg->prompt, dlg->height, dlg->width);
3484c8945a0SNathan Whitehorn     }
3494c8945a0SNathan Whitehorn 
3504c8945a0SNathan Whitehorn     mydraw_mixed_box(dlg->dialog,
3514c8945a0SNathan Whitehorn 		     dlg->height - 4,
3524c8945a0SNathan Whitehorn 		     2 + MARGIN,
3534c8945a0SNathan Whitehorn 		     2 + MARGIN,
3544c8945a0SNathan Whitehorn 		     dlg->width - 2 * (2 + MARGIN),
3554c8945a0SNathan Whitehorn 		     dialog_attr,
3564c8945a0SNathan Whitehorn 		     border_attr);
3574c8945a0SNathan Whitehorn 
3584c8945a0SNathan Whitehorn     *began += 1;
3594c8945a0SNathan Whitehorn }
3604c8945a0SNathan Whitehorn 
3614c8945a0SNathan Whitehorn /*
3624c8945a0SNathan Whitehorn  * Discard the mixed-gauge dialog.
3634c8945a0SNathan Whitehorn  */
3644c8945a0SNathan Whitehorn static int
dlg_finish_mixedgauge(DIALOG_MIXEDGAUGE * dlg,int status)3654c8945a0SNathan Whitehorn dlg_finish_mixedgauge(DIALOG_MIXEDGAUGE * dlg, int status)
3664c8945a0SNathan Whitehorn {
3674c8945a0SNathan Whitehorn     (void) wrefresh(dlg->dialog);
3684c8945a0SNathan Whitehorn #ifdef KEY_RESIZE
3694c8945a0SNathan Whitehorn     nodelay(stdscr, FALSE);
3704c8945a0SNathan Whitehorn #endif
3714c8945a0SNathan Whitehorn     curs_set(1);
3724c8945a0SNathan Whitehorn     dlg_del_window(dlg->dialog);
373*a96ef450SBaptiste Daroussin     free(dlg->prompt);
374*a96ef450SBaptiste Daroussin     free(dlg->list);
3754c8945a0SNathan Whitehorn     return status;
3764c8945a0SNathan Whitehorn }
3774c8945a0SNathan Whitehorn 
3784c8945a0SNathan Whitehorn /*
3794c8945a0SNathan Whitehorn  * Setup dialog, read mixed-gauge data from pipe.
3804c8945a0SNathan Whitehorn  */
3814c8945a0SNathan Whitehorn int
dialog_mixedgauge(const char * title,const char * cprompt,int height,int width,int percent,int item_no,char ** items)3824c8945a0SNathan Whitehorn dialog_mixedgauge(const char *title,
3834c8945a0SNathan Whitehorn 		  const char *cprompt,
3844c8945a0SNathan Whitehorn 		  int height,
3854c8945a0SNathan Whitehorn 		  int width,
3864c8945a0SNathan Whitehorn 		  int percent,
3874c8945a0SNathan Whitehorn 		  int item_no,
3884c8945a0SNathan Whitehorn 		  char **items)
3894c8945a0SNathan Whitehorn {
3904c8945a0SNathan Whitehorn     DIALOG_MIXEDGAUGE dlg;
3914c8945a0SNathan Whitehorn     int began = 0;
3924c8945a0SNathan Whitehorn 
393f4f33ea0SBaptiste Daroussin     DLG_TRACE(("# mixedgauge args:\n"));
394f4f33ea0SBaptiste Daroussin     DLG_TRACE2S("title", title);
395f4f33ea0SBaptiste Daroussin     DLG_TRACE2S("message", cprompt);
396f4f33ea0SBaptiste Daroussin     DLG_TRACE2N("height", height);
397f4f33ea0SBaptiste Daroussin     DLG_TRACE2N("width", width);
398f4f33ea0SBaptiste Daroussin     DLG_TRACE2N("percent", percent);
399f4f33ea0SBaptiste Daroussin     DLG_TRACE2N("llength", item_no);
400f4f33ea0SBaptiste Daroussin     /* FIXME dump the items[][] too */
401f4f33ea0SBaptiste Daroussin 
4024c8945a0SNathan Whitehorn     dlg_begin_mixedgauge(&dlg, &began, title, cprompt, height,
4034c8945a0SNathan Whitehorn 			 width, item_no, items);
4044c8945a0SNathan Whitehorn 
4054c8945a0SNathan Whitehorn     dlg_update_mixedgauge(&dlg, percent);
4064c8945a0SNathan Whitehorn 
4074c8945a0SNathan Whitehorn     return dlg_finish_mixedgauge(&dlg, DLG_EXIT_OK);
4084c8945a0SNathan Whitehorn }
409