Don't use menuForEvent: in wxDataViewCtrl on macOS

Returning nil from menuForEvent: and then popping up a menu manually
causes some kind of Cocoa internal state confusion if the right-click
was performed by holding down Control and clicking (as is the Mac
alternative to right-click). See https://github.com/vslavik/poedit/issues/849

Implement wxEVT_DATAVIEW_ITEM_CONTEXT_MENU event using a handler for
the regular wxEVT_CONTEXT_MENU event instead.
This commit is contained in:
Václav Slavík
2024-07-12 16:07:35 +02:00
parent 37efaacba3
commit f370e9e8ea
3 changed files with 18 additions and 27 deletions
+2
View File
@@ -291,6 +291,8 @@ private:
virtual wxDataViewItem DoGetCurrentItem() const override;
virtual void DoSetCurrentItem(const wxDataViewItem& item) override;
void OnContextMenu(wxContextMenuEvent& event);
//
// variables
//
-27
View File
@@ -1663,33 +1663,6 @@ outlineView:(NSOutlineView*)outlineView
}
}
//
// contextual menus
//
-(NSMenu*) menuForEvent:(NSEvent*)theEvent
{
wxUnusedVar(theEvent);
// this method does not do any special menu event handling but only sends
// an event message; therefore, the user has full control if a context
// menu should be shown or not
wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl();
// get the item information;
// theoretically more than one ID can be returned but the event can only
// handle one item, therefore only the first item of the array is
// returned:
wxDataViewItem item;
wxDataViewItemArray selectedItems;
if (dvc->GetSelections(selectedItems) > 0)
item = selectedItems[0];
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, dvc, item);
dvc->GetEventHandler()->ProcessEvent(event);
// nothing is done:
return nil;
}
//
// delegate methods
//
+16
View File
@@ -852,6 +852,21 @@ void wxDataViewCtrl::OnSize(wxSizeEvent& event)
event.Skip();
}
void wxDataViewCtrl::OnContextMenu(wxContextMenuEvent& WXUNUSED(e))
{
// get the item information;
// theoretically more than one ID can be returned but the event can only
// handle one item, therefore only the first item of the array is
// returned:
wxDataViewItem item;
wxDataViewItemArray selectedItems;
if (GetSelections(selectedItems) > 0)
item = selectedItems[0];
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, this, item);
GetEventHandler()->ProcessEvent(event);
}
wxSize wxDataViewCtrl::DoGetBestSize() const
{
wxSize best = wxControl::DoGetBestSize();
@@ -864,6 +879,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase);
wxBEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase)
EVT_SIZE(wxDataViewCtrl::OnSize)
EVT_CONTEXT_MENU(wxDataViewCtrl::OnContextMenu)
wxEND_EVENT_TABLE()
#endif // !wxHAS_GENERIC_DATAVIEWCTRL