LCL Drag Dock

From Free Pascal wiki
Jump to navigationJump to search

Controls or entire forms in a GUI can be glued together and detached again. Such docking is similar to drag-drop, but differs in some aspects.

Procedure

A docking operation is organized just as any other dragging operation.

DragInit

On start of a docking operation the visual feedback has to be initialized, as usual.

DragTo

On a move a couple of steps have to be taken:

  • Whether the user doesn't want to dock at all
  • Determination of possible target sites
  • Determination of the precise drop zone
  • Visual feedback

DragDone

On a drop, several reasons can block docking,

Docking Elements Overview

In addition to the drag-drop players, some more players enter the scene:

  • Dock sites
  • Dock rectangles as visual feedback
  • Dock managers

Dock Source

A control or form can be made dockable by setting its DragKind property to dkDock.

Dock Targets

Docking requires special drop target zones, called dock sites. A TWinControl becomes a docking target by setting its DockSite property to True.

The DockRect

Usually a rectangular shape follows the mouse pointer in a docking operation, to distinguish it from a drag-drop operation. The difference becomes obvious when the mouse hovers over a dock site. Then the shape snaps to a possible drop location, in both position and size.

The DockObject

A special DockObject is used in a docking operation, derived from TDragObject. It's unclear why this class introduces new methods, instead of overriding the existing virtual methods for the different visual feedback.

Helper Methods

A bunch of helper methods and fields has been introduced into the TControl and TWinControl classes. The purpose of the methods is not always clear, and the Delphi implementation only happens to work under certain conditions, and with significant restrictions.

RegisterDockSite

Dock sites can be covered partially or entirely by other forms, but shall act as docking targets in any case. This procedure registers and unregisters controls in an application as dock sites, so that even hidden candidates can be found while dragging a dock source over the screen.

GetSiteInfo

The TWinControl.GetSiteInfo method returns an influence (catching) rectangle, associated with the dock site. This convention allows to e.g. hide empty dock sites in the GUI, without making them unreachable for dropping. The default implementation returns the visible control extent, increased by an certain amount in either direction.