anchordocking: restore custom dock site: restore splitter position

git-svn-id: trunk@26205 -
This commit is contained in:
mattias 2010-06-20 12:49:26 +00:00
parent 0eb9153024
commit 22d9391ac8
2 changed files with 46 additions and 9 deletions

View File

@ -65,18 +65,17 @@
- design time package for IDE - design time package for IDE
- dnd move page index - dnd move page index
- dnd move page to another pagecontrol - dnd move page to another pagecontrol
- on close button: save a restore layout
ToDo: ToDo:
- smaller header - restore custom dock site size
- undock on hide
- option: hide caption - option: hide caption
- list of default layouts
- make options a frame
- popup menu - popup menu
- shrink side left, top, right, bottom - shrink side left, top, right, bottom
- simple way to make forms dockable at designtime - simple way to make forms dockable at designtime
- minimize button and Hide => show in header - minimize button and Hide => show in header
- on close button: save a default layout - on show again: restore layout
- on show again: restore a default layout
- close button for pages - close button for pages
} }
unit AnchorDocking; unit AnchorDocking;
@ -344,7 +343,7 @@ type
procedure ResetBounds(Force: Boolean); override; procedure ResetBounds(Force: Boolean); override;
procedure SaveToStream(Stream: TStream); override; procedure SaveToStream(Stream: TStream); override;
function GetDockEdge(ADockObject: TDragDockObject): boolean; override; function GetDockEdge(ADockObject: TDragDockObject): boolean; override;
procedure RestoreSite; procedure RestoreSite(SplitterPos: integer);
property Site: TWinControl read FSite; // the associated TControl (a TAnchorDockHostSite or a custom dock site) property Site: TWinControl read FSite; // the associated TControl (a TAnchorDockHostSite or a custom dock site)
property DockSite: TAnchorDockHostSite read FDockSite; // if Site is a TAnchorDockHostSite, this is it property DockSite: TAnchorDockHostSite read FDockSite; // if Site is a TAnchorDockHostSite, this is it
@ -1183,7 +1182,8 @@ function TAnchorDockMaster.RestoreLayout(Tree: TAnchorDockLayoutTree): boolean;
Site.Parent:=Parent; Site.Parent:=Parent;
if IsCustomSite(Parent) then begin if IsCustomSite(Parent) then begin
Site.Align:=Node.Align; Site.Align:=Node.Align;
TAnchorDockManager(Parent.DockManager).RestoreSite; //debugln(['TAnchorDockMaster.RestoreLayout.SetupSite Site=',DbgSName(Site),' Site.Bounds=',dbgs(Site.BoundsRect),' BoundSplitterPos=',Node.BoundSplitterPos]);
TAnchorDockManager(Parent.DockManager).RestoreSite(Node.BoundSplitterPos);
Site.HostDockSite:=Parent; Site.HostDockSite:=Parent;
end; end;
if Site is TAnchorDockHostSite then if Site is TAnchorDockHostSite then
@ -1922,6 +1922,10 @@ begin
if Site<>nil then begin if Site<>nil then begin
LayoutNode:=LayoutTree.NewNode(LayoutNode); LayoutNode:=LayoutTree.NewNode(LayoutNode);
Site.SaveLayout(LayoutTree,LayoutNode); Site.SaveLayout(LayoutTree,LayoutNode);
{if Site.BoundSplitter<>nil then begin
LayoutNode:=LayoutTree.NewNode(LayoutNode);
Site.BoundSplitter.SaveLayout(LayoutNode);
end;}
end; end;
end else end else
raise EAnchorDockLayoutError.Create('invalid root control for save: '+DbgSName(AControl)); raise EAnchorDockLayoutError.Create('invalid root control for save: '+DbgSName(AControl));
@ -4032,6 +4036,12 @@ begin
LayoutNode.HeaderPosition:=Header.HeaderPosition; LayoutNode.HeaderPosition:=Header.HeaderPosition;
end else end else
LayoutNode.NodeType:=adltnNone; LayoutNode.NodeType:=adltnNone;
if BoundSplitter<>nil then begin
if Align in [alLeft,alRight] then
LayoutNode.BoundSplitterPos:=BoundSplitter.Left
else
LayoutNode.BoundSplitterPos:=BoundSplitter.Top;
end;
end; end;
constructor TAnchorDockHostSite.Create(AOwner: TComponent); constructor TAnchorDockHostSite.Create(AOwner: TComponent);
@ -4617,7 +4627,7 @@ begin
WidthDiff:=FSiteClientRect.Right-OldSiteClientRect.Right; WidthDiff:=FSiteClientRect.Right-OldSiteClientRect.Right;
HeightDiff:=FSiteClientRect.Bottom-OldSiteClientRect.Bottom; HeightDiff:=FSiteClientRect.Bottom-OldSiteClientRect.Bottom;
//debugln(['TAnchorDockManager.ResetBounds ',dbgs(Child.BaseBounds),' ',WidthDiff,',',HeightDiff]); debugln(['TAnchorDockManager.ResetBounds ',DbgSName(Site),' ',dbgs(Child.BaseBounds),' ',WidthDiff,',',HeightDiff]);
case ResizePolicy of case ResizePolicy of
admrpChild: admrpChild:
begin begin
@ -4710,7 +4720,7 @@ begin
Result:=true; Result:=true;
end; end;
procedure TAnchorDockManager.RestoreSite; procedure TAnchorDockManager.RestoreSite(SplitterPos: integer);
var var
ChildSite: TAnchorDockHostSite; ChildSite: TAnchorDockHostSite;
begin begin
@ -4721,6 +4731,19 @@ begin
if ChildSite<>nil then begin if ChildSite<>nil then begin
ChildSite.CreateBoundSplitter; ChildSite.CreateBoundSplitter;
ChildSite.PositionBoundSplitter; ChildSite.PositionBoundSplitter;
if ChildSite.Align in [alLeft,alRight] then
ChildSite.BoundSplitter.Left:=SplitterPos
else
ChildSite.BoundSplitter.Top:=SplitterPos;
case ChildSite.Align of
alTop: ChildSite.Height:=ChildSite.BoundSplitter.Top;
alBottom: ChildSite.Height:=Site.ClientHeight
-(ChildSite.BoundSplitter.Top+ChildSite.BoundSplitter.Height);
alLeft: ChildSite.Width:=ChildSite.BoundSplitter.Left;
alRight: ChildSite.Width:=Site.ClientWidth
-(ChildSite.BoundSplitter.Left+ChildSite.BoundSplitter.Width);
end;
//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)]);
end; end;
end; end;

