* Display a dialog box with a list of options that can be turned on or off * in the style of radiolist (only one option turned on at a time). */
| 102 | * in the style of radiolist (only one option turned on at a time). |
| 103 | */ |
| 104 | int dialog_checklist(const char *title, const char *prompt, int height, |
| 105 | int width, int list_height) |
| 106 | { |
| 107 | int i, x, y, box_x, box_y; |
| 108 | int key = 0, button = 0, choice = 0, scroll = 0, max_choice; |
| 109 | WINDOW *dialog, *list; |
| 110 | |
| 111 | /* which item to highlight */ |
| 112 | item_foreach() { |
| 113 | if (item_is_tag('X')) |
| 114 | choice = item_n(); |
| 115 | if (item_is_selected()) { |
| 116 | choice = item_n(); |
| 117 | break; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | do_resize: |
| 122 | if (getmaxy(stdscr) < (height + CHECKLIST_HEIGTH_MIN)) |
| 123 | return -ERRDISPLAYTOOSMALL; |
| 124 | if (getmaxx(stdscr) < (width + CHECKLIST_WIDTH_MIN)) |
| 125 | return -ERRDISPLAYTOOSMALL; |
| 126 | |
| 127 | max_choice = MIN(list_height, item_count()); |
| 128 | |
| 129 | /* center dialog box on screen */ |
| 130 | x = (getmaxx(stdscr) - width) / 2; |
| 131 | y = (getmaxy(stdscr) - height) / 2; |
| 132 | |
| 133 | draw_shadow(stdscr, y, x, height, width); |
| 134 | |
| 135 | dialog = newwin(height, width, y, x); |
| 136 | keypad(dialog, TRUE); |
| 137 | |
| 138 | draw_box(dialog, 0, 0, height, width, |
| 139 | dlg.dialog.atr, dlg.border.atr); |
| 140 | wattrset(dialog, dlg.border.atr); |
| 141 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); |
| 142 | for (i = 0; i < width - 2; i++) |
| 143 | waddch(dialog, ACS_HLINE); |
| 144 | wattrset(dialog, dlg.dialog.atr); |
| 145 | waddch(dialog, ACS_RTEE); |
| 146 | |
| 147 | print_title(dialog, title, width); |
| 148 | |
| 149 | wattrset(dialog, dlg.dialog.atr); |
| 150 | print_autowrap(dialog, prompt, width - 2, 1, 3); |
| 151 | |
| 152 | list_width = width - 6; |
| 153 | box_y = height - list_height - 5; |
| 154 | box_x = (width - list_width) / 2 - 1; |
| 155 | |
| 156 | /* create new window for the list */ |
| 157 | list = subwin(dialog, list_height, list_width, y + box_y + 1, |
| 158 | x + box_x + 1); |
| 159 | |
| 160 | keypad(list, TRUE); |
| 161 |
no test coverage detected