diff --git a/docs/changes.txt b/docs/changes.txt index 41b4baba6d..5f1698d1b7 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -180,6 +180,7 @@ All (GUI): - Add "hint" property to wxSearchCtrl XRC handler. - Add wxEVT_SEARCH[_CANCEL] synonyms for wxSearchCtrl events. - Generate wxEVT_SEARCH on Enter under all platforms. +- Extend wxRendererNative::DrawGauge() to work for vertical gauges too. wxGTK: diff --git a/include/wx/renderer.h b/include/wx/renderer.h index fd67b7a760..e816725bbf 100644 --- a/include/wx/renderer.h +++ b/include/wx/renderer.h @@ -333,7 +333,9 @@ public: int flags = 0) = 0; #endif // wxHAS_DRAW_TITLE_BAR_BITMAP - // Draw a gauge with native style like a wxGauge would display + // Draw a gauge with native style like a wxGauge would display. + // + // wxCONTROL_SPECIAL flag must be used for drawing vertical gauges. virtual void DrawGauge(wxWindow* win, wxDC& dc, const wxRect& rect, diff --git a/interface/wx/renderer.h b/interface/wx/renderer.h index 92be723034..2a3772b78a 100644 --- a/interface/wx/renderer.h +++ b/interface/wx/renderer.h @@ -359,6 +359,8 @@ public: bar that is drawn as being filled in, @a max must be strictly positive and @a value must be between 0 and @a max. + @c wxCONTROL_SPECIAL must be set in @a flags for the vertical gauges. + @since 3.1.0 */ virtual void DrawGauge(wxWindow* win, diff --git a/samples/render/render.cpp b/samples/render/render.cpp index d626b301de..1e4b819dcf 100644 --- a/samples/render/render.cpp +++ b/samples/render/render.cpp @@ -138,6 +138,7 @@ private: void OnUseIcon(wxCommandEvent& event); void OnUseBitmap(wxCommandEvent& event); + void OnUseGeneric(wxCommandEvent& event); #if wxUSE_DYNLIB_CLASS void OnLoad(wxCommandEvent& event); void OnUnload(wxCommandEvent& event); @@ -163,7 +164,8 @@ public: m_flags = 0; m_align = wxALIGN_LEFT; m_useIcon = - m_useBitmap = false; + m_useBitmap = + m_useGeneric = false; } int GetFlags() const { return m_flags; } @@ -172,13 +174,15 @@ public: void SetAlignment(int align) { m_align = align; } void SetUseIcon(bool useIcon) { m_useIcon = useIcon; } void SetUseBitmap(bool useBitmap) { m_useBitmap = useBitmap; } + void SetUseGeneric(bool useGeneric) { m_useGeneric = useGeneric; } private: void OnPaint(wxPaintEvent&) { wxPaintDC dc(this); - wxRendererNative& renderer = wxRendererNative::Get(); + wxRendererNative& renderer = m_useGeneric ? wxRendererNative::GetGeneric() + : wxRendererNative::Get(); int x1 = 10, // text offset x2 = 300, // drawing offset @@ -223,6 +227,8 @@ private: wxART_LIST); } + // Note that we need to use GetDefault() explicitly to show the default + // implementation. dc.DrawText("DrawHeaderButton() (default)", x1, y); wxRendererNative::GetDefault().DrawHeaderButton(this, dc, wxRect(x2, y, widthHdr, heightHdr), m_flags, @@ -278,12 +284,17 @@ private: y += lineHeight + rBtn.height; #endif // wxHAS_DRAW_TITLE_BAR_BITMAP + // The meanings of those are reversed for the vertical gauge below. const wxCoord heightGauge = 24; const wxCoord widthGauge = 180; dc.DrawText("DrawGauge()", x1, y); - wxRendererNative::GetDefault().DrawGauge(this, dc, + renderer.DrawGauge(this, dc, wxRect(x2, y, widthGauge, heightGauge), 25, 100, m_flags); + renderer.DrawGauge(this, dc, + wxRect(x2 + widthGauge + 30, y + heightGauge - widthGauge, + heightGauge, widthGauge), + 25, 100, m_flags | wxCONTROL_SPECIAL); y += lineHeight + heightGauge; @@ -291,10 +302,10 @@ private: const wxCoord widthListItem = 260; dc.DrawText("DrawItemSelectionRect()", x1, y); - wxRendererNative::GetDefault().DrawItemSelectionRect(this, dc, + renderer.DrawItemSelectionRect(this, dc, wxRect(x2, y, widthListItem, heightListItem), m_flags | wxCONTROL_SELECTED); - wxRendererNative::GetDefault().DrawItemText(this, dc, "DrawItemText()", + renderer.DrawItemText(this, dc, "DrawItemText()", wxRect(x2, y, widthListItem, heightListItem).Inflate(-2, -2), m_align, m_flags | wxCONTROL_SELECTED); y += lineHeight + heightListItem; @@ -303,7 +314,8 @@ private: int m_flags; int m_align; bool m_useIcon, - m_useBitmap; + m_useBitmap, + m_useGeneric; wxDECLARE_EVENT_TABLE(); }; @@ -335,6 +347,7 @@ enum Render_UseIcon, Render_UseBitmap, + Render_UseGeneric, #if wxUSE_DYNLIB_CLASS Render_Load, Render_Unload, @@ -371,6 +384,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Render_UseIcon, MyFrame::OnUseIcon) EVT_MENU(Render_UseBitmap, MyFrame::OnUseBitmap) + EVT_MENU(Render_UseGeneric, MyFrame::OnUseGeneric) #if wxUSE_DYNLIB_CLASS EVT_MENU(Render_Load, MyFrame::OnLoad) EVT_MENU(Render_Unload,MyFrame::OnUnload) @@ -422,9 +436,7 @@ bool MyApp::OnInit() MyFrame::MyFrame() : wxFrame(NULL, wxID_ANY, - wxT("Render wxWidgets Sample"), - wxPoint(50, 50), - wxSize(450, 340)) + wxT("Render wxWidgets Sample")) { // set the frame icon SetIcon(wxICON(sample)); @@ -457,6 +469,7 @@ MyFrame::MyFrame() menuFile->AppendCheckItem(Render_UseBitmap, "Draw &bitmap\tCtrl-B"); menuFile->AppendSeparator(); + menuFile->AppendCheckItem(Render_UseGeneric, "Use &generic renderer\tCtrl-G"); #if wxUSE_DYNLIB_CLASS menuFile->Append(Render_Load, wxT("&Load renderer...\tCtrl-L")); menuFile->Append(Render_Unload, wxT("&Unload renderer\tCtrl-U")); @@ -479,6 +492,8 @@ MyFrame::MyFrame() m_panel = new MyPanel(this); + SetClientSize(600, 600); + #if wxUSE_STATUSBAR // create a status bar just for fun (by default with 1 pane only) CreateStatusBar(2); @@ -526,6 +541,12 @@ void MyFrame::OnUseBitmap(wxCommandEvent& event) m_panel->Refresh(); } +void MyFrame::OnUseGeneric(wxCommandEvent& event) +{ + m_panel->SetUseGeneric(event.IsChecked()); + m_panel->Refresh(); +} + #if wxUSE_DYNLIB_CLASS void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event)) diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp index 1961141fc4..5cf2656cef 100644 --- a/src/generic/renderg.cpp +++ b/src/generic/renderg.cpp @@ -910,7 +910,7 @@ void wxRendererGeneric::DrawGauge(wxWindow* win, const wxRect& rect, int value, int max, - int WXUNUSED(flags)) + int flags) { // Use same background as text controls. DrawTextCtrl(win, dc, rect); @@ -918,7 +918,16 @@ void wxRendererGeneric::DrawGauge(wxWindow* win, // Calculate the progress bar size. wxRect progRect(rect); progRect.Deflate(2); - progRect.width = wxMulDivInt32(progRect.width, value, max); + if ( flags & wxCONTROL_SPECIAL ) + { + const int h = wxMulDivInt32(progRect.height, value, max); + progRect.y += progRect.height - h; + progRect.height = h; + } + else // Horizontal. + { + progRect.width = wxMulDivInt32(progRect.width, value, max); + } dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); dc.SetPen(*wxTRANSPARENT_PEN); diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index fff5432e6d..7935e05dcc 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -1098,7 +1098,7 @@ void wxRendererXP::DrawGauge(wxWindow* win, ::DrawThemeBackground( hTheme, GetHdcOf(dc.GetTempHDC()), - PP_BAR, + flags & wxCONTROL_SPECIAL ? PP_BARVERT : PP_BAR, 0, &r, NULL); @@ -1107,20 +1107,31 @@ void wxRendererXP::DrawGauge(wxWindow* win, ::GetThemeBackgroundContentRect( hTheme, GetHdcOf(dc.GetTempHDC()), - PP_BAR, + flags & wxCONTROL_SPECIAL ? PP_BARVERT : PP_BAR, 0, &r, &contentRect); - contentRect.right = contentRect.left + + if ( flags & wxCONTROL_SPECIAL ) + { + // For a vertical gauge, the value grows from the bottom to the top. + contentRect.top = contentRect.bottom - + wxMulDivInt32(contentRect.bottom - contentRect.top, + value, + max); + } + else // Horizontal. + { + contentRect.right = contentRect.left + wxMulDivInt32(contentRect.right - contentRect.left, value, max); + } ::DrawThemeBackground( hTheme, GetHdcOf(dc.GetTempHDC()), - PP_CHUNK, + flags & wxCONTROL_SPECIAL ? PP_CHUNKVERT : PP_CHUNK, 0, &contentRect, NULL);