Unwanted MouseMode

This article was written for phGantTimePackage VCL (Delphi XE5)

We got the question and a repeating sample to support that showed a scenario where the developer wanted to bring up a modal dialog in double click on a TimeItem.

All that is straight forward:

procedure TForm1.phGant1DblClickGantArea(theGant: TphGant_ComBasic;
  theDataEntity: TphDataEntity_GantTime);
var FrmModal:TFrmModal;
begin
  FrmModal:=TFrmModal.create(nil);
  try
    FrmModal.ShowModal;
  finally
    FrmModal.Free;
  end;
end;

 

The problem was that when the user did this double click and was in a resize hot-zone for the time item – the mouse mode Resize was entered and was still set when the modal dialog was closed.

My first response was to call the method MouseMoveModeCancel. This method is useful for programmatically end any current mouse mode.

However it turned out to not work in this case.

The reason for it not working was that after the DblClick event returns – VCL diretly fires the MouseDown once more – and this is where we actually entered the mouse mode.

In phGantTimePackage there is a way do dispatch a call to the windows message queue and this comes in handy here. The mechanism is called TDoLater and the solution looks like this:

 

procedure TForm1.phGant1DblClickGantArea(theGant: TphGant_ComBasic;
  theDataEntity: TphDataEntity_GantTime);
var FrmModal:TFrmModal;
begin
  FrmModal:=TFrmModal.create(nil);
  try
    FrmModal.ShowModal;
    TDoLater.DoLater(LeaveAnyUnintentionalMouseMoveMode,nil);
  finally
    FrmModal.Free;
  end;
end;

procedure TForm1.LeaveAnyUnintentionalMouseMoveMode(a:TObject);
begin
    phGant1.MouseMoveModeCancel;
end;

 

This way the defer the MouseMoveCancel to a time to directly after all the current messages that windows has on user interaction.

To use the TDoLater you need a uses for phDoLater.

Leave a Reply