[Lazarus] Purpose of MouseCapture?

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sun Jan 9 15:23:48 CET 2011


Paul Ishenin schrieb:
> 08.01.2011 22:16, Hans-Peter Diettrich wrote:
>> Hans-Peter Diettrich schrieb:
>>> What's the purpose of setting the mouse capture in the LCL?
>>
>> While nobody seems to know, I found that TSpltter uses mouse capture.
> Sorry, I did not notice the initial mail.
>>
>> So the DragManager simply should ignore CaptureChanged.
> The purpose of mouse capture is to be sure that you are recieving all 
> mouse events until you want to stop mouse capture

So much about theory. My question was about reasons for using mouse
capture in LCL components, in detail the csCaptureMouse control state
flag. So far its only reasonable use is in a TSplitter, to allow for
fake moves (user feedback) and to obtain the final position of the splitter.

> or external event 
> stops your mouse capture. Such external event can be for example 
> switching task or another window require a mouse capture.

The mouse is a shared resource, managed by the OS. I doubt that the
mouse capture can be stolen by other processes. I.e. the owner of the
mouse capture must release the capture, at some time (usually when the
mouse button is released).

> When you start a drag operator you must always request the capture. In 
> other case you cannot track mouse events outside the dragged control.

ACK.

> DragManager must handle the CaptureChanged event in order to understand 
> that capture it has was requested by other control and therefore it must 
> stop the drag operation.

NACK. The LCL components implement some weird behaviour, that can result
in many changes of the mouse capture at the begin of a drag operation.
These nearly unpredictable changes often cause the DragManager to stop
dragging, in the current implementation. Once a control is dragged, 
there is no reason why the mouse capture should change until the end of 
the operation. When a control decides that dragging should stop, it 
should call DragManager.DragStop, everything else is insane.

DoDi





More information about the Lazarus mailing list