diff --git a/examples/anchordocking/anchordocking.pas b/examples/anchordocking/anchordocking.pas index 534ad7016c..2834b2ebdf 100644 --- a/examples/anchordocking/anchordocking.pas +++ b/examples/anchordocking/anchordocking.pas @@ -299,6 +299,7 @@ type property DockSite: TAnchorDockHostSite read FDockSite; property Site: TWinControl read FSite; property DockableSites: TAnchors read FDockableSites write FDockableSites; + function GetChildSite: TAnchorDockHostSite; end; { TAnchorDockMaster } @@ -1092,19 +1093,37 @@ var Site: TAnchorDockHostSite; SavedSites: TFPList; LayoutNode: TAnchorDockLayoutTreeNode; + AForm: TCustomForm; begin SavedSites:=TFPList.Create; try for i:=0 to ControlCount-1 do begin AControl:=Controls[i]; if not AControl.IsVisible then continue; - Site:=GetParentForm(AControl) as TAnchorDockHostSite; - if SavedSites.IndexOf(Site)>=0 then continue; - SavedSites.Add(Site); - debugln(['TAnchorDockMaster.SaveMainLayoutToTree Site=',DbgSName(Site)]); - DebugWriteChildAnchors(Site); - LayoutNode:=LayoutTree.NewNode(LayoutTree.Root); - Site.SaveLayout(LayoutTree,LayoutNode); + AForm:=GetParentForm(AControl); + if AForm=nil then continue; + if SavedSites.IndexOf(AForm)>=0 then continue; + SavedSites.Add(AForm); + debugln(['TAnchorDockMaster.SaveMainLayoutToTree AForm=',DbgSName(AForm)]); + DebugWriteChildAnchors(AForm); + if (AForm is TAnchorDockHostSite) then begin + Site:=TAnchorDockHostSite(AForm); + LayoutNode:=LayoutTree.NewNode(LayoutTree.Root); + Site.SaveLayout(LayoutTree,LayoutNode); + end else if (AForm.DockManager is TAnchorDockManager) + and (AForm.Parent=nil) then begin + // custom dock site + LayoutNode:=LayoutTree.NewNode(LayoutTree.Root); + LayoutNode.NodeType:=adltnCustomSite; + LayoutNode.Assign(AForm); + // can have one normal dock site + Site:=TAnchorDockManager(AForm.DockManager).GetChildSite; + if Site<>nil then begin + LayoutNode:=LayoutTree.NewNode(LayoutNode); + Site.SaveLayout(LayoutTree,LayoutNode); + end; + end else + raise EAnchorDockLayoutError.Create('invalid root control class '+DbgSName(AControl)); end; finally SavedSites.Free; @@ -3409,6 +3428,18 @@ begin Result:=true; end; +function TAnchorDockManager.GetChildSite: TAnchorDockHostSite; +var + i: Integer; +begin + for i:=0 to Site.ControlCount-1 do + if Site.Controls[i] is TAnchorDockHostSite then begin + Result:=TAnchorDockHostSite(Site.Controls[i]); + exit; + end; + Result:=nil; +end; + { TAnchorDockSplitter } procedure TAnchorDockSplitter.SetResizeAnchor(const AValue: TAnchorKind); diff --git a/examples/anchordocking/anchordockstorage.pas b/examples/anchordocking/anchordockstorage.pas index f8aeed3a9a..6e4e8ba35d 100644 --- a/examples/anchordocking/anchordockstorage.pas +++ b/examples/anchordocking/anchordockstorage.pas @@ -47,7 +47,8 @@ type adltnControl, adltnSplitterHorizontal, adltnSplitterVertical, - adltnPages + adltnPages, + adltnCustomSite ); TADLTreeNodeTypes = set of TADLTreeNodeType; @@ -199,7 +200,8 @@ const 'Control', 'SplitterHorizontal', 'SplitterVertical', - 'Pages' + 'Pages', + 'CustomSite' ); ADLWindowStateNames: array[TWindowState] of string = ( 'Normal', @@ -964,7 +966,7 @@ var begin Name:=AControl.Name; BoundsRect:=AControl.BoundsRect; - if (AControl.Parent<>nil) and (AControl is TCustomForm) then begin + if (AControl.Parent=nil) and (AControl is TCustomForm) then begin WindowState:=TCustomForm(AControl).WindowState; Monitor:=TCustomForm(AControl).Monitor.MonitorNum; end else @@ -1114,12 +1116,16 @@ begin dbgs(Side), '"', Anchors[Side], '"'])); end; end; - // only the root node, pages and layouts can have children - if (Parent<>nil) and (Count>0) and (not (NodeType in [adltnLayout,adltnPages])) + // only the root node, pages, layouts and customsite can have children + if (Parent<>nil) and (Count>0) + and (not (NodeType in [adltnLayout,adltnPages,adltnCustomSite])) then raise EAnchorDockLayoutError.Create( Format(adrsNoChildrenAllowedForNodeType, ['"', Name, '"', ADLTreeNodeTypeNames[NodeType]])); + if (NodeType=adltnCustomSite) and (Count>1) then + raise EAnchorDockLayoutError.Create(Format( + adrsCustomDockSiteCanHaveOnlyOneSite, ['"', Name, '"'])); // check grandchild for i:=0 to Count-1 do begin @@ -1153,6 +1159,8 @@ begin // delete all children while ChildNode.Count>0 do ChildNode[0].Free; + end else if ChildNode.NodeType=adltnCustomSite then begin + // custom dock site end else if ChildNode.Count=0 then begin // inner node without child => delete DeleteNode(ChildNode); diff --git a/examples/anchordocking/anchordockstr.pas b/examples/anchordocking/anchordockstr.pas index 973f3b1080..f9da7362c6 100644 --- a/examples/anchordocking/anchordockstr.pas +++ b/examples/anchordocking/anchordockstr.pas @@ -63,6 +63,8 @@ resourcestring +'splitter: Node=%s%s%s Anchors[%s]=%s%s%s'; adrsNoChildrenAllowedForNodeType = 'No children allowed for Node=%s%s%s ' +'Type=%s'; + adrsCustomDockSiteCanHaveOnlyOneSite = 'Custom dock site %s%s%s can have ' + +'only one site.'; adrsEmptyName = 'Empty name: '; adrsDuplicateName = 'Duplicate name: ';