cxcurrencyedit.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 747 行 · 第 1/2 页

PAS
747
字号

{********************************************************************}
{                                                                    }
{       Developer Express Visual Component Library                   }
{       ExpressEditors                                               }
{                                                                    }
{       Copyright (c) 1998-2008 Developer Express Inc.               }
{       ALL RIGHTS RESERVED                                          }
{                                                                    }
{   The entire contents of this file is protected by U.S. and        }
{   International Copyright Laws. Unauthorized reproduction,         }
{   reverse-engineering, and distribution of all or any portion of   }
{   the code contained in this file is strictly prohibited and may   }
{   result in severe civil and criminal penalties and will be        }
{   prosecuted to the maximum extent possible under the law.         }
{                                                                    }
{   RESTRICTIONS                                                     }
{                                                                    }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES            }
{   (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE     }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS    }
{   LICENSED TO DISTRIBUTE THE EXPRESSEDITORS AND ALL                }
{   ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
{                                                                    }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED       }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE         }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE        }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT   }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                       }
{                                                                    }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON        }
{   ADDITIONAL RESTRICTIONS.                                         }
{                                                                    }
{********************************************************************}

unit cxCurrencyEdit;

{$I cxVer.inc}

interface

uses
  Windows, Messages,
{$IFDEF DELPHI6}
  Types,
{$ENDIF}
  SysUtils, Classes, Controls, Clipbrd, cxContainer, cxDataStorage, cxDataUtils,
  cxEdit, cxTextEdit, cxFilterControlUtils;

