}
}
+void wxGridCellAttr::GetNonDefaultAlignment(int *hAlign, int *vAlign) const
+{
+ if ( hAlign && m_hAlign != wxALIGN_INVALID )
+ *hAlign = m_hAlign;
+
+ if ( vAlign && m_vAlign != wxALIGN_INVALID )
+ *vAlign = m_vAlign;
+}
+
void wxGridCellAttr::GetSize( int *num_rows, int *num_cols ) const
{
if ( num_rows )
bool captureMouse)
{
#if wxUSE_LOG_TRACE
- static const wxChar *cursorModes[] =
+ static const wxChar *const cursorModes[] =
{
wxT("SELECT_CELL"),
wxT("RESIZE_ROW"),
wxGridCellAttrProvider * const
attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
+
+ // notice that an explicit static_cast is needed to avoid a compilation
+ // error with VC7.1 which, for some reason, tries to instantiate (abstract)
+ // wxGridRowHeaderRenderer class without it
const wxGridRowHeaderRenderer&
rend = attrProvider ? attrProvider->GetRowHeaderRenderer(row)
- : gs_defaultHeaderRenderers.rowRenderer;
+ : static_cast<const wxGridRowHeaderRenderer&>
+ (gs_defaultHeaderRenderers.rowRenderer);
+
wxRect rect(0, GetRowTop(row), m_rowLabelWidth, GetRowHeight(row));
rend.DrawBorder(*this, dc, rect);
attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
const wxGridCornerHeaderRenderer&
rend = attrProvider ? attrProvider->GetCornerRenderer()
- : gs_defaultHeaderRenderers.cornerRenderer;
+ : static_cast<wxGridCornerHeaderRenderer&>
+ (gs_defaultHeaderRenderers.cornerRenderer);
rend.DrawBorder(*this, dc, rect);
}
attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
const wxGridColumnHeaderRenderer&
rend = attrProvider ? attrProvider->GetColumnHeaderRenderer(col)
- : gs_defaultHeaderRenderers.colRenderer;
+ : static_cast<wxGridColumnHeaderRenderer&>
+ (gs_defaultHeaderRenderers.colRenderer);
if ( m_nativeColumnLabels )
{
return allow;
}
-void wxGrid::GetCellSize( int row, int col, int *num_rows, int *num_cols ) const
+wxGrid::CellSpan
+wxGrid::GetCellSize( int row, int col, int *num_rows, int *num_cols ) const
{
wxGridCellAttr *attr = GetCellAttr(row, col);
attr->GetSize( num_rows, num_cols );
attr->DecRef();
+
+ 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;
}
wxGridCellRenderer* wxGrid::GetCellRenderer(int row, int col) const
HideCellEditControl();
SaveEditControlValue();
- // init both of them to avoid compiler warnings, even if we only need one
+ // initialize both of them just to avoid compiler warnings
int row = -1,
col = -1;
- if ( column )
- col = colOrRow;
- else
- row = colOrRow;
wxCoord extent, extentMax = 0;
int max = column ? m_numRows : m_numCols;
for ( int rowOrCol = 0; rowOrCol < max; rowOrCol++ )
{
if ( column )
+ {
row = rowOrCol;
+ col = colOrRow;
+ }
else
+ {
+ row = colOrRow;
col = rowOrCol;
+ }
+
+ // we need to account for the cells spanning multiple columns/rows:
+ // while they may need a lot of space, they don't need all of it in
+ // this column/row
+ int numRows, numCols;
+ const CellSpan span = GetCellSize(row, col, &numRows, &numCols);
+ if ( span == CellSpan_Inside )
+ {
+ // we need to get the size of the main cell, not of a cell hidden
+ // by it
+ row += numRows;
+ col += numCols;
+
+ // get the size of the main cell too
+ GetCellSize(row, col, &numRows, &numCols);
+ }
wxGridCellAttr *attr = GetCellAttr(row, col);
wxGridCellRenderer *renderer = attr->GetRenderer(this, row, col);
{
wxSize size = renderer->GetBestSize(*this, *attr, dc, row, col);
extent = column ? size.x : size.y;
+
+ if ( span != CellSpan_None )
+ {
+ // we spread the size of a spanning cell over all the cells it
+ // covers evenly -- this is probably not ideal but we can't
+ // really do much better here
+ //
+ // notice that numCols and numRows are never 0 as they
+ // correspond to the size of the main cell of the span and not
+ // of the cell inside it
+ extent /= column ? numCols : numRows;
+ }
+
if ( extent > extentMax )
extentMax = extent;