LCL: reduced number of TWSWinControlClass.SetBounds calls

git-svn-id: trunk@12668 -
This commit is contained in:
mattias 2007-11-01 02:05:47 +00:00
parent 574f810690
commit 178543e288
4 changed files with 90 additions and 39 deletions

View File

@ -286,17 +286,17 @@ constructor TfrmCompilerOptions.Create(TheOwner: TComponent);
var var
Page: integer; Page: integer;
begin begin
inherited Create(TheOwner);
Caption := dlgCompilerOptions;
IDEDialogLayoutList.ApplyLayout(Self,550,450);
ImageIndexPackage := IDEImages.LoadImage(16, 'pkg_package');
ImageIndexRequired := IDEImages.LoadImage(16, 'pkg_required');
ImageIndexInherited := IDEImages.LoadImage(16, 'pkg_inherited');
DisableAlign; DisableAlign;
try try
inherited Create(TheOwner);
Caption := dlgCompilerOptions;
IDEDialogLayoutList.ApplyLayout(Self,550,450);
ImageIndexPackage := IDEImages.LoadImage(16, 'pkg_package');
ImageIndexRequired := IDEImages.LoadImage(16, 'pkg_required');
ImageIndexInherited := IDEImages.LoadImage(16, 'pkg_inherited');
MainNotebook.PageIndex:=0; MainNotebook.PageIndex:=0;
Page:=0; Page:=0;

View File

@ -756,7 +756,6 @@ type
cfHeightLoaded, cfHeightLoaded,
cfClientWidthLoaded, cfClientWidthLoaded,
cfClientHeightLoaded, cfClientHeightLoaded,
cfLastAlignedBoundsValid,
cfBoundsRectForNewParentValid, cfBoundsRectForNewParentValid,
cfBaseBoundsValid, cfBaseBoundsValid,
cfPreferredSizeValid, cfPreferredSizeValid,
@ -826,6 +825,7 @@ type
FHostDockSite: TWinControl; FHostDockSite: TWinControl;
FIsControl: Boolean; FIsControl: Boolean;
fLastAlignedBounds: TRect; fLastAlignedBounds: TRect;
fLastAlignedBoundsTried: integer;
FLastChangebounds: TRect; FLastChangebounds: TRect;
FLastDoChangeBounds: TRect; FLastDoChangeBounds: TRect;
FLastDoChangeClientSize: TPoint; FLastDoChangeClientSize: TPoint;
@ -972,6 +972,7 @@ type
procedure ChangeScale(Multiplier, Divider: Integer); dynamic; procedure ChangeScale(Multiplier, Divider: Integer); dynamic;
function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; virtual; function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; virtual;
procedure SetAlignedBounds(aLeft, aTop, aWidth, aHeight: integer); virtual; procedure SetAlignedBounds(aLeft, aTop, aWidth, aHeight: integer); virtual;
function IsAParentAligning: boolean;
function GetClientOrigin: TPoint; virtual; function GetClientOrigin: TPoint; virtual;
function GetClientRect: TRect; virtual; function GetClientRect: TRect; virtual;
function GetScrolledClientRect: TRect; virtual; function GetScrolledClientRect: TRect; virtual;
@ -1597,6 +1598,7 @@ type
procedure ControlsAligned; virtual;// called by AlignControls after aligning controls procedure ControlsAligned; virtual;// called by AlignControls after aligning controls
procedure DoSendBoundsToInterface; virtual; procedure DoSendBoundsToInterface; virtual;
procedure RealizeBounds; virtual;// checks for changes and calls DoSendBoundsToInterface procedure RealizeBounds; virtual;// checks for changes and calls DoSendBoundsToInterface
procedure RealizeBoundsRecursive;
procedure CreateSubClass(var Params: TCreateParams;ControlClassName: PChar); procedure CreateSubClass(var Params: TCreateParams;ControlClassName: PChar);
procedure DoConstraintsChange(Sender: TObject); override; procedure DoConstraintsChange(Sender: TObject); override;
procedure DoSetBounds(ALeft, ATop, AWidth, AHeight: integer); override; procedure DoSetBounds(ALeft, ATop, AWidth, AHeight: integer); override;

View File

@ -1282,11 +1282,16 @@ var
NewBounds: TRect; NewBounds: TRect;
begin begin
NewBounds:=Bounds(aLeft, aTop, aWidth, aHeight); NewBounds:=Bounds(aLeft, aTop, aWidth, aHeight);
if (cfLastAlignedBoundsValid in FControlFlags) if (fLastAlignedBoundsTried>0)
and CompareRect(@NewBounds,@fLastAlignedBounds) then and CompareRect(@NewBounds,@fLastAlignedBounds) then begin
exit; inc(fLastAlignedBoundsTried);
if fLastAlignedBoundsTried>4 then begin
DebugLn(['TControl.SetAlignedBounds ',DbgSName(Self),' last try ',dbgs(NewBounds),' try=',fLastAlignedBoundsTried]);
exit;
end;
end;
fLastAlignedBounds:=NewBounds; fLastAlignedBounds:=NewBounds;
Include(FControlFlags,cfLastAlignedBoundsValid); fLastAlignedBoundsTried:=1;
//if AnsiCompareText(ClassName,'TSCROLLBAR')=0 then //if AnsiCompareText(ClassName,'TSCROLLBAR')=0 then
// DebugLn('TControl.SetAlignedBounds A ',Name,':',ClassName,' ',aLeft,',',aTop,',',aWidth,',',aHeight); // DebugLn('TControl.SetAlignedBounds A ',Name,':',ClassName,' ',aLeft,',',aTop,',',aWidth,',',aHeight);
@ -1294,6 +1299,20 @@ begin
SetBoundsKeepBase(aLeft, aTop, aWidth, aHeight, true); SetBoundsKeepBase(aLeft, aTop, aWidth, aHeight, true);
end; end;
function TControl.IsAParentAligning: boolean;
var
p: TWinControl;
begin
p:=Parent;
while (p<>nil) do begin
if (wcfAligningControls in p.FWinControlFlags)
or (p.FAlignLevel>0) then
exit(true);
p:=p.Parent;
end;
Result:=false;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
procedure TControl.VisibleChanging; procedure TControl.VisibleChanging;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -2738,7 +2757,7 @@ begin
//DebugLn(['TControl.SetAlign ',DbgSName(Self),' Old=',AlignNames[FAlign],' New=',AlignNames[Value],' ',Anchors<>AnchorAlign[FAlign]]); //DebugLn(['TControl.SetAlign ',DbgSName(Self),' Old=',AlignNames[FAlign],' New=',AlignNames[Value],' ',Anchors<>AnchorAlign[FAlign]]);
OldAlign:=FAlign; OldAlign:=FAlign;
FAlign := Value; FAlign := Value;
Exclude(FControlFlags,cfLastAlignedBoundsValid); fLastAlignedBoundsTried:=0;
// if anchors were on default then change them to new default // if anchors were on default then change them to new default
// This is done for Delphi compatibility. // This is done for Delphi compatibility.
if (Anchors=AnchorAlign[OldAlign]) and (Anchors<>AnchorAlign[FAlign]) then if (Anchors=AnchorAlign[OldAlign]) and (Anchors<>AnchorAlign[FAlign]) then
@ -2754,7 +2773,7 @@ procedure TControl.SetAnchors(const AValue: TAnchors);
begin begin
if Anchors=AValue then exit; if Anchors=AValue then exit;
FAnchors:=AValue; FAnchors:=AValue;
Exclude(FControlFlags,cfLastAlignedBoundsValid); fLastAlignedBoundsTried:=0;
RequestAlign; RequestAlign;
end; end;

View File

