|
|
1.1 root 1: /*
2: * $Source: /u1/X/xterm/RCS/cursor.c,v $
3: * $Header: cursor.c,v 10.100 86/12/01 14:43:54 jg Rel $
4: */
5:
6: #ifndef lint
7: static char *rcsid_cursor_c = "$Header: cursor.c,v 10.100 86/12/01 14:43:54 jg Rel $";
8: #endif lint
9:
10: #include <X/mit-copyright.h>
11:
12: /* Copyright 1984, 1985 Massachusetts Institute of Technology */
13:
14: /* cursor.c */
15:
16:
17: #ifndef lint
18: static char sccs_id[] = "@(#)cursor.c\tX10/6.6B\t12/26/86";
19: #endif lint
20:
21: #include <X/Xlib.h>
22: #include <stdio.h>
23: #include <sys/ioctl.h>
24: #include "scrollbar.h"
25: #include "ptyx.h"
26:
27: extern Terminal term;
28:
29: /*
30: * Moves the cursor to the specified position, checking for bounds.
31: * (this includes scrolling regions)
32: * The origin is considered to be 0, 0 for this procedure.
33: * In the status line, the cursor moves only horizontally.
34: */
35: CursorSet(screen, row, col, flags)
36: register Screen *screen;
37: register int row, col;
38: unsigned flags;
39: {
40: register int maxr;
41:
42: col = (col < 0 ? 0 : col);
43: screen->cur_col = (col <= screen->max_col ? col : screen->max_col);
44: if(!screen->instatus) {
45: maxr = screen->max_row;
46: if (flags & ORIGIN) {
47: row += screen->top_marg;
48: maxr = screen->bot_marg;
49: }
50: row = (row < 0 ? 0 : row);
51: screen->cur_row = (row <= maxr ? row : maxr);
52: }
53: screen->do_wrap = 0;
54: }
55:
56: /*
57: * moves the cursor left n, no wrap around
58: */
59: CursorBack(screen, n)
60: register Screen *screen;
61: int n;
62: {
63: register int i, j, k, rev;
64:
65: if((rev = (term.flags & (REVERSEWRAP | WRAPAROUND)) ==
66: (REVERSEWRAP | WRAPAROUND)) && screen->do_wrap)
67: n--;
68: if ((screen->cur_col -= n) < 0) {
69: if(rev) {
70: if((i = (j = screen->max_col + 1) * screen->cur_row +
71: screen->cur_col) < 0) {
72: k = j * (screen->max_row + 1);
73: i += ((-i) / k + 1) * k;
74: }
75: screen->cur_row = i / j;
76: screen->cur_col = i % j;
77: } else
78: screen->cur_col = 0;
79: }
80: screen->do_wrap = 0;
81: }
82:
83: /*
84: * moves the cursor forward n, no wraparound
85: */
86: CursorForward(screen, n)
87: register Screen *screen;
88: int n;
89: {
90: screen->cur_col += n;
91: if (screen->cur_col > screen->max_col)
92: screen->cur_col = screen->max_col;
93: screen->do_wrap = 0;
94: }
95:
96: /*
97: * moves the cursor down n, no scrolling.
98: * Won't pass bottom margin or bottom of screen.
99: */
100: CursorDown(screen, n)
101: register Screen *screen;
102: int n;
103: {
104: register int max;
105:
106: max = (screen->cur_row > screen->bot_marg ?
107: screen->max_row : screen->bot_marg);
108:
109: screen->cur_row += n;
110: if (screen->cur_row > max)
111: screen->cur_row = max;
112: screen->do_wrap = 0;
113: }
114:
115: /*
116: * moves the cursor up n, no linestarving.
117: * Won't pass top margin or top of screen.
118: */
119: CursorUp(screen, n)
120: register Screen *screen;
121: int n;
122: {
123: register int min;
124:
125: min = (screen->cur_row < screen->top_marg ?
126: 0 : screen->top_marg);
127:
128: screen->cur_row -= n;
129: if (screen->cur_row < min)
130: screen->cur_row = min;
131: screen->do_wrap = 0;
132: }
133:
134: /*
135: * Moves cursor down amount lines, scrolls if necessary.
136: * Won't leave scrolling region. No carriage return.
137: */
138: Index(screen, amount)
139: register Screen *screen;
140: register int amount;
141: {
142: register int lines, j;
143: register char *str;
144: int n;
145: XEvent ev;
146:
147: /*
148: * indexing when below scrolling region is cursor down.
149: * if cursor high enough, no scrolling necessary.
150: */
151: if (screen->cur_row > screen->bot_marg
152: || screen->cur_row + amount <= screen->bot_marg) {
153: if(screen->pagemode)
154: screen->pagecnt += amount;
155: CursorDown(screen, amount);
156: return;
157: }
158:
159: CursorDown(screen, j = screen->bot_marg - screen->cur_row);
160: amount -= j;
161: if((lines = screen->bot_marg - screen->top_marg - screen->pageoverlap)
162: <= 0)
163: lines = 1;
164: if(!screen->pagemode || (amount + screen->pagecnt) <= lines) {
165: if(screen->pagemode)
166: screen->pagecnt += amount;
167: Scroll(screen, amount);
168: return;
169: }
170: ioctl(screen->respond, TIOCSTOP, NULL);
171: if(screen->cursor_state)
172: HideCursor();
173: if((j = lines - screen->pagecnt) > 0) {
174: Scroll(screen, j);
175: amount -= j;
176: }
177: do {
178: if(screen->scroll_amt)
179: FlushScroll(screen);
180: j = FALSE;
181: do {
182: XNextEvent(&ev);
183: switch((int)ev.type) {
184: case KeyPressed:
185: str = XLookupMapping(&ev, &n);
186: if(n > 0) {
187: if(*str == '\r')
188: screen->pagecnt = (lines - 1);
189: else if(*str < ' ' || *str == '\177') {
190: screen->pagecnt = 0;
191: Input(&term.keyboard, screen,
192: &ev);
193: ioctl(screen->respond, TIOCSTOP,
194: NULL);
195: } else
196: screen->pagecnt = 0;
197: } else
198: screen->pagecnt = 0;
199: j = TRUE;
200: break;
201: case ButtonPressed:
202: case ButtonReleased:
203: screen->pagecnt = amount;
204: xeventpass(&ev);
205: if(!screen->pagemode) {
206: Scroll(screen, amount);
207: ioctl(screen->respond, TIOCSTART, NULL);
208: return;
209: }
210: break;
211: default:
212: xeventpass(&ev);
213: break;
214: }
215: } while(!j);
216: j = lines - screen->pagecnt;
217: if(j > amount)
218: j = amount;
219: Scroll(screen, j);
220: screen->pagecnt += j;
221: } while((amount -= j) > 0);
222: ioctl(screen->respond, TIOCSTART, NULL);
223: }
224:
225: /*
226: * Moves cursor up amount lines, reverse scrolls if necessary.
227: * Won't leave scrolling region. No carriage return.
228: */
229: RevIndex(screen, amount)
230: register Screen *screen;
231: register int amount;
232: {
233: /*
234: * reverse indexing when above scrolling region is cursor up.
235: * if cursor low enough, no reverse indexing needed
236: */
237: if (screen->cur_row < screen->top_marg
238: || screen->cur_row-amount >= screen->top_marg) {
239: CursorUp(screen, amount);
240: return;
241: }
242:
243: RevScroll(screen, amount - (screen->cur_row - screen->top_marg));
244: CursorUp(screen, screen->cur_row - screen->top_marg);
245: }
246:
247: /*
248: * Moves Cursor To First Column In Line
249: */
250: CarriageReturn(screen)
251: register Screen *screen;
252: {
253: screen->cur_col = 0;
254: screen->do_wrap = 0;
255: }
256:
257: /*
258: * Save Cursor and Attributes
259: */
260: CursorSave(term, sc)
261: register Terminal *term;
262: register SavedCursor *sc;
263: {
264: register Screen *screen = &term->screen;
265:
266: sc->row = screen->cur_row;
267: sc->col = screen->cur_col;
268: sc->flags = term->flags;
269: sc->curgl = screen->curgl;
270: sc->curgr = screen->curgr;
271: bcopy(screen->gsets, sc->gsets, sizeof(screen->gsets));
272: }
273:
274: /*
275: * Restore Cursor and Attributes
276: */
277: CursorRestore(term, sc)
278: register Terminal *term;
279: register SavedCursor *sc;
280: {
281: register Screen *screen = &term->screen;
282:
283: bcopy(sc->gsets, screen->gsets, sizeof(screen->gsets));
284: screen->curgl = sc->curgl;
285: screen->curgr = sc->curgr;
286: term->flags &= ~(BOLD|INVERSE|UNDERLINE);
287: term->flags |= sc->flags & (BOLD|INVERSE|UNDERLINE);
288: CursorSet(screen, sc->row, sc->col, term->flags);
289: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.