From 75cd574d960ceeade625a6cde667ab53f955ae1a Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 19 May 2010 13:40:14 +0000 Subject: [PATCH] LCL: use AdjustClientRect for AnchorSides git-svn-id: trunk@25515 - --- lcl/controls.pp | 33 +++++++++++++++++++++++++++------ lcl/include/control.inc | 2 ++ lcl/include/wincontrol.inc | 14 ++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/lcl/controls.pp b/lcl/controls.pp index fbb5e45fa5..9de16830af 100644 --- a/lcl/controls.pp +++ b/lcl/controls.pp @@ -1588,7 +1588,8 @@ type wcfRealizingBounds, wcfBoundsRealized, // bounds were sent to the interface wcfUpdateShowing, - wcfHandleVisible + wcfHandleVisible, + wcfAdjustedLogicalClientRectValid ); TWinControlFlags = set of TWinControlFlag; @@ -1625,6 +1626,7 @@ type FBorderStyle: TBorderStyle; FBrush: TBrush; FAdjustClientRectRealized: TRect; + FAdjustClientRect: TRect; // valid if wcfAdjustClientRectValid FChildSizing: TControlChildSizing; FControls: TFPList; // the child controls FOnGetDockCaption: TGetDockCaptionEvent; @@ -1685,6 +1687,7 @@ type FWinControlFlags: TWinControlFlags; class procedure WSRegisterClass; override; procedure AdjustClientRect(var ARect: TRect); virtual; + procedure GetAdjustedLogicalClientRect(out ARect: TRect); procedure CreateControlAlignList(TheAlign: TAlign; AlignList: TFPList; StartControl: TControl); procedure AlignControls(AControl: TControl; @@ -3399,6 +3402,9 @@ end; procedure TAnchorSide.GetSidePosition(out ReferenceControl: TControl; out ReferenceSide: TAnchorSideReference; out Position: Integer); +var + ParentRect: TRect; + ParentRectValid: boolean; procedure RaiseInvalidSide; begin @@ -3417,6 +3423,20 @@ procedure TAnchorSide.GetSidePosition(out ReferenceControl: TControl; Result:=false; end; + function GetParentSidePos(Side: TAnchorKind): integer; + begin + if not ParentRectValid then begin + FOwner.Parent.GetAdjustedLogicalClientRect(ParentRect); + ParentRectValid:=true; + end; + case Side of + akTop: Result:=ParentRect.Top; + akLeft: Result:=ParentRect.Left; + akRight: Result:=ParentRect.Right; + akBottom: Result:=ParentRect.Bottom; + end; + end; + var NextReferenceSide: TAnchorSide; ChainLength: Integer; @@ -3436,6 +3456,7 @@ begin //if CheckPosition(Owner) then DebugLn(['TAnchorSide.GetSidePosition OwnerParent=nil']); exit; end; + ParentRectValid:=false; ChainLength:=0; MaxChainLength:=OwnerParent.ControlCount; Found:=false; @@ -3480,7 +3501,7 @@ begin if Kind in [akLeft,akRight] then begin // anchor to left side of ReferenceControl if ReferenceControl=OwnerParent then - Position:=0 + Position:=GetParentSidePos(akLeft) else Position:=ReferenceControl.Left; if ReferenceControl=OwnerParent then @@ -3500,7 +3521,7 @@ begin end else begin // anchor to top side of ReferenceControl if ReferenceControl=OwnerParent then - Position:=0 + Position:=GetParentSidePos(akTop) else Position:=ReferenceControl.Top; if ReferenceControl=OwnerParent then @@ -3523,7 +3544,7 @@ begin if Kind in [akLeft,akRight] then begin // anchor to right side of ReferenceControl if ReferenceControl=OwnerParent then - Position:=OwnerParent.GetLogicalClientRect.Right + Position:=GetParentSidePos(akRight) else Position:=ReferenceControl.Left+ReferenceControl.Width; if ReferenceControl=OwnerParent then @@ -3543,7 +3564,7 @@ begin end else begin // anchor to bottom side of ReferenceControl if ReferenceControl=OwnerParent then - Position:=OwnerParent.GetLogicalClientRect.Bottom + Position:=GetParentSidePos(akBottom) else Position:=ReferenceControl.Top+ReferenceControl.Height; if ReferenceControl=OwnerParent then @@ -3566,7 +3587,7 @@ begin if Kind in [akLeft,akRight] then begin // center horizontally if ReferenceControl=OwnerParent then - Position:=OwnerParent.ClientWidth div 2 + Position:=GetParentSidePos(akRight)-GetParentSidePos(akLeft) else Position:=ReferenceControl.Left+(ReferenceControl.Width div 2); if Kind=akLeft then diff --git a/lcl/include/control.inc b/lcl/include/control.inc index 12ed5db30d..068c186dbc 100644 --- a/lcl/include/control.inc +++ b/lcl/include/control.inc @@ -4679,6 +4679,8 @@ begin while AControl<>nil do begin Exclude(AControl.FControlFlags,cfPreferredSizeValid); Exclude(AControl.FControlFlags,cfPreferredMinSizeValid); + if AControl is TWinControl then + Exclude(TWinControl(AControl).FWinControlFlags,wcfAdjustedLogicalClientRectValid); if not AControl.IsControlVisible then break; AControl:=AControl.Parent; end; diff --git a/lcl/include/wincontrol.inc b/lcl/include/wincontrol.inc index 7e10f11878..346dbd6b1d 100644 --- a/lcl/include/wincontrol.inc +++ b/lcl/include/wincontrol.inc @@ -2377,6 +2377,16 @@ begin // It's called often, so don't put expensive code here, or cache the result end; +procedure TWinControl.GetAdjustedLogicalClientRect(out ARect: TRect); +begin + if not (wcfAdjustedLogicalClientRectValid in FWinControlFlags) then begin + FAdjustClientRect:=GetLogicalClientRect; + AdjustClientRect(FAdjustClientRect); + Include(FWinControlFlags,wcfAdjustedLogicalClientRectValid); + end; + ARect:=FAdjustClientRect; +end; + {------------------------------------------------------------------------------ TWinControl CreateControlAlignList @@ -3197,6 +3207,8 @@ begin AControl:=Controls[i]; Exclude(AControl.FControlFlags,cfPreferredSizeValid); Exclude(AControl.FControlFlags,cfPreferredMinSizeValid); + if AControl is TWinControl then + Exclude(TWinControl(AControl).FWinControlFlags,wcfAdjustedLogicalClientRectValid); if AControl is TWinControl then TWinControl(AControl).InvalidatePreferredChildSizes; end; @@ -3621,6 +3633,7 @@ begin //DumpStack; end; {$ENDIF} + Exclude(FWinControlFlags,wcfAdjustedLogicalClientRectValid); Include(FWinControlFlags,wcfClientRectNeedsUpdate); if WithChildControls then begin @@ -3842,6 +3855,7 @@ function TWinControl.GetClientRect: TRect; DebugLn(['StoreClientRect ',DbgSName(Self),' ',FClientWidth,',',FClientHeight,' HandleAllocated=',HandleAllocated,' wcfBoundsRealized=',wcfBoundsRealized in FWinControlFlags]); {$ENDIF} FAdjustClientRectRealized:=Rect(0,0,0,0); + Exclude(FWinControlFlags,wcfAdjustedLogicalClientRectValid); end; Exclude(FWinControlFlags,wcfClientRectNeedsUpdate); end;