📄 flatedits.pas
字号:
unit FlatEdits;
interface
{$I FlatStyle.inc}
uses
Windows, Messages, Classes, Controls, Forms, Graphics, StdCtrls, SysUtils,
FlatUtilitys, DB, DBCtrls, Mask, FlatBtns;
type
{ TFlatLabel }
TFlatLabel = class(TCustomLabel)
private
function GetTop: Integer;
function GetLeft: Integer;
function GetWidth: Integer;
function GetHeight: Integer;
procedure SetHeight(const Value: Integer);
procedure SetWidth(const Value: Integer);
protected
procedure AdjustBounds; override;
public
constructor Create(AOwner: TComponent); override;
published
property BiDiMode;
property Caption;
property Color;
property DragCursor;
property DragKind;
property DragMode;
property Font;
property Height: Integer read GetHeight write SetHeight;
property Left: Integer read GetLeft;
property ParentBiDiMode;
property ParentColor;
property ParentFont;
property Top: Integer read GetTop;
property Transparent;
property Layout;
property WordWrap;
property Width: Integer read GetWidth write SetWidth;
end;
{ TCustomFlatEdit }
TCustomFlatEdit = class(TCustomEdit)
private
FUseAdvColors: Boolean;
FAdvColorFocused: TAdvColors;
FAdvColorBorder: TAdvColors;
FParentColor: Boolean;
FFocusedColor: TColor;
FBorderColor: TColor;
FFlatColor: TColor;
MouseInControl: Boolean;
FAlignment: TAlignment;
fLabel : TLabel;
FLabelSpacing: Integer;
FEditLabel: TFlatLabel;
FLabelPosition: TLabelPosition;
procedure SetColors (Index: Integer; Value: TColor);
procedure SetAdvColors (Index: Integer; Value: TAdvColors);
procedure SetUseAdvColors (Value: Boolean);
procedure SetParentColor (Value: Boolean);
protected
procedure RedrawBorder (const Clip: HRGN);
procedure NewAdjustHeight;
procedure CMEnabledChanged (var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMFontChanged (var Message: TMessage); message CM_FONTCHANGED;
procedure CMMouseEnter (var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave (var Message: TMessage); message CM_MOUSELEAVE;
procedure CMTextChanged (var Message: TMessage); message CM_TEXTCHANGED;
procedure WMSetFocus (var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus (var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure WMNCCalcSize (var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
procedure WMNCPaint (var Message: TMessage); message WM_NCPAINT;
procedure CMSysColorChange (var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMParentColorChanged (var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
procedure SetAlignment(const Value: TAlignment);
procedure LabelMouseEnter(Sender: TObject);
procedure SeTBEPosition(const Value: TLabelPosition);
procedure SetLabelSpacing(const Value: Integer);
procedure SetName(const Value: TComponentName); override;
procedure CMVisiblechanged(var Message: TMessage); message CM_VISIBLECHANGED;
procedure CMBidimodechanged(var Message: TMessage); message CM_BIDIMODECHANGED;
procedure SetParent(AParent: TWinControl); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure KeyPress(var Key: Char); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure CalcAdvColors;
procedure Loaded; override;
property EditLabel: TFlatLabel read FEditLabel;
property LabelPosition: TLabelPosition read FLabelPosition write SeTBEPosition default lpLeft;
property LabelSpacing: Integer read FLabelSpacing write SetLabelSpacing default 3;
property ColorFocused: TColor index 0 read FFocusedColor write SetColors default clWhite;
property ColorBorder: TColor index 1 read FBorderColor write SetColors default $004080FF;
property ColorFlat: TColor index 2 read FFlatColor write SetColors default $00E1EAEB;
property ParentColor: Boolean read FParentColor write SetParentColor default false;
property AdvColorFocused: TAdvColors index 0 read FAdvColorFocused write SetAdvColors default 10;
property AdvColorBorder: TAdvColors index 1 read FAdvColorBorder write SetAdvColors default 50;
property UseAdvColors: Boolean read FUseAdvColors write SetUseAdvColors default false;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
property CharCase;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property MaxLength;
property OEMConvert;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
{$IFDEF DFS_DELPHI_4_UP}
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
property OnEndDock;
property OnStartDock;
{$ENDIF}
public
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
procedure SetupInternalLabel;
procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
end;
{ TFlatEdit }
TFlatEdit = class(TCustomFlatEdit)
published
property Alignment;
property ColorFocused;
property ColorBorder;
property ColorFlat;
property ParentColor;
property AdvColorFocused;
property AdvColorBorder;
property UseAdvColors;
property CharCase;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property MaxLength;
property OEMConvert;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property EditLabel;
property LabelPosition;
property LabelSpacing;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
{$IFDEF DFS_DELPHI_4_UP}
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
property OnEndDock;
property OnStartDock;
{$ENDIF}
end;
{ TFlatDBEdit }
TFlatDBEdit = class(TFlatEdit)
private
FDataLink: TFieldDataLink;
FCanvas: TControlCanvas;
FAlignment: TAlignment;
FFocused: Boolean;
procedure ActiveChange(Sender: TObject);
procedure DataChange(Sender: TObject);
procedure EditingChange(Sender: TObject);
function GetDataField: string;
function GetDataSource: TDataSource;
function GetField: TField;
function GetReadOnly: Boolean;
function GetTextMargins: TPoint;
procedure ResetMaxLength;
procedure SetDataField(const Value: string);
procedure SetDataSource(Value: TDataSource);
procedure SetFocused(Value: Boolean);
procedure SetReadOnly(Value: Boolean);
procedure UpdateData(Sender: TObject);
procedure WMCut(var Message: TMessage); message WM_CUT;
procedure WMPaste(var Message: TMessage); message WM_PASTE;
procedure WMUndo(var Message: TMessage); message WM_UNDO;
procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure CMGetDataLink(var Message: TMessage); message CM_GETDATALINK;
protected
procedure Change; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure Loaded; override;
procedure Notification(AComponent: TComponent;Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function ExecuteAction(Action: TBasicAction): Boolean; override;
function UpdateAction(Action: TBasicAction): Boolean; override;
function UseRightToLeftAlignment: Boolean; override;
property Field: TField read GetField;
published
property Anchors;
property AutoSelect;
property AutoSize;
property BiDiMode;
property BorderStyle;
property CharCase;
property Color;
property Constraints;
property Ctl3D;
property DataField: string read GetDataField write SetDataField;
property DataSource: TDataSource read GetDataSource write SetDataSource;
property EditLabel;
property LabelPosition;
property LabelSpacing;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property ImeMode;
property ImeName;
property MaxLength;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
{ TFlatInteger }
TFlatInteger = class(TCustomFlatEdit)
private
FMinValue: LongInt;
FMaxValue: LongInt;
FIncrement: LongInt;
FButton: TFlatSpinButton;
FEditorEnabled: Boolean;
function GetMinHeight: Integer;
function GetValue: LongInt;
function CheckValue (NewValue: LongInt): LongInt;
procedure SetValue (NewValue: LongInt);
procedure SetEditRect;
procedure WMSize (var Message: TWMSize); message WM_SIZE;
procedure CMEnter (var Message: TCMGotFocus); message CM_ENTER;
procedure CMExit (var Message: TCMExit); message CM_EXIT;
procedure WMPaste (var Message: TWMPaste); message WM_PASTE;
procedure WMCut (var Message: TWMCut); message WM_CUT;
protected
function IsValidChar (Key: Char): Boolean; virtual;
procedure UpClick (Sender: TObject); virtual;
procedure DownClick (Sender: TObject); virtual;
procedure KeyDown (var Key: Word; Shift: TShiftState); override;
procedure KeyPress (var Key: Char); override;
procedure CreateParams (var Params: TCreateParams); override;
procedure Loaded; override;
procedure CreateWnd; override;
public
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
property Button: TFlatSpinButton read FButton;
published
property Alignment;
property ColorFocused;
property ColorBorder;
property ColorFlat;
property AdvColorFocused;
property AdvColorBorder;
property UseAdvColors;
property AutoSelect;
property AutoSize;
property DragCursor;
property DragMode;
property EditorEnabled: Boolean read FEditorEnabled write FEditorEnabled default True;
property Enabled;
property Font;
property Increment: LongInt read FIncrement write FIncrement default 1;
property MaxValue: LongInt read FMaxValue write FMaxValue;
property MinValue: LongInt read FMinValue write FMinValue;
property EditLabel;
property LabelPosition;
property LabelSpacing;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Value: LongInt read GetValue write SetValue;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
{$IFDEF DFS_COMPILER_4_UP}
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
property OnEndDock;
property OnStartDock;
{$ENDIF}
end;
{ TFlatFloat }
TFlatFloat = class(TCustomFlatEdit)
private
FPrecision, FDigits: Integer;
FFloatFormat: TFloatFormat;
FMinValue: Extended;
FMaxValue: Extended;
FIncrement: Extended;
FButton: TFlatSpinButton;
FEditorEnabled: Boolean;
function GetMinHeight: Integer;
function GetValue: Extended;
function CheckValue (Value: Extended): Extended;
procedure SetValue (Value: Extended);
procedure SetPrecision (Value: Integer);
procedure SetDigits (Value: Integer);
procedure SetFloatFormat (Value: TFloatFormat);
procedure SetEditRect;
procedure WMSize (var Message: TWMSize); message WM_SIZE;
procedure CMEnter (var Message: TCMGotFocus); message CM_ENTER;
procedure CMExit (var Message: TCMExit); message CM_EXIT;
procedure WMPaste (var Message: TWMPaste); message WM_PASTE;
procedure WMCut (var Message: TWMCut); message WM_CUT;
protected
function IsValidChar (Key: Char): Boolean; virtual;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -