+// Extend event processing to search the view's event table
+bool wxDocManager::ProcessEvent(wxEvent& event)
+{
+ wxView* view = GetCurrentView();
+ if (view)
+ {
+ if (view->ProcessEvent(event))
+ return TRUE;
+ }
+ return wxEvtHandler::ProcessEvent(event);
+}
+
+wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags)
+{
+ wxDocTemplate **templates = new wxDocTemplate *[m_templates.Number()];
+ int i;
+ int n = 0;
+ for (i = 0; i < m_templates.Number(); i++)
+ {
+ wxDocTemplate *temp = (wxDocTemplate *)(m_templates.Nth(i)->Data());
+ if (temp->IsVisible())
+ {
+ templates[n] = temp;
+ n ++;
+ }
+ }
+ if (n == 0)
+ {
+ delete[] templates;
+ return (wxDocument *) NULL;
+ }
+
+ // If we've reached the max number of docs, close the
+ // first one.
+ if (GetDocuments().Number() >= m_maxDocsOpen)
+ {
+ wxDocument *doc = (wxDocument *)GetDocuments().First()->Data();
+ if (doc->Close())
+ {
+ // Implicitly deletes the document when
+ // the last view is deleted
+ doc->DeleteAllViews();
+
+ // Check we're really deleted
+ if (m_docs.Member(doc))
+ delete doc;
+ }
+ else
+ return (wxDocument *) NULL;
+ }
+
+ // New document: user chooses a template, unless there's only one.
+ if (flags & wxDOC_NEW)
+ {
+ if (n == 1)
+ {
+ wxDocTemplate *temp = templates[0];
+ delete[] templates;
+ wxDocument *newDoc = temp->CreateDocument(path, flags);
+ if (newDoc)
+ {
+ newDoc->SetDocumentName(temp->GetDocumentName());
+ newDoc->SetDocumentTemplate(temp);
+ newDoc->OnNewDocument();
+ }
+ return newDoc;
+ }
+
+ wxDocTemplate *temp = SelectDocumentType(templates, n);
+ delete[] templates;
+ if (temp)
+ {
+ wxDocument *newDoc = temp->CreateDocument(path, flags);
+ if (newDoc)
+ {
+ newDoc->SetDocumentName(temp->GetDocumentName());
+ newDoc->SetDocumentTemplate(temp);
+ newDoc->OnNewDocument();
+ }
+ return newDoc;
+ }
+ else
+ return (wxDocument *) NULL;
+ }
+
+ // Existing document
+ wxDocTemplate *temp = (wxDocTemplate *) NULL;
+
+ wxString path2(wxT(""));
+ if (path != wxT(""))
+ path2 = path;
+
+ if (flags & wxDOC_SILENT)
+ temp = FindTemplateForPath(path2);
+ else
+ temp = SelectDocumentPath(templates, n, path2, flags);
+
+ delete[] templates;
+
+ if (temp)
+ {
+ wxDocument *newDoc = temp->CreateDocument(path2, flags);
+ if (newDoc)
+ {
+ newDoc->SetDocumentName(temp->GetDocumentName());
+ newDoc->SetDocumentTemplate(temp);
+ if (!newDoc->OnOpenDocument(path2))
+ {
+ newDoc->DeleteAllViews();
+ // delete newDoc; // Implicitly deleted by DeleteAllViews
+ return (wxDocument *) NULL;
+ }
+ AddFileToHistory(path2);
+ }
+ return newDoc;
+ }
+
+ return (wxDocument *) NULL;
+}
+
+wxView *wxDocManager::CreateView(wxDocument *doc, long flags)
+{
+ wxDocTemplate **templates = new wxDocTemplate *[m_templates.Number()];
+ int n =0;
+ int i;
+ for (i = 0; i < m_templates.Number(); i++)
+ {
+ wxDocTemplate *temp = (wxDocTemplate *)(m_templates.Nth(i)->Data());
+ if (temp->IsVisible())
+ {
+ if (temp->GetDocumentName() == doc->GetDocumentName())
+ {
+ templates[n] = temp;
+ n ++;
+ }
+ }
+ }
+ if (n == 0)
+ {
+ delete[] templates;
+ return (wxView *) NULL;
+ }
+ if (n == 1)
+ {
+ wxDocTemplate *temp = templates[0];
+ delete[] templates;
+ wxView *view = temp->CreateView(doc, flags);
+ if (view)
+ view->SetViewName(temp->GetViewName());
+ return view;
+ }
+
+ wxDocTemplate *temp = SelectViewType(templates, n);
+ delete[] templates;
+ if (temp)
+ {
+ wxView *view = temp->CreateView(doc, flags);
+ if (view)
+ view->SetViewName(temp->GetViewName());
+ return view;
+ }
+ else
+ return (wxView *) NULL;
+}
+
+// Not yet implemented
+void wxDocManager::DeleteTemplate(wxDocTemplate *WXUNUSED(temp), long WXUNUSED(flags))
+{
+}
+
+// Not yet implemented
+bool wxDocManager::FlushDoc(wxDocument *WXUNUSED(doc))
+{
+ return FALSE;
+}
+
+wxDocument *wxDocManager::GetCurrentDocument() const
+{
+ if (m_currentView)
+ return m_currentView->GetDocument();
+ else
+ return (wxDocument *) NULL;
+}
+
+// Make a default document name
+bool wxDocManager::MakeDefaultName(wxString& name)
+{
+ name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter);
+ m_defaultDocumentNameCounter++;
+
+ return TRUE;
+}
+
+// Make a frame title (override this to do something different)
+// If docName is empty, a document is not currently active.
+wxString wxDocManager::MakeFrameTitle(wxDocument* doc)