Build custom dock manager

From Lazarus wiki
Revision as of 11:06, 26 August 2010 by Chronos (talk | contribs)
Jump to navigationJump to search

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.

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;

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.

TCustomDockManager = class(TDockManager)
end;

To make dock manager default for all dockable controls use:

DefaultDockManagerClass := TCustomDockManager;

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

External links