type
  { TcxCurrencyEditPropertiesValues }

  TcxCurrencyEditPropertiesValues = class(TcxTextEditPropertiesValues)
  private
    FDecimalPlaces: Boolean;
    procedure SetDecimalPlaces(Value: Boolean);
  public
    procedure Assign(Source: TPersistent); override;
    procedure RestoreDefaults; override;
  published
    property DecimalPlaces: Boolean read FDecimalPlaces write SetDecimalPlaces
      stored False;
  end;

  { TcxCustomCurrencyEditProperties }

  TcxCustomCurrencyEditProperties = class(TcxCustomTextEditProperties)
  private
    FDecimalPlaces: Integer;
    FFormatChanging: Boolean;
    FNullable: Boolean;
    FNullString: string;
    FUseThousandSeparator: Boolean;
    function GetAssignedValues: TcxCurrencyEditPropertiesValues;
    function GetDecimalPlaces: Integer;
    function IsDecimalPlacesStored: Boolean;
    procedure SetAssignedValues(Value: TcxCurrencyEditPropertiesValues);
    procedure SetDecimalPlaces(Value: Integer);
    procedure SetNullable(const Value: Boolean);
    procedure SetNullString(const Value: string);
    procedure SetUseThousandSeparator(const Value: Boolean);
  protected
    class function GetAssignedValuesClass: TcxCustomEditPropertiesValuesClass; override;
    function GetDefaultDisplayFormat: string; override;
    function GetDisplayFormatOptions: TcxEditDisplayFormatOptions; override;
    function HasDigitGrouping(AIsDisplayValueSynchronizing: Boolean): Boolean; override;
    function InternalGetEditFormat(out AIsCurrency, AIsOnGetTextAssigned: Boolean;
      AEdit: TcxCustomTextEdit = nil): string; override; //for VCL .Net
    function IsEditValueNumeric: Boolean; override;
    function StrToFloatEx(S: string; var Value: Double): Boolean;
    property AssignedValues: TcxCurrencyEditPropertiesValues read GetAssignedValues
      write SetAssignedValues;
  public
    constructor Create(AOwner: TPersistent); override;
    procedure Assign(Source: TPersistent); override;
    class function GetContainerClass: TcxContainerClass; override;
    function GetEditValueSource(AEditFocused: Boolean): TcxDataEditValueSource; override;
    function IsDisplayValueValid(var DisplayValue: TcxEditValue; AEditFocused: Boolean): Boolean; override;
    procedure PrepareDisplayValue(const AEditValue: TcxEditValue;
      var DisplayValue: TcxEditValue; AEditFocused: Boolean); override;
    procedure ValidateDisplayValue(var ADisplayValue: TcxEditValue;
      var AErrorText: TCaption; var AError: Boolean;
      AEdit: TcxCustomEdit); override;
    // !!!
    property DecimalPlaces: Integer read GetDecimalPlaces write SetDecimalPlaces
      stored IsDecimalPlacesStored;
    property Nullable: Boolean read FNullable write SetNullable default True;
    property NullString: string read FNullString write SetNullString;
    property ValidateOnEnter default True;
    property UseThousandSeparator: Boolean read FUseThousandSeparator
      write SetUseThousandSeparator default False;
  end;

  { TcxCurrencyEditProperties }

  TcxCurrencyEditProperties = class(TcxCustomCurrencyEditProperties)
  published
    property Alignment;
    property AssignedValues;
    property AutoSelect;
    property ClearKey;
    property DecimalPlaces;
    property DisplayFormat;
    property EchoMode;
    property EditFormat;
    property HideSelection;
    property ImeMode;
    property ImeName;
    property MaxLength;
    property MaxValue;
    property MinValue;
    property Nullable;
    property NullString;
    property PasswordChar;
    property ReadOnly;
    property UseDisplayFormatWhenEditing;
    property UseLeftAlignmentOnEditing;
    property UseThousandSeparator;
    property ValidateOnEnter;
    property OnChange;
    property OnEditValueChanged;
    property OnValidate;
  end;

  { TcxCustomCurrencyEdit }

  TcxCustomCurrencyEdit = class(TcxCustomTextEdit)
  private
    function GetProperties: TcxCustomCurrencyEditProperties;
    function GetActiveProperties: TcxCustomCurrencyEditProperties;
    function GetValue: Double;
    procedure SetProperties(Value: TcxCustomCurrencyEditProperties);
    procedure SetValue(Value: Double);
  protected
    procedure CheckEditorValueBounds; override;
    procedure Initialize; override;
    function InternalGetEditingValue: TcxEditValue; override;
    function IsValidChar(Key: Char): Boolean; override;
    procedure KeyPress(var Key: Char); override;
    procedure PropertiesChanged(Sender: TObject); override;
  public
    class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
    procedure PasteFromClipboard; override;
    procedure PrepareEditValue(const ADisplayValue: TcxEditValue;
      out EditValue: TcxEditValue; AEditFocused: Boolean); override;
    property ActiveProperties: TcxCustomCurrencyEditProperties read GetActiveProperties;
    property Properties: TcxCustomCurrencyEditProperties read GetProperties
      write SetProperties;
    property Value: Double read GetValue write SetValue stored False;
  end;

  { TcxCurrencyEdit }

  TcxCurrencyEdit = class(TcxCustomCurrencyEdit)
  private
    function GetActiveProperties: TcxCurrencyEditProperties;
    function GetProperties: TcxCurrencyEditProperties;
    procedure SetProperties(Value: TcxCurrencyEditProperties);
  public
    class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
    property ActiveProperties: TcxCurrencyEditProperties read GetActiveProperties;
  published
    property Anchors;
    property AutoSize;
    property BeepOnEnter;
    property Constraints;
    property DragCursor;
    property DragKind;
    property DragMode;
    property EditValue;
    property Enabled;
    property ImeMode;
    property ImeName;
    property ParentColor;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property Properties: TcxCurrencyEditProperties read GetProperties
      write SetProperties;
    property ShowHint;
    property Style;
    property StyleDisabled;
    property StyleFocused;
    property StyleHot;
    property TabOrder;
    property TabStop;
    property Value;
    property Visible;
    property OnClick;
{$IFDEF DELPHI5}
    property OnContextPopup;
{$ENDIF}
    property OnDblClick;
    property OnEditing;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property BiDiMode;
    property ParentBiDiMode;
    property OnEndDock;
    property OnStartDock;
  end;

  { TcxFilterCurrencyEditHelper }

  TcxFilterCurrencyEditHelper = class(TcxFilterTextEditHelper)
  public
    class function GetFilterEditClass: TcxCustomEditClass; override;
    class function GetSupportedFilterOperators(
      AProperties: TcxCustomEditProperties;
      AValueTypeClass: TcxValueTypeClass;
      AExtendedSet: Boolean = False): TcxFilterControlOperators; override;
    class procedure InitializeProperties(AProperties,
      AEditProperties: TcxCustomEditProperties; AHasButtons: Boolean); override;
  end;

