From 6697b576b21f10e4296c7338353d1ee07da83a78 Mon Sep 17 00:00:00 2001 From: Kvaz1r Date: Tue, 11 Feb 2020 16:48:13 +0200 Subject: [PATCH] Close AUI MDI children when the parent frame is closed This ensures that the parent frame doesn't close if any of the children can't be closed and also that all children are closed before the parent if they do agree to close. Closes https://github.com/wxWidgets/wxWidgets/pull/1734 Closes #15170. --- include/wx/aui/tabmdi.h | 5 +++++ src/aui/tabmdi.cpp | 33 +++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/wx/aui/tabmdi.h b/include/wx/aui/tabmdi.h index bd98406353..af0a100ef6 100644 --- a/include/wx/aui/tabmdi.h +++ b/include/wx/aui/tabmdi.h @@ -108,6 +108,11 @@ protected: virtual void DoGetClientSize(int *width, int *height) const wxOVERRIDE; private: + void OnClose(wxCloseEvent& event); + + // close all children, return false if any of them vetoed it + bool CloseAll(); + wxDECLARE_EVENT_TABLE(); wxDECLARE_DYNAMIC_CLASS(wxAuiMDIParentFrame); }; diff --git a/src/aui/tabmdi.cpp b/src/aui/tabmdi.cpp index 5c0ac18b7e..dca9b8404e 100644 --- a/src/aui/tabmdi.cpp +++ b/src/aui/tabmdi.cpp @@ -54,6 +54,7 @@ enum MDI_MENU_ID wxIMPLEMENT_DYNAMIC_CLASS(wxAuiMDIParentFrame, wxFrame); wxBEGIN_EVENT_TABLE(wxAuiMDIParentFrame, wxFrame) + EVT_CLOSE(wxAuiMDIParentFrame::OnClose) #if wxUSE_MENUS EVT_MENU (wxID_ANY, wxAuiMDIParentFrame::DoHandleMenu) EVT_UPDATE_UI (wxID_ANY, wxAuiMDIParentFrame::DoHandleUpdateUI) @@ -241,6 +242,29 @@ bool wxAuiMDIParentFrame::ProcessEvent(wxEvent& event) return res; } +void wxAuiMDIParentFrame::OnClose(wxCloseEvent& event) +{ + if (!CloseAll()) + event.Veto(); + else + event.Skip(); +} + +bool wxAuiMDIParentFrame::CloseAll() +{ + wxAuiMDIChildFrame* pActiveChild; + while ((pActiveChild = GetActiveChild()) != NULL) + { + if (!pActiveChild->Close()) + { + // it refused to close, don't close the remaining ones neither + return false; + } + } + + return true; +} + wxAuiMDIChildFrame *wxAuiMDIParentFrame::GetActiveChild() const { // We can be called before the client window is created, so check for its @@ -343,14 +367,7 @@ void wxAuiMDIParentFrame::DoHandleMenu(wxCommandEvent& event) } case wxWINDOWCLOSEALL: { - wxAuiMDIChildFrame* pActiveChild; - while ((pActiveChild = GetActiveChild()) != NULL) - { - if (!pActiveChild->Close()) - { - return; // failure - } - } + CloseAll(); break; } case wxWINDOWNEXT: