Opened 4 years ago

Closed 4 years ago

Last modified 4 months ago

#16406 closed enhancement (fixed)

New wxNativeRenderer method DrawGauge for native progress display style in custom controls

Reported by: TcT Owned by: VZ
Priority: normal Milestone:
Component: base Version: dev-latest
Keywords: msw, osx Cc:
Blocked By: Blocking:
Patch: yes


In various scenarios a wxGauge like progress display is required in another control like in wxDataViewProgressRenderer.

I've attached a patch that implements a ::DrawGauge method to wxNativeRenderer.

I've implemented the function for MSW (XP theme and legacy), OSX and generic. I've also modified wxDataViewProgressRenderer to use wxNativeRenderer::DrawGauge. A screenshot of the wxDataView sample with the patch applied is attached.

New method is modeled like the existing wxNativeRenderer methods:

virtual void DrawGauge(wxWindow* win,
                       wxDC& dc,
                       const wxRect& rect,
                       int value,
                       int max,
                       int flags = 0) = 0;
  • value current progress value
  • max maximum progress value
  • flags currently unused

Attachments (2)

wxWidgets-gauge_native_renderer.patch download (9.5 KB) - added by TcT 4 years ago.
Patch based on r77018
DrawGauge_sample.jpg download (116.6 KB) - added by TcT 4 years ago.
Sample screenshot

Download all attachments as: .zip

Change History (7)

Changed 4 years ago by TcT

Patch based on r77018

Changed 4 years ago by TcT

Sample screenshot

comment:1 Changed 4 years ago by vadz

Thanks for the nice patch! Applying it with just some minor style changes and the addition of the documentation to source:wxWidgets/trunk/interface/wx/renderer.h.

I looked at how this could be implemented for wxGTK, but this doesn't look trivial, there is no standard function to do it and the closes I could find was gtk_cell_renderer_progress_render() used by GtkCellRendererProgress but it's rather longish... Still, ideally we should do something like this to match the themed look for wxGTK.

comment:2 Changed 4 years ago by VZ

  • Owner set to VZ
  • Resolution set to fixed
  • Status changed from new to closed

In 77023:

Add wxRendererNative::DrawGauge() method.

Add the method with the native implementations for MSW and OS X and a generic
version fallback.

Closes #16406.

comment:3 Changed 4 years ago by VZ

In 77024:

(The changeset message doesn't reference this ticket)

comment:4 Changed 3 years ago by vadz

For future reference: there was a problem with the initial implementation, see r78278 for the correction.

comment:5 Changed 4 months ago by Vadim Zeitlin <vadim@…>

In 30f73aea/git-wxWidgets:

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.

Note: See TracTickets for help on using tickets.