attributes.c revision 1.1.6.1 1 /* $NetBSD: attributes.c,v 1.1.6.1 2000/01/09 20:43:17 jdc 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
30 /*
31 * wattron
32 * Test and set attributes.
33 *
34 * Modes are blinking, bold (extra bright), dim (half-bright),
35 * blanking (invisible), protected and reverse video
36 */
37
38 int
39 wattron(win, attr)
40 WINDOW *win;
41 int attr;
42 {
43 if ((attr_t) attr & __BLINK) {
44 /*
45 * If can do blink, set the screen blink bit.
46 */
47 if (MB != NULL && ME != NULL) {
48 #ifdef DEBUG
49 __CTRACE("wattron: BLINK\n");
50 #endif
51 win->wattr |= __BLINK;
52 }
53 }
54 if ((attr_t) attr & __BOLD) {
55 /*
56 * If can do bold, set the screen bold bit.
57 */
58 if (MD != NULL && ME != NULL) {
59 #ifdef DEBUG
60 __CTRACE("wattron: BOLD\n");
61 #endif
62 win->wattr |= __BOLD;
63 }
64 }
65 if ((attr_t) attr & __DIM) {
66 /*
67 * If can do dim, set the screen dim bit.
68 */
69 if (MH != NULL && ME != NULL) {
70 #ifdef DEBUG
71 __CTRACE("wattron: DIM\n");
72 #endif
73 win->wattr |= __DIM;
74 }
75 }
76 if ((attr_t) attr & __BLANK) {
77 /*
78 * If can do blink, set the screen blink bit.
79 */
80 if (MK != NULL && ME != NULL) {
81 #ifdef DEBUG
82 __CTRACE("wattron: BLANK\n");
83 #endif
84 win->wattr |= __BLANK;
85 }
86 }
87 if ((attr_t) attr & __PROTECT) {
88 /*
89 * If can do protected, set the screen protected bit.
90 */
91 if (MP != NULL && ME != NULL) {
92 #ifdef DEBUG
93 __CTRACE("wattron: PROTECT\n");
94 #endif
95 win->wattr |= __PROTECT;
96 }
97 }
98 if ((attr_t) attr & __REVERSE) {
99 /*
100 * If can do reverse video, set the screen reverse video bit.
101 */
102 if (MR != NULL && ME != NULL)
103 {
104 #ifdef DEBUG
105 __CTRACE("wattron: REVERSE\n");
106 #endif
107 win->wattr |= __REVERSE;
108 }
109 }
110 if ((attr_t) attr & __STANDOUT) {
111 wstandout(win);
112 }
113 if (attr & __UNDERSCORE) {
114 wunderscore(win);
115 }
116 return (1);
117 }
118
119 /*
120 * wattroff
121 * Test and unset attributes.
122 *
123 * Note that the 'me' sequence unsets all attributes. We handle
124 * which attributes should really be set in refresh.c:makech().
125 */
126 int
127 wattroff(win, attr)
128 WINDOW *win;
129 int attr;
130 {
131 /*
132 * If can do exit modes, unset the relevent attribute bits.
133 */
134 if ((attr_t) attr & __BLINK) {
135 if (ME != NULL) {
136 #ifdef DEBUG
137 __CTRACE("wattroff: BLINK\n");
138 #endif
139 win->wattr &= ~__BLINK;
140 }
141 }
142 if ((attr_t) attr & __BOLD) {
143 if (ME != NULL) {
144 #ifdef DEBUG
145 __CTRACE("wattroff: BOLD\n");
146 #endif
147 win->wattr &= ~__BOLD;
148 }
149 }
150 if ((attr_t) attr & __DIM) {
151 if (ME != NULL) {
152 #ifdef DEBUG
153 __CTRACE("wattroff: DIM\n");
154 #endif
155 win->wattr &= ~__DIM;
156 }
157 }
158 if ((attr_t) attr & __BLANK) {
159 if (ME != NULL) {
160 #ifdef DEBUG
161 __CTRACE("wattroff: BLANK\n");
162 #endif
163 win->wattr &= ~__BLANK;
164 }
165 }
166 if ((attr_t) attr & __PROTECT) {
167 if (ME != NULL) {
168 #ifdef DEBUG
169 __CTRACE("wattroff: PROTECT\n");
170 #endif
171 win->wattr &= ~__PROTECT;
172 }
173 }
174 if ((attr_t) attr & __REVERSE) {
175 if (ME != NULL) {
176 #ifdef DEBUG
177 __CTRACE("wattroff: REVERSE\n");
178 #endif
179 win->wattr &= ~__REVERSE;
180 }
181 }
182 if ((attr_t) attr & __STANDOUT) {
183 wstandend(win);
184 }
185 if (attr & __UNDERSCORE) {
186 wunderend(win);
187 }
188 return (1);
189 }
190
191 /*
192 * wattrset
193 * Set specific attribute modes.
194 * Unset others.
195 */
196 int
197 wattrset(win, attr)
198 WINDOW *win;
199 int attr;
200 {
201 if ((attr_t) attr & __BLINK) {
202 if (MB != NULL && ME != NULL) {
203 #ifdef DEBUG
204 __CTRACE("wattrset: BLINK\n");
205 #endif
206 win->wattr |= __BLINK;
207 }
208 } else {
209 if (ME != NULL) {
210 #ifdef DEBUG
211 __CTRACE("wattrset: !BLINK\n");
212 #endif
213 win->wattr &= ~__BLINK;
214 }
215 }
216 if ((attr_t) attr & __BOLD) {
217 if (MD != NULL && ME != NULL) {
218 #ifdef DEBUG
219 __CTRACE("wattrset: BOLD\n");
220 #endif
221 win->wattr |= __BOLD;
222 }
223 } else {
224 if (ME != NULL) {
225 #ifdef DEBUG
226 __CTRACE("wattrset: !BOLD\n");
227 #endif
228 win->wattr &= ~__BOLD;
229 }
230 }
231 if ((attr_t) attr & __DIM) {
232 if (MH != NULL && ME != NULL) {
233 #ifdef DEBUG
234 __CTRACE("wattrset: DIM\n");
235 #endif
236 win->wattr |= __DIM;
237 }
238 } else {
239 if (ME != NULL) {
240 #ifdef DEBUG
241 __CTRACE("wattrset: !DIM\n");
242 #endif
243 win->wattr &= ~__DIM;
244 }
245 }
246 if ((attr_t) attr & __BLANK) {
247 if (MK != NULL && ME != NULL) {
248 #ifdef DEBUG
249 __CTRACE("wattrset: BLANK\n");
250 #endif
251 win->wattr |= __BLANK;
252 }
253 } else {
254 if (ME != NULL) {
255 #ifdef DEBUG
256 __CTRACE("wattrset: !BLANK\n");
257 #endif
258 win->wattr &= ~__BLANK;
259 }
260 }
261 if ((attr_t) attr & __PROTECT) {
262 if (MP != NULL && ME != NULL) {
263 #ifdef DEBUG
264 __CTRACE("wattrset: PROTECT\n");
265 #endif
266 win->wattr |= __PROTECT;
267 }
268 } else {
269 if (ME != NULL) {
270 #ifdef DEBUG
271 __CTRACE("wattrset: !PROTECT\n");
272 #endif
273 win->wattr &= ~__PROTECT;
274 }
275 }
276 if ((attr_t) attr & __REVERSE) {
277 if (MR != NULL && ME != NULL)
278 {
279 #ifdef DEBUG
280 __CTRACE("wattrset: REVERSE\n");
281 #endif
282 win->wattr |= __REVERSE;
283 }
284 } else {
285 if (ME != NULL) {
286 #ifdef DEBUG
287 __CTRACE("wattrset: !REVERSE\n");
288 #endif
289 win->wattr &= ~__REVERSE;
290 }
291 }
292 if ((attr_t) attr & __STANDOUT) {
293 wstandout(win);
294 } else {
295 wstandend(win);
296 }
297 if (attr & __UNDERSCORE) {
298 wunderscore(win);
299 } else {
300 wunderend(win);
301 }
302 return (1);
303 }
304