LCL: TScrollingWinControl.ScrollInView or TScrollBox.ScrollInView does not calculate stacked controls. Issue #38838. Patch from Jamie Philbrook

git-svn-id: trunk@65078 -
This commit is contained in:
michl 2021-05-01 17:48:42 +00:00
parent dbd10977a4
commit f192422579

View File

@ -248,27 +248,34 @@ end;
procedure TScrollingWinControl.ScrollInView(AControl: TControl); procedure TScrollingWinControl.ScrollInView(AControl: TControl);
var var
xRect: TRect; LRect: TRect;
LParent: TWinControl;
begin begin
if AControl=nil then if AControl = nil then Exit;
Exit; LRect := AControl.BoundsRect;
xRect := AControl.BoundsRect; LParent := AControl.Parent;
OffsetRect(xRect, -HorzScrollBar.Position, -VertScrollBar.Position); while LParent <> Self do
if xRect.Left < 0 then
HorzScrollBar.Position := HorzScrollBar.Position + xRect.Left
else if xRect.Right > ClientWidth then
begin begin
if xRect.Right - xRect.Left > ClientWidth then OffsetRect(LRect, LParent.BoundsRect.Left, LParent.BoundsRect.Top);
xRect.Right := xRect.Left + ClientWidth; LParent := LParent.Parent;
HorzScrollBar.Position := HorzScrollBar.Position + xRect.Right - ClientWidth; if LParent = nil then Exit; //ScrollingWinControl isn't parent of AControl
end; end;
if xRect.Top < 0 then OffsetRect(LRect, -HorzScrollBar.Position, -VertScrollBar.Position);
VertScrollBar.Position := VertScrollBar.Position + xRect.Top if LRect.Left < 0 then
else if xRect.Bottom > ClientHeight then HorzScrollBar.Position := HorzScrollBar.Position + LRect.Left
else if LRect.Right > ClientWidth then
begin begin
if xRect.Bottom - xRect.Top > ClientHeight then if LRect.Right - LRect.Left > ClientWidth then
xRect.Bottom := xRect.Top + ClientHeight; LRect.Right := LRect.Left + ClientWidth;
VertScrollBar.Position := VertScrollBar.Position + xRect.Bottom - ClientHeight; HorzScrollBar.Position := HorzScrollBar.Position + LRect.Right - ClientWidth;
end;
if LRect.Top < 0 then
VertScrollBar.Position := VertScrollBar.Position + LRect.Top
else if LRect.Bottom > ClientHeight then
begin
if LRect.Bottom - LRect.Top > ClientHeight then
LRect.Bottom := LRect.Top + ClientHeight;
VertScrollBar.Position := VertScrollBar.Position + LRect.Bottom - ClientHeight;
end; end;
end; end;