15382d832SPeter Avalos /*
2*a8e38dc0SAntonio Huete Jimenez * $Id: timebox.c,v 1.72 2022/04/03 22:39:10 tom Exp $
35382d832SPeter Avalos *
45382d832SPeter Avalos * timebox.c -- implements the timebox dialog
55382d832SPeter Avalos *
6*a8e38dc0SAntonio Huete Jimenez * Copyright 2001-2021,2022 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 #define ONE_WIDE 2
295382d832SPeter Avalos #define BTN_HIGH 2
305382d832SPeter Avalos
315382d832SPeter Avalos #define MIN_HIGH (ONE_HIGH + BTN_HIGH + (4 * MARGIN))
325382d832SPeter Avalos #define MIN_WIDE ((3 * (ONE_WIDE + 2 * MARGIN)) + 2 + (2 * MARGIN))
335382d832SPeter Avalos
345382d832SPeter Avalos typedef enum {
355382d832SPeter Avalos sHR = -3
365382d832SPeter Avalos ,sMN = -2
375382d832SPeter Avalos ,sSC = -1
385382d832SPeter Avalos } STATES;
395382d832SPeter Avalos
405382d832SPeter Avalos struct _box;
415382d832SPeter Avalos
425382d832SPeter Avalos typedef struct _box {
435382d832SPeter Avalos WINDOW *parent;
445382d832SPeter Avalos WINDOW *window;
455382d832SPeter Avalos int x;
465382d832SPeter Avalos int y;
475382d832SPeter Avalos int width;
485382d832SPeter Avalos int height;
495382d832SPeter Avalos int period;
505382d832SPeter Avalos int value;
515382d832SPeter Avalos } BOX;
525382d832SPeter Avalos
535382d832SPeter Avalos static int
next_or_previous(int key)545382d832SPeter Avalos next_or_previous(int key)
555382d832SPeter Avalos {
565382d832SPeter Avalos int result = 0;
575382d832SPeter Avalos
585382d832SPeter Avalos switch (key) {
595382d832SPeter Avalos case DLGK_ITEM_PREV:
605382d832SPeter Avalos result = -1;
615382d832SPeter Avalos break;
625382d832SPeter Avalos case DLGK_ITEM_NEXT:
635382d832SPeter Avalos result = 1;
645382d832SPeter Avalos break;
655382d832SPeter Avalos default:
665382d832SPeter Avalos beep();
675382d832SPeter Avalos break;
685382d832SPeter Avalos }
695382d832SPeter Avalos return result;
705382d832SPeter Avalos }
715382d832SPeter Avalos /*
725382d832SPeter Avalos * Draw the hour-of-month selection box
735382d832SPeter Avalos */
745382d832SPeter Avalos static int
draw_cell(BOX * data)755382d832SPeter Avalos draw_cell(BOX * data)
765382d832SPeter Avalos {
775382d832SPeter Avalos werase(data->window);
785382d832SPeter Avalos dlg_draw_box(data->parent,
795382d832SPeter Avalos data->y - MARGIN, data->x - MARGIN,
805382d832SPeter Avalos data->height + (2 * MARGIN), data->width + (2 * MARGIN),
815382d832SPeter Avalos menubox_border_attr, menubox_border2_attr);
825382d832SPeter Avalos
835940c9abSDaniel Fojt dlg_attrset(data->window, item_attr);
845382d832SPeter Avalos wprintw(data->window, "%02d", data->value);
855382d832SPeter Avalos return 0;
865382d832SPeter Avalos }
875382d832SPeter Avalos
885382d832SPeter Avalos static int
init_object(BOX * data,WINDOW * parent,int x,int y,int width,int height,int period,int value,int code)895382d832SPeter Avalos init_object(BOX * data,
905382d832SPeter Avalos WINDOW *parent,
915382d832SPeter Avalos int x, int y,
925382d832SPeter Avalos int width, int height,
935382d832SPeter Avalos int period, int value,
945382d832SPeter Avalos int code)
955382d832SPeter Avalos {
965382d832SPeter Avalos (void) code;
975382d832SPeter Avalos
985382d832SPeter Avalos data->parent = parent;
995382d832SPeter Avalos data->x = x;
1005382d832SPeter Avalos data->y = y;
1015382d832SPeter Avalos data->width = width;
1025382d832SPeter Avalos data->height = height;
1035382d832SPeter Avalos data->period = period;
1045382d832SPeter Avalos data->value = value % period;
1055382d832SPeter Avalos
106*a8e38dc0SAntonio Huete Jimenez data->window = dlg_der_window(data->parent,
1075382d832SPeter Avalos data->height, data->width,
1085382d832SPeter Avalos data->y, data->x);
1095382d832SPeter Avalos if (data->window == 0)
1105382d832SPeter Avalos return -1;
1115382d832SPeter Avalos
1125382d832SPeter Avalos dlg_mouse_setbase(getbegx(parent), getbegy(parent));
1135382d832SPeter Avalos dlg_mouse_mkregion(y, x, height, width, code);
1145382d832SPeter Avalos
1155382d832SPeter Avalos return 0;
1165382d832SPeter Avalos }
1175382d832SPeter Avalos
1185382d832SPeter Avalos static int
CleanupResult(int code,WINDOW * dialog,char * prompt,DIALOG_VARS * save_vars)1195382d832SPeter Avalos CleanupResult(int code, WINDOW *dialog, char *prompt, DIALOG_VARS * save_vars)
1205382d832SPeter Avalos {
1215382d832SPeter Avalos dlg_del_window(dialog);
1225382d832SPeter Avalos dlg_mouse_free_regions();
1235382d832SPeter Avalos free(prompt);
1245382d832SPeter Avalos dlg_restore_vars(save_vars);
1255382d832SPeter Avalos
1265382d832SPeter Avalos return code;
1275382d832SPeter Avalos }
1285382d832SPeter Avalos
1295382d832SPeter Avalos #define DrawObject(data) draw_cell(data)
1305382d832SPeter Avalos
1315382d832SPeter Avalos /*
1325382d832SPeter Avalos * Display a dialog box for entering a date
1335382d832SPeter Avalos */
1345382d832SPeter Avalos int
dialog_timebox(const char * title,const char * subtitle,int height,int width,int hour,int minute,int second)1355382d832SPeter Avalos dialog_timebox(const char *title,
1365382d832SPeter Avalos const char *subtitle,
1375382d832SPeter Avalos int height,
1385382d832SPeter Avalos int width,
1395382d832SPeter Avalos int hour,
1405382d832SPeter Avalos int minute,
1415382d832SPeter Avalos int second)
1425382d832SPeter Avalos {
1435382d832SPeter Avalos /* *INDENT-OFF* */
1445382d832SPeter Avalos static DLG_KEYS_BINDING binding[] = {
1455382d832SPeter Avalos DLG_KEYS_DATA( DLGK_DELETE_RIGHT,KEY_DC ),
1465382d832SPeter Avalos HELPKEY_BINDINGS,
1475382d832SPeter Avalos ENTERKEY_BINDINGS,
1485940c9abSDaniel Fojt TOGGLEKEY_BINDINGS,
1495382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_FIRST,KEY_HOME ),
1505382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_LAST, KEY_END ),
1515382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_LAST, KEY_LL ),
1525382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_NEXT, CHR_NEXT ),
1535382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ),
1545382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
1555382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_PREV, CHR_BACKSPACE ),
1565382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_PREV, CHR_PREVIOUS ),
1575382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
1585382d832SPeter Avalos DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ),
1595382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_NEXT, '+'),
1605382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_NEXT, KEY_DOWN),
1615382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_NEXT, KEY_NEXT),
1625382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_NEXT, KEY_NPAGE),
1635382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_PREV, '-' ),
1645382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_PREV, KEY_PPAGE ),
1655382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_PREV, KEY_PREVIOUS ),
1665382d832SPeter Avalos DLG_KEYS_DATA( DLGK_ITEM_PREV, KEY_UP ),
1675382d832SPeter Avalos END_KEYS_BINDING
1685382d832SPeter Avalos };
1695382d832SPeter Avalos /* *INDENT-ON* */
1705382d832SPeter Avalos
1715382d832SPeter Avalos #ifdef KEY_RESIZE
1725382d832SPeter Avalos int old_height = height;
1735382d832SPeter Avalos int old_width = width;
1745382d832SPeter Avalos #endif
1755382d832SPeter Avalos BOX hr_box, mn_box, sc_box;
1765940c9abSDaniel Fojt int key, fkey;
1775382d832SPeter Avalos int button;
1785382d832SPeter Avalos int result = DLG_EXIT_UNKNOWN;
1795382d832SPeter Avalos WINDOW *dialog;
1805940c9abSDaniel Fojt time_t now_time;
1815382d832SPeter Avalos struct tm current;
1825382d832SPeter Avalos int state = dlg_default_button();
1835382d832SPeter Avalos const char **buttons = dlg_ok_labels();
1845940c9abSDaniel Fojt char *prompt;
1855382d832SPeter Avalos char buffer[MAX_LEN];
1865382d832SPeter Avalos DIALOG_VARS save_vars;
1875382d832SPeter Avalos
1885940c9abSDaniel Fojt DLG_TRACE(("# timebox args:\n"));
1895940c9abSDaniel Fojt DLG_TRACE2S("title", title);
1905940c9abSDaniel Fojt DLG_TRACE2S("message", subtitle);
1915940c9abSDaniel Fojt DLG_TRACE2N("height", height);
1925940c9abSDaniel Fojt DLG_TRACE2N("width", width);
1935940c9abSDaniel Fojt DLG_TRACE2N("hour", hour);
1945940c9abSDaniel Fojt DLG_TRACE2N("minute", minute);
1955940c9abSDaniel Fojt DLG_TRACE2N("second", second);
1965940c9abSDaniel Fojt
1975382d832SPeter Avalos now_time = time((time_t *) 0);
1985382d832SPeter Avalos current = *localtime(&now_time);
1995382d832SPeter Avalos
2005382d832SPeter Avalos dlg_save_vars(&save_vars);
2015382d832SPeter Avalos dialog_vars.separate_output = TRUE;
2025382d832SPeter Avalos
2035382d832SPeter Avalos dlg_does_output();
2045382d832SPeter Avalos
2055382d832SPeter Avalos #ifdef KEY_RESIZE
2065382d832SPeter Avalos retry:
2075382d832SPeter Avalos #endif
2085382d832SPeter Avalos
2095940c9abSDaniel Fojt prompt = dlg_strclone(subtitle);
210*a8e38dc0SAntonio Huete Jimenez if (height > 0)
211*a8e38dc0SAntonio Huete Jimenez height += MIN_HIGH;
2125940c9abSDaniel Fojt dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, MIN_WIDE);
2135940c9abSDaniel Fojt
214*a8e38dc0SAntonio Huete Jimenez if (width < MIN_WIDE)
215*a8e38dc0SAntonio Huete Jimenez width = MIN_WIDE;
2165382d832SPeter Avalos dlg_button_layout(buttons, &width);
2175382d832SPeter Avalos dlg_print_size(height, width);
2185382d832SPeter Avalos dlg_ctl_size(height, width);
2195382d832SPeter Avalos
2205382d832SPeter Avalos dialog = dlg_new_window(height, width,
2215382d832SPeter Avalos dlg_box_y_ordinate(height),
2225382d832SPeter Avalos dlg_box_x_ordinate(width));
2235382d832SPeter Avalos
2245382d832SPeter Avalos if (hour >= 24 || minute >= 60 || second >= 60) {
2255382d832SPeter Avalos return CleanupResult(DLG_EXIT_ERROR, dialog, prompt, &save_vars);
2265382d832SPeter Avalos }
2275382d832SPeter Avalos
2285382d832SPeter Avalos dlg_register_window(dialog, "timebox", binding);
2295382d832SPeter Avalos dlg_register_buttons(dialog, "timebox", buttons);
2305382d832SPeter Avalos
2315382d832SPeter Avalos dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr);
2325382d832SPeter Avalos dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr);
2335382d832SPeter Avalos dlg_draw_title(dialog, title);
2345382d832SPeter Avalos dlg_draw_helpline(dialog, FALSE);
2355382d832SPeter Avalos
2365940c9abSDaniel Fojt dlg_attrset(dialog, dialog_attr);
2375382d832SPeter Avalos dlg_print_autowrap(dialog, prompt, height, width);
2385382d832SPeter Avalos
2395382d832SPeter Avalos /* compute positions of hour, month and year boxes */
2405382d832SPeter Avalos memset(&hr_box, 0, sizeof(hr_box));
2415382d832SPeter Avalos memset(&mn_box, 0, sizeof(mn_box));
2425382d832SPeter Avalos memset(&sc_box, 0, sizeof(sc_box));
2435382d832SPeter Avalos
2445382d832SPeter Avalos if (init_object(&hr_box,
2455382d832SPeter Avalos dialog,
2465382d832SPeter Avalos (width - MIN_WIDE + 1) / 2 + MARGIN,
2475382d832SPeter Avalos (height - MIN_HIGH + MARGIN),
2485382d832SPeter Avalos ONE_WIDE,
2495382d832SPeter Avalos ONE_HIGH,
2505382d832SPeter Avalos 24,
2515382d832SPeter Avalos hour >= 0 ? hour : current.tm_hour,
2525382d832SPeter Avalos 'H') < 0
2535382d832SPeter Avalos || DrawObject(&hr_box) < 0) {
2545382d832SPeter Avalos return CleanupResult(DLG_EXIT_ERROR, dialog, prompt, &save_vars);
2555382d832SPeter Avalos }
2565382d832SPeter Avalos
2575382d832SPeter Avalos mvwprintw(dialog, hr_box.y, hr_box.x + ONE_WIDE + MARGIN, ":");
2585382d832SPeter Avalos if (init_object(&mn_box,
2595382d832SPeter Avalos dialog,
2605382d832SPeter Avalos hr_box.x + (ONE_WIDE + 2 * MARGIN + 1),
2615382d832SPeter Avalos hr_box.y,
2625382d832SPeter Avalos hr_box.width,
2635382d832SPeter Avalos hr_box.height,
2645382d832SPeter Avalos 60,
2655382d832SPeter Avalos minute >= 0 ? minute : current.tm_min,
2665382d832SPeter Avalos 'M') < 0
2675382d832SPeter Avalos || DrawObject(&mn_box) < 0) {
2685382d832SPeter Avalos return CleanupResult(DLG_EXIT_ERROR, dialog, prompt, &save_vars);
2695382d832SPeter Avalos }
2705382d832SPeter Avalos
2715382d832SPeter Avalos mvwprintw(dialog, mn_box.y, mn_box.x + ONE_WIDE + MARGIN, ":");
2725382d832SPeter Avalos if (init_object(&sc_box,
2735382d832SPeter Avalos dialog,
2745382d832SPeter Avalos mn_box.x + (ONE_WIDE + 2 * MARGIN + 1),
2755382d832SPeter Avalos mn_box.y,
2765382d832SPeter Avalos mn_box.width,
2775382d832SPeter Avalos mn_box.height,
2785382d832SPeter Avalos 60,
2795382d832SPeter Avalos second >= 0 ? second : current.tm_sec,
2805382d832SPeter Avalos 'S') < 0
2815382d832SPeter Avalos || DrawObject(&sc_box) < 0) {
2825382d832SPeter Avalos return CleanupResult(DLG_EXIT_ERROR, dialog, prompt, &save_vars);
2835382d832SPeter Avalos }
2845382d832SPeter Avalos
2855382d832SPeter Avalos dlg_trace_win(dialog);
2865382d832SPeter Avalos while (result == DLG_EXIT_UNKNOWN) {
2875382d832SPeter Avalos BOX *obj = (state == sHR ? &hr_box
2885382d832SPeter Avalos : (state == sMN ? &mn_box :
2895382d832SPeter Avalos (state == sSC ? &sc_box : 0)));
2905940c9abSDaniel Fojt int key2;
2915382d832SPeter Avalos
2925382d832SPeter Avalos button = (state < 0) ? 0 : state;
2935382d832SPeter Avalos dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
2945382d832SPeter Avalos if (obj != 0)
2955382d832SPeter Avalos dlg_set_focus(dialog, obj->window);
2965382d832SPeter Avalos
2975382d832SPeter Avalos key = dlg_mouse_wgetch(dialog, &fkey);
2985940c9abSDaniel Fojt if (dlg_result_key(key, fkey, &result)) {
2995940c9abSDaniel Fojt if (!dlg_button_key(result, &button, &key, &fkey))
3005382d832SPeter Avalos break;
3015940c9abSDaniel Fojt }
3025382d832SPeter Avalos
3035382d832SPeter Avalos if ((key2 = dlg_char_to_button(key, buttons)) >= 0) {
3045382d832SPeter Avalos result = key2;
3055382d832SPeter Avalos } else {
3065382d832SPeter Avalos /* handle function-keys */
3075382d832SPeter Avalos if (fkey) {
3085382d832SPeter Avalos switch (key) {
3095382d832SPeter Avalos case DLGK_MOUSE('H'):
3105382d832SPeter Avalos state = sHR;
3115382d832SPeter Avalos break;
3125382d832SPeter Avalos case DLGK_MOUSE('M'):
3135382d832SPeter Avalos state = sMN;
3145382d832SPeter Avalos break;
3155382d832SPeter Avalos case DLGK_MOUSE('S'):
3165382d832SPeter Avalos state = sSC;
3175382d832SPeter Avalos break;
3185940c9abSDaniel Fojt case DLGK_TOGGLE:
3195382d832SPeter Avalos case DLGK_ENTER:
320*a8e38dc0SAntonio Huete Jimenez result = dlg_enter_buttoncode(button);
321*a8e38dc0SAntonio Huete Jimenez break;
322*a8e38dc0SAntonio Huete Jimenez case DLGK_LEAVE:
3235382d832SPeter Avalos result = dlg_ok_buttoncode(button);
3245382d832SPeter Avalos break;
3255382d832SPeter Avalos case DLGK_FIELD_PREV:
3265382d832SPeter Avalos state = dlg_prev_ok_buttonindex(state, sHR);
3275382d832SPeter Avalos break;
3285382d832SPeter Avalos case DLGK_FIELD_NEXT:
3295382d832SPeter Avalos state = dlg_next_ok_buttonindex(state, sHR);
3305382d832SPeter Avalos break;
3315382d832SPeter Avalos case DLGK_FIELD_FIRST:
3325382d832SPeter Avalos if (obj != 0) {
3335382d832SPeter Avalos obj->value = 0;
3345382d832SPeter Avalos (void) DrawObject(obj);
3355382d832SPeter Avalos }
3365382d832SPeter Avalos break;
3375382d832SPeter Avalos case DLGK_FIELD_LAST:
3385382d832SPeter Avalos if (obj != 0) {
3395382d832SPeter Avalos switch (state) {
3405382d832SPeter Avalos case sHR:
3415382d832SPeter Avalos obj->value = 23;
3425382d832SPeter Avalos break;
3435382d832SPeter Avalos case sMN:
3445382d832SPeter Avalos case sSC:
3455382d832SPeter Avalos obj->value = 59;
3465382d832SPeter Avalos break;
3475382d832SPeter Avalos }
3485382d832SPeter Avalos (void) DrawObject(obj);
3495382d832SPeter Avalos }
3505382d832SPeter Avalos break;
3515382d832SPeter Avalos case DLGK_DELETE_RIGHT:
3525382d832SPeter Avalos if (obj != 0) {
3535382d832SPeter Avalos obj->value /= 10;
3545382d832SPeter Avalos (void) DrawObject(obj);
3555382d832SPeter Avalos }
3565382d832SPeter Avalos break;
3575382d832SPeter Avalos #ifdef KEY_RESIZE
3585382d832SPeter Avalos case KEY_RESIZE:
3595940c9abSDaniel Fojt dlg_will_resize(dialog);
3605382d832SPeter Avalos /* reset data */
3615382d832SPeter Avalos height = old_height;
3625382d832SPeter Avalos width = old_width;
3635382d832SPeter Avalos hour = hr_box.value;
3645382d832SPeter Avalos minute = mn_box.value;
3655382d832SPeter Avalos second = sc_box.value;
3665382d832SPeter Avalos /* repaint */
3675940c9abSDaniel Fojt free(prompt);
3685940c9abSDaniel Fojt _dlg_resize_cleanup(dialog);
3695382d832SPeter Avalos goto retry;
3705382d832SPeter Avalos #endif
3715382d832SPeter Avalos default:
3725382d832SPeter Avalos if (is_DLGK_MOUSE(key)) {
3735382d832SPeter Avalos result = dlg_ok_buttoncode(key - M_EVENT);
3745382d832SPeter Avalos if (result < 0)
3755382d832SPeter Avalos result = DLG_EXIT_OK;
3765382d832SPeter Avalos } else if (obj != 0) {
3775382d832SPeter Avalos int step = next_or_previous(key);
3785382d832SPeter Avalos if (step != 0) {
3795382d832SPeter Avalos obj->value += step;
3805382d832SPeter Avalos while (obj->value < 0)
3815382d832SPeter Avalos obj->value += obj->period;
3825382d832SPeter Avalos obj->value %= obj->period;
3835382d832SPeter Avalos (void) DrawObject(obj);
3845382d832SPeter Avalos }
3855382d832SPeter Avalos }
3865382d832SPeter Avalos break;
3875382d832SPeter Avalos }
3885382d832SPeter Avalos } else if (isdigit(key)) {
3895382d832SPeter Avalos if (obj != 0) {
3905382d832SPeter Avalos int digit = (key - '0');
3915382d832SPeter Avalos int value = (obj->value * 10) + digit;
3925382d832SPeter Avalos if (value < obj->period) {
3935382d832SPeter Avalos obj->value = value;
3945382d832SPeter Avalos (void) DrawObject(obj);
3955382d832SPeter Avalos } else {
3965382d832SPeter Avalos beep();
3975382d832SPeter Avalos }
3985382d832SPeter Avalos }
3995940c9abSDaniel Fojt } else if (key > 0) {
4005382d832SPeter Avalos beep();
4015382d832SPeter Avalos }
4025382d832SPeter Avalos }
4035382d832SPeter Avalos }
4045382d832SPeter Avalos
4055382d832SPeter Avalos #define DefaultFormat(dst, src) \
4065382d832SPeter Avalos sprintf(dst, "%02d:%02d:%02d", \
4075382d832SPeter Avalos hr_box.value, mn_box.value, sc_box.value)
4085382d832SPeter Avalos
4095382d832SPeter Avalos #if defined(HAVE_STRFTIME)
4105382d832SPeter Avalos if (dialog_vars.time_format != 0) {
4115382d832SPeter Avalos size_t used;
4125382d832SPeter Avalos time_t now = time((time_t *) 0);
4135382d832SPeter Avalos struct tm *parts = localtime(&now);
4145382d832SPeter Avalos
4155382d832SPeter Avalos parts->tm_sec = sc_box.value;
4165382d832SPeter Avalos parts->tm_min = mn_box.value;
4175382d832SPeter Avalos parts->tm_hour = hr_box.value;
4185382d832SPeter Avalos used = strftime(buffer,
4195382d832SPeter Avalos sizeof(buffer) - 1,
4205382d832SPeter Avalos dialog_vars.time_format,
4215382d832SPeter Avalos parts);
4225382d832SPeter Avalos if (used == 0 || *buffer == '\0')
4235382d832SPeter Avalos DefaultFormat(buffer, hr_box);
4245382d832SPeter Avalos } else
4255382d832SPeter Avalos #endif
4265382d832SPeter Avalos DefaultFormat(buffer, hr_box);
4275382d832SPeter Avalos
4285382d832SPeter Avalos dlg_add_result(buffer);
4295940c9abSDaniel Fojt AddLastKey();
4305382d832SPeter Avalos
4315382d832SPeter Avalos return CleanupResult(result, dialog, prompt, &save_vars);
4325382d832SPeter Avalos }
433