Exemplo n.º 1
0
/*
 * Display a dialog box with a list of options that can be turned on or off
 * The `flag' parameter is used to select between radiolist and checklist.
 */
int
dialog_checklist(const char *title,
		 const char *cprompt,
		 int height,
		 int width,
		 int list_height,
		 int item_no,
		 char **items,
		 int flag)
{
    int result;
    int i;
    DIALOG_LISTITEM *listitems;
    bool separate_output = ((flag == FLAG_CHECK)
			    && (dialog_vars.separate_output));
    bool show_status = FALSE;
    int current = 0;

    listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1);
    assert_ptr(listitems, "dialog_checklist");

    for (i = 0; i < item_no; ++i) {
	listitems[i].name = ItemName(i);
	listitems[i].text = ItemText(i);
	listitems[i].help = ((dialog_vars.item_help)
			     ? ItemHelp(i)
			     : dlg_strempty());
	listitems[i].state = !dlg_strcmp(ItemStatus(i), "on");
    }
    dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);

    result = dlg_checklist(title,
			   cprompt,
			   height,
			   width,
			   list_height,
			   item_no,
			   listitems,
			   NULL,
			   flag,
			   &current);

    switch (result) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
	show_status = TRUE;
	break;
    case DLG_EXIT_HELP:
	dlg_add_result("HELP ");
	show_status = dialog_vars.help_status;
	if (USE_ITEM_HELP(listitems[current].help)) {
	    if (show_status) {
		if (separate_output) {
		    dlg_add_string(listitems[current].help);
		    dlg_add_separator();
		} else {
		    dlg_add_quoted(listitems[current].help);
		}
	    } else {
		dlg_add_string(listitems[current].help);
	    }
	    result = DLG_EXIT_ITEM_HELP;
	} else {
	    if (show_status) {
		if (separate_output) {
		    dlg_add_string(listitems[current].name);
		    dlg_add_separator();
		} else {
		    dlg_add_quoted(listitems[current].name);
		}
	    } else {
		dlg_add_string(listitems[current].name);
	    }
	}
	break;
    }

    if (show_status) {
	for (i = 0; i < item_no; i++) {
	    if (listitems[i].state) {
		if (separate_output) {
		    dlg_add_string(listitems[i].name);
		    dlg_add_separator();
		} else {
		    if (dlg_need_separator())
			dlg_add_separator();
		    dlg_add_string(listitems[i].name);
		}
	    }
	}
    }

    dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
    free(listitems);
    return result;
}
Exemplo n.º 2
0
/*
 * Display a dialog box with a list of options that can be turned on or off
 * The `flag' parameter is used to select between radiolist and checklist.
 */
int
dialog_checklist(const char *title,
		 const char *cprompt,
		 int height,
		 int width,
		 int list_height,
		 int item_no,
		 char **items,
		 int flag)
{
    int result;
    int i, j;
    DIALOG_LISTITEM *listitems;
    bool separate_output = ((flag == FLAG_CHECK)
			    && (dialog_vars.separate_output));
    bool show_status = FALSE;
    int current = 0;
    char *help_result;

    listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1);
    assert_ptr(listitems, "dialog_checklist");

    for (i = j = 0; i < item_no; ++i) {
	listitems[i].name = items[j++];
	listitems[i].text = (dialog_vars.no_items
			     ? dlg_strempty()
			     : items[j++]);
	listitems[i].state = !dlg_strcmp(items[j++], "on");
	listitems[i].help = ((dialog_vars.item_help)
			     ? items[j++]
			     : dlg_strempty());
    }
    dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);

    result = dlg_checklist(title,
			   cprompt,
			   height,
			   width,
			   list_height,
			   item_no,
			   listitems,
			   NULL,
			   flag,
			   &current);

    switch (result) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
	show_status = TRUE;
	break;
    case DLG_EXIT_HELP:
	dlg_add_help_listitem(&result, &help_result, &listitems[current]);
	if ((show_status = dialog_vars.help_status)) {
	    if (separate_output) {
		dlg_add_string(help_result);
		dlg_add_separator();
	    } else {
		dlg_add_quoted(help_result);
	    }
	} else {
	    dlg_add_string(help_result);
	}
	break;
    }

    if (show_status) {
	for (i = 0; i < item_no; i++) {
	    if (listitems[i].state) {
		if (separate_output) {
		    dlg_add_string(listitems[i].name);
		    dlg_add_separator();
		} else {
		    if (dlg_need_separator())
			dlg_add_separator();
		    if (flag == FLAG_CHECK)
			dlg_add_quoted(listitems[i].name);
		    else
			dlg_add_string(listitems[i].name);
		}
	    }
	}
	dlg_add_last_key(separate_output);
    }

    dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
    free(listitems);
    return result;
}
Exemplo n.º 3
0
int
dialog_mixedform(const char *title,
                 const char *cprompt,
                 int height,
                 int width,
                 int form_height,
                 int item_no,
                 char **items)
{
    int result;
    int choice;
    int i;
    DIALOG_FORMITEM *listitems;
    DIALOG_VARS save_vars;
    bool show_status = FALSE;

    dlg_save_vars(&save_vars);
    dialog_vars.separate_output = TRUE;

    listitems = dlg_calloc(DIALOG_FORMITEM, (size_t) item_no + 1);
    assert_ptr(listitems, "dialog_mixedform");

    for (i = 0; i < item_no; ++i) {
        listitems[i].type = dialog_vars.formitem_type;
        listitems[i].name = ItemName(i);
        listitems[i].name_len = (int) strlen(ItemName(i));
        listitems[i].name_y = dlg_ordinate(ItemNameY(i));
        listitems[i].name_x = dlg_ordinate(ItemNameX(i));
        listitems[i].text = ItemText(i);
        listitems[i].text_len = (int) strlen(ItemText(i));
        listitems[i].text_y = dlg_ordinate(ItemTextY(i));
        listitems[i].text_x = dlg_ordinate(ItemTextX(i));
        listitems[i].text_flen = atoi(ItemTextFLen(i));
        listitems[i].text_ilen = atoi(ItemTextILen(i));
        listitems[i].help = (dialog_vars.item_help ? ItemHelp(i) :
                             dlg_strempty());
        listitems[i].type = (unsigned) atoi(ItemTypep(i));
    }

    result = dlg_form(title,
                      cprompt,
                      height,
                      width,
                      form_height,
                      item_no,
                      listitems,
                      &choice);

    switch (result) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
        show_status = TRUE;
        break;
    case DLG_EXIT_HELP:
        dlg_add_result("HELP ");
        show_status = dialog_vars.help_status;
        if (USE_ITEM_HELP(listitems[choice].help)) {
            dlg_add_string(listitems[choice].help);
            result = DLG_EXIT_ITEM_HELP;
        } else {
            dlg_add_string(listitems[choice].name);
        }
        if (show_status)
            dlg_add_separator();
        break;
    }
    if (show_status) {
        for (i = 0; i < item_no; i++) {
            if (listitems[i].text_flen > 0) {
                dlg_add_string(listitems[i].text);
                dlg_add_separator();
            }
        }
        dlg_add_last_key(-1);
    }

    dlg_free_formitems(listitems);
    dlg_restore_vars(&save_vars);

    return result;
}