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