From 2874dab7f004259d1d2aa9b79e68fc92543619f8 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Thu, 8 Aug 2019 00:52:06 +0200 Subject: [PATCH] Add DrawCheckMark and GetCheckMarkSize to wxRendererNative Show its use in the render sample. Also use the recently added GetExpanderSize for the size of DrawTreeItemButton. --- include/wx/renderer.h | 22 +++++++++++- interface/wx/renderer.h | 26 ++++++++++++++ samples/render/render.cpp | 11 ++++-- src/generic/renderg.cpp | 22 ++++++++++++ src/msw/renderer.cpp | 74 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+), 3 deletions(-) diff --git a/include/wx/renderer.h b/include/wx/renderer.h index 8d984477e7..4a4b92375a 100644 --- a/include/wx/renderer.h +++ b/include/wx/renderer.h @@ -250,9 +250,20 @@ public: const wxRect& rect, int flags = 0) = 0; + // draw check mark + // + // flags may use wxCONTROL_DISABLED + virtual void DrawCheckMark(wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags = 0) = 0; + // Returns the default size of a check box. virtual wxSize GetCheckBoxSize(wxWindow *win) = 0; + // Returns the default size of a check mark. + virtual wxSize GetCheckMarkSize(wxWindow *win) = 0; + // Returns the default size of a expander. virtual wxSize GetExpanderSize(wxWindow *win) = 0; @@ -479,10 +490,19 @@ public: int flags = 0) wxOVERRIDE { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); } + virtual void DrawCheckMark(wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags = 0) wxOVERRIDE + { m_rendererNative.DrawCheckMark( win, dc, rect, flags ); } + virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE { return m_rendererNative.GetCheckBoxSize(win); } - virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE + virtual wxSize GetCheckMarkSize(wxWindow *win) wxOVERRIDE + { return m_rendererNative.GetCheckMarkSize(win); } + + virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE { return m_rendererNative.GetExpanderSize(win); } virtual void DrawPushButton(wxWindow *win, diff --git a/interface/wx/renderer.h b/interface/wx/renderer.h index e2c5036d47..0cb0685fc7 100644 --- a/interface/wx/renderer.h +++ b/interface/wx/renderer.h @@ -234,8 +234,13 @@ public: virtual void DrawCheckBox(wxWindow *win, wxDC& dc, const wxRect& rect, int flags = 0 ); + virtual void DrawCheckMark(wxWindow *win, wxDC& dc, + const wxRect& rect, int flags = 0 ); + virtual wxSize GetCheckBoxSize(wxWindow *win); + virtual wxSize GetCheckMarkSize(wxWindow *win); + virtual wxSize GetExpanderSize(wxWindow* win); virtual void DrawPushButton(wxWindow *win, wxDC& dc, @@ -532,6 +537,17 @@ public: wxTitleBarButton button, int flags = 0) = 0; + /** + Draw a check mark. + + @a flags may have the @c wxCONTROL_DISABLED bit set, see + @ref wxCONTROL_FLAGS. + + @since 3.1.3 + */ + virtual void DrawCheckMark(wxWindow* win, wxDC& dc, const wxRect& rect, + int flags = 0) = 0; + /** Return the currently used renderer. */ @@ -560,6 +576,16 @@ public: */ virtual wxSize GetCheckBoxSize(wxWindow* win) = 0; + /** + Returns the size of a check mark. + + @param win A valid, i.e. non-null, window pointer which is used to get + the theme defining the checkmark size under some platforms. + + @since 3.1.3 + */ + virtual wxSize GetCheckMarkSize(wxWindow* win) = 0; + /** Returns the size of the expander used in tree-like controls. diff --git a/samples/render/render.cpp b/samples/render/render.cpp index 158e16d5ba..835490840f 100644 --- a/samples/render/render.cpp +++ b/samples/render/render.cpp @@ -247,6 +247,12 @@ private: wxRect(wxPoint(x2, y), sizeCheck), m_flags); y += lineHeight + sizeCheck.y; + dc.DrawText("DrawCheckMark()", x1, y); + const wxSize sizeMark = renderer.GetCheckMarkSize(this); + renderer.DrawCheckMark(this, dc, + wxRect(wxPoint(x2, y), sizeMark), m_flags); + y += lineHeight + sizeMark.y; + dc.DrawText("DrawRadioBitmap()", x1, y); renderer.DrawRadioBitmap(this, dc, wxRect(wxPoint(x2, y), sizeCheck), m_flags); @@ -259,9 +265,10 @@ private: y += lineHeight + sizeCollapse.y; dc.DrawText("DrawTreeItemButton()", x1, y); + const wxSize sizeExpand = renderer.GetExpanderSize(this); renderer.DrawTreeItemButton(this, dc, - wxRect(x2, y, 20, 20), m_flags); - y += lineHeight + 20; + wxRect(wxPoint(x2, y), sizeExpand), m_flags); + y += lineHeight + sizeExpand.y; #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP dc.DrawText("DrawTitleBarBitmap()", x1, y); diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp index 19f540322c..4a328ffaa8 100644 --- a/src/generic/renderg.cpp +++ b/src/generic/renderg.cpp @@ -106,8 +106,15 @@ public: const wxRect& rect, int flags = 0) wxOVERRIDE; + virtual void DrawCheckMark(wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags = 0) wxOVERRIDE; + virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE; + virtual wxSize GetCheckMarkSize(wxWindow *win) wxOVERRIDE; + virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE; virtual void DrawPushButton(wxWindow *win, @@ -714,6 +721,16 @@ wxRendererGeneric::DrawCheckBox(wxWindow *WXUNUSED(win), } } +void +wxRendererGeneric::DrawCheckMark(wxWindow *WXUNUSED(win), + wxDC& dc, + const wxRect& rect, + int flags) +{ + dc.SetPen(*(flags & wxCONTROL_DISABLED ? wxGREY_PEN : wxBLACK_PEN)); + dc.DrawCheckMark(rect); +} + wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *win) { wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" ); @@ -721,6 +738,11 @@ wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *win) return win->FromDIP(wxSize(16, 16)); } +wxSize wxRendererGeneric::GetCheckMarkSize(wxWindow *win) +{ + return GetCheckBoxSize(win); +} + wxSize wxRendererGeneric::GetExpanderSize(wxWindow *win) { wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" ); diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index 0ccbbdb33a..2b1a5470af 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -135,6 +135,14 @@ public: DoDrawButton(DFCS_BUTTONCHECK, win, dc, rect, flags); } + virtual void DrawCheckMark(wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags = 0) wxOVERRIDE + { + DoDrawFrameControl(DFC_MENU, DFCS_MENUCHECK, win, dc, rect, flags); + } + virtual void DrawPushButton(wxWindow *win, wxDC& dc, const wxRect& rect, @@ -230,6 +238,15 @@ public: m_rendererNative.DrawCheckBox(win, dc, rect, flags); } + virtual void DrawCheckMark(wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags = 0) wxOVERRIDE + { + if ( !DoDrawCheckMark(MENU_POPUPCHECK, win, dc, rect, flags) ) + m_rendererNative.DrawCheckMark(win, dc, rect, flags); + } + virtual void DrawPushButton(wxWindow *win, wxDC& dc, const wxRect& rect, @@ -273,6 +290,8 @@ public: virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE; + virtual wxSize GetCheckMarkSize(wxWindow* win) wxOVERRIDE; + virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE; virtual void DrawGauge(wxWindow* win, @@ -309,6 +328,12 @@ private: const wxRect& rect, int flags); + bool DoDrawCheckMark(int kind, + wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags); + wxDECLARE_NO_COPY_CLASS(wxRendererXP); }; @@ -736,6 +761,38 @@ wxRendererXP::DoDrawXPButton(int kind, return true; } +bool +wxRendererXP::DoDrawCheckMark(int kind, + wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags) +{ + wxUxThemeHandle hTheme(win, L"MENU"); + if ( !hTheme ) + return false; + + wxCHECK_MSG( dc.GetImpl(), false, wxT("Invalid wxDC") ); + + RECT r = ConvertToRECT(dc, rect); + + int state = MC_CHECKMARKNORMAL; + if ( flags & wxCONTROL_DISABLED ) + state = MC_CHECKMARKDISABLED; + + ::DrawThemeBackground + ( + hTheme, + GetHdcOf(dc.GetTempHDC()), + kind, + state, + &r, + NULL + ); + + return true; +} + void wxRendererXP::DoDrawButtonLike(HTHEME htheme, int part, @@ -852,6 +909,23 @@ wxSize wxRendererXP::GetCheckBoxSize(wxWindow* win) return m_rendererNative.GetCheckBoxSize(win); } +wxSize wxRendererXP::GetCheckMarkSize(wxWindow* win) +{ + wxCHECK_MSG(win, wxSize(0, 0), "Must have a valid window"); + + wxUxThemeHandle hTheme(win, L"MENU"); + if (hTheme) + { + if (::IsThemePartDefined(hTheme, MENU_POPUPCHECK, 0)) + { + SIZE checkSize; + if (::GetThemePartSize(hTheme, NULL, MENU_POPUPCHECK, MC_CHECKMARKNORMAL, NULL, TS_DRAW, &checkSize) == S_OK) + return wxSize(checkSize.cx, checkSize.cy); + } + } + return m_rendererNative.GetCheckMarkSize(win); +} + wxSize wxRendererXP::GetExpanderSize(wxWindow* win) { wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" );