1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1995, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 /*
28  * wbkgrnd.c
29  *
30  * XCurses Library
31  *
32  * Copyright 1990, 1995 by Mortice Kern Systems Inc.  All rights reserved.
33  *
34  */
35 
36 #ifdef M_RCSID
37 #ifndef lint
38 static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/wbkgrnd.c 1.4 1995/06/21 20:30:57 ant Exp $";
39 #endif
40 #endif
41 
42 #include <private.h>
43 #include <string.h>
44 
45 /*f
46  * Combine the new background setting with every position in the window.
47  * The background is any combination of attributes and a character.
48  * Only the attribute part is used to set the background of non-blank
49  * characters, while both character and attributes are used for blank
50  * positions.
51  */
52 int
wbkgrnd(w,bg)53 wbkgrnd(w, bg)
54 WINDOW *w;
55 const cchar_t *bg;
56 {
57 	short y, x;
58 	cchar_t old_bg, *cp;
59 
60 #ifdef M_CURSES_TRACE
61 	__m_trace("wbkgrnd(%p, %p)", w, bg);
62 #endif
63 
64 	old_bg = w->_bg;
65 	w->_bg = *bg;
66 
67 	for (y = 0; y < w->_maxy; ++y) {
68 		for (cp = w->_line[y], x = 0; x < w->_maxx; ++x) {
69 			old_bg._f = cp->_f;
70 			if (__m_cc_compare(cp, &w->_bg, 0)) {
71 				/* Replace entire background character. */
72 				*cp = *bg;
73 			} else {
74 				/* Disable old background attributes. */
75 				cp->_at &= ~old_bg._at;
76 
77 				/* Enable new background and current
78 				 * foreground.  The foreground is included
79 				 * in case there was overlap with the old
80 				 * background and the foreground.
81 				 */
82 				cp->_at |= bg->_at | w->_fg._at;
83 			}
84 		}
85 
86 		/* Mark line as touched. */
87 		w->_first[y] = 0;
88 		w->_last[y] = x;
89 	}
90 
91 	WSYNC(w);
92 
93 	return __m_return_code("wbkgrnd", WFLUSH(w));
94 }
95