LCL: anchordocking: added owner for TlazDockForms, implemented DragOver for TlazDockForm

git-svn-id: trunk@14032 -
This commit is contained in:
mattias 2008-02-08 15:06:19 +00:00
parent 7e96f598d5
commit 1ca8d4b353
2 changed files with 69 additions and 8 deletions

View File

@ -25,6 +25,8 @@
This unit contains visual components for docking and streaming. This unit contains visual components for docking and streaming.
ToDo: ToDo:
- move the docking code to TCustomAnchoredDockManager
and keep only the resizing code here.
- restoring layout: pages - restoring layout: pages
- restoring layout: move form after inserting a control - restoring layout: move form after inserting a control
- restoring layout: spiral splitter - restoring layout: spiral splitter
@ -903,7 +905,7 @@ begin
if NeighbourControl.Parent=nil then begin if NeighbourControl.Parent=nil then begin
// NeighbourControl is a standalone control (e.g. an undocked form) // NeighbourControl is a standalone control (e.g. an undocked form)
// => create a new TLazDockForm and put both controls into it // => create a new TLazDockForm and put both controls into it
NewParent:=TLazDockForm.Create(nil); NewParent:=Manager.Manager.CreateForm;
NewParentCreated:=true; NewParentCreated:=true;
end else begin end else begin
// NeighbourControl is docked // NeighbourControl is docked
@ -1079,7 +1081,7 @@ begin
if NeighbourControl.Parent=nil then begin if NeighbourControl.Parent=nil then begin
// NeighbourControl is a top level control (no parents, no neighbours) // NeighbourControl is a top level control (no parents, no neighbours)
// => create a TLazDockForm with a TLazDockPages and two TLazDockPage // => create a TLazDockForm with a TLazDockPages and two TLazDockPage
TopForm:=TLazDockForm.Create(nil); TopForm:=Manager.Manager.CreateForm;
TopFormBounds:=PagesNode.Bounds; TopFormBounds:=PagesNode.Bounds;
// TODO: shrink TopFormBounds // TODO: shrink TopFormBounds
TopForm.BoundsRect:=TopFormBounds; TopForm.BoundsRect:=TopFormBounds;

View File

