Home | History | Annotate | Line # | Download | only in libcurses
attributes.c revision 1.10
      1  1.10      jdc /*	$NetBSD: attributes.c,v 1.10 2003/01/27 21:04:10 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.6    blymn 
     39   1.6    blymn #include <sys/cdefs.h>
     40   1.6    blymn #ifndef lint
     41  1.10      jdc __RCSID("$NetBSD: attributes.c,v 1.10 2003/01/27 21:04:10 jdc 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.8      jdc  * 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.8      jdc  * 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.8      jdc  * 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.8      jdc  * 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.8      jdc 	__CTRACE ("wattron: win %0.2o, attr %08x\n", win, attr);
     95   1.3      jdc #endif
     96   1.7  mycroft 	/* If can enter modes, set the relevent attribute bits. */
     97   1.9      jdc 	if (__tc_me != NULL) {
     98   1.9      jdc 		if ((attr_t) attr & __BLINK && __tc_mb != NULL)
     99   1.2    blymn 			win->wattr |= __BLINK;
    100   1.9      jdc 		if ((attr_t) attr & __BOLD && __tc_md != NULL)
    101   1.2    blymn 			win->wattr |= __BOLD;
    102   1.9      jdc 		if ((attr_t) attr & __DIM && __tc_mh != NULL)
    103   1.2    blymn 			win->wattr |= __DIM;
    104   1.9      jdc 		if ((attr_t) attr & __BLANK && __tc_mk != NULL)
    105   1.2    blymn 			win->wattr |= __BLANK;
    106   1.9      jdc 		if ((attr_t) attr & __PROTECT && __tc_mp != NULL)
    107   1.2    blymn 			win->wattr |= __PROTECT;
    108   1.9      jdc 		if ((attr_t) attr & __REVERSE && __tc_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.3      jdc 	if ((attr_t) attr & __COLOR) {
    116   1.3      jdc 		/* If another color pair is set, turn that off first. */
    117   1.7  mycroft 		win->wattr &= ~__COLOR;
    118   1.3      jdc 		/* If can do color video, set the color pair bits. */
    119  1.10      jdc 		if (__tc_Co != NULL)
    120   1.3      jdc 			win->wattr |= attr & __COLOR;
    121   1.3      jdc 	}
    122   1.7  mycroft 	return (OK);
    123   1.1      mrg }
    124   1.1      mrg 
    125   1.1      mrg /*
    126   1.8      jdc  * wattroff --
    127   1.1      mrg  *	Test and unset attributes.
    128   1.1      mrg  *
    129   1.1      mrg  *	Note that the 'me' sequence unsets all attributes.  We handle
    130   1.1      mrg  *	which attributes should really be set in refresh.c:makech().
    131   1.1      mrg  */
    132   1.1      mrg int
    133   1.4    blymn wattroff(WINDOW *win, int attr)
    134   1.1      mrg {
    135   1.3      jdc #ifdef DEBUG
    136   1.8      jdc 	__CTRACE ("wattroff: win %0.2o, attr %08x\n", win, attr);
    137   1.3      jdc #endif
    138   1.3      jdc 	/* If can do exit modes, unset the relevent attribute bits. */
    139   1.9      jdc 	if (__tc_me != NULL) {
    140   1.7  mycroft 		if ((attr_t) attr & __BLINK)
    141   1.2    blymn 			win->wattr &= ~__BLINK;
    142   1.7  mycroft 		if ((attr_t) attr & __BOLD)
    143   1.2    blymn 			win->wattr &= ~__BOLD;
    144   1.7  mycroft 		if ((attr_t) attr & __DIM)
    145   1.2    blymn 			win->wattr &= ~__DIM;
    146   1.7  mycroft 		if ((attr_t) attr & __BLANK)
    147   1.2    blymn 			win->wattr &= ~__BLANK;
    148   1.7  mycroft 		if ((attr_t) attr & __PROTECT)
    149   1.2    blymn 			win->wattr &= ~__PROTECT;
    150   1.7  mycroft 		if ((attr_t) attr & __REVERSE)
    151   1.2    blymn 			win->wattr &= ~__REVERSE;
    152   1.1      mrg 	}
    153   1.7  mycroft 	if ((attr_t) attr & __STANDOUT)
    154   1.2    blymn 		wstandend(win);
    155   1.7  mycroft 	if ((attr_t) attr & __UNDERSCORE)
    156   1.1      mrg 		wunderend(win);
    157   1.3      jdc 	if ((attr_t) attr & __COLOR) {
    158   1.9      jdc 		if (__tc_Co != NULL)
    159   1.3      jdc 			win->wattr &= ~__COLOR;
    160   1.3      jdc 	}
    161   1.7  mycroft 	return (OK);
    162   1.1      mrg }
    163   1.1      mrg 
    164   1.1      mrg /*
    165   1.8      jdc  * wattrset --
    166   1.1      mrg  *	Set specific attribute modes.
    167   1.1      mrg  *	Unset others.
    168   1.1      mrg  */
    169   1.1      mrg int
    170   1.4    blymn wattrset(WINDOW *win, int attr)
    171   1.1      mrg {
    172   1.5      jdc #ifdef DEBUG
    173   1.8      jdc 	__CTRACE ("wattrset: win %0.2o, attr %08x\n", win, attr);
    174   1.5      jdc #endif
    175   1.7  mycroft 	wattron(win, attr);
    176   1.7  mycroft 	wattroff(win, (~attr & ~__COLOR) | ((attr & __COLOR) ? 0 : __COLOR));
    177   1.7  mycroft 	return (OK);
    178   1.8      jdc }
    179   1.8      jdc 
    180   1.8      jdc /*
    181   1.8      jdc  * getattrs --
    182   1.8      jdc  * Get window attributes.
    183   1.8      jdc  */
    184   1.8      jdc chtype
    185   1.8      jdc getattrs(WINDOW *win)
    186   1.8      jdc {
    187   1.8      jdc #ifdef DEBUG
    188   1.8      jdc 	__CTRACE ("getattrs: win %0.2o\n", win);
    189   1.8      jdc #endif
    190   1.8      jdc 	return((chtype) win->wattr);
    191   1.1      mrg }
    192