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 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40 /*LINTLIBRARY*/
41
42 #include <string.h>
43 #include <sys/types.h>
44 #include "curses_inc.h"
45
46 /* Like refresh but does not output */
47
48 int
wnoutrefresh(WINDOW * win)49 wnoutrefresh(WINDOW *win)
50 {
51 short *bch, *ech, *sbch, *sech;
52 chtype **wcp, **scp, *wc, *sc;
53 int *hash;
54 short y, x, xorg, yorg, scrli, scrco, boty, sminy, smaxy, minx,
55 maxx, lo, hi;
56 bool doall;
57
58 if (win->_parent)
59 wsyncdown(win);
60
61 doall = win->_clear;
62
63 sminy = SP->Yabove;
64 smaxy = sminy + LINES;
65 scrli = curscr->_maxy;
66 scrco = curscr->_maxx;
67
68 yorg = win->_begy + win->_yoffset;
69 xorg = win->_begx;
70
71 /* save flags, cursor positions */
72 SP->virt_scr->_leave = win->_leave;
73 if ((!win->_leave && (win->_flags & (_WINCHANGED | _WINMOVED))) &&
74 ((y = win->_cury + yorg) >= 0) && (y < scrli) &&
75 ((x = win->_curx + xorg) >= 0) && (x < scrco)) {
76 _virtscr->_cury = y;
77 _virtscr->_curx = x;
78 }
79 if (!(win->_use_idc))
80 _virtscr->_use_idc = FALSE;
81 if (win->_use_idl)
82 _virtscr->_use_idl = TRUE;
83 if (win->_clear) {
84 _virtscr->_clear = TRUE;
85 win->_clear = FALSE;
86 win->_flags |= _WINCHANGED;
87 }
88
89 if (!(win->_flags & _WINCHANGED))
90 goto done;
91
92 /* region to update */
93 boty = win->_maxy+yorg;
94 if (yorg >= sminy && yorg < smaxy && boty >= smaxy)
95 boty = smaxy;
96 else
97 if (boty > scrli)
98 boty = scrli;
99 boty -= yorg;
100
101 minx = 0;
102 if ((maxx = win->_maxx+xorg) > scrco)
103 maxx = scrco;
104 maxx -= xorg + 1;
105
106 /* update structure */
107 bch = win->_firstch;
108 ech = win->_lastch;
109 wcp = win->_y;
110
111 hash = _VIRTHASH + yorg;
112 sbch = _virtscr->_firstch + yorg;
113 sech = _virtscr->_lastch + yorg;
114 scp = _virtscr->_y + yorg;
115
116 /* first time around, set proper top/bottom changed lines */
117 if (curscr->_sync) {
118 _VIRTTOP = scrli;
119 _VIRTBOT = -1;
120 }
121
122 /* update each line */
123 for (y = 0; y < boty; ++y, ++hash, ++bch, ++ech, ++sbch,
124 ++sech, ++wcp, ++scp) {
125 if (!doall && *bch == _INFINITY)
126 continue;
127
128 lo = (doall || *bch == _REDRAW || *bch < minx) ? minx : *bch;
129 hi = (doall || *bch == _REDRAW || *ech > maxx) ? maxx : *ech;
130
131 wc = *wcp;
132 sc = *scp;
133 /* adjust lo and hi so they contain whole characters */
134 if (_scrmax > 1) {
135 if (ISCBIT(wc[lo])) {
136 for (x = lo - 1; x >= minx; --x)
137 if (!ISCBIT(wc[x]))
138 break;
139 if (x < minx) {
140 for (x = lo + 1; x <= maxx; ++x)
141 if (!ISCBIT(wc[x]))
142 break;
143 if (x > maxx)
144 goto nextline;
145 }
146 lo = x;
147 }
148 if (ISMBIT(wc[hi])) {
149 int w;
150 unsigned char rb;
151 for (x = hi; x >= lo; --x)
152 if (!ISCBIT(wc[x]))
153 break;
154 /* LINTED */
155 rb = (unsigned char) RBYTE(wc[x]);
156 w = _curs_scrwidth[TYPE(rb)];
157 hi = (x+w) <= maxx+1 ? x+w-1 : x;
158 }
159 }
160
161 if (hi < lo)
162 continue;
163
164 /* clear partial multi-chars about to be overwritten */
165 if (_scrmax > 1) {
166 if (ISMBIT(sc[lo + xorg]))
167 (void) _mbclrch(_virtscr, y + yorg, lo + xorg);
168 if (ISMBIT(sc[hi + xorg]))
169 (void) _mbclrch(_virtscr, y + yorg, hi + xorg);
170 }
171
172 /* update the change structure */
173 if (*bch == _REDRAW || *sbch == _REDRAW)
174 *sbch = _REDRAW;
175 else {
176 if (*sbch > lo+xorg)
177 *sbch = lo+xorg;
178 if (*sech < hi+xorg)
179 *sech = hi+xorg;
180 }
181 if ((y + yorg) < _VIRTTOP)
182 _VIRTTOP = y+yorg;
183 if ((y + yorg) > _VIRTBOT)
184 _VIRTBOT = y + yorg;
185
186 /* update the image */
187 wc = *wcp + lo;
188 sc = *scp + lo + xorg;
189 (void) memcpy((char *)sc, (char *)wc, (size_t)
190 (((hi - lo) + 1) * sizeof (chtype)));
191
192 /* the hash value of the line */
193 *hash = _NOHASH;
194
195 nextline:
196 *bch = _INFINITY;
197 *ech = -1;
198 }
199
200 done:
201 _virtscr->_flags |= _WINCHANGED;
202 win->_flags &= ~(_WINCHANGED | _WINMOVED | _WINSDEL);
203 return (OK);
204 }
205