ClearSelection();
m_lines.Clear();
m_longestLine = 0;
-
- int pos = 0;
- for (;;)
+
+ if (value.IsEmpty())
+ {
+ m_lines.Add( new wxSourceLine( wxT("") ) );
+ }
+ else
{
- // TODO make more efficient
- wxString tmp = value;
- tmp.Remove( 0, pos );
- pos = tmp.Find( '\n' );
- if (pos == -1)
+ int begin = 0;
+ int pos = 0;
+ for (;;)
{
- if (tmp.Len() > m_longestLine)
- m_longestLine = tmp.Len();
-
- m_lines.Add( new wxSourceLine( tmp ) );
- break;
+ pos = value.find( wxT('\n'), begin );
+ if (pos < 0)
+ {
+ if (value.Len()-begin > m_longestLine)
+ m_longestLine = value.Len()-begin;
+
+ m_lines.Add( new wxSourceLine( value.Mid( begin, value.Len()-begin ) ) );
- }
- else
- {
- if (pos > m_longestLine)
- m_longestLine = pos;
+ break;
+ }
+ else
+ {
+ if (pos-begin > m_longestLine)
+ m_longestLine = pos-begin;
- tmp.Remove( pos, tmp.Len()-pos );
- m_lines.Add( new wxSourceLine( tmp ) );
+ m_lines.Add( new wxSourceLine( value.Mid( begin, pos-begin ) ) );
+
+ begin = pos+1;
+ }
}
}
m_cursorX = 0;
m_cursorY = 0;
ClearSelection();
+
m_lines.Clear();
+ m_lines.Add( new wxSourceLine( wxT("") ) );
+
SetScrollbars( m_charWidth, m_lineHeight, 0, 0, 0, 0 );
Refresh();
m_undos.Clear();
void wxTextCtrl::WriteText(const wxString& text2)
{
+ if (text2.IsEmpty()) return;
+
m_modified = TRUE;
wxString text( 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_cursorX = m_lines[m_cursorY].m_text.Len();
+ m_modified = TRUE;
+
+ 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();
- WriteText( text );
+ size_t y = m_lines.GetCount()-1;
+
+ wxString tmp( m_lines[y].m_text );
+ tmp.Append( lines[0] );
- Refresh();
+ 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)