View Issue Details

IDProjectCategoryView StatusLast Update
0006474JEDI VCL00 JVCL Componentspublic2016-08-04 19:37
ReporterRalfNegtAssigned ToAHUser 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.48 
Target VersionFixed in VersionDaily / GIT 
Summary0006474: JvDBGrid OnMouseDown won't be called
DescriptionActually i cannot start a drag action with an OnMouseDown event handler.

Have a look at the method "TJvDBGrid.MouseDown" below and
especially the flag "InheritedCalled".
There are three conditions setting the flag.
The event OnMouseDown will only be called if the flag isn't set.

When i assign an event handler i want it to be called.
But here the component itself decides whether or not to do so.
Please remove the flag "InheritedCalled".
By the way the variable "MouseDownEvent" is unnecessary.
It can be replace by "OnMouseDown".

procedure TJvDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  ...
  MouseDownEvent: TMouseEvent;
  ...
  InheritedCalled: Boolean;
begin
  ...
      InheritedCalled := False;
  ...
          if dgIndicator in Options then
          begin
            inherited MouseDown(Button, Shift, 1, Y);
            InheritedCalled := True;
          end
  ...
            if (dgRowSelect in Options) and (Cell.Y >= TitleOffset) then
            begin
              // Why do we always have to work around the VCL. If we use the original X the
              // Grid will scroll back to the first column. But if we don't use the original X
              // and goRowSizing is enabled, the user can start resizing rows in the wild.
              WasRowResizing := goRowSizing in TCustomGridAccess(Self).Options;
              try
                // Disable goRowSizing without all the code that SetOptions executes.
                TGridOptions(Pointer(@TCustomGridAccess(Self).Options)^) := TCustomGridAccess(Self).Options - [goRowSizing];
                inherited MouseDown(Button, Shift, 1, Y);
                InheritedCalled := True;
              finally
                if WasRowResizing then
                  TGridOptions(Pointer(@TCustomGridAccess(Self).Options)^) := TCustomGridAccess(Self).Options + [goRowSizing];
              end;
            end
            else
            begin
              inherited MouseDown(Button, Shift, X, Y);
              InheritedCalled := True;
            end;
  ...
      MouseDownEvent := OnMouseDown;
      if Assigned(MouseDownEvent) and not InheritedCalled then
        MouseDownEvent(Self, Button, Shift, X, Y);
  ...
end;
TagsNo tags attached.

Activities

dougwoodrow

2016-04-11 11:37

reporter   ~0021283

This appears to have been introduced by an attempt to fix a situation with OnMouseDown being called twice.

see commit by obones Dec 16 2013 "Mantis 5915: Do not call OnMouseDown twice"

https://github.com/project-jedi/jvcl/commit/b6b42daa3350c35ccf0040bd8201c40edd58d28b

dougwoodrow

2016-04-11 12:09

reporter   ~0021284

This bug results in the OnMouseDown event not being called when the mouse is over a data record, it is called when the mouse is over the title buttons or outside the data records.

2016-04-12 11:03

 

DBGridOnMouseDownFailure.zip (1,702 bytes)

dougwoodrow

2016-04-12 11:07

reporter   ~0021285

I've attached a sample Delphi 7 application (copied from Mantis 5915) to demonstrate the problem.

Note that with RalfNegt's proposed solution the TJvUltimGrid still has problems, but TJvDBGrid seems ok.

http://issuetracker.delphi-jedi.org/view.php?id=5915

dougwoodrow

2016-04-12 11:30

reporter   ~0021286

(Sorry, please remove mad* from Project1.dpr).

Note also this problem is still present in JVCL version 3.49.

AHUser

2016-08-04 19:37

developer   ~0021328

Fixed in master branch.

OnMouseDown is now called even if there was a call to "inherited MouseDown" that didn't call "TControl.MouseDown".

I also added a OnBeforeMouseDown and OnAfterMouseDown event, so you also get notified if the user clicks on a header cell.

Issue History

Date Modified Username Field Change
2015-11-30 17:08 RalfNegt New Issue
2016-04-11 11:37 dougwoodrow Note Added: 0021283
2016-04-11 12:09 dougwoodrow Note Added: 0021284
2016-04-12 11:03 dougwoodrow File Added: DBGridOnMouseDownFailure.zip
2016-04-12 11:08 dougwoodrow Note Added: 0021285
2016-04-12 11:30 dougwoodrow Note Added: 0021286
2016-08-04 19:37 AHUser Note Added: 0021328
2016-08-04 19:37 AHUser Status new => resolved
2016-08-04 19:37 AHUser Fixed in Version => Daily / GIT
2016-08-04 19:37 AHUser Resolution open => fixed
2016-08-04 19:37 AHUser Assigned To => AHUser