bool wxSheetCellAttr::MergeWith(const wxSheetCellAttr &other) { wxCHECK_MSG(Ok() && other.Ok(), false, wxT("this or Attr to MergeWith from is not created")); if ( !HasForegoundColour() && other.HasForegoundColour() ) SetForegroundColour(other.GetForegroundColour()); if ( !HasBackgroundColour() && other.HasBackgroundColour() ) SetBackgroundColour(other.GetBackgroundColour()); if ( !HasFont() && other.HasFont() ) SetFont(other.GetFont()); if ( !HasAlignment() && other.HasAlignment() ) SetAlignment(other.GetAlignment()); if ( !HasOrientation() && other.HasOrientation() ) SetOrientation(other.GetOrientation()); if ( !HasLevel() && other.HasLevel() ) SetLevel(other.GetLevel()); if ( !HasReadWriteMode() && other.HasReadWriteMode() ) SetReadOnly(other.GetReadOnly()); if ( !HasOverflowMode() && other.HasOverflowMode() ) SetOverflow(other.GetOverflow()); if ( !HasOverflowMarkerMode() && other.HasOverflowMarkerMode() ) SetOverflowMarker(other.GetOverflowMarker()); if ( !HasShowEditorMode() && other.HasShowEditorMode() ) SetShowEditor(other.GetShowEditor()); // Directly access m_renderer/m_editor as GetRender/Editor may return different one // Maybe add support for merge of Render and Editor? if ( !HasRenderer() && other.HasRenderer() ) SetRenderer(((wxSheetCellAttrRefData*)other.m_refData)->m_renderer->Clone()); if ( !HasEditor() && other.HasEditor() ) SetEditor(((wxSheetCellAttrRefData*)other.m_refData)->m_editor->Clone()); if ( !HasDefaultAttr() && other.HasDefaultAttr() ) SetDefaultAttr(other.GetDefaultAttr()); return true; }
void wxSheetCellStringRendererRefData::DoDraw(wxSheet& sheet, const wxSheetCellAttr& attr, wxDC& dc, const wxRect& rectCell, const wxSheetCoords& coords, bool isSelected) { wxRect rect = rectCell; rect.Inflate(-1); int align = attr.GetAlignment(); int orient = attr.GetOrientation(); wxString value( sheet.GetCellValue(coords) ); int best_width = DoGetBestSize(sheet, attr, dc, value).GetWidth(); wxSheetCoords cellSpan(sheet.GetCellSpan(coords)); // shouldn't get here if <=0 int cell_rows = cellSpan.m_row; int cell_cols = cellSpan.m_col; bool is_grid_cell = coords.IsGridCell(); // no overflow for row/col/corner labels bool overflow = is_grid_cell && (orient == wxSHEET_AttrOrientHoriz) ? attr.GetOverflow() : false; int overflowCols = 0; int num_cols = sheet.GetNumberCols(); // this is the right col which includes overflow int rightCol = coords.m_col + cell_cols - 1; // Check if this cell should overflow to right and for how many cells if (overflow) { bool is_editing = sheet.IsCellEditControlShown(); wxSheetCoords editorCell = is_editing ? sheet.GetEditControlCoords() : wxNullSheetCoords; int row = coords.GetRow(), col = coords.GetCol(); wxSheetCoords ownerCell; if ((best_width > rectCell.width) && (col < num_cols-1) && sheet.GetTable()) { wxSheetCoords cell; for (cell.m_col = col+cell_cols; cell.m_col < num_cols; cell.m_col++) { bool is_empty = true; for (cell.m_row = row; cell.m_row < row+cell_rows; cell.m_row++) { // check w/ anchor cell for spanned cell block ownerCell = sheet.GetCellOwner(cell); if ( sheet.GetTable()->HasValue(ownerCell) || (ownerCell == editorCell) ) { is_empty = false; break; } } if (is_empty) rect.width += sheet.GetColWidth(cell.m_col); else { cell.m_col--; break; } if (rect.width >= best_width) break; } // this may extend out of sheet overflowCols = cell.m_col - col - cell_cols + 1; rightCol = wxMin(coords.m_col+cell_cols-1+overflowCols, num_cols - 1); } // redraw overflow cells individually for proper selection hilight if (overflowCols > 0) { // if overflowed then it's left aligned (yes I know ALIGN_LEFT=0) align &= ~wxSHEET_AttrAlignHoriz_Mask; align |= wxSHEET_AttrAlignLeft; wxRect clip(rect); clip.x += rectCell.width; int col_width; wxSheetCoords cell(coords); // draw each cell individually since it may be selected or not for (cell.m_col = col+cell_cols; cell.m_col <= rightCol; cell.m_col++) { col_width = sheet.GetColWidth(cell.m_col); clip.width = col_width - 1; dc.DestroyClippingRegion(); dc.SetClippingRegion(clip); SetTextColoursAndFont(sheet, attr, dc, sheet.IsCellSelected(cell)); sheet.DrawTextRectangle(dc, value, rect, align, orient); clip.x += col_width - 1; } rect = rectCell; rect.Inflate(-1); rect.width++; dc.DestroyClippingRegion(); } } // Draw the text SetTextColoursAndFont(sheet, attr, dc, isSelected); sheet.DrawTextRectangle(dc, value, rect, align, orient); if (attr.GetOverflowMarker()) { // Draw a marker to show that the contents has been clipped off int cellRight = sheet.GetColRight(rightCol); if (cellRight - rect.x < best_width) { int bmpWidth = s_overflowBitmap.GetWidth(); int bmpHeight = s_overflowBitmap.GetHeight(); int cellWidth = sheet.GetColWidth(rightCol); int cellHeight = sheet.GetRowHeight(coords.m_row); if ((bmpWidth < cellWidth-3) && (bmpHeight < cellHeight-3)) { int cellTop = sheet.GetRowTop(coords.m_row); int x = cellRight - bmpWidth - 2; int y = cellTop + (cellHeight - bmpHeight)/2; wxRect r(x-2, cellTop, bmpWidth+4-1, cellHeight-1); wxSheetCellAttr rightAttr(attr); if (overflowCols > 0) { wxSheetCoords clipCell(coords.m_row, rightCol); isSelected = sheet.IsCellSelected(clipCell); rightAttr = sheet.GetAttr(clipCell); } // clear background for bitmap wxSheetCellRendererRefData::Draw(sheet, rightAttr, dc, r, coords, isSelected); dc.DrawBitmap( s_overflowBitmap, x, y, true ); } } } }