View File

@ -69,6 +69,7 @@ type
private private
FAlign: TAlign; FAlign: TAlign;
fAnchors: array[TAnchorKind] of string; fAnchors: array[TAnchorKind] of string;
FBoundSplitterPos: integer;
FBoundsRect: TRect; FBoundsRect: TRect;
FHeaderPosition: TADLHeaderPosition; FHeaderPosition: TADLHeaderPosition;
FMonitor: integer; FMonitor: integer;
@ -89,6 +90,7 @@ type
procedure SetAlign(const AValue: TAlign); procedure SetAlign(const AValue: TAlign);
procedure SetAnchors(Site: TAnchorKind; const AValue: string); procedure SetAnchors(Site: TAnchorKind; const AValue: string);
procedure SetBottom(const AValue: integer); procedure SetBottom(const AValue: integer);
procedure SetBoundSplitterPos(const AValue: integer);
procedure SetBoundsRect(const AValue: TRect); procedure SetBoundsRect(const AValue: TRect);
procedure SetHeaderPosition(const AValue: TADLHeaderPosition); procedure SetHeaderPosition(const AValue: TADLHeaderPosition);
procedure SetHeight(const AValue: integer); procedure SetHeight(const AValue: integer);
@ -143,6 +145,7 @@ type
property Monitor: integer read FMonitor write SetMonitor; property Monitor: integer read FMonitor write SetMonitor;
property HeaderPosition: TADLHeaderPosition read FHeaderPosition write SetHeaderPosition; property HeaderPosition: TADLHeaderPosition read FHeaderPosition write SetHeaderPosition;
property TabPosition: TTabPosition read FTabPosition write SetTabPosition; property TabPosition: TTabPosition read FTabPosition write SetTabPosition;
property BoundSplitterPos: integer read FBoundSplitterPos write SetBoundSplitterPos;
function Count: integer; function Count: integer;
function IsSplitter: boolean; function IsSplitter: boolean;
function IsRootWindow: boolean; function IsRootWindow: boolean;
@ -886,6 +889,13 @@ begin
IncreaseChangeStamp; IncreaseChangeStamp;
end; end;
procedure TAnchorDockLayoutTreeNode.SetBoundSplitterPos(const AValue: integer);
begin
if FBoundSplitterPos=AValue then exit;
FBoundSplitterPos:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockLayoutTreeNode.SetBoundsRect(const AValue: TRect); procedure TAnchorDockLayoutTreeNode.SetBoundsRect(const AValue: TRect);
begin begin
if CompareRect(@FBoundsRect,@AValue) then exit; if CompareRect(@FBoundsRect,@AValue) then exit;
@ -1028,6 +1038,7 @@ begin
or (WindowState<>Node.WindowState) or (WindowState<>Node.WindowState)
or (HeaderPosition<>Node.HeaderPosition) or (HeaderPosition<>Node.HeaderPosition)
or (TabPosition<>Node.TabPosition) or (TabPosition<>Node.TabPosition)
or (BoundSplitterPos<>Node.BoundSplitterPos)
then then
exit; exit;
for a:=low(TAnchorKind) to high(TAnchorKind) do for a:=low(TAnchorKind) to high(TAnchorKind) do
@ -1050,6 +1061,7 @@ begin
WindowState:=Node.WindowState; WindowState:=Node.WindowState;
HeaderPosition:=Node.HeaderPosition; HeaderPosition:=Node.HeaderPosition;
TabPosition:=Node.TabPosition; TabPosition:=Node.TabPosition;
BoundSplitterPos:=Node.BoundSplitterPos;
for a:=low(TAnchorKind) to high(TAnchorKind) do for a:=low(TAnchorKind) to high(TAnchorKind) do
Anchors[a]:=Node.Anchors[a]; Anchors[a]:=Node.Anchors[a];
while Count>Node.Count do Nodes[Count-1].Free; while Count>Node.Count do Nodes[Count-1].Free;
@ -1103,6 +1115,7 @@ begin
Top:=Config.GetValue('Bounds/Top',0); Top:=Config.GetValue('Bounds/Top',0);
Width:=Config.GetValue('Bounds/Width',0); Width:=Config.GetValue('Bounds/Width',0);
Height:=Config.GetValue('Bounds/Height',0); Height:=Config.GetValue('Bounds/Height',0);
BoundSplitterPos:=Config.GetValue('Bounds/SplitterPos',0);
Anchors[akLeft]:=Config.GetValue('Anchors/Left',''); Anchors[akLeft]:=Config.GetValue('Anchors/Left','');
Anchors[akTop]:=Config.GetValue('Anchors/Top',''); Anchors[akTop]:=Config.GetValue('Anchors/Top','');
Anchors[akRight]:=Config.GetValue('Anchors/Right',''); Anchors[akRight]:=Config.GetValue('Anchors/Right','');
@ -1133,6 +1146,7 @@ begin
Config.SetDeleteValue('Bounds/Top',Top,0); Config.SetDeleteValue('Bounds/Top',Top,0);
Config.SetDeleteValue('Bounds/Width',Width,0); Config.SetDeleteValue('Bounds/Width',Width,0);
Config.SetDeleteValue('Bounds/Height',Height,0); Config.SetDeleteValue('Bounds/Height',Height,0);
Config.SetDeleteValue('Bounds/SplitterPos',BoundSplitterPos,0);
Config.SetDeleteValue('Anchors/Left',Anchors[akLeft],''); Config.SetDeleteValue('Anchors/Left',Anchors[akLeft],'');
Config.SetDeleteValue('Anchors/Top',Anchors[akTop],''); Config.SetDeleteValue('Anchors/Top',Anchors[akTop],'');
Config.SetDeleteValue('Anchors/Right',Anchors[akRight],''); Config.SetDeleteValue('Anchors/Right',Anchors[akRight],'');