2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid[] = "@(#)wwscroll.c 8.1 (Berkeley) 6/6/93";
39 static char rcsid[] = "@(#)$FreeBSD$";
46 register struct ww *w;
58 else if (top + w->ww_b.nr < w->ww_w.b)
59 top = w->ww_w.b - w->ww_b.nr;
60 n = abs(top - w->ww_b.t);
63 (void) wwscroll1(w, w->ww_i.t, w->ww_i.b, dir, 0);
69 w->ww_buf -= top - w->ww_b.t;
71 w->ww_b.b = top + w->ww_b.nr;
77 * Scroll one line, between 'row1' and 'row2', in direction 'dir'.
78 * Don't adjust ww_scroll.
79 * And don't redraw 'leaveit' lines.
81 wwscroll1(w, row1, row2, dir, leaveit)
82 register struct ww *w;
93 * See how many lines on the screen are affected.
94 * And calculate row1x, row2x, and left at the same time.
96 for (i = row1; i < row2 && w->ww_nvis[i] == 0; i++)
98 if (i >= row2) /* can't do any fancy stuff */
101 for (i = row2 - 1; i >= row1 && w->ww_nvis[i] == 0; i--)
104 goto out; /* just one line is easy */
108 * See how much of this window is visible.
110 nvismax = wwncol * (row2x - row1x);
112 for (i = row1x; i < row2x; i++)
113 nvis += w->ww_nvis[i];
116 * If it's a good idea to scroll and the terminal can, then do it.
118 if (nvis < nvismax / 2)
119 goto no_scroll; /* not worth it */
120 if ((dir > 0 ? tt.tt_scroll_down == 0 : tt.tt_scroll_up == 0) ||
121 (tt.tt_scroll_top != row1x || tt.tt_scroll_bot != row2x - 1) &&
122 tt.tt_setscroll == 0)
123 if (tt.tt_delline == 0 || tt.tt_insline == 0)
125 xxscroll(dir, row1x, row2x);
128 * Fix up the old screen.
131 register union ww_char *tmp;
132 register union ww_char **cpp, **cqq;
138 for (i = row2x - row1x; --i > 0;)
145 for (i = row2x - row1x; --i > 0;)
149 for (i = wwncol; --i >= 0;)
155 * Fix the new screen.
157 if (nvis == nvismax) {
159 * Can shift whole lines.
163 register union ww_char *tmp;
164 register union ww_char **cpp, **cqq;
169 for (i = row2x - row1x; --i > 0;)
174 register char *p, *q;
176 p = &wwtouched[row1x];
178 for (i = row2x - row1x; --i > 0;)
184 p = &wwtouched[row1x];
185 for (i = row2x - row1x; --i >= 0;)
188 wwredrawwin1(w, row1, row1x, dir);
189 wwredrawwin1(w, row2x - 1, row2 - leaveit, dir);
192 register union ww_char *tmp;
193 register union ww_char **cpp, **cqq;
198 for (i = row2x - row1x; --i > 0;)
203 register char *p, *q;
205 p = &wwtouched[row2x];
207 for (i = row2x - row1x; --i > 0;)
213 p = &wwtouched[row1x];
214 for (i = row2x - row1x; --i >= 0;)
217 wwredrawwin1(w, row1 + leaveit, row1x + 1, dir);
218 wwredrawwin1(w, row2x, row2, dir);
224 p = &wwtouched[row1x];
225 for (i = row2x - row1x; --i >= 0;)
230 wwredrawwin1(w, row1, row2 - leaveit, dir);
232 wwredrawwin1(w, row1 + leaveit, row2, dir);