Delete the selection before inserting text in WriteText. Also, fix

bug in repositioning of the caret after the insertion.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17252 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2002-09-18 18:47:39 +00:00
parent 8c2d31e9f3
commit 702fe1fccf
2 changed files with 10 additions and 6 deletions

View File

@@ -552,6 +552,7 @@ void wxTextCtrl::WriteText( const wxString &text )
wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ) );
#endif
GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) );
// TODO: call wahtever is needed to delete the selection
gtk_text_buffer_insert_at_cursor( text_buffer, buffer, strlen(buffer) );
#else // GTK 1.x
@@ -561,6 +562,7 @@ void wxTextCtrl::WriteText( const wxString &text )
// always use m_defaultStyle, even if it is empty as otherwise
// resetting the style and appending some more text wouldn't work: if
// we don't specify the style explicitly, the old style would be used
gtk_editable_delete_selection( GTK_EDITABLE(m_text) );
wxGtkTextInsert(m_text, m_defaultStyle, text.c_str(), text.Len());
// Bring editable's cursor back uptodate.
@@ -569,6 +571,9 @@ void wxTextCtrl::WriteText( const wxString &text )
}
else // single line
{
// First remove the selection if there is one
gtk_editable_delete_selection( GTK_EDITABLE(m_text) );
// This moves the cursor pos to behind the inserted text.
gint len = GET_EDITABLE_POS(m_text);
@@ -585,9 +590,6 @@ void wxTextCtrl::WriteText( const wxString &text )
gtk_editable_insert_text( GTK_EDITABLE(m_text), text.c_str(), text.Len(), &len );
#endif
// Bring editable's cursor uptodate.
len += text.Len();
// Bring entry's cursor uptodate.
gtk_entry_set_position( GTK_ENTRY(m_text), len );
}

View File

@@ -552,6 +552,7 @@ void wxTextCtrl::WriteText( const wxString &text )
wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ) );
#endif
GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) );
// TODO: call wahtever is needed to delete the selection
gtk_text_buffer_insert_at_cursor( text_buffer, buffer, strlen(buffer) );
#else // GTK 1.x
@@ -561,6 +562,7 @@ void wxTextCtrl::WriteText( const wxString &text )
// always use m_defaultStyle, even if it is empty as otherwise
// resetting the style and appending some more text wouldn't work: if
// we don't specify the style explicitly, the old style would be used
gtk_editable_delete_selection( GTK_EDITABLE(m_text) );
wxGtkTextInsert(m_text, m_defaultStyle, text.c_str(), text.Len());
// Bring editable's cursor back uptodate.
@@ -569,6 +571,9 @@ void wxTextCtrl::WriteText( const wxString &text )
}
else // single line
{
// First remove the selection if there is one
gtk_editable_delete_selection( GTK_EDITABLE(m_text) );
// This moves the cursor pos to behind the inserted text.
gint len = GET_EDITABLE_POS(m_text);
@@ -585,9 +590,6 @@ void wxTextCtrl::WriteText( const wxString &text )
gtk_editable_insert_text( GTK_EDITABLE(m_text), text.c_str(), text.Len(), &len );
#endif
// Bring editable's cursor uptodate.
len += text.Len();
// Bring entry's cursor uptodate.
gtk_entry_set_position( GTK_ENTRY(m_text), len );
}