Avoid bogus selection events from keys in generic wxDataViewCtrl

Don't do anything and, in particular, don't send any events if pressing a
navigation key, such as a cursor up/down arrow, didn't actually change the
current item because it was already the first/last one.

This fixes an endless stream of wxEVT_DATAVIEW_SELECTION_CHANGED events if the
up/down arrow is simply kept pressed when the selection is on first/last item.
This commit is contained in:
Vadim Zeitlin
2016-02-06 01:46:17 +01:00
parent 9ca5c2dce3
commit 189aedd89a

View File

@@ -3806,6 +3806,9 @@ void wxDataViewMainWindow::OnVerticalNavigation(const wxKeyEvent& event, int del
unsigned int oldCurrent = m_currentRow; unsigned int oldCurrent = m_currentRow;
unsigned int newCurrent = (unsigned int)newRow; unsigned int newCurrent = (unsigned int)newRow;
if ( newCurrent == oldCurrent )
return;
// in single selection we just ignore Shift as we can't select several // in single selection we just ignore Shift as we can't select several
// items anyhow // items anyhow
if ( event.ShiftDown() && !IsSingleSel() ) if ( event.ShiftDown() && !IsSingleSel() )
@@ -3822,14 +3825,12 @@ void wxDataViewMainWindow::OnVerticalNavigation(const wxKeyEvent& event, int del
} }
SelectRows(oldCurrent, newCurrent); SelectRows(oldCurrent, newCurrent);
if (oldCurrent!=newCurrent)
{
wxSelectionStore::IterationState cookie; wxSelectionStore::IterationState cookie;
const unsigned firstSel = m_selection.GetFirstSelectedItem(cookie); const unsigned firstSel = m_selection.GetFirstSelectedItem(cookie);
if ( firstSel != wxSelectionStore::NO_SELECTION ) if ( firstSel != wxSelectionStore::NO_SELECTION )
SendSelectionChangedEvent(GetItemByRow(firstSel)); SendSelectionChangedEvent(GetItemByRow(firstSel));
} }
}
else // !shift else // !shift
{ {
RefreshRow( oldCurrent ); RefreshRow( oldCurrent );