150276Speter/**************************************************************************** 2178866Srafan * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * 350276Speter * * 450276Speter * Permission is hereby granted, free of charge, to any person obtaining a * 550276Speter * copy of this software and associated documentation files (the * 650276Speter * "Software"), to deal in the Software without restriction, including * 750276Speter * without limitation the rights to use, copy, modify, merge, publish, * 850276Speter * distribute, distribute with modifications, sublicense, and/or sell * 950276Speter * copies of the Software, and to permit persons to whom the Software is * 1050276Speter * furnished to do so, subject to the following conditions: * 1150276Speter * * 1250276Speter * The above copyright notice and this permission notice shall be included * 1350276Speter * in all copies or substantial portions of the Software. * 1450276Speter * * 1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2250276Speter * * 2350276Speter * Except as contained in this notice, the name(s) of the above copyright * 2450276Speter * holders shall not be used in advertising or otherwise to promote the * 2550276Speter * sale, use or other dealings in this Software without prior written * 2650276Speter * authorization. * 2750276Speter ****************************************************************************/ 2850276Speter 2950276Speter/**************************************************************************** 3050276Speter * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 3150276Speter * and: Eric S. Raymond <esr@snark.thyrsus.com> * 32166124Srafan * and: Juergen Pfeifer 1997 * 33166124Srafan * and: Sven Verdoolaege 2000 * 34166124Srafan * and: Thomas E. Dickey 1996-on * 3550276Speter ****************************************************************************/ 3650276Speter 3750276Speter#include <curses.priv.h> 3850276Speter 39178866SrafanMODULE_ID("$Id: lib_bkgd.c,v 1.36 2008/03/23 00:09:14 tom Exp $") 4050276Speter 4197049Speter/* 4297049Speter * Set the window's background information. 4397049Speter */ 4497049Speter#if USE_WIDEC_SUPPORT 4576726SpeterNCURSES_EXPORT(void) 4697049Speter#else 47166124Srafanstatic NCURSES_INLINE void 4897049Speter#endif 4997049Speterwbkgrndset(WINDOW *win, const ARG_CH_T ch) 5050276Speter{ 5197049Speter T((T_CALLED("wbkgdset(%p,%s)"), win, _tracech_t(ch))); 5276726Speter 5376726Speter if (win) { 5497049Speter attr_t off = AttrOf(win->_nc_bkgd); 5597049Speter attr_t on = AttrOf(CHDEREF(ch)); 5676726Speter 57166124Srafan toggle_attr_off(WINDOW_ATTRS(win), off); 58166124Srafan toggle_attr_on(WINDOW_ATTRS(win), on); 5976726Speter 60166124Srafan#if NCURSES_EXT_COLORS 61166124Srafan { 62166124Srafan int pair; 63166124Srafan 64166124Srafan if ((pair = GetPair(win->_nc_bkgd)) != 0) 65166124Srafan SET_WINDOW_PAIR(win, 0); 66166124Srafan if ((pair = GetPair(CHDEREF(ch))) != 0) 67166124Srafan SET_WINDOW_PAIR(win, pair); 68166124Srafan } 69166124Srafan#endif 70166124Srafan 71166124Srafan if (CharOf(CHDEREF(ch)) == L('\0')) { 7297049Speter SetChar(win->_nc_bkgd, BLANK_TEXT, AttrOf(CHDEREF(ch))); 73178866Srafan if_EXT_COLORS(SetPair(win->_nc_bkgd, GetPair(CHDEREF(ch)))); 74166124Srafan } else { 7597049Speter win->_nc_bkgd = CHDEREF(ch); 76166124Srafan } 7797049Speter#if USE_WIDEC_SUPPORT 7897049Speter /* 7997049Speter * If we're compiled for wide-character support, _bkgrnd is the 8097049Speter * preferred location for the background information since it stores 8197049Speter * more than _bkgd. Update _bkgd each time we modify _bkgrnd, so the 8297049Speter * macro getbkgd() will work. 8397049Speter */ 8497049Speter { 8597049Speter cchar_t wch; 8697049Speter int tmp; 8797049Speter 8897049Speter wgetbkgrnd(win, &wch); 89166124Srafan tmp = _nc_to_char((wint_t) CharOf(wch)); 9097049Speter 91166124Srafan win->_bkgd = (((tmp == EOF) ? ' ' : (chtype) tmp) 92166124Srafan | (AttrOf(wch) & ALL_BUT_COLOR) 93166124Srafan | COLOR_PAIR(GET_WINDOW_PAIR(win))); 9497049Speter } 9597049Speter#endif 9676726Speter } 9776726Speter returnVoid; 9850276Speter} 9950276Speter 10097049SpeterNCURSES_EXPORT(void) 10197049Speterwbkgdset(WINDOW *win, chtype ch) 10297049Speter{ 10397049Speter NCURSES_CH_T wch; 10497049Speter SetChar2(wch, ch); 10597049Speter wbkgrndset(win, CHREF(wch)); 10697049Speter} 10797049Speter 10897049Speter/* 10997049Speter * Set the window's background information and apply it to each cell. 11097049Speter */ 11197049Speter#if USE_WIDEC_SUPPORT 11276726SpeterNCURSES_EXPORT(int) 11397049Speter#else 114166124Srafanstatic NCURSES_INLINE int 11597049Speter#undef wbkgrnd 11697049Speter#endif 11797049Speterwbkgrnd(WINDOW *win, const ARG_CH_T ch) 11850276Speter{ 11976726Speter int code = ERR; 12076726Speter int x, y; 12197049Speter NCURSES_CH_T new_bkgd = CHDEREF(ch); 12250276Speter 12397049Speter T((T_CALLED("wbkgd(%p,%s)"), win, _tracech_t(ch))); 12450276Speter 12576726Speter if (win) { 12697049Speter NCURSES_CH_T old_bkgrnd; 12797049Speter wgetbkgrnd(win, &old_bkgrnd); 12850276Speter 12997049Speter wbkgrndset(win, CHREF(new_bkgd)); 13097049Speter wattrset(win, AttrOf(win->_nc_bkgd)); 13176726Speter 13276726Speter for (y = 0; y <= win->_maxy; y++) { 13376726Speter for (x = 0; x <= win->_maxx; x++) { 134166124Srafan if (CharEq(win->_line[y].text[x], old_bkgrnd)) { 13597049Speter win->_line[y].text[x] = win->_nc_bkgd; 136166124Srafan } else { 13797049Speter NCURSES_CH_T wch = win->_line[y].text[x]; 138166124Srafan RemAttr(wch, (~(A_ALTCHARSET | A_CHARTEXT))); 13997049Speter win->_line[y].text[x] = _nc_render(win, wch); 14097049Speter } 14176726Speter } 14276726Speter } 14376726Speter touchwin(win); 14476726Speter _nc_synchook(win); 14576726Speter code = OK; 14650276Speter } 14776726Speter returnCode(code); 14850276Speter} 14997049Speter 15097049SpeterNCURSES_EXPORT(int) 151166124Srafanwbkgd(WINDOW *win, chtype ch) 15297049Speter{ 15397049Speter NCURSES_CH_T wch; 15497049Speter SetChar2(wch, ch); 15597049Speter return wbkgrnd(win, CHREF(wch)); 15697049Speter} 157