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
2 changed files with 11 additions and 16 deletions

View File

@@ -247,11 +247,11 @@ int wxCheckBox::MSWGetButtonCheckedFlag() const
return wxCONTROL_CHECKED; return wxCONTROL_CHECKED;
case wxCHK_UNDETERMINED: case wxCHK_UNDETERMINED:
return wxCONTROL_PRESSED; return wxCONTROL_UNDETERMINED;
case wxCHK_UNCHECKED: case wxCHK_UNCHECKED:
// no extra styles needed // no extra styles needed
return 0; return wxCONTROL_NONE;
} }
wxFAIL_MSG( wxT("unexpected Get3StateValue() return value") ); 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 // 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;
} }