2021-11-24 08:42:13 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*
|
2022-01-28 08:14:55 +00:00
|
|
|
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
2021-11-24 08:42:13 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2021-12-06 10:35:28 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
|
2021-12-21 15:06:19 +00:00
|
|
|
#include <ctype.h>
|
2022-01-28 08:14:55 +00:00
|
|
|
#include <curses.h>
|
2021-12-06 10:35:28 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2021-11-24 08:42:13 +00:00
|
|
|
#include "bsddialog.h"
|
2022-09-03 14:36:16 +00:00
|
|
|
#include "bsddialog_theme.h"
|
2022-01-28 08:14:55 +00:00
|
|
|
#include "lib_util.h"
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
#define MINWDATE 23 /* 3 windows and their borders */
|
|
|
|
#define MINWTIME 14 /* 3 windows and their borders */
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
static void
|
2022-09-25 13:04:33 +00:00
|
|
|
drawsquare(struct bsddialog_conf *conf, WINDOW *win, const char *fmt,
|
2022-09-03 14:36:16 +00:00
|
|
|
const void *value, bool focus)
|
|
|
|
{
|
|
|
|
int h, l, w;
|
|
|
|
|
|
|
|
getmaxyx(win, h, w);
|
|
|
|
draw_borders(conf, win, h, w, LOWERED);
|
|
|
|
if (focus) {
|
|
|
|
l = 2 + w%2;
|
|
|
|
wattron(win, t.dialog.arrowcolor);
|
|
|
|
mvwhline(win, 0, w/2 - l/2,
|
|
|
|
conf->ascii_lines ? '^' : ACS_UARROW, l);
|
|
|
|
mvwhline(win, h-1, w/2 - l/2,
|
|
|
|
conf->ascii_lines ? 'v' : ACS_DARROW, l);
|
|
|
|
wattroff(win, t.dialog.arrowcolor);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (focus)
|
|
|
|
wattron(win, t.menu.f_namecolor);
|
|
|
|
if (strchr(fmt, 's') != NULL)
|
|
|
|
mvwprintw(win, 1, 1, fmt, (const char*)value);
|
|
|
|
else
|
|
|
|
mvwprintw(win, 1, 1, fmt, *((const int*)value));
|
|
|
|
if (focus)
|
|
|
|
wattroff(win, t.menu.f_namecolor);
|
|
|
|
|
|
|
|
wrefresh(win);
|
|
|
|
}
|
|
|
|
|
2021-12-06 10:35:28 +00:00
|
|
|
static int
|
|
|
|
datetime_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h,
|
2022-01-28 08:14:55 +00:00
|
|
|
int *w, int minw, const char *text, struct buttons bs)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
2022-01-28 08:14:55 +00:00
|
|
|
int htext, wtext;
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if (cols == BSDDIALOG_AUTOSIZE || rows == BSDDIALOG_AUTOSIZE) {
|
|
|
|
if (text_size(conf, rows, cols, text, &bs, 3, minw, &htext,
|
|
|
|
&wtext) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if (cols == BSDDIALOG_AUTOSIZE)
|
2022-09-03 14:36:16 +00:00
|
|
|
*w = widget_min_width(conf, wtext, minw, &bs);
|
2022-01-28 08:14:55 +00:00
|
|
|
|
|
|
|
if (rows == BSDDIALOG_AUTOSIZE)
|
|
|
|
*h = widget_min_height(conf, htext, 3 /* windows */, true);
|
|
|
|
|
|
|
|
return (0);
|
2021-12-06 10:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2022-01-28 08:14:55 +00:00
|
|
|
datetime_checksize(int rows, int cols, int minw, struct buttons bs)
|
2021-12-06 10:35:28 +00:00
|
|
|
{
|
|
|
|
int mincols;
|
|
|
|
|
|
|
|
mincols = VBORDERS;
|
2022-09-03 14:36:16 +00:00
|
|
|
mincols += buttons_min_width(bs);
|
2021-12-06 10:35:28 +00:00
|
|
|
mincols = MAX(minw, mincols);
|
|
|
|
|
|
|
|
if (cols < mincols)
|
|
|
|
RETURN_ERROR("Few cols for this timebox/datebox");
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if (rows < 7) /* 2 button + 2 borders + 3 windows */
|
|
|
|
RETURN_ERROR("Few rows for this timebox/datebox, at least 7");
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
return (0);
|
2021-12-06 10:35:28 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
int
|
|
|
|
bsddialog_timebox(struct bsddialog_conf *conf, const char* text, int rows,
|
|
|
|
int cols, unsigned int *hh, unsigned int *mm, unsigned int *ss)
|
2021-12-06 10:35:28 +00:00
|
|
|
{
|
2022-03-13 01:34:57 +00:00
|
|
|
bool loop, focusbuttons;
|
2022-09-03 14:36:16 +00:00
|
|
|
int i, retval, y, x, h, w, sel;
|
|
|
|
wint_t input;
|
2021-12-06 10:35:28 +00:00
|
|
|
WINDOW *widget, *textpad, *shadow;
|
|
|
|
struct buttons bs;
|
2021-11-24 08:42:13 +00:00
|
|
|
struct myclockstruct {
|
|
|
|
unsigned int max;
|
2021-12-06 10:35:28 +00:00
|
|
|
unsigned int value;
|
2021-11-24 08:42:13 +00:00
|
|
|
WINDOW *win;
|
2021-12-06 10:35:28 +00:00
|
|
|
};
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2021-12-06 10:35:28 +00:00
|
|
|
if (hh == NULL || mm == NULL || ss == NULL)
|
|
|
|
RETURN_ERROR("hh / mm / ss cannot be NULL");
|
|
|
|
|
|
|
|
struct myclockstruct c[3] = {
|
|
|
|
{23, *hh, NULL},
|
|
|
|
{59, *mm, NULL},
|
|
|
|
{59, *ss, NULL}
|
|
|
|
};
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2021-12-06 10:35:28 +00:00
|
|
|
for (i = 0 ; i < 3; i++) {
|
|
|
|
if (c[i].value > c[i].max)
|
|
|
|
c[i].value = c[i].max;
|
|
|
|
}
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
get_buttons(conf, &bs, BUTTON_OK_LABEL, BUTTON_CANCEL_LABEL);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2021-12-06 10:35:28 +00:00
|
|
|
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
if (datetime_autosize(conf, rows, cols, &h, &w, MINWTIME, text,
|
|
|
|
bs) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
if (datetime_checksize(h, w, MINWTIME, bs) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, &bs,
|
|
|
|
true) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
pnoutrefresh(textpad, 0, 0, y+1, x+2, y+h-7, x+w-2);
|
|
|
|
doupdate();
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
c[0].win = new_boxed_window(conf, y+h-6, x + w/2 - 7, 3, 4, LOWERED);
|
2021-12-06 10:35:28 +00:00
|
|
|
mvwaddch(widget, h - 5, w/2 - 3, ':');
|
2022-01-28 08:14:55 +00:00
|
|
|
c[1].win = new_boxed_window(conf, y+h-6, x + w/2 - 2, 3, 4, LOWERED);
|
2021-12-06 10:35:28 +00:00
|
|
|
mvwaddch(widget, h - 5, w/2 + 2, ':');
|
2022-01-28 08:14:55 +00:00
|
|
|
c[2].win = new_boxed_window(conf, y+h-6, x + w/2 + 3, 3, 4, LOWERED);
|
2021-12-06 10:35:28 +00:00
|
|
|
|
|
|
|
wrefresh(widget);
|
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
sel = -1;
|
2022-03-13 01:34:57 +00:00
|
|
|
loop = focusbuttons = true;
|
2022-01-28 08:14:55 +00:00
|
|
|
while (loop) {
|
2022-09-03 14:36:16 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
2022-09-25 13:04:33 +00:00
|
|
|
drawsquare(conf, c[i].win, "%02d", &c[i].value,
|
2022-09-03 14:36:16 +00:00
|
|
|
sel == i);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
if (get_wch(&input) == ERR)
|
|
|
|
continue;
|
2021-11-24 08:42:13 +00:00
|
|
|
switch(input) {
|
2021-12-06 10:35:28 +00:00
|
|
|
case KEY_ENTER:
|
2021-11-24 08:42:13 +00:00
|
|
|
case 10: /* Enter */
|
2022-09-03 14:36:16 +00:00
|
|
|
if (focusbuttons || conf->button.always_active) {
|
|
|
|
retval = bs.value[bs.curr];
|
|
|
|
loop = false;
|
|
|
|
}
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
|
|
|
case 27: /* Esc */
|
2022-01-28 08:14:55 +00:00
|
|
|
if (conf->key.enable_esc) {
|
2022-09-03 14:36:16 +00:00
|
|
|
retval = BSDDIALOG_ESC;
|
2022-01-28 08:14:55 +00:00
|
|
|
loop = false;
|
|
|
|
}
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
2022-03-13 01:34:57 +00:00
|
|
|
case KEY_RIGHT:
|
2021-11-24 08:42:13 +00:00
|
|
|
case '\t': /* TAB */
|
2022-03-13 01:34:57 +00:00
|
|
|
if (focusbuttons) {
|
|
|
|
bs.curr++;
|
|
|
|
focusbuttons = bs.curr < (int)bs.nbuttons ?
|
|
|
|
true : false;
|
|
|
|
if (focusbuttons == false) {
|
|
|
|
sel = 0;
|
2022-09-03 14:36:16 +00:00
|
|
|
bs.curr = conf->button.always_active ? 0 : -1;
|
2022-03-13 01:34:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sel++;
|
|
|
|
focusbuttons = sel > 2 ? true : false;
|
|
|
|
if (focusbuttons) {
|
|
|
|
bs.curr = 0;
|
|
|
|
}
|
|
|
|
}
|
2022-01-28 08:14:55 +00:00
|
|
|
draw_buttons(widget, bs, true);
|
|
|
|
wrefresh(widget);
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
2022-03-13 01:34:57 +00:00
|
|
|
if (focusbuttons) {
|
|
|
|
bs.curr--;
|
|
|
|
focusbuttons = bs.curr < 0 ? false : true;
|
|
|
|
if (focusbuttons == false) {
|
|
|
|
sel = 2;
|
2022-09-03 14:36:16 +00:00
|
|
|
bs.curr = conf->button.always_active ? 0 : -1;
|
2022-03-13 01:34:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sel--;
|
|
|
|
focusbuttons = sel < 0 ? true : false;
|
2022-09-03 14:36:16 +00:00
|
|
|
if (focusbuttons)
|
2022-03-13 01:34:57 +00:00
|
|
|
bs.curr = (int)bs.nbuttons - 1;
|
|
|
|
}
|
|
|
|
draw_buttons(widget, bs, true);
|
|
|
|
wrefresh(widget);
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
|
|
|
case KEY_UP:
|
2022-09-03 14:36:16 +00:00
|
|
|
if (focusbuttons) {
|
|
|
|
sel = 0;
|
|
|
|
focusbuttons = false;
|
|
|
|
bs.curr = conf->button.always_active ? 0 : -1;
|
|
|
|
draw_buttons(widget, bs, true);
|
|
|
|
wrefresh(widget);
|
|
|
|
} else { c[sel].value = c[sel].value > 0 ?
|
2022-01-28 08:14:55 +00:00
|
|
|
c[sel].value - 1 : c[sel].max;
|
2022-09-03 14:36:16 +00:00
|
|
|
}
|
2021-12-06 10:35:28 +00:00
|
|
|
break;
|
2022-03-13 01:34:57 +00:00
|
|
|
case KEY_DOWN:
|
|
|
|
if (focusbuttons)
|
|
|
|
break;
|
|
|
|
c[sel].value = c[sel].value < c[sel].max ?
|
|
|
|
c[sel].value + 1 : 0;
|
|
|
|
break;
|
2021-12-06 10:35:28 +00:00
|
|
|
case KEY_F(1):
|
2022-03-13 01:34:57 +00:00
|
|
|
if (conf->key.f1_file == NULL &&
|
|
|
|
conf->key.f1_message == NULL)
|
2021-12-06 10:35:28 +00:00
|
|
|
break;
|
|
|
|
if (f1help(conf) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
/* No break, screen size can change */
|
2021-12-06 10:35:28 +00:00
|
|
|
case KEY_RESIZE:
|
2022-01-28 08:14:55 +00:00
|
|
|
/* Important for decreasing screen */
|
|
|
|
hide_widget(y, x, h, w, conf->shadow);
|
2021-12-06 10:35:28 +00:00
|
|
|
refresh();
|
|
|
|
|
|
|
|
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
if (datetime_autosize(conf, rows, cols, &h, &w,
|
|
|
|
MINWTIME, text, bs) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
if (datetime_checksize(h, w, MINWTIME, bs) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if (update_dialog(conf, shadow, widget, y, x, h, w,
|
|
|
|
textpad, text, &bs, true) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
doupdate();
|
2021-12-06 10:35:28 +00:00
|
|
|
|
|
|
|
mvwaddch(widget, h - 5, w/2 - 3, ':');
|
|
|
|
mvwaddch(widget, h - 5, w/2 + 2, ':');
|
|
|
|
wrefresh(widget);
|
|
|
|
|
|
|
|
prefresh(textpad, 0, 0, y+1, x+2, y+h-7, x+w-2);
|
|
|
|
|
|
|
|
wclear(c[0].win);
|
|
|
|
mvwin(c[0].win, y + h - 6, x + w/2 - 7);
|
|
|
|
wclear(c[1].win);
|
|
|
|
mvwin(c[1].win, y + h - 6, x + w/2 - 2);
|
|
|
|
wclear(c[2].win);
|
|
|
|
mvwin(c[2].win, y + h - 6, x + w/2 + 3);
|
|
|
|
|
|
|
|
/* Important to avoid grey lines expanding screen */
|
|
|
|
refresh();
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
2021-12-06 10:35:28 +00:00
|
|
|
default:
|
2022-01-28 08:14:55 +00:00
|
|
|
if (shortcut_buttons(input, &bs)) {
|
2022-09-03 14:36:16 +00:00
|
|
|
retval = bs.value[bs.curr];
|
2022-01-28 08:14:55 +00:00
|
|
|
loop = false;
|
2021-12-06 10:35:28 +00:00
|
|
|
}
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
if (retval == BSDDIALOG_OK) {
|
2022-03-13 01:34:57 +00:00
|
|
|
*hh = c[0].value;
|
|
|
|
*mm = c[1].value;
|
|
|
|
*ss = c[2].value;
|
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
2021-11-24 08:42:13 +00:00
|
|
|
delwin(c[i].win);
|
2022-01-28 08:14:55 +00:00
|
|
|
end_dialog(conf, shadow, widget, textpad);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
return (retval);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 10:35:28 +00:00
|
|
|
int
|
2022-01-28 08:14:55 +00:00
|
|
|
bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
|
|
|
|
int cols, unsigned int *yy, unsigned int *mm, unsigned int *dd)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
2022-03-13 01:34:57 +00:00
|
|
|
bool loop, focusbuttons;
|
2022-09-03 14:36:16 +00:00
|
|
|
int i, retval, y, x, h, w, sel;
|
|
|
|
wint_t input;
|
2021-12-06 10:35:28 +00:00
|
|
|
WINDOW *widget, *textpad, *shadow;
|
2021-11-24 08:42:13 +00:00
|
|
|
struct buttons bs;
|
|
|
|
struct calendar {
|
2021-12-06 10:35:28 +00:00
|
|
|
int max;
|
|
|
|
int value;
|
2021-11-24 08:42:13 +00:00
|
|
|
WINDOW *win;
|
|
|
|
unsigned int x;
|
2021-12-06 10:35:28 +00:00
|
|
|
};
|
2021-11-24 08:42:13 +00:00
|
|
|
struct month {
|
2022-03-13 01:34:57 +00:00
|
|
|
const char *name;
|
2021-11-24 08:42:13 +00:00
|
|
|
unsigned int days;
|
|
|
|
};
|
|
|
|
|
2021-12-06 10:35:28 +00:00
|
|
|
if (yy == NULL || mm == NULL || dd == NULL)
|
|
|
|
RETURN_ERROR("yy / mm / dd cannot be NULL");
|
|
|
|
|
|
|
|
struct calendar c[3] = {
|
|
|
|
{9999, *yy, NULL, 4 },
|
|
|
|
{12, *mm, NULL, 9 },
|
|
|
|
{31, *dd, NULL, 2 }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct month m[12] = {
|
|
|
|
{ "January", 31 }, { "February", 28 }, { "March", 31 },
|
|
|
|
{ "April", 30 }, { "May", 31 }, { "June", 30 },
|
|
|
|
{ "July", 31 }, { "August", 31 }, { "September", 30 },
|
|
|
|
{ "October", 31 }, { "November", 30 }, { "December", 31 }
|
|
|
|
};
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2021-12-06 10:35:28 +00:00
|
|
|
for (i = 0 ; i < 3; i++) {
|
|
|
|
if (c[i].value > c[i].max)
|
|
|
|
c[i].value = c[i].max;
|
|
|
|
if (c[i].value < 1)
|
|
|
|
c[i].value = 1;
|
|
|
|
}
|
|
|
|
c[2].max = m[c[1].value -1].days;
|
2022-09-25 13:04:33 +00:00
|
|
|
if (c[1].value == 2 && ISLEAP(c[0].value))
|
2021-12-06 10:35:28 +00:00
|
|
|
c[2].max = 29;
|
|
|
|
if (c[2].value > c[2].max)
|
|
|
|
c[2].value = c[2].max;
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
get_buttons(conf, &bs, BUTTON_OK_LABEL, BUTTON_CANCEL_LABEL);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2021-12-06 10:35:28 +00:00
|
|
|
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
if (datetime_autosize(conf, rows, cols, &h, &w, MINWDATE, text,
|
|
|
|
bs) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
if (datetime_checksize(h, w, MINWDATE, bs) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, &bs,
|
|
|
|
true) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
pnoutrefresh(textpad, 0, 0, y+1, x+2, y+h-7, x+w-2);
|
|
|
|
doupdate();
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
c[0].win = new_boxed_window(conf, y+h-6, x + w/2 - 11, 3, 6, LOWERED);
|
2021-12-06 10:35:28 +00:00
|
|
|
mvwaddch(widget, h - 5, w/2 - 5, '/');
|
2022-01-28 08:14:55 +00:00
|
|
|
c[1].win = new_boxed_window(conf, y+h-6, x + w/2 - 4, 3, 11, LOWERED);
|
2021-12-06 10:35:28 +00:00
|
|
|
mvwaddch(widget, h - 5, w/2 + 7, '/');
|
2022-01-28 08:14:55 +00:00
|
|
|
c[2].win = new_boxed_window(conf, y+h-6, x + w/2 + 8, 3, 4, LOWERED);
|
|
|
|
|
2021-12-06 10:35:28 +00:00
|
|
|
wrefresh(widget);
|
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
sel = -1;
|
2022-03-13 01:34:57 +00:00
|
|
|
loop = focusbuttons = true;
|
2022-01-28 08:14:55 +00:00
|
|
|
while (loop) {
|
2022-09-25 13:04:33 +00:00
|
|
|
drawsquare(conf, c[0].win, "%4d", &c[0].value, sel == 0);
|
|
|
|
drawsquare(conf, c[1].win, "%9s", m[c[1].value-1].name,
|
2022-09-03 14:36:16 +00:00
|
|
|
sel == 1);
|
2022-09-25 13:04:33 +00:00
|
|
|
drawsquare(conf, c[2].win, "%02d", &c[2].value, sel == 2);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
if (get_wch(&input) == ERR)
|
|
|
|
continue;
|
2021-11-24 08:42:13 +00:00
|
|
|
switch(input) {
|
2021-12-06 10:35:28 +00:00
|
|
|
case KEY_ENTER:
|
|
|
|
case 10: /* Enter */
|
2022-09-03 14:36:16 +00:00
|
|
|
if (focusbuttons || conf->button.always_active) {
|
|
|
|
retval = bs.value[bs.curr];
|
|
|
|
loop = false;
|
|
|
|
}
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
2021-12-06 10:35:28 +00:00
|
|
|
case 27: /* Esc */
|
2022-01-28 08:14:55 +00:00
|
|
|
if (conf->key.enable_esc) {
|
2022-09-03 14:36:16 +00:00
|
|
|
retval = BSDDIALOG_ESC;
|
2022-01-28 08:14:55 +00:00
|
|
|
loop = false;
|
|
|
|
}
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
2022-03-13 01:34:57 +00:00
|
|
|
case KEY_RIGHT:
|
2021-12-06 10:35:28 +00:00
|
|
|
case '\t': /* TAB */
|
2022-03-13 01:34:57 +00:00
|
|
|
if (focusbuttons) {
|
|
|
|
bs.curr++;
|
|
|
|
focusbuttons = bs.curr < (int)bs.nbuttons ?
|
|
|
|
true : false;
|
|
|
|
if (focusbuttons == false) {
|
|
|
|
sel = 0;
|
2022-09-03 14:36:16 +00:00
|
|
|
bs.curr = conf->button.always_active ? 0 : -1;
|
2022-03-13 01:34:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sel++;
|
|
|
|
focusbuttons = sel > 2 ? true : false;
|
|
|
|
if (focusbuttons) {
|
|
|
|
bs.curr = 0;
|
|
|
|
}
|
|
|
|
}
|
2022-01-28 08:14:55 +00:00
|
|
|
draw_buttons(widget, bs, true);
|
|
|
|
wrefresh(widget);
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
2022-03-13 01:34:57 +00:00
|
|
|
if (focusbuttons) {
|
|
|
|
bs.curr--;
|
|
|
|
focusbuttons = bs.curr < 0 ? false : true;
|
|
|
|
if (focusbuttons == false) {
|
|
|
|
sel = 2;
|
2022-09-03 14:36:16 +00:00
|
|
|
bs.curr = conf->button.always_active ? 0 : -1;
|
2022-03-13 01:34:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sel--;
|
|
|
|
focusbuttons = sel < 0 ? true : false;
|
2022-09-03 14:36:16 +00:00
|
|
|
if (focusbuttons)
|
2022-03-13 01:34:57 +00:00
|
|
|
bs.curr = (int)bs.nbuttons - 1;
|
|
|
|
}
|
|
|
|
draw_buttons(widget, bs, true);
|
|
|
|
wrefresh(widget);
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
|
|
|
case KEY_UP:
|
2022-09-03 14:36:16 +00:00
|
|
|
if (focusbuttons) {
|
|
|
|
sel = 0;
|
|
|
|
focusbuttons = false;
|
|
|
|
bs.curr = conf->button.always_active ? 0 : -1;
|
|
|
|
draw_buttons(widget, bs, true);
|
|
|
|
wrefresh(widget);
|
|
|
|
} else {
|
|
|
|
c[sel].value = c[sel].value > 1 ?
|
|
|
|
c[sel].value - 1 : c[sel].max ;
|
|
|
|
/* if mount change */
|
|
|
|
c[2].max = m[c[1].value -1].days;
|
|
|
|
/* if year change */
|
2022-09-25 13:04:33 +00:00
|
|
|
if (c[1].value == 2 && ISLEAP(c[0].value))
|
2022-09-03 14:36:16 +00:00
|
|
|
c[2].max = 29;
|
|
|
|
/* set new day */
|
|
|
|
if (c[2].value > c[2].max)
|
|
|
|
c[2].value = c[2].max;
|
|
|
|
}
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
|
|
|
case KEY_DOWN:
|
2022-03-13 01:34:57 +00:00
|
|
|
if (focusbuttons)
|
|
|
|
break;
|
2022-01-28 08:14:55 +00:00
|
|
|
c[sel].value = c[sel].value < c[sel].max ?
|
|
|
|
c[sel].value + 1 : 1;
|
2021-12-06 10:35:28 +00:00
|
|
|
/* if mount change */
|
|
|
|
c[2].max = m[c[1].value -1].days;
|
|
|
|
/* if year change */
|
2022-09-25 13:04:33 +00:00
|
|
|
if (c[1].value == 2 && ISLEAP(c[0].value))
|
2021-12-06 10:35:28 +00:00
|
|
|
c[2].max = 29;
|
|
|
|
/* set new day */
|
|
|
|
if (c[2].value > c[2].max)
|
|
|
|
c[2].value = c[2].max;
|
|
|
|
break;
|
|
|
|
case KEY_F(1):
|
2022-03-13 01:34:57 +00:00
|
|
|
if (conf->key.f1_file == NULL &&
|
|
|
|
conf->key.f1_message == NULL)
|
2021-12-06 10:35:28 +00:00
|
|
|
break;
|
|
|
|
if (f1help(conf) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
/* No break, screen size can change */
|
2021-12-06 10:35:28 +00:00
|
|
|
case KEY_RESIZE:
|
2022-01-28 08:14:55 +00:00
|
|
|
/* Important for decreasing screen */
|
|
|
|
hide_widget(y, x, h, w, conf->shadow);
|
2021-12-06 10:35:28 +00:00
|
|
|
refresh();
|
|
|
|
|
|
|
|
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
if (datetime_autosize(conf, rows, cols, &h, &w,
|
|
|
|
MINWDATE, text, bs) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
if (datetime_checksize(h, w, MINWDATE, bs) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if (update_dialog(conf, shadow, widget, y, x, h, w,
|
|
|
|
textpad, text, &bs, true) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
doupdate();
|
2021-12-06 10:35:28 +00:00
|
|
|
|
|
|
|
mvwaddch(widget, h - 5, w/2 - 5, '/');
|
|
|
|
mvwaddch(widget, h - 5, w/2 + 7, '/');
|
|
|
|
wrefresh(widget);
|
|
|
|
|
|
|
|
prefresh(textpad, 0, 0, y+1, x+2, y+h-7, x+w-2);
|
|
|
|
|
|
|
|
wclear(c[0].win);
|
|
|
|
mvwin(c[0].win, y + h - 6, x + w/2 - 11);
|
|
|
|
wclear(c[1].win);
|
|
|
|
mvwin(c[1].win, y + h - 6, x + w/2 - 4);
|
|
|
|
wclear(c[2].win);
|
|
|
|
mvwin(c[2].win, y + h - 6, x + w/2 + 8);
|
|
|
|
|
|
|
|
/* Important to avoid grey lines expanding screen */
|
|
|
|
refresh();
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
2021-12-06 10:35:28 +00:00
|
|
|
default:
|
2022-01-28 08:14:55 +00:00
|
|
|
if (shortcut_buttons(input, &bs)) {
|
2022-09-03 14:36:16 +00:00
|
|
|
retval = bs.value[bs.curr];
|
2022-01-28 08:14:55 +00:00
|
|
|
loop = false;
|
2021-12-06 10:35:28 +00:00
|
|
|
}
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
if (retval == BSDDIALOG_OK) {
|
2022-03-13 01:34:57 +00:00
|
|
|
*yy = c[0].value;
|
|
|
|
*mm = c[1].value;
|
|
|
|
*dd = c[2].value;
|
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
2021-11-24 08:42:13 +00:00
|
|
|
delwin(c[i].win);
|
2022-01-28 08:14:55 +00:00
|
|
|
end_dialog(conf, shadow, widget, textpad);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
return (retval);
|
2022-09-25 13:04:33 +00:00
|
|
|
}
|