

{$M+}
{$E+}

PROGRAM Mock;

{$I i:\opus.i}
{$I i:\GCTV.inc}

{$I i:\gemsubs.def}
{$I i:\vdi_aes.def}
{$I i:\globsubs.def}
{$I d:\pascal\opus\xbios.def}
{$I d:\pascal\opus\stringfn.def}

PROCEDURE GET_NUM_SCR_ENTRIES ( direction : ExpandDirection );
   { right expansion is based on start_col;
     left expansion is based on finish_col }
   LABEL 1;
   VAR x_tot,i,j,width : INTEGER;
   BEGIN
        IF start_row < logical_row_1 THEN
           start_row := logical_row_1
        ELSE IF start_row > n_rows THEN
           start_row := n_rows;
        IF start_col < logical_col_1 THEN
           start_col := logical_col_1
        ELSE IF start_col > n_cols THEN
           start_col := n_cols;
        IF finish_col > n_cols THEN
           finish_col := n_cols
        ELSE IF finish_col < logical_col_1 THEN
           finish_col := logical_col_1;   
        Work_Rect(act_hdl,x_1,y_1,w_1,h_1);
1:      h_entry := 0;
        width := w_1-x_margin;
        x_tot := 0;
        i := 1;
        IF direction = ExRight THEN BEGIN
           WHILE i <= max_screen_cols DO BEGIN { right expand }
              IF start_col+i-1 <= n_cols THEN
                 IF x_tot+col_width[start_col+i-1,pixels] < width THEN BEGIN
                    h_entry := h_entry+1;
                    x_tot := x_tot+col_width[start_col+i-1,pixels]
                 END
                 ELSE
                    i := max_screen_cols+1;
              i := i+1
           END;
           IF (start_col > logical_col_1) AND
              (h_entry > 0) THEN { left expand if possible }
              IF x_tot+col_width[start_col-1,pixels] < width THEN BEGIN
                 start_col := start_col-1;
                 GOTO 1
              END;
           IF h_entry < 1 THEN
              h_entry := 1;
           finish_col := start_col+h_entry-1; { no need to check if > n_cols }
           IF finish_col < n_cols THEN BEGIN
              virtual_f_col := finish_col+1;
              virtual_h_entry := h_entry+1
           END
           ELSE BEGIN
              virtual_f_col := finish_col;
              virtual_h_entry := h_entry
           END
        END
        ELSE BEGIN
           WHILE i <= max_screen_cols DO BEGIN { left expand }
              IF finish_col-i+1 >= logical_col_1 THEN
                 IF x_tot+col_width[finish_col-i+1,pixels] < width THEN BEGIN
                    h_entry := h_entry+1;
                    x_tot := x_tot+col_width[finish_col-i+1,pixels]
                 END
                 ELSE
                    i := max_screen_cols+1;
              i := i+1
           END;
           IF (finish_col < n_cols) AND
              (h_entry > 0) THEN { right expand if possible }
              IF x_tot+col_width[finish_col+1,pixels] < width THEN BEGIN
                 finish_col := finish_col+1;
                 GOTO 1
              END;
           IF h_entry < 1 THEN
              h_entry := 1;
           start_col := finish_col-h_entry+1; { no need to check if < }
           IF finish_col < n_cols THEN BEGIN  { logical_col_1 }
              virtual_f_col := finish_col+1;
              virtual_h_entry := h_entry+1
           END
           ELSE BEGIN
              virtual_f_col := finish_col;
              virtual_h_entry := h_entry
           END
        END;   
        v_entry := (h_1-y_margin) DIV cell_height;
        finish_row := start_row+v_entry-1;
        IF finish_row > n_rows THEN
           finish_row := n_rows;
        IF finish_row < n_rows THEN BEGIN
           virtual_f_row := finish_row+1;
           virtual_v_entry := v_entry+1
        END
        ELSE BEGIN
           virtual_f_row := finish_row;
           virtual_v_entry := v_entry
        END;
        IF data_row < start_row THEN
           data_row := start_row
        ELSE IF data_row > finish_row THEN
           data_row := finish_row;
        IF data_col < start_col THEN
           data_col := start_col
        ELSE IF data_col > finish_col THEN
           data_col := finish_col
   END; { GET_NUM_SCR_ENTRIES }

PROCEDURE DEF_VERT_GRID;
   VAR i,j : INTEGER;
   BEGIN
        i := x_1+x_margin;
        j := 1;
        vert_grid[1] := i;
        WHILE j <= virtual_h_entry DO BEGIN
            i := i+col_width[start_col+j-1,pixels];
            vert_grid[j+1] := i;
            j := j+1
        END
   END; { DEF_VERT_GRID }

PROCEDURE DEF_SHEET_AREA;
   BEGIN
       get_num_scr_entries(ExRight);
       def_vert_grid;
       find_screen_pos(data_row,data_col,scr_row,scr_col); { keep current }
       save_attr { most current attributes; ESSENTIAL!!! }
   END; { DEF_SHEET_AREA }

FUNCTION DATA_CLIP : BOOLEAN;
   BEGIN
       data_clip := TRUE;
       Work_Rect(act_hdl,x_1,y_1,w_1,h_1);
       clip_x := x_1+x_margin+1;
       clip_y := y_1+y_margin+1;
       clip_w := w_1-(x_margin+1);
       clip_h := h_1-(y_margin+1);
       IF redraw_flag THEN BEGIN
          IF redraw_x >= clip_x THEN BEGIN { redraw area within data area? }
             clip_x := redraw_x;
             clip_w := redraw_w
          END
          ELSE IF redraw_x+redraw_w > clip_x THEN { width within data area? }
             clip_w := redraw_x+redraw_w-clip_x { set width then }
          ELSE
             data_clip := FALSE; { note that we could set w = 0, but }
          clip_y := redraw_y;    { Set_Clip doesn't seem to work with clip }
          clip_h := redraw_h     { width of zero }
       END;
       Set_Clip(clip_x,clip_y,clip_w,clip_h)
   END; { DATA_CLIP }

PROCEDURE DRAW_SHEET ( extent                              : ExtentType;
                       row_start,row_end,col_start,col_end : INTEGER;
                       blit_flag                           : BOOLEAN );
   LABEL 1;
   VAR
      i,j,k,offset,width,t,t2 : INTEGER;
   BEGIN
        { extent determines which parts of the screen are painted and then
          redrawn. if NoRowNames, for example, the row names as displayed
          are protected from being redrawn by limiting the clipping
          rectangle }
        Work_Rect(act_hdl,x_1,y_1,w_1,h_1);
        CASE extent OF
           NoRowNames : Set_Clip(x_1+x_margin+1,y_1,w_1-x_margin-1,h_1);
           NoColNames : Set_Clip(x_1,y_1+y_margin+1,w_1,h_1-(y_margin+1));
           WholeSheet  : IF redraw_flag THEN
                            Set_Clip(redraw_x,redraw_y,redraw_w,redraw_h)
                         ELSE
                            Set_Clip(x_1,y_1,w_1,h_1);
           JustData    : IF NOT data_clip THEN
                             GOTO 1;
        END; { CASE extent }
        IF NOT blit_flag THEN
           Paint_Rect(x_1,y_1,w_1,h_1);
        Line_Color(LightBlue); 
        Line_Style(Solid);
        width := x_1+w_1;
        Line(x_1,y_1+cell_height-1,width,y_1+cell_height-1);
        IF freeze_row > 0 THEN
           Line(x_1,y_1+y_margin,width,y_1+y_margin);
        IF freeze_col > 0 THEN BEGIN
           Line(x_1+38,y_1,x_1+38,y_1+h_1);
           Line(vert_grid[1],y_1,vert_grid[1],y_1+h_1)
        END
        ELSE   
           Line(vert_grid[1],y_1,vert_grid[1],y_1+h_1);
        t := y_1+y_margin-cell_height+1;
        t2 := y_1+y_margin;
        { set up pts_in array so that we only have to calculate the }
        { vertical coordinates of the lines once }
        FOR k := row_start TO row_end+1 DO
            pts_in[k] := t+k*cell_height;
        IF rez = 1 THEN { high }
           offset := 3
        ELSE
           offset := 2;
        FOR j := col_start+1 TO col_end+1 DO BEGIN { vertical lines... }
            Line_Style(Solid);                     { these are easy    }
            Line(vert_grid[j],y_1,vert_grid[j],t2); { col title separators }
            IF grid_flag THEN BEGIN
               My_Line_Style ($AAAA); { grid }
               FOR k := row_start TO row_end DO
                   Line(vert_grid[j],pts_in[k],vert_grid[j],pts_in[k+1]-offset)
            END   
        END;
        i := y_1+y_margin+row_start*cell_height;
        Line_Style(Solid);
        FOR j := row_start TO row_end DO BEGIN { horizontal lines }
            Line(x_1,i,vert_grid[1],i); { row title separators }
            i := i+cell_height
        END;
        { The big problem in drawing the grid is avoiding shifting lines
          when moving off screen; the screen is blitted in the pertinent
          direction. Now if the pixels in every column of the same width
          are not in exactly the same relative positions, a 'shift' of the
          grid lines occurs upn blitting; this is most annoying. So the first
          step in avoiding this is to break the lines up into segments and
          process them all the same way. This also applies to the vertical grid
          but for some reason that was easy to do. If it were that easy for
          the horizontal lines...
          For the horizontal grid, a line pattern of X X X X... is sufficient
          for mono, if it's drawn as below; this avoids shifting lines when
          the screen is blitted left to right. The line segments are all
          processed in the same way. This also works in
          color, but the 'grid' looks like a dim solid line; no way the monitor
          has 640 pixels resolution. Does a different line-type work? Not that
          I could discover; the VDI does NOT always start a line with the most
          sig. bit of the line style ( why it works in mono I don't know ), and
          varying the offsets from the vertgrids proved fruitless. So, by
          DRAWING lines in color, segments which are different in each column
          appear, and the shifting lines are back. Solution? Process the
          segments by columns, doing all the rows in a column, and begin by
          PLOTTING the pixels in the first row. Then for the remaining rows,
          BLIT a 1-pixel high raster of the plotted points in the position of
          each segment in that column, and plotting every row is just too slow.
          This way, every segment is processed identically, and no more
          shifting lines. }

        IF grid_flag THEN BEGIN
           IF rez = 2 THEN { med rez }
              FOR j := col_start TO col_end DO BEGIN
                  i := y_1+y_margin+row_start*cell_height;
                  IF redraw_flag THEN
                     WHILE i < redraw_y DO BEGIN
                        i := i+cell_height;
                        row_start := row_start+1
                     END;
                  k := vert_grid[j]+2;
                  WHILE k < vert_grid[j+1]-2 DO BEGIN
                     Plot(k,i);
                     k := k+8
                  END;
                  FOR k := row_start+1 TO row_end DO BEGIN
                      Blit(screen_mfdb,screen_mfdb,vert_grid[j]+1,i,
                           vert_grid[j]+1,i+cell_height,
                           vert_grid[j+1]-vert_grid[j],1);
                      i := i+cell_height
                  END
              END
           ELSE BEGIN
              My_Line_Style($AAAA); { grid }
              i := y_1+y_margin+row_start*cell_height;
              FOR j := row_start TO row_end DO BEGIN
                  FOR k := col_start TO col_end DO
                      Line(vert_grid[k]+2,i,vert_grid[k+1]-2,i);
                  i := i+cell_height
              END
           END
        END;   
1: END; (* DRAW_SHEET *)

PROCEDURE TOGGLE_INVERSE ( color,row,col : INTEGER );
   { proc to toggle inverse video on a CELL; uses a Paint_Rect call to do this
     and is very fast as opposed to old method ( see DRAW_INVERSE_VIDEO ),
     since no draw_string is called and needn't worry about format of cell }
   { accepts row,col as sheet not screen coordinates }
   { has already had it's clip rectangle set }
   VAR x,y,w,h,l_scr_row,l_scr_col : INTEGER;
   BEGIN
       find_screen_pos(row,col,l_scr_row,l_scr_col);
       x := vert_grid[l_scr_col]+1;                 { upper left corner }
       y := y_1+y_margin+1+(l_scr_row-1)*cell_height; { of cell }
       w := col_width[col,pixels]-1;
       h := cell_height-1;
       Draw_Mode(XOR_Mode);
       Paint_Color(color);
       Paint_Rect(x,y,w,h);
       Paint_Color(White);
       Draw_Mode(Replace_Mode)
   END; { TOGGLE_INVERSE }

PROCEDURE PREP_CELL ( ptr : CellPtr; VAR temp : STRING );
   BEGIN
       temp := '';
       IF ptr <> NIL THEN
          IF ptr^.status <> Empty THEN
             WITH ptr^ DO
                CASE class OF
                   Val  : prepare_num(ptr,temp);
                   Labl : temp := str^;
                   Expr :
                      IF NOT form_flag THEN { don't display formulas }
                         IF status < OK THEN { error! }
                            temp := error_msg[status]
                         ELSE
                            prepare_num(ptr,temp)
                      ELSE
                         temp := str^
                END
   END; { PREP_CELL }

PROCEDURE SET_STYLE ( format : INTEGER );
   VAR style : INTEGER;
   BEGIN
      IF format & style_mask <> 0 THEN BEGIN
         style := 0;
         IF format & bold_mask <> 0 THEN
            style := style | Bold;
         IF format & italic_mask <> 0 THEN
            style := style | Italics;
         IF format & under_mask <> 0 THEN
            style := style | Underlined;
         Text_Style(style)
      END
   END; { SET_STYLE }
   
PROCEDURE DRAW_CELL ( row,col : INTEGER; force : BOOLEAN );
   { row,col are the positions within the sheet, not the screen positions }
   LABEL 1;
   VAR i,l_scr_row,l_scr_col : INTEGER;
       in_range              : BOOLEAN;
       temp                  : STRING;
       ptr                   : CellPtr;
       a                     : AssignedStatus;
   BEGIN
       { draw cell contents; i.e. extent = just_data, so... }
       IF NOT data_clip THEN
          GOTO 1;
       temp := '';
       { now find out what screen row and col we're in }
       find_screen_pos(row,col,l_scr_row,l_scr_col);
       a := assigned(row,col,ptr);
       { the following lets me move among unassigned cells
         without having to draw a blank cell for them, taking more time and
         possibly writing over assigned ones adjacent to it that overlap.
         However, I can punt this by passing a TRUE 'force' value. Useful
         when I know for sure that I'm NOT moving, i.e. changing cell class,
         updating on-screen cells from within a dialog routine ( sort, prec,
         etc. ) }
       IF (a = Void) OR (a = Desolate) THEN
          IF NOT force THEN BEGIN { force = true forces a draw of the cell }
             toggle_inverse(Black,row,col);
             GOTO 1
          END;
       IF block_set THEN
          in_range := (row >= b_s_row) AND (row <= b_e_row) AND
                      (col >= b_s_col) AND (col <= b_e_col)
       ELSE
          in_range := FALSE;
       prep_cell(ptr,temp); { we know we're going to draw }
       total := 0;
       y_pos := y_1+y_margin+cell_height+(l_scr_row-1)*cell_height-1;
       { must first blank out the cell to be sure that when we draw
         this one, nothing from adjacent cells spills into it }
       Paint_Rect(vert_grid[l_scr_col]+1,y_pos-cell_height+2,
                  col_width[col,pixels]-1,cell_height-1);
       IF ptr <> NIL THEN
          WITH ptr^ DO BEGIN
             set_style(format);
             CASE find_just(ptr) OF
                VDI_Left : Draw_Just(vert_grid[l_scr_col]+1,y_pos,
                                     VDI_Left,temp);
                VDI_Center : Draw_Just(vert_grid[l_scr_col]+1+
                                       col_width[col,pixels] DIV 2,
                                       y_pos,VDI_Center,temp);
                VDI_Right : Draw_Just(vert_grid[l_scr_col+1],y_pos,
                                      VDI_Right,temp)
             END; { CASE }
             Text_Style(Normal)
          END; { WITH }       
       { at this point the current cell has been drawn in replace mode
         and ISN'T highlighted }
       IF in_range THEN
          toggle_inverse(Black,row,col);
       IF (row = data_row) AND (col = data_col) THEN
          toggle_inverse(Black,row,col);
1: END; { DRAW_CELL }


PROCEDURE DISPLAY_DATA ( extent                       : ExtentType;
                         row_begin,row_end,col_begin,
                         col_end                      : INTEGER );
   LABEL 1,2,3;
   VAR i,j,k,l,row,col,m,t,style : INTEGER;
       found,over,quit           : BOOLEAN;
       temp                      : STRING;
       ptr                       : CellPtr;
   BEGIN
       IF row_begin < logical_row_1 THEN
          row_begin := logical_row_1
       ELSE IF row_begin > n_rows THEN
          row_begin := n_rows;
       IF col_begin < logical_col_1 THEN
          col_begin := logical_col_1
       ELSE IF col_begin > n_cols THEN
          col_begin := n_cols;
       IF row_end < logical_row_1 THEN
          row_end := logical_row_1
       ELSE IF row_end > n_rows THEN
          row_end := n_rows;
       IF col_end < logical_col_1 THEN
          col_end := logical_col_1
       ELSE IF col_end > n_cols THEN
          col_end := n_cols;
       temp := '';
       Work_Rect(act_hdl,x_1,y_1,w_1,h_1);
       IF redraw_flag THEN
          Set_Clip(redraw_x,redraw_y,redraw_w,redraw_h)
       ELSE
          Set_Clip(x_1,y_1,w_1,h_1);
       Text_Color(Red);
       { draw row numbers; no_col_names means we aren't changing them and
         that implies we have moved up or down and thus need to redraw the
         row numbers }
       IF (extent = WholeSheet) OR (extent = NoColNames) THEN BEGIN
          j := y_1+cell_height+y_margin-1;
          t := x_1+38 DIV 2;
          IF freeze_row > 0 THEN BEGIN
             int_to_string(freeze_row,temp);
             Draw_Just(t,j-cell_height,VDI_Center,temp)
          END;
          FOR i := start_row TO row_begin-1 DO
              j := j+cell_height;
          FOR i := row_begin TO row_end DO BEGIN
              int_to_string(i,temp);
              Draw_Just(t,j,VDI_Center,temp);
              j := j+cell_height
          END
       END;
       { draw column letters; if no_row_names we have moved left or right
         and hence must redraw the col names }
       IF (extent = WholeSheet) OR (extent = NoRowNames) THEN BEGIN
          t := y_1+cell_height-2;
          j := col_begin-start_col+1;
          IF freeze_col > 0 THEN
             Draw_Just(x_1+39+col_width[freeze_col,pixels] DIV 2,t,
                       VDI_Center,col_name[freeze_col]);
          FOR i := col_begin TO col_end DO BEGIN
              { in the middle of a cell }
              Draw_Just(vert_grid[j]+1+col_width[i,pixels] DIV 2,t,
                        VDI_Center,col_name[i]);
              j := j+1
          END
       END;
       
       { first determine the y coordinates here rather than within the inner
         loop for speed }
         
       pts_in[1] := y_1+y_margin+(row_begin-start_row+1)*cell_height-1;
       FOR i := 2 TO row_end-row_begin+1 DO
           pts_in[i] := pts_in[i-1]+cell_height;
       Text_Color(Black);
       
       IF (extent = WholeSheet) OR (extent = NoColNames) THEN
          IF freeze_col > 0 THEN BEGIN
             clip_x := x_1+39;
             clip_y := y_1+y_margin+1;
             clip_w := col_width[freeze_col,pixels]-1;
             clip_h := h_1-(y_margin+1);
             IF redraw_flag THEN BEGIN
                IF redraw_x > clip_x+clip_w THEN
                   GOTO 2
                ELSE IF redraw_x >= clip_x THEN BEGIN
                   IF redraw_x+redraw_w > clip_x+clip_w THEN
                      clip_w := clip_w-(redraw_x-clip_x)
                   ELSE
                      clip_w := redraw_w;
                   clip_x := redraw_x
                END
                ELSE IF redraw_x+redraw_w > clip_x THEN BEGIN
                   clip_w := redraw_x+redraw_w-clip_x;
                   IF clip_w > col_width[freeze_col,pixels] THEN
                      clip_w := col_width[freeze_col,pixels]
                END
                ELSE
                   GOTO 2;
                clip_y := redraw_y;
                clip_h := redraw_h
             END;
             Set_Clip(clip_x,clip_y,clip_w,clip_h);
             FOR i := row_begin TO row_end DO BEGIN
                 ptr := locate_cell(i,freeze_col);
                 IF ptr <> NIL THEN BEGIN
                    prep_cell(ptr,temp);
                    set_style(ptr^.format);
                    row := i+1-row_begin;
                    CASE find_just(ptr) OF
                       VDI_Left   : Draw_Just(x_1+39,pts_in[row],
                                              VDI_Left,temp);
                       VDI_Center : Draw_Just(x_1+39+
                                              col_width[ptr^.c,pixels] DIV 2,
                                              pts_in[row],VDI_Center,temp);
                       VDI_Right  : Draw_Just(vert_grid[1],pts_in[row],
                                              VDI_Right,temp)
                    END; { CASE }
                    Text_Style(Normal)
                 END
             END
          END;
          
2:     IF (extent = WholeSheet) OR (extent = NoRowNames) THEN
          IF freeze_row > 0 THEN BEGIN
             clip_x := x_1+x_margin+1;
             clip_y := y_1+cell_height;
             clip_w := w_1-(x_margin+1);
             clip_h := h_1-cell_height;
             IF redraw_flag THEN BEGIN
                IF redraw_x >= clip_x THEN BEGIN
                   clip_x := redraw_x;
                   clip_w := redraw_w
                END
                ELSE IF redraw_x+redraw_w > clip_x THEN
                   clip_w := redraw_x+redraw_w-clip_x
                ELSE
                   GOTO 3;   
                clip_y := redraw_y;
                clip_h := redraw_h
             END;
             Set_Clip(clip_x,clip_y,clip_w,clip_h);
             m := y_1+y_margin-1;
             FOR i := col_begin TO col_end DO BEGIN
                 ptr := locate_cell(freeze_row,i);
                 IF ptr <> NIL THEN BEGIN
                    prep_cell(ptr,temp);
                    set_style(ptr^.format);
                    k := ptr^.c-start_col+1;
                    CASE find_just(ptr) OF
                       VDI_Left   : Draw_Just(vert_grid[k]+1,m,VDI_Left,temp);
                       VDI_Center : Draw_Just(vert_grid[k]+1+
                                              col_width[ptr^.c,pixels] DIV 2,
                                              m,VDI_Center,temp);
                       VDI_Right  : Draw_Just(vert_grid[k+1],m,VDI_Right,temp)
                    END; { CASE }
                    Text_Style(Normal)
                 END
             END
          END;
                 
       { draw cell contents; i.e. extent = just_data, so... }
3:     IF NOT data_clip THEN
          GOTO 1;
       FOR i := row_begin TO row_end DO BEGIN
           { needn't blank out individual unassigned cells since this is
             only called when the entire sheet has been redrawn and the
             screen painted }
           found := FALSE;
           quit := FALSE;
           ptr := data[i];
           WHILE (ptr <> NIL) AND (NOT found) AND (NOT quit) DO 
              IF (ptr^.c >= col_begin) AND (ptr^.c <= col_end) THEN
                 found := TRUE
              ELSE IF ptr^.c > col_end THEN
                 quit := TRUE
              ELSE
                 ptr := ptr^.next;
           over := FALSE;
           row := i-row_begin+1;
           IF found THEN 
              WHILE (ptr <> NIL) AND (NOT over) DO BEGIN
                 { draw the current cell LAST because it may extend beyond the
                   borders of itself, and its neighbors might overwrite this
                   extension; want THIS cell to have precedence! }
                 IF (i <> data_row) OR (ptr^.c <> data_col) THEN BEGIN
                    prep_cell(ptr,temp);
                    { here we could first blank out each cell or better yet
                      check if bounding cells extend into the current cell
                      and then blank it out; i.e. only the current cells
                      contents would be in that cell with no overflow from
                      other cells. But this would really slow things down,
                      and since this really only applies to labels, the
                      user should't have labels bigger than their cells
                      and then want numbers in adjacent cells to be
                      displayed properly; i.e. he might thus get something
                      like this :
                                  A     |     B
                               Doug Harrison is a -9.0
                      rather than :
                                  A     |     B
                               Doug Harri         -9.0
                      This only apllies when the WHOLE window is redrawn;
                      DRAW_CELL does, if the cell is assigned, blank out
                      the cell first, and I think this is more
                      important, and it doesn't slow things down... }
                    set_style(ptr^.format);
                    k := ptr^.c-start_col+1;
                    CASE find_just(ptr) OF
                       VDI_Left   : Draw_Just(vert_grid[k]+1,pts_in[row],
                                              VDI_Left,temp);
                       VDI_Center : Draw_Just(vert_grid[k]+1+
                                              col_width[ptr^.c,pixels] DIV 2,
                                              pts_in[row],VDI_Center,temp);
                       VDI_Right  : Draw_Just(vert_grid[k+1],pts_in[row],
                                              VDI_Right,temp)
                    END; { CASE }
                    Text_Style(Normal)
                 END; { IF }
                 ptr := ptr^.next;
                 IF ptr <> NIL THEN
                    IF ptr^.c > col_end THEN
                       over := TRUE
              END; { WHILE }
           IF block_set THEN 
              IF (i >= b_s_row) AND (i <= b_e_row) THEN
                 FOR j := col_begin TO col_end DO 
                     IF (j >= b_s_col) AND (j <= b_e_col) THEN
                        toggle_inverse(Black,i,j)
       END; { FOR i }
       { so the output from this is such that ALL cells in a range are
         highlighted }
       draw_cell(data_row,data_col,FALSE);
1: END; (* DISPLAY_DATA *)

PROCEDURE SET_UP_CELL_NAME;
   BEGIN
      string_a_cell(data_row,data_col,col_row);
      Set_Text(new_desk_ptr,editcell,col_row,s0,5)
   END; { SET_UP_CELL_NAME }
   
PROCEDURE WRITE_CELL_NAME;
   BEGIN
      Set_Text(new_desk_ptr,editcell,'     ',s0,5);
      Hide_Mouse;
      Obj_Draw(new_desk_ptr,editcell,Max_Depth,
               0,0,screen_width,screen_height);
      set_up_cell_name;
      Obj_Draw(new_desk_ptr,editcell,Max_Depth,
               0,0,screen_width,screen_height);
      Show_Mouse
   END; { WRITE_CELL_NAME }

PROCEDURE SHEET_REDRAW ( extent    : ExtentType;
                         blit_flag : BOOLEAN;
                         direction : BlitDirection );
   { note that caller *MUST* call Begin_Update beforehand!!! }
   VAR
       v_slider_pos,h_slider_pos,
       i,j,x,y,w,h,x2,y2,vert_pos : INTEGER;
    PROCEDURE RESET_WINDOW;
       BEGIN
           def_sheet_area;
           save_attr; { do it again in case we had to home cursor.  }
                      { Can't elimiate save_attr in def_sheet_area  }
                      { because other routines call it; i.e.        }
                      { MOVE_SHEET, and some of the column-movement }
                      { routines }
           IF (extent = WholeSheet) OR (extent = NoColNames) OR
              ((blit_flag) AND (direction > Right)) THEN BEGIN           
              v_slider_pos := TRUNC(1000.0*(start_row-1)/(n_rows-v_entry));
              Wind_Set(act_hdl,WF_VSLSize,ROUND(1000.0*v_entry/n_rows),
                       0,0,0);
              Wind_Set(act_hdl,WF_VSlide,v_slider_pos,0,0,0)
           END;   
           IF (extent = WholeSheet) OR (extent = NoRowNames) OR
              ((blit_flag) AND (direction < Up)) THEN BEGIN           
              h_slider_pos := TRUNC(1000.0*(start_col-1)/(n_cols-h_entry));
              Wind_Set(act_hdl,WF_HSLSize,ROUND(1000.0*h_entry/n_cols),
                       0,0,0);
              Wind_Set(act_hdl,WF_HSlide,h_slider_pos,0,0,0)
           END   
       END; (* RESET_WINDOW *)

    PROCEDURE BLIT_LEFT;
       BEGIN
           IF o_s_col <= finish_col THEN BEGIN
              x := x_1+x_margin+1;
              w := w_1;
              y := y_1;
              h := h_1;
              i := start_col;
              j := 1;
              WHILE i <= finish_col DO BEGIN
                  IF i = o_s_col THEN BEGIN
                     vert_pos := j;
                     i := 500
                  END
                  ELSE
                     i := i+1;
                  j := j+1
              END;
              x2 := vert_grid[vert_pos]+1;
              y2 := y;
              Blit(screen_mfdb,screen_mfdb,x,y,x2,y2,w,h);
              Paint_Rect(x,y,x2-x,h_1);
              draw_sheet(extent,1,virtual_v_entry,
                                1,o_s_col-start_col,TRUE);
              display_data(NoRowNames,start_row,virtual_f_row,
                                      start_col,o_s_col-1)
           END
           ELSE BEGIN
              draw_sheet(extent,1,virtual_v_entry,1,virtual_h_entry,FALSE);
              display_data(extent,start_row,virtual_f_row,
                                  start_col,virtual_f_col)
           END
       END; { BLIT_LEFT }

    PROCEDURE BLIT_RIGHT;
       BEGIN
           IF o_f_col >= start_col THEN BEGIN
              i := o_s_col;
              j := 1;
              WHILE i <= o_f_col DO BEGIN
                  IF i = start_col THEN BEGIN
                     vert_pos := j;
                     i := 500
                  END
                  ELSE
                     i := i+1;
                  j := j+1
              END;
              x := old_vert_grid[vert_pos]+1;
              y := y_1;
              w := old_vert_grid[o_f_col-o_s_col+2]-old_vert_grid[vert_pos];
              h := h_1;
              x2 := x_1+x_margin+1;
              y2 := y;
              Blit(screen_mfdb,screen_mfdb,x,y,x2,y2,w,h);
              Paint_Rect(x2+w,y,w_1,h_1);
              draw_sheet(extent,1,virtual_v_entry,
                                h_entry-(finish_col-o_f_col)+1,
                                virtual_h_entry,TRUE);
              display_data(NoRowNames,start_row,virtual_f_row,
                                      o_f_col+1,virtual_f_col)
           END
           ELSE BEGIN
              draw_sheet(extent,1,virtual_v_entry,1,virtual_h_entry,FALSE);
              display_data(extent,start_row,virtual_f_row,
                                  start_col,virtual_f_col)
           END
       END; { BLIT_RIGHT }

    PROCEDURE BLIT_UP;
       BEGIN
           x := x_1;
           y := y_1+y_margin+1;
           w := w_1;
           h := h_1;
           x2 := x;
           y2 := y+cell_height;
           Blit(screen_mfdb,screen_mfdb,x,y,x2,y2,w,h);
           Paint_Rect(x,y,w,cell_height-1);
           draw_sheet(extent,1,1,1,virtual_h_entry,TRUE);
           display_data(NoColNames,start_row,start_row,
                                   start_col,virtual_f_col)
       END; { BLIT_UP }

    PROCEDURE BLIT_DOWN;
       BEGIN
           x := x_1;
           y := y_1+y_margin+cell_height+1;
           w := w_1;
           h := cell_height*(v_entry-1)-1;
           x2 := x;
           y2 := y-cell_height;
           Blit(screen_mfdb,screen_mfdb,x,y,x2,y2,w,h);
           Paint_Rect(x,y2+h+1,w_1,h_1);
           draw_sheet(extent,v_entry,virtual_v_entry,1,virtual_h_entry,TRUE);
           display_data(NoColNames,finish_row,virtual_f_row,
                                   start_col,virtual_f_col)
       END; { BLIT_DOWN }

   BEGIN { SHEET_REDRAW }
       Hide_Mouse;
       reset_window;
       IF NOT blit_flag THEN BEGIN
          draw_sheet(extent,1,virtual_v_entry,1,virtual_h_entry,FALSE);
          display_data(extent,start_row,virtual_f_row,
                              start_col,virtual_f_col)
       END
       ELSE BEGIN
          Set_Clip(x_1,y_1,w_1,h_1); {current because of Work_Rect}
          CASE direction OF          {in def_sheet_area}
             Left  : blit_left;
             Right : blit_right;
             Up    : blit_up;
             Down  : blit_down
          END
       END;
       Show_Mouse;
       IF Front_Window = act_hdl THEN
          write_cell_name
   END; { SHEET_REDRAW }


BEGIN
END.



