cxspinedit.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,961 行 · 第 1/5 页
PAS
1,961 行
{********************************************************************}
{ }
{ 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 cxSpinEdit;
{$I cxVer.inc}
interface
uses
Windows,
{$IFDEF DELPHI6}
Variants,
{$ENDIF}
Classes, Controls, Forms, Graphics, SysUtils, cxClasses, cxContainer,
cxControls, cxDataStorage, cxDataUtils, cxEdit, cxGraphics, cxMaskEdit,
cxTextEdit, cxVariants, cxLookAndFeelPainters, cxFilterControlUtils;
const
cxSpinBackwardButtonIndex = 0;
cxSpinForwardButtonIndex = 1;
cxSpinFastBackwardButtonIndex = 2;
cxSpinFastForwardButtonIndex = 3;
type
TcxSpinBoundsCheckingKind = (bckDoNotExceed, bckExtendToBound, bckCircular);
TcxSpinEditButtonsPosition = (sbpHorzLeftRight, sbpHorzRight, sbpVert);
TcxSpinEditButton = (sebBackward, sebForward, sebFastBackward, sebFastForward);
{ TcxSpinEditViewInfo }
TcxSpinEditViewInfo = class(TcxCustomTextEditViewInfo)
protected
procedure DrawHotFlatButtonBorder(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo;
var ARect: TRect; out AContentRect: TRect; var APenColor, ABrushColor: TColor); override;
procedure DrawNativeButtonBorder(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo;
var ARect: TRect; out AContentRect: TRect; var APenColor, ABrushColor: TColor); override;
procedure DrawUltraFlatButtonBorder(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo;
AIsOffice11Style: Boolean; var ARect: TRect; var AContentRect: TRect; out APenColor, ABrushColor: TColor); override;
procedure DrawNativeButtonBackground(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo; const ARect: TRect); override;
procedure InternalPaint(ACanvas: TcxCanvas); override;
public
ArrowSize: Integer;
ButtonsPosition: TcxSpinEditButtonsPosition;
DelimiterLine: array[0..1] of TPoint;
procedure DrawButtonContent(ACanvas: TcxCanvas; AButtonVisibleIndex: Integer;
const AContentRect: TRect; APenColor, ABrushColor: TColor;
ANeedOffsetContent: Boolean); override;
end;
{ TcxSpinEditViewData }
TcxSpinEditPressedState = (epsNone, epsDown, epsUp, epsFastDown, epsFastUp);
TcxCustomSpinEditProperties = class;
TcxSpinEditViewData = class(TcxCustomTextEditViewData)
private
function GetProperties: TcxCustomSpinEditProperties;
protected
function CanPressButton(AViewInfo: TcxCustomEditViewInfo; AButtonVisibleIndex: Integer):
Boolean; override;
function IsButtonPressed(AViewInfo: TcxCustomEditViewInfo; AButtonVisibleIndex:
Integer): Boolean; override;
procedure CalculateButtonNativeInfo(AButtonViewInfo: TcxEditButtonViewInfo); override;
public
PressedState: TcxSpinEditPressedState;
procedure Calculate(ACanvas: TcxCanvas; const ABounds: TRect; const P: TPoint;
Button: TcxMouseButton; Shift: TShiftState; AViewInfo: TcxCustomEditViewInfo;
AIsMouseEvent: Boolean); override;
procedure CalculateButtonBounds(ACanvas: TcxCanvas; AViewInfo: TcxCustomEditViewInfo;
AButtonVisibleIndex: Integer; var ButtonsRect: TRect); override;
procedure CalculateButtonViewInfo(ACanvas: TcxCanvas; AViewInfo: TcxCustomEditViewInfo;
AButtonVisibleIndex: Integer; var ButtonsRect: TRect); override;
procedure CheckButtonsOnly(AViewInfo: TcxCustomEditViewInfo;
APrevButtonsWidth, AButtonsWidth: Integer); override;
function IgnoreButtonWhileStretching(
AButtonVisibleIndex: Integer): Boolean; override;
property Properties: TcxCustomSpinEditProperties read GetProperties;
end;
{ TcxSpinEditButtons }
TcxSpinEditButtons = class(TPersistent)
private
FOwner: TPersistent;
FPosition: TcxSpinEditButtonsPosition;
FShowFastButtons: Boolean;
FVisible: Boolean;
function GetProperties: TcxCustomSpinEditProperties;
procedure SetPosition(Value: TcxSpinEditButtonsPosition);
procedure SetShowFastButtons(Value: Boolean);
procedure SetVisible(Value: Boolean);
protected
procedure Changed;
property Properties: TcxCustomSpinEditProperties read GetProperties;
public
constructor Create(AOwner: TPersistent); virtual;
procedure Assign(Source: TPersistent); override;
published
property Position: TcxSpinEditButtonsPosition read FPosition
write SetPosition default sbpVert;
property ShowFastButtons: Boolean read FShowFastButtons
write SetShowFastButtons default False;
property Visible: Boolean read FVisible
write SetVisible default True;
end;
{ TcxSpinEditPropertiesValues }
TcxSpinEditPropertiesValues = class(TcxTextEditPropertiesValues)
private
FValueType: Boolean;
procedure SetValueType(Value: Boolean);
public
procedure Assign(Source: TPersistent); override;
procedure RestoreDefaults; override;
published
property ValueType: Boolean read FValueType write SetValueType stored False;
end;
{ TcxCustomSpinEditProperties }
TcxSpinEditValueType = (vtInt, vtFloat);
TcxCustomSpinEdit = class;
TcxSpinEditGetValueEvent = procedure(Sender: TObject; const AText: TCaption;
out AValue: Variant; var ErrorText: TCaption; var Error: Boolean) of object;
TcxCustomSpinEditProperties = class(TcxCustomMaskEditProperties)
private
FSpinButtons: TcxSpinEditButtons;
FCanEdit: Boolean;
FCircular: Boolean;
FIncrement, FLargeIncrement: Double;
FExceptionOnInvalidInput: Boolean;
FUseCtrlIncrement: Boolean;
FValueType: TcxSpinEditValueType;
FOnGetValue: TcxSpinEditGetValueEvent;
function DoubleAsValueType(AValue: Double;
AValueType: TcxSpinEditValueType): Double;
function GetAssignedValues: TcxSpinEditPropertiesValues;
function GetValueType: TcxSpinEditValueType;
function IsIncrementStored: Boolean;
function IsLargeIncrementStored: Boolean;
function IsValueTypeStored: Boolean;
procedure ReadZeroIncrement(Reader: TReader);
procedure ReadZeroLargeIncrement(Reader: TReader);
procedure SetAssignedValues(Value: TcxSpinEditPropertiesValues);
procedure SetCircular(Value: Boolean);
procedure SetSpinButtons(Value: TcxSpinEditButtons);
procedure SetValueType(Value: TcxSpinEditValueType);
function TryTextToValue(S: string; out AValue: TcxEditValue): Boolean;
function VarToCurrentValueType(AValue: TcxEditValue): TcxEditValue;
procedure WriteZeroIncrement(Writer: TWriter);
procedure WriteZeroLargeIncrement(Writer: TWriter);
protected
function DefaultFocusedDisplayValue: TcxEditValue; override;
procedure DefineProperties(Filer: TFiler); override;
class function GetAssignedValuesClass: TcxCustomEditPropertiesValuesClass; override;
class function GetViewDataClass: TcxCustomEditViewDataClass; override;
function IsEditValueNumeric: Boolean; override;
function CheckValueBounds(const Value: Variant): Variant;
function ExtendValueUpToBound: Boolean; virtual;
function GetBoundsCheckingKind: TcxSpinBoundsCheckingKind; virtual;
function GetMaxMinValueForCurrentValueType(
AMinValue: Boolean = True): TcxEditValue;
function InternalMaxValue: TcxEditValue; virtual;
function InternalMinValue: TcxEditValue; virtual;
function IsDisplayValueNumeric: Boolean; virtual;
function IsValueBoundsValid(AValue: Extended): Boolean;
function PrepareValue(const AValue: TcxEditValue): Variant; virtual;
function PreserveSelection: Boolean; virtual;
function SetVariantType(const Value: TcxEditValue): TcxEditValue;
property AssignedValues: TcxSpinEditPropertiesValues read GetAssignedValues
write SetAssignedValues;
public
constructor Create(AOwner: TPersistent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure Changed; override;
function CreateViewData(AStyle: TcxCustomEditStyle;
AIsInplace: Boolean; APreviewMode: Boolean = False): TcxCustomEditViewData; override;
class function GetContainerClass: TcxContainerClass; override;
function GetEditValueSource(AEditFocused: Boolean): TcxDataEditValueSource; override;
class function GetViewInfoClass: TcxContainerViewInfoClass; override;
function IsDisplayValueValid(var DisplayValue: TcxEditValue; AEditFocused: Boolean): Boolean; override;
function IsEditValueValid(var EditValue: TcxEditValue;
AEditFocused: Boolean): Boolean; override;
procedure ValidateDisplayValue(var ADisplayValue: TcxEditValue;
var AErrorText: TCaption; var AError: Boolean;
AEdit: TcxCustomEdit); override;
// !!!
property CanEdit: Boolean read FCanEdit write FCanEdit default True;
property Circular: Boolean read FCircular write SetCircular default False;
property ExceptionOnInvalidInput: Boolean read FExceptionOnInvalidInput
write FExceptionOnInvalidInput default False;
property Increment: Double read FIncrement write FIncrement stored IsIncrementStored;
property LargeIncrement: Double read FLargeIncrement write FLargeIncrement
stored IsLargeIncrementStored;
property SpinButtons: TcxSpinEditButtons read FSpinButtons write SetSpinButtons;
property UseCtrlIncrement: Boolean read FUseCtrlIncrement write FUseCtrlIncrement default False;
property ValueType: TcxSpinEditValueType read GetValueType write SetValueType stored IsValueTypeStored;
property OnGetValue: TcxSpinEditGetValueEvent read FOnGetValue
write FOnGetValue;
end;
{ TcxSpinEditProperties }
TcxSpinEditProperties = class(TcxCustomSpinEditProperties)
published
property Alignment;
property AssignedValues;
property AutoSelect;
property BeepOnError;
property CanEdit;
property ClearKey;
property DisplayFormat;
property EchoMode;
property EditFormat;
property ExceptionOnInvalidInput;
property HideSelection;
property ImeMode;
property ImeName;
property ImmediatePost;
property Increment;
property LargeIncrement;
property MaxValue;
property MinValue;
property PasswordChar;
property ReadOnly;
property SpinButtons;
property UseCtrlIncrement;
property UseDisplayFormatWhenEditing;
property UseLeftAlignmentOnEditing;
property ValidateOnEnter;
property ValueType;
property OnChange;
property OnEditValueChanged;
property OnGetValue;
property OnValidate;
end;
{ TcxCustomSpinEdit }
TcxCustomSpinEdit = class(TcxCustomMaskEdit)
private
FInternalValue: TcxEditValue;
FIsCustomText: Boolean;
FIsCustomTextAction: Boolean;
FPressedState: TcxSpinEditPressedState;
FTimer: TcxTimer;
function GetProperties: TcxCustomSpinEditProperties;
function GetActiveProperties: TcxCustomSpinEditProperties;
procedure HandleTimer(Sender: TObject);
function IsValueStored: Boolean;
procedure SetInternalValue(AValue: TcxEditValue);
procedure SetPressedState(Value: TcxSpinEditPressedState);
procedure SetProperties(Value: TcxCustomSpinEditProperties);
procedure StopTracking;
protected
procedure ChangeHandler(Sender: TObject); override;
procedure CheckEditorValueBounds; override;
procedure DoButtonDown(AButtonVisibleIndex: Integer); override;
procedure DoEditKeyDown(var Key: Word; Shift: TShiftState); override;
procedure DoEditKeyPress(var Key: Char); override;
procedure DoEditKeyUp(var Key: Word; Shift: TShiftState); override;
function DoMouseWheelDown(Shift: TShiftState; MousePos:
TPoint): Boolean; override;
function DoMouseWheelUp(Shift: TShiftState; MousePos:
TPoint): Boolean; override;
procedure FocusChanged; override;
procedure Initialize; override;
function InternalGetEditingValue: TcxEditValue; override;
function InternalGetNotPublishedStyleValues: TcxEditStyleValues; override;
function IsValidChar(AChar: Char): Boolean; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure PropertiesChanged(Sender: TObject); override;
function RefreshContainer(const P: TPoint; Button: TcxMouseButton; Shift: TShiftState;
AIsMouseEvent: Boolean): Boolean; override;
procedure SynchronizeDisplayValue; override;
procedure SynchronizeEditValue; override;
procedure DoOnGetValue(const AText: TCaption; out AValue: Variant;
var ErrorText: TCaption; var Error: Boolean);
function GetIncrement(AButton: TcxSpinEditButton): Double; virtual;
function GetValue: Variant; virtual;
function IncrementValueToStr(const AValue: TcxEditValue): string; virtual;
function InternalPrepareEditValue(const ADisplayValue: TcxEditValue;
ARaiseException: Boolean; out EditValue: TcxEditValue;
out AErrorText: TCaption): Boolean;
function IsOnGetValueEventAssigned: Boolean;
procedure SetValue(const Value: Variant); virtual;
property PressedState: TcxSpinEditPressedState read FPressedState write SetPressedState;
property Value: Variant read GetValue write SetValue stored IsValueStored;
public
procedure ClearSelection; override;
procedure CutToClipboard; override;
class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
function Increment(AButton: TcxSpinEditButton): Boolean; virtual;
procedure PasteFromClipboard; override;
procedure PrepareEditValue(const ADisplayValue: TcxEditValue;
out EditValue: TcxEditValue; AEditFocused: Boolean); override;
property ActiveProperties: TcxCustomSpinEditProperties read GetActiveProperties;
property Properties: TcxCustomSpinEditProperties read GetProperties
write SetProperties;
end;
{ TcxSpinEdit }
TcxSpinEdit = class(TcxCustomSpinEdit)
private
function GetActiveProperties: TcxSpinEditProperties;
function GetProperties: TcxSpinEditProperties;
procedure SetProperties(Value: TcxSpinEditProperties);
public
class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
property ActiveProperties: TcxSpinEditProperties read GetActiveProperties;
published
property Anchors;
property AutoSize;
property BeepOnEnter;
property Constraints;
property DragMode;
property Enabled;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property Properties: TcxSpinEditProperties read GetProperties write SetProperties;
property ShowHint;
property Style;
property StyleDisabled;
property StyleFocused;
property StyleHot;
property TabOrder;
property TabStop;
property Value;
property Visible;
property DragCursor;
property DragKind;
property ImeMode;
property ImeName;
property OnClick;
{$IFDEF DELPHI5}
property OnContextPopup;
{$ENDIF}
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEditing;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseEnter;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?