Return -1 from GetLineLength() if line number is out of range
Make wxTextCtrl behaviour in all ports consistent with the documentation and also update wxStyledTextCtrl to behave accordingly. Closes #18431.
This commit is contained in:
committed by
Vadim Zeitlin
parent
6e556d4a71
commit
c3ce5244e3
@@ -5333,7 +5333,14 @@ public:
|
||||
// implement wxTextAreaBase pure virtual methods
|
||||
// ---------------------------------------------
|
||||
|
||||
virtual int GetLineLength(long lineNo) const wxOVERRIDE { return static_cast<int>(GetLineText(lineNo).length()); }
|
||||
virtual int GetLineLength(long lineNo) const wxOVERRIDE
|
||||
{
|
||||
if ( lineNo < 0 || lineNo >= GetNumberOfLines() )
|
||||
return -1;
|
||||
|
||||
return static_cast<int>(GetLineText(lineNo).length());
|
||||
}
|
||||
|
||||
virtual wxString GetLineText(long lineNo) const wxOVERRIDE
|
||||
{
|
||||
wxString text = GetLine(static_cast<int>(lineNo));
|
||||
|
@@ -1803,6 +1803,9 @@ int wxTextCtrl::GetLineLength(long lineNo) const
|
||||
{
|
||||
long pos = XYToPosition(0, lineNo);
|
||||
|
||||
if ( pos == -1 )
|
||||
return -1;
|
||||
|
||||
return GetLengthOfLineContainingPos(pos);
|
||||
}
|
||||
|
||||
|
@@ -776,7 +776,7 @@ int wxTextWidgetImpl::GetLineLength(long lineNo) const
|
||||
count++;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
void wxTextWidgetImpl::SetJustification()
|
||||
|
@@ -450,7 +450,14 @@ public:
|
||||
// implement wxTextAreaBase pure virtual methods
|
||||
// ---------------------------------------------
|
||||
|
||||
virtual int GetLineLength(long lineNo) const wxOVERRIDE { return static_cast<int>(GetLineText(lineNo).length()); }
|
||||
virtual int GetLineLength(long lineNo) const wxOVERRIDE
|
||||
{
|
||||
if ( lineNo < 0 || lineNo >= GetNumberOfLines() )
|
||||
return -1;
|
||||
|
||||
return static_cast<int>(GetLineText(lineNo).length());
|
||||
}
|
||||
|
||||
virtual wxString GetLineText(long lineNo) const wxOVERRIDE
|
||||
{
|
||||
wxString text = GetLine(static_cast<int>(lineNo));
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user