From 5dd5d68e6730d1a59a49bff77108533ef8ba8327 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 30 Jan 2016 05:00:43 +0100 Subject: [PATCH] Revert "Fix fields initialization in wxCommandEvent copy ctor." This reverts commit 62763ad54146661e20f0232fdae9f7dab8a262c7 which seems to have been completely unnecessary as the fields had been already initialized and this commit actually broke initialization of the propagation level of the copied wxCommandEvent objects. Add a unit test proving that things do work. Closes #16739. --- include/wx/event.h | 13 +++---------- tests/events/propagation.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/include/wx/event.h b/include/wx/event.h index 24e5545175..a57df24c22 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -1502,8 +1502,10 @@ public: { m_clientData = NULL; m_clientObject = NULL; + m_isCommandEvent = true; - Init(); + // the command events are propagated upwards by default + m_propagationLevel = wxEVENT_PROPAGATE_MAX; } wxCommandEvent(const wxCommandEvent& event) @@ -1516,8 +1518,6 @@ public: // need to copy it explicitly. if ( m_cmdString.empty() ) m_cmdString = event.GetString(); - - Init(); } // Set/Get client data from controls @@ -1549,13 +1549,6 @@ protected: wxClientData* m_clientObject; // Arbitrary client object private: - void Init() - { - m_isCommandEvent = true; - - // the command events are propagated upwards by default - m_propagationLevel = wxEVENT_PROPAGATE_MAX; - } wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCommandEvent); }; diff --git a/tests/events/propagation.cpp b/tests/events/propagation.cpp index 5663403827..36cf3569f1 100644 --- a/tests/events/propagation.cpp +++ b/tests/events/propagation.cpp @@ -248,6 +248,7 @@ private: #endif CPPUNIT_TEST( DocView ); WXUISIM_TEST( ContextMenuEvent ); + CPPUNIT_TEST( PropagationLevel ); CPPUNIT_TEST_SUITE_END(); void OneHandler(); @@ -260,6 +261,7 @@ private: void MenuEvent(); void DocView(); void ContextMenuEvent(); + void PropagationLevel(); wxDECLARE_NO_COPY_CLASS(EventPropagationTestCase); }; @@ -669,4 +671,31 @@ void EventPropagationTestCase::ContextMenuEvent() CPPUNIT_ASSERT_EQUAL( "p", g_str ); } +// Helper function: get the event propagation level. +int GetPropagationLevel(wxEvent& e) +{ + const int level = e.StopPropagation(); + e.ResumePropagation(level); + return level; +} + +void EventPropagationTestCase::PropagationLevel() +{ + wxSizeEvent se; + CPPUNIT_ASSERT_EQUAL( GetPropagationLevel(se), (int)wxEVENT_PROPAGATE_NONE ); + + wxCommandEvent ce; + CPPUNIT_ASSERT_EQUAL( GetPropagationLevel(ce), (int)wxEVENT_PROPAGATE_MAX ); + + wxCommandEvent ce2(ce); + CPPUNIT_ASSERT_EQUAL( GetPropagationLevel(ce2), (int)wxEVENT_PROPAGATE_MAX ); + + wxCommandEvent ce3; + ce3.ResumePropagation(17); + CPPUNIT_ASSERT_EQUAL( GetPropagationLevel(ce3), 17 ); + + wxCommandEvent ce4(ce3); + CPPUNIT_ASSERT_EQUAL( GetPropagationLevel(ce4), 17 ); +} + #endif // wxUSE_UIACTIONSIMULATOR