Merge branch 'release-4.0'
[kiteware-cmake.git] / Utilities / cmpdcurses / pdcurses / bkgd.c
blobf576437317f5e87858b0c0b956bb0b2bff74bcda
1 /* PDCurses */
3 #include <curspriv.h>
5 /*man-start**************************************************************
7 bkgd
8 ----
10 ### Synopsis
12 int bkgd(chtype ch);
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);
25 ### Description
27 bkgdset() and wbkgdset() manipulate the background of a window. The
28 background is a chtype consisting of any combination of attributes
29 and a character; it is combined with each chtype added or inserted to
30 the window by waddch() or winsch(). Only the attribute part is used
31 to set the background of non-blank characters, while both character
32 and attributes are used for blank positions.
34 bkgd() and wbkgd() not only change the background, but apply it
35 immediately to every cell in the window.
37 wbkgrnd(), wbkgrndset() and wgetbkgrnd() are the "wide-character"
38 versions of these functions, taking a pointer to a cchar_t instead of
39 a chtype. However, in PDCurses, cchar_t and chtype are the same.
41 The attributes that are defined with the attrset()/attron() set of
42 functions take precedence over the background attributes if there is
43 a conflict (e.g., different color pairs).
45 ### Return Value
47 bkgd() and wbkgd() return OK, unless the window is NULL, in which
48 case they return ERR.
50 ### Portability
51 X/Open ncurses NetBSD
52 bkgd Y Y Y
53 bkgdset Y Y Y
54 getbkgd Y Y Y
55 wbkgd Y Y Y
56 wbkgdset Y Y Y
57 bkgrnd Y Y Y
58 bkgrndset Y Y Y
59 getbkgrnd Y Y Y
60 wbkgrnd Y Y Y
61 wbkgrndset Y Y Y
62 wgetbkgrnd Y Y Y
64 **man-end****************************************************************/
66 int wbkgd(WINDOW *win, chtype ch)
68 int x, y;
69 chtype oldcolr, oldch, newcolr, newch, colr, attr;
70 chtype oldattr = 0, newattr = 0;
71 chtype *winptr;
73 PDC_LOG(("wbkgd() - called\n"));
75 if (!win)
76 return ERR;
78 if (win->_bkgd == ch)
79 return OK;
81 oldcolr = win->_bkgd & A_COLOR;
82 if (oldcolr)
83 oldattr = (win->_bkgd & A_ATTRIBUTES) ^ oldcolr;
85 oldch = win->_bkgd & A_CHARTEXT;
87 wbkgdset(win, ch);
89 newcolr = win->_bkgd & A_COLOR;
90 if (newcolr)
91 newattr = (win->_bkgd & A_ATTRIBUTES) ^ newcolr;
93 newch = win->_bkgd & A_CHARTEXT;
95 /* what follows is what seems to occur in the System V
96 implementation of this routine */
98 for (y = 0; y < win->_maxy; y++)
100 for (x = 0; x < win->_maxx; x++)
102 winptr = win->_y[y] + x;
104 ch = *winptr;
106 /* determine the colors and attributes of the character read
107 from the window */
109 colr = ch & A_COLOR;
110 attr = ch & (A_ATTRIBUTES ^ A_COLOR);
112 /* if the color is the same as the old background color,
113 then make it the new background color, otherwise leave it */
115 if (colr == oldcolr)
116 colr = newcolr;
118 /* remove any attributes (non color) from the character that
119 were part of the old background, then combine the
120 remaining ones with the new background */
122 attr ^= oldattr;
123 attr |= newattr;
125 /* change character if it is there because it was the old
126 background character */
128 ch &= A_CHARTEXT;
129 if (ch == oldch)
130 ch = newch;
132 ch |= (attr | colr);
134 *winptr = ch;
139 touchwin(win);
140 PDC_sync(win);
141 return OK;
144 int bkgd(chtype ch)
146 PDC_LOG(("bkgd() - called\n"));
148 return wbkgd(stdscr, ch);
151 void wbkgdset(WINDOW *win, chtype ch)
153 PDC_LOG(("wbkgdset() - called\n"));
155 if (win)
157 if (!(ch & A_CHARTEXT))
158 ch |= ' ';
160 win->_bkgd = ch;
164 void bkgdset(chtype ch)
166 PDC_LOG(("bkgdset() - called\n"));
168 wbkgdset(stdscr, ch);
171 chtype getbkgd(WINDOW *win)
173 PDC_LOG(("getbkgd() - called\n"));
175 return win ? win->_bkgd : (chtype)ERR;
178 #ifdef PDC_WIDE
179 int wbkgrnd(WINDOW *win, const cchar_t *wch)
181 PDC_LOG(("wbkgrnd() - called\n"));
183 return wch ? wbkgd(win, *wch) : ERR;
186 int bkgrnd(const cchar_t *wch)
188 PDC_LOG(("bkgrnd() - called\n"));
190 return wbkgrnd(stdscr, wch);
193 void wbkgrndset(WINDOW *win, const cchar_t *wch)
195 PDC_LOG(("wbkgdset() - called\n"));
197 if (wch)
198 wbkgdset(win, *wch);
201 void bkgrndset(const cchar_t *wch)
203 PDC_LOG(("bkgrndset() - called\n"));
205 wbkgrndset(stdscr, wch);
208 int wgetbkgrnd(WINDOW *win, cchar_t *wch)
210 PDC_LOG(("wgetbkgrnd() - called\n"));
212 if (!win || !wch)
213 return ERR;
215 *wch = win->_bkgd;
217 return OK;
220 int getbkgrnd(cchar_t *wch)
222 PDC_LOG(("getbkgrnd() - called\n"));
224 return wgetbkgrnd(stdscr, wch);
226 #endif