attributes.c revision 1.2 1 /* $NetBSD: attributes.c,v 1.2 2000/04/11 13:57:08 blymn Exp $ */
2
3 /*
4 * Copyright (c) 1999 Julian. D. Coleman
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include "curses.h"
29 #include "curses_private.h"
30
31 /*
32 * wattron
33 * Test and set attributes.
34 *
35 * Modes are blinking, bold (extra bright), dim (half-bright),
36 * blanking (invisible), protected and reverse video
37 */
38
39 int
40 wattron(win, attr)
41 WINDOW *win;
42 int attr;
43 {
44 if ((attr_t) attr & __BLINK) {
45 /*
46 * If can do blink, set the screen blink bit.
47 */
48 if (MB != NULL && ME != NULL) {
49 #ifdef DEBUG
50 __CTRACE("wattron: BLINK\n");
51 #endif
52 win->wattr |= __BLINK;
53 }
54 }
55 if ((attr_t) attr & __BOLD) {
56 /*
57 * If can do bold, set the screen bold bit.
58 */
59 if (MD != NULL && ME != NULL) {
60 #ifdef DEBUG
61 __CTRACE("wattron: BOLD\n");
62 #endif
63 win->wattr |= __BOLD;
64 }
65 }
66 if ((attr_t) attr & __DIM) {
67 /*
68 * If can do dim, set the screen dim bit.
69 */
70 if (MH != NULL && ME != NULL) {
71 #ifdef DEBUG
72 __CTRACE("wattron: DIM\n");
73 #endif
74 win->wattr |= __DIM;
75 }
76 }
77 if ((attr_t) attr & __BLANK) {
78 /*
79 * If can do blink, set the screen blink bit.
80 */
81 if (MK != NULL && ME != NULL) {
82 #ifdef DEBUG
83 __CTRACE("wattron: BLANK\n");
84 #endif
85 win->wattr |= __BLANK;
86 }
87 }
88 if ((attr_t) attr & __PROTECT) {
89 /*
90 * If can do protected, set the screen protected bit.
91 */
92 if (MP != NULL && ME != NULL) {
93 #ifdef DEBUG
94 __CTRACE("wattron: PROTECT\n");
95 #endif
96 win->wattr |= __PROTECT;
97 }
98 }
99 if ((attr_t) attr & __REVERSE) {
100 /*
101 * If can do reverse video, set the screen reverse video bit.
102 */
103 if (MR != NULL && ME != NULL)
104 {
105 #ifdef DEBUG
106 __CTRACE("wattron: REVERSE\n");
107 #endif
108 win->wattr |= __REVERSE;
109 }
110 }
111 if ((attr_t) attr & __STANDOUT) {
112 wstandout(win);
113 }
114 if (attr & __UNDERSCORE) {
115 wunderscore(win);
116 }
117 return (1);
118 }
119
120 /*
121 * wattroff
122 * Test and unset attributes.
123 *
124 * Note that the 'me' sequence unsets all attributes. We handle
125 * which attributes should really be set in refresh.c:makech().
126 */
127 int
128 wattroff(win, attr)
129 WINDOW *win;
130 int attr;
131 {
132 /*
133 * If can do exit modes, unset the relevent attribute bits.
134 */
135 if ((attr_t) attr & __BLINK) {
136 if (ME != NULL) {
137 #ifdef DEBUG
138 __CTRACE("wattroff: BLINK\n");
139 #endif
140 win->wattr &= ~__BLINK;
141 }
142 }
143 if ((attr_t) attr & __BOLD) {
144 if (ME != NULL) {
145 #ifdef DEBUG
146 __CTRACE("wattroff: BOLD\n");
147 #endif
148 win->wattr &= ~__BOLD;
149 }
150 }
151 if ((attr_t) attr & __DIM) {
152 if (ME != NULL) {
153 #ifdef DEBUG
154 __CTRACE("wattroff: DIM\n");
155 #endif
156 win->wattr &= ~__DIM;
157 }
158 }
159 if ((attr_t) attr & __BLANK) {
160 if (ME != NULL) {
161 #ifdef DEBUG
162 __CTRACE("wattroff: BLANK\n");
163 #endif
164 win->wattr &= ~__BLANK;
165 }
166 }
167 if ((attr_t) attr & __PROTECT) {
168 if (ME != NULL) {
169 #ifdef DEBUG
170 __CTRACE("wattroff: PROTECT\n");
171 #endif
172 win->wattr &= ~__PROTECT;
173 }
174 }
175 if ((attr_t) attr & __REVERSE) {
176 if (ME != NULL) {
177 #ifdef DEBUG
178 __CTRACE("wattroff: REVERSE\n");
179 #endif
180 win->wattr &= ~__REVERSE;
181 }
182 }
183 if ((attr_t) attr & __STANDOUT) {
184 wstandend(win);
185 }
186 if (attr & __UNDERSCORE) {
187 wunderend(win);
188 }
189 return (1);
190 }
191
192 /*
193 * wattrset
194 * Set specific attribute modes.
195 * Unset others.
196 */
197 int
198 wattrset(win, attr)
199 WINDOW *win;
200 int attr;
201 {
202 if ((attr_t) attr & __BLINK) {
203 if (MB != NULL && ME != NULL) {
204 #ifdef DEBUG
205 __CTRACE("wattrset: BLINK\n");
206 #endif
207 win->wattr |= __BLINK;
208 }
209 } else {
210 if (ME != NULL) {
211 #ifdef DEBUG
212 __CTRACE("wattrset: !BLINK\n");
213 #endif
214 win->wattr &= ~__BLINK;
215 }
216 }
217 if ((attr_t) attr & __BOLD) {
218 if (MD != NULL && ME != NULL) {
219 #ifdef DEBUG
220 __CTRACE("wattrset: BOLD\n");
221 #endif
222 win->wattr |= __BOLD;
223 }
224 } else {
225 if (ME != NULL) {
226 #ifdef DEBUG
227 __CTRACE("wattrset: !BOLD\n");
228 #endif
229 win->wattr &= ~__BOLD;
230 }
231 }
232 if ((attr_t) attr & __DIM) {
233 if (MH != NULL && ME != NULL) {
234 #ifdef DEBUG
235 __CTRACE("wattrset: DIM\n");
236 #endif
237 win->wattr |= __DIM;
238 }
239 } else {
240 if (ME != NULL) {
241 #ifdef DEBUG
242 __CTRACE("wattrset: !DIM\n");
243 #endif
244 win->wattr &= ~__DIM;
245 }
246 }
247 if ((attr_t) attr & __BLANK) {
248 if (MK != NULL && ME != NULL) {
249 #ifdef DEBUG
250 __CTRACE("wattrset: BLANK\n");
251 #endif
252 win->wattr |= __BLANK;
253 }
254 } else {
255 if (ME != NULL) {
256 #ifdef DEBUG
257 __CTRACE("wattrset: !BLANK\n");
258 #endif
259 win->wattr &= ~__BLANK;
260 }
261 }
262 if ((attr_t) attr & __PROTECT) {
263 if (MP != NULL && ME != NULL) {
264 #ifdef DEBUG
265 __CTRACE("wattrset: PROTECT\n");
266 #endif
267 win->wattr |= __PROTECT;
268 }
269 } else {
270 if (ME != NULL) {
271 #ifdef DEBUG
272 __CTRACE("wattrset: !PROTECT\n");
273 #endif
274 win->wattr &= ~__PROTECT;
275 }
276 }
277 if ((attr_t) attr & __REVERSE) {
278 if (MR != NULL && ME != NULL)
279 {
280 #ifdef DEBUG
281 __CTRACE("wattrset: REVERSE\n");
282 #endif
283 win->wattr |= __REVERSE;
284 }
285 } else {
286 if (ME != NULL) {
287 #ifdef DEBUG
288 __CTRACE("wattrset: !REVERSE\n");
289 #endif
290 win->wattr &= ~__REVERSE;
291 }
292 }
293 if ((attr_t) attr & __STANDOUT) {
294 wstandout(win);
295 } else {
296 wstandend(win);
297 }
298 if (attr & __UNDERSCORE) {
299 wunderscore(win);
300 } else {
301 wunderend(win);
302 }
303 return (1);
304 }
305