From 8255a71dc7cb6db93d6e7cf37a3d89915efdfde4 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 14 Dec 2020 10:13:27 -0300 Subject: [PATCH] Fix error when clicking on empty space in wxDVC under Mac Double clicking on empty space under the items in wxDataViewCtrl still results in actionDoubleClick: being called, even though there is no valid item under the mouse. Just ignore such notifications, as we're not supposed to generate any events in this case (neither GTK nor generic version do it) and calling itemAtRow: with invalid row results in errors due to invalid index use. Closes https://github.com/wxWidgets/wxWidgets/pull/2142 Closes #18984. --- src/osx/cocoa/dataview.mm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 69f7d914a3..6935f463ed 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -1680,7 +1680,17 @@ outlineView:(NSOutlineView*)outlineView wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); wxDataViewModel * const model = dvc->GetModel(); - const wxDataViewItem item = wxDataViewItemFromItem([self itemAtRow:[self clickedRow]]); + const NSInteger row = [self clickedRow]; + if ( row == -1 ) + { + // We can be called even when there is no item under mouse, e.g. when + // clicking on empty space under the items. Just ignore such clicks as + // we're not supposed to generate any events in this case (and calling + // itemAtRow: below would result in errors when the row is invalid). + return; + } + + const wxDataViewItem item = wxDataViewItemFromItem([self itemAtRow:row]); const NSInteger col = [self clickedColumn]; wxDataViewColumn* const dvCol = implementation->GetColumn(col);