From e0b8ef85f27f7e603c802e9bd0573193501111dd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 3 Dec 2019 02:35:03 +0100 Subject: [PATCH 1/2] Don't use invalid grid cell coordinates when deleting grid rows Since the changes of dda6aa6bdc8e30ba3a1feefa9aba3ce6fec076e8 wxGrid code could ask the grid table for the data of an invalid cell due to redrawing the old, and now possibly invalid, current cell from inside SetCurrentCell() called from wxGrid::Redimension(). Fix this by explicitly resetting the old current cell to an invalid value when changing it in UpdateCurrentCellOnRedim(). Also avoid calling SetCurrentCell() entirely if the current cell doesn't change, as this is just completely unnecessary and results in a possible unexpected wxEVT_GRID_SELECT_CELL event. See https://github.com/wxWidgets/wxWidgets/pull/1546 --- src/generic/grid.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 496c9265fd..6fd5207eda 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3640,13 +3640,21 @@ void wxGrid::UpdateCurrentCellOnRedim() } else { - int col = m_currentCellCoords.GetCol(); - int row = m_currentCellCoords.GetRow(); - if (col >= m_numCols) - col = m_numCols - 1; - if (row >= m_numRows) - row = m_numRows - 1; - SetCurrentCell(row, col); + // Check if the current cell coordinates are still valid. + wxGridCellCoords updatedCoords = m_currentCellCoords; + if ( updatedCoords.GetCol() >= m_numCols ) + updatedCoords.SetCol(m_numCols - 1); + if ( updatedCoords.GetRow() >= m_numRows ) + updatedCoords.SetRow(m_numRows - 1); + + // And change them if they're not. + if ( updatedCoords != m_currentCellCoords ) + { + // Prevent SetCurrentCell() from redrawing the previous current + // cell whose coordinates are invalid now. + m_currentCellCoords = wxGridNoCellCoords; + SetCurrentCell(updatedCoords); + } } } } From 90d547feb6d0e0cc86e6b482cd9d91c852e73125 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 3 Dec 2019 02:56:46 +0100 Subject: [PATCH 2/2] Don't redraw current cell when the grid is frozen Don't update the grid appearance when inside a sequence of batch operations, it will be updated at the end of it anyhow and doing it in the middle only results in extra flicker. --- src/generic/grid.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 6fd5207eda..d4e82b5bd7 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -5759,13 +5759,16 @@ bool wxGrid::SetCurrentCell( const wxGridCellCoords& coords ) m_currentCellCoords = coords; - wxGridCellAttr *attr = GetCellAttr( coords ); #if !defined(__WXMAC__) - wxClientDC dc( currentGridWindow ); - PrepareDCFor(dc, currentGridWindow); - DrawCellHighlight( dc, attr ); + if ( !GetBatchCount() ) + { + wxGridCellAttr *attr = GetCellAttr( coords ); + wxClientDC dc( currentGridWindow ); + PrepareDCFor(dc, currentGridWindow); + DrawCellHighlight( dc, attr ); + attr->DecRef(); + } #endif - attr->DecRef(); return true; }