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
This commit is contained in:
Maarten Bent
2021-03-10 23:46:24 +01:00
parent 18edbe93f2
commit 3a1576f74c

View File

@@ -542,34 +542,29 @@ bool wxMSWOwnerDrawnButtonBase::MSWDrawButton(WXDRAWITEMSTRUCT *item)
// choose the values consistent with those used for native, non // choose the values consistent with those used for native, non
// owner-drawn, buttons // owner-drawn, buttons
static const int MARGIN = 3;
int CXMENUCHECK = wxGetSystemMetrics(SM_CXMENUCHECK, m_win) + 1;
// the buttons were even bigger under Windows XP const int spacing = m_win->FromDIP(3);
if ( wxGetWinVersion() < wxWinVersion_6 ) const wxSize cbSize = wxRendererNative::Get().GetCheckBoxSize(m_win, flags);
CXMENUCHECK += 2;
// The space between the button and the label const int buttonSize = wxMin(cbSize.y, m_win->GetSize().y);
// is included in the button bitmap.
const int buttonSize = wxMin(CXMENUCHECK - MARGIN, m_win->GetSize().y);
rectButton.top = rect.top + (rect.bottom - rect.top - buttonSize) / 2; rectButton.top = rect.top + (rect.bottom - rect.top - buttonSize) / 2;
rectButton.bottom = rectButton.top + buttonSize; rectButton.bottom = rectButton.top + buttonSize;
const bool isRightAligned = m_win->HasFlag(wxALIGN_RIGHT); const bool isRightAligned = m_win->HasFlag(wxALIGN_RIGHT);
if ( isRightAligned ) if ( isRightAligned )
{ {
rectLabel.right = rect.right - CXMENUCHECK; rectButton.right = rect.right;
rectLabel.left = rect.left; rectButton.left = rectButton.right - buttonSize;
rectButton.left = rectLabel.right + ( CXMENUCHECK + MARGIN - buttonSize ) / 2; rectLabel.right = rectButton.left - spacing;
rectButton.right = rectButton.left + buttonSize; rectLabel.left = rect.left;
} }
else // normal, left-aligned button else // normal, left-aligned button
{ {
rectButton.left = rect.left + ( CXMENUCHECK - MARGIN - buttonSize ) / 2; rectButton.left = rect.left;
rectButton.right = rectButton.left + buttonSize; rectButton.right = rectButton.left + buttonSize;
rectLabel.left = rect.left + CXMENUCHECK; rectLabel.left = spacing + rectButton.right;
rectLabel.right = rect.right; rectLabel.right = rect.right;
} }