MG: fixed moving non visual components

git-svn-id: trunk@1760 -
This commit is contained in:
lazarus 2002-06-21 19:21:34 +00:00
parent 7bdd276204
commit d5164583f5
2 changed files with 42 additions and 16 deletions

View File

@ -695,8 +695,10 @@ begin
NewTop:=FTop;
NewRight:=FLeft+FWidth;
NewBottom:=FTop+FHeight;
writeln('[TControlSelection.DoApplyUserBounds] S Old=',FOldLeft,',',FOldTop,',',FOldWidth,',',FOldHeight,
' User=',FLeft,',',FTop,',',FWidth,',',FHeight);
{$IFDEF VerboseDesigner}
writeln('[TControlSelection.DoApplyUserBounds] S Old=',FOldLeft,',',FOldTop,',',FOldWidth,',',FOldHeight,
' User=',FLeft,',',FTop,',',FWidth,',',FHeight);
{$ENDIF}
Items[0].SetBounds(
Min(NewLeft,NewRight),
Min(NewTop,NewBottom),
@ -705,8 +707,10 @@ writeln('[TControlSelection.DoApplyUserBounds] S Old=',FOldLeft,',',FOldTop,',',
);
end else if Count>1 then begin
// multi selection
writeln('[TControlSelection.DoApplyUserBounds] M Old=',FOldLeft,',',FOldTop,',',FOldWidth,',',FOldHeight,
' User=',FLeft,',',FTop,',',FWidth,',',FHeight);
{$IFDEF VerboseDesigner}
writeln('[TControlSelection.DoApplyUserBounds] M Old=',FOldLeft,',',FOldTop,',',FOldWidth,',',FOldHeight,
' User=',FLeft,',',FTop,',',FWidth,',',FHeight);
{$ENDIF}
if (FOldWidth<>0) and (FOldHeight<>0) then begin
for i:=0 to Count-1 do begin
@ -727,8 +731,10 @@ writeln('[TControlSelection.DoApplyUserBounds] M Old=',FOldLeft,',',FOldTop,',',
end;
if NewHeight<1 then NewHeight:=1;
Items[i].SetBounds(NewLeft,NewTop,NewWidth,NewHeight);
writeln(' i=',i,
' ',Items[i].Left,',',Items[i].Top,',',Items[i].Width,',',Items[i].Height);
{$IFDEF VerboseDesigner}
writeln(' i=',i,
' ',Items[i].Left,',',Items[i].Top,',',Items[i].Width,',',Items[i].Height);
{$ENDIF}
end;
end;
end;
@ -1286,13 +1292,17 @@ procedure TControlSelection.MoveSelectionWithSnapping(TotalDX, TotalDY: integer
);
begin
if (Count=0) or (IsResizing) then exit;
{$IFDEF VerboseDesigner}
writeln('[TControlSelection.MoveSelectionWithSnapping] A ',
TotalDX,',',TotalDY);
{$ENDIF}
BeginResizing;
FLeft:=FindNearestSnapLeft(FOldLeft+TotalDX,FWidth);
FTop:=FindNearestSnapTop(FOldTop+TotalDY,FHeight);
{$IFDEF VerboseDesigner}
writeln('[TControlSelection.MoveSelectionWithSnapping] B ',
FLeft,',',FTop,',',FWidth,',',FHeight);
{$ENDIF}
EndResizing(true);
end;
@ -1304,7 +1314,9 @@ var
begin
if (Count=0) or (IsResizing) then exit;
if (dx=0) and (dy=0) then exit;
{$IFDEF VerboseDesigner}
writeln('[TControlSelection.SizeSelection] A ',dx,',',dy);
{$ENDIF}
BeginResizing;
if FActiveGrabber<>nil then
GrabberPos:=FActiveGrabber.Positions
@ -1346,8 +1358,10 @@ function TControlSelection.GrabberAtPos(X,Y:integer):TGrabber;
var g:TGrabIndex;
begin
if FControls.Count>0 then begin
{$IFDEF VerboseDesigner}
writeln('[TControlSelection.GrabberAtPos] ',x,',',y,' '
,FGrabbers[4].Left,',',FGrabbers[4].Top);
{$ENDIF}
for g:=Low(TGrabIndex) to High(TGrabIndex) do
if (FGrabbers[g].Left<=x) and (FGrabbers[g].Top<=y)
and (FGrabbers[g].Left+FGrabbers[g].Width>x)

View File

@ -143,6 +143,7 @@ type
procedure ValidateRename(AComponent: TComponent;
const CurName, NewName: string); override;
Procedure SelectOnlyThisComponent(AComponent:TComponent);
function NonVisualComponentLeftTop(AComponent: TComponent): TPoint;
function NonVisualComponentAtPos(x,y: integer): TComponent;
procedure DrawNonVisualComponents(DC: HDC);
@ -260,6 +261,14 @@ begin
ControlSelection.EndUpdate;
end;
function TDesigner.NonVisualComponentLeftTop(AComponent: TComponent): TPoint;
begin
Result.X:=Min(LongRec(AComponent.DesignInfo).Lo,
Form.ClientWidth-NonVisualCompWidth);
Result.Y:=Min(LongRec(AComponent.DesignInfo).Hi,
Form.ClientHeight-NonVisualCompWidth);
end;
procedure TDesigner.InvalidateWithParent(AComponent: TComponent);
begin
{$IFDEF VerboseDesigner}
@ -634,6 +643,7 @@ begin
ControlSelection.SizeSelection(
LastMouseMovePos.X-OldMouseMovePos.X,
LastMouseMovePos.Y-OldMouseMovePos.Y);
FCustomForm.Invalidate;
if Assigned(OnModified) then OnModified(Self);
end else begin
if (not ComponentIsTopLvl(MouseDownComponent))
@ -648,6 +658,7 @@ begin
ControlSelection.MoveSelectionWithSnapping(
LastMouseMovePos.X-MouseDownPos.X,LastMouseMovePos.Y-MouseDownPos.Y);
if Assigned(OnModified) then OnModified(Self);
FCustomForm.Invalidate;
end
else
begin
@ -902,7 +913,7 @@ procedure TDesigner.DrawNonVisualComponents(DC: HDC);
var
i, j, ItemLeft, ItemTop, ItemRight, ItemBottom,
IconWidth, IconHeight: integer;
FormOrigin, DCOrigin, Diff: TPoint;
FormOrigin, DCOrigin, Diff, ItemLeftTop: TPoint;
SaveIndex: HDC;
IconRect: TRect;
IconCanvas: TCanvas;
@ -916,8 +927,9 @@ begin
for i:=0 to FCustomForm.ComponentCount-1 do begin
if not (FCustomForm.Components[i] is TControl) then begin
// non-visual component
ItemLeft:=LongRec(FCustomForm.Components[i].DesignInfo).Lo+Diff.X;
ItemTop:=LongRec(FCustomForm.Components[i].DesignInfo).Hi+Diff.Y;
ItemLeftTop:=NonVisualComponentLeftTop(FCustomForm.Components[i]);
ItemLeft:=ItemLeftTop.X+Diff.X;
ItemTop:=ItemLeftTop.Y+Diff.Y;
ItemRight:=ItemLeft+NonVisualCompWidth;
ItemBottom:=ItemTop+NonVisualCompWidth;
with FCustomForm.Canvas do begin
@ -962,17 +974,17 @@ begin
end;
function TDesigner.NonVisualComponentAtPos(x,y: integer): TComponent;
var i, ALeft, ATop: integer;
var i: integer;
LeftTop: TPoint;
begin
for i:=FCustomForm.ComponentCount-1 downto 0 do begin
Result:=FCustomForm.Components[i];
if (Result is TControl)=false then begin
if not (Result is TControl) then begin
with Result do begin
ALeft:=LongRec(DesignInfo).Lo;
ATop:=LongRec(DesignInfo).Hi;
if (ALeft<=x) and (ATop<=y)
and (ALeft+NonVisualCompWidth>x)
and (ATop+NonVisualCompWidth>y) then
LeftTop:=NonVisualComponentLeftTop(Result);
if (LeftTop.x<=x) and (LeftTop.y<=y)
and (LeftTop.x+NonVisualCompWidth>x)
and (LeftTop.y+NonVisualCompWidth>y) then
exit;
end;
end;