]> git.saurik.com Git - wxWidgets.git/commitdiff
make sure that IsModified() returns false when it's called from EVT_TEXT handler...
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 17 May 2006 00:20:20 +0000 (00:20 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 17 May 2006 00:20:20 +0000 (00:20 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39172 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/textctrl.h
src/gtk/textctrl.cpp

index 26b6e3e8e4f73f7641ea7ed09ac481c75d7eda49..b9b793eb19c62941410a4d3056b8f8476445b2cf 100644 (file)
@@ -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
index 9211dde77cfcc86f588a1af6ac89fa0034532e00..40329ca9fa743641503650b2e40df6a92bb2d3fd 100644 (file)
@@ -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) )