X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c04ec4965704643f498999fb5123e63330a3ee50..82a16d7e5e5c83e95a4caa7314de2dbfbd1debdc:/src/gtk1/textctrl.cpp?ds=sidebyside diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 4f48c8f5cd..023debbdb1 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -518,7 +518,8 @@ wxString wxTextCtrl::GetValue() const #else wxCharBuffer buffer( wxConvLocal.cWC2WX( wxConvUTF8.cMB2WC( text ) ) ); #endif - tmp = buffer; + if ( buffer ) + tmp = buffer; g_free( text ); #else @@ -550,6 +551,9 @@ void wxTextCtrl::SetValue( const wxString &value ) wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( value ) ) ); #endif GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) ); + if (gtk_text_buffer_get_char_count(text_buffer) != 0) + IgnoreNextTextUpdate(); + gtk_text_buffer_set_text( text_buffer, buffer, strlen(buffer) ); #else @@ -593,6 +597,12 @@ void wxTextCtrl::WriteText( const wxString &text ) #else wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ) ); #endif + if ( !buffer ) + { + // what else can we do? at least don't crash... + return; + } + GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) ); // TODO: Call whatever is needed to delete the selection. @@ -815,14 +825,19 @@ void wxTextCtrl::SetInsertionPoint( long pos ) { wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); - if (m_windowStyle & wxTE_MULTILINE) + if ( IsMultiLine() ) { #ifdef __WXGTK20__ GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) ); GtkTextIter iter; gtk_text_buffer_get_iter_at_offset( text_buffer, &iter, pos ); gtk_text_buffer_place_cursor( text_buffer, &iter ); -#else + gtk_text_view_scroll_mark_onscreen + ( + GTK_TEXT_VIEW(m_text), + gtk_text_buffer_get_insert( text_buffer ) + ); +#else // GTK+ 1.x gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); @@ -839,7 +854,7 @@ void wxTextCtrl::SetInsertionPoint( long pos ) // bring editable's cursor uptodate. Bug in GTK. SET_EDITABLE_POS(m_text, gtk_text_get_point( GTK_TEXT(m_text) )); -#endif +#endif // GTK+ 2/1 } else { @@ -1424,12 +1439,14 @@ void wxTextCtrl::ChangeFontGlobally() // possible! // // TODO: it can be implemented much more efficiently for GTK2 - wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE) #ifndef __WXGTK20__ - && m_updateFont -#endif // GTK+ 1.x - , + wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE) && m_updateFont, + + _T("shouldn't be called for single line controls") ); +#else + wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE), _T("shouldn't be called for single line controls") ); +#endif wxString value = GetValue(); if ( !value.IsEmpty() ) @@ -1469,8 +1486,10 @@ bool wxTextCtrl::SetBackgroundColour( const wxColour &colour ) if ( !wxControl::SetBackgroundColour( colour ) ) return FALSE; +#ifndef __WXGTK20__ if (!m_widget->window) return FALSE; +#endif if (!m_backgroundColour.Ok()) return FALSE; @@ -1718,16 +1737,18 @@ void wxTextCtrl::Thaw() GtkAdjustment *wxTextCtrl::GetVAdj() const { + if ( !IsMultiLine() ) + return NULL; + #ifdef __WXGTK20__ - return NULL; + return gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(m_widget)); #else - return HasFlag(wxTE_MULTILINE) ? GTK_TEXT(m_text)->vadj : NULL; + return GTK_TEXT(m_text)->vadj; #endif } bool wxTextCtrl::DoScroll(GtkAdjustment *adj, int diff) { -#ifndef __WXGTK20__ float value = adj->value + diff; if ( value < 0 ) @@ -1746,39 +1767,38 @@ bool wxTextCtrl::DoScroll(GtkAdjustment *adj, int diff) adj->value = value; +#ifdef __WXGTK20__ + gtk_adjustment_value_changed(GTK_ADJUSTMENT(adj)); +#else gtk_signal_emit_by_name(GTK_OBJECT(adj), "value_changed"); - #endif + return TRUE; } bool wxTextCtrl::ScrollLines(int lines) { -#ifdef __WXGTK20__ - return FALSE; -#else GtkAdjustment *adj = GetVAdj(); if ( !adj ) return FALSE; +#ifdef __WXGTK20__ + int diff = (int)ceil(lines*adj->step_increment); +#else // this is hardcoded to 10 in GTK+ 1.2 (great idea) - static const int KEY_SCROLL_PIXELS = 10; - - return DoScroll(adj, lines*KEY_SCROLL_PIXELS); + int diff = 10*lines; #endif + + return DoScroll(adj, diff); } bool wxTextCtrl::ScrollPages(int pages) { -#ifdef __WXGTK20__ - return FALSE; -#else GtkAdjustment *adj = GetVAdj(); if ( !adj ) return FALSE; return DoScroll(adj, (int)ceil(pages*adj->page_increment)); -#endif }