ide: create new forms and datamodules on the IDE monitor

git-svn-id: trunk@21669 -
This commit is contained in:
paul 2009-09-12 16:34:58 +00:00
parent 9d47b22a8e
commit ec4e4a66cf

View File

@ -1574,6 +1574,9 @@ end;
function TCustomFormEditor.CreateComponent(ParentCI: TIComponentInterface; function TCustomFormEditor.CreateComponent(ParentCI: TIComponentInterface;
TypeClass: TComponentClass; const AUnitName: shortstring; X, Y, W, H: Integer TypeClass: TComponentClass; const AUnitName: shortstring; X, Y, W, H: Integer
): TIComponentInterface; ): TIComponentInterface;
const
PreferredDistanceMin = 30;
PreferredDistanceMax = 250;
var var
Temp: TComponentInterface; Temp: TComponentInterface;
NewJITIndex: Integer; NewJITIndex: Integer;
@ -1589,6 +1592,19 @@ var
NewUnitName: String; NewUnitName: String;
s: String; s: String;
Mediator: TDesignerMediator; Mediator: TDesignerMediator;
MonitorBounds: TRect;
function ActiveMonitor: TMonitor;
begin
if Screen.ActiveCustomForm <> nil then
Result := Screen.ActiveCustomForm.Monitor
else
if Application.MainForm <> nil then
Result := Application.MainForm.Monitor
else
Result := Screen.PrimaryMonitor;
end;
begin begin
Result:=nil; Result:=nil;
Temp:=nil; Temp:=nil;
@ -1702,49 +1718,61 @@ begin
CompWidth:=W; CompWidth:=W;
CompHeight:=H; CompHeight:=H;
if NewComponent is TControl then if NewComponent is TControl then
Begin begin
AControl:=TControl(NewComponent); AControl := TControl(NewComponent);
// calc bounds // calc bounds
if CompWidth<=0 then CompWidth:=Max(5,AControl.Width); if CompWidth <= 0 then CompWidth := Max(5, AControl.Width);
if CompHeight<=0 then CompHeight:=Max(5,AControl.Height); if CompHeight <= 0 then CompHeight := Max(5, AControl.Height);
if CompLeft<0 then begin MonitorBounds := ActiveMonitor.BoundsRect;
if AParent<>nil then if (CompLeft < 0) and (AParent <> nil) then
CompLeft:=(AParent.Width - CompWidth) div 2 CompLeft := (AParent.Width - CompWidth) div 2
else if (AControl is TCustomForm) then else
CompLeft:=Max(1,Min(250,Screen.Width-CompWidth-50)) if (AControl is TCustomForm) and (CompLeft < MonitorBounds.Left + PreferredDistanceMin) then
else with MonitorBounds do
CompLeft:=0; CompLeft := Max(Left + PreferredDistanceMin, Min(Left + PreferredDistanceMax, Right - CompWidth - PreferredDistanceMin))
end; else
if CompTop<0 then begin if CompLeft < 0 then
if AParent<>nil then CompLeft := 0;
CompTop:=(AParent.Height - CompHeight) div 2 if (CompTop < 0) and (AParent <> nil) then
else if (AControl is TCustomForm) then CompTop := (AParent.Height - CompHeight) div 2
CompTop:=Max(1,Min(250,Screen.Height-CompHeight-50)) else
else if (AControl is TCustomForm) and (CompTop < MonitorBounds.Top + PreferredDistanceMin) then
CompTop:=0; with MonitorBounds do
end; CompTop := Max(Top + PreferredDistanceMin, Min(Top + PreferredDistanceMax, Bottom - CompWidth - PreferredDistanceMin))
if (AParent<>nil) or (AControl is TCustomForm) then begin else
if CompTop < 0 then
CompTop := 0;
if (AParent <> nil) or (AControl is TCustomForm) then
begin
// set parent after placing control to prevent display at (0,0) // set parent after placing control to prevent display at (0,0)
AControl.SetBounds(CompLeft,CompTop,CompWidth,CompHeight); AControl.SetBounds(CompLeft,CompTop,CompWidth,CompHeight);
AControl.Parent := AParent; AControl.Parent := AParent;
end else begin end else
begin
// no parent and not a form // no parent and not a form
AControl.SetBounds(0,0,CompWidth,CompHeight); AControl.SetBounds(0,0,CompWidth,CompHeight);
AControl.DesignInfo := LeftTopToDesignInfo(CompLeft, CompTop); AControl.DesignInfo := LeftTopToDesignInfo(CompLeft, CompTop);
//DebugLn(['TCustomFormEditor.CreateComponent ',dbgsName(AControl),' ',LongRec(AControl.DesignInfo).Lo,',',LongRec(AControl.DesignInfo).Hi]); //DebugLn(['TCustomFormEditor.CreateComponent ',dbgsName(AControl),' ',LongRec(AControl.DesignInfo).Lo,',',LongRec(AControl.DesignInfo).Hi]);
end; end;
end end
else if (NewComponent is TDataModule) then begin else
if (NewComponent is TDataModule) then
begin
// data module // data module
with TDataModule(NewComponent) do begin with TDataModule(NewComponent) do
if CompWidth<=0 then CompWidth:=Max(50,DesignSize.X); begin
if CompHeight<=0 then CompHeight:=Max(50,DesignSize.Y); if CompWidth <= 0 then CompWidth := Max(50, DesignSize.X);
if CompLeft<30 then if CompHeight <= 0 then CompHeight := Max(50, DesignSize.Y);
CompLeft:=Max(30,Min(250,Screen.Width-CompWidth-50)); MonitorBounds := ActiveMonitor.BoundsRect;
if CompTop<30 then if CompLeft < MonitorBounds.Left + PreferredDistanceMin then
CompTop:=Max(30,Min(250,Screen.Height-CompHeight-50)); with MonitorBounds do
DesignOffset:=Point(CompLeft,CompTop); CompLeft := Max(Left + PreferredDistanceMin, Min(Left + PreferredDistanceMax, Right - CompWidth - PreferredDistanceMin));
DesignSize:=Point(CompWidth,CompHeight); if CompTop < MonitorBounds.Top + PreferredDistanceMin then
with MonitorBounds do
CompTop := Max(Top + PreferredDistanceMin, Min(Top + PreferredDistanceMax, Bottom - CompWidth - PreferredDistanceMin));
DesignOffset := Point(CompLeft, CompTop);
DesignSize := Point(CompWidth, CompHeight);
//debugln('TCustomFormEditor.CreateComponent TDataModule Bounds ',dbgsName(NewComponent),' ',dbgs(DesignOffset.X),',',dbgs(DesignOffset.Y),' ',DbgS(NewComponent),8),' ',DbgS(Cardinal(@DesignOffset)); //debugln('TCustomFormEditor.CreateComponent TDataModule Bounds ',dbgsName(NewComponent),' ',dbgs(DesignOffset.X),',',dbgs(DesignOffset.Y),' ',DbgS(NewComponent),8),' ',DbgS(Cardinal(@DesignOffset));
end; end;
end end