mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-10-06 07:00:16 +08:00
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:
@@ -291,6 +291,8 @@ private:
|
||||
virtual wxDataViewItem DoGetCurrentItem() const override;
|
||||
virtual void DoSetCurrentItem(const wxDataViewItem& item) override;
|
||||
|
||||
void OnContextMenu(wxContextMenuEvent& event);
|
||||
|
||||
//
|
||||
// variables
|
||||
//
|
||||
|
||||
@@ -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
|
||||
//
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user