Implement wxGridBlockCoords class

wxGridBlockCoords represents a location of a block of cells in the grid.
This commit is contained in:
Ilya Sinitsyn
2020-02-28 02:38:03 +07:00
committed by Vadim Zeitlin
parent 673ed29d7b
commit acd72efbf1
4 changed files with 722 additions and 2 deletions

View File

@@ -747,10 +747,133 @@ private:
};
// ----------------------------------------------------------------------------
// wxGridBlockCoords: location of a block of cells in the grid
// ----------------------------------------------------------------------------
struct wxGridBlockDiffResult;
class WXDLLIMPEXP_CORE wxGridBlockCoords
{
public:
wxGridBlockCoords() :
m_topRow(-1),
m_leftCol(-1),
m_bottomRow(-1),
m_rightCol(-1)
{
}
wxGridBlockCoords(int topRow, int leftCol, int bottomRow, int rightCol) :
m_topRow(topRow),
m_leftCol(leftCol),
m_bottomRow(bottomRow),
m_rightCol(rightCol)
{
}
// default copy ctor is ok
int GetTopRow() const { return m_topRow; }
void SetTopRow(int row) { m_topRow = row; }
int GetLeftCol() const { return m_leftCol; }
void SetLeftCol(int col) { m_leftCol = col; }
int GetBottomRow() const { return m_bottomRow; }
void SetBottomRow(int row) { m_bottomRow = row; }
int GetRightCol() const { return m_rightCol; }
void SetRightCol(int col) { m_rightCol = col; }
wxGridCellCoords GetTopLeft() const
{
return wxGridCellCoords(m_topRow, m_leftCol);
}
wxGridCellCoords GetBottomRight() const
{
return wxGridCellCoords(m_bottomRow, m_rightCol);
}
wxGridBlockCoords Canonicalize() const
{
wxGridBlockCoords result = *this;
if ( result.m_topRow > result.m_bottomRow )
wxSwap(result.m_topRow, result.m_bottomRow);
if ( result.m_leftCol > result.m_rightCol )
wxSwap(result.m_leftCol, result.m_rightCol);
return result;
}
bool Intersects(const wxGridBlockCoords& other) const
{
return m_topRow <= other.m_bottomRow && m_bottomRow >= other.m_topRow &&
m_leftCol <= other.m_rightCol && m_rightCol >= other.m_leftCol;
}
// Whether the block contains the cell.
// returns @true, if the block contains the cell,
// @false, otherwise
bool ContainCell(const wxGridCellCoords& cell) const;
// 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;
// Calculates the result blocks by subtracting the other block from this
// block. splitOrientation can be wxVERTICAL or wxHORIZONTAL.
wxGridBlockDiffResult
Difference(const wxGridBlockCoords& other, int splitOrientation) const;
// Calculates the symmetric difference of the blocks.
wxGridBlockDiffResult
SymDifference(const wxGridBlockCoords& other) const;
bool operator==(const wxGridBlockCoords& other) const
{
return m_topRow == other.m_topRow && m_leftCol == other.m_leftCol &&
m_bottomRow == other.m_bottomRow && m_rightCol == other.m_rightCol;
}
bool operator!=(const wxGridBlockCoords& other) const
{
return !(*this == other);
}
bool operator!() const
{
return m_topRow == -1 && m_leftCol == -1 &&
m_bottomRow == -1 && m_rightCol == -1;
}
private:
int m_topRow;
int m_leftCol;
int m_bottomRow;
int m_rightCol;
};
// ----------------------------------------------------------------------------
// wxGridBlockDiffResult: The helper struct uses as a result type for difference
// functions of wxGridBlockCoords class.
// Parts can be uninitialized (equals to wxGridNoBlockCoords), that means
// that the corresponding part doesn't exists in the result.
// ----------------------------------------------------------------------------
struct wxGridBlockDiffResult
{
wxGridBlockCoords m_parts[4];
};
// For comparisons...
//
extern WXDLLIMPEXP_CORE wxGridCellCoords wxGridNoCellCoords;
extern WXDLLIMPEXP_CORE wxRect wxGridNoCellRect;
extern WXDLLIMPEXP_CORE wxGridCellCoords wxGridNoCellCoords;
extern WXDLLIMPEXP_CORE wxGridBlockCoords wxGridNoBlockCoords;
extern WXDLLIMPEXP_CORE wxRect wxGridNoCellRect;
// An array of cell coords...
//