diff --git a/docs/changes.txt b/docs/changes.txt index e2bf706603..fa22a0eb19 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -50,6 +50,7 @@ All (GUI): - Add support for embedding bitmaps in generated SVG in wxSVGFileDC (iwbnwif). - Add support for sorting wxDataViewCtrl by multiple columns (Trigve). - Allow dropping data on wxDataViewCtrl background (Laurent Poujoulat). +- Add wxRendererNative::DrawGauge() (Tobias Taschner). - Add wxHtmlWindow::SetDefaultHTMLCursor() (Jeff A. Marr). - Add default ctor and Create() to wxContextHelpButton (Hanmac). - Send events when toggling wxPropertyGrid nodes from keyboard (Armel Asselin). diff --git a/include/wx/renderer.h b/include/wx/renderer.h index a6076b5b96..3dede7aa0f 100644 --- a/include/wx/renderer.h +++ b/include/wx/renderer.h @@ -321,6 +321,13 @@ public: int flags = 0) = 0; #endif // wxHAS_DRAW_TITLE_BAR_BITMAP + // Draw a gauge with native style like a wxGauge would display + virtual void DrawGauge(wxWindow* win, + wxDC& dc, + const wxRect& rect, + int value, + int max, + int flags = 0) = 0; // geometry functions // ------------------ @@ -500,6 +507,14 @@ public: { m_rendererNative.DrawTitleBarBitmap(win, dc, rect, button, flags); } #endif // wxHAS_DRAW_TITLE_BAR_BITMAP + virtual void DrawGauge(wxWindow* win, + wxDC& dc, + const wxRect& rect, + int value, + int max, + int flags = 0) + { m_rendererNative.DrawGauge(win, dc, rect, value, max, flags); } + virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) { return m_rendererNative.GetSplitterParams(win); } diff --git a/interface/wx/renderer.h b/interface/wx/renderer.h index 7ff81f43b6..c33f532e0a 100644 --- a/interface/wx/renderer.h +++ b/interface/wx/renderer.h @@ -349,6 +349,22 @@ public: virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0) = 0; + /** + Draw a progress bar in the specified rectangle. + + The @a value and @a max arguments determine the part of the progress + bar that is drawn as being filled in, @a max must be strictly positive + and @a value must be between 0 and @a max. + + @since 3.1.0 + */ + virtual void DrawGauge(wxWindow* win, + wxDC& dc, + const wxRect& rect, + int value, + int max, + int flags = 0) = 0; + /** Draw the header control button (used, for example, by wxListCtrl). diff --git a/samples/render/render.cpp b/samples/render/render.cpp index 7c8f03904a..132d1727e8 100644 --- a/samples/render/render.cpp +++ b/samples/render/render.cpp @@ -267,6 +267,15 @@ private: y += lineHeight + rBtn.height; #endif // wxHAS_DRAW_TITLE_BAR_BITMAP + + const wxCoord heightGauge = 24; + const wxCoord widthGauge = 180; + + dc.DrawText("DrawGauge()", x1, y); + wxRendererNative::GetDefault().DrawGauge(this, dc, + wxRect(x2, y, widthGauge, heightGauge), 25, 100, m_flags); + + y += lineHeight + heightGauge; } int m_flags; diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 2101073494..ca5616a2f0 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -1211,20 +1211,12 @@ bool wxDataViewProgressRenderer::GetValue( wxVariant &value ) const bool wxDataViewProgressRenderer::Render(wxRect rect, wxDC *dc, int WXUNUSED(state)) { - // deflate the rect to leave a small border between bars in adjacent rows - wxRect bar = rect.Deflate(0, 1); - - dc->SetBrush( *wxTRANSPARENT_BRUSH ); - dc->SetPen( *wxBLACK_PEN ); - dc->DrawRectangle( bar ); - - bar.width = (int)(bar.width * m_value / 100.); - dc->SetPen( *wxTRANSPARENT_PEN ); - - const wxDataViewItemAttr& attr = GetAttr(); - dc->SetBrush( attr.HasColour() ? wxBrush(attr.GetColour()) - : *wxBLUE_BRUSH ); - dc->DrawRectangle( bar ); + wxRendererNative::Get().DrawGauge( + GetOwner()->GetOwner(), + *dc, + rect, + m_value, + 100); return true; } diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp index 3bbe88b946..a754440ea8 100644 --- a/src/generic/renderg.cpp +++ b/src/generic/renderg.cpp @@ -130,6 +130,8 @@ public: int flags = 0) wxOVERRIDE; #endif // wxHAS_DRAW_TITLE_BAR_BITMAP + virtual void DrawGauge(wxWindow* win, wxDC& dc, const wxRect& rect, int value, int max, int flags = 0) wxOVERRIDE; + virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) wxOVERRIDE; virtual wxRendererVersion GetVersion() const wxOVERRIDE @@ -792,6 +794,20 @@ void wxRendererGeneric::DrawTitleBarBitmap(wxWindow * WXUNUSED(win), #endif // wxHAS_DRAW_TITLE_BAR_BITMAP +void wxRendererGeneric::DrawGauge(wxWindow* win, wxDC& dc, const wxRect& rect, int value, int max, int WXUNUSED(flags)) +{ + // Use same background as text controls. + DrawTextCtrl(win, dc, rect); + + // Calculate the progress bar size. + wxRect progRect(rect); + progRect.Deflate(2); + progRect.SetWidth(progRect.GetWidth() * ((double)value / max)); + + dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); + dc.SetPen(*wxTRANSPARENT_PEN); + dc.DrawRectangle(progRect); +} // ---------------------------------------------------------------------------- // A module to allow cleanup of generic renderer. diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index 81d205e81c..18a2eef532 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -98,6 +98,10 @@ #define WP_CLOSEBUTTON 18 #define WP_RESTOREBUTTON 21 #define WP_HELPBUTTON 23 + + #define PP_BAR 1 + #define PP_CHUNK 3 + #endif #if defined(__WXWINCE__) @@ -203,6 +207,13 @@ public: wxTitleBarButton button, int flags = 0); + virtual void DrawGauge(wxWindow* win, + wxDC& dc, + const wxRect& rect, + int value, + int max, + int flags = 0); + virtual wxSize GetCheckBoxSize(wxWindow *win); virtual int GetHeaderButtonHeight(wxWindow *win); @@ -308,6 +319,14 @@ public: wxTitleBarButton button, int flags = 0); + virtual void DrawGauge(wxWindow* win, + wxDC& dc, + const wxRect& rect, + int value, + int max, + int flags = 0); + + virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); private: @@ -595,6 +614,25 @@ void wxRendererMSW::DrawTextCtrl(wxWindow* WXUNUSED(win), dc.DrawRectangle(rect); } +void wxRendererMSW::DrawGauge(wxWindow* win, + wxDC& dc, + const wxRect& rect, + int value, + int max, + int WXUNUSED(flags)) +{ + // Use text ctrl back as background + DrawTextCtrl(win, dc, rect); + + // Calc progress bar size + wxRect progRect(rect); + progRect.Deflate(2); + progRect.SetWidth(progRect.GetWidth() * ((double)value / max)); + + dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); + dc.SetPen(*wxTRANSPARENT_PEN); + dc.DrawRectangle(progRect); +} // ============================================================================ // wxRendererXP implementation @@ -888,6 +926,51 @@ void wxRendererXP::DrawTextCtrl(wxWindow* win, dc.DrawRectangle(rect); } +void wxRendererXP::DrawGauge(wxWindow* win, + wxDC& dc, + const wxRect& rect, + int value, + int max, + int flags) +{ + wxUxThemeHandle hTheme(win, L"PROGRESS"); + if ( !hTheme ) + { + m_rendererNative.DrawGauge(win, dc, rect, value, max, flags); + return; + } + + RECT r; + wxCopyRectToRECT(rect, r); + + wxUxThemeEngine::Get()->DrawThemeBackground( + hTheme, + GetHdcOf(dc.GetTempHDC()), + PP_BAR, + 0, + &r, + NULL); + + RECT contentRect; + wxUxThemeEngine::Get()->GetThemeBackgroundContentRect( + hTheme, + GetHdcOf(dc.GetTempHDC()), + PP_BAR, + 0, + &r, + &contentRect); + + contentRect.right = contentRect.left + (contentRect.right - contentRect.left) * ((double)value / max); + + wxUxThemeEngine::Get()->DrawThemeBackground( + hTheme, + GetHdcOf(dc.GetTempHDC()), + PP_CHUNK, + 0, + &contentRect, + NULL); +} + // ---------------------------------------------------------------------------- // splitter drawing // ---------------------------------------------------------------------------- diff --git a/src/osx/carbon/renderer.cpp b/src/osx/carbon/renderer.cpp index fec1c194ee..fa4df9b01f 100644 --- a/src/osx/carbon/renderer.cpp +++ b/src/osx/carbon/renderer.cpp @@ -123,6 +123,13 @@ public: int flags = 0) wxOVERRIDE; #endif // wxHAS_DRAW_TITLE_BAR_BITMAP + virtual void DrawGauge(wxWindow* win, + wxDC& dc, + const wxRect& rect, + int value, + int max, + int flags = 0); + virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) wxOVERRIDE; private: @@ -863,4 +870,38 @@ void wxRendererMac::DrawTitleBarBitmap(wxWindow *win, #endif // wxHAS_DRAW_TITLE_BAR_BITMAP +void wxRendererMac::DrawGauge(wxWindow* win, + wxDC& dc, + const wxRect& rect, + int value, + int max, + int flags) +{ + const wxCoord x = rect.x; + const wxCoord y = rect.y; + const wxCoord w = rect.width; + const wxCoord h = rect.height; + + HIThemeTrackDrawInfo tdi; + tdi.version = 0; + tdi.min = 0; + tdi.value = value; + tdi.max = max; + tdi.bounds = CGRectMake(x, y, w, h); + tdi.attributes = kThemeTrackHorizontal; + tdi.enableState = kThemeTrackActive; + tdi.kind = kThemeLargeProgressBar; + + int milliSecondsPerStep = 1000 / 60; + wxLongLongNative localTime = wxGetLocalTimeMillis(); + tdi.trackInfo.progress.phase = localTime.GetValue() / milliSecondsPerStep % 32; + + CGContextRef cgContext; + wxGCDCImpl *impl = (wxGCDCImpl*) dc.GetImpl(); + + cgContext = (CGContextRef) impl->GetGraphicsContext()->GetNativeContext(); + + HIThemeDrawTrack(&tdi, NULL, cgContext, kHIThemeOrientationNormal); +} + #endif