📄 sxskinedit.pas
字号:
unit SXSkinEdit;
////////////////////////////////////////////////////////////////////////////////
// SXSkinComponents: Skinnable Visual Controls for Delphi and C++Builder //
//----------------------------------------------------------------------------//
// Version: 1.2.1 //
// Author: Alexey Sadovnikov //
// Web Site: http://www.saarixx.info/sxskincomponents/ //
// E-Mail: sxskincomponents@saarixx.info //
//----------------------------------------------------------------------------//
// LICENSE: //
// 1. You may freely distribute this file. //
// 2. You may not make any changes to this file. //
// 3. The only person who may change this file is Alexey Sadovnikov. //
// 4. You may use this file in your freeware projects. //
// 5. If you want to use this file in your shareware or commercial project, //
// you should purchase a project license or a personal license of //
// SXSkinComponents: http://saarixx.info/sxskincomponents/en/purchase.htm //
// 6. You may freely use, distribute and modify skins for SXSkinComponents. //
// 7. You may create skins for SXSkinComponents. //
//----------------------------------------------------------------------------//
// Copyright (C) 2006-2007, Alexey Sadovnikov. All Rights Reserved. //
////////////////////////////////////////////////////////////////////////////////
interface
{$I Compilers.inc}
uses Windows, Classes, Controls, Messages, StdCtrls, SXSkinControl, Forms,
SysUtils, Graphics, GR32, SXSkinLibrary, GR32_Blend, Types;
const
VARE_W = 1;
VARE_H = 2;
type
{$IFNDEF COMPILER_9_UP}
TSelection=record
StartPos,EndPos:Integer;
end;
TWMPrint=packed record
Msg:Cardinal;
DC:HDC;
Flags:Cardinal;
Result:Integer;
end;
{$ENDIF}
TSXSkinCustomEdit=class;
TSXSkinCustomEditThread=class(TThread)
public
Control:TSXSkinCustomEdit;
constructor Create;
procedure Execute; override;
procedure DoEvent;
end;
TSXSkinEditResetParam=(erpTextControl,
erpTextControlOnFontChange,
erpInvalidateOnStyleChange);
TSXSkinEditResetParams=set of TSXSkinEditResetParam;
TSXEditVariableComparer=class(TSXVariableComparer)
private
Control:TSXSkinCustomEdit;
function GetValue(VarID:Integer):Integer;
protected
function VarListOnGetVariable(const VarName:String;var Error:Boolean):Single; override;
public
function GetVarValsForVarList(VarList:TList):TList; override;
function Changed(VarList:TList;OldVarVals:TList):Boolean; override;
procedure Update(VarList:TList;VarVals:TList); override;
procedure DestroyVarList(VarList:TList); override;
procedure DestroyVarVals(VarList:TList;VarVals:TList); override;
end;
TSXSkinCustomEditTextControl=class(TSXWinControl)
private
FParentEdit:TSXSkinCustomEdit;
FOldSelLength:Integer;
FOldSelStart:Integer;
FCreating:Boolean;
FModified:Boolean;
FChanging:Boolean;
FFontChanged:Boolean;
FLastFocused:Boolean;
LastClickTime:Cardinal;
procedure CMEnter(var Message:TCMGotFocus); message CM_ENTER;
procedure CNCommand(var Message:TWMCommand); message CN_COMMAND;
procedure CMTextChanged(var Message:TMessage); message CM_TEXTCHANGED;
procedure WMContextMenu(var Message:TWMContextMenu); message WM_CONTEXTMENU;
procedure WMEraseBkgnd(var Msg:TWMEraseBkgnd); message WM_ERASEBKGND;
procedure WMSetFocus(var Msg:TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Msg:TWMKillFocus); message WM_KILLFOCUS;
procedure WMMouseLeave(var Msg:TMessage); message WM_MOUSELEAVE;
procedure WMMouseMove(var Msg:TWMMouseMove); message WM_MOUSEMOVE;
procedure WMLButtonDown(var Msg:TWMLButtonDown); message WM_LBUTTONDOWN;
procedure WMLButtonUp(var Msg:TWMLButtonUp); message WM_LBUTTONUP;
procedure WMLButtonDblClk(var Msg:TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
procedure CMFontChanged(var Message:TMessage); message CM_FONTCHANGED;
procedure WMPrint(var Msg:TWMPrint); message WM_PRINT;
procedure CNChar(var Msg:TMessage); message CN_CHAR;
procedure CNKeyDown(var Msg:TMessage); message CN_KEYDOWN;
protected
function CapturesMouseAt(X,Y:Integer):Boolean; override;
procedure Change; dynamic;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWindowHandle(const Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DestroyWnd; override;
procedure DoSetMaxLength(Value: Integer); virtual;
procedure LocalKeyDown(Sender:TObject;var Key:Word;Shift:TShiftState);
function LocalGetText:TCaption;
procedure LocalSetText(Value:TCaption);
procedure KeyDown(var Key:Word;Shift:TShiftState); override;
procedure KeyUp(var Key:Word;Shift:TShiftState); override;
procedure KeyPress(var Key:Char); override;
public
constructor Create(AOwner: TComponent); override;
procedure Clear; virtual;
procedure DefaultHandler(var Message); override;
published
property TabStop default True;
property Text:TCaption read LocalGetText write LocalSetText;
end;
TSXSkinCustomEdit=class(TSXSkinCustomControl)
private
FMaxLength:Integer;
FPassword:Boolean;
FReadOnly:Boolean;
FAutoSelect:Boolean;
FHideSelection:Boolean;
FOEMConvert:Boolean;
FCharCase:TEditCharCase;
FOnChange:TNotifyEvent;
FTextControl:TSXSkinCustomEditTextControl;
FMouseOver:Boolean;
FOnMouseEnter:TNotifyEvent;
FOnMouseLeave:TNotifyEvent;
FOnUserModified:TNotifyEvent;
FAutoSizeHeight:Boolean;
FFrequentChange:Boolean;
FAlignment:TAlignment;
//
FLastEditTransform:TSXTransformEffectData;
FDoneSteps:Integer;
FLastEdit:TBitmap32;
FThread:TSXSkinCustomEditThread;
//
FLastStyle:String;
FLastFontData:TSXFontData;
FLastChangedValue:String;
FBackBrush:TBrush;
FBrushBitmap:TBitmap;
CEID_Back:Integer;
VComparer:TSXEditVariableComparer;
function GetModified:Boolean;
function GetCanUndo:Boolean;
function GetTabStop:Boolean;
function GetTabOrder:Integer;
function GetText:String;
procedure SetText(const Value:String);
procedure SetCharCase(Value:TEditCharCase);
procedure SetHideSelection(Value:Boolean);
procedure SetMaxLength(Value:Integer);
procedure SetModified(Value:Boolean);
procedure SetOEMConvert(Value:Boolean);
procedure SetPassword(Value:Boolean);
procedure SetReadOnly(Value:Boolean);
procedure SetSelText(const Value:String);
procedure SetTabStop(Value:Boolean);
procedure SetTabOrder(Value:Integer);
procedure SetAutoSizeHeight(Value:Boolean);
procedure SetAlignment(Value:TAlignment);
function OnGetVariable(const VarName:String;var Error:Boolean):Single;
procedure CMFontChanged(var Message:TMessage); message CM_FONTCHANGED;
procedure WMCtlColorEdit(var Msg:TMessage); message WM_CTLCOLOREDIT;
procedure WMCtlColorStatic(var Msg:TMessage); message WM_CTLCOLORSTATIC;
procedure InternalMouseEnter;
procedure InternalMouseLeave;
procedure InvalidateEdit;
procedure DoThreadActions;
procedure CreateThreadIfNeeded;
function HasUnusualSkinStyle:Boolean;
procedure GetCurrentTransformEffect(Action:TSXGlyphChangeAction;var Effect:TSXTransformEffectData);
protected
procedure MouseLeave; override;
procedure MouseMove(Shift:TShiftState;X,Y:Integer); override;
function CapturesMouseAt(X,Y:Integer):Boolean; override;
procedure SetEnabled(Value:Boolean); override;
procedure Loaded; override;
procedure PaintCurrentEStyle(Bitmap:TBitmap32;X,Y:Integer;Rect:TRect;Rgn:HRGN);
procedure PaintCurrentBlendedEStyle(Bitmap:TBitmap32;X,Y:Integer;Rect:TRect;Rgn:HRGN);
procedure DoSetMaxLength(Value: Integer); virtual;
function GetSelLength: Integer; virtual;
function GetSelStart: Integer; virtual;
function GetSelText: string; virtual;
procedure SetSelLength(Value: Integer); virtual;
procedure SetSelStart(Value: Integer); virtual;
procedure GetCurrentEState(var EState:TSXSkinEditStateParam);
procedure StartChanging(T:TSXGlyphChangeAction);
procedure ResetEditParams(Params:TSXSkinEditResetParams=[]);
procedure InternalSetBounds(ALeft,ATop,AWidth,AHeight:Integer);
property AutoSelect:Boolean read FAutoSelect write FAutoSelect default True;
property CharCase:TEditCharCase read FCharCase write SetCharCase default ecNormal;
property HideSelection:Boolean read FHideSelection write SetHideSelection default True;
property OEMConvert:Boolean read FOEMConvert write SetOEMConvert default False;
property Password:Boolean read FPassword write SetPassword default False;
property ParentColor default False;
public
function IsTransparent(X,Y:Integer;Limit:Integer=10):Boolean; override;
procedure PaintRectToBitmap(DestCanvasHandle:HDC;DestCanvasRect:TRect;
Rect:TRect;Rgn:HRGN;Bitmap:TBitmap32;X,Y:Integer;
WithSubItems:Boolean); override;
procedure SkinChanged; override;
procedure SetBounds(ALeft,ATop,AWidth,AHeight:Integer); override;
procedure Clear; virtual;
procedure ClearSelection;
procedure CopyToClipboard;
procedure CutToClipboard;
procedure PasteFromClipboard;
procedure Undo;
procedure ClearUndo;
function GetSelTextBuf(Buffer: PChar; BufSize: Integer): Integer; virtual;
procedure SelectAll;
procedure SetSelTextBuf(Buffer: PChar);
procedure InvalidateIfStyleChanged;
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
property Alignment:TAlignment read FAlignment write SetAlignment default taLeftJustify;
property CanUndo:Boolean read GetCanUndo;
property MaxLength:Integer read FMaxLength write SetMaxLength default 0;
property Modified:Boolean read GetModified write SetModified;
property ReadOnly:Boolean read FReadOnly write SetReadOnly default False;
property SelLength:Integer read GetSelLength write SetSelLength;
property SelStart:Integer read GetSelStart write SetSelStart;
property SelText:String read GetSelText write SetSelText;
property Text:String read GetText write SetText;
property SkinStyle stored HasUnusualSkinStyle;
property AutoSizeHeight:Boolean read FAutoSizeHeight write SetAutoSizeHeight default True;
property FrequentChange:Boolean read FFrequentChange write FFrequentChange default False;
property OnChange:TNotifyEvent read FOnChange write FOnChange;
property OnUserModified:TNotifyEvent read FOnUserModified write FOnUserModified;
published
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnKeyDown;
property OnKeyPress;
property TabStop:Boolean read GetTabStop write SetTabStop default True;
property TabOrder:Integer read GetTabOrder write SetTabOrder;
property OnMouseEnter:TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave:TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;
TSXSkinEdit=class(TSXSkinCustomEdit)
published
property Align;
property Alignment;
property Anchors;
property AutoSelect;
property AutoSizeHeight;
property CharCase;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property FrequentChange;
property HideSelection;
//property HintData;
property ImeMode;
property ImeName;
property MaxLength;
property OEMConvert;
property ParentFont;
property ParentShowHint;
property Password;
property PopupMenu;
property ReadOnly;
property ShowHint;
property SkinLibrary;
property SkinStyle;
property TabOrder;
property TabStop;
property Text;
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 OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUserModified;
end;
implementation
uses SXBitmap32Utils;
{ TSXSkinCustomEditThread }
constructor TSXSkinCustomEditThread.Create;
begin
inherited Create(True);
FreeOnTerminate:=False;
end;
procedure TSXSkinCustomEditThread.Execute;
begin
while not Terminated do
begin
SleepEx(30,True);
if not Suspended then
Synchronize(DoEvent);
end;
end;
procedure TSXSkinCustomEditThread.DoEvent;
begin
if Assigned(Control) then
Control.DoThreadActions;
end;
{ TSXEditVariableComparer }
function TSXEditVariableComparer.VarListOnGetVariable(const VarName:String;var Error:Boolean):Single;
var CurVarVal:Integer;
begin
Result:=1234;
CurVarVal:=-1;
if VarName='W' then
CurVarVal:=VARE_W else
if VarName='H' then
CurVarVal:=VARE_H;
if CurVarVal>=0 then
begin
if CurValList=nil then
CurValList:=TList.Create;
CurValList.Add(Pointer(CurVarVal));
end;
end;
function TSXEditVariableComparer.GetValue(VarID:Integer):Integer;
begin
Result:=0;
if Control<>nil then
begin
case VarID of
VARE_W: Result:=Control.Width;
VARE_H: Result:=Control.Height;
end;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -