From 860d9d09bceee989f0ca813fe8bfac0429126643 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Tue, 19 Jan 2021 22:26:03 +0100 Subject: [PATCH] Refactor code deciding the kind of span of a grid cell Move wxGrid's GetCellSize() cell span logic into GetCellSpan() for future usage. --- src/generic/grid.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 566f0a8102..cd06df1b72 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -158,6 +158,24 @@ wxDEFINE_EVENT( wxEVT_GRID_TABBING, wxGridEvent ); // implementation // ============================================================================ +namespace +{ + +// Helper function for consistent cell span determination based on cell size. +wxGrid::CellSpan GetCellSpan(int numRows, int numCols) +{ + if ( numRows == 1 && numCols == 1 ) + return wxGrid::CellSpan_None; // just a normal cell + + if ( numRows < 0 || numCols < 0 ) + return wxGrid::CellSpan_Inside; // covered by a multi-span cell + + // this cell spans multiple cells to its right/bottom + return wxGrid::CellSpan_Main; +} + +} // anonymous namespace + wxIMPLEMENT_ABSTRACT_CLASS(wxGridCellEditorEvtHandler, wxEvtHandler); wxBEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler, wxEvtHandler ) @@ -9126,14 +9144,7 @@ wxGrid::GetCellSize( int row, int col, int *num_rows, int *num_cols ) const { GetCellAttrPtr(row, col)->GetSize( num_rows, num_cols ); - if ( *num_rows == 1 && *num_cols == 1 ) - return CellSpan_None; // just a normal cell - - if ( *num_rows < 0 || *num_cols < 0 ) - return CellSpan_Inside; // covered by a multi-span cell - - // this cell spans multiple cells to its right/bottom - return CellSpan_Main; + return GetCellSpan(*num_rows, *num_cols); } wxGridCellRenderer* wxGrid::GetCellRenderer(int row, int col) const