Home | History | Annotate | Line # | Download | only in libcurses
attributes.c revision 1.7
      1 /*	$NetBSD: attributes.c,v 1.7 2000/04/28 23:37:11 mycroft 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.7 2000/04/28 23:37:11 mycroft 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 can enter modes, set the relevent attribute bits. */
     97 	if (ME != NULL) {
     98 		if ((attr_t) attr & __BLINK && MB != NULL)
     99 			win->wattr |= __BLINK;
    100 		if ((attr_t) attr & __BOLD && MD != NULL)
    101 			win->wattr |= __BOLD;
    102 		if ((attr_t) attr & __DIM && MH != NULL)
    103 			win->wattr |= __DIM;
    104 		if ((attr_t) attr & __BLANK && MK != NULL)
    105 			win->wattr |= __BLANK;
    106 		if ((attr_t) attr & __PROTECT && MP != NULL)
    107 			win->wattr |= __PROTECT;
    108 		if ((attr_t) attr & __REVERSE && 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 	/* Check for conflict with color. */
    116 	if (win->wattr & __nca)
    117 		win->wattr &= ~__COLOR;
    118 	if ((attr_t) attr & __COLOR) {
    119 		/* If another color pair is set, turn that off first. */
    120 		win->wattr &= ~__COLOR;
    121 		/* If can do color video, set the color pair bits. */
    122 		if (cO != NULL) {
    123 			win->wattr |= attr & __COLOR;
    124 			win->wattr &= ~__nca;
    125 		}
    126 	}
    127 	return (OK);
    128 }
    129 
    130 /*
    131  * wattroff
    132  *	Test and unset attributes.
    133  *
    134  *	Note that the 'me' sequence unsets all attributes.  We handle
    135  *	which attributes should really be set in refresh.c:makech().
    136  */
    137 int
    138 wattroff(WINDOW *win, int attr)
    139 {
    140 #ifdef DEBUG
    141 	__CTRACE ("wattroff: %08x\n", attr);
    142 #endif
    143 	/* If can do exit modes, unset the relevent attribute bits. */
    144 	if (ME != NULL) {
    145 		if ((attr_t) attr & __BLINK)
    146 			win->wattr &= ~__BLINK;
    147 		if ((attr_t) attr & __BOLD)
    148 			win->wattr &= ~__BOLD;
    149 		if ((attr_t) attr & __DIM)
    150 			win->wattr &= ~__DIM;
    151 		if ((attr_t) attr & __BLANK)
    152 			win->wattr &= ~__BLANK;
    153 		if ((attr_t) attr & __PROTECT)
    154 			win->wattr &= ~__PROTECT;
    155 		if ((attr_t) attr & __REVERSE)
    156 			win->wattr &= ~__REVERSE;
    157 	}
    158 	if ((attr_t) attr & __STANDOUT)
    159 		wstandend(win);
    160 	if ((attr_t) attr & __UNDERSCORE)
    161 		wunderend(win);
    162 	if ((attr_t) attr & __COLOR) {
    163 		if (cO != NULL)
    164 			win->wattr &= ~__COLOR;
    165 	}
    166 	return (OK);
    167 }
    168 
    169 /*
    170  * wattrset
    171  *	Set specific attribute modes.
    172  *	Unset others.
    173  */
    174 int
    175 wattrset(WINDOW *win, int attr)
    176 {
    177 #ifdef DEBUG
    178 	__CTRACE ("wattrset: %08x\n", attr, __nca);
    179 #endif
    180 	wattron(win, attr);
    181 	wattroff(win, (~attr & ~__COLOR) | ((attr & __COLOR) ? 0 : __COLOR));
    182 	return (OK);
    183 }
    184