MG: added some multi form editing checks

git-svn-id: trunk@2099 -
This commit is contained in:
lazarus 2002-08-17 23:40:56 +00:00
parent 3d9c75633e
commit d6391459c5

View File

@ -2,7 +2,7 @@
designer.pp - Lazarus IDE unit designer.pp - Lazarus IDE unit
-------------------------------- --------------------------------
Initial Revision : Sat May 10 23:15:32 CST 1999 Initial Revision : Sat May 10 23:15:32 CST 1999
***************************************************************************/ ***************************************************************************/
@ -317,6 +317,8 @@ Begin
{$IFDEF VerboseDesigner} {$IFDEF VerboseDesigner}
Writeln('[TDesigner.NudgeControl]'); Writeln('[TDesigner.NudgeControl]');
{$ENDIF} {$ENDIF}
if (ControlSelection.SelectionForm<>Form)
or (ControlSelection.IsSelected(Form)) then exit;
ControlSelection.MoveSelection(DiffX, DiffY); ControlSelection.MoveSelection(DiffX, DiffY);
if ControlSelection.OnlyNonVisualComponentsSelected then if ControlSelection.OnlyNonVisualComponentsSelected then
FCustomForm.Invalidate; FCustomForm.Invalidate;
@ -327,6 +329,8 @@ Begin
{$IFDEF VerboseDesigner} {$IFDEF VerboseDesigner}
Writeln('[TDesigner.NudgeSize]'); Writeln('[TDesigner.NudgeSize]');
{$ENDIF} {$ENDIF}
if (ControlSelection.SelectionForm<>Form)
or (ControlSelection.IsSelected(Form)) then exit;
ControlSelection.SizeSelection(DiffX, DiffY); ControlSelection.SizeSelection(DiffX, DiffY);
end; end;
@ -522,9 +526,9 @@ Begin
writeln('************************************************************'); writeln('************************************************************');
write('MouseDownOnControl'); write('MouseDownOnControl');
write(' ',Sender.Name,':',Sender.ClassName); write(' ',Sender.Name,':',Sender.ClassName);
write(' Msg=',TheMessage.Pos.X,',',TheMessage.Pos.Y); //write(' Msg=',TheMessage.Pos.X,',',TheMessage.Pos.Y);
write(' Mouse=',MouseDownPos.X,',',MouseDownPos.Y); //write(' Mouse=',MouseDownPos.X,',',MouseDownPos.Y);
writeln(''); //writeln('');
if (TheMessage.Keys and MK_Shift) = MK_Shift then if (TheMessage.Keys and MK_Shift) = MK_Shift then
Write(' Shift down') Write(' Shift down')
@ -613,7 +617,7 @@ procedure TDesigner.MouseUpOnControl(Sender : TControl;
TheMessage:TLMMouse); TheMessage:TLMMouse);
var var
ParentCI, NewCI: TComponentInterface; ParentCI, NewCI: TComponentInterface;
NewLeft, NewTop, NewWidth, NewHeight, MoveX, MoveY: Integer; NewLeft, NewTop, NewWidth, NewHeight: Integer;
Shift: TShiftState; Shift: TShiftState;
SenderParentForm: TCustomForm; SenderParentForm: TCustomForm;
RubberBandWasActive: boolean; RubberBandWasActive: boolean;
@ -648,73 +652,73 @@ var
begin begin
// add a new component // add a new component
ControlSelection.RubberbandActive:=false; ControlSelection.RubberbandActive:=false;
ControlSelection.BeginUpdate; ControlSelection.Clear;
try
// find a parent for the new component // find a parent for the new component
NewParent:=TWinControl(MouseDownComponent); NewParent:=TWinControl(MouseDownComponent);
while (NewParent<>nil) while (NewParent<>nil)
and ((not (csAcceptsControls in NewParent.ControlStyle)) and ((not (csAcceptsControls in NewParent.ControlStyle))
or ((NewParent.Owner<>Form) and (NewParent<>Form))) or ((NewParent.Owner<>Form) and (NewParent<>Form)))
do begin do begin
NewParent:=NewParent.Parent; NewParent:=NewParent.Parent;
end; end;
ParentCI:=TComponentInterface(TheFormEditor.FindComponent(NewParent)); ParentCI:=TComponentInterface(TheFormEditor.FindComponent(NewParent));
if not Assigned(ParentCI) then exit; if not Assigned(ParentCI) then exit;
// calculate initial bounds
ParentClientOrigin:=GetParentFormRelativeClientOrigin(NewParent);
NewLeft:=Min(MouseDownPos.X,MouseUpPos.X);
NewTop:=Min(MouseDownPos.Y,MouseUpPos.Y);
if SelectedCompClass.ComponentClass.InheritsFrom(TControl) then begin
// adjust left,top to parent origin
dec(NewLeft,ParentClientOrigin.X);
dec(NewTop,ParentClientOrigin.Y);
end;
NewWidth:=Abs(MouseUpPos.X-MouseDownPos.X);
NewHeight:=Abs(MouseUpPos.Y-MouseDownPos.Y);
if Abs(NewWidth+NewHeight)<7 then begin
// this very small component is probably only a wag, take default size
NewWidth:=0;
NewHeight:=0;
end;
// create component and component interface
NewCI := TComponentInterface(TheFormEditor.CreateComponent(
ParentCI,SelectedCompClass.ComponentClass
,NewLeft,NewTop,NewWidth,NewHeight));
// calculate initial bounds // set initial properties
ParentClientOrigin:=GetParentFormRelativeClientOrigin(NewParent); if NewCI.Component is TControl then
NewLeft:=Min(MouseDownPos.X,MouseUpPos.X); TControl(NewCI.Component).Visible:=true;
NewTop:=Min(MouseDownPos.Y,MouseUpPos.Y); if Assigned(FOnSetDesigning) then
if SelectedCompClass.ComponentClass.InheritsFrom(TControl) then begin FOnSetDesigning(Self,NewCI.Component,True);
// adjust left,top to parent origin
dec(NewLeft,ParentClientOrigin.X); // tell IDE about the new component (e.g. add it to the source)
dec(NewTop,ParentClientOrigin.Y); try
end;
NewWidth:=Abs(MouseUpPos.X-MouseDownPos.X);
NewHeight:=Abs(MouseUpPos.Y-MouseDownPos.Y);
if Abs(NewWidth+NewHeight)<7 then begin
// this very small component is probably only a wag, take default size
NewWidth:=0;
NewHeight:=0;
end;
// create component and component interface
NewCI := TComponentInterface(TheFormEditor.CreateComponent(
ParentCI,SelectedCompClass.ComponentClass
,NewLeft,NewTop,NewWidth,NewHeight));
// set initial properties
if NewCI.Component is TControl then
TControl(NewCI.Component).Visible:=true;
if Assigned(FOnSetDesigning) then
FOnSetDesigning(Self,NewCI.Component,True);
// tell IDE about the new component (e.g. add it to the source)
if Assigned(FOnComponentAdded) then if Assigned(FOnComponentAdded) then
FOnComponentAdded(Self,NewCI.Component,SelectedCompClass); FOnComponentAdded(Self,NewCI.Component,SelectedCompClass);
except
// creation completed on E: Exception do
// -> select new component MessageDlg('Error:',E.Message,mtError,[mbOk],0);
SelectOnlyThisComponent(TComponent(NewCI.Component));
if not (ssShift in Shift) then
if Assigned(FOnUnselectComponentClass) then
// this resets the component palette to the selection tool
FOnUnselectComponentClass(Self);
Form.Invalidate;
{$IFDEF VerboseDesigner}
writeln('NEW COMPONENT ADDED: Form.ComponentCount=',Form.ComponentCount,
' NewCI.Control.Owner.Name=',NewCI.Component.Owner.Name);
{$ENDIF}
finally
ControlSelection.EndUpdate;
end; end;
// creation completed
// -> select new component
SelectOnlyThisComponent(TComponent(NewCI.Component));
if not (ssShift in Shift) then
if Assigned(FOnUnselectComponentClass) then
// this resets the component palette to the selection tool
FOnUnselectComponentClass(Self);
Form.Invalidate;
{$IFDEF VerboseDesigner}
writeln('NEW COMPONENT ADDED: Form.ComponentCount=',Form.ComponentCount,
' NewCI.Control.Owner.Name=',NewCI.Component.Owner.Name);
{$ENDIF}
end; end;
procedure RubberbandSelect; procedure RubberbandSelect;
begin begin
ControlSelection.BeginUpdate;
if (ssShift in Shift) if (ssShift in Shift)
and (ControlSelection.SelectionForm<>nil) and (ControlSelection.SelectionForm<>nil)
and (ControlSelection.SelectionForm<>Form) and (ControlSelection.SelectionForm<>Form)
@ -725,8 +729,12 @@ var
exit; exit;
end; end;
NewRubberbandSelection:=(not (ssShift in Shift)) ControlSelection.BeginUpdate;
and ControlSelection.IsOnlySelected(Form); NewRubberbandSelection:=
((not (ssShift in Shift))
and ControlSelection.IsOnlySelected(Form))
or ((ControlSelection.SelectionForm<>nil)
and (ControlSelection.SelectionForm<>Form));
SelectionChanged:=false; SelectionChanged:=false;
ControlSelection.SelectWithRubberBand( ControlSelection.SelectWithRubberBand(
Form,NewRubberbandSelection,ssShift in Shift,SelectionChanged); Form,NewRubberbandSelection,ssShift in Shift,SelectionChanged);
@ -749,7 +757,8 @@ var
// select only the mouse down component // select only the mouse down component
if ControlSelection.AssignComponent(MouseDownComponent) then if ControlSelection.AssignComponent(MouseDownComponent) then
Form.Invalidate; Form.Invalidate;
if MouseDownClickCount=2 then begin if (MouseDownClickCount=2)
and (ControlSelection.SelectionForm=Form) then begin
// Double Click -> invoke 'Edit' of the component editor // Double Click -> invoke 'Edit' of the component editor
FShiftState:=Shift; FShiftState:=Shift;
InvokeComponentEditor(MouseDownComponent,-1); InvokeComponentEditor(MouseDownComponent,-1);
@ -788,8 +797,6 @@ Begin
GetShift; GetShift;
MouseUpPos:=GetFormRelativeMousePosition(Form); MouseUpPos:=GetFormRelativeMousePosition(Form);
MoveX:=MouseUpPos.X-MouseDownPos.X;
MoveY:=MouseUpPos.Y-MouseDownPos.Y;
SelectedCompClass:=GetSelectedComponentClass; SelectedCompClass:=GetSelectedComponentClass;
@ -797,8 +804,7 @@ Begin
writeln('************************************************************'); writeln('************************************************************');
write('MouseUpOnControl'); write('MouseUpOnControl');
write(' ',Sender.Name,':',Sender.ClassName); write(' ',Sender.Name,':',Sender.ClassName);
write(' Msg=',TheMessage.Pos.X,',',TheMessage.Pos.Y); //write(' Msg=',TheMessage.Pos.X,',',TheMessage.Pos.Y);
write(' Move=',MoveX,',',MoveY);
writeln(''); writeln('');
{$ENDIF} {$ENDIF}
@ -869,7 +875,12 @@ begin
if (OldMouseMovePos.X=LastMouseMovePos.X) if (OldMouseMovePos.X=LastMouseMovePos.X)
and (OldMouseMovePos.Y=LastMouseMovePos.Y) then exit; and (OldMouseMovePos.Y=LastMouseMovePos.Y) then exit;
Grabber:= ControlSelection.GrabberAtPos(LastMouseMovePos.X, LastMouseMovePos.Y); if ControlSelection.SelectionForm=Form then
Grabber:=ControlSelection.GrabberAtPos(
LastMouseMovePos.X, LastMouseMovePos.Y)
else
Grabber:=nil;
if MouseDownComponent=nil then begin if MouseDownComponent=nil then begin
if Grabber = nil then if Grabber = nil then
ACursor:= crDefault ACursor:= crDefault
@ -890,48 +901,51 @@ begin
if (TheMessage.keys and MK_Control) = MK_Control then if (TheMessage.keys and MK_Control) = MK_Control then
Shift := Shift + [ssCTRL]; Shift := Shift + [ssCTRL];
if (TheMessage.keys and MK_LButton) = MK_LButton then begin if ControlSelection.SelectionForm=Form then begin
// left button pressed if (TheMessage.keys and MK_LButton) = MK_LButton then begin
if ControlSelection.ActiveGrabber<>nil then begin // left button pressed
// grabber moving -> size selection if (ControlSelection.ActiveGrabber<>nil) then begin
if not (dfHasSized in FFlags) then begin // grabber moving -> size selection
ControlSelection.SaveBounds;
Include(FFlags,dfHasSized);
end;
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))
and (ControlSelection.Count>=1)
and not (ControlSelection[0].Component is TCustomForm) then
begin
// move selection
if not (dfHasSized in FFlags) then begin if not (dfHasSized in FFlags) then begin
ControlSelection.SaveBounds; ControlSelection.SaveBounds;
Include(FFlags,dfHasSized); Include(FFlags,dfHasSized);
end; end;
if ControlSelection.MoveSelectionWithSnapping( ControlSelection.SizeSelection(
LastMouseMovePos.X-MouseDownPos.X,LastMouseMovePos.Y-MouseDownPos.Y) LastMouseMovePos.X-OldMouseMovePos.X,
then begin LastMouseMovePos.Y-OldMouseMovePos.Y);
if Assigned(OnModified) then OnModified(Self); FCustomForm.Invalidate;
FCustomForm.Invalidate; if Assigned(OnModified) then OnModified(Self);
end else begin
if (not ComponentIsTopLvl(MouseDownComponent))
and (ControlSelection.Count>=1)
and not (ControlSelection[0].Component is TCustomForm) then
begin
// move selection
if not (dfHasSized in FFlags) then begin
ControlSelection.SaveBounds;
Include(FFlags,dfHasSized);
end;
if ControlSelection.MoveSelectionWithSnapping(
LastMouseMovePos.X-MouseDownPos.X,LastMouseMovePos.Y-MouseDownPos.Y)
then begin
if Assigned(OnModified) then OnModified(Self);
FCustomForm.Invalidate;
end;
end
else
begin
// rubberband sizing
ControlSelection.RubberBandBounds:=Rect(MouseDownPos.X,MouseDownPos.Y,
LastMouseMovePos.X,
LastMouseMovePos.Y);
ControlSelection.RubberBandActive:=true;
SenderParentForm.Invalidate;
end; end;
end
else
begin
// rubberband sizing
ControlSelection.RubberBandBounds:=Rect(MouseDownPos.X,MouseDownPos.Y,
LastMouseMovePos.X,
LastMouseMovePos.Y);
ControlSelection.RubberBandActive:=true;
SenderParentForm.Invalidate;
end; end;
end
else begin
ControlSelection.ActiveGrabber:=nil;
end; end;
end else begin
ControlSelection.ActiveGrabber:=nil;
end; end;
end; end;
@ -999,7 +1013,7 @@ end;
Procedure TDesigner.KeyUp(Sender : TControl; TheMessage:TLMKEY); Procedure TDesigner.KeyUp(Sender : TControl; TheMessage:TLMKEY);
Begin Begin
{$IFDEF VerboseDesigner} {$IFDEF VerboseDesigner}
Writeln('TDesigner.KEYUP ',TheMessage.CharCode,' ',TheMessage.KeyData); //Writeln('TDesigner.KEYUP ',TheMessage.CharCode,' ',TheMessage.KeyData);
{$ENDIF} {$ENDIF}
end; end;
@ -1007,6 +1021,8 @@ procedure TDesigner.DoDeleteSelectedComponents;
var var
i: integer; i: integer;
begin begin
if (ControlSelection.Count=0) or (ControlSelection.SelectionForm<>Form) then
exit;
if (ControlSelection.IsSelected(FCustomForm)) then begin if (ControlSelection.IsSelected(FCustomForm)) then begin
if ControlSelection.Count>1 then if ControlSelection.Count>1 then
MessageDlg('Invalid delete', MessageDlg('Invalid delete',
@ -1365,7 +1381,8 @@ end;
function TDesigner.GetComponentEditorForSelection: TBaseComponentEditor; function TDesigner.GetComponentEditorForSelection: TBaseComponentEditor;
begin begin
Result:=nil; Result:=nil;
if ControlSelection.Count<>1 then exit; if (ControlSelection.Count<>1)
or (ControlSelection.SelectionForm<>Form) then exit;
Result:=TheFormEditor.GetComponentEditor(ControlSelection[0].Component); Result:=TheFormEditor.GetComponentEditor(ControlSelection[0].Component);
end; end;
@ -1433,7 +1450,8 @@ var
begin begin
if FPopupMenu<>nil then FPopupMenu.Free; if FPopupMenu<>nil then FPopupMenu.Free;
ControlSelIsNotEmpty:=ControlSelection.Count>0; ControlSelIsNotEmpty:=(ControlSelection.Count>0)
and (ControlSelection.SelectionForm=Form);
FormIsSelected:=ControlSelection.IsSelected(Form); FormIsSelected:=ControlSelection.IsSelected(Form);
OnlyNonVisualCompsAreSelected:= OnlyNonVisualCompsAreSelected:=
ControlSelection.OnlyNonVisualComponentsSelected; ControlSelection.OnlyNonVisualComponentsSelected;