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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LIBBSDDIALOG_UTIL_H_
|
|
|
|
#define _LIBBSDDIALOG_UTIL_H_
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
#define HBORDERS 2
|
|
|
|
#define VBORDERS 2
|
|
|
|
#define TEXTHMARGIN 1
|
|
|
|
#define TEXTHMARGINS (TEXTHMARGIN + TEXTHMARGIN)
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
/* theme utils */
|
2022-03-13 01:34:57 +00:00
|
|
|
extern struct bsddialog_theme t;
|
2022-09-03 14:36:16 +00:00
|
|
|
extern bool hastermcolors;
|
2022-03-13 01:34:57 +00:00
|
|
|
|
2021-11-24 08:42:13 +00:00
|
|
|
/* debug */
|
|
|
|
#define BSDDIALOG_DEBUG(y,x,fmt, ...) do { \
|
|
|
|
mvprintw(y, x, fmt, __VA_ARGS__); \
|
|
|
|
refresh(); \
|
|
|
|
} while (0)
|
|
|
|
|
2022-09-25 13:04:33 +00:00
|
|
|
/* date */
|
|
|
|
#define ISLEAP(year) ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
|
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
/* unicode */
|
|
|
|
unsigned int strcols(const char *mbstring);
|
|
|
|
int str_props(const char *mbstring, unsigned int *cols, bool *has_multi_col);
|
|
|
|
void mvwaddwch(WINDOW *w, int y, int x, wchar_t wch);
|
|
|
|
wchar_t* alloc_mbstows(const char *mbstring);
|
|
|
|
|
2021-11-24 08:42:13 +00:00
|
|
|
/* error buffer */
|
|
|
|
const char *get_error_string(void);
|
2022-03-13 01:34:57 +00:00
|
|
|
void set_error_string(const char *string);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
#define RETURN_ERROR(str) do { \
|
|
|
|
set_error_string(str); \
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR); \
|
2021-11-24 08:42:13 +00:00
|
|
|
} while (0)
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
/* buttons */
|
2021-11-24 08:42:13 +00:00
|
|
|
struct buttons {
|
|
|
|
unsigned int nbuttons;
|
2022-01-28 08:14:55 +00:00
|
|
|
#define MAXBUTTONS 6 /* ok + extra + cancel + help + 2 generics */
|
|
|
|
const char *label[MAXBUTTONS];
|
2022-09-03 14:36:16 +00:00
|
|
|
wchar_t first[MAXBUTTONS];
|
2021-11-24 08:42:13 +00:00
|
|
|
int value[MAXBUTTONS];
|
|
|
|
int curr;
|
|
|
|
unsigned int sizebutton; /* including left and right delimiters */
|
|
|
|
};
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
#define BUTTON_OK_LABEL "OK"
|
|
|
|
#define BUTTON_CANCEL_LABEL "Cancel"
|
2021-11-24 08:42:13 +00:00
|
|
|
void
|
2022-03-13 01:34:57 +00:00
|
|
|
get_buttons(struct bsddialog_conf *conf, struct buttons *bs,
|
|
|
|
const char *yesoklabel, const char *nocancellabel);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
void
|
2022-01-28 08:14:55 +00:00
|
|
|
draw_buttons(WINDOW *window, struct buttons bs, bool shortcut);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
int buttons_min_width(struct buttons bs);
|
|
|
|
bool shortcut_buttons(wint_t key, struct buttons *bs);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
/* help window with F1 key */
|
2021-12-06 10:35:28 +00:00
|
|
|
int f1help(struct bsddialog_conf *conf);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
/* cleaner */
|
|
|
|
int hide_widget(int y, int x, int h, int w, bool withshadow);
|
|
|
|
|
|
|
|
/* (auto) size and (auto) position */
|
2022-01-28 08:14:55 +00:00
|
|
|
#define SCREENLINES (getmaxy(stdscr))
|
|
|
|
#define SCREENCOLS (getmaxx(stdscr))
|
|
|
|
|
2021-11-24 08:42:13 +00:00
|
|
|
int
|
2022-01-28 08:14:55 +00:00
|
|
|
text_size(struct bsddialog_conf *conf, int rows, int cols, const char *text,
|
|
|
|
struct buttons *bs, int rowsnotext, int startwtext, int *htext, int *wtext);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2021-12-06 10:35:28 +00:00
|
|
|
int widget_max_height(struct bsddialog_conf *conf);
|
|
|
|
int widget_max_width(struct bsddialog_conf *conf);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
int
|
2022-01-28 08:14:55 +00:00
|
|
|
widget_min_height(struct bsddialog_conf *conf, int htext, int minwidget,
|
|
|
|
bool withbuttons);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
int
|
2022-01-28 08:14:55 +00:00
|
|
|
widget_min_width(struct bsddialog_conf *conf, int wtext, int minwidget,
|
|
|
|
struct buttons *bs);
|
|
|
|
|
|
|
|
int
|
|
|
|
set_widget_size(struct bsddialog_conf *conf, int rows, int cols, int *h,
|
|
|
|
int *w);
|
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
|
|
|
set_widget_position(struct bsddialog_conf *conf, int *y, int *x, int h, int w);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
/* widget builders */
|
2021-11-24 08:42:13 +00:00
|
|
|
enum elevation { RAISED, LOWERED };
|
|
|
|
|
|
|
|
void
|
2021-12-06 10:35:28 +00:00
|
|
|
draw_borders(struct bsddialog_conf *conf, WINDOW *win, int rows, int cols,
|
2021-11-24 08:42:13 +00:00
|
|
|
enum elevation elev);
|
|
|
|
|
|
|
|
WINDOW *
|
2021-12-06 10:35:28 +00:00
|
|
|
new_boxed_window(struct bsddialog_conf *conf, int y, int x, int rows, int cols,
|
2021-11-24 08:42:13 +00:00
|
|
|
enum elevation elev);
|
|
|
|
|
|
|
|
int
|
2022-01-28 08:14:55 +00:00
|
|
|
new_dialog(struct bsddialog_conf *conf, WINDOW **shadow, WINDOW **widget, int y,
|
|
|
|
int x, int h, int w, WINDOW **textpad, const char *text, struct buttons *bs,
|
|
|
|
bool shortcutbuttons);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
int
|
2022-01-28 08:14:55 +00:00
|
|
|
update_dialog(struct bsddialog_conf *conf, WINDOW *shadow, WINDOW *widget,
|
|
|
|
int y, int x, int h, int w, WINDOW *textpad, const char *text,
|
|
|
|
struct buttons *bs, bool shortcutbuttons);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
void
|
2022-01-28 08:14:55 +00:00
|
|
|
end_dialog(struct bsddialog_conf *conf, WINDOW *shadow, WINDOW *widget,
|
|
|
|
WINDOW *textpad);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
#endif
|