From 5a72f4fee47c243ad62cd85ce6fac1efb8b494d2 Mon Sep 17 00:00:00 2001 From: mattias Date: Fri, 11 Sep 2009 12:05:49 +0000 Subject: [PATCH] IDE: designer mediator: implemented rubberband and draw markers git-svn-id: trunk@21649 - --- designer/controlselection.pp | 87 +++++++++++++++---------- designer/designer.pp | 17 +++-- examples/designnonlcl/project/unit1.lfm | 7 ++ examples/designnonlcl/project/unit1.lrs | 3 +- examples/designnonlcl/project/unit1.pas | 1 + 5 files changed, 74 insertions(+), 41 deletions(-) diff --git a/designer/controlselection.pp b/designer/controlselection.pp index 210edfac0a..9984712a20 100644 --- a/designer/controlselection.pp +++ b/designer/controlselection.pp @@ -488,9 +488,10 @@ type procedure SelectAll(ALookupRoot: TComponent); procedure SelectWithRubberBand(ALookupRoot: TComponent; + AMediator: TDesignerMediator; ClearBefore, ExclusiveOr: boolean; var SelectionChanged: boolean; - MaxParentControl: TControl); + MaxParentComponent: TComponent); property Visible:boolean read GetVisible write SetVisible; @@ -1276,19 +1277,16 @@ procedure TControlSelection.DoDrawMarker(Index: integer; DC: TDesignerDeviceContext); var CompLeft, CompTop, CompWidth, CompHeight: integer; - CompOrigin, DCOrigin: TPoint; + DCOrigin: TPoint; CurItem: TSelectedControl; - AComponent: TComponent; begin CurItem:=Items[Index]; if not CurItem.IsTComponent then exit; - AComponent:=TComponent(CurItem.Persistent); - GetComponentBounds(AComponent,CompLeft,CompTop,CompWidth,CompHeight); - CompOrigin:=GetParentFormRelativeParentClientOrigin(AComponent); + CurItem.GetFormRelativeBounds(CompLeft,CompTop,CompWidth,CompHeight); DCOrigin:=DC.FormOrigin; - CompLeft:=CompLeft+CompOrigin.X-DCOrigin.X; - CompTop:=CompTop+CompOrigin.Y-DCOrigin.Y; + CompLeft:=CompLeft-DCOrigin.X; + CompTop:=CompTop-DCOrigin.Y; {writeln('DoDrawMarker A ',FForm.Name ,' Component',AComponent.Name,',',CompLeft,',',CompLeft @@ -2480,42 +2478,65 @@ begin end; procedure TControlSelection.SelectWithRubberBand(ALookupRoot: TComponent; - ClearBefore, ExclusiveOr:boolean; var SelectionChanged: boolean; - MaxParentControl: TControl); + AMediator: TDesignerMediator; ClearBefore, ExclusiveOr: boolean; + var SelectionChanged: boolean; MaxParentComponent: TComponent); var i: integer; AComponent: TComponent; - function ControlInRubberBand(AComponent: TComponent): boolean; + function ComponentInRubberBand(AComponent: TComponent): boolean; var ALeft, ATop, ARight, ABottom: integer; Origin: TPoint; AControl: TControl; + CurBounds: TRect; + CurParent: TComponent; begin Result:=false; - if ComponentIsInvisible(AComponent) then exit; - if (AComponent is TControl) then begin - AControl:=TControl(AComponent); - // check if control is visible on form - if not ControlIsInDesignerVisible(AControl) then exit; - // check if control - if (MaxParentControl<>nil) then begin - // select only controls, that are childs of MaxParentControl - if (not MaxParentControl.IsParentOf(AControl)) then exit; - // check if control is a grand child + if AMediator<>nil then begin + // check if component is visible on form + if not AMediator.ComponentIsVisible(AComponent) then exit; + if MaxParentComponent<>nil then begin + // check if component is a grand child + CurParent:=AComponent.GetParentComponent; if (not EnvironmentOptions.RubberbandSelectsGrandChilds) - and (AControl.Parent<>MaxParentControl) then exit; + and (CurParent<>MaxParentComponent) then exit; + // check if component is a child (direct or grand) + while (CurParent<>nil) and (CurParent<>MaxParentComponent) do + CurParent:=CurParent.GetParentComponent; + if CurParent=nil then exit; end; - end; - Origin:=GetParentFormRelativeTopLeft(AComponent); - ALeft:=Origin.X; - ATop:=Origin.Y; - if AComponent is TControl then begin - ARight:=ALeft+TControl(AComponent).Width; - ABottom:=ATop+TControl(AComponent).Height; + AMediator.GetBounds(AComponent,CurBounds); + Origin:=AMediator.GetComponentOriginOnForm(AComponent); + ALeft:=Origin.X; + ATop:=Origin.Y; + ARight:=ALeft+CurBounds.Right-CurBounds.Left; + ABottom:=ATop+CurBounds.Bottom-CurBounds.Top; end else begin - ARight:=ALeft+NonVisualCompWidth; - ABottom:=ATop+NonVisualCompWidth; + if ComponentIsInvisible(AComponent) then exit; + if (AComponent is TControl) then begin + AControl:=TControl(AComponent); + // check if control is visible on form + if not ControlIsInDesignerVisible(AControl) then exit; + // check if control + if (MaxParentComponent is TWinControl) then begin + // select only controls, that are childs of MaxParentComponent + if (not TWinControl(MaxParentComponent).IsParentOf(AControl)) then exit; + // check if control is a grand child + if (not EnvironmentOptions.RubberbandSelectsGrandChilds) + and (AControl.Parent<>MaxParentComponent) then exit; + end; + end; + Origin:=GetParentFormRelativeTopLeft(AComponent); + ALeft:=Origin.X; + ATop:=Origin.Y; + if AComponent is TControl then begin + ARight:=ALeft+TControl(AComponent).Width; + ABottom:=ATop+TControl(AComponent).Height; + end else begin + ARight:=ALeft+NonVisualCompWidth; + ABottom:=ATop+NonVisualCompWidth; + end; end; Result:=(ALeftnil) @@ -1620,14 +1620,17 @@ var MoveNonVisualComponentsIntoForm; // if user press the Control key, then component candidates are only // childs of the control, where the mouse started - if (ssCtrl in shift) and (MouseDownComponent is TControl) then - MaxParentControl:=TControl(MouseDownComponent) - else - MaxParentControl:=Form; + if (ssCtrl in shift) then begin + if MouseDownComponent=Form then + MaxParentComponent:=FLookupRoot + else + MaxParentComponent:=MouseDownComponent; + end else + MaxParentComponent:=FLookupRoot; SelectionChanged:=false; ControlSelection.SelectWithRubberBand( - FLookupRoot,NewRubberbandSelection,ssShift in Shift,SelectionChanged, - MaxParentControl); + FLookupRoot,Mediator,NewRubberbandSelection,ssShift in Shift, + SelectionChanged,MaxParentComponent); if ControlSelection.Count=0 then begin ControlSelection.Add(FLookupRoot); SelectionChanged:=true; diff --git a/examples/designnonlcl/project/unit1.lfm b/examples/designnonlcl/project/unit1.lfm index 82b83277ea..ab27c2fa82 100644 --- a/examples/designnonlcl/project/unit1.lfm +++ b/examples/designnonlcl/project/unit1.lfm @@ -12,4 +12,11 @@ object MyForm1: TMyForm1 Height = 25 Caption = 'MyButton1' end + object MyButton2: TMyButton + Left = 30 + Top = 70 + Width = 75 + Height = 25 + Caption = 'MyButton2' + end end diff --git a/examples/designnonlcl/project/unit1.lrs b/examples/designnonlcl/project/unit1.lrs index 6318c93f9d..3243d1a147 100644 --- a/examples/designnonlcl/project/unit1.lrs +++ b/examples/designnonlcl/project/unit1.lrs @@ -2,5 +2,6 @@ LazarusResources.Add('TMyForm1','FORMDATA',[ 'TPF0'#8'TMyForm1'#7'MyForm1'#4'Left'#3'?'#1#3'Top'#3#231#0#5'Width'#3'B'#1#6 +'Height'#3#236#0#7'Visible'#8#7'Caption'#6#7'MyForm1'#0#9'TMyButton'#9'MyBut' +'ton1'#4'Left'#2#20#3'Top'#2#10#5'Width'#2'K'#6'Height'#2#25#7'Caption'#6#9 - +'MyButton1'#0#0#0 + +'MyButton1'#0#0#9'TMyButton'#9'MyButton2'#4'Left'#2#30#3'Top'#2'F'#5'Width'#2 + +'K'#6'Height'#2#25#7'Caption'#6#9'MyButton2'#0#0#0 ]); diff --git a/examples/designnonlcl/project/unit1.pas b/examples/designnonlcl/project/unit1.pas index 1d30c2dadf..ea4532999d 100644 --- a/examples/designnonlcl/project/unit1.pas +++ b/examples/designnonlcl/project/unit1.pas @@ -10,6 +10,7 @@ uses type TMyForm1 = class(TMyForm) MyButton1: TMyButton; + MyButton2: TMyButton; private { private declarations } public