Home | History | Annotate | Line # | Download | only in libcurses
attributes.c revision 1.7
      1  1.7  mycroft /*	$NetBSD: attributes.c,v 1.7 2000/04/28 23:37:11 mycroft 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.6    blymn 
     39  1.6    blymn #include <sys/cdefs.h>
     40  1.6    blymn #ifndef lint
     41  1.7  mycroft __RCSID("$NetBSD: attributes.c,v 1.7 2000/04/28 23:37:11 mycroft Exp $");
     42  1.6    blymn #endif				/* not lint */
     43  1.1      mrg 
     44  1.1      mrg #include "curses.h"
     45  1.2    blymn #include "curses_private.h"
     46  1.1      mrg 
     47  1.4    blymn #ifndef _CURSES_USE_MACROS
     48  1.4    blymn /*
     49  1.4    blymn  * attron
     50  1.4    blymn  *	Test and set attributes on stdscr
     51  1.4    blymn  */
     52  1.4    blymn 
     53  1.4    blymn int
     54  1.4    blymn attron(int attr)
     55  1.4    blymn {
     56  1.4    blymn 	return wattron(stdscr, attr);
     57  1.4    blymn }
     58  1.4    blymn 
     59  1.4    blymn /*
     60  1.4    blymn  * attroff
     61  1.4    blymn  *	Test and unset attributes on stdscr.
     62  1.4    blymn  */
     63  1.4    blymn int
     64  1.4    blymn attroff(int attr)
     65  1.4    blymn {
     66  1.4    blymn 	return wattroff(stdscr, attr);
     67  1.4    blymn }
     68  1.4    blymn 
     69  1.4    blymn /*
     70  1.4    blymn  * attrset
     71  1.4    blymn  *	Set specific attribute modes.
     72  1.4    blymn  *	Unset others.  On stdscr.
     73  1.4    blymn  */
     74  1.4    blymn int
     75  1.4    blymn attrset(int attr)
     76  1.4    blymn {
     77  1.4    blymn 	return wattrset(stdscr, attr);
     78  1.4    blymn }
     79  1.4    blymn 
     80  1.4    blymn #endif
     81  1.4    blymn 
     82  1.1      mrg /*
     83  1.1      mrg  * wattron
     84  1.1      mrg  *	Test and set attributes.
     85  1.1      mrg  *
     86  1.1      mrg  *	Modes are blinking, bold (extra bright), dim (half-bright),
     87  1.1      mrg  *	blanking (invisible), protected and reverse video
     88  1.1      mrg  */
     89  1.2    blymn 
     90  1.1      mrg int
     91  1.4    blymn wattron(WINDOW *win, int attr)
     92  1.1      mrg {
     93  1.3      jdc #ifdef DEBUG
     94  1.3      jdc 	__CTRACE ("wattron: %08x, %08x\n", attr, __nca);
     95  1.3      jdc #endif
     96  1.7  mycroft 	/* If can enter modes, set the relevent attribute bits. */
     97  1.7  mycroft 	if (ME != NULL) {
     98  1.7  mycroft 		if ((attr_t) attr & __BLINK && MB != NULL)
     99  1.2    blymn 			win->wattr |= __BLINK;
    100  1.7  mycroft 		if ((attr_t) attr & __BOLD && MD != NULL)
    101  1.2    blymn 			win->wattr |= __BOLD;
    102  1.7  mycroft 		if ((attr_t) attr & __DIM && MH != NULL)
    103  1.2    blymn 			win->wattr |= __DIM;
    104  1.7  mycroft 		if ((attr_t) attr & __BLANK && MK != NULL)
    105  1.2    blymn 			win->wattr |= __BLANK;
    106  1.7  mycroft 		if ((attr_t) attr & __PROTECT && MP != NULL)
    107  1.2    blymn 			win->wattr |= __PROTECT;
    108  1.7  mycroft 		if ((attr_t) attr & __REVERSE && MR != NULL)
    109  1.2    blymn 			win->wattr |= __REVERSE;
    110  1.1      mrg 	}
    111  1.7  mycroft 	if ((attr_t) attr & __STANDOUT)
    112  1.2    blymn 		wstandout(win);
    113  1.7  mycroft 	if ((attr_t) attr & __UNDERSCORE)
    114  1.1      mrg 		wunderscore(win);
    115  1.7  mycroft 	/* Check for conflict with color. */
    116  1.7  mycroft 	if (win->wattr & __nca)
    117  1.7  mycroft 		win->wattr &= ~__COLOR;
    118  1.3      jdc 	if ((attr_t) attr & __COLOR) {
    119  1.3      jdc 		/* If another color pair is set, turn that off first. */
    120  1.7  mycroft 		win->wattr &= ~__COLOR;
    121  1.3      jdc 		/* If can do color video, set the color pair bits. */
    122  1.7  mycroft 		if (cO != NULL) {
    123  1.3      jdc 			win->wattr |= attr & __COLOR;
    124  1.7  mycroft 			win->wattr &= ~__nca;
    125  1.3      jdc 		}
    126  1.3      jdc 	}
    127  1.7  mycroft 	return (OK);
    128  1.1      mrg }
    129  1.1      mrg 
    130  1.1      mrg /*
    131  1.1      mrg  * wattroff
    132  1.1      mrg  *	Test and unset attributes.
    133  1.1      mrg  *
    134  1.1      mrg  *	Note that the 'me' sequence unsets all attributes.  We handle
    135  1.1      mrg  *	which attributes should really be set in refresh.c:makech().
    136  1.1      mrg  */
    137  1.1      mrg int
    138  1.4    blymn wattroff(WINDOW *win, int attr)
    139  1.1      mrg {
    140  1.3      jdc #ifdef DEBUG
    141  1.3      jdc 	__CTRACE ("wattroff: %08x\n", attr);
    142  1.3      jdc #endif
    143  1.3      jdc 	/* If can do exit modes, unset the relevent attribute bits. */
    144  1.7  mycroft 	if (ME != NULL) {
    145  1.7  mycroft 		if ((attr_t) attr & __BLINK)
    146  1.2    blymn 			win->wattr &= ~__BLINK;
    147  1.7  mycroft 		if ((attr_t) attr & __BOLD)
    148  1.2    blymn 			win->wattr &= ~__BOLD;
    149  1.7  mycroft 		if ((attr_t) attr & __DIM)
    150  1.2    blymn 			win->wattr &= ~__DIM;
    151  1.7  mycroft 		if ((attr_t) attr & __BLANK)
    152  1.2    blymn 			win->wattr &= ~__BLANK;
    153  1.7  mycroft 		if ((attr_t) attr & __PROTECT)
    154  1.2    blymn 			win->wattr &= ~__PROTECT;
    155  1.7  mycroft 		if ((attr_t) attr & __REVERSE)
    156  1.2    blymn 			win->wattr &= ~__REVERSE;
    157  1.1      mrg 	}
    158  1.7  mycroft 	if ((attr_t) attr & __STANDOUT)
    159  1.2    blymn 		wstandend(win);
    160  1.7  mycroft 	if ((attr_t) attr & __UNDERSCORE)
    161  1.1      mrg 		wunderend(win);
    162  1.3      jdc 	if ((attr_t) attr & __COLOR) {
    163  1.3      jdc 		if (cO != NULL)
    164  1.3      jdc 			win->wattr &= ~__COLOR;
    165  1.3      jdc 	}
    166  1.7  mycroft 	return (OK);
    167  1.1      mrg }
    168  1.1      mrg 
    169  1.1      mrg /*
    170  1.1      mrg  * wattrset
    171  1.1      mrg  *	Set specific attribute modes.
    172  1.1      mrg  *	Unset others.
    173  1.1      mrg  */
    174  1.1      mrg int
    175  1.4    blymn wattrset(WINDOW *win, int attr)
    176  1.1      mrg {
    177  1.5      jdc #ifdef DEBUG
    178  1.5      jdc 	__CTRACE ("wattrset: %08x\n", attr, __nca);
    179  1.5      jdc #endif
    180  1.7  mycroft 	wattron(win, attr);
    181  1.7  mycroft 	wattroff(win, (~attr & ~__COLOR) | ((attr & __COLOR) ? 0 : __COLOR));
    182  1.7  mycroft 	return (OK);
    183  1.1      mrg }
    184