995
|
1 /*
|
|
2 * Window management. Some of the functions are internal, and some are
|
|
3 * attached to keys that the user actually types.
|
|
4 */
|
|
5
|
|
6 #include <stdio.h>
|
|
7 #include "ueed.h"
|
|
8
|
|
9 /*
|
|
10 * Reposition dot in the current window to line "n". If the argument is
|
|
11 * positive, it is that line. If it is negative it is that line from the
|
|
12 * bottom. If it is 0 the window is centered (this is what the standard
|
|
13 * redisplay code does). With no argument it defaults to 1. Bound to M-!.
|
|
14 * Because of the default, it works like in Gosling.
|
|
15 */
|
|
16 reposition(f, n)
|
|
17 {
|
|
18 curwp->w_force = n;
|
|
19 curwp->w_flag |= WFFORCE;
|
|
20 return (TRUE);
|
|
21 }
|
|
22
|
|
23 /*
|
|
24 * Refresh the screen. With no argument, it just does the refresh. With an
|
|
25 * argument it recenters "." in the current window. Bound to "C-L".
|
|
26 */
|
|
27 refresh(f, n)
|
|
28 {
|
|
29 if (f == FALSE)
|
|
30 sgarbf = TRUE;
|
|
31 else
|
|
32 {
|
|
33 curwp->w_force = 0; /* Center dot. */
|
|
34 curwp->w_flag |= WFFORCE;
|
|
35 }
|
|
36
|
|
37 return (TRUE);
|
|
38 }
|
|
39
|
|
40 #ifndef OS9
|
|
41 /*
|
|
42 * The command make the next window (next => down the screen) the current
|
|
43 * window. There are no real errors, although the command does nothing if
|
|
44 * there is only 1 window on the screen. Bound to "C-X C-N".
|
|
45 */
|
|
46 nextwind(f, n)
|
|
47 {
|
|
48 register WINDOW *wp;
|
|
49
|
|
50 if ((wp = curwp->w_wndp) == NULL)
|
|
51 wp = wheadp;
|
|
52
|
|
53 curwp = wp;
|
|
54 curbp = wp->w_bufp;
|
|
55 return (TRUE);
|
|
56 }
|
|
57
|
|
58 /*
|
|
59 * This command makes the previous window (previous => up the screen) the
|
|
60 * current window. There arn't any errors, although the command does not do a
|
|
61 * lot if there is 1 window.
|
|
62 */
|
|
63 prevwind(f, n)
|
|
64 {
|
|
65 register WINDOW *wp1;
|
|
66 register WINDOW *wp2;
|
|
67
|
|
68 wp1 = wheadp;
|
|
69
|
|
70 wp2 = curwp;
|
|
71
|
|
72 if (wp1 == wp2)
|
|
73 wp2 = NULL;
|
|
74
|
|
75 while (wp1->w_wndp != wp2)
|
|
76 wp1 = wp1->w_wndp;
|
|
77
|
|
78 curwp = wp1;
|
|
79 curbp = wp1->w_bufp;
|
|
80 return (TRUE);
|
|
81 }
|
|
82
|
|
83 /*
|
|
84 * This command moves the current window down by "arg" lines. Recompute the
|
|
85 * top line in the window. The move up and move down code is almost completely
|
|
86 * the same; most of the work has to do with reframing the window, and picking
|
|
87 * a new dot. We share the code by having "move down" just be an interface to
|
|
88 * "move up". Magic. Bound to "C-X C-N".
|
|
89 */
|
|
90 mvdnwind(f, n)
|
|
91 int n;
|
|
92 {
|
|
93 return (mvupwind(f, -n));
|
|
94 }
|
|
95
|
|
96 /*
|
|
97 * Move the current window up by "arg" lines. Recompute the new top line of
|
|
98 * the window. Look to see if "." is still on the screen. If it is, you win.
|
|
99 * If it isn't, then move "." to center it in the new framing of the window
|
|
100 * (this command does not really move "."; it moves the frame). Bound to
|
|
101 * "C-X C-P".
|
|
102 */
|
|
103 mvupwind(f, n)
|
|
104 int n;
|
|
105 {
|
|
106 register LINE *lp;
|
|
107 register int i;
|
|
108
|
|
109 lp = curwp->w_linep;
|
|
110
|
|
111 if (n < 0)
|
|
112 {
|
|
113 while (n++ && lp!=curbp->b_linep)
|
|
114 lp = lforw(lp);
|
|
115 }
|
|
116 else
|
|
117 {
|
|
118 while (n-- && lback(lp)!=curbp->b_linep)
|
|
119 lp = lback(lp);
|
|
120 }
|
|
121
|
|
122 curwp->w_linep = lp;
|
|
123 curwp->w_flag |= WFHARD; /* Mode line is OK. */
|
|
124
|
|
125 for (i = 0; i < curwp->w_ntrows; ++i)
|
|
126 {
|
|
127 if (lp == curwp->w_dotp)
|
|
128 return (TRUE);
|
|
129 if (lp == curbp->b_linep)
|
|
130 break;
|
|
131 lp = lforw(lp);
|
|
132 }
|
|
133
|
|
134 lp = curwp->w_linep;
|
|
135 i = curwp->w_ntrows/2;
|
|
136
|
|
137 while (i-- && lp != curbp->b_linep)
|
|
138 lp = lforw(lp);
|
|
139
|
|
140 curwp->w_dotp = lp;
|
|
141 curwp->w_doto = 0;
|
|
142 return (TRUE);
|
|
143 }
|
|
144
|
|
145 /*
|
|
146 * This command makes the current window the only window on the screen. Bound
|
|
147 * to "C-X 1". Try to set the framing so that "." does not have to move on the
|
|
148 * display. Some care has to be taken to keep the values of dot and mark in
|
|
149 * the buffer structures right if the distruction of a window makes a buffer
|
|
150 * become undisplayed.
|
|
151 */
|
|
152 onlywind(f, n)
|
|
153 {
|
|
154 register WINDOW *wp;
|
|
155 register LINE *lp;
|
|
156 register int i;
|
|
157
|
|
158 while (wheadp != curwp) {
|
|
159 wp = wheadp;
|
|
160 wheadp = wp->w_wndp;
|
|
161 if (--wp->w_bufp->b_nwnd == 0) {
|
|
162 wp->w_bufp->b_dotp = wp->w_dotp;
|
|
163 wp->w_bufp->b_doto = wp->w_doto;
|
|
164 wp->w_bufp->b_markp = wp->w_markp;
|
|
165 wp->w_bufp->b_marko = wp->w_marko;
|
|
166 }
|
|
167 free((char *) wp);
|
|
168 }
|
|
169 while (curwp->w_wndp != NULL) {
|
|
170 wp = curwp->w_wndp;
|
|
171 curwp->w_wndp = wp->w_wndp;
|
|
172 if (--wp->w_bufp->b_nwnd == 0) {
|
|
173 wp->w_bufp->b_dotp = wp->w_dotp;
|
|
174 wp->w_bufp->b_doto = wp->w_doto;
|
|
175 wp->w_bufp->b_markp = wp->w_markp;
|
|
176 wp->w_bufp->b_marko = wp->w_marko;
|
|
177 }
|
|
178 free((char *) wp);
|
|
179 }
|
|
180 lp = curwp->w_linep;
|
|
181 i = curwp->w_toprow;
|
|
182 while (i!=0 && lback(lp)!=curbp->b_linep) {
|
|
183 --i;
|
|
184 lp = lback(lp);
|
|
185 }
|
|
186 curwp->w_toprow = 0;
|
|
187 curwp->w_ntrows = term.t_nrow-1;
|
|
188 curwp->w_linep = lp;
|
|
189 curwp->w_flag |= WFMODE|WFHARD;
|
|
190 return (TRUE);
|
|
191 }
|
|
192
|
|
193 /*
|
|
194 * Split the current window. A window smaller than 3 lines cannot be split.
|
|
195 * The only other error that is possible is a "malloc" failure allocating the
|
|
196 * structure for the new window. Bound to "C-X 2".
|
|
197 */
|
|
198 splitwind(f, n)
|
|
199 {
|
|
200 register WINDOW *wp;
|
|
201 register LINE *lp;
|
|
202 register int ntru;
|
|
203 register int ntrl;
|
|
204 register int ntrd;
|
|
205 register WINDOW *wp1;
|
|
206 register WINDOW *wp2;
|
|
207
|
|
208 if (curwp->w_ntrows < 3) {
|
|
209 mlwrite("Cannot split a %d line window", curwp->w_ntrows);
|
|
210 return (FALSE);
|
|
211 }
|
|
212 if ((wp = (WINDOW *) malloc(sizeof(WINDOW))) == NULL) {
|
|
213 mlwrite("Cannot allocate WINDOW block");
|
|
214 return (FALSE);
|
|
215 }
|
|
216 ++curbp->b_nwnd; /* Displayed twice. */
|
|
217 wp->w_bufp = curbp;
|
|
218 wp->w_dotp = curwp->w_dotp;
|
|
219 wp->w_doto = curwp->w_doto;
|
|
220 wp->w_markp = curwp->w_markp;
|
|
221 wp->w_marko = curwp->w_marko;
|
|
222 wp->w_flag = 0;
|
|
223 wp->w_force = 0;
|
|
224 ntru = (curwp->w_ntrows-1) / 2; /* Upper size */
|
|
225 ntrl = (curwp->w_ntrows-1) - ntru; /* Lower size */
|
|
226 lp = curwp->w_linep;
|
|
227 ntrd = 0;
|
|
228 while (lp != curwp->w_dotp) {
|
|
229 ++ntrd;
|
|
230 lp = lforw(lp);
|
|
231 }
|
|
232 lp = curwp->w_linep;
|
|
233 if (ntrd <= ntru) { /* Old is upper window. */
|
|
234 if (ntrd == ntru) /* Hit mode line. */
|
|
235 lp = lforw(lp);
|
|
236 curwp->w_ntrows = ntru;
|
|
237 wp->w_wndp = curwp->w_wndp;
|
|
238 curwp->w_wndp = wp;
|
|
239 wp->w_toprow = curwp->w_toprow+ntru+1;
|
|
240 wp->w_ntrows = ntrl;
|
|
241 } else { /* Old is lower window */
|
|
242 wp1 = NULL;
|
|
243 wp2 = wheadp;
|
|
244 while (wp2 != curwp) {
|
|
245 wp1 = wp2;
|
|
246 wp2 = wp2->w_wndp;
|
|
247 }
|
|
248 if (wp1 == NULL)
|
|
249 wheadp = wp;
|
|
250 else
|
|
251 wp1->w_wndp = wp;
|
|
252 wp->w_wndp = curwp;
|
|
253 wp->w_toprow = curwp->w_toprow;
|
|
254 wp->w_ntrows = ntru;
|
|
255 ++ntru; /* Mode line. */
|
|
256 curwp->w_toprow += ntru;
|
|
257 curwp->w_ntrows = ntrl;
|
|
258 while (ntru--)
|
|
259 lp = lforw(lp);
|
|
260 }
|
|
261 curwp->w_linep = lp; /* Adjust the top lines */
|
|
262 wp->w_linep = lp; /* if necessary. */
|
|
263 curwp->w_flag |= WFMODE|WFHARD;
|
|
264 wp->w_flag |= WFMODE|WFHARD;
|
|
265
|
|
266 return (TRUE);
|
|
267 }
|
|
268
|
|
269 /*
|
|
270 * Enlarge the current window. Find the window that loses space. Make sure it
|
|
271 * is big enough. If so, hack the window descriptions, and ask redisplay to do
|
|
272 * all the hard work. You don't just set "force reframe" because dot would
|
|
273 * move. Bound to "C-X Z".
|
|
274 */
|
|
275 enlargewind(f, n)
|
|
276 {
|
|
277 register WINDOW *adjwp;
|
|
278 register LINE *lp;
|
|
279 register int i;
|
|
280
|
|
281 if (n < 0)
|
|
282 return (shrinkwind(f, -n));
|
|
283 if (wheadp->w_wndp == NULL) {
|
|
284 mlwrite("Only one window");
|
|
285 return (FALSE);
|
|
286 }
|
|
287 if ((adjwp=curwp->w_wndp) == NULL) {
|
|
288 adjwp = wheadp;
|
|
289 while (adjwp->w_wndp != curwp)
|
|
290 adjwp = adjwp->w_wndp;
|
|
291 }
|
|
292 if (adjwp->w_ntrows <= n) {
|
|
293 mlwrite("Impossible change");
|
|
294 return (FALSE);
|
|
295 }
|
|
296 if (curwp->w_wndp == adjwp) { /* Shrink below. */
|
|
297 lp = adjwp->w_linep;
|
|
298 for (i=0; i<n && lp!=adjwp->w_bufp->b_linep; ++i)
|
|
299 lp = lforw(lp);
|
|
300 adjwp->w_linep = lp;
|
|
301 adjwp->w_toprow += n;
|
|
302 } else { /* Shrink above. */
|
|
303 lp = curwp->w_linep;
|
|
304 for (i=0; i<n && lback(lp)!=curbp->b_linep; ++i)
|
|
305 lp = lback(lp);
|
|
306 curwp->w_linep = lp;
|
|
307 curwp->w_toprow -= n;
|
|
308 }
|
|
309 curwp->w_ntrows += n;
|
|
310 adjwp->w_ntrows -= n;
|
|
311 curwp->w_flag |= WFMODE|WFHARD;
|
|
312 adjwp->w_flag |= WFMODE|WFHARD;
|
|
313 return (TRUE);
|
|
314 }
|
|
315
|
|
316 /*
|
|
317 * Shrink the current window. Find the window that gains space. Hack at the
|
|
318 * window descriptions. Ask the redisplay to do all the hard work. Bound to
|
|
319 * "C-X C-Z".
|
|
320 */
|
|
321 shrinkwind(f, n)
|
|
322 {
|
|
323 register WINDOW *adjwp;
|
|
324 register LINE *lp;
|
|
325 register int i;
|
|
326
|
|
327 if (n < 0)
|
|
328 return (enlargewind(f, -n));
|
|
329 if (wheadp->w_wndp == NULL) {
|
|
330 mlwrite("Only one window");
|
|
331 return (FALSE);
|
|
332 }
|
|
333 if ((adjwp=curwp->w_wndp) == NULL) {
|
|
334 adjwp = wheadp;
|
|
335 while (adjwp->w_wndp != curwp)
|
|
336 adjwp = adjwp->w_wndp;
|
|
337 }
|
|
338 if (curwp->w_ntrows <= n) {
|
|
339 mlwrite("Impossible change");
|
|
340 return (FALSE);
|
|
341 }
|
|
342 if (curwp->w_wndp == adjwp) { /* Grow below. */
|
|
343 lp = adjwp->w_linep;
|
|
344 for (i=0; i<n && lback(lp)!=adjwp->w_bufp->b_linep; ++i)
|
|
345 lp = lback(lp);
|
|
346 adjwp->w_linep = lp;
|
|
347 adjwp->w_toprow -= n;
|
|
348 } else { /* Grow above. */
|
|
349 lp = curwp->w_linep;
|
|
350 for (i=0; i<n && lp!=curbp->b_linep; ++i)
|
|
351 lp = lforw(lp);
|
|
352 curwp->w_linep = lp;
|
|
353 curwp->w_toprow += n;
|
|
354 }
|
|
355 curwp->w_ntrows -= n;
|
|
356 adjwp->w_ntrows += n;
|
|
357 curwp->w_flag |= WFMODE|WFHARD;
|
|
358 adjwp->w_flag |= WFMODE|WFHARD;
|
|
359 return (TRUE);
|
|
360 }
|
|
361
|
|
362 /*
|
|
363 * Pick a window for a pop-up. Split the screen if there is only one window.
|
|
364 * Pick the uppermost window that isn't the current window. An LRU algorithm
|
|
365 * might be better. Return a pointer, or NULL on error.
|
|
366 */
|
|
367 WINDOW *
|
|
368 wpopup()
|
|
369 {
|
|
370 register WINDOW *wp;
|
|
371
|
|
372 if (wheadp->w_wndp == NULL /* Only 1 window */
|
|
373 && splitwind(FALSE, 0) == FALSE) /* and it won't split */
|
|
374 return (NULL);
|
|
375 wp = wheadp; /* Find window to use */
|
|
376 while (wp!=NULL && wp==curwp)
|
|
377 wp = wp->w_wndp;
|
|
378 return (wp);
|
|
379 }
|
|
380 #endif
|
|
381
|