+ m_text->AppendText("blue on grey");
+
+ // Get getting the style at a specific location
+ wxTextAttr style;
+
+ // We have to check that styles are supported
+ if(m_text->GetStyle(3, style))
+ {
+ CPPUNIT_ASSERT_EQUAL(style.GetTextColour(), *wxRED);
+ CPPUNIT_ASSERT_EQUAL(style.GetBackgroundColour(), *wxWHITE);
+ }
+
+ // And then setting the style
+ if(m_text->SetStyle(15, 18, style))
+ {
+ m_text->GetStyle(17, style);
+
+ CPPUNIT_ASSERT_EQUAL(style.GetTextColour(), *wxRED);
+ CPPUNIT_ASSERT_EQUAL(style.GetBackgroundColour(), *wxWHITE);
+ }
+#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;
+ CreateText(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()
+{
+ m_text->SetValue("line1\nline2\nlong long line 3");
+ m_text->Refresh();
+ m_text->Update();
+
+ CPPUNIT_ASSERT_EQUAL(3, m_text->GetNumberOfLines());
+ CPPUNIT_ASSERT_EQUAL(5, m_text->GetLineLength(0));
+ CPPUNIT_ASSERT_EQUAL("line2", m_text->GetLineText(1));
+ CPPUNIT_ASSERT_EQUAL(16, m_text->GetLineLength(2));
+
+ m_text->AppendText("\n\nMore text on line 5");
+
+ CPPUNIT_ASSERT_EQUAL(5, m_text->GetNumberOfLines());
+ CPPUNIT_ASSERT_EQUAL(0, m_text->GetLineLength(3));
+ CPPUNIT_ASSERT_EQUAL("", m_text->GetLineText(3));
+
+ // Verify that wrapped lines count as 2 lines.
+ //
+ // This currently doesn't work neither in wxGTK nor wxOSX/Cocoa, see
+ // #12366, where GetNumberOfLines() always returns the number of logical,
+ // not physical, lines.
+ m_text->AppendText("\n" + wxString(50, '1') + ' ' + wxString(50, '2'));
+#if defined(__WXGTK__) || defined(__WXOSX_COCOA__)
+ CPPUNIT_ASSERT_EQUAL(6, m_text->GetNumberOfLines());
+#else
+ CPPUNIT_ASSERT_EQUAL(7, m_text->GetNumberOfLines());
+#endif
+}
+
+void TextCtrlTestCase::LogTextCtrl()
+{
+ CPPUNIT_ASSERT(m_text->IsEmpty());
+
+ wxLogTextCtrl* logtext = new wxLogTextCtrl(m_text);
+
+ wxLog* old = wxLog::SetActiveTarget(logtext);
+
+ logtext->LogText("text");
+
+ delete wxLog::SetActiveTarget(old);
+
+ CPPUNIT_ASSERT(!m_text->IsEmpty());
+}
+
+void TextCtrlTestCase::PositionToCoords()
+{
+ DoPositionToCoordsTestWithStyle(0);
+}
+
+void TextCtrlTestCase::PositionToCoordsRich()
+{
+ DoPositionToCoordsTestWithStyle(wxTE_RICH);
+}
+
+void TextCtrlTestCase::PositionToCoordsRich2()
+{
+ DoPositionToCoordsTestWithStyle(wxTE_RICH2);
+}
+
+void TextCtrlTestCase::DoPositionToCoordsTestWithStyle(long style)
+{
+ delete m_text;
+ CreateText(style);
+
+ // Asking for invalid index should fail.
+ WX_ASSERT_FAILS_WITH_ASSERT( m_text->PositionToCoords(1) );
+
+ // Getting position shouldn't return wxDefaultPosition except if the method
+ // is not implemented at all in the current port.
+ const wxPoint pos0 = m_text->PositionToCoords(0);
+ if ( pos0 == wxDefaultPosition )
+ {
+#if defined(__WXMSW__) || defined(__WXGTK20__)
+ CPPUNIT_FAIL( "PositionToCoords() unexpectedly failed." );
+#endif
+ return;
+ }
+
+ CPPUNIT_ASSERT(pos0.x >= 0);
+ CPPUNIT_ASSERT(pos0.y >= 0);
+
+
+ m_text->SetValue("Hello");
+ wxYield(); // Let GTK layout the control correctly.
+
+ // Position of non-first character should be positive.
+ const long posHello4 = m_text->PositionToCoords(4).x;
+ CPPUNIT_ASSERT( posHello4 > 0 );
+
+ // Asking for position beyond the last character should succeed and return
+ // reasonable result.
+ CPPUNIT_ASSERT( m_text->PositionToCoords(5).x > posHello4 );
+
+ // But asking for the next position should fail.
+ WX_ASSERT_FAILS_WITH_ASSERT( m_text->PositionToCoords(6) );
+
+ // Test getting the coordinates of the last character when it is in the
+ // beginning of a new line to exercise MSW code which has specific logic
+ // for it.
+ m_text->AppendText("\n");
+ const wxPoint posLast = m_text->PositionToCoords(m_text->GetLastPosition());
+ CPPUNIT_ASSERT_EQUAL( pos0.x, posLast.x );
+ CPPUNIT_ASSERT( posLast.y > 0 );
+
+
+ // Add enough contents to the control to make sure it has a scrollbar.
+ m_text->SetValue("First line" + wxString(50, '\n') + "Last line");