Annotation of os2sdk/demos/apps/ds/display.c, revision 1.1.1.2

1.1.1.2 ! root        1: /*  display.c - screen display stuff for tree      */
        !             2: /*  Created by Microsoft Corp. 1986  */
        !             3: 
1.1       root        4: 
                      5: #include <conio.h>
                      6: #include <process.h>
                      7: #include <stdio.h>
                      8: #include <stdlib.h>
                      9: 
                     10: #include "ds.h"
                     11: #include "vars.h"
                     12: 
                     13: 
                     14: /*  External routines */
                     15: 
                     16: extern pruneTree (Directory **);
                     17: 
                     18: 
                     19: /*  Local variables */
                     20: 
                     21: static char helpMsg[] = "Press F1 for Help";
                     22: 
                     23: 
                     24: /***   getKey - return two-byte key stroke; includes IBM extended ASCII codes
                     25: *
                     26: *
                     27: */
1.1.1.2 ! root       28: UINT getKey ()
1.1       root       29: {
                     30:     char c;
1.1.1.2 ! root       31:     UINT key;
1.1       root       32: 
                     33:     if (c = getch())               /* Get character */
                     34:        key = c << 8;               /* Make scan code zero */
                     35:     else
                     36:        key = getch();              /* Get scan code */
                     37: }   /* getKey */
                     38: 
                     39: 
                     40: /***   screenInit - Initialize the screen
                     41: *
                     42: *
                     43: */
                     44: screenInit ()
                     45: {
1.1.1.2 ! root       46:     VIOMODEINFO TheModeData;   /* Mode return data from VIOGETMODE */
1.1       root       47: 
1.1.1.2 ! root       48:     VioGetMode (&TheModeData, VioHandle);
1.1       root       49:     N_of_Cols = TheModeData.col;
                     50:     N_of_Rows = TheModeData.row;
                     51:     WINDOW_RIGHT = N_of_Cols - 1;
                     52:     WINDOW_BOTTOM = N_of_Rows - 1;
                     53:     WINDOW_SIZE = WINDOW_BOTTOM - WINDOW_TOP + 1;
                     54: }   /* screenInit */
                     55: 
                     56: 
                     57: /***   handleDisplay - display tree and handel user keystrokes
                     58: *
                     59: *
                     60: */
                     61: handleDisplay (root)
                     62: Directory   *root;
                     63: {
                     64:     int topRow;
1.1.1.2 ! root       65:     UINT key;
1.1       root       66:     char tmp[MAX_PATH_LEN];
                     67:     char path[MAX_PATH_LEN];
                     68:     int imageRow;
                     69:     Directory *curDir,*lastDir,*p;
                     70:     int rc;
1.1.1.2 ! root       71:     NPCH commandPath;
1.1       root       72: 
                     73:     LastTopRow = LastRow-WINDOW_SIZE+1; /* Top row when last row displayed */
                     74:                                        /*   at the bottom of the window */
                     75:     if (LastTopRow < 0)
                     76:        LastTopRow = 0;
                     77: 
                     78:     topRow = 0;
                     79:     displayWindow (WINDOW_TOP,topRow,WINDOW_SIZE);
                     80:     curDir = root->d_child;
                     81:     highlightDir (topRow, curDir, color[cursorC]);
                     82:     key = 0;
                     83:     while (key != exitKey) {
                     84:        lastDir = curDir;
                     85:        key = getKey();
                     86:        switch (key) {
                     87:            case optKey:
                     88:                showOption ();
                     89:                refreshDisplay (topRow, curDir);
                     90:                break;
                     91:            case helpKey:
                     92:                showHelp ();
                     93:                refreshDisplay (topRow, curDir);
                     94:                break;
                     95:            case enterKey:                    /* Exec shell */
                     96:                p = curDir;
                     97:                path[0] = '\0';               /* Empty path */
                     98:                while (p->d_parent) {         /* Process all but root */
                     99:                    strcpy (tmp, path);       /* Save path so far */
                    100:                    strcpy (path,"\\");       /* Put in separator */
                    101:                    strcat (path, p->d_name); /* Append directory name */
                    102:                    strcat (path, tmp);       /* Append rest of path so far */
                    103:                    p = p->d_parent;          /* Go up to parent */
                    104:                }
                    105:                strcpy (tmp, path);           /* Save tail of path */
                    106:                strcpy (path, IntRootPath);   /* Get root path */
                    107:                strcat (path, tmp);           /* Append tail of path */
                    108: 
                    109:                if (chdir(path) == -1)        /* Change directory failed */
                    110:                    pruneTree (&curDir);      /* Node is gone, update tree */
                    111:                else {
                    112:                    commandPath = getenv ("COMSPEC");   /* Get shell path */
                    113:                    clearBottomLine ();
                    114:                    if (commandPath)
                    115:                        rc = spawnl(P_WAIT,commandPath,"COMMAND",NULL);
                    116:                    else
                    117:                        rc = spawnlp(P_WAIT,"COMMAND","COMMAND",NULL);
                    118:                    if (rc == -1) {               /* Exec failed */
                    119:                        perror ("\nCouldn't spawn shell");
                    120:                        exitError (2);
                    121:                    }
                    122:                    clearScreen ();
                    123:                }
                    124:                refreshDisplay (topRow, curDir);
                    125:                break;
                    126:            case upKey:                       /* Go to previous sibling */
                    127:                if (curDir->d_prev)           /* Previous sibling exists */
                    128:                    curDir = curDir->d_prev;  /* Go to previous sibling */
                    129:                break;
                    130:            case downKey:                     /* Go to next sibling */
                    131:                if (curDir->d_next)           /* Next sibling exists */
                    132:                    curDir = curDir->d_next;  /* Go to next sibling */
                    133:                break;
                    134:            case leftKey:               /* Go to parent */
                    135:                if (curDir->d_parent->d_parent) /* Not top level directory */
                    136:                    curDir = curDir->d_parent;  /* Go to parent */
                    137:                break;
                    138:            case rightKey:              /* Go to first child */
                    139:                if (curDir->d_child)    /* Child exists */
                    140:                    curDir = curDir->d_child;  /* Go to child */
                    141:                break;
                    142:            default:
                    143:                break;
                    144:        }   /* switch */
                    145:        if (curDir != lastDir)
                    146:            adjustWindow (&topRow, curDir, lastDir);
                    147:     }  /* while */
                    148: }   /* handleDisplay */
                    149: 
                    150: 
                    151: /***   clearScreen - blank out the entire screen
                    152: *
                    153: *
                    154: */
                    155: clearScreen ()
                    156: {
                    157:     Cell c;
                    158: 
                    159:     c.ch = ' ';
                    160:     c.at = color[blankC];
1.1.1.2 ! root      161:     VioWrtNCell(cefs(&c), N_of_Rows*N_of_Cols, 0, 0, VioHandle);
1.1       root      162: 
                    163: }   /* clearScreen */
                    164: 
                    165: 
                    166: /***   clearBottomLine - Clear the bottom line on the screen
                    167: *
                    168: *
                    169: */
                    170: clearBottomLine ()
                    171: {
                    172:     Cell c;
                    173: 
                    174:     c.ch = ' ';
                    175:     c.at = color[blankC];
1.1.1.2 ! root      176:     VioWrtNCell(cefs(&c), N_of_Cols, N_of_Rows-1,0, VioHandle);
1.1       root      177: 
                    178: }   /* clearBottomLine */
                    179: 
                    180: 
                    181: /***   refreshDisplay - Repaint the main screen
                    182: *
                    183: *
                    184: */
                    185: refreshDisplay (topRow, curDir)
                    186: int topRow;
                    187: Directory *curDir;
                    188: {
                    189:     int col;
                    190:     char buf[MAX_PATH_LEN];
                    191:     int lStr;
                    192:     Cell c;
                    193:     Attr a;
                    194: 
                    195:     c.ch = '[';
                    196:     c.at = color[statusC];
1.1.1.2 ! root      197:     VioWrtNCell(cefs(&c), 1, 0,0, VioHandle);
1.1       root      198: 
                    199:     lStr = strlen(RootPath);
                    200:     a = color[nameC];
1.1.1.2 ! root      201:     VioWrtCharStrAtt (chfs(RootPath), lStr, 0,1, afs(&a), VioHandle);
1.1       root      202: 
                    203:     c.ch = ']';
                    204:     c.at = color[statusC];
1.1.1.2 ! root      205:     VioWrtNCell(cefs(&c), 1, 0,lStr+1, VioHandle);
1.1       root      206: 
                    207:     lStr = strlen(helpMsg);
                    208:     col = N_of_Cols - lStr;
                    209:     a = color[statusC];
1.1.1.2 ! root      210:     VioWrtCharStrAtt (chfs(helpMsg), lStr, 0,col, afs(&a), VioHandle);
1.1       root      211: 
                    212:     if (topRow >= 0) {
                    213:        displayWindow (WINDOW_TOP,topRow,WINDOW_SIZE);
                    214:        highlightDir (topRow, curDir, color[cursorC]);
                    215:     }
1.1.1.2 ! root      216:     VioSetCurPos (N_of_Rows-1, N_of_Cols-1, VioHandle); /* Hide cursor */
1.1       root      217: }
                    218: 
                    219: 
                    220: /***   adjustWindow - Repaint tree with minimum screen writing
                    221: *
                    222: *
                    223: */
                    224: adjustWindow (topRow, curDir, lastDir)
                    225: int *topRow;
                    226: Directory *curDir;
                    227: Directory *lastDir;
                    228: {
                    229:     int botRow, cRow, lRow;
                    230: 
                    231:     botRow = *topRow + WINDOW_SIZE - 1;
                    232:     cRow = curDir->d_row;
                    233:     lRow = lastDir->d_row;
                    234:     if ((*topRow <= cRow) && (cRow <= botRow)) { /* Window doesn't move */
                    235:        highlightDir (*topRow, lastDir, color[nameC]);  /* Turn off old cursor */
                    236:        highlightDir (*topRow, curDir, color[cursorC]); /* Turn on new cursor */
                    237:     }
                    238:     else if ((cRow <= *topRow - WINDOW_SIZE) ||
                    239:            (botRow + WINDOW_SIZE <= cRow)) {   /* Repaint entire window */
                    240:        *topRow = (cRow < LastTopRow) ? cRow : LastTopRow;
                    241:        displayWindow (WINDOW_TOP,*topRow,WINDOW_SIZE);
                    242:        highlightDir (*topRow, curDir, color[cursorC]);
                    243:     }
                    244:     else {                                     /* Can do a scroll */
                    245:        if (cRow < lRow)        /* Pretend scroll up */
                    246:            *topRow = (cRow < LastTopRow) ? cRow : LastTopRow;
                    247:        else {                  /* Pretend scroll down */
                    248:            cRow = cRow - WINDOW_SIZE + 1;
                    249:            *topRow = cRow ? cRow : 0;
                    250:        }
                    251:        displayWindow (WINDOW_TOP,*topRow,WINDOW_SIZE);
                    252:        highlightDir (*topRow, curDir, color[cursorC]);
                    253:     }
                    254: }   /* adjustWindow */
                    255: 
                    256: 
                    257: /***   highlightDir - Highlight the currently selected directory
                    258: *
                    259: *
                    260: */
                    261: highlightDir (topRow, p, color)
                    262: int topRow;
                    263: Directory *p;
                    264: int color;
                    265: {
1.1.1.2 ! root      266:     USHORT dLen,cCol,cRow;
1.1       root      267:     Attr a;
                    268: 
                    269:     cRow = WINDOW_TOP + p->d_row - topRow;
                    270:     cCol = p->d_col;
                    271: 
                    272:     dLen = strlen(p->d_name);
                    273:     a = color;
1.1.1.2 ! root      274:     VioWrtNAttr (afs(&a), dLen, cRow, cCol, VioHandle);
1.1       root      275: 
                    276: }   /* highlightDir */
                    277: 
                    278: 
1.1.1.2 ! root      279: /***   displayWindow - Display a portion of the tree in the tree window
1.1       root      280: *
                    281: *
                    282: */
                    283: displayWindow (screenRow,imageRow,count)
1.1.1.2 ! root      284: USHORT screenRow,imageRow,count;
1.1       root      285: {
                    286:     int row;
                    287:     Cell c;
                    288: 
                    289:     while (count-- && (imageRow <= LastRow)) {
1.1.1.2 ! root      290:        VioWrtCellStr (cefs(DisplayRow[imageRow]), N_of_Cols*sizeof(Cell),
1.1       root      291:                       screenRow,0, VioHandle);
                    292:        screenRow++;
                    293:        imageRow++;
                    294:     }
                    295:     c.ch = ' ';
                    296:     c.at = color[blankC];
                    297:     for (row=screenRow; row<N_of_Rows; row++)  /* Clear remaining lines */
1.1.1.2 ! root      298:        VioWrtNCell (cefs(&c), N_of_Cols, row,0, VioHandle);
1.1       root      299: }   /* displayWindow */

unix.superglobalmegacorp.com

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