implemented Remove() and Replace() for GTK2 (patch 705051 from Nerijus)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19786 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-03-24 23:03:19 +00:00
parent 82ac3b0a42
commit 581ee8a9c5
3 changed files with 50 additions and 12 deletions

View File

@@ -482,3 +482,11 @@ Checking in src/msw/radiobut.cpp;
/pack/cvsroots/wxwindows/wxWindows/src/msw/radiobut.cpp,v <-- radiobut.cpp /pack/cvsroots/wxwindows/wxWindows/src/msw/radiobut.cpp,v <-- radiobut.cpp
new revision: 1.32; previous revision: 1.31 new revision: 1.32; previous revision: 1.31
42. Implement wxTextCtrl::Remove/Replace() for GTK2
http://sf.net/tracker/index.php?func=detail&aid=705051&group_id=9863&atid=309863
Checking in src/gtk/textctrl.cpp;
/pack/cvsroots/wxwindows/wxWindows/src/gtk/textctrl.cpp,v <-- textctrl.cpp
new revision: 1.154; previous revision: 1.153

View File

@@ -1078,29 +1078,44 @@ void wxTextCtrl::Remove( long from, long to )
{ {
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
#ifndef __WXGTK20__ #ifdef __WXGTK20__
gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); if ( m_windowStyle & wxTE_MULTILINE )
{
GtkTextBuffer *
text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) );
GtkTextIter fromi, toi;
gtk_text_buffer_get_iter_at_offset( text_buffer, &fromi, from );
gtk_text_buffer_get_iter_at_offset( text_buffer, &toi, to );
gtk_text_buffer_delete( text_buffer, &fromi, &toi );
}
else // single line
#endif #endif
gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
} }
void wxTextCtrl::Replace( long from, long to, const wxString &value ) void wxTextCtrl::Replace( long from, long to, const wxString &value )
{ {
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
#ifndef __WXGTK20__ Remove( from, to );
gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
if (!value.IsEmpty()) if (!value.IsEmpty())
{ {
#ifdef __WXGTK20__
SetInsertionPoint( from );
WriteText( value );
#else // GTK 1.x
gint pos = (gint)from; gint pos = (gint)from;
#if wxUSE_UNICODE #if wxUSE_UNICODE
wxWX2MBbuf buf = value.mbc_str(); wxWX2MBbuf buf = value.mbc_str();
gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &pos ); gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &pos );
#else #else
gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos ); gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos );
#endif #endif // wxUSE_UNICODE
#endif // GTK 1.x/2.x
} }
#endif
} }
void wxTextCtrl::Cut() void wxTextCtrl::Cut()

View File

@@ -1078,29 +1078,44 @@ void wxTextCtrl::Remove( long from, long to )
{ {
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
#ifndef __WXGTK20__ #ifdef __WXGTK20__
gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); if ( m_windowStyle & wxTE_MULTILINE )
{
GtkTextBuffer *
text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) );
GtkTextIter fromi, toi;
gtk_text_buffer_get_iter_at_offset( text_buffer, &fromi, from );
gtk_text_buffer_get_iter_at_offset( text_buffer, &toi, to );
gtk_text_buffer_delete( text_buffer, &fromi, &toi );
}
else // single line
#endif #endif
gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
} }
void wxTextCtrl::Replace( long from, long to, const wxString &value ) void wxTextCtrl::Replace( long from, long to, const wxString &value )
{ {
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
#ifndef __WXGTK20__ Remove( from, to );
gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
if (!value.IsEmpty()) if (!value.IsEmpty())
{ {
#ifdef __WXGTK20__
SetInsertionPoint( from );
WriteText( value );
#else // GTK 1.x
gint pos = (gint)from; gint pos = (gint)from;
#if wxUSE_UNICODE #if wxUSE_UNICODE
wxWX2MBbuf buf = value.mbc_str(); wxWX2MBbuf buf = value.mbc_str();
gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &pos ); gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &pos );
#else #else
gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos ); gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos );
#endif #endif // wxUSE_UNICODE
#endif // GTK 1.x/2.x
} }
#endif
} }
void wxTextCtrl::Cut() void wxTextCtrl::Cut()