designer: disable snapping when Alt key is pressed (issue #0001974)

git-svn-id: trunk@26910 -
This commit is contained in:
paul 2010-07-30 08:17:49 +00:00
parent 4075c56ad3
commit 41160c3a52
2 changed files with 97 additions and 69 deletions

View File

@ -414,8 +414,8 @@ type
procedure UpdateBounds; procedure UpdateBounds;
procedure RestoreBounds; procedure RestoreBounds;
procedure MoveSelection(dx, dy: integer); function MoveSelection(dx, dy: integer; TotalDeltas: Boolean): Boolean;
function MoveSelectionWithSnapping(TotalDX, TotalDY: integer): boolean; function MoveSelectionWithSnapping(TotalDx, TotalDy: integer): Boolean;
procedure SizeSelection(dx, dy: integer); procedure SizeSelection(dx, dy: integer);
procedure SetBounds(NewLeft,NewTop,NewWidth,NewHeight: integer); procedure SetBounds(NewLeft,NewTop,NewWidth,NewHeight: integer);
procedure AlignComponents(HorizAlignment,VertAlignment:TComponentAlignment); procedure AlignComponents(HorizAlignment,VertAlignment:TComponentAlignment);
@ -1678,19 +1678,20 @@ begin
Result:=ABottom; Result:=ABottom;
end; end;
function TControlSelection.SnapGrabberMousePos(const CurMousePos: TPoint function TControlSelection.SnapGrabberMousePos(const CurMousePos: TPoint): TPoint;
): TPoint;
begin begin
Result:=CurMousePos; Result := CurMousePos;
if (not EnvironmentOptions.SnapToGrid) or (ActiveGrabber=nil) then exit; if (not EnvironmentOptions.SnapToGrid) or (ActiveGrabber = nil) then exit;
if gpLeft in ActiveGrabber.Positions then if gpLeft in ActiveGrabber.Positions then
Result.X:=FindNearestSnapLeft(Result.X) Result.X := FindNearestSnapLeft(Result.X)
else if gpRight in ActiveGrabber.Positions then else
Result.X:=FindNearestSnapRight(Result.X); if gpRight in ActiveGrabber.Positions then
Result.X := FindNearestSnapRight(Result.X);
if gpTop in ActiveGrabber.Positions then if gpTop in ActiveGrabber.Positions then
Result.Y:=FindNearestSnapTop(Result.Y) Result.Y := FindNearestSnapTop(Result.Y)
else if gpBottom in ActiveGrabber.Positions then else
Result.Y:=FindNearestSnapBottom(Result.Y); if gpBottom in ActiveGrabber.Positions then
Result.Y := FindNearestSnapBottom(Result.Y);
end; end;
function TControlSelection.GetLeftGuideLine(var ALine: TRect): boolean; function TControlSelection.GetLeftGuideLine(var ALine: TRect): boolean;
@ -2169,44 +2170,60 @@ begin
Result:=(Count=1) and (Items[0].Persistent=APersistent); Result:=(Count=1) and (Items[0].Persistent=APersistent);
end; end;
procedure TControlSelection.MoveSelection(dx, dy: integer); function TControlSelection.MoveSelection(dx, dy: integer; TotalDeltas: Boolean): Boolean;
begin
if (Count=0) or (IsResizing) then exit;
if (dx=0) and (dy=0) then exit;
//DebugLn('[TControlSelection.MoveSelection] A %d,%d',[dx,dy]);
BeginResizing;
//DebugLn('[TControlSelection.MoveSelection] B %d',[FResizeLockCount]);
inc(FLeft,dx);
inc(FTop,dy);
EndResizing(true);
end;
function TControlSelection.MoveSelectionWithSnapping(TotalDX, TotalDY: integer
): boolean;
var var
NewLeft, NewTop: integer; NewLeft, NewTop: integer;
begin begin
Result:=false; Result := False;
if (Count=0) or (IsResizing) then exit; if (Count = 0) or IsResizing then Exit;
NewLeft:=FindNearestSnapLeft(FOldLeft+TotalDX,FWidth); //DebugLn('[TControlSelection.MoveSelection] A %d,%d',[dx,dy]);
NewTop:=FindNearestSnapTop(FOldTop+TotalDY,FHeight); //DebugLn('[TControlSelection.MoveSelection] B %d',[FResizeLockCount]);
if TotalDeltas then
begin
NewLeft := FOldLeft + dx;
NewTop := FOldTop + dy;
end
else
begin
NewLeft := FLeft + dx;
NewTop := FTop + dy
end;
if (NewLeft <> FLeft) or (NewTop <> FTop) then
begin
Result := True;
BeginResizing;
FLeft := NewLeft;
FTop := NewTop;
EndResizing(True);
end;
end;
function TControlSelection.MoveSelectionWithSnapping(TotalDx, TotalDy: integer): boolean;
var
NewLeft, NewTop: integer;
begin
Result := False;
if (Count = 0) or IsResizing then Exit;
NewLeft := FindNearestSnapLeft(FOldLeft + TotalDx, FWidth);
NewTop := FindNearestSnapTop(FOldTop + TotalDy, FHeight);
{$IFDEF VerboseDesigner} {$IFDEF VerboseDesigner}
DebugLn('[TControlSelection.MoveSelectionWithSnapping] A ', DebugLn('[TControlSelection.MoveSelectionWithSnapping] A ',
'TotalD='+dbgs(TotalDX)+','+dbgs(TotalDY), 'TotalD='+dbgs(TotalDx)+','+dbgs(TotalDy),
' CurBounds='+dbgs(FLeft)+','+dbgs(FTop)+','+dbgs(FWidth)+','+dbgs(FHeight), ' CurBounds='+dbgs(FLeft)+','+dbgs(FTop)+','+dbgs(FWidth)+','+dbgs(FHeight),
' OldBounds='+dbgs(FOldLeft)+','+dbgs(FOldTop)+','+dbgs(FOldWidth)+','+dbgs(FOldHeight) ' OldBounds='+dbgs(FOldLeft)+','+dbgs(FOldTop)+','+dbgs(FOldWidth)+','+dbgs(FOldHeight)
+' NewPos='+dbgs(NewLeft)+','+dbgs(NewTop)); +' NewPos='+dbgs(NewLeft)+','+dbgs(NewTop));
{$ENDIF} {$ENDIF}
if (NewLeft<>FLeft) or (NewTop<>FTop) then begin if (NewLeft <> FLeft) or (NewTop <> FTop) then
Result:=true; begin
Result := True;
BeginResizing; BeginResizing;
FLeft:=NewLeft; FLeft := NewLeft;
FTop:=NewTop; FTop := NewTop;
{$IFDEF VerboseDesigner} {$IFDEF VerboseDesigner}
DebugLn('[TControlSelection.MoveSelectionWithSnapping] B ', DebugLn('[TControlSelection.MoveSelectionWithSnapping] B ',
' Bounds='+dbgs(FLeft)+','+dbgs(FTop)+','+dbgs(FWidth)+','+dbgs(FHeight)); ' Bounds='+dbgs(FLeft)+','+dbgs(FTop)+','+dbgs(FWidth)+','+dbgs(FHeight));
{$ENDIF} {$ENDIF}
EndResizing(true); EndResizing(True);
end; end;
end; end;

View File

@ -670,7 +670,7 @@ begin
{$ENDIF} {$ENDIF}
if (ControlSelection.SelectionForm<>Form) if (ControlSelection.SelectionForm<>Form)
or ControlSelection.LookupRootSelected then exit; or ControlSelection.LookupRootSelected then exit;
ControlSelection.MoveSelection(DiffX, DiffY); ControlSelection.MoveSelection(DiffX, DiffY, False);
Modified; Modified;
end; end;
@ -1600,61 +1600,64 @@ procedure TDesigner.GetMouseMsgShift(TheMessage: TLMMouse;
begin begin
Shift := []; Shift := [];
if (TheMessage.Keys and MK_Shift) = MK_Shift then if (TheMessage.Keys and MK_Shift) = MK_Shift then
Include(Shift,ssShift); Include(Shift, ssShift);
if (TheMessage.Keys and MK_Control) = MK_Control then if (TheMessage.Keys and MK_Control) = MK_Control then
Include(Shift,ssCtrl); Include(Shift, ssCtrl);
if GetKeyState(VK_MENU) < 0 then Include(Shift, ssAlt);
if (GetKeyState(VK_LWIN) < 0) or (GetKeyState(VK_RWIN) < 0) then Include(Shift, ssMeta);
case TheMessage.Msg of case TheMessage.Msg of
LM_LBUTTONUP,LM_LBUTTONDBLCLK,LM_LBUTTONTRIPLECLK,LM_LBUTTONQUADCLK: LM_LBUTTONUP,LM_LBUTTONDBLCLK,LM_LBUTTONTRIPLECLK,LM_LBUTTONQUADCLK:
begin begin
Include(Shift,ssLeft); Include(Shift, ssLeft);
Button:=mbLeft; Button := mbLeft;
end; end;
LM_MBUTTONUP,LM_MBUTTONDBLCLK,LM_MBUTTONTRIPLECLK,LM_MBUTTONQUADCLK: LM_MBUTTONUP,LM_MBUTTONDBLCLK,LM_MBUTTONTRIPLECLK,LM_MBUTTONQUADCLK:
begin begin
Include(Shift,ssMiddle); Include(Shift, ssMiddle);
Button:=mbMiddle; Button := mbMiddle;
end; end;
LM_RBUTTONUP,LM_RBUTTONDBLCLK,LM_RBUTTONTRIPLECLK,LM_RBUTTONQUADCLK: LM_RBUTTONUP,LM_RBUTTONDBLCLK,LM_RBUTTONTRIPLECLK,LM_RBUTTONQUADCLK:
begin begin
Include(Shift,ssRight); Include(Shift, ssRight);
Button:=mbRight; Button := mbRight;
end; end;
else else
if (TheMessage.Keys and MK_MButton) <> 0 then if (TheMessage.Keys and MK_MButton) <> 0 then
begin begin
Include(Shift,ssMiddle); Include(Shift, ssMiddle);
Button:=mbMiddle; Button := mbMiddle;
end; end;
if (TheMessage.Keys and MK_RButton) <> 0 then if (TheMessage.Keys and MK_RButton) <> 0 then
begin begin
Include(Shift,ssRight); Include(Shift, ssRight);
Button:=mbRight; Button := mbRight;
end; end;
if (TheMessage.Keys and MK_LButton) <> 0 then if (TheMessage.Keys and MK_LButton) <> 0 then
begin begin
Include(Shift,ssLeft); Include(Shift, ssLeft);
Button:=mbLeft; Button := mbLeft;
end; end;
if (TheMessage.Keys and MK_XBUTTON1) <> 0 then if (TheMessage.Keys and MK_XBUTTON1) <> 0 then
begin begin
Include(Shift,ssExtra1); Include(Shift, ssExtra1);
Button:=mbExtra1; Button := mbExtra1;
end; end;
if (TheMessage.Keys and MK_XBUTTON2) <> 0 then if (TheMessage.Keys and MK_XBUTTON2) <> 0 then
begin begin
Include(Shift,ssExtra2); Include(Shift, ssExtra2);
Button:=mbExtra2; Button := mbExtra2;
end; end;
end; end;
case TheMessage.Msg of case TheMessage.Msg of
LM_LBUTTONDBLCLK,LM_MBUTTONDBLCLK,LM_RBUTTONDBLCLK,LM_XBUTTONDBLCLK: LM_LBUTTONDBLCLK,LM_MBUTTONDBLCLK,LM_RBUTTONDBLCLK,LM_XBUTTONDBLCLK:
Include(Shift,ssDouble); Include(Shift, ssDouble);
LM_LBUTTONTRIPLECLK,LM_MBUTTONTRIPLECLK,LM_RBUTTONTRIPLECLK,LM_XBUTTONTRIPLECLK: LM_LBUTTONTRIPLECLK,LM_MBUTTONTRIPLECLK,LM_RBUTTONTRIPLECLK,LM_XBUTTONTRIPLECLK:
Include(Shift,ssTriple); Include(Shift, ssTriple);
LM_LBUTTONQUADCLK,LM_MBUTTONQUADCLK,LM_RBUTTONQUADCLK,LM_XBUTTONQUADCLK: LM_LBUTTONQUADCLK,LM_MBUTTONQUADCLK,LM_RBUTTONQUADCLK,LM_XBUTTONQUADCLK:
Include(Shift,ssQuad); Include(Shift, ssQuad);
end; end;
end; end;
@ -2251,9 +2254,9 @@ begin
begin begin
if Grabber = nil then if Grabber = nil then
ACursor := crDefault ACursor := crDefault
else begin else
ACursor := Grabber.Cursor; ACursor := Grabber.Cursor;
end;
if ACursor <> LastFormCursor then if ACursor <> LastFormCursor then
begin begin
LastFormCursor := ACursor; LastFormCursor := ACursor;
@ -2276,8 +2279,17 @@ begin
ControlSelection.SaveBounds; ControlSelection.SaveBounds;
Include(FFlags, dfHasSized); Include(FFlags, dfHasSized);
end; end;
OldSnappedMousePos := ControlSelection.SnapGrabberMousePos(OldMouseMovePos); // skip snapping when Alt is pressed
CurSnappedMousePos:= ControlSelection.SnapGrabberMousePos(LastMouseMovePos); if not (ssAlt in Shift) then
begin
OldSnappedMousePos := ControlSelection.SnapGrabberMousePos(OldMouseMovePos);
CurSnappedMousePos := ControlSelection.SnapGrabberMousePos(LastMouseMovePos);
end
else
begin
OldSnappedMousePos := OldMouseMovePos;
CurSnappedMousePos := LastMouseMovePos;
end;
ControlSelection.SizeSelection( ControlSelection.SizeSelection(
CurSnappedMousePos.X - OldSnappedMousePos.X, CurSnappedMousePos.X - OldSnappedMousePos.X,
CurSnappedMousePos.Y - OldSnappedMousePos.Y); CurSnappedMousePos.Y - OldSnappedMousePos.Y);
@ -2289,7 +2301,7 @@ begin
SelectedCompClass := GetSelectedComponentClass; SelectedCompClass := GetSelectedComponentClass;
if (not ControlSelection.RubberBandActive) and if (not ControlSelection.RubberBandActive) and
(SelectedCompClass=nil) and (SelectedCompClass=nil) and
(Shift=[ssLeft]) and ((Shift=[ssLeft]) or (Shift=[ssAlt, ssLeft])) and
(ControlSelection.Count>=1) and (ControlSelection.Count>=1) and
(not ControlSelection.LookupRootSelected) then (not ControlSelection.LookupRootSelected) then
begin // move selection begin // move selection
@ -2299,9 +2311,8 @@ begin
Include(FFlags, dfHasSized); Include(FFlags, dfHasSized);
end; end;
//debugln('TDesigner.MouseMoveOnControl Move MouseDownComponent=',dbgsName(MouseDownComponent),' OldMouseMovePos=',dbgs(OldMouseMovePos),' MouseMovePos',dbgs(LastMouseMovePos),' MouseDownPos=',dbgs(MouseDownPos)); //debugln('TDesigner.MouseMoveOnControl Move MouseDownComponent=',dbgsName(MouseDownComponent),' OldMouseMovePos=',dbgs(OldMouseMovePos),' MouseMovePos',dbgs(LastMouseMovePos),' MouseDownPos=',dbgs(MouseDownPos));
if ControlSelection.MoveSelectionWithSnapping( if ((ssAlt in Shift) and ControlSelection.MoveSelection(LastMouseMovePos.X - MouseDownPos.X, LastMouseMovePos.Y - MouseDownPos.Y, True)) or
LastMouseMovePos.X - MouseDownPos.X, ControlSelection.MoveSelectionWithSnapping(LastMouseMovePos.X - MouseDownPos.X, LastMouseMovePos.Y - MouseDownPos.Y) then
LastMouseMovePos.Y - MouseDownPos.Y) then
DoModified; DoModified;
end end
else else
@ -2880,7 +2891,7 @@ end;
procedure TDesigner.OnSnapToGridOptionMenuClick(Sender: TObject); procedure TDesigner.OnSnapToGridOptionMenuClick(Sender: TObject);
begin begin
EnvironmentOptions.SnapToGrid:=not EnvironmentOptions.SnapToGrid; EnvironmentOptions.SnapToGrid := not EnvironmentOptions.SnapToGrid;
end; end;
procedure TDesigner.OnShowOptionsMenuItemClick(Sender: TObject); procedure TDesigner.OnShowOptionsMenuItemClick(Sender: TObject);
@ -2890,7 +2901,7 @@ end;
procedure TDesigner.OnSnapToGuideLinesOptionMenuClick(Sender: TObject); procedure TDesigner.OnSnapToGuideLinesOptionMenuClick(Sender: TObject);
begin begin
EnvironmentOptions.SnapToGuideLines:=not EnvironmentOptions.SnapToGuideLines; EnvironmentOptions.SnapToGuideLines := not EnvironmentOptions.SnapToGuideLines;
end; end;
procedure TDesigner.OnViewLFMMenuClick(Sender: TObject); procedure TDesigner.OnViewLFMMenuClick(Sender: TObject);
@ -2978,7 +2989,7 @@ end;
function TDesigner.GetSnapToGrid: boolean; function TDesigner.GetSnapToGrid: boolean;
begin begin
Result:=EnvironmentOptions.SnapToGrid; Result := EnvironmentOptions.SnapToGrid;
end; end;
procedure TDesigner.SetShowGrid(const AValue: boolean); procedure TDesigner.SetShowGrid(const AValue: boolean);