From 591136c7bc603f6fdafb91aeea4f2e32ed320f6e Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Fri, 11 Oct 2019 19:22:07 +0200 Subject: [PATCH] Improve button heights at high DPI on wxMSW Don't use FromDIP together with ConvertDialogToPixels, because the font height is already adjusted to the DPI. Also limit the button height at higher DPI. Because the height determined by ConvertDialogToPixels is higher than standard buttons use on Windows. Closes #18528 --- src/msw/anybutton.cpp | 11 +++++++++-- src/msw/gauge.cpp | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/msw/anybutton.cpp b/src/msw/anybutton.cpp index 76021aa0ae..b5e97de827 100644 --- a/src/msw/anybutton.cpp +++ b/src/msw/anybutton.cpp @@ -431,8 +431,15 @@ wxSize wxMSWButton::IncreaseToStdSizeAndCache(wxControl *btn, const wxSize& size // // Note that we intentionally don't use GetDefaultSize() here, because // it's inexact -- dialog units depend on this dialog's font. - const wxSize sizeDef = btn->ConvertDialogToPixels(btn->FromDIP(wxSize(50, 14))); - + wxSize sizeDef = btn->ConvertDialogToPixels(wxSize(50, 14)); + if ( btn->GetContentScaleFactor() > 1.0 ) + { + // At higher DPI, the returned height is too big compared to + // standard Windows buttons (like Save, Open, OK). FromDIP(25) + // matches the size of the buttons in standard Windows dialogs, see + // https://trac.wxwidgets.org/ticket/18528 for the discussion. + sizeDef.y = btn->FromDIP(25); + } sizeBtn.IncTo(sizeDef); } else // wxBU_EXACTFIT case diff --git a/src/msw/gauge.cpp b/src/msw/gauge.cpp index af7cefdee5..ac03441790 100644 --- a/src/msw/gauge.cpp +++ b/src/msw/gauge.cpp @@ -122,9 +122,9 @@ wxSize wxGauge::DoGetBestSize() const // the smaller one. if (HasFlag(wxGA_VERTICAL)) - return ConvertDialogToPixels(FromDIP(wxSize(8, 107))); + return ConvertDialogToPixels(wxSize(8, 107)); else - return ConvertDialogToPixels(FromDIP(wxSize(107, 8))); + return ConvertDialogToPixels(wxSize(107, 8)); } // ----------------------------------------------------------------------------