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