IDE: designer mediator: fixed non visual components selection and moving, patch #26234

git-svn-id: trunk@45216 -
This commit is contained in:
mattias 2014-05-28 22:43:19 +00:00
parent 2a05226c0a
commit 8844f15f3a
10 changed files with 165 additions and 9 deletions

View File

@ -29,11 +29,15 @@ uses
ObjInspStrConsts, PropEdits, PropEditUtils;
type
TCTVGetImageIndexEvent = procedure(APersistent: TPersistent;
var AIndex: integer) of object;
{ TComponentTreeView }
TComponentTreeView = class(TCustomTreeView)
private
FComponentList: TBackupComponentList;
FOnComponentGetImageIndex: TCTVGetImageIndexEvent;
FOnModified: TNotifyEvent;
FPropertyEditorHook: TPropertyEditorHook;
FImageList: TImageList;
@ -65,6 +69,8 @@ type
read FPropertyEditorHook write SetPropertyEditorHook;
property OnSelectionChanged;
property OnModified: TNotifyEvent read FOnModified write FOnModified;
property OnComponentGetImageIndex : TCTVGetImageIndexEvent
read FOnComponentGetImageIndex write FOnComponentGetImageIndex;
end;
implementation
@ -546,6 +552,10 @@ begin
end
else
Result := -1;
//finally, ask the designer such as TDesignerMediator to override it, if any
if assigned(OnComponentGetImageIndex) then
OnComponentGetImageIndex(APersistent, Result);
end;
procedure TComponentTreeView.SetPropertyEditorHook(

View File

@ -78,6 +78,7 @@ type
procedure MouseDown({%H-}Button: TMouseButton; {%H-}Shift: TShiftState; {%H-}p: TPoint; var {%H-}Handled: boolean); virtual;
procedure MouseMove({%H-}Shift: TShiftState; {%H-}p: TPoint; var {%H-}Handled: boolean); virtual;
procedure MouseUp({%H-}Button: TMouseButton; {%H-}Shift: TShiftState; {%H-}p: TPoint; var {%H-}Handled: boolean); virtual;
procedure OiNodeGetImageIndex(APersistent: TPersistent; var AIndex: integer); virtual;
property LCLForm: TForm read FLCLForm write SetLCLForm;
property Designer: TComponentEditorDesigner read FDesigner write SetDesigner;
@ -375,6 +376,12 @@ var
ScrollOffset: TPoint;
CurBounds: TRect;
begin
if ComponentIsIcon(AComponent) then
begin
Result.X := LeftFromDesignInfo(AComponent.DesignInfo);
Result.Y := TopFromDesignInfo(AComponent.DesignInfo);
Exit;
end;
Result:=Point(0,0);
while AComponent<>nil do begin
Parent:=AComponent.GetParentComponent;
@ -451,6 +458,10 @@ begin
and (not ComponentIsSelectable(Child)) then
continue;
GetBounds(Child,ChildBounds);
if ComponentIsIcon(Child) then
OffsetRect(ChildBounds,ScrollOffset.X,
ScrollOffset.Y)
else///x2nie
OffsetRect(ChildBounds,ClientArea.Left+ScrollOffset.X,
ClientArea.Top+ScrollOffset.Y);
//DebugLn(['TDesignerMediator.ComponentAtPos ChildBounds=',dbgs(ChildBounds),' p=',dbgs(p)]);
@ -520,5 +531,11 @@ begin
end;
procedure TDesignerMediator.OiNodeGetImageIndex(APersistent: TPersistent;
var AIndex: integer);
begin
end;
end.

View File

@ -565,6 +565,8 @@ type
TOnAddAvailablePersistent = procedure(APersistent: TPersistent;
var Allowed: boolean) of object;
//copy of TGetPersistentImageIndexEvent
TOnOINodeGetImageEvent = procedure(APersistent: TPersistent; var AImageIndex: integer) of object;
TOIFlag = (
oifRebuildPropListsNeeded
@ -635,6 +637,7 @@ type
procedure OnShowStatusBarPopupMenuItemClick(Sender: TObject);
procedure OnShowOptionsPopupMenuItemClick(Sender: TObject);
procedure OnMainPopupMenuPopup(Sender: TObject);
procedure OnVTNodeGetImageIndex(APersistent: TPersistent; var AIndex: integer);
procedure RestrictedPageShow(Sender: TObject);
procedure WidgetSetRestrictedPaint(Sender: TObject);
procedure ComponentRestrictedPaint(Sender: TObject);
@ -672,6 +675,7 @@ type
FUpdateLock: integer;
FUpdatingAvailComboBox: Boolean;
FComponentEditor: TBaseComponentEditor;
FOnNodeGetImageIndex: TOnOINodeGetImageEvent;
function GetGridControl(Page: TObjectInspectorPage): TOICustomPropertyGrid;
procedure SetComponentEditor(const AValue: TBaseComponentEditor);
procedure SetFavorites(const AValue: TOIFavoriteProperties);
@ -774,6 +778,7 @@ type
property OnUpdateRestricted: TNotifyEvent read FOnUpdateRestricted
write FOnUpdateRestricted;
property OnViewRestricted: TNotifyEvent read FOnViewRestricted write FOnViewRestricted;
property OnNodeGetImageIndex : TOnOINodeGetImageEvent read FOnNodeGetImageIndex write FOnNodeGetImageIndex;
property PropertyEditorHook: TPropertyEditorHook
read FPropertyEditorHook write SetPropertyEditorHook;
property RestrictedProps: TOIRestrictedProperties read FRestricted write SetRestricted;
@ -4089,6 +4094,7 @@ begin
OnDblClick := @ComponentTreeDblClick;
OnKeyDown := @ComponentTreeKeyDown;
OnSelectionChanged := @ComponentTreeSelectionChanged;
OnComponentGetImageIndex := @OnVTNodeGetImageIndex;
OnModified := @DoModified;
Scrollbars := ssAutoBoth;
PopupMenu := MainPopupMenu;
@ -5508,6 +5514,14 @@ begin
FavoriteGrid.Favorites:=FFavorites;
end;
procedure TObjectInspectorDlg.OnVTNodeGetImageIndex(
APersistent: TPersistent; var AIndex: integer);
begin
//ask TMediator
if assigned(FOnNodeGetImageIndex) then
FOnNodeGetImageIndex(APersistent, AIndex);
end;
{ TCustomPropertiesGrid }
function TCustomPropertiesGrid.GetTIObject: TPersistent;

View File

@ -132,6 +132,7 @@ type
FUsedLeft: integer;
FUsedTop: integer;
FUsedWidth: integer;
function GetIsNonVisualComponent: boolean;
function GetLeft: integer;
procedure SetLeft(ALeft: integer);
function GetTop: integer;
@ -178,7 +179,7 @@ type
property IsTComponent: boolean read FIsTComponent;
property IsTControl: boolean read FIsTControl;
property IsTWinControl: boolean read FIsTWinControl;
property IsNonVisualComponent: boolean read FIsNonVisualComponent;
property IsNonVisualComponent: boolean read GetIsNonVisualComponent;
property DesignerForm: TCustomForm read FDesignerForm;
property MarkerPaintedBounds: TRect read FMarkerPaintedBounds write FMarkerPaintedBounds;
end;
@ -347,6 +348,7 @@ type
procedure SetRubberbandType(const AValue: TRubberbandType);
procedure SetSnapping(const AValue: boolean);
procedure SetVisible(const AValue: Boolean);
function GetParentFormRelativeBounds(AComponent: TComponent): TRect;
procedure GetCompSize(var arr: TArrSize);
protected
procedure AdjustGrabbers;
@ -600,14 +602,20 @@ begin
FIsTComponent:=FPersistent is TComponent;
FIsTControl:=FPersistent is TControl;
FIsTWinControl:=FPersistent is TWinControl;
FIsNonVisualComponent:=FIsTComponent and (not FIsTControl);
if (Owner.Mediator<>nil) and FIsTComponent then
FIsNonVisualComponent:=Owner.Mediator.ComponentIsIcon(TComponent(FPersistent));
FDesignerForm:=GetDesignerForm(FPersistent);
FIsVisible:=FIsTComponent
and (not ComponentIsInvisible(TComponent(APersistent)));
end;
function TSelectedControl.GetIsNonVisualComponent: boolean;
//recalculate because FIsNonVisualCOmponent doesn't work properly for Non LCL
begin
FIsNonVisualComponent:=FIsTComponent and (not FIsTControl);
if (Owner.Mediator<>nil) and FIsTComponent then
FIsNonVisualComponent:=Owner.Mediator.ComponentIsIcon(TComponent(FPersistent));
Result := FIsNonVisualComponent;
end;
destructor TSelectedControl.Destroy;
begin
inherited Destroy;
@ -646,12 +654,20 @@ begin
if not FIsTComponent then exit;
if Owner.Mediator <> nil then
begin
if Owner.Mediator.ComponentIsIcon(TComponent(FPersistent)) then
begin
Owner.Mediator.SetBounds(TComponent(FPersistent),Rect( ALeft, ATop, ALeft+AWidth, ATop+AHeight));//x2nie
end
else
begin
Owner.Mediator.GetBounds(TComponent(FPersistent),OldBounds);
ParentOffset:=Owner.Mediator.GetComponentOriginOnForm(TComponent(FPersistent));
dec(ParentOffset.X,OldBounds.Left);
dec(ParentOffset.Y,OldBounds.Top);
Owner.Mediator.SetBounds(TComponent(FPersistent),
Bounds(ALeft-ParentOffset.X,ATop-ParentOffset.Y,AWidth,AHeight));
end;
end
else
begin
@ -669,12 +685,20 @@ begin
if FIsTComponent then
begin
if Owner.Mediator<>nil then begin
if Owner.Mediator.ComponentIsIcon(TComponent(FPersistent)) then
begin
GetComponentBounds(TComponent(FPersistent),ALeft, ATop, AWidth, AHeight);//x2nie
end
else
begin
ALeftTop:=Owner.Mediator.GetComponentOriginOnForm(TComponent(FPersistent));
Owner.Mediator.GetBounds(TComponent(FPersistent),CurBounds);
ALeft:=ALeftTop.X;
ATop:=ALeftTop.Y;
AWidth:=CurBounds.Right-CurBounds.Left;
AHeight:=CurBounds.Bottom-CurBounds.Top;
end;
end else begin
ALeftTop := GetParentFormRelativeTopLeft(TComponent(FPersistent));
ALeft := ALeftTop.X;
@ -707,11 +731,19 @@ var
begin
if not FIsTComponent then exit;
if Owner.Mediator<>nil then begin
if Owner.Mediator.ComponentIsIcon(TComponent(FPersistent)) then
begin
GetComponentBounds(TComponent(FPersistent),
FOldLeft,FOldTop,FOldWidth,FOldHeight);
end
else
begin
Owner.Mediator.GetBounds(TComponent(FPersistent),r);
FOldLeft:=r.Left;
FOldTop:=r.Top;
FOldWidth:=r.Right-r.Left;
FOldHeight:=r.Bottom-r.Top;
end;
end else begin
GetComponentBounds(TComponent(FPersistent),
FOldLeft,FOldTop,FOldWidth,FOldHeight);
@ -1608,6 +1640,11 @@ begin
AComponent:=FLookupRoot.Components[i];
if not PersistentAlignable(AComponent) then continue;
if IsSelected(AComponent) then continue;
if FMediator <> nil then
begin
CurLeft := FMediator.GetComponentOriginOnForm(AComponent).X;
end
else
CurLeft:=GetParentFormRelativeTopLeft(AComponent).X;
CurDist:=Abs(CurLeft-NearestInt.OldValue);
if CurDist>MaxDist then continue; // skip components far away
@ -1618,6 +1655,7 @@ end;
procedure TControlSelection.FindNearestRightGuideLine(
var NearestInt: TNearestInt);
var i, CurRight, MaxDist, CurDist: integer;
R : TRect;
AComponent: TComponent;
begin
if (not EnvironmentOptions.SnapToGuideLines) or (FLookupRoot=nil) then exit;
@ -1627,6 +1665,12 @@ begin
AComponent:=FLookupRoot.Components[i];
if not PersistentAlignable(AComponent) then continue;
if IsSelected(AComponent) then continue;
if FMediator <> nil then
begin
FMediator.GetBounds(AComponent,R);
CurRight := FMediator.GetComponentOriginOnForm(AComponent).X+ R.Right;
end
else
CurRight:=GetParentFormRelativeTopLeft(AComponent).X
+GetComponentWidth(AComponent);
CurDist:=Abs(CurRight-NearestInt.OldValue);
@ -1646,6 +1690,11 @@ begin
AComponent:=FLookupRoot.Components[i];
if not PersistentAlignable(AComponent) then continue;
if IsSelected(AComponent) then continue;
if FMediator <> nil then
begin
CurTop := FMediator.GetComponentOriginOnForm(AComponent).Y;
end
else
CurTop:=GetParentFormRelativeTopLeft(AComponent).Y;
CurDist:=Abs(CurTop-NearestInt.OldValue);
if CurDist>MaxDist then continue; // skip components far away
@ -1656,6 +1705,7 @@ end;
procedure TControlSelection.FindNearestBottomGuideLine(
var NearestInt: TNearestInt);
var i, CurBottom, MaxDist, CurDist: integer;
R: TRect;
AComponent: TComponent;
begin
if (not EnvironmentOptions.SnapToGuideLines) or (FLookupRoot=nil) then exit;
@ -1665,6 +1715,12 @@ begin
AComponent:=FLookupRoot.Components[i];
if not PersistentAlignable(AComponent) then continue;
if IsSelected(AComponent) then continue;
if FMediator <> nil then
begin
FMediator.GetBounds(AComponent,R);
CurBottom := FMediator.GetComponentOriginOnForm(AComponent).Y+ R.Bottom;
end
else
CurBottom:=GetParentFormRelativeTopLeft(AComponent).Y
+GetComponentHeight(AComponent);
CurDist:=Abs(CurBottom-NearestInt.OldValue);
@ -2101,6 +2157,21 @@ begin
end;
end;
function TControlSelection.GetParentFormRelativeBounds(AComponent: TComponent
): TRect;
var R:TRect;
P : TPoint;
begin
if FMediator <> nil then
begin
FMediator.GetBounds(AComponent,R);
P := FMediator.GetComponentOriginOnForm(AComponent);
Result :=Bounds(P.X, P.Y, R.Right - R.Left, R.Bottom - R.Top);
end
else
Result := DesignerProcs.GetParentFormRelativeBounds(AComponent);
end;
function TControlSelection.GetItems(Index:integer):TSelectedControl;
begin
Result:=TSelectedControl(FControls[Index]);
@ -2835,7 +2906,7 @@ begin
if cssOnlyNonVisualNeedsUpdate in FStates then begin
Result:=true;
for i:=0 to FControls.Count-1 do
if Items[i].IsTControl then begin
if not Items[i].IsNonVisualComponent then begin
Result:=false;
break;
end;

View File

@ -3617,9 +3617,6 @@ var
begin
if Mediator<>nil then begin
Result:=Mediator.GetComponentOriginOnForm(AComponent);
Mediator.GetClientArea(AComponent,CurClientArea,ScrollOffset);
inc(Result.X,CurClientArea.Left+ScrollOffset.X);
inc(Result.Y,CurClientArea.Top+ScrollOffset.Y);
end else begin
Result:=DesignerProcs.GetParentFormRelativeClientOrigin(AComponent);
end;
@ -3941,7 +3938,7 @@ begin
SelectionVisible:=not ControlSelection.OnlyInvisiblePersistentsSelected;
CompsAreSelected:=ControlSelIsNotEmpty and SelectionVisible
and not LookupRootIsSelected;
OneControlSelected := ControlSelIsNotEmpty and ControlSelection[0].IsTControl;
OneControlSelected := ControlSelIsNotEmpty and not ControlSelection[0].IsNonVisualComponent;
MultiCompsAreSelected := CompsAreSelected and (ControlSelection.Count>1);
UnitIsVirtual:=(SrcFile=nil) or not FilenameIsAbsolute(SrcFile.Filename);

View File

@ -130,6 +130,8 @@ var
begin
inherited Paint;
with Canvas do begin
if LookupRoot is TDataModule then
begin
Brush.Color:=clWhite;
ARect:=Rect(FrameWidth,FrameWidth,
Self.ClientWidth-FrameWidth,
@ -138,6 +140,7 @@ begin
ARect:=Rect(0,0,Self.ClientWidth+1,Self.ClientHeight+1);
Pen.Color:=clBlack;
Frame3d(ARect, FrameWidth, bvLowered);
end;
if (Mediator<>nil) and (LookupRoot<>nil) then
Mediator.Paint;
end;

View File

@ -64,6 +64,8 @@ type
destructor Destroy; override;
procedure InvalidateRect(Sender: TObject; ARect: TRect; Erase: boolean);
property MyForm: TMyForm read FMyForm;
public
procedure OiNodeGetImageIndex(APersistent: TPersistent; var AIndex: integer); override;
end;
{ TFileDescPascalUnitWithMyForm }
@ -138,6 +140,21 @@ begin
LCLIntf.InvalidateRect(LCLForm.Handle,@ARect,Erase);
end;
procedure TMyWidgetMediator.OiNodeGetImageIndex(APersistent: TPersistent;
var AIndex: integer);
begin
if Assigned(APersistent) then
begin
if (APersistent is TMyWidget) and (TMyWidget(APersistent).AcceptChildrenAtDesignTime) then
AIndex := 3
else
if (APersistent is TMyWidget) then
AIndex := 2
else
inherited OiNodeGetImageIndex(APersistent, AIndex);
end
end;
procedure TMyWidgetMediator.SetBounds(AComponent: TComponent; NewBounds: TRect);
begin
if AComponent is TMyWidget then begin

View File

@ -252,6 +252,11 @@ begin
for i:=0 to ChildCount-1 do
if Children[i].Owner=Root then
Proc(Children[i]);
if Root = self then
for i:=0 to ComponentCount-1 do
if Components[i].GetParentComponent = nil then
Proc(Components[i]);
end;
constructor TMyWidget.Create(AOwner: TComponent);

View File

@ -72,6 +72,7 @@ type
FStandardDefinePropertiesRegistered: Boolean;
FDesignerBaseClasses: TFPList; // list of TComponentClass
FDesignerMediatorClasses: TFPList;// list of TDesignerMediatorClass
FOnNodeGetImageIndex: TOnOINodeGetImageEvent;
function GetPropertyEditorHook: TPropertyEditorHook;
function FindDefinePropertyNode(const APersistentClassName: string
): TAVLTreeNode;
@ -101,6 +102,9 @@ type
function GetDesignerBaseClasses(Index: integer): TComponentClass; override;
procedure OnDesignerMenuItemClick(Sender: TObject); virtual;
function FindNonFormFormNode(LookupRoot: TComponent): TAVLTreeNode;
//because we only meet ObjInspectore here, not in abstract ancestor
procedure DoOnNodeGetImageIndex(APersistent: TPersistent; var AImageIndex: integer); virtual;
public
JITFormList: TJITForms;// designed forms
JITNonFormList: TJITNonFormComponents;// designed custom components like data modules
@ -248,6 +252,8 @@ type
read FObj_Inspector write SetObj_Inspector;
property PropertyEditorHook: TPropertyEditorHook read GetPropertyEditorHook;
property OnSelectFrame: TSelectFrameEvent read FOnSelectFrame write FOnSelectFrame;
property OnNodeGetImageIndex : TOnOINodeGetImageEvent read FOnNodeGetImageIndex
write FOnNodeGetImageIndex;
end;
@ -2396,16 +2402,31 @@ begin
if AnObjectInspector=FObj_Inspector then exit;
if FObj_Inspector<>nil then begin
FObj_Inspector.OnModified:=nil;
FObj_inspector.OnNodeGetImageIndex:= nil;
end;
FObj_Inspector:=AnObjectInspector;
if FObj_Inspector<>nil then begin
FObj_Inspector.OnModified:=@OnObjectInspectorModified;
FObj_inspector.OnNodeGetImageIndex:= @DoOnNodeGetImageIndex;
end;
end;
procedure TCustomFormEditor.DoOnNodeGetImageIndex(APersistent: TPersistent;
var AImageIndex: integer);
var
DesignerForm : TCustomForm;
begin
DesignerForm := GetDesignerForm(APersistent);
//ask TMediator
if DesignerForm is TNonControlDesignerForm then
TNonControlDesignerForm(DesignerForm).Mediator.OiNodeGetImageIndex(APersistent, AImageIndex);
end;
{ TDefinePropertiesCacheItem }
destructor TDefinePropertiesCacheItem.Destroy;

View File

@ -486,6 +486,7 @@ begin
if AProject.CompilerOptions.LoadFromFile(AFilename)<>mrOk then
DebugLn(['TMainIDEBase.DoLoadDefaultCompilerOptions failed']);
end;
// change target file name
AFilename:=ExtractFileName(AProject.CompilerOptions.TargetFilename);
if AFilename='' then