@ -31,8 +31,8 @@
{off $DEFINE CHECK_POSITION} {off $DEFINE CHECK_POSITION}
{$IFDEF CHECK_POSITION} {$IFDEF CHECK_POSITION}
const CheckPostionClassName = 'xxxTButtonPanel'; const CheckPostionClassName = 'xxxTButtonPanel';
const CheckPostionName = 'xxxedtUnitOutputDir'; const CheckPostionName = 'xxInhTreeView';
const CheckPostionParentName = 'PathPage'; const CheckPostionParentName = 'xxxInheritedPage';
function CheckPosition(AControl: TControl): boolean; function CheckPosition(AControl: TControl): boolean;
begin begin
@ -1958,12 +1958,11 @@ begin
NewBounds:=ControlBox.NewControlBounds; NewBounds:=ControlBox.NewControlBounds;
OldBounds:=CurControl.BoundsRect; OldBounds:=CurControl.BoundsRect;
if not CompareRect(@NewBounds,@OldBounds) then begin if not CompareRect(@NewBounds,@OldBounds) then begin
//DebugLn('TAutoSizeBox.SetTableControlBounds Control=',DbgSName(CurControl),' CellBounds=',dbgs(CellBounds),' NewBounds=',dbgs(NewBounds));
Result:=true; Result:=true;
CurControl.SetBoundsKeepBase(NewBounds.Left, CurControl.SetAlignedBounds(NewBounds.Left,
NewBounds.Top, NewBounds.Top,
NewBounds.Right-NewBounds.Left, NewBounds.Right-NewBounds.Left,
NewBounds.Bottom-NewBounds.Top); NewBounds.Bottom-NewBounds.Top);
end; end;
end; end;
end; end;
@ -2188,6 +2187,14 @@ var
end; end;
end; end;
function IsNotAligned(AControl: TControl): boolean;
begin
Result:=(AControl.Align=alNone)
and (AControl.Anchors=[akLeft,akTop])
and (AControl.AnchorSide[akLeft].Control=nil)
and (AControl.AnchorSide[akTop].Control=nil);
end;
procedure DoPosition(Control: TControl; AAlign: TAlign); procedure DoPosition(Control: TControl; AAlign: TAlign);
var var
NewLeft, NewTop, NewWidth, NewHeight: Integer; NewLeft, NewTop, NewWidth, NewHeight: Integer;
@ -2666,6 +2673,7 @@ var
procedure DoAlign(AAlign: TAlign); procedure DoAlign(AAlign: TAlign);
var var
I: Integer; I: Integer;
Control: TControl;
begin begin
//DebugLn(['DoAlign ',DbgSName(Self),' ',dbgs(ClientRect)]); //DebugLn(['DoAlign ',DbgSName(Self),' ',dbgs(ClientRect)]);
CreateControlAlignList(AAlign,AlignList,AControl); CreateControlAlignList(AAlign,AlignList,AControl);
@ -2681,10 +2689,19 @@ var
DebugLn(']'); DebugLn(']');
end; end;
{$ENDIF} {$ENDIF}
if not DoAlignChildControls(AAlign,AControl,AlignList,RemainingClientRect) then // let override handle them
for I := 0 to AlignList.Count - 1 do if DoAlignChildControls(AAlign,AControl,AlignList,RemainingClientRect) then
DoPosition(TControl(AlignList[I]), AAlign); exit;
// remove controls that are positioned by other means
if (AAlign=alNone) and (AutoSize or (ChildSizing.Layout<>cclNone)) then
for I := AlignList.Count - 1 downto 0 do begin
Control:=TControl(AlignList[I]);
if IsNotAligned(Control) then AlignList.Delete(I);
end;
// anchor/align control
for I := 0 to AlignList.Count - 1 do
DoPosition(TControl(AlignList[I]), AAlign);
end; end;
procedure DoAlignNotAligned; procedure DoAlignNotAligned;
@ -2701,14 +2718,8 @@ var
AlignList.Clear; AlignList.Clear;
for i:=0 to ControlCount-1 do begin for i:=0 to ControlCount-1 do begin
Control := Controls[i]; Control := Controls[i];
if (Control.Align=alNone) if IsNotAligned(Control) and Control.IsControlVisible then
and Control.IsControlVisible
and (Control.Anchors=[akLeft,akTop])
and (Control.AnchorSide[akLeft].Control=nil)
and (Control.AnchorSide[akTop].Control=nil)
then begin
AlignList.Add(Control); AlignList.Add(Control);
end;
end; end;
//debugln('DoAlignNotAligned ',DbgSName(Self),' AlignList.Count=',dbgs(AlignList.Count)); //debugln('DoAlignNotAligned ',DbgSName(Self),' AlignList.Count=',dbgs(AlignList.Count));
if AlignList.Count=0 then exit; if AlignList.Count=0 then exit;
@ -3065,7 +3076,7 @@ begin
inc(NewTop,Height-PreferredHeight); inc(NewTop,Height-PreferredHeight);
//if CompareText(Name,'NewUnitOkButton')=0 then //if CompareText(Name,'NewUnitOkButton')=0 then
//debugln(['DoAutoSize Resize ',DbgSName(Self),' Old=',dbgs(BoundsRect),' New=',dbgs(Bounds(NewLeft,NewTop,PreferredWidth,PreferredHeight)),' WidthIsFixed=',WidthIsFixed,' HeightIsFixed=',HeightIsFixed,' Align=',dbgs(Align),' Anchors=',dbgs(Anchors)]); //debugln(['DoAutoSize Resize ',DbgSName(Self),' Old=',dbgs(BoundsRect),' New=',dbgs(Bounds(NewLeft,NewTop,PreferredWidth,PreferredHeight)),' WidthIsFixed=',WidthIsFixed,' HeightIsFixed=',HeightIsFixed,' Align=',dbgs(Align),' Anchors=',dbgs(Anchors)]);
SetBoundsKeepBase(NewLeft,NewTop,PreferredWidth,PreferredHeight,true); SetAlignedBounds(NewLeft,NewTop,PreferredWidth,PreferredHeight);
end; end;
finally finally
Exclude(FControlFlags,cfAutoSizeNeeded); Exclude(FControlFlags,cfAutoSizeNeeded);
@ -3405,7 +3416,7 @@ function TWinControl.GetClientRect: TRect;
{$ENDIF} {$ENDIF}
if ClientSizeChanged then begin if ClientSizeChanged then begin
for i:=0 to ControlCount-1 do for i:=0 to ControlCount-1 do
Exclude(Controls[i].FControlFlags,cfLastAlignedBoundsValid); Controls[i].fLastAlignedBoundsTried:=0;
end; end;
Exclude(FWinControlFlags,wcfClientRectNeedsUpdate); Exclude(FWinControlFlags,wcfClientRectNeedsUpdate);
end; end;
@ -5547,6 +5558,9 @@ begin
finally finally
Exclude(FControlState, csAlignmentNeeded); Exclude(FControlState, csAlignmentNeeded);
EnableAlign; EnableAlign;
if (FAlignLevel=0) and (not IsAParentAligning) and (FWinControls<>nil) then
for i:=0 to FWinControls.Count-1 do
TWinControl(FWinControls[i]).RealizeBoundsRecursive;
end; end;
End; End;
@ -6912,7 +6926,10 @@ begin
if CheckPosition(Self) and (AWidth=1) then if CheckPosition(Self) and (AWidth=1) then
DumpStack; DumpStack;
{$ENDIF} {$ENDIF}
if BoundsLockCount<>0 then exit; if BoundsLockCount<>0 then begin
//DebugLn(['TWinControl.SetBounds ',DbgSName(Self),' ignoring loop Cur=',dbgs(BoundsRect),' ',dbgs(Bounds(ALeft,ATop,AWidth,AHeight))]);
exit;
end;
OldBounds:=BoundsRect; OldBounds:=BoundsRect;
NewBounds:=Bounds(ALeft, ATop, AWidth, AHeight); NewBounds:=Bounds(ALeft, ATop, AWidth, AHeight);
@ -7161,8 +7178,10 @@ var
begin begin
NewBounds:=Bounds(Left, Top, Width, Height); NewBounds:=Bounds(Left, Top, Width, Height);
if HandleAllocated if HandleAllocated
and (not (csLoading in ComponentState)) and ([csLoading,csDestroying]*ComponentState=[])
and (not CompareRect(@NewBounds,@FBoundsRealized)) then and (not (csDestroyingHandle in ControlState))
and (not CompareRect(@NewBounds,@FBoundsRealized))
and (not IsAParentAligning) then
begin begin
// the new bounds were not yet sent to the InterfaceObject -> send them // the new bounds were not yet sent to the InterfaceObject -> send them
{$IFDEF CHECK_POSITION} {$IFDEF CHECK_POSITION}
@ -7181,6 +7200,17 @@ begin
end; end;
end; end;
procedure TWinControl.RealizeBoundsRecursive;
var
i: Integer;
begin
RealizeBounds;
if FWinControls<>nil then begin
for i:=0 to FWinControls.Count-1 do
TWinControl(FWinControls[i]).RealizeBoundsRecursive;
end;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TWinControl.CMShowingChanged Method: TWinControl.CMShowingChanged
Params: Message : not used Params: Message : not used