Merge branch 'ownerdrawn-checkbox-dpi' of https://github.com/MaartenBent/wxWidgets

Fix size of owner-drawn checkbox at non-standard DPI.

See https://github.com/wxWidgets/wxWidgets/pull/2274
This commit is contained in:
Vadim Zeitlin 2021-03-13 12:50:25 +01:00
commit 1830128cbd
2 changed files with 11 additions and 16 deletions

View File

@ -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") );

View File

@ -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;
}