mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-07 14:57:53 +01:00
anchordocking: using default layout
git-svn-id: trunk@26171 -
This commit is contained in:
parent
67c97f6d6d
commit
16b503ab91
@ -79,8 +79,6 @@
|
|||||||
- on show again: restore a default layout
|
- on show again: restore a default layout
|
||||||
- close button for pages
|
- close button for pages
|
||||||
}
|
}
|
||||||
{ TODO : RRR1
|
|
||||||
}
|
|
||||||
unit AnchorDocking;
|
unit AnchorDocking;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
@ -435,8 +433,10 @@ type
|
|||||||
function IndexOfControl(const aName: string): integer;
|
function IndexOfControl(const aName: string): integer;
|
||||||
function FindControl(const aName: string): TControl;
|
function FindControl(const aName: string): TControl;
|
||||||
function IsSite(AControl: TControl): boolean;
|
function IsSite(AControl: TControl): boolean;
|
||||||
|
function IsAnchorSite(AControl: TControl): boolean;
|
||||||
function IsCustomSite(AControl: TControl): boolean;
|
function IsCustomSite(AControl: TControl): boolean;
|
||||||
function GetSite(AControl: TControl): TAnchorDockHostSite;
|
function GetSite(AControl: TControl): TAnchorDockHostSite;
|
||||||
|
function GetControl(Site: TControl): TControl;
|
||||||
function GetPopupMenu: TPopupMenu;
|
function GetPopupMenu: TPopupMenu;
|
||||||
function AddPopupMenuItem(AName, ACaption: string;
|
function AddPopupMenuItem(AName, ACaption: string;
|
||||||
const OnClickEvent: TNotifyEvent; AParent: TMenuItem = nil): TMenuItem; virtual;
|
const OnClickEvent: TNotifyEvent; AParent: TMenuItem = nil): TMenuItem; virtual;
|
||||||
@ -1622,6 +1622,11 @@ begin
|
|||||||
Result:=(AControl is TAnchorDockHostSite) or IsCustomSite(AControl);
|
Result:=(AControl is TAnchorDockHostSite) or IsCustomSite(AControl);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TAnchorDockMaster.IsAnchorSite(AControl: TControl): boolean;
|
||||||
|
begin
|
||||||
|
Result:=AControl is TAnchorDockHostSite;
|
||||||
|
end;
|
||||||
|
|
||||||
function TAnchorDockMaster.IsCustomSite(AControl: TControl): boolean;
|
function TAnchorDockMaster.IsCustomSite(AControl: TControl): boolean;
|
||||||
begin
|
begin
|
||||||
Result:=(AControl is TCustomForm) // also checks for nil
|
Result:=(AControl is TCustomForm) // also checks for nil
|
||||||
@ -1639,6 +1644,20 @@ begin
|
|||||||
Result:=nil;
|
Result:=nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TAnchorDockMaster.GetControl(Site: TControl): TControl;
|
||||||
|
var
|
||||||
|
AnchorSite: TAnchorDockHostSite;
|
||||||
|
begin
|
||||||
|
Result:=nil;
|
||||||
|
if IsCustomSite(Site) then
|
||||||
|
Result:=Site
|
||||||
|
else if Site is TAnchorDockHostSite then begin
|
||||||
|
AnchorSite:=TAnchorDockHostSite(Site);
|
||||||
|
if AnchorSite.SiteType=adhstOneControl then
|
||||||
|
Result:=AnchorSite.GetOneControl;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TAnchorDockMaster.GetPopupMenu: TPopupMenu;
|
function TAnchorDockMaster.GetPopupMenu: TPopupMenu;
|
||||||
begin
|
begin
|
||||||
if fPopupMenu=nil then begin
|
if fPopupMenu=nil then begin
|
||||||
@ -1696,6 +1715,7 @@ begin
|
|||||||
AControl.DisableAutoSizing;
|
AControl.DisableAutoSizing;
|
||||||
try
|
try
|
||||||
if AControl is TAnchorDockHostSite then begin
|
if AControl is TAnchorDockHostSite then begin
|
||||||
|
// already a site
|
||||||
Site:=TAnchorDockHostSite(AControl);
|
Site:=TAnchorDockHostSite(AControl);
|
||||||
end else if AControl.Parent=nil then begin
|
end else if AControl.Parent=nil then begin
|
||||||
|
|
||||||
@ -1714,7 +1734,7 @@ begin
|
|||||||
AControl.ManualDock(Site);
|
AControl.ManualDock(Site);
|
||||||
AControl.Visible:=true;
|
AControl.Visible:=true;
|
||||||
if not AddDockHeader then
|
if not AddDockHeader then
|
||||||
Site.Header.Parent:=nil; // ToDo set property
|
Site.Header.Parent:=nil;
|
||||||
except
|
except
|
||||||
FreeAndNil(Site);
|
FreeAndNil(Site);
|
||||||
raise;
|
raise;
|
||||||
@ -4406,7 +4426,7 @@ end;
|
|||||||
|
|
||||||
procedure TAnchorDockManager.LoadFromStream(Stream: TStream);
|
procedure TAnchorDockManager.LoadFromStream(Stream: TStream);
|
||||||
begin
|
begin
|
||||||
debugln(['TAnchorDockManager.LoadFromStream TODO Site="',DbgSName(Site),'"']);
|
debugln(['TAnchorDockManager.LoadFromStream not implemented Site="',DbgSName(Site),'"']);
|
||||||
if Stream=nil then ;
|
if Stream=nil then ;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -4561,7 +4581,7 @@ end;
|
|||||||
procedure TAnchorDockManager.SaveToStream(Stream: TStream);
|
procedure TAnchorDockManager.SaveToStream(Stream: TStream);
|
||||||
begin
|
begin
|
||||||
if Stream=nil then ;
|
if Stream=nil then ;
|
||||||
debugln(['TAnchorDockManager.SaveToStream TODO Site="',DbgSName(Site),'"']);
|
debugln(['TAnchorDockManager.SaveToStream not implemented Site="',DbgSName(Site),'"']);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TAnchorDockManager.GetDockEdge(ADockObject: TDragDockObject): boolean;
|
function TAnchorDockManager.GetDockEdge(ADockObject: TDragDockObject): boolean;
|
||||||
|
|||||||
@ -47,10 +47,12 @@ type
|
|||||||
|
|
||||||
TIDEAnchorDockMaster = class(TIDEDockMaster)
|
TIDEAnchorDockMaster = class(TIDEDockMaster)
|
||||||
private
|
private
|
||||||
|
FDefaultLayoutLoaded: boolean;
|
||||||
procedure DockMasterCreateControl(Sender: TObject; aName: string;
|
procedure DockMasterCreateControl(Sender: TObject; aName: string;
|
||||||
var AControl: TControl; DoDisableAutoSizing: boolean);
|
var AControl: TControl; DoDisableAutoSizing: boolean);
|
||||||
procedure GetDefaultBounds(AForm: TCustomForm; out Creator: TIDEWindowCreator;
|
procedure GetDefaultBounds(AForm: TCustomForm; out Creator: TIDEWindowCreator;
|
||||||
out NewBounds: TRect; out DockSiblingName: string; out DockAlign: TAlign);
|
out NewBounds: TRect; out DockSiblingName: string; out DockAlign: TAlign);
|
||||||
|
procedure SetDefaultLayoutLoaded(const AValue: boolean);
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -63,6 +65,7 @@ type
|
|||||||
procedure CloseAll; override;
|
procedure CloseAll; override;
|
||||||
procedure OnIDEClose(Sender: TObject);
|
procedure OnIDEClose(Sender: TObject);
|
||||||
procedure OnIDERestoreWindows(Sender: TObject);
|
procedure OnIDERestoreWindows(Sender: TObject);
|
||||||
|
property DefaultLayoutLoaded: boolean read FDefaultLayoutLoaded write SetDefaultLayoutLoaded;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -91,10 +94,18 @@ end;
|
|||||||
procedure TIDEAnchorDockMaster.GetDefaultBounds(AForm: TCustomForm; out
|
procedure TIDEAnchorDockMaster.GetDefaultBounds(AForm: TCustomForm; out
|
||||||
Creator: TIDEWindowCreator; out NewBounds: TRect; out
|
Creator: TIDEWindowCreator; out NewBounds: TRect; out
|
||||||
DockSiblingName: string; out DockAlign: TAlign);
|
DockSiblingName: string; out DockAlign: TAlign);
|
||||||
|
var
|
||||||
|
AControl: TControl;
|
||||||
begin
|
begin
|
||||||
NewBounds:=Rect(0,0,0,0);
|
NewBounds:=Rect(0,0,0,0);
|
||||||
DockSiblingName:='';
|
DockSiblingName:='';
|
||||||
DockAlign:=alNone;
|
DockAlign:=alNone;
|
||||||
|
|
||||||
|
// get the embedded control
|
||||||
|
AControl:=DockMaster.GetControl(AForm);
|
||||||
|
if not (AControl is TCustomForm) then exit;
|
||||||
|
AForm:=TCustomForm(AControl);
|
||||||
|
|
||||||
Creator:=IDEWindowCreators.FindWithName(AForm.Name);
|
Creator:=IDEWindowCreators.FindWithName(AForm.Name);
|
||||||
if Creator=nil then exit;
|
if Creator=nil then exit;
|
||||||
if Creator.OnGetLayout<>nil then
|
if Creator.OnGetLayout<>nil then
|
||||||
@ -110,6 +121,12 @@ begin
|
|||||||
NewBounds.Bottom:=Max(NewBounds.Top+100,NewBounds.Bottom);
|
NewBounds.Bottom:=Max(NewBounds.Top+100,NewBounds.Bottom);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TIDEAnchorDockMaster.SetDefaultLayoutLoaded(const AValue: boolean);
|
||||||
|
begin
|
||||||
|
if FDefaultLayoutLoaded=AValue then exit;
|
||||||
|
FDefaultLayoutLoaded:=AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TIDEAnchorDockMaster.Create;
|
constructor TIDEAnchorDockMaster.Create;
|
||||||
begin
|
begin
|
||||||
IDEAnchorDockMaster:=Self;
|
IDEAnchorDockMaster:=Self;
|
||||||
@ -125,11 +142,13 @@ end;
|
|||||||
|
|
||||||
procedure TIDEAnchorDockMaster.MakeIDEWindowDockSite(AForm: TCustomForm);
|
procedure TIDEAnchorDockMaster.MakeIDEWindowDockSite(AForm: TCustomForm);
|
||||||
begin
|
begin
|
||||||
|
debugln(['TIDEAnchorDockMaster.MakeIDEWindowDockSite ',DbgSName(AForm)]);
|
||||||
DockMaster.MakeDockSite(AForm,[akBottom],admrpChild);
|
DockMaster.MakeDockSite(AForm,[akBottom],admrpChild);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TIDEAnchorDockMaster.MakeIDEWindowDockable(AControl: TWinControl);
|
procedure TIDEAnchorDockMaster.MakeIDEWindowDockable(AControl: TWinControl);
|
||||||
begin
|
begin
|
||||||
|
debugln(['TIDEAnchorDockMaster.MakeIDEWindowDockable ',DbgSName(AControl)]);
|
||||||
DockMaster.MakeDockable(AControl,false);
|
DockMaster.MakeDockable(AControl,false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -148,8 +167,10 @@ begin
|
|||||||
debugln(['TIDEAnchorDockMaster.LoadDefaultLayout ',Filename]);
|
debugln(['TIDEAnchorDockMaster.LoadDefaultLayout ',Filename]);
|
||||||
Config:=GetIDEConfigStorage(Filename,true);
|
Config:=GetIDEConfigStorage(Filename,true);
|
||||||
try
|
try
|
||||||
if not DockMaster.ConfigIsEmpty(Config) then
|
if not DockMaster.ConfigIsEmpty(Config) then begin
|
||||||
DockMaster.LoadLayoutFromConfig(Config);
|
DockMaster.LoadLayoutFromConfig(Config);
|
||||||
|
DefaultLayoutLoaded:=true;
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
Config.Free;
|
Config.Free;
|
||||||
end;
|
end;
|
||||||
@ -192,36 +213,37 @@ var
|
|||||||
DockSibling: TCustomForm;
|
DockSibling: TCustomForm;
|
||||||
NewDockSite: TAnchorDockHostSite;
|
NewDockSite: TAnchorDockHostSite;
|
||||||
Site: TAnchorDockHostSite;
|
Site: TAnchorDockHostSite;
|
||||||
|
AControl: TControl;
|
||||||
begin
|
begin
|
||||||
debugln(['TIDEAnchorDockMaster.ShowForm ',DbgSName(AForm),' BringToFront=',BringToFront]);
|
debugln(['TIDEAnchorDockMaster.ShowForm ',DbgSName(AForm),' BringToFront=',BringToFront,' IsSite=',DockMaster.IsSite(AForm),' IsCustomSite=',DockMaster.IsCustomSite(AForm)]);
|
||||||
try
|
try
|
||||||
AForm.DisableAlign;
|
AForm.DisableAlign;
|
||||||
if DockMaster.IsSite(AForm) then begin
|
|
||||||
// already docked
|
|
||||||
end else begin
|
|
||||||
// this form was not yet docked
|
|
||||||
|
|
||||||
// place it at a default position and make it dockable
|
if not DockMaster.IsSite(AForm) then begin
|
||||||
|
// this form was not yet docked
|
||||||
|
// => make it dockable
|
||||||
|
DockMaster.MakeDockable(AForm,false);
|
||||||
|
end;
|
||||||
|
AControl:=DockMaster.GetControl(AForm);
|
||||||
|
|
||||||
|
if (AControl<>nil) and (not AForm.IsVisible) and (AForm.Parent=nil) then begin
|
||||||
|
// this form is not yet on the screen and is not yet docked
|
||||||
|
debugln(['TIDEAnchorDockMaster.ShowForm placing ',DbgSName(AControl),' ...']);
|
||||||
|
|
||||||
|
// ToDo: use the restore layout
|
||||||
|
|
||||||
|
// place it at a default position and/or dock it
|
||||||
GetDefaultBounds(AForm,Creator,NewBounds,DockSiblingName,DockAlign);
|
GetDefaultBounds(AForm,Creator,NewBounds,DockSiblingName,DockAlign);
|
||||||
if Creator<>nil then
|
if Creator<>nil then begin
|
||||||
begin
|
|
||||||
// this window should become dockable
|
|
||||||
NewBounds.Left:=Min(10000,Max(-10000,NewBounds.Left));
|
|
||||||
NewBounds.Top:=Min(10000,Max(-10000,NewBounds.Top));
|
|
||||||
NewBounds.Right:=Max(NewBounds.Left+100,NewBounds.Right);
|
|
||||||
NewBounds.Bottom:=Max(NewBounds.Top+100,NewBounds.Bottom);
|
|
||||||
AForm.BoundsRect:=NewBounds;
|
AForm.BoundsRect:=NewBounds;
|
||||||
AForm.UndockWidth:=NewBounds.Right-NewBounds.Left;
|
AForm.UndockWidth:=NewBounds.Right-NewBounds.Left;
|
||||||
AForm.UndockHeight:=NewBounds.Bottom-NewBounds.Top;
|
AForm.UndockHeight:=NewBounds.Bottom-NewBounds.Top;
|
||||||
debugln(['TIDEAnchorDockMaster.ShowForm creator for ',DbgSName(AForm),' found: Left=',Creator.Left,' Top=',Creator.Top,' Width=',Creator.Width,' Height=',Creator.Height,' DockSiblingName=',DockSiblingName,' DockAlign=',dbgs(DockAlign)]);
|
debugln(['TIDEAnchorDockMaster.ShowForm creator for ',DbgSName(AControl),' found: Left=',Creator.Left,' Top=',Creator.Top,' Width=',Creator.Width,' Height=',Creator.Height,' DockSiblingName=',DockSiblingName,' DockAlign=',dbgs(DockAlign)]);
|
||||||
DockMaster.MakeDockable(AForm,false);
|
|
||||||
Site:=DockMaster.GetSite(AForm);
|
Site:=DockMaster.GetSite(AForm);
|
||||||
if DockSiblingName<>'' then
|
if DockMaster.IsAnchorSite(Site) and (DockSiblingName<>'') then begin
|
||||||
begin
|
|
||||||
DockSibling:=Screen.FindForm(DockSiblingName);
|
DockSibling:=Screen.FindForm(DockSiblingName);
|
||||||
debugln(['TIDEAnchorDockMaster.ShowForm DockSiblingName="',DockSiblingName,'" DockSibling=',DbgSName(DockSibling)]);
|
debugln(['TIDEAnchorDockMaster.ShowForm DockSiblingName="',DockSiblingName,'" DockSibling=',DbgSName(DockSibling)]);
|
||||||
if DockSibling<>nil then
|
if DockSibling<>nil then begin
|
||||||
begin
|
|
||||||
NewDockSite:=DockMaster.GetSite(DockSibling);
|
NewDockSite:=DockMaster.GetSite(DockSibling);
|
||||||
debugln(['TIDEAnchorDockMaster.ShowForm NewDockSite=',DbgSName(NewDockSite),'="',NewDockSite.Caption,'"']);
|
debugln(['TIDEAnchorDockMaster.ShowForm NewDockSite=',DbgSName(NewDockSite),'="',NewDockSite.Caption,'"']);
|
||||||
DockMaster.ManualDock(Site,NewDockSite,DockAlign);
|
DockMaster.ManualDock(Site,NewDockSite,DockAlign);
|
||||||
@ -231,10 +253,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
finally
|
finally
|
||||||
if DockMaster.IsCustomSite(AForm) then
|
DockMaster.MakeVisible(AForm,BringToFront);
|
||||||
AForm.Visible:=true
|
|
||||||
else
|
|
||||||
DockMaster.MakeDockable(AForm,true,false);
|
|
||||||
AForm.EnableAlign;
|
AForm.EnableAlign;
|
||||||
|
|
||||||
if BringToFront then begin
|
if BringToFront then begin
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user