Destroy all views associated to wxDocument being forcefully closed.

Forcefully closing a modified document misbehaved in several ways: first, the
question about whether the document should be saved was asked twice if the
first message box was cancelled. Second, DeleteAllViews() didn't actually
delete the views if the second message box was cancelled as well -- so the
views could be left alive while their associated document was destroyed,
resulting in more or less guaranteed crash (e.g. during the next event
handling as wxDocChildFrameAnyBase::TryProcessEvent() assumes that
m_childDocument is still alive if m_childView is).

Fix both problems by really forcing the document to close by pretending that
it is not modified.

We still ask the user once though, as it could be useful to be able to save
the document even when it will be closed. Ideally, the message box shown in
this case shouldn't have a "Cancel" button at all, but this is left for the
future.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78282 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-12-19 15:56:42 +00:00
parent 8f134c9a28
commit 8ce753db08

View File

@@ -1001,13 +1001,17 @@ bool wxDocManager::CloseDocument(wxDocument* doc, bool force)
if ( !doc->Close() && !force )
return false;
// To really force the document to close, we must ensure that it isn't
// modified, otherwise it would ask the user about whether it should be
// destroyed (again, it had been already done by Close() above) and might
// not destroy it at all, while we must do it here.
doc->Modify(false);
// Implicitly deletes the document when
// the last view is deleted
doc->DeleteAllViews();
// Check we're really deleted
if (m_docs.Member(doc))
delete doc;
wxASSERT(!m_docs.Member(doc));
return true;
}