#135 Right mouse click doesn't release mouse capture

open
nobody
None
5
2012-11-22
2012-11-22
No

When the right mouse button is pressed in a tImgView32, and the control has layers, the mouse listener is gets set and not released. This has the effect of making it so that mouse clicks outside the image view cause controls to not work. Here are some segments of code in a right mouse click:

function TLayerCollection.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer): TCustomLayer;
begin
if Assigned(MouseListener) then
Result := MouseListener
else
Result := FindLayerAtPos(X, Y, LOB_MOUSE_EVENTS);

if (Result <> MouseListener) and ((Result = nil) or ((Result.FLayerOptions and LOB_NO_CAPTURE) = 0)) then
MouseListener := Result; // capture the mouse <===== Get assigned here.

if Assigned(MouseListener) then
begin
Include(MouseListener.FLayerStates, CStateMap[Button]);
MouseListener.MouseDown(Button, Shift, X, Y);
end;
end;

Then, this causes the mouse capture setting to be set to true in the following method

procedure TCustomImage32.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Layer: TCustomLayer;
begin
inherited;

if TabStop and CanFocus then SetFocus;

if Layers.MouseEvents then
Layer := TLayerCollectionAccess(Layers).MouseDown(Button, Shift, X, Y)
else
Layer := nil;

// lock the capture only if mbLeft was pushed or any mouse listener was activated
if (Button = mbLeft) or (TLayerCollectionAccess(Layers).MouseListener <> nil) then
MouseCapture := True; <===== Right here, because the mouse listener is not null, then mouse capture is set to true.

MouseDown(Button, Shift, X, Y, Layer);
end;.

Mouse is released, we have
function TLayerCollection.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer): TCustomLayer;
begin
Result := MouseListener;
if Result = nil then Result := FindLayerAtPos(X, Y, LOB_MOUSE_EVENTS);

if Assigned(Result) then
begin
Exclude(Result.FLayerStates, CStateMap[Button]);
Result.MouseUp(Button, Shift, X, Y);
end;

if Assigned(MouseListener) and
(MouseListener.FLayerStates *
[lsMouseLeft, lsMouseRight, lsMouseMiddle] = []) then
MouseListener := nil; // reset mouse capture <=============By resetting it here, the following section of code causes the mouse capture to stay on.
end;

procedure TCustomImage32.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Layer: TCustomLayer;
begin
if Layers.MouseEvents then
Layer := TLayerCollectionAccess(Layers).MouseUp(Button, Shift, X, Y)
else
Layer := nil;

// unlock the capture using same criteria as was used to acquire it
if (Button = mbLeft) or (TLayerCollectionAccess(Layers).MouseListener <> nil) then
MouseCapture := False; <========= This line does not get run because the button is not the left button, and the listener is now Null (set in the above method).

MouseUp(Button, Shift, X, Y, Layer);
end;

Discussion

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks