]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/base/lib_dft_fgbg.c
ncurses 6.2 - patch 20200627
[ncurses.git] / ncurses / base / lib_dft_fgbg.c
1 /****************************************************************************
2  * Copyright 2020 Thomas E. Dickey                                          *
3  * Copyright 1998-2014,2017 Free Software Foundation, Inc.                  *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29
30 /****************************************************************************
31  *  Author: Thomas E. Dickey          1998-on                               *
32  *          Juergen Pfeifer           2009                                  *
33  ****************************************************************************/
34
35 #include <curses.priv.h>
36
37 #ifndef CUR
38 #define CUR SP_TERMTYPE
39 #endif
40
41 MODULE_ID("$Id: lib_dft_fgbg.c,v 1.30 2020/02/02 23:34:34 tom Exp $")
42
43 /*
44  * Modify the behavior of color-pair 0 so that the library doesn't assume that
45  * it is white on black.  This is an extension to XSI curses.
46  */
47 NCURSES_EXPORT(int)
48 NCURSES_SP_NAME(use_default_colors) (NCURSES_SP_DCL0)
49 {
50     T((T_CALLED("use_default_colors(%p)"), (void *) SP_PARM));
51     returnCode(NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_ARGx -1, -1));
52 }
53
54 #if NCURSES_SP_FUNCS
55 NCURSES_EXPORT(int)
56 use_default_colors(void)
57 {
58     return NCURSES_SP_NAME(use_default_colors) (CURRENT_SCREEN);
59 }
60 #endif
61
62 /*
63  * Modify the behavior of color-pair 0 so that the library assumes that it
64  * is something specific, possibly not white on black.
65  */
66 NCURSES_EXPORT(int)
67 NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_DCLx int fg, int bg)
68 {
69     int code = ERR;
70
71     T((T_CALLED("assume_default_colors(%p,%d,%d)"), (void *) SP_PARM, fg, bg));
72     if (SP_PARM != 0) {
73 #ifdef USE_TERM_DRIVER
74         code = CallDriver_2(SP_PARM, td_defaultcolors, fg, bg);
75 #else
76         if ((orig_pair || orig_colors) && !initialize_pair) {
77
78             SP_PARM->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
79             SP_PARM->_has_sgr_39_49 = (tigetflag("AX") == TRUE);
80             SP_PARM->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : fg;
81             SP_PARM->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : bg;
82             if (SP_PARM->_color_pairs != 0) {
83                 bool save = SP_PARM->_default_color;
84                 SP_PARM->_assumed_color = TRUE;
85                 SP_PARM->_default_color = TRUE;
86                 init_pair(0, (short) fg, (short) bg);
87                 SP_PARM->_default_color = save;
88             }
89             code = OK;
90         }
91 #endif
92     }
93     returnCode(code);
94 }
95
96 #if NCURSES_SP_FUNCS
97 NCURSES_EXPORT(int)
98 assume_default_colors(int fg, int bg)
99 {
100     return NCURSES_SP_NAME(assume_default_colors) (CURRENT_SCREEN, fg, bg);
101 }
102 #endif