blob: c46ca42aed56540e9d9219b20ab303e978f3ff5d [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
Steve Kondikae271bc2015-11-15 02:50:53 +01002 * Copyright (c) 1998-2012,2014 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05303 * *
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: *
11 * *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
14 * *
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. *
22 * *
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 *
26 * authorization. *
27 ****************************************************************************/
28
29/****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Juergen Pfeifer 1997 *
33 * and: Sven Verdoolaege 2000 *
34 * and: Thomas E. Dickey 1996-on *
35 ****************************************************************************/
36
37#include <curses.priv.h>
38
Steve Kondikae271bc2015-11-15 02:50:53 +010039MODULE_ID("$Id: lib_bkgd.c,v 1.49 2014/09/04 09:36:20 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053040
41/*
42 * Set the window's background information.
43 */
44#if USE_WIDEC_SUPPORT
45NCURSES_EXPORT(void)
46#else
47static NCURSES_INLINE void
48#endif
49wbkgrndset(WINDOW *win, const ARG_CH_T ch)
50{
Steve Kondikae271bc2015-11-15 02:50:53 +010051 T((T_CALLED("wbkgdset(%p,%s)"), (void *) win, _tracech_t(ch)));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053052
53 if (win) {
54 attr_t off = AttrOf(win->_nc_bkgd);
55 attr_t on = AttrOf(CHDEREF(ch));
56
57 toggle_attr_off(WINDOW_ATTRS(win), off);
58 toggle_attr_on(WINDOW_ATTRS(win), on);
59
60#if NCURSES_EXT_COLORS
61 {
62 int pair;
63
64 if ((pair = GetPair(win->_nc_bkgd)) != 0)
65 SET_WINDOW_PAIR(win, 0);
66 if ((pair = GetPair(CHDEREF(ch))) != 0)
67 SET_WINDOW_PAIR(win, pair);
68 }
69#endif
70
71 if (CharOf(CHDEREF(ch)) == L('\0')) {
72 SetChar(win->_nc_bkgd, BLANK_TEXT, AttrOf(CHDEREF(ch)));
73 if_EXT_COLORS(SetPair(win->_nc_bkgd, GetPair(CHDEREF(ch))));
74 } else {
75 win->_nc_bkgd = CHDEREF(ch);
76 }
77#if USE_WIDEC_SUPPORT
78 /*
79 * If we're compiled for wide-character support, _bkgrnd is the
80 * preferred location for the background information since it stores
81 * more than _bkgd. Update _bkgd each time we modify _bkgrnd, so the
82 * macro getbkgd() will work.
83 */
84 {
85 cchar_t wch;
86 int tmp;
87
Steve Kondikae271bc2015-11-15 02:50:53 +010088 memset(&wch, 0, sizeof(wch));
89 (void) wgetbkgrnd(win, &wch);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053090 tmp = _nc_to_char((wint_t) CharOf(wch));
91
92 win->_bkgd = (((tmp == EOF) ? ' ' : (chtype) tmp)
93 | (AttrOf(wch) & ALL_BUT_COLOR)
Steve Kondikae271bc2015-11-15 02:50:53 +010094 | (chtype) ColorPair(GET_WINDOW_PAIR(win)));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053095 }
96#endif
97 }
98 returnVoid;
99}
100
101NCURSES_EXPORT(void)
102wbkgdset(WINDOW *win, chtype ch)
103{
104 NCURSES_CH_T wch;
105 SetChar2(wch, ch);
106 wbkgrndset(win, CHREF(wch));
107}
108
109/*
110 * Set the window's background information and apply it to each cell.
111 */
112#if USE_WIDEC_SUPPORT
113NCURSES_EXPORT(int)
114#else
115static NCURSES_INLINE int
116#undef wbkgrnd
117#endif
118wbkgrnd(WINDOW *win, const ARG_CH_T ch)
119{
120 int code = ERR;
121 int x, y;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530122
Steve Kondikae271bc2015-11-15 02:50:53 +0100123 T((T_CALLED("wbkgd(%p,%s)"), (void *) win, _tracech_t(ch)));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530124
125 if (win) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100126 NCURSES_CH_T new_bkgd = CHDEREF(ch);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530127 NCURSES_CH_T old_bkgrnd;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530128
Steve Kondikae271bc2015-11-15 02:50:53 +0100129 memset(&old_bkgrnd, 0, sizeof(old_bkgrnd));
130 (void) wgetbkgrnd(win, &old_bkgrnd);
131
132 (void) wbkgrndset(win, CHREF(new_bkgd));
133 (void) wattrset(win, (int) AttrOf(win->_nc_bkgd));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530134
135 for (y = 0; y <= win->_maxy; y++) {
136 for (x = 0; x <= win->_maxx; x++) {
137 if (CharEq(win->_line[y].text[x], old_bkgrnd)) {
138 win->_line[y].text[x] = win->_nc_bkgd;
139 } else {
140 NCURSES_CH_T wch = win->_line[y].text[x];
141 RemAttr(wch, (~(A_ALTCHARSET | A_CHARTEXT)));
142 win->_line[y].text[x] = _nc_render(win, wch);
143 }
144 }
145 }
146 touchwin(win);
147 _nc_synchook(win);
148 code = OK;
149 }
150 returnCode(code);
151}
152
153NCURSES_EXPORT(int)
154wbkgd(WINDOW *win, chtype ch)
155{
156 NCURSES_CH_T wch;
157 SetChar2(wch, ch);
158 return wbkgrnd(win, CHREF(wch));
159}