17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate * The Regents of the University of California
337c478bd9Sstevel@tonic-gate * All Rights Reserved
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate * contributors.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate #include <string.h>
437c478bd9Sstevel@tonic-gate #include <sys/types.h>
447c478bd9Sstevel@tonic-gate #include "curses_inc.h"
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate /* Like refresh but does not output */
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate int
wnoutrefresh(WINDOW * win)497c478bd9Sstevel@tonic-gate wnoutrefresh(WINDOW *win)
507c478bd9Sstevel@tonic-gate {
517c478bd9Sstevel@tonic-gate short *bch, *ech, *sbch, *sech;
527c478bd9Sstevel@tonic-gate chtype **wcp, **scp, *wc, *sc;
537c478bd9Sstevel@tonic-gate int *hash;
54*e07d85f8SToomas Soome short y, x, xorg, yorg, scrli, scrco, boty, sminy, smaxy, minx,
55*e07d85f8SToomas Soome maxx, lo, hi;
567c478bd9Sstevel@tonic-gate bool doall;
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate if (win->_parent)
597c478bd9Sstevel@tonic-gate wsyncdown(win);
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate doall = win->_clear;
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate sminy = SP->Yabove;
647c478bd9Sstevel@tonic-gate smaxy = sminy + LINES;
657c478bd9Sstevel@tonic-gate scrli = curscr->_maxy;
667c478bd9Sstevel@tonic-gate scrco = curscr->_maxx;
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate yorg = win->_begy + win->_yoffset;
697c478bd9Sstevel@tonic-gate xorg = win->_begx;
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate /* save flags, cursor positions */
727c478bd9Sstevel@tonic-gate SP->virt_scr->_leave = win->_leave;
737c478bd9Sstevel@tonic-gate if ((!win->_leave && (win->_flags & (_WINCHANGED | _WINMOVED))) &&
747c478bd9Sstevel@tonic-gate ((y = win->_cury + yorg) >= 0) && (y < scrli) &&
757c478bd9Sstevel@tonic-gate ((x = win->_curx + xorg) >= 0) && (x < scrco)) {
767c478bd9Sstevel@tonic-gate _virtscr->_cury = y;
777c478bd9Sstevel@tonic-gate _virtscr->_curx = x;
787c478bd9Sstevel@tonic-gate }
797c478bd9Sstevel@tonic-gate if (!(win->_use_idc))
807c478bd9Sstevel@tonic-gate _virtscr->_use_idc = FALSE;
817c478bd9Sstevel@tonic-gate if (win->_use_idl)
827c478bd9Sstevel@tonic-gate _virtscr->_use_idl = TRUE;
837c478bd9Sstevel@tonic-gate if (win->_clear) {
847c478bd9Sstevel@tonic-gate _virtscr->_clear = TRUE;
857c478bd9Sstevel@tonic-gate win->_clear = FALSE;
867c478bd9Sstevel@tonic-gate win->_flags |= _WINCHANGED;
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate if (!(win->_flags & _WINCHANGED))
907c478bd9Sstevel@tonic-gate goto done;
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate /* region to update */
937c478bd9Sstevel@tonic-gate boty = win->_maxy+yorg;
947c478bd9Sstevel@tonic-gate if (yorg >= sminy && yorg < smaxy && boty >= smaxy)
957c478bd9Sstevel@tonic-gate boty = smaxy;
967c478bd9Sstevel@tonic-gate else
977c478bd9Sstevel@tonic-gate if (boty > scrli)
987c478bd9Sstevel@tonic-gate boty = scrli;
997c478bd9Sstevel@tonic-gate boty -= yorg;
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate minx = 0;
1027c478bd9Sstevel@tonic-gate if ((maxx = win->_maxx+xorg) > scrco)
1037c478bd9Sstevel@tonic-gate maxx = scrco;
1047c478bd9Sstevel@tonic-gate maxx -= xorg + 1;
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate /* update structure */
1077c478bd9Sstevel@tonic-gate bch = win->_firstch;
1087c478bd9Sstevel@tonic-gate ech = win->_lastch;
1097c478bd9Sstevel@tonic-gate wcp = win->_y;
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate hash = _VIRTHASH + yorg;
1127c478bd9Sstevel@tonic-gate sbch = _virtscr->_firstch + yorg;
1137c478bd9Sstevel@tonic-gate sech = _virtscr->_lastch + yorg;
1147c478bd9Sstevel@tonic-gate scp = _virtscr->_y + yorg;
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate /* first time around, set proper top/bottom changed lines */
1177c478bd9Sstevel@tonic-gate if (curscr->_sync) {
1187c478bd9Sstevel@tonic-gate _VIRTTOP = scrli;
1197c478bd9Sstevel@tonic-gate _VIRTBOT = -1;
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate /* update each line */
1237c478bd9Sstevel@tonic-gate for (y = 0; y < boty; ++y, ++hash, ++bch, ++ech, ++sbch,
1247c478bd9Sstevel@tonic-gate ++sech, ++wcp, ++scp) {
1257c478bd9Sstevel@tonic-gate if (!doall && *bch == _INFINITY)
1267c478bd9Sstevel@tonic-gate continue;
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate lo = (doall || *bch == _REDRAW || *bch < minx) ? minx : *bch;
1297c478bd9Sstevel@tonic-gate hi = (doall || *bch == _REDRAW || *ech > maxx) ? maxx : *ech;
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate wc = *wcp;
1327c478bd9Sstevel@tonic-gate sc = *scp;
1337c478bd9Sstevel@tonic-gate /* adjust lo and hi so they contain whole characters */
1347c478bd9Sstevel@tonic-gate if (_scrmax > 1) {
1357c478bd9Sstevel@tonic-gate if (ISCBIT(wc[lo])) {
1367c478bd9Sstevel@tonic-gate for (x = lo - 1; x >= minx; --x)
1377c478bd9Sstevel@tonic-gate if (!ISCBIT(wc[x]))
1387c478bd9Sstevel@tonic-gate break;
1397c478bd9Sstevel@tonic-gate if (x < minx) {
1407c478bd9Sstevel@tonic-gate for (x = lo + 1; x <= maxx; ++x)
1417c478bd9Sstevel@tonic-gate if (!ISCBIT(wc[x]))
1427c478bd9Sstevel@tonic-gate break;
1437c478bd9Sstevel@tonic-gate if (x > maxx)
1447c478bd9Sstevel@tonic-gate goto nextline;
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate lo = x;
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate if (ISMBIT(wc[hi])) {
1497c478bd9Sstevel@tonic-gate int w;
1507c478bd9Sstevel@tonic-gate unsigned char rb;
1517c478bd9Sstevel@tonic-gate for (x = hi; x >= lo; --x)
1527c478bd9Sstevel@tonic-gate if (!ISCBIT(wc[x]))
1537c478bd9Sstevel@tonic-gate break;
1547c478bd9Sstevel@tonic-gate /* LINTED */
1557c478bd9Sstevel@tonic-gate rb = (unsigned char) RBYTE(wc[x]);
1567c478bd9Sstevel@tonic-gate w = _curs_scrwidth[TYPE(rb)];
1577c478bd9Sstevel@tonic-gate hi = (x+w) <= maxx+1 ? x+w-1 : x;
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate if (hi < lo)
1627c478bd9Sstevel@tonic-gate continue;
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate /* clear partial multi-chars about to be overwritten */
1657c478bd9Sstevel@tonic-gate if (_scrmax > 1) {
1667c478bd9Sstevel@tonic-gate if (ISMBIT(sc[lo + xorg]))
1677c478bd9Sstevel@tonic-gate (void) _mbclrch(_virtscr, y + yorg, lo + xorg);
1687c478bd9Sstevel@tonic-gate if (ISMBIT(sc[hi + xorg]))
1697c478bd9Sstevel@tonic-gate (void) _mbclrch(_virtscr, y + yorg, hi + xorg);
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate /* update the change structure */
1737c478bd9Sstevel@tonic-gate if (*bch == _REDRAW || *sbch == _REDRAW)
1747c478bd9Sstevel@tonic-gate *sbch = _REDRAW;
1757c478bd9Sstevel@tonic-gate else {
1767c478bd9Sstevel@tonic-gate if (*sbch > lo+xorg)
1777c478bd9Sstevel@tonic-gate *sbch = lo+xorg;
1787c478bd9Sstevel@tonic-gate if (*sech < hi+xorg)
1797c478bd9Sstevel@tonic-gate *sech = hi+xorg;
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate if ((y + yorg) < _VIRTTOP)
1827c478bd9Sstevel@tonic-gate _VIRTTOP = y+yorg;
1837c478bd9Sstevel@tonic-gate if ((y + yorg) > _VIRTBOT)
1847c478bd9Sstevel@tonic-gate _VIRTBOT = y + yorg;
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate /* update the image */
1877c478bd9Sstevel@tonic-gate wc = *wcp + lo;
1887c478bd9Sstevel@tonic-gate sc = *scp + lo + xorg;
1897c478bd9Sstevel@tonic-gate (void) memcpy((char *)sc, (char *)wc, (size_t)
1907c478bd9Sstevel@tonic-gate (((hi - lo) + 1) * sizeof (chtype)));
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate /* the hash value of the line */
1937c478bd9Sstevel@tonic-gate *hash = _NOHASH;
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate nextline:
1967c478bd9Sstevel@tonic-gate *bch = _INFINITY;
1977c478bd9Sstevel@tonic-gate *ech = -1;
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate done:
2017c478bd9Sstevel@tonic-gate _virtscr->_flags |= _WINCHANGED;
2027c478bd9Sstevel@tonic-gate win->_flags &= ~(_WINCHANGED | _WINMOVED | _WINSDEL);
2037c478bd9Sstevel@tonic-gate return (OK);
2047c478bd9Sstevel@tonic-gate }
205