| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | #include <xterm.h> |
|---|
| 59 | #include <data.h> |
|---|
| 60 | #include <menu.h> |
|---|
| 61 | |
|---|
| 62 | #include <assert.h> |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | void |
|---|
| 70 | CursorSet(TScreen * screen, int row, int col, unsigned flags) |
|---|
| 71 | { |
|---|
| 72 | int use_row = row; |
|---|
| 73 | int max_row; |
|---|
| 74 | |
|---|
| 75 | col = (col < 0 ? 0 : col); |
|---|
| 76 | set_cur_col(screen, (col <= screen->max_col ? col : screen->max_col)); |
|---|
| 77 | max_row = screen->max_row; |
|---|
| 78 | if (flags & ORIGIN) { |
|---|
| 79 | use_row += screen->top_marg; |
|---|
| 80 | max_row = screen->bot_marg; |
|---|
| 81 | } |
|---|
| 82 | use_row = (use_row < 0 ? 0 : use_row); |
|---|
| 83 | set_cur_row(screen, (use_row <= max_row ? use_row : max_row)); |
|---|
| 84 | screen->do_wrap = 0; |
|---|
| 85 | |
|---|
| 86 | TRACE(("CursorSet(%d,%d) margins [%d..%d] -> %d,%d %s\n", |
|---|
| 87 | row, col, |
|---|
| 88 | screen->top_marg, |
|---|
| 89 | screen->bot_marg, |
|---|
| 90 | screen->cur_row, |
|---|
| 91 | screen->cur_col, |
|---|
| 92 | (flags & ORIGIN ? "origin" : "normal"))); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | void |
|---|
| 99 | CursorBack(XtermWidget xw, int n) |
|---|
| 100 | { |
|---|
| 101 | TScreen *screen = &xw->screen; |
|---|
| 102 | int i, j, k, rev; |
|---|
| 103 | |
|---|
| 104 | if ((rev = (xw->flags & (REVERSEWRAP | WRAPAROUND)) == |
|---|
| 105 | (REVERSEWRAP | WRAPAROUND)) != 0 |
|---|
| 106 | && screen->do_wrap) |
|---|
| 107 | n--; |
|---|
| 108 | if ((screen->cur_col -= n) < 0) { |
|---|
| 109 | if (rev) { |
|---|
| 110 | if ((i = ((j = MaxCols(screen)) |
|---|
| 111 | * screen->cur_row) + screen->cur_col) < 0) { |
|---|
| 112 | k = j * MaxRows(screen); |
|---|
| 113 | i += ((-i) / k + 1) * k; |
|---|
| 114 | } |
|---|
| 115 | set_cur_row(screen, i / j); |
|---|
| 116 | set_cur_col(screen, i % j); |
|---|
| 117 | do_xevents(); |
|---|
| 118 | } else { |
|---|
| 119 | set_cur_col(screen, 0); |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | screen->do_wrap = 0; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | void |
|---|
| 129 | CursorForward(TScreen * screen, int n) |
|---|
| 130 | { |
|---|
| 131 | int next = screen->cur_col + n; |
|---|
| 132 | int max = CurMaxCol(screen, screen->cur_row); |
|---|
| 133 | |
|---|
| 134 | if (next > max) |
|---|
| 135 | next = max; |
|---|
| 136 | |
|---|
| 137 | set_cur_col(screen, next); |
|---|
| 138 | screen->do_wrap = 0; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | void |
|---|
| 146 | CursorDown(TScreen * screen, int n) |
|---|
| 147 | { |
|---|
| 148 | int max; |
|---|
| 149 | int next = screen->cur_row + n; |
|---|
| 150 | |
|---|
| 151 | max = (screen->cur_row > screen->bot_marg ? |
|---|
| 152 | screen->max_row : screen->bot_marg); |
|---|
| 153 | if (next > max) |
|---|
| 154 | next = max; |
|---|
| 155 | if (next > screen->max_row) |
|---|
| 156 | next = screen->max_row; |
|---|
| 157 | |
|---|
| 158 | set_cur_row(screen, next); |
|---|
| 159 | screen->do_wrap = 0; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | void |
|---|
| 167 | CursorUp(TScreen * screen, int n) |
|---|
| 168 | { |
|---|
| 169 | int min; |
|---|
| 170 | int next = screen->cur_row - n; |
|---|
| 171 | |
|---|
| 172 | min = ((screen->cur_row < screen->top_marg) |
|---|
| 173 | ? 0 |
|---|
| 174 | : screen->top_marg); |
|---|
| 175 | if (next < min) |
|---|
| 176 | next = min; |
|---|
| 177 | if (next < 0) |
|---|
| 178 | next = 0; |
|---|
| 179 | |
|---|
| 180 | set_cur_row(screen, next); |
|---|
| 181 | screen->do_wrap = 0; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | void |
|---|
| 189 | xtermIndex(XtermWidget xw, int amount) |
|---|
| 190 | { |
|---|
| 191 | TScreen *screen = &xw->screen; |
|---|
| 192 | int j; |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | if (screen->cur_row > screen->bot_marg |
|---|
| 199 | || screen->cur_row + amount <= screen->bot_marg) { |
|---|
| 200 | CursorDown(screen, amount); |
|---|
| 201 | return; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | CursorDown(screen, j = screen->bot_marg - screen->cur_row); |
|---|
| 205 | xtermScroll(xw, amount - j); |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | void |
|---|
| 213 | RevIndex(XtermWidget xw, int amount) |
|---|
| 214 | { |
|---|
| 215 | TScreen *screen = &xw->screen; |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | if (screen->cur_row < screen->top_marg |
|---|
| 222 | || screen->cur_row - amount >= screen->top_marg) { |
|---|
| 223 | CursorUp(screen, amount); |
|---|
| 224 | return; |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | RevScroll(xw, amount - (screen->cur_row - screen->top_marg)); |
|---|
| 228 | CursorUp(screen, screen->cur_row - screen->top_marg); |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | void |
|---|
| 236 | CarriageReturn(TScreen * screen) |
|---|
| 237 | { |
|---|
| 238 | set_cur_col(screen, 0); |
|---|
| 239 | screen->do_wrap = 0; |
|---|
| 240 | do_xevents(); |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | void |
|---|
| 249 | AdjustSavedCursor(XtermWidget xw, int adjust) |
|---|
| 250 | { |
|---|
| 251 | TScreen *screen = &xw->screen; |
|---|
| 252 | |
|---|
| 253 | if (screen->alternate) { |
|---|
| 254 | SavedCursor *sc = &screen->sc[screen->alternate == False]; |
|---|
| 255 | |
|---|
| 256 | if (adjust > 0) { |
|---|
| 257 | TRACE(("AdjustSavedCursor %d -> %d\n", sc->row, sc->row - adjust)); |
|---|
| 258 | sc->row += adjust; |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | void |
|---|
| 267 | CursorSave(XtermWidget xw) |
|---|
| 268 | { |
|---|
| 269 | TScreen *screen = &xw->screen; |
|---|
| 270 | SavedCursor *sc = &screen->sc[screen->alternate != False]; |
|---|
| 271 | |
|---|
| 272 | sc->saved = True; |
|---|
| 273 | sc->row = screen->cur_row; |
|---|
| 274 | sc->col = screen->cur_col; |
|---|
| 275 | sc->flags = xw->flags; |
|---|
| 276 | sc->curgl = screen->curgl; |
|---|
| 277 | sc->curgr = screen->curgr; |
|---|
| 278 | #if OPT_ISO_COLORS |
|---|
| 279 | sc->cur_foreground = xw->cur_foreground; |
|---|
| 280 | sc->cur_background = xw->cur_background; |
|---|
| 281 | sc->sgr_foreground = xw->sgr_foreground; |
|---|
| 282 | #endif |
|---|
| 283 | memmove(sc->gsets, screen->gsets, sizeof(screen->gsets)); |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | #define DECSC_FLAGS (ATTRIBUTES|ORIGIN|WRAPAROUND|PROTECTED) |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | void |
|---|
| 296 | CursorRestore(XtermWidget xw) |
|---|
| 297 | { |
|---|
| 298 | TScreen *screen = &xw->screen; |
|---|
| 299 | SavedCursor *sc = &screen->sc[screen->alternate != False]; |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | if (sc->saved) { |
|---|
| 305 | memmove(screen->gsets, sc->gsets, sizeof(screen->gsets)); |
|---|
| 306 | screen->curgl = sc->curgl; |
|---|
| 307 | screen->curgr = sc->curgr; |
|---|
| 308 | } else { |
|---|
| 309 | resetCharsets(screen); |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | xw->flags &= ~DECSC_FLAGS; |
|---|
| 313 | xw->flags |= sc->flags & DECSC_FLAGS; |
|---|
| 314 | CursorSet(screen, |
|---|
| 315 | ((xw->flags & ORIGIN) |
|---|
| 316 | ? sc->row - screen->top_marg |
|---|
| 317 | : sc->row), |
|---|
| 318 | sc->col, xw->flags); |
|---|
| 319 | |
|---|
| 320 | #if OPT_ISO_COLORS |
|---|
| 321 | xw->sgr_foreground = sc->sgr_foreground; |
|---|
| 322 | SGR_Foreground(xw, xw->flags & FG_COLOR ? sc->cur_foreground : -1); |
|---|
| 323 | SGR_Background(xw, xw->flags & BG_COLOR ? sc->cur_background : -1); |
|---|
| 324 | #endif |
|---|
| 325 | update_autowrap(); |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | void |
|---|
| 332 | CursorNextLine(TScreen * screen, int count) |
|---|
| 333 | { |
|---|
| 334 | CursorDown(screen, count < 1 ? 1 : count); |
|---|
| 335 | CarriageReturn(screen); |
|---|
| 336 | do_xevents(); |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | void |
|---|
| 343 | CursorPrevLine(TScreen * screen, int count) |
|---|
| 344 | { |
|---|
| 345 | CursorUp(screen, count < 1 ? 1 : count); |
|---|
| 346 | CarriageReturn(screen); |
|---|
| 347 | do_xevents(); |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | #if OPT_TRACE |
|---|
| 351 | int |
|---|
| 352 | set_cur_row(TScreen * screen, int value) |
|---|
| 353 | { |
|---|
| 354 | assert(screen != 0); |
|---|
| 355 | assert(value >= 0); |
|---|
| 356 | assert(value <= screen->max_row); |
|---|
| 357 | screen->cur_row = value; |
|---|
| 358 | return value; |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | int |
|---|
| 362 | set_cur_col(TScreen * screen, int value) |
|---|
| 363 | { |
|---|
| 364 | assert(screen != 0); |
|---|
| 365 | assert(value >= 0); |
|---|
| 366 | assert(value <= screen->max_col); |
|---|
| 367 | screen->cur_col = value; |
|---|
| 368 | return value; |
|---|
| 369 | } |
|---|
| 370 | #endif |
|---|