1 /* Public Domain Curses */
5 RCSID("$Id: bkgd.c,v 1.39 2008/07/13 16:08:18 wmcbrine Exp $")
7 /*man-start**************************************************************
13 void bkgdset(chtype ch);
14 chtype getbkgd(WINDOW *win);
15 int wbkgd(WINDOW *win, chtype ch);
16 void wbkgdset(WINDOW *win, chtype ch);
18 int bkgrnd(const cchar_t *wch);
19 void bkgrndset(const cchar_t *wch);
20 int getbkgrnd(cchar_t *wch);
21 int wbkgrnd(WINDOW *win, const cchar_t *wch);
22 void wbkgrndset(WINDOW *win, const cchar_t *wch);
23 int wgetbkgrnd(WINDOW *win, cchar_t *wch);
26 bkgdset() and wbkgdset() manipulate the background of a window.
27 The background is a chtype consisting of any combination of
28 attributes and a character; it is combined with each chtype
29 added or inserted to the window by waddch() or winsch(). Only
30 the attribute part is used to set the background of non-blank
31 characters, while both character and attributes are used for
34 bkgd() and wbkgd() not only change the background, but apply it
35 immediately to every cell in the window.
37 The attributes that are defined with the attrset()/attron() set
38 of functions take precedence over the background attributes if
39 there is a conflict (e.g., different color pairs).
42 bkgd() and wbkgd() return OK, unless the window is NULL, in
43 which case they return ERR.
45 Portability X/Open BSD SYS V
58 **man-end****************************************************************/
60 int wbkgd(WINDOW
*win
, chtype ch
)
63 chtype oldcolr
, oldch
, newcolr
, newch
, colr
, attr
;
64 chtype oldattr
= 0, newattr
= 0;
67 PDC_LOG(("wbkgd() - called\n"));
75 oldcolr
= win
->_bkgd
& A_COLOR
;
77 oldattr
= (win
->_bkgd
& A_ATTRIBUTES
) ^ oldcolr
;
79 oldch
= win
->_bkgd
& A_CHARTEXT
;
83 newcolr
= win
->_bkgd
& A_COLOR
;
85 newattr
= (win
->_bkgd
& A_ATTRIBUTES
) ^ newcolr
;
87 newch
= win
->_bkgd
& A_CHARTEXT
;
89 /* what follows is what seems to occur in the System V
90 implementation of this routine */
92 for (y
= 0; y
< win
->_maxy
; y
++)
94 for (x
= 0; x
< win
->_maxx
; x
++)
96 winptr
= win
->_y
[y
] + x
;
100 /* determine the colors and attributes of the character read
104 attr
= ch
& (A_ATTRIBUTES
^ A_COLOR
);
106 /* if the color is the same as the old background color,
107 then make it the new background color, otherwise leave it */
112 /* remove any attributes (non color) from the character that
113 were part of the old background, then combine the
114 remaining ones with the new background */
119 /* change character if it is there because it was the old
120 background character */
140 PDC_LOG(("bkgd() - called\n"));
142 return wbkgd(stdscr
, ch
);
145 void wbkgdset(WINDOW
*win
, chtype ch
)
147 PDC_LOG(("wbkgdset() - called\n"));
151 if (!(ch
& A_CHARTEXT
))
158 void bkgdset(chtype ch
)
160 PDC_LOG(("bkgdset() - called\n"));
162 wbkgdset(stdscr
, ch
);
165 chtype
getbkgd(WINDOW
*win
)
167 PDC_LOG(("getbkgd() - called\n"));
169 return win
? win
->_bkgd
: (chtype
)ERR
;
173 int wbkgrnd(WINDOW
*win
, const cchar_t
*wch
)
175 PDC_LOG(("wbkgrnd() - called\n"));
177 return wch
? wbkgd(win
, *wch
) : ERR
;
180 int bkgrnd(const cchar_t
*wch
)
182 PDC_LOG(("bkgrnd() - called\n"));
184 return wbkgrnd(stdscr
, wch
);
187 void wbkgrndset(WINDOW
*win
, const cchar_t
*wch
)
189 PDC_LOG(("wbkgdset() - called\n"));
195 void bkgrndset(const cchar_t
*wch
)
197 PDC_LOG(("bkgrndset() - called\n"));
199 wbkgrndset(stdscr
, wch
);
202 int wgetbkgrnd(WINDOW
*win
, cchar_t
*wch
)
204 PDC_LOG(("wgetbkgrnd() - called\n"));
214 int getbkgrnd(cchar_t
*wch
)
216 PDC_LOG(("getbkgrnd() - called\n"));
218 return wgetbkgrnd(stdscr
, wch
);