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