timebox.c (b319d934379f5b819cd195be7e03dbd407566fd4) timebox.c (84823cc70824c8d842f503d8c2e6d7b0c2d95b61)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2021-2022 Alfonso Sabato Siciliano
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 25 unchanged lines hidden (view full) ---

34#include "bsddialog.h"
35#include "bsddialog_theme.h"
36#include "lib_util.h"
37
38#define MINWDATE 23 /* 3 windows and their borders */
39#define MINWTIME 14 /* 3 windows and their borders */
40
41static void
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2021-2022 Alfonso Sabato Siciliano
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 25 unchanged lines hidden (view full) ---

34#include "bsddialog.h"
35#include "bsddialog_theme.h"
36#include "lib_util.h"
37
38#define MINWDATE 23 /* 3 windows and their borders */
39#define MINWTIME 14 /* 3 windows and their borders */
40
41static void
42drawquare(struct bsddialog_conf *conf, WINDOW *win, const char *fmt,
42drawsquare(struct bsddialog_conf *conf, WINDOW *win, const char *fmt,
43 const void *value, bool focus)
44{
45 int h, l, w;
46
47 getmaxyx(win, h, w);
48 draw_borders(conf, win, h, w, LOWERED);
49 if (focus) {
50 l = 2 + w%2;

--- 111 unchanged lines hidden (view full) ---

162 c[2].win = new_boxed_window(conf, y+h-6, x + w/2 + 3, 3, 4, LOWERED);
163
164 wrefresh(widget);
165
166 sel = -1;
167 loop = focusbuttons = true;
168 while (loop) {
169 for (i = 0; i < 3; i++)
43 const void *value, bool focus)
44{
45 int h, l, w;
46
47 getmaxyx(win, h, w);
48 draw_borders(conf, win, h, w, LOWERED);
49 if (focus) {
50 l = 2 + w%2;

--- 111 unchanged lines hidden (view full) ---

162 c[2].win = new_boxed_window(conf, y+h-6, x + w/2 + 3, 3, 4, LOWERED);
163
164 wrefresh(widget);
165
166 sel = -1;
167 loop = focusbuttons = true;
168 while (loop) {
169 for (i = 0; i < 3; i++)
170 drawquare(conf, c[i].win, "%02d", &c[i].value,
170 drawsquare(conf, c[i].win, "%02d", &c[i].value,
171 sel == i);
172
173 if (get_wch(&input) == ERR)
174 continue;
175 switch(input) {
176 case KEY_ENTER:
177 case 10: /* Enter */
178 if (focusbuttons || conf->button.always_active) {

--- 157 unchanged lines hidden (view full) ---

336
337 struct month m[12] = {
338 { "January", 31 }, { "February", 28 }, { "March", 31 },
339 { "April", 30 }, { "May", 31 }, { "June", 30 },
340 { "July", 31 }, { "August", 31 }, { "September", 30 },
341 { "October", 31 }, { "November", 30 }, { "December", 31 }
342 };
343
171 sel == i);
172
173 if (get_wch(&input) == ERR)
174 continue;
175 switch(input) {
176 case KEY_ENTER:
177 case 10: /* Enter */
178 if (focusbuttons || conf->button.always_active) {

--- 157 unchanged lines hidden (view full) ---

336
337 struct month m[12] = {
338 { "January", 31 }, { "February", 28 }, { "March", 31 },
339 { "April", 30 }, { "May", 31 }, { "June", 30 },
340 { "July", 31 }, { "August", 31 }, { "September", 30 },
341 { "October", 31 }, { "November", 30 }, { "December", 31 }
342 };
343
344#define ISLEAF(year) ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
345
346 for (i = 0 ; i < 3; i++) {
347 if (c[i].value > c[i].max)
348 c[i].value = c[i].max;
349 if (c[i].value < 1)
350 c[i].value = 1;
351 }
352 c[2].max = m[c[1].value -1].days;
344 for (i = 0 ; i < 3; i++) {
345 if (c[i].value > c[i].max)
346 c[i].value = c[i].max;
347 if (c[i].value < 1)
348 c[i].value = 1;
349 }
350 c[2].max = m[c[1].value -1].days;
353 if (c[1].value == 2 && ISLEAF(c[0].value))
351 if (c[1].value == 2 && ISLEAP(c[0].value))
354 c[2].max = 29;
355 if (c[2].value > c[2].max)
356 c[2].value = c[2].max;
357
358 get_buttons(conf, &bs, BUTTON_OK_LABEL, BUTTON_CANCEL_LABEL);
359
360 if (set_widget_size(conf, rows, cols, &h, &w) != 0)
361 return (BSDDIALOG_ERROR);

--- 18 unchanged lines hidden (view full) ---

380 mvwaddch(widget, h - 5, w/2 + 7, '/');
381 c[2].win = new_boxed_window(conf, y+h-6, x + w/2 + 8, 3, 4, LOWERED);
382
383 wrefresh(widget);
384
385 sel = -1;
386 loop = focusbuttons = true;
387 while (loop) {
352 c[2].max = 29;
353 if (c[2].value > c[2].max)
354 c[2].value = c[2].max;
355
356 get_buttons(conf, &bs, BUTTON_OK_LABEL, BUTTON_CANCEL_LABEL);
357
358 if (set_widget_size(conf, rows, cols, &h, &w) != 0)
359 return (BSDDIALOG_ERROR);

--- 18 unchanged lines hidden (view full) ---

378 mvwaddch(widget, h - 5, w/2 + 7, '/');
379 c[2].win = new_boxed_window(conf, y+h-6, x + w/2 + 8, 3, 4, LOWERED);
380
381 wrefresh(widget);
382
383 sel = -1;
384 loop = focusbuttons = true;
385 while (loop) {
388 drawquare(conf, c[0].win, "%4d", &c[0].value, sel == 0);
389 drawquare(conf, c[1].win, "%9s", m[c[1].value-1].name,
386 drawsquare(conf, c[0].win, "%4d", &c[0].value, sel == 0);
387 drawsquare(conf, c[1].win, "%9s", m[c[1].value-1].name,
390 sel == 1);
388 sel == 1);
391 drawquare(conf, c[2].win, "%02d", &c[2].value, sel == 2);
389 drawsquare(conf, c[2].win, "%02d", &c[2].value, sel == 2);
392
393 if (get_wch(&input) == ERR)
394 continue;
395 switch(input) {
396 case KEY_ENTER:
397 case 10: /* Enter */
398 if (focusbuttons || conf->button.always_active) {
399 retval = bs.value[bs.curr];

--- 51 unchanged lines hidden (view full) ---

451 draw_buttons(widget, bs, true);
452 wrefresh(widget);
453 } else {
454 c[sel].value = c[sel].value > 1 ?
455 c[sel].value - 1 : c[sel].max ;
456 /* if mount change */
457 c[2].max = m[c[1].value -1].days;
458 /* if year change */
390
391 if (get_wch(&input) == ERR)
392 continue;
393 switch(input) {
394 case KEY_ENTER:
395 case 10: /* Enter */
396 if (focusbuttons || conf->button.always_active) {
397 retval = bs.value[bs.curr];

--- 51 unchanged lines hidden (view full) ---

449 draw_buttons(widget, bs, true);
450 wrefresh(widget);
451 } else {
452 c[sel].value = c[sel].value > 1 ?
453 c[sel].value - 1 : c[sel].max ;
454 /* if mount change */
455 c[2].max = m[c[1].value -1].days;
456 /* if year change */
459 if (c[1].value == 2 && ISLEAF(c[0].value))
457 if (c[1].value == 2 && ISLEAP(c[0].value))
460 c[2].max = 29;
461 /* set new day */
462 if (c[2].value > c[2].max)
463 c[2].value = c[2].max;
464 }
465 break;
466 case KEY_DOWN:
467 if (focusbuttons)
468 break;
469 c[sel].value = c[sel].value < c[sel].max ?
470 c[sel].value + 1 : 1;
471 /* if mount change */
472 c[2].max = m[c[1].value -1].days;
473 /* if year change */
458 c[2].max = 29;
459 /* set new day */
460 if (c[2].value > c[2].max)
461 c[2].value = c[2].max;
462 }
463 break;
464 case KEY_DOWN:
465 if (focusbuttons)
466 break;
467 c[sel].value = c[sel].value < c[sel].max ?
468 c[sel].value + 1 : 1;
469 /* if mount change */
470 c[2].max = m[c[1].value -1].days;
471 /* if year change */
474 if (c[1].value == 2 && ISLEAF(c[0].value))
472 if (c[1].value == 2 && ISLEAP(c[0].value))
475 c[2].max = 29;
476 /* set new day */
477 if (c[2].value > c[2].max)
478 c[2].value = c[2].max;
479 break;
480 case KEY_F(1):
481 if (conf->key.f1_file == NULL &&
482 conf->key.f1_message == NULL)

--- 60 unchanged lines hidden ---
473 c[2].max = 29;
474 /* set new day */
475 if (c[2].value > c[2].max)
476 c[2].value = c[2].max;
477 break;
478 case KEY_F(1):
479 if (conf->key.f1_file == NULL &&
480 conf->key.f1_message == NULL)

--- 60 unchanged lines hidden ---