X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/81c882b613b5d99ddb1e5ab69fcd7ebccc287025..4c0d2cd3d0c59bf0114e0e10355bff86ddb116a0:/src/gtk/textctrl.cpp diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 295f3bfbec..1b08ecc0a8 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -10,6 +10,8 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" +#if wxUSE_TEXTCTRL + #include "wx/textctrl.h" #ifndef WX_PRECOMP @@ -428,7 +430,7 @@ au_check_word( GtkTextIter *s, GtkTextIter *e ) gtk_text_iter_backward_find_char( &end, pred_nonpunct_or_slash, NULL, &start ); gtk_text_iter_forward_char(&end); - gchar* text = gtk_text_iter_get_text( &start, &end ); + wxGtkString text(gtk_text_iter_get_text( &start, &end )); size_t len = strlen(text), prefix_len; size_t n; @@ -757,6 +759,18 @@ bool wxTextCtrl::Create( wxWindow *parent, gtk_widget_show(m_text); } + // We want to be notified about text changes. + if (multi_line) + { + g_signal_connect (m_buffer, "changed", + G_CALLBACK (gtk_text_changed_callback), this); + } + else + { + g_signal_connect (m_text, "changed", + G_CALLBACK (gtk_text_changed_callback), this); + } + if (!value.empty()) { SetValue( value ); @@ -772,13 +786,9 @@ bool wxTextCtrl::Create( wxWindow *parent, if ( style & (wxTE_RIGHT | wxTE_CENTRE) ) GTKSetJustification(); - // We want to be notified about text changes. if (multi_line) { - g_signal_connect (m_buffer, "changed", - G_CALLBACK (gtk_text_changed_callback), this); - - // .. and handle URLs on multi-line controls with wxTE_AUTO_URL style + // Handle URLs on multi-line controls with wxTE_AUTO_URL style if (style & wxTE_AUTO_URL) { GtkTextIter start, end; @@ -814,12 +824,7 @@ bool wxTextCtrl::Create( wxWindow *parent, au_check_range(&start, &end); } } - else - { - g_signal_connect (m_text, "changed", - G_CALLBACK (gtk_text_changed_callback), this); - } - + g_signal_connect (m_text, "copy-clipboard", G_CALLBACK (gtk_copy_clipboard_callback), this); g_signal_connect (m_text, "cut-clipboard", @@ -996,12 +1001,7 @@ void wxTextCtrl::DoSetValue( const wxString &value, int flags ) { wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); - // the control won't be modified any more as we programmatically replace - // all the existing text, so reset the flag and don't set it again (and do - // it now, before the text event handler is ran so that IsModified() called - // from there returns the expected value) m_modified = false; - DontMarkDirtyOnNextChange(); wxFontEncoding enc = m_defaultStyle.HasFont() ? m_defaultStyle.GetFont().GetEncoding() @@ -1018,19 +1018,13 @@ void wxTextCtrl::DoSetValue( const wxString &value, int flags ) return; } - // if the control is not empty, two "changed" signals are emitted, - // otherwise only one and we need to ignore either both or one of them - int ignore = flags & SetValue_SendEvent ? 0 : 1; - if ( !IsEmpty() ) - ignore++; - - if ( ignore ) - IgnoreNextTextUpdate(ignore); - + void* blockWidget = IsMultiLine() ? (void*)m_buffer : (void*)m_text; + g_signal_handlers_block_by_func(blockWidget, + (gpointer)gtk_text_changed_callback, this); if ( IsMultiLine() ) { gtk_text_buffer_set_text( m_buffer, buffer, strlen(buffer) ); - + if ( !m_defaultStyle.IsDefault() ) { GtkTextIter start, end; @@ -1039,20 +1033,14 @@ void wxTextCtrl::DoSetValue( const wxString &value, int flags ) &start, &end); } } - else // single line + else { gtk_entry_set_text( GTK_ENTRY(m_text), buffer ); } - - // if, for whatever reason, the callback wasn't called the expected number - // of times, still reset the flags to the default values - m_dontMarkDirty = false; - m_countUpdatesToIgnore = 0; - - - // GRG, Jun/2000: Changed this after a lot of discussion in - // the lists. wxWidgets 2.2 will have a set of flags to - // customize this behaviour. + g_signal_handlers_unblock_by_func(blockWidget, + (gpointer)gtk_text_changed_callback, this); + + // This was added after discussion on the list SetInsertionPoint(0); } @@ -2003,3 +1991,5 @@ wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) { return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true); } + +#endif // wxUSE_TEXTCTRL