From 6733ef3cfc873c82ae77347922d9f72c4a169e70 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Wed, 25 May 2016 00:07:34 +0200 Subject: [PATCH] wxAuiManager persistence changed to resolve asserts in Win32 builds --- ZRCola/ZRCola.fbp | 2 +- ZRCola/zrcolafrm.cpp | 19 ++++++++++++------- ZRCola/zrcolafrm.h | 1 + ZRCola/zrcolagui.cpp | 2 ++ ZRCola/zrcolagui.h | 1 + 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ZRCola/ZRCola.fbp b/ZRCola/ZRCola.fbp index c1ffeee..d3b2f7e 100644 --- a/ZRCola/ZRCola.fbp +++ b/ZRCola/ZRCola.fbp @@ -62,7 +62,7 @@ - + OnClose diff --git a/ZRCola/zrcolafrm.cpp b/ZRCola/zrcolafrm.cpp index 35000fc..f4c5426 100644 --- a/ZRCola/zrcolafrm.cpp +++ b/ZRCola/zrcolafrm.cpp @@ -69,10 +69,6 @@ wxZRColaFrame::wxZRColaFrame() : m_toolbarCompose->SetWindowStyleFlag(m_toolbarCompose->GetWindowStyleFlag() | wxAUI_TB_HORIZONTAL); } - // Restore the wxAuiManager's state here to keep symmetric with save in the destructor below. - // See the comment in destructor why. - wxPersistentAuiManager(&m_mgr).Restore(); - // Load main window icons. #ifdef __WINDOWS__ wxIcon icon_small(wxT("00_zrcola.ico"), wxBITMAP_TYPE_ICO_RESOURCE, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON)); @@ -135,6 +131,9 @@ wxZRColaFrame::wxZRColaFrame() : entries[0].Set(wxACCEL_NORMAL, WXK_F4, wxID_FOCUS_CHARACTER_CATALOG); SetAcceleratorTable(wxAcceleratorTable(_countof(entries), entries)); } + + // Restore persistent state of wxAuiManager manually, since m_mgr is not on the heap. + wxPersistentAuiManager(&m_mgr).Restore(); } @@ -161,10 +160,16 @@ wxZRColaFrame::~wxZRColaFrame() m_taskBarIcon->Disconnect(wxEVT_TASKBAR_LEFT_DOWN, wxTaskBarIconEventHandler(wxZRColaFrame::OnTaskbarIconClick), NULL, this); delete m_taskBarIcon; } +} - // Save wxAuiManager's state before return to parent's destructor. - // Since the later calls m_mgr.UnInit() the regular persistence mechanism is useless to save wxAuiManager's state. - wxPersistentAuiManager((wxAuiManager*)&m_mgr).Save(); + +void wxZRColaFrame::OnClose(wxCloseEvent& event) +{ + event.Skip(); + + // Save wxAuiManager's state before destructor. + // Since the destructor calls m_mgr.UnInit() the regular persistence mechanism is useless to save wxAuiManager's state. + wxPersistentAuiManager(&m_mgr).Save(); } diff --git a/ZRCola/zrcolafrm.h b/ZRCola/zrcolafrm.h index e82baa4..6f60edb 100644 --- a/ZRCola/zrcolafrm.h +++ b/ZRCola/zrcolafrm.h @@ -65,6 +65,7 @@ public: friend class wxZRColaComposerPanel; protected: + virtual void OnClose(wxCloseEvent& event); void OnExit(wxCommandEvent& event); void OnForwardEventUpdate(wxUpdateUIEvent& event); void OnForwardEvent(wxCommandEvent& event); diff --git a/ZRCola/zrcolagui.cpp b/ZRCola/zrcolagui.cpp index 7858992..7442362 100644 --- a/ZRCola/zrcolagui.cpp +++ b/ZRCola/zrcolagui.cpp @@ -190,6 +190,7 @@ wxZRColaFrameBase::wxZRColaFrameBase( wxWindow* parent, wxWindowID id, const wxS this->Centre( wxBOTH ); // Connect Events + this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( wxZRColaFrameBase::OnClose ) ); this->Connect( wxEVT_ICONIZE, wxIconizeEventHandler( wxZRColaFrameBase::OnIconize ) ); this->Connect( wxEVT_IDLE, wxIdleEventHandler( wxZRColaFrameBase::OnIdle ) ); } @@ -197,6 +198,7 @@ wxZRColaFrameBase::wxZRColaFrameBase( wxWindow* parent, wxWindowID id, const wxS wxZRColaFrameBase::~wxZRColaFrameBase() { // Disconnect Events + this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( wxZRColaFrameBase::OnClose ) ); this->Disconnect( wxEVT_ICONIZE, wxIconizeEventHandler( wxZRColaFrameBase::OnIconize ) ); this->Disconnect( wxEVT_IDLE, wxIdleEventHandler( wxZRColaFrameBase::OnIdle ) ); diff --git a/ZRCola/zrcolagui.h b/ZRCola/zrcolagui.h index 0557922..8cbc992 100644 --- a/ZRCola/zrcolagui.h +++ b/ZRCola/zrcolagui.h @@ -91,6 +91,7 @@ class wxZRColaFrameBase : public wxFrame wxStatusBar* m_statusBar; // Virtual event handlers, overide them in your derived class + virtual void OnClose( wxCloseEvent& event ) { event.Skip(); } virtual void OnIconize( wxIconizeEvent& event ) { event.Skip(); } virtual void OnIdle( wxIdleEvent& event ) { event.Skip(); }