X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e808cf8a0a77ced81143e9b27283a3b2a907a747..b85db900cdc04cd70dfa940c7d99469f7f4c2b41:/src/gtk/textctrl.cpp?ds=sidebyside diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 79cdce6465..0638f5c1fa 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -448,9 +448,7 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win ) if ( win->MarkDirtyOnChange() ) win->MarkDirty(); - wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() ); - event.SetEventObject( win ); - win->GetEventHandler()->ProcessEvent( event ); + win->SendTextUpdatedEvent(); } } @@ -544,9 +542,10 @@ END_EVENT_TABLE() void wxTextCtrl::Init() { m_dontMarkDirty = - m_ignoreNextUpdate = m_modified = false; + m_countUpdatesToIgnore = 0; + SetUpdateFont(false); m_text = NULL; @@ -820,7 +819,15 @@ wxFontEncoding wxTextCtrl::GetTextEncoding() const return enc; } -void wxTextCtrl::SetValue( const wxString &value ) +bool wxTextCtrl::IsEmpty() const +{ + if ( IsMultiLine() ) + return gtk_text_buffer_get_char_count(m_buffer) != 0; + + return wxTextCtrlBase::IsEmpty(); +} + +void wxTextCtrl::DoSetValue( const wxString &value, int flags ) { wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); @@ -831,31 +838,31 @@ void wxTextCtrl::SetValue( const wxString &value ) m_modified = false; DontMarkDirtyOnNextChange(); - if ( IsMultiLine() ) + const wxCharBuffer buffer(wxGTK_CONV_ENC(value, GetTextEncoding())); + if ( !buffer ) { - const wxCharBuffer buffer(wxGTK_CONV_ENC(value, GetTextEncoding())); - if ( !buffer ) - { - // see comment in WriteText() as to why we must warn the user about - // this - wxLogWarning(_("Failed to set text in the text control.")); - return; - } + // see comment in WriteText() as to why we must warn the user about + // this + wxLogWarning(_("Failed to set text in the text control.")); + return; + } - if (gtk_text_buffer_get_char_count(m_buffer) != 0) - IgnoreNextTextUpdate(); + // 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); + + if ( IsMultiLine() ) + { gtk_text_buffer_set_text( m_buffer, buffer, strlen(buffer) ); } else // single line { - // gtk_entry_set_text() emits two "changed" signals if the control is - // not empty because internally it calls gtk_editable_delete_text() and - // gtk_editable_insert_text() but we want to have only one event - if ( !GetValue().empty() ) - IgnoreNextTextUpdate(); - - gtk_entry_set_text( GTK_ENTRY(m_text), wxGTK_CONV(value) ); + gtk_entry_set_text( GTK_ENTRY(m_text), buffer ); } // GRG, Jun/2000: Changed this after a lot of discussion in @@ -1178,9 +1185,9 @@ void wxTextCtrl::DiscardEdits() bool wxTextCtrl::IgnoreTextUpdate() { - if ( m_ignoreNextUpdate ) + if ( m_countUpdatesToIgnore > 0 ) { - m_ignoreNextUpdate = false; + m_countUpdatesToIgnore--; return true; }