diff --git a/lcl/controls.pp b/lcl/controls.pp index e28d7df40c..69b20f013c 100644 --- a/lcl/controls.pp +++ b/lcl/controls.pp @@ -1026,7 +1026,9 @@ type {$ENDIF} procedure BeginAutoSizing; // set AutoSizing=true, can be used to prevent circles procedure EndAutoSizing; // set AutoSizing=false + {$IFDEF OldAutoSize} function AutoSizeCanStart: boolean; virtual; + {$ENDIF} procedure AnchorSideChanged(TheAnchorSide: TAnchorSide); virtual; procedure ForeignAnchorSideChanged(TheAnchorSide: TAnchorSide; Operation: TAnchorSideChangeOperation); virtual; diff --git a/lcl/forms.pp b/lcl/forms.pp index da85ca8754..72f29383dd 100644 --- a/lcl/forms.pp +++ b/lcl/forms.pp @@ -574,6 +574,9 @@ type function IsShortcut(var Message: TLMKey): boolean; virtual; procedure MakeFullyVisible(AMonitor: TMonitor = nil; UseWorkarea: Boolean = False); function AutoSizeCheckParent: Boolean; override; + procedure GetPreferredSize(var PreferredWidth, PreferredHeight: integer; + Raw: boolean = false; + WithThemeSpace: boolean = true); override; procedure Release; function CanFocus: Boolean; override; procedure SetFocus; override; diff --git a/lcl/include/control.inc b/lcl/include/control.inc index c2e8caf559..ec65d10372 100644 --- a/lcl/include/control.inc +++ b/lcl/include/control.inc @@ -2399,8 +2399,8 @@ procedure TControl.DoAllAutoSize; i: Integer; begin if AControl.AutoSizeDelayed then exit; - if not (cfAutoSizeNeeded in AControl.FControlFlags) then exit; + //DebugLn(['TControl.DoAllAutoSize.AutoSizeControl ',DbgSName(AControl),' AutoSize=',AControl.AutoSize]); Exclude(AControl.FControlFlags,cfAutoSizeNeeded); if AControl.AutoSize then @@ -2472,6 +2472,7 @@ begin end; end; +{$IFDEF OldAutoSize} {------------------------------------------------------------------------------ function TControl.AutoSizeCanStart: boolean; @@ -2505,6 +2506,7 @@ begin end; {$ENDIF} end; +{$ENDIF} {$IFNDEF OldAutoSize} function TControl.AutoSizePhase: TControlAutoSizePhase; diff --git a/lcl/include/customform.inc b/lcl/include/customform.inc index b83a8d4008..eaa853402a 100644 --- a/lcl/include/customform.inc +++ b/lcl/include/customform.inc @@ -560,8 +560,6 @@ end; procedure TCustomForm.WMPaint(var Message: TLMPaint); begin //DebugLn('[TCustomForm.WMPaint] ',Name,':',ClassName); - if AutoSizingLockCount = 0 then - Include(FFormState, fsDisableAutoSize); inherited WMPaint(Message); //DebugLn('[TCustomForm.WMPaint] END ',Name,':',ClassName); end; @@ -581,6 +579,18 @@ begin {$IFDEF CHECK_POSITION} DebugLn('[TCustomForm.WMSize] ',DbgSName(Self),' Message.SizeType=',dbgs(Message.SizeType),' Message.Width=',dbgs(Message.Width),' Message.Height=',dbgs(Message.Height)); {$ENDIF} + + if (Parent=nil) and ((Message.SizeType and SIZE_SourceIsInterface)>0) then + begin + // this is a top level form (constraints depend on window manager) + // and the widgetset set a size + if (Message.Width<>Width) or (Message.Height<>Height) then + begin + // the window manager sets another size => disable autosize to prevent endless loop + Include(FFormState,fsDisableAutoSize); + end; + end; + Assert(False, 'Trace:WMSIZE in TCustomForm'); if not (csDesigning in ComponentState) then begin @@ -1158,11 +1168,22 @@ begin end; end; +procedure TCustomForm.GetPreferredSize(var PreferredWidth, + PreferredHeight: integer; Raw: boolean; WithThemeSpace: boolean); +begin + if fsDisableAutoSize in FFormState then begin + PreferredWidth:=Width; + PreferredHeight:=Height; + end else begin + inherited GetPreferredSize(PreferredWidth, PreferredHeight, Raw, + WithThemeSpace); + end; +end; + procedure TCustomForm.DoAutoSize; begin //DebugLn(['TCustomForm.DoAutoSize ',DbgSName(Self),' ',WindowState=wsNormal,' ',fsDisableAutoSize in FFormState,' ',dbgs(BoundsRect),' ',dbgs(ClientRect)]); - if (WindowState=wsNormal) and (not (fsDisableAutoSize in FFormState)) then - inherited DoAutoSize; + inherited DoAutoSize; end; procedure TCustomForm.SetAutoSize(Value: Boolean); diff --git a/lcl/include/wincontrol.inc b/lcl/include/wincontrol.inc index 74f191eb5d..240ee7210f 100644 --- a/lcl/include/wincontrol.inc +++ b/lcl/include/wincontrol.inc @@ -3319,7 +3319,7 @@ begin {$IFDEF VerboseAllAutoSize} debugln('TWinControl.DoAutoSize ',DbgSName(Self)); {$ENDIF} - if (not AutoSizeCanStart) or (AutoSizePhase<>caspComputingBounds) then begin + if (AutoSizePhase<>caspComputingBounds) then begin {$IFDEF VerboseAllAutoSize} DebugLn(['TWinControl.DoAutoSize DELAYED AutoSizeCanStart=',AutoSizeCanStart,' AutoSizeDelayed=',AutoSizeDelayed,' AutoSizePhase=',AutoSizePhaseNames[AutoSizePhase]]); {$ENDIF}