+ m_defaultDocumentNameCounter = 1;
+ m_flags = flags;
+ m_currentView = (wxView *) NULL;
+ m_maxDocsOpen = 10000;
+ m_fileHistory = (wxFileHistory *) NULL;
+ if (initialize)
+ Initialize();
+ sm_docManager = this;
+}
+
+wxDocManager::~wxDocManager()
+{
+ Clear();
+ if (m_fileHistory)
+ delete m_fileHistory;
+ sm_docManager = (wxDocManager*) NULL;
+}
+
+// closes the specified document
+bool wxDocManager::CloseDocument(wxDocument* doc, bool force)
+{
+ if (doc->Close() || force)
+ {
+ // Implicitly deletes the document when
+ // the last view is deleted
+ doc->DeleteAllViews();
+
+ // Check we're really deleted
+ if (m_docs.Member(doc))
+ delete doc;
+
+ return TRUE;
+ }
+ return FALSE;
+}
+
+bool wxDocManager::CloseDocuments(bool force)
+{
+ wxList::compatibility_iterator node = m_docs.GetFirst();
+ while (node)
+ {
+ wxDocument *doc = (wxDocument *)node->GetData();
+ wxList::compatibility_iterator next = node->GetNext();
+
+ if (!CloseDocument(doc, force))
+ return FALSE;
+
+ // This assumes that documents are not connected in
+ // any way, i.e. deleting one document does NOT
+ // delete another.
+ node = next;
+ }
+ return TRUE;
+}
+
+bool wxDocManager::Clear(bool force)
+{
+ if (!CloseDocuments(force))
+ return FALSE;
+
+ wxList::compatibility_iterator node = m_templates.GetFirst();
+ while (node)
+ {
+ wxDocTemplate *templ = (wxDocTemplate*) node->GetData();
+ wxList::compatibility_iterator next = node->GetNext();
+ delete templ;
+ node = next;
+ }
+ return TRUE;
+}
+
+bool wxDocManager::Initialize()
+{
+ m_fileHistory = OnCreateFileHistory();
+ return TRUE;
+}
+
+wxFileHistory *wxDocManager::OnCreateFileHistory()
+{
+ return new wxFileHistory;
+}
+
+void wxDocManager::OnFileClose(wxCommandEvent& WXUNUSED(event))
+{
+ wxDocument *doc = GetCurrentDocument();
+ if (!doc)
+ return;
+ if (doc->Close())
+ {
+ doc->DeleteAllViews();
+ if (m_docs.Member(doc))
+ delete doc;
+ }
+}
+
+void wxDocManager::OnFileCloseAll(wxCommandEvent& WXUNUSED(event))
+{
+ CloseDocuments(FALSE);
+}
+
+void wxDocManager::OnFileNew(wxCommandEvent& WXUNUSED(event))
+{
+ CreateDocument( wxT(""), wxDOC_NEW );
+}
+
+void wxDocManager::OnFileOpen(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !CreateDocument( wxT(""), 0) )
+ {
+ OnOpenFileFailure();
+ }
+}
+
+void wxDocManager::OnFileRevert(wxCommandEvent& WXUNUSED(event))
+{
+ wxDocument *doc = GetCurrentDocument();
+ if (!doc)
+ return;
+ doc->Revert();
+}
+
+void wxDocManager::OnFileSave(wxCommandEvent& WXUNUSED(event))
+{
+ wxDocument *doc = GetCurrentDocument();
+ if (!doc)
+ return;
+ doc->Save();
+}
+
+void wxDocManager::OnFileSaveAs(wxCommandEvent& WXUNUSED(event))
+{
+ wxDocument *doc = GetCurrentDocument();
+ if (!doc)
+ return;
+ doc->SaveAs();
+}
+
+void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event))
+{
+#if wxUSE_PRINTING_ARCHITECTURE
+ wxView *view = GetCurrentView();
+ if (!view)
+ return;
+
+ wxPrintout *printout = view->OnCreatePrintout();
+ if (printout)
+ {
+ wxPrinter printer;
+ printer.Print(view->GetFrame(), printout, TRUE);
+
+ delete printout;
+ }
+#endif // wxUSE_PRINTING_ARCHITECTURE