mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-06 22:37:27 +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
|
||||
- close button for pages
|
||||
}
|
||||
{ TODO : RRR1
|
||||
}
|
||||
unit AnchorDocking;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
@ -435,8 +433,10 @@ type
|
||||
function IndexOfControl(const aName: string): integer;
|
||||
function FindControl(const aName: string): TControl;
|
||||
function IsSite(AControl: TControl): boolean;
|
||||
function IsAnchorSite(AControl: TControl): boolean;
|
||||
function IsCustomSite(AControl: TControl): boolean;
|
||||
function GetSite(AControl: TControl): TAnchorDockHostSite;
|
||||
function GetControl(Site: TControl): TControl;
|
||||
function GetPopupMenu: TPopupMenu;
|
||||
function AddPopupMenuItem(AName, ACaption: string;
|
||||
const OnClickEvent: TNotifyEvent; AParent: TMenuItem = nil): TMenuItem; virtual;
|
||||
@ -1622,6 +1622,11 @@ begin
|
||||
Result:=(AControl is TAnchorDockHostSite) or IsCustomSite(AControl);
|
||||
end;
|
||||
|
||||
function TAnchorDockMaster.IsAnchorSite(AControl: TControl): boolean;
|
||||
begin
|
||||
Result:=AControl is TAnchorDockHostSite;
|
||||
end;
|
||||
|
||||
function TAnchorDockMaster.IsCustomSite(AControl: TControl): boolean;
|
||||
begin
|
||||
Result:=(AControl is TCustomForm) // also checks for nil
|
||||
@ -1639,6 +1644,20 @@ begin
|
||||
Result:=nil;
|
||||
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;
|
||||
begin
|
||||
if fPopupMenu=nil then begin
|
||||
@ -1696,6 +1715,7 @@ begin
|
||||
AControl.DisableAutoSizing;
|
||||
try
|
||||
if AControl is TAnchorDockHostSite then begin
|
||||
// already a site
|
||||
Site:=TAnchorDockHostSite(AControl);
|
||||
end else if AControl.Parent=nil then begin
|
||||
|
||||
@ -1714,7 +1734,7 @@ begin
|
||||
AControl.ManualDock(Site);
|
||||
AControl.Visible:=true;
|
||||
if not AddDockHeader then
|
||||
Site.Header.Parent:=nil; // ToDo set property
|
||||
Site.Header.Parent:=nil;
|
||||
except
|
||||
FreeAndNil(Site);
|
||||
raise;
|
||||
@ -4406,7 +4426,7 @@ end;
|
||||
|
||||
procedure TAnchorDockManager.LoadFromStream(Stream: TStream);
|
||||
begin
|
||||
debugln(['TAnchorDockManager.LoadFromStream TODO Site="',DbgSName(Site),'"']);
|
||||
debugln(['TAnchorDockManager.LoadFromStream not implemented Site="',DbgSName(Site),'"']);
|
||||
if Stream=nil then ;
|
||||
end;
|
||||
|
||||
@ -4561,7 +4581,7 @@ end;
|
||||
procedure TAnchorDockManager.SaveToStream(Stream: TStream);
|
||||
begin
|
||||
if Stream=nil then ;
|
||||
debugln(['TAnchorDockManager.SaveToStream TODO Site="',DbgSName(Site),'"']);
|
||||
debugln(['TAnchorDockManager.SaveToStream not implemented Site="',DbgSName(Site),'"']);
|
||||
end;
|
||||
|
||||
function TAnchorDockManager.GetDockEdge(ADockObject: TDragDockObject): boolean;
|
||||
|
||||
@ -47,10 +47,12 @@ type
|
||||
|
||||
TIDEAnchorDockMaster = class(TIDEDockMaster)
|
||||
private
|
||||
FDefaultLayoutLoaded: boolean;
|
||||
procedure DockMasterCreateControl(Sender: TObject; aName: string;
|
||||
var AControl: TControl; DoDisableAutoSizing: boolean);
|
||||
procedure GetDefaultBounds(AForm: TCustomForm; out Creator: TIDEWindowCreator;
|
||||
out NewBounds: TRect; out DockSiblingName: string; out DockAlign: TAlign);
|
||||
procedure SetDefaultLayoutLoaded(const AValue: boolean);
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
@ -63,6 +65,7 @@ type
|
||||
procedure CloseAll; override;
|
||||
procedure OnIDEClose(Sender: TObject);
|
||||
procedure OnIDERestoreWindows(Sender: TObject);
|
||||
property DefaultLayoutLoaded: boolean read FDefaultLayoutLoaded write SetDefaultLayoutLoaded;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -91,10 +94,18 @@ end;
|
||||
procedure TIDEAnchorDockMaster.GetDefaultBounds(AForm: TCustomForm; out
|
||||
Creator: TIDEWindowCreator; out NewBounds: TRect; out
|
||||
DockSiblingName: string; out DockAlign: TAlign);
|
||||
var
|
||||
AControl: TControl;
|
||||
begin
|
||||
NewBounds:=Rect(0,0,0,0);
|
||||
DockSiblingName:='';
|
||||
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);
|
||||
if Creator=nil then exit;
|
||||
if Creator.OnGetLayout<>nil then
|
||||
@ -110,6 +121,12 @@ begin
|
||||
NewBounds.Bottom:=Max(NewBounds.Top+100,NewBounds.Bottom);
|
||||
end;
|
||||
|
||||
procedure TIDEAnchorDockMaster.SetDefaultLayoutLoaded(const AValue: boolean);
|
||||
begin
|
||||
if FDefaultLayoutLoaded=AValue then exit;
|
||||
FDefaultLayoutLoaded:=AValue;
|
||||
end;
|
||||
|
||||
constructor TIDEAnchorDockMaster.Create;
|
||||
begin
|
||||
IDEAnchorDockMaster:=Self;
|
||||
@ -125,11 +142,13 @@ end;
|
||||
|
||||
procedure TIDEAnchorDockMaster.MakeIDEWindowDockSite(AForm: TCustomForm);
|
||||
begin
|
||||
debugln(['TIDEAnchorDockMaster.MakeIDEWindowDockSite ',DbgSName(AForm)]);
|
||||
DockMaster.MakeDockSite(AForm,[akBottom],admrpChild);
|
||||
end;
|
||||
|
||||
procedure TIDEAnchorDockMaster.MakeIDEWindowDockable(AControl: TWinControl);
|
||||
begin
|
||||
debugln(['TIDEAnchorDockMaster.MakeIDEWindowDockable ',DbgSName(AControl)]);
|
||||
DockMaster.MakeDockable(AControl,false);
|
||||
end;
|
||||
|
||||
@ -148,8 +167,10 @@ begin
|
||||
debugln(['TIDEAnchorDockMaster.LoadDefaultLayout ',Filename]);
|
||||
Config:=GetIDEConfigStorage(Filename,true);
|
||||
try
|
||||
if not DockMaster.ConfigIsEmpty(Config) then
|
||||
if not DockMaster.ConfigIsEmpty(Config) then begin
|
||||
DockMaster.LoadLayoutFromConfig(Config);
|
||||
DefaultLayoutLoaded:=true;
|
||||
end;
|
||||
finally
|
||||
Config.Free;
|
||||
end;
|
||||
@ -192,36 +213,37 @@ var
|
||||
DockSibling: TCustomForm;
|
||||
NewDockSite: TAnchorDockHostSite;
|
||||
Site: TAnchorDockHostSite;
|
||||
AControl: TControl;
|
||||
begin
|
||||
debugln(['TIDEAnchorDockMaster.ShowForm ',DbgSName(AForm),' BringToFront=',BringToFront]);
|
||||
debugln(['TIDEAnchorDockMaster.ShowForm ',DbgSName(AForm),' BringToFront=',BringToFront,' IsSite=',DockMaster.IsSite(AForm),' IsCustomSite=',DockMaster.IsCustomSite(AForm)]);
|
||||
try
|
||||
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);
|
||||
if Creator<>nil then
|
||||
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);
|
||||
if Creator<>nil then begin
|
||||
AForm.BoundsRect:=NewBounds;
|
||||
AForm.UndockWidth:=NewBounds.Right-NewBounds.Left;
|
||||
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)]);
|
||||
DockMaster.MakeDockable(AForm,false);
|
||||
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)]);
|
||||
Site:=DockMaster.GetSite(AForm);
|
||||
if DockSiblingName<>'' then
|
||||
begin
|
||||
if DockMaster.IsAnchorSite(Site) and (DockSiblingName<>'') then begin
|
||||
DockSibling:=Screen.FindForm(DockSiblingName);
|
||||
debugln(['TIDEAnchorDockMaster.ShowForm DockSiblingName="',DockSiblingName,'" DockSibling=',DbgSName(DockSibling)]);
|
||||
if DockSibling<>nil then
|
||||
begin
|
||||
if DockSibling<>nil then begin
|
||||
NewDockSite:=DockMaster.GetSite(DockSibling);
|
||||
debugln(['TIDEAnchorDockMaster.ShowForm NewDockSite=',DbgSName(NewDockSite),'="',NewDockSite.Caption,'"']);
|
||||
DockMaster.ManualDock(Site,NewDockSite,DockAlign);
|
||||
@ -231,10 +253,7 @@ begin
|
||||
end;
|
||||
|
||||
finally
|
||||
if DockMaster.IsCustomSite(AForm) then
|
||||
AForm.Visible:=true
|
||||
else
|
||||
DockMaster.MakeDockable(AForm,true,false);
|
||||
DockMaster.MakeVisible(AForm,BringToFront);
|
||||
AForm.EnableAlign;
|
||||
|
||||
if BringToFront then begin
|
||||
|
||||
Loading…
Reference in New Issue
Block a user