mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-28 10:49:14 +02:00
anchordocking: restore custom dock site child
git-svn-id: trunk@26035 -
This commit is contained in:
parent
f987a5217d
commit
7a85daf14a
@ -338,6 +338,7 @@ type
|
||||
function RestoreLayout(Tree: TAnchorDockLayoutTree;
|
||||
TreeNameToDocker: TADNameToControl): boolean;
|
||||
function DoCreateControl(aName: string; DisableAutoSizing: boolean): TControl;
|
||||
procedure DisableControlAutoSizing(AControl: TControl);
|
||||
procedure EnableAllAutoSizing;
|
||||
procedure ClearLayoutProperties(AControl: TControl);
|
||||
protected
|
||||
@ -529,19 +530,14 @@ function TAnchorDockMaster.CreateNeededControls(Tree: TAnchorDockLayoutTree;
|
||||
AControl:=FindControl(Node.Name);
|
||||
if AControl<>nil then begin
|
||||
debugln(['CreateControlsForNode ',Node.Name,' already exists']);
|
||||
if DisableAutoSizing and (fDisabledAutosizing.IndexOf(AControl)<0) then
|
||||
begin
|
||||
AControl.DisableAutoSizing;
|
||||
fDisabledAutosizing.Add(AControl);
|
||||
end;
|
||||
DisableControlAutoSizing(AControl);
|
||||
end else begin
|
||||
debugln(['CreateControlsForNode ',Node.Name,' needs creation']);
|
||||
AControl:=DoCreateControl(Node.Name,DisableAutoSizing);
|
||||
if AControl<>nil then begin
|
||||
debugln(['CreateControlsForNode ',AControl.Name,' created']);
|
||||
if fDisabledAutosizing.IndexOf(AControl)>=0 then
|
||||
RaiseGDBException(''); // should never happen
|
||||
fDisabledAutosizing.Add(AControl);
|
||||
if fDisabledAutosizing.IndexOf(AControl)<0 then
|
||||
fDisabledAutosizing.Add(AControl);
|
||||
MakeDockable(AControl,false);
|
||||
end else begin
|
||||
debugln(['CreateControlsForNode ',Node.Name,' failed to create']);
|
||||
@ -721,6 +717,8 @@ function TAnchorDockMaster.RestoreLayout(Tree: TAnchorDockLayoutTree;
|
||||
Site.BoundsRect:=Node.BoundsRect;
|
||||
Site.Visible:=true;
|
||||
Site.Parent:=Parent;
|
||||
if IsCustomSite(Parent) then
|
||||
Site.Align:=Node.Align;
|
||||
if Site is TAnchorDockHostSite then
|
||||
TAnchorDockHostSite(Site).Header.HeaderPosition:=Node.HeaderPosition;
|
||||
if Parent=nil then begin
|
||||
@ -753,6 +751,7 @@ function TAnchorDockMaster.RestoreLayout(Tree: TAnchorDockLayoutTree;
|
||||
debugln(['TAnchorDockMaster.RestoreLayout.Restore can not find control ',Node.Name]);
|
||||
exit;
|
||||
end;
|
||||
DisableControlAutoSizing(AControl);
|
||||
if AControl.HostDockSite=nil then
|
||||
MakeDockable(AControl,false)
|
||||
else
|
||||
@ -775,8 +774,13 @@ function TAnchorDockMaster.RestoreLayout(Tree: TAnchorDockLayoutTree;
|
||||
debugln(['TAnchorDockMaster.RestoreLayout.Restore WARNING: ',Node.Name,' is not a custom dock site ',DbgSName(AControl)]);
|
||||
exit;
|
||||
end;
|
||||
DisableControlAutoSizing(AControl);
|
||||
SetupSite(TCustomForm(AControl),Node,nil);
|
||||
Result:=AControl;
|
||||
// restore docked site
|
||||
if Node.Count>0 then begin
|
||||
Restore(Node[0],TCustomForm(AControl));
|
||||
end;
|
||||
end else if Node.IsSplitter then begin
|
||||
// restore splitter
|
||||
Splitter:=TAnchorDockSplitter(TreeNameToDocker[Node.Name]);
|
||||
@ -877,11 +881,22 @@ function TAnchorDockMaster.DoCreateControl(aName: string;
|
||||
begin
|
||||
Result:=nil;
|
||||
OnCreateControl(Self,aName,Result,DisableAutoSizing);
|
||||
if Result=nil then
|
||||
debugln(['TAnchorDockMaster.DoCreateControl WARNING: control not found: "',aName,'"']);
|
||||
if (Result<>nil) and (Result.Name<>aName) then
|
||||
raise Exception.Create('TAnchorDockMaster.DoCreateControl'+Format(
|
||||
adrsRequestedButCreated, [aName, Result.Name]));
|
||||
end;
|
||||
|
||||
procedure TAnchorDockMaster.DisableControlAutoSizing(AControl: TControl);
|
||||
begin
|
||||
if fDisabledAutosizing.IndexOf(AControl)>=0 then exit;
|
||||
debugln(['TAnchorDockMaster.DisableControlAutoSizing ',DbgSName(AControl)]);
|
||||
fDisabledAutosizing.Add(AControl);
|
||||
AControl.FreeNotification(Self);
|
||||
AControl.DisableAutoSizing;
|
||||
end;
|
||||
|
||||
procedure TAnchorDockMaster.EnableAllAutoSizing;
|
||||
var
|
||||
i: Integer;
|
||||
@ -1145,7 +1160,7 @@ begin
|
||||
if SavedSites.IndexOf(AForm)>=0 then continue;
|
||||
SavedSites.Add(AForm);
|
||||
debugln(['TAnchorDockMaster.SaveMainLayoutToTree AForm=',DbgSName(AForm)]);
|
||||
DebugWriteChildAnchors(AForm);
|
||||
DebugWriteChildAnchors(AForm,true,true);
|
||||
if (AForm is TAnchorDockHostSite) then begin
|
||||
Site:=TAnchorDockHostSite(AForm);
|
||||
LayoutNode:=LayoutTree.NewNode(LayoutTree.Root);
|
||||
@ -1693,7 +1708,7 @@ begin
|
||||
BoundsIncreased:=true;
|
||||
end;
|
||||
debugln(['TAnchorDockHostSite.DockAnotherControl AFTER ENLARGE ',Caption]);
|
||||
DebugWriteChildAnchors(Self);
|
||||
DebugWriteChildAnchors(Self,true,true);
|
||||
end;
|
||||
|
||||
// anchors
|
||||
@ -1850,7 +1865,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
DebugWriteChildAnchors(Self);
|
||||
DebugWriteChildAnchors(Self,true,true);
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
@ -1962,7 +1977,7 @@ procedure TAnchorDockHostSite.RemoveControlFromLayout(AControl: TControl);
|
||||
debugln(['RemoveControlBoundSplitter ',DbgSName(Splitter)]);
|
||||
Splitter.Free;
|
||||
|
||||
DebugWriteChildAnchors(GetParentForm(Self));
|
||||
DebugWriteChildAnchors(GetParentForm(Self),true,true);
|
||||
end;
|
||||
|
||||
procedure ConvertToOneControlType(OnlySiteLeft: TAnchorDockHostSite);
|
||||
@ -2031,7 +2046,7 @@ procedure TAnchorDockHostSite.RemoveControlFromLayout(AControl: TControl);
|
||||
UpdateHeaderAlign;
|
||||
|
||||
debugln(['TAnchorDockHostSite.RemoveControlFromLayout.ConvertToOneControlType AFTER CONVERT "',Caption,'" to onecontrol OnlySiteLeft="',OnlySiteLeft.Caption,'"']);
|
||||
DebugWriteChildAnchors(GetParentForm(Self));
|
||||
DebugWriteChildAnchors(GetParentForm(Self),true,true);
|
||||
|
||||
DockMaster.NeedSimplify(Self);
|
||||
finally
|
||||
@ -2192,7 +2207,7 @@ begin
|
||||
EnableAutoSizing;
|
||||
end;
|
||||
debugln(['TAnchorDockHostSite.SimplifyPages END Self="',Caption,'"']);
|
||||
DebugWriteChildAnchors(GetParentForm(Self));
|
||||
DebugWriteChildAnchors(GetParentForm(Self),true,true);
|
||||
end else if Pages.PageCount=0 then begin
|
||||
debugln(['TAnchorDockHostSite.SimplifyPages "',Caption,'" PageCount=0 Self=',dbgs(Pointer(Self))]);
|
||||
FSiteType:=adhstNone;
|
||||
@ -2257,7 +2272,7 @@ begin
|
||||
end;
|
||||
|
||||
debugln(['TAnchorDockHostSite.SimplifyOneControl END Self="',Caption,'"']);
|
||||
DebugWriteChildAnchors(GetParentForm(Self));
|
||||
DebugWriteChildAnchors(GetParentForm(Self),true,true);
|
||||
end;
|
||||
|
||||
function TAnchorDockHostSite.GetOneControl: TControl;
|
||||
|
@ -67,6 +67,7 @@ type
|
||||
|
||||
TAnchorDockLayoutTreeNode = class
|
||||
private
|
||||
FAlign: TAlign;
|
||||
fAnchors: array[TAnchorKind] of string;
|
||||
FBoundsRect: TRect;
|
||||
FHeaderPosition: TADLHeaderPosition;
|
||||
@ -84,6 +85,7 @@ type
|
||||
function GetRight: integer;
|
||||
function GetTop: integer;
|
||||
function GetWidth: integer;
|
||||
procedure SetAlign(const AValue: TAlign);
|
||||
procedure SetAnchors(Site: TAnchorKind; const AValue: string);
|
||||
procedure SetBottom(const AValue: integer);
|
||||
procedure SetBoundsRect(const AValue: TRect);
|
||||
@ -134,6 +136,7 @@ type
|
||||
property Bottom: integer read GetBottom write SetBottom;
|
||||
property BoundsRect: TRect read FBoundsRect write SetBoundsRect;
|
||||
property Anchors[Site: TAnchorKind]: string read GetAnchors write SetAnchors; // empty means default (parent)
|
||||
property Align: TAlign read FAlign write SetAlign;
|
||||
property WindowState: TWindowState read FWindowState write SetWindowState;
|
||||
property Monitor: integer read FMonitor write SetMonitor;
|
||||
property HeaderPosition: TADLHeaderPosition read FHeaderPosition write SetHeaderPosition;
|
||||
@ -215,16 +218,27 @@ const
|
||||
'right',
|
||||
'bottom'
|
||||
);
|
||||
ADLAlignNames: array[TAlign] of string = (
|
||||
'None',
|
||||
'Top',
|
||||
'Bottom',
|
||||
'Left',
|
||||
'Right',
|
||||
'Client',
|
||||
'Custom'
|
||||
);
|
||||
|
||||
function NameToADLTreeNodeType(s: string): TADLTreeNodeType;
|
||||
function NameToADLWindowState(s: string): TWindowState;
|
||||
function NameToADLHeaderPosition(s: string): TADLHeaderPosition;
|
||||
function NameToADLAlign(s: string): TAlign;
|
||||
function dbgs(const NodeType: TADLTreeNodeType): string; overload;
|
||||
|
||||
procedure WriteDebugLayout(Title: string; RootNode: TObject);
|
||||
function DebugLayoutAsString(RootNode: TObject): string;
|
||||
procedure DebugWriteChildAnchors(RootNode: TAnchorDockLayoutTreeNode); overload;
|
||||
procedure DebugWriteChildAnchors(RootControl: TWinControl); overload;
|
||||
procedure DebugWriteChildAnchors(RootControl: TWinControl;
|
||||
OnlyWinControls, OnlyForms: boolean); overload;
|
||||
|
||||
implementation
|
||||
|
||||
@ -249,6 +263,13 @@ begin
|
||||
Result:=adlhpAuto;
|
||||
end;
|
||||
|
||||
function NameToADLAlign(s: string): TAlign;
|
||||
begin
|
||||
for Result:=low(TAlign) to high(TAlign) do
|
||||
if s=ADLAlignNames[Result] then exit;
|
||||
Result:=alNone;
|
||||
end;
|
||||
|
||||
function dbgs(const NodeType: TADLTreeNodeType): string; overload;
|
||||
begin
|
||||
Result:=ADLTreeNodeTypeNames[NodeType];
|
||||
@ -498,7 +519,7 @@ var
|
||||
if MinPosCalculating then begin
|
||||
DebugLn(['DebugLayoutAsString.GetMinPos.Compute WARNING: anchor circle detected RootNode=',DbgSName(RootNode)]);
|
||||
if RootNode is TWinControl then
|
||||
DebugWriteChildAnchors(TWinControl(RootNode))
|
||||
DebugWriteChildAnchors(TWinControl(RootNode),true,true)
|
||||
else if RootNode is TAnchorDockLayoutTreeNode then
|
||||
DebugWriteChildAnchors(TAnchorDockLayoutTreeNode(RootNode));
|
||||
RaiseGDBException('circle detected');
|
||||
@ -700,7 +721,8 @@ begin
|
||||
WriteControl(RootNode[i],' ');
|
||||
end;
|
||||
|
||||
procedure DebugWriteChildAnchors(RootControl: TWinControl); overload;
|
||||
procedure DebugWriteChildAnchors(RootControl: TWinControl;
|
||||
OnlyWinControls, OnlyForms: boolean); overload;
|
||||
|
||||
procedure WriteControl(AControl: TControl; Prefix: string);
|
||||
var
|
||||
@ -709,6 +731,9 @@ procedure DebugWriteChildAnchors(RootControl: TWinControl); overload;
|
||||
AnchorControl: TControl;
|
||||
AnchorName: String;
|
||||
begin
|
||||
if OnlyWinControls and (not (AControl is TWinControl)) then exit;
|
||||
if OnlyForms and (not (AControl is TCustomForm)) then exit;
|
||||
|
||||
debugln([Prefix,DbgSName(AControl),' Caption="',dbgstr(AControl.Caption),'" Align=',dbgs(AControl.Align),' Bounds=',dbgs(AControl.BoundsRect)]);
|
||||
for a:=low(TAnchorKind) to high(TAnchorKind) do begin
|
||||
AnchorControl:=AControl.AnchorSide[a].Control;
|
||||
@ -777,6 +802,13 @@ begin
|
||||
Result:=FBoundsRect.Right-FBoundsRect.Left;
|
||||
end;
|
||||
|
||||
procedure TAnchorDockLayoutTreeNode.SetAlign(const AValue: TAlign);
|
||||
begin
|
||||
if FAlign=AValue then exit;
|
||||
FAlign:=AValue;
|
||||
IncreaseChangeStamp;
|
||||
end;
|
||||
|
||||
procedure TAnchorDockLayoutTreeNode.SetAnchors(Site: TAnchorKind;
|
||||
const AValue: string);
|
||||
begin
|
||||
@ -923,6 +955,7 @@ begin
|
||||
or (Count<>Node.Count)
|
||||
or (NodeType<>Node.NodeType)
|
||||
or (Name<>Node.Name)
|
||||
or (Align<>Node.Align)
|
||||
or (WindowState<>Node.WindowState)
|
||||
or (HeaderPosition<>Node.HeaderPosition)
|
||||
then
|
||||
@ -943,6 +976,7 @@ begin
|
||||
Name:=Node.Name;
|
||||
NodeType:=Node.NodeType;
|
||||
BoundsRect:=Node.BoundsRect;
|
||||
Align:=Node.Align;
|
||||
WindowState:=Node.WindowState;
|
||||
HeaderPosition:=Node.HeaderPosition;
|
||||
for a:=low(TAnchorKind) to high(TAnchorKind) do
|
||||
@ -966,6 +1000,7 @@ var
|
||||
begin
|
||||
Name:=AControl.Name;
|
||||
BoundsRect:=AControl.BoundsRect;
|
||||
Align:=AControl.Align;
|
||||
if (AControl.Parent=nil) and (AControl is TCustomForm) then begin
|
||||
WindowState:=TCustomForm(AControl).WindowState;
|
||||
Monitor:=TCustomForm(AControl).Monitor.MonitorNum;
|
||||
@ -997,6 +1032,7 @@ begin
|
||||
Anchors[akTop]:=Config.GetValue('Anchors/Top','');
|
||||
Anchors[akRight]:=Config.GetValue('Anchors/Right','');
|
||||
Anchors[akBottom]:=Config.GetValue('Anchors/Bottom','');
|
||||
Align:=NameToADLAlign(Config.GetValue('Anchors/Align',AlignNames[alNone]));
|
||||
WindowState:=NameToADLWindowState(Config.GetValue('WindowState',ADLWindowStateNames[wsNormal]));
|
||||
HeaderPosition:=NameToADLHeaderPosition(Config.GetValue('Header/Position',ADLHeaderPositionNames[adlhpAuto]));
|
||||
Monitor:=Config.GetValue('Monitor',0);
|
||||
@ -1025,6 +1061,7 @@ begin
|
||||
Config.SetDeleteValue('Anchors/Top',Anchors[akTop],'');
|
||||
Config.SetDeleteValue('Anchors/Right',Anchors[akRight],'');
|
||||
Config.SetDeleteValue('Anchors/Bottom',Anchors[akBottom],'');
|
||||
Config.SetDeleteValue('Anchors/Align',ADLAlignNames[Align],ADLAlignNames[alNone]);
|
||||
Config.SetDeleteValue('WindowState',ADLWindowStateNames[WindowState],
|
||||
ADLWindowStateNames[wsNormal]);
|
||||
Config.SetDeleteValue('Header/Position',ADLHeaderPositionNames[HeaderPosition],
|
||||
|
@ -81,6 +81,12 @@ procedure TMainIDE.DockMasterCreateControl(Sender: TObject; aName: string; var
|
||||
end;
|
||||
|
||||
begin
|
||||
AControl:=Screen.FindForm(aName);
|
||||
if AControl<>nil then begin
|
||||
if DoDisableAutoSizing then
|
||||
AControl.DisableAutoSizing;
|
||||
exit;
|
||||
end;
|
||||
if aName='CodeExplorer' then
|
||||
CreateForm('Code Explorer',Bounds(700,230,100,250))
|
||||
else if aName='FPDocEditor' then
|
||||
@ -117,8 +123,8 @@ begin
|
||||
|
||||
SetBounds(100,50,600,80);
|
||||
ViewSrcEditor1ToolButtonClick(Self);
|
||||
ViewMessagesToolButtonClick(Self);
|
||||
ViewOIToolButtonClick(Self);
|
||||
//ViewMessagesToolButtonClick(Self);
|
||||
//ViewOIToolButtonClick(Self);
|
||||
end;
|
||||
|
||||
procedure TMainIDE.LoadLayoutToolButtonClick(Sender: TObject);
|
||||
|
Loading…
Reference in New Issue
Block a user