]> git.saurik.com Git - wxWidgets.git/commitdiff
Separated creation and initialisation of a document via its doc template.
authorJulian Smart <julian@anthemion.co.uk>
Thu, 3 Jun 2004 14:19:39 +0000 (14:19 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Thu, 3 Jun 2004 14:19:39 +0000 (14:19 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27600 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/doctempl.tex
include/wx/docview.h
src/common/docview.cpp

index ebae77f6ef5eaab95b3d6559c9f88e38682075b1..afaaea357e16dee3546389acfb4e1e5ea544370d 100644 (file)
@@ -154,6 +154,9 @@ Creates a new instance of the associated document class. If you have not supplie
 a wxClassInfo parameter to the template constructor, you will need to override this
 function to return an appropriate document instance.
 
 a wxClassInfo parameter to the template constructor, you will need to override this
 function to return an appropriate document instance.
 
+This function calls wxDocTemplate::InitDocument which in turns
+calls wxDocument::OnCreate.
+
 \membersection{wxDocTemplate::CreateView}
 
 \func{wxView *}{CreateView}{\param{wxDocument *}{doc}, \param{long}{ flags = 0}}
 \membersection{wxDocTemplate::CreateView}
 
 \func{wxView *}{CreateView}{\param{wxDocument *}{doc}, \param{long}{ flags = 0}}
@@ -210,6 +213,13 @@ Returns the flags, as passed to the document template constructor.
 
 Returns the view type name, as passed to the document template constructor.
 
 
 Returns the view type name, as passed to the document template constructor.
 
+\membersection{wxDocTemplate::InitDocument}
+
+\func{bool}{InitDocument}{\param{wxDocument* }{doc}, \param{const wxString\& }{path}, \param{long}{ flags = 0}}
+
+Initialises the document, calling wxDocument::OnCreate. This is called from
+wxDocTemplate::CreateDocument.
+
 \membersection{wxDocTemplate::IsVisible}
 
 \func{bool}{IsVisible}{\void}
 \membersection{wxDocTemplate::IsVisible}
 
 \func{bool}{IsVisible}{\void}
index ef574fd486e640ba4c627cdfc6b913b0305e1f75..08a9a3ce4440ee977a0c85c792a4e444d8a46cf8 100644 (file)
@@ -254,6 +254,10 @@ public:
     virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
     virtual wxView *CreateView(wxDocument *doc, long flags = 0);
 
     virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
     virtual wxView *CreateView(wxDocument *doc, long flags = 0);
 
+    // Helper method for CreateDocument; also allows you to do your own document
+    // creation
+    virtual bool InitDocument(wxDocument* doc, const wxString& path, long flags = 0);
+
     wxString GetDefaultExtension() const { return m_defaultExt; };
     wxString GetDescription() const { return m_description; }
     wxString GetDirectory() const { return m_directory; };
     wxString GetDefaultExtension() const { return m_defaultExt; };
     wxString GetDescription() const { return m_description; }
     wxString GetDirectory() const { return m_directory; };
index a9687e03270dc043b4d3bea4e2e6f5c036c11d7c..f77b00cdbda2f97f9c81506006b9d3f4e679ed7a 100644 (file)
@@ -691,18 +691,31 @@ wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
     if (!m_docClassInfo)
         return (wxDocument *) NULL;
     wxDocument *doc = (wxDocument *)m_docClassInfo->CreateObject();
     if (!m_docClassInfo)
         return (wxDocument *) NULL;
     wxDocument *doc = (wxDocument *)m_docClassInfo->CreateObject();
+    
+    if (InitDocument(doc, path, flags))
+    {
+        return doc;
+    }
+    else
+    {
+        return (wxDocument *) NULL;
+    }
+}
+
+bool wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long flags)
+{
     doc->SetFilename(path);
     doc->SetDocumentTemplate(this);
     GetDocumentManager()->AddDocument(doc);
     doc->SetCommandProcessor(doc->OnCreateCommandProcessor());
 
     if (doc->OnCreate(path, flags))
     doc->SetFilename(path);
     doc->SetDocumentTemplate(this);
     GetDocumentManager()->AddDocument(doc);
     doc->SetCommandProcessor(doc->OnCreateCommandProcessor());
 
     if (doc->OnCreate(path, flags))
-        return doc;
+        return true;
     else
     {
         if (GetDocumentManager()->GetDocuments().Member(doc))
             doc->DeleteAllViews();
     else
     {
         if (GetDocumentManager()->GetDocuments().Member(doc))
             doc->DeleteAllViews();
-        return (wxDocument *) NULL;
+        return false;
     }
 }
 
     }
 }