4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
44 #include <sys/types.h>
45 #include "curses_inc.h"
47 /* Change the background of a window. nbkgd : new background. */
50 wbkgd(WINDOW
*win
, chtype nbkgd
)
54 chtype
*wcp
, obkgda
, obkgdc
, nbkgda
,
58 /* if 'nbkgd' contains color information, but this is not a color */
59 /* terminal, erase that information. */
61 if ((nbkgd
& A_COLOR
) && (cur_term
->_pairs_tbl
== NULL
))
64 if (nbkgd
== win
->_bkgd
)
67 obkgdc
= _CHAR(win
->_bkgd
);
68 obkgda
= _ATTR(win
->_bkgd
);
70 nbkgdc
= _CHAR(nbkgd
);
71 nbkgda
= _ATTR(nbkgd
);
73 /* switch byte order if necessary */
75 nbkgdc
= _CHAR((RBYTE(nbkgdc
) << 8) | (LBYTE(nbkgdc
)|MBIT
)) |
78 if ((nbkgdc
< ' ' || nbkgdc
== _CTRL('?')) ||
79 _curs_scrwidth
[TYPE(c
)] > 1)
81 nbkgd
= (nbkgdc
& ~CBIT
) | nbkgda
;
85 /* delete the old background from the attribute field and replace */
86 /* it with the new background. Note: if the same attribute was */
87 /* first set by wbkgd() and then by wattron(), or vice versa, it */
88 /* will be deleted, so the effect of wattron() will be lost. */
89 /* This applies to both video and color attributes. */
91 if ((acolor
= (win
->_attrs
& A_COLOR
)) != 0) {
92 if (acolor
== (obkgda
& A_COLOR
)) {
93 win
->_attrs
= _ATTR((win
->_attrs
& ~obkgda
) | nbkgda
);
95 win
->_attrs
= _ATTR((win
->_attrs
&
96 (~obkgda
| A_COLOR
)) | (nbkgda
& ~A_COLOR
));
99 win
->_attrs
= _ATTR((win
->_attrs
& ~obkgda
) | nbkgda
);
101 maxx
= win
->_maxx
- 1;
102 begch
= win
->_firstch
;
103 endch
= win
->_lastch
;
104 for (y
= win
->_maxy
-1; y
>= 0; --y
, ++begch
, ++endch
) {
105 for (x
= maxx
, wcp
= win
->_y
[y
]; x
-- >= 0; ++wcp
) {
106 if ((c
= _CHAR(*wcp
)) == obkgdc
)
108 if ((acolor
= (*wcp
& A_COLOR
)) != 0) {
109 if (acolor
== (obkgda
& A_COLOR
))
110 *wcp
= c
| _ATTR((*wcp
& ~obkgda
) |
113 *wcp
= c
| _ATTR((*wcp
& (~obkgda
|
114 A_COLOR
)) | (nbkgda
& ~A_COLOR
));
116 *wcp
= c
| _ATTR((*wcp
& ~obkgda
) | nbkgda
);
122 win
->_flags
|= _WINCHANGED
;
126 return (win
->_immed
? wrefresh(win
) : OK
);