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

  1. {*
  2. *   TvInput.pas
  3. *
  4. *   Enhancements to Turbo Vision TInputLine.
  5. *
  6. *   Copyright 1992 by Richard W. Hansen
  7. *
  8. *}
  9.  
  10. (*
  11.     THERE ARE CHANGES NEEDED TO VIEWS.PAS!!!!!!
  12.  
  13.     <<<< AT LINE 260 MAKE Select a virtual method >>>>
  14.     procedure Select; virtual;
  15. *)
  16.  
  17.  
  18.  
  19.  
  20. UNIT TvInput;
  21. {$V-}
  22. {$X+}
  23.  
  24. {$I TVDEFS.INC}
  25.  
  26. INTERFACE
  27.  
  28.  
  29. USES
  30.   Dialogs, Drivers, Objects, Views, MsgBox,
  31.   {$IFDEF USE_TVSCROLL}
  32.   TvScroll,
  33.   {$ENDIF}
  34.   TvConst, TvString, TvType;
  35.  
  36.  
  37.  
  38. CONST
  39.   HideChar  : Char = '*'; { character used for passwords  }
  40.  
  41.   DecimalPt = '.';
  42.   CommaChar = ',';
  43.   Left      = True;
  44.   Right     = False;
  45.  
  46.   { 3D InputLine Palette }
  47.   { 1 = Inputline active }
  48.   { 2 = Inputline passive }
  49.   { 3 = Inputline selected text }
  50.   { 4 = Inputline arrow }
  51.   C3DInputLine  = #45#45#46#47;
  52.  
  53.  
  54. TYPE
  55.   P3DInputLine  = ^T3DInputLine;
  56.   T3DInputLine  = Object(TInputLine)
  57.     Constructor Init(var Bounds : TRect;
  58.                          AMaxLen: Integer);
  59.     Function    GetPalette: PPalette;                     Virtual;
  60.   end;
  61.  
  62.  
  63.   { This is the base input line for all the new data entry line objects.
  64.     When you pass an edit mask the MaxLen is calculated automatically.
  65.     Only the characters in the set associated with a particular edit
  66.     mask will be accepted.
  67.   }
  68.   PEditLine = ^TEditLine;             {$IFDEF USE_TVSCROLL}
  69.   TEditLine = Object(TScrollInputLine){$ELSE}
  70.   TEditLine = Object(TInputLine)      {$ENDIF}
  71.     PadChar   : Char;   { blank place holder char }
  72.     XPos      : Byte;   { insert position         }
  73.     First     : Byte;   { first editable position }
  74.     Mask      : PString;{ edit mask               }
  75.     ID        : Word;
  76.     LLabel    : PView;
  77.     PostEdit  : Pointer;
  78.     EditFlags : Word;
  79.  
  80.     Constructor Init(var Bounds   : TRect;
  81.                          EditMask : String);
  82.     (*
  83.     Constructor Load(var S: TStream);
  84.     Procedure   Store(var S: TStream);
  85.     *)
  86.     Destructor  Done;                                     Virtual;
  87.     Procedure   Merge(var St      : String;
  88.                           Justify : Boolean);             Virtual;
  89.     Function    Remove(St : String): String;
  90.     Function    CanScroll(ScrollLeft : Boolean): Boolean;
  91.     Procedure   Draw;                                     Virtual;
  92.     Procedure   SelectAll(Enable : Boolean);
  93.     Procedure   SetState(AState : Word;
  94.                          Enable : Boolean);               Virtual;
  95.     Function    NextPos(Pos : Integer): Integer;          Virtual;
  96.     Function    PrevPos(Pos : Integer): Integer;          Virtual;
  97.     Function    HomePos: Integer;                         Virtual;
  98.     Procedure   SetData(var Rec);                         Virtual;
  99.     Procedure   GetData(var Rec);                         Virtual;
  100.     Function    DataSize: Word;                           Virtual;
  101.     Function    EditToMaskPos(Pos : Integer): Integer;
  102.     Function    MaskToEditPos(Pos : Integer): Integer;
  103.     Procedure   DeleteMarked;
  104.     Procedure   InsertChar(Ch : Char);                    Virtual;
  105.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  106.     Function    Valid(Command : Word): Boolean;           Virtual;
  107.  
  108.     Procedure   SetPostEdit(P : Pointer);
  109.     Function    Empty: Boolean;                           Virtual;
  110.     Procedure   SetEditFlag(AFlag : Word;
  111.                             Enable: Boolean);
  112.     Procedure   AddLabel(ALabel : PView);
  113.     Procedure   Lock;
  114.     Procedure   UnLock;
  115.     Procedure   SetID(AFieldID : Word);
  116.     Function    GetID: Word;
  117.     {$IFDEF HAVE_RTL}
  118.     Procedure   Select;                                   Virtual;
  119.     {$ENDIF}
  120.   end;
  121.  
  122.  
  123.   { This is the base object for all numeric edit line objects. }
  124.   PNumericEdit  = ^TNumericEdit;
  125.   TNumericEdit  = Object(TEditLine)
  126.     ErrCode : Integer;    { string to numeric conversion error  }
  127.  
  128.     Procedure   HandleEvent(var Event: TEvent);           Virtual;
  129.     Function    Valid(Command : Word): Boolean;           Virtual;
  130.     Function    OutOfRange: Boolean;                      Virtual;
  131.     Function    OutOfRangeMsg: String;                    Virtual;
  132.   end;
  133.  
  134.  
  135.   { TLongEdit is the base object for all integer edit lines. AMin and
  136.     AMax define the valid range of values for the field. If AMin and
  137.     AMax are both zero any valid number may be entered. All the types
  138.     defined below vary only in the range of numbers that are valid and
  139.     in the data type returned and expected by SetData and GetData.
  140.   }
  141.   PLongEdit = ^TLongEdit;
  142.   TLongEdit = Object(TNumericEdit)
  143.     Min   : LongInt;  { smallest acceptable value }
  144.     Max   : LongInt;  { largest acceptable value  }
  145.  
  146.     Constructor Init(var Bounds   : TRect;
  147.                          EditMask : String;
  148.                          AMin     : LongInt;
  149.                          AMax     : LongInt);
  150.     Function    DataSize: Word;                           Virtual;
  151.     Procedure   GetData(var Rec);                         Virtual;
  152.     Procedure   SetData(var Rec);                         Virtual;
  153.     Function    OutOfRange: Boolean;                      Virtual;
  154.     Function    OutOfRangeMsg: String;                    Virtual;
  155.   end;
  156.  
  157.  
  158.   PIntegerEdit = ^TIntegerEdit;
  159.   TIntegerEdit = Object(TLongEdit)
  160.     Constructor Init(var Bounds   : TRect;
  161.                          EditMask : String;
  162.                          AMin     : Integer;
  163.                          AMax     : Integer);
  164.     Function    DataSize: Word;                           Virtual;
  165.     Procedure   GetData(var Rec);                         Virtual;
  166.     Procedure   SetData(var Rec);                         Virtual;
  167.   end;
  168.  
  169.  
  170.   PWordEdit = ^TWordEdit;
  171.   TWordEdit = Object(TLongEdit)
  172.     Constructor Init(var Bounds   : TRect;
  173.                          EditMask : String;
  174.                          AMin     : Word;
  175.                          AMax     : Word);
  176.     Function    DataSize: Word;                           Virtual;
  177.     Procedure   GetData(var Rec);                         Virtual;
  178.     Procedure   SetData(var Rec);                         Virtual;
  179.   end;
  180.  
  181.  
  182.   PByteEdit = ^TByteEdit;
  183.   TByteEdit = Object(TLongEdit)
  184.     Constructor Init(var Bounds   : TRect;
  185.                          EditMask : String;
  186.                          AMin     : Byte;
  187.                          AMax     : Byte);
  188.     Function    DataSize: Word;                           Virtual;
  189.     Procedure   GetData(var Rec);                         Virtual;
  190.     Procedure   SetData(var Rec);                         Virtual;
  191.   end;
  192.  
  193.   { THexEdit accepts long integers in hexadecimal format. }
  194.   PHexEdit  = ^THexEdit;
  195.   THexEdit  = Object(TLongEdit)
  196.     Procedure   SetData(var Rec);                         Virtual;
  197.     Function    OutOfRangeMsg: String;                    Virtual;
  198.   end;
  199.  
  200.  
  201.   { TFloatEdit is the base object for all floating point input. You may
  202.     include a decimal point in the edit mask for floating point numbers.
  203.     The user may only enter as many digits after the deciml point as are
  204.     specified in the eidt mask. AMin and AMax define the valid range of
  205.     values for the field. If AMin and AMax are both zero any valid number
  206.     may be entered. All the floaing point types defined below vary only
  207.     in the range of numbers that are valid and the data type returned by
  208.     and expected by SetData and GetData.
  209.   }
  210.  
  211.   PFloatEdit = ^TFloatEdit;
  212.   TFloatEdit = Object(TNumericEdit)
  213.     DP      : Byte;   { number of decimal places  }
  214.  
  215.     Constructor Init(var Bounds   : TRect;
  216.                          EditMask : String);
  217.     Procedure   HandleEvent(var Event: TEvent);           Virtual;
  218.     Procedure   Merge(var St      : String;
  219.                           Justify : Boolean);             Virtual;
  220.   end;
  221.  
  222.   {$IFOPT N+}
  223.   PDoubleEdit = ^TDoubleEdit;
  224.   TDoubleEdit = Object(TFloatEdit)
  225.     Min   : Double; { smallest acceptable value }
  226.     Max   : Double; { largest acceptable value  }
  227.  
  228.     Constructor Init(var Bounds   : TRect;
  229.                          EditMask : String;
  230.                          AMin     : Double;
  231.                          AMax     : Double);
  232.     Function    DataSize: Word;                           Virtual;
  233.     Procedure   GetData(var Rec);                         Virtual;
  234.     Procedure   SetData(var Rec);                         Virtual;
  235.     Function    OutOfRange: Boolean;                      Virtual;
  236.     Function    OutOfRangeMsg: String;                    Virtual;
  237.   end;
  238.   {$ENDIF}
  239.  
  240.  
  241.   PRealEdit = ^TRealEdit;
  242.   TRealEdit = Object(TFloatEdit)
  243.     Min   : Real; { smallest acceptable value }
  244.     Max   : Real; { largest acceptable value  }
  245.  
  246.     Constructor Init(var Bounds   : TRect;
  247.                          EditMask : String;
  248.                          AMin     : Real;
  249.                          AMax     : Real);
  250.     Function    DataSize: Word;                           Virtual;
  251.     Procedure   GetData(var Rec);                         Virtual;
  252.     Procedure   SetData(var Rec);                         Virtual;
  253.     Function    OutOfRange: Boolean;                      Virtual;
  254.     Function    OutOfRangeMsg: String;                    Virtual;
  255.   end;
  256.  
  257.  
  258.   { This descendant of TDialog has mehods for locking/unlocking fields
  259.     on the fly. It also contains some the logic for required fields.
  260.     If you assign an ID number to the entry fields you can later pass
  261.     that ID to LockField to later lock or unlock a field.
  262.   }
  263.   PEntryDialog  = ^TEntryDialog;        {$IFDEF USE_TVSCROLL}
  264.   TEntryDialog  = Object(TScrollDialog) {$ELSE}
  265.   TEntryDialog  = Object(TDialog)       {$ENDIF}
  266.     Constructor Init(var Bounds : TRect;
  267.                          ATitle : TTitleStr);
  268.     Function    FindField(ID : Word): Pointer;
  269.     Procedure   LockField(ID     : Word;
  270.                           Enable : Boolean);
  271.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  272.     {$IFDEF USE_TVSCROLL}
  273.     Procedure   Insert(P : PView);
  274.     {$ENDIF}
  275.   end;
  276.  
  277.  
  278.   PNewCheckBoxes = ^TNewCheckBoxes;
  279.   TNewCheckBoxes = Object(TCheckBoxes)
  280.     PostEdit  : Pointer;
  281.     ID        : Word;
  282.     LLabel    : PView;
  283.     EditFlags : Word;
  284.  
  285.     Constructor Init(var Bounds  : TRect;
  286.                          AStrings: PSItem);
  287.     Procedure   SetPostEdit(P : Pointer);
  288.     Function    Empty: Boolean;                           Virtual;
  289.     Procedure   SetEditFlag(AFlag : Word;
  290.                             Enable: Boolean);
  291.     Procedure   AddLabel(ALabel : PView);
  292.     Procedure   Lock;
  293.     Procedure   UnLock;
  294.     Procedure   SetID(AFieldID : Word);
  295.     Function    GetID: Word;
  296.     {$IFDEF HAVE_RTL}
  297.     Procedure   Select;                                   Virtual;
  298.     {$ENDIF}
  299.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  300.     Function    Valid(Command: Word): Boolean;            Virtual;
  301.     Procedure   SetState(AState : Word;
  302.                          Enable : Boolean);               Virtual;
  303.  
  304.   end;
  305.  
  306.  
  307.   PNewRadioButtons = ^TNewRadioButtons;
  308.   TNewRadioButtons = Object(TRadioButtons)
  309.     PostEdit  : Pointer;
  310.     ID        : Word;
  311.     LLabel    : PView;
  312.     EditFlags : Word;
  313.  
  314.     Constructor Init(var Bounds  : TRect;
  315.                          AStrings: PSItem);
  316.     Procedure   SetPostEdit(P : Pointer);
  317.     Function    Empty: Boolean;                           Virtual;
  318.     Procedure   SetEditFlag(AFlag : Word;
  319.                             Enable: Boolean);
  320.     Procedure   AddLabel(ALabel : PView);
  321.     Procedure   Lock;
  322.     Procedure   UnLock;
  323.     Procedure   SetID(AFieldID : Word);
  324.     Function    GetID: Word;
  325.     {$IFDEF HAVE_RTL}
  326.     Procedure   Select;                                   Virtual;
  327.     {$ENDIF}
  328.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  329.     Function    Valid(Command: Word): Boolean;            Virtual;
  330.     Procedure   SetState(AState : Word;
  331.                          Enable : Boolean);               Virtual;
  332.  
  333.   end;
  334.  
  335.  
  336. CONST
  337.   AnyChar     = 'X';         { any character                        }
  338.   ForceUp     = 'U';         { any character, force upper case      }
  339.   ForceLo     = 'L';         { any character, force lower case      }
  340.   AlphaOnly   = 'a';         { alpha numeric only                   }
  341.   UpperAlpha  = 'u';         { alpha numeric only, force upper case }
  342.   LowerAlpha  = 'l';         { alpha numeric only, force lower case }
  343.   NumberOnly  = '#';         { numbers, minus, period               }
  344.   DigitOnly   = '9';         { numbers only                         }
  345.   HexOnly     = '&';         { hexadecimal numbers                  }
  346.  
  347.  
  348.   EditMaskChars : TCharSet = [AnyChar, ForceUp, ForceLo, AlphaOnly,
  349.                               UpperAlpha, LowerAlpha, NumberOnly,
  350.                               DigitOnly, HexOnly];
  351.  
  352.   AnyCharSet    : TCharSet = [#32..#255];
  353.   AlphaOnlySet  : TCharSet = ['0'..'9', 'A'..'Z', 'a'..'z', ' '];
  354.   DigitOnlySet  : TCharSet = ['0'..'9'];
  355.   NumberOnlySet : TCharSet = ['0'..'9', '-'];
  356.   HexOnlySet    : TCharSet = ['0'..'9', 'A'..'F', 'a'..'f', '$'];
  357.  
  358.  
  359.   DateMaskSet   : TCharSet = ['m','M', 'd','D', 'y','Y', DateSlash];
  360.  
  361.  
  362.  
  363.