designer: ask mediator for default size

This commit is contained in:
mattias 2022-12-30 13:10:17 +01:00
parent cbef44b7ef
commit f480047750
2 changed files with 26 additions and 6 deletions

View File

@ -148,6 +148,7 @@ type
class function FormClass: TComponentClass; virtual; abstract;
class function CreateMediator(TheOwner, aForm: TComponent): TDesignerMediator; virtual;
class procedure InitFormInstance({%H-}aForm: TComponent); virtual; // called after NewInstance, before constructor
class function GetDefaultSize: TPoint; virtual;
public
procedure SetBounds(AComponent: TComponent; NewBounds: TRect); virtual;
procedure GetBounds(AComponent: TComponent; out CurBounds: TRect); virtual;
@ -598,6 +599,11 @@ begin
end;
class function TDesignerMediator.GetDefaultSize: TPoint;
begin
Result:=Point(320,240);
end;
procedure TDesignerMediator.SetBounds(AComponent: TComponent; NewBounds: TRect);
begin
SetComponentLeftTopOrDesignInfo(AComponent,NewBounds.Left,NewBounds.Top);

View File

@ -1290,15 +1290,27 @@ var
end;
procedure CreateMediator;
var
NewSize: TPoint;
begin
if Mediator<>nil then exit;
MediatorClass:=GetDesignerMediatorClass(TComponentClass(NewComponent.ClassType));
if MediatorClass<>nil then begin
if MediatorClass<>nil then
begin
Mediator:=MediatorClass.CreateMediator(nil,NewComponent);
FreeMediator:=Mediator<>nil;
if Mediator<>nil then
begin
NewSize:=Mediator.GetDefaultSize;
NewWidth:=NewSize.X;
NewHeight:=NewSize.Y;
end;
end;
//DebugLn(['TCustomFormEditor.CreateComponent ',DbgSName(NewComponent),' ',dbgs(Bounds(CompLeft,CompTop,CompWidth,CompHeight)),' ',Mediator<>nil]);
end;
procedure MediatorInitComponent;
begin
if Mediator<>nil then begin
//DebugLn(['TCustomFormEditor.CreateComponent ',DbgSName(NewComponent),' ',dbgs(Bounds(CompLeft,CompTop,CompWidth,CompHeight)),' ',Mediator<>nil]);
Mediator.InitComponent(NewComponent,ParentComponent,
Bounds(CompLeft,CompTop,CompWidth,CompHeight));
end;
@ -1412,6 +1424,8 @@ begin
end;
try
CreateMediator;
// set bounds
CompLeft:=NewLeft;
CompTop:=NewTop;
@ -1480,7 +1494,6 @@ begin
AControl.DesignInfo := LeftTopToDesignInfo(CompLeft, CompTop);
//DebugLn(['TCustomFormEditor.CreateComponent ',dbgsName(AControl),' ',LazLongRec(AControl.DesignInfo).Lo,',',LazLongRec(AControl.DesignInfo).Hi]);
end;
CreateMediator;
end
else
if (NewComponent is TDataModule) then
@ -1509,15 +1522,16 @@ begin
CompLeft := Max(Low(SmallInt), Min(High(SmallInt), CompLeft));
CompTop := Max(Low(SmallInt), Min(High(SmallInt), CompTop));
if Mediator=nil then
SetComponentLeftTopOrDesignInfo(NewComponent,CompLeft,CompTop);
SetComponentLeftTopOrDesignInfo(NewComponent,CompLeft,CompTop);
if ParentComponent <> nil then
begin
DesignForm := GetDesignerForm(ParentComponent);
if DesignForm <> nil then DesignForm.Invalidate;
end;
CreateMediator;
end;
MediatorInitComponent;
except
on e: Exception do begin
DebugLn(e.Message);