anchordocking: fixed loading settings, fixed ignoring invalid Monitor.WorkareaRect

git-svn-id: trunk@30238 -
This commit is contained in:
mattias 2011-04-08 02:56:18 +00:00
parent 9c26e8ecf5
commit af4ddf60a7
3 changed files with 80 additions and 34 deletions

View File

@ -4,11 +4,15 @@
<Name Value="AnchorDocking"/> <Name Value="AnchorDocking"/>
<Author Value="Mattias Gaertner mattias@freepascal.org"/> <Author Value="Mattias Gaertner mattias@freepascal.org"/>
<CompilerOptions> <CompilerOptions>
<Version Value="9"/> <Version Value="10"/>
<SearchPaths> <SearchPaths>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths> </SearchPaths>
<Other> <Other>
<CompilerMessages>
<UseMsgFile Value="True"/>
</CompilerMessages>
<CustomOptions Value="$(IDEBuildOptions)"/>
<CompilerPath Value="$(CompPath)"/> <CompilerPath Value="$(CompPath)"/>
</Other> </Other>
</CompilerOptions> </CompilerOptions>
@ -44,7 +48,7 @@
<UnitName Value="AnchorDockOptionsDlg"/> <UnitName Value="AnchorDockOptionsDlg"/>
</Item6> </Item6>
</Files> </Files>
<LazDoc Paths="doc/"/> <LazDoc Paths="doc"/>
<i18n> <i18n>
<EnableI18N Value="True"/> <EnableI18N Value="True"/>
<OutDir Value="languages"/> <OutDir Value="languages"/>
@ -60,7 +64,7 @@
</Item2> </Item2>
</RequiredPkgs> </RequiredPkgs>
<UsageOptions> <UsageOptions>
<UnitPath Value="$(PkgOutDir)/"/> <UnitPath Value="$(PkgOutDir)"/>
</UsageOptions> </UsageOptions>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>

View File

@ -1217,7 +1217,7 @@ var
function ScaleY(p: integer; const SrcRect: TRect): integer; function ScaleY(p: integer; const SrcRect: TRect): integer;
begin begin
Result:=p; Result:=p;
if SrcRectValid(SrcRect) then if SrcRectValid(SrcRect) and SrcRectValid(WorkArea) then
Result:=((p-SrcRect.Top)*(WorkArea.Bottom-WorkArea.Top)) Result:=((p-SrcRect.Top)*(WorkArea.Bottom-WorkArea.Top))
div (SrcRect.Bottom-SrcRect.Top) div (SrcRect.Bottom-SrcRect.Top)
+WorkArea.Top; +WorkArea.Top;
@ -1232,7 +1232,9 @@ var
begin begin
if Parent=nil then begin if Parent=nil then begin
WorkArea:=Site.Monitor.WorkareaRect; WorkArea:=Site.Monitor.WorkareaRect;
//debugln(['SetupSite WorkArea=',dbgs(WorkArea)]); {$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.SetupSite WorkArea=',dbgs(WorkArea)]);
{$ENDIF}
end; end;
if IsCustomSite(Site) then begin if IsCustomSite(Site) then begin
aManager:=TAnchorDockManager(Site.DockManager); aManager:=TAnchorDockManager(Site.DockManager);
@ -1244,16 +1246,22 @@ var
Site.Constraints.MaxWidth:=0; Site.Constraints.MaxWidth:=0;
Site.Constraints.MaxHeight:=0; Site.Constraints.MaxHeight:=0;
NewBounds:=Node.BoundsRect; NewBounds:=Node.BoundsRect;
if Parent=nil then if Parent=nil then begin
NewBounds:=Rect(ScaleX(NewBounds.Left,SrcRect),ScaleY(NewBounds.Top,SrcRect), NewBounds:=Rect(ScaleX(NewBounds.Left,SrcRect),ScaleY(NewBounds.Top,SrcRect),
ScaleX(NewBounds.Right,SrcRect),ScaleY(NewBounds.Bottom,SrcRect)); ScaleX(NewBounds.Right,SrcRect),ScaleY(NewBounds.Bottom,SrcRect));
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.SetupSite scale Site=',DbgSName(Site),' OldWorkArea=',dbgs(SrcRect),' CurWorkArea=',dbgs(WorkArea),' OldBounds=',dbgs(Node.BoundsRect),' NewBounds=',dbgs(NewBounds)]);
{$ENDIF}
end;
Site.BoundsRect:=NewBounds; Site.BoundsRect:=NewBounds;
Site.Visible:=true; Site.Visible:=true;
Site.Parent:=Parent; Site.Parent:=Parent;
if IsCustomSite(Parent) then begin if IsCustomSite(Parent) then begin
aManager:=TAnchorDockManager(Parent.DockManager); aManager:=TAnchorDockManager(Parent.DockManager);
Site.Align:=Node.Align; Site.Align:=Node.Align;
//debugln(['TAnchorDockMaster.RestoreLayout.SetupSite Site=',DbgSName(Site),' Site.Bounds=',dbgs(Site.BoundsRect),' BoundSplitterPos=',Node.BoundSplitterPos]); {$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.SetupSite custom Site=',DbgSName(Site),' Site.Bounds=',dbgs(Site.BoundsRect),' BoundSplitterPos=',Node.BoundSplitterPos]);
{$ENDIF}
aManager.RestoreSite(Node.BoundSplitterPos); aManager.RestoreSite(Node.BoundSplitterPos);
Site.HostDockSite:=Parent; Site.HostDockSite:=Parent;
end; end;
@ -1285,7 +1293,9 @@ var
Result:=nil; Result:=nil;
if Scale and SrcRectValid(Node.WorkAreaRect) then if Scale and SrcRectValid(Node.WorkAreaRect) then
SrcRect:=Node.WorkAreaRect; SrcRect:=Node.WorkAreaRect;
//debugln(['Restore ',Node.Name,' ',dbgs(Node.NodeType),' Bounds=',dbgs(Node.BoundsRect),' Parent=',DbgSName(Parent),' ']); {$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.Restore ',Node.Name,' ',dbgs(Node.NodeType),' Bounds=',dbgs(Node.BoundsRect),' Parent=',DbgSName(Parent),' ']);
{$ENDIF}
if Node.NodeType=adltnControl then begin if Node.NodeType=adltnControl then begin
// restore control // restore control
// the control was already created // the control was already created
@ -1301,7 +1311,9 @@ var
else else
ClearLayoutProperties(AControl); ClearLayoutProperties(AControl);
Site:=AControl.HostDockSite as TAnchorDockHostSite; Site:=AControl.HostDockSite as TAnchorDockHostSite;
//debugln(['Restore Control Node.Name=',Node.Name,' Control=',DbgSName(AControl),' Site=',DbgSName(Site)]); {$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.Restore Control Node.Name=',Node.Name,' Control=',DbgSName(AControl),' Site=',DbgSName(Site)]);
{$ENDIF}
AControl.Visible:=true; AControl.Visible:=true;
SetupSite(Site,Node,Parent,SrcRect); SetupSite(Site,Node,Parent,SrcRect);
Result:=Site; Result:=Site;
@ -1332,7 +1344,9 @@ var
Splitter:=CreateSplitter; Splitter:=CreateSplitter;
fTreeNameToDocker[Node.Name]:=Splitter; fTreeNameToDocker[Node.Name]:=Splitter;
end; end;
//debugln(['Restore Splitter Node.Name=',Node.Name,' ',dbgs(Node.NodeType),' Splitter=',DbgSName(Splitter)]); {$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.Restore Splitter Node.Name=',Node.Name,' ',dbgs(Node.NodeType),' Splitter=',DbgSName(Splitter)]);
{$ENDIF}
Splitter.Parent:=Parent; Splitter.Parent:=Parent;
NewBounds:=Node.BoundsRect; NewBounds:=Node.BoundsRect;
if SrcRectValid(SrcRect) then if SrcRectValid(SrcRect) then
@ -1353,7 +1367,9 @@ var
fDisabledAutosizing.Add(Site); fDisabledAutosizing.Add(Site);
fTreeNameToDocker[Node.Name]:=Site; fTreeNameToDocker[Node.Name]:=Site;
end; end;
//debugln(['Restore Layout Node.Name=',Node.Name,' ChildCount=',Node.Count]); {$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.Restore Layout Node.Name=',Node.Name,' ChildCount=',Node.Count]);
{$ENDIF}
Site.BeginUpdateLayout; Site.BeginUpdateLayout;
try try
SetupSite(Site,Node,Parent,SrcRect); SetupSite(Site,Node,Parent,SrcRect);
@ -1366,7 +1382,9 @@ var
for i:=0 to Node.Count-1 do begin for i:=0 to Node.Count-1 do begin
ChildNode:=Node[i]; ChildNode:=Node[i];
AControl:=fTreeNameToDocker[ChildNode.Name]; AControl:=fTreeNameToDocker[ChildNode.Name];
//debugln([' Restore layout child anchors Site=',DbgSName(Site),' ChildNode.Name=',ChildNode.Name,' Control=',DbgSName(AControl)]); {$IFDEF VerboseAnchorDockRestore}
debugln([' Restore layout child anchors Site=',DbgSName(Site),' ChildNode.Name=',ChildNode.Name,' Control=',DbgSName(AControl)]);
{$ENDIF}
if AControl=nil then continue; if AControl=nil then continue;
for Side:=Low(TAnchorKind) to high(TAnchorKind) do begin for Side:=Low(TAnchorKind) to high(TAnchorKind) do begin
if ((ChildNode.NodeType=adltnSplitterHorizontal) if ((ChildNode.NodeType=adltnSplitterHorizontal)
@ -2173,8 +2191,10 @@ begin
RestoreLayouts.LoadFromConfig(Config); RestoreLayouts.LoadFromConfig(Config);
Config.UndoAppendBasePath; Config.UndoAppendBasePath;
//WriteDebugLayout('TAnchorDockMaster.LoadLayoutFromConfig ',Tree.Root); {$IFDEF VerboseAnchorDockRestore}
//DebugWriteChildAnchors(Tree.Root); WriteDebugLayout('TAnchorDockMaster.LoadLayoutFromConfig ',Tree.Root);
DebugWriteChildAnchors(Tree.Root);
{$ENDIF}
// close all unneeded forms/controls // close all unneeded forms/controls
if not CloseUnneededControls(Tree) then exit; if not CloseUnneededControls(Tree) then exit;
@ -2186,13 +2206,17 @@ begin
// simplify layouts // simplify layouts
ControlNames.Sort; ControlNames.Sort;
//debugln(['TAnchorDockMaster.LoadLayoutFromConfig controls: ']); {$IFDEF VerboseAnchorDockRestore}
//debugln(ControlNames.Text); debugln(['TAnchorDockMaster.LoadLayoutFromConfig controls: ']);
debugln(ControlNames.Text);
{$ENDIF}
Tree.Root.Simplify(ControlNames); Tree.Root.Simplify(ControlNames);
// reuse existing sites to reduce flickering // reuse existing sites to reduce flickering
MapTreeToControls(Tree); MapTreeToControls(Tree);
//fTreeNameToDocker.WriteDebugReport('TAnchorDockMaster.LoadLayoutFromConfig Map'); {$IFDEF VerboseAnchorDockRestore}
fTreeNameToDocker.WriteDebugReport('TAnchorDockMaster.LoadLayoutFromConfig Map');
{$ENDIF}
// create sites // create sites
RestoreLayout(Tree,Scale); RestoreLayout(Tree,Scale);
@ -2207,7 +2231,9 @@ begin
// commit (this can raise an exception) // commit (this can raise an exception)
EnableAllAutoSizing; EnableAllAutoSizing;
end; end;
//DebugWriteChildAnchors(Application.MainForm,true,false); {$IFDEF VerboseAnchorDockRestore}
DebugWriteChildAnchors(Application.MainForm,true,false);
{$ENDIF}
Result:=true; Result:=true;
end; end;
@ -2216,16 +2242,16 @@ begin
Config.AppendBasePath('Settings/'); Config.AppendBasePath('Settings/');
DragTreshold:=Config.GetValue('DragThreshold',4); DragTreshold:=Config.GetValue('DragThreshold',4);
DockOutsideMargin:=Config.GetValue('DockOutsideMargin',10); DockOutsideMargin:=Config.GetValue('DockOutsideMargin',10);
DockParentMargin:=Config.GetValue('DockOutsideMargin',10); DockParentMargin:=Config.GetValue('DockParentMargin',10);
PageAreaInPercent:=Config.GetValue('DockOutsideMargin',40); PageAreaInPercent:=Config.GetValue('PageAreaInPercent',40);
HeaderAlignTop:=Config.GetValue('DockOutsideMargin',80); HeaderAlignTop:=Config.GetValue('HeaderAlignTop',80);
HeaderAlignLeft:=Config.GetValue('DockOutsideMargin',120); HeaderAlignLeft:=Config.GetValue('HeaderAlignLeft',120);
SplitterWidth:=Config.GetValue('DockOutsideMargin',4); SplitterWidth:=Config.GetValue('SplitterWidth',4);
ScaleOnResize:=Config.GetValue('DockOutsideMargin',true); ScaleOnResize:=Config.GetValue('ScaleOnResize',true);
ShowHeaderCaption:=Config.GetValue('DockOutsideMargin',true); ShowHeaderCaption:=Config.GetValue('ShowHeaderCaption',true);
HideHeaderCaptionFloatingControl:=Config.GetValue('DockOutsideMargin',true); HideHeaderCaptionFloatingControl:=Config.GetValue('HideHeaderCaptionFloatingControl',true);
AllowDragging:=Config.GetValue('DockOutsideMargin',true); AllowDragging:=Config.GetValue('AllowDragging',true);
HeaderButtonSize:=Config.GetValue('DockOutsideMargin',10); HeaderButtonSize:=Config.GetValue('HeaderButtonSize',10);
//property HeaderHint: string read FHeaderHint write FHeaderHint; //property HeaderHint: string read FHeaderHint write FHeaderHint;
@ -4889,7 +4915,9 @@ var
b:=TAnchorDockSplitter(AControl).DockRestoreBounds; b:=TAnchorDockSplitter(AControl).DockRestoreBounds;
if (b.Right<=b.Left) or (b.Bottom<=b.Top) then if (b.Right<=b.Left) or (b.Bottom<=b.Top) then
b:=AControl.BoundsRect; b:=AControl.BoundsRect;
//debugln(['TAnchorDockManager.ResetBounds RESTORE ',DbgSName(AControl),' Cur=',dbgs(AControl.BoundsRect),' Restore=',dbgs(b)]); {$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockManager.ResetBounds RESTORE ',DbgSName(AControl),' Cur=',dbgs(AControl.BoundsRect),' Restore=',dbgs(b)]);
{$ENDIF}
if AControl is TAnchorDockSplitter then begin if AControl is TAnchorDockSplitter then begin
// fit splitter into clientarea // fit splitter into clientarea
if AControl.AnchorSide[akLeft].Control=nil then if AControl.AnchorSide[akLeft].Control=nil then
@ -4918,7 +4946,9 @@ var
Child:=GetChildSite; Child:=GetChildSite;
if Child=nil then exit; if Child=nil then exit;
//debugln(['TAnchorDockManager.ResetBounds ',DbgSName(Site),' ',dbgs(Child.BaseBounds),' ',WidthDiff,',',HeightDiff]); {$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockManager.ResetBounds ',DbgSName(Site),' ',dbgs(Child.BaseBounds),' ',WidthDiff,',',HeightDiff]);
{$ENDIF}
ChildMaxSize:=Point(Site.ClientWidth-DockMaster.SplitterWidth, ChildMaxSize:=Point(Site.ClientWidth-DockMaster.SplitterWidth,
Site.ClientHeight-DockMaster.SplitterWidth); Site.ClientHeight-DockMaster.SplitterWidth);
if PreferredSiteSizeAsSiteMinimum then begin if PreferredSiteSizeAsSiteMinimum then begin
@ -4938,7 +4968,9 @@ var
Child.Width:=Max(1,Min(ChildMaxSize.X,Child.Width+WidthDiff)) Child.Width:=Max(1,Min(ChildMaxSize.X,Child.Width+WidthDiff))
else begin else begin
i:=Max(1,Min(ChildMaxSize.Y,Child.Height+HeightDiff)); i:=Max(1,Min(ChildMaxSize.Y,Child.Height+HeightDiff));
//debugln(['TAnchorDockManager.ResetBounds Child=',DbgSName(Child),' OldHeight=',Child.Height,' NewHeight=',i]); {$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockManager.ResetBounds Child=',DbgSName(Child),' OldHeight=',Child.Height,' NewHeight=',i]);
{$ENDIF}
Child.Height:=i; Child.Height:=i;
end; end;
end; end;
@ -5042,7 +5074,9 @@ begin
FSiteClientRect:=Site.ClientRect; FSiteClientRect:=Site.ClientRect;
if DockSite<>nil then exit; if DockSite<>nil then exit;
ChildSite:=GetChildSite; ChildSite:=GetChildSite;
//debugln(['TAnchorDockManager.RestoreSite ',DbgSName(Site),' ChildSite=',DbgSName(ChildSite)]); {$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockManager.RestoreSite START ',DbgSName(Site),' ChildSite=',DbgSName(ChildSite)]);
{$ENDIF}
if ChildSite<>nil then begin if ChildSite<>nil then begin
ChildSite.CreateBoundSplitter; ChildSite.CreateBoundSplitter;
ChildSite.PositionBoundSplitter; ChildSite.PositionBoundSplitter;
@ -5060,7 +5094,9 @@ begin
end; end;
// only allow to dock one control // only allow to dock one control
DragManager.RegisterDockSite(Site,false); DragManager.RegisterDockSite(Site,false);
//debugln(['TAnchorDockManager.RestoreSite ',DbgSName(Site),' ChildSite=',DbgSName(ChildSite),' Site.Bounds=',dbgs(Site.BoundsRect),' Site.Client=',dbgs(Site.ClientRect),' ChildSite.Bounds=',dbgs(ChildSite.BoundsRect),' Splitter.Bounds=',dbgs(ChildSite.BoundSplitter.BoundsRect)]); {$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockManager.RestoreSite ',DbgSName(Site),' ChildSite=',DbgSName(ChildSite),' Site.Bounds=',dbgs(Site.BoundsRect),' Site.Client=',dbgs(Site.ClientRect),' ChildSite.Bounds=',dbgs(ChildSite.BoundsRect),' Splitter.Bounds=',dbgs(ChildSite.BoundSplitter.BoundsRect)]);
{$ENDIF}
end; end;
end; end;

View File

@ -759,11 +759,17 @@ procedure DebugWriteChildAnchors(RootNode: TAnchorDockLayoutTreeNode);
DbgOut(Prefix); DbgOut(Prefix);
DbgOut('"'+Node.Name+'"'); DbgOut('"'+Node.Name+'"');
DbgOut(' Type='+dbgs(Node.NodeType)); DbgOut(' Type='+dbgs(Node.NodeType));
DbgOut(' Bounds=',dbgs(Node.BoundsRect)); DbgOut(' Bounds=',dbgs(Node.BoundsRect)
,',w=',dbgs(Node.BoundsRect.Right-Node.BoundsRect.Left)
,',h=',dbgs(Node.BoundsRect.Bottom-Node.BoundsRect.Top));
if Node.WindowState<>wsNormal then if Node.WindowState<>wsNormal then
DbgOut(' WindowState=',dbgs(Node.WindowState)); DbgOut(' WindowState=',dbgs(Node.WindowState));
if Node.Monitor<>0 then if Node.Monitor<>0 then
DbgOut(' Monitor=',dbgs(Node.Monitor)); DbgOut(' Monitor=',dbgs(Node.Monitor));
if Node.BoundSplitterPos<>0 then
DbgOut(' SplitterPos=',dbgs(Node.BoundSplitterPos));
if (Node.WorkAreaRect.Right>0) and (Node.WorkAreaRect.Bottom>0) then
DbgOut(' WorkArea=',dbgs(Node.WorkAreaRect));
debugln; debugln;
for a:=low(TAnchorKind) to high(TAnchorKind) do begin for a:=low(TAnchorKind) to high(TAnchorKind) do begin
if Node.Anchors[a]<>'' then if Node.Anchors[a]<>'' then