Fix some crashes in new wxTextCtrl.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14915 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2002-04-02 19:40:57 +00:00
parent b70462f4f7
commit ee1797f141

View File

@ -269,30 +269,36 @@ void wxTextCtrl::SetValue(const wxString& value)
ClearSelection(); ClearSelection();
m_lines.Clear(); m_lines.Clear();
m_longestLine = 0; m_longestLine = 0;
int pos = 0; if (value.IsEmpty())
for (;;)
{ {
// TODO make more efficient m_lines.Add( new wxSourceLine( wxT("") ) );
wxString tmp = value; }
tmp.Remove( 0, pos ); else
pos = tmp.Find( '\n' ); {
if (pos == -1) int begin = 0;
int pos = 0;
for (;;)
{ {
if (tmp.Len() > m_longestLine) pos = value.find( wxT('\n'), begin );
m_longestLine = tmp.Len(); if (pos < 0)
{
m_lines.Add( new wxSourceLine( tmp ) ); if (value.Len()-begin > m_longestLine)
break; m_longestLine = value.Len()-begin;
m_lines.Add( new wxSourceLine( value.Mid( begin, value.Len()-begin ) ) );
} break;
else }
{ else
if (pos > m_longestLine) {
m_longestLine = pos; if (pos-begin > m_longestLine)
m_longestLine = pos-begin;
tmp.Remove( pos, tmp.Len()-pos ); m_lines.Add( new wxSourceLine( value.Mid( begin, pos-begin ) ) );
m_lines.Add( new wxSourceLine( tmp ) );
begin = pos+1;
}
} }
} }
@ -342,7 +348,10 @@ void wxTextCtrl::Clear()
m_cursorX = 0; m_cursorX = 0;
m_cursorY = 0; m_cursorY = 0;
ClearSelection(); ClearSelection();
m_lines.Clear(); m_lines.Clear();
m_lines.Add( new wxSourceLine( wxT("") ) );
SetScrollbars( m_charWidth, m_lineHeight, 0, 0, 0, 0 ); SetScrollbars( m_charWidth, m_lineHeight, 0, 0, 0, 0 );
Refresh(); Refresh();
m_undos.Clear(); m_undos.Clear();
@ -369,6 +378,8 @@ void wxTextCtrl::SetMaxLength(unsigned long len)
void wxTextCtrl::WriteText(const wxString& text2) void wxTextCtrl::WriteText(const wxString& text2)
{ {
if (text2.IsEmpty()) return;
m_modified = TRUE; m_modified = TRUE;
wxString text( text2 ); wxString text( text2 );
@ -423,16 +434,47 @@ void wxTextCtrl::WriteText(const wxString& text2)
} }
} }
void wxTextCtrl::AppendText(const wxString& text) void wxTextCtrl::AppendText(const wxString& text2)
{ {
// Leaves cursor garbage if (text2.IsEmpty()) return;
m_cursorY = m_lines.GetCount()-1; m_modified = TRUE;
m_cursorX = m_lines[m_cursorY].m_text.Len();
WriteText( text ); wxString text( text2 );
wxArrayString lines;
int pos;
while ( (pos = text.Find('\n')) != -1 )
{
lines.Add( text.Left( pos ) );
text.Remove( 0, pos+1 );
}
lines.Add( text );
int count = (int)lines.GetCount();
Refresh(); size_t y = m_lines.GetCount()-1;
wxString tmp( m_lines[y].m_text );
tmp.Append( lines[0] );
if (count == 1)
{
m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_LINE, y, y, this ) );
m_lines[y].m_text = tmp;
RefreshLine( y );
}
else
{
m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_PASTE, y, y+count-1, this ) );
m_lines[y].m_text = tmp;
int i;
for (i = 1; i < count; i++)
m_lines.Insert( new wxSourceLine( lines[i] ), y+i );
MyAdjustScrollbars();
RefreshDown( y );
}
} }
bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)