Home | History | Annotate | Line # | Download | only in libcurses
attributes.c revision 1.3
      1  1.2  blymn /*	$NetBSD: attributes.c,v 1.3 2000/04/12 21:43:57 jdc Exp $	*/
      2  1.1    mrg 
      3  1.3    jdc /*-
      4  1.3    jdc  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  1.1    mrg  * All rights reserved.
      6  1.1    mrg  *
      7  1.3    jdc  * This code is derived from software contributed to The NetBSD Foundation
      8  1.3    jdc  * by Julian Coleman.
      9  1.3    jdc  *
     10  1.1    mrg  * Redistribution and use in source and binary forms, with or without
     11  1.1    mrg  * modification, are permitted provided that the following conditions
     12  1.1    mrg  * are met:
     13  1.1    mrg  * 1. Redistributions of source code must retain the above copyright
     14  1.1    mrg  *    notice, this list of conditions and the following disclaimer.
     15  1.3    jdc  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.3    jdc  *    notice, this list of conditions and the following disclaimer in the
     17  1.3    jdc  *    documentation and/or other materials provided with the distribution.
     18  1.3    jdc  * 3. All advertising materials mentioning features or use of this software
     19  1.3    jdc  *    must display the following acknowledgement:
     20  1.3    jdc  *        This product includes software developed by the NetBSD
     21  1.3    jdc  *        Foundation, Inc. and its contributors.
     22  1.3    jdc  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.3    jdc  *    contributors may be used to endorse or promote products derived
     24  1.3    jdc  *    from this software without specific prior written permission.
     25  1.1    mrg  *
     26  1.3    jdc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.3    jdc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.3    jdc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.3    jdc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.3    jdc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.3    jdc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.3    jdc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.3    jdc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.3    jdc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.3    jdc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.3    jdc  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1    mrg  */
     38  1.1    mrg 
     39  1.1    mrg #include "curses.h"
     40  1.2  blymn #include "curses_private.h"
     41  1.1    mrg 
     42  1.1    mrg /*
     43  1.1    mrg  * wattron
     44  1.1    mrg  *	Test and set attributes.
     45  1.1    mrg  *
     46  1.1    mrg  *	Modes are blinking, bold (extra bright), dim (half-bright),
     47  1.1    mrg  *	blanking (invisible), protected and reverse video
     48  1.1    mrg  */
     49  1.2  blymn 
     50  1.1    mrg int
     51  1.1    mrg wattron(win, attr)
     52  1.1    mrg 	WINDOW	*win;
     53  1.2  blymn 	int	 attr;
     54  1.1    mrg {
     55  1.3    jdc #ifdef DEBUG
     56  1.3    jdc 	__CTRACE ("wattron: %08x, %08x\n", attr, __nca);
     57  1.3    jdc #endif
     58  1.2  blymn 	if ((attr_t) attr & __BLINK) {
     59  1.3    jdc 		/* If can do blink, set the screen blink bit. */
     60  1.1    mrg 		if (MB != NULL && ME != NULL) {
     61  1.2  blymn 			win->wattr |= __BLINK;
     62  1.3    jdc 			/*
     63  1.3    jdc 			 * Check for conflict with color.
     64  1.3    jdc 			 */
     65  1.3    jdc 			if ((win->wattr & __COLOR) && (__nca & __BLINK)) {
     66  1.3    jdc 				win->wattr &= ~__COLOR;
     67  1.3    jdc 			}
     68  1.1    mrg 		}
     69  1.1    mrg 	}
     70  1.2  blymn 	if ((attr_t) attr & __BOLD) {
     71  1.3    jdc 		/* If can do bold, set the screen bold bit. */
     72  1.1    mrg 		if (MD != NULL && ME != NULL) {
     73  1.2  blymn 			win->wattr |= __BOLD;
     74  1.3    jdc 			if ((win->wattr & __COLOR) && (__nca & __BOLD)) {
     75  1.3    jdc 				win->wattr &= ~__COLOR;
     76  1.3    jdc 			}
     77  1.1    mrg 		}
     78  1.1    mrg 	}
     79  1.2  blymn 	if ((attr_t) attr & __DIM) {
     80  1.3    jdc 		/* If can do dim, set the screen dim bit. */
     81  1.1    mrg 		if (MH != NULL && ME != NULL) {
     82  1.2  blymn 			win->wattr |= __DIM;
     83  1.3    jdc 			if ((win->wattr & __COLOR) && (__nca & __DIM)) {
     84  1.3    jdc 				win->wattr &= ~__COLOR;
     85  1.3    jdc 			}
     86  1.1    mrg 		}
     87  1.1    mrg 	}
     88  1.2  blymn 	if ((attr_t) attr & __BLANK) {
     89  1.3    jdc 		/* If can do blank, set the screen blank bit. */
     90  1.1    mrg 		if (MK != NULL && ME != NULL) {
     91  1.2  blymn 			win->wattr |= __BLANK;
     92  1.3    jdc 			if ((win->wattr & __COLOR) && (__nca & __BLANK)) {
     93  1.3    jdc 				win->wattr &= ~__COLOR;
     94  1.3    jdc 			}
     95  1.1    mrg 		}
     96  1.1    mrg 	}
     97  1.2  blymn 	if ((attr_t) attr & __PROTECT) {
     98  1.3    jdc 		/* If can do protected, set the screen protected bit. */
     99  1.1    mrg 		if (MP != NULL && ME != NULL) {
    100  1.2  blymn 			win->wattr |= __PROTECT;
    101  1.3    jdc 			if ((win->wattr & __COLOR) && (__nca & __PROTECT)) {
    102  1.3    jdc 				win->wattr &= ~__COLOR;
    103  1.3    jdc 			}
    104  1.1    mrg 		}
    105  1.1    mrg 	}
    106  1.2  blymn 	if ((attr_t) attr & __REVERSE) {
    107  1.3    jdc 		/* If can do reverse video, set the screen reverse video bit. */
    108  1.1    mrg 		if (MR != NULL && ME != NULL)
    109  1.1    mrg 		{
    110  1.2  blymn 			win->wattr |= __REVERSE;
    111  1.3    jdc 			if ((win->wattr & __COLOR) && (__nca & __REVERSE)) {
    112  1.3    jdc 				win->wattr &= ~__COLOR;
    113  1.3    jdc 			}
    114  1.1    mrg 		}
    115  1.1    mrg 	}
    116  1.2  blymn 	if ((attr_t) attr & __STANDOUT) {
    117  1.2  blymn 		wstandout(win);
    118  1.2  blymn 	}
    119  1.3    jdc 	if ((attr_t) attr & __UNDERSCORE) {
    120  1.1    mrg 		wunderscore(win);
    121  1.1    mrg 	}
    122  1.3    jdc 	if ((attr_t) attr & __COLOR) {
    123  1.3    jdc 		/* If another color pair is set, turn that off first. */
    124  1.3    jdc 		if ((win->wattr & __COLOR) != ((attr_t) attr & __COLOR))
    125  1.3    jdc 			win->wattr &= ~__COLOR;
    126  1.3    jdc 		/* If can do color video, set the color pair bits. */
    127  1.3    jdc 		if (cO != NULL)
    128  1.3    jdc 		{
    129  1.3    jdc 			win->wattr |= attr & __COLOR;
    130  1.3    jdc 			if (__nca != __NORMAL) {
    131  1.3    jdc 				win->wattr &= ~__nca;
    132  1.3    jdc 			}
    133  1.3    jdc 		}
    134  1.3    jdc 	}
    135  1.1    mrg 	return (1);
    136  1.1    mrg }
    137  1.1    mrg 
    138  1.1    mrg /*
    139  1.1    mrg  * wattroff
    140  1.1    mrg  *	Test and unset attributes.
    141  1.1    mrg  *
    142  1.1    mrg  *	Note that the 'me' sequence unsets all attributes.  We handle
    143  1.1    mrg  *	which attributes should really be set in refresh.c:makech().
    144  1.1    mrg  */
    145  1.1    mrg int
    146  1.1    mrg wattroff(win, attr)
    147  1.1    mrg 	WINDOW	*win;
    148  1.2  blymn 	int	 attr;
    149  1.1    mrg {
    150  1.3    jdc #ifdef DEBUG
    151  1.3    jdc 	__CTRACE ("wattroff: %08x\n", attr);
    152  1.3    jdc #endif
    153  1.3    jdc 	/* If can do exit modes, unset the relevent attribute bits. */
    154  1.2  blymn 	if ((attr_t) attr & __BLINK) {
    155  1.1    mrg 		if (ME != NULL) {
    156  1.2  blymn 			win->wattr &= ~__BLINK;
    157  1.1    mrg 		}
    158  1.1    mrg 	}
    159  1.2  blymn 	if ((attr_t) attr & __BOLD) {
    160  1.1    mrg 		if (ME != NULL) {
    161  1.2  blymn 			win->wattr &= ~__BOLD;
    162  1.1    mrg 		}
    163  1.1    mrg 	}
    164  1.2  blymn 	if ((attr_t) attr & __DIM) {
    165  1.1    mrg 		if (ME != NULL) {
    166  1.2  blymn 			win->wattr &= ~__DIM;
    167  1.1    mrg 		}
    168  1.1    mrg 	}
    169  1.2  blymn 	if ((attr_t) attr & __BLANK) {
    170  1.1    mrg 		if (ME != NULL) {
    171  1.2  blymn 			win->wattr &= ~__BLANK;
    172  1.1    mrg 		}
    173  1.1    mrg 	}
    174  1.2  blymn 	if ((attr_t) attr & __PROTECT) {
    175  1.1    mrg 		if (ME != NULL) {
    176  1.2  blymn 			win->wattr &= ~__PROTECT;
    177  1.1    mrg 		}
    178  1.1    mrg 	}
    179  1.2  blymn 	if ((attr_t) attr & __REVERSE) {
    180  1.1    mrg 		if (ME != NULL) {
    181  1.2  blymn 			win->wattr &= ~__REVERSE;
    182  1.1    mrg 		}
    183  1.1    mrg 	}
    184  1.2  blymn 	if ((attr_t) attr & __STANDOUT) {
    185  1.2  blymn 		wstandend(win);
    186  1.2  blymn 	}
    187  1.3    jdc 	if ((attr_t) attr & __UNDERSCORE) {
    188  1.1    mrg 		wunderend(win);
    189  1.1    mrg 	}
    190  1.3    jdc 	if ((attr_t) attr & __COLOR) {
    191  1.3    jdc 		if (cO != NULL)
    192  1.3    jdc 		{
    193  1.3    jdc 			win->wattr &= ~__COLOR;
    194  1.3    jdc 		}
    195  1.3    jdc 	}
    196  1.3    jdc 
    197  1.1    mrg 	return (1);
    198  1.1    mrg }
    199  1.1    mrg 
    200  1.1    mrg /*
    201  1.1    mrg  * wattrset
    202  1.1    mrg  *	Set specific attribute modes.
    203  1.1    mrg  *	Unset others.
    204  1.1    mrg  */
    205  1.1    mrg int
    206  1.1    mrg wattrset(win, attr)
    207  1.1    mrg 	WINDOW	*win;
    208  1.2  blymn 	int	 attr;
    209  1.1    mrg {
    210  1.3    jdc 	if ((attr_t) attr & __BLINK)
    211  1.3    jdc 		wattron(win, __BLINK);
    212  1.3    jdc 	else
    213  1.3    jdc 		wattroff(win, __BLINK);
    214  1.3    jdc 	if ((attr_t) attr & __BOLD)
    215  1.3    jdc 		wattron(win, __BOLD);
    216  1.3    jdc 	else
    217  1.3    jdc 		wattroff(win, __BOLD);
    218  1.3    jdc 	if ((attr_t) attr & __DIM)
    219  1.3    jdc 		wattron(win, __DIM);
    220  1.3    jdc 	else
    221  1.3    jdc 		wattroff(win, __DIM);
    222  1.3    jdc 	if ((attr_t) attr & __BLANK)
    223  1.3    jdc 		wattron(win, __BLANK);
    224  1.3    jdc 	else
    225  1.3    jdc 		wattroff(win, __BLANK);
    226  1.3    jdc 	if ((attr_t) attr & __PROTECT)
    227  1.3    jdc 		wattron(win, __PROTECT);
    228  1.3    jdc 	else
    229  1.3    jdc 		wattroff(win, __PROTECT);
    230  1.3    jdc 	if ((attr_t) attr & __REVERSE)
    231  1.3    jdc 		wattron(win, __REVERSE);
    232  1.3    jdc 	else
    233  1.3    jdc 		wattroff(win, __REVERSE);
    234  1.3    jdc 	if ((attr_t) attr & __STANDOUT)
    235  1.2  blymn 		wstandout(win);
    236  1.3    jdc 	else
    237  1.2  blymn 		wstandend(win);
    238  1.3    jdc 	if ((attr_t) attr & __UNDERSCORE)
    239  1.1    mrg 		wunderscore(win);
    240  1.3    jdc 	else
    241  1.1    mrg 		wunderend(win);
    242  1.3    jdc 	if ((attr_t) attr & __COLOR)
    243  1.3    jdc 		wattron(win, attr & (int) __COLOR);
    244  1.3    jdc 	else
    245  1.3    jdc 		wattroff(win, (int) __COLOR);
    246  1.1    mrg 	return (1);
    247  1.1    mrg }
    248