]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix setting the fonts for wxMSW wxTextCtrl with wxTE_RICH(2) style.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 25 May 2010 21:15:24 +0000 (21:15 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 25 May 2010 21:15:24 +0000 (21:15 +0000)
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
src/msw/textctrl.cpp

index 5354104c74d6b488380a50ad3a3e9fc4b7e8bfec..ee8d91971fbec594a708978a72856cd8f8263ae3 100644 (file)
@@ -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 weust 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
index d5e40992c3183f0764356e7e6cda7de356993b6d..d9376ed7564521ae0317cf433f6ad177b8b88ab9 100644 (file)
@@ -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
 // ----------------------------------------------------------------------------