1 /****************************************************************************
2 * Copyright (c) 1998,2001-2002 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
34 #include <curses.priv.h>
36 MODULE_ID("$Id: lib_bkgd.c,v 1.30 2003/07/05 16:46:49 tom Exp $")
39 * Set the window's background information.
46 wbkgrndset(WINDOW *win, const ARG_CH_T ch)
48 T((T_CALLED("wbkgdset(%p,%s)"), win, _tracech_t(ch)));
51 attr_t off = AttrOf(win->_nc_bkgd);
52 attr_t on = AttrOf(CHDEREF(ch));
54 toggle_attr_off(win->_attrs, off);
55 toggle_attr_on(win->_attrs, on);
57 if (CharOf(CHDEREF(ch)) == L('\0'))
58 SetChar(win->_nc_bkgd, BLANK_TEXT, AttrOf(CHDEREF(ch)));
60 win->_nc_bkgd = CHDEREF(ch);
63 * If we're compiled for wide-character support, _bkgrnd is the
64 * preferred location for the background information since it stores
65 * more than _bkgd. Update _bkgd each time we modify _bkgrnd, so the
66 * macro getbkgd() will work.
72 wgetbkgrnd(win, &wch);
73 tmp = _nc_to_char(CharOf(wch));
75 win->_bkgd = ((tmp == EOF) ? ' ' : (chtype) tmp) | AttrOf(wch);
83 wbkgdset(WINDOW *win, chtype ch)
87 wbkgrndset(win, CHREF(wch));
91 * Set the window's background information and apply it to each cell.
99 wbkgrnd(WINDOW *win, const ARG_CH_T ch)
103 NCURSES_CH_T new_bkgd = CHDEREF(ch);
105 T((T_CALLED("wbkgd(%p,%s)"), win, _tracech_t(ch)));
108 NCURSES_CH_T old_bkgrnd;
109 wgetbkgrnd(win, &old_bkgrnd);
111 wbkgrndset(win, CHREF(new_bkgd));
112 wattrset(win, AttrOf(win->_nc_bkgd));
114 for (y = 0; y <= win->_maxy; y++) {
115 for (x = 0; x <= win->_maxx; x++) {
116 if (CharEq(win->_line[y].text[x], old_bkgrnd))
117 win->_line[y].text[x] = win->_nc_bkgd;
119 NCURSES_CH_T wch = win->_line[y].text[x];
120 RemAttr(wch, (~A_ALTCHARSET));
121 win->_line[y].text[x] = _nc_render(win, wch);
133 wbkgd(WINDOW *win, chtype ch)
137 return wbkgrnd(win, CHREF(wch));