X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/93d0805b35757bbfd30ed4ae6756b9764c112c0d..60d66be369d360e1528e4dd4bb65a909a8c6ac9a:/src/common/docview.cpp?ds=sidebyside diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 849a3a2754..fc1c256337 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -1185,7 +1185,7 @@ void wxDocManager::OnMRUFileNotExist(unsigned n, const wxString& filename) void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event)) { - wxView *view = GetActiveView(); + wxView *view = GetAnyUsableView(); if (!view) return; @@ -1219,7 +1219,7 @@ wxPreviewFrame* wxDocManager::CreatePreviewFrame(wxPrintPreviewBase* preview, void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event)) { wxBusyCursor busy; - wxView *view = GetActiveView(); + wxView *view = GetAnyUsableView(); if (!view) return; @@ -1348,7 +1348,7 @@ void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event) cmdproc->SetMenuStrings(); } -wxView *wxDocManager::GetActiveView() const +wxView *wxDocManager::GetAnyUsableView() const { wxView *view = GetCurrentView(); @@ -1374,7 +1374,7 @@ wxView *wxDocManager::GetActiveView() const bool wxDocManager::TryBefore(wxEvent& event) { - wxView * const view = GetActiveView(); + wxView * const view = GetAnyUsableView(); return view && view->ProcessEventLocally(event); } @@ -1407,9 +1407,9 @@ wxDocTemplateVector GetVisibleTemplates(const wxList& allTemplates) } // anonymous namespace -void wxDocManager::ActivateDocument(wxDocument *doc) +void wxDocument::Activate() { - wxView * const view = doc->GetFirstView(); + wxView * const view = GetFirstView(); if ( !view ) return; @@ -1418,6 +1418,19 @@ void wxDocManager::ActivateDocument(wxDocument *doc) win->Raise(); } +wxDocument* wxDocManager::FindDocumentByPath(const wxString& path) const +{ + const wxFileName fileName(path); + for ( wxList::const_iterator i = m_docs.begin(); i != m_docs.end(); ++i ) + { + wxDocument * const doc = wxStaticCast(*i, wxDocument); + + if ( fileName == wxFileName(doc->GetFilename()) ) + return doc; + } + return NULL; +} + wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags) { // this ought to be const but SelectDocumentType/Path() are not @@ -1464,21 +1477,15 @@ wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags) // check whether the document with this path is already opened if ( !path.empty() ) { - const wxFileName fn(path); - for ( wxList::const_iterator i = m_docs.begin(); i != m_docs.end(); ++i ) + wxDocument * const doc = FindDocumentByPath(path); + if (doc) { - wxDocument * const doc = (wxDocument*)*i; - - if ( fn == doc->GetFilename() ) - { - // file already open, just activate it and return - ActivateDocument(doc); - return doc; - } + // file already open, just activate it and return + doc->Activate(); + return doc; } } - // no, we need to create a new document @@ -1523,7 +1530,7 @@ wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags) // at least under Mac (where views are top level windows) it seems to be // necessary to manually activate the new document to bring it to the // forefront -- and it shouldn't hurt doing this under the other platforms - ActivateDocument(docNew); + docNew->Activate(); return docNew; } @@ -1563,7 +1570,7 @@ bool wxDocManager::FlushDoc(wxDocument *WXUNUSED(doc)) wxDocument *wxDocManager::GetCurrentDocument() const { - wxView * const view = GetActiveView(); + wxView * const view = GetAnyUsableView(); return view ? view->GetDocument() : NULL; } @@ -2007,6 +2014,26 @@ void wxDocManager::ActivateView(wxView *view, bool activate) // wxDocChildFrameAnyBase // ---------------------------------------------------------------------------- +bool wxDocChildFrameAnyBase::TryProcessEvent(wxEvent& event) +{ + if ( !m_childView ) + { + // We must be being destroyed, don't forward events anywhere as + // m_childDocument could be invalid by now. + return false; + } + + // Forward the event to the document manager which will, in turn, forward + // it to its active view which must be our m_childView. + // + // Notice that we do things in this roundabout way to guarantee the correct + // event handlers call order: first the document, then the new and then the + // document manager itself. And if we forwarded the event directly to the + // view, then the document manager would do it once again when we forwarded + // it to it. + return m_childDocument->GetDocumentManager()->ProcessEventLocally(event); +} + bool wxDocChildFrameAnyBase::CloseView(wxCloseEvent& event) { if ( m_childView ) @@ -2039,6 +2066,44 @@ bool wxDocChildFrameAnyBase::CloseView(wxCloseEvent& event) // wxDocParentFrameAnyBase // ---------------------------------------------------------------------------- +bool wxDocParentFrameAnyBase::TryProcessEvent(wxEvent& event) +{ + if ( !m_docManager ) + return false; + + // If we have an active view, its associated child frame may have + // already forwarded the event to wxDocManager, check for this: + if ( wxView* const view = m_docManager->GetAnyUsableView() ) + { + wxWindow* win = view->GetFrame(); + if ( win && win != m_frame ) + { + // 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 + // all or if we are the frame's view ourselves. + return m_docManager->ProcessEventLocally(event); +} + +// ---------------------------------------------------------------------------- +// Printing support +// ---------------------------------------------------------------------------- + #if wxUSE_PRINTING_ARCHITECTURE namespace