xref: /freebsd/contrib/bsddialog/lib/theme.c (revision d93b4d32034df7cd70e80b496e8fe8c1bc57c629)
1c76f0793SBaptiste Daroussin /*-
2c76f0793SBaptiste Daroussin  * SPDX-License-Identifier: BSD-2-Clause
3c76f0793SBaptiste Daroussin  *
4c76f0793SBaptiste Daroussin  * Copyright (c) 2021 Alfonso Sabato Siciliano
5c76f0793SBaptiste Daroussin  *
6c76f0793SBaptiste Daroussin  * Redistribution and use in source and binary forms, with or without
7c76f0793SBaptiste Daroussin  * modification, are permitted provided that the following conditions
8c76f0793SBaptiste Daroussin  * are met:
9c76f0793SBaptiste Daroussin  * 1. Redistributions of source code must retain the above copyright
10c76f0793SBaptiste Daroussin  *    notice, this list of conditions and the following disclaimer.
11c76f0793SBaptiste Daroussin  * 2. Redistributions in binary form must reproduce the above copyright
12c76f0793SBaptiste Daroussin  *    notice, this list of conditions and the following disclaimer in the
13c76f0793SBaptiste Daroussin  *    documentation and/or other materials provided with the distribution.
14c76f0793SBaptiste Daroussin  *
15c76f0793SBaptiste Daroussin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16c76f0793SBaptiste Daroussin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17c76f0793SBaptiste Daroussin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18c76f0793SBaptiste Daroussin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19c76f0793SBaptiste Daroussin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20c76f0793SBaptiste Daroussin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21c76f0793SBaptiste Daroussin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22c76f0793SBaptiste Daroussin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23c76f0793SBaptiste Daroussin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24c76f0793SBaptiste Daroussin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25c76f0793SBaptiste Daroussin  * SUCH DAMAGE.
26c76f0793SBaptiste Daroussin  */
27c76f0793SBaptiste Daroussin 
28c76f0793SBaptiste Daroussin #ifdef PORTNCURSES
298c4f4028SBaptiste Daroussin #include <ncurses/ncurses.h>
30c76f0793SBaptiste Daroussin #else
318c4f4028SBaptiste Daroussin #include <ncurses.h>
32c76f0793SBaptiste Daroussin #endif
33c76f0793SBaptiste Daroussin 
34c76f0793SBaptiste Daroussin #include "bsddialog.h"
35c76f0793SBaptiste Daroussin #include "lib_util.h"
36c76f0793SBaptiste Daroussin #include "bsddialog_theme.h"
37c76f0793SBaptiste Daroussin 
38c76f0793SBaptiste Daroussin #define GET_COLOR(bg, fg) (COLOR_PAIR(bg * 8 + fg +1))
39c76f0793SBaptiste Daroussin 
40c76f0793SBaptiste Daroussin struct bsddialog_theme t;
41c76f0793SBaptiste Daroussin 
42c76f0793SBaptiste Daroussin static struct bsddialog_theme bsddialogtheme = {
43c76f0793SBaptiste Daroussin #define bgwidget  COLOR_WHITE
44c76f0793SBaptiste Daroussin #define bgcurr    COLOR_YELLOW
458c4f4028SBaptiste Daroussin 	.terminal.color = GET_COLOR(COLOR_BLACK, COLOR_CYAN),
468c4f4028SBaptiste Daroussin 
47f499134dSBaptiste Daroussin 	.shadow.color   = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
48f499134dSBaptiste Daroussin 	.shadow.h       = 1,
49f499134dSBaptiste Daroussin 	.shadow.w       = 2,
50c76f0793SBaptiste Daroussin 
518c4f4028SBaptiste Daroussin 	.dialog.delimtitle       = true,
528c4f4028SBaptiste Daroussin 	.dialog.titlecolor       = GET_COLOR(COLOR_YELLOW, bgwidget),
538c4f4028SBaptiste Daroussin 	.dialog.lineraisecolor   = GET_COLOR(COLOR_BLACK,  bgwidget),
548c4f4028SBaptiste Daroussin 	.dialog.linelowercolor   = GET_COLOR(COLOR_BLACK,  bgwidget),
558c4f4028SBaptiste Daroussin 	.dialog.color            = GET_COLOR(COLOR_BLACK,  bgwidget),
568c4f4028SBaptiste Daroussin 	.dialog.bottomtitlecolor = GET_COLOR(COLOR_BLACK,  bgwidget),
57c76f0793SBaptiste Daroussin 
58f499134dSBaptiste Daroussin 	.text.hmargin = 1,
59c76f0793SBaptiste Daroussin 
60f499134dSBaptiste Daroussin 	.menu.arrowcolor      = GET_COLOR(COLOR_YELLOW, bgwidget),
618c4f4028SBaptiste Daroussin 	.menu.selectorcolor   = GET_COLOR(COLOR_BLACK,  bgwidget) | A_BOLD,
62f499134dSBaptiste Daroussin 	.menu.f_desccolor     = GET_COLOR(COLOR_WHITE,  bgcurr),
63f499134dSBaptiste Daroussin 	.menu.desccolor       = GET_COLOR(COLOR_BLACK,  bgwidget),
64f499134dSBaptiste Daroussin 	.menu.f_namecolor     = GET_COLOR(COLOR_BLACK,  bgcurr),
65f499134dSBaptiste Daroussin 	.menu.namecolor       = GET_COLOR(COLOR_YELLOW, bgwidget),
66f499134dSBaptiste Daroussin 	.menu.namesepcolor    = GET_COLOR(COLOR_YELLOW, bgwidget),
67f499134dSBaptiste Daroussin 	.menu.descsepcolor    = GET_COLOR(COLOR_YELLOW, bgwidget),
688c4f4028SBaptiste Daroussin 	.menu.f_shortcutcolor = GET_COLOR(COLOR_RED,    bgcurr),
698c4f4028SBaptiste Daroussin 	.menu.shortcutcolor   = GET_COLOR(COLOR_RED,    bgwidget),
70c76f0793SBaptiste Daroussin 
71f499134dSBaptiste Daroussin 	.form.f_fieldcolor  = GET_COLOR(COLOR_WHITE,  COLOR_BLUE),
72f499134dSBaptiste Daroussin 	.form.fieldcolor    = GET_COLOR(COLOR_WHITE,  COLOR_CYAN),
73f499134dSBaptiste Daroussin 	.form.readonlycolor = GET_COLOR(COLOR_CYAN,COLOR_WHITE),
74c76f0793SBaptiste Daroussin 
75f499134dSBaptiste Daroussin 	.bar.f_color = GET_COLOR(COLOR_WHITE, COLOR_BLUE),
76f499134dSBaptiste Daroussin 	.bar.color   = GET_COLOR(COLOR_BLUE,  COLOR_WHITE),
77c76f0793SBaptiste Daroussin 
78f499134dSBaptiste Daroussin 	.button.space        = 3,
79f499134dSBaptiste Daroussin 	.button.leftch       = '[',
80f499134dSBaptiste Daroussin 	.button.rightch      = ']',
81f499134dSBaptiste Daroussin 	.button.f_delimcolor = GET_COLOR(COLOR_WHITE,  bgcurr),
82f499134dSBaptiste Daroussin 	.button.delimcolor   = GET_COLOR(COLOR_BLACK,  bgwidget),
83f499134dSBaptiste Daroussin 	.button.f_color      = GET_COLOR(COLOR_WHITE,  bgcurr)    | A_UNDERLINE,
84f499134dSBaptiste Daroussin 	.button.color        = GET_COLOR(COLOR_BLACK,  bgwidget)  | A_UNDERLINE,
85f499134dSBaptiste Daroussin 	.button.f_shortcutcolor = GET_COLOR(COLOR_BLACK, bgcurr)  | A_UNDERLINE,
86f499134dSBaptiste Daroussin 	.button.shortcutcolor = GET_COLOR(COLOR_YELLOW, bgwidget) | A_UNDERLINE
87c76f0793SBaptiste Daroussin };
88c76f0793SBaptiste Daroussin 
89c76f0793SBaptiste Daroussin static struct bsddialog_theme blackwhite = {
90c76f0793SBaptiste Daroussin #define fg  COLOR_WHITE
91*d93b4d32SBaptiste Daroussin #define bk  COLOR_BLACK
928c4f4028SBaptiste Daroussin 	.terminal.color = GET_COLOR(fg, bk),
938c4f4028SBaptiste Daroussin 
94f499134dSBaptiste Daroussin 	.shadow.color   = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
95f499134dSBaptiste Daroussin 	.shadow.h       = 1,
96f499134dSBaptiste Daroussin 	.shadow.w       = 2,
97c76f0793SBaptiste Daroussin 
988c4f4028SBaptiste Daroussin 	.dialog.delimtitle       = true,
998c4f4028SBaptiste Daroussin 	.dialog.titlecolor       = GET_COLOR(fg, bk),
1008c4f4028SBaptiste Daroussin 	.dialog.lineraisecolor   = GET_COLOR(fg, bk),
1018c4f4028SBaptiste Daroussin 	.dialog.linelowercolor   = GET_COLOR(fg, bk),
1028c4f4028SBaptiste Daroussin 	.dialog.color            = GET_COLOR(fg, bk),
1038c4f4028SBaptiste Daroussin 	.dialog.bottomtitlecolor = GET_COLOR(fg, bk),
104c76f0793SBaptiste Daroussin 
105f499134dSBaptiste Daroussin 	.text.hmargin = 1,
106c76f0793SBaptiste Daroussin 
107f499134dSBaptiste Daroussin 	.menu.arrowcolor      = GET_COLOR(fg, bk),
1088c4f4028SBaptiste Daroussin 	.menu.selectorcolor   = GET_COLOR(fg, bk),
109f499134dSBaptiste Daroussin 	.menu.f_desccolor     = GET_COLOR(fg, bk) | A_REVERSE,
110f499134dSBaptiste Daroussin 	.menu.desccolor       = GET_COLOR(fg, bk),
111f499134dSBaptiste Daroussin 	.menu.f_namecolor     = GET_COLOR(fg, bk) | A_REVERSE,
112f499134dSBaptiste Daroussin 	.menu.namecolor       = GET_COLOR(fg, bk),
113f499134dSBaptiste Daroussin 	.menu.namesepcolor    = GET_COLOR(fg, bk),
114f499134dSBaptiste Daroussin 	.menu.descsepcolor    = GET_COLOR(fg, bk),
1158c4f4028SBaptiste Daroussin 	.menu.f_shortcutcolor = GET_COLOR(fg, bk) | A_UNDERLINE | A_REVERSE,
1168c4f4028SBaptiste Daroussin 	.menu.shortcutcolor   = GET_COLOR(fg, bk) | A_UNDERLINE,
117c76f0793SBaptiste Daroussin 
118f499134dSBaptiste Daroussin 	.form.f_fieldcolor  = GET_COLOR(fg, bk) | A_REVERSE,
119f499134dSBaptiste Daroussin 	.form.fieldcolor    = GET_COLOR(fg, bk),
120f499134dSBaptiste Daroussin 	.form.readonlycolor = GET_COLOR(fg, bk),
121c76f0793SBaptiste Daroussin 
122f499134dSBaptiste Daroussin 	.bar.f_color = GET_COLOR(fg, bk) | A_REVERSE,
123f499134dSBaptiste Daroussin 	.bar.color   = GET_COLOR(fg, bk),
124c76f0793SBaptiste Daroussin 
125f499134dSBaptiste Daroussin 	.button.space           = 3,
126f499134dSBaptiste Daroussin 	.button.leftch          = '[',
127f499134dSBaptiste Daroussin 	.button.rightch         = ']',
128f499134dSBaptiste Daroussin 	.button.f_delimcolor    = GET_COLOR(fg, bk),
129f499134dSBaptiste Daroussin 	.button.delimcolor      = GET_COLOR(fg, bk),
130f499134dSBaptiste Daroussin 	.button.f_color         = GET_COLOR(fg, bk) | A_UNDERLINE | A_REVERSE,
131f499134dSBaptiste Daroussin 	.button.color           = GET_COLOR(fg, bk) | A_UNDERLINE,
132f499134dSBaptiste Daroussin 	.button.f_shortcutcolor = GET_COLOR(fg, bk) | A_UNDERLINE | A_REVERSE,
133f499134dSBaptiste Daroussin 	.button.shortcutcolor   = GET_COLOR(fg, bk) | A_UNDERLINE
134c76f0793SBaptiste Daroussin };
135c76f0793SBaptiste Daroussin 
136c76f0793SBaptiste Daroussin static struct bsddialog_theme dialogtheme = {
1378c4f4028SBaptiste Daroussin 	.terminal.color = GET_COLOR(COLOR_CYAN,  COLOR_BLUE)  | A_BOLD,
1388c4f4028SBaptiste Daroussin 
139f499134dSBaptiste Daroussin 	.shadow.color   = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
140f499134dSBaptiste Daroussin 	.shadow.h       = 1,
141f499134dSBaptiste Daroussin 	.shadow.w       = 2,
142c76f0793SBaptiste Daroussin 
1438c4f4028SBaptiste Daroussin 	.dialog.delimtitle       = false,
1448c4f4028SBaptiste Daroussin 	.dialog.titlecolor       = GET_COLOR(COLOR_BLUE,  COLOR_WHITE) | A_BOLD,
1458c4f4028SBaptiste Daroussin 	.dialog.lineraisecolor   = GET_COLOR(COLOR_WHITE, COLOR_WHITE) | A_BOLD,
1468c4f4028SBaptiste Daroussin 	.dialog.linelowercolor   = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
1478c4f4028SBaptiste Daroussin 	.dialog.color            = GET_COLOR(COLOR_BLACK, COLOR_WHITE),
1488c4f4028SBaptiste Daroussin 	.dialog.bottomtitlecolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
149c76f0793SBaptiste Daroussin 
150f499134dSBaptiste Daroussin 	.text.hmargin = 1,
151c76f0793SBaptiste Daroussin 
152f499134dSBaptiste Daroussin 	.menu.arrowcolor      = GET_COLOR(COLOR_GREEN,  COLOR_WHITE),
1538c4f4028SBaptiste Daroussin 	.menu.selectorcolor   = GET_COLOR(COLOR_BLACK,  bgwidget)    | A_BOLD,
154f499134dSBaptiste Daroussin 	.menu.f_desccolor     = GET_COLOR(COLOR_WHITE,  COLOR_BLUE)  | A_BOLD,
155f499134dSBaptiste Daroussin 	.menu.desccolor       = GET_COLOR(COLOR_BLACK,  COLOR_WHITE) | A_BOLD,
156f499134dSBaptiste Daroussin 	.menu.f_namecolor     = GET_COLOR(COLOR_YELLOW, COLOR_BLUE)  | A_BOLD,
157f499134dSBaptiste Daroussin 	.menu.namecolor       = GET_COLOR(COLOR_BLUE,   COLOR_WHITE) | A_BOLD,
158f499134dSBaptiste Daroussin 	.menu.namesepcolor    = GET_COLOR(COLOR_RED,    COLOR_WHITE),
159f499134dSBaptiste Daroussin 	.menu.descsepcolor    = GET_COLOR(COLOR_RED,    COLOR_WHITE),
1608c4f4028SBaptiste Daroussin 	.menu.f_shortcutcolor = GET_COLOR(COLOR_RED,    COLOR_BLUE)  | A_BOLD,
1618c4f4028SBaptiste Daroussin 	.menu.shortcutcolor   = GET_COLOR(COLOR_RED,    COLOR_WHITE) | A_BOLD,
162c76f0793SBaptiste Daroussin 
163f499134dSBaptiste Daroussin 	.form.f_fieldcolor  = GET_COLOR(COLOR_WHITE, COLOR_BLUE) | A_BOLD,
164f499134dSBaptiste Daroussin 	.form.fieldcolor    = GET_COLOR(COLOR_WHITE, COLOR_CYAN) | A_BOLD,
165f499134dSBaptiste Daroussin 	.form.readonlycolor = GET_COLOR(COLOR_CYAN,  COLOR_WHITE)| A_BOLD,
166c76f0793SBaptiste Daroussin 
167f499134dSBaptiste Daroussin 	.bar.f_color = GET_COLOR(COLOR_WHITE, COLOR_BLUE)  | A_BOLD,
168f499134dSBaptiste Daroussin 	.bar.color   = GET_COLOR(COLOR_BLUE,  COLOR_WHITE) | A_BOLD,
169c76f0793SBaptiste Daroussin 
170f499134dSBaptiste Daroussin 	.button.space           = 3,
171f499134dSBaptiste Daroussin 	.button.leftch          = '<',
172f499134dSBaptiste Daroussin 	.button.rightch         = '>',
173f499134dSBaptiste Daroussin 	.button.f_delimcolor    = GET_COLOR(COLOR_WHITE,  COLOR_BLUE)  | A_BOLD,
174f499134dSBaptiste Daroussin 	.button.delimcolor      = GET_COLOR(COLOR_BLACK,  COLOR_WHITE),
175f499134dSBaptiste Daroussin 	.button.f_color         = GET_COLOR(COLOR_YELLOW, COLOR_BLUE)  | A_BOLD,
176f499134dSBaptiste Daroussin 	.button.color           = GET_COLOR(COLOR_BLACK,  COLOR_WHITE),
177f499134dSBaptiste Daroussin 	.button.f_shortcutcolor = GET_COLOR(COLOR_WHITE,  COLOR_BLUE)  | A_BOLD,
178f499134dSBaptiste Daroussin 	.button.shortcutcolor   = GET_COLOR(COLOR_RED,    COLOR_WHITE) | A_BOLD
179c76f0793SBaptiste Daroussin };
180c76f0793SBaptiste Daroussin 
1818c4f4028SBaptiste Daroussin static void
1828c4f4028SBaptiste Daroussin set_theme(struct bsddialog_theme *dst, struct bsddialog_theme *src)
183c76f0793SBaptiste Daroussin {
1848c4f4028SBaptiste Daroussin 	dst->shadow.color = src->shadow.color;
1858c4f4028SBaptiste Daroussin 	dst->shadow.h     = src->shadow.h;
1868c4f4028SBaptiste Daroussin 	dst->shadow.w     = src->shadow.w;
187c76f0793SBaptiste Daroussin 
1888c4f4028SBaptiste Daroussin 	dst->terminal.color          = src->terminal.color;
1898c4f4028SBaptiste Daroussin 	dst->dialog.delimtitle       = src->dialog.delimtitle;
1908c4f4028SBaptiste Daroussin 	dst->dialog.titlecolor       = src->dialog.titlecolor;
1918c4f4028SBaptiste Daroussin 	dst->dialog.lineraisecolor   = src->dialog.lineraisecolor;
1928c4f4028SBaptiste Daroussin 	dst->dialog.linelowercolor   = src->dialog.linelowercolor;
1938c4f4028SBaptiste Daroussin 	dst->dialog.color            = src->dialog.color;
1948c4f4028SBaptiste Daroussin 	dst->dialog.bottomtitlecolor = src->dialog.bottomtitlecolor;
195c76f0793SBaptiste Daroussin 
1968c4f4028SBaptiste Daroussin 	dst->text.hmargin = src->text.hmargin;
197c76f0793SBaptiste Daroussin 
1988c4f4028SBaptiste Daroussin 	dst->menu.arrowcolor      = src->menu.arrowcolor;
1998c4f4028SBaptiste Daroussin 	dst->menu.selectorcolor   = src->menu.selectorcolor;
2008c4f4028SBaptiste Daroussin 	dst->menu.f_desccolor     = src->menu.f_desccolor;
2018c4f4028SBaptiste Daroussin 	dst->menu.desccolor       = src->menu.desccolor;
2028c4f4028SBaptiste Daroussin 	dst->menu.f_namecolor     = src->menu.f_namecolor;
2038c4f4028SBaptiste Daroussin 	dst->menu.namecolor       = src->menu.namecolor;
2048c4f4028SBaptiste Daroussin 	dst->menu.namesepcolor    = src->menu.namesepcolor;
2058c4f4028SBaptiste Daroussin 	dst->menu.descsepcolor    = src->menu.descsepcolor;
2068c4f4028SBaptiste Daroussin 	dst->menu.f_shortcutcolor = src->menu.f_shortcutcolor;
2078c4f4028SBaptiste Daroussin 	dst->menu.shortcutcolor   = src->menu.shortcutcolor;
208c76f0793SBaptiste Daroussin 
2098c4f4028SBaptiste Daroussin 	dst->form.f_fieldcolor  = src->form.f_fieldcolor;
2108c4f4028SBaptiste Daroussin 	dst->form.fieldcolor    = src->form.fieldcolor;
2118c4f4028SBaptiste Daroussin 	dst->form.readonlycolor = src->form.readonlycolor;
212c76f0793SBaptiste Daroussin 
2138c4f4028SBaptiste Daroussin 	dst->bar.f_color = src->bar.f_color;
2148c4f4028SBaptiste Daroussin 	dst->bar.color   = src->bar.color;
215c76f0793SBaptiste Daroussin 
2168c4f4028SBaptiste Daroussin 	dst->button.space           = src->button.space;
2178c4f4028SBaptiste Daroussin 	dst->button.leftch          = src->button.leftch;
2188c4f4028SBaptiste Daroussin 	dst->button.rightch         = src->button.rightch;
2198c4f4028SBaptiste Daroussin 	dst->button.f_delimcolor    = src->button.f_delimcolor;
2208c4f4028SBaptiste Daroussin 	dst->button.delimcolor      = src->button.delimcolor;
2218c4f4028SBaptiste Daroussin 	dst->button.f_color         = src->button.f_color;
2228c4f4028SBaptiste Daroussin 	dst->button.color           = src->button.color;
2238c4f4028SBaptiste Daroussin 	dst->button.f_shortcutcolor = src->button.f_shortcutcolor;
2248c4f4028SBaptiste Daroussin 	dst->button.shortcutcolor   = src->button.shortcutcolor;
225c76f0793SBaptiste Daroussin 
2268c4f4028SBaptiste Daroussin 	bkgd(dst->terminal.color);
227c76f0793SBaptiste Daroussin 	refresh();
228c76f0793SBaptiste Daroussin }
229c76f0793SBaptiste Daroussin 
2308c4f4028SBaptiste Daroussin /* API */
2318c4f4028SBaptiste Daroussin int bsddialog_get_theme(struct bsddialog_theme *theme)
2328c4f4028SBaptiste Daroussin {
2338c4f4028SBaptiste Daroussin 	if (theme == NULL)
2348c4f4028SBaptiste Daroussin 		RETURN_ERROR("theme is NULL");
2358c4f4028SBaptiste Daroussin 	if (sizeof(*theme) != sizeof(struct bsddialog_theme))
2368c4f4028SBaptiste Daroussin 		RETURN_ERROR("Bad suze struct bsddialog_theme");
2378c4f4028SBaptiste Daroussin 
2388c4f4028SBaptiste Daroussin 	set_theme(theme, &t);
2398c4f4028SBaptiste Daroussin 
2408c4f4028SBaptiste Daroussin 	return (0);
2418c4f4028SBaptiste Daroussin }
2428c4f4028SBaptiste Daroussin 
2438c4f4028SBaptiste Daroussin int bsddialog_set_theme(struct bsddialog_theme *theme)
2448c4f4028SBaptiste Daroussin {
2458c4f4028SBaptiste Daroussin 	if (theme == NULL)
2468c4f4028SBaptiste Daroussin 		RETURN_ERROR("theme is NULL");
2478c4f4028SBaptiste Daroussin 	if (sizeof(*theme) != sizeof(struct bsddialog_theme))
2488c4f4028SBaptiste Daroussin 		RETURN_ERROR("Bad size struct bsddialog_theme");
2498c4f4028SBaptiste Daroussin 
2508c4f4028SBaptiste Daroussin 	set_theme(&t, theme);
2518c4f4028SBaptiste Daroussin 
2528c4f4028SBaptiste Daroussin 	return (0);
2538c4f4028SBaptiste Daroussin }
2548c4f4028SBaptiste Daroussin 
255c76f0793SBaptiste Daroussin int bsddialog_set_default_theme(enum bsddialog_default_theme newtheme)
256c76f0793SBaptiste Daroussin {
257c76f0793SBaptiste Daroussin 
2588c4f4028SBaptiste Daroussin 	if (newtheme == BSDDIALOG_THEME_DEFAULT) {
2598c4f4028SBaptiste Daroussin 		bsddialog_set_theme(&dialogtheme);
2608c4f4028SBaptiste Daroussin 		t.dialog.lineraisecolor = t.dialog.linelowercolor;
2618c4f4028SBaptiste Daroussin 	}
262c76f0793SBaptiste Daroussin 	else if (newtheme == BSDDIALOG_THEME_BSDDIALOG)
2638c4f4028SBaptiste Daroussin 		bsddialog_set_theme(&bsddialogtheme);
264c76f0793SBaptiste Daroussin 	else if (newtheme == BSDDIALOG_THEME_BLACKWHITE)
2658c4f4028SBaptiste Daroussin 		bsddialog_set_theme(&blackwhite);
266c76f0793SBaptiste Daroussin 	else if (newtheme == BSDDIALOG_THEME_DIALOG)
2678c4f4028SBaptiste Daroussin 		bsddialog_set_theme(&dialogtheme);
268c76f0793SBaptiste Daroussin 	else
269c76f0793SBaptiste Daroussin 		RETURN_ERROR("Unknow default theme");
270c76f0793SBaptiste Daroussin 
2718c4f4028SBaptiste Daroussin 	return (0);
272c76f0793SBaptiste Daroussin }
273c76f0793SBaptiste Daroussin 
274c76f0793SBaptiste Daroussin int
275*d93b4d32SBaptiste Daroussin bsddialog_color(enum bsddialog_color foreground,
276*d93b4d32SBaptiste Daroussin     enum bsddialog_color background, unsigned int flags)
277c76f0793SBaptiste Daroussin {
2788c4f4028SBaptiste Daroussin 	unsigned int cursesflags = 0;
279c76f0793SBaptiste Daroussin 
2808c4f4028SBaptiste Daroussin 	if (flags & BSDDIALOG_BOLD)
2818c4f4028SBaptiste Daroussin 		cursesflags |= A_BOLD;
2828c4f4028SBaptiste Daroussin 	if (flags & BSDDIALOG_REVERSE)
2838c4f4028SBaptiste Daroussin 		cursesflags |= A_REVERSE;
2848c4f4028SBaptiste Daroussin 	if (flags & BSDDIALOG_UNDERLINE)
2858c4f4028SBaptiste Daroussin 		cursesflags |= A_UNDERLINE;
286c76f0793SBaptiste Daroussin 
287*d93b4d32SBaptiste Daroussin 	return (GET_COLOR(foreground, background) | cursesflags);
288c76f0793SBaptiste Daroussin }
289