1 /* $NetBSD: attributes.c,v 1.11 2003/02/17 11:07:19 dsl 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.11 2003/02/17 11:07:19 dsl 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: win %p, attr %08x\n", win, attr); 95 #endif 96 /* If can enter modes, set the relevent attribute bits. */ 97 if (__tc_me != NULL) { 98 if ((attr_t) attr & __BLINK && __tc_mb != NULL) 99 win->wattr |= __BLINK; 100 if ((attr_t) attr & __BOLD && __tc_md != NULL) 101 win->wattr |= __BOLD; 102 if ((attr_t) attr & __DIM && __tc_mh != NULL) 103 win->wattr |= __DIM; 104 if ((attr_t) attr & __BLANK && __tc_mk != NULL) 105 win->wattr |= __BLANK; 106 if ((attr_t) attr & __PROTECT && __tc_mp != NULL) 107 win->wattr |= __PROTECT; 108 if ((attr_t) attr & __REVERSE && __tc_mr != NULL) 109 win->wattr |= __REVERSE; 110 } 111 if ((attr_t) attr & __STANDOUT) 112 wstandout(win); 113 if ((attr_t) attr & __UNDERSCORE) 114 wunderscore(win); 115 if ((attr_t) attr & __COLOR) { 116 /* If another color pair is set, turn that off first. */ 117 win->wattr &= ~__COLOR; 118 /* If can do color video, set the color pair bits. */ 119 if (__tc_Co != NULL) 120 win->wattr |= attr & __COLOR; 121 } 122 return (OK); 123 } 124 125 /* 126 * wattroff -- 127 * Test and unset attributes. 128 * 129 * Note that the 'me' sequence unsets all attributes. We handle 130 * which attributes should really be set in refresh.c:makech(). 131 */ 132 int 133 wattroff(WINDOW *win, int attr) 134 { 135 #ifdef DEBUG 136 __CTRACE ("wattroff: win %p, attr %08x\n", win, attr); 137 #endif 138 /* If can do exit modes, unset the relevent attribute bits. */ 139 if (__tc_me != NULL) { 140 if ((attr_t) attr & __BLINK) 141 win->wattr &= ~__BLINK; 142 if ((attr_t) attr & __BOLD) 143 win->wattr &= ~__BOLD; 144 if ((attr_t) attr & __DIM) 145 win->wattr &= ~__DIM; 146 if ((attr_t) attr & __BLANK) 147 win->wattr &= ~__BLANK; 148 if ((attr_t) attr & __PROTECT) 149 win->wattr &= ~__PROTECT; 150 if ((attr_t) attr & __REVERSE) 151 win->wattr &= ~__REVERSE; 152 } 153 if ((attr_t) attr & __STANDOUT) 154 wstandend(win); 155 if ((attr_t) attr & __UNDERSCORE) 156 wunderend(win); 157 if ((attr_t) attr & __COLOR) { 158 if (__tc_Co != NULL) 159 win->wattr &= ~__COLOR; 160 } 161 return (OK); 162 } 163 164 /* 165 * wattrset -- 166 * Set specific attribute modes. 167 * Unset others. 168 */ 169 int 170 wattrset(WINDOW *win, int attr) 171 { 172 #ifdef DEBUG 173 __CTRACE ("wattrset: win %p, attr %08x\n", win, attr); 174 #endif 175 wattron(win, attr); 176 wattroff(win, (~attr & ~__COLOR) | ((attr & __COLOR) ? 0 : __COLOR)); 177 return (OK); 178 } 179 180 /* 181 * getattrs -- 182 * Get window attributes. 183 */ 184 chtype 185 getattrs(WINDOW *win) 186 { 187 #ifdef DEBUG 188 __CTRACE ("getattrs: win %p\n", win); 189 #endif 190 return((chtype) win->wattr); 191 } 192