📄 sxskinedit.pas
字号:
function TSXEditVariableComparer.GetVarValsForVarList(VarList:TList):TList;
var A:Integer;
begin
if VarList=nil then
begin
Result:=nil;
exit;
end;
Result:=TList.Create;
for A:=0 to VarList.Count-1 do
Result.Add(Pointer(GetValue(Integer(VarList[A]))));
end;
function TSXEditVariableComparer.Changed(VarList:TList;OldVarVals:TList):Boolean;
var A:Integer;
begin
Result:=False;
if VarList=nil then exit;
for A:=0 to VarList.Count-1 do
if Integer(OldVarVals[A])<>GetValue(Integer(VarList[A])) then
begin
Result:=True;
exit;
end;
end;
procedure TSXEditVariableComparer.Update(VarList:TList;VarVals:TList);
var A:Integer;
begin
if VarList=nil then exit;
for A:=0 to VarList.Count-1 do
VarVals[A]:=Pointer(GetValue(Integer(VarList[A])));
end;
procedure TSXEditVariableComparer.DestroyVarList(VarList:TList);
begin
VarList.Free;
end;
procedure TSXEditVariableComparer.DestroyVarVals(VarList:TList;VarVals:TList);
begin
VarVals.Free;
end;
{ TSXSkinCustomEditTextControl }
constructor TSXSkinCustomEditTextControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if AOwner is TSXSkinCustomEdit then
FParentEdit:=TSXSkinCustomEdit(AOwner);
ControlStyle:=[csClickEvents,csSetCaption,csDoubleClicks{$IFDEF COMPILER_10_UP},csPannable{$ENDIF}];
TabStop:=True;
ParentColor:=False;
inherited OnKeyDown:=LocalKeyDown;
end;
function TSXSkinCustomEditTextControl.CapturesMouseAt(X,Y:Integer):Boolean;
begin
Result:=False;
end;
procedure TSXSkinCustomEditTextControl.DoSetMaxLength(Value: Integer);
begin
SendMessage(Handle,EM_LIMITTEXT,Value,0);
end;
procedure TSXSkinCustomEditTextControl.Clear;
begin
SetWindowText(Handle,'');
end;
procedure TSXSkinCustomEditTextControl.CreateParams(var Params:TCreateParams);
const Passwords:array[Boolean]of DWORD=(0,ES_PASSWORD);
ReadOnlys:array[Boolean]of DWORD=(0,ES_READONLY);
CharCases:array[TEditCharCase]of DWORD=(0,ES_UPPERCASE,ES_LOWERCASE);
HideSelections:array[Boolean]of DWORD=(ES_NOHIDESEL,0);
OEMConverts:array[Boolean]of DWORD=(0,ES_OEMCONVERT);
AlignmentStyles:array[TAlignment]of DWORD=(ES_LEFT,ES_RIGHT,ES_CENTER);
begin
inherited CreateParams(Params);
CreateSubClass(Params,'EDIT');
with Params do
begin
Style:=Style or (ES_AUTOHSCROLL or ES_AUTOVSCROLL) or
Passwords[FParentEdit.FPassword] or ReadOnlys[FParentEdit.FReadOnly] or
CharCases[FParentEdit.FCharCase] or HideSelections[FParentEdit.FHideSelection] or
OEMConverts[FParentEdit.FOEMConvert] or AlignmentStyles[FParentEdit.FAlignment];
end;
end;
procedure TSXSkinCustomEditTextControl.CreateWindowHandle(const Params: TCreateParams);
var P:TCreateParams;
begin
if SysLocale.FarEast and (Win32Platform<>VER_PLATFORM_WIN32_NT) and
(Params.Style and ES_READONLY<>0) then
begin
P:=Params;
P.Style:=P.Style and not ES_READONLY;
inherited CreateWindowHandle(P);
if WindowHandle<>0 then
SendMessage(WindowHandle,EM_SETREADONLY,Ord(True),0);
end else inherited CreateWindowHandle(Params);
end;
procedure TSXSkinCustomEditTextControl.CreateWnd;
begin
FCreating:=True;
try
inherited CreateWnd;
finally
FCreating:=False;
end;
DoSetMaxLength(FParentEdit.FMaxLength);
FParentEdit.Modified:=FModified;
if FOldSelStart<>-1 then
FParentEdit.SelStart:=FOldSelStart;
if FOldSelLength<>-1 then
FParentEdit.SelLength:=FOldSelLength;
end;
procedure TSXSkinCustomEditTextControl.DestroyWnd;
begin
FModified:=FParentEdit.Modified;
FOldSelLength:=FParentEdit.SelLength;
FOldSelStart:=FParentEdit.SelStart;
inherited DestroyWnd;
end;
procedure TSXSkinCustomEditTextControl.Change;
begin
inherited;
if FParentEdit<>nil then
begin
if Assigned(FParentEdit.FOnChange) then
FParentEdit.FOnChange(Self);
if not FChanging and Assigned(FParentEdit.FOnUserModified) and FParentEdit.FFrequentChange then
begin
if LocalGetText<>FParentEdit.FLastChangedValue then
begin
FParentEdit.FOnUserModified(FParentEdit);
FParentEdit.FLastChangedValue:=LocalGetText;
end;
end;
end;
end;
procedure TSXSkinCustomEditTextControl.DefaultHandler(var Message);
begin
case TMessage(Message).Msg of
WM_SETFOCUS:
if (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
not IsWindow(TWMSetFocus(Message).FocusedWnd) then
TWMSetFocus(Message).FocusedWnd := 0;
end;
inherited;
end;
procedure TSXSkinCustomEditTextControl.CNCommand(var Message:TWMCommand);
begin
if (Message.NotifyCode=EN_CHANGE) and not FCreating then Change;
end;
procedure TSXSkinCustomEditTextControl.CMEnter(var Message: TCMGotFocus);
begin
if FParentEdit.FAutoSelect and not (csLButtonDown in ControlState) and
(GetWindowLong(Handle,GWL_STYLE) and ES_MULTILINE=0) then FParentEdit.SelectAll;
inherited;
end;
procedure TSXSkinCustomEditTextControl.CMTextChanged(var Message:TMessage);
begin
inherited;
if not HandleAllocated or (GetWindowLong(Handle,GWL_STYLE) and ES_MULTILINE<>0) then Change;
end;
procedure TSXSkinCustomEditTextControl.WMContextMenu(var Message:TWMContextMenu);
begin
SetFocus;
inherited;
end;
procedure TSXSkinCustomEditTextControl.WMEraseBkgnd(var Msg:TWmEraseBkgnd);
begin
Msg.Result:=1;
end;
procedure TSXSkinCustomEditTextControl.WMSetFocus(var Msg:TWMSetFocus);
begin
if FParentEdit<>nil then
begin
FParentEdit.StartChanging(gcaFocus);
FLastFocused:=True;
FParentEdit.InvalidateIfStyleChanged;
end;
inherited;
end;
procedure TSXSkinCustomEditTextControl.WMKillFocus(var Msg:TWMKillFocus);
begin
// ShowCaret(Handle);
if FParentEdit<>nil then
begin
FParentEdit.StartChanging(gcaUnfocus);
FLastFocused:=False;
FParentEdit.InvalidateIfStyleChanged;
if Assigned(FParentEdit.FOnUserModified) then
if LocalGetText<>FParentEdit.FLastChangedValue then
begin
FParentEdit.FOnUserModified(FParentEdit);
FParentEdit.FLastChangedValue:=LocalGetText;
end;
end;
inherited;
end;
procedure TSXSkinCustomEditTextControl.WMMouseLeave(var Msg:TMessage);
begin
inherited;
if FParentEdit<>nil then
SendMessage(FParentEdit.Handle,WM_MOUSELEAVE,0,0);
end;
procedure TSXSkinCustomEditTextControl.WMMouseMove(var Msg:TWMMouseMove);
begin
inherited;
if FParentEdit<>nil then
SendMessage(FParentEdit.Handle,WM_MOUSEMOVE,TMessage(Msg).WParam,
(Msg.XPos+Left) or ((Msg.YPos+Top) shl 16));
end;
procedure TSXSkinCustomEditTextControl.WMLButtonDown(var Msg:TWMLButtonDown);
begin
LastClickTime:=GetTickCount;
inherited;
if FParentEdit<>nil then
SendMessage(FParentEdit.Handle,WM_LBUTTONDOWN,TMessage(Msg).WParam,
(Msg.XPos+Left) or ((Msg.YPos+Top) shl 16));
end;
procedure TSXSkinCustomEditTextControl.WMLButtonUp(var Msg:TWMLButtonUp);
begin
inherited;
if FParentEdit<>nil then
SendMessage(FParentEdit.Handle,WM_LBUTTONUP,TMessage(Msg).WParam,
(Msg.XPos+Left) or ((Msg.YPos+Top) shl 16));
end;
procedure TSXSkinCustomEditTextControl.WMLButtonDblClk(var Msg:TWMLButtonDblClk);
begin
inherited;
if FParentEdit<>nil then
SendMessage(FParentEdit.Handle,WM_LBUTTONDBLCLK,TMessage(Msg).WParam,
(Msg.XPos+Left) or ((Msg.YPos+Top) shl 16));
end;
procedure TSXSkinCustomEditTextControl.CMFontChanged(var Message:TMessage);
begin
inherited;
FFontChanged:=True;
end;
procedure TSXSkinCustomEditTextControl.WMPrint(var Msg:TWMPrint);
var P:TPoint;
XX,YY:Integer;
ACanvas:TCanvas;
BTime:Cardinal;
begin
inherited;
if Focused then
begin
BTime:=GetCaretBlinkTime;
if GetCaretPos(P) and ((GetTickCount-LastClickTime) mod (BTime*2)<BTime) and PaintCaret then
begin
ACanvas:=TCanvas.Create;
try
ACanvas.Handle:=Msg.DC;
ACanvas.Pen.Style:=psSolid;
ACanvas.Pen.Mode:=pmXor;
ACanvas.Pen.Color:=clWhite;
ACanvas.Brush.Style:=bsClear;
XX:=P.X;
YY:=P.Y;
ACanvas.MoveTo(XX,YY);
ACanvas.LineTo(XX,YY+Height);
finally
ACanvas.Free;
end;
end;
end;
end;
procedure TSXSkinCustomEditTextControl.CNChar(var Msg:TMessage);
begin
LastClickTime:=GetTickCount;
inherited;
end;
procedure TSXSkinCustomEditTextControl.CNKeyDown(var Msg:TMessage);
begin
LastClickTime:=GetTickCount;
inherited;
end;
procedure TSXSkinCustomEditTextControl.LocalKeyDown(Sender:TObject;var Key:Word;Shift:TShiftState);
begin
if (FParentEdit<>nil) and Assigned(FParentEdit.OnKeyDown) then
FParentEdit.OnKeyDown(Sender,Key,Shift);
if Key=VK_RETURN then
if (FParentEdit<>nil) and Assigned(FParentEdit.FOnUserModified) then
begin
if LocalGetText<>FParentEdit.FLastChangedValue then
begin
FParentEdit.FOnUserModified(FParentEdit);
FParentEdit.FLastChangedValue:=LocalGetText;
end;
Parent.SetFocus;
end else
if Key=VK_ESCAPE then
begin
if FParentEdit<>nil then
Text:=FParentEdit.FLastChangedValue;
Parent.SetFocus;
end;
end;
function TSXSkinCustomEditTextControl.LocalGetText:TCaption;
var Len:Integer;
begin
Len:=GetTextLen;
SetString(Result,PChar(nil),Len);
if Len<>0 then GetTextBuf(Pointer(Result),Len+1);
end;
procedure TSXSkinCustomEditTextControl.LocalSetText(Value:TCaption);
begin
if LocalGetText<>Value then
begin
FChanging:=True;
SetTextBuf(PChar(Value));
FChanging:=False;
if FParentEdit<>nil then
FParentEdit.FLastChangedValue:=Value;
end;
end;
procedure TSXSkinCustomEditTextControl.KeyDown(var Key:Word;Shift:TShiftState);
begin
if Assigned(FParentEdit.OnKeyDown) then
FParentEdit.OnKeyDown(FParentEdit,Key,Shift);
inherited;
end;
procedure TSXSkinCustomEditTextControl.KeyUp(var Key:Word;Shift:TShiftState);
begin
if Assigned(FParentEdit.OnKeyUp) then
FParentEdit.OnKeyUp(FParentEdit,Key,Shift);
inherited;
end;
procedure TSXSkinCustomEditTextControl.KeyPress(var Key:Char);
begin
if Assigned(FParentEdit.OnKeyPress) then
FParentEdit.OnKeyPress(FParentEdit,Key);
inherited;
end;
{ TSXSkinCustomEdit }
procedure TSXSkinCustomEdit.SetEnabled(Value:Boolean);
begin
if Enabled<>Value then
begin
if not (csLoading in ComponentState) then
begin
if Enabled then
StartChanging(gcaDisable) else
StartChanging(gcaEnable);
end;
inherited;
if not Enabled then
FMouseOver:=False;
if not (csLoading in ComponentState) then
ResetEditParams([erpTextControlOnFontChange,erpInvalidateOnStyleChange]);
end;
end;
function TSXSkinCustomEdit.HasUnusualSkinStyle:Boolean;
begin
Result:=SkinStyle<>'_Edit';
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -