From 37be4adec6c4d88289477912f05efb7e3b30f51f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 31 Dec 2018 01:52:12 +0100 Subject: [PATCH] Don't change RICHEDIT control font on DPI change The control seems to somehow react to DPI changes on its own (which is rather mysterious as we don't forward WM_DPICHANGED to it, so it's not really clear how does it do it, but it does) and changing its font is worse than useless, as it's not just redundant, but also resets all the styles used inside the control and so is really undesirable. Hence override the just added MSWUpdateFontOnDPIChange() to do nothing for rich edit controls, while still updating the font for the plain EDIT ones (which is required as they don't scale correctly on their own). --- include/wx/msw/textctrl.h | 2 ++ src/msw/textctrl.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 5ef3128a7c..f7be3725be 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -240,6 +240,8 @@ protected: virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const wxOVERRIDE; #if wxUSE_RICHEDIT + virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI) wxOVERRIDE; + // Apply the character-related parts of wxTextAttr to the given selection // or the entire control if start == end == -1. // diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 7b138bc75f..9118db73bd 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -2633,6 +2633,16 @@ wxMenu *wxTextCtrl::MSWCreateContextMenu() return m; } +void wxTextCtrl::MSWUpdateFontOnDPIChange(const wxSize& newDPI) +{ + // Don't do anything for the rich edit controls, they (somehow?) update + // their appearance on their own and changing their HFONT, as the base + // class version does, would reset all the styles used by them when the DPI + // changes, which is unwanted. + if ( !IsRich() ) + wxTextCtrlBase::MSWUpdateFontOnDPIChange(newDPI); +} + // ---------------------------------------------------------------------------- // EN_LINK processing // ----------------------------------------------------------------------------