]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix the size of the font returned from wxTextCtrl::GetStyle() in wxMSW.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 14 Jan 2012 17:57:11 +0000 (17:57 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 14 Jan 2012 17:57:11 +0000 (17:57 +0000)
Due to a typo the size was expressed in 1/10th of a point and not in points.
Fix this and add a unit test checking that GetStyle() returns the same font as
was set by SetStyle().

Closes #2120.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70341 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/msw/textctrl.cpp
tests/controls/textctrltest.cpp

index d9397e54b0a5c3da14d9ff1217778f416dc87a81..6722097017cb66f244d5d23db044962d70805859 100644 (file)
@@ -478,6 +478,7 @@ MSW:
 - Added support for wxEXEC_MAKE_GROUP_LEADER to wxExecute (tteras).
 - Set wxMenu being closed in wxEVT_MENU_CLOSE events (Marcin Malich).
 - Fix coordinates and Z-position for joystick events (Markus Juergens).
+- Fix size of the font returned by wxTextCtrl::GetStyle() (Igor Korot).
 
 OSX:
 
index d62b8ab16167afdab64993b4ba9d88a2921f4b40..ef2b7a898993abd3967f06ddd51521ac6b9aef60 100644 (file)
@@ -2744,7 +2744,7 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
     // Convert the height from the units of 1/20th of the point in which
     // CHARFORMAT stores it to pixel-based units used by LOGFONT.
     const wxCoord ppi = wxClientDC(this).GetPPI().y;
-    lf.lfHeight = -MulDiv(cf.yHeight/2, ppi, 72);
+    lf.lfHeight = -MulDiv(cf.yHeight/20, ppi, 72);
     lf.lfWidth = 0;
     lf.lfCharSet = ANSI_CHARSET; // FIXME: how to get correct charset?
     lf.lfClipPrecision = 0;
index 4ab4e82367150bd4b8d63ca24483521ae4c51b11..5836e68bc1b9b2a326d89a8981313cf13c02913e 100644 (file)
@@ -57,6 +57,7 @@ private:
         //WXUISIM_TEST( ProcessEnter );
         WXUISIM_TEST( Url );
         CPPUNIT_TEST( Style );
+        CPPUNIT_TEST( FontStyle );
         CPPUNIT_TEST( Lines );
         CPPUNIT_TEST( LogTextCtrl );
         CPPUNIT_TEST( PositionToCoords );
@@ -72,6 +73,7 @@ private:
     //void ProcessEnter();
     void Url();
     void Style();
+    void FontStyle();
     void Lines();
     void LogTextCtrl();
     void PositionToCoords();
@@ -386,6 +388,62 @@ void TextCtrlTestCase::Style()
 #endif
 }
 
+void TextCtrlTestCase::FontStyle()
+{
+    // We need wxTE_RICH under MSW and wxTE_MULTILINE under GTK for style
+    // support so recreate the control with these styles.
+    delete m_text;
+    m_text = new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "",
+                            wxDefaultPosition, wxDefaultSize,
+                            wxTE_MULTILINE | wxTE_RICH);
+
+    // Check that we get back the same font from GetStyle() after setting it
+    // with SetDefaultStyle().
+    wxFont fontIn(14,
+                  wxFONTFAMILY_DEFAULT,
+                  wxFONTSTYLE_NORMAL,
+                  wxFONTWEIGHT_NORMAL);
+    wxTextAttr attrIn;
+    attrIn.SetFont(fontIn);
+    if ( !m_text->SetDefaultStyle(attrIn) )
+    {
+        // Skip the test if the styles are not supported.
+        return;
+    }
+
+    m_text->AppendText("Default font size 14");
+
+    wxTextAttr attrOut;
+    m_text->GetStyle(5, attrOut);
+
+    CPPUNIT_ASSERT( attrOut.HasFont() );
+
+    wxFont fontOut = attrOut.GetFont();
+#ifdef __WXMSW__
+    // Under MSW we get back an encoding in the font even though we hadn't
+    // specified it originally. It's not really a problem but we need this hack
+    // to prevent the assert below from failing because of it.
+    fontOut.SetEncoding(fontIn.GetEncoding());
+#endif
+    CPPUNIT_ASSERT_EQUAL( fontIn, fontOut );
+
+
+    // Also check the same for SetStyle().
+    fontIn.SetPointSize(10);
+    fontIn.SetWeight(wxFONTWEIGHT_BOLD);
+    attrIn.SetFont(fontIn);
+    m_text->SetStyle(0, 6, attrIn);
+
+    m_text->GetStyle(4, attrOut);
+    CPPUNIT_ASSERT( attrOut.HasFont() );
+
+    fontOut = attrOut.GetFont();
+#ifdef __WXMSW__
+    fontOut.SetEncoding(fontIn.GetEncoding());
+#endif
+    CPPUNIT_ASSERT_EQUAL( fontIn, fontOut );
+}
+
 void TextCtrlTestCase::Lines()
 {
     delete m_text;