IDE: designer mediator: implemented rubberband and draw markers

git-svn-id: trunk@21649 -
This commit is contained in:
mattias 2009-09-11 12:05:49 +00:00
parent 1417561829
commit 5a72f4fee4
5 changed files with 74 additions and 41 deletions

View File

@ -488,9 +488,10 @@ type
procedure SelectAll(ALookupRoot: TComponent); procedure SelectAll(ALookupRoot: TComponent);
procedure SelectWithRubberBand(ALookupRoot: TComponent; procedure SelectWithRubberBand(ALookupRoot: TComponent;
AMediator: TDesignerMediator;
ClearBefore, ExclusiveOr: boolean; ClearBefore, ExclusiveOr: boolean;
var SelectionChanged: boolean; var SelectionChanged: boolean;
MaxParentControl: TControl); MaxParentComponent: TComponent);
property Visible:boolean read GetVisible write SetVisible; property Visible:boolean read GetVisible write SetVisible;
@ -1276,19 +1277,16 @@ procedure TControlSelection.DoDrawMarker(Index: integer;
DC: TDesignerDeviceContext); DC: TDesignerDeviceContext);
var var
CompLeft, CompTop, CompWidth, CompHeight: integer; CompLeft, CompTop, CompWidth, CompHeight: integer;
CompOrigin, DCOrigin: TPoint; DCOrigin: TPoint;
CurItem: TSelectedControl; CurItem: TSelectedControl;
AComponent: TComponent;
begin begin
CurItem:=Items[Index]; CurItem:=Items[Index];
if not CurItem.IsTComponent then exit; if not CurItem.IsTComponent then exit;
AComponent:=TComponent(CurItem.Persistent);
GetComponentBounds(AComponent,CompLeft,CompTop,CompWidth,CompHeight); CurItem.GetFormRelativeBounds(CompLeft,CompTop,CompWidth,CompHeight);
CompOrigin:=GetParentFormRelativeParentClientOrigin(AComponent);
DCOrigin:=DC.FormOrigin; DCOrigin:=DC.FormOrigin;
CompLeft:=CompLeft+CompOrigin.X-DCOrigin.X; CompLeft:=CompLeft-DCOrigin.X;
CompTop:=CompTop+CompOrigin.Y-DCOrigin.Y; CompTop:=CompTop-DCOrigin.Y;
{writeln('DoDrawMarker A ',FForm.Name {writeln('DoDrawMarker A ',FForm.Name
,' Component',AComponent.Name,',',CompLeft,',',CompLeft ,' Component',AComponent.Name,',',CompLeft,',',CompLeft
@ -2480,31 +2478,53 @@ begin
end; end;
procedure TControlSelection.SelectWithRubberBand(ALookupRoot: TComponent; procedure TControlSelection.SelectWithRubberBand(ALookupRoot: TComponent;
ClearBefore, ExclusiveOr:boolean; var SelectionChanged: boolean; AMediator: TDesignerMediator; ClearBefore, ExclusiveOr: boolean;
MaxParentControl: TControl); var SelectionChanged: boolean; MaxParentComponent: TComponent);
var var
i: integer; i: integer;
AComponent: TComponent; AComponent: TComponent;
function ControlInRubberBand(AComponent: TComponent): boolean; function ComponentInRubberBand(AComponent: TComponent): boolean;
var var
ALeft, ATop, ARight, ABottom: integer; ALeft, ATop, ARight, ABottom: integer;
Origin: TPoint; Origin: TPoint;
AControl: TControl; AControl: TControl;
CurBounds: TRect;
CurParent: TComponent;
begin begin
Result:=false; Result:=false;
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 (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;
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
if ComponentIsInvisible(AComponent) then exit; if ComponentIsInvisible(AComponent) then exit;
if (AComponent is TControl) then begin if (AComponent is TControl) then begin
AControl:=TControl(AComponent); AControl:=TControl(AComponent);
// check if control is visible on form // check if control is visible on form
if not ControlIsInDesignerVisible(AControl) then exit; if not ControlIsInDesignerVisible(AControl) then exit;
// check if control // check if control
if (MaxParentControl<>nil) then begin if (MaxParentComponent is TWinControl) then begin
// select only controls, that are childs of MaxParentControl // select only controls, that are childs of MaxParentComponent
if (not MaxParentControl.IsParentOf(AControl)) then exit; if (not TWinControl(MaxParentComponent).IsParentOf(AControl)) then exit;
// check if control is a grand child // check if control is a grand child
if (not EnvironmentOptions.RubberbandSelectsGrandChilds) if (not EnvironmentOptions.RubberbandSelectsGrandChilds)
and (AControl.Parent<>MaxParentControl) then exit; and (AControl.Parent<>MaxParentComponent) then exit;
end; end;
end; end;
Origin:=GetParentFormRelativeTopLeft(AComponent); Origin:=GetParentFormRelativeTopLeft(AComponent);
@ -2517,6 +2537,7 @@ var
ARight:=ALeft+NonVisualCompWidth; ARight:=ALeft+NonVisualCompWidth;
ABottom:=ATop+NonVisualCompWidth; ABottom:=ATop+NonVisualCompWidth;
end; end;
end;
Result:=(ALeft<FRubberBandBounds.Right) Result:=(ALeft<FRubberBandBounds.Right)
and (ATop<FRubberBandBounds.Bottom) and (ATop<FRubberBandBounds.Bottom)
and (ARight>=FRubberBandBounds.Left) and (ARight>=FRubberBandBounds.Left)
@ -2533,7 +2554,7 @@ begin
end; end;
for i:=0 to ALookupRoot.ComponentCount-1 do begin for i:=0 to ALookupRoot.ComponentCount-1 do begin
AComponent:=ALookupRoot.Components[i]; AComponent:=ALookupRoot.Components[i];
if not ControlInRubberBand(AComponent) then begin if not ComponentInRubberBand(AComponent) then begin
if IsSelected(AComponent) then begin if IsSelected(AComponent) then begin
Remove(AComponent); Remove(AComponent);
SelectionChanged:=true; SelectionChanged:=true;
@ -2543,7 +2564,7 @@ begin
end; end;
for i:=0 to ALookupRoot.ComponentCount-1 do begin for i:=0 to ALookupRoot.ComponentCount-1 do begin
AComponent:=ALookupRoot.Components[i]; AComponent:=ALookupRoot.Components[i];
if ControlInRubberBand(AComponent) then begin if ComponentInRubberBand(AComponent) then begin
if IsSelected(AComponent) then begin if IsSelected(AComponent) then begin
if ExclusiveOr then begin if ExclusiveOr then begin
Remove(AComponent); Remove(AComponent);

View File

@ -1600,7 +1600,7 @@ var
procedure RubberbandSelect; procedure RubberbandSelect;
var var
MaxParentControl: TControl; MaxParentComponent: TComponent;
begin begin
if (ssShift in Shift) if (ssShift in Shift)
and (ControlSelection.SelectionForm<>nil) and (ControlSelection.SelectionForm<>nil)
@ -1620,14 +1620,17 @@ var
MoveNonVisualComponentsIntoForm; MoveNonVisualComponentsIntoForm;
// if user press the Control key, then component candidates are only // if user press the Control key, then component candidates are only
// childs of the control, where the mouse started // childs of the control, where the mouse started
if (ssCtrl in shift) and (MouseDownComponent is TControl) then if (ssCtrl in shift) then begin
MaxParentControl:=TControl(MouseDownComponent) if MouseDownComponent=Form then
MaxParentComponent:=FLookupRoot
else else
MaxParentControl:=Form; MaxParentComponent:=MouseDownComponent;
end else
MaxParentComponent:=FLookupRoot;
SelectionChanged:=false; SelectionChanged:=false;
ControlSelection.SelectWithRubberBand( ControlSelection.SelectWithRubberBand(
FLookupRoot,NewRubberbandSelection,ssShift in Shift,SelectionChanged, FLookupRoot,Mediator,NewRubberbandSelection,ssShift in Shift,
MaxParentControl); SelectionChanged,MaxParentComponent);
if ControlSelection.Count=0 then begin if ControlSelection.Count=0 then begin
ControlSelection.Add(FLookupRoot); ControlSelection.Add(FLookupRoot);
SelectionChanged:=true; SelectionChanged:=true;

View File

@ -12,4 +12,11 @@ object MyForm1: TMyForm1
Height = 25 Height = 25
Caption = 'MyButton1' Caption = 'MyButton1'
end end
object MyButton2: TMyButton
Left = 30
Top = 70
Width = 75
Height = 25
Caption = 'MyButton2'
end
end end

View File

@ -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 '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' +'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 +'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
]); ]);

View File

@ -10,6 +10,7 @@ uses
type type
TMyForm1 = class(TMyForm) TMyForm1 = class(TMyForm)
MyButton1: TMyButton; MyButton1: TMyButton;
MyButton2: TMyButton;
private private
{ private declarations } { private declarations }
public public