EasyDockingManager

From Lazarus wiki
Jump to navigationJump to search

Easy Docking Manager Package

The examples/EasyDockMgr package offers several helpers for docking support. This entry is organized in multiple levels, which cover different views on the docking topics.

Please note: All mentioned names may change in a final release!

Adding Docking Support to an entire Application

In the most simple case you make one or more forms of your application DockSites, to which other forms can be docked. Then make selected or all other forms dockable, and everything else will be done for you :-)

Prerequisites

The uMakeSite unit defines a DockMaster class and variable (singleton), that manages all docking issues.

Making a Form a DockSite

Use DockMaster.AddElasticSites() to make a form a DockSite. Currently docking regions (panels) can be added to the left, right and bottom of a form. "Elastic" here means that the docking regions are almost invisible, as long as nothing is docked into them. When a first component is docked into such a region, the panel extends either within the form, reducing the form's client area, or it expands the form, depending on where exactly the component is dropped. The DockRect frame indicates which kind of expansion will occur on a drop. The size of every docking region can be adjusted later by moving its associated splitter.

Making a Form dockable

Use DockMaster.MakeDockable() to make any of your forms dockable. This includes setting the related properties (DragKind...), and a pin-shaped dock grip is added to the form. This grip is needed on platforms that do not (yet) support for dragging entire forms, its exact appearance and placement may be changed.

When a form doesn't deserve special initialization, DockMaster.CreateDockable() can be used to also create the dockable form, given a form name. Here the form name must correspond to a registered form class name, and it can include an instance number. E.g. "Form3" will create a form of class "TForm3" when fMultiInst is False. When fMultiInst is True, e.g. "DockForm2" will create a form of class "TDockForm", named "DockForm2".

Saving and Restoring a Layout

If you want your application to restore the previous docked layout on the next start, DockMaster.SaveToStream() stores all required layout information in the given stream. It's your responsibility to provide an according TFileStream. You can store different layouts in different files, if you like.

DockMaster.LoadFromStream() restores the previously stored layout. This means that the elastic and floating dock sites are created, and the previously docked forms are searched or created, and then are docked into their previous places.

But how does the DockMaster know whether a docked form already exists, or whether a new instance has to be created? This requires that all dockable forms have the same Owner (TComponent), which includes a list of all already created dockable form or component instances. In default GUI applications the Application object is the Owner of all Forms, the Lazarus IDE instead uses a dedicated OwningComponent for this purpose.

The EasyDockTree Manager

Almost every DockSite needs an DockManager. The EasyDockTree manager allows to build an dock tree, that grows by docking other components to any side (top/bottom, left/right) of an already docked component. Dropping a component into the middle of another component creates a tabbed notebook, to which more components can be docked as notebook pages.

Docking Helper Classes

A FloatingSite is a container form for other components, that possibly cannot exist without a parent form (TControl). It also acts as an entire docking site (form), to which other components can be docked.

A DockBook also is a container form for other components, that keeps docked components in distinct notebook pages, while a FloatingSite shows the docked components beneath each other.