15382d832SPeter Avalos /*
2*a8e38dc0SAntonio Huete Jimenez * $Id: rangebox.c,v 1.32 2020/11/22 23:25:09 tom Exp $
35382d832SPeter Avalos *
45382d832SPeter Avalos * rangebox.c -- implements the rangebox dialog
55382d832SPeter Avalos *
65940c9abSDaniel Fojt * Copyright 2012-2019,2020 Thomas E. Dickey
75382d832SPeter Avalos *
85382d832SPeter Avalos * This program is free software; you can redistribute it and/or modify
95382d832SPeter Avalos * it under the terms of the GNU Lesser General Public License, version 2.1
105382d832SPeter Avalos * as published by the Free Software Foundation.
115382d832SPeter Avalos *
125382d832SPeter Avalos * This program is distributed in the hope that it will be useful, but
135382d832SPeter Avalos * WITHOUT ANY WARRANTY; without even the implied warranty of
145382d832SPeter Avalos * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
155382d832SPeter Avalos * Lesser General Public License for more details.
165382d832SPeter Avalos *
175382d832SPeter Avalos * You should have received a copy of the GNU Lesser General Public
185382d832SPeter Avalos * License along with this program; if not, write to
195382d832SPeter Avalos * Free Software Foundation, Inc.
205382d832SPeter Avalos * 51 Franklin St., Fifth Floor
215382d832SPeter Avalos * Boston, MA 02110, USA.
225382d832SPeter Avalos */
235382d832SPeter Avalos
245940c9abSDaniel Fojt #include <dlg_internals.h>
255382d832SPeter Avalos #include <dlg_keys.h>
265382d832SPeter Avalos
275382d832SPeter Avalos #define ONE_HIGH 1
285382d832SPeter Avalos
295382d832SPeter Avalos #define MIN_HIGH (ONE_HIGH + 1 + (4 * MARGIN))
305382d832SPeter Avalos #define MIN_WIDE (10 + 2 + (2 * MARGIN))
315382d832SPeter Avalos
325382d832SPeter Avalos typedef struct {
335382d832SPeter Avalos /* window in which the value and slider are drawn */
345382d832SPeter Avalos WINDOW *window;
355382d832SPeter Avalos int min_value;
365382d832SPeter Avalos int max_value;
375382d832SPeter Avalos /* position and width of the numeric field */
385382d832SPeter Avalos int value_x;
395382d832SPeter Avalos int value_len;
405382d832SPeter Avalos int value_col;
415382d832SPeter Avalos /* position and width of the slider field */
425382d832SPeter Avalos int slide_x;
435382d832SPeter Avalos int slide_y;
445382d832SPeter Avalos int slide_len;
455382d832SPeter Avalos /* current value drawn */
465382d832SPeter Avalos int current;
475382d832SPeter Avalos /* value to add to make slider move by one cell */
485382d832SPeter Avalos int slide_inc;
495382d832SPeter Avalos } VALUE;
505382d832SPeter Avalos
515382d832SPeter Avalos static int
digits_of(int value)525382d832SPeter Avalos digits_of(int value)
535382d832SPeter Avalos {
545382d832SPeter Avalos char temp[80];
555382d832SPeter Avalos sprintf(temp, "%d", value);
565382d832SPeter Avalos return (int) strlen(temp);
575382d832SPeter Avalos }
585382d832SPeter Avalos
595382d832SPeter Avalos static int
digit_of(VALUE * data)605382d832SPeter Avalos digit_of(VALUE * data)
615382d832SPeter Avalos {
625382d832SPeter Avalos int col = data->value_col;
635382d832SPeter Avalos int result = 1;
645382d832SPeter Avalos
655382d832SPeter Avalos while (++col < data->value_len) {
665382d832SPeter Avalos result *= 10;
675382d832SPeter Avalos }
685382d832SPeter Avalos return result;
695382d832SPeter Avalos }
705382d832SPeter Avalos
715382d832SPeter Avalos static bool
set_digit(VALUE * data,int chr)725382d832SPeter Avalos set_digit(VALUE * data, int chr)
735382d832SPeter Avalos {
745382d832SPeter Avalos bool result = FALSE;
755382d832SPeter Avalos char buffer[80];
765382d832SPeter Avalos long check;
775382d832SPeter Avalos char *next = 0;
785382d832SPeter Avalos
795382d832SPeter Avalos sprintf(buffer, "%*d", data->value_len, data->current);
805382d832SPeter Avalos buffer[data->value_col] = (char) chr;
815382d832SPeter Avalos check = strtol(buffer, &next, 10);
825382d832SPeter Avalos if (next == 0 || *next == '\0') {
835382d832SPeter Avalos if ((check <= (long) data->max_value) &&
845382d832SPeter Avalos (check >= (long) data->min_value)) {
855382d832SPeter Avalos result = TRUE;
865382d832SPeter Avalos data->current = (int) check;
875382d832SPeter Avalos }
885382d832SPeter Avalos }
895382d832SPeter Avalos
905382d832SPeter Avalos return result;
915382d832SPeter Avalos }
925382d832SPeter Avalos
935382d832SPeter Avalos /*
945382d832SPeter Avalos * This is similar to the gauge code, but differs in the way the number
955382d832SPeter Avalos * is displayed, etc.
965382d832SPeter Avalos */
975382d832SPeter Avalos static void
draw_value(VALUE * data,int value)985382d832SPeter Avalos draw_value(VALUE * data, int value)
995382d832SPeter Avalos {
1005382d832SPeter Avalos if (value != data->current) {
1015382d832SPeter Avalos WINDOW *win = data->window;
1025382d832SPeter Avalos int y, x;
1035382d832SPeter Avalos int n;
1045382d832SPeter Avalos int ranges = (data->max_value + 1 - data->min_value);
1055382d832SPeter Avalos int offset = (value - data->min_value);
1065382d832SPeter Avalos int scaled;
1075382d832SPeter Avalos
1085382d832SPeter Avalos getyx(win, y, x);
1095382d832SPeter Avalos
1105382d832SPeter Avalos if (ranges > data->slide_len) {
1115382d832SPeter Avalos scaled = (offset + data->slide_inc) / data->slide_inc;
1125382d832SPeter Avalos } else if (ranges < data->slide_len) {
1135382d832SPeter Avalos scaled = (offset + 1) * data->slide_inc;
1145382d832SPeter Avalos } else {
1155382d832SPeter Avalos scaled = offset;
1165382d832SPeter Avalos }
1175382d832SPeter Avalos
1185940c9abSDaniel Fojt dlg_attrset(win, gauge_attr);
1195382d832SPeter Avalos wmove(win, data->slide_y, data->slide_x);
1205382d832SPeter Avalos for (n = 0; n < data->slide_len; ++n) {
1215382d832SPeter Avalos (void) waddch(win, ' ');
1225382d832SPeter Avalos }
1235382d832SPeter Avalos wmove(win, data->slide_y, data->value_x);
1245382d832SPeter Avalos wprintw(win, "%*d", data->value_len, value);
1255382d832SPeter Avalos if ((gauge_attr & A_REVERSE) != 0) {
1265940c9abSDaniel Fojt dlg_attroff(win, A_REVERSE);
1275382d832SPeter Avalos } else {
1285940c9abSDaniel Fojt dlg_attrset(win, A_REVERSE);
1295382d832SPeter Avalos }
1305382d832SPeter Avalos wmove(win, data->slide_y, data->slide_x);
1315382d832SPeter Avalos for (n = 0; n < scaled; ++n) {
1325382d832SPeter Avalos chtype ch2 = winch(win);
1335382d832SPeter Avalos if (gauge_attr & A_REVERSE) {
1345382d832SPeter Avalos ch2 &= ~A_REVERSE;
1355382d832SPeter Avalos }
1365382d832SPeter Avalos (void) waddch(win, ch2);
1375382d832SPeter Avalos }
1385940c9abSDaniel Fojt dlg_attrset(win, dialog_attr);
1395382d832SPeter Avalos
1405382d832SPeter Avalos wmove(win, y, x);
1415382d832SPeter Avalos data->current = value;
1425382d832SPeter Avalos
1435940c9abSDaniel Fojt DLG_TRACE(("# drew %d offset %d scaled %d limit %d inc %d\n",
1445382d832SPeter Avalos value,
1455382d832SPeter Avalos offset,
1465382d832SPeter Avalos scaled,
1475382d832SPeter Avalos data->slide_len,
1485940c9abSDaniel Fojt data->slide_inc));
1495382d832SPeter Avalos
1505382d832SPeter Avalos dlg_trace_win(win);
1515382d832SPeter Avalos }
1525382d832SPeter Avalos }
1535382d832SPeter Avalos
1545382d832SPeter Avalos /*
1555382d832SPeter Avalos * Allow the user to select from a range of values, e.g., using a slider.
1565382d832SPeter Avalos */
1575382d832SPeter Avalos int
dialog_rangebox(const char * title,const char * cprompt,int height,int width,int min_value,int max_value,int default_value)1585382d832SPeter Avalos dialog_rangebox(const char *title,
1595382d832SPeter Avalos const char *cprompt,
1605382d832SPeter Avalos int height,
1615382d832SPeter Avalos int width,
1625382d832SPeter Avalos int min_value,
1635382d832SPeter Avalos int max_value,
1645382d832SPeter Avalos int default_value)
1655382d832SPeter Avalos {
1665382d832SPeter Avalos /* *INDENT-OFF* */
1675382d832SPeter Avalos static DLG_KEYS_BINDING binding[] = {
1685382d832SPeter Avalos DLG_KEYS_DATA( DLGK_DELETE_RIGHT,KEY_DC ),
1695382d832SPeter Avalos HELPKEY_BINDINGS,
1705382d832SPeter Avalos ENTERKEY_BINDINGS,
1715940c9abSDaniel Fojt TOGGLEKEY_BINDINGS,
1725382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_NEXT, CHR_NEXT ),
1735382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ),
1745382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
1755382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_PREV, CHR_BACKSPACE ),
1765382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_PREV, CHR_PREVIOUS ),
1775382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
1785382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ),
1795382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_FIRST, KEY_HOME),
1805382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_LAST, KEY_END),
1815382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_LAST, KEY_LL ),
1825382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_NEXT, '+'),
1835382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_NEXT, KEY_DOWN),
1845382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_PREV, '-' ),
1855382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_PREV, KEY_UP ),
1865382d832SPeter Avalos DLG_KEYS_DATA( DLGK_PAGE_NEXT, KEY_NEXT),
1875382d832SPeter Avalos DLG_KEYS_DATA( DLGK_PAGE_NEXT, KEY_NPAGE),
1885382d832SPeter Avalos DLG_KEYS_DATA( DLGK_PAGE_PREV, KEY_PPAGE ),
1895382d832SPeter Avalos DLG_KEYS_DATA( DLGK_PAGE_PREV, KEY_PREVIOUS ),
1905382d832SPeter Avalos END_KEYS_BINDING
1915382d832SPeter Avalos };
1925382d832SPeter Avalos /* *INDENT-ON* */
1935382d832SPeter Avalos
1945382d832SPeter Avalos #ifdef KEY_RESIZE
1955382d832SPeter Avalos int old_height = height;
1965382d832SPeter Avalos int old_width = width;
1975382d832SPeter Avalos #endif
1985382d832SPeter Avalos VALUE data;
1995940c9abSDaniel Fojt int key, fkey;
2005382d832SPeter Avalos int button;
2015382d832SPeter Avalos int result = DLG_EXIT_UNKNOWN;
2025382d832SPeter Avalos WINDOW *dialog;
2035382d832SPeter Avalos int state = dlg_default_button();
2045382d832SPeter Avalos const char **buttons = dlg_ok_labels();
2055940c9abSDaniel Fojt char *prompt;
2065382d832SPeter Avalos char buffer[MAX_LEN];
2075382d832SPeter Avalos int cur_value = default_value;
2085382d832SPeter Avalos int usable;
2095382d832SPeter Avalos int ranges;
2105382d832SPeter Avalos int yorg, xorg;
2115382d832SPeter Avalos
2125940c9abSDaniel Fojt DLG_TRACE(("# tailbox args:\n"));
2135940c9abSDaniel Fojt DLG_TRACE2S("title", title);
2145940c9abSDaniel Fojt DLG_TRACE2S("message", cprompt);
2155940c9abSDaniel Fojt DLG_TRACE2N("height", height);
2165940c9abSDaniel Fojt DLG_TRACE2N("width", width);
2175940c9abSDaniel Fojt DLG_TRACE2N("minval", min_value);
2185940c9abSDaniel Fojt DLG_TRACE2N("maxval", max_value);
2195940c9abSDaniel Fojt DLG_TRACE2N("default", default_value);
2205940c9abSDaniel Fojt
2215382d832SPeter Avalos if (max_value < min_value)
2225382d832SPeter Avalos max_value = min_value;
2235382d832SPeter Avalos if (cur_value > max_value)
2245382d832SPeter Avalos cur_value = max_value;
2255382d832SPeter Avalos if (cur_value < min_value)
2265382d832SPeter Avalos cur_value = min_value;
2275382d832SPeter Avalos
2285382d832SPeter Avalos dlg_does_output();
2295382d832SPeter Avalos
2305382d832SPeter Avalos #ifdef KEY_RESIZE
2315382d832SPeter Avalos retry:
2325382d832SPeter Avalos #endif
2335382d832SPeter Avalos
2345940c9abSDaniel Fojt prompt = dlg_strclone(cprompt);
2355940c9abSDaniel Fojt dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, MIN_WIDE);
2365940c9abSDaniel Fojt
2375382d832SPeter Avalos dlg_button_layout(buttons, &width);
2385382d832SPeter Avalos dlg_print_size(height, width);
2395382d832SPeter Avalos dlg_ctl_size(height, width);
2405382d832SPeter Avalos
2415382d832SPeter Avalos dialog = dlg_new_window(height, width,
2425382d832SPeter Avalos yorg = dlg_box_y_ordinate(height),
2435382d832SPeter Avalos xorg = dlg_box_x_ordinate(width));
2445382d832SPeter Avalos
2455382d832SPeter Avalos data.window = dialog;
2465382d832SPeter Avalos
2475382d832SPeter Avalos data.min_value = min_value;
2485382d832SPeter Avalos data.max_value = max_value;
2495382d832SPeter Avalos
2505382d832SPeter Avalos usable = (width - 2 - 4 * MARGIN);
2515382d832SPeter Avalos ranges = max_value - min_value + 1;
2525382d832SPeter Avalos
2535382d832SPeter Avalos /*
2545382d832SPeter Avalos * Center the number after allowing for its maximum number of digits.
2555382d832SPeter Avalos */
2565382d832SPeter Avalos data.value_len = digits_of(max_value);
2575382d832SPeter Avalos if (digits_of(min_value) > data.value_len)
2585382d832SPeter Avalos data.value_len = digits_of(min_value);
2595382d832SPeter Avalos data.value_x = (usable - data.value_len) / 2 + MARGIN;
2605382d832SPeter Avalos data.value_col = data.value_len - 1;
2615382d832SPeter Avalos
2625382d832SPeter Avalos /*
2635382d832SPeter Avalos * The slider is scaled, to try to use the width of the dialog.
2645382d832SPeter Avalos */
2655382d832SPeter Avalos if (ranges > usable) {
2665382d832SPeter Avalos data.slide_inc = (ranges + usable - 1) / usable;
2675382d832SPeter Avalos data.slide_len = 1 + ranges / data.slide_inc;
2685382d832SPeter Avalos } else if (ranges < usable) {
2695382d832SPeter Avalos data.slide_inc = usable / ranges;
2705382d832SPeter Avalos data.slide_len = ranges * data.slide_inc;
2715382d832SPeter Avalos } else {
2725382d832SPeter Avalos data.slide_inc = 1;
2735382d832SPeter Avalos data.slide_len = usable;
2745382d832SPeter Avalos }
2755382d832SPeter Avalos data.slide_x = (usable - data.slide_len) / 2 + MARGIN + 2;
2765382d832SPeter Avalos data.slide_y = height - 5;
2775382d832SPeter Avalos
2785382d832SPeter Avalos data.current = cur_value - 1;
2795382d832SPeter Avalos
2805382d832SPeter Avalos dlg_register_window(dialog, "rangebox", binding);
2815382d832SPeter Avalos dlg_register_buttons(dialog, "rangebox", buttons);
2825382d832SPeter Avalos
2835382d832SPeter Avalos dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr);
2845382d832SPeter Avalos dlg_mouse_setbase(xorg, yorg);
2855382d832SPeter Avalos dlg_mouse_mkregion(data.slide_y - 1, data.slide_x - 1, 3, usable + 2, 'i');
2865382d832SPeter Avalos dlg_draw_box2(dialog,
2875382d832SPeter Avalos height - 6, data.slide_x - MARGIN,
2885382d832SPeter Avalos 2 + MARGIN, data.slide_len + 2 * MARGIN,
2895382d832SPeter Avalos dialog_attr,
2905382d832SPeter Avalos border_attr,
2915382d832SPeter Avalos border2_attr);
2925382d832SPeter Avalos dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr);
2935382d832SPeter Avalos dlg_draw_title(dialog, title);
2945382d832SPeter Avalos dlg_draw_helpline(dialog, FALSE);
2955382d832SPeter Avalos
2965940c9abSDaniel Fojt dlg_attrset(dialog, dialog_attr);
2975382d832SPeter Avalos dlg_print_autowrap(dialog, prompt, height, width);
2985382d832SPeter Avalos
2995382d832SPeter Avalos dlg_trace_win(dialog);
3005940c9abSDaniel Fojt
3015382d832SPeter Avalos while (result == DLG_EXIT_UNKNOWN) {
3025940c9abSDaniel Fojt int key2;
3035940c9abSDaniel Fojt
3045382d832SPeter Avalos draw_value(&data, cur_value);
3055382d832SPeter Avalos button = (state < 0) ? 0 : state;
3065382d832SPeter Avalos dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
3075382d832SPeter Avalos if (state < 0) {
3085382d832SPeter Avalos data.value_col = data.value_len + state;
3095382d832SPeter Avalos wmove(dialog, data.slide_y, data.value_x + data.value_col);
3105382d832SPeter Avalos }
3115382d832SPeter Avalos
3125382d832SPeter Avalos key = dlg_mouse_wgetch(dialog, &fkey);
3135940c9abSDaniel Fojt if (dlg_result_key(key, fkey, &result)) {
3145940c9abSDaniel Fojt if (!dlg_button_key(result, &button, &key, &fkey))
3155382d832SPeter Avalos break;
3165940c9abSDaniel Fojt }
3175382d832SPeter Avalos
3185382d832SPeter Avalos if ((key2 = dlg_char_to_button(key, buttons)) >= 0) {
3195382d832SPeter Avalos result = key2;
3205382d832SPeter Avalos } else {
3215382d832SPeter Avalos /* handle function-keys */
3225382d832SPeter Avalos if (fkey) {
3235382d832SPeter Avalos switch (key) {
3245940c9abSDaniel Fojt case DLGK_TOGGLE:
3255382d832SPeter Avalos case DLGK_ENTER:
326*a8e38dc0SAntonio Huete Jimenez result = dlg_enter_buttoncode(button);
327*a8e38dc0SAntonio Huete Jimenez break;
328*a8e38dc0SAntonio Huete Jimenez case DLGK_LEAVE:
3295382d832SPeter Avalos result = dlg_ok_buttoncode(button);
3305382d832SPeter Avalos break;
3315382d832SPeter Avalos case DLGK_FIELD_PREV:
3325382d832SPeter Avalos if (state < 0 && state > -data.value_len) {
3335382d832SPeter Avalos --state;
3345382d832SPeter Avalos } else {
3355382d832SPeter Avalos state = dlg_prev_ok_buttonindex(state, -data.value_len);
3365382d832SPeter Avalos }
3375382d832SPeter Avalos break;
3385382d832SPeter Avalos case DLGK_FIELD_NEXT:
3395382d832SPeter Avalos if (state < 0) {
3405382d832SPeter Avalos ++state;
3415382d832SPeter Avalos } else {
3425382d832SPeter Avalos state = dlg_next_ok_buttonindex(state, -data.value_len);
3435382d832SPeter Avalos }
3445382d832SPeter Avalos break;
3455382d832SPeter Avalos case DLGK_ITEM_FIRST:
3465382d832SPeter Avalos cur_value = min_value;
3475382d832SPeter Avalos break;
3485382d832SPeter Avalos case DLGK_ITEM_LAST:
3495382d832SPeter Avalos cur_value = max_value;
3505382d832SPeter Avalos break;
3515382d832SPeter Avalos case DLGK_ITEM_PREV:
3525382d832SPeter Avalos if (state < 0) {
3535382d832SPeter Avalos cur_value -= digit_of(&data);
3545382d832SPeter Avalos } else {
3555382d832SPeter Avalos cur_value -= 1;
3565382d832SPeter Avalos }
3575382d832SPeter Avalos if (cur_value < min_value)
3585382d832SPeter Avalos cur_value = min_value;
3595382d832SPeter Avalos break;
3605382d832SPeter Avalos case DLGK_ITEM_NEXT:
3615382d832SPeter Avalos if (state < 0) {
3625382d832SPeter Avalos cur_value += digit_of(&data);
3635382d832SPeter Avalos } else {
3645382d832SPeter Avalos cur_value += 1;
3655382d832SPeter Avalos }
3665382d832SPeter Avalos if (cur_value > max_value)
3675382d832SPeter Avalos cur_value = max_value;
3685382d832SPeter Avalos break;
3695382d832SPeter Avalos case DLGK_PAGE_PREV:
3705382d832SPeter Avalos cur_value -= data.slide_inc;
3715382d832SPeter Avalos if (cur_value < min_value)
3725382d832SPeter Avalos cur_value = min_value;
3735382d832SPeter Avalos break;
3745382d832SPeter Avalos case DLGK_PAGE_NEXT:
3755382d832SPeter Avalos cur_value += data.slide_inc;
3765382d832SPeter Avalos if (cur_value > max_value)
3775382d832SPeter Avalos cur_value = max_value;
3785382d832SPeter Avalos break;
3795382d832SPeter Avalos #ifdef KEY_RESIZE
3805382d832SPeter Avalos case KEY_RESIZE:
3815940c9abSDaniel Fojt dlg_will_resize(dialog);
3825382d832SPeter Avalos /* reset data */
3835382d832SPeter Avalos height = old_height;
3845382d832SPeter Avalos width = old_width;
3855382d832SPeter Avalos /* repaint */
3865940c9abSDaniel Fojt free(prompt);
3875940c9abSDaniel Fojt _dlg_resize_cleanup(dialog);
3885382d832SPeter Avalos goto retry;
3895382d832SPeter Avalos #endif
3905382d832SPeter Avalos case DLGK_MOUSE('i'):
3915382d832SPeter Avalos state = -data.value_len;
3925382d832SPeter Avalos break;
3935382d832SPeter Avalos default:
3945382d832SPeter Avalos if (is_DLGK_MOUSE(key)) {
3955382d832SPeter Avalos result = dlg_ok_buttoncode(key - M_EVENT);
3965382d832SPeter Avalos if (result < 0)
3975382d832SPeter Avalos result = DLG_EXIT_OK;
3985382d832SPeter Avalos }
3995382d832SPeter Avalos break;
4005382d832SPeter Avalos }
4015382d832SPeter Avalos } else if (isdigit(key) && state < 0) {
4025382d832SPeter Avalos if (set_digit(&data, key)) {
4035382d832SPeter Avalos cur_value = data.current;
4045382d832SPeter Avalos data.current--;
4055382d832SPeter Avalos }
4065382d832SPeter Avalos } else {
4075382d832SPeter Avalos beep();
4085382d832SPeter Avalos }
4095382d832SPeter Avalos }
4105382d832SPeter Avalos }
4115382d832SPeter Avalos
4125382d832SPeter Avalos sprintf(buffer, "%d", cur_value);
4135382d832SPeter Avalos dlg_add_result(buffer);
4145940c9abSDaniel Fojt AddLastKey();
4155382d832SPeter Avalos
4165382d832SPeter Avalos dlg_del_window(dialog);
4175382d832SPeter Avalos dlg_mouse_free_regions();
4185382d832SPeter Avalos free(prompt);
4195382d832SPeter Avalos
4205382d832SPeter Avalos return result;
4215382d832SPeter Avalos }
422