home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TVTOOL.ZIP / TVVIEWS.INT < prev    next >
Encoding:
Text File  |  1992-10-08  |  10.6 KB  |  317 lines

  1. {*
  2. *   TvViews.pas
  3. *
  4. *   Enhancements to Turbo Vision views.
  5. *
  6. *   Copyright 1992 by Richard W. Hansen
  7. *
  8. *}
  9.  
  10. UNIT TvViews;
  11. {$X+}
  12. {$V-}
  13.  
  14. {$I TVDEFS.INC}
  15.  
  16. INTERFACE
  17.  
  18.  
  19. USES
  20.   TvKeys, TvType, TvConst, TvMenus,
  21.   App, Drivers, Menus, Objects, Views, TextView, Dos;
  22.  
  23.  
  24. CONST
  25.   ActiveFrame1    : FrameArray = '┌╖╘╝│║─═';
  26.   ActiveFrame2    : FrameArray = '╔╗╚╝║║══';
  27.   PassiveFrame    : FrameArray = '┌┐└┘││──';
  28.  
  29.   ofPosIndicator  = $1000;
  30.   ofVScrollBar    = $2000;
  31.   ofHScrollBar    = $4000;
  32.  
  33.  
  34. CONST
  35.   { Position Indicator Palette }
  36.   { Indicator normal }
  37.   { Indicator passive }
  38.   { Indicator dragging }
  39.   CPosIndicator   = #2#1#3;
  40.  
  41.   { Max/Min button Palette }
  42.   { Button normal }
  43.   { Button frame normal }
  44.   { Button dragging }
  45.   CMinMax         = #3#2#3;
  46.  
  47.   { 3D Dialog Frame Palette }
  48.   { Frame passive }
  49.   { Title passive }
  50.   { Frame normal }
  51.   { Title normal }
  52.   { Frame shaded }
  53.   { Frame icon/dragging }
  54.   C3DFrame        = #35#35#33#33#34#36;
  55.  
  56.  
  57. TYPE
  58.   { If views that are inserted into a dialog descend from TEditView
  59.     instead of TView, greater edit control is possible. TEditView
  60.     handles post-edit routines and required fields.
  61.   }
  62.   PEditView = ^TEditView;
  63.   TEditView = Object(TView)
  64.     ID        : Word;
  65.     LLabel    : PView;
  66.     PostEdit  : Pointer;
  67.     EditFlags : Word;
  68.  
  69.     Constructor Init(var Bounds: TRect);
  70.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  71.     Function    Valid(Command: Word): Boolean;            Virtual;
  72.     Procedure   SetPostEdit(P : Pointer);
  73.     Function    Empty: Boolean;                           Virtual;
  74.     Procedure   SetEditFlag(AFlag : Word;
  75.                             Enable: Boolean);
  76.     Procedure   SetState(AState : Word;
  77.                          Enable : Boolean);               Virtual;
  78.     Procedure   Select;                                   Virtual;
  79.     Procedure   AddLabel(ALabel : PView);
  80.     Procedure   Lock;
  81.     Procedure   UnLock;
  82.     Procedure   SetID(AFieldID : Word);
  83.     Function    GetID: Word;
  84.   end;
  85.  
  86.  
  87.   { This object is a position indicator, it is made to be inserted
  88.     into a TWindow or descendant frame.
  89.   }
  90.   PPosIndicator = ^TPosIndicator;
  91.   TPosIndicator = Object(TView)
  92.     Pos : Word;
  93.  
  94.     Constructor Init(var Bounds: TRect);
  95.     Procedure   Draw;                                     Virtual;
  96.     Function    GetPalette: PPalette;                     Virtual;
  97.     Procedure   SetState(AState: Word; Enable : Boolean); Virtual;
  98.     Function    DataSize: Word;                           Virtual;
  99.     Procedure   SetData(var Rec);                         Virtual;
  100.     Procedure   GetData(var Rec);                         Virtual;
  101.   end;
  102.  
  103.  
  104.   { This object implements a window minimize and maximize icon. }
  105.   PMinMaxButton = ^TMinMaxButton;
  106.   TMinMaxButton = Object(TView)
  107.     Constructor Init(var Bounds : TRect);
  108.     Procedure   Draw;                                     Virtual;
  109.     Function    GetPalette: PPalette;                     Virtual;
  110.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  111.     Procedure   SetState(AState : Word;
  112.                          Enable : Boolean);               Virtual;
  113.   end;
  114.  
  115.  
  116.   PNewFrame = ^TNewFrame;
  117.   TNewFrame = Object(TFrame)
  118.     Procedure   HandleEvent(var Event: TEvent);           Virtual;
  119.   end;
  120.  
  121.  
  122.   { PNewWindow is a window that can be minimized (iconized) }
  123.   PNewWindow = ^TNewWindow;
  124.   TNewWindow = Object(TWindow)
  125.     PMinMax   : PMinMaxButton;
  126.     MinSize   : TPoint;
  127.     MaxRect   : TRect;
  128.     wfSave    : Word;
  129.     Minimized : Boolean;
  130.  
  131.     Constructor Init(var Bounds : TRect;
  132.                          ATitle : TTitleStr;
  133.                          ANumber: Integer);
  134.     Procedure HandleEvent(var Event : TEvent);            Virtual;
  135.     Procedure SizeLimits(var Min, Max : TPoint);          Virtual;
  136.     Procedure SetState(AState : Word;
  137.                        Enable : Boolean);                 Virtual;
  138.     Procedure InitFrame;                                  Virtual;
  139.     Procedure ControlMenu(Mouse : Boolean);
  140.   end;
  141.  
  142.  
  143.   { This is a scroll bar object that can be used by two or more
  144.     views at the same time. It will always be active, no matter
  145.     which of the views that own it is focused.
  146.   }
  147.   PMultiBuffScrollBar = ^TMultiBuffScrollBar;
  148.   TMultiBuffScrollBar = Object(TScrollBar)
  149.     Procedure   SetState(AState : Word; Enable : Boolean);Virtual;
  150.     Destructor  Done;                                     Virtual;
  151.   end;
  152.  
  153.  
  154.   { An abstract edit buff, that will become a hex or ascii edit buffer
  155.     for use in the TEditBuffWindow defined below.
  156.   }
  157.   PEditBuff = ^TEditBuff;
  158.   TEditBuff = Object(TScroller)
  159.     Buf       : PByteBuf;       { pointer to raw data       }
  160.     BufSize   : Word;           { actual buffer size        }
  161.     ItemSize  : Byte;           { display size of each char }
  162.  
  163.     Constructor Init(Bounds       : TRect;
  164.                      Buff         : Pointer;
  165.                      BuffSize     : Word;
  166.                      ItemWidth    : Byte;
  167.                      AVScrollBar  : PScrollBar);
  168.  
  169.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  170.     Procedure   SetXY(Pos : TPoint);
  171.     Procedure   GetXY(var Pos : TPoint);
  172.     Function    GetOffset: Word;
  173.   end;
  174.  
  175.  
  176.   { An descendant of TEditBuff, that will become the ascii edit buffer
  177.     in the TEditBuffWindow defined below.
  178.   }
  179.   PAsciiBuff = ^TAsciiBuff;
  180.   TAsciiBuff = Object(TEditBuff)
  181.     Constructor Init(Bounds       : TRect;
  182.                      Buff         : Pointer;
  183.                      BuffSize     : Word;
  184.                      AVScrollBar  : PScrollBar);
  185.  
  186.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  187.     Procedure   Draw;                                     Virtual;
  188.   end;
  189.  
  190.  
  191.   { An descendant of TEditBuff, that will become the hex edit buffer
  192.     in the TEditBuffWindow defined below.
  193.   }
  194.   PHexBuff = ^THexBuff;
  195.   THexBuff = Object(TEditBuff)
  196.     Constructor Init(Bounds       : TRect;
  197.                      Buff         : Pointer;
  198.                      BuffSize     : Word;
  199.                      AVScrollBar  : PScrollBar);
  200.  
  201.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  202.     Procedure   Draw;                                     Virtual;
  203.   end;
  204.  
  205.  
  206.   { This object implements a ASCII/HEX editing window. It is just like
  207.     those used with disk utilities. The window can be of any size, but to
  208.     keep ASCII and Hex views in sync, in the side by side views, there are
  209.     a couple things to remember. The hex view will take twice as many chars
  210.     to display the same data as the ascii view. So the X dimemsion should
  211.     be an even number that will allow one view to be exactly twice as big
  212.     as the other. The X dimension should also be evenly divisible by 3.
  213.     This will make sure that the hex display does not split a character
  214.     across two rows. This said, make sure to account for the frame.
  215.  
  216.     An example : a width of 62, allows 2 chars for the frame, and will
  217.     give hex view 40 wide and an ascii view 20 wide.
  218.  
  219.     Because of all the above, and because I could not get the right
  220.     combination of gfGrow modes, the window is set up to only grow in
  221.     the Y axis.
  222.  
  223.     The AOptions param in Init only uses the ofPosIndicator flag, to
  224.     insert or not a position indicator into the frame.
  225.   }
  226.   PEditBuffWindow = ^TEditBuffWindow;
  227.   TEditBuffWindow = Object(TWindow)
  228.     MaxWidth    : Word;
  229.     MaxPos      : Word;                 { highest position edited }
  230.     LView       : PEditBuff;            { left side HEX buffer    }
  231.     RView       : PEditBuff;            { right side ASCII buffer }
  232.     VScrollBar  : PMultiBuffScrollBar;  { vertical scroll bar     }
  233.     Indicator   : PPosIndicator;        { byte position indicator }
  234.  
  235.     Constructor Init(Bounds   : TRect;
  236.                      ATitle   : TTitleStr;
  237.                      ANumber  : Integer;
  238.                      AOptions : Word;
  239.                      Buff     : Pointer;
  240.                      BuffSize : Word);
  241.  
  242.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  243.     Procedure   SizeLimits(var Min, Max : TPoint);        Virtual;
  244.     Procedure   SetState(AState: Word; Enable: Boolean);  Virtual;
  245.   end;
  246.  
  247.  
  248.   { TFormattedTextScroller is a TScroller that will word wrap and line
  249.     wrap at carrige returns. Give it a pointer text buffer and
  250.     it will do its best to display it.
  251.   }
  252.   PFormattedTextScroller = ^TFormattedTextScroller;
  253.   TFormattedTextScroller = Object(TScroller)
  254.     Buffer  : PCharBuf;
  255.     BufSize : Word;
  256.  
  257.     Constructor Init(var Bounds      : TRect;
  258.                          AVScrollBar : PScrollBar;
  259.                          Buff        : PCharBuf;
  260.                          BuffSize    : Word
  261.                     );
  262.     Procedure   Draw;                                   Virtual;
  263.     Procedure   ChangeBounds(var Bounds: TRect);        Virtual;
  264.     Procedure   GetNextLine(    First : Word;
  265.                             var Count : Word;
  266.                             var NextCh: Word);
  267.     Procedure   CountLines;
  268.   end;
  269.  
  270.  
  271.  
  272.   { Here is a window that contains an instance of TTerminal for
  273.     instant text display capabilities. Pass ofVScrollBar and/or
  274.     ofHScrollBar in AOptions, if you want scrollbars for a scrolling
  275.     window. If you need a quick text display window, but don't
  276.     want the bother of defining a Draw method, just slap one of these into
  277.     the desktop. TTextWindow has a Write method for displaying strings.
  278.     Insert a cmDisplayStr broadcast event and an InfoPtr to a string into
  279.     the event queue with an and the string will be displayed in any open
  280.     PTextWindow.
  281.   }
  282.   PTextWindow = ^TTextWindow;
  283.   TTextWindow = Object(TNewWindow)
  284.     Interior    : PTerminal;
  285.     HScrollBar  : PScrollBar;
  286.     VScrollBar  : PScrollBar;
  287.     Width       : Byte;
  288.     Height      : Byte;
  289.  
  290.     Constructor Init(Bounds     : TRect;
  291.                      WinTitle   : String;
  292.                      WinNumber  : Word;
  293.                      AOptions   : Word;
  294.                      AMaxLines  : Word
  295.                     );
  296.     Procedure   Clear;
  297.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  298.     Procedure   Write(St : String);
  299.   end;
  300.  
  301.  
  302.   P3DFrame = ^T3DFrame;
  303.   T3DFrame = object(TFrame)
  304.     Procedure   Draw;                                     Virtual;
  305.     Function    GetPalette: PPalette;                     Virtual;
  306.     Procedure   GetFrame(var F : FrameArray);             Virtual;
  307.   end;
  308.  
  309.  
  310. { Redirect output to a PTextWindow. Set F to "Output" to redirect all
  311.   Writeln statements to the window.
  312. }
  313. Procedure AssignOutput(var F : Text;
  314.                            AWindow : PTextWindow);
  315.  
  316.  
  317.