From: Vadim Zeitlin Date: Wed, 17 May 2006 00:20:20 +0000 (+0000) Subject: make sure that IsModified() returns false when it's called from EVT_TEXT handler... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6964cbbac953c53157236e81c251f0228ac6b051 make sure that IsModified() returns false when it's called from EVT_TEXT handler invoked because of SetValue() call git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39172 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 26b6e3e8e4..b9b793eb19 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -157,11 +157,19 @@ public: virtual void OnParentEnable( bool enable ) ; // tell the control to ignore next text changed signal - void IgnoreNextTextUpdate(); + void IgnoreNextTextUpdate() { m_ignoreNextUpdate = true; } // should we ignore the changed signal? always resets the flag bool IgnoreTextUpdate(); + // call this to indicate that the control is about to be changed + // programmatically and so m_modified flag shouldn't be set + void DontMarkDirtyOnNextChange() { m_dontMarkDirty = true; } + + // should we mark the control as dirty? always resets the flag + bool MarkDirtyOnChange(); + + static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); @@ -187,6 +195,7 @@ private: bool m_modified:1; bool m_ignoreNextUpdate:1; + bool m_dontMarkDirty:1; // Our text buffer. Convenient, and holds the buffer while using // a dummy one when m_frozenness > 0 diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 9211dde77c..40329ca9fa 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -454,7 +454,8 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win ) if (g_isIdle) wxapp_install_idle_handler(); - win->MarkDirty(); + if ( win->MarkDirtyOnChange() ) + win->MarkDirty(); wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() ); event.SetEventObject( win ); @@ -551,9 +552,12 @@ END_EVENT_TABLE() void wxTextCtrl::Init() { + m_dontMarkDirty = m_ignoreNextUpdate = m_modified = false; + SetUpdateFont(false); + m_text = NULL; m_frozenness = 0; m_gdkHandCursor = NULL; @@ -812,6 +816,13 @@ void wxTextCtrl::SetValue( const wxString &value ) { 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(); + if (m_windowStyle & wxTE_MULTILINE) { const wxCharBuffer buffer(wxGTK_CONV(value)); @@ -840,8 +851,6 @@ void wxTextCtrl::SetValue( const wxString &value ) // the lists. wxWidgets 2.2 will have a set of flags to // customize this behaviour. SetInsertionPoint(0); - - m_modified = false; } void wxTextCtrl::WriteText( const wxString &text ) @@ -858,10 +867,8 @@ void wxTextCtrl::WriteText( const wxString &text ) return; } - // gtk_text_changed_callback() will set m_modified to true but m_modified - // shouldn't be changed by the program writing to the text control itself, - // so save the old value and restore when we're done - bool oldModified = m_modified; + // we're changing the text programmatically + DontMarkDirtyOnNextChange(); if ( m_windowStyle & wxTE_MULTILINE ) { @@ -896,8 +903,6 @@ void wxTextCtrl::WriteText( const wxString &text ) // Bring entry's cursor uptodate. gtk_editable_set_position( GTK_EDITABLE(m_text), len ); } - - m_modified = oldModified; } void wxTextCtrl::AppendText( const wxString &text ) @@ -1139,11 +1144,6 @@ void wxTextCtrl::DiscardEdits() // max text length support // ---------------------------------------------------------------------------- -void wxTextCtrl::IgnoreNextTextUpdate() -{ - m_ignoreNextUpdate = true; -} - bool wxTextCtrl::IgnoreTextUpdate() { if ( m_ignoreNextUpdate ) @@ -1156,6 +1156,18 @@ bool wxTextCtrl::IgnoreTextUpdate() return false; } +bool wxTextCtrl::MarkDirtyOnChange() +{ + if ( m_dontMarkDirty ) + { + m_dontMarkDirty = false; + + return false; + } + + return true; +} + void wxTextCtrl::SetMaxLength(unsigned long len) { if ( !HasFlag(wxTE_MULTILINE) )