* Display a dialog box for inputing a string */
| 29 | * Display a dialog box for inputing a string |
| 30 | */ |
| 31 | int dialog_inputbox(const char *title, const char *prompt, int height, int width, |
| 32 | const char *init) |
| 33 | { |
| 34 | int i, x, y, box_y, box_x, box_width; |
| 35 | int input_x = 0, key = 0, button = -1; |
| 36 | int show_x, len, pos; |
| 37 | char *instr = dialog_input_result; |
| 38 | WINDOW *dialog; |
| 39 | |
| 40 | if (!init) |
| 41 | instr[0] = '\0'; |
| 42 | else |
| 43 | strcpy(instr, init); |
| 44 | |
| 45 | do_resize: |
| 46 | if (getmaxy(stdscr) <= (height - INPUTBOX_HEIGTH_MIN)) |
| 47 | return -ERRDISPLAYTOOSMALL; |
| 48 | if (getmaxx(stdscr) <= (width - INPUTBOX_WIDTH_MIN)) |
| 49 | return -ERRDISPLAYTOOSMALL; |
| 50 | |
| 51 | /* center dialog box on screen */ |
| 52 | x = (getmaxx(stdscr) - width) / 2; |
| 53 | y = (getmaxy(stdscr) - height) / 2; |
| 54 | |
| 55 | draw_shadow(stdscr, y, x, height, width); |
| 56 | |
| 57 | dialog = newwin(height, width, y, x); |
| 58 | keypad(dialog, TRUE); |
| 59 | |
| 60 | draw_box(dialog, 0, 0, height, width, |
| 61 | dlg.dialog.atr, dlg.border.atr); |
| 62 | wattrset(dialog, dlg.border.atr); |
| 63 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); |
| 64 | for (i = 0; i < width - 2; i++) |
| 65 | waddch(dialog, ACS_HLINE); |
| 66 | wattrset(dialog, dlg.dialog.atr); |
| 67 | waddch(dialog, ACS_RTEE); |
| 68 | |
| 69 | print_title(dialog, title, width); |
| 70 | |
| 71 | wattrset(dialog, dlg.dialog.atr); |
| 72 | print_autowrap(dialog, prompt, width - 2, 1, 3); |
| 73 | |
| 74 | /* Draw the input field box */ |
| 75 | box_width = width - 6; |
| 76 | getyx(dialog, y, x); |
| 77 | box_y = y + 2; |
| 78 | box_x = (width - box_width) / 2; |
| 79 | draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, |
| 80 | dlg.dialog.atr, dlg.border.atr); |
| 81 | |
| 82 | print_buttons(dialog, height, width, 0); |
| 83 | |
| 84 | /* Set up the initial value */ |
| 85 | wmove(dialog, box_y, box_x); |
| 86 | wattrset(dialog, dlg.inputbox.atr); |
| 87 | |
| 88 | len = strlen(instr); |
nothing calls this directly
no test coverage detected