Annotation of 43BSDTahoe/new/X/xterm/util.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.