{$I OVC.INC}

{$B-} {Complete Boolean Evaluation}
{$I+} {Input/Output-Checking}
{$P+} {Open Parameters}
{$T-} {Typed @ Operator}
{$W-} {Windows Stack Frame}
{$X+} {Extended Syntax}

{$IFNDEF Win32}
{$G+} {286 Instructions}
{$N+} {Numeric Coprocessor}
{$C MOVEABLE,DEMANDLOAD,DISCARDABLE}
{$ENDIF}

{*********************************************************}
{*                    OVCNF.PAS 2.00                     *}
{*     Copyright (c) TurboPower Software Co 1995-96      *}
{*                 All rights reserved.                  *}
{*********************************************************}

unit OvcNF;
  {-numeric field visual component}

interface

uses
  {$IFDEF Win32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
  Classes, Controls, Forms, Graphics, Menus, Messages, SysUtils,
  OvcBase, OvcCaret, OvcCmd, OvcColor, OvcConst,
  OvcData, OvcEf, OvcExcpt, OvcMisc, OvcPb, OvcStr, OvcVer;

type
  {numeric field types}
  TNumericDataType   = (
    nftLongInt, nftWord, nftInteger, nftByte, nftShortInt, nftReal,
    nftExtended, nftDouble, nftSingle, nftComp);

const
  DefNumericDataType = nftLongInt;
  DefNumericMask     = '##########';

type
  TOvcCustomNumericField = class(TOvcPictureBase)
  {.Z+}
  protected {private}
    {property instance variables}
    FNumericDataType   : TNumericDataType;
    FPictureMask       : string;

    {private instance variables}
    nfMaxLen    : Word;        {maximum length of numeric string}
    nfMaxDigits : Word;        {maximum # of digits to left of decimal}
    nfPlaces    : Word;        {# of decimal places}
    nfMinus     : Boolean;     {true if number is negative}
    nfTmp       : TEditString; {temporary input string}

    function nfGetDataType(Value : TNumericDataType) : Byte;
      {-return a Byte value representing the data type of this field}
    procedure nfReloadTmp;
      {-reload Tmp from efEditSt, etc.}
    procedure nfResetFieldProperties(FT : TNumericDataType);
      {-reset field properties based on current setings}
    procedure nfSetDefaultRanges;
      {-set default range values based on the field type}
    procedure nfSetMaxLength(Mask : PAnsiChar);
      {-determine and set MaxLength}

    procedure WMSetFocus(var Msg : TWMSetFocus);
      message WM_SETFOCUS;
    procedure WMKillFocus(var Msg : TWMKillFocus);
      message WM_KILLFOCUS;

  protected
    {VCL methods}
    procedure Assign(Source : TPersistent);
      override;
    procedure CreateParams(var Params : TCreateParams);
      override;
    procedure CreateWnd;
      override;

    procedure efCaretToEnd;
      override;
      {-move the caret to the end of the field}
    procedure efCaretToStart;
      override;
      {-move the caret to the beginning of the field}
    procedure efChangeMask(Mask : PAnsiChar);
      override;
      {-change the picture mask}
    procedure efEdit(var Msg : TMessage; Cmd : Word);
      override;
      {-process the specified editing command}
    function efGetDisplayString(Dest : PAnsiChar; Size : Word) : PAnsiChar;
      override;
      {-return the display string in Dest and a pointer as the result}
    procedure efIncDecValue(Wrap : Boolean; Delta : Double);
      override;
      {-increment field by Delta}
    function efTransfer(DataPtr : Pointer; TransferFlag : Word) : Word;
      override;
      {-transfer data to/from the entry fields}
        procedure pbRemoveSemiLits;
      override;
      {-remove semi-literal mask characters from the edit string}

    {virtual property methods}
    procedure efSetCaretPos(Value : Integer);
      override;
      {-set position of caret within the field}
    procedure nfSetDataType(Value : TNumericDataType);
      virtual;
      {-set the data type for this field}
    procedure nfSetPictureMask(const Value : string);
      virtual;
      {-set the picture mask}
  {.Z-}

  public
    constructor Create(AOwner: TComponent);
      override;

  {.Z+}
    function efValidateField : Word;
      override;
      {-validate contents of field; result is error code or 0}
  {.Z-}

    {public properties}
    property DataType : TNumericDataType
      read FNumericDataType
      write nfSetDataType
      default DefNumericDataType;

    property PictureMask : string
      read FPictureMask
      write nfSetPictureMask;
  end;

  TOvcNumericField = class(TOvcCustomNumericField)
  published
    {inherited properties}
    property DataType;              {needs to loaded before most other properties}
    property AutoAdvanceChar;
    property AutoAdvanceLeftRight;
    property AutoAdvanceUpDown;
    property AutoSelect;
    property AutoSize;
    property BeepOnError;
    property BorderStyle;
    property CaretIns;
    property CaretOvr;
    property Color;
    property Controller;
    property Ctl3D;
    property DragCursor;
    property DragMode;
    property Enabled;
    property ErrorColors;
    property Font;
    property HighlightColors;
    property InputRequired;
    property PadChar;
    property ParentColor default DefParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PictureMask;
    property PopupMenu;
    property RangeHi stored False;
    property RangeLo stored False;
    property ReadOnly;
    property ShowHint;
    property SoftValidation;
    property TabOrder;
    property TabStop default DefTabStop;
    property Tag;
    property TextMargin;
    property Uninitialized;
    property Visible;
    property ZeroDisplay;
    property ZeroDisplayValue;

    {inherited events}
    property OnChange;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnError;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    {$IFDEF Win32}
    property OnStartDrag;
    {$ENDIF}
    property OnUserCommand;
    property OnUserValidation;
  end;

implementation
