no real changes, just minor refactoring and cleanup

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58494 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-01-29 12:52:17 +00:00
parent e61f95ea78
commit 89d94e046d
2 changed files with 166 additions and 146 deletions

View File

@@ -51,7 +51,7 @@ enum
enum enum
{ {
wxTEMPLATE_VISIBLE = 1, wxTEMPLATE_VISIBLE = 1,
wxTEMPLATE_INVISIBLE, wxTEMPLATE_INVISIBLE = 2,
wxDEFAULT_TEMPLATE_FLAGS = wxTEMPLATE_VISIBLE wxDEFAULT_TEMPLATE_FLAGS = wxTEMPLATE_VISIBLE
}; };
@@ -118,8 +118,10 @@ public:
// By default, creates a base wxCommandProcessor. // By default, creates a base wxCommandProcessor.
virtual wxCommandProcessor *OnCreateCommandProcessor(); virtual wxCommandProcessor *OnCreateCommandProcessor();
virtual wxCommandProcessor *GetCommandProcessor() const { return m_commandProcessor; } virtual wxCommandProcessor *GetCommandProcessor() const
virtual void SetCommandProcessor(wxCommandProcessor *proc) { m_commandProcessor = proc; } { return m_commandProcessor; }
virtual void SetCommandProcessor(wxCommandProcessor *proc)
{ m_commandProcessor = proc; }
// Called after a view is added or removed. The default implementation // Called after a view is added or removed. The default implementation
// deletes the document if this is there are no more views. // deletes the document if this is there are no more views.
@@ -145,8 +147,10 @@ public:
// Other stuff // Other stuff
virtual wxDocManager *GetDocumentManager() const; virtual wxDocManager *GetDocumentManager() const;
virtual wxDocTemplate *GetDocumentTemplate() const { return m_documentTemplate; } virtual wxDocTemplate *GetDocumentTemplate() const
virtual void SetDocumentTemplate(wxDocTemplate *temp) { m_documentTemplate = temp; } { return m_documentTemplate; }
virtual void SetDocumentTemplate(wxDocTemplate *temp)
{ m_documentTemplate = temp; }
// Get the document name to be shown to the user: the title if there is // Get the document name to be shown to the user: the title if there is
// any, otherwise the filename if the document was saved and, finally, // any, otherwise the filename if the document was saved and, finally,
@@ -204,7 +208,9 @@ public:
wxWindow *GetFrame() const { return m_viewFrame ; } wxWindow *GetFrame() const { return m_viewFrame ; }
void SetFrame(wxWindow *frame) { m_viewFrame = frame; } void SetFrame(wxWindow *frame) { m_viewFrame = frame; }
virtual void OnActivateView(bool activate, wxView *activeView, wxView *deactiveView); virtual void OnActivateView(bool activate,
wxView *activeView,
wxView *deactiveView);
virtual void OnDraw(wxDC *dc) = 0; virtual void OnDraw(wxDC *dc) = 0;
virtual void OnPrint(wxDC *dc, wxObject *info); virtual void OnPrint(wxDC *dc, wxObject *info);
virtual void OnUpdate(wxView *sender, wxObject *hint = NULL); virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
@@ -278,13 +284,16 @@ public:
// Helper method for CreateDocument; also allows you to do your own document // Helper method for CreateDocument; also allows you to do your own document
// creation // creation
virtual bool InitDocument(wxDocument* doc, const wxString& path, long flags = 0); virtual bool InitDocument(wxDocument* doc,
const wxString& path,
long flags = 0);
wxString GetDefaultExtension() const { return m_defaultExt; } wxString GetDefaultExtension() const { return m_defaultExt; }
wxString GetDescription() const { return m_description; } wxString GetDescription() const { return m_description; }
wxString GetDirectory() const { return m_directory; } wxString GetDirectory() const { return m_directory; }
wxDocManager *GetDocumentManager() const { return m_documentManager; } wxDocManager *GetDocumentManager() const { return m_documentManager; }
void SetDocumentManager(wxDocManager *manager) { m_documentManager = manager; } void SetDocumentManager(wxDocManager *manager)
{ m_documentManager = manager; }
wxString GetFileFilter() const { return m_fileFilter; } wxString GetFileFilter() const { return m_fileFilter; }
long GetFlags() const { return m_flags; } long GetFlags() const { return m_flags; }
virtual wxString GetViewName() const { return m_viewTypeName; } virtual wxString GetViewName() const { return m_viewTypeName; }
@@ -296,7 +305,7 @@ public:
void SetDefaultExtension(const wxString& ext) { m_defaultExt = ext; } void SetDefaultExtension(const wxString& ext) { m_defaultExt = ext; }
void SetFlags(long flags) { m_flags = flags; } void SetFlags(long flags) { m_flags = flags; }
bool IsVisible() const { return ((m_flags & wxTEMPLATE_VISIBLE) == wxTEMPLATE_VISIBLE); } bool IsVisible() const { return (m_flags & wxTEMPLATE_VISIBLE) != 0; }
wxClassInfo* GetDocClassInfo() const { return m_docClassInfo; } wxClassInfo* GetDocClassInfo() const { return m_docClassInfo; }
wxClassInfo* GetViewClassInfo() const { return m_viewClassInfo; } wxClassInfo* GetViewClassInfo() const { return m_viewClassInfo; }
@@ -317,9 +326,11 @@ protected:
wxClassInfo* m_docClassInfo; wxClassInfo* m_docClassInfo;
wxClassInfo* m_viewClassInfo; wxClassInfo* m_viewClassInfo;
// Called by CreateDocument and CreateView to create the actual document/view object. // Called by CreateDocument and CreateView to create the actual
// By default uses the ClassInfo provided to the constructor. Override these functions // document/view object.
// to provide a different method of creation. //
// By default uses the ClassInfo provided to the constructor. Override
// these functions to provide a different method of creation.
virtual wxDocument *DoCreateDocument(); virtual wxDocument *DoCreateDocument();
virtual wxView *DoCreateView(); virtual wxView *DoCreateView();
@@ -458,6 +469,10 @@ protected:
// hook the currently active view into event handlers chain here // hook the currently active view into event handlers chain here
virtual bool TryValidator(wxEvent& event); virtual bool TryValidator(wxEvent& event);
// return the command processor for the current document, if any
wxCommandProcessor *GetCurrentCommandProcessor() const;
int m_defaultDocumentNameCounter; int m_defaultDocumentNameCounter;
int m_maxDocsOpen; int m_maxDocsOpen;
wxList m_docs; wxList m_docs;
@@ -573,10 +588,13 @@ class WXDLLIMPEXP_CORE wxDocPrintout : public wxPrintout
{ {
public: public:
wxDocPrintout(wxView *view = NULL, const wxString& title = wxT("Printout")); wxDocPrintout(wxView *view = NULL, const wxString& title = wxT("Printout"));
bool OnPrintPage(int page);
bool HasPage(int page); // implement wxPrintout methods
bool OnBeginDocument(int startPage, int endPage); virtual bool OnPrintPage(int page);
void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo); virtual bool HasPage(int page);
virtual bool OnBeginDocument(int startPage, int endPage);
virtual void GetPageInfo(int *minPage, int *maxPage,
int *selPageFrom, int *selPageTo);
virtual wxView *GetView() { return m_printoutView; } virtual wxView *GetView() { return m_printoutView; }
@@ -655,16 +673,18 @@ inline size_t wxFileHistory::GetNoHistoryFiles() const
} }
#endif // WXWIN_COMPATIBILITY_2_6 #endif // WXWIN_COMPATIBILITY_2_6
// For compatibility with existing file formats:
// converts from/to a stream to/from a temporary file.
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
// For compatibility with existing file formats: bool WXDLLIMPEXP_CORE
// converts from/to a stream to/from a temporary file. wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream);
bool WXDLLIMPEXP_CORE wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream); bool WXDLLIMPEXP_CORE
bool WXDLLIMPEXP_CORE wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename); wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename);
#else #else
// For compatibility with existing file formats: bool WXDLLIMPEXP_CORE
// converts from/to a stream to/from a temporary file. wxTransferFileToStream(const wxString& filename, wxOutputStream& stream);
bool WXDLLIMPEXP_CORE wxTransferFileToStream(const wxString& filename, wxOutputStream& stream); bool WXDLLIMPEXP_CORE
bool WXDLLIMPEXP_CORE wxTransferStreamToFile(wxInputStream& stream, const wxString& filename); wxTransferStreamToFile(wxInputStream& stream, const wxString& filename);
#endif // wxUSE_STD_IOSTREAM #endif // wxUSE_STD_IOSTREAM

View File

@@ -156,8 +156,7 @@ wxDocument::~wxDocument()
{ {
DeleteContents(); DeleteContents();
if (m_commandProcessor) delete m_commandProcessor;
delete m_commandProcessor;
if (GetDocumentManager()) if (GetDocumentManager())
GetDocumentManager()->RemoveDocument(this); GetDocumentManager()->RemoveDocument(this);
@@ -170,10 +169,10 @@ wxDocument::~wxDocument()
bool wxDocument::Close() bool wxDocument::Close()
{ {
if (OnSaveModified()) if ( !OnSaveModified() )
return OnCloseDocument();
else
return false; return false;
return OnCloseDocument();
} }
bool wxDocument::OnCloseDocument() bool wxDocument::OnCloseDocument()
@@ -233,9 +232,10 @@ bool wxDocument::DeleteAllViews()
wxView *wxDocument::GetFirstView() const wxView *wxDocument::GetFirstView() const
{ {
if (m_documentViews.GetCount() == 0) if ( m_documentViews.empty() )
return NULL; return NULL;
return (wxView *)m_documentViews.GetFirst()->GetData();
return static_cast<wxView *>(m_documentViews.GetFirst()->GetData());
} }
wxDocManager *wxDocument::GetDocumentManager() const wxDocManager *wxDocument::GetDocumentManager() const
@@ -276,15 +276,17 @@ bool wxDocument::SaveAs()
if (!docTemplate) if (!docTemplate)
return false; return false;
#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__) #ifdef wxHAS_MULTIPLE_FILEDLG_FILTERS
wxString filter = docTemplate->GetDescription() + wxT(" (") + docTemplate->GetFileFilter() + wxT(")|") + docTemplate->GetFileFilter(); wxString filter = docTemplate->GetDescription() + wxT(" (") +
docTemplate->GetFileFilter() + wxT(")|") +
docTemplate->GetFileFilter();
// Now see if there are some other template with identical view and document // Now see if there are some other template with identical view and document
// classes, whose filters may also be used. // classes, whose filters may also be used.
if (docTemplate->GetViewClassInfo() && docTemplate->GetDocClassInfo()) if (docTemplate->GetViewClassInfo() && docTemplate->GetDocClassInfo())
{ {
wxList::compatibility_iterator node = docTemplate->GetDocumentManager()->GetTemplates().GetFirst(); wxList::compatibility_iterator
node = docTemplate->GetDocumentManager()->GetTemplates().GetFirst();
while (node) while (node)
{ {
wxDocTemplate *t = (wxDocTemplate*) node->GetData(); wxDocTemplate *t = (wxDocTemplate*) node->GetData();
@@ -297,7 +299,8 @@ bool wxDocument::SaveAs()
if ( !filter.empty() ) if ( !filter.empty() )
filter << wxT('|'); filter << wxT('|');
filter << t->GetDescription() << wxT(" (") << t->GetFileFilter() << wxT(") |") filter << t->GetDescription()
<< wxT(" (") << t->GetFileFilter() << wxT(") |")
<< t->GetFileFilter(); << t->GetFileFilter();
} }
@@ -307,6 +310,7 @@ bool wxDocument::SaveAs()
#else #else
wxString filter = docTemplate->GetFileFilter() ; wxString filter = docTemplate->GetFileFilter() ;
#endif #endif
wxString defaultDir = docTemplate->GetDirectory(); wxString defaultDir = docTemplate->GetDirectory();
if ( defaultDir.empty() ) if ( defaultDir.empty() )
{ {
@@ -324,7 +328,7 @@ bool wxDocument::SaveAs()
GetDocumentWindow()); GetDocumentWindow());
if (fileName.empty()) if (fileName.empty())
return false; return false; // cancelled by user
wxString ext; wxString ext;
wxFileName::SplitPath(fileName, NULL, NULL, &ext); wxFileName::SplitPath(fileName, NULL, NULL, &ext);
@@ -342,17 +346,15 @@ bool wxDocument::SaveAs()
SetTitle(wxFileNameFromPath(fileName)); SetTitle(wxFileNameFromPath(fileName));
SetFilename(fileName, true); // will call OnChangeFileName automatically SetFilename(fileName, true); // will call OnChangeFileName automatically
// A file that doesn't use the default extension of its document template cannot be opened // A file that doesn't use the default extension of its document template
// via the FileHistory, so we do not add it. // cannot be opened via the FileHistory, so we do not add it.
if (docTemplate->FileMatchesTemplate(fileName)) if (docTemplate->FileMatchesTemplate(fileName))
{ {
GetDocumentManager()->AddFileToHistory(fileName); GetDocumentManager()->AddFileToHistory(fileName);
} }
else //else: the user will probably not be able to open the file again, so we
{ // could warn about the wrong file-extension here
// The user will probably not be able to open the file again, so
// we could warn about the wrong file-extension here.
}
return true; return true;
} }
@@ -455,11 +457,9 @@ wxString wxDocument::DoGetUserReadableName() const
wxWindow *wxDocument::GetDocumentWindow() const wxWindow *wxDocument::GetDocumentWindow() const
{ {
wxView *view = GetFirstView(); wxView * const view = GetFirstView();
if (view)
return view->GetFrame(); return view ? view->GetFrame() : wxTheApp->GetTopWindow();
else
return wxTheApp->GetTopWindow();
} }
wxCommandProcessor *wxDocument::OnCreateCommandProcessor() wxCommandProcessor *wxDocument::OnCreateCommandProcessor()
@@ -655,7 +655,9 @@ bool wxView::TryValidator(wxEvent& event)
return doc && doc->ProcessEventHere(event); return doc && doc->ProcessEventHere(event);
} }
void wxView::OnActivateView(bool WXUNUSED(activate), wxView *WXUNUSED(activeView), wxView *WXUNUSED(deactiveView)) void wxView::OnActivateView(bool WXUNUSED(activate),
wxView *WXUNUSED(activeView),
wxView *WXUNUSED(deactiveView))
{ {
} }
@@ -770,12 +772,10 @@ wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long flags)
if (doc->OnCreate(path, flags)) if (doc->OnCreate(path, flags))
return true; return true;
else
{ if (GetDocumentManager()->GetDocuments().Member(doc))
if (GetDocumentManager()->GetDocuments().Member(doc)) doc->DeleteAllViews();
doc->DeleteAllViews(); return false;
return false;
}
} }
wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags) wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)
@@ -814,7 +814,7 @@ wxDocument *wxDocTemplate::DoCreateDocument()
if (!m_docClassInfo) if (!m_docClassInfo)
return NULL; return NULL;
return (wxDocument *)m_docClassInfo->CreateObject(); return static_cast<wxDocument *>(m_docClassInfo->CreateObject());
} }
wxView *wxDocTemplate::DoCreateView() wxView *wxDocTemplate::DoCreateView()
@@ -822,7 +822,7 @@ wxView *wxDocTemplate::DoCreateView()
if (!m_viewClassInfo) if (!m_viewClassInfo)
return NULL; return NULL;
return (wxView *)m_viewClassInfo->CreateObject(); return static_cast<wxView *>(m_viewClassInfo->CreateObject());
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -885,19 +885,18 @@ wxDocManager::~wxDocManager()
// closes the specified document // closes the specified document
bool wxDocManager::CloseDocument(wxDocument* doc, bool force) bool wxDocManager::CloseDocument(wxDocument* doc, bool force)
{ {
if (doc->Close() || force) if ( !doc->Close() && !force )
{ return false;
// Implicitly deletes the document when
// the last view is deleted
doc->DeleteAllViews();
// Check we're really deleted // Implicitly deletes the document when
if (m_docs.Member(doc)) // the last view is deleted
delete doc; doc->DeleteAllViews();
return true; // Check we're really deleted
} if (m_docs.Member(doc))
return false; delete doc;
return true;
} }
bool wxDocManager::CloseDocuments(bool force) bool wxDocManager::CloseDocuments(bool force)
@@ -986,7 +985,7 @@ void wxDocManager::OnFileNew(wxCommandEvent& WXUNUSED(event))
void wxDocManager::OnFileOpen(wxCommandEvent& WXUNUSED(event)) void wxDocManager::OnFileOpen(wxCommandEvent& WXUNUSED(event))
{ {
if ( !CreateDocument( wxEmptyString, 0) ) if ( !CreateDocument("") )
{ {
OnOpenFileFailure(); OnOpenFileFailure();
} }
@@ -1045,16 +1044,18 @@ void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event))
if (printout) if (printout)
{ {
// Pass two printout objects: for preview, and possible printing. // Pass two printout objects: for preview, and possible printing.
wxPrintPreviewBase *preview = new wxPrintPreview(printout, view->OnCreatePrintout()); wxPrintPreviewBase *
preview = new wxPrintPreview(printout, view->OnCreatePrintout());
if ( !preview->Ok() ) if ( !preview->Ok() )
{ {
delete preview; delete preview;
wxMessageBox( _("Sorry, print preview needs a printer to be installed.") ); wxLogError(_("Print preview creation failed."));
return; return;
} }
wxPreviewFrame *frame = new wxPreviewFrame(preview, (wxFrame *)wxTheApp->GetTopWindow(), _("Print Preview"), wxPreviewFrame *
wxPoint(100, 100), wxSize(600, 650)); frame = new wxPreviewFrame(preview, wxTheApp->GetTopWindow(),
_("Print Preview"));
frame->Centre(wxBOTH); frame->Centre(wxBOTH);
frame->Initialize(); frame->Initialize();
frame->Show(true); frame->Show(true);
@@ -1064,24 +1065,26 @@ void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event))
void wxDocManager::OnUndo(wxCommandEvent& event) void wxDocManager::OnUndo(wxCommandEvent& event)
{ {
wxDocument *doc = GetCurrentDocument(); wxCommandProcessor * const cmdproc = GetCurrentCommandProcessor();
if (!doc) if ( !cmdproc )
return; {
if (doc->GetCommandProcessor())
doc->GetCommandProcessor()->Undo();
else
event.Skip(); event.Skip();
return;
}
cmdproc->Undo();
} }
void wxDocManager::OnRedo(wxCommandEvent& event) void wxDocManager::OnRedo(wxCommandEvent& event)
{ {
wxDocument *doc = GetCurrentDocument(); wxCommandProcessor * const cmdproc = GetCurrentCommandProcessor();
if (!doc) if ( !cmdproc )
return; {
if (doc->GetCommandProcessor())
doc->GetCommandProcessor()->Redo();
else
event.Skip(); event.Skip();
return;
}
cmdproc->Redo();
} }
// Handlers for UI update commands // Handlers for UI update commands
@@ -1113,30 +1116,28 @@ void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event)
void wxDocManager::OnUpdateUndo(wxUpdateUIEvent& event) void wxDocManager::OnUpdateUndo(wxUpdateUIEvent& event)
{ {
wxDocument *doc = GetCurrentDocument(); wxCommandProcessor * const cmdproc = GetCurrentCommandProcessor();
if (!doc) if ( !cmdproc )
event.Enable(false);
else if (!doc->GetCommandProcessor())
event.Skip();
else
{ {
event.Enable( doc->GetCommandProcessor()->CanUndo() ); event.Enable(false);
doc->GetCommandProcessor()->SetMenuStrings(); return;
} }
event.Enable(cmdproc->CanUndo());
cmdproc->SetMenuStrings();
} }
void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event) void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event)
{ {
wxDocument *doc = GetCurrentDocument(); wxCommandProcessor * const cmdproc = GetCurrentCommandProcessor();
if (!doc) if ( !cmdproc )
event.Enable(false);
else if (!doc->GetCommandProcessor())
event.Skip();
else
{ {
event.Enable( doc->GetCommandProcessor()->CanRedo() ); event.Enable(false);
doc->GetCommandProcessor()->SetMenuStrings(); return;
} }
event.Enable(cmdproc->CanRedo());
cmdproc->SetMenuStrings();
} }
wxView *wxDocManager::GetCurrentView() const wxView *wxDocManager::GetCurrentView() const
@@ -1328,11 +1329,14 @@ bool wxDocManager::FlushDoc(wxDocument *WXUNUSED(doc))
wxDocument *wxDocManager::GetCurrentDocument() const wxDocument *wxDocManager::GetCurrentDocument() const
{ {
wxView *view = GetCurrentView(); wxView * const view = GetCurrentView();
if (view) return view ? view->GetDocument() : NULL;
return view->GetDocument(); }
else
return NULL; wxCommandProcessor *wxDocManager::GetCurrentCommandProcessor() const
{
wxDocument * const doc = GetCurrentDocument();
return doc ? doc->GetCommandProcessor() : NULL;
} }
// Make a default name for a new document // Make a default name for a new document
@@ -1480,12 +1484,10 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
long WXUNUSED(flags), long WXUNUSED(flags),
bool WXUNUSED(save)) bool WXUNUSED(save))
{ {
// We can only have multiple filters in Windows and GTK #ifdef wxHAS_MULTIPLE_FILEDLG_FILTERS
#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
wxString descrBuf; wxString descrBuf;
int i; for (int i = 0; i < noTemplates; i++)
for (i = 0; i < noTemplates; i++)
{ {
if (templates[i]->IsVisible()) if (templates[i]->IsVisible())
{ {
@@ -1526,8 +1528,10 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
else else
msgTitle = wxString(_("File error")); msgTitle = wxString(_("File error"));
(void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK | wxICON_EXCLAMATION | wxCENTRE, wxMessageBox(_("Sorry, could not open this file."),
parent); msgTitle,
wxOK | wxICON_EXCLAMATION | wxCENTRE,
parent);
path = wxEmptyString; path = wxEmptyString;
return NULL; return NULL;
@@ -1545,16 +1549,18 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
theTemplate = FindTemplateForPath(path); theTemplate = FindTemplateForPath(path);
if ( !theTemplate ) if ( !theTemplate )
{ {
// Since we do not add files with non-default extensions to the FileHistory this // Since we do not add files with non-default extensions to the
// can only happen if the application changes the allowed templates in runtime. // file history this can only happen if the application changes the
(void)wxMessageBox(_("Sorry, the format for this file is unknown."), // allowed templates in runtime.
_("Open File"), wxMessageBox(_("Sorry, the format for this file is unknown."),
wxOK | wxICON_EXCLAMATION | wxCENTRE, wxFindSuitableParent()); _("Open File"),
wxOK | wxICON_EXCLAMATION | wxCENTRE,
parent);
} }
} }
else else
{ {
path = wxEmptyString; path.clear();
} }
return theTemplate; return theTemplate;
@@ -1564,7 +1570,7 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates,
int noTemplates, bool sort) int noTemplates, bool sort)
{ {
wxArrayString strings; wxArrayString strings;
wxDocTemplate **data = new wxDocTemplate *[noTemplates]; wxScopedArray<wxDocTemplate *> data(new wxDocTemplate *[noTemplates]);
int i; int i;
int n = 0; int n = 0;
@@ -1631,13 +1637,11 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates,
_("Select a document template"), _("Select a document template"),
_("Templates"), _("Templates"),
strings, strings,
(void **)data, (void **)data.get(),
wxFindSuitableParent() wxFindSuitableParent()
); );
} }
delete[] data;
return theTemplate; return theTemplate;
} }
@@ -1645,7 +1649,7 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates,
int noTemplates, bool sort) int noTemplates, bool sort)
{ {
wxArrayString strings; wxArrayString strings;
wxDocTemplate **data = new wxDocTemplate *[noTemplates]; wxScopedArray<wxDocTemplate *> data(new wxDocTemplate *[noTemplates]);
int i; int i;
int n = 0; int n = 0;
@@ -1708,13 +1712,12 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates,
_("Select a document view"), _("Select a document view"),
_("Views"), _("Views"),
strings, strings,
(void **)data, (void **)data.get(),
wxFindSuitableParent() wxFindSuitableParent()
); );
} }
delete[] data;
return theTemplate; return theTemplate;
} }
@@ -1806,26 +1809,22 @@ void wxDocChildFrame::OnActivate(wxActivateEvent& event)
void wxDocChildFrame::OnCloseWindow(wxCloseEvent& event) void wxDocChildFrame::OnCloseWindow(wxCloseEvent& event)
{ {
if (m_childView) if ( !m_childView )
return;
// passing false to Close() means to not delete associated window
if ( event.CanVeto() && !m_childView->Close(false) )
{ {
bool ans = event.CanVeto()
? m_childView->Close(false) // false means don't delete associated window
: true; // Must delete.
if (ans)
{
m_childView->Activate(false);
delete m_childView;
m_childView = NULL;
m_childDocument = NULL;
this->Destroy();
}
else
event.Veto();
}
else
event.Veto(); event.Veto();
return;
}
m_childView->Activate(false);
delete m_childView;
m_childView = NULL;
m_childDocument = NULL;
Destroy();
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1919,7 +1918,7 @@ void wxDocParentFrame::OnCloseWindow(wxCloseEvent& event)
{ {
if (m_docManager->Clear(!event.CanVeto())) if (m_docManager->Clear(!event.CanVeto()))
{ {
this->Destroy(); Destroy();
} }
else else
event.Veto(); event.Veto();
@@ -1985,7 +1984,8 @@ bool wxDocPrintout::OnBeginDocument(int startPage, int endPage)
return true; return true;
} }
void wxDocPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) void wxDocPrintout::GetPageInfo(int *minPage, int *maxPage,
int *selPageFrom, int *selPageTo)
{ {
*minPage = 1; *minPage = 1;
*maxPage = 1; *maxPage = 1;