1 /* $NetBSD: background.c,v 1.15 2009/07/22 16:57:14 roy Exp $ */
4 * Copyright (c) 2000 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: background.c,v 1.15 2009/07/22 16:57:14 roy Exp $");
39 #include "curses_private.h"
43 * Set new background attributes on stdscr.
53 * Set new background and new background attributes on stdscr.
58 return(wbkgd(stdscr
, ch
));
63 * Set new background attributes.
66 wbkgdset(WINDOW
*win
, chtype ch
)
69 __CTRACE(__CTRACE_ATTR
, "wbkgdset: (%p), '%s', %08x\n",
70 win
, unctrl(ch
& +__CHARTEXT
), ch
& __ATTRIBUTES
);
73 /* Background character. */
75 win
->bch
= (wchar_t) ch
& __CHARTEXT
;
77 /* Background attributes (check colour). */
78 if (__using_color
&& !(ch
& __COLOR
))
79 ch
|= __default_color
;
80 win
->battr
= (attr_t
) ch
& __ATTRIBUTES
;
85 * Set new background and new background attributes.
88 wbkgd(WINDOW
*win
, chtype ch
)
93 __CTRACE(__CTRACE_ATTR
, "wbkgd: (%p), '%s', %08x\n",
94 win
, unctrl(ch
& +__CHARTEXT
), ch
& __ATTRIBUTES
);
97 /* Background attributes (check colour). */
98 if (__using_color
&& !(ch
& __COLOR
))
99 ch
|= __default_color
;
101 win
->battr
= (attr_t
) ch
& __ATTRIBUTES
;
103 for (y
= 0; y
< win
->maxy
; y
++)
104 for (x
= 0; x
< win
->maxx
; x
++) {
105 /* Copy character if space */
106 if (ch
& A_CHARTEXT
&& win
->alines
[y
]->line
[x
].ch
== ' ')
107 win
->alines
[y
]->line
[x
].ch
= ch
& __CHARTEXT
;
108 /* Merge attributes */
109 if (win
->alines
[y
]->line
[x
].attr
& __ALTCHARSET
)
110 win
->alines
[y
]->line
[x
].attr
=
111 (ch
& __ATTRIBUTES
) | __ALTCHARSET
;
113 win
->alines
[y
]->line
[x
].attr
=
116 SET_WCOL(win
->alines
[y
]->line
[x
], 1);
125 * Get current background attributes.
132 /* Background attributes (check colour). */
133 battr
= win
->battr
& A_ATTRIBUTES
;
134 if (__using_color
&& ((battr
& __COLOR
) == __default_color
))
135 battr
&= ~__default_color
;
137 return ((chtype
) ((win
->bch
& A_CHARTEXT
) | battr
));
140 int bkgrnd(const cchar_t
*wch
)
145 return wbkgrnd( stdscr
, wch
);
146 #endif /* HAVE_WCHAR */
149 void bkgrndset(const cchar_t
*wch
)
152 wbkgrndset( stdscr
, wch
);
153 #endif /* HAVE_WCHAR */
156 int getbkgrnd(cchar_t
*wch
)
161 return wgetbkgrnd( stdscr
, wch
);
162 #endif /* HAVE_WCHAR */
165 int wbkgrnd(WINDOW
*win
, const cchar_t
*wch
)
172 /* nschar_t *np, *tnp, *pnp; */
175 __CTRACE(__CTRACE_ATTR
, "wbkgrnd: (%p), '%s', %x\n",
176 win
, (const char *) wunctrl(wch
), wch
->attributes
);
179 /* ignore multi-column characters */
180 if ( !wch
->elements
|| wcwidth( wch
->vals
[ 0 ]) > 1 )
183 /* Background attributes (check colour). */
184 battr
= wch
->attributes
& WA_ATTRIBUTES
;
185 if (__using_color
&& !( battr
& __COLOR
))
186 battr
|= __default_color
;
189 wbkgrndset(win
, wch
);
192 #endif /* HAVE_WCHAR */
195 void wbkgrndset(WINDOW
*win
, const cchar_t
*wch
)
203 __CTRACE(__CTRACE_ATTR
, "wbkgrndset: (%p), '%s', %x\n",
204 win
, (const char *) wunctrl(wch
), wch
->attributes
);
207 /* ignore multi-column characters */
208 if ( !wch
->elements
|| wcwidth( wch
->vals
[ 0 ]) > 1 )
211 /* Background character. */
212 tnp
= np
= win
->bnsp
;
213 if ( wcwidth( wch
->vals
[ 0 ]))
214 win
->bch
= wch
->vals
[ 0 ];
217 np
= (nschar_t
*)malloc(sizeof(nschar_t
));
223 np
->ch
= wch
->vals
[ 0 ];
227 /* add non-spacing characters */
228 if ( wch
->elements
> 1 ) {
229 for ( i
= 1; i
< wch
->elements
; i
++ ) {
231 np
= (nschar_t
*)malloc(sizeof(nschar_t
));
240 np
->ch
= wch
->vals
[ i
];
245 /* clear the old non-spacing characters */
252 /* Background attributes (check colour). */
253 battr
= wch
->attributes
& WA_ATTRIBUTES
;
254 if (__using_color
&& !( battr
& __COLOR
))
255 battr
|= __default_color
;
257 SET_BGWCOL((*win
), 1);
258 #endif /* HAVE_WCHAR */
261 int wgetbkgrnd(WINDOW
*win
, cchar_t
*wch
)
268 /* Background attributes (check colour). */
269 wch
->attributes
= win
->battr
& WA_ATTRIBUTES
;
270 if (__using_color
&& (( wch
->attributes
& __COLOR
)
272 wch
->attributes
&= ~__default_color
;
273 wch
->vals
[ 0 ] = win
->bch
;
277 while ( np
&& wch
->elements
< CURSES_CCHAR_MAX
) {
278 wch
->vals
[ wch
->elements
++ ] = np
->ch
;
284 #endif /* HAVE_WCHAR */