* Display a menu for choosing among a number of options */
| 161 | * Display a menu for choosing among a number of options |
| 162 | */ |
| 163 | int dialog_menu(const char *title, const char *prompt, |
| 164 | const void *selected, int *s_scroll) |
| 165 | { |
| 166 | int i, j, x, y, box_x, box_y; |
| 167 | int height, width, menu_height; |
| 168 | int key = 0, button = 0, scroll = 0, choice = 0; |
| 169 | int first_item = 0, max_choice; |
| 170 | WINDOW *dialog, *menu; |
| 171 | |
| 172 | do_resize: |
| 173 | height = getmaxy(stdscr); |
| 174 | width = getmaxx(stdscr); |
| 175 | if (height < MENUBOX_HEIGTH_MIN || width < MENUBOX_WIDTH_MIN) |
| 176 | return -ERRDISPLAYTOOSMALL; |
| 177 | |
| 178 | height -= 4; |
| 179 | width -= 5; |
| 180 | menu_height = height - 10; |
| 181 | |
| 182 | max_choice = MIN(menu_height, item_count()); |
| 183 | |
| 184 | /* center dialog box on screen */ |
| 185 | x = (getmaxx(stdscr) - width) / 2; |
| 186 | y = (getmaxy(stdscr) - height) / 2; |
| 187 | |
| 188 | draw_shadow(stdscr, y, x, height, width); |
| 189 | |
| 190 | dialog = newwin(height, width, y, x); |
| 191 | keypad(dialog, TRUE); |
| 192 | |
| 193 | draw_box(dialog, 0, 0, height, width, |
| 194 | dlg.dialog.atr, dlg.border.atr); |
| 195 | wattrset(dialog, dlg.border.atr); |
| 196 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); |
| 197 | for (i = 0; i < width - 2; i++) |
| 198 | waddch(dialog, ACS_HLINE); |
| 199 | wattrset(dialog, dlg.dialog.atr); |
| 200 | wbkgdset(dialog, dlg.dialog.atr & A_COLOR); |
| 201 | waddch(dialog, ACS_RTEE); |
| 202 | |
| 203 | print_title(dialog, title, width); |
| 204 | |
| 205 | wattrset(dialog, dlg.dialog.atr); |
| 206 | print_autowrap(dialog, prompt, width - 2, 1, 3); |
| 207 | |
| 208 | menu_width = width - 6; |
| 209 | box_y = height - menu_height - 5; |
| 210 | box_x = (width - menu_width) / 2 - 1; |
| 211 | |
| 212 | /* create new window for the menu */ |
| 213 | menu = subwin(dialog, menu_height, menu_width, |
| 214 | y + box_y + 1, x + box_x + 1); |
| 215 | keypad(menu, TRUE); |
| 216 | |
| 217 | /* draw a box around the menu items */ |
| 218 | draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, |
| 219 | dlg.menubox_border.atr, dlg.menubox.atr); |
| 220 |
no test coverage detected