1: #include <X/mit-copyright.h>
   2: 
   3: /* Copyright 1984, 1985   Massachusetts Institute of Technology		*/
   4: 
   5: /* cursor.c */
   6: 
   7: 
   8: #ifndef lint
   9: static char *rcsid_cursor_c = "$Header: cursor.c,v 10.9 86/02/01 16:06:14 tony Rel $";
  10: #endif	lint
  11: 
  12: #include <X/Xlib.h>
  13: #include <stdio.h>
  14: #include "ptyx.h"
  15: 
  16: /*
  17:  * Moves the cursor to the specified position, checking for bounds.
  18:  * (this includes scrolling regions)
  19:  * The origin is considered to be 0, 0 for this procedure.
  20:  */
  21: CursorSet(screen, row, col, flags)
  22: register Screen *screen;
  23: register int    row, col;
  24: unsigned    flags;
  25: {
  26:     register int maxr = screen->max_row;
  27: 
  28:     if (flags & ORIGIN) {
  29:         row += screen->top_marg;
  30:         maxr = screen->bot_marg;
  31:     }
  32: 
  33:     row = (row < 0 ? 0 : row);
  34:     col = (col < 0 ? 0 : col);
  35:     screen->cur_col = (col <= screen->max_col ? col : screen->max_col);
  36:     screen->cur_row = (row <= maxr ? row : maxr);
  37:     screen->do_wrap = 0;
  38: }
  39: 
  40: /*
  41:  * moves the cursor left n, no wrap around
  42:  */
  43: CursorBack(screen, n)
  44: register Screen *screen;
  45: int     n;
  46: {
  47:     screen->cur_col -= n;
  48:     if (screen->cur_col < 0)
  49:         screen->cur_col = 0;
  50:     screen->do_wrap = 0;
  51: }
  52: 
  53: /*
  54:  * moves the cursor forward n, no wraparound
  55:  */
  56: CursorForward(screen, n)
  57: register Screen *screen;
  58: int     n;
  59: {
  60:     screen->cur_col += n;
  61:     if (screen->cur_col > screen->max_col)
  62:         screen->cur_col = screen->max_col;
  63:     screen->do_wrap = 0;
  64: }
  65: 
  66: /*
  67:  * moves the cursor down n, no scrolling.
  68:  * Won't pass bottom margin or bottom of screen.
  69:  */
  70: CursorDown(screen, n)
  71: register Screen *screen;
  72: int     n;
  73: {
  74:     register int max;
  75: 
  76:     max = (screen->cur_row > screen->bot_marg ?
  77:         screen->max_row : screen->bot_marg);
  78: 
  79:     screen->cur_row += n;
  80:     if (screen->cur_row > max)
  81:         screen->cur_row = max;
  82:     screen->do_wrap = 0;
  83: }
  84: 
  85: /*
  86:  * moves the cursor up n, no linestarving.
  87:  * Won't pass top margin or top of screen.
  88:  */
  89: CursorUp(screen, n)
  90: register Screen *screen;
  91: int     n;
  92: {
  93:     register int min;
  94: 
  95:     min = (screen->cur_row < screen->top_marg ?
  96:         0 : screen->top_marg);
  97: 
  98:     screen->cur_row -= n;
  99:     if (screen->cur_row < min)
 100:         screen->cur_row = min;
 101:     screen->do_wrap = 0;
 102: }
 103: 
 104: /*
 105:  * Moves cursor down amount lines, scrolls if necessary.
 106:  * Won't leave scrolling region. No carriage return.
 107:  */
 108: Index(screen, amount)
 109: register Screen *screen;
 110: register int    amount;
 111: {
 112:     /*
 113: 	 * indexing when below scrolling region is cursor down.
 114: 	 * if cursor high enough, no scrolling necessary.
 115: 	 */
 116:     if (screen->cur_row > screen->bot_marg
 117:     || screen->cur_row + amount <= screen->bot_marg) {
 118:         CursorDown(screen, amount);
 119:         return;
 120:     }
 121: 
 122:     Scroll(screen, amount - (screen->bot_marg - screen->cur_row));
 123:     CursorDown(screen, screen->bot_marg - screen->cur_row);
 124: }
 125: 
 126: /*
 127:  * Moves cursor up amount lines, reverse scrolls if necessary.
 128:  * Won't leave scrolling region. No carriage return.
 129:  */
 130: RevIndex(screen, amount)
 131: register Screen *screen;
 132: register int    amount;
 133: {
 134:     /*
 135: 	 * reverse indexing when above scrolling region is cursor up.
 136: 	 * if cursor low enough, no reverse indexing needed
 137: 	 */
 138:     if (screen->cur_row < screen->top_marg
 139:     || screen->cur_row-amount >= screen->top_marg) {
 140:         CursorUp(screen, amount);
 141:         return;
 142:     }
 143: 
 144:     RevScroll(screen, amount - (screen->cur_row - screen->top_marg));
 145:     CursorUp(screen, screen->cur_row - screen->top_marg);
 146: }
 147: 
 148: 
 149: /*
 150:  * Moves Cursor To First Column In Line
 151:  */
 152: CarriageReturn(screen)
 153: register Screen *screen;
 154: {
 155:     screen->cur_col = 0;
 156:     screen->do_wrap = 0;
 157: }
 158: 
 159: /*
 160:  * Toggles cursor on or off at cursor position in screen.
 161:  */
 162: CursorToggle(screen, turnOn)
 163: register Screen *screen;
 164: int     turnOn;
 165: {
 166:     int fg = screen->foreground;
 167:     int bg = screen->background;
 168:     short flags = screen->buf [screen->cur_row] [screen->cur_col];
 169:     char c;
 170:     if (((turnOn ? INVERSEbit : 0) ^ (flags & INVERSEbit))) {
 171:         fg = screen->background;
 172:         bg = screen->cursorcolor;
 173:     }
 174:     /* If in normal mode repaint character */
 175:     if (!screen->TekEmu) {
 176:         if ((c = (flags & CHAR)) == 0) c = ' ';
 177:         XText(screen->window, CursorX (screen), CursorY(screen), &c,1,
 178:             ((flags & BOLDbit) ? screen->fnt_bold : screen->fnt_norm),
 179:             fg, bg);
 180:     /* If in Tek mode then invert */
 181:     /* If in TekAmode then use TCursor instead of Cursor */
 182:     } else if (screen->TekAMode)
 183:         XPixFill(screen->window, TCursorX (screen), TCursorY(screen),
 184:             screen->f_width, screen->f_height, screen->foreground,
 185:             0, GXinvert, screen->xorplane);
 186: 
 187:     /* Avoid toggling cursor during Tektronix coordinate computations */
 188:     else if (!screen->TekGMode)
 189:         XPixFill(screen->window, CursorX (screen), CursorY(screen),
 190:             screen->f_width, screen->f_height, screen->foreground,
 191:             0, GXinvert, screen->xorplane);
 192: }

Defined functions

CarriageReturn defined in line 152; used 3 times
CursorBack defined in line 43; used 2 times
CursorDown defined in line 70; used 3 times
CursorForward defined in line 56; used 2 times
CursorSet defined in line 21; used 6 times
CursorToggle defined in line 162; used 3 times
CursorUp defined in line 89; used 3 times
Index defined in line 108; used 5 times
RevIndex defined in line 130; used 2 times

Defined variables

rcsid_cursor_c defined in line 9; never used
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1320
Valid CSS Valid XHTML 1.0 Strict