From 30f73aea6af19df18bfcf7ba394e357ced5ace62 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 3 Feb 2018 19:21:46 +0100 Subject: [PATCH] Make using custom colour for wxDataViewProgressRenderer work again This used to work in 3.0, but got broken with the switch to using a native function for rendering the gauge in generic wxDataViewCtrl 86cf756ba95be9ac6988bc466b462e899edf5c4b (see #16406). Restore it now, even if it requires not one, but two hacks: one at wxRendererGeneric level to guess whether a custom colour is being used or not by examining wxDC::GetBackground(), and the other one in wxDataViewProgressRenderer itself to fall back to wxRendererGeneric if the colour is specified. But it is arguably worth doing this to fix the regression, even if it would be nice to provide a better API instead (see #18076). Closes #17885. --- src/generic/datavgen.cpp | 13 ++++++++++++- src/generic/renderg.cpp | 14 +++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 95a056e350..d9840af8ab 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -1373,7 +1373,18 @@ wxString wxDataViewProgressRenderer::GetAccessibleDescription() const bool wxDataViewProgressRenderer::Render(wxRect rect, wxDC *dc, int WXUNUSED(state)) { - wxRendererNative::Get().DrawGauge( + const wxDataViewItemAttr& attr = GetAttr(); + if ( attr.HasColour() ) + dc->SetBackground(attr.GetColour()); + + // This is a hack, but native renderers don't support using custom colours, + // but typically gauge colour is important (e.g. it's commonly green/red to + // indicate some qualitative difference), so we fall back to the generic + // implementation which looks ugly but does support using custom colour. + wxRendererNative& renderer = attr.HasColour() + ? wxRendererNative::GetGeneric() + : wxRendererNative::Get(); + renderer.DrawGauge( GetOwner()->GetOwner(), *dc, rect, diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp index 5cf2656cef..fc2f39645d 100644 --- a/src/generic/renderg.cpp +++ b/src/generic/renderg.cpp @@ -912,6 +912,18 @@ void wxRendererGeneric::DrawGauge(wxWindow* win, int max, int flags) { + // This is a hack, but we want to allow customizing the colour used for the + // gauge body, as this is important for the generic wxDataViewCtrl + // implementation which uses this method. So we assume that if the caller + // had set up a brush using background colour different from the default, + // it should be used. Otherwise we use the default one. + const wxBrush& bg = dc.GetBackground(); + wxColour colBar; + if ( bg.IsOk() && bg.GetColour() != win->GetBackgroundColour() ) + colBar = bg.GetColour(); + else + colBar = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); + // Use same background as text controls. DrawTextCtrl(win, dc, rect); @@ -929,7 +941,7 @@ void wxRendererGeneric::DrawGauge(wxWindow* win, progRect.width = wxMulDivInt32(progRect.width, value, max); } - dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); + dc.SetBrush(colBar); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(progRect); }