LCL: scale control default size when needed. Solves issue #32702

git-svn-id: trunk@58125 -
This commit is contained in:
ondrej 2018-06-04 15:35:01 +00:00
parent 7d10edbadb
commit 3ec78f9640
3 changed files with 14 additions and 6 deletions

View File

@ -1474,6 +1474,7 @@ type
procedure DoContextPopup(MousePos: TPoint; var Handled: Boolean); virtual;
procedure SetZOrder(TopMost: Boolean); virtual;
class function GetControlClassDefaultSize: TSize; virtual;
function GetScaledControlClassDefaultSize: TSize;
function ColorIsStored: boolean; virtual;
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: Double); virtual;

View File

@ -1409,6 +1409,13 @@ begin
Result := ColorToRGB(GetColorResolvingParent());
end;
function TControl.GetScaledControlClassDefaultSize: TSize;
begin
Result := GetControlClassDefaultSize;
Result.cx := Scale96ToFont(Result.cx);
Result.cy := Scale96ToFont(Result.cy);
end;
{------------------------------------------------------------------------------
TControl.DoConstrainedResize
------------------------------------------------------------------------------}
@ -5570,14 +5577,14 @@ function TControl.GetDefaultWidth: integer;
begin
if WidthIsAnchored then
// if width is anchored the read and base bounds were changed at designtime
Result := GetControlClassDefaultSize.cx
Result := GetScaledControlClassDefaultSize.cx
else if cfBaseBoundsValid in FControlFlags then
Result := FBaseBounds.Right - FBaseBounds.Left
else
if cfWidthLoaded in FControlFlags then
Result := FReadBounds.Right - FReadBounds.Left
else
Result := GetControlClassDefaultSize.cx;
Result := GetScaledControlClassDefaultSize.cx;
end;
{------------------------------------------------------------------------------
@ -5590,14 +5597,14 @@ function TControl.GetDefaultHeight: integer;
begin
if HeightIsAnchored then
// if height is anchored the read and base bounds were changed at designtime
Result := GetControlClassDefaultSize.cy
Result := GetScaledControlClassDefaultSize.cy
else if cfBaseBoundsValid in FControlFlags then
Result := BaseBounds.Bottom - BaseBounds.Top
else
if cfHeightLoaded in FControlFlags then
Result := FReadBounds.Bottom - FReadBounds.Top
else
Result := GetControlClassDefaultSize.CY;
Result := GetScaledControlClassDefaultSize.cy;
end;
{------------------------------------------------------------------------------

View File

@ -1431,10 +1431,10 @@ begin
// if no preferred size is valid use the class defaults
if not IsPrefWidthValid then
PreferredSize[asboHorizontal]:=
Control.Constraints.MinMaxWidth(Control.GetControlClassDefaultSize.CX);
Control.Constraints.MinMaxWidth(Control.GetScaledControlClassDefaultSize.CX);
if not IsPrefHeightValid then
PreferredSize[asboVertical]:=
Control.Constraints.MinMaxHeight(Control.GetControlClassDefaultSize.CX);
Control.Constraints.MinMaxHeight(Control.GetScaledControlClassDefaultSize.CY);
//DebugLn(['TAutoSizeBox.SetControl ',DbgSName(Control),' ',PreferredSize[asboHorizontal]]);
Control.BorderSpacing.GetSpaceAround(Border);