I recently had a need to display slightly rich text in a wxGrid. This seems to be something that is requested occasionally but not yet implemented AFAIK.
#include <wx/html/winpars.h>
#include <wx/html/htmprint.h>
void
myGridCellHtmlRenderer::Draw(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
const wxRect& rect,
int row, int col,
bool isSelected)
{
// call base class ::Draw to clear the cell and draw the borders etc.
wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
wxHtmlDCRenderer renderer;
wxFont font = grid.GetCellFont(row, col);
renderer.SetDC (&dc);
renderer.SetStandardFonts(font.GetPointSize(),
font.GetFaceName(), wxEmptyString);
renderer.SetSize (grid.GetColSize(col) - 4, grid.GetRowSize(row));
renderer.SetHtmlText (grid.GetCellValue(row, col));
wxArrayInt value = 0;
renderer.Render (rect.x + 2, rect.y + 2, value);
}
wxSize
myGridCellHtmlRenderer::GetBestSize(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
int row, int col)
{
wxHtmlDCRenderer renderer;
wxFont font = grid.GetCellFont(row, col);
renderer.SetDC (&dc);
renderer.SetStandardFonts(font.GetPointSize(),
font.GetFaceName(), wxEmptyString);
renderer.SetSize (grid.GetColSize(col), grid.GetRowSize(row));
renderer.SetHtmlText (grid.GetCellValue(row, col));
return wxSize (grid.GetColSize(col) - 4, renderer.GetTotalHeight() + 4);
}