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