From: Vadim Zeitlin Date: Sun, 24 Oct 2010 23:03:38 +0000 (+0000) Subject: Add wxDocManager::FindTemplate() method. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/a70d268a1b43dc8ef2025b2beaeb5a595ba173fc Add wxDocManager::FindTemplate() method. This allows to find the template corresponding to the document of the given class. Closes #12170. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65915 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index b34dfa11bc..69bb9a4e1e 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -425,6 +425,7 @@ All (GUI): - Restore text drag-and-drop in wxSTC broken by Scintilla 2 update (Jens Lody). - Improve wxGTK print/page setup dialog (rafravago). - Added wxToolbook XRC handler (Andrea Zanellato). +- Added wxDocManager::FindTemplate() (troelsk). MSW: diff --git a/include/wx/docview.h b/include/wx/docview.h index 8a400b74c6..78038deaeb 100644 --- a/include/wx/docview.h +++ b/include/wx/docview.h @@ -414,6 +414,9 @@ public: void AssociateTemplate(wxDocTemplate *temp); void DisassociateTemplate(wxDocTemplate *temp); + // Find template from document class info, may return NULL. + wxDocTemplate* FindTemplate(const wxClassInfo* documentClassInfo); + wxDocument *GetCurrentDocument() const; void SetMaxDocsOpen(int n) { m_maxDocsOpen = n; } diff --git a/interface/wx/docview.h b/interface/wx/docview.h index 360c40e258..14bf99ba6a 100644 --- a/interface/wx/docview.h +++ b/interface/wx/docview.h @@ -363,6 +363,27 @@ public: */ void AssociateTemplate(wxDocTemplate* temp); + /** + Search for a particular document template. + + Example: + @code + // creating a document instance of the specified document type: + m_doc = (MyDoc*)docManager->FindTemplate(CLASSINFO(MyDoc))-> + CreateDocument(wxEmptyString, wxDOC_SILENT); + @endcode + + @param classinfo + Class info of a document class for which a wxDocTemplate had been + previously created. + + @return + Pointer to a wxDocTemplate, or @NULL if none found. + + @since 2.9.2 + */ + wxDocTemplate* FindTemplate(const wxClassInfo* classinfo); + /** Closes the specified document. diff --git a/src/common/docview.cpp b/src/common/docview.cpp index e2ff18c915..86d1783490 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -1894,6 +1894,20 @@ void wxDocManager::DisassociateTemplate(wxDocTemplate *temp) m_templates.DeleteObject(temp); } +wxDocTemplate* wxDocManager::FindTemplate(const wxClassInfo* classinfo) +{ + for ( wxList::compatibility_iterator node = m_templates.GetFirst(); + node; + node = node->GetNext() ) + { + wxDocTemplate* t = wxStaticCast(node->GetData(), wxDocTemplate); + if ( t->GetDocClassInfo() == classinfo ) + return t; + } + + return NULL; +} + // Add and remove a document from the manager's list void wxDocManager::AddDocument(wxDocument *doc) {