1 /* $NetBSD: attributes.c,v 1.18 2008/04/28 20:23:01 martin Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: attributes.c,v 1.18 2008/04/28 20:23:01 martin Exp $");
38 #include "curses_private.h"
40 void __wcolor_set(WINDOW
*, attr_t
);
42 #ifndef _CURSES_USE_MACROS
45 * Get wide attributes and color pair from stdscr
49 attr_get(attr_t
*attr
, short *pair
, void *opt
)
51 return wattr_get(stdscr
, attr
, pair
, opt
);
56 * Test and set wide attributes on stdscr
60 attr_on(attr_t attr
, void *opt
)
62 return wattr_on(stdscr
, attr
, opt
);
67 * Test and unset wide attributes on stdscr
71 attr_off(attr_t attr
, void *opt
)
73 return wattr_off(stdscr
, attr
, opt
);
78 * Set wide attributes and color pair on stdscr
82 attr_set(attr_t attr
, short pair
, void *opt
)
84 return wattr_set(stdscr
, attr
, pair
, opt
);
89 * Set color pair on stdscr
93 color_set(short pair
, void *opt
)
95 return wcolor_set(stdscr
, pair
, opt
);
100 * Test and set attributes on stdscr
105 return wattr_on(stdscr
, (attr_t
) attr
, NULL
);
110 * Test and unset attributes on stdscr.
115 return wattr_off(stdscr
, (attr_t
) attr
, NULL
);
120 * Set specific attribute modes.
121 * Unset others. On stdscr.
126 return wattrset(stdscr
, attr
);
128 #endif /* _CURSES_USE_MACROS */
132 * Get wide attributes and colour pair from window
133 * Note that attributes also includes colour.
137 wattr_get(WINDOW
*win
, attr_t
*attr
, short *pair
, void *opt
)
140 __CTRACE(__CTRACE_ATTR
, "wattr_get: win %p\n", win
);
145 *attr
&= WA_ATTRIBUTES
;
150 *pair
= PAIR_NUMBER(win
->wattr
);
156 * Test and set wide attributes on window
160 wattr_on(WINDOW
*win
, attr_t attr
, void *opt
)
163 __CTRACE(__CTRACE_ATTR
, "wattr_on: win %p, attr %08x\n", win
, attr
);
165 /* If can enter modes, set the relevent attribute bits. */
166 if (__tc_me
!= NULL
) {
167 if (attr
& __BLINK
&& __tc_mb
!= NULL
)
168 win
->wattr
|= __BLINK
;
169 if (attr
& __BOLD
&& __tc_md
!= NULL
)
170 win
->wattr
|= __BOLD
;
171 if (attr
& __DIM
&& __tc_mh
!= NULL
)
173 if (attr
& __BLANK
&& __tc_mk
!= NULL
)
174 win
->wattr
|= __BLANK
;
175 if (attr
& __PROTECT
&& __tc_mp
!= NULL
)
176 win
->wattr
|= __PROTECT
;
177 if (attr
& __REVERSE
&& __tc_mr
!= NULL
)
178 win
->wattr
|= __REVERSE
;
180 if (attr
& WA_LOW
&& __tc_Xo
!= NULL
)
181 win
->wattr
|= WA_LOW
;
182 if (attr
& WA_TOP
&& __tc_Xt
!= NULL
)
183 win
->wattr
|= WA_TOP
;
184 if (attr
& WA_LEFT
&& __tc_Xl
!= NULL
)
185 win
->wattr
|= WA_LEFT
;
186 if (attr
& WA_RIGHT
&& __tc_Xr
!= NULL
)
187 win
->wattr
|= WA_RIGHT
;
188 if (attr
& WA_HORIZONTAL
&& __tc_Xh
!= NULL
)
189 win
->wattr
|= WA_HORIZONTAL
;
190 if (attr
& WA_VERTICAL
&& __tc_Xv
!= NULL
)
191 win
->wattr
|= WA_VERTICAL
;
192 #endif /* HAVE_WCHAR */
194 if (attr
& __STANDOUT
&& __tc_so
!= NULL
&& __tc_se
!= NULL
)
196 if (attr
& __UNDERSCORE
&& __tc_us
!= NULL
&& __tc_ue
!= NULL
)
198 if ((attr_t
) attr
& __COLOR
)
199 __wcolor_set(win
, (attr_t
) attr
);
205 * Test and unset wide attributes on window
207 * Note that the 'me' sequence unsets all attributes. We handle
208 * which attributes should really be set in refresh.c:makech().
212 wattr_off(WINDOW
*win
, attr_t attr
, void *opt
)
215 __CTRACE(__CTRACE_ATTR
, "wattr_off: win %p, attr %08x\n", win
, attr
);
217 /* If can do exit modes, unset the relevent attribute bits. */
218 if (__tc_me
!= NULL
) {
220 win
->wattr
&= ~__BLINK
;
222 win
->wattr
&= ~__BOLD
;
224 win
->wattr
&= ~__DIM
;
226 win
->wattr
&= ~__BLANK
;
227 if (attr
& __PROTECT
)
228 win
->wattr
&= ~__PROTECT
;
229 if (attr
& __REVERSE
)
230 win
->wattr
&= ~__REVERSE
;
233 win
->wattr
&= ~WA_LOW
;
235 win
->wattr
&= ~WA_TOP
;
237 win
->wattr
&= ~WA_LEFT
;
239 win
->wattr
&= ~WA_RIGHT
;
240 if (attr
& WA_HORIZONTAL
)
241 win
->wattr
&= ~WA_HORIZONTAL
;
242 if (attr
& WA_VERTICAL
)
243 win
->wattr
&= ~WA_VERTICAL
;
244 #endif /* HAVE_WCHAR */
246 if (attr
& __STANDOUT
)
248 if (attr
& __UNDERSCORE
)
250 if ((attr_t
) attr
& __COLOR
) {
252 win
->wattr
&= ~__COLOR
;
259 * Set wide attributes and color pair on window
262 wattr_set(WINDOW
*win
, attr_t attr
, short pair
, void *opt
)
265 __CTRACE(__CTRACE_ATTR
, "wattr_set: win %p, attr %08x, pair %d\n",
268 wattr_off(win
, __ATTRIBUTES
, opt
);
270 * This overwrites any colour setting from the attributes
271 * and is compatible with ncurses.
273 attr
= (attr
& ~__COLOR
) | COLOR_PAIR(pair
);
274 wattr_on(win
, attr
, opt
);
280 * Test and set attributes.
283 wattron(WINDOW
*win
, int attr
)
286 __CTRACE(__CTRACE_ATTR
, "wattron: win %p, attr %08x\n", win
, attr
);
288 return wattr_on(win
, (attr_t
) attr
, NULL
);
293 * Test and unset attributes.
296 wattroff(WINDOW
*win
, int attr
)
299 __CTRACE(__CTRACE_ATTR
, "wattroff: win %p, attr %08x\n", win
, attr
);
301 return wattr_off(win
, (attr_t
) attr
, NULL
);
306 * Set specific attribute modes.
310 wattrset(WINDOW
*win
, int attr
)
313 __CTRACE(__CTRACE_ATTR
, "wattrset: win %p, attr %08x\n", win
, attr
);
315 wattr_off(win
, __ATTRIBUTES
, NULL
);
316 wattr_on(win
, (attr_t
) attr
, NULL
);
322 * Set color pair on window
326 wcolor_set(WINDOW
*win
, short pair
, void *opt
)
329 __CTRACE(__CTRACE_COLOR
, "wolor_set: win %p, pair %d\n", win
, pair
);
331 __wcolor_set(win
, (attr_t
) COLOR_PAIR(pair
));
337 * Get window attributes.
340 getattrs(WINDOW
*win
)
343 __CTRACE(__CTRACE_ATTR
, "getattrs: win %p\n", win
);
345 return((chtype
) win
->wattr
);
350 * Get terminal attributes
358 __CTRACE(__CTRACE_ATTR
, "termattrs\n");
360 if (__tc_me
!= NULL
) {
374 if (__tc_so
!= NULL
&& __tc_se
!= NULL
)
376 if (__tc_us
!= NULL
&& __tc_ue
!= NULL
)
378 if (__tc_as
!= NULL
&& __tc_ae
!= NULL
)
386 * Get terminal wide attributes
394 __CTRACE(__CTRACE_ATTR
, "term_attrs\n");
396 if (__tc_me
!= NULL
) {
419 attr
|= WA_HORIZONTAL
;
422 #endif /* HAVE_WCHAR */
424 if (__tc_so
!= NULL
&& __tc_se
!= NULL
)
426 if (__tc_us
!= NULL
&& __tc_ue
!= NULL
)
427 attr
|= __UNDERSCORE
;
428 if (__tc_as
!= NULL
&& __tc_ae
!= NULL
)
429 attr
|= __ALTCHARSET
;
436 * Set color attribute on window
439 __wcolor_set(WINDOW
*win
, attr_t attr
)
441 /* If another color pair is set, turn that off first. */
442 win
->wattr
&= ~__COLOR
;
443 /* If can do color video, set the color pair bits. */
444 if (__tc_Co
!= 0 && attr
& __COLOR
)
445 win
->wattr
|= attr
& __COLOR
;