LCL: TAnchorSide.GetSidePosition check always for circles

git-svn-id: trunk@20298 -
This commit is contained in:
mattias 2009-05-29 14:24:23 +00:00
parent 8ac8d4e9f9
commit e50a4f4556
2 changed files with 151 additions and 133 deletions

View File

@ -1736,6 +1736,7 @@ begin
CurrentIdentifierList.ContextFlags:= CurrentIdentifierList.ContextFlags:=
CurrentIdentifierList.ContextFlags+[ilcfStartInStatement]; CurrentIdentifierList.ContextFlags+[ilcfStartInStatement];
end; end;
// context in front of // context in front of
StartPosOfVariable:=FindStartOfVariable(IdentStartPos); StartPosOfVariable:=FindStartOfVariable(IdentStartPos);
if StartPosOfVariable>0 then begin if StartPosOfVariable>0 then begin

View File

@ -3269,190 +3269,207 @@ var
MaxChainLength: LongInt; MaxChainLength: LongInt;
OwnerBorderSpacing: LongInt; OwnerBorderSpacing: LongInt;
OwnerParent: TWinControl; OwnerParent: TWinControl;
Found: Boolean;
CurReferenceControl: TControl;
CurReferenceSide: TAnchorSideReference;
begin begin
ReferenceControl:=Control; ReferenceControl:=nil;
ReferenceSide:=Side; ReferenceSide:=Side;
Position:=0; Position:=0;
OwnerParent:=FOwner.Parent; OwnerParent:=FOwner.Parent;
if OwnerParent=nil then begin if OwnerParent=nil then begin
// AnchorSide is only between siblings or its direct parent allowed // AnchorSide is only between siblings or its direct parent allowed
//if CheckPosition(Owner) then DebugLn(['TAnchorSide.GetSidePosition OwnerParent=nil']); //if CheckPosition(Owner) then DebugLn(['TAnchorSide.GetSidePosition OwnerParent=nil']);
ReferenceControl:=nil;
exit; exit;
end; end;
ChainLength:=0; ChainLength:=0;
MaxChainLength:=OwnerParent.ControlCount; MaxChainLength:=OwnerParent.ControlCount;
while ReferenceControl<>nil do begin Found:=false;
CurReferenceControl:=Control;
CurReferenceSide:=Side;
while CurReferenceControl<>nil do begin
// check for circles // check for circles
inc(ChainLength); inc(ChainLength);
if ChainLength>MaxChainLength then begin if ChainLength>MaxChainLength then begin
// the chain has more elements than there are siblings -> circle // the chain has more elements than there are siblings -> circle
//if CheckPosition(Owner) then DebugLn(['TAnchorSide.GetSidePosition Circle']); //if CheckPosition(Owner) then
DebugLn(['TAnchorSide.GetSidePosition Circle ',DbgSName(Owner)]);
ReferenceControl:=nil; ReferenceControl:=nil;
exit; exit;
end; end;
// check if ReferenceControl is valid // check if ReferenceControl is valid
if (ReferenceControl.Parent<>OwnerParent) if (CurReferenceControl.Parent<>OwnerParent)
and (ReferenceControl<>OwnerParent) then begin and (CurReferenceControl<>OwnerParent) then begin
// not a sibling and not the parent -> invalid AnchorSide // not a sibling and not the parent -> invalid AnchorSide
//if CheckPosition(Owner) then DebugLn(['TAnchorSide.GetSidePosition invalid AnchorSide ',dbgsName(ReferenceControl)]); //if CheckPosition(Owner) then DebugLn(['TAnchorSide.GetSidePosition invalid AnchorSide ',dbgsName(ReferenceControl)]);
ReferenceControl:=nil; ReferenceControl:=nil;
exit; exit;
end; end;
if ReferenceControl.IsControlVisible then begin if CurReferenceControl.IsControlVisible then begin
// ReferenceControl is visible // ReferenceControl is visible
// -> calculate Position if not Found then begin
OwnerBorderSpacing:=FOwner.BorderSpacing.GetSpace(Kind); Found:=true;
//if CheckPosition(Owner) then DebugLn(['TAnchorSide.GetSidePosition ',dbgsName(Owner),' ReferenceControl=',dbgsName(ReferenceControl),' ',dbgs(ReferenceControl.BoundsRect),' OwnerBorderSpacing=',OwnerBorderSpacing,' Kind=',dbgs(Kind),' ReferenceSide=',dbgs(Kind,ReferenceSide)]); ReferenceControl:=CurReferenceControl;
case ReferenceSide of ReferenceSide:=CurReferenceSide;
asrTop: // asrTop = asrLeft // -> calculate Position
if Kind in [akLeft,akRight] then begin OwnerBorderSpacing:=FOwner.BorderSpacing.GetSpace(Kind);
// anchor to left side of ReferenceControl //if CheckPosition(Owner) then DebugLn(['TAnchorSide.GetSidePosition ',dbgsName(Owner),' ReferenceControl=',dbgsName(ReferenceControl),' ',dbgs(ReferenceControl.BoundsRect),' OwnerBorderSpacing=',OwnerBorderSpacing,' Kind=',dbgs(Kind),' ReferenceSide=',dbgs(Kind,ReferenceSide)]);
if ReferenceControl=OwnerParent then case ReferenceSide of
Position:=0
else asrTop: // asrTop = asrLeft
Position:=ReferenceControl.Left; if Kind in [akLeft,akRight] then begin
if ReferenceControl=OwnerParent then // anchor to left side of ReferenceControl
OwnerBorderSpacing:=Max(OwnerBorderSpacing, if ReferenceControl=OwnerParent then
OwnerParent.ChildSizing.LeftRightSpacing) Position:=0
else if Kind=akRight then else
OwnerBorderSpacing:=Max(Max(OwnerBorderSpacing, Position:=ReferenceControl.Left;
ReferenceControl.BorderSpacing.GetSpace(OppositeAnchor[Kind])), if ReferenceControl=OwnerParent then
OwnerParent.ChildSizing.HorizontalSpacing); OwnerBorderSpacing:=Max(OwnerBorderSpacing,
if Kind=akLeft then begin OwnerParent.ChildSizing.LeftRightSpacing)
// anchor left of ReferenceControl and left of Owner else if Kind=akRight then
inc(Position,OwnerBorderSpacing); OwnerBorderSpacing:=Max(Max(OwnerBorderSpacing,
ReferenceControl.BorderSpacing.GetSpace(OppositeAnchor[Kind])),
OwnerParent.ChildSizing.HorizontalSpacing);
if Kind=akLeft then begin
// anchor left of ReferenceControl and left of Owner
inc(Position,OwnerBorderSpacing);
end else begin
// anchor left of ReferenceControl and right of Owner
dec(Position,OwnerBorderSpacing);
end;
end else begin end else begin
// anchor left of ReferenceControl and right of Owner // anchor to top side of ReferenceControl
dec(Position,OwnerBorderSpacing); if ReferenceControl=OwnerParent then
Position:=0
else
Position:=ReferenceControl.Top;
if ReferenceControl=OwnerParent then
OwnerBorderSpacing:=Max(OwnerBorderSpacing,
OwnerParent.ChildSizing.TopBottomSpacing)
else if Kind=akBottom then
OwnerBorderSpacing:=Max(Max(OwnerBorderSpacing,
ReferenceControl.BorderSpacing.GetSpace(OppositeAnchor[Kind])),
OwnerParent.ChildSizing.VerticalSpacing);
if Kind=akTop then begin
// anchor top of ReferenceControl and top of Owner
inc(Position,OwnerBorderSpacing);
end else begin
// anchor top of ReferenceControl and bottom of Owner
dec(Position,OwnerBorderSpacing);
end;
end; end;
end else begin
// anchor to top side of ReferenceControl asrBottom: // asrBottom = asrRight
if ReferenceControl=OwnerParent then if Kind in [akLeft,akRight] then begin
Position:=0 // anchor to right side of ReferenceControl
else if ReferenceControl=OwnerParent then
Position:=ReferenceControl.Top; Position:=OwnerParent.GetLogicalClientRect.Right
if ReferenceControl=OwnerParent then else
OwnerBorderSpacing:=Max(OwnerBorderSpacing, Position:=ReferenceControl.Left+ReferenceControl.Width;
OwnerParent.ChildSizing.TopBottomSpacing) if ReferenceControl=OwnerParent then
else if Kind=akBottom then OwnerBorderSpacing:=Max(OwnerBorderSpacing,
OwnerBorderSpacing:=Max(Max(OwnerBorderSpacing, OwnerParent.ChildSizing.LeftRightSpacing)
ReferenceControl.BorderSpacing.GetSpace(OppositeAnchor[Kind])), else if Kind=akLeft then
OwnerParent.ChildSizing.VerticalSpacing); OwnerBorderSpacing:=Max(Max(OwnerBorderSpacing,
if Kind=akTop then begin ReferenceControl.BorderSpacing.GetSpace(OppositeAnchor[Kind])),
// anchor top of ReferenceControl and top of Owner OwnerParent.ChildSizing.HorizontalSpacing);
inc(Position,OwnerBorderSpacing); if Kind=akLeft then begin
// anchor right of ReferenceControl and left of Owner
inc(Position,OwnerBorderSpacing);
end else begin
// anchor right of ReferenceControl and right of Owner
dec(Position,OwnerBorderSpacing);
end;
end else begin end else begin
// anchor top of ReferenceControl and bottom of Owner // anchor to bottom side of ReferenceControl
dec(Position,OwnerBorderSpacing); if ReferenceControl=OwnerParent then
Position:=OwnerParent.GetLogicalClientRect.Bottom
else
Position:=ReferenceControl.Top+ReferenceControl.Height;
if ReferenceControl=OwnerParent then
OwnerBorderSpacing:=Max(OwnerBorderSpacing,
OwnerParent.ChildSizing.TopBottomSpacing)
else if Kind=akTop then
OwnerBorderSpacing:=Max(Max(OwnerBorderSpacing,
ReferenceControl.BorderSpacing.GetSpace(OppositeAnchor[Kind])),
OwnerParent.ChildSizing.VerticalSpacing);
if Kind=akTop then begin
// anchor bottom of ReferenceControl and top of Owner
inc(Position,OwnerBorderSpacing);
end else begin
// anchor bottom of ReferenceControl and bottom of Owner
dec(Position,OwnerBorderSpacing);
end;
end; end;
asrCenter:
if Kind in [akLeft,akRight] then begin
// center horizontally
if ReferenceControl=OwnerParent then
Position:=OwnerParent.ClientWidth div 2
else
Position:=ReferenceControl.Left+(ReferenceControl.Width div 2);
if Kind=akLeft then
dec(Position,FOwner.Width div 2)
else
inc(Position,FOwner.Width div 2);
end else begin
// center vertically
if ReferenceControl=OwnerParent then
Position:=OwnerParent.ClientHeight div 2
else
Position:=ReferenceControl.Top+(ReferenceControl.Height div 2);
if Kind=akTop then
dec(Position,FOwner.Height div 2)
else
inc(Position,FOwner.Height div 2);
end;
else
RaiseInvalidSide;
end; end;
asrBottom: // asrBottom = asrRight
if Kind in [akLeft,akRight] then begin
// anchor to right side of ReferenceControl
if ReferenceControl=OwnerParent then
Position:=OwnerParent.GetLogicalClientRect.Right
else
Position:=ReferenceControl.Left+ReferenceControl.Width;
if ReferenceControl=OwnerParent then
OwnerBorderSpacing:=Max(OwnerBorderSpacing,
OwnerParent.ChildSizing.LeftRightSpacing)
else if Kind=akLeft then
OwnerBorderSpacing:=Max(Max(OwnerBorderSpacing,
ReferenceControl.BorderSpacing.GetSpace(OppositeAnchor[Kind])),
OwnerParent.ChildSizing.HorizontalSpacing);
if Kind=akLeft then begin
// anchor right of ReferenceControl and left of Owner
inc(Position,OwnerBorderSpacing);
end else begin
// anchor right of ReferenceControl and right of Owner
dec(Position,OwnerBorderSpacing);
end;
end else begin
// anchor to bottom side of ReferenceControl
if ReferenceControl=OwnerParent then
Position:=OwnerParent.GetLogicalClientRect.Bottom
else
Position:=ReferenceControl.Top+ReferenceControl.Height;
if ReferenceControl=OwnerParent then
OwnerBorderSpacing:=Max(OwnerBorderSpacing,
OwnerParent.ChildSizing.TopBottomSpacing)
else if Kind=akTop then
OwnerBorderSpacing:=Max(Max(OwnerBorderSpacing,
ReferenceControl.BorderSpacing.GetSpace(OppositeAnchor[Kind])),
OwnerParent.ChildSizing.VerticalSpacing);
if Kind=akTop then begin
// anchor bottom of ReferenceControl and top of Owner
inc(Position,OwnerBorderSpacing);
end else begin
// anchor bottom of ReferenceControl and bottom of Owner
dec(Position,OwnerBorderSpacing);
end;
end;
asrCenter:
if Kind in [akLeft,akRight] then begin
// center horizontally
if ReferenceControl=OwnerParent then
Position:=OwnerParent.ClientWidth div 2
else
Position:=ReferenceControl.Left+(ReferenceControl.Width div 2);
if Kind=akLeft then
dec(Position,FOwner.Width div 2)
else
inc(Position,FOwner.Width div 2);
end else begin
// center vertically
if ReferenceControl=OwnerParent then
Position:=OwnerParent.ClientHeight div 2
else
Position:=ReferenceControl.Top+(ReferenceControl.Height div 2);
if Kind=akTop then
dec(Position,FOwner.Height div 2)
else
inc(Position,FOwner.Height div 2);
end;
else
RaiseInvalidSide;
end; end;
// side found // side found
exit; // continue to detect circles
end; end;
// ReferenceControl is not visible -> try next // try next
NextReferenceSide:=nil; NextReferenceSide:=nil;
if ReferenceControl<>OwnerParent then begin if CurReferenceControl<>OwnerParent then
if ReferenceSide=asrCenter then begin begin
if CurReferenceSide=asrCenter then
begin
// center can only be anchored to another centered anchor // center can only be anchored to another centered anchor
if Kind in [akLeft,akRight] then begin if Kind in [akLeft,akRight] then
if not GetNextCentered(ReferenceControl,akLeft,NextReferenceSide) begin
then GetNextCentered(ReferenceControl,akRight,NextReferenceSide); if not GetNextCentered(CurReferenceControl,akLeft,NextReferenceSide)
then GetNextCentered(CurReferenceControl,akRight,NextReferenceSide);
end else begin end else begin
if not GetNextCentered(ReferenceControl,akTop,NextReferenceSide) if not GetNextCentered(CurReferenceControl,akTop,NextReferenceSide)
then GetNextCentered(ReferenceControl,akBottom,NextReferenceSide); then GetNextCentered(CurReferenceControl,akBottom,NextReferenceSide);
end; end;
end else if (ReferenceSide=asrLeft) = (Kind in [akLeft,akTop]) then begin end else if (CurReferenceSide=asrLeft) = (Kind in [akLeft,akTop]) then
begin
// anchor parallel (e.g. a left side to a left side) // anchor parallel (e.g. a left side to a left side)
NextReferenceSide:=ReferenceControl.AnchorSide[Kind]; NextReferenceSide:=CurReferenceControl.AnchorSide[Kind];
end else begin end else begin
// anchor opposite (e.g. a left side to a right side) // anchor opposite (e.g. a left side to a right side)
NextReferenceSide:=ReferenceControl.AnchorSide[Kind]; NextReferenceSide:=CurReferenceControl.AnchorSide[Kind];
end; end;
end; end;
if (NextReferenceSide=nil) then begin if (NextReferenceSide=nil) then
begin
// no further side => anchor ok
//if CheckPosition(Owner) and (Kind=akRight) then //if CheckPosition(Owner) and (Kind=akRight) then
// DebugLn(['TAnchorSide.GetSidePosition not IsControlVisible ReferenceControl=',dbgsName(ReferenceControl)]); // DebugLn(['TAnchorSide.GetSidePosition not IsControlVisible ReferenceControl=',dbgsName(ReferenceControl)]);
ReferenceControl:=nil;
exit; exit;
end; end;
ReferenceControl:=NextReferenceSide.Control; CurReferenceControl:=NextReferenceSide.Control;
ReferenceSide:=NextReferenceSide.Side; CurReferenceSide:=NextReferenceSide.Side;
//DebugLn(['TAnchorSide.GetSidePosition ',DbgSName(FOwner),' ReferenceControl=',DbgSName(ReferenceControl),' Kind=',dbgs(Kind),' ReferenceSide=',dbgs(Kind,ReferenceSide)]); //DebugLn(['TAnchorSide.GetSidePosition ',DbgSName(FOwner),' ReferenceControl=',DbgSName(ReferenceControl),' Kind=',dbgs(Kind),' ReferenceSide=',dbgs(Kind,ReferenceSide)]);
end; end;
end; end;