void dlg_draw_arrows(WINDOW *win, int top_arrow, int bottom_arrow, int x, int top, int bottom) { dlg_draw_helpline(win, TRUE); dlg_draw_arrows2(win, top_arrow, bottom_arrow, x, top, bottom, menubox_border2_attr, menubox_border_attr); }
/* * Display text from a file in a dialog box, like in a "tail -f". */ int dialog_tailbox(const char *title, const char *file, int height, int width, int bg_task) { /* *INDENT-OFF* */ static DLG_KEYS_BINDING binding[] = { HELPKEY_BINDINGS, ENTERKEY_BINDINGS, DLG_KEYS_DATA( DLGK_BEGIN, '0' ), DLG_KEYS_DATA( DLGK_BEGIN, KEY_BEG ), DLG_KEYS_DATA( DLGK_GRID_LEFT, 'H' ), DLG_KEYS_DATA( DLGK_GRID_LEFT, 'h' ), DLG_KEYS_DATA( DLGK_GRID_LEFT, KEY_LEFT ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'L' ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'l' ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, KEY_RIGHT ), END_KEYS_BINDING }; /* *INDENT-ON* */ #ifdef KEY_RESIZE int old_height = height; int old_width = width; #endif int fkey; int x, y, result, thigh; WINDOW *dialog, *text; const char **buttons = 0; MY_OBJ *obj; FILE *fd; int min_width = 12; /* Open input file for reading */ if ((fd = fopen(file, "rb")) == NULL) dlg_exiterr("Can't open input file in dialog_tailbox()."); #ifdef KEY_RESIZE retry: #endif dlg_auto_sizefile(title, file, &height, &width, 2, min_width); dlg_print_size(height, width); dlg_ctl_size(height, width); x = dlg_box_x_ordinate(width); y = dlg_box_y_ordinate(height); thigh = height - ((2 * MARGIN) + (bg_task ? 0 : 2)); dialog = dlg_new_window(height, width, y, x); dlg_mouse_setbase(x, y); /* Create window for text region, used for scrolling text */ text = dlg_sub_window(dialog, thigh, width - (2 * MARGIN), y + MARGIN, x + MARGIN); dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); dlg_draw_bottom_box(dialog); dlg_draw_title(dialog, title); dlg_draw_helpline(dialog, FALSE); if (!bg_task) { buttons = dlg_exit_label(); dlg_button_layout(buttons, &min_width); dlg_draw_buttons(dialog, height - (2 * MARGIN), 0, buttons, FALSE, FALSE, width); } (void) wmove(dialog, thigh, (MARGIN + 1)); (void) wnoutrefresh(dialog); obj = dlg_calloc(MY_OBJ, 1); assert_ptr(obj, "dialog_tailbox"); obj->obj.input = fd; obj->obj.win = dialog; obj->obj.handle_getc = handle_my_getc; obj->obj.handle_input = bg_task ? handle_input : 0; obj->obj.keep_bg = bg_task && dialog_vars.cant_kill; obj->obj.bg_task = bg_task; obj->text = text; obj->buttons = buttons; dlg_add_callback(&(obj->obj)); dlg_register_window(dialog, "tailbox", binding); dlg_register_buttons(dialog, "tailbox", buttons); /* Print last page of text */ dlg_attr_clear(text, thigh, getmaxx(text), dialog_attr); repaint_text(obj); if (bg_task) { result = DLG_EXIT_OK; } else { int ch; do { ch = dlg_getc(dialog, &fkey); #ifdef KEY_RESIZE if (fkey && ch == KEY_RESIZE) { /* reset data */ height = old_height; width = old_width; /* repaint */ dlg_clear(); dlg_del_window(dialog); refresh(); dlg_mouse_free_regions(); dlg_button_layout(buttons, &min_width); goto retry; } #endif } while (handle_my_getc(&(obj->obj), ch, fkey, &result)); } dlg_mouse_free_regions(); return result; }
void dlg_draw_scrollbar(WINDOW *win, long first_data, long this_data, long next_data, long total_data, int left, int right, int top, int bottom, chtype attr, chtype borderattr) { char buffer[80]; int percent; int len; int oldy, oldx; chtype save = dlg_get_attrs(win); int top_arrow = (first_data != 0); int bottom_arrow = (next_data < total_data); getyx(win, oldy, oldx); dlg_draw_helpline(win, TRUE); if (bottom_arrow || top_arrow || dialog_state.use_scrollbar) { percent = (!total_data ? 100 : (int) ((next_data * 100) / total_data)); if (percent < 0) percent = 0; else if (percent > 100) percent = 100; (void) wattrset(win, position_indicator_attr); (void) sprintf(buffer, "%d%%", percent); (void) wmove(win, bottom, right - 7); (void) waddstr(win, buffer); if ((len = dlg_count_columns(buffer)) < 4) { (void) wattrset(win, border_attr); whline(win, dlg_boxchar(ACS_HLINE), 4 - len); } } #define BARSIZE(num) (int) (0.5 + (double) ((all_high * (int) (num)) / (double) total_data)) #define ORDSIZE(num) (int) ((double) ((all_high * (int) (num)) / (double) all_diff)) if (dialog_state.use_scrollbar) { int all_high = (bottom - top - 1); this_data = MAX(0, this_data); if (total_data > 0 && all_high > 0) { int all_diff = (int) (total_data + 1); int bar_diff = (int) (next_data + 1 - this_data); int bar_high; int bar_y; bar_high = ORDSIZE(bar_diff); if (bar_high <= 0) bar_high = 1; if (bar_high < all_high) { int bar_last = BARSIZE(next_data); wmove(win, top + 1, right); (void) wattrset(win, save); wvline(win, ACS_VLINE | A_REVERSE, all_high); bar_y = ORDSIZE(this_data); if (bar_y >= bar_last && bar_y > 0) bar_y = bar_last - 1; if (bar_last - bar_y > bar_high && bar_high > 1) ++bar_y; bar_last = MIN(bar_last, all_high); wmove(win, top + 1 + bar_y, right); (void) wattrset(win, position_indicator_attr); wattron(win, A_REVERSE); #if defined(WACS_BLOCK) && defined(NCURSES_VERSION) && defined(USE_WIDE_CURSES) wvline_set(win, WACS_BLOCK, bar_last - bar_y); #else wvline(win, ACS_BLOCK, bar_last - bar_y); #endif } } } dlg_draw_arrows2(win, top_arrow, bottom_arrow, left + ARROWS_COL, top, bottom, attr, borderattr); (void) wattrset(win, save); wmove(win, oldy, oldx); }
/* * Display a message box. Program will pause and display an "OK" button * if the parameter 'pauseopt' is non-zero. */ int dialog_msgbox(const char *title, const char *cprompt, int height, int width, int pauseopt) { /* *INDENT-OFF* */ static DLG_KEYS_BINDING binding[] = { HELPKEY_BINDINGS, ENTERKEY_BINDINGS, TRAVERSE_BINDINGS, SCROLLKEY_BINDINGS, END_KEYS_BINDING }; /* *INDENT-ON* */ int x, y, last = 0, page; int button; int key = 0, fkey; int result = DLG_EXIT_UNKNOWN; WINDOW *dialog = 0; char *prompt = dlg_strclone(cprompt); const char **buttons = dlg_ok_label(); int offset = 0; int check; bool show = TRUE; int min_width = (pauseopt == 1 ? 12 : 0); int save_nocancel = dialog_vars.nocancel; #ifdef KEY_RESIZE int req_high; int req_wide; #endif dialog_vars.nocancel = TRUE; button = dlg_default_button(); #ifdef KEY_RESIZE req_high = height; req_wide = width; restart: #endif dlg_button_layout(buttons, &min_width); dlg_tab_correct_str(prompt); dlg_auto_size(title, prompt, &height, &width, (pauseopt == 1 ? 2 : 0), min_width); dlg_print_size(height, width); dlg_ctl_size(height, width); x = dlg_box_x_ordinate(width); y = dlg_box_y_ordinate(height); #ifdef KEY_RESIZE if (dialog != 0) dlg_move_window(dialog, height, width, y, x); else #endif { dialog = dlg_new_window(height, width, y, x); dlg_register_window(dialog, "msgbox", binding); dlg_register_buttons(dialog, "msgbox", buttons); } page = height - (1 + 3 * MARGIN); dlg_mouse_setbase(x, y); dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr); dlg_draw_title(dialog, title); wattrset(dialog, dialog_attr); if (pauseopt) { dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr); mouse_mkbutton(height - 2, width / 2 - 4, 6, '\n'); dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); dlg_draw_helpline(dialog, FALSE); while (result == DLG_EXIT_UNKNOWN) { if (show) { last = dlg_print_scrolled(dialog, prompt, offset, page, width, pauseopt); dlg_trace_win(dialog); show = FALSE; } key = dlg_mouse_wgetch(dialog, &fkey); if (dlg_result_key(key, fkey, &result)) break; if (!fkey && (check = dlg_char_to_button(key, buttons)) >= 0) { result = dlg_ok_buttoncode(check); break; } if (fkey) { switch (key) { #ifdef KEY_RESIZE case KEY_RESIZE: dlg_clear(); height = req_high; width = req_wide; show = TRUE; goto restart; #endif case DLGK_FIELD_NEXT: button = dlg_next_button(buttons, button); if (button < 0) button = 0; dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); break; case DLGK_FIELD_PREV: button = dlg_prev_button(buttons, button); if (button < 0) button = 0; dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); break; case DLGK_ENTER: result = dlg_ok_buttoncode(button); break; default: if (is_DLGK_MOUSE(key)) { result = dlg_ok_buttoncode(key - M_EVENT); if (result < 0) result = DLG_EXIT_OK; } else if (dlg_check_scrolled(key, last, page, &show, &offset) == 0) { } else { beep(); } break; } } else { beep(); } } } else { dlg_print_scrolled(dialog, prompt, offset, page, width, pauseopt); dlg_draw_helpline(dialog, FALSE); wrefresh(dialog); dlg_trace_win(dialog); result = DLG_EXIT_OK; } dlg_del_window(dialog); dlg_mouse_free_regions(); free(prompt); dialog_vars.nocancel = save_nocancel; return result; }
static void repaint_text(MY_OBJ * obj) { WINDOW *dialog = obj->obj.win; int i, x; if (dialog != 0 && obj->obj.input != 0) { (void) werase(dialog); dlg_draw_box2(dialog, 0, 0, obj->height, obj->width, dialog_attr, border_attr, border2_attr); dlg_draw_title(dialog, obj->title); (void) wattrset(dialog, dialog_attr); dlg_draw_helpline(dialog, FALSE); dlg_print_autowrap(dialog, obj->prompt, obj->height, obj->width); dlg_draw_box2(dialog, obj->height - 4, 2 + MARGIN, 2 + MARGIN, obj->width - 2 * (2 + MARGIN), dialog_attr, border_attr, border2_attr); /* * Clear the area for the progress bar by filling it with spaces * in the gauge-attribute, and write the percentage with that * attribute. */ (void) wmove(dialog, obj->height - 3, 4); (void) wattrset(dialog, gauge_attr); for (i = 0; i < (obj->width - 2 * (3 + MARGIN)); i++) (void) waddch(dialog, ' '); (void) wmove(dialog, obj->height - 3, (obj->width / 2) - 2); (void) wprintw(dialog, "%3d%%", obj->percent); /* * Now draw a bar in reverse, relative to the background. * The window attribute was useful for painting the background, * but requires some tweaks to reverse it. */ x = (obj->percent * (obj->width - 2 * (3 + MARGIN))) / 100; if ((gauge_attr & A_REVERSE) != 0) { wattroff(dialog, A_REVERSE); } else { (void) wattrset(dialog, A_REVERSE); } (void) wmove(dialog, obj->height - 3, 4); for (i = 0; i < x; i++) { chtype ch2 = winch(dialog); if (gauge_attr & A_REVERSE) { ch2 &= ~A_REVERSE; } (void) waddch(dialog, ch2); } (void) wrefresh(dialog); } }
int dlg_progressbox(const char *title, const char *cprompt, int height, int width, int pauseopt, FILE *fp) { int i; int x, y, thigh; WINDOW *dialog, *text; MY_OBJ *obj; char *prompt = dlg_strclone(cprompt); int result; dlg_tab_correct_str(prompt); dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, MIN_WIDE); dlg_print_size(height, width); dlg_ctl_size(height, width); x = dlg_box_x_ordinate(width); y = dlg_box_y_ordinate(height); thigh = height - (2 * MARGIN); dialog = dlg_new_window(height, width, y, x); dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr); dlg_draw_title(dialog, title); dlg_draw_helpline(dialog, FALSE); if (*prompt != '\0') { int y2, x2; (void) wattrset(dialog, dialog_attr); dlg_print_autowrap(dialog, prompt, height, width); getyx(dialog, y2, x2); (void) x2; ++y2; wmove(dialog, y2, MARGIN); for (i = 0; i < getmaxx(dialog) - 2 * MARGIN; i++) (void) waddch(dialog, dlg_boxchar(ACS_HLINE)); y += y2; thigh -= y2; } /* Create window for text region, used for scrolling text */ text = dlg_sub_window(dialog, thigh, width - (2 * MARGIN), y + MARGIN, x + MARGIN); (void) wrefresh(dialog); (void) wmove(dialog, thigh, (MARGIN + 1)); (void) wnoutrefresh(dialog); obj = dlg_calloc(MY_OBJ, 1); assert_ptr(obj, "dlg_progressbox"); obj->obj.input = fp; obj->obj.win = dialog; obj->text = text; dlg_attr_clear(text, thigh, getmaxx(text), dialog_attr); for (i = 0; get_line(obj); i++) { if (i < thigh) { print_line(obj, text, i, width - (2 * MARGIN)); } else { scrollok(text, TRUE); scroll(text); scrollok(text, FALSE); print_line(obj, text, thigh - 1, width - (2 * MARGIN)); } (void) wrefresh(text); dlg_trace_win(dialog); if (obj->is_eof) break; } if (pauseopt) { scrollok(text, TRUE); wscrl(text, 1 + MARGIN); (void) wrefresh(text); result = pause_for_ok(dialog, height, width); } else { wrefresh(dialog); result = DLG_EXIT_OK; } dlg_del_window(dialog); free(prompt); free(obj); return result; }
/* * Display a dialog box with two buttons - Yes and No. */ int dialog_yesno(const char *title, const char *cprompt, int height, int width) { /* *INDENT-OFF* */ static DLG_KEYS_BINDING binding[] = { HELPKEY_BINDINGS, ENTERKEY_BINDINGS, DLG_KEYS_DATA( DLGK_ENTER, ' ' ), DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_DOWN ), DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ), DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ), DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_UP ), DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ), DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ), SCROLLKEY_BINDINGS, END_KEYS_BINDING }; /* *INDENT-ON* */ int x, y; int key = 0, fkey; int code; int button = dlg_defaultno_button(); WINDOW *dialog = 0; int result = DLG_EXIT_UNKNOWN; char *prompt = dlg_strclone(cprompt); const char **buttons = dlg_yes_labels(); int min_width = 25; bool show = TRUE; int page, last = 0, offset = 0; #ifdef KEY_RESIZE int req_high = height; int req_wide = width; restart: #endif dlg_tab_correct_str(prompt); dlg_button_layout(buttons, &min_width); dlg_auto_size(title, prompt, &height, &width, 2, min_width); dlg_print_size(height, width); dlg_ctl_size(height, width); x = dlg_box_x_ordinate(width); y = dlg_box_y_ordinate(height); #ifdef KEY_RESIZE if (dialog != 0) dlg_move_window(dialog, height, width, y, x); else #endif { dialog = dlg_new_window(height, width, y, x); dlg_register_window(dialog, "yesno", binding); dlg_register_buttons(dialog, "yesno", buttons); } dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); dlg_draw_bottom_box(dialog); dlg_draw_title(dialog, title); dlg_draw_helpline(dialog, FALSE); wattrset(dialog, dialog_attr); page = height - (1 + 3 * MARGIN); dlg_draw_buttons(dialog, height - 2 * MARGIN, 0, buttons, button, FALSE, width); while (result == DLG_EXIT_UNKNOWN) { if (show) { last = dlg_print_scrolled(dialog, prompt, offset, page, width, TRUE); show = FALSE; } key = dlg_mouse_wgetch(dialog, &fkey); if (dlg_result_key(key, fkey, &result)) break; if ((code = dlg_char_to_button(key, buttons)) >= 0) { result = dlg_ok_buttoncode(code); break; } /* handle function keys */ if (fkey) { switch (key) { case DLGK_FIELD_NEXT: button = dlg_next_button(buttons, button); if (button < 0) button = 0; dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); break; case DLGK_FIELD_PREV: button = dlg_prev_button(buttons, button); if (button < 0) button = 0; dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); break; case DLGK_ENTER: result = dlg_yes_buttoncode(button); break; #ifdef KEY_RESIZE case KEY_RESIZE: dlg_clear(); height = req_high; width = req_wide; goto restart; #endif default: if (is_DLGK_MOUSE(key)) { result = dlg_yes_buttoncode(key - M_EVENT); if (result < 0) result = DLG_EXIT_OK; } else if (dlg_check_scrolled(key, last, page, &show, &offset) != 0) { beep(); } break; } } else { beep(); } } dlg_del_window(dialog); dlg_mouse_free_regions(); free(prompt); return result; }