Home | History | Annotate | Line # | Download | only in libcurses
attributes.c revision 1.23.14.2
      1  1.23.14.2    martin /*	$NetBSD: attributes.c,v 1.23.14.2 2020/04/13 08:03:12 martin 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.1       mrg  *
     19        1.3       jdc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.3       jdc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.3       jdc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.3       jdc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.3       jdc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.3       jdc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.3       jdc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.3       jdc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.3       jdc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.3       jdc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.3       jdc  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1       mrg  */
     31        1.6     blymn 
     32        1.6     blymn #include <sys/cdefs.h>
     33        1.6     blymn #ifndef lint
     34  1.23.14.2    martin __RCSID("$NetBSD: attributes.c,v 1.23.14.2 2020/04/13 08:03:12 martin Exp $");
     35        1.6     blymn #endif				/* not lint */
     36        1.1       mrg 
     37        1.1       mrg #include "curses.h"
     38        1.2     blymn #include "curses_private.h"
     39        1.1       mrg 
     40  1.23.14.1  christos static int __wattr_off(WINDOW *, attr_t);
     41  1.23.14.1  christos static int __wattr_on(WINDOW *, attr_t);
     42  1.23.14.1  christos static void __wcolor_set(WINDOW *, attr_t);
     43  1.23.14.1  christos 
     44       1.12       jdc 
     45        1.4     blymn #ifndef _CURSES_USE_MACROS
     46  1.23.14.2    martin #ifdef HAVE_WCHAR
     47        1.4     blymn /*
     48       1.12       jdc  * attr_get --
     49       1.16       jdc  *	Get wide attributes and color pair from stdscr
     50       1.12       jdc  */
     51       1.12       jdc /* ARGSUSED */
     52       1.12       jdc int
     53  1.23.14.1  christos attr_get(attr_t *attr, short *pair, void *opts)
     54       1.12       jdc {
     55  1.23.14.1  christos 	return wattr_get(stdscr, attr, pair, opts);
     56       1.12       jdc }
     57       1.12       jdc 
     58       1.12       jdc /*
     59       1.12       jdc  * attr_on --
     60       1.16       jdc  *	Test and set wide attributes on stdscr
     61       1.12       jdc  */
     62       1.12       jdc /* ARGSUSED */
     63       1.12       jdc int
     64  1.23.14.1  christos attr_on(attr_t attr, void *opts)
     65       1.12       jdc {
     66  1.23.14.1  christos 	return wattr_on(stdscr, attr, opts);
     67       1.12       jdc }
     68       1.12       jdc 
     69       1.12       jdc /*
     70       1.12       jdc  * attr_off --
     71       1.16       jdc  *	Test and unset wide attributes on stdscr
     72       1.12       jdc  */
     73       1.12       jdc /* ARGSUSED */
     74       1.12       jdc int
     75  1.23.14.1  christos attr_off(attr_t attr, void *opts)
     76       1.12       jdc {
     77  1.23.14.1  christos 	return wattr_off(stdscr, attr, opts);
     78       1.12       jdc }
     79       1.12       jdc 
     80       1.12       jdc /*
     81       1.12       jdc  * attr_set --
     82       1.16       jdc  *	Set wide attributes and color pair on stdscr
     83       1.12       jdc  */
     84       1.12       jdc /* ARGSUSED */
     85       1.12       jdc int
     86  1.23.14.1  christos attr_set(attr_t attr, short pair, void *opts)
     87       1.12       jdc {
     88  1.23.14.1  christos 	return wattr_set(stdscr, attr, pair, opts);
     89       1.12       jdc }
     90       1.12       jdc 
     91       1.12       jdc /*
     92       1.12       jdc  * color_set --
     93       1.12       jdc  *	Set color pair on stdscr
     94       1.12       jdc  */
     95       1.12       jdc /* ARGSUSED */
     96       1.12       jdc int
     97  1.23.14.1  christos color_set(short pair, void *opts)
     98       1.12       jdc {
     99  1.23.14.1  christos 	return wcolor_set(stdscr, pair, opts);
    100       1.12       jdc }
    101  1.23.14.2    martin #endif /* HAVE_WCHAR */
    102       1.12       jdc 
    103       1.12       jdc /*
    104        1.8       jdc  * attron --
    105        1.4     blymn  *	Test and set attributes on stdscr
    106        1.4     blymn  */
    107        1.4     blymn int
    108        1.4     blymn attron(int attr)
    109        1.4     blymn {
    110  1.23.14.1  christos 	return wattron(stdscr, attr);
    111        1.4     blymn }
    112        1.4     blymn 
    113        1.4     blymn /*
    114        1.8       jdc  * attroff --
    115        1.4     blymn  *	Test and unset attributes on stdscr.
    116        1.4     blymn  */
    117        1.4     blymn int
    118        1.4     blymn attroff(int attr)
    119        1.4     blymn {
    120  1.23.14.1  christos 	return wattroff(stdscr, attr);
    121        1.4     blymn }
    122        1.4     blymn 
    123        1.4     blymn /*
    124        1.8       jdc  * attrset --
    125        1.4     blymn  *	Set specific attribute modes.
    126        1.4     blymn  *	Unset others.  On stdscr.
    127        1.4     blymn  */
    128        1.4     blymn int
    129        1.4     blymn attrset(int attr)
    130        1.4     blymn {
    131        1.4     blymn 	return wattrset(stdscr, attr);
    132        1.4     blymn }
    133       1.12       jdc #endif	/* _CURSES_USE_MACROS */
    134        1.4     blymn 
    135  1.23.14.2    martin 
    136  1.23.14.2    martin #ifdef HAVE_WCHAR
    137       1.12       jdc /*
    138       1.12       jdc  * wattr_get --
    139       1.16       jdc  *	Get wide attributes and colour pair from window
    140       1.12       jdc  *	Note that attributes also includes colour.
    141       1.12       jdc  */
    142       1.12       jdc /* ARGSUSED */
    143       1.12       jdc int
    144  1.23.14.1  christos wattr_get(WINDOW *win, attr_t *attr, short *pair, void *opts)
    145       1.12       jdc {
    146       1.12       jdc #ifdef DEBUG
    147       1.14       jdc 	__CTRACE(__CTRACE_ATTR, "wattr_get: win %p\n", win);
    148        1.4     blymn #endif
    149       1.15     blymn 	if (attr != NULL) {
    150       1.12       jdc 		*attr = win->wattr;
    151       1.15     blymn #ifdef HAVE_WCHAR
    152       1.15     blymn 		*attr &= WA_ATTRIBUTES;
    153       1.15     blymn #endif
    154       1.15     blymn 	}
    155       1.15     blymn 
    156       1.12       jdc 	if (pair != NULL)
    157       1.12       jdc 		*pair = PAIR_NUMBER(win->wattr);
    158       1.12       jdc 	return OK;
    159       1.12       jdc }
    160        1.4     blymn 
    161        1.1       mrg /*
    162       1.12       jdc  * wattr_on --
    163       1.16       jdc  *	Test and set wide attributes on window
    164        1.1       mrg  */
    165        1.1       mrg int
    166  1.23.14.1  christos wattr_on(WINDOW *win, attr_t attr, void *opts)
    167        1.1       mrg {
    168  1.23.14.1  christos 	if (__predict_false(opts != NULL))
    169  1.23.14.1  christos 		return ERR;
    170       1.23       roy 
    171  1.23.14.1  christos 	return __wattr_on(win, attr);
    172        1.1       mrg }
    173        1.1       mrg 
    174        1.1       mrg /*
    175       1.12       jdc  * wattr_off --
    176       1.16       jdc  *	Test and unset wide attributes on window
    177        1.1       mrg  *
    178        1.1       mrg  *	Note that the 'me' sequence unsets all attributes.  We handle
    179        1.1       mrg  *	which attributes should really be set in refresh.c:makech().
    180        1.1       mrg  */
    181        1.1       mrg int
    182  1.23.14.1  christos wattr_off(WINDOW *win, attr_t attr, void *opts)
    183        1.1       mrg {
    184  1.23.14.1  christos 	if (__predict_false(opts != NULL))
    185  1.23.14.1  christos 		return ERR;
    186       1.23       roy 
    187  1.23.14.1  christos 	return __wattr_off(win, attr);
    188       1.12       jdc }
    189       1.12       jdc 
    190  1.23.14.1  christos 
    191       1.12       jdc /*
    192       1.12       jdc  * wattr_set --
    193       1.16       jdc  *	Set wide attributes and color pair on window
    194       1.12       jdc  */
    195       1.12       jdc int
    196  1.23.14.1  christos wattr_set(WINDOW *win, attr_t attr, short pair, void *opts)
    197       1.12       jdc {
    198       1.12       jdc #ifdef DEBUG
    199       1.14       jdc 	__CTRACE(__CTRACE_ATTR, "wattr_set: win %p, attr %08x, pair %d\n",
    200       1.14       jdc 	    win, attr, pair);
    201       1.12       jdc #endif
    202  1.23.14.1  christos 	if (__predict_false(opts != NULL))
    203  1.23.14.1  christos 		return ERR;
    204  1.23.14.1  christos 
    205       1.12       jdc 	/*
    206       1.15     blymn 	 * This overwrites any colour setting from the attributes
    207       1.12       jdc 	 * and is compatible with ncurses.
    208       1.12       jdc 	 */
    209       1.22       roy 	attr = (attr & ~__COLOR) | COLOR_PAIR(pair);
    210  1.23.14.1  christos 
    211  1.23.14.1  christos 	__wattr_off(win, WA_ATTRIBUTES);
    212  1.23.14.1  christos 	__wattr_on(win, attr);
    213       1.12       jdc 	return OK;
    214       1.12       jdc }
    215       1.12       jdc 
    216       1.12       jdc /*
    217  1.23.14.1  christos  * wcolor_set --
    218  1.23.14.1  christos  *	Set color pair on window
    219       1.12       jdc  */
    220  1.23.14.1  christos /* ARGSUSED */
    221       1.12       jdc int
    222  1.23.14.1  christos wcolor_set(WINDOW *win, short pair, void *opts)
    223       1.12       jdc {
    224       1.12       jdc #ifdef DEBUG
    225  1.23.14.1  christos 	__CTRACE(__CTRACE_COLOR, "wolor_set: win %p, pair %d\n", win, pair);
    226       1.12       jdc #endif
    227  1.23.14.1  christos 	__wcolor_set(win, (attr_t) COLOR_PAIR(pair));
    228  1.23.14.1  christos 	return OK;
    229       1.12       jdc }
    230  1.23.14.2    martin #endif /* HAVE_WCHAR */
    231  1.23.14.2    martin 
    232       1.12       jdc 
    233       1.12       jdc /*
    234  1.23.14.1  christos  * getattrs --
    235  1.23.14.1  christos  *	Get window attributes.
    236       1.12       jdc  */
    237  1.23.14.1  christos chtype
    238  1.23.14.1  christos getattrs(WINDOW *win)
    239       1.12       jdc {
    240       1.12       jdc #ifdef DEBUG
    241  1.23.14.1  christos 	__CTRACE(__CTRACE_ATTR, "getattrs: win %p\n", win);
    242       1.12       jdc #endif
    243  1.23.14.1  christos 	return((chtype) win->wattr);
    244        1.1       mrg }
    245        1.1       mrg 
    246        1.1       mrg /*
    247  1.23.14.1  christos  * wattron --
    248  1.23.14.1  christos  *	Test and set attributes.
    249        1.1       mrg  */
    250        1.1       mrg int
    251  1.23.14.1  christos wattron(WINDOW *win, int attr)
    252        1.1       mrg {
    253        1.5       jdc #ifdef DEBUG
    254  1.23.14.1  christos 	__CTRACE(__CTRACE_ATTR, "wattron: win %p, attr %08x\n", win, attr);
    255        1.5       jdc #endif
    256  1.23.14.1  christos 	return __wattr_on(win, (attr_t) attr);
    257       1.12       jdc }
    258       1.12       jdc 
    259       1.12       jdc /*
    260  1.23.14.1  christos  * wattroff --
    261  1.23.14.1  christos  *	Test and unset attributes.
    262       1.12       jdc  */
    263       1.12       jdc int
    264  1.23.14.1  christos wattroff(WINDOW *win, int attr)
    265       1.12       jdc {
    266       1.12       jdc #ifdef DEBUG
    267  1.23.14.1  christos 	__CTRACE(__CTRACE_ATTR, "wattroff: win %p, attr %08x\n", win, attr);
    268       1.12       jdc #endif
    269  1.23.14.1  christos 	return __wattr_off(win, (attr_t) attr);
    270        1.8       jdc }
    271        1.8       jdc 
    272        1.8       jdc /*
    273  1.23.14.1  christos  * wattrset --
    274  1.23.14.1  christos  *	Set specific attribute modes.
    275  1.23.14.1  christos  *	Unset others.
    276        1.8       jdc  */
    277  1.23.14.1  christos int
    278  1.23.14.1  christos wattrset(WINDOW *win, int attr)
    279        1.8       jdc {
    280        1.8       jdc #ifdef DEBUG
    281  1.23.14.1  christos 	__CTRACE(__CTRACE_ATTR, "wattrset: win %p, attr %08x\n", win, attr);
    282        1.8       jdc #endif
    283  1.23.14.1  christos 	__wattr_off(win, __ATTRIBUTES);
    284  1.23.14.1  christos 	__wattr_on(win, (attr_t) attr);
    285  1.23.14.1  christos 	return OK;
    286       1.12       jdc }
    287       1.12       jdc 
    288       1.12       jdc /*
    289       1.16       jdc  * termattrs --
    290       1.16       jdc  *	Get terminal attributes
    291       1.16       jdc  */
    292       1.16       jdc chtype
    293       1.16       jdc termattrs(void)
    294       1.16       jdc {
    295       1.19      yamt 	chtype ch = 0;
    296       1.19      yamt 
    297       1.16       jdc #ifdef DEBUG
    298       1.16       jdc 	__CTRACE(__CTRACE_ATTR, "termattrs\n");
    299       1.16       jdc #endif
    300       1.20       roy 	if (exit_attribute_mode != NULL) {
    301       1.21     blymn #ifdef DEBUG
    302       1.21     blymn 	__CTRACE(__CTRACE_ATTR, "termattrs: have exit attribute mode\n");
    303       1.21     blymn #endif
    304       1.20       roy 		if (enter_blink_mode != NULL)
    305       1.16       jdc 			ch |= __BLINK;
    306       1.20       roy 		if (enter_bold_mode != NULL)
    307       1.16       jdc 			ch |= __BOLD;
    308       1.20       roy 		if (enter_dim_mode != NULL)
    309       1.16       jdc 			ch |= __DIM;
    310       1.20       roy 		if (enter_secure_mode != NULL)
    311       1.16       jdc 			ch |= __BLANK;
    312       1.20       roy 		if (enter_protected_mode != NULL)
    313       1.16       jdc 			ch |= __PROTECT;
    314       1.20       roy 		if (enter_reverse_mode != NULL)
    315       1.16       jdc 			ch |= __REVERSE;
    316       1.16       jdc 	}
    317       1.20       roy 	if (enter_standout_mode != NULL && exit_standout_mode != NULL)
    318       1.16       jdc 		ch |= __STANDOUT;
    319       1.20       roy 	if (enter_underline_mode != NULL && exit_underline_mode != NULL)
    320       1.16       jdc 		ch |= __UNDERSCORE;
    321       1.20       roy 	if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL)
    322       1.16       jdc 		ch |= __ALTCHARSET;
    323       1.16       jdc 
    324       1.16       jdc 	return ch;
    325       1.16       jdc }
    326       1.16       jdc 
    327  1.23.14.2    martin 
    328  1.23.14.2    martin #ifdef HAVE_WCHAR
    329       1.16       jdc /*
    330       1.16       jdc  * term_attrs --
    331       1.16       jdc  *	Get terminal wide attributes
    332       1.16       jdc  */
    333       1.16       jdc attr_t
    334       1.16       jdc term_attrs(void)
    335       1.16       jdc {
    336       1.19      yamt 	attr_t attr = 0;
    337       1.19      yamt 
    338       1.16       jdc #ifdef DEBUG
    339       1.16       jdc 	__CTRACE(__CTRACE_ATTR, "term_attrs\n");
    340       1.16       jdc #endif
    341       1.20       roy 	if (exit_attribute_mode != NULL) {
    342       1.20       roy 		if (enter_blink_mode != NULL)
    343       1.17       jdc 			attr |= __BLINK;
    344       1.20       roy 		if (enter_bold_mode != NULL)
    345       1.17       jdc 			attr |= __BOLD;
    346       1.20       roy 		if (enter_dim_mode != NULL)
    347       1.17       jdc 			attr |= __DIM;
    348       1.20       roy 		if (enter_secure_mode != NULL)
    349       1.17       jdc 			attr |= __BLANK;
    350       1.20       roy 		if (enter_protected_mode != NULL)
    351       1.17       jdc 			attr |= __PROTECT;
    352       1.20       roy 		if (enter_reverse_mode != NULL)
    353       1.17       jdc 			attr |= __REVERSE;
    354       1.16       jdc #ifdef HAVE_WCHAR
    355       1.20       roy 		if (enter_low_hl_mode != NULL)
    356       1.16       jdc 			attr |= WA_LOW;
    357       1.20       roy 		if (enter_top_hl_mode != NULL)
    358       1.16       jdc 			attr |= WA_TOP;
    359       1.20       roy 		if (enter_left_hl_mode != NULL)
    360       1.16       jdc 			attr |= WA_LEFT;
    361       1.20       roy 		if (enter_right_hl_mode != NULL)
    362       1.16       jdc 			attr |= WA_RIGHT;
    363       1.20       roy 		if (enter_horizontal_hl_mode != NULL)
    364       1.16       jdc 			attr |= WA_HORIZONTAL;
    365       1.20       roy 		if (enter_vertical_hl_mode != NULL)
    366       1.16       jdc 			attr |= WA_VERTICAL;
    367       1.16       jdc #endif /* HAVE_WCHAR */
    368       1.16       jdc 	}
    369       1.20       roy 	if (enter_standout_mode != NULL && exit_standout_mode != NULL)
    370       1.17       jdc 		attr |= __STANDOUT;
    371       1.20       roy 	if (enter_underline_mode != NULL && exit_underline_mode != NULL)
    372       1.17       jdc 		attr |= __UNDERSCORE;
    373       1.20       roy 	if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL)
    374       1.17       jdc 		attr |= __ALTCHARSET;
    375       1.16       jdc 
    376       1.16       jdc 	return attr;
    377       1.16       jdc }
    378  1.23.14.2    martin #endif /* HAVE_WCHAR */
    379       1.16       jdc 
    380  1.23.14.1  christos 
    381  1.23.14.1  christos static int
    382  1.23.14.1  christos __wattr_on(WINDOW *win, attr_t attr)
    383  1.23.14.1  christos {
    384  1.23.14.1  christos 	const TERMINAL *t = win->screen->term;
    385  1.23.14.1  christos 
    386  1.23.14.1  christos #ifdef DEBUG
    387  1.23.14.1  christos 	__CTRACE(__CTRACE_ATTR, "wattr_on: win %p, attr %08x\n", win, attr);
    388  1.23.14.1  christos #endif
    389  1.23.14.1  christos 	/* If can enter modes, set the relevent attribute bits. */
    390  1.23.14.1  christos 	if (t_exit_attribute_mode(t) != NULL) {
    391  1.23.14.1  christos 		if (attr & __BLINK && t_enter_blink_mode(t) != NULL)
    392  1.23.14.1  christos 			win->wattr |= __BLINK;
    393  1.23.14.1  christos 		if (attr & __BOLD && t_enter_bold_mode(t) != NULL)
    394  1.23.14.1  christos 			win->wattr |= __BOLD;
    395  1.23.14.1  christos 		if (attr & __DIM && t_enter_dim_mode(t) != NULL)
    396  1.23.14.1  christos 			win->wattr |= __DIM;
    397  1.23.14.1  christos 		if (attr & __BLANK && t_enter_secure_mode(t) != NULL)
    398  1.23.14.1  christos 			win->wattr |= __BLANK;
    399  1.23.14.1  christos 		if (attr & __PROTECT && t_enter_protected_mode(t) != NULL)
    400  1.23.14.1  christos 			win->wattr |= __PROTECT;
    401  1.23.14.1  christos 		if (attr & __REVERSE && t_enter_reverse_mode(t) != NULL)
    402  1.23.14.1  christos 			win->wattr |= __REVERSE;
    403  1.23.14.1  christos #ifdef HAVE_WCHAR
    404  1.23.14.1  christos 		if (attr & WA_LOW && t_enter_low_hl_mode(t) != NULL)
    405  1.23.14.1  christos 			win->wattr |= WA_LOW;
    406  1.23.14.1  christos 		if (attr & WA_TOP && t_enter_top_hl_mode(t) != NULL)
    407  1.23.14.1  christos 			win->wattr |= WA_TOP;
    408  1.23.14.1  christos 		if (attr & WA_LEFT && t_enter_left_hl_mode(t) != NULL)
    409  1.23.14.1  christos 			win->wattr |= WA_LEFT;
    410  1.23.14.1  christos 		if (attr & WA_RIGHT && t_enter_right_hl_mode(t) != NULL)
    411  1.23.14.1  christos 			win->wattr |= WA_RIGHT;
    412  1.23.14.1  christos 		if (attr & WA_HORIZONTAL && t_enter_horizontal_hl_mode(t) != NULL)
    413  1.23.14.1  christos 			win->wattr |= WA_HORIZONTAL;
    414  1.23.14.1  christos 		if (attr & WA_VERTICAL && t_enter_vertical_hl_mode(t) != NULL)
    415  1.23.14.1  christos 			win->wattr |= WA_VERTICAL;
    416  1.23.14.1  christos #endif /* HAVE_WCHAR */
    417  1.23.14.1  christos 	}
    418  1.23.14.1  christos 	if (attr & __STANDOUT && t_enter_standout_mode(t) != NULL &&
    419  1.23.14.1  christos 	    t_exit_standout_mode(t) != NULL)
    420  1.23.14.1  christos 		wstandout(win);
    421  1.23.14.1  christos 	if (attr & __UNDERSCORE && t_enter_underline_mode(t) != NULL &&
    422  1.23.14.1  christos 	    t_exit_underline_mode(t) != NULL)
    423  1.23.14.1  christos 		wunderscore(win);
    424  1.23.14.1  christos 	if (attr & __COLOR)
    425  1.23.14.1  christos 		__wcolor_set(win, attr);
    426  1.23.14.1  christos 	return OK;
    427  1.23.14.1  christos }
    428  1.23.14.1  christos 
    429  1.23.14.1  christos 
    430  1.23.14.1  christos static int
    431  1.23.14.1  christos __wattr_off(WINDOW *win, attr_t attr)
    432  1.23.14.1  christos {
    433  1.23.14.1  christos 	const TERMINAL *t = win->screen->term;
    434  1.23.14.1  christos 
    435  1.23.14.1  christos #ifdef DEBUG
    436  1.23.14.1  christos 	__CTRACE(__CTRACE_ATTR, "wattr_off: win %p, attr %08x\n", win, attr);
    437  1.23.14.1  christos #endif
    438  1.23.14.1  christos 	/* If can do exit modes, unset the relevent attribute bits. */
    439  1.23.14.1  christos 	if (t_exit_attribute_mode(t) != NULL) {
    440  1.23.14.1  christos 		if (attr & __BLINK)
    441  1.23.14.1  christos 			win->wattr &= ~__BLINK;
    442  1.23.14.1  christos 		if (attr & __BOLD)
    443  1.23.14.1  christos 			win->wattr &= ~__BOLD;
    444  1.23.14.1  christos 		if (attr & __DIM)
    445  1.23.14.1  christos 			win->wattr &= ~__DIM;
    446  1.23.14.1  christos 		if (attr & __BLANK)
    447  1.23.14.1  christos 			win->wattr &= ~__BLANK;
    448  1.23.14.1  christos 		if (attr & __PROTECT)
    449  1.23.14.1  christos 			win->wattr &= ~__PROTECT;
    450  1.23.14.1  christos 		if (attr & __REVERSE)
    451  1.23.14.1  christos 			win->wattr &= ~__REVERSE;
    452  1.23.14.1  christos #ifdef HAVE_WCHAR
    453  1.23.14.1  christos 		if (attr & WA_LOW)
    454  1.23.14.1  christos 			win->wattr &= ~WA_LOW;
    455  1.23.14.1  christos 		if (attr & WA_TOP)
    456  1.23.14.1  christos 			win->wattr &= ~WA_TOP;
    457  1.23.14.1  christos 		if (attr & WA_LEFT)
    458  1.23.14.1  christos 			win->wattr &= ~WA_LEFT;
    459  1.23.14.1  christos 		if (attr & WA_RIGHT)
    460  1.23.14.1  christos 			win->wattr &= ~WA_RIGHT;
    461  1.23.14.1  christos 		if (attr & WA_HORIZONTAL)
    462  1.23.14.1  christos 			win->wattr &= ~WA_HORIZONTAL;
    463  1.23.14.1  christos 		if (attr & WA_VERTICAL)
    464  1.23.14.1  christos 			win->wattr &= ~WA_VERTICAL;
    465  1.23.14.1  christos #endif /* HAVE_WCHAR */
    466  1.23.14.1  christos 	}
    467  1.23.14.1  christos 	if (attr & __STANDOUT)
    468  1.23.14.1  christos 		wstandend(win);
    469  1.23.14.1  christos 	if (attr & __UNDERSCORE)
    470  1.23.14.1  christos 		wunderend(win);
    471  1.23.14.1  christos 	if (attr & __COLOR) {
    472  1.23.14.1  christos 		if (max_colors != 0)
    473  1.23.14.1  christos 			win->wattr &= ~__COLOR;
    474  1.23.14.1  christos 	}
    475  1.23.14.1  christos 	return OK;
    476  1.23.14.1  christos }
    477  1.23.14.1  christos 
    478  1.23.14.1  christos 
    479  1.23.14.1  christos static void
    480       1.12       jdc __wcolor_set(WINDOW *win, attr_t attr)
    481       1.12       jdc {
    482       1.23       roy 	const TERMINAL *t = win->screen->term;
    483       1.23       roy 
    484       1.12       jdc 	/* If another color pair is set, turn that off first. */
    485       1.12       jdc 	win->wattr &= ~__COLOR;
    486       1.12       jdc 	/* If can do color video, set the color pair bits. */
    487       1.23       roy 	if (t_max_colors(t) != 0 && attr & __COLOR)
    488       1.12       jdc 		win->wattr |= attr & __COLOR;
    489        1.1       mrg }
    490