Index: census_document.cpp
===================================================================
RCS file: /sources/lmi/lmi/census_document.cpp,v
retrieving revision 1.19
diff -U 3 -r1.19 census_document.cpp
--- census_document.cpp	27 Dec 2008 02:56:37 -0000	1.19
+++ census_document.cpp	15 Mar 2009 04:49:18 -0000
@@ -39,13 +39,51 @@
 
 IMPLEMENT_DYNAMIC_CLASS(CensusDocument, wxDocument)
 
-CensusDocument::CensusDocument()
-    :wxDocument()
-{
+CensusDocument::CensusDocument(wxDocument* parent)
+    :wxDocument      (parent)
+    ,m_documentParent(parent)
+{
+#if 0 // Exposition only.
+    // This is needed only for closing and deleting later.
+    if(m_documentParent)
+        m_documentParent->m_documentChildren->Insert(this);
+#endif // 0
 }
 
 CensusDocument::~CensusDocument()
 {
+#if 0 // Exposition only.
+    m_documentChildren->DeleteContents(true);
+    // Maybe DeleteAllViews should be called on each child?
+    m_documentChildren->Clear();
+
+    if(m_documentParent) {
+        m_documentParent->m_documentChildren->DeleteContents(true);
+        // Maybe DeleteAllViews should be called on each child?
+        m_documentParent->m_documentChildren->Clear();
+        }
+#endif // 0
+}
+
+bool CensusDocument::OnCloseDocument()
+{
+warning() << "CensusDocument::OnCloseDocument()" << LMI_FLUSH;
+    const wxList::iterator end = m_documentChildren.end();
+    for ( wxList::iterator i = m_documentChildren.begin(); i != end; ++i )
+    {
+        wxDocument *doc = (wxDocument *)*i;
+warning() << "Handling child " << doc << LMI_FLUSH;
+        if ( !doc->DeleteAllViews() )
+            return false;
+        // Isn't this done implicitly by DeleteAllViews()?
+#if 0
+        if ( !doc->Close() )
+            return false;
+#endif // 0            
+    }
+
+warning() << "CensusDocument::OnCloseDocument() returning normally." << LMI_FLUSH;
+    return wxDocument::OnCloseDocument();
 }
 
 wxListView& CensusDocument::PredominantViewWindow() const
Index: census_document.hpp
===================================================================
RCS file: /sources/lmi/lmi/census_document.hpp,v
retrieving revision 1.14
diff -U 3 -r1.14 census_document.hpp
--- census_document.hpp	27 Dec 2008 02:56:37 -0000	1.14
+++ census_document.hpp	15 Mar 2009 04:49:18 -0000
@@ -33,6 +33,8 @@
 
 #include <wx/docview.h>
 
+#include <cstddef> // NULL
+
 class WXDLLIMPEXP_FWD_CORE wxListView;
 
 class CensusDocument
@@ -42,13 +44,24 @@
     friend class CensusView;
 
   public:
-    CensusDocument();
+    CensusDocument(wxDocument* parent = NULL);
     virtual ~CensusDocument();
 
+    wxDocument* GetParent() const {
+        return m_documentParent;
+        }
+
+    // Private members to add to class wxDocument: public here only
+    // so that other wxDocument-derived classes can use them.
+    wxDocument* m_documentParent;
+// Not a template?    wxList<wxDocument> m_documentChildren;
+    wxList m_documentChildren;
+
   private:
     wxListView& PredominantViewWindow() const;
 
     // wxDocument overrides.
+    virtual bool OnCloseDocument();
     virtual bool OnCreate(wxString const& filename, long int flags);
     virtual bool OnNewDocument();
     virtual bool DoOpenDocument(wxString const& filename);
Index: census_view.cpp
===================================================================
RCS file: /sources/lmi/lmi/census_view.cpp,v
retrieving revision 1.87
diff -U 3 -r1.87 census_view.cpp
--- census_view.cpp	27 Dec 2008 02:56:38 -0000	1.87
+++ census_view.cpp	15 Mar 2009 04:49:19 -0000
@@ -867,6 +867,7 @@
     IllustrationView& illview = MakeNewIllustrationDocAndView
         (document().GetDocumentManager()
         ,serial_file_path(base_filename(), name, index, "ill").string().c_str()
+        ,&document()
         );
     illview.Run(&cell_parms()[index]);
 }
@@ -888,6 +889,7 @@
         IllustrationView& illview = MakeNewIllustrationDocAndView
             (document().GetDocumentManager()
             ,serial_file_path(base_filename(), name, -1, "ill").string().c_str()
+            ,&document()
             );
 
         // This is necessary for the view to be able to print.
Index: illustration_document.cpp
===================================================================
RCS file: /sources/lmi/lmi/illustration_document.cpp,v
retrieving revision 1.24
diff -U 3 -r1.24 illustration_document.cpp
--- illustration_document.cpp	13 Mar 2009 16:21:30 -0000	1.24
+++ illustration_document.cpp	15 Mar 2009 04:49:19 -0000
@@ -38,13 +38,48 @@
 
 IMPLEMENT_DYNAMIC_CLASS(IllustrationDocument, wxDocument)
 
