static void conf_choice(struct menu *menu) { const char *prompt = menu_get_prompt(menu); struct menu *child; struct symbol *active; while (1) { current_menu = menu; active = sym_get_choice_value(menu->sym); cdone(); cinit(); for (child = menu->list; child; child = child->next) { if (!menu_is_visible(child)) continue; cmake(); cprint_tag("%p", child); cprint_name("%s", menu_get_prompt(child)); items[item_no - 1]->selected = (child->sym == active); } switch (dialog_checklist(prompt ? prompt : "Main Menu", radiolist_instructions, 15, 70, 6, item_no, items, FLAG_RADIO)) { case 0: if (sscanf(first_sel_item(item_no, items)->tag, "%p", &menu) != 1) break; sym_set_tristate_value(menu->sym, yes); return; case 1: show_help(menu); break; case 255: return; } } }
static void conf_choice(struct menu *menu) { const char *prompt = _(menu_get_prompt(menu)); struct menu *child; struct symbol *active; active = sym_get_choice_value(menu->sym); while (1) { int res; int selected; item_reset(); current_menu = menu; for (child = menu->list; child; child = child->next) { if (!menu_is_visible(child)) continue; if (child->sym) item_make("%s", _(menu_get_prompt(child))); else { item_make("*** %s ***", _(menu_get_prompt(child))); item_set_tag(':'); } item_set_data(child); if (child->sym == active) item_set_selected(1); if (child->sym == sym_get_choice_value(menu->sym)) item_set_tag('X'); } dialog_clear(); res = dialog_checklist(prompt ? _(prompt) : _("Main Menu"), _(radiolist_instructions), 15, 70, 6); selected = item_activate_selected(); switch (res) { case 0: if (selected) { child = item_data(); if (!child->sym) break; sym_set_tristate_value(child->sym, yes); } return; case 1: if (selected) { child = item_data(); show_help(child); active = child->sym; } else show_help(menu); break; case KEY_ESC: return; case -ERRDISPLAYTOOSMALL: return; } } }
static int j_radiolist(JUMPARGS) { int tags = howmany_tags(av + 5, CHECKBOX_TAGS); *offset_add = 5 + tags * CHECKBOX_TAGS; return dialog_checklist(t, av[1], numeric_arg(av, 2), numeric_arg(av, 3), numeric_arg(av, 4), tags, av + 5, FLAG_RADIO, dialog_vars.separate_output); }
/* Traverse over an internal menu */ Boolean dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons) { int n, rval = 0; dialogMenuItem *items; items = menu->items; if (buttons) items += 2; /* Count up all the items */ for (n = 0; items[n].title; n++); while (1) { char buf[FILENAME_MAX]; WINDOW *w = savescr(); /* Any helpful hints, put 'em up! */ use_helpline(menu->helpline); use_helpfile(systemHelpFile(menu->helpfile, buf)); dialog_clear_norefresh(); /* Pop up that dialog! */ if (menu->type & DMENU_NORMAL_TYPE) rval = dialog_menu((u_char *)menu->title, (u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n, items, (char *)(uintptr_t)buttons, choice, scroll); else if (menu->type & DMENU_RADIO_TYPE) rval = dialog_radiolist((u_char *)menu->title, (u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n, items, (char *)(uintptr_t)buttons); else if (menu->type & DMENU_CHECKLIST_TYPE) rval = dialog_checklist((u_char *)menu->title, (u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n, items, (char *)(uintptr_t)buttons); else msgFatal("Menu: `%s' is of an unknown type\n", menu->title); if (exited) { exited = FALSE; restorescr(w); return TRUE; } else if (rval) { restorescr(w); return FALSE; } else if (menu->type & DMENU_SELECTION_RETURNS) { restorescr(w); return TRUE; } } }
/* Kick it off, James! */ int main(int argc, char **argv) { int retval; init_dialog(); retval = dialog_checklist("this is dialog_checklist() in action, test #2", "Same as before, but now we relabel the buttons and override the OK action.", -1, -1, 4, -4, menu3 + 2, (char *)TRUE); dialog_clear(); fprintf(stderr, "returned value for dialog_checklist was %d\n", retval); end_dialog(); return 0; }
/* Kick it off, James! */ int main(int argc, char **argv) { int retval; init_dialog(); retval = dialog_checklist("this is dialog_checklist() in action, test #3", "Now we show off some of the button 'styles' one can create.", -1, -1, 7, -7, menu4, NULL); dialog_clear(); fprintf(stderr, "spent $%d on %s%s%s books\n", spending, german_book ? " german" : "", italian_book ? " italian" : "", slang_book ? " slang" : ""); end_dialog(); return 0; }
void /* ANSI C can bite me */ main() { int rc; char result[20]; int sc=0, ch=0; extern int LINES, COLS; init_dialog(); while (1) { rc = dialog_menu(0, "Choose a dialog function to test", LINES-2, COLS-2, NRCHOICES, NRCHOICES, choices, result, &sc, &ch); if (rc != 0) break; if (strstr(result, "menu")) { int sc2=0, ch2=0; rc = dialog_menu("menu", "menu box", -1, -1, 4, 7, menu, result, &sc2, &ch2); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); sc2=0, ch2=0; rc = dialog_menu("menu", "menu box\nnumber 2", 13, 35, 4, 7, menu, result, &sc2, &ch2); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result,"check")) { rc = dialog_checklist("checklist", "checklist box", -1, -1, 4, 7, checklist, result); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result,"radio")) { rc = dialog_radiolist("radiolist", "radiolist box", -1, -1, 4, 7, checklist, result); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result, "notify")) dialog_notify("A Notification box"); else if (strstr(result, "msg")) { dialog_msgbox("msgbox", "Sleeping 2 seconds on a\n" "msg box without user input", -1, -1, 0); sleep(1); dialog_msgbox("msgbox", "Sleeping 1 second on a\n" "msg box without user input", -1, -1, 0); sleep(1); dialog_msgbox("msgbox", "A msg box that wants user input", -1, -1, 1); } else if (strstr(result, "mesg")) dialog_mesgbox("mesgbox", "A mesg box", -1, -1); else if (strstr(result, "yesno")) { rc = dialog_yesno("yesno", "Test me\nPress YES or NO", -1, -1); if (rc == 0) dialog_notify("You pressed YES"); else if (rc > 0) dialog_notify("You pressed NO"); else dialog_notify("Something Wicked Happened!"); } else if (strstr(result, "gauge")) { int x; for (x=0; x<=20; x++) { dialog_gauge("test", "gauge", -1, -1, -1, 40, x*5); usleep(300000); } } } end_dialog(); exit((rc < 0) ? 1 : 0); }
int index_menu(PkgNodePtr root, PkgNodePtr top, PkgNodePtr plist, int *pos, int *scroll) { struct ListPtrs lists; size_t maxname; int n, rval; int curr, max; PkgNodePtr kp; dialogMenuItem *nitems; Boolean hasPackages; WINDOW *w; lists.root = root; lists.top = top; lists.plist = plist; hasPackages = FALSE; nitems = NULL; n = maxname = 0; /* Figure out if this menu is full of "leaves" or "branches" */ for (kp = top->kids; kp && kp->name; kp = kp->next) { size_t len; ++n; if (kp->type == PACKAGE && plist) { hasPackages = TRUE; if ((len = strlen(kp->name)) > maxname) maxname = len; } } if (!n && plist) { msgConfirm("The %s menu is empty.", top->name); return DITEM_LEAVE_MENU; } w = savescr(); while (1) { n = 0; curr = max = 0; use_helpline(NULL); use_helpfile(NULL); kp = top->kids; if (!hasPackages && plist) { nitems = item_add(nitems, "OK", NULL, NULL, NULL, NULL, NULL, NULL, &curr, &max); nitems = item_add(nitems, "Install", NULL, NULL, NULL, NULL, NULL, NULL, &curr, &max); } while (kp && kp->name) { char buf[256]; IndexEntryPtr ie = kp->data; /* Brutally adjust description to fit in menu */ if (kp->type == PACKAGE) snprintf(buf, sizeof buf, "[%s]", ie->path ? ie->path : "External vendor"); else SAFE_STRCPY(buf, kp->desc); if (strlen(buf) > (_MAX_DESC - maxname)) buf[_MAX_DESC - maxname] = '\0'; nitems = item_add(nitems, kp->name, buf, pkg_checked, pkg_fire, pkg_selected, kp, &lists, &curr, &max); ++n; kp = kp->next; } /* NULL delimiter so item_free() knows when to stop later */ nitems = item_add(nitems, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &curr, &max); recycle: dialog_clear_norefresh(); if (hasPackages) rval = dialog_checklist(top->name, top->desc, -1, -1, n > MAX_MENU ? MAX_MENU : n, -n, nitems, NULL); else rval = dialog_menu(top->name, top->desc, -1, -1, n > MAX_MENU ? MAX_MENU : n, -n, nitems + (plist ? 2 : 0), (char *)plist, pos, scroll); if (rval == -1 && plist) { static char *cp; PkgNodePtr menu; /* Search */ if ((cp = msgGetInput(cp, "Search by package name. Please enter search string:")) != NULL) { PkgNodePtr p = index_search(top, cp, &menu); if (p) { int pos, scroll; /* These need to be set to point at the found item, actually. Hmmm! */ pos = scroll = 0; index_menu(root, menu, plist, &pos, &scroll); } else msgConfirm("Search string: %s yielded no hits.", cp); } goto recycle; } items_free(nitems, &curr, &max); restorescr(w); return rval ? DITEM_FAILURE : DITEM_SUCCESS; } }