Home | History | Annotate | Line # | Download | only in libcurses
attributes.c revision 1.13.18.4
      1  1.13.18.4    blymn /*	$NetBSD: attributes.c,v 1.13.18.4 2007/05/28 14:17:55 blymn 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.13.18.4    blymn __RCSID("$NetBSD: attributes.c,v 1.13.18.4 2007/05/28 14:17:55 blymn 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.12      jdc void __wcolor_set(WINDOW *, attr_t);
     48       1.12      jdc 
     49        1.4    blymn #ifndef _CURSES_USE_MACROS
     50        1.4    blymn /*
     51       1.12      jdc  * attr_get --
     52       1.12      jdc  *	Get attributes and color pair from stdscr
     53       1.12      jdc  */
     54       1.12      jdc /* ARGSUSED */
     55       1.12      jdc int
     56       1.12      jdc attr_get(attr_t *attr, short *pair, void *opt)
     57       1.12      jdc {
     58       1.12      jdc 	return wattr_get(stdscr, attr, pair, opt);
     59       1.12      jdc }
     60       1.12      jdc 
     61       1.12      jdc /*
     62       1.12      jdc  * attr_on --
     63       1.12      jdc  *	Test and set attributes on stdscr
     64       1.12      jdc  */
     65       1.12      jdc /* ARGSUSED */
     66       1.12      jdc int
     67       1.12      jdc attr_on(attr_t attr, void *opt)
     68       1.12      jdc {
     69       1.12      jdc 	return wattr_on(stdscr, attr, opt);
     70       1.12      jdc }
     71       1.12      jdc 
     72       1.12      jdc /*
     73       1.12      jdc  * attr_off --
     74       1.12      jdc  *	Test and unset attributes on stdscr
     75       1.12      jdc  */
     76       1.12      jdc /* ARGSUSED */
     77       1.12      jdc int
     78       1.12      jdc attr_off(attr_t attr, void *opt)
     79       1.12      jdc {
     80       1.12      jdc 	return wattr_off(stdscr, attr, opt);
     81       1.12      jdc }
     82       1.12      jdc 
     83       1.12      jdc /*
     84       1.12      jdc  * attr_set --
     85       1.12      jdc  *	Set attributes and color pair on stdscr
     86       1.12      jdc  */
     87       1.12      jdc /* ARGSUSED */
     88       1.12      jdc int
     89       1.12      jdc attr_set(attr_t attr, short pair, void *opt)
     90       1.12      jdc {
     91       1.12      jdc 	return wattr_set(stdscr, attr, pair, opt);
     92       1.12      jdc }
     93       1.12      jdc 
     94       1.12      jdc /*
     95       1.12      jdc  * color_set --
     96       1.12      jdc  *	Set color pair on stdscr
     97       1.12      jdc  */
     98       1.12      jdc /* ARGSUSED */
     99       1.12      jdc int
    100       1.12      jdc color_set(short pair, void *opt)
    101       1.12      jdc {
    102       1.12      jdc 	return wcolor_set(stdscr, pair, opt);
    103       1.12      jdc }
    104       1.12      jdc 
    105       1.12      jdc /*
    106        1.8      jdc  * attron --
    107        1.4    blymn  *	Test and set attributes on stdscr
    108        1.4    blymn  */
    109        1.4    blymn int
    110        1.4    blymn attron(int attr)
    111        1.4    blymn {
    112       1.12      jdc 	return wattr_on(stdscr, (attr_t) attr, NULL);
    113        1.4    blymn }
    114        1.4    blymn 
    115        1.4    blymn /*
    116        1.8      jdc  * attroff --
    117        1.4    blymn  *	Test and unset attributes on stdscr.
    118        1.4    blymn  */
    119        1.4    blymn int
    120        1.4    blymn attroff(int attr)
    121        1.4    blymn {
    122       1.12      jdc 	return wattr_off(stdscr, (attr_t) attr, NULL);
    123        1.4    blymn }
    124        1.4    blymn 
    125        1.4    blymn /*
    126        1.8      jdc  * attrset --
    127        1.4    blymn  *	Set specific attribute modes.
    128        1.4    blymn  *	Unset others.  On stdscr.
    129        1.4    blymn  */
    130        1.4    blymn int
    131        1.4    blymn attrset(int attr)
    132        1.4    blymn {
    133        1.4    blymn 	return wattrset(stdscr, attr);
    134        1.4    blymn }
    135       1.12      jdc #endif	/* _CURSES_USE_MACROS */
    136        1.4    blymn 
    137       1.12      jdc /*
    138       1.12      jdc  * wattr_get --
    139       1.12      jdc  *	Get 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.12      jdc wattr_get(WINDOW *win, attr_t *attr, short *pair, void *opt)
    145       1.12      jdc {
    146       1.12      jdc #ifdef DEBUG
    147  1.13.18.2      jdc 	__CTRACE(__CTRACE_ATTR, "wattr_get: win %p\n", win);
    148        1.4    blymn #endif
    149  1.13.18.3    blymn 	if (attr != NULL) {
    150       1.12      jdc 		*attr = win->wattr;
    151  1.13.18.3    blymn #ifdef HAVE_WCHAR
    152  1.13.18.3    blymn 		*attr &= WA_ATTRIBUTES;
    153  1.13.18.3    blymn #endif
    154  1.13.18.3    blymn 	}
    155  1.13.18.3    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.12      jdc  *	Test and set attributes on stdscr
    164        1.1      mrg  *
    165        1.1      mrg  *	Modes are blinking, bold (extra bright), dim (half-bright),
    166        1.1      mrg  *	blanking (invisible), protected and reverse video
    167        1.1      mrg  */
    168       1.12      jdc /* ARGSUSED */
    169        1.1      mrg int
    170       1.12      jdc wattr_on(WINDOW *win, attr_t attr, void *opt)
    171        1.1      mrg {
    172        1.3      jdc #ifdef DEBUG
    173  1.13.18.2      jdc 	__CTRACE(__CTRACE_ATTR, "wattr_on: win %p, attr %08x\n", win, attr);
    174        1.3      jdc #endif
    175        1.7  mycroft 	/* If can enter modes, set the relevent attribute bits. */
    176        1.9      jdc 	if (__tc_me != NULL) {
    177       1.12      jdc 		if (attr & __BLINK && __tc_mb != NULL)
    178        1.2    blymn 			win->wattr |= __BLINK;
    179       1.12      jdc 		if (attr & __BOLD && __tc_md != NULL)
    180        1.2    blymn 			win->wattr |= __BOLD;
    181       1.12      jdc 		if (attr & __DIM && __tc_mh != NULL)
    182        1.2    blymn 			win->wattr |= __DIM;
    183       1.12      jdc 		if (attr & __BLANK && __tc_mk != NULL)
    184        1.2    blymn 			win->wattr |= __BLANK;
    185       1.12      jdc 		if (attr & __PROTECT && __tc_mp != NULL)
    186        1.2    blymn 			win->wattr |= __PROTECT;
    187       1.12      jdc 		if (attr & __REVERSE && __tc_mr != NULL)
    188        1.2    blymn 			win->wattr |= __REVERSE;
    189  1.13.18.1    blymn #ifdef HAVE_WCHAR
    190  1.13.18.1    blymn 		if (attr & WA_LOW && __tc_Xo != NULL)
    191  1.13.18.1    blymn 			win->wattr |= WA_LOW;
    192  1.13.18.1    blymn 		if (attr & WA_TOP && __tc_Xt != NULL)
    193  1.13.18.1    blymn 			win->wattr |= WA_TOP;
    194  1.13.18.1    blymn 		if (attr & WA_LEFT && __tc_Xl != NULL)
    195  1.13.18.1    blymn 			win->wattr |= WA_LEFT;
    196  1.13.18.1    blymn 		if (attr & WA_RIGHT && __tc_Xr != NULL)
    197  1.13.18.1    blymn 			win->wattr |= WA_RIGHT;
    198  1.13.18.1    blymn 		if (attr & WA_HORIZONTAL && __tc_Xh != NULL)
    199  1.13.18.1    blymn 			win->wattr |= WA_HORIZONTAL;
    200  1.13.18.1    blymn 		if (attr & WA_VERTICAL && __tc_Xv != NULL)
    201  1.13.18.1    blymn 			win->wattr |= WA_VERTICAL;
    202  1.13.18.1    blymn #endif /* HAVE_WCHAR */
    203        1.1      mrg 	}
    204       1.12      jdc 	if (attr & __STANDOUT)
    205        1.2    blymn 		wstandout(win);
    206       1.12      jdc 	if (attr & __UNDERSCORE)
    207        1.1      mrg 		wunderscore(win);
    208       1.12      jdc 	if ((attr_t) attr & __COLOR)
    209       1.12      jdc 		__wcolor_set(win, (attr_t) attr);
    210       1.12      jdc 	return OK;
    211        1.1      mrg }
    212        1.1      mrg 
    213        1.1      mrg /*
    214       1.12      jdc  * wattr_off --
    215       1.12      jdc  *	Test and unset attributes on stdscr
    216        1.1      mrg  *
    217        1.1      mrg  *	Note that the 'me' sequence unsets all attributes.  We handle
    218        1.1      mrg  *	which attributes should really be set in refresh.c:makech().
    219        1.1      mrg  */
    220       1.12      jdc /* ARGSUSED */
    221        1.1      mrg int
    222       1.12      jdc wattr_off(WINDOW *win, attr_t attr, void *opt)
    223        1.1      mrg {
    224        1.3      jdc #ifdef DEBUG
    225  1.13.18.2      jdc 	__CTRACE(__CTRACE_ATTR, "wattr_off: win %p, attr %08x\n", win, attr);
    226        1.3      jdc #endif
    227        1.3      jdc 	/* If can do exit modes, unset the relevent attribute bits. */
    228        1.9      jdc 	if (__tc_me != NULL) {
    229       1.12      jdc 		if (attr & __BLINK)
    230        1.2    blymn 			win->wattr &= ~__BLINK;
    231       1.12      jdc 		if (attr & __BOLD)
    232        1.2    blymn 			win->wattr &= ~__BOLD;
    233       1.12      jdc 		if (attr & __DIM)
    234        1.2    blymn 			win->wattr &= ~__DIM;
    235       1.12      jdc 		if (attr & __BLANK)
    236        1.2    blymn 			win->wattr &= ~__BLANK;
    237       1.12      jdc 		if (attr & __PROTECT)
    238        1.2    blymn 			win->wattr &= ~__PROTECT;
    239       1.12      jdc 		if (attr & __REVERSE)
    240        1.2    blymn 			win->wattr &= ~__REVERSE;
    241  1.13.18.1    blymn #ifdef HAVE_WCHAR
    242  1.13.18.1    blymn 		if (attr & WA_LOW)
    243  1.13.18.1    blymn 			win->wattr &= ~WA_LOW;
    244  1.13.18.1    blymn 		if (attr & WA_TOP)
    245  1.13.18.1    blymn 			win->wattr &= ~WA_TOP;
    246  1.13.18.1    blymn 		if (attr & WA_LEFT)
    247  1.13.18.1    blymn 			win->wattr &= ~WA_LEFT;
    248  1.13.18.1    blymn 		if (attr & WA_RIGHT)
    249  1.13.18.1    blymn 			win->wattr &= ~WA_RIGHT;
    250  1.13.18.1    blymn 		if (attr & WA_HORIZONTAL)
    251  1.13.18.1    blymn 			win->wattr &= ~WA_HORIZONTAL;
    252  1.13.18.1    blymn 		if (attr & WA_VERTICAL)
    253  1.13.18.1    blymn 			win->wattr &= ~WA_VERTICAL;
    254  1.13.18.1    blymn #endif /* HAVE_WCHAR */
    255        1.1      mrg 	}
    256       1.12      jdc 	if (attr & __STANDOUT)
    257        1.2    blymn 		wstandend(win);
    258       1.12      jdc 	if (attr & __UNDERSCORE)
    259        1.1      mrg 		wunderend(win);
    260        1.3      jdc 	if ((attr_t) attr & __COLOR) {
    261       1.13     fvdl 		if (__tc_Co != 0)
    262        1.3      jdc 			win->wattr &= ~__COLOR;
    263        1.3      jdc 	}
    264       1.12      jdc 	return OK;
    265       1.12      jdc }
    266       1.12      jdc 
    267       1.12      jdc /*
    268       1.12      jdc  * wattr_set --
    269       1.12      jdc  *	Set attributes and color pair on stdscr
    270       1.12      jdc  */
    271       1.12      jdc int
    272       1.12      jdc wattr_set(WINDOW *win, attr_t attr, short pair, void *opt)
    273       1.12      jdc {
    274       1.12      jdc #ifdef DEBUG
    275  1.13.18.2      jdc 	__CTRACE(__CTRACE_ATTR, "wattr_set: win %p, attr %08x, pair %d\n",
    276  1.13.18.2      jdc 	    win, attr, pair);
    277       1.12      jdc #endif
    278  1.13.18.4    blymn  	wattr_off(win, __ATTRIBUTES, opt);
    279       1.12      jdc 	/*
    280  1.13.18.2      jdc 	 * This overwrites any colour setting from the attributes
    281       1.12      jdc 	 * and is compatible with ncurses.
    282       1.12      jdc 	 */
    283  1.13.18.4    blymn  	attr = (attr & ~__COLOR) | COLOR_PAIR(pair);
    284  1.13.18.4    blymn  	wattr_on(win, attr, opt);
    285       1.12      jdc 	return OK;
    286       1.12      jdc }
    287       1.12      jdc 
    288       1.12      jdc /*
    289       1.12      jdc  * wattron --
    290       1.12      jdc  *	Test and set attributes.
    291       1.12      jdc  */
    292       1.12      jdc int
    293       1.12      jdc wattron(WINDOW *win, int attr)
    294       1.12      jdc {
    295       1.12      jdc #ifdef DEBUG
    296  1.13.18.2      jdc 	__CTRACE(__CTRACE_ATTR, "wattron: win %p, attr %08x\n", win, attr);
    297       1.12      jdc #endif
    298       1.12      jdc 	return wattr_on(win, (attr_t) attr, NULL);
    299       1.12      jdc }
    300       1.12      jdc 
    301       1.12      jdc /*
    302       1.12      jdc  * wattroff --
    303       1.12      jdc  *	Test and unset attributes.
    304       1.12      jdc  */
    305       1.12      jdc int
    306       1.12      jdc wattroff(WINDOW *win, int attr)
    307       1.12      jdc {
    308       1.12      jdc #ifdef DEBUG
    309  1.13.18.2      jdc 	__CTRACE(__CTRACE_ATTR, "wattroff: win %p, attr %08x\n", win, attr);
    310       1.12      jdc #endif
    311       1.12      jdc 	return wattr_off(win, (attr_t) attr, NULL);
    312        1.1      mrg }
    313        1.1      mrg 
    314        1.1      mrg /*
    315        1.8      jdc  * wattrset --
    316        1.1      mrg  *	Set specific attribute modes.
    317        1.1      mrg  *	Unset others.
    318        1.1      mrg  */
    319        1.1      mrg int
    320        1.4    blymn wattrset(WINDOW *win, int attr)
    321        1.1      mrg {
    322        1.5      jdc #ifdef DEBUG
    323  1.13.18.2      jdc 	__CTRACE(__CTRACE_ATTR, "wattrset: win %p, attr %08x\n", win, attr);
    324        1.5      jdc #endif
    325  1.13.18.4    blymn 	wattr_off(win, __ATTRIBUTES, NULL);
    326       1.12      jdc 	wattr_on(win, (attr_t) attr, NULL);
    327       1.12      jdc 	return OK;
    328       1.12      jdc }
    329       1.12      jdc 
    330       1.12      jdc /*
    331       1.12      jdc  * wcolor_set --
    332       1.12      jdc  *	Set color pair on window
    333       1.12      jdc  */
    334       1.12      jdc /* ARGSUSED */
    335       1.12      jdc int
    336       1.12      jdc wcolor_set(WINDOW *win, short pair, void *opt)
    337       1.12      jdc {
    338       1.12      jdc #ifdef DEBUG
    339  1.13.18.2      jdc 	__CTRACE(__CTRACE_COLOR, "wolor_set: win %p, pair %d\n", win, pair);
    340       1.12      jdc #endif
    341       1.12      jdc 	__wcolor_set(win, (attr_t) COLOR_PAIR(pair));
    342       1.12      jdc 	return OK;
    343        1.8      jdc }
    344        1.8      jdc 
    345        1.8      jdc /*
    346        1.8      jdc  * getattrs --
    347        1.8      jdc  * Get window attributes.
    348        1.8      jdc  */
    349        1.8      jdc chtype
    350        1.8      jdc getattrs(WINDOW *win)
    351        1.8      jdc {
    352        1.8      jdc #ifdef DEBUG
    353  1.13.18.2      jdc 	__CTRACE(__CTRACE_ATTR, "getattrs: win %p\n", win);
    354        1.8      jdc #endif
    355        1.8      jdc 	return((chtype) win->wattr);
    356       1.12      jdc }
    357       1.12      jdc 
    358       1.12      jdc /*
    359       1.12      jdc  * __wcolor_set --
    360       1.12      jdc  * Set color attribute on window
    361       1.12      jdc  */
    362       1.12      jdc void
    363       1.12      jdc __wcolor_set(WINDOW *win, attr_t attr)
    364       1.12      jdc {
    365       1.12      jdc 	/* If another color pair is set, turn that off first. */
    366       1.12      jdc 	win->wattr &= ~__COLOR;
    367       1.12      jdc 	/* If can do color video, set the color pair bits. */
    368       1.13     fvdl 	if (__tc_Co != 0 && attr & __COLOR)
    369       1.12      jdc 		win->wattr |= attr & __COLOR;
    370        1.1      mrg }
    371