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: