LCL: autosizing now uses logical clienrect, so Align<>alNone controls now fills the whole logical area

git-svn-id: trunk@12679 -
This commit is contained in:
mattias 2007-11-01 14:32:15 +00:00
parent 6157d8c8b3
commit 112a347fa5
5 changed files with 46 additions and 18 deletions

View File

@ -974,8 +974,9 @@ type
procedure SetAlignedBounds(aLeft, aTop, aWidth, aHeight: integer); virtual;
function IsAParentAligning: boolean;
function GetClientOrigin: TPoint; virtual;
function GetClientRect: TRect; virtual;
function GetScrolledClientRect: TRect; virtual;
function GetClientRect: TRect; virtual;// visual size of client area
function GetLogicalClientRect: TRect; virtual;// logical size of client area (e.g. in a TScrollBox the logical client area can be bigger than the visual)
function GetScrolledClientRect: TRect; virtual;// visual client area scrolled
function GetClientScrollOffset: TPoint; virtual;
function GetControlOrigin: TPoint; virtual;
function IsClientHeightStored: boolean; virtual;
@ -3166,7 +3167,7 @@ begin
if Kind in [akLeft,akRight] then begin
// anchor to right side of ReferenceControl
if ReferenceControl=OwnerParent then
Position:=OwnerParent.ClientWidth
Position:=OwnerParent.GetLogicalClientRect.Right
else
Position:=ReferenceControl.Left+ReferenceControl.Width;
if ReferenceControl=OwnerParent then
@ -3186,7 +3187,7 @@ begin
end else begin
// anchor to bottom side of ReferenceControl
if ReferenceControl=OwnerParent then
Position:=OwnerParent.ClientHeight
Position:=OwnerParent.GetLogicalClientRect.Bottom
else
Position:=ReferenceControl.Top+ReferenceControl.Height;
if ReferenceControl=OwnerParent then

View File

@ -156,6 +156,7 @@ type
procedure AlignControls(AControl: TControl; var ARect: TRect); override;
procedure CreateWnd; override;
function GetClientScrollOffset: TPoint; override;
function GetLogicalClientRect: TRect; override;// logical size of client area
procedure DoOnResize; override;
class function GetControlClassDefaultSize: TPoint; override;
procedure WMHScroll(var Message : TLMHScroll); message LM_HScroll;

View File

@ -128,7 +128,7 @@ begin
DebugLn('TControl.DoDock BEFORE Adjusting ',Name,' ',dbgs(ARect));
// adjust new bounds, so that they at least fit into the client area of
// its parent
LCLProc.MoveRectToFit(ARect,NewDockSite.ClientRect);
LCLProc.MoveRectToFit(ARect,NewDockSite.GetLogicalClientRect);
// consider Align to increase chance the width/height is kept
case Align of
alLeft: OffsetRect(ARect,-ARect.Left,0);
@ -1413,7 +1413,11 @@ begin
end;
{------------------------------------------------------------------------------
TControl GetClientRect
TControl GetClientRect
Returns the size of visual client area.
For example the inner size of a TGroupBox.
For a TScrollBox it is the visual size, not the logical size.
------------------------------------------------------------------------------}
function TControl.GetClientRect: TRect;
begin
@ -1423,6 +1427,18 @@ begin
Result.Bottom := Height;
end;
{------------------------------------------------------------------------------
TControl GetLogicalClientRect
Returns the size of complete client area. It can be bigger or smaller than
the visual size, but normally it is the same. For example a TScrollBox can
have different sizes.
------------------------------------------------------------------------------}
function TControl.GetLogicalClientRect: TRect;
begin
Result:=ClientRect;
end;
{------------------------------------------------------------------------------
function TControl.GetScrolledClientRect: TRect;

View File

@ -43,6 +43,11 @@ begin
end;
end;
function TScrollingWinControl.GetLogicalClientRect: TRect;
begin
Result:=Rect(0,0,Max(0,FHorzScrollBar.Range),Max(0,FVertScrollBar.Range));
end;
procedure TScrollingWinControl.AlignControls(AControl: TControl;
var ARect: TRect);
begin

View File

@ -737,6 +737,7 @@ var
ChildData: TAutoSizeCtrlData;
MoveDiff: Integer;
AlignList: TFPList;
r: TRect;
begin
if ChildCount=0 then exit;
if WinControl.ChildSizing.Layout=cclNone then begin
@ -771,8 +772,8 @@ begin
ChildSizing.ShrinkVertical:=crsAnchorAligning;
ChildSizing.EnlargeVertical:=crsAnchorAligning;
// compute static layout
Box.AlignControlsInTable(AlignList,ChildSizing,
WinControl.ClientWidth,WinControl.ClientHeight,false);
r:=WinControl.GetLogicalClientRect;
Box.AlignControlsInTable(AlignList,ChildSizing,r.Right,r.Bottom,false);
//Box.WriteDebugReport('TAutoSizeCtrlData.SetupNonAlignedChilds');
// transfer the coords of the layout
for y:=0 to Box.ChildCount[asboVertical]-1 do begin
@ -2219,6 +2220,7 @@ var
CurAlignAnchors: TAnchors;
OldBounds: TRect;
NewBounds: TRect;
r: TRect;
function ConstraintWidth(NewWidth: integer): Integer;
begin
@ -2329,8 +2331,9 @@ var
ConstraintWidth(NewLeft,NewWidth);
ConstraintHeight(NewTop,NewHeight);
end;
ParentClientWidth:=Control.Parent.ClientWidth;
ParentClientHeight:=Control.Parent.ClientHeight;
r:=Control.Parent.GetLogicalClientRect;
ParentClientWidth:=r.Right;
ParentClientHeight:=r.Bottom;
InitAnchorSideCache;
@ -2426,7 +2429,7 @@ var
if akBottom in CurAnchors then begin
// keep distance to bottom side of parent
// -> change the height
NewBottom:=Control.Parent.ClientHeight
NewBottom:=ParentClientHeight
-(ParentBaseClientSize.Y-CurBaseBounds.Bottom);
if (not (akBottom in CurAlignAnchors))
and (akBottom in Control.Anchors) then
@ -2441,7 +2444,7 @@ var
if akBottom in CurAnchors then begin
// keep distance to bottom side of parent
// and keep new height
NewBottom:=Control.Parent.ClientHeight
NewBottom:=ParentClientHeight
-(ParentBaseClientSize.Y-CurBaseBounds.Bottom);
if (not (akBottom in CurAlignAnchors))
and (akBottom in Control.Anchors) then
@ -2450,7 +2453,7 @@ var
end else begin
// do not anchor to the bottom
// -> keep new height and center vertically
NewTop:=(Control.Parent.ClientHeight-NewHeight) div 2;
NewTop:=(ParentClientHeight-NewHeight) div 2;
end;
end;
{$IFDEF CHECK_POSITION}
@ -3014,7 +3017,7 @@ begin
// move free childs as much as possible to left and top (all free childs the same)
if HasVisibleChilds then begin
CurClientRect:=ClientRect;
CurClientRect:=GetLogicalClientRect;
AdjustClientRect(CurClientRect);
// get minimum left, top of non aligned childs
GetMoveDiffForNonAlignedChilds(CurClientRect,dx,dy);
@ -5409,6 +5412,7 @@ procedure TWinControl.AlignNonAlignedControls(ListOfControls: TFPList;
}
var
Box: TAutoSizeBox;
r: TRect;
begin
// check if ChildSizing aligning is enabled
if (ChildSizing.Layout=cclNone) or (ListOfControls.Count=0) then
@ -5418,8 +5422,9 @@ begin
Box:=TAutoSizeBox.Create;
try
r:=GetLogicalClientRect;
BoundsModified:=Box.AlignControlsInTable(ListOfControls,ChildSizing,
ClientWidth,ClientHeight,true);
r.Right,r.Bottom,true);
finally
Box.Free;
end;
@ -5554,11 +5559,11 @@ begin
DisableAlign;
try
ARect:= GetClientRect;
ARect:= GetLogicalClientRect;
AlignControls(AControl, ARect);
// some widgetsets updates their clientrect when the first child was moved
// do a second pass if ClientRect changed
NewRect:=GetClientRect;
NewRect:=GetLogicalClientRect;
if not CompareRect(@ARect,@NewRect) then
AlignControls(AControl, NewRect);
finally
@ -5789,7 +5794,7 @@ var
CurControl: TControl;
AWidth: Integer;
begin
AWidth:=ClientWidth;
AWidth:=GetLogicalClientRect.Right;
for i:=0 to ControlCount-1 do begin
CurControl:=Controls[i];
CurControl.Left:=AWidth-CurControl.Left-CurControl.Width;