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( procedure CalculatePreferredSize(
var PreferredWidth, PreferredHeight: Integer; var PreferredWidth, PreferredHeight: Integer;
{%H-}WithThemeSpace: Boolean); override; {%H-}WithThemeSpace: Boolean); override;
procedure ShouldAutoAdjust(var ALeft, ATop, AWidth, AHeight: Boolean); override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
function ShouldAutoAdjustWidthAndHeight: Boolean; override;
published published
property Caption; property Caption;
property Align; property Align;
@ -397,9 +397,15 @@ begin
end; end;
end; end;
function TDividerBevel.ShouldAutoAdjustWidthAndHeight: Boolean; procedure TDividerBevel.ShouldAutoAdjust(var ALeft, ATop, AWidth,
AHeight: Boolean);
begin 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; end;
constructor TDividerBevel.Create(AOwner: TComponent); constructor TDividerBevel.Create(AOwner: TComponent);

View File

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

View File

@ -243,7 +243,7 @@ type
procedure SetAutoSize(AValue: Boolean); override; procedure SetAutoSize(AValue: Boolean); override;
procedure SetColor(AValue: TColor); override; procedure SetColor(AValue: TColor); override;
procedure SetCursor(AValue: TCursor); 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 AutoSelect: Boolean read GetAutoSelect write SetAutoSelect default True;
property AutoSelected: Boolean read GetAutoSelected write SetAutoSelected; property AutoSelected: Boolean read GetAutoSelected write SetAutoSelected;
@ -847,9 +847,13 @@ begin
FEdit.Cursor := AValue; FEdit.Cursor := AValue;
end; end;
function TCustomAbstractGroupedEdit.ShouldAutoAdjustWidthAndHeight: Boolean; procedure TCustomAbstractGroupedEdit.ShouldAutoAdjust(var ALeft, ATop, AWidth,
AHeight: Boolean);
begin 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; end;
procedure TCustomAbstractGroupedEdit.SetFocus; procedure TCustomAbstractGroupedEdit.SetFocus;

View File

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

View File

@ -622,9 +622,13 @@ begin
Result := False; Result := False;
end; end;
function TCustomComboBox.ShouldAutoAdjustWidthAndHeight: Boolean; procedure TCustomComboBox.ShouldAutoAdjust(var ALeft, ATop, AWidth,
AHeight: Boolean);
begin 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; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------

View File

@ -505,9 +505,13 @@ begin
inherited WndProc(Message); inherited WndProc(Message);
end; end;
function TCustomEdit.ShouldAutoAdjustWidthAndHeight: Boolean; procedure TCustomEdit.ShouldAutoAdjust(var ALeft, ATop, AWidth, AHeight: Boolean
);
begin 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; end;
procedure TCustomEdit.CMWantSpecialKey(var Message: TCMWantSpecialKey); procedure TCustomEdit.CMWantSpecialKey(var Message: TCMWantSpecialKey);

View File

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