diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index 294c693e83..8c68f743c7 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -5333,7 +5333,14 @@ public: // implement wxTextAreaBase pure virtual methods // --------------------------------------------- - virtual int GetLineLength(long lineNo) const wxOVERRIDE { return static_cast(GetLineText(lineNo).length()); } + virtual int GetLineLength(long lineNo) const wxOVERRIDE + { + if ( lineNo < 0 || lineNo >= GetNumberOfLines() ) + return -1; + + return static_cast(GetLineText(lineNo).length()); + } + virtual wxString GetLineText(long lineNo) const wxOVERRIDE { wxString text = GetLine(static_cast(lineNo)); diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index fed5741b58..dadb293c2a 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -1803,6 +1803,9 @@ int wxTextCtrl::GetLineLength(long lineNo) const { long pos = XYToPosition(0, lineNo); + if ( pos == -1 ) + return -1; + return GetLengthOfLineContainingPos(pos); } diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 2eeea31854..c00e462ae4 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -776,7 +776,7 @@ int wxTextWidgetImpl::GetLineLength(long lineNo) const count++; } - return 0 ; + return -1 ; } void wxTextWidgetImpl::SetJustification() diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index 5fdc401d75..593b5dce88 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -450,7 +450,14 @@ public: // implement wxTextAreaBase pure virtual methods // --------------------------------------------- - virtual int GetLineLength(long lineNo) const wxOVERRIDE { return static_cast(GetLineText(lineNo).length()); } + virtual int GetLineLength(long lineNo) const wxOVERRIDE + { + if ( lineNo < 0 || lineNo >= GetNumberOfLines() ) + return -1; + + return static_cast(GetLineText(lineNo).length()); + } + virtual wxString GetLineText(long lineNo) const wxOVERRIDE { wxString text = GetLine(static_cast(lineNo)); diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index 51aa4bc903..0b71630f4c 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -1684,8 +1684,8 @@ int wxTextCtrl::GetLineLength(wxTextCoord line) const } else // multiline { - wxCHECK_MSG( (size_t)line < GetLineCount(), -1, - wxT("line index out of range") ); + if ( line < 0 || line >= GetLineCount() ) + return -1; return GetLines()[line].length(); } diff --git a/src/x11/textctrl.cpp b/src/x11/textctrl.cpp index 4c1473baa6..4c65e0cc8f 100644 --- a/src/x11/textctrl.cpp +++ b/src/x11/textctrl.cpp @@ -347,8 +347,8 @@ void wxTextCtrl::DoSetValue(const wxString& value, int flags) int wxTextCtrl::GetLineLength(long lineNo) const { - if (lineNo >= (long)m_lines.GetCount()) - return 0; + if (lineNo < 0 || lineNo >= (long)m_lines.GetCount()) + return -1; return m_lines[lineNo].m_text.Len(); }