Annotation of src/usr.bin/window/wwscroll.c, Revision 1.1.1.1
1.1 deraadt 1: /* $NetBSD: wwscroll.c,v 1.3 1995/09/28 10:35:53 tls Exp $ */
2:
3: /*
4: * Copyright (c) 1983, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * This code is derived from software contributed to Berkeley by
8: * Edward Wang at The University of California, Berkeley.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by the University of
21: * California, Berkeley and its contributors.
22: * 4. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: */
38:
39: #ifndef lint
40: #if 0
41: static char sccsid[] = "@(#)wwscroll.c 8.1 (Berkeley) 6/6/93";
42: #else
43: static char rcsid[] = "$NetBSD: wwscroll.c,v 1.3 1995/09/28 10:35:53 tls Exp $";
44: #endif
45: #endif /* not lint */
46:
47: #include "ww.h"
48: #include "tt.h"
49:
50: wwscroll(w, n)
51: register struct ww *w;
52: int n;
53: {
54: register dir;
55: register top;
56:
57: if (n == 0)
58: return;
59: dir = n < 0 ? -1 : 1;
60: top = w->ww_b.t - n;
61: if (top > w->ww_w.t)
62: top = w->ww_w.t;
63: else if (top + w->ww_b.nr < w->ww_w.b)
64: top = w->ww_w.b - w->ww_b.nr;
65: n = abs(top - w->ww_b.t);
66: if (n < w->ww_i.nr) {
67: while (--n >= 0) {
68: (void) wwscroll1(w, w->ww_i.t, w->ww_i.b, dir, 0);
69: w->ww_buf += dir;
70: w->ww_b.t -= dir;
71: w->ww_b.b -= dir;
72: }
73: } else {
74: w->ww_buf -= top - w->ww_b.t;
75: w->ww_b.t = top;
76: w->ww_b.b = top + w->ww_b.nr;
77: wwredrawwin(w);
78: }
79: }
80:
81: /*
82: * Scroll one line, between 'row1' and 'row2', in direction 'dir'.
83: * Don't adjust ww_scroll.
84: * And don't redraw 'leaveit' lines.
85: */
86: wwscroll1(w, row1, row2, dir, leaveit)
87: register struct ww *w;
88: int row1, row2, dir;
89: int leaveit;
90: {
91: register i;
92: int row1x, row2x;
93: int nvis;
94: int nvismax;
95: int scrolled = 0;
96:
97: /*
98: * See how many lines on the screen are affected.
99: * And calculate row1x, row2x, and left at the same time.
100: */
101: for (i = row1; i < row2 && w->ww_nvis[i] == 0; i++)
102: ;
103: if (i >= row2) /* can't do any fancy stuff */
104: goto out;
105: row1x = i;
106: for (i = row2 - 1; i >= row1 && w->ww_nvis[i] == 0; i--)
107: ;
108: if (i <= row1x)
109: goto out; /* just one line is easy */
110: row2x = i + 1;
111:
112: /*
113: * See how much of this window is visible.
114: */
115: nvismax = wwncol * (row2x - row1x);
116: nvis = 0;
117: for (i = row1x; i < row2x; i++)
118: nvis += w->ww_nvis[i];
119:
120: /*
121: * If it's a good idea to scroll and the terminal can, then do it.
122: */
123: if (nvis < nvismax / 2)
124: goto no_scroll; /* not worth it */
125: if ((dir > 0 ? tt.tt_scroll_down == 0 : tt.tt_scroll_up == 0) ||
126: (tt.tt_scroll_top != row1x || tt.tt_scroll_bot != row2x - 1) &&
127: tt.tt_setscroll == 0)
128: if (tt.tt_delline == 0 || tt.tt_insline == 0)
129: goto no_scroll;
130: xxscroll(dir, row1x, row2x);
131: scrolled = 1;
132: /*
133: * Fix up the old screen.
134: */
135: {
136: register union ww_char *tmp;
137: register union ww_char **cpp, **cqq;
138:
139: if (dir > 0) {
140: cpp = &wwos[row1x];
141: cqq = cpp + 1;
142: tmp = *cpp;
143: for (i = row2x - row1x; --i > 0;)
144: *cpp++ = *cqq++;
145: *cpp = tmp;
146: } else {
147: cpp = &wwos[row2x];
148: cqq = cpp - 1;
149: tmp = *cqq;
150: for (i = row2x - row1x; --i > 0;)
151: *--cpp = *--cqq;
152: *cqq = tmp;
153: }
154: for (i = wwncol; --i >= 0;)
155: tmp++->c_w = ' ';
156: }
157:
158: no_scroll:
159: /*
160: * Fix the new screen.
161: */
162: if (nvis == nvismax) {
163: /*
164: * Can shift whole lines.
165: */
166: if (dir > 0) {
167: {
168: register union ww_char *tmp;
169: register union ww_char **cpp, **cqq;
170:
171: cpp = &wwns[row1x];
172: cqq = cpp + 1;
173: tmp = *cpp;
174: for (i = row2x - row1x; --i > 0;)
175: *cpp++ = *cqq++;
176: *cpp = tmp;
177: }
178: if (scrolled) {
179: register char *p, *q;
180:
181: p = &wwtouched[row1x];
182: q = p + 1;
183: for (i = row2x - row1x; --i > 0;)
184: *p++ = *q++;
185: *p |= WWU_TOUCHED;
186: } else {
187: register char *p;
188:
189: p = &wwtouched[row1x];
190: for (i = row2x - row1x; --i >= 0;)
191: *p++ |= WWU_TOUCHED;
192: }
193: wwredrawwin1(w, row1, row1x, dir);
194: wwredrawwin1(w, row2x - 1, row2 - leaveit, dir);
195: } else {
196: {
197: register union ww_char *tmp;
198: register union ww_char **cpp, **cqq;
199:
200: cpp = &wwns[row2x];
201: cqq = cpp - 1;
202: tmp = *cqq;
203: for (i = row2x - row1x; --i > 0;)
204: *--cpp = *--cqq;
205: *cqq = tmp;
206: }
207: if (scrolled) {
208: register char *p, *q;
209:
210: p = &wwtouched[row2x];
211: q = p - 1;
212: for (i = row2x - row1x; --i > 0;)
213: *--p = *--q;
214: *q |= WWU_TOUCHED;
215: } else {
216: register char *p;
217:
218: p = &wwtouched[row1x];
219: for (i = row2x - row1x; --i >= 0;)
220: *p++ |= WWU_TOUCHED;
221: }
222: wwredrawwin1(w, row1 + leaveit, row1x + 1, dir);
223: wwredrawwin1(w, row2x, row2, dir);
224: }
225: } else {
226: if (scrolled) {
227: register char *p;
228:
229: p = &wwtouched[row1x];
230: for (i = row2x - row1x; --i >= 0;)
231: *p++ |= WWU_TOUCHED;
232: }
233: out:
234: if (dir > 0)
235: wwredrawwin1(w, row1, row2 - leaveit, dir);
236: else
237: wwredrawwin1(w, row1 + leaveit, row2, dir);
238: }
239: return scrolled;
240: }