Difference between revisions of "Build custom dock manager"
Line 4: | Line 4: | ||
Recommended reading: [[LCL Drag Dock]] | Recommended reading: [[LCL Drag Dock]] | ||
+ | |||
+ | ==Possible docking features== | ||
+ | |||
+ | * Docking zone hierarchy | ||
+ | ** One item | ||
+ | ** Linear list | ||
+ | ** Tree | ||
+ | ** Table | ||
+ | ** Anchored layout | ||
+ | ** Another complex organization | ||
+ | * Tabbed docking | ||
+ | * Docking multiple forms to floating conjoined window | ||
+ | * Themes | ||
+ | * Persistence, Store/Restore docking layout | ||
+ | * Tabbed docking with autoshow/autohide forms, pin button to switch autohide/visible | ||
+ | * Custom header buttons | ||
+ | * Building default layout directly from code, manual management | ||
+ | * Supporting visual design-time components, docking customize form | ||
+ | * Class for global docking operations | ||
==Dragging== | ==Dragging== | ||
Line 58: | Line 77: | ||
</pre> | </pre> | ||
− | == | + | ==Implementing basic custom DockManager== |
It is possible to derive our custom manager from default TDockTree. But for purpose of creating completely custom manager parent class have to be TDockManager. All methods from parent class should be overridden. | It is possible to derive our custom manager from default TDockTree. But for purpose of creating completely custom manager parent class have to be TDockManager. All methods from parent class should be overridden. | ||
− | For basic demonstration dock manager should be able to manage one control. That class can be extended later. | + | * For basic demonstration dock manager should be able to manage one control. That class can be extended later. |
<pre>TCustomDockManager = class(TDockManager) | <pre>TCustomDockManager = class(TDockManager) | ||
Line 88: | Line 107: | ||
</pre> | </pre> | ||
− | + | * DockManager have to know to which TWinControl belong. So manager need field FDockSite of type TWinControl which is assigned by constructor. | |
+ | |||
+ | * Now we can implement method PositionDockRect which determine dock frame size according to size of DockSite. | ||
− | + | procedure PositionDockRect(Client, DropCtl: TControl; DropAlign: TAlign; | |
+ | var DockRect: TRect); override; overload; | ||
+ | begin | ||
+ | DockRect := Rect(0, 0, FDockSite.ClientWidth, FDockSite.ClientHeight); | ||
+ | end; | ||
− | + | * To make dock manager default for all dockable controls insert initialization section to end of unit. Then simply inclusion of dock manager unit into main form unit will setup your docking system. | |
− | + | initialization | |
− | + | DefaultDockManagerClass := TCustomDockManager; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==See also== | ==See also== |
Revision as of 12:28, 26 August 2010
Introduction
VCL and LCL support basic docking of controls. For advanced docking behavior custom dock manager have to be created. Basic abstract dock manager class TDockManager is placed in Controls unit. All custom manager have to be deriver from this class. Basic LCL implementation of TDockManager is TDockTree which is capable of handling tree of dock zones.
Recommended reading: LCL Drag Dock
Possible docking features
- Docking zone hierarchy
- One item
- Linear list
- Tree
- Table
- Anchored layout
- Another complex organization
- Tabbed docking
- Docking multiple forms to floating conjoined window
- Themes
- Persistence, Store/Restore docking layout
- Tabbed docking with autoshow/autohide forms, pin button to switch autohide/visible
- Custom header buttons
- Building default layout directly from code, manual management
- Supporting visual design-time components, docking customize form
- Class for global docking operations
Dragging
Docking is basically special case of Drag & Drop action for forms and similar controls. Therefore basic events of controls are similar.
Dragging events: OnDragOver, OnDragDrop, OnStartDrag, OnEndDrag Docking events: OnDockOver, OnDockDrop, OnStartDock, OnEndDock, OnUnDock
Dragged object is represented by class TDragObject and this class is further extended to class TDragControlObject and for needs of docking next to TDragDockObject. Whole process of dragging is controlled by TDragManager similarly to TDockManager.
Docking subsystem
TControl support
TControl = class ... procedure DragDrop(Source: TObject; X,Y: Integer); virtual; procedure Dock(NewDockSite: TWinControl; ARect: TRect); virtual; function ManualDock(NewDockSite: TWinControl; DropControl: TControl = nil; ControlSide: TAlign = alNone; KeepDockSiteSize: Boolean = true): Boolean; virtual; function ManualFloat(TheScreenRect: TRect; KeepDockSiteSize: Boolean = true): Boolean; virtual; property DockOrientation: TDockOrientation read FDockOrientation write FDockOrientation; property Floating: Boolean read GetFloating; property FloatingDockSiteClass: TWinControlClass read GetFloatingDockSiteClass write FFloatingDockSiteClass; property HostDockSite: TWinControl read FHostDockSite write SetHostDockSite; property LRDockWidth: Integer read GetLRDockWidth write FLRDockWidth; property TBDockHeight: Integer read GetTBDockHeight write FTBDockHeight; property UndockHeight: Integer read GetUndockHeight write FUndockHeight; // Height used when undocked property UndockWidth: Integer read GetUndockWidth write FUndockWidth; // Width used when undocked ... end;
TWinControl support
TWinControl = class(TControl) ... property DockClientCount: Integer read GetDockClientCount; property DockClients[Index: Integer]: TControl read GetDockClients; property DockManager: TDockManager read FDockManager write SetDockManager; property DockSite: Boolean read FDockSite write SetDockSite default False; property OnUnDock: TUnDockEvent read FOnUnDock write FOnUnDock; property UseDockManager: Boolean read FUseDockManager write SetUseDockManager default False; property VisibleDockClientCount: Integer read GetVisibleDockClientCount; procedure DockDrop(DragDockObject: TDragDockObject; X, Y: Integer); virtual; ... end;
Implementing basic custom DockManager
It is possible to derive our custom manager from default TDockTree. But for purpose of creating completely custom manager parent class have to be TDockManager. All methods from parent class should be overridden.
- For basic demonstration dock manager should be able to manage one control. That class can be extended later.
TCustomDockManager = class(TDockManager) constructor Create(ADockSite: TWinControl); override; procedure BeginUpdate; override; procedure EndUpdate; override; procedure GetControlBounds(Control: TControl; out AControlBounds: TRect); override; function GetDockEdge(ADockObject: TDragDockObject): boolean; override; procedure InsertControl(ADockObject: TDragDockObject); override; overload; procedure InsertControl(Control: TControl; InsertAt: TAlign; DropCtl: TControl); override; overload; procedure LoadFromStream(Stream: TStream); override; procedure PaintSite(DC: HDC); override; procedure MessageHandler(Sender: TControl; var Message: TLMessage); override; procedure PositionDockRect(ADockObject: TDragDockObject); override; overload; procedure PositionDockRect(Client, DropCtl: TControl; DropAlign: TAlign; var DockRect: TRect); override; overload; procedure RemoveControl(Control: TControl); override; procedure ResetBounds(Force: Boolean); override; procedure SaveToStream(Stream: TStream); override; procedure SetReplacingControl(Control: TControl); override; function AutoFreeByControl: Boolean; override; end;
- DockManager have to know to which TWinControl belong. So manager need field FDockSite of type TWinControl which is assigned by constructor.
- Now we can implement method PositionDockRect which determine dock frame size according to size of DockSite.
procedure PositionDockRect(Client, DropCtl: TControl; DropAlign: TAlign; var DockRect: TRect); override; overload; begin DockRect := Rect(0, 0, FDockSite.ClientWidth, FDockSite.ClientHeight); end;
- To make dock manager default for all dockable controls insert initialization section to end of unit. Then simply inclusion of dock manager unit into main form unit will setup your docking system.
initialization DefaultDockManagerClass := TCustomDockManager;