Opened 10 years ago

Closed 10 years ago

#12706 closed defect (fixed)

wxDataViewCtrl does not handle context menu events beyond the list of items

Reported by: andyburke Owned by:
Priority: normal Milestone:
Component: base Version:
Keywords: Cc:
Blocked By: Blocking:
Patch: yes

Description

If you right-click (on windows) in a wxDataViewCtrl and your mouse is above an existing item, you will properly receive a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU. If, however, there is no item under your mouse, you will not receive any event. There does not appear to be a straightforward way to hook up a generic context menu within a wxDataViewCtrl.

I'd like to propose that if you try to get a context menu in a wxDataViewCtrl that the event be generated regardless of if there is an item under the mouse cursor. If there is an item, the event will be filled out with that item and value as appropriate. If there is no item under the mouse cursor, there will be no item or value associated with the event.

I've attached a patch that implements this behavior.

If there is some other way you are supposed to make a context menu work within a wxDataViewCtrl, please let me know. I did quite a bit of looking, but it's possible I missed something.

Attachments (2)

context menu handling.patch download (1.8 KB) - added by andyburke 10 years ago.
context menu event skipping.patch download (594 bytes) - added by andyburke 10 years ago.

Download all attachments as: .zip

Change History (9)

Changed 10 years ago by andyburke

comment:1 Changed 10 years ago by vadz

  • Resolution set to wontfix
  • Status changed from new to closed

You can always use the standard EVT_CONTEXT_MENU for this. Sending ITEM_CONTEXT_MENU with invalid item would be inconsistent with EVT_TREE_ITEM_MENU behaviour so I don't think it would be a good thing. Also, this would need to be implemented in GTK and OSX versions as well and while this looks easy for the former I'm not sure if it's possible for the latter.

So all in all I don't think we should do it but please reopen if I'm missing something.

comment:2 Changed 10 years ago by andyburke

  • Summary changed from wxDataViewCtrl does not handle context menu events beyond the list of items to t u

Actually, as far as I can tell, you can't use the standard EVT_CONTEXT_MENU. Hooking that up on the wxDataViewCtrl only allows it to work on the column header bar. Hooking it up on the wxDataViewCtrl's main window (ctrl->GetMainWindow()->Connect(...)) doesn't appear to work at all. Is there a way to actually hook up EVT_CONTEXT_MENU in a wxDataViewCtrl that allows the user to right-click anywhere within the wxDataViewControl and get a context menu?

comment:3 Changed 10 years ago by vadz

  • Patch unset
  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Summary changed from t u to wxDataViewCtrl does not handle context menu events beyond the list of items

I don't know why EVT_CONTEXT_MENU doesn't work, it should even without connecting to the main window as it's a command event which is propagated upwards. Can you please attach a small patch to the dataview sample showing that it doesn't work?

comment:4 Changed 10 years ago by andyburke

  • Patch set

I don't have the examples set up, so it's not easy for me to generate a working patch against them.

However, I'm attaching a patch that seems to make EVT_CONTEXT_MENU work as I would expect it to. This patch adds a couple of event.Skip() calls when the wxDataViewCtrl decides it shouldn't be handling the event (before, they were just bare returns and the event was eaten).

Changed 10 years ago by andyburke

comment:5 Changed 10 years ago by vadz

  • Status changed from reopened to confirmed

The patch makes sense, thanks, I'll apply it soon.

comment:6 Changed 10 years ago by andyburke

Much obliged for the quick response.

comment:7 Changed 10 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [66250]) Skip mouse events outside of item area in wxDataViewCtrl.

Don't consume mouse events outside of the area occupied by the items in the
generic implementation of wxDataViewCtrl as this prevented wxEVT_CONTEXT_MENU
events from being generated.

Closes #12706.

Note: See TracTickets for help on using tickets.