diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index 6dfd914320..422a703e5a 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -1197,19 +1197,15 @@ public: /** Returns the number of lines in the text control buffer. + The returned number is the number of logical lines, i.e. just the count + of the number of newline characters in the control + 1, for wxGTK and + wxOSX/Cocoa ports while it is the number of physical lines, i.e. the + count of lines actually shown in the control, in wxMSW and wxOSX/Carbon. + Because of this discrepancy, it is not recommended to use this function. + @remarks Note that even empty text controls have one line (where the insertion point is), so GetNumberOfLines() never returns 0. - For wxGTK using GTK+ 1.2.x and earlier, the number of lines in a - multi-line text control is calculated by actually counting newline - characters in the buffer, i.e. this function returns the number of - logical lines and doesn't depend on whether any of them are wrapped. - For all the other platforms, the number of physical lines in the - control is returned. - Also note that you may wish to avoid using functions that work with - line numbers if you are working with controls that contain large - amounts of text as this function has O(N) complexity for N being - the number of lines. */ virtual int GetNumberOfLines() const; diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index 86f0fbee7a..1c001d3ac2 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -388,7 +388,6 @@ void TextCtrlTestCase::Style() void TextCtrlTestCase::Lines() { -#ifndef __WXOSX__ delete m_text; m_text = new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "", wxDefaultPosition, wxSize(400, 200), wxTE_MULTILINE | wxTE_DONTWRAP); @@ -407,6 +406,17 @@ void TextCtrlTestCase::Lines() 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 }