Add wxRendererNative::DrawItemText() for list-like controls

Add a new method that should be used for drawing the elements of list-like
controls (i.e. wx{List,Tree,DataView}Ctrl and similar).

Implement it for wxMSW natively and provide a straightforward generic fallback
for the other ports.

See #16414.
This commit is contained in:
Tobias Taschner
2015-09-17 14:38:03 +02:00
committed by Vadim Zeitlin
parent ba4bfc5414
commit b7a89f8746
8 changed files with 189 additions and 0 deletions

View File

@@ -138,6 +138,13 @@ public:
virtual void DrawGauge(wxWindow* win, wxDC& dc, const wxRect& rect, int value, int max, int flags = 0) wxOVERRIDE;
virtual void DrawItemText(wxWindow* win,
wxDC& dc,
const wxString& text,
const wxRect& rect,
int align = wxALIGN_LEFT | wxALIGN_TOP,
int flags = 0) wxOVERRIDE;
virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) wxOVERRIDE;
virtual wxRendererVersion GetVersion() const wxOVERRIDE
@@ -832,6 +839,46 @@ void wxRendererGeneric::DrawGauge(wxWindow* win,
dc.DrawRectangle(progRect);
}
void
wxRendererGeneric::DrawItemText(wxWindow* win,
wxDC& dc,
const wxString& text,
const wxRect& rect,
int align,
int flags)
{
// Determine text color
wxColour textColour;
if ( flags & wxCONTROL_SELECTED )
{
if ( flags & wxCONTROL_FOCUSED )
{
textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
}
else // !focused
{
textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT);
}
}
else if ( flags & wxCONTROL_DISABLED )
{
textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
}
else // enabled but not selected
{
textColour = win->GetForegroundColour();
}
const wxString paintText = wxControl::Ellipsize(text, dc,
wxELLIPSIZE_END,
rect.GetWidth());
// Draw text
dc.SetTextForeground(textColour);
dc.SetTextBackground(wxTransparentColour);
dc.DrawLabel(paintText, rect, align);
}
// ----------------------------------------------------------------------------
// A module to allow cleanup of generic renderer.
// ----------------------------------------------------------------------------