implementation

uses
{$IFDEF DELPHI6}
  Variants,
{$ENDIF}
  cxEditConsts, cxFormats, cxVariants, cxControls;

{$IFNDEF DELPHI6}
function StrToCurrDef(const S: string; const Default: Currency): Currency;
begin
  if not TextToFloat(PChar(S), Result, fvCurrency) then
    Result := Default;
end;
{$ENDIF}

{ TcxCurrencyEditPropertiesValues }

procedure TcxCurrencyEditPropertiesValues.Assign(Source: TPersistent);
begin
  if Source is TcxCurrencyEditPropertiesValues then
  begin
    BeginUpdate;
    try
      inherited Assign(Source);
      DecimalPlaces := TcxCurrencyEditPropertiesValues(Source).DecimalPlaces;
    finally
      EndUpdate;
    end;
  end
  else
    inherited Assign(Source);
end;

procedure TcxCurrencyEditPropertiesValues.RestoreDefaults;
begin
  BeginUpdate;
  try
    inherited RestoreDefaults;
    DecimalPlaces := False;
  finally
    EndUpdate;
  end;
end;

procedure TcxCurrencyEditPropertiesValues.SetDecimalPlaces(Value: Boolean);
begin
  if Value <> FDecimalPlaces then
  begin
    FDecimalPlaces := Value;
    Changed;
  end;
end;

{ TcxCustomCurrencyEditProperties }

constructor TcxCustomCurrencyEditProperties.Create(AOwner: TPersistent);
begin
  inherited Create(AOwner);
  FNullable := True;
  ValidateOnEnter := True;
end;

function TcxCustomCurrencyEditProperties.GetAssignedValues: TcxCurrencyEditPropertiesValues;
begin
  Result := TcxCurrencyEditPropertiesValues(FAssignedValues);
end;

function TcxCustomCurrencyEditProperties.GetDecimalPlaces: Integer;
begin
  if AssignedValues.DecimalPlaces then
    Result := FDecimalPlaces
  else
    Result := CurrencyDecimals;
end;

function TcxCustomCurrencyEditProperties.IsDecimalPlacesStored: Boolean;
begin
  Result := AssignedValues.DecimalPlaces;
end;

procedure TcxCustomCurrencyEditProperties.SetAssignedValues(
  Value: TcxCurrencyEditPropertiesValues);
begin
  FAssignedValues.Assign(Value);
end;

procedure TcxCustomCurrencyEditProperties.SetDecimalPlaces(Value: Integer);
begin
  if AssignedValues.DecimalPlaces and (Value = FDecimalPlaces) then
    Exit;
  AssignedValues.FDecimalPlaces := True;
  FDecimalPlaces := Value;
  Changed;
end;

procedure TcxCustomCurrencyEditProperties.SetNullable(
  const Value: Boolean);
begin
  if FNullable <> Value then
  begin
    FNullable := Value;
    Changed;
  end;
end;

procedure TcxCustomCurrencyEditProperties.SetNullString(
  const Value: string);
begin
  if FNullString <> Value then
  begin
    FNullString := Value;
    Changed;
  end;
end;

procedure TcxCustomCurrencyEditProperties.SetUseThousandSeparator(
  const Value: Boolean);
begin
  if FUseThousandSeparator <> Value then
  begin
    FUseThousandSeparator := Value;
    Changed;
  end;
end;

class function TcxCustomCurrencyEditProperties.GetAssignedValuesClass: TcxCustomEditPropertiesValuesClass;
begin
  Result := TcxCurrencyEditPropertiesValues;
end;

function TcxCustomCurrencyEditProperties.GetDefaultDisplayFormat: string;
begin

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?