attributes.c revision 1.3 1 /* $NetBSD: attributes.c,v 1.3 2000/04/12 21:43:57 jdc 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 "curses.h"
40 #include "curses_private.h"
41
42 /*
43 * wattron
44 * Test and set attributes.
45 *
46 * Modes are blinking, bold (extra bright), dim (half-bright),
47 * blanking (invisible), protected and reverse video
48 */
49
50 int
51 wattron(win, attr)
52 WINDOW *win;
53 int attr;
54 {
55 #ifdef DEBUG
56 __CTRACE ("wattron: %08x, %08x\n", attr, __nca);
57 #endif
58 if ((attr_t) attr & __BLINK) {
59 /* If can do blink, set the screen blink bit. */
60 if (MB != NULL && ME != NULL) {
61 win->wattr |= __BLINK;
62 /*
63 * Check for conflict with color.
64 */
65 if ((win->wattr & __COLOR) && (__nca & __BLINK)) {
66 win->wattr &= ~__COLOR;
67 }
68 }
69 }
70 if ((attr_t) attr & __BOLD) {
71 /* If can do bold, set the screen bold bit. */
72 if (MD != NULL && ME != NULL) {
73 win->wattr |= __BOLD;
74 if ((win->wattr & __COLOR) && (__nca & __BOLD)) {
75 win->wattr &= ~__COLOR;
76 }
77 }
78 }
79 if ((attr_t) attr & __DIM) {
80 /* If can do dim, set the screen dim bit. */
81 if (MH != NULL && ME != NULL) {
82 win->wattr |= __DIM;
83 if ((win->wattr & __COLOR) && (__nca & __DIM)) {
84 win->wattr &= ~__COLOR;
85 }
86 }
87 }
88 if ((attr_t) attr & __BLANK) {
89 /* If can do blank, set the screen blank bit. */
90 if (MK != NULL && ME != NULL) {
91 win->wattr |= __BLANK;
92 if ((win->wattr & __COLOR) && (__nca & __BLANK)) {
93 win->wattr &= ~__COLOR;
94 }
95 }
96 }
97 if ((attr_t) attr & __PROTECT) {
98 /* If can do protected, set the screen protected bit. */
99 if (MP != NULL && ME != NULL) {
100 win->wattr |= __PROTECT;
101 if ((win->wattr & __COLOR) && (__nca & __PROTECT)) {
102 win->wattr &= ~__COLOR;
103 }
104 }
105 }
106 if ((attr_t) attr & __REVERSE) {
107 /* If can do reverse video, set the screen reverse video bit. */
108 if (MR != NULL && ME != NULL)
109 {
110 win->wattr |= __REVERSE;
111 if ((win->wattr & __COLOR) && (__nca & __REVERSE)) {
112 win->wattr &= ~__COLOR;
113 }
114 }
115 }
116 if ((attr_t) attr & __STANDOUT) {
117 wstandout(win);
118 }
119 if ((attr_t) attr & __UNDERSCORE) {
120 wunderscore(win);
121 }
122 if ((attr_t) attr & __COLOR) {
123 /* If another color pair is set, turn that off first. */
124 if ((win->wattr & __COLOR) != ((attr_t) attr & __COLOR))
125 win->wattr &= ~__COLOR;
126 /* If can do color video, set the color pair bits. */
127 if (cO != NULL)
128 {
129 win->wattr |= attr & __COLOR;
130 if (__nca != __NORMAL) {
131 win->wattr &= ~__nca;
132 }
133 }
134 }
135 return (1);
136 }
137
138 /*
139 * wattroff
140 * Test and unset attributes.
141 *
142 * Note that the 'me' sequence unsets all attributes. We handle
143 * which attributes should really be set in refresh.c:makech().
144 */
145 int
146 wattroff(win, attr)
147 WINDOW *win;
148 int attr;
149 {
150 #ifdef DEBUG
151 __CTRACE ("wattroff: %08x\n", attr);
152 #endif
153 /* If can do exit modes, unset the relevent attribute bits. */
154 if ((attr_t) attr & __BLINK) {
155 if (ME != NULL) {
156 win->wattr &= ~__BLINK;
157 }
158 }
159 if ((attr_t) attr & __BOLD) {
160 if (ME != NULL) {
161 win->wattr &= ~__BOLD;
162 }
163 }
164 if ((attr_t) attr & __DIM) {
165 if (ME != NULL) {
166 win->wattr &= ~__DIM;
167 }
168 }
169 if ((attr_t) attr & __BLANK) {
170 if (ME != NULL) {
171 win->wattr &= ~__BLANK;
172 }
173 }
174 if ((attr_t) attr & __PROTECT) {
175 if (ME != NULL) {
176 win->wattr &= ~__PROTECT;
177 }
178 }
179 if ((attr_t) attr & __REVERSE) {
180 if (ME != NULL) {
181 win->wattr &= ~__REVERSE;
182 }
183 }
184 if ((attr_t) attr & __STANDOUT) {
185 wstandend(win);
186 }
187 if ((attr_t) attr & __UNDERSCORE) {
188 wunderend(win);
189 }
190 if ((attr_t) attr & __COLOR) {
191 if (cO != NULL)
192 {
193 win->wattr &= ~__COLOR;
194 }
195 }
196
197 return (1);
198 }
199
200 /*
201 * wattrset
202 * Set specific attribute modes.
203 * Unset others.
204 */
205 int
206 wattrset(win, attr)
207 WINDOW *win;
208 int attr;
209 {
210 if ((attr_t) attr & __BLINK)
211 wattron(win, __BLINK);
212 else
213 wattroff(win, __BLINK);
214 if ((attr_t) attr & __BOLD)
215 wattron(win, __BOLD);
216 else
217 wattroff(win, __BOLD);
218 if ((attr_t) attr & __DIM)
219 wattron(win, __DIM);
220 else
221 wattroff(win, __DIM);
222 if ((attr_t) attr & __BLANK)
223 wattron(win, __BLANK);
224 else
225 wattroff(win, __BLANK);
226 if ((attr_t) attr & __PROTECT)
227 wattron(win, __PROTECT);
228 else
229 wattroff(win, __PROTECT);
230 if ((attr_t) attr & __REVERSE)
231 wattron(win, __REVERSE);
232 else
233 wattroff(win, __REVERSE);
234 if ((attr_t) attr & __STANDOUT)
235 wstandout(win);
236 else
237 wstandend(win);
238 if ((attr_t) attr & __UNDERSCORE)
239 wunderscore(win);
240 else
241 wunderend(win);
242 if ((attr_t) attr & __COLOR)
243 wattron(win, attr & (int) __COLOR);
244 else
245 wattroff(win, (int) __COLOR);
246 return (1);
247 }
248