📄 sxskinupdown.pas
字号:
procedure TSXSkinCustomUpDown.SkinChanged;
begin
if not (csLoading in ComponentState) then
begin
FLastUpDown.Free;
FLastUpDown:=nil;
FLastUpButton.Free;
FLastUpButton:=nil;
FLastDownButton.Free;
FLastDownButton:=nil;
if (FThread<>nil) and not FThread.Suspended then
FThread.Suspend;
ResetUpDownParams([udrpButtonRects]);
end;
inherited;
end;
procedure TSXSkinCustomUpDown.SetBounds(ALeft,ATop,AWidth,AHeight:Integer);
var OldWidth:Integer;
OldHeight:Integer;
begin
if (ALeft=Left) and (ATop=Top) and (AWidth=Width) and (AHeight=Height) then exit;
OldWidth:=Width;
OldHeight:=Height;
inherited SetBounds(ALeft,ATop,AWidth,AHeight);
if (Width<>OldWidth) or (Height<>OldHeight) then
ResetUpDownParams([udrpButtonRects]);
end;
procedure TSXSkinCustomUpDown.Loaded;
begin
inherited;
ResetUpDownParams([udrpButtonRects]);
end;
procedure TSXSkinCustomUpDown.WMSetFocus(var Msg:TWMSetFocus);
begin
if not (csLoading in ComponentState) then
StartChangingEffect(gcaFocus);
FLastFocused:=True;
if not (csLoading in ComponentState) then
ResetUpDownParams([udrpInvalidateOnStyleChange]);
end;
procedure TSXSkinCustomUpDown.WMKillFocus(var Msg:TWMKillFocus);
begin
if not (csLoading in ComponentState) then
StartChangingEffect(gcaUnfocus);
FLastFocused:=False;
if not (csLoading in ComponentState) then
ResetUpDownParams([udrpInvalidateOnStyleChange]);
if FDownUp then
begin
StartChangingEffect(gcaUp);
StartUpButtonChangingEffect(gcaUp);
FDownUp:=False;
ResetUpDownParams([udrpInvalidateOnStyleChange,udrpInvalidateUpButtonOnStyleChange]);
end;
if FDownDown then
begin
StartChangingEffect(gcaUp);
StartDownButtonChangingEffect(gcaUp);
FDownDown:=False;
ResetUpDownParams([udrpInvalidateOnStyleChange,udrpInvalidateDownButtonOnStyleChange]);
end;
end;
procedure TSXSkinCustomUpDown.DoKeyDown(var Msg: TMessage);
begin
inherited;
{ if Enabled and (Msg.WParam in [VK_SPACE,VK_RETURN]) then
begin
StartGlyphChanging(gcaDown);
FDown:=True;
ResetUpDownParams([brpTextOnFontChange,brpGlyphOnStyleChange,
brpDDGlyphOnStyleChange,brpInvalidateOnStyleChange]);
end;
}
end;
procedure TSXSkinCustomUpDown.DoKeyUp(var Msg: TMessage);
begin
inherited;
{
if Enabled and FDown then
begin
StartGlyphChanging(gcaUp);
FDown:=False;
ResetUpDownParams([brpTextOnFontChange,brpGlyphOnStyleChange,
brpDDGlyphOnStyleChange,brpInvalidateOnStyleChange]);
if Msg.WParam in [VK_SPACE,VK_RETURN] then
begin
Click;
end;
end;
}
end;
procedure TSXSkinCustomUpDown.ResetUpDownParams(Params:TSXSkinUpDownResetParams=[]);
var OldUpButtonRect:TRect;
OldDownButtonRect:TRect;
UpButtonChanged:Boolean;
DownButtonChanged:Boolean;
UDState:TSXSkinUpDownStateParam;
BState:TSXSkinButtonStateParam;
Style:TSXSkinUpDownStyle;
A:Integer;
begin
if Parent=nil then exit;
OldUpButtonRect:=FUpButtonRect;
OldDownButtonRect:=FDownButtonRect;
UpButtonChanged:=False;
DownButtonChanged:=False;
//
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
if udrpButtonRects in Params then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinUpDownStyle) then
begin
Style:=TSXSkinUpDownStyle(SkinLibrary.Styles[A]);
if Style.UpButtonRect<>'' then
GetRectFromString(Style.UpButtonRect,FUpButtonRect,OnGetVariable);
if Style.DownButtonRect<>'' then
GetRectFromString(Style.DownButtonRect,FDownButtonRect,OnGetVariable);
end;
UpButtonChanged:=not EqualRect(FUpButtonRect,OldUpButtonRect);
DownButtonChanged:=not EqualRect(FDownButtonRect,OldDownButtonRect);
end;
if udrpInvalidateUpButtonOnStyleChange in Params then
begin
GetCurrentUpButtonState(BState);
if (BState.Style<>FLastUpButtonStyle) or (BState.OverStyle<>FLastUpButtonOverStyle) then
begin
UpButtonChanged:=True;
FLastUpButtonStyle:=BState.Style;
FLastUpButtonOverStyle:=BState.OverStyle;
end;
end;
if udrpInvalidateDownButtonOnStyleChange in Params then
begin
GetCurrentDownButtonState(BState);
if (BState.Style<>FLastDownButtonStyle) or (BState.OverStyle<>FLastDownButtonOverStyle) then
begin
DownButtonChanged:=True;
FLastDownButtonStyle:=BState.Style;
FLastDownButtonOverStyle:=BState.OverStyle;
end;
end;
end;
//Invalidating Regions
if UpButtonChanged and HandleAllocated then
begin
InvalidateRect(Handle,@OldUpButtonRect,False);
InvalidateRect(Handle,@FUpButtonRect,False);
end;
if DownButtonChanged and HandleAllocated then
begin
InvalidateRect(Handle,@OldDownButtonRect,False);
InvalidateRect(Handle,@FDownButtonRect,False);
end;
//
if udrpInvalidateOnStyleChange in Params then
begin
GetCurrentUDState(UDState);
if (UDState.Style<>FLastStyle) or (UDState.OverStyle<>FLastOverStyle) then
begin
if HandleAllocated then
InvalidateRect(Handle,nil,False);
FLastStyle:=UDState.Style;
FLastOverStyle:=UDState.OverStyle;
end;
end;
end;
function TSXSkinCustomUpDown.IsTransparent(X,Y:Integer;Limit:Integer=10):Boolean;
var A:Integer;
Style:TSXSkinGeneralStyle;
UDState:TSXSkinUpDownStateParam;
BState:TSXSkinButtonStateParam;
begin
Result:=True;
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
GetCurrentUDState(UDState);
A:=SkinLibrary.Styles.GetGStyleIndex(UDState.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 then
begin
A:=SkinLibrary.Styles.GetGStyleIndex(UDState.OverStyle,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;
end;
if Result then
begin
GetCurrentUpButtonState(BState);
A:=SkinLibrary.Styles.GetGStyleIndex(BState.Style,FUpButtonRect.Right-FUpButtonRect.Left,
FUpButtonRect.Bottom-FUpButtonRect.Top);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Result:=Style.IsTransparent(Self,CEID_Up,X-FUpButtonRect.Left,Y-FUpButtonRect.Top,
FUpButtonRect.Right-FUpButtonRect.Left,FUpButtonRect.Bottom-FUpButtonRect.Top,
SkinLibrary,Limit);
end;
if Result then
begin
A:=SkinLibrary.Styles.GetGStyleIndex(BState.OverStyle,FUpButtonRect.Right-FUpButtonRect.Left,
FUpButtonRect.Bottom-FUpButtonRect.Top);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Result:=Style.IsTransparent(Self,CEID_Up,X-FUpButtonRect.Left,Y-FUpButtonRect.Top,
FUpButtonRect.Right-FUpButtonRect.Left,FUpButtonRect.Bottom-FUpButtonRect.Top,
SkinLibrary,Limit);
end;
end;
end;
if Result then
begin
GetCurrentDownButtonState(BState);
A:=SkinLibrary.Styles.GetGStyleIndex(BState.Style,FDownButtonRect.Right-FDownButtonRect.Left,
FDownButtonRect.Bottom-FDownButtonRect.Top);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Result:=Style.IsTransparent(Self,CEID_Down,X-FDownButtonRect.Left,Y-FDownButtonRect.Top,
FDownButtonRect.Right-FDownButtonRect.Left,FDownButtonRect.Bottom-FDownButtonRect.Top,
SkinLibrary,Limit);
end;
if Result then
begin
A:=SkinLibrary.Styles.GetGStyleIndex(BState.OverStyle,FDownButtonRect.Right-FDownButtonRect.Left,
FDownButtonRect.Bottom-FDownButtonRect.Top);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Result:=Style.IsTransparent(Self,CEID_Down,X-FDownButtonRect.Left,Y-FDownButtonRect.Top,
FDownButtonRect.Right-FDownButtonRect.Left,FDownButtonRect.Bottom-FDownButtonRect.Top,
SkinLibrary,Limit);
end;
end;
end;
end;
end;
function TSXSkinCustomUpDown.UpButtonCapturesMouseAt(X,Y:Integer):Boolean;
var A:Integer;
Style:TSXSkinGeneralStyle;
BState:TSXSkinButtonStateParam;
begin
Result:=True;
GetCurrentUpButtonState(BState);
A:=SkinLibrary.Styles.GetGStyleIndex(BState.Style,FUpButtonRect.Right-FUpButtonRect.Left,
FUpButtonRect.Bottom-FUpButtonRect.Top);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Result:=Style.CapturesMouseAt(Self,CEID_Up,X-FUpButtonRect.Left,Y-FUpButtonRect.Top,
FUpButtonRect.Right-FUpButtonRect.Left,FUpButtonRect.Bottom-FUpButtonRect.Top,
SkinLibrary);
end;
if not Result then
begin
A:=SkinLibrary.Styles.GetGStyleIndex(BState.OverStyle,FUpButtonRect.Right-FUpButtonRect.Left,
FUpButtonRect.Bottom-FUpButtonRect.Top);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Result:=Style.CapturesMouseAt(Self,CEID_Up,X-FUpButtonRect.Left,Y-FUpButtonRect.Top,
FUpButtonRect.Right-FUpButtonRect.Left,FUpButtonRect.Bottom-FUpButtonRect.Top,
SkinLibrary);
end;
end;
end;
function TSXSkinCustomUpDown.DownButtonCapturesMouseAt(X,Y:Integer):Boolean;
var A:Integer;
Style:TSXSkinGeneralStyle;
BState:TSXSkinButtonStateParam;
begin
Result:=True;
GetCurrentDownButtonState(BState);
A:=SkinLibrary.Styles.GetGStyleIndex(BState.Style,FDownButtonRect.Right-FDownButtonRect.Left,
FDownButtonRect.Bottom-FDownButtonRect.Top);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Result:=Style.CapturesMouseAt(Self,CEID_Down,X-FDownButtonRect.Left,Y-FDownButtonRect.Top,
FDownButtonRect.Right-FDownButtonRect.Left,FDownButtonRect.Bottom-FDownButtonRect.Top,
SkinLibrary);
end;
if not Result then
begin
A:=SkinLibrary.Styles.GetGStyleIndex(BState.OverStyle,FDownButtonRect.Right-FDownButtonRect.Left,
FDownButtonRect.Bottom-FDownButtonRect.Top);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Result:=Style.CapturesMouseAt(Self,CEID_Down,X-FDownButtonRect.Left,Y-FDownButtonRect.Top,
FDownButtonRect.Right-FDownButtonRect.Left,FDownButtonRect.Bottom-FDownButtonRect.Top,
SkinLibrary);
end;
end;
end;
function TSXSkinCustomUpDown.CapturesMouseAt(X,Y:Integer):Boolean;
var A:Integer;
Style:TSXSkinGeneralStyle;
UDState:TSXSkinUpDownStateParam;
begin
Result:=True;
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
GetCurrentUDState(UDState);
A:=SkinLibrary.Styles.GetGStyleIndex(UDState.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
begin
A:=SkinLibrary.Styles.GetGStyleIndex(UDState.OverStyle,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;
end;
if not Result then
Result:=UpButtonCapturesMouseAt(X,Y);
if not Result then
Result:=DownButtonCapturesMouseAt(X,Y);
end;
end;
procedure TSXSkinCustomUpDown.WndProc(var Msg: TMessage);
begin
if Msg.Msg=WM_TIMER then
begin
Inc(SeqClickNum);
if SeqClickNum=1 then
begin
KillTimer(Handle,1);
SetTimer(Handle,1,200,nil);
end else
if SeqClickNum=5 then
begin
KillTimer(Handle,1);
SetTimer(Handle,1,150,nil);
end else
if SeqClickNum=10 then
begin
KillTimer(Handle,1);
SetTimer(Handle,1,100,nil);
end;
if FDownUp and FMouseOverUp then
DoClick(True) else
if FDownDown and FMouseOverDown then
DoClick(False);
end;
inherited;
end;
constructor TSXSkinCustomUpDown.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
CEID_Back:=GetNewCElementID;
CEID_Up:=GetNewCElementID;
CEID_Down:=GetNewCElementID;
VComparer:=TSXUpDownVariableComparer.Create;
VComparer.Control:=Self;
VComparer.OnGetVariable:=OnGetVariable;
ControlStyle:=ControlStyle-[csDoubleClicks];
FEnabledUp:=True;
FEnabledDown:=True;
SkinStyle:='_UpDown';
TabStop:=True;
end;
destructor TSXSkinCustomUpDown.Destroy;
begin
FThread.Free;
FLastUpDown.Free;
FLastUpButton.Free;
FLastDownButton.Free;
inherited;
VComparer.Free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -