diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index fcb2f8b4b8..96a3844f6b 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -823,11 +823,12 @@ public: m_leftCol <= cell.GetCol() && cell.GetCol() <= m_rightCol; } - // Whether the blocks contain each other. - // returns 1, if this block contains the other, - // -1, if the other block contains this one, - // 0, otherwise - int ContainBlock(const wxGridBlockCoords& other) const; + // Return whether this blocks fully contains another one. + bool ContainsBlock(const wxGridBlockCoords& other) const + { + return m_topRow <= other.m_topRow && other.m_bottomRow <= m_bottomRow && + m_leftCol <= other.m_leftCol && other.m_rightCol <= m_rightCol; + } // Calculates the result blocks by subtracting the other block from this // block. splitOrientation can be wxVERTICAL or wxHORIZONTAL. diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 6e263abb58..6122f6b3fa 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -1924,14 +1924,12 @@ public: bool ContainsCell(const wxGridCellCoords& cell) const; /** - Whether the blocks contain each other. + Check whether this block contains another one. @return - 1, if this block contains the other, - -1, if the other block contains this one, - 0, otherwise. + @true if @a other is entirely contained within this block. */ - int ContainBlock(const wxGridBlockCoords& other) const; + int ContainsBlock(const wxGridBlockCoords& other) const; /** Calculates the result blocks by subtracting the other block from this diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index ed5a8bc3d3..70ee786943 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -1140,21 +1140,6 @@ const wxGridCornerHeaderRenderer& wxGridCellAttrProvider::GetCornerRenderer() // wxGridBlockCoords // ---------------------------------------------------------------------------- -int wxGridBlockCoords::ContainBlock(const wxGridBlockCoords& other) const -{ -// returns 1, if this block contains the other, -// -1, if the other block contains this one, -// 0, otherwise - if ( m_topRow <= other.m_topRow && other.m_bottomRow <= m_bottomRow && - m_leftCol <= other.m_leftCol && other.m_rightCol <= m_rightCol ) - return 1; - else if ( other.m_topRow <= m_topRow && m_bottomRow <= other.m_bottomRow && - other.m_leftCol <= m_leftCol && m_rightCol <= other.m_rightCol ) - return -1; - - return 0; -} - wxGridBlockDiffResult wxGridBlockCoords::Difference(const wxGridBlockCoords& other, int splitOrientation) const diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index 62ea7312d7..6fcd64140f 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -741,19 +741,14 @@ void wxGridSelection::MergeOrAddBlock(wxVectorGridBlockCoords& blocks, { const wxGridBlockCoords& block = blocks[n]; - switch ( block.ContainBlock(newBlock) ) + if ( block.ContainsBlock(newBlock) ) + return; + + if ( newBlock.ContainsBlock(block) ) { - case 1: - return; - - case -1: - blocks.erase(blocks.begin() + n); - n--; - count--; - break; - - default: - break; + blocks.erase(blocks.begin() + n); + n--; + count--; } } diff --git a/tests/controls/gridtest.cpp b/tests/controls/gridtest.cpp index f1749634c9..708f42cd18 100644 --- a/tests/controls/gridtest.cpp +++ b/tests/controls/gridtest.cpp @@ -1337,17 +1337,19 @@ TEST_CASE("GridBlockCoords::ContainsCell", "[grid]") CHECK(!wxGridBlockCoords(1, 1, 3, 3).ContainsCell(wxGridCellCoords(5, 5))); } -TEST_CASE("GridBlockCoords::ContainBlock", "[grid]") +TEST_CASE("GridBlockCoords::ContainsBlock", "[grid]") { wxGridBlockCoords block1(1, 1, 5, 5); wxGridBlockCoords block2(1, 1, 3, 3); wxGridBlockCoords block3(2, 2, 7, 7); wxGridBlockCoords block4(10, 10, 12, 12); - CHECK(block1.ContainBlock(block2) == 1); - CHECK(block2.ContainBlock(block1) == -1); - CHECK(block1.ContainBlock(block3) == 0); - CHECK(block1.ContainBlock(block4) == 0); + CHECK( block1.ContainsBlock(block2)); + CHECK(!block2.ContainsBlock(block1)); + CHECK(!block1.ContainsBlock(block3)); + CHECK(!block1.ContainsBlock(block4)); + CHECK(!block3.ContainsBlock(block1)); + CHECK(!block4.ContainsBlock(block1)); } TEST_CASE("GridBlockCoords::Difference", "[grid]")