From 81fb185e4f837355335c4c8831e1a0c1a1bd1334 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 May 2010 21:15:24 +0000 Subject: [PATCH] Fix setting the fonts for wxMSW wxTextCtrl with wxTE_RICH(2) style. Using WM_SETFONT seemed to work with rich edit controls but in fact it doesn't, it only changes the font used by the control initially apparently but it can be reset later. Use EM_SETCHARFORMAT which is more reliable. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64394 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/textctrl.h | 5 +++-- src/msw/textctrl.cpp | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 5354104c74..ee8d91971f 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -125,10 +125,11 @@ public: int GetRichVersion() const { return m_verRichEdit; } bool IsRich() const { return m_verRichEdit != 0; } - // rich edit controls are not compatible with normal ones and wem ust set - // the colours for them otherwise + // rich edit controls are not compatible with normal ones and we must set + // the colours and font for them otherwise virtual bool SetBackgroundColour(const wxColour& colour); virtual bool SetForegroundColour(const wxColour& colour); + virtual bool SetFont(const wxFont& font); #else bool IsRich() const { return false; } #endif // wxUSE_RICHEDIT diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index d5e40992c3..d9376ed756 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -2360,6 +2360,26 @@ bool wxTextCtrl::SetForegroundColour(const wxColour& colour) return true; } +bool wxTextCtrl::SetFont(const wxFont& font) +{ + if ( !wxTextCtrlBase::SetFont(font) ) + return false; + + if ( IsRich() ) + { + // Using WM_SETFONT doesn't work reliably with rich edit controls: as + // an example, if we set a fixed width font for a richedit 4.1 control, + // it's used for the ASCII characters but inserting any non-ASCII ones + // switches the font to a proportional one, whether it's done + // programmatically or not. So just use EM_SETCHARFORMAT for this too. + wxTextAttr attr; + attr.SetFont(font); + SetDefaultStyle(attr); + } + + return true; +} + // ---------------------------------------------------------------------------- // styling support for rich edit controls // ---------------------------------------------------------------------------- -- 2.45.2