IDE: anchor editor: warn for circles

git-svn-id: trunk@26219 -
This commit is contained in:
mattias 2010-06-20 22:00:27 +00:00
parent 061e3724eb
commit 60adf0cc86
3 changed files with 90 additions and 38 deletions

View File

@ -406,36 +406,41 @@ var
NewValue: String; NewValue: String;
UseNeighbours: boolean; UseNeighbours: boolean;
OldPositions,OldPositions2: array of Integer; OldPositions,OldPositions2: array of Integer;
function NeighbourPosition(c: tcontrol):Integer;
begin function NeighbourPosition(c: tcontrol):Integer;
case CurNeighbour of begin
akTop: result:=c.top; case CurNeighbour of
akLeft: result:=c.Left; akTop: result:=c.top;
akRight: result:=c.left+c.Width; akLeft: result:=c.Left;
akBottom: result:=c.Top+c.Height; akRight: result:=c.left+c.Width;
end; akBottom: result:=c.Top+c.Height;
end; end;
end;
function FindNeighbour(i:longint):TControl;
var firstNeighbour,lastNeighbour,cur,resultId: Integer; function FindNeighbour(i:longint):TControl;
begin var firstNeighbour,lastNeighbour,cur,resultId: Integer;
if i=0 then exit(nil); begin
firstNeighbour:=i-1; if i=0 then exit(nil);
while (firstNeighbour>=0) and (OldPositions[firstNeighbour] = OldPositions[i]) do firstNeighbour:=i-1;
dec(firstNeighbour); while (firstNeighbour>=0) and (OldPositions[firstNeighbour] = OldPositions[i]) do
if firstNeighbour=-1 then exit(nil); //there is no real neighbour at this side dec(firstNeighbour);
lastNeighbour:=firstNeighbour; if firstNeighbour=-1 then exit(nil); //there is no real neighbour at this side
while (lastNeighbour>=0) and (OldPositions[lastNeighbour] = OldPositions[firstNeighbour]) do lastNeighbour:=firstNeighbour;
dec(lastNeighbour); while (lastNeighbour>=0) and (OldPositions[lastNeighbour] = OldPositions[firstNeighbour]) do
inc(lastNeighbour); dec(lastNeighbour);
//take nearest inc(lastNeighbour);
resultId:=lastNeighbour; //take nearest
for cur:=lastNeighbour+1 to firstNeighbour do resultId:=lastNeighbour;
if abs(OldPositions2[cur]-OldPositions2[i]) < abs(OldPositions2[resultId]-OldPositions2[i]) then for cur:=lastNeighbour+1 to firstNeighbour do
resultid:=cur; if abs(OldPositions2[cur]-OldPositions2[i]) < abs(OldPositions2[resultId]-OldPositions2[i]) then
result:=tcontrol(SelectedControls[resultId]); resultid:=cur;
result:=tcontrol(SelectedControls[resultId]);
end; end;
var
ReferenceControl: TControl;
ReferenceSide: TAnchorSideReference;
CheckPosition: Integer;
begin begin
//debugln('TAnchorDesigner.SiblingComboBoxChange ',DbgSName(Sender),' ',TComboBox(Sender).Text); //debugln('TAnchorDesigner.SiblingComboBoxChange ',DbgSName(Sender),' ',TComboBox(Sender).Text);
if FUpdating or (Values=nil) then exit; if FUpdating or (Values=nil) then exit;
@ -476,18 +481,18 @@ begin
begin begin
//todo: copy the list if it is needed unsorted somewhere else //todo: copy the list if it is needed unsorted somewhere else
case CurNeighbour of //todo: use just one sorting function case CurNeighbour of //todo: use just one sorting function
akTop: SelectedControls.Sort(@compareControlTop); akTop: SelectedControls.Sort(@compareControlTop);
akLeft: SelectedControls.Sort(@compareControlLeft); akLeft: SelectedControls.Sort(@compareControlLeft);
akRight: SelectedControls.Sort(@compareControlRight); akRight: SelectedControls.Sort(@compareControlRight);
akBottom: SelectedControls.Sort(@compareControlBottom); akBottom: SelectedControls.Sort(@compareControlBottom);
end; end;
setlength(OldPositions,SelectedControls.Count); setlength(OldPositions,SelectedControls.Count);
setlength(OldPositions2,SelectedControls.Count); setlength(OldPositions2,SelectedControls.Count);
for i:=0 to SelectedControls.Count-1 do begin for i:=0 to SelectedControls.Count-1 do begin
OldPositions[i]:=NeighbourPosition(tcontrol(SelectedControls[i])); OldPositions[i]:=NeighbourPosition(TControl(SelectedControls[i]));
case CurNeighbour of case CurNeighbour of
akLeft,akRight: OldPositions2[i]:=tcontrol(SelectedControls[i]).top; akLeft,akRight: OldPositions2[i]:=TControl(SelectedControls[i]).top;
akTop,akBottom: OldPositions2[i]:=tcontrol(SelectedControls[i]).Left; akTop,akBottom: OldPositions2[i]:=TControl(SelectedControls[i]).Left;
end; end;
end; end;
end end
@ -496,6 +501,27 @@ begin
if NewSibling=nil then exit; if NewSibling=nil then exit;
end; end;
end; end;
// check
for i:=0 to SelectedControls.Count-1 do begin
CurControl:=TControl(SelectedControls[i]);
if UseNeighbours then begin
NewSibling:=findNeighbour(i);
if (NewSibling=nil) and (i<>0) then continue;
end;
if not CurControl.AnchorSide[Kind].CheckSidePosition(NewSibling,
CurControl.AnchorSide[Kind].Side,
ReferenceControl,ReferenceSide,CheckPosition)
then begin
if MessageDlg(lisCCOWarningCaption,
lisThisWillCreateACircle, mtWarning, [mbIgnore, mbCancel], 0)<>
mrIgnore
then begin
Refresh(false);
exit;
end;
end;
end;
// commit
for i:=0 to SelectedControls.Count-1 do begin for i:=0 to SelectedControls.Count-1 do begin
CurControl:=TControl(SelectedControls[i]); CurControl:=TControl(SelectedControls[i]);
if UseNeighbours then begin if UseNeighbours then begin
@ -526,6 +552,9 @@ var
SelectedControls: TList; SelectedControls: TList;
i: Integer; i: Integer;
CurControl: TControl; CurControl: TControl;
ReferenceControl: TControl;
ReferenceSide: TAnchorSideReference;
CheckPosition: Integer;
begin begin
//debugln('TAnchorDesigner.ReferenceSideButtonClicked ',DbgSName(Sender),' ',dbgs(TSpeedButton(Sender).Down)); //debugln('TAnchorDesigner.ReferenceSideButtonClicked ',DbgSName(Sender),' ',dbgs(TSpeedButton(Sender).Down));
if FUpdating or (Values=nil) then exit; if FUpdating or (Values=nil) then exit;
@ -585,6 +614,23 @@ begin
// user changed a sibling // user changed a sibling
SelectedControls:=GetSelectedControls; SelectedControls:=GetSelectedControls;
if SelectedControls=nil then exit; if SelectedControls=nil then exit;
// check
for i:=0 to SelectedControls.Count-1 do begin
CurControl:=TControl(SelectedControls[i]);
if not CurControl.AnchorSide[Kind].CheckSidePosition(
CurControl.AnchorSide[Kind].Control,Side,
ReferenceControl,ReferenceSide,CheckPosition)
then begin
if MessageDlg(lisCCOWarningCaption,
lisThisWillCreateACircle, mtWarning, [mbIgnore, mbCancel], 0)<>
mrIgnore
then begin
Refresh(false);
exit;
end;
end;
end;
// commit
for i:=0 to SelectedControls.Count-1 do begin for i:=0 to SelectedControls.Count-1 do begin
CurControl:=TControl(SelectedControls[i]); CurControl:=TControl(SelectedControls[i]);
CurControl.AnchorSide[Kind].Side:=Side; CurControl.AnchorSide[Kind].Side:=Side;
@ -694,7 +740,7 @@ begin
//debugln('TAnchorDesigner.Refresh A '); //debugln('TAnchorDesigner.Refresh A ');
if not Force then begin if not Force then begin
// check if uddate is needed // check if uddate is needed
if not Visible then exit; if not IsVisible then exit;
end; end;
if FUpdating then exit; if FUpdating then exit;
FUpdating:=true; FUpdating:=true;

