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