Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-08

TListView and TPopupMenu and the right mouse button

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bernd Kreuss

This might be a stupid question but I'm not 100% sure how to proceed from here. There seems to be a bug in TListView on GTK2 that impacts the usage of the right mouse button as soon as there is a popup menu defined for it.

If I right click without the PopupMenu property set it will select the row on mouse down which is the expected behavior of most users (me at least), but as soon as PopupMenu is set to a menu the right mouse button will open the menu but it will not select any row anymore. This does not feel like the behavior I know from any other application I have ever used, this must be a bug.

My first idea was to simply leave the PopupMenu property completely empty and simply show the menu manually on mouse down. But I cannot find any example how to manually open a menu that was designed in the form designer? How do I manually instantiate a menu from the data that seems to be hidden somewhere in all the data that the form designer generated?

I have not yet tried whether the mousedown comes before the popup menu is opened (or whether it comes at all) so maybe I can also do it the other way around and manually select the row on mouse down and then let the list open its popup menu from the PopupMenu property.

Or what would be the most elegant workaround for me around this bug?

Or maybe it is easily fixable once and for all in the LCL itself? Maybe just a forgotten line somewhere to properly propagate the mouse event?

Reply by email

Paul Ishenin
to Bernd Kreuss
Bernd Kreuss wrote
This might be a stupid question but I'm not 100% sure how to proceed from here. There seems to be a bug in TListView on GTK2 that impacts the usage of the right mouse button as soon as there is a popup menu defined for it.

Yes. This is how we designed the right click handling for gtk2. If we allow the default action to happen then you can suddenly see 2 popup menus: one your and one standard - for example for TEdit or TPageConrol (since gtk2 will handle the right click and will show a popup on it and LCL will do the same).

My first idea was to simply leave the PopupMenu property completely empty and simply show the menu manually on mouse down. But I cannot find any example how to manually open a menu that was designed in the form designer?
PopupMenu.PopupAt();

Best regards,
Paul Ishenin.

Reply by email

Bernd Kreuss
to Paul Ishenin
Paul Ishenin wrote
PopupMenu.PopupAt();

Thanks, this almost works but there still must be something missing:

After a menu has been shown it needs two right mouse clicks into the list until MouseDown events (for the right button) work again (this makes three right mouse clicks to show the menu another time). List selection works immediately but the next two right mouse button events will not trigger the event method. Left clicks work immediately but the next two right clicks won't trigger my event handler:

procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  debugln(['TForm1.ListView1MouseDown ', x, ' ', y]);
  if Button = mbRight then begin
    PopupMenu1.PopUp();
  end;
end;

Reply by email