wxGrid: minor fixups and cleanups

See #22795.
This commit is contained in:
Vadim Zeitlin 2022-09-22 18:20:25 +02:00
commit fd193c08d2
4 changed files with 43 additions and 26 deletions

View file

@ -19,6 +19,7 @@
#include "wx/vector.h"
wxDEPRECATED_MSG("use wxGridBlockCoordsVector instead")
typedef wxVector<wxGridBlockCoords> wxVectorGridBlockCoords;
// Note: for all eventType arguments of the methods of this class wxEVT_NULL
@ -109,7 +110,7 @@ public:
wxArrayInt GetRowSelection() const;
wxArrayInt GetColSelection() const;
wxVectorGridBlockCoords& GetBlocks() { return m_selection; }
const wxGridBlockCoordsVector& GetBlocks() const { return m_selection; }
void EndSelecting();
void CancelSelecting();
@ -119,7 +120,7 @@ private:
{
SelectBlock(block.GetTopRow(), block.GetLeftCol(),
block.GetBottomRow(), block.GetRightCol(),
wxKeyboardState(), false);
wxKeyboardState(), wxEVT_NULL);
}
// Really select the block and don't check for the current selection mode.
@ -136,7 +137,7 @@ private:
// We don't currently check if the new block is contained by several
// existing blocks, as this would be more difficult and doesn't seem to be
// really needed in practice.
void MergeOrAddBlock(wxVectorGridBlockCoords& blocks,
void MergeOrAddBlock(wxGridBlockCoordsVector& blocks,
const wxGridBlockCoords& block);
// All currently selected blocks. We expect there to be a relatively small
@ -146,7 +147,7 @@ private:
// Selection may be empty, but if it isn't, the last block is special, as
// it is the current block, which is affected by operations such as
// extending the current selection from keyboard.
wxVectorGridBlockCoords m_selection;
wxGridBlockCoordsVector m_selection;
wxGrid *m_grid;
wxGrid::wxGridSelectionModes m_selectionMode;

View file

@ -10948,7 +10948,7 @@ wxGridBlocks wxGrid::GetSelectedBlocks() const
if ( !m_selection )
return wxGridBlocks();
const wxVectorGridBlockCoords& blocks = m_selection->GetBlocks();
const wxGridBlockCoordsVector& blocks = m_selection->GetBlocks();
return wxGridBlocks(blocks.begin(), blocks.end());
}
@ -11144,7 +11144,7 @@ wxArrayInt wxGrid::GetSelectedCols() const
void wxGrid::ClearSelection()
{
if ( m_selection )
if ( IsSelection() )
m_selection->ClearSelection();
}

View file

@ -312,7 +312,7 @@ wxGridSelection::DeselectBlock(const wxGridBlockCoords& block,
// Note: in row/column selection mode, we only need part1 and part2
// Blocks to refresh.
wxVectorGridBlockCoords refreshBlocks;
wxGridBlockCoordsVector refreshBlocks;
// Add the deselected block.
refreshBlocks.push_back(canonicalizedBlock);
@ -882,7 +882,7 @@ wxGridSelection::Select(const wxGridBlockCoords& block,
}
}
void wxGridSelection::MergeOrAddBlock(wxVectorGridBlockCoords& blocks,
void wxGridSelection::MergeOrAddBlock(wxGridBlockCoordsVector& blocks,
const wxGridBlockCoords& newBlock)
{
size_t count = blocks.size();

View file

@ -28,6 +28,14 @@
#include "waitforpaint.h"
// To disable tests which work locally, but not when run on GitHub CI.
#if defined(__WXGTK__) && !defined(__WXGTK3__)
#define wxSKIP_AUTOMATIC_TEST_IF_GTK2() \
if ( IsAutomaticTest() ) return
#else
#define wxSKIP_AUTOMATIC_TEST_IF_GTK2()
#endif
namespace
{
@ -609,17 +617,13 @@ TEST_CASE_METHOD(GridTestCase, "Grid::SortClick", "[grid]")
TEST_CASE_METHOD(GridTestCase, "Grid::Size", "[grid]")
{
// TODO on OSX resizing interactively works, but not automated
// Grid could not pass the test under GTK, OSX, and Universal.
// Grid could not pass the test under OSX and Universal.
// So there may has bug in Grid implementation
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__) && !defined(__WXUNIVERSAL__)
if ( !EnableUITests() )
return;
#ifdef __WXGTK20__
// Works locally, but not when run on Travis CI.
if ( IsAutomaticTest() )
return;
#endif
wxSKIP_AUTOMATIC_TEST_IF_GTK2();
EventCounter colsize(m_grid, wxEVT_GRID_COL_SIZE);
EventCounter rowsize(m_grid, wxEVT_GRID_ROW_SIZE);
@ -659,6 +663,21 @@ TEST_CASE_METHOD(GridTestCase, "Grid::RangeSelect", "[grid]")
if ( !EnableUITests() )
return;
wxSKIP_AUTOMATIC_TEST_IF_GTK2();
#ifdef __WXGTK3__
// works locally, but not when run on GitHub CI.
if ( IsAutomaticTest() )
{
wxString useASAN;
if ( wxGetEnv("wxUSE_ASAN", &useASAN) && useASAN == "1" )
{
WARN("Skipping test failing for unknown reason");
return;
}
}
#endif // __WXGTK3__
EventCounter select(m_grid, wxEVT_GRID_RANGE_SELECTED);
wxUIActionSimulator sim;
@ -674,6 +693,11 @@ TEST_CASE_METHOD(GridTestCase, "Grid::RangeSelect", "[grid]")
sim.MouseDown();
wxYield();
// Move the mouse a bit while staying inside the first cell of the range
// so that the range selection really starts off by the next move.
sim.MouseMove(pt.x + 5, pt.y + 5);
wxYield();
sim.MouseMove(pt.x + 50, pt.y + 50);
wxYield();
@ -1445,16 +1469,12 @@ TEST_CASE_METHOD(GridTestCase, "Grid::WindowAsEditorControl", "[grid]")
TEST_CASE_METHOD(GridTestCase, "Grid::ResizeScrolledHeader", "[grid]")
{
// TODO this test currently works only under Windows unfortunately
// TODO this test currently works only under Windows and GTK unfortunately
#if wxUSE_UIACTIONSIMULATOR && (defined(__WXMSW__) || defined(__WXGTK__))
if ( !EnableUITests() )
return;
#ifdef __WXGTK20__
// Works locally, but not when run on Travis CI.
if ( IsAutomaticTest() )
return;
#endif
wxSKIP_AUTOMATIC_TEST_IF_GTK2();
SECTION("Default") {}
SECTION("Native header") { m_grid->UseNativeColHeader(); }
@ -1496,16 +1516,12 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ResizeScrolledHeader", "[grid]")
TEST_CASE_METHOD(GridTestCase, "Grid::ColumnMinWidth", "[grid]")
{
// TODO this test currently works only under Windows unfortunately
// TODO this test currently works only under Windows and GTK unfortunately
#if wxUSE_UIACTIONSIMULATOR && (defined(__WXMSW__) || defined(__WXGTK__))
if ( !EnableUITests() )
return;
#ifdef __WXGTK20__
// Works locally, but not when run on Travis CI.
if ( IsAutomaticTest() )
return;
#endif
wxSKIP_AUTOMATIC_TEST_IF_GTK2();
SECTION("Default") {}
SECTION("Native header")