-IllustrationDocument::IllustrationDocument()
-    :is_phony_(false)
-{
+#include "census_document.hpp" // Only for proposed new wxDocument members.
+
+IllustrationDocument::IllustrationDocument(wxDocument* parent)
+    :wxDocument      (parent)
+    ,m_documentParent(parent)
+    ,is_phony_       (false)
+{
+    // This is needed only for closing and deleting later.
+    if(m_documentParent)
+        // Cast only because wxDocument lacks m_documentChildren.
+        ((CensusDocument*)m_documentParent)->m_documentChildren.Insert(this);
 }
 
 IllustrationDocument::~IllustrationDocument()
 {
+#if 0
+    // Wait--does this really make sense? This says that closing
+    // any child forces all siblings to close. Instead, the behavior
+    // desired is: closing the parent forces all its children to close.
+    // But that's what the parent's OnCloseDocument() does, so maybe
+    // this just does some sort of necessary cleanup?
+    if(m_documentParent) {
+        // Cast only because wxDocument lacks m_documentChildren.
+        ((CensusDocument*)m_documentParent)->m_documentChildren.DeleteContents(true);
+        // Maybe DeleteAllViews should be called on each child?
+        // Cast only because wxDocument lacks m_documentChildren.
+        ((CensusDocument*)m_documentParent)->m_documentChildren.Clear();
+        }
+#endif // 0
+}
+
+bool IllustrationDocument::OnCloseDocument()
+{
+    const wxList::iterator end = m_documentChildren.end();
+    for ( wxList::iterator i = m_documentChildren.begin(); i != end; ++i )
+    {
+        wxDocument *doc = (wxDocument *)*i;
+        if ( !doc->Close() )
+            return false;
+    }
+
+    return wxDocument::OnCloseDocument();
 }
 
 IllustrationView& IllustrationDocument::PredominantView() const
Index: illustration_document.hpp
===================================================================
RCS file: /sources/lmi/lmi/illustration_document.hpp,v
retrieving revision 1.16
diff -U 3 -r1.16 illustration_document.hpp
--- illustration_document.hpp	13 Mar 2009 16:21:36 -0000	1.16
+++ illustration_document.hpp	15 Mar 2009 04:49:19 -0000
@@ -33,6 +33,8 @@
 
 #include <wx/docview.h>
 
+#include <cstddef> // NULL
+
 /// WX !! The wx document-view implementation has no notion of 'child'
 /// documents, but sometimes lmi creates a document that logically is
 /// a 'child' of a parent CensusDocument: it corresponds to no actual,
@@ -56,15 +58,26 @@
     friend class IllustrationView;
 
   public:
-    IllustrationDocument();
+    IllustrationDocument(wxDocument* parent = NULL);
     virtual ~IllustrationDocument();
 
+    wxDocument* GetParent() const {
+        return m_documentParent;
+        }
+
     IllustrationView& PredominantView() const;
 
+    // Private members to add to class wxDocument: public here only
+    // so that other wxDocument-derived classes can use them.
+    wxDocument* m_documentParent;
+// Not a template?    wxList<wxDocument> m_documentChildren;
+    wxList m_documentChildren;
+
   private:
     wxHtmlWindow& PredominantViewWindow() const;
 
     // wxDocument overrides.
+    virtual bool OnCloseDocument();
     virtual bool OnCreate(wxString const& filename, long int flags);
 #if !wxCHECK_VERSION(2,9,0)
     virtual bool OnNewDocument();
Index: illustration_view.cpp
===================================================================
RCS file: /sources/lmi/lmi/illustration_view.cpp,v
retrieving revision 1.105
diff -U 3 -r1.105 illustration_view.cpp
--- illustration_view.cpp	14 Mar 2009 13:41:37 -0000	1.105
+++ illustration_view.cpp	15 Mar 2009 04:49:19 -0000
@@ -323,9 +323,13 @@
 /// This could be generalized as a function template if that ever
 /// becomes useful.
 
+// Include only because wxDocument lacks m_documentChildren.
+#include "census_document.hpp"
+
 IllustrationView& MakeNewIllustrationDocAndView
     (wxDocManager* dm
     ,char const*   filename
+    ,wxDocument*   parent
     )
 {
     LMI_ASSERT(0 != dm);
@@ -342,6 +346,12 @@
     IllustrationDocument& illdoc =
         safely_dereference_as<IllustrationDocument>(new_document)
         ;
+
+    // Really want wx doc-view to handle this, passing parent to
+    // wxDocument ctor:
+    illdoc.m_documentParent = parent;
+    ((CensusDocument*)illdoc.m_documentParent)->m_documentChildren.Insert(new_document);
+
     illdoc.SetFilename(filename, true);
     illdoc.Modify(false);
     illdoc.SetDocumentSaved(true);
@@ -381,6 +391,7 @@
                 IllustrationView& illview = MakeNewIllustrationDocAndView
                     (dm
                     ,(c.custom_output_filename() + ".ill").c_str()
+                    ,0 // TODO ?? Is this right?
                     );
                 illview.SetLedger(z.principal_ledger());
                 illview.DisplaySelectedValuesAsHtml();
Index: illustration_view.hpp
===================================================================
RCS file: /sources/lmi/lmi/illustration_view.hpp,v
retrieving revision 1.38
diff -U 3 -r1.38 illustration_view.hpp
--- illustration_view.hpp	27 Dec 2008 02:56:45 -0000	1.38
+++ illustration_view.hpp	15 Mar 2009 04:49:19 -0000
@@ -106,6 +106,7 @@
 IllustrationView& MakeNewIllustrationDocAndView
     (wxDocManager* dm
     ,char const*   filename
+    ,wxDocument*   parent
     );
 
 bool custom_io_0_run_if_file_exists(wxDocManager*);
