From 415bab551ce06c1e7fdc20290afa418a1fc6f2c1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Apr 2020 01:06:42 +0200 Subject: [PATCH] Add wxGridSelection::SelectAll() and use it in wxGrid The difference between calling SelectAll() and SelectBlock() with a block covering the entire grid is that the former discards any previously selected blocks, which become clearly redundant. As a consequence, clicking on the grid corner 10 times in a row still results in a selection with a single block, not 10 (identical) blocks. --- include/wx/generic/gridsel.h | 4 ++++ src/generic/grid.cpp | 7 ++----- src/generic/gridsel.cpp | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/wx/generic/gridsel.h b/include/wx/generic/gridsel.h index c6859d94d6..cb53078f2c 100644 --- a/include/wx/generic/gridsel.h +++ b/include/wx/generic/gridsel.h @@ -52,6 +52,10 @@ public: kbd, sendEvent); } + // This function replaces all the existing selected blocks (which become + // redundant) with a single block covering the entire grid. + void SelectAll(); + void DeselectBlock(const wxGridBlockCoords& block, const wxKeyboardState& kbd = wxKeyboardState(), bool sendEvent = true ); diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index fe821cd87a..56f1cfec6a 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -10235,11 +10235,8 @@ void wxGrid::SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol, void wxGrid::SelectAll() { - if ( m_numRows > 0 && m_numCols > 0 ) - { - if ( m_selection ) - m_selection->SelectBlock( 0, 0, m_numRows - 1, m_numCols - 1 ); - } + if ( m_selection ) + m_selection->SelectAll(); } // ---------------------------------------------------------------------------- diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index e8cfdbf048..cc361a0d97 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -194,6 +194,23 @@ void wxGridSelection::SelectBlock( int topRow, int leftCol, kbd, sendEvent); } +void +wxGridSelection::SelectAll() +{ + // There is no need to refresh anything, as Select() will do it anyhow, and + // no need to generate any events, so do not call ClearSelection() here. + m_selection.clear(); + + const int numRows = m_grid->GetNumberRows(); + const int numCols = m_grid->GetNumberCols(); + + if ( numRows && numCols ) + { + Select(wxGridBlockCoords(0, 0, numRows - 1, numCols - 1), + wxKeyboardState(), true /* send event */); + } +} + void wxGridSelection::DeselectBlock(const wxGridBlockCoords& block, const wxKeyboardState& kbd,