From adf87c511a90244ff964262c7640cf2b83a1be17 Mon Sep 17 00:00:00 2001 From: ondrej Date: Sat, 3 Dec 2016 06:52:15 +0000 Subject: [PATCH] lcl: merge ShouldAutoAdjust* into one method. Fix Width and Height adjustment in relation to Align. git-svn-id: trunk@53538 - --- components/lazcontrols/dividerbevel.pas | 12 +++++-- lcl/controls.pp | 3 +- lcl/groupededit.pp | 10 ++++-- lcl/include/control.inc | 46 ++++++++++++++----------- lcl/include/customcombobox.inc | 8 +++-- lcl/include/customedit.inc | 8 +++-- lcl/stdctrls.pp | 4 +-- 7 files changed, 56 insertions(+), 35 deletions(-) diff --git a/components/lazcontrols/dividerbevel.pas b/components/lazcontrols/dividerbevel.pas index 714dda1c6a..aaf5fda141 100644 --- a/components/lazcontrols/dividerbevel.pas +++ b/components/lazcontrols/dividerbevel.pas @@ -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); diff --git a/lcl/controls.pp b/lcl/controls.pp index 4e0b6f1140..2dd70a9ccd 100644 --- a/lcl/controls.pp +++ b/lcl/controls.pp @@ -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; diff --git a/lcl/groupededit.pp b/lcl/groupededit.pp index 4751f271c6..9360b55ab2 100644 --- a/lcl/groupededit.pp +++ b/lcl/groupededit.pp @@ -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; diff --git a/lcl/include/control.inc b/lcl/include/control.inc index 5b4a9ab8f9..02ca8ec35f 100644 --- a/lcl/include/control.inc +++ b/lcl/include/control.inc @@ -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; diff --git a/lcl/include/customcombobox.inc b/lcl/include/customcombobox.inc index 56592ff159..1e1606b32f 100644 --- a/lcl/include/customcombobox.inc +++ b/lcl/include/customcombobox.inc @@ -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; {------------------------------------------------------------------------------ diff --git a/lcl/include/customedit.inc b/lcl/include/customedit.inc index 658a414013..3797355a5f 100644 --- a/lcl/include/customedit.inc +++ b/lcl/include/customedit.inc @@ -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); diff --git a/lcl/stdctrls.pp b/lcl/stdctrls.pp index e8181e7558..9319b0c0d6 100644 --- a/lcl/stdctrls.pp +++ b/lcl/stdctrls.pp @@ -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;