From 3d405210f99e32c44521bab8749ab5390ef07bc5 Mon Sep 17 00:00:00 2001 From: michl Date: Thu, 24 Jan 2019 18:10:30 +0000 Subject: [PATCH] AnchorDocking: Fixed SimplifyOneControl destroy the layout, Issue #34937 git-svn-id: trunk@60206 - --- components/anchordocking/anchordocking.pas | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/components/anchordocking/anchordocking.pas b/components/anchordocking/anchordocking.pas index 785bbcda2c..bc5b189a2d 100644 --- a/components/anchordocking/anchordocking.pas +++ b/components/anchordocking/anchordocking.pas @@ -4789,7 +4789,7 @@ procedure TAnchorDockHostSite.SimplifyOneControl; var Site: TAnchorDockHostSite; i: Integer; - Child: TControl; + Child, PlaceHolder: TControl; a: TAnchorKind; begin if SiteType<>adhstOneControl then exit; @@ -4813,11 +4813,22 @@ begin Site.BeginUpdateLayout; // move controls from Site to Self + // when a site is moved to a other parent, we have to insert a place holder + // on old site or the splitters will be removed, see issue #34937 i:=Site.ControlCount-1; while i>=0 do begin Child:=Site.Controls[i]; - if Child.Owner<>Site then begin - //debugln(['TAnchorDockHostSite.SimplifyOneControl Self="',Caption,'" Child=',DbgSName(Child),'="',Child.Caption,'"']); + if (Child.Owner<>Site) then begin + if not (Child is TAnchorDockSplitter) then begin + PlaceHolder:=TAnchorDockHostSite.CreateNew(Site); + PlaceHolder.Parent:=Site; + PlaceHolder.Anchors:=Child.Anchors; + for a:=Low(TAnchorKind) to High(TAnchorKind) do + PlaceHolder.AnchorSide[a].Control:=Child.AnchorSide[a].Control; + PlaceHolder.SetBounds(Child.Left, Child.Top, Child.Width, Child.Height); + PlaceHolder.Name:='_'+Child.Name; + PlaceHolder.Visible:=Child.Visible; + end; Child.Parent:=Self; if Child=Site.Pages then begin FPages:=Site.Pages; @@ -4832,6 +4843,15 @@ begin end; i:=Min(i,Site.ControlCount)-1; end; + + for i:=0 to ControlCount-1 do begin + Child:=Controls[i]; + PlaceHolder:=TControl(Site.FindComponent('_'+Child.Name)); + if not Assigned(PlaceHolder) then continue; + for a:=Low(TAnchorKind) to High(TAnchorKind) do + if PlaceHolder.AnchorSide[a].Control<>Site then + Child.AnchorSide[a].Control:=PlaceHolder.AnchorSide[a].Control; + end; Site.EndUpdateLayout; // delete Site