mirror of
				https://gitlab.com/freepascal.org/lazarus/lazarus.git
				synced 2025-10-31 17:21:34 +01:00 
			
		
		
		
	IDE: designer mediator: implemented rubberband and draw markers
git-svn-id: trunk@21649 -
This commit is contained in:
		
							parent
							
								
									1417561829
								
							
						
					
					
						commit
						5a72f4fee4
					
				| @ -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,31 +2478,53 @@ 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 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 (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; | ||||
|         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<>MaxParentControl) then exit; | ||||
|           and (AControl.Parent<>MaxParentComponent) then exit; | ||||
|         end; | ||||
|       end; | ||||
|       Origin:=GetParentFormRelativeTopLeft(AComponent); | ||||
| @ -2517,6 +2537,7 @@ var | ||||
|         ARight:=ALeft+NonVisualCompWidth; | ||||
|         ABottom:=ATop+NonVisualCompWidth; | ||||
|       end; | ||||
|     end; | ||||
|     Result:=(ALeft<FRubberBandBounds.Right) | ||||
|         and (ATop<FRubberBandBounds.Bottom) | ||||
|         and (ARight>=FRubberBandBounds.Left) | ||||
| @ -2533,7 +2554,7 @@ begin | ||||
|     end; | ||||
|     for i:=0 to ALookupRoot.ComponentCount-1 do begin | ||||
|       AComponent:=ALookupRoot.Components[i]; | ||||
|       if not ControlInRubberBand(AComponent) then begin | ||||
|       if not ComponentInRubberBand(AComponent) then begin | ||||
|         if IsSelected(AComponent) then begin | ||||
|           Remove(AComponent); | ||||
|           SelectionChanged:=true; | ||||
| @ -2543,7 +2564,7 @@ begin | ||||
|   end; | ||||
|   for i:=0 to ALookupRoot.ComponentCount-1 do begin | ||||
|     AComponent:=ALookupRoot.Components[i]; | ||||
|     if ControlInRubberBand(AComponent) then begin | ||||
|     if ComponentInRubberBand(AComponent) then begin | ||||
|       if IsSelected(AComponent) then begin | ||||
|         if ExclusiveOr then begin | ||||
|           Remove(AComponent); | ||||
|  | ||||
| @ -1600,7 +1600,7 @@ var | ||||
| 
 | ||||
|   procedure RubberbandSelect; | ||||
|   var | ||||
|     MaxParentControl: TControl; | ||||
|     MaxParentComponent: TComponent; | ||||
|   begin | ||||
|     if (ssShift in Shift) | ||||
|     and (ControlSelection.SelectionForm<>nil) | ||||
| @ -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) | ||||
|     if (ssCtrl in shift) then begin | ||||
|       if MouseDownComponent=Form then | ||||
|         MaxParentComponent:=FLookupRoot | ||||
|       else | ||||
|       MaxParentControl:=Form; | ||||
|         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; | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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 | ||||
| ]); | ||||
|  | ||||
| @ -10,6 +10,7 @@ uses | ||||
| type | ||||
|   TMyForm1 = class(TMyForm) | ||||
|     MyButton1: TMyButton; | ||||
|     MyButton2: TMyButton; | ||||
|   private | ||||
|     { private declarations } | ||||
|   public | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 mattias
						mattias