From 13163fb315ac055890f3e339a6acc02158913f57 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 03:06:03 +0100 Subject: [PATCH] Send event when clearing wxTextCtrl in wxGTK again This was broken by 1c946a469a36006b8f262473c4e6355987bfb28b and resulted in test failures in OwnerDrawnComboBoxTestCase::TextChangeEvents() unit test because wxOwnerDrawnComboBox::Clear() used SetValue("") and didn't generate any events any more. Fix this regression by explicitly sending an event if we're returning early and add a unit test explicitly checking that SetValue("") does generate an event. --- src/gtk/textctrl.cpp | 5 +++++ tests/controls/textentrytest.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 56f5848901..c3d56aaee2 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1046,7 +1046,12 @@ void wxTextCtrl::WriteText( const wxString &text ) wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); if ( text.empty() ) + { + // We don't need to actually do anything, but we still need to generate + // an event expected from this call. + SendTextUpdatedEvent(this); return; + } // we're changing the text programmatically DontMarkDirtyOnNextChange(); diff --git a/tests/controls/textentrytest.cpp b/tests/controls/textentrytest.cpp index b5c4fddfe9..96b121de84 100644 --- a/tests/controls/textentrytest.cpp +++ b/tests/controls/textentrytest.cpp @@ -57,6 +57,10 @@ void TextEntryTestCase::TextChangeEvents() CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() ); updated.Clear(); + entry->SetValue(""); + CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() ); + updated.Clear(); + entry->ChangeValue("bar"); CPPUNIT_ASSERT_EQUAL( 0, updated.GetCount() );