diff options
Diffstat (limited to 'scripts/kconfig/libcurses/bkgd.c')
-rw-r--r-- | scripts/kconfig/libcurses/bkgd.c | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/bkgd.c b/scripts/kconfig/libcurses/bkgd.c new file mode 100644 index 000000000..af2d0e054 --- /dev/null +++ b/scripts/kconfig/libcurses/bkgd.c | |||
@@ -0,0 +1,226 @@ | |||
1 | /* PDCurses */ | ||
2 | |||
3 | #include "curspriv.h" | ||
4 | |||
5 | /*man-start************************************************************** | ||
6 | |||
7 | bkgd | ||
8 | ---- | ||
9 | |||
10 | ### Synopsis | ||
11 | |||
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); | ||
17 | |||
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); | ||
24 | |||
25 | ### Description | ||
26 | |||
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. | ||
33 | |||
34 | bkgd() and wbkgd() not only change the background, but apply it | ||
35 | immediately to every cell in the window. | ||
36 | |||
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. | ||
40 | |||
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). | ||
44 | |||
45 | ### Return Value | ||
46 | |||
47 | bkgd() and wbkgd() return OK, unless the window is NULL, in which | ||
48 | case they return ERR. | ||
49 | |||
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 | ||
63 | |||
64 | **man-end****************************************************************/ | ||
65 | |||
66 | int wbkgd(WINDOW *win, chtype ch) | ||
67 | { | ||
68 | int x, y; | ||
69 | chtype oldcolr, oldch, newcolr, newch, colr, attr; | ||
70 | chtype oldattr = 0, newattr = 0; | ||
71 | chtype *winptr; | ||
72 | |||
73 | PDC_LOG(("wbkgd() - called\n")); | ||
74 | |||
75 | if (!win) | ||
76 | return ERR; | ||
77 | |||
78 | if (win->_bkgd == ch) | ||
79 | return OK; | ||
80 | |||
81 | oldcolr = win->_bkgd & A_COLOR; | ||
82 | if (oldcolr) | ||
83 | oldattr = (win->_bkgd & A_ATTRIBUTES) ^ oldcolr; | ||
84 | |||
85 | oldch = win->_bkgd & A_CHARTEXT; | ||
86 | |||
87 | wbkgdset(win, ch); | ||
88 | |||
89 | newcolr = win->_bkgd & A_COLOR; | ||
90 | if (newcolr) | ||
91 | newattr = (win->_bkgd & A_ATTRIBUTES) ^ newcolr; | ||
92 | |||
93 | newch = win->_bkgd & A_CHARTEXT; | ||
94 | |||
95 | /* what follows is what seems to occur in the System V | ||
96 | implementation of this routine */ | ||
97 | |||
98 | for (y = 0; y < win->_maxy; y++) | ||
99 | { | ||
100 | for (x = 0; x < win->_maxx; x++) | ||
101 | { | ||
102 | winptr = win->_y[y] + x; | ||
103 | |||
104 | ch = *winptr; | ||
105 | |||
106 | /* determine the colors and attributes of the character read | ||
107 | from the window */ | ||
108 | |||
109 | colr = ch & A_COLOR; | ||
110 | attr = ch & (A_ATTRIBUTES ^ A_COLOR); | ||
111 | |||
112 | /* if the color is the same as the old background color, | ||
113 | then make it the new background color, otherwise leave it */ | ||
114 | |||
115 | if (colr == oldcolr) | ||
116 | colr = newcolr; | ||
117 | |||
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 */ | ||
121 | |||
122 | attr ^= oldattr; | ||
123 | attr |= newattr; | ||
124 | |||
125 | /* change character if it is there because it was the old | ||
126 | background character */ | ||
127 | |||
128 | ch &= A_CHARTEXT; | ||
129 | if (ch == oldch) | ||
130 | ch = newch; | ||
131 | |||
132 | ch |= (attr | colr); | ||
133 | |||
134 | *winptr = ch; | ||
135 | |||
136 | } | ||
137 | } | ||
138 | |||
139 | touchwin(win); | ||
140 | PDC_sync(win); | ||
141 | return OK; | ||
142 | } | ||
143 | |||
144 | int bkgd(chtype ch) | ||
145 | { | ||
146 | PDC_LOG(("bkgd() - called\n")); | ||
147 | |||
148 | return wbkgd(stdscr, ch); | ||
149 | } | ||
150 | |||
151 | void wbkgdset(WINDOW *win, chtype ch) | ||
152 | { | ||
153 | PDC_LOG(("wbkgdset() - called\n")); | ||
154 | |||
155 | if (win) | ||
156 | { | ||
157 | if (!(ch & A_CHARTEXT)) | ||
158 | ch |= ' '; | ||
159 | |||
160 | win->_bkgd = ch; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | void bkgdset(chtype ch) | ||
165 | { | ||
166 | PDC_LOG(("bkgdset() - called\n")); | ||
167 | |||
168 | wbkgdset(stdscr, ch); | ||
169 | } | ||
170 | |||
171 | chtype getbkgd(WINDOW *win) | ||
172 | { | ||
173 | PDC_LOG(("getbkgd() - called\n")); | ||
174 | |||
175 | return win ? win->_bkgd : (chtype)ERR; | ||
176 | } | ||
177 | |||
178 | #ifdef PDC_WIDE | ||
179 | int wbkgrnd(WINDOW *win, const cchar_t *wch) | ||
180 | { | ||
181 | PDC_LOG(("wbkgrnd() - called\n")); | ||
182 | |||
183 | return wch ? wbkgd(win, *wch) : ERR; | ||
184 | } | ||
185 | |||
186 | int bkgrnd(const cchar_t *wch) | ||
187 | { | ||
188 | PDC_LOG(("bkgrnd() - called\n")); | ||
189 | |||
190 | return wbkgrnd(stdscr, wch); | ||
191 | } | ||
192 | |||
193 | void wbkgrndset(WINDOW *win, const cchar_t *wch) | ||
194 | { | ||
195 | PDC_LOG(("wbkgdset() - called\n")); | ||
196 | |||
197 | if (wch) | ||
198 | wbkgdset(win, *wch); | ||
199 | } | ||
200 | |||
201 | void bkgrndset(const cchar_t *wch) | ||
202 | { | ||
203 | PDC_LOG(("bkgrndset() - called\n")); | ||
204 | |||
205 | wbkgrndset(stdscr, wch); | ||
206 | } | ||
207 | |||
208 | int wgetbkgrnd(WINDOW *win, cchar_t *wch) | ||
209 | { | ||
210 | PDC_LOG(("wgetbkgrnd() - called\n")); | ||
211 | |||
212 | if (!win || !wch) | ||
213 | return ERR; | ||
214 | |||
215 | *wch = win->_bkgd; | ||
216 | |||
217 | return OK; | ||
218 | } | ||
219 | |||
220 | int getbkgrnd(cchar_t *wch) | ||
221 | { | ||
222 | PDC_LOG(("getbkgrnd() - called\n")); | ||
223 | |||
224 | return wgetbkgrnd(stdscr, wch); | ||
225 | } | ||
226 | #endif | ||