Commit | Line | Data |
---|---|---|
60de5df9 | 1 | /* |
46e9ea25 KB |
2 | * Copyright (c) 1983 Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
5e8b0e60 KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
60de5df9 EW |
16 | */ |
17 | ||
46e9ea25 | 18 | #ifndef lint |
5e8b0e60 | 19 | static char sccsid[] = "@(#)cmd5.c 3.16 (Berkeley) %G%"; |
46e9ea25 KB |
20 | #endif /* not lint */ |
21 | ||
8baf70f5 EW |
22 | #include "defs.h" |
23 | ||
24 | /* | |
25 | * Window movement. | |
26 | */ | |
f176f953 | 27 | |
8baf70f5 EW |
28 | c_move(w) |
29 | register struct ww *w; | |
30 | { | |
31 | int col, row; | |
19f9784c EW |
32 | int mincol, minrow; |
33 | int maxcol, maxrow; | |
34 | int curcol, currow; | |
8baf70f5 | 35 | |
b27a9cfb EW |
36 | if (!terse) |
37 | wwputs("New window position: ", cmdwin); | |
8baf70f5 EW |
38 | col = w->ww_w.l; |
39 | row = w->ww_w.t; | |
40 | wwadd(boxwin, framewin->ww_back); | |
41 | for (;;) { | |
42 | wwbox(boxwin, row - 1, col - 1, w->ww_w.nr + 2, w->ww_w.nc + 2); | |
19f9784c EW |
43 | getminmax(row, w->ww_w.nr, 1, wwnrow, |
44 | &currow, &minrow, &maxrow); | |
45 | getminmax(col, w->ww_w.nc, 0, wwncol, | |
46 | &curcol, &mincol, &maxcol); | |
47 | wwsetcursor(currow, curcol); | |
8fa6d94c EW |
48 | while (wwpeekc() < 0) |
49 | wwiomux(); | |
19f9784c | 50 | switch (getpos(&row, &col, minrow, mincol, maxrow, maxcol)) { |
eb52ebfc EW |
51 | case 3: |
52 | wwunbox(boxwin); | |
8baf70f5 | 53 | wwdelete(boxwin); |
8baf70f5 | 54 | return; |
eb52ebfc EW |
55 | case 2: |
56 | wwunbox(boxwin); | |
8baf70f5 | 57 | break; |
eb52ebfc EW |
58 | case 1: |
59 | wwunbox(boxwin); | |
8baf70f5 EW |
60 | case 0: |
61 | continue; | |
62 | } | |
63 | break; | |
64 | } | |
65 | wwdelete(boxwin); | |
66 | if (!terse) | |
bf3b96e9 | 67 | wwputc('\n', cmdwin); |
8baf70f5 | 68 | wwcurtowin(cmdwin); |
f176f953 EW |
69 | movewin(w, row, col); |
70 | } | |
71 | ||
72 | movewin(w, row, col) | |
73 | register struct ww *w; | |
74 | { | |
75 | struct ww *back = w->ww_back; | |
76 | ||
b27a9cfb EW |
77 | w->ww_alt.t = w->ww_w.t; |
78 | w->ww_alt.l = w->ww_w.l; | |
8baf70f5 | 79 | wwdelete(w); |
19f9784c | 80 | wwmove(w, row, col); |
8baf70f5 EW |
81 | wwadd(w, back); |
82 | reframe(); | |
83 | } | |
19f9784c EW |
84 | |
85 | /* | |
86 | * Weird stufff, don't ask. | |
87 | */ | |
88 | getminmax(x, n, a, b, curx, minx, maxx) | |
89 | register x, n, a, b; | |
90 | int *curx, *minx, *maxx; | |
91 | { | |
f2a77fe1 | 92 | if (x < 0) |
19f9784c | 93 | *curx = x + n - 1; |
f2a77fe1 | 94 | else |
19f9784c | 95 | *curx = x; |
f2a77fe1 EW |
96 | |
97 | if (x <= a) | |
19f9784c | 98 | *minx = 1 - n; |
f2a77fe1 | 99 | else if (x <= b - n) |
19f9784c | 100 | *minx = a; |
f2a77fe1 | 101 | else |
19f9784c | 102 | *minx = b - n; |
f2a77fe1 EW |
103 | |
104 | if (x >= b - n) | |
19f9784c | 105 | *maxx = b - 1; |
f2a77fe1 EW |
106 | else if (x >= a) |
107 | *maxx = b - n; | |
108 | else | |
109 | *maxx = a; | |
19f9784c | 110 | } |