📄 sxskinedit.pas
字号:
SetEStateFrom(Style.NUState);
end;
end else
if FTextControl.FLastFocused then
begin
SetEStateFrom(Style.NFState);
SetEStateFrom(Style.NUState);
end else SetEStateFrom(Style.NUState);
end;
end;
SetDefaultFontData(EState.FD,Font);
end;
procedure TSXSkinCustomEdit.InvalidateIfStyleChanged;
begin
ResetEditParams([erpTextControlOnFontChange,erpInvalidateOnStyleChange]);
end;
procedure TSXSkinCustomEdit.InternalMouseEnter;
begin
StartChanging(gcaHighlightIn);
FMouseOver:=True;
InvalidateIfStyleChanged;
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;
procedure TSXSkinCustomEdit.InternalMouseLeave;
begin
if FMouseOver then
begin
StartChanging(gcaHighlightOut);
FMouseOver:=False;
InvalidateIfStyleChanged;
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;
end;
procedure TSXSkinCustomEdit.MouseLeave;
begin
if FMouseOver then
InternalMouseLeave;
inherited;
end;
procedure TSXSkinCustomEdit.MouseMove(Shift:TShiftState;X,Y:Integer);
var B:Boolean;
P:TPoint;
begin
inherited;
if Enabled then
begin
P:=Point(X,Y);
B:=(X>=0) and (X<Width) and (Y>=0) and (Y<Height) and CapturesMouseAt(X,Y);
if B<>FMouseOver then
begin
if B then InternalMouseEnter else
InternalMouseLeave;
end;
end;
end;
procedure TSXSkinCustomEdit.StartChanging(T:TSXGlyphChangeAction);
var B:TBitmap32;
Rgn:HRGN;
NeedThread:Boolean;
ETransform:TSXTransformEffectData;
begin
GetCurrentTransformEffect(T,ETransform);
NeedThread:=HasTransformEffect(ETransform);
if NeedThread then
begin
CreateThreadIfNeeded;
B:=TBitmap32.Create;
B.SetSize(Width,Height);
B.Clear(0);
Rgn:=CreateRectRgn(0,0,Width,Height);
PaintCurrentBlendedEStyle(B,0,0,Rect(0,0,Width,Height),Rgn);
DeleteObject(Rgn);
FLastEdit.Free;
FLastEdit:=B;
if FLastEdit<>nil then
begin
FLastEdit.DrawMode:=dmBlend;
FLastEdit.CombineMode:=cmMerge;
end;
FDoneSteps:=1;
if FThread.Suspended then
FThread.Resume;
end else
if (FThread<>nil) and not FThread.Suspended then
begin
FDoneSteps:=MaxInt;
FThread.Suspend;
end;
FLastEditTransform:=ETransform;
end;
procedure TSXSkinCustomEdit.InvalidateEdit;
begin
InvalidateRect(Handle,nil,False);
end;
procedure TSXSkinCustomEdit.DoThreadActions;
begin
if not (csDestroying in ComponentState) then
begin
Inc(FDoneSteps);
if (FThread<>nil) and not FThread.Suspended and
(not HasTransformEffect(FLastEditTransform) or (FDoneSteps>=FLastEditTransform.StepsNum)) then
begin
FThread.Suspend;
end;
InvalidateEdit;
Update;
if FTextControl.HandleAllocated then
begin
InvalidateRect(FTextControl.Handle,nil,False);
FTextControl.Update;
end;
end;
end;
procedure TSXSkinCustomEdit.CreateThreadIfNeeded;
begin
if FThread=nil then
begin
FThread:=TSXSkinCustomEditThread.Create;
FThread.Control:=Self;
end;
end;
procedure TSXSkinCustomEdit.CMFontChanged(var Message:TMessage);
begin
inherited;
if not (csLoading in ComponentState) then
ResetEditParams([erpTextControlOnFontChange]);
end;
procedure TSXSkinCustomEdit.ResetEditParams(Params:TSXSkinEditResetParams=[]);
var EState:TSXSkinEditStateParam;
SetEState:Boolean;
Changed:Boolean;
EStyle:TSXSkinEditStyle;
A,H,TH:Integer;
NewTCBRect:TRect;
NewBRect:TRect;
procedure DoSetEState;
begin
if not SetEState then
begin
SetEState:=True;
GetCurrentEState(EState);
end;
end;
begin
SetEState:=False;
if Params*[erpTextControl,erpTextControlOnFontChange]<>[] then
begin
DoSetEState;
if erpTextControl in Params then Changed:=True else
Changed:=not SameFontData(EState.FD,FLastFontData);
FLastFontData:=EState.FD;
if Changed then
begin
FTextControl.Font.Name:=EState.FD.FontName;
FTextControl.Font.Size:=EState.FD.FontSize;
FTextControl.Font.Style:=EState.FD.FontStyle;
FTextControl.Font.Color:=WinColor(EState.FD.FontColor);
Canvas.Font:=FTextControl.Font;
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinEditStyle) then
begin
EStyle:=TSXSkinEditStyle(SkinLibrary.Styles[A]);
TH:=Canvas.TextHeight('1');
if FAutoSizeHeight then
begin
NewBRect:=Rect(0,0,Width,EStyle.TextTopOffset+EStyle.TextBottomOffset+TH);
OffsetRect(NewBRect,Left,Top);
if not EqualRect(NewBRect,BoundsRect) then
InternalSetBounds(NewBRect.Left,NewBRect.Top,
NewBRect.Right-NewBRect.Left,NewBRect.Bottom-NewBRect.Top);
end;
H:=Height-EStyle.TextTopOffset-EStyle.TextBottomOffset;
NewTCBRect:=Rect(EStyle.TextLeftOffset,EStyle.TextTopOffset+(H-TH) div 2,
Width-EStyle.TextRightOffset,EStyle.TextTopOffset+(H+TH) div 2);
if not EqualRect(FTextControl.BoundsRect,NewTCBRect) then
FTextControl.BoundsRect:=NewTCBRect;
end;
end;
end;
end;
if erpInvalidateOnStyleChange in Params then
begin
DoSetEState;
if EState.Style<>FLastStyle then
begin
FLastStyle:=EState.Style;
InvalidateEdit;
Update;
end;
end;
end;
procedure TSXSkinCustomEdit.Loaded;
begin
inherited;
ResetEditParams([erpTextControl,erpInvalidateOnStyleChange]);
SendMessage(FTextControl.Handle,EM_SETMARGINS,EC_LEFTMARGIN or EC_RIGHTMARGIN,0);
end;
procedure TSXSkinCustomEdit.SkinChanged;
begin
if not (csLoading in ComponentState) then
begin
FLastEdit.Free;
FLastEdit:=nil;
if (FThread<>nil) and not FThread.Suspended then
FThread.Suspend;
ResetEditParams([erpTextControl,erpInvalidateOnStyleChange]);
end;
inherited;
end;
procedure TSXSkinCustomEdit.WMCtlColorEdit(var Msg:TMessage);
var B:TBitmap32;
Rgn:HRGN;
R:TRect;
PC:TControl;
begin
B:=TBitmap32.Create;
try
B.SetSize(FTextControl.Width,FTextControl.Height);
B.DrawMode:=dmBlend;
B.CombineMode:=cmMerge;
Rgn:=CreateRectRgnIndirect(FTextControl.BoundsRect);
R:=FTextControl.BoundsRect;
PC:=Parent;
while (PC<>nil) and (PC is TSXSkinCustomControl) and (PC.Parent<>nil) and
(PC.Parent is TSXSkinCustomControl) do
begin
OffsetRect(R,PC.Left,PC.Top);
OffsetRgn(Rgn,PC.Left,PC.Top);
PC:=PC.Parent;
end;
ControlsNotToPaint.Add(FTextControl);
if (PC<>nil) and (PC is TSXSkinCustomControl) then
begin
OffsetRgn(Rgn,Left,Top);
OffsetRect(R,Left,Top);
TSXSkinCustomControl(PC).PaintRectToBitmap(HDC(Msg.WParam),FTextControl.ClientRect,R,Rgn,B,0,0,True);
end else PaintRectToBitmap(HDC(Msg.WParam),FTextControl.ClientRect,R,Rgn,B,0,0,False);
ControlsNotToPaint.Remove(FTextControl);
DeleteObject(Rgn);
FBrushBitmap.Width:=B.Width;
FBrushBitmap.Height:=B.Height;
B.DrawTo(FBrushBitmap.Canvas.Handle,0,0);
FBackBrush.Bitmap:=nil;
FBackBrush.Bitmap:=FBrushBitmap;
Msg.Result:=Integer(FBackBrush.Handle);
SetTextColor(HDC(Msg.WParam),ColorToRGB(FTextControl.Font.Color));
SetBkMode(HDC(Msg.WParam),TRANSPARENT);
if FTextControl.FFontChanged then
begin
FTextControl.FFontChanged:=False;
SendMessage(FTextControl.Handle,EM_SETMARGINS,EC_LEFTMARGIN or EC_RIGHTMARGIN,0);
end;
finally
B.Free;
end;
end;
procedure TSXSkinCustomEdit.WMCtlColorStatic(var Msg:TMessage);
begin
WMCtlColorEdit(Msg);
end;
procedure TSXSkinCustomEdit.GetCurrentTransformEffect(Action:TSXGlyphChangeAction;
var Effect:TSXTransformEffectData);
var A:Integer;
EStyle:TSXSkinEditStyle;
begin
FillChar(Effect,sizeof(Effect),0);
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinEditStyle) then
begin
EStyle:=TSXSkinEditStyle(SkinLibrary.Styles[A]);
case Action of
gcaHighlightIn: Effect:=EStyle.HInEditEffect;
gcaHighlightOut: Effect:=EStyle.HOutEditEffect;
gcaEnable: Effect:=EStyle.EnableEditEffect;
gcaDisable: Effect:=EStyle.DisableEditEffect;
gcaFocus: Effect:=EStyle.FocusEditEffect;
gcaUnfocus: Effect:=EStyle.UnfocusEditEffect;
end;
end;
end;
end;
function TSXSkinCustomEdit.GetText:String;
begin
Result:=FTextControl.Text;
end;
procedure TSXSkinCustomEdit.SetText(const Value:String);
begin
FTextControl.Text:=Value;
end;
function TSXSkinCustomEdit.IsTransparent(X,Y:Integer;Limit:Integer=10):Boolean;
var A:Integer;
Style:TSXSkinGeneralStyle;
EState:TSXSkinEditStateParam;
begin
Result:=True;
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
GetCurrentEState(EState);
A:=SkinLibrary.Styles.GetGStyleIndex(EState.Style,Width,Height);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Result:=Style.IsTransparent(Self,CEID_Back,X,Y,Width,Height,SkinLibrary,Limit,VComparer);
end;
if Result and (FTextControl<>nil) then
Result:=not PtInRect(FTextControl.BoundsRect,Point(X,Y));
end;
end;
function TSXSkinCustomEdit.CapturesMouseAt(X,Y:Integer):Boolean;
var A:Integer;
Style:TSXSkinGeneralStyle;
EState:TSXSkinEditStateParam;
begin
Result:=True;
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
GetCurrentEState(EState);
A:=SkinLibrary.Styles.GetGStyleIndex(EState.Style,Width,Height);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Result:=Style.CapturesMouseAt(Self,CEID_Back,X,Y,Width,Height,SkinLibrary,VComparer);
end;
if not Result then
Result:=PtInRect(FTextControl.BoundsRect,Point(X,Y));
end;
end;
constructor TSXSkinCustomEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
CEID_Back:=GetNewCElementID;
VComparer:=TSXEditVariableComparer.Create;
VComparer.Control:=Self;
VComparer.OnGetVariable:=OnGetVariable;
FBackBrush:=TBrush.Create;
FBrushBitmap:=TBitmap.Create;
ControlStyle:=[csClickEvents,csSetCaption,csDoubleClicks{$IFDEF COMPILER_10_UP},csPannable{$ENDIF}];
FTextControl:=TSXSkinCustomEditTextControl.Create(Self);
FTextControl.Parent:=Self;
FTextControl.BoundsRect:=Rect(4,4,Width-4,Height-4);
ParentColor:=False;
FAutoSelect:=True;
FAutoSizeHeight:=True;
FHideSelection:=True;
Width:=121;
Height:=25;
TabStop:=True;
SkinStyle:='_Edit';
end;
destructor TSXSkinCustomEdit.Destroy;
begin
FBackBrush.Free;
FBrushBitmap.Free;
FLastEdit.Free;
FThread.Free;
inherited;
VComparer.Free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -