X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/670d01778a69731665cbb7c77726f067a1c8ce17..b30661fdd01159eceffd1a35dcc51b8a4d803854:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index d19952c919..45cfa65c3f 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -476,6 +476,15 @@ void wxGridCellAttr::GetAlignment(int *hAlign, int *vAlign) const } } +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 ) @@ -3573,7 +3582,7 @@ void wxGrid::ChangeCursorMode(CursorMode mode, bool captureMouse) { #if wxUSE_LOG_TRACE - static const wxChar *cursorModes[] = + static const wxChar *const cursorModes[] = { wxT("SELECT_CELL"), wxT("RESIZE_ROW"), @@ -5443,9 +5452,15 @@ void wxGrid::DrawRowLabel( wxDC& dc, int 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 + (gs_defaultHeaderRenderers.rowRenderer); + wxRect rect(0, GetRowTop(row), m_rowLabelWidth, GetRowHeight(row)); rend.DrawBorder(*this, dc, rect); @@ -5518,7 +5533,8 @@ void wxGrid::DrawCornerLabel(wxDC& dc) attrProvider = m_table ? m_table->GetAttrProvider() : NULL; const wxGridCornerHeaderRenderer& rend = attrProvider ? attrProvider->GetCornerRenderer() - : gs_defaultHeaderRenderers.cornerRenderer; + : static_cast + (gs_defaultHeaderRenderers.cornerRenderer); rend.DrawBorder(*this, dc, rect); } @@ -5536,7 +5552,8 @@ void wxGrid::DrawColLabel(wxDC& dc, int col) attrProvider = m_table ? m_table->GetAttrProvider() : NULL; const wxGridColumnHeaderRenderer& rend = attrProvider ? attrProvider->GetColumnHeaderRenderer(col) - : gs_defaultHeaderRenderers.colRenderer; + : static_cast + (gs_defaultHeaderRenderers.colRenderer); if ( m_nativeColumnLabels ) { @@ -7122,11 +7139,21 @@ bool wxGrid::GetCellOverflow( int row, int col ) const 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 @@ -7785,22 +7812,40 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction) 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); @@ -7808,6 +7853,19 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction) { 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;