|
|
1.1 ! root 1: /* ! 2: * $Source: /u1/X11/clients/xterm/RCS/util.c,v $ ! 3: * $Header: util.c,v 1.11 87/09/11 08:16:49 toddb Exp $ ! 4: */ ! 5: ! 6: #include <X11/copyright.h> ! 7: ! 8: /* ! 9: * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. ! 10: * ! 11: * All Rights Reserved ! 12: * ! 13: * Permission to use, copy, modify, and distribute this software and its ! 14: * documentation for any purpose and without fee is hereby granted, ! 15: * provided that the above copyright notice appear in all copies and that ! 16: * both that copyright notice and this permission notice appear in ! 17: * supporting documentation, and that the name of Digital Equipment ! 18: * Corporation not be used in advertising or publicity pertaining to ! 19: * distribution of the software without specific, written prior permission. ! 20: * ! 21: * ! 22: * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ! 23: * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ! 24: * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ! 25: * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ! 26: * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ! 27: * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ! 28: * SOFTWARE. ! 29: */ ! 30: ! 31: /* util.c */ ! 32: ! 33: #ifndef lint ! 34: static char rcs_id[] = "$Header: util.c,v 1.11 87/09/11 08:16:49 toddb Exp $"; ! 35: #endif lint ! 36: ! 37: #include <stdio.h> ! 38: #include <X11/Xlib.h> ! 39: #include <X11/Intrinsic.h> ! 40: #include <signal.h> ! 41: #include <setjmp.h> ! 42: typedef int *jmp_ptr; ! 43: ! 44: #include "ptyx.h" ! 45: #include "data.h" ! 46: #include "error.h" ! 47: ! 48: /* ! 49: * These routines are used for the jump scroll feature ! 50: */ ! 51: FlushScroll(screen) ! 52: register TScreen *screen; ! 53: { ! 54: register int i; ! 55: register int shift = -screen->topline; ! 56: register int bot = screen->max_row - shift; ! 57: register int refreshtop; ! 58: register int refreshheight; ! 59: register int scrolltop; ! 60: register int scrollheight; ! 61: ! 62: if(screen->cursor_state) ! 63: HideCursor(); ! 64: if(screen->scroll_amt > 0) { ! 65: refreshheight = screen->refresh_amt; ! 66: scrollheight = screen->bot_marg - screen->top_marg - ! 67: refreshheight + 1; ! 68: if((refreshtop = screen->bot_marg - refreshheight + 1 + shift) > ! 69: (i = screen->max_row - screen->scroll_amt + 1)) ! 70: refreshtop = i; ! 71: if(screen->scrollWindow && !screen->alternate ! 72: && screen->top_marg == 0) { ! 73: scrolltop = 0; ! 74: if((scrollheight += shift) > i) ! 75: scrollheight = i; ! 76: if((i = screen->bot_marg - bot) > 0 && ! 77: (refreshheight -= i) < screen->scroll_amt) ! 78: refreshheight = screen->scroll_amt; ! 79: if((i = screen->savedlines) < screen->savelines) { ! 80: if((i += screen->scroll_amt) > ! 81: screen->savelines) ! 82: i = screen->savelines; ! 83: screen->savedlines = i; ! 84: ScrollBarDrawThumb(screen->scrollWindow); ! 85: } ! 86: } else { ! 87: scrolltop = screen->top_marg + shift; ! 88: if((i = bot - (screen->bot_marg - screen->refresh_amt + ! 89: screen->scroll_amt)) > 0) { ! 90: if(bot < screen->bot_marg) ! 91: refreshheight = screen->scroll_amt + i; ! 92: } else { ! 93: scrollheight += i; ! 94: refreshheight = screen->scroll_amt; ! 95: if((i = screen->top_marg + screen->scroll_amt - ! 96: 1 - bot) > 0) { ! 97: refreshtop += i; ! 98: refreshheight -= i; ! 99: } ! 100: } ! 101: } ! 102: } else { ! 103: refreshheight = -screen->refresh_amt; ! 104: scrollheight = screen->bot_marg - screen->top_marg - ! 105: refreshheight + 1; ! 106: refreshtop = screen->top_marg + shift; ! 107: scrolltop = refreshtop + refreshheight; ! 108: if((i = screen->bot_marg - bot) > 0) ! 109: scrollheight -= i; ! 110: if((i = screen->top_marg + refreshheight - 1 - bot) > 0) ! 111: refreshheight -= i; ! 112: } ! 113: if(scrollheight > 0) { ! 114: if (screen->multiscroll && scrollheight == 1 && ! 115: screen->topline == 0 && screen->top_marg == 0 && ! 116: screen->bot_marg == screen->max_row) { ! 117: if (screen->incopy < 0 && screen->scrolls == 0) ! 118: CopyWait (screen); ! 119: screen->scrolls++; ! 120: } else { ! 121: if (screen->incopy) ! 122: CopyWait (screen); ! 123: screen->incopy = -1; ! 124: } ! 125: ! 126: XCopyArea ( ! 127: screen->display, ! 128: TextWindow(screen), ! 129: TextWindow(screen), ! 130: screen->normalGC, ! 131: (int) screen->border + screen->scrollbar, ! 132: (int) (scrolltop + screen->scroll_amt) * FontHeight(screen) ! 133: + screen->border, ! 134: (unsigned) Width(screen), ! 135: (unsigned) scrollheight * FontHeight(screen), ! 136: (int) screen->border + screen->scrollbar, ! 137: (int) scrolltop*FontHeight(screen) + screen->border); ! 138: } ! 139: screen->scroll_amt = 0; ! 140: screen->refresh_amt = 0; ! 141: if(refreshheight > 0) { ! 142: XClearArea ( ! 143: screen->display, ! 144: TextWindow(screen), ! 145: (int) screen->border + screen->scrollbar, ! 146: (int) refreshtop * FontHeight(screen) + screen->border, ! 147: (unsigned) Width(screen), ! 148: (unsigned) refreshheight * FontHeight(screen), ! 149: FALSE); ! 150: ScrnRefresh(screen, refreshtop, 0, refreshheight, ! 151: screen->max_col + 1); ! 152: } ! 153: } ! 154: ! 155: AddToRefresh(screen) ! 156: register TScreen *screen; ! 157: { ! 158: register int amount = screen->refresh_amt; ! 159: register int row = screen->cur_row; ! 160: ! 161: if(amount == 0) ! 162: return(0); ! 163: if(amount > 0) { ! 164: register int bottom; ! 165: ! 166: if(row == (bottom = screen->bot_marg) - amount) { ! 167: screen->refresh_amt++; ! 168: return(1); ! 169: } ! 170: return(row >= bottom - amount + 1 && row <= bottom); ! 171: } else { ! 172: register int top; ! 173: ! 174: amount = -amount; ! 175: if(row == (top = screen->top_marg) + amount) { ! 176: screen->refresh_amt--; ! 177: return(1); ! 178: } ! 179: return(row <= top + amount - 1 && row >= top); ! 180: } ! 181: } ! 182: ! 183: /* ! 184: * scrolls the screen by amount lines, erases bottom, doesn't alter ! 185: * cursor position (i.e. cursor moves down amount relative to text). ! 186: * All done within the scrolling region, of course. ! 187: * requires: amount > 0 ! 188: */ ! 189: Scroll(screen, amount) ! 190: register TScreen *screen; ! 191: register int amount; ! 192: { ! 193: register int i = screen->bot_marg - screen->top_marg + 1; ! 194: register int shift; ! 195: register int bot; ! 196: register int refreshtop; ! 197: register int refreshheight; ! 198: register int scrolltop; ! 199: register int scrollheight; ! 200: ! 201: if(screen->cursor_state) ! 202: HideCursor(); ! 203: if (amount > i) ! 204: amount = i; ! 205: if(screen->jumpscroll) { ! 206: if(screen->scroll_amt > 0) { ! 207: if(screen->refresh_amt + amount > i) ! 208: FlushScroll(screen); ! 209: screen->scroll_amt += amount; ! 210: screen->refresh_amt += amount; ! 211: } else { ! 212: if(screen->scroll_amt < 0) ! 213: FlushScroll(screen); ! 214: screen->scroll_amt = amount; ! 215: screen->refresh_amt = amount; ! 216: } ! 217: refreshheight = 0; ! 218: } else { ! 219: ! 220: if (amount == i) { ! 221: ClearScreen(screen); ! 222: return; ! 223: } ! 224: shift = -screen->topline; ! 225: bot = screen->max_row - shift; ! 226: scrollheight = i - amount; ! 227: refreshheight = amount; ! 228: if((refreshtop = screen->bot_marg - refreshheight + 1 + shift) > ! 229: (i = screen->max_row - refreshheight + 1)) ! 230: refreshtop = i; ! 231: if(screen->scrollWindow && !screen->alternate ! 232: && screen->top_marg == 0) { ! 233: scrolltop = 0; ! 234: if((scrollheight += shift) > i) ! 235: scrollheight = i; ! 236: if((i = screen->savedlines) < screen->savelines) { ! 237: if((i += amount) > screen->savelines) ! 238: i = screen->savelines; ! 239: screen->savedlines = i; ! 240: ScrollBarDrawThumb(screen->scrollWindow); ! 241: } ! 242: } else { ! 243: scrolltop = screen->top_marg + shift; ! 244: if((i = screen->bot_marg - bot) > 0) { ! 245: scrollheight -= i; ! 246: if((i = screen->top_marg + amount - 1 - bot) >= 0) { ! 247: refreshtop += i; ! 248: refreshheight -= i; ! 249: } ! 250: } ! 251: } ! 252: if(scrollheight > 0) { ! 253: if (screen->multiscroll ! 254: && amount==1 && screen->topline == 0 ! 255: && screen->top_marg==0 ! 256: && screen->bot_marg==screen->max_row) { ! 257: if (screen->incopy<0 && screen->scrolls==0) ! 258: CopyWait(screen); ! 259: screen->scrolls++; ! 260: } else { ! 261: if (screen->incopy) ! 262: CopyWait(screen); ! 263: screen->incopy = -1; ! 264: } ! 265: ! 266: XCopyArea( ! 267: screen->display, ! 268: TextWindow(screen), ! 269: TextWindow(screen), ! 270: screen->normalGC, ! 271: (int) screen->border + screen->scrollbar, ! 272: (int) (scrolltop+amount) * FontHeight(screen) + screen->border, ! 273: (unsigned) Width(screen), ! 274: (unsigned) scrollheight * FontHeight(screen), ! 275: (int) screen->border + screen->scrollbar, ! 276: (int) scrolltop * FontHeight(screen) + screen->border); ! 277: } ! 278: if(refreshheight > 0) { ! 279: XClearArea ( ! 280: screen->display, ! 281: TextWindow(screen), ! 282: (int) screen->border + screen->scrollbar, ! 283: (int) refreshtop * FontHeight(screen) + screen->border, ! 284: (unsigned) Width(screen), ! 285: (unsigned) refreshheight * FontHeight(screen), ! 286: FALSE); ! 287: if(refreshheight > shift) ! 288: refreshheight = shift; ! 289: } ! 290: } ! 291: if(screen->scrollWindow && !screen->alternate && screen->top_marg == 0) ! 292: ScrnDeleteLine(screen->allbuf, screen->bot_marg + ! 293: screen->savelines, 0, amount, screen->max_col + 1); ! 294: else ! 295: ScrnDeleteLine(screen->buf, screen->bot_marg, screen->top_marg, ! 296: amount, screen->max_col + 1); ! 297: if(refreshheight > 0) ! 298: ScrnRefresh(screen, refreshtop, 0, refreshheight, ! 299: screen->max_col + 1); ! 300: } ! 301: ! 302: ! 303: /* ! 304: * Reverse scrolls the screen by amount lines, erases top, doesn't alter ! 305: * cursor position (i.e. cursor moves up amount relative to text). ! 306: * All done within the scrolling region, of course. ! 307: * Requires: amount > 0 ! 308: */ ! 309: RevScroll(screen, amount) ! 310: register TScreen *screen; ! 311: register int amount; ! 312: { ! 313: register int i = screen->bot_marg - screen->top_marg + 1; ! 314: register int shift; ! 315: register int bot; ! 316: register int refreshtop; ! 317: register int refreshheight; ! 318: register int scrolltop; ! 319: register int scrollheight; ! 320: ! 321: if(screen->cursor_state) ! 322: HideCursor(); ! 323: if (amount > i) ! 324: amount = i; ! 325: if(screen->jumpscroll) { ! 326: if(screen->scroll_amt < 0) { ! 327: if(-screen->refresh_amt + amount > i) ! 328: FlushScroll(screen); ! 329: screen->scroll_amt -= amount; ! 330: screen->refresh_amt -= amount; ! 331: } else { ! 332: if(screen->scroll_amt > 0) ! 333: FlushScroll(screen); ! 334: screen->scroll_amt = -amount; ! 335: screen->refresh_amt = -amount; ! 336: } ! 337: } else { ! 338: shift = -screen->topline; ! 339: bot = screen->max_row - shift; ! 340: refreshheight = amount; ! 341: scrollheight = screen->bot_marg - screen->top_marg - ! 342: refreshheight + 1; ! 343: refreshtop = screen->top_marg + shift; ! 344: scrolltop = refreshtop + refreshheight; ! 345: if((i = screen->bot_marg - bot) > 0) ! 346: scrollheight -= i; ! 347: if((i = screen->top_marg + refreshheight - 1 - bot) > 0) ! 348: refreshheight -= i; ! 349: if(scrollheight > 0) { ! 350: if (screen->multiscroll ! 351: && amount==1 && screen->topline == 0 ! 352: && screen->top_marg==0 ! 353: && screen->bot_marg==screen->max_row) { ! 354: if (screen->incopy<0 && screen->scrolls==0) ! 355: CopyWait(screen); ! 356: screen->scrolls++; ! 357: } else { ! 358: if (screen->incopy) ! 359: CopyWait(screen); ! 360: screen->incopy = -1; ! 361: } ! 362: ! 363: XCopyArea ( ! 364: screen->display, ! 365: TextWindow(screen), ! 366: TextWindow(screen), ! 367: screen->normalGC, ! 368: (int) screen->border + screen->scrollbar, ! 369: (int) (scrolltop-amount) * FontHeight(screen) + screen->border, ! 370: (unsigned) Width(screen), ! 371: (unsigned) scrollheight * FontHeight(screen), ! 372: (int) screen->border + screen->scrollbar, ! 373: (int) scrolltop * FontHeight(screen) + screen->border); ! 374: } ! 375: if(refreshheight > 0) ! 376: XClearArea ( ! 377: screen->display, ! 378: TextWindow(screen), ! 379: (int) screen->border + screen->scrollbar, ! 380: (int) refreshtop * FontHeight(screen) + screen->border, ! 381: (unsigned) Width(screen), ! 382: (unsigned) refreshheight * FontHeight(screen), ! 383: FALSE); ! 384: } ! 385: ScrnInsertLine (screen->buf, screen->bot_marg, screen->top_marg, ! 386: amount, screen->max_col + 1); ! 387: } ! 388: ! 389: /* ! 390: * If cursor not in scrolling region, returns. Else, ! 391: * inserts n blank lines at the cursor's position. Lines above the ! 392: * bottom margin are lost. ! 393: */ ! 394: InsertLine (screen, n) ! 395: register TScreen *screen; ! 396: register int n; ! 397: { ! 398: register int i; ! 399: register int shift; ! 400: register int bot; ! 401: register int refreshtop; ! 402: register int refreshheight; ! 403: register int scrolltop; ! 404: register int scrollheight; ! 405: ! 406: if (screen->cur_row < screen->top_marg || ! 407: screen->cur_row > screen->bot_marg) ! 408: return; ! 409: if(screen->cursor_state) ! 410: HideCursor(); ! 411: screen->do_wrap = 0; ! 412: if (n > (i = screen->bot_marg - screen->cur_row + 1)) ! 413: n = i; ! 414: if(screen->jumpscroll) { ! 415: if(screen->scroll_amt <= 0 && ! 416: screen->cur_row <= -screen->refresh_amt) { ! 417: if(-screen->refresh_amt + n > screen->max_row + 1) ! 418: FlushScroll(screen); ! 419: screen->scroll_amt -= n; ! 420: screen->refresh_amt -= n; ! 421: } else if(screen->scroll_amt) ! 422: FlushScroll(screen); ! 423: } ! 424: if(!screen->scroll_amt) { ! 425: shift = -screen->topline; ! 426: bot = screen->max_row - shift; ! 427: refreshheight = n; ! 428: scrollheight = screen->bot_marg - screen->cur_row - refreshheight + 1; ! 429: refreshtop = screen->cur_row + shift; ! 430: scrolltop = refreshtop + refreshheight; ! 431: if((i = screen->bot_marg - bot) > 0) ! 432: scrollheight -= i; ! 433: if((i = screen->cur_row + refreshheight - 1 - bot) > 0) ! 434: refreshheight -= i; ! 435: if(scrollheight > 0) { ! 436: if (screen->incopy) ! 437: CopyWait (screen); ! 438: screen->incopy = -1; ! 439: XCopyArea ( ! 440: screen->display, ! 441: TextWindow(screen), ! 442: TextWindow(screen), ! 443: screen->normalGC, ! 444: (int) screen->border + screen->scrollbar, ! 445: (int) (scrolltop - n) * FontHeight(screen) + screen->border, ! 446: (unsigned) Width(screen), ! 447: (unsigned) scrollheight * FontHeight(screen), ! 448: (int) screen->border + screen->scrollbar, ! 449: (int) scrolltop * FontHeight(screen) + screen->border); ! 450: } ! 451: if(refreshheight > 0) ! 452: XClearArea ( ! 453: screen->display, ! 454: TextWindow(screen), ! 455: (int) screen->border + screen->scrollbar, ! 456: (int) refreshtop * FontHeight(screen) + screen->border, ! 457: (unsigned) Width(screen), ! 458: (unsigned) refreshheight * FontHeight(screen), ! 459: FALSE); ! 460: } ! 461: /* adjust screen->buf */ ! 462: ScrnInsertLine(screen->buf, screen->bot_marg, screen->cur_row, n, ! 463: screen->max_col + 1); ! 464: } ! 465: ! 466: /* ! 467: * If cursor not in scrolling region, returns. Else, deletes n lines ! 468: * at the cursor's position, lines added at bottom margin are blank. ! 469: */ ! 470: DeleteLine(screen, n) ! 471: register TScreen *screen; ! 472: register int n; ! 473: { ! 474: register int i; ! 475: register int shift; ! 476: register int bot; ! 477: register int refreshtop; ! 478: register int refreshheight; ! 479: register int scrolltop; ! 480: register int scrollheight; ! 481: ! 482: if (screen->cur_row < screen->top_marg || ! 483: screen->cur_row > screen->bot_marg) ! 484: return; ! 485: if(screen->cursor_state) ! 486: HideCursor(); ! 487: screen->do_wrap = 0; ! 488: if (n > (i = screen->bot_marg - screen->cur_row + 1)) ! 489: n = i; ! 490: if(screen->jumpscroll) { ! 491: if(screen->scroll_amt >= 0 && screen->cur_row == screen->top_marg) { ! 492: if(screen->refresh_amt + n > screen->max_row + 1) ! 493: FlushScroll(screen); ! 494: screen->scroll_amt += n; ! 495: screen->refresh_amt += n; ! 496: } else if(screen->scroll_amt) ! 497: FlushScroll(screen); ! 498: } ! 499: if(!screen->scroll_amt) { ! 500: ! 501: shift = -screen->topline; ! 502: bot = screen->max_row - shift; ! 503: scrollheight = i - n; ! 504: refreshheight = n; ! 505: if((refreshtop = screen->bot_marg - refreshheight + 1 + shift) > ! 506: (i = screen->max_row - refreshheight + 1)) ! 507: refreshtop = i; ! 508: if(screen->scrollWindow && !screen->alternate && screen->cur_row == 0) { ! 509: scrolltop = 0; ! 510: if((scrollheight += shift) > i) ! 511: scrollheight = i; ! 512: if((i = screen->savedlines) < screen->savelines) { ! 513: if((i += n) > screen->savelines) ! 514: i = screen->savelines; ! 515: screen->savedlines = i; ! 516: ScrollBarDrawThumb(screen->scrollWindow); ! 517: } ! 518: } else { ! 519: scrolltop = screen->cur_row + shift; ! 520: if((i = screen->bot_marg - bot) > 0) { ! 521: scrollheight -= i; ! 522: if((i = screen->cur_row + n - 1 - bot) >= 0) { ! 523: refreshheight -= i; ! 524: } ! 525: } ! 526: } ! 527: if(scrollheight > 0) { ! 528: if (screen->incopy) ! 529: CopyWait(screen); ! 530: screen->incopy = -1; ! 531: ! 532: XCopyArea ( ! 533: screen->display, ! 534: TextWindow(screen), ! 535: TextWindow(screen), ! 536: screen->normalGC, ! 537: (int) screen->border + screen->scrollbar, ! 538: (int) (scrolltop + n) * FontHeight(screen) + screen->border, ! 539: (unsigned) Width(screen), ! 540: (unsigned) scrollheight * FontHeight(screen), ! 541: (int) screen->border + screen->scrollbar, ! 542: (int) scrolltop * FontHeight(screen) + screen->border); ! 543: } ! 544: if(refreshheight > 0) ! 545: XClearArea ( ! 546: screen->display, ! 547: TextWindow(screen), ! 548: (int) screen->border + screen->scrollbar, ! 549: (int) refreshtop * FontHeight(screen) + screen->border, ! 550: (unsigned) Width(screen), ! 551: (unsigned) refreshheight * FontHeight(screen), ! 552: FALSE); ! 553: } ! 554: /* adjust screen->buf */ ! 555: if(screen->scrollWindow && !screen->alternate && screen->cur_row == 0) ! 556: ScrnDeleteLine(screen->allbuf, screen->bot_marg + ! 557: screen->savelines, 0, n, screen->max_col + 1); ! 558: else ! 559: ScrnDeleteLine(screen->buf, screen->bot_marg, screen->cur_row, ! 560: n, screen->max_col + 1); ! 561: } ! 562: ! 563: /* ! 564: * Insert n blanks at the cursor's position, no wraparound ! 565: */ ! 566: InsertChar (screen, n) ! 567: register TScreen *screen; ! 568: register int n; ! 569: { ! 570: register int width = n * FontWidth(screen), cx, cy; ! 571: ! 572: if(screen->cursor_state) ! 573: HideCursor(); ! 574: screen->do_wrap = 0; ! 575: if(screen->cur_row - screen->topline <= screen->max_row) { ! 576: if(!AddToRefresh(screen)) { ! 577: if(screen->scroll_amt) ! 578: FlushScroll(screen); ! 579: ! 580: if (screen->incopy) ! 581: CopyWait (screen); ! 582: screen->incopy = -1; ! 583: ! 584: cx = CursorX (screen, screen->cur_col); ! 585: cy = CursorY (screen, screen->cur_row); ! 586: XCopyArea( ! 587: screen->display, ! 588: TextWindow(screen), TextWindow(screen), ! 589: screen->normalGC, ! 590: cx, cy, ! 591: (unsigned) Width(screen) ! 592: - (screen->cur_col + n) * FontWidth(screen), ! 593: (unsigned) FontHeight(screen), ! 594: cx + width, cy); ! 595: XFillRectangle( ! 596: screen->display, ! 597: TextWindow(screen), ! 598: screen->reverseGC, ! 599: cx, cy, ! 600: (unsigned) width, (unsigned) FontHeight(screen)); ! 601: } ! 602: } ! 603: /* adjust screen->buf */ ! 604: ScrnInsertChar(screen->buf, screen->cur_row, screen->cur_col, n, ! 605: screen->max_col + 1); ! 606: } ! 607: ! 608: /* ! 609: * Deletes n chars at the cursor's position, no wraparound. ! 610: */ ! 611: DeleteChar (screen, n) ! 612: register TScreen *screen; ! 613: register int n; ! 614: { ! 615: register int width, cx, cy; ! 616: ! 617: if(screen->cursor_state) ! 618: HideCursor(); ! 619: screen->do_wrap = 0; ! 620: if (n > (width = screen->max_col + 1 - screen->cur_col)) ! 621: n = width; ! 622: ! 623: if(screen->cur_row - screen->topline <= screen->max_row) { ! 624: if(!AddToRefresh(screen)) { ! 625: if(screen->scroll_amt) ! 626: FlushScroll(screen); ! 627: ! 628: width = n * FontWidth(screen); ! 629: ! 630: if (screen->incopy) ! 631: CopyWait (screen); ! 632: screen->incopy = -1; ! 633: ! 634: cx = CursorX (screen, screen->cur_col); ! 635: cy = CursorY (screen, screen->cur_row); ! 636: XCopyArea(screen->display, ! 637: TextWindow(screen), TextWindow(screen), ! 638: screen->normalGC, ! 639: cx + width, cy, ! 640: Width(screen) - (screen->cur_col + n) * FontWidth(screen), ! 641: FontHeight(screen), ! 642: cx, cy); ! 643: XFillRectangle (screen->display, TextWindow(screen), ! 644: screen->reverseGC, ! 645: screen->border + screen->scrollbar + Width(screen) - width, ! 646: cy, width, FontHeight(screen)); ! 647: } ! 648: } ! 649: /* adjust screen->buf */ ! 650: ScrnDeleteChar (screen->buf, screen->cur_row, screen->cur_col, n, ! 651: screen->max_col + 1); ! 652: ! 653: } ! 654: ! 655: /* ! 656: * Clear from cursor position to beginning of display, inclusive. ! 657: */ ! 658: ClearAbove (screen) ! 659: register TScreen *screen; ! 660: { ! 661: register top, height; ! 662: ! 663: if(screen->cursor_state) ! 664: HideCursor(); ! 665: if((top = -screen->topline) <= screen->max_row) { ! 666: if(screen->scroll_amt) ! 667: FlushScroll(screen); ! 668: if((height = screen->cur_row + top) > screen->max_row) ! 669: height = screen->max_row; ! 670: if((height -= top) > 0) ! 671: XClearArea(screen->display, TextWindow(screen), ! 672: screen->border + screen->scrollbar, top * ! 673: FontHeight(screen) + screen->border, ! 674: Width(screen), height * FontHeight(screen), FALSE); ! 675: ! 676: if(screen->cur_row - screen->topline <= screen->max_row) ! 677: ClearLeft(screen); ! 678: } ! 679: ClearBufRows(screen, 0, screen->cur_row - 1); ! 680: } ! 681: ! 682: /* ! 683: * Clear from cursor position to end of display, inclusive. ! 684: */ ! 685: ClearBelow (screen) ! 686: register TScreen *screen; ! 687: { ! 688: register top; ! 689: ! 690: ClearRight(screen); ! 691: if((top = screen->cur_row - screen->topline) <= screen->max_row) { ! 692: if(screen->scroll_amt) ! 693: FlushScroll(screen); ! 694: if(++top <= screen->max_row) ! 695: XClearArea(screen->display, TextWindow(screen), ! 696: screen->border + screen->scrollbar, top * ! 697: FontHeight(screen) + screen->border, ! 698: Width(screen), (screen->max_row - top + 1) * ! 699: FontHeight(screen), FALSE); ! 700: } ! 701: ClearBufRows(screen, screen->cur_row + 1, screen->max_row); ! 702: } ! 703: ! 704: /* ! 705: * Clear last part of cursor's line, inclusive. ! 706: */ ! 707: ClearRight (screen) ! 708: register TScreen *screen; ! 709: { ! 710: if(screen->cursor_state) ! 711: HideCursor(); ! 712: screen->do_wrap = 0; ! 713: if(screen->cur_row - screen->topline <= screen->max_row) { ! 714: if(!AddToRefresh(screen)) { ! 715: if(screen->scroll_amt) ! 716: FlushScroll(screen); ! 717: XFillRectangle(screen->display, TextWindow(screen), ! 718: screen->reverseGC, ! 719: CursorX(screen, screen->cur_col), ! 720: CursorY(screen, screen->cur_row), ! 721: Width(screen) - screen->cur_col * FontWidth(screen), ! 722: FontHeight(screen)); ! 723: } ! 724: } ! 725: bzero(screen->buf [2 * screen->cur_row] + screen->cur_col, ! 726: (screen->max_col - screen->cur_col + 1)); ! 727: bzero(screen->buf [2 * screen->cur_row + 1] + screen->cur_col, ! 728: (screen->max_col - screen->cur_col + 1)); ! 729: } ! 730: ! 731: /* ! 732: * Clear first part of cursor's line, inclusive. ! 733: */ ! 734: ClearLeft (screen) ! 735: register TScreen *screen; ! 736: { ! 737: if(screen->cursor_state) ! 738: HideCursor(); ! 739: screen->do_wrap = 0; ! 740: if(screen->cur_row - screen->topline <= screen->max_row) { ! 741: if(!AddToRefresh(screen)) { ! 742: if(screen->scroll_amt) ! 743: FlushScroll(screen); ! 744: XFillRectangle (screen->display, TextWindow(screen), ! 745: screen->reverseGC, ! 746: screen->border + screen->scrollbar, ! 747: CursorY (screen, screen->cur_row), ! 748: (screen->cur_col + 1) * FontWidth(screen), ! 749: FontHeight(screen)); ! 750: } ! 751: } ! 752: bzero (screen->buf [2 * screen->cur_row], (screen->cur_col + 1)); ! 753: bzero (screen->buf [2 * screen->cur_row + 1], (screen->cur_col + 1)); ! 754: } ! 755: ! 756: /* ! 757: * Erase the cursor's line. ! 758: */ ! 759: ClearLine(screen) ! 760: register TScreen *screen; ! 761: { ! 762: if(screen->cursor_state) ! 763: HideCursor(); ! 764: screen->do_wrap = 0; ! 765: if(screen->cur_row - screen->topline <= screen->max_row) { ! 766: if(!AddToRefresh(screen)) { ! 767: if(screen->scroll_amt) ! 768: FlushScroll(screen); ! 769: XFillRectangle (screen->display, TextWindow(screen), ! 770: screen->reverseGC, ! 771: screen->border + screen->scrollbar, ! 772: CursorY (screen, screen->cur_row), ! 773: Width(screen), FontHeight(screen)); ! 774: } ! 775: } ! 776: bzero (screen->buf [2 * screen->cur_row], (screen->max_col + 1)); ! 777: bzero (screen->buf [2 * screen->cur_row + 1], (screen->max_col + 1)); ! 778: } ! 779: ! 780: ClearScreen(screen) ! 781: register TScreen *screen; ! 782: { ! 783: register int top; ! 784: ! 785: if(screen->cursor_state) ! 786: HideCursor(); ! 787: screen->do_wrap = 0; ! 788: if((top = -screen->topline) <= screen->max_row) { ! 789: if(screen->scroll_amt) ! 790: FlushScroll(screen); ! 791: if(top == 0) ! 792: XClearWindow(screen->display, TextWindow(screen)); ! 793: else ! 794: XClearArea(screen->display, TextWindow(screen), ! 795: screen->border + screen->scrollbar, ! 796: top * FontHeight(screen) + screen->border, ! 797: Width(screen), (screen->max_row - top + 1) * ! 798: FontHeight(screen), FALSE); ! 799: } ! 800: ClearBufRows (screen, 0, screen->max_row); ! 801: } ! 802: ! 803: CopyWait(screen) ! 804: register TScreen *screen; ! 805: { ! 806: XEvent reply; ! 807: XEvent *rep = &reply; ! 808: ! 809: while (1) { ! 810: XWindowEvent (screen->display, VWindow(screen), ! 811: ExposureMask, &reply); ! 812: switch (reply.type) { ! 813: case Expose: ! 814: HandleExposure (screen, (XExposeEvent *) &reply); ! 815: break; ! 816: case NoExpose: ! 817: case GraphicsExpose: ! 818: if (screen->incopy <= 0) { ! 819: screen->incopy = 1; ! 820: if (screen->scrolls > 0) ! 821: screen->scrolls--; ! 822: } ! 823: if (reply.type == GraphicsExpose) ! 824: HandleExposure (screen, (XExposeEvent *) &reply); ! 825: ! 826: if ((reply.type == NoExpose) || ! 827: ((XExposeEvent *)rep)->count == 0) { ! 828: if (screen->incopy <= 0 && screen->scrolls > 0) ! 829: screen->scrolls--; ! 830: if (screen->scrolls == 0) { ! 831: screen->incopy = 0; ! 832: return; ! 833: } ! 834: screen->incopy = -1; ! 835: } ! 836: break; ! 837: } ! 838: } ! 839: } ! 840: /* ! 841: * This routine handles exposure events ! 842: */ ! 843: HandleExposure (screen, reply) ! 844: register TScreen *screen; ! 845: register XExposeEvent *reply; ! 846: { ! 847: register int toprow, leftcol, nrows, ncols; ! 848: extern Terminal term; /* kludge */ ! 849: ! 850: if((toprow = (reply->y - screen->border) / ! 851: FontHeight(screen)) < 0) ! 852: toprow = 0; ! 853: if((leftcol = (reply->x - screen->border - screen->scrollbar) ! 854: / FontWidth(screen)) < 0) ! 855: leftcol = 0; ! 856: nrows = (reply->y + reply->height - 1 - screen->border) / ! 857: FontHeight(screen) - toprow + 1; ! 858: ncols = ! 859: (reply->x + reply->width - 1 - screen->border - screen->scrollbar) / ! 860: FontWidth(screen) - leftcol + 1; ! 861: toprow -= screen->scrolls; ! 862: if (toprow < 0) { ! 863: nrows += toprow; ! 864: toprow = 0; ! 865: } ! 866: if (toprow + nrows - 1 > screen->max_row) ! 867: nrows = screen->max_row - toprow + 1; ! 868: if (leftcol + ncols - 1 > screen->max_col) ! 869: ncols = screen->max_col - leftcol + 1; ! 870: ! 871: if (nrows > 0 && ncols > 0) { ! 872: ScrnRefresh (screen, toprow, leftcol, nrows, ncols); ! 873: if (screen->cur_row >= toprow && ! 874: screen->cur_row < toprow + nrows && ! 875: screen->cur_col >= leftcol && ! 876: screen->cur_col < leftcol + ncols) ! 877: return (1); ! 878: } ! 879: return (0); ! 880: } ! 881: ! 882: ReverseVideo (term) ! 883: Terminal *term; ! 884: { ! 885: register TScreen *screen = &term->screen; ! 886: register GC tmpGC; ! 887: register int tmp; ! 888: register Window tek = TWindow(screen); ! 889: ! 890: tmp = screen->background; ! 891: if(screen->cursorcolor == screen->foreground) ! 892: screen->cursorcolor = tmp; ! 893: if(screen->mousecolor == screen->foreground) ! 894: screen->mousecolor = tmp; ! 895: screen->background = screen->foreground; ! 896: screen->foreground = tmp; ! 897: ! 898: tmpGC = screen->normalGC; ! 899: screen->normalGC = screen->reverseGC; ! 900: screen->reverseGC = tmpGC; ! 901: ! 902: tmpGC = screen->normalboldGC; ! 903: screen->normalboldGC = screen->reverseboldGC; ! 904: screen->reverseboldGC = tmpGC; ! 905: ! 906: screen->color = (screen->color & ~C_FBMASK) | switchfb[screen->color ! 907: & C_FBMASK]; ! 908: ! 909: ! 910: XFreeCursor(screen->display, screen->curs); ! 911: if (XStrCmp(curs_shape, "arrow") == 0) { ! 912: screen->curs = make_arrow(screen->mousecolor, screen->background); ! 913: } else { ! 914: screen->curs = make_xterm(screen->mousecolor, screen->background); ! 915: } ! 916: XFreeCursor(screen->display, screen->arrow); ! 917: screen->arrow = make_arrow(screen->mousecolor, screen->background); ! 918: ! 919: XDefineCursor(screen->display, TextWindow(screen), screen->curs); ! 920: if(tek) ! 921: XDefineCursor(screen->display, tek, screen->arrow); ! 922: #ifdef MODEMENU ! 923: MenuNewCursor(screen->arrow); ! 924: #endif MODEMENU ! 925: ! 926: if (screen->borderwidth && screen->bordercolor == screen->background ! 927: && (screen->foreground)) { ! 928: screen->bordercolor = screen->foreground; ! 929: XSetWindowBorder(screen->display, TextWindow(screen), screen->foreground); ! 930: if(tek) { ! 931: XSetWindowBorder(screen->display, tek,screen->foreground ); ! 932: } ! 933: } ! 934: ! 935: if(screen->scrollWindow) ! 936: ScrollBarReverseVideo(screen->scrollWindow); ! 937: ! 938: XSetWindowBackground(screen->display, TextWindow(screen), screen->background); ! 939: if(tek) { ! 940: TekReverseVideo(screen); ! 941: } ! 942: XClearWindow(screen->display, TextWindow(screen)); ! 943: ScrnRefresh (screen, 0, 0, screen->max_row + 1, ! 944: screen->max_col + 1); ! 945: if(screen->Tshow) { ! 946: XClearWindow(screen->display, tek); ! 947: TekExpose((XExposeEvent *) NULL); ! 948: } ! 949: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.