From 575e4cd67024ca1c49b4218ce748c68aa938ce27 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 29 Jan 2009 13:04:40 +0000 Subject: [PATCH] don't fall back to the only currently existing document in wxDocManager::GetCurrentView() as it breaks activation logic (#9518) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58496 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/docview.h | 7 ++++++- src/common/docview.cpp | 34 +++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/wx/docview.h b/include/wx/docview.h index f03945b..a7c6df2 100644 --- a/include/wx/docview.h +++ b/include/wx/docview.h @@ -417,7 +417,7 @@ public: // Views or windows should inform the document manager // when a view is going in or out of focus virtual void ActivateView(wxView *view, bool activate = true); - virtual wxView *GetCurrentView() const; + virtual wxView *GetCurrentView() const { return m_currentView; } wxList& GetDocuments() { return m_docs; } wxList& GetTemplates() { return m_templates; } @@ -472,6 +472,11 @@ protected: // return the command processor for the current document, if any wxCommandProcessor *GetCurrentCommandProcessor() const; + // this method tries to find an active view harder than GetCurrentView(): + // if the latter is NULL, it also checks if we don't have just a single + // view and returns it then + wxView *GetActiveView() const; + int m_defaultDocumentNameCounter; int m_maxDocsOpen; diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 829ce9b..9c5118b 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -1018,7 +1018,7 @@ void wxDocManager::OnFileSaveAs(wxCommandEvent& WXUNUSED(event)) void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event)) { #if wxUSE_PRINTING_ARCHITECTURE - wxView *view = GetCurrentView(); + wxView *view = GetActiveView(); if (!view) return; @@ -1036,7 +1036,7 @@ void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event)) void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event)) { #if wxUSE_PRINTING_ARCHITECTURE - wxView *view = GetCurrentView(); + wxView *view = GetActiveView(); if (!view) return; @@ -1140,21 +1140,33 @@ void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event) cmdproc->SetMenuStrings(); } -wxView *wxDocManager::GetCurrentView() const +wxView *wxDocManager::GetActiveView() const { - if (m_currentView) - return m_currentView; - if (m_docs.GetCount() == 1) + wxView *view = GetCurrentView(); + + if ( !view && !m_docs.empty() ) { - wxDocument* doc = (wxDocument*) m_docs.GetFirst()->GetData(); - return doc->GetFirstView(); + // if we have exactly one document, consider its view to be the current + // one + // + // VZ: I'm not exactly sure why is this needed but this is how this + // code used to behave before the bug #9518 was fixed and it seems + // safer to preserve the old logic + wxList::compatibility_iterator node = m_docs.GetFirst(); + if ( !node->GetNext() ) + { + wxDocument *doc = static_cast(node->GetData()); + view = doc->GetFirstView(); + } + //else: we have more than one document } - return NULL; + + return view; } bool wxDocManager::TryValidator(wxEvent& event) { - wxView * const view = GetCurrentView(); + wxView * const view = GetActiveView(); return view && view->ProcessEventHere(event); } @@ -1329,7 +1341,7 @@ bool wxDocManager::FlushDoc(wxDocument *WXUNUSED(doc)) wxDocument *wxDocManager::GetCurrentDocument() const { - wxView * const view = GetCurrentView(); + wxView * const view = GetActiveView(); return view ? view->GetDocument() : NULL; } -- 2.7.4