xref: /titanic_44/usr/src/lib/libcurses/screen/wnoutref.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate  * contributors.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #include	<string.h>
45*7c478bd9Sstevel@tonic-gate #include	<sys/types.h>
46*7c478bd9Sstevel@tonic-gate #include	"curses_inc.h"
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /* Like refresh but does not output */
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate int
wnoutrefresh(WINDOW * win)51*7c478bd9Sstevel@tonic-gate wnoutrefresh(WINDOW *win)
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate 	short	*bch, *ech, *sbch, *sech;
54*7c478bd9Sstevel@tonic-gate 	chtype	**wcp, **scp, *wc, *sc;
55*7c478bd9Sstevel@tonic-gate 	int	*hash;
56*7c478bd9Sstevel@tonic-gate 	short	y, x, xorg, yorg, scrli, scrco,
57*7c478bd9Sstevel@tonic-gate 		boty, sminy, smaxy, minx, maxx, lo, hi;
58*7c478bd9Sstevel@tonic-gate 	bool	doall;
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate 	if (win->_parent)
61*7c478bd9Sstevel@tonic-gate 		wsyncdown(win);
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 	doall = win->_clear;
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate 	sminy = SP->Yabove;
66*7c478bd9Sstevel@tonic-gate 	smaxy = sminy + LINES;
67*7c478bd9Sstevel@tonic-gate 	scrli = curscr->_maxy;
68*7c478bd9Sstevel@tonic-gate 	scrco = curscr->_maxx;
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 	yorg = win->_begy + win->_yoffset;
71*7c478bd9Sstevel@tonic-gate 	xorg = win->_begx;
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate 	/* save flags, cursor positions */
74*7c478bd9Sstevel@tonic-gate 	SP->virt_scr->_leave = win->_leave;
75*7c478bd9Sstevel@tonic-gate 	if ((!win->_leave && (win->_flags & (_WINCHANGED | _WINMOVED))) &&
76*7c478bd9Sstevel@tonic-gate 	    ((y = win->_cury + yorg) >= 0) && (y < scrli) &&
77*7c478bd9Sstevel@tonic-gate 	    ((x = win->_curx + xorg) >= 0) && (x < scrco)) {
78*7c478bd9Sstevel@tonic-gate 		_virtscr->_cury = y;
79*7c478bd9Sstevel@tonic-gate 		_virtscr->_curx = x;
80*7c478bd9Sstevel@tonic-gate 	}
81*7c478bd9Sstevel@tonic-gate 	if (!(win->_use_idc))
82*7c478bd9Sstevel@tonic-gate 		_virtscr->_use_idc = FALSE;
83*7c478bd9Sstevel@tonic-gate 	if (win->_use_idl)
84*7c478bd9Sstevel@tonic-gate 		_virtscr->_use_idl = TRUE;
85*7c478bd9Sstevel@tonic-gate 	if (win->_clear) {
86*7c478bd9Sstevel@tonic-gate 		_virtscr->_clear = TRUE;
87*7c478bd9Sstevel@tonic-gate 		win->_clear = FALSE;
88*7c478bd9Sstevel@tonic-gate 		win->_flags |= _WINCHANGED;
89*7c478bd9Sstevel@tonic-gate 	}
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate 	if (!(win->_flags & _WINCHANGED))
92*7c478bd9Sstevel@tonic-gate 		goto done;
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 	/* region to update */
95*7c478bd9Sstevel@tonic-gate 	boty = win->_maxy+yorg;
96*7c478bd9Sstevel@tonic-gate 	if (yorg >= sminy && yorg < smaxy && boty >= smaxy)
97*7c478bd9Sstevel@tonic-gate 		boty = smaxy;
98*7c478bd9Sstevel@tonic-gate 	else
99*7c478bd9Sstevel@tonic-gate 		if (boty > scrli)
100*7c478bd9Sstevel@tonic-gate 			boty = scrli;
101*7c478bd9Sstevel@tonic-gate 	boty -= yorg;
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate 	minx = 0;
104*7c478bd9Sstevel@tonic-gate 	if ((maxx = win->_maxx+xorg) > scrco)
105*7c478bd9Sstevel@tonic-gate 		maxx = scrco;
106*7c478bd9Sstevel@tonic-gate 	maxx -= xorg + 1;
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 	/* update structure */
109*7c478bd9Sstevel@tonic-gate 	bch = win->_firstch;
110*7c478bd9Sstevel@tonic-gate 	ech = win->_lastch;
111*7c478bd9Sstevel@tonic-gate 	wcp = win->_y;
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	hash = _VIRTHASH + yorg;
114*7c478bd9Sstevel@tonic-gate 	sbch = _virtscr->_firstch + yorg;
115*7c478bd9Sstevel@tonic-gate 	sech = _virtscr->_lastch + yorg;
116*7c478bd9Sstevel@tonic-gate 	scp  = _virtscr->_y + yorg;
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	/* first time around, set proper top/bottom changed lines */
119*7c478bd9Sstevel@tonic-gate 	if (curscr->_sync) {
120*7c478bd9Sstevel@tonic-gate 		_VIRTTOP = scrli;
121*7c478bd9Sstevel@tonic-gate 		_VIRTBOT = -1;
122*7c478bd9Sstevel@tonic-gate 	}
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate 	/* update each line */
125*7c478bd9Sstevel@tonic-gate 	for (y = 0; y < boty; ++y, ++hash, ++bch, ++ech, ++sbch,
126*7c478bd9Sstevel@tonic-gate 	    ++sech, ++wcp, ++scp) {
127*7c478bd9Sstevel@tonic-gate 		if (!doall && *bch == _INFINITY)
128*7c478bd9Sstevel@tonic-gate 			continue;
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 		lo = (doall || *bch == _REDRAW || *bch < minx) ? minx : *bch;
131*7c478bd9Sstevel@tonic-gate 		hi = (doall || *bch == _REDRAW || *ech > maxx) ? maxx : *ech;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 		wc = *wcp;
134*7c478bd9Sstevel@tonic-gate 		sc = *scp;
135*7c478bd9Sstevel@tonic-gate 		/* adjust lo and hi so they contain whole characters */
136*7c478bd9Sstevel@tonic-gate 		if (_scrmax > 1) {
137*7c478bd9Sstevel@tonic-gate 			if (ISCBIT(wc[lo])) {
138*7c478bd9Sstevel@tonic-gate 				for (x = lo - 1; x >= minx; --x)
139*7c478bd9Sstevel@tonic-gate 					if (!ISCBIT(wc[x]))
140*7c478bd9Sstevel@tonic-gate 						break;
141*7c478bd9Sstevel@tonic-gate 					if (x < minx) {
142*7c478bd9Sstevel@tonic-gate 						for (x = lo+1; x <= maxx; ++x)
143*7c478bd9Sstevel@tonic-gate 							if (!ISCBIT(wc[x]))
144*7c478bd9Sstevel@tonic-gate 								break;
145*7c478bd9Sstevel@tonic-gate 						if (x > maxx)
146*7c478bd9Sstevel@tonic-gate 							goto nextline;
147*7c478bd9Sstevel@tonic-gate 					}
148*7c478bd9Sstevel@tonic-gate 				lo = x;
149*7c478bd9Sstevel@tonic-gate 			}
150*7c478bd9Sstevel@tonic-gate 			if (ISMBIT(wc[hi])) {
151*7c478bd9Sstevel@tonic-gate 				int		w;
152*7c478bd9Sstevel@tonic-gate 				unsigned char	rb;
153*7c478bd9Sstevel@tonic-gate 				for (x = hi; x >= lo; --x)
154*7c478bd9Sstevel@tonic-gate 					if (!ISCBIT(wc[x]))
155*7c478bd9Sstevel@tonic-gate 						break;
156*7c478bd9Sstevel@tonic-gate 				/* LINTED */
157*7c478bd9Sstevel@tonic-gate 				rb = (unsigned char) RBYTE(wc[x]);
158*7c478bd9Sstevel@tonic-gate 				w = _curs_scrwidth[TYPE(rb)];
159*7c478bd9Sstevel@tonic-gate 				hi = (x+w) <= maxx+1 ? x+w-1 : x;
160*7c478bd9Sstevel@tonic-gate 			}
161*7c478bd9Sstevel@tonic-gate 		}
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate 		if (hi < lo)
164*7c478bd9Sstevel@tonic-gate 			continue;
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 		/* clear partial multi-chars about to be overwritten */
167*7c478bd9Sstevel@tonic-gate 		if (_scrmax > 1) {
168*7c478bd9Sstevel@tonic-gate 			if (ISMBIT(sc[lo + xorg]))
169*7c478bd9Sstevel@tonic-gate 				(void) _mbclrch(_virtscr, y + yorg, lo + xorg);
170*7c478bd9Sstevel@tonic-gate 			if (ISMBIT(sc[hi + xorg]))
171*7c478bd9Sstevel@tonic-gate 				(void) _mbclrch(_virtscr, y + yorg, hi + xorg);
172*7c478bd9Sstevel@tonic-gate 		}
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate 		/* update the change structure */
175*7c478bd9Sstevel@tonic-gate 		if (*bch == _REDRAW || *sbch == _REDRAW)
176*7c478bd9Sstevel@tonic-gate 			*sbch =  _REDRAW;
177*7c478bd9Sstevel@tonic-gate 		else {
178*7c478bd9Sstevel@tonic-gate 			if (*sbch > lo+xorg)
179*7c478bd9Sstevel@tonic-gate 				*sbch = lo+xorg;
180*7c478bd9Sstevel@tonic-gate 			if (*sech < hi+xorg)
181*7c478bd9Sstevel@tonic-gate 				*sech = hi+xorg;
182*7c478bd9Sstevel@tonic-gate 		}
183*7c478bd9Sstevel@tonic-gate 		if ((y + yorg) < _VIRTTOP)
184*7c478bd9Sstevel@tonic-gate 			_VIRTTOP = y+yorg;
185*7c478bd9Sstevel@tonic-gate 		if ((y + yorg) > _VIRTBOT)
186*7c478bd9Sstevel@tonic-gate 			_VIRTBOT = y + yorg;
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate 		/* update the image */
189*7c478bd9Sstevel@tonic-gate 		wc = *wcp + lo;
190*7c478bd9Sstevel@tonic-gate 		sc = *scp + lo + xorg;
191*7c478bd9Sstevel@tonic-gate 		(void) memcpy((char *) sc, (char *) wc, (size_t)
192*7c478bd9Sstevel@tonic-gate 		    (((hi - lo) + 1) * sizeof (chtype)));
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate 		/* the hash value of the line */
195*7c478bd9Sstevel@tonic-gate 		*hash = _NOHASH;
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate nextline:
198*7c478bd9Sstevel@tonic-gate 		*bch = _INFINITY;
199*7c478bd9Sstevel@tonic-gate 		*ech = -1;
200*7c478bd9Sstevel@tonic-gate 	}
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate done:
203*7c478bd9Sstevel@tonic-gate 	_virtscr->_flags |= _WINCHANGED;
204*7c478bd9Sstevel@tonic-gate 	win->_flags &= ~(_WINCHANGED | _WINMOVED | _WINSDEL);
205*7c478bd9Sstevel@tonic-gate 	return (OK);
206*7c478bd9Sstevel@tonic-gate }
207