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