Difference between revisions of "LCL Drag Drop"

From Lazarus wiki
Jump to navigationJump to search
 
Line 1: Line 1:
== DoDi's Guide to Dragging, Dropping and Docking ==
+
DoDi's Guide to Dragging, Dropping and Docking
 +
 
 
Controls can be grabbed with the mouse, dragged to other locations, and dropped onto other controls or onto the desktop. When the dragged control is moved to a different location, the operation is called "docking". Otherwise the source and target control can exchange information or interact in any other way, what's called a "drag-drop" operation.
 
Controls can be grabbed with the mouse, dragged to other locations, and dropped onto other controls or onto the desktop. When the dragged control is moved to a different location, the operation is called "docking". Otherwise the source and target control can exchange information or interact in any other way, what's called a "drag-drop" operation.
 +
 +
But all that does'n work by itself, an application must set up the allowed operations so that the LCL can know what to do with every single control in a GUI. Sophisticated operations require further code for managing the visual feedback to the application user, and what will happen when the dragged control finally is dropped.
 +
__TOC__
 +
== Common Principles ==
 +
A control can be made draggable by setting its ''DragMode'' property to ''dmAutomatic''. When the user presses the left mouse button over such a control, the mouse pointer changes into an dragging indicator until the user releases the button, or cancels the operation by pressing the Escape key. The indicator now follows the mouse movements and changes its shape, according to what will happen when the control is dropped in the current location. All that is managed by a ''DragManager'', in cooperation with the source and target controls. The desired action is given in the ''DragKind'' property of the source control, which can be either ''dkDrag'' for drag-drop or ''dkDock'' for docking.
 +
 +
Sometimes dragging shall not be started immediately, so that a control can be clicked for it's "natural" operation. This can be achieved in two ways: Mouse.DragImmediate affects all dragging operations, otherwise dragging can be started in the OnMouseDown (or any other) event handler, by calling source.BeginDrag(False).

Revision as of 12:20, 16 April 2009

DoDi's Guide to Dragging, Dropping and Docking

Controls can be grabbed with the mouse, dragged to other locations, and dropped onto other controls or onto the desktop. When the dragged control is moved to a different location, the operation is called "docking". Otherwise the source and target control can exchange information or interact in any other way, what's called a "drag-drop" operation.

But all that does'n work by itself, an application must set up the allowed operations so that the LCL can know what to do with every single control in a GUI. Sophisticated operations require further code for managing the visual feedback to the application user, and what will happen when the dragged control finally is dropped.

Common Principles

A control can be made draggable by setting its DragMode property to dmAutomatic. When the user presses the left mouse button over such a control, the mouse pointer changes into an dragging indicator until the user releases the button, or cancels the operation by pressing the Escape key. The indicator now follows the mouse movements and changes its shape, according to what will happen when the control is dropped in the current location. All that is managed by a DragManager, in cooperation with the source and target controls. The desired action is given in the DragKind property of the source control, which can be either dkDrag for drag-drop or dkDock for docking.

Sometimes dragging shall not be started immediately, so that a control can be clicked for it's "natural" operation. This can be achieved in two ways: Mouse.DragImmediate affects all dragging operations, otherwise dragging can be started in the OnMouseDown (or any other) event handler, by calling source.BeginDrag(False).