Home | History | Annotate | Line # | Download | only in libcurses
attributes.c revision 1.13.18.1
      1  1.13.18.1    blymn /*	$NetBSD: attributes.c,v 1.13.18.1 2007/01/21 11:38:59 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.1    blymn __RCSID("$NetBSD: attributes.c,v 1.13.18.1 2007/01/21 11:38:59 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.12      jdc 	__CTRACE ("wattr_get: win %p\n", win);
    148        1.4    blymn #endif
    149       1.12      jdc 	if (attr != NULL)
    150       1.12      jdc 		*attr = win->wattr;
    151       1.12      jdc 	if (pair != NULL)
    152       1.12      jdc 		*pair = PAIR_NUMBER(win->wattr);
    153       1.12      jdc 	return OK;
    154       1.12      jdc }
    155        1.4    blymn 
    156        1.1      mrg /*
    157       1.12      jdc  * wattr_on --
    158       1.12      jdc  *	Test and set attributes on stdscr
    159        1.1      mrg  *
    160        1.1      mrg  *	Modes are blinking, bold (extra bright), dim (half-bright),
    161        1.1      mrg  *	blanking (invisible), protected and reverse video
    162        1.1      mrg  */
    163       1.12      jdc /* ARGSUSED */
    164        1.1      mrg int
    165       1.12      jdc wattr_on(WINDOW *win, attr_t attr, void *opt)
    166        1.1      mrg {
    167        1.3      jdc #ifdef DEBUG
    168       1.12      jdc 	__CTRACE ("wattr_on: win %p, attr %08x\n", win, attr);
    169        1.3      jdc #endif
    170        1.7  mycroft 	/* If can enter modes, set the relevent attribute bits. */
    171        1.9      jdc 	if (__tc_me != NULL) {
    172       1.12      jdc 		if (attr & __BLINK && __tc_mb != NULL)
    173        1.2    blymn 			win->wattr |= __BLINK;
    174       1.12      jdc 		if (attr & __BOLD && __tc_md != NULL)
    175        1.2    blymn 			win->wattr |= __BOLD;
    176       1.12      jdc 		if (attr & __DIM && __tc_mh != NULL)
    177        1.2    blymn 			win->wattr |= __DIM;
    178       1.12      jdc 		if (attr & __BLANK && __tc_mk != NULL)
    179        1.2    blymn 			win->wattr |= __BLANK;
    180       1.12      jdc 		if (attr & __PROTECT && __tc_mp != NULL)
    181        1.2    blymn 			win->wattr |= __PROTECT;
    182       1.12      jdc 		if (attr & __REVERSE && __tc_mr != NULL)
    183        1.2    blymn 			win->wattr |= __REVERSE;
    184  1.13.18.1    blymn #ifdef HAVE_WCHAR
    185  1.13.18.1    blymn 		if (attr & WA_LOW && __tc_Xo != NULL)
    186  1.13.18.1    blymn 			win->wattr |= WA_LOW;
    187  1.13.18.1    blymn 		if (attr & WA_TOP && __tc_Xt != NULL)
    188  1.13.18.1    blymn 			win->wattr |= WA_TOP;
    189  1.13.18.1    blymn 		if (attr & WA_LEFT && __tc_Xl != NULL)
    190  1.13.18.1    blymn 			win->wattr |= WA_LEFT;
    191  1.13.18.1    blymn 		if (attr & WA_RIGHT && __tc_Xr != NULL)
    192  1.13.18.1    blymn 			win->wattr |= WA_RIGHT;
    193  1.13.18.1    blymn 		if (attr & WA_HORIZONTAL && __tc_Xh != NULL)
    194  1.13.18.1    blymn 			win->wattr |= WA_HORIZONTAL;
    195  1.13.18.1    blymn 		if (attr & WA_VERTICAL && __tc_Xv != NULL)
    196  1.13.18.1    blymn 			win->wattr |= WA_VERTICAL;
    197  1.13.18.1    blymn #endif /* HAVE_WCHAR */
    198        1.1      mrg 	}
    199       1.12      jdc 	if (attr & __STANDOUT)
    200        1.2    blymn 		wstandout(win);
    201       1.12      jdc 	if (attr & __UNDERSCORE)
    202        1.1      mrg 		wunderscore(win);
    203       1.12      jdc 	if ((attr_t) attr & __COLOR)
    204       1.12      jdc 		__wcolor_set(win, (attr_t) attr);
    205       1.12      jdc 	return OK;
    206        1.1      mrg }
    207        1.1      mrg 
    208        1.1      mrg /*
    209       1.12      jdc  * wattr_off --
    210       1.12      jdc  *	Test and unset attributes on stdscr
    211        1.1      mrg  *
    212        1.1      mrg  *	Note that the 'me' sequence unsets all attributes.  We handle
    213        1.1      mrg  *	which attributes should really be set in refresh.c:makech().
    214        1.1      mrg  */
    215       1.12      jdc /* ARGSUSED */
    216        1.1      mrg int
    217       1.12      jdc wattr_off(WINDOW *win, attr_t attr, void *opt)
    218        1.1      mrg {
    219        1.3      jdc #ifdef DEBUG
    220       1.12      jdc 	__CTRACE ("wattr_off: win %p, attr %08x\n", win, attr);
    221        1.3      jdc #endif
    222        1.3      jdc 	/* If can do exit modes, unset the relevent attribute bits. */
    223        1.9      jdc 	if (__tc_me != NULL) {
    224       1.12      jdc 		if (attr & __BLINK)
    225        1.2    blymn 			win->wattr &= ~__BLINK;
    226       1.12      jdc 		if (attr & __BOLD)
    227        1.2    blymn 			win->wattr &= ~__BOLD;
    228       1.12      jdc 		if (attr & __DIM)
    229        1.2    blymn 			win->wattr &= ~__DIM;
    230       1.12      jdc 		if (attr & __BLANK)
    231        1.2    blymn 			win->wattr &= ~__BLANK;
    232       1.12      jdc 		if (attr & __PROTECT)
    233        1.2    blymn 			win->wattr &= ~__PROTECT;
    234       1.12      jdc 		if (attr & __REVERSE)
    235        1.2    blymn 			win->wattr &= ~__REVERSE;
    236  1.13.18.1    blymn #ifdef HAVE_WCHAR
    237  1.13.18.1    blymn 		if (attr & WA_LOW)
    238  1.13.18.1    blymn 			win->wattr &= ~WA_LOW;
    239  1.13.18.1    blymn 		if (attr & WA_TOP)
    240  1.13.18.1    blymn 			win->wattr &= ~WA_TOP;
    241  1.13.18.1    blymn 		if (attr & WA_LEFT)
    242  1.13.18.1    blymn 			win->wattr &= ~WA_LEFT;
    243  1.13.18.1    blymn 		if (attr & WA_RIGHT)
    244  1.13.18.1    blymn 			win->wattr &= ~WA_RIGHT;
    245  1.13.18.1    blymn 		if (attr & WA_HORIZONTAL)
    246  1.13.18.1    blymn 			win->wattr &= ~WA_HORIZONTAL;
    247  1.13.18.1    blymn 		if (attr & WA_VERTICAL)
    248  1.13.18.1    blymn 			win->wattr &= ~WA_VERTICAL;
    249  1.13.18.1    blymn #endif /* HAVE_WCHAR */
    250        1.1      mrg 	}
    251       1.12      jdc 	if (attr & __STANDOUT)
    252        1.2    blymn 		wstandend(win);
    253       1.12      jdc 	if (attr & __UNDERSCORE)
    254        1.1      mrg 		wunderend(win);
    255        1.3      jdc 	if ((attr_t) attr & __COLOR) {
    256       1.13     fvdl 		if (__tc_Co != 0)
    257        1.3      jdc 			win->wattr &= ~__COLOR;
    258        1.3      jdc 	}
    259       1.12      jdc 	return OK;
    260       1.12      jdc }
    261       1.12      jdc 
    262       1.12      jdc /*
    263       1.12      jdc  * wattr_set --
    264       1.12      jdc  *	Set attributes and color pair on stdscr
    265       1.12      jdc  */
    266       1.12      jdc /* ARGSUSED */
    267       1.12      jdc int
    268       1.12      jdc wattr_set(WINDOW *win, attr_t attr, short pair, void *opt)
    269       1.12      jdc {
    270       1.12      jdc #ifdef DEBUG
    271       1.12      jdc 	__CTRACE ("wattr_set: win %p, attr %08x, pair %d\n", win, attr, pair);
    272       1.12      jdc #endif
    273       1.12      jdc 	wattr_on(win, attr, NULL);
    274       1.12      jdc 	wattr_off(win, (~attr & ~__COLOR) | ((attr & __COLOR) ? 0 : __COLOR),
    275       1.12      jdc 	    NULL);
    276       1.12      jdc 	/*
    277  1.13.18.1    blymn      * This overwrites any colour setting from the attributes
    278       1.12      jdc 	 * and is compatible with ncurses.
    279       1.12      jdc 	 */
    280       1.12      jdc 	__wcolor_set(win, (attr_t) COLOR_PAIR(pair));
    281       1.12      jdc 	return OK;
    282       1.12      jdc }
    283       1.12      jdc 
    284       1.12      jdc /*
    285       1.12      jdc  * wattron --
    286       1.12      jdc  *	Test and set attributes.
    287       1.12      jdc  */
    288       1.12      jdc 
    289       1.12      jdc int
    290       1.12      jdc wattron(WINDOW *win, int attr)
    291       1.12      jdc {
    292       1.12      jdc #ifdef DEBUG
    293       1.12      jdc 	__CTRACE ("wattron: win %p, attr %08x\n", win, attr);
    294       1.12      jdc #endif
    295       1.12      jdc 	return wattr_on(win, (attr_t) attr, NULL);
    296       1.12      jdc }
    297       1.12      jdc 
    298       1.12      jdc /*
    299       1.12      jdc  * wattroff --
    300       1.12      jdc  *	Test and unset attributes.
    301       1.12      jdc  */
    302       1.12      jdc int
    303       1.12      jdc wattroff(WINDOW *win, int attr)
    304       1.12      jdc {
    305       1.12      jdc #ifdef DEBUG
    306       1.12      jdc 	__CTRACE ("wattroff: win %p, attr %08x\n", win, attr);
    307       1.12      jdc #endif
    308       1.12      jdc 	return wattr_off(win, (attr_t) attr, NULL);
    309        1.1      mrg }
    310        1.1      mrg 
    311        1.1      mrg /*
    312        1.8      jdc  * wattrset --
    313        1.1      mrg  *	Set specific attribute modes.
    314        1.1      mrg  *	Unset others.
    315        1.1      mrg  */
    316        1.1      mrg int
    317        1.4    blymn wattrset(WINDOW *win, int attr)
    318        1.1      mrg {
    319        1.5      jdc #ifdef DEBUG
    320       1.11      dsl 	__CTRACE ("wattrset: win %p, attr %08x\n", win, attr);
    321        1.5      jdc #endif
    322       1.12      jdc 	wattr_on(win, (attr_t) attr, NULL);
    323       1.12      jdc 	wattr_off(win,
    324       1.12      jdc 	    (attr_t) (~attr & ~__COLOR) | ((attr & __COLOR) ? 0 : __COLOR),
    325       1.12      jdc 	    NULL);
    326       1.12      jdc 	return OK;
    327       1.12      jdc }
    328       1.12      jdc 
    329       1.12      jdc /*
    330       1.12      jdc  * wcolor_set --
    331       1.12      jdc  *	Set color pair on window
    332       1.12      jdc  */
    333       1.12      jdc /* ARGSUSED */
    334       1.12      jdc int
    335       1.12      jdc wcolor_set(WINDOW *win, short pair, void *opt)
    336       1.12      jdc {
    337       1.12      jdc #ifdef DEBUG
    338       1.12      jdc 	__CTRACE ("wolor_set: win %p, pair %%d\n", win, pair);
    339       1.12      jdc #endif
    340       1.12      jdc 	__wcolor_set(win, (attr_t) COLOR_PAIR(pair));
    341       1.12      jdc 	return OK;
    342        1.8      jdc }
    343        1.8      jdc 
    344        1.8      jdc /*
    345        1.8      jdc  * getattrs --
    346        1.8      jdc  * Get window attributes.
    347        1.8      jdc  */
    348        1.8      jdc chtype
    349        1.8      jdc getattrs(WINDOW *win)
    350        1.8      jdc {
    351        1.8      jdc #ifdef DEBUG
    352       1.11      dsl 	__CTRACE ("getattrs: win %p\n", win);
    353        1.8      jdc #endif
    354        1.8      jdc 	return((chtype) win->wattr);
    355       1.12      jdc }
    356       1.12      jdc 
    357       1.12      jdc /*
    358       1.12      jdc  * __wcolor_set --
    359       1.12      jdc  * Set color attribute on window
    360       1.12      jdc  */
    361       1.12      jdc void
    362       1.12      jdc __wcolor_set(WINDOW *win, attr_t attr)
    363       1.12      jdc {
    364       1.12      jdc 	/* If another color pair is set, turn that off first. */
    365       1.12      jdc 	win->wattr &= ~__COLOR;
    366       1.12      jdc 	/* If can do color video, set the color pair bits. */
    367       1.13     fvdl 	if (__tc_Co != 0 && attr & __COLOR)
    368       1.12      jdc 		win->wattr |= attr & __COLOR;
    369        1.1      mrg }
    370