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+[ilcfStartInStatement];
end;
// context in front of
StartPosOfVariable:=FindStartOfVariable(IdentStartPos);
if StartPosOfVariable>0 then begin

View File

@ -3269,41 +3269,52 @@ var
MaxChainLength: LongInt;
OwnerBorderSpacing: LongInt;
OwnerParent: TWinControl;
Found: Boolean;
CurReferenceControl: TControl;
CurReferenceSide: TAnchorSideReference;
begin
ReferenceControl:=Control;
ReferenceControl:=nil;
ReferenceSide:=Side;
Position:=0;
OwnerParent:=FOwner.Parent;
if OwnerParent=nil then begin
// AnchorSide is only between siblings or its direct parent allowed
//if CheckPosition(Owner) then DebugLn(['TAnchorSide.GetSidePosition OwnerParent=nil']);
ReferenceControl:=nil;
exit;
end;
ChainLength:=0;
MaxChainLength:=OwnerParent.ControlCount;
while ReferenceControl<>nil do begin
Found:=false;
CurReferenceControl:=Control;
CurReferenceSide:=Side;
while CurReferenceControl<>nil do begin
// check for circles
inc(ChainLength);
if ChainLength>MaxChainLength then begin
// 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;
exit;
end;
// check if ReferenceControl is valid
if (ReferenceControl.Parent<>OwnerParent)
and (ReferenceControl<>OwnerParent) then begin
if (CurReferenceControl.Parent<>OwnerParent)
and (CurReferenceControl<>OwnerParent) then begin
// not a sibling and not the parent -> invalid AnchorSide
//if CheckPosition(Owner) then DebugLn(['TAnchorSide.GetSidePosition invalid AnchorSide ',dbgsName(ReferenceControl)]);
ReferenceControl:=nil;
exit;
end;
if ReferenceControl.IsControlVisible then begin
if CurReferenceControl.IsControlVisible then begin
// ReferenceControl is visible
if not Found then begin
Found:=true;
ReferenceControl:=CurReferenceControl;
ReferenceSide:=CurReferenceSide;
// -> calculate Position
OwnerBorderSpacing:=FOwner.BorderSpacing.GetSpace(Kind);
//if CheckPosition(Owner) then DebugLn(['TAnchorSide.GetSidePosition ',dbgsName(Owner),' ReferenceControl=',dbgsName(ReferenceControl),' ',dbgs(ReferenceControl.BoundsRect),' OwnerBorderSpacing=',OwnerBorderSpacing,' Kind=',dbgs(Kind),' ReferenceSide=',dbgs(Kind,ReferenceSide)]);
@ -3421,38 +3432,44 @@ begin
else
RaiseInvalidSide;
end;
end;
// side found
exit;
// continue to detect circles
end;
// ReferenceControl is not visible -> try next
// try next
NextReferenceSide:=nil;
if ReferenceControl<>OwnerParent then begin
if ReferenceSide=asrCenter then begin
if CurReferenceControl<>OwnerParent then
begin
if CurReferenceSide=asrCenter then
begin
// center can only be anchored to another centered anchor
if Kind in [akLeft,akRight] then begin
if not GetNextCentered(ReferenceControl,akLeft,NextReferenceSide)
then GetNextCentered(ReferenceControl,akRight,NextReferenceSide);
if Kind in [akLeft,akRight] then
begin
if not GetNextCentered(CurReferenceControl,akLeft,NextReferenceSide)
then GetNextCentered(CurReferenceControl,akRight,NextReferenceSide);
end else begin
if not GetNextCentered(ReferenceControl,akTop,NextReferenceSide)
then GetNextCentered(ReferenceControl,akBottom,NextReferenceSide);
if not GetNextCentered(CurReferenceControl,akTop,NextReferenceSide)
then GetNextCentered(CurReferenceControl,akBottom,NextReferenceSide);
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)
NextReferenceSide:=ReferenceControl.AnchorSide[Kind];
NextReferenceSide:=CurReferenceControl.AnchorSide[Kind];
end else begin
// anchor opposite (e.g. a left side to a right side)
NextReferenceSide:=ReferenceControl.AnchorSide[Kind];
NextReferenceSide:=CurReferenceControl.AnchorSide[Kind];
end;
end;
if (NextReferenceSide=nil) then begin
if (NextReferenceSide=nil) then
begin
// no further side => anchor ok
//if CheckPosition(Owner) and (Kind=akRight) then
// DebugLn(['TAnchorSide.GetSidePosition not IsControlVisible ReferenceControl=',dbgsName(ReferenceControl)]);
ReferenceControl:=nil;
exit;
end;
ReferenceControl:=NextReferenceSide.Control;
ReferenceSide:=NextReferenceSide.Side;
CurReferenceControl:=NextReferenceSide.Control;
CurReferenceSide:=NextReferenceSide.Side;
//DebugLn(['TAnchorSide.GetSidePosition ',DbgSName(FOwner),' ReferenceControl=',DbgSName(ReferenceControl),' Kind=',dbgs(Kind),' ReferenceSide=',dbgs(Kind,ReferenceSide)]);
end;
end;