From 32aabf7a413d8e6d0d318477ee209f0c0e1d1045 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 30 Dec 2018 23:10:20 +0100 Subject: [PATCH] Update font of wxSpinCtrl when DPI changes Fix position of spin control in wxSpinCtrlDouble after DPI change The old size of the control was used to determine the position. Use GetBestSize instead, which will return the correct size. --- include/wx/msw/spinctrl.h | 1 + src/generic/spinctlg.cpp | 9 ++++++++- src/msw/spinctrl.cpp | 11 ++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/wx/msw/spinctrl.h b/include/wx/msw/spinctrl.h index c81ed26665..2152ca828d 100644 --- a/include/wx/msw/spinctrl.h +++ b/include/wx/msw/spinctrl.h @@ -131,6 +131,7 @@ protected: virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) wxOVERRIDE; virtual bool MSWOnScroll(int orientation, WXWORD wParam, WXWORD pos, WXHWND control) wxOVERRIDE; + virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI) wxOVERRIDE; // handle processing of special keys void OnChar(wxKeyEvent& event); diff --git a/src/generic/spinctlg.cpp b/src/generic/spinctlg.cpp index feef3a6c5f..b49c5db77b 100644 --- a/src/generic/spinctlg.cpp +++ b/src/generic/spinctlg.cpp @@ -298,7 +298,14 @@ void wxSpinCtrlGenericBase::DoMoveWindow(int x, int y, int width, int height) wxControl::DoMoveWindow(x, y, width, height); // position the subcontrols inside the client area - wxSize sizeBtn = m_spinButton->GetSize(); + + // Use GetBestSize instead of GetSize to get the size of the spin control. + // This fixes a problem on wxMSW when the size is set after a DPI change. + // GetSize returns the old, invalid, size. GetBestSize will return the size + // that the control should be. Normally, GetBestSize and GetSize should + // always return the same value because the size of the spinButton never + // changes. + wxSize sizeBtn = m_spinButton->GetBestSize(); wxCoord wText = width - sizeBtn.x - MARGIN; m_textCtrl->SetSize(0, 0, wText, height); diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 6f1e8c7864..f76ad61968 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -223,6 +223,14 @@ void wxSpinCtrl::OnKillFocus(wxFocusEvent& event) event.Skip(); } +void wxSpinCtrl::MSWUpdateFontOnDPIChange(const wxSize& newDPI) +{ + wxSpinButton::MSWUpdateFontOnDPIChange(newDPI); + + if ( m_font.IsOk() ) + wxSetWindowFont(GetBuddyHwnd(), m_font); +} + void wxSpinCtrl::OnSetFocus(wxFocusEvent& event) { // when we get focus, give it to our buddy window as it needs it more than @@ -577,7 +585,8 @@ bool wxSpinCtrl::SetFont(const wxFont& font) return false; } - wxSetWindowFont(GetBuddyHwnd(), GetFont()); + if ( m_font.IsOk() ) + wxSetWindowFont(GetBuddyHwnd(), m_font); return true; }