Mercurial > emacs
annotate src/scroll.c @ 15892:6a4227841dec
(kill-region): inhibit-read-only overrides text props too.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 21 Aug 1996 16:20:39 +0000 |
parents | ee40177f6c68 |
children | fa9ff387d260 |
rev | line source |
---|---|
154 | 1 /* Calculate what line insertion or deletion to do, and do it, |
7307 | 2 Copyright (C) 1985, 1986, 1990, 1993, 1994 Free Software Foundation, Inc. |
154 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
732 | 8 the Free Software Foundation; either version 2, or (at your option) |
154 | 9 any later version. |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13415
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13415
diff
changeset
|
19 Boston, MA 02111-1307, USA. */ |
154 | 20 |
21 | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
3356
diff
changeset
|
22 #include <config.h> |
154 | 23 #include "termchar.h" |
24 #include "lisp.h" | |
25 #include "dispextern.h" | |
766 | 26 #include "frame.h" |
154 | 27 |
28 extern struct display_line **ophys_lines; | |
29 | |
30 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
31 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
32 | |
33 /* All costs measured in characters. | |
766 | 34 So no cost can exceed the area of a frame, measured in characters. |
6773
ed16e189b9a5
(struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents:
6647
diff
changeset
|
35 Let's hope this is never more than 1000000 characters. */ |
154 | 36 |
6773
ed16e189b9a5
(struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents:
6647
diff
changeset
|
37 #define INFINITY 1000000 |
154 | 38 |
39 struct matrix_elt | |
40 { | |
41 /* Cost of outputting through this line | |
42 if no insert/delete is done just above it. */ | |
6773
ed16e189b9a5
(struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents:
6647
diff
changeset
|
43 int writecost; |
154 | 44 /* Cost of outputting through this line |
45 if an insert is done just above it. */ | |
6773
ed16e189b9a5
(struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents:
6647
diff
changeset
|
46 int insertcost; |
154 | 47 /* Cost of outputting through this line |
48 if a delete is done just above it. */ | |
6773
ed16e189b9a5
(struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents:
6647
diff
changeset
|
49 int deletecost; |
154 | 50 /* Number of inserts so far in this run of inserts, |
51 for the cost in insertcost. */ | |
6773
ed16e189b9a5
(struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents:
6647
diff
changeset
|
52 unsigned char insertcount; |
154 | 53 /* Number of deletes so far in this run of deletes, |
54 for the cost in deletecost. */ | |
6773
ed16e189b9a5
(struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents:
6647
diff
changeset
|
55 unsigned char deletecount; |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
56 /* Number of writes so far since the last insert |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
57 or delete for the cost in writecost. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
58 unsigned char writecount; |
154 | 59 }; |
60 | |
61 | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
62 /* Determine, in matrix[i,j], the cost of updating the first j old |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
63 lines into the first i new lines using the general scrolling method. |
154 | 64 This involves using insert or delete somewhere if i != j. |
65 For each matrix elements, three kinds of costs are recorded: | |
66 the smallest cost that ends with an insert, the smallest | |
67 cost that ends with a delete, and the smallest cost that | |
68 ends with neither one. These are kept separate because | |
69 on some terminals the cost of doing an insert varies | |
70 depending on whether one was just done, etc. */ | |
71 | |
72 /* draw_cost[VPOS] is the cost of outputting new line at VPOS. | |
73 old_hash[VPOS] is the hash code of the old line at VPOS. | |
74 new_hash[VPOS] is the hash code of the new line at VPOS. | |
766 | 75 Note that these are not true frame vpos's, but relative |
154 | 76 to the place at which the first mismatch between old and |
77 new contents appears. */ | |
78 | |
79 static void | |
766 | 80 calculate_scrolling (frame, matrix, window_size, lines_below, |
154 | 81 draw_cost, old_hash, new_hash, |
82 free_at_end) | |
766 | 83 FRAME_PTR frame; |
154 | 84 /* matrix is of size window_size + 1 on each side. */ |
85 struct matrix_elt *matrix; | |
86 int window_size; | |
87 int *draw_cost; | |
88 int *old_hash; | |
89 int *new_hash; | |
90 int free_at_end; | |
91 { | |
92 register int i, j; | |
766 | 93 int frame_height = FRAME_HEIGHT (frame); |
154 | 94 register struct matrix_elt *p, *p1; |
95 register int cost, cost1; | |
96 | |
97 int lines_moved = window_size + (scroll_region_ok ? 0 : lines_below); | |
98 /* first_insert_cost[I] is the cost of doing the first insert-line | |
99 at the I'th line of the lines we are considering, | |
100 where I is origin 1 (as it is below). */ | |
101 int *first_insert_cost | |
766 | 102 = &FRAME_INSERT_COST (frame)[frame_height - 1 - lines_moved]; |
154 | 103 int *first_delete_cost |
766 | 104 = &FRAME_DELETE_COST (frame)[frame_height - 1 - lines_moved]; |
154 | 105 int *next_insert_cost |
766 | 106 = &FRAME_INSERTN_COST (frame)[frame_height - 1 - lines_moved]; |
154 | 107 int *next_delete_cost |
766 | 108 = &FRAME_DELETEN_COST (frame)[frame_height - 1 - lines_moved]; |
154 | 109 |
110 /* Discourage long scrolls on fast lines. | |
766 | 111 Don't scroll nearly a full frame height unless it saves |
154 | 112 at least 1/4 second. */ |
766 | 113 int extra_cost = baud_rate / (10 * 4 * FRAME_HEIGHT (frame)); |
154 | 114 |
3356
09759a9653c5
(calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
115 if (baud_rate <= 0) |
09759a9653c5
(calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
116 extra_cost = 1; |
09759a9653c5
(calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
117 |
154 | 118 /* initialize the top left corner of the matrix */ |
119 matrix->writecost = 0; | |
120 matrix->insertcost = INFINITY; | |
121 matrix->deletecost = INFINITY; | |
122 matrix->insertcount = 0; | |
123 matrix->deletecount = 0; | |
124 | |
125 /* initialize the left edge of the matrix */ | |
126 cost = first_insert_cost[1] - next_insert_cost[1]; | |
127 for (i = 1; i <= window_size; i++) | |
128 { | |
129 p = matrix + i * (window_size + 1); | |
130 cost += draw_cost[i] + next_insert_cost[i] + extra_cost; | |
131 p->insertcost = cost; | |
132 p->writecost = INFINITY; | |
133 p->deletecost = INFINITY; | |
134 p->insertcount = i; | |
135 p->deletecount = 0; | |
136 } | |
137 | |
138 /* initialize the top edge of the matrix */ | |
139 cost = first_delete_cost[1] - next_delete_cost[1]; | |
140 for (j = 1; j <= window_size; j++) | |
141 { | |
142 cost += next_delete_cost[j]; | |
143 matrix[j].deletecost = cost; | |
144 matrix[j].writecost = INFINITY; | |
145 matrix[j].insertcost = INFINITY; | |
146 matrix[j].deletecount = j; | |
147 matrix[j].insertcount = 0; | |
148 } | |
149 | |
766 | 150 /* `i' represents the vpos among new frame contents. |
151 `j' represents the vpos among the old frame contents. */ | |
154 | 152 p = matrix + window_size + 2; /* matrix [1, 1] */ |
153 for (i = 1; i <= window_size; i++, p++) | |
154 for (j = 1; j <= window_size; j++, p++) | |
155 { | |
156 /* p contains the address of matrix [i, j] */ | |
157 | |
158 /* First calculate the cost assuming we do | |
159 not insert or delete above this line. | |
160 That is, if we update through line i-1 | |
161 based on old lines through j-1, | |
162 and then just change old line j to new line i. */ | |
163 p1 = p - window_size - 2; /* matrix [i-1, j-1] */ | |
164 cost = p1->writecost; | |
165 if (cost > p1->insertcost) | |
166 cost = p1->insertcost; | |
167 if (cost > p1->deletecost) | |
168 cost = p1->deletecost; | |
169 if (old_hash[j] != new_hash[i]) | |
170 cost += draw_cost[i]; | |
171 p->writecost = cost; | |
172 | |
173 /* Calculate the cost if we do an insert-line | |
174 before outputting this line. | |
175 That is, we update through line i-1 | |
176 based on old lines through j, | |
177 do an insert-line on line i, | |
178 and then output line i from scratch, | |
179 leaving old lines starting from j for reuse below. */ | |
180 p1 = p - window_size - 1; /* matrix [i-1, j] */ | |
181 /* No need to think about doing a delete followed | |
182 immediately by an insert. It cannot be as good | |
183 as not doing either of them. */ | |
184 if (free_at_end == i) | |
185 { | |
186 cost = p1->writecost; | |
187 cost1 = p1->insertcost; | |
188 } | |
189 else | |
190 { | |
191 cost = p1->writecost + first_insert_cost[i]; | |
6888
a39caeb88721
(calculate_scrolling): Add explicit casts, to avoid compiler warnings.
Karl Heuer <kwzh@gnu.org>
parents:
6773
diff
changeset
|
192 if ((int) p1->insertcount > i) |
154 | 193 abort (); |
194 cost1 = p1->insertcost + next_insert_cost[i - p1->insertcount]; | |
195 } | |
196 p->insertcost = min (cost, cost1) + draw_cost[i] + extra_cost; | |
197 p->insertcount = (cost < cost1) ? 1 : p1->insertcount + 1; | |
6888
a39caeb88721
(calculate_scrolling): Add explicit casts, to avoid compiler warnings.
Karl Heuer <kwzh@gnu.org>
parents:
6773
diff
changeset
|
198 if ((int) p->insertcount > i) |
154 | 199 abort (); |
200 | |
201 /* Calculate the cost if we do a delete line after | |
202 outputting this line. | |
203 That is, we update through line i | |
204 based on old lines through j-1, | |
205 and throw away old line j. */ | |
206 p1 = p - 1; /* matrix [i, j-1] */ | |
207 /* No need to think about doing an insert followed | |
208 immediately by a delete. */ | |
209 if (free_at_end == i) | |
210 { | |
211 cost = p1->writecost; | |
212 cost1 = p1->deletecost; | |
213 } | |
214 else | |
215 { | |
216 cost = p1->writecost + first_delete_cost[i]; | |
217 cost1 = p1->deletecost + next_delete_cost[i]; | |
218 } | |
219 p->deletecost = min (cost, cost1); | |
220 p->deletecount = (cost < cost1) ? 1 : p1->deletecount + 1; | |
221 } | |
222 } | |
223 | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
224 /* Perform insert-lines and delete-lines operations on FRAME according |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
225 to the costs in MATRIX, using the general scrolling method. |
6647
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
226 Update the frame's current_glyphs info to record what was done. |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
227 |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
228 WINDOW_SIZE is the number of lines being considered for scrolling |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
229 and UNCHANGED_AT_TOP is the vpos of the first line being considered. |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
230 These two arguments can specify any contiguous range of lines. |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
231 |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
232 We also shuffle the charstarts vectors for the lines |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
233 along with the glyphs; but the results are not quite right, |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
234 since we cannot offset them for changes in amount of text |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
235 in this line or that line. Luckily it doesn't matter, |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
236 since update_frame and update_line will copy in the proper |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
237 new charstarts vectors from the frame's desired_glyphs. */ |
154 | 238 |
239 static void | |
766 | 240 do_scrolling (frame, matrix, window_size, unchanged_at_top) |
241 FRAME_PTR frame; | |
154 | 242 struct matrix_elt *matrix; |
243 int window_size; | |
244 int unchanged_at_top; | |
245 { | |
246 register struct matrix_elt *p; | |
247 register int i, j; | |
766 | 248 register struct frame_glyphs *current_frame; |
249 /* temp_frame->enable[i] means line i has been moved to current_frame. */ | |
250 register struct frame_glyphs *temp_frame; | |
154 | 251 struct queue { int count, pos; } *queue; |
252 int offset = unchanged_at_top; | |
253 int qi = 0; | |
254 int window = 0; | |
255 register int tem; | |
256 int next; | |
257 | |
766 | 258 queue = (struct queue *) alloca (FRAME_HEIGHT (frame) |
154 | 259 * sizeof (struct queue)); |
260 | |
766 | 261 current_frame = FRAME_CURRENT_GLYPHS (frame); |
262 temp_frame = FRAME_TEMP_GLYPHS (frame); | |
154 | 263 |
766 | 264 bcopy (current_frame->glyphs, temp_frame->glyphs, |
265 current_frame->height * sizeof (GLYPH *)); | |
6647
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
266 bcopy (current_frame->charstarts, temp_frame->charstarts, |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
267 current_frame->height * sizeof (GLYPH *)); |
766 | 268 bcopy (current_frame->used, temp_frame->used, |
269 current_frame->height * sizeof (int)); | |
270 bcopy (current_frame->highlight, temp_frame->highlight, | |
271 current_frame->height * sizeof (char)); | |
272 bzero (temp_frame->enable, temp_frame->height * sizeof (char)); | |
273 bcopy (current_frame->bufp, temp_frame->bufp, | |
274 current_frame->height * sizeof (int)); | |
154 | 275 |
13415
5c4c0319a6e7
[HAVE_NTGUI] (do_scrolling, do_direct_scrolling): Update frame geometry.
Geoff Voelker <voelker@cs.washington.edu>
parents:
10262
diff
changeset
|
276 #ifdef HAVE_WINDOW_SYSTEM |
5c4c0319a6e7
[HAVE_NTGUI] (do_scrolling, do_direct_scrolling): Update frame geometry.
Geoff Voelker <voelker@cs.washington.edu>
parents:
10262
diff
changeset
|
277 if (FRAME_WINDOW_P (frame)) |
154 | 278 { |
766 | 279 bcopy (current_frame->top_left_x, temp_frame->top_left_x, |
280 current_frame->height * sizeof (short)); | |
281 bcopy (current_frame->top_left_y, temp_frame->top_left_y, | |
282 current_frame->height * sizeof (short)); | |
283 bcopy (current_frame->pix_width, temp_frame->pix_width, | |
284 current_frame->height * sizeof (short)); | |
285 bcopy (current_frame->pix_height, temp_frame->pix_height, | |
286 current_frame->height * sizeof (short)); | |
1410
9b29df8c7cb3
* scroll.c (do_scrolling): Don't bcopy non-existant `nruns' or
Joseph Arceneaux <jla@gnu.org>
parents:
968
diff
changeset
|
287 bcopy (current_frame->max_ascent, temp_frame->max_ascent, |
1714
2a1dbc7de507
* scroll.c (do_scrolling): When bcopying the max_ascent field from
Jim Blandy <jimb@redhat.com>
parents:
1410
diff
changeset
|
288 current_frame->height * sizeof (short)); |
154 | 289 } |
290 #endif | |
291 | |
292 i = j = window_size; | |
293 | |
294 while (i > 0 || j > 0) | |
295 { | |
296 p = matrix + i * (window_size + 1) + j; | |
297 tem = p->insertcost; | |
298 if (tem < p->writecost && tem < p->deletecost) | |
299 { | |
300 /* Insert should be done at vpos i-1, plus maybe some before */ | |
301 queue[qi].count = p->insertcount; | |
302 i -= p->insertcount; | |
303 queue[qi++].pos = i + unchanged_at_top; | |
304 } | |
305 else if (p->deletecost < p->writecost) | |
306 { | |
307 /* Old line at vpos j-1, and maybe some before it, | |
308 should be deleted */ | |
309 j -= p->deletecount; | |
310 if (!window) | |
311 { | |
312 set_terminal_window (window_size + unchanged_at_top); | |
313 window = 1; | |
314 } | |
315 ins_del_lines (j + unchanged_at_top, - p->deletecount); | |
316 } | |
317 else | |
318 { | |
319 /* Best thing done here is no insert or delete */ | |
320 /* Old line at vpos j-1 ends up at vpos i-1 */ | |
766 | 321 current_frame->glyphs[i + offset - 1] |
322 = temp_frame->glyphs[j + offset - 1]; | |
6647
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
323 current_frame->charstarts[i + offset - 1] |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
324 = temp_frame->charstarts[j + offset - 1]; |
766 | 325 current_frame->used[i + offset - 1] |
326 = temp_frame->used[j + offset - 1]; | |
327 current_frame->highlight[i + offset - 1] | |
328 = temp_frame->highlight[j + offset - 1]; | |
154 | 329 |
766 | 330 temp_frame->enable[j + offset - 1] = 1; |
154 | 331 i--; |
332 j--; | |
333 } | |
334 } | |
335 | |
336 if (!window && qi) | |
337 { | |
338 set_terminal_window (window_size + unchanged_at_top); | |
339 window = 1; | |
340 } | |
341 | |
342 /* Now do all insertions */ | |
343 | |
344 next = unchanged_at_top; | |
345 for (i = qi - 1; i >= 0; i--) | |
346 { | |
347 ins_del_lines (queue[i].pos, queue[i].count); | |
348 | |
349 /* Mark the inserted lines as clear, | |
350 and put into them the line-contents strings | |
351 that were discarded during the deletions. | |
766 | 352 Those are the ones for which temp_frame->enable was not set. */ |
154 | 353 tem = queue[i].pos; |
320 | 354 for (j = tem + queue[i].count - 1; j >= tem; j--) |
154 | 355 { |
766 | 356 current_frame->enable[j] = 0; |
357 while (temp_frame->enable[next]) | |
154 | 358 next++; |
6647
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
359 current_frame->glyphs[j] = temp_frame->glyphs[next]; |
e6611521fb67
(do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
360 current_frame->charstarts[j] = temp_frame->charstarts[next++]; |
154 | 361 } |
362 } | |
363 | |
364 if (window) | |
365 set_terminal_window (0); | |
366 } | |
367 | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
368 /* Determine, in matrix[i,j], the cost of updating the first j |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
369 old lines into the first i new lines using the direct |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
370 scrolling method. When the old line and the new line have |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
371 different hash codes, the calculated cost of updating old |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
372 line j into new line i includes the cost of outputting new |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
373 line i, and if i != j, the cost of outputting the old line j |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
374 is also included, as a penalty for moving the line and then |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
375 erasing it. In addition, the cost of updating a sequence of |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
376 lines with constant i - j includes the cost of scrolling the |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
377 old lines into their new positions, unless i == j. Scrolling |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
378 is achieved by setting the screen window to avoid affecting |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
379 other lines below, and inserting or deleting lines at the top |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
380 of the scrolled region. The cost of scrolling a sequence of |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
381 lines includes the fixed cost of specifying a scroll region, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
382 plus a variable cost which can depend upon the number of lines |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
383 involved and the distance by which they are scrolled, and an |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
384 extra cost to discourage long scrolls. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
385 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
386 As reflected in the matrix, an insert or delete does not |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
387 correspond directly to the insertion or deletion which is |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
388 used in scrolling lines. An insert means that the value of i |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
389 has increased without a corresponding increase in the value |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
390 of j. A delete means that the value of j has increased |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
391 without a corresponding increase in the value of i. A write |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
392 means that i and j are both increased by the same amount, and |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
393 that the old lines will be moved to their new positions. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
394 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
395 An insert following a delete is allowed only if i > j. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
396 A delete following an insert is allowed only if i < j. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
397 These restrictions ensure that the new lines in an insert |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
398 will always be blank as an effect of the neighboring writes. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
399 Thus the calculated cost of an insert is simply the cost of |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
400 outputting the new line contents. The direct cost of a |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
401 delete is zero. Inserts and deletes indirectly affect the |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
402 total cost through their influence on subsequent writes. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
403 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
404 /* The vectors draw_cost, old_hash, and new_hash have the same |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
405 meanings here as in calculate_scrolling, and old_draw_cost |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
406 is the equivalent of draw_cost for the old line contents */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
407 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
408 static void |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
409 calculate_direct_scrolling (frame, matrix, window_size, lines_below, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
410 draw_cost, old_draw_cost, old_hash, new_hash, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
411 free_at_end) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
412 FRAME_PTR frame; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
413 /* matrix is of size window_size + 1 on each side. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
414 struct matrix_elt *matrix; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
415 int window_size; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
416 int *draw_cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
417 int *old_draw_cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
418 int *old_hash; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
419 int *new_hash; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
420 int free_at_end; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
421 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
422 register int i, j; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
423 int frame_height = FRAME_HEIGHT (frame); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
424 register struct matrix_elt *p, *p1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
425 register int cost, cost1, delta; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
426 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
427 /* first_insert_cost[-I] is the cost of doing the first insert-line |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
428 at a position I lines above the bottom line in the scroll window. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
429 int *first_insert_cost |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
430 = &FRAME_INSERT_COST (frame)[frame_height - 1]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
431 int *first_delete_cost |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
432 = &FRAME_DELETE_COST (frame)[frame_height - 1]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
433 int *next_insert_cost |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
434 = &FRAME_INSERTN_COST (frame)[frame_height - 1]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
435 int *next_delete_cost |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
436 = &FRAME_DELETEN_COST (frame)[frame_height - 1]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
437 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
438 int scroll_overhead; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
439 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
440 /* Discourage long scrolls on fast lines. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
441 Don't scroll nearly a full frame height unless it saves |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
442 at least 1/4 second. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
443 int extra_cost = baud_rate / (10 * 4 * FRAME_HEIGHT (frame)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
444 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
445 if (baud_rate <= 0) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
446 extra_cost = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
447 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
448 /* Overhead of setting the scroll window, plus the extra cost |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
449 cost of scrolling by a distance of one. The extra cost is |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
450 added once for consistency with the cost vectors */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
451 scroll_overhead = scroll_region_cost + extra_cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
452 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
453 /* initialize the top left corner of the matrix */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
454 matrix->writecost = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
455 matrix->insertcost = INFINITY; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
456 matrix->deletecost = INFINITY; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
457 matrix->writecount = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
458 matrix->insertcount = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
459 matrix->deletecount = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
460 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
461 /* initialize the left edge of the matrix */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
462 cost = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
463 for (i = 1; i <= window_size; i++) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
464 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
465 p = matrix + i * (window_size + 1); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
466 cost += draw_cost[i]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
467 p->insertcost = cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
468 p->writecost = INFINITY; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
469 p->deletecost = INFINITY; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
470 p->insertcount = i; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
471 p->writecount = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
472 p->deletecount = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
473 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
474 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
475 /* initialize the top edge of the matrix */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
476 for (j = 1; j <= window_size; j++) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
477 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
478 matrix[j].deletecost = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
479 matrix[j].writecost = INFINITY; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
480 matrix[j].insertcost = INFINITY; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
481 matrix[j].deletecount = j; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
482 matrix[j].writecount = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
483 matrix[j].insertcount = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
484 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
485 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
486 /* `i' represents the vpos among new frame contents. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
487 `j' represents the vpos among the old frame contents. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
488 p = matrix + window_size + 2; /* matrix [1, 1] */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
489 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
490 for (i = 1; i <= window_size; i++, p++) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
491 for (j = 1; j <= window_size; j++, p++) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
492 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
493 /* p contains the address of matrix [i, j] */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
494 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
495 /* First calculate the cost assuming we do |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
496 not insert or delete above this line. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
497 That is, if we update through line i-1 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
498 based on old lines through j-1, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
499 and then just change old line j to new line i. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
500 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
501 Depending on which choice gives the lower cost, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
502 this usually involves either scrolling a single line |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
503 or extending a sequence of scrolled lines, but |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
504 when i == j, no scrolling is required. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
505 p1 = p - window_size - 2; /* matrix [i-1, j-1] */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
506 cost = p1->insertcost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
507 if (cost > p1->deletecost) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
508 cost = p1->deletecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
509 cost1 = p1->writecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
510 if (i == j) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
511 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
512 if (cost > cost1) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
513 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
514 cost = cost1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
515 p->writecount = p1->writecount + 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
516 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
517 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
518 p->writecount = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
519 if (old_hash[j] != new_hash[i]) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
520 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
521 cost += draw_cost[i]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
522 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
523 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
524 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
525 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
526 if (i > j) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
527 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
528 delta = i - j; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
529 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
530 /* The cost added here for scrolling the first line by |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
531 a distance N includes the overhead of setting the |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
532 scroll window, the cost of inserting N lines at a |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
533 position N lines above the bottom line of the window, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
534 and an extra cost which is proportional to N. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
535 cost += scroll_overhead + first_insert_cost[-delta] + |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
536 (delta-1) * (next_insert_cost[-delta] + extra_cost); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
537 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
538 /* In the most general case, the insertion overhead and |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
539 the multiply factor can grow linearly as the distance |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
540 from the bottom of the window increases. The incremental |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
541 cost of scrolling an additional line depends upon the |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
542 rate of change of these two parameters. Each of these |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
543 growth rates can be determined by a simple difference. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
544 To reduce the cumulative effects of rounding error, we |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
545 vary the position at which the difference is computed. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
546 cost1 += first_insert_cost[-j] - first_insert_cost[1-j] + |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
547 (delta-1) * (next_insert_cost[-j] - next_insert_cost[1-j]); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
548 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
549 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
550 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
551 delta = j - i; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
552 cost += scroll_overhead + first_delete_cost[-delta] + |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
553 (delta-1) * (next_delete_cost[-delta] + extra_cost); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
554 cost1 += first_delete_cost[-i] - first_delete_cost[1-i] + |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
555 (delta-1) * ( next_delete_cost[-i] - next_delete_cost[1-i]); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
556 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
557 if (cost1 < cost) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
558 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
559 cost = cost1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
560 p->writecount = p1->writecount + 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
561 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
562 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
563 p->writecount = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
564 if (old_hash[j] != new_hash[i]) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
565 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
566 cost += draw_cost[i] + old_draw_cost[j]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
567 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
568 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
569 p->writecost = cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
570 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
571 /* Calculate the cost if we do an insert-line |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
572 before outputting this line. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
573 That is, we update through line i-1 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
574 based on old lines through j, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
575 do an insert-line on line i, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
576 and then output line i from scratch, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
577 leaving old lines starting from j for reuse below. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
578 p1 = p - window_size - 1; /* matrix [i-1, j] */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
579 cost = p1->writecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
580 /* If i > j, an insert is allowed after a delete. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
581 if (i > j && p1->deletecost < cost) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
582 cost = p1->deletecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
583 if (p1->insertcost <= cost) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
584 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
585 cost = p1->insertcost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
586 p->insertcount = p1->insertcount + 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
587 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
588 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
589 p->insertcount = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
590 cost += draw_cost[i]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
591 p->insertcost = cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
592 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
593 /* Calculate the cost if we do a delete line after |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
594 outputting this line. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
595 That is, we update through line i |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
596 based on old lines through j-1, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
597 and throw away old line j. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
598 p1 = p - 1; /* matrix [i, j-1] */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
599 cost = p1->writecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
600 /* If i < j, a delete is allowed after an insert. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
601 if (i < j && p1->insertcost < cost) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
602 cost = p1->insertcost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
603 cost1 = p1->deletecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
604 if (p1->deletecost <= cost) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
605 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
606 cost = p1->deletecost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
607 p->deletecount = p1->deletecount + 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
608 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
609 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
610 p->deletecount = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
611 p->deletecost = cost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
612 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
613 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
614 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
615 /* Perform insert-lines and delete-lines operations on FRAME according |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
616 to the costs in MATRIX, using the direct scrolling method. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
617 Update the frame's current_glyphs info to record what was done. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
618 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
619 WINDOW_SIZE is the number of lines being considered for scrolling |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
620 and UNCHANGED_AT_TOP is the vpos of the first line being considered. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
621 These two arguments can specify any contiguous range of lines. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
622 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
623 We also shuffle the charstarts vectors for the lines |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
624 along with the glyphs; but the results are not quite right, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
625 since we cannot offset them for changes in amount of text |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
626 in this line or that line. Luckily it doesn't matter, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
627 since update_frame and update_line will copy in the proper |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
628 new charstarts vectors from the frame's desired_glyphs. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
629 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
630 In the direct scrolling method, a new scroll window is selected |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
631 before each insertion or deletion, so that groups of lines can be |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
632 scrolled directly to their final vertical positions. This method |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
633 is described in more detail in calculate_direct_scrolling, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
634 where the cost matrix for this approach is constructed. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
635 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
636 static void |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
637 do_direct_scrolling (frame, matrix, window_size, unchanged_at_top) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
638 FRAME_PTR frame; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
639 struct matrix_elt *matrix; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
640 int window_size; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
641 int unchanged_at_top; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
642 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
643 register struct matrix_elt *p; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
644 register int i, j; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
645 register struct frame_glyphs *current_frame; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
646 /* temp_frame->enable[i] means line i has been moved to current_frame. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
647 register struct frame_glyphs *temp_frame; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
648 struct alt_queue { int count, pos, window; } *queue; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
649 int offset = unchanged_at_top; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
650 int qi = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
651 int window = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
652 register int tem; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
653 int next; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
654 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
655 /* A nonzero value of write_follows indicates that a write has been |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
656 selected, allowing either an insert or a delete to be selected next. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
657 When write_follows is zero, a delete cannot be selected unless j < i, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
658 and an insert cannot be selected unless i < j. This corresponds to |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
659 a similar restriction (with the ordering reversed) in |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
660 calculate_direct_scrolling, which is intended to ensure that lines |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
661 marked as inserted will be blank. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
662 int write_follows = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
663 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
664 queue = (struct alt_queue *) alloca (FRAME_HEIGHT (frame) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
665 * sizeof (struct alt_queue)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
666 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
667 current_frame = FRAME_CURRENT_GLYPHS (frame); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
668 temp_frame = FRAME_TEMP_GLYPHS (frame); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
669 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
670 bcopy (current_frame->glyphs, temp_frame->glyphs, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
671 current_frame->height * sizeof (GLYPH *)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
672 bcopy (current_frame->charstarts, temp_frame->charstarts, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
673 current_frame->height * sizeof (GLYPH *)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
674 bcopy (current_frame->used, temp_frame->used, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
675 current_frame->height * sizeof (int)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
676 bcopy (current_frame->highlight, temp_frame->highlight, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
677 current_frame->height * sizeof (char)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
678 bzero (temp_frame->enable, temp_frame->height * sizeof (char)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
679 bcopy (current_frame->bufp, temp_frame->bufp, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
680 current_frame->height * sizeof (int)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
681 |
13415
5c4c0319a6e7
[HAVE_NTGUI] (do_scrolling, do_direct_scrolling): Update frame geometry.
Geoff Voelker <voelker@cs.washington.edu>
parents:
10262
diff
changeset
|
682 #ifdef HAVE_WINDOW_SYSTEM |
5c4c0319a6e7
[HAVE_NTGUI] (do_scrolling, do_direct_scrolling): Update frame geometry.
Geoff Voelker <voelker@cs.washington.edu>
parents:
10262
diff
changeset
|
683 if (FRAME_WINDOW_P (frame)) |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
684 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
685 bcopy (current_frame->top_left_x, temp_frame->top_left_x, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
686 current_frame->height * sizeof (short)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
687 bcopy (current_frame->top_left_y, temp_frame->top_left_y, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
688 current_frame->height * sizeof (short)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
689 bcopy (current_frame->pix_width, temp_frame->pix_width, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
690 current_frame->height * sizeof (short)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
691 bcopy (current_frame->pix_height, temp_frame->pix_height, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
692 current_frame->height * sizeof (short)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
693 bcopy (current_frame->max_ascent, temp_frame->max_ascent, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
694 current_frame->height * sizeof (short)); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
695 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
696 #endif |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
697 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
698 i = j = window_size; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
699 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
700 while (i > 0 || j > 0) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
701 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
702 p = matrix + i * (window_size + 1) + j; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
703 tem = p->insertcost; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
704 if (tem < p->writecost && tem < p->deletecost |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
705 && (write_follows || i < j)) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
706 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
707 /* Insert should be done at vpos i-1, plus maybe some before. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
708 Setting count to 0 in the queue marks this as an insert. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
709 write_follows = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
710 queue[qi].window = i + unchanged_at_top; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
711 queue[qi].count = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
712 i -= p->insertcount; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
713 queue[qi++].pos = i + unchanged_at_top; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
714 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
715 else if (p->deletecost < p->writecost && (write_follows || i > j)) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
716 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
717 /* Delete should be done at vpos j-1, plus maybe some before. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
718 write_follows = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
719 j -= p->deletecount; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
720 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
721 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
722 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
723 /* One or more lines should be retained. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
724 write_follows = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
725 tem = p->writecount; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
726 if (i > j) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
727 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
728 /* Immediately scroll a group of lines downward */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
729 set_terminal_window (i + unchanged_at_top); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
730 window = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
731 ins_del_lines (j - tem + unchanged_at_top, i - j); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
732 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
733 else if (i < j) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
734 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
735 /* Queue the upward scrolling of a group of lines */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
736 queue[qi].pos = i - tem + unchanged_at_top; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
737 queue[qi].window = j + unchanged_at_top; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
738 queue[qi++].count = i - j; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
739 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
740 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
741 /* Now copy the line-contents strings */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
742 while (tem > 0) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
743 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
744 i--; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
745 j--; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
746 tem--; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
747 current_frame->glyphs[i + offset] |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
748 = temp_frame->glyphs[j + offset]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
749 current_frame->charstarts[i + offset] |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
750 = temp_frame->charstarts[j + offset]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
751 current_frame->used[i + offset] |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
752 = temp_frame->used[j + offset]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
753 current_frame->highlight[i + offset] |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
754 = temp_frame->highlight[j + offset]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
755 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
756 temp_frame->enable[j + offset] = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
757 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
758 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
759 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
760 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
761 /* Now do all the upward scrolling, and copy the line-contents |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
762 strings for the blank lines of the recorded inserts. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
763 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
764 next = unchanged_at_top; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
765 for (i = qi - 1; i >= 0; i--) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
766 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
767 if (queue[i].count) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
768 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
769 set_terminal_window (queue[i].window); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
770 window = 1; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
771 ins_del_lines (queue[i].pos, queue[i].count); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
772 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
773 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
774 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
775 /* Mark the inserted lines as clear, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
776 and put into them the line-contents strings |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
777 that were discarded during the deletions. |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
778 Those are the ones for which temp_frame->enable was not set. */ |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
779 tem = queue[i].pos; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
780 for (j = queue[i].window - 1; j >= tem; j--) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
781 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
782 current_frame->enable[j] = 0; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
783 while (temp_frame->enable[next]) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
784 next++; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
785 current_frame->glyphs[j] = temp_frame->glyphs[next]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
786 current_frame->charstarts[j] = temp_frame->charstarts[next++]; |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
787 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
788 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
789 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
790 |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
791 if (window) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
792 set_terminal_window (0); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
793 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
794 |
154 | 795 void |
766 | 796 scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom, |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
797 draw_cost, old_draw_cost, old_hash, new_hash, free_at_end) |
766 | 798 FRAME_PTR frame; |
154 | 799 int window_size, unchanged_at_top, unchanged_at_bottom; |
800 int *draw_cost; | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
801 int *old_draw_cost; |
154 | 802 int *old_hash; |
803 int *new_hash; | |
804 int free_at_end; | |
805 { | |
806 struct matrix_elt *matrix; | |
807 matrix = ((struct matrix_elt *) | |
808 alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix)); | |
809 | |
10262
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
810 if (scroll_region_ok) |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
811 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
812 calculate_direct_scrolling (frame, matrix, window_size, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
813 unchanged_at_bottom, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
814 draw_cost, old_draw_cost, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
815 old_hash, new_hash, free_at_end); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
816 do_direct_scrolling (frame, matrix, window_size, unchanged_at_top); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
817 } |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
818 else |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
819 { |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
820 calculate_scrolling (frame, matrix, window_size, unchanged_at_bottom, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
821 draw_cost, old_hash, new_hash, |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
822 free_at_end); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
823 do_scrolling (frame, matrix, window_size, unchanged_at_top); |
4face60ac721
(scrolling_1): When scroll_region_ok is set, use a
Richard M. Stallman <rms@gnu.org>
parents:
10109
diff
changeset
|
824 } |
154 | 825 } |
826 | |
766 | 827 /* Return number of lines in common between current and desired frame contents |
154 | 828 described to us only as vectors of hash codes OLDHASH and NEWHASH. |
829 Consider only vpos range START to END (not including END). | |
830 Ignore short lines on the assumption that | |
831 avoiding redrawing such a line will have little weight. */ | |
832 | |
833 int | |
834 scrolling_max_lines_saved (start, end, oldhash, newhash, cost) | |
835 int start, end; | |
836 int *oldhash, *newhash, *cost; | |
837 { | |
838 struct { int hash; int count; } lines[01000]; | |
839 register int i, h; | |
840 register int matchcount = 0; | |
841 int avg_length = 0; | |
842 int threshold; | |
843 | |
844 /* Compute a threshold which is 1/4 of average length of these lines. */ | |
845 | |
846 for (i = start; i < end; i++) | |
847 avg_length += cost[i]; | |
848 | |
849 avg_length /= end - start; | |
850 threshold = avg_length / 4; | |
851 | |
852 bzero (lines, sizeof lines); | |
853 | |
854 /* Put new lines' hash codes in hash table. | |
855 Ignore lines shorter than the threshold. | |
856 Thus, if the lines that are in common | |
857 are mainly the ones that are short, | |
858 they won't count. */ | |
859 for (i = start; i < end; i++) | |
860 { | |
861 if (cost[i] > threshold) | |
862 { | |
863 h = newhash[i] & 0777; | |
864 lines[h].hash = newhash[i]; | |
865 lines[h].count++; | |
866 } | |
867 } | |
868 | |
869 /* Look up old line hash codes in the hash table. | |
870 Count number of matches between old lines and new. */ | |
871 | |
872 for (i = start; i < end; i++) | |
873 { | |
874 h = oldhash[i] & 0777; | |
875 if (oldhash[i] == lines[h].hash) | |
876 { | |
877 matchcount++; | |
878 if (--lines[h].count == 0) | |
879 lines[h].hash = 0; | |
880 } | |
881 } | |
882 | |
883 return matchcount; | |
884 } | |
885 | |
886 /* Return a measure of the cost of moving the lines | |
887 starting with vpos FROM, up to but not including vpos TO, | |
888 down by AMOUNT lines (AMOUNT may be negative). | |
889 These are the same arguments that might be given to | |
766 | 890 scroll_frame_lines to perform this scrolling. */ |
154 | 891 |
766 | 892 scroll_cost (frame, from, to, amount) |
893 FRAME_PTR frame; | |
154 | 894 int from, to, amount; |
895 { | |
766 | 896 /* Compute how many lines, at bottom of frame, |
154 | 897 will not be involved in actual motion. */ |
898 int limit = to; | |
899 int offset; | |
766 | 900 int height = FRAME_HEIGHT (frame); |
154 | 901 |
421 | 902 if (amount == 0) |
903 return 0; | |
904 | |
154 | 905 if (! scroll_region_ok) |
906 limit = height; | |
421 | 907 else if (amount > 0) |
908 limit += amount; | |
154 | 909 |
910 if (amount < 0) | |
911 { | |
912 int temp = to; | |
913 to = from + amount; | |
914 from = temp + amount; | |
915 amount = - amount; | |
916 } | |
917 | |
918 offset = height - limit; | |
919 | |
920 return | |
766 | 921 (FRAME_INSERT_COST (frame)[offset + from] |
922 + (amount - 1) * FRAME_INSERTN_COST (frame)[offset + from] | |
10109
869e177ca872
(scroll_cost): FRAME_DELETE_COST and FRAME_DELETEN_COSTS were confused. Fixed.
Richard M. Stallman <rms@gnu.org>
parents:
9576
diff
changeset
|
923 + FRAME_DELETE_COST (frame)[offset + to] |
869e177ca872
(scroll_cost): FRAME_DELETE_COST and FRAME_DELETEN_COSTS were confused. Fixed.
Richard M. Stallman <rms@gnu.org>
parents:
9576
diff
changeset
|
924 + (amount - 1) * FRAME_DELETEN_COST (frame)[offset + to]); |
154 | 925 } |
926 | |
927 /* Calculate the line insertion/deletion | |
928 overhead and multiply factor values */ | |
929 | |
930 static void | |
766 | 931 line_ins_del (frame, ov1, pf1, ovn, pfn, ov, mf) |
932 FRAME_PTR frame; | |
154 | 933 int ov1, ovn; |
934 int pf1, pfn; | |
935 register int *ov, *mf; | |
936 { | |
937 register int i; | |
766 | 938 register int frame_height = FRAME_HEIGHT (frame); |
154 | 939 register int insert_overhead = ov1 * 10; |
940 register int next_insert_cost = ovn * 10; | |
941 | |
766 | 942 for (i = frame_height-1; i >= 0; i--) |
154 | 943 { |
529 | 944 mf[i] = next_insert_cost / 10; |
154 | 945 next_insert_cost += pfn; |
529 | 946 ov[i] = (insert_overhead + next_insert_cost) / 10; |
154 | 947 insert_overhead += pf1; |
948 } | |
949 } | |
950 | |
951 static void | |
766 | 952 ins_del_costs (frame, |
154 | 953 one_line_string, multi_string, |
954 setup_string, cleanup_string, | |
955 costvec, ncostvec, coefficient) | |
766 | 956 FRAME_PTR frame; |
154 | 957 char *one_line_string, *multi_string; |
958 char *setup_string, *cleanup_string; | |
959 int *costvec, *ncostvec; | |
960 int coefficient; | |
961 { | |
962 if (multi_string) | |
766 | 963 line_ins_del (frame, |
154 | 964 string_cost (multi_string) * coefficient, |
965 per_line_cost (multi_string) * coefficient, | |
966 0, 0, costvec, ncostvec); | |
967 else if (one_line_string) | |
766 | 968 line_ins_del (frame, |
154 | 969 string_cost (setup_string) + string_cost (cleanup_string), 0, |
970 string_cost (one_line_string), | |
971 per_line_cost (one_line_string), | |
972 costvec, ncostvec); | |
973 else | |
766 | 974 line_ins_del (frame, |
154 | 975 9999, 0, 9999, 0, |
976 costvec, ncostvec); | |
977 } | |
978 | |
979 /* Calculate the insert and delete line costs. | |
980 Note that this is done even when running with a window system | |
981 because we want to know how long scrolling takes (and avoid it). | |
766 | 982 This must be redone whenever the frame height changes. |
154 | 983 |
984 We keep the ID costs in a precomputed array based on the position | |
985 at which the I or D is performed. Also, there are two kinds of ID | |
986 costs: the "once-only" and the "repeated". This is to handle both | |
987 those terminals that are able to insert N lines at a time (once- | |
988 only) and those that must repeatedly insert one line. | |
989 | |
990 The cost to insert N lines at line L is | |
766 | 991 [tt.t_ILov + (frame_height + 1 - L) * tt.t_ILpf] + |
992 N * [tt.t_ILnov + (frame_height + 1 - L) * tt.t_ILnpf] | |
154 | 993 |
994 ILov represents the basic insert line overhead. ILpf is the padding | |
995 required to allow the terminal time to move a line: insertion at line | |
766 | 996 L changes (frame_height + 1 - L) lines. |
154 | 997 |
998 The first bracketed expression above is the overhead; the second is | |
999 the multiply factor. Both are dependent only on the position at | |
1000 which the insert is performed. We store the overhead in | |
766 | 1001 FRAME_INSERT_COST (frame) and the multiply factor in |
1002 FRAME_INSERTN_COST (frame). Note however that any insertion | |
154 | 1003 must include at least one multiply factor. Rather than compute this |
766 | 1004 as FRAME_INSERT_COST (frame)[line]+FRAME_INSERTN_COST (frame)[line], |
1005 we add FRAME_INSERTN_COST (frame) into FRAME_INSERT_COST (frame). | |
154 | 1006 This is reasonable because of the particular algorithm used in calcM. |
1007 | |
1008 Deletion is essentially the same as insertion. | |
1009 */ | |
1010 | |
766 | 1011 do_line_insertion_deletion_costs (frame, |
154 | 1012 ins_line_string, multi_ins_string, |
1013 del_line_string, multi_del_string, | |
1014 setup_string, cleanup_string, coefficient) | |
766 | 1015 FRAME_PTR frame; |
154 | 1016 char *ins_line_string, *multi_ins_string; |
1017 char *del_line_string, *multi_del_string; | |
1018 char *setup_string, *cleanup_string; | |
1019 int coefficient; | |
1020 { | |
766 | 1021 if (FRAME_INSERT_COST (frame) != 0) |
154 | 1022 { |
766 | 1023 FRAME_INSERT_COST (frame) = |
1024 (int *) xrealloc (FRAME_INSERT_COST (frame), | |
1025 FRAME_HEIGHT (frame) * sizeof (int)); | |
1026 FRAME_DELETEN_COST (frame) = | |
1027 (int *) xrealloc (FRAME_DELETEN_COST (frame), | |
1028 FRAME_HEIGHT (frame) * sizeof (int)); | |
1029 FRAME_INSERTN_COST (frame) = | |
1030 (int *) xrealloc (FRAME_INSERTN_COST (frame), | |
1031 FRAME_HEIGHT (frame) * sizeof (int)); | |
1032 FRAME_DELETE_COST (frame) = | |
1033 (int *) xrealloc (FRAME_DELETE_COST (frame), | |
1034 FRAME_HEIGHT (frame) * sizeof (int)); | |
154 | 1035 } |
1036 else | |
1037 { | |
766 | 1038 FRAME_INSERT_COST (frame) = |
1039 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); | |
1040 FRAME_DELETEN_COST (frame) = | |
1041 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); | |
1042 FRAME_INSERTN_COST (frame) = | |
1043 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); | |
1044 FRAME_DELETE_COST (frame) = | |
1045 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int)); | |
154 | 1046 } |
1047 | |
766 | 1048 ins_del_costs (frame, |
154 | 1049 ins_line_string, multi_ins_string, |
1050 setup_string, cleanup_string, | |
766 | 1051 FRAME_INSERT_COST (frame), FRAME_INSERTN_COST (frame), |
154 | 1052 coefficient); |
766 | 1053 ins_del_costs (frame, |
154 | 1054 del_line_string, multi_del_string, |
1055 setup_string, cleanup_string, | |
9576
14cd96eda0e3
(do_line_insertion_deletion_costs): Fix argument order.
Karl Heuer <kwzh@gnu.org>
parents:
7307
diff
changeset
|
1056 FRAME_DELETE_COST (frame), FRAME_DELETEN_COST (frame), |
154 | 1057 coefficient); |
1058 } |