From 3a1576f74c643b1873386ab0468e22c8b3a0d492 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 10 Mar 2021 23:46:24 +0100 Subject: [PATCH 1/2] Fix size of owner-drawn checkbox at non-standard DPI Get the correct size from wxRendererNative instead of wxGetSystemMetrics. Simplify positioning the button and label rectangles. Closes #19095 --- src/msw/control.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/msw/control.cpp b/src/msw/control.cpp index 10bc8f0b4f..e111d272ca 100644 --- a/src/msw/control.cpp +++ b/src/msw/control.cpp @@ -542,34 +542,29 @@ bool wxMSWOwnerDrawnButtonBase::MSWDrawButton(WXDRAWITEMSTRUCT *item) // choose the values consistent with those used for native, non // owner-drawn, buttons - static const int MARGIN = 3; - int CXMENUCHECK = wxGetSystemMetrics(SM_CXMENUCHECK, m_win) + 1; - // the buttons were even bigger under Windows XP - if ( wxGetWinVersion() < wxWinVersion_6 ) - CXMENUCHECK += 2; + const int spacing = m_win->FromDIP(3); + const wxSize cbSize = wxRendererNative::Get().GetCheckBoxSize(m_win, flags); - // The space between the button and the label - // is included in the button bitmap. - const int buttonSize = wxMin(CXMENUCHECK - MARGIN, m_win->GetSize().y); + const int buttonSize = wxMin(cbSize.y, m_win->GetSize().y); rectButton.top = rect.top + (rect.bottom - rect.top - buttonSize) / 2; rectButton.bottom = rectButton.top + buttonSize; const bool isRightAligned = m_win->HasFlag(wxALIGN_RIGHT); if ( isRightAligned ) { - rectLabel.right = rect.right - CXMENUCHECK; - rectLabel.left = rect.left; + rectButton.right = rect.right; + rectButton.left = rectButton.right - buttonSize; - rectButton.left = rectLabel.right + ( CXMENUCHECK + MARGIN - buttonSize ) / 2; - rectButton.right = rectButton.left + buttonSize; + rectLabel.right = rectButton.left - spacing; + rectLabel.left = rect.left; } else // normal, left-aligned button { - rectButton.left = rect.left + ( CXMENUCHECK - MARGIN - buttonSize ) / 2; + rectButton.left = rect.left; rectButton.right = rectButton.left + buttonSize; - rectLabel.left = rect.left + CXMENUCHECK; + rectLabel.left = spacing + rectButton.right; rectLabel.right = rect.right; } From 47047a608adb74e7190de5f6d4168074135e5cdb Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 10 Mar 2021 23:46:50 +0100 Subject: [PATCH 2/2] Fix drawing undetermined state of owner-drawn checkbox --- src/msw/checkbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/msw/checkbox.cpp b/src/msw/checkbox.cpp index d489201848..ac2784da74 100644 --- a/src/msw/checkbox.cpp +++ b/src/msw/checkbox.cpp @@ -247,11 +247,11 @@ int wxCheckBox::MSWGetButtonCheckedFlag() const return wxCONTROL_CHECKED; case wxCHK_UNDETERMINED: - return wxCONTROL_PRESSED; + return wxCONTROL_UNDETERMINED; case wxCHK_UNCHECKED: // no extra styles needed - return 0; + return wxCONTROL_NONE; } wxFAIL_MSG( wxT("unexpected Get3StateValue() return value") );