From 62763ad54146661e20f0232fdae9f7dab8a262c7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 5 Dec 2014 22:17:52 +0000 Subject: [PATCH] Fix fields initialization in wxCommandEvent copy ctor. Neither m_isCommandEvent nor, worse, m_propagationLevel was set correctly for wxCommandEvent objects constructed using copy ctor -- and hence Clone(). This means that such events were not propagated upwards the window hierarchy, quite possibly resulting in mysterious bugs. Fix this now by initializing these fields in both the normal and copy ctors. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78229 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/event.h | 19 ++++++++++++++++++- src/common/event.cpp | 11 ----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/wx/event.h b/include/wx/event.h index 5e1d7b305b..4f6aca1f80 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -1496,7 +1496,14 @@ class WXDLLIMPEXP_CORE wxCommandEvent : public wxEvent, public wxEventBasicPayloadMixin { public: - wxCommandEvent(wxEventType commandType = wxEVT_NULL, int winid = 0); + wxCommandEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) + : wxEvent(winid, commandType) + { + m_clientData = NULL; + m_clientObject = NULL; + + Init(); + } wxCommandEvent(const wxCommandEvent& event) : wxEvent(event), @@ -1508,6 +1515,8 @@ public: // need to copy it explicitly. if ( m_cmdString.empty() ) m_cmdString = event.GetString(); + + Init(); } // Set/Get client data from controls @@ -1539,6 +1548,14 @@ 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; + } + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCommandEvent) }; diff --git a/src/common/event.cpp b/src/common/event.cpp index eb5070ad4f..e1457b408e 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -423,17 +423,6 @@ wxEvent& wxEvent::operator=(const wxEvent& src) // wxCommandEvent // ---------------------------------------------------------------------------- -wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId) - : wxEvent(theId, commandType) -{ - m_clientData = NULL; - m_clientObject = NULL; - m_isCommandEvent = true; - - // the command events are propagated upwards by default - m_propagationLevel = wxEVENT_PROPAGATE_MAX; -} - wxString wxCommandEvent::GetString() const { // This is part of the hack retrieving the event string from the control