Merge branch 'fix-grid-demo'
Fix colour of starts in the grid sample. See https://github.com/wxWidgets/wxWidgets/pull/2019
This commit is contained in:
@@ -228,6 +228,13 @@ public:
|
|||||||
|
|
||||||
// create a new object which is the copy of this one
|
// create a new object which is the copy of this one
|
||||||
virtual wxGridCellRenderer *Clone() const = 0;
|
virtual wxGridCellRenderer *Clone() const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// set the text colours before drawing
|
||||||
|
void SetTextColoursAndFont(const wxGrid& grid,
|
||||||
|
const wxGridCellAttr& attr,
|
||||||
|
wxDC& dc,
|
||||||
|
bool isSelected);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Smart pointer to wxGridCellRenderer, calling DecRef() on it automatically.
|
// Smart pointer to wxGridCellRenderer, calling DecRef() on it automatically.
|
||||||
|
@@ -41,12 +41,6 @@ public:
|
|||||||
{ return new wxGridCellStringRenderer; }
|
{ return new wxGridCellStringRenderer; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// set the text colours before drawing
|
|
||||||
void SetTextColoursAndFont(const wxGrid& grid,
|
|
||||||
const wxGridCellAttr& attr,
|
|
||||||
wxDC& dc,
|
|
||||||
bool isSelected);
|
|
||||||
|
|
||||||
// calc the string extent for given string/font
|
// calc the string extent for given string/font
|
||||||
wxSize DoGetBestSize(const wxGridCellAttr& attr,
|
wxSize DoGetBestSize(const wxGridCellAttr& attr,
|
||||||
wxDC& dc,
|
wxDC& dc,
|
||||||
|
@@ -109,6 +109,23 @@ public:
|
|||||||
wxDC& dc);
|
wxDC& dc);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
Helper function setting the correct colours and font.
|
||||||
|
|
||||||
|
This function can be useful in the derived classes Draw()
|
||||||
|
implementation as it takes care of setting the appropriate colours and
|
||||||
|
font for @a dc depending on the global @a grid attributes, cell
|
||||||
|
attributions specified in @a attr and whether @a isSelected is @true.
|
||||||
|
|
||||||
|
Simply call it before doing any drawing in the derived class version to
|
||||||
|
use consistent colours and font for all cells.
|
||||||
|
|
||||||
|
@since 3.1.5
|
||||||
|
*/
|
||||||
|
void SetTextColoursAndFont(const wxGrid& grid,
|
||||||
|
const wxGridCellAttr& attr,
|
||||||
|
wxDC& dc,
|
||||||
|
bool isSelected);
|
||||||
/**
|
/**
|
||||||
The destructor is private because only DecRef() can delete us.
|
The destructor is private because only DecRef() can delete us.
|
||||||
*/
|
*/
|
||||||
|
@@ -162,6 +162,8 @@ public:
|
|||||||
{
|
{
|
||||||
wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
|
wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
|
||||||
|
|
||||||
|
SetTextColoursAndFont(grid, attr, dc, isSelected);
|
||||||
|
|
||||||
grid.DrawTextRectangle(dc, GetStarString(GetStarValue(grid, row, col)),
|
grid.DrawTextRectangle(dc, GetStarString(GetStarValue(grid, row, col)),
|
||||||
rect, attr);
|
rect, attr);
|
||||||
}
|
}
|
||||||
|
@@ -69,6 +69,42 @@ void wxGridCellRenderer::Draw(wxGrid& grid,
|
|||||||
dc.DrawRectangle(rect);
|
dc.DrawRectangle(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGridCellRenderer::SetTextColoursAndFont(const wxGrid& grid,
|
||||||
|
const wxGridCellAttr& attr,
|
||||||
|
wxDC& dc,
|
||||||
|
bool isSelected)
|
||||||
|
{
|
||||||
|
dc.SetBackgroundMode( wxBRUSHSTYLE_TRANSPARENT );
|
||||||
|
|
||||||
|
// TODO some special colours for attr.IsReadOnly() case?
|
||||||
|
|
||||||
|
// different coloured text when the grid is disabled
|
||||||
|
if ( grid.IsThisEnabled() )
|
||||||
|
{
|
||||||
|
if ( isSelected )
|
||||||
|
{
|
||||||
|
wxColour clr;
|
||||||
|
if ( grid.HasFocus() )
|
||||||
|
clr = grid.GetSelectionBackground();
|
||||||
|
else
|
||||||
|
clr = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW);
|
||||||
|
dc.SetTextBackground( clr );
|
||||||
|
dc.SetTextForeground( grid.GetSelectionForeground() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dc.SetTextBackground( attr.GetBackgroundColour() );
|
||||||
|
dc.SetTextForeground( attr.GetTextColour() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
|
||||||
|
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
|
||||||
|
}
|
||||||
|
|
||||||
|
dc.SetFont( attr.GetFont() );
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxGridCellDateTimeRenderer
|
// wxGridCellDateTimeRenderer
|
||||||
@@ -573,43 +609,6 @@ wxGridCellAutoWrapStringRenderer::GetBestWidth(wxGrid& grid,
|
|||||||
// wxGridCellStringRenderer
|
// wxGridCellStringRenderer
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxGridCellStringRenderer::SetTextColoursAndFont(const wxGrid& grid,
|
|
||||||
const wxGridCellAttr& attr,
|
|
||||||
wxDC& dc,
|
|
||||||
bool isSelected)
|
|
||||||
{
|
|
||||||
dc.SetBackgroundMode( wxBRUSHSTYLE_TRANSPARENT );
|
|
||||||
|
|
||||||
// TODO some special colours for attr.IsReadOnly() case?
|
|
||||||
|
|
||||||
// different coloured text when the grid is disabled
|
|
||||||
if ( grid.IsThisEnabled() )
|
|
||||||
{
|
|
||||||
if ( isSelected )
|
|
||||||
{
|
|
||||||
wxColour clr;
|
|
||||||
if ( grid.HasFocus() )
|
|
||||||
clr = grid.GetSelectionBackground();
|
|
||||||
else
|
|
||||||
clr = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW);
|
|
||||||
dc.SetTextBackground( clr );
|
|
||||||
dc.SetTextForeground( grid.GetSelectionForeground() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dc.SetTextBackground( attr.GetBackgroundColour() );
|
|
||||||
dc.SetTextForeground( attr.GetTextColour() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
|
|
||||||
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.SetFont( attr.GetFont() );
|
|
||||||
}
|
|
||||||
|
|
||||||
wxSize wxGridCellStringRenderer::DoGetBestSize(const wxGridCellAttr& attr,
|
wxSize wxGridCellStringRenderer::DoGetBestSize(const wxGridCellAttr& attr,
|
||||||
wxDC& dc,
|
wxDC& dc,
|
||||||
const wxString& text)
|
const wxString& text)
|
||||||
|
Reference in New Issue
Block a user