1 /* $NetBSD: wwscroll.c,v 1.7 2003/08/07 11:17:44 agc Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid[] = "@(#)wwscroll.c 8.1 (Berkeley) 6/6/93";
40 __RCSID("$NetBSD: wwscroll.c,v 1.7 2003/08/07 11:17:44 agc Exp $");
51 wwscroll(struct ww *w, int n)
62 else if (top + w->ww_b.nr < w->ww_w.b)
63 top = w->ww_w.b - w->ww_b.nr;
64 n = abs(top - w->ww_b.t);
67 (void) wwscroll1(w, w->ww_i.t, w->ww_i.b, dir, 0);
73 w->ww_buf -= top - w->ww_b.t;
75 w->ww_b.b = top + w->ww_b.nr;
81 * Scroll one line, between 'row1' and 'row2', in direction 'dir'.
82 * Don't adjust ww_scroll.
83 * And don't redraw 'leaveit' lines.
86 wwscroll1(struct ww *w, int row1, int row2, int dir, int leaveit)
95 * See how many lines on the screen are affected.
96 * And calculate row1x, row2x, and left at the same time.
98 for (i = row1; i < row2 && w->ww_nvis[i] == 0; i++)
100 if (i >= row2) /* can't do any fancy stuff */
103 for (i = row2 - 1; i >= row1 && w->ww_nvis[i] == 0; i--)
106 goto out; /* just one line is easy */
110 * See how much of this window is visible.
112 nvismax = wwncol * (row2x - row1x);
114 for (i = row1x; i < row2x; i++)
115 nvis += w->ww_nvis[i];
118 * If it's a good idea to scroll and the terminal can, then do it.
120 if (nvis < nvismax / 2)
121 goto no_scroll; /* not worth it */
122 if ((dir > 0 ? tt.tt_scroll_down == 0 : tt.tt_scroll_up == 0) ||
123 ((tt.tt_scroll_top != row1x || tt.tt_scroll_bot != row2x - 1) &&
124 tt.tt_setscroll == 0))
125 if (tt.tt_delline == 0 || tt.tt_insline == 0)
127 xxscroll(dir, row1x, row2x);
130 * Fix up the old screen.
134 union ww_char **cpp, **cqq;
140 for (i = row2x - row1x; --i > 0;)
147 for (i = row2x - row1x; --i > 0;)
151 for (i = wwncol; --i >= 0;)
157 * Fix the new screen.
159 if (nvis == nvismax) {
161 * Can shift whole lines.
166 union ww_char **cpp, **cqq;
171 for (i = row2x - row1x; --i > 0;)
178 p = &wwtouched[row1x];
180 for (i = row2x - row1x; --i > 0;)
186 p = &wwtouched[row1x];
187 for (i = row2x - row1x; --i >= 0;)
190 wwredrawwin1(w, row1, row1x, dir);
191 wwredrawwin1(w, row2x - 1, row2 - leaveit, dir);
195 union ww_char **cpp, **cqq;
200 for (i = row2x - row1x; --i > 0;)
207 p = &wwtouched[row2x];
209 for (i = row2x - row1x; --i > 0;)
215 p = &wwtouched[row1x];
216 for (i = row2x - row1x; --i >= 0;)
219 wwredrawwin1(w, row1 + leaveit, row1x + 1, dir);
220 wwredrawwin1(w, row2x, row2, dir);
226 p = &wwtouched[row1x];
227 for (i = row2x - row1x; --i >= 0;)
232 wwredrawwin1(w, row1, row2 - leaveit, dir);
234 wwredrawwin1(w, row1 + leaveit, row2, dir);