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
This commit is contained in:
Vadim Zeitlin 2010-05-30 20:05:44 +00:00
parent b99017ce20
commit 8325504f4b
2 changed files with 20 additions and 7 deletions

View File

@ -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;

View File

@ -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;
}