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

View File

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