Fix handling selection in wxGrid::Render()

Temporarily reset the m_selection pointer itself instead of clearing the
selection, this is much more efficient, especially for big grids, and
also more correct, as the old code simply lost the original selection in
non-block selection modes.
This commit is contained in:
Vadim Zeitlin 2021-10-26 19:41:06 +01:00
parent 5f8e9c14ae
commit 9b820b74b2

View File

@ -2301,17 +2301,12 @@ void wxGrid::Render( wxDC& dc,
// remove grid selection, don't paint selection colour // remove grid selection, don't paint selection colour
// unless we have wxGRID_DRAW_SELECTION // unless we have wxGRID_DRAW_SELECTION
// block selections are the only ones catered for here wxGridSelection* selectionOrig = NULL;
wxGridCellCoordsArray selectedCells; if ( m_selection && !( style & wxGRID_DRAW_SELECTION ) )
bool hasSelection = IsSelection();
if ( hasSelection && !( style & wxGRID_DRAW_SELECTION ) )
{ {
selectedCells = GetSelectionBlockTopLeft(); // remove the selection temporarily, it will be restored below
// non block selections may not have a bottom right selectionOrig = m_selection;
if ( GetSelectionBlockBottomRight().size() ) m_selection = NULL;
selectedCells.Add( GetSelectionBlockBottomRight()[ 0 ] );
ClearSelection();
} }
// store user device origin // store user device origin
@ -2437,12 +2432,9 @@ void wxGrid::Render( wxDC& dc,
dc.SetDeviceOrigin( userOriginX, userOriginY ); dc.SetDeviceOrigin( userOriginX, userOriginY );
dc.SetUserScale( scaleUserX, scaleUserY ); dc.SetUserScale( scaleUserX, scaleUserY );
if ( selectedCells.size() && !( style & wxGRID_DRAW_SELECTION ) ) if ( selectionOrig )
{ {
SelectBlock( selectedCells[ 0 ].GetRow(), m_selection = selectionOrig;
selectedCells[ 0 ].GetCol(),
selectedCells[ selectedCells.size() -1 ].GetRow(),
selectedCells[ selectedCells.size() -1 ].GetCol() );
} }
} }