X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a7c0de8a98250e908329ece9e14742b9d688d1e4..69384772acc96ab55b235f8d0e4d67d8ee4d6862:/src/common/docview.cpp diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 246d247254..c5ba8064b2 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -4,7 +4,6 @@ // Author: Julian Smart // Modified by: Vadim Zeitlin // Created: 01/02/97 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -858,19 +857,25 @@ wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags) bool wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long flags) { - wxScopeGuard g = wxMakeObjGuard(*doc, &wxDocument::DeleteAllViews); - - doc->SetFilename(path); - doc->SetDocumentTemplate(this); - GetDocumentManager()->AddDocument(doc); - doc->SetCommandProcessor(doc->OnCreateCommandProcessor()); - - if ( !doc->OnCreate(path, flags) ) - return false; - - g.Dismiss(); // no need to call DeleteAllViews() anymore + // Normally, if wxDocument::OnCreate() fails, it happens because the view + // initialization fails and then the document is destroyed due to the + // destruction of its last view. But take into account the (currently + // unrealized, AFAICS) possibility of other failures as well and ensure + // that the document is always destroyed if it can't be initialized. + wxTRY + { + doc->SetFilename(path); + doc->SetDocumentTemplate(this); + GetDocumentManager()->AddDocument(doc); + doc->SetCommandProcessor(doc->OnCreateCommandProcessor()); - return true; + return doc->OnCreate(path, flags); + } + wxCATCH_ALL( + if ( GetDocumentManager()->GetDocuments().Member(doc) ) + doc->DeleteAllViews(); + throw; + ) } wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags) @@ -2075,15 +2080,24 @@ bool wxDocParentFrameAnyBase::TryProcessEvent(wxEvent& event) // already forwarded the event to wxDocManager, check for this: if ( wxView* const view = m_docManager->GetAnyUsableView() ) { - // Notice that we intentionally don't use wxGetTopLevelParent() here - // because we want to check both for the case of a child "frame" (e.g. - // MDI child frame or notebook page) inside this TLW and a separate - // child TLW frame (as used in the SDI mode) here. - for ( wxWindow* win = view->GetFrame(); win; win = win->GetParent() ) + wxWindow* win = view->GetFrame(); + if ( win && win != m_frame ) { - if ( win == m_frame ) - return false; + // Notice that we intentionally don't use wxGetTopLevelParent() + // here because we want to check both for the case of a child + // "frame" (e.g. MDI child frame or notebook page) inside this TLW + // and a separate child TLW frame (as used in the SDI mode) here. + for ( win = win->GetParent(); win; win = win->GetParent() ) + { + if ( win == m_frame ) + return false; + } } + //else: This view is directly associated with the parent frame (which + // can happen in the so called "single" mode in which only one + // document can be opened and so is managed by the parent frame + // itself), there can be no child frame in play so we must forward + // the event to wxDocManager ourselves. } // But forward the event to wxDocManager ourselves if there are no views at