@ -108,7 +108,6 @@ type
TLazDockForm = class(TCustomForm) TLazDockForm = class(TCustomForm)
private private
FMainControl: TControl; FMainControl: TControl;
FPageControl: TLazDockPages;
procedure SetMainControl(const AValue: TControl); procedure SetMainControl(const AValue: TControl);
procedure PaintWindow(DC: HDC); override; procedure PaintWindow(DC: HDC); override;
protected protected
@ -124,8 +123,7 @@ type
function ControlHasTitle(Control: TControl): boolean; function ControlHasTitle(Control: TControl): boolean;
function GetTitleRect(Control: TControl): TRect; function GetTitleRect(Control: TControl): TRect;
function GetTitleOrientation(Control: TControl): TDockOrientation; function GetTitleOrientation(Control: TControl): TDockOrientation;
property PageControl: TLazDockPages read FPageControl; property MainControl: TControl read FMainControl write SetMainControl;// used for the default caption
property MainControl: TControl read FMainControl write SetMainControl;
end; end;
@ -165,12 +163,26 @@ type
TLazDockSplitter = class(TCustomSplitter) TLazDockSplitter = class(TCustomSplitter)
end; end;
TCustomAnchoredDockManager = class;
{ TLazDockOwnerComponent
A TComponent owning all automatically created controls of a
TCustomAnchoredDockManager, like TLazDockForm }
TLazDockOwnerComponent = class(TComponent)
public
Manager: TCustomAnchoredDockManager;
end;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
{ TCustomAnchoredDockManager { TCustomAnchoredDockManager
This class implements an LCL TDockManager via anchoring. This class implements an LCL TDockManager via anchoring.
The TCustomLazDockingManager component uses this docking manager It implements the docking, undocking, enlarging, shrinking.
and extends it by layouts that can be stored/restored. }
The TCustomLazDockingManager component in LDockCtrl uses this
docking manager and extends it by layouts that can be stored/restored. }
TCustomAnchoredDockManager = class(TDockManager) TCustomAnchoredDockManager = class(TDockManager)
private private
@ -179,6 +191,7 @@ type
FTitleWidth: integer; FTitleWidth: integer;
FUpdateCount: integer; FUpdateCount: integer;
protected protected
FOwnerComponent: TLazDockOwnerComponent;
procedure DeleteSideSplitter(Splitter: TLazDockSplitter; Side: TAnchorKind; procedure DeleteSideSplitter(Splitter: TLazDockSplitter; Side: TAnchorKind;
NewAnchorControl: TControl); NewAnchorControl: TControl);
procedure CombineSpiralSplitterPair(Splitter1, Splitter2: TLazDockSplitter); procedure CombineSpiralSplitterPair(Splitter1, Splitter2: TLazDockSplitter);
@ -187,8 +200,11 @@ type
procedure DeleteDockForm(ADockForm: TLazDockForm); procedure DeleteDockForm(ADockForm: TLazDockForm);
function GetAnchorDepth(AControl: TControl; Side: TAnchorKind): Integer; function GetAnchorDepth(AControl: TControl; Side: TAnchorKind): Integer;
function GetPreferredTitlePosition(AWidth, AHeight: integer): TAnchorKind; function GetPreferredTitlePosition(AWidth, AHeight: integer): TAnchorKind;
procedure OnLazDockFormDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
public public
constructor Create; constructor Create;
destructor Destroy; override;
procedure BeginUpdate; override; procedure BeginUpdate; override;
procedure EndUpdate; override; procedure EndUpdate; override;
procedure GetControlBounds(Control: TControl; procedure GetControlBounds(Control: TControl;
@ -218,6 +234,10 @@ type
procedure ResetBounds(Force: Boolean); override;// not implemented procedure ResetBounds(Force: Boolean); override;// not implemented
procedure SaveToStream(Stream: TStream); override;// not implemented procedure SaveToStream(Stream: TStream); override;// not implemented
procedure SetReplacingControl(Control: TControl); override;// not implemented procedure SetReplacingControl(Control: TControl); override;// not implemented
// ToDo: move this to protected, after dockig code from LDockCtrl was moved
// here.
function CreateForm: TLazDockForm;
end; end;
@ -1347,6 +1367,32 @@ end;
{ TCustomAnchoredDockManager } { TCustomAnchoredDockManager }
procedure TCustomAnchoredDockManager.OnLazDockFormDragOver(Sender,
Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
var
Form: TLazDockForm;
DragCtrlObj: TDragControlObject;
SrcForm: TLazDockForm;
begin
Accept:=false;
//DebugLn(['TCustomAnchoredDockManager.CustomAnchoredDockManagerDragOver ',DbgSName(Sender),' ',DbgSName(Source)]);
if not (Sender is TLazDockForm) then exit;
Form:=TLazDockForm(Sender);
if Form.Owner<>FOwnerComponent then exit;
if (Source is TDragControlObject) then
begin
DragCtrlObj:=TDragControlObject(Source);
if DragCtrlObj.Control is TLazDockForm then
begin
SrcForm:=TLazDockForm(DragCtrlObj.Control);
end else
exit;
if SrcForm.Owner<>FOwnerComponent then exit;
end else
exit;
Accept:=true;
end;
procedure TCustomAnchoredDockManager.DeleteSideSplitter(Splitter: TLazDockSplitter; procedure TCustomAnchoredDockManager.DeleteSideSplitter(Splitter: TLazDockSplitter;
Side: TAnchorKind; NewAnchorControl: TControl); Side: TAnchorKind; NewAnchorControl: TControl);
var var
@ -1548,11 +1594,18 @@ end;
constructor TCustomAnchoredDockManager.Create; constructor TCustomAnchoredDockManager.Create;
begin begin
FOwnerComponent:=TLazDockOwnerComponent.Create(nil);
FSplitterSize:=5; FSplitterSize:=5;
FTitleWidth:=20; FTitleWidth:=20;
FTitleHeight:=20; FTitleHeight:=20;
end; end;
destructor TCustomAnchoredDockManager.Destroy;
begin
FreeAndNil(FOwnerComponent);
inherited Destroy;
end;
procedure TCustomAnchoredDockManager.BeginUpdate; procedure TCustomAnchoredDockManager.BeginUpdate;
begin begin
inc(FUpdateCount); inc(FUpdateCount);
@ -1663,7 +1716,7 @@ begin
// remember bounds // remember bounds
NewDropCtlBounds:=Rect(0,0,DropCtl.ClientWidth,DropCtl.ClientHeight); NewDropCtlBounds:=Rect(0,0,DropCtl.ClientWidth,DropCtl.ClientHeight);
// create a TLazDockForm as new parent with the size of DropCtl // create a TLazDockForm as new parent with the size of DropCtl
NewParent:=TLazDockForm.Create(Application);// starts with Visible=false NewParent:=CreateForm;// starts with Visible=false
NewParent.DisableAlign; NewParent.DisableAlign;
ParentDisabledAlign:=true; ParentDisabledAlign:=true;
NewParent.BoundsRect:=DropCtl.BoundsRect; NewParent.BoundsRect:=DropCtl.BoundsRect;
@ -2379,6 +2432,12 @@ begin
RaiseGDBException('TCustomAnchoredDockManager.SetReplacingControl TODO'); RaiseGDBException('TCustomAnchoredDockManager.SetReplacingControl TODO');
end; end;
function TCustomAnchoredDockManager.CreateForm: TLazDockForm;
begin
Result:=TLazDockForm.Create(FOwnerComponent);
Result.OnDragOver:=@OnLazDockFormDragOver;
end;
procedure TCustomAnchoredDockManager.ReplaceAnchoredControl(OldControl, procedure TCustomAnchoredDockManager.ReplaceAnchoredControl(OldControl,
NewControl: TControl); NewControl: TControl);
var var