]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't change wxTextEntry value if it didn't really change.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 28 Apr 2012 22:25:03 +0000 (22:25 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 28 Apr 2012 22:25:03 +0000 (22:25 +0000)
This is not only unnecessary but also can result in a kind of infinite loop
when wxTextEntry::SetValue() is called from wxEVT_IDLE handler as really
modifying the text results in another wxEVT_IDLE being generated and another
call to SetValue() and so on while not doing it in the first place completely
works around the problem and is also more efficient.

Closes #13936.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71308 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/textentrycmn.cpp

index 5b08496492d14eba7423de13e6a78193c0e93cb9..54b738a9babb5460fce6cc98e3dd55aacc13b96a 100644 (file)
@@ -224,10 +224,19 @@ void wxTextEntryBase::AppendText(const wxString& text)
 
 void wxTextEntryBase::DoSetValue(const wxString& value, int flags)
 {
-    EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent));
+    if ( value != GetValue() )
+    {
+        EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent));
 
-    SelectAll();
-    WriteText(value);
+        SelectAll();
+        WriteText(value);
+    }
+    else // Same value, no need to do anything.
+    {
+        // Except that we still need to generate the event for consistency with
+        // the normal case when the text does change.
+        SendTextUpdatedEvent(GetEditableWindow());
+    }
 
     SetInsertionPoint(0);
 }