lcl: merge ShouldAutoAdjust* into one method. Fix Width and Height adjustment in relation to Align.

git-svn-id: trunk@53538 -
This commit is contained in:
ondrej 2016-12-03 06:52:15 +00:00
parent f48f4618a6
commit adf87c511a
7 changed files with 56 additions and 35 deletions

View File

@ -52,9 +52,9 @@ type
procedure CalculatePreferredSize(
var PreferredWidth, PreferredHeight: Integer;
{%H-}WithThemeSpace: Boolean); override;
procedure ShouldAutoAdjust(var ALeft, ATop, AWidth, AHeight: Boolean); override;
public
constructor Create(AOwner: TComponent); override;
function ShouldAutoAdjustWidthAndHeight: Boolean; override;
published
property Caption;
property Align;
@ -397,9 +397,15 @@ begin
end;
end;
function TDividerBevel.ShouldAutoAdjustWidthAndHeight: Boolean;
procedure TDividerBevel.ShouldAutoAdjust(var ALeft, ATop, AWidth,
AHeight: Boolean);
begin
Result := (Align = alNone);
ALeft := (Align = alNone) and (Parent <> nil);
ATop := ALeft;
AWidth := (Align in [alNone, alLeft, alRight])
and (AutoSize = False) and not (Orientation = trVertical);
AHeight := (Align in [alNone, alTop, alBottom])
and (AutoSize = False) and not (Orientation = trHorizontal);
end;
constructor TDividerBevel.Create(AOwner: TComponent);

View File

@ -1525,8 +1525,7 @@ type
procedure AutoAdjustLayout(AMode: TLayoutAdjustmentPolicy;
const AFromDPI, AToDPI, AOldFormWidth, ANewFormWidth: Integer;
const AScaleFonts: Boolean); virtual;
function ShouldAutoAdjustLeftAndTop: Boolean; virtual;
function ShouldAutoAdjustWidthAndHeight: Boolean; virtual;
procedure ShouldAutoAdjust(var ALeft, ATop, AWidth, AHeight: Boolean); virtual;
public
constructor Create(TheOwner: TComponent);override;
destructor Destroy; override;

View File

@ -243,7 +243,7 @@ type
procedure SetAutoSize(AValue: Boolean); override;
procedure SetColor(AValue: TColor); override;
procedure SetCursor(AValue: TCursor); override;
function ShouldAutoAdjustWidthAndHeight: Boolean; override;
procedure ShouldAutoAdjust(var ALeft, ATop, AWidth, AHeight: Boolean); override;
property AutoSelect: Boolean read GetAutoSelect write SetAutoSelect default True;
property AutoSelected: Boolean read GetAutoSelected write SetAutoSelected;
@ -847,9 +847,13 @@ begin
FEdit.Cursor := AValue;
end;
function TCustomAbstractGroupedEdit.ShouldAutoAdjustWidthAndHeight: Boolean;
procedure TCustomAbstractGroupedEdit.ShouldAutoAdjust(var ALeft, ATop, AWidth,
AHeight: Boolean);
begin
Result := (Align = alNone);
ALeft := (Align = alNone) and (Parent <> nil);
ATop := ALeft;
AWidth := (Align in [alNone, alLeft, alRight]);
AHeight := (Align in [alNone, alTop, alBottom]) and (AutoSize = False);
end;
procedure TCustomAbstractGroupedEdit.SetFocus;

View File

@ -3840,6 +3840,7 @@ var
lXProportion, lYProportion: Double;
NewLeft, NewTop, NewHeight, NewWidth: Integer;
lMode: TLayoutAdjustmentPolicy;
AALeft, AATop, AAWidth, AAHeight: Boolean;
begin
// First resolve ladDefault
lMode := AMode;
@ -3866,41 +3867,44 @@ begin
// Apply the changes
if lMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
begin
if ShouldAutoAdjustLeftAndTop then
begin
NewLeft := Round(Left * lXProportion);
NewTop := Round(Top * lYProportion);
end
AALeft := False;
AATop := False;
AAWidth := False;
AAHeight := False;
NewWidth := Width;
NewHeight := Height;
ShouldAutoAdjust(AALeft, AATop, AAWidth, AAHeight);
if AALeft then
NewLeft := Round(Left * lXProportion)
else
begin
NewLeft := Left;
NewTop := Top;
end;
if ShouldAutoAdjustWidthAndHeight then
begin
NewWidth := Round(Width * lXProportion);
NewHeight := Round(Height * lYProportion);
end
if AATop then
NewTop := Round(Top * lYProportion)
else
NewTop := Top;
// Give a shake at the autosize to recalculate font sizes for example
if (not AAWidth or not AAHeight) and AutoSize then
begin
// Give a shake at the autosize to recalculate font sizes for example
if AutoSize then AdjustSize();
NewWidth := Width;
NewHeight := Height;
end;
if AAWidth then
NewWidth := Round(Width * lXProportion);
if AAHeight then
NewHeight := Round(Height * lYProportion);
SetBounds(NewLeft, NewTop, NewWidth, NewHeight);
end;
end;
// Auto-adjust the layout of controls without alignment. Custom anchoring is allowed.
function TControl.ShouldAutoAdjustLeftAndTop: Boolean;
procedure TControl.ShouldAutoAdjust(var ALeft, ATop, AWidth, AHeight: Boolean);
begin
Result := (Align = alNone) and (Parent <> nil);
end;
function TControl.ShouldAutoAdjustWidthAndHeight: Boolean;
begin
Result := (Align = alNone) and (AutoSize = False);
ALeft := (Align = alNone) and (Parent <> nil);
ATop := ALeft;
AWidth := (Align in [alNone, alLeft, alRight]) and (AutoSize = False);
AHeight := (Align in [alNone, alTop, alBottom]) and (AutoSize = False);
end;
procedure TControl.UpdateAnchorRules;

View File

@ -622,9 +622,13 @@ begin
Result := False;
end;
function TCustomComboBox.ShouldAutoAdjustWidthAndHeight: Boolean;
procedure TCustomComboBox.ShouldAutoAdjust(var ALeft, ATop, AWidth,
AHeight: Boolean);
begin
Result := (Align = alNone);
ALeft := (Align = alNone) and (Parent <> nil);
ATop := ALeft;
AWidth := (Align in [alNone, alLeft, alRight]);
AHeight := (Align in [alNone, alTop, alBottom]) and (AutoSize = False);
end;
{------------------------------------------------------------------------------

View File

@ -505,9 +505,13 @@ begin
inherited WndProc(Message);
end;
function TCustomEdit.ShouldAutoAdjustWidthAndHeight: Boolean;
procedure TCustomEdit.ShouldAutoAdjust(var ALeft, ATop, AWidth, AHeight: Boolean
);
begin
Result := (Align = alNone);
ALeft := (Align = alNone) and (Parent <> nil);
ATop := ALeft;
AWidth := (Align in [alNone, alLeft, alRight]);
AHeight := (Align in [alNone, alTop, alBottom]) and (AutoSize = False);
end;
procedure TCustomEdit.CMWantSpecialKey(var Message: TCMWantSpecialKey);

View File

@ -345,7 +345,7 @@ type
procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override;
procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X, Y: Integer); override;
function SelectItem(const AnItem: String): Boolean;
function ShouldAutoAdjustWidthAndHeight: Boolean; override;
procedure ShouldAutoAdjust(var ALeft, ATop, AWidth, AHeight: Boolean); override;
property ItemHeight: Integer read GetItemHeight write SetItemHeight;
property ItemWidth: Integer read GetItemWidth write SetItemWidth default 0;
@ -765,7 +765,7 @@ type
procedure WMChar(var Message: TLMChar); message LM_CHAR;
procedure CMWantSpecialKey(var Message: TCMWantSpecialKey); message CM_WANTSPECIALKEY;
procedure WndProc(var Message: TLMessage); override;
function ShouldAutoAdjustWidthAndHeight: Boolean; override;
procedure ShouldAutoAdjust(var ALeft, ATop, AWidth, AHeight: Boolean); override;
property AutoSelect: Boolean read FAutoSelect write FAutoSelect default True;
property AutoSelected: Boolean read FAutoSelected write FAutoSelected;