Board index » delphi » TTreeView.OnMouseUp doesn't work properly with D5

TTreeView.OnMouseUp doesn't work properly with D5

I have an OnMouseUp event handler defined for a TTreeView.  Under Delphi 5,
the event handler is only called on the second right mouse-button click, not
the first.  It works fine however for the left mouse-button.

Is anyone else able to reproduce this error.  I created a simple app with a
treeview and a listview and assigned the following OnMouseUp event handler
to both.

procedure TForm1.ListView1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   ShowMessage('Mouse up');
end;

When I right-click the listview, the message shows straight away, but when I
right-click the treeview it only comes up after the second right-click.

Regards,
Scott Barden

 

Re:TTreeView.OnMouseUp doesn't work properly with D5


Quote
> I have an OnMouseUp event handler defined for a TTreeView.  Under Delphi 5,
> the event handler is only called on the second right mouse-button click, not
> the first.  

It only fires if you double-click with the right mouse button, if the two
clicks are spaced apart by more than the systems doubleclick time it will not
fire. I think this is due to the fact that the treeview needs to override the
right mouse click behaviour. If you right-mouse down on an item the item is
selected and if the button goes up selection reverts to the previously
selected item.  From the code in comctrls.pas it looks as if the treeview does
not even *get* WM_RBUTTONUP after a right button down on an item, and even the
WM_RBUTTONDOWN does only arrive after the button has gone up again (the
OnMouseDown event fires when you let go of the button, not when it went down).

This seems to be a problem in the Windows common control itself, not in the
Delphi wrapper, which does absolutely nothing with right button messages.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:TTreeView.OnMouseUp doesn't work properly with D5


Thanks for the in-depth analysis Peter, and I take your point about the D5
wrapper not doing anything with the right-button messages.  Still, I find it
strange that this has only started happening since I upgraded to D5.  The
app never had this problem under D4.

The cause of my problem is trying to get a popup menu to appear.
Unfortunately, my third-party popup menu component is not compatible with
TPopupMenu and thus I can't assign it to the PopupMenu property of the
TTreeView (which interestingly doesn't have a problem appearing after a
single right-click).

I was hoping to use a dummy TPopupMenu and then have it display my custom
popup menu during it's OnPopup event, but unfortunately I am unable to stop
the dummy pop-up from displaying.

Thanks,
Scott

Quote

>This seems to be a problem in the Windows common control itself, not in the
>Delphi wrapper, which does absolutely nothing with right button messages.

>Peter Below (TeamB)  100113.1...@compuserve.com)
>No e-mail responses, please, unless explicitly requested!

Re:TTreeView.OnMouseUp doesn't work properly with D5


Quote
In article <7v0275$ep...@forums.borland.com>, Scott Barden wrote:
> The cause of my problem is trying to get a popup menu to appear.

I think i have found the cause for the different bahaviour of D4 and
D5. TCustomTreeview has a rather complex handler for CN_NOTIFY and one
of the cases is

      NM_RCLICK:
        begin
          FRClickNode := nil;
          GetCursorPos(MousePos);
          if RightClickSelect then
            with PointToSmallPoint(ScreenToClient(MousePos)) do
            begin
              FRClickNode := GetNodeAt(X, Y);
              Perform(WM_CONTEXTMENU, Handle,
Integer(PointToSmallPoint(MousePos)));
              FRClickNode := nil;
            end
          else
            // Win95/98 eat WM_CONTEXTMENU when posted to the message
queue  
            PostMessage(Handle, CN_BASE+WM_CONTEXTMENU, Handle,
Integer(PointToSmallPoint(MousePos)));
          Message.Result := 1;  // tell treeview not to perform default
response
        end;

See the last comment? Returning 1 here is probably the reason why the
control does not get standard mouse events. The code also shows that
you should be able to derive a new class from TTreeview and handle the
WM_CONTEXTMENU and CN_CONTEXTMENU messages (define the latter as
CN_BASE + WM_CONTEXTMENU, the VCL fails to define it). Show the popup
in response to the messages.      

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Other Threads