View File

@ -4274,6 +4274,7 @@ resourcestring
lisLeftGroupBoxCaption = 'Left anchoring'; lisLeftGroupBoxCaption = 'Left anchoring';
lisBottomGroupBoxCaption = 'Bottom anchoring'; lisBottomGroupBoxCaption = 'Bottom anchoring';
lisUnableToSetAnchorSideControl = 'Unable to set AnchorSide Control'; lisUnableToSetAnchorSideControl = 'Unable to set AnchorSide Control';
lisThisWillCreateACircle = 'This will create a circle.';
lisAnchorEditorNoControlSelected = 'Anchor Editor - no control selected'; lisAnchorEditorNoControlSelected = 'Anchor Editor - no control selected';
lisAnchorsOfSelectedControls = 'Anchors of selected controls'; lisAnchorsOfSelectedControls = 'Anchors of selected controls';
lisDebugOptionsFrmAdditionalSearchPath = 'Additional search path'; lisDebugOptionsFrmAdditionalSearchPath = 'Additional search path';

View File

@ -3675,8 +3675,13 @@ begin
// DebugLn(['TAnchorSide.GetSidePosition Success ',DbgSName(Owner),' ReferenceControl=',dbgsName(ReferenceControl),' CurReferenceControl=',DbgSName(CurReferenceControl),' CurReferenceSide=',dbgs(Kind,CurReferenceSide)]); // DebugLn(['TAnchorSide.GetSidePosition Success ',DbgSName(Owner),' ReferenceControl=',dbgsName(ReferenceControl),' CurReferenceControl=',DbgSName(CurReferenceControl),' CurReferenceSide=',dbgs(Kind,CurReferenceSide)]);
exit(true); exit(true);
end; end;
CurReferenceControl:=NextReferenceSide.Control; if NextReferenceSide=Self then begin
CurReferenceSide:=NextReferenceSide.Side; CurReferenceControl:=NewControl;
CurReferenceSide:=NewSide;
end else begin
CurReferenceControl:=NextReferenceSide.Control;
CurReferenceSide:=NextReferenceSide.Side;
end;
//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;