mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-30 11:02:56 +02:00
DockMaster: fix form positioning
git-svn-id: trunk@36257 -
This commit is contained in:
parent
4494ab3e94
commit
d5ba4d32d2
@ -34,6 +34,8 @@ unit RegisterEasyDockMgr;
|
|||||||
|
|
||||||
{$DEFINE DockMaster} //must match IDE setting
|
{$DEFINE DockMaster} //must match IDE setting
|
||||||
|
|
||||||
|
{.$DEFINE oldPos} //as implemented by Mattias? (problem with multiple monitors!)
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -84,6 +86,7 @@ var
|
|||||||
IDEEasyDockMaster: TIDEEasyDockMaster = nil;
|
IDEEasyDockMaster: TIDEEasyDockMaster = nil;
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
|
function FitToMonitor(const tlbr: TRect): TRect;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -98,6 +101,47 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function FitInto(const src, dst: TRect): TRect;
|
||||||
|
begin
|
||||||
|
(* Adjust src to fit into dst.
|
||||||
|
Keep src extent if possible.
|
||||||
|
*)
|
||||||
|
if src.Right > dst.Right then begin
|
||||||
|
//shift left
|
||||||
|
Result.Right := dst.Right;
|
||||||
|
Result.Left := Max(dst.Left, Result.Right - (src.Right - src.Left));
|
||||||
|
end else if src.Left < dst.Left then begin
|
||||||
|
//shift right
|
||||||
|
Result.Left := src.Left;
|
||||||
|
Result.Right := Min(dst.Right, Result.Left + (src.Right - src.Left));
|
||||||
|
end else begin
|
||||||
|
Result.Left := src.Left;
|
||||||
|
Result.Right:= src.Right;
|
||||||
|
end;
|
||||||
|
if src.Bottom > dst.Bottom then begin
|
||||||
|
//shift up
|
||||||
|
Result.Bottom := dst.Bottom;
|
||||||
|
Result.Top := Max(dst.Top, Result.Bottom - (src.Bottom - src.Top));
|
||||||
|
end else if src.Top < dst.Top then begin
|
||||||
|
//shift down
|
||||||
|
Result.Top := dst.Top;
|
||||||
|
Result.Bottom := Min(dst.Bottom, Result.Top + (src.Bottom - src.Top));
|
||||||
|
end else begin
|
||||||
|
Result.Top := src.Top;
|
||||||
|
Result.Bottom := src.Bottom;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function FitToMonitor(const tlbr: TRect): TRect;
|
||||||
|
var
|
||||||
|
r: TRect;
|
||||||
|
m: TMonitor;
|
||||||
|
begin
|
||||||
|
m := Screen.MonitorFromPoint(tlbr.BottomRight, mdNearest);
|
||||||
|
r := m.BoundsRect;
|
||||||
|
Result := FitInto(tlbr, r);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TIDEEasyDockMaster }
|
{ TIDEEasyDockMaster }
|
||||||
|
|
||||||
function TIDEEasyDockMaster.DockMasterRestore(const CtrlName: string;
|
function TIDEEasyDockMaster.DockMasterRestore(const CtrlName: string;
|
||||||
@ -117,7 +161,11 @@ procedure TIDEEasyDockMaster.GetDefaultBounds(AForm: TCustomForm; out
|
|||||||
Creator: TIDEWindowCreator; out NewBounds: TRect; out DockSiblingName: string;
|
Creator: TIDEWindowCreator; out NewBounds: TRect; out DockSiblingName: string;
|
||||||
out DockAlign: TAlign);
|
out DockAlign: TAlign);
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF oldPos}
|
||||||
NewBounds:=Rect(0,0,0,0);
|
NewBounds:=Rect(0,0,0,0);
|
||||||
|
{$ELSE}
|
||||||
|
NewBounds:=AForm.BoundsRect;
|
||||||
|
{$ENDIF}
|
||||||
DockSiblingName:='';
|
DockSiblingName:='';
|
||||||
DockAlign:=alNone;
|
DockAlign:=alNone;
|
||||||
Creator:=IDEWindowCreators.FindWithName(AForm.Name);
|
Creator:=IDEWindowCreators.FindWithName(AForm.Name);
|
||||||
@ -129,10 +177,14 @@ begin
|
|||||||
DockSiblingName:=Creator.DockSibling;
|
DockSiblingName:=Creator.DockSibling;
|
||||||
DockAlign:=Creator.DockAlign;
|
DockAlign:=Creator.DockAlign;
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF oldPos}
|
||||||
NewBounds.Left:=Min(10000,Max(-10000,NewBounds.Left));
|
NewBounds.Left:=Min(10000,Max(-10000,NewBounds.Left));
|
||||||
NewBounds.Top:=Min(10000,Max(-10000,NewBounds.Top));
|
NewBounds.Top:=Min(10000,Max(-10000,NewBounds.Top));
|
||||||
NewBounds.Right:=Max(NewBounds.Left+100,NewBounds.Right);
|
NewBounds.Right:=Max(NewBounds.Left+100,NewBounds.Right);
|
||||||
NewBounds.Bottom:=Max(NewBounds.Top+100,NewBounds.Bottom);
|
NewBounds.Bottom:=Max(NewBounds.Top+100,NewBounds.Bottom);
|
||||||
|
{$ELSE}
|
||||||
|
NewBounds := FitToMonitor(NewBounds);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TIDEEasyDockMaster.Create;
|
constructor TIDEEasyDockMaster.Create;
|
||||||
@ -171,8 +223,10 @@ var
|
|||||||
begin
|
begin
|
||||||
debugln(['TIDEEasyDockMaster.MakeIDEWindowDockSite BEFORE ',DbgSName(AForm),' ',dbgs(AForm.BoundsRect)]);
|
debugln(['TIDEEasyDockMaster.MakeIDEWindowDockSite BEFORE ',DbgSName(AForm),' ',dbgs(AForm.BoundsRect)]);
|
||||||
GetDefaultBounds(AForm,Creator,NewBounds,DockSiblingName,DockAlign);
|
GetDefaultBounds(AForm,Creator,NewBounds,DockSiblingName,DockAlign);
|
||||||
if Creator<>nil then
|
if Creator<>nil then begin
|
||||||
|
debugln(['TIDEEasyDockMaster.MakeIDEWindowDockSite Creator ',DbgSName(AForm),' ',dbgs(NewBounds)]);
|
||||||
AForm.BoundsRect:=NewBounds;
|
AForm.BoundsRect:=NewBounds;
|
||||||
|
end;
|
||||||
DockMaster.AddElasticSites(AForm, ASides);
|
DockMaster.AddElasticSites(AForm, ASides);
|
||||||
debugln(['TIDEEasyDockMaster.MakeIDEWindowDockSite AFTER ',DbgSName(AForm),' ',dbgs(AForm.BoundsRect)]);
|
debugln(['TIDEEasyDockMaster.MakeIDEWindowDockSite AFTER ',DbgSName(AForm),' ',dbgs(AForm.BoundsRect)]);
|
||||||
end;
|
end;
|
||||||
@ -240,17 +294,35 @@ var
|
|||||||
AControl: TControl;
|
AControl: TControl;
|
||||||
begin
|
begin
|
||||||
debugln(['TIDEEasyDockMaster.ShowForm ',DbgSName(AForm),' BringToFront=',BringToFront,' IsDockSite=',IsDockSite(AForm),' IsDockable=',IsDockable(AForm)]);
|
debugln(['TIDEEasyDockMaster.ShowForm ',DbgSName(AForm),' BringToFront=',BringToFront,' IsDockSite=',IsDockSite(AForm),' IsDockable=',IsDockable(AForm)]);
|
||||||
|
{$IFDEF oldPos}
|
||||||
|
{$ELSE}
|
||||||
|
if AForm.HostDockSite <> nil then begin
|
||||||
|
//check host dock site position?
|
||||||
|
Parent:=GetParentForm(AForm);
|
||||||
|
Parent.BoundsRect := FitToMonitor(Parent.BoundsRect);
|
||||||
|
exit; //never move docked forms
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
//Somewhere down here the form shrinks to the bottom right of the screen.
|
||||||
|
|
||||||
|
//This prevents minimizing, but does not force initial show
|
||||||
|
//if AForm.Visible then exit;
|
||||||
|
|
||||||
try
|
try
|
||||||
AForm.DisableAlign;
|
AForm.DisableAlign;
|
||||||
if AForm.HostDockSite<>nil then
|
if AForm.HostDockSite<>nil then
|
||||||
begin
|
begin
|
||||||
// already docked
|
// already docked - check dkDock?
|
||||||
|
//MakeIDEWindowDockable(AForm);
|
||||||
end else if not (IsDockSite(AForm) or IsDockable(AForm)) then
|
end else if not (IsDockSite(AForm) or IsDockable(AForm)) then
|
||||||
begin
|
begin
|
||||||
// this form was not yet docked
|
// this form was not yet docked
|
||||||
// place it at a default position and make it dockable
|
// place it at a default position and make it dockable
|
||||||
GetDefaultBounds(AForm,Creator,NewBounds,DockSiblingName,DockAlign);
|
GetDefaultBounds(AForm,Creator,NewBounds,DockSiblingName,DockAlign);
|
||||||
if Creator<>nil then
|
DebugLn('default bounds: ', DbgS(NewBounds));
|
||||||
|
{$IFDEF oldPos}
|
||||||
|
if (Creator<>nil) then
|
||||||
begin
|
begin
|
||||||
// this window should become dockable
|
// this window should become dockable
|
||||||
NewBounds.Left:=Min(10000,Max(-10000,NewBounds.Left));
|
NewBounds.Left:=Min(10000,Max(-10000,NewBounds.Left));
|
||||||
@ -281,6 +353,15 @@ begin
|
|||||||
MakeIDEWindowDockable(AForm);
|
MakeIDEWindowDockable(AForm);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
{$ELSE}
|
||||||
|
begin
|
||||||
|
AForm.BoundsRect := FitToMonitor(NewBounds);
|
||||||
|
DebugLn('default bounds: ', DbgS(NewBounds));
|
||||||
|
//AForm.BoundsRect := NewBounds;
|
||||||
|
MakeIDEWindowDockable(AForm);
|
||||||
|
DebugLn('After MakeDockable: ', DbgS(NewBounds));
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
finally
|
finally
|
||||||
@ -294,6 +375,7 @@ begin
|
|||||||
AControl.Visible:=true;
|
AControl.Visible:=true;
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
AControl.Visible := True;
|
AControl.Visible := True;
|
||||||
|
//if AControl.Parent = nil then AControl.BoundsRect := NewBounds; //top form, if floating
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
AControl:=AControl.Parent;
|
AControl:=AControl.Parent;
|
||||||
end;
|
end;
|
||||||
@ -301,11 +383,16 @@ begin
|
|||||||
|
|
||||||
if BringToFront then begin
|
if BringToFront then begin
|
||||||
Parent:=GetParentForm(AForm);
|
Parent:=GetParentForm(AForm);
|
||||||
if Parent<>nil then
|
if Parent<>nil then begin
|
||||||
Parent.ShowOnTop;
|
Parent.ShowOnTop;
|
||||||
|
//Parent.BoundsRect := FitToMonitor(NewBounds);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
debugln(['TIDEEasyDockMaster.ShowForm END ',DbgSName(AForm),' ',dbgs(AForm.BoundsRect)]);
|
Parent:=GetParentForm(AForm);
|
||||||
|
if Parent <> nil then
|
||||||
|
debugln(['TIDEEasyDockMaster.ShowForm END Parent ',dbgs(Parent.BoundsRect)]);
|
||||||
|
debugln(['TIDEEasyDockMaster.ShowForm END ',DbgSName(AForm),' ',dbgs(AForm.BoundsRect)])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TIDEEasyDockMaster.CloseAll;
|
procedure TIDEEasyDockMaster.CloseAll;
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
|
<Version Value="9"/>
|
||||||
<PathDelim Value="\"/>
|
<PathDelim Value="\"/>
|
||||||
<Version Value="7"/>
|
|
||||||
<General>
|
<General>
|
||||||
<Flags>
|
<Flags>
|
||||||
<AlwaysBuild Value="False"/>
|
|
||||||
<LRSInOutputDirectory Value="False"/>
|
<LRSInOutputDirectory Value="False"/>
|
||||||
</Flags>
|
</Flags>
|
||||||
<SessionStorage Value="InIDEConfig"/>
|
<SessionStorage Value="InIDEConfig"/>
|
||||||
<MainUnit Value="0"/>
|
<MainUnit Value="0"/>
|
||||||
<TargetFileExt Value=".exe"/>
|
|
||||||
<Title Value="EasyDocking"/>
|
<Title Value="EasyDocking"/>
|
||||||
</General>
|
</General>
|
||||||
<VersionInfo>
|
<VersionInfo>
|
||||||
<StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion=""/>
|
<StringTable ProductVersion=""/>
|
||||||
</VersionInfo>
|
</VersionInfo>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
<DestinationDirectory Value="D:\Tests\dockmanager"/>
|
<DestinationDirectory Value="D:\Tests\dockmanager"/>
|
||||||
@ -73,12 +74,13 @@
|
|||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="8"/>
|
<Version Value="11"/>
|
||||||
<PathDelim Value="\"/>
|
<PathDelim Value="\"/>
|
||||||
<Parsing>
|
<Parsing>
|
||||||
<SyntaxOptions>
|
<SyntaxOptions>
|
||||||
<CStyleOperator Value="False"/>
|
<CStyleOperator Value="False"/>
|
||||||
<IncludeAssertionCode Value="True"/>
|
<IncludeAssertionCode Value="True"/>
|
||||||
|
<UseAnsiStrings Value="False"/>
|
||||||
</SyntaxOptions>
|
</SyntaxOptions>
|
||||||
</Parsing>
|
</Parsing>
|
||||||
<Other>
|
<Other>
|
||||||
|
@ -356,6 +356,9 @@ function FindOwnedComponent(const AName: string; AOwner: TComponent): TComponen
|
|||||||
const
|
const
|
||||||
CustomDockSiteID = 1;
|
CustomDockSiteID = 1;
|
||||||
//var AppDockBookClass: TDockBookClass;
|
//var AppDockBookClass: TDockBookClass;
|
||||||
|
AlignNames: array[TAlign] of string = (
|
||||||
|
'alNone', 'alTop', 'alBottom', 'alLeft', 'alRight', 'alClient', 'alCustom'
|
||||||
|
);
|
||||||
|
|
||||||
var //debug only, these are valid only until drop
|
var //debug only, these are valid only until drop
|
||||||
DropOn: TControl;
|
DropOn: TControl;
|
||||||
|
@ -196,6 +196,7 @@ begin
|
|||||||
{$ELSE}
|
{$ELSE}
|
||||||
po := AForm; //owned by the form - proper destruction
|
po := AForm; //owned by the form - proper destruction
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
DebugLn('AddElastic BEFORE %s %s', [AForm.Name, DbgS(AForm.BoundsRect)]);
|
||||||
AForm.DisableAlign;
|
AForm.DisableAlign;
|
||||||
for side := low(side) to high(side) do begin
|
for side := low(side) to high(side) do begin
|
||||||
if (side in AllowedSides) and (side in Sides) then begin
|
if (side in AllowedSides) and (side in Sides) then begin
|
||||||
@ -245,7 +246,9 @@ begin
|
|||||||
LastPanel := pnl; //for reload layout
|
LastPanel := pnl; //for reload layout
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
DebugLn('AddElastic added %s %s', [AForm.Name, DbgS(AForm.BoundsRect)]);
|
||||||
AForm.EnableAlign;
|
AForm.EnableAlign;
|
||||||
|
DebugLn('AddElastic AFTER %s %s', [AForm.Name, DbgS(AForm.BoundsRect)]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDockMaster.CreateDockable(const AName: string;
|
function TDockMaster.CreateDockable(const AName: string;
|
||||||
@ -498,6 +501,8 @@ Notebooks?
|
|||||||
site.EnableAutoSizing;
|
site.EnableAutoSizing;
|
||||||
site.Show;
|
site.Show;
|
||||||
end;
|
end;
|
||||||
|
// --- debug ---
|
||||||
|
//DumpSites; - crash! ???
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDockMaster.SaveToStream(Stream: TStream);
|
procedure TDockMaster.SaveToStream(Stream: TStream);
|
||||||
|
Loading…
Reference in New Issue
Block a user