1*c7ef0cfcSnicm /* $OpenBSD: lib_dft_fgbg.c,v 1.9 2023/10/17 09:52:08 nicm Exp $ */
292dd1ec0Smillert
392dd1ec0Smillert /****************************************************************************
4*c7ef0cfcSnicm * Copyright 2020,2021 Thomas E. Dickey *
5*c7ef0cfcSnicm * Copyright 1998-2014,2017 Free Software Foundation, Inc. *
692dd1ec0Smillert * *
792dd1ec0Smillert * Permission is hereby granted, free of charge, to any person obtaining a *
892dd1ec0Smillert * copy of this software and associated documentation files (the *
992dd1ec0Smillert * "Software"), to deal in the Software without restriction, including *
1092dd1ec0Smillert * without limitation the rights to use, copy, modify, merge, publish, *
1192dd1ec0Smillert * distribute, distribute with modifications, sublicense, and/or sell *
1292dd1ec0Smillert * copies of the Software, and to permit persons to whom the Software is *
1392dd1ec0Smillert * furnished to do so, subject to the following conditions: *
1492dd1ec0Smillert * *
1592dd1ec0Smillert * The above copyright notice and this permission notice shall be included *
1692dd1ec0Smillert * in all copies or substantial portions of the Software. *
1792dd1ec0Smillert * *
1892dd1ec0Smillert * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
1992dd1ec0Smillert * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
2092dd1ec0Smillert * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
2192dd1ec0Smillert * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
2292dd1ec0Smillert * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
2392dd1ec0Smillert * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
2492dd1ec0Smillert * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
2592dd1ec0Smillert * *
2692dd1ec0Smillert * Except as contained in this notice, the name(s) of the above copyright *
2792dd1ec0Smillert * holders shall not be used in advertising or otherwise to promote the *
2892dd1ec0Smillert * sale, use or other dealings in this Software without prior written *
2992dd1ec0Smillert * authorization. *
3092dd1ec0Smillert ****************************************************************************/
3192dd1ec0Smillert
3292dd1ec0Smillert /****************************************************************************
33*c7ef0cfcSnicm * Author: Thomas E. Dickey 1998-on *
34*c7ef0cfcSnicm * Juergen Pfeifer 2009 *
3592dd1ec0Smillert ****************************************************************************/
364b107ee4Smillert
3792dd1ec0Smillert #include <curses.priv.h>
3892dd1ec0Smillert
39*c7ef0cfcSnicm #ifndef CUR
40*c7ef0cfcSnicm #define CUR SP_TERMTYPE
41*c7ef0cfcSnicm #endif
42*c7ef0cfcSnicm
43*c7ef0cfcSnicm MODULE_ID("$Id: lib_dft_fgbg.c,v 1.9 2023/10/17 09:52:08 nicm Exp $")
4492dd1ec0Smillert
4592dd1ec0Smillert /*
4692dd1ec0Smillert * Modify the behavior of color-pair 0 so that the library doesn't assume that
479ee63291Smillert * it is white on black. This is an extension to XSI curses.
4892dd1ec0Smillert */
NCURSES_EXPORT(int)4984af20ceSmillert NCURSES_EXPORT(int)
50*c7ef0cfcSnicm NCURSES_SP_NAME(use_default_colors) (NCURSES_SP_DCL0)
51*c7ef0cfcSnicm {
52*c7ef0cfcSnicm T((T_CALLED("use_default_colors(%p)"), (void *) SP_PARM));
53*c7ef0cfcSnicm returnCode(NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_ARGx -1, -1));
54*c7ef0cfcSnicm }
55*c7ef0cfcSnicm
56*c7ef0cfcSnicm #if NCURSES_SP_FUNCS
57*c7ef0cfcSnicm NCURSES_EXPORT(int)
use_default_colors(void)5892dd1ec0Smillert use_default_colors(void)
5992dd1ec0Smillert {
60*c7ef0cfcSnicm return NCURSES_SP_NAME(use_default_colors) (CURRENT_SCREEN);
619ee63291Smillert }
62*c7ef0cfcSnicm #endif
6392dd1ec0Smillert
649ee63291Smillert /*
659ee63291Smillert * Modify the behavior of color-pair 0 so that the library assumes that it
669ee63291Smillert * is something specific, possibly not white on black.
679ee63291Smillert */
6884af20ceSmillert NCURSES_EXPORT(int)
NCURSES_SP_NAME(assume_default_colors)69*c7ef0cfcSnicm NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_DCLx int fg, int bg)
70*c7ef0cfcSnicm {
71*c7ef0cfcSnicm int code = ERR;
72*c7ef0cfcSnicm
73*c7ef0cfcSnicm T((T_CALLED("assume_default_colors(%p,%d,%d)"), (void *) SP_PARM, fg, bg));
74*c7ef0cfcSnicm if (SP_PARM != 0) {
75*c7ef0cfcSnicm #ifdef USE_TERM_DRIVER
76*c7ef0cfcSnicm code = CallDriver_2(SP_PARM, td_defaultcolors, fg, bg);
77*c7ef0cfcSnicm #else
78*c7ef0cfcSnicm if ((orig_pair || orig_colors) && !initialize_pair) {
79*c7ef0cfcSnicm
80*c7ef0cfcSnicm SP_PARM->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
81*c7ef0cfcSnicm SP_PARM->_has_sgr_39_49 = (tigetflag("AX") == TRUE);
82*c7ef0cfcSnicm SP_PARM->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : fg;
83*c7ef0cfcSnicm SP_PARM->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : bg;
84*c7ef0cfcSnicm if (SP_PARM->_color_pairs != 0) {
85*c7ef0cfcSnicm bool save = SP_PARM->_default_color;
86*c7ef0cfcSnicm SP_PARM->_assumed_color = TRUE;
87*c7ef0cfcSnicm SP_PARM->_default_color = TRUE;
88*c7ef0cfcSnicm NCURSES_SP_NAME(init_pair) (NCURSES_SP_ARGx 0,
89*c7ef0cfcSnicm (short)fg,
90*c7ef0cfcSnicm (short)bg);
91*c7ef0cfcSnicm SP_PARM->_default_color = save;
92*c7ef0cfcSnicm }
93*c7ef0cfcSnicm code = OK;
94*c7ef0cfcSnicm }
95*c7ef0cfcSnicm #endif
96*c7ef0cfcSnicm }
97*c7ef0cfcSnicm returnCode(code);
98*c7ef0cfcSnicm }
99*c7ef0cfcSnicm
100*c7ef0cfcSnicm #if NCURSES_SP_FUNCS
101*c7ef0cfcSnicm NCURSES_EXPORT(int)
assume_default_colors(int fg,int bg)1029ee63291Smillert assume_default_colors(int fg, int bg)
1039ee63291Smillert {
104*c7ef0cfcSnicm return NCURSES_SP_NAME(assume_default_colors) (CURRENT_SCREEN, fg, bg);
10581d8c4e1Snicm }
106*c7ef0cfcSnicm #endif
107