home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / misc / ada1110b.lha / Examples / Dine / winbody.ada < prev    next >
Encoding:
Text File  |  1992-03-02  |  5.9 KB  |  204 lines

  1. PACKAGE BODY Windows is
  2.  
  3. -- Body of window manager package.
  4. -- Adapted by
  5. -- Michael B. Feldman, The George Washington University, November 1990.
  6.  
  7.   CursorRow: RowRange := 1;            -- Current cursor position 
  8.   CursorCol: ColRange := 1;
  9.    
  10.    PROCEDURE Open (    w: in out WINDOW;
  11.                        row: RowRange;
  12.                        column: ColRange;
  13.                        height: RowLength;
  14.                        width:  ColLength) is
  15.              --put the window's cursor in upper left corner 
  16.    BEGIN
  17.       w.CurrentRow := row;
  18.       w.firstrow := row;
  19.       w.lastrow := row + height - 1;
  20.       w.CurrentColumn := column;
  21.       w.firstcolumn := column;
  22.       w.lastcolumn := column + width - 1;
  23.    END Open;
  24.    
  25.    PROCEDURE Close (w: in out WINDOW) IS
  26.    BEGIN
  27.       null;
  28.    END Close;
  29.    
  30.    PROCEDURE Title (w     : in out WINDOW;
  31.                     name  : STRING;
  32.                     under : CHARACTER) IS
  33.    -- Put name at the top of the window.  If under <>  ' ', underline
  34.    -- the title. 
  35.       i: ColRange;
  36.    BEGIN
  37.       -- put name on top line 
  38.       w.CurrentColumn := w.firstcolumn;
  39.       w.CurrentRow := w.firstrow;
  40.       put_string (w, name);
  41.       new_line (w);
  42.       -- Underline name if desired, and move the first line of the window
  43.       -- below the title 
  44.       IF under = ' ' THEN
  45.          w.firstrow := w.firstrow + 1;
  46.       ELSE
  47.          FOR i IN w.firstcolumn .. w.lastcolumn LOOP
  48.             put (w, under);
  49.             END LOOP;
  50.          new_line (w);
  51.          w.firstrow := w.firstrow + 2;
  52.       END IF;
  53.    END Title;
  54.    
  55.       
  56.    PROCEDURE GotoRowColumn (w    : in out WINDOW;
  57.                             row  : RowRange;
  58.                             column : ColRange) IS
  59.    -- Relative to writable window boundaries, of course 
  60.    BEGIN
  61.       w.CurrentRow := w.firstrow + row;
  62.       w.CurrentColumn := w.firstcolumn + column;
  63.    END GotoRowColumn;
  64.       
  65.       
  66.    PROCEDURE Borders (w   : in out WINDOW;
  67.                       corner, down, across: CHARACTER) IS
  68.    -- Draw border around current writable area in window with characters.
  69.    -- Call this BEFORE Title.  
  70.       i: RowRange;
  71.       j: ColRange;
  72.    BEGIN
  73.       -- put top line of border 
  74.       SetCursorAt (w.firstcolumn, w.firstrow);
  75.       TEXT_IO.put (corner);
  76.       FOR j IN w.firstcolumn + 1  ..  w.lastcolumn - 1 LOOP
  77.          TEXT_IO.put (across);
  78.          END LOOP;
  79.       TEXT_IO.put (corner);
  80.       
  81.       -- put the two side lines 
  82.       FOR i IN w.firstrow + 1  .. w.lastrow - 1 LOOP
  83.          SetCursorAt (w.firstcolumn, i);
  84.          TEXT_IO.put (down);
  85.          SetCursorAt (w.lastcolumn, i);
  86.          TEXT_IO.put (down);
  87.          END LOOP;
  88.          
  89.       -- put the bottom line of the border 
  90.       SetCursorAt (w.firstcolumn, w.lastrow);
  91.       TEXT_IO.put (corner);
  92.       FOR j IN w.firstcolumn + 1  .. w.lastcolumn - 1 LOOP
  93.          TEXT_IO.put (across);
  94.          END LOOP;
  95.       TEXT_IO.put (corner);
  96.       
  97.       -- Put the cursor at the very end of the window 
  98.       CursorRow := w.lastrow;
  99.       CursorCol := w.lastcolumn + 1;
  100.       
  101.       -- Make the window smaller by one character on each side 
  102.       w.firstrow := w.firstrow + 1;
  103.       w.CurrentRow := w.firstrow;
  104.       w.lastrow := w.lastrow - 1;
  105.       w.firstcolumn := w.firstcolumn + 1;
  106.       w.CurrentColumn := w.firstcolumn;
  107.       w.lastcolumn := w.lastcolumn - 1;
  108.    END Borders;
  109.    
  110.  
  111.    PROCEDURE EraseToEndOfLine (w: in out WINDOW) IS
  112.       i: ColRange;
  113.    BEGIN
  114.       SetCursorAt (w.CurrentColumn, w.CurrentRow);
  115.       FOR i IN w.CurrentColumn .. w.lastcolumn LOOP
  116.          TEXT_IO.put (' ');
  117.          END LOOP;
  118.       SetCursorAt (w.CurrentColumn, w.CurrentRow);
  119.       CursorCol := w.CurrentColumn;
  120.       CursorRow := w.CurrentRow;
  121.    END EraseToEndOfLine;
  122.    
  123.       
  124.    PROCEDURE put (w: in out WINDOW;
  125.                    ch: CHARACTER) IS
  126.    
  127.    -- If after end of line, move to first character of next line 
  128.    -- If about to write first character on line, blank rest of line.
  129.    -- put character. 
  130.    
  131.    BEGIN
  132.       IF ch = ASCII.CR THEN
  133.          new_line(w);
  134.          RETURN;
  135.          END IF;
  136.          
  137.          -- If at end of current line, move to next line 
  138.          IF w.CurrentColumn > w.lastcolumn THEN
  139.             IF w.CurrentRow = w.lastrow THEN
  140.                w.CurrentRow := w.firstrow;
  141.             ELSE 
  142.                w.CurrentRow := w.CurrentRow + 1;
  143.             END IF;
  144.             w.CurrentColumn := w.firstcolumn;
  145.          END IF;
  146.          
  147.          -- If at w.first char, erase line 
  148.          IF w.CurrentColumn = w.firstcolumn THEN
  149.             EraseToEndOfLine (w);
  150.          END IF;
  151.          
  152.          -- Put physical cursor at window's cursor  
  153.          IF (CursorCol /= w.CurrentColumn) OR (CursorRow /= w.CurrentRow) 
  154.          THEN
  155.             SetCursorAt (w.CurrentColumn, w.CurrentRow);
  156.             CursorRow := w.CurrentRow;
  157.          END IF;
  158.          
  159.          IF ch = ASCII.BS THEN
  160.             -- Special backspace handling 
  161.             IF w.CurrentColumn /= w.firstcolumn THEN
  162.                TEXT_IO.put(ch);
  163.                w.CurrentColumn := w.CurrentColumn - 1;
  164.             END IF;
  165.          ELSE
  166.             TEXT_IO.put (ch);
  167.             w.CurrentColumn := w.CurrentColumn + 1;
  168.          END IF;
  169.          CursorCol := w.CurrentColumn;
  170.    END put;
  171.       
  172.    
  173.    PROCEDURE new_line (w: in out WINDOW) IS
  174.       col: ColRange;
  175.    
  176.    -- If not after line, blank rest of line.
  177.    -- Move to first character of next line 
  178.    
  179.    BEGIN
  180.       IF w.CurrentColumn = 0 THEN
  181.          EraseToEndOfLine (w);
  182.       END IF;
  183.       IF w.CurrentRow = w.lastrow THEN
  184.          w.CurrentRow := w.firstrow;
  185.       ELSE w.CurrentRow := w.CurrentRow + 1;
  186.       END IF;
  187.       w.CurrentColumn := w.firstcolumn;
  188.    END new_line;
  189.    
  190.    
  191.    PROCEDURE put_string (w: in out WINDOW;
  192.                           s: STRING) IS
  193.    BEGIN
  194.       FOR i in s'first .. s'last LOOP
  195.          put (w, s(i));
  196.       END LOOP;
  197.    END put_string;
  198.    
  199.  
  200. BEGIN -- Windows 
  201.    ClearScreen;
  202.    SetCursorAt (1, 1);
  203. END Windows;
  204.