1 /* @(#)wwscroll.c 8.1 (Berkeley) 6/6/93 */
2 /* $NetBSD: wwscroll.c,v 1.7 2003/08/07 11:17:44 agc Exp $ */
5 * Copyright (c) 1983, 1993
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
9 * Edward Wang at The University of California, Berkeley.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 wwscroll(struct ww
*w
, int n
)
54 else if (top
+ w
->ww_b
.nr
< w
->ww_w
.b
)
55 top
= w
->ww_w
.b
- w
->ww_b
.nr
;
56 n
= abs(top
- w
->ww_b
.t
);
59 (void) wwscroll1(w
, w
->ww_i
.t
, w
->ww_i
.b
, dir
, 0);
65 w
->ww_buf
-= top
- w
->ww_b
.t
;
67 w
->ww_b
.b
= top
+ w
->ww_b
.nr
;
73 * Scroll one line, between 'row1' and 'row2', in direction 'dir'.
74 * Don't adjust ww_scroll.
75 * And don't redraw 'leaveit' lines.
78 wwscroll1(struct ww
*w
, int row1
, int row2
, int dir
, int leaveit
)
87 * See how many lines on the screen are affected.
88 * And calculate row1x, row2x, and left at the same time.
90 for (i
= row1
; i
< row2
&& w
->ww_nvis
[i
] == 0; i
++)
92 if (i
>= row2
) /* can't do any fancy stuff */
95 for (i
= row2
- 1; i
>= row1
&& w
->ww_nvis
[i
] == 0; i
--)
98 goto out
; /* just one line is easy */
102 * See how much of this window is visible.
104 nvismax
= wwncol
* (row2x
- row1x
);
106 for (i
= row1x
; i
< row2x
; i
++)
107 nvis
+= w
->ww_nvis
[i
];
110 * If it's a good idea to scroll and the terminal can, then do it.
112 if (nvis
< nvismax
/ 2)
113 goto no_scroll
; /* not worth it */
114 if ((dir
> 0 ? tt
.tt_scroll_down
== 0 : tt
.tt_scroll_up
== 0) ||
115 ((tt
.tt_scroll_top
!= row1x
|| tt
.tt_scroll_bot
!= row2x
- 1) &&
116 tt
.tt_setscroll
== 0))
117 if (tt
.tt_delline
== 0 || tt
.tt_insline
== 0)
119 xxscroll(dir
, row1x
, row2x
);
122 * Fix up the old screen.
126 union ww_char
**cpp
, **cqq
;
132 for (i
= row2x
- row1x
; --i
> 0;)
139 for (i
= row2x
- row1x
; --i
> 0;)
143 for (i
= wwncol
; --i
>= 0;)
149 * Fix the new screen.
151 if (nvis
== nvismax
) {
153 * Can shift whole lines.
158 union ww_char
**cpp
, **cqq
;
163 for (i
= row2x
- row1x
; --i
> 0;)
170 p
= &wwtouched
[row1x
];
172 for (i
= row2x
- row1x
; --i
> 0;)
178 p
= &wwtouched
[row1x
];
179 for (i
= row2x
- row1x
; --i
>= 0;)
182 wwredrawwin1(w
, row1
, row1x
, dir
);
183 wwredrawwin1(w
, row2x
- 1, row2
- leaveit
, dir
);
187 union ww_char
**cpp
, **cqq
;
192 for (i
= row2x
- row1x
; --i
> 0;)
199 p
= &wwtouched
[row2x
];
201 for (i
= row2x
- row1x
; --i
> 0;)
207 p
= &wwtouched
[row1x
];
208 for (i
= row2x
- row1x
; --i
>= 0;)
211 wwredrawwin1(w
, row1
+ leaveit
, row1x
+ 1, dir
);
212 wwredrawwin1(w
, row2x
, row2
, dir
);
218 p
= &wwtouched
[row1x
];
219 for (i
= row2x
- row1x
; --i
>= 0;)
224 wwredrawwin1(w
, row1
, row2
- leaveit
, dir
);
226 wwredrawwin1(w
, row1
+ leaveit
, row2
, dir
);