From 8325504f4bf9dc557745f4dcb26b43c029d5106d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 May 2010 20:05:44 +0000 Subject: [PATCH] Activate the view of a newly created document. This appears to be necessary under Mac where views are top level windows and should do no harm elsewhere. Also factor out the activation code in a new wxDocManager::ActivateDocument() method to avoid duplicating it. Closes #11417. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64440 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/docview.h | 3 +++ src/common/docview.cpp | 24 +++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/wx/docview.h b/include/wx/docview.h index 0c92952467..7be6af0d74 100644 --- a/include/wx/docview.h +++ b/include/wx/docview.h @@ -501,6 +501,9 @@ protected: // view and returns it then wxView *GetActiveView() const; + // activate the first view of the given document if any + void ActivateDocument(wxDocument *doc); + int m_defaultDocumentNameCounter; int m_maxDocsOpen; diff --git a/src/common/docview.cpp b/src/common/docview.cpp index fa23123c8d..e95866bd14 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -1295,6 +1295,17 @@ wxDocTemplates GetVisibleTemplates(const wxList& allTemplates) } // anonymous namespace +void wxDocManager::ActivateDocument(wxDocument *doc) +{ + wxView * const view = doc->GetFirstView(); + if ( !view ) + return; + + view->Activate(true); + if ( wxWindow *win = view->GetFrame() ) + win->SetFocus(); +} + wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags) { // this ought to be const but SelectDocumentType/Path() are not @@ -1349,13 +1360,7 @@ wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags) if ( fn == doc->GetFilename() ) { // file already open, just activate it and return - if ( doc->GetFirstView() ) - { - ActivateView(doc->GetFirstView()); - if ( doc->GetDocumentWindow() ) - doc->GetDocumentWindow()->SetFocus(); - return doc; - } + ActivateDocument(doc); } } } @@ -1402,6 +1407,11 @@ wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags) if ( !(flags & wxDOC_NEW) && temp->FileMatchesTemplate(path) ) AddFileToHistory(path); + // 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); + return docNew; } -- 2.45.2