enum
{
wxTEMPLATE_VISIBLE = 1,
- wxTEMPLATE_INVISIBLE,
+ wxTEMPLATE_INVISIBLE = 2,
wxDEFAULT_TEMPLATE_FLAGS = wxTEMPLATE_VISIBLE
};
// By default, creates a base wxCommandProcessor.
virtual wxCommandProcessor *OnCreateCommandProcessor();
- virtual wxCommandProcessor *GetCommandProcessor() const { return m_commandProcessor; }
- virtual void SetCommandProcessor(wxCommandProcessor *proc) { m_commandProcessor = proc; }
+ virtual wxCommandProcessor *GetCommandProcessor() const
+ { return m_commandProcessor; }
+ virtual void SetCommandProcessor(wxCommandProcessor *proc)
+ { m_commandProcessor = proc; }
// Called after a view is added or removed. The default implementation
// deletes the document if this is there are no more views.
// Other stuff
virtual wxDocManager *GetDocumentManager() const;
- virtual wxDocTemplate *GetDocumentTemplate() const { return m_documentTemplate; }
- virtual void SetDocumentTemplate(wxDocTemplate *temp) { m_documentTemplate = temp; }
+ virtual wxDocTemplate *GetDocumentTemplate() const
+ { 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
// any, otherwise the filename if the document was saved and, finally,
wxWindow *GetFrame() const { return m_viewFrame ; }
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 OnPrint(wxDC *dc, wxObject *info);
virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
// Helper method for CreateDocument; also allows you to do your own document
// 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 GetDescription() const { return m_description; }
wxString GetDirectory() const { return m_directory; }
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; }
long GetFlags() const { return m_flags; }
virtual wxString GetViewName() const { return m_viewTypeName; }
void SetDefaultExtension(const wxString& ext) { m_defaultExt = ext; }
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* GetViewClassInfo() const { return m_viewClassInfo; }
wxClassInfo* m_docClassInfo;
wxClassInfo* m_viewClassInfo;
- // Called by CreateDocument and CreateView to create the actual document/view object.
- // By default uses the ClassInfo provided to the constructor. Override these functions
- // to provide a different method of creation.
+ // Called by CreateDocument and CreateView to create the actual
+ // document/view object.
+ //
+ // By default uses the ClassInfo provided to the constructor. Override
+ // these functions to provide a different method of creation.
virtual wxDocument *DoCreateDocument();
virtual wxView *DoCreateView();
// hook the currently active view into event handlers chain here
virtual bool TryValidator(wxEvent& event);
+ // return the command processor for the current document, if any
+ wxCommandProcessor *GetCurrentCommandProcessor() const;
+
+
int m_defaultDocumentNameCounter;
int m_maxDocsOpen;
wxList m_docs;
{
public:
wxDocPrintout(wxView *view = NULL, const wxString& title = wxT("Printout"));
- bool OnPrintPage(int page);
- bool HasPage(int page);
- bool OnBeginDocument(int startPage, int endPage);
- void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
+
+ // implement wxPrintout methods
+ virtual bool OnPrintPage(int page);
+ 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; }
}
#endif // WXWIN_COMPATIBILITY_2_6
-#if wxUSE_STD_IOSTREAM
// For compatibility with existing file formats:
// converts from/to a stream to/from a temporary file.
-bool WXDLLIMPEXP_CORE wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream);
-bool WXDLLIMPEXP_CORE wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename);
+#if wxUSE_STD_IOSTREAM
+bool WXDLLIMPEXP_CORE
+wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream);
+bool WXDLLIMPEXP_CORE
+wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename);
#else
-// For compatibility with existing file formats:
-// converts from/to a stream to/from a temporary file.
-bool WXDLLIMPEXP_CORE wxTransferFileToStream(const wxString& filename, wxOutputStream& stream);
-bool WXDLLIMPEXP_CORE wxTransferStreamToFile(wxInputStream& stream, const wxString& filename);
+bool WXDLLIMPEXP_CORE
+wxTransferFileToStream(const wxString& filename, wxOutputStream& stream);
+bool WXDLLIMPEXP_CORE
+wxTransferStreamToFile(wxInputStream& stream, const wxString& filename);
#endif // wxUSE_STD_IOSTREAM
{
DeleteContents();
- if (m_commandProcessor)
- delete m_commandProcessor;
+ delete m_commandProcessor;
if (GetDocumentManager())
GetDocumentManager()->RemoveDocument(this);
bool wxDocument::Close()
{
- if (OnSaveModified())
- return OnCloseDocument();
- else
+ if ( !OnSaveModified() )
return false;
+
+ return OnCloseDocument();
}
bool wxDocument::OnCloseDocument()
wxView *wxDocument::GetFirstView() const
{
- if (m_documentViews.GetCount() == 0)
+ if ( m_documentViews.empty() )
return NULL;
- return (wxView *)m_documentViews.GetFirst()->GetData();
+
+ return static_cast<wxView *>(m_documentViews.GetFirst()->GetData());
}
wxDocManager *wxDocument::GetDocumentManager() const
if (!docTemplate)
return false;
-#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
- wxString filter = docTemplate->GetDescription() + wxT(" (") + docTemplate->GetFileFilter() + wxT(")|") + docTemplate->GetFileFilter();
+#ifdef wxHAS_MULTIPLE_FILEDLG_FILTERS
+ wxString filter = docTemplate->GetDescription() + wxT(" (") +
+ docTemplate->GetFileFilter() + wxT(")|") +
+ docTemplate->GetFileFilter();
// Now see if there are some other template with identical view and document
// classes, whose filters may also be used.
-
if (docTemplate->GetViewClassInfo() && docTemplate->GetDocClassInfo())
{
- wxList::compatibility_iterator node = docTemplate->GetDocumentManager()->GetTemplates().GetFirst();
+ wxList::compatibility_iterator
+ node = docTemplate->GetDocumentManager()->GetTemplates().GetFirst();
while (node)
{
wxDocTemplate *t = (wxDocTemplate*) node->GetData();
if ( !filter.empty() )
filter << wxT('|');
- filter << t->GetDescription() << wxT(" (") << t->GetFileFilter() << wxT(") |")
+ filter << t->GetDescription()
+ << wxT(" (") << t->GetFileFilter() << wxT(") |")
<< t->GetFileFilter();
}
#else
wxString filter = docTemplate->GetFileFilter() ;
#endif
+
wxString defaultDir = docTemplate->GetDirectory();
if ( defaultDir.empty() )
{
GetDocumentWindow());
if (fileName.empty())
- return false;
+ return false; // cancelled by user
wxString ext;
wxFileName::SplitPath(fileName, NULL, NULL, &ext);
SetTitle(wxFileNameFromPath(fileName));
SetFilename(fileName, true); // will call OnChangeFileName automatically
- // A file that doesn't use the default extension of its document template cannot be opened
- // via the FileHistory, so we do not add it.
+ // A file that doesn't use the default extension of its document template
+ // cannot be opened via the FileHistory, so we do not add it.
if (docTemplate->FileMatchesTemplate(fileName))
{
GetDocumentManager()->AddFileToHistory(fileName);
}
- else
- {
- // The user will probably not be able to open the file again, so
- // we could warn about the wrong file-extension here.
- }
+ //else: the user will probably not be able to open the file again, so we
+ // could warn about the wrong file-extension here
+
return true;
}
wxWindow *wxDocument::GetDocumentWindow() const
{
- wxView *view = GetFirstView();
- if (view)
- return view->GetFrame();
- else
- return wxTheApp->GetTopWindow();
+ wxView * const view = GetFirstView();
+
+ return view ? view->GetFrame() : wxTheApp->GetTopWindow();
}
wxCommandProcessor *wxDocument::OnCreateCommandProcessor()
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))
{
}
if (doc->OnCreate(path, flags))
return true;
- else
- {
- if (GetDocumentManager()->GetDocuments().Member(doc))
- doc->DeleteAllViews();
- return false;
- }
+
+ if (GetDocumentManager()->GetDocuments().Member(doc))
+ doc->DeleteAllViews();
+ return false;
}
wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)
if (!m_docClassInfo)
return NULL;
- return (wxDocument *)m_docClassInfo->CreateObject();
+ return static_cast<wxDocument *>(m_docClassInfo->CreateObject());
}
wxView *wxDocTemplate::DoCreateView()
if (!m_viewClassInfo)
return NULL;
- return (wxView *)m_viewClassInfo->CreateObject();
+ return static_cast<wxView *>(m_viewClassInfo->CreateObject());
}
// ----------------------------------------------------------------------------
// 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();
+ if ( !doc->Close() && !force )
+ return false;
- // Check we're really deleted
- if (m_docs.Member(doc))
- delete doc;
+ // Implicitly deletes the document when
+ // the last view is deleted
+ doc->DeleteAllViews();
- return true;
- }
- return false;
+ // Check we're really deleted
+ if (m_docs.Member(doc))
+ delete doc;
+
+ return true;
}
bool wxDocManager::CloseDocuments(bool force)
void wxDocManager::OnFileOpen(wxCommandEvent& WXUNUSED(event))
{
- if ( !CreateDocument( wxEmptyString, 0) )
+ if ( !CreateDocument("") )
{
OnOpenFileFailure();
}
if (printout)
{
// 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() )
{
delete preview;
- wxMessageBox( _("Sorry, print preview needs a printer to be installed.") );
+ wxLogError(_("Print preview creation failed."));
return;
}
- wxPreviewFrame *frame = new wxPreviewFrame(preview, (wxFrame *)wxTheApp->GetTopWindow(), _("Print Preview"),
- wxPoint(100, 100), wxSize(600, 650));
+ wxPreviewFrame *
+ frame = new wxPreviewFrame(preview, wxTheApp->GetTopWindow(),
+ _("Print Preview"));
frame->Centre(wxBOTH);
frame->Initialize();
frame->Show(true);
void wxDocManager::OnUndo(wxCommandEvent& event)
{
- wxDocument *doc = GetCurrentDocument();
- if (!doc)
- return;
- if (doc->GetCommandProcessor())
- doc->GetCommandProcessor()->Undo();
- else
+ wxCommandProcessor * const cmdproc = GetCurrentCommandProcessor();
+ if ( !cmdproc )
+ {
event.Skip();
+ return;
+ }
+
+ cmdproc->Undo();
}
void wxDocManager::OnRedo(wxCommandEvent& event)
{
- wxDocument *doc = GetCurrentDocument();
- if (!doc)
- return;
- if (doc->GetCommandProcessor())
- doc->GetCommandProcessor()->Redo();
- else
+ wxCommandProcessor * const cmdproc = GetCurrentCommandProcessor();
+ if ( !cmdproc )
+ {
event.Skip();
+ return;
+ }
+
+ cmdproc->Redo();
}
// Handlers for UI update commands
void wxDocManager::OnUpdateUndo(wxUpdateUIEvent& event)
{
- wxDocument *doc = GetCurrentDocument();
- if (!doc)
- event.Enable(false);
- else if (!doc->GetCommandProcessor())
- event.Skip();
- else
+ wxCommandProcessor * const cmdproc = GetCurrentCommandProcessor();
+ if ( !cmdproc )
{
- event.Enable( doc->GetCommandProcessor()->CanUndo() );
- doc->GetCommandProcessor()->SetMenuStrings();
+ event.Enable(false);
+ return;
}
+
+ event.Enable(cmdproc->CanUndo());
+ cmdproc->SetMenuStrings();
}
void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event)
{
- wxDocument *doc = GetCurrentDocument();
- if (!doc)
- event.Enable(false);
- else if (!doc->GetCommandProcessor())
- event.Skip();
- else
+ wxCommandProcessor * const cmdproc = GetCurrentCommandProcessor();
+ if ( !cmdproc )
{
- event.Enable( doc->GetCommandProcessor()->CanRedo() );
- doc->GetCommandProcessor()->SetMenuStrings();
+ event.Enable(false);
+ return;
}
+
+ event.Enable(cmdproc->CanRedo());
+ cmdproc->SetMenuStrings();
}
wxView *wxDocManager::GetCurrentView() const
wxDocument *wxDocManager::GetCurrentDocument() const
{
- wxView *view = GetCurrentView();
- if (view)
- return view->GetDocument();
- else
- return NULL;
+ wxView * const view = GetCurrentView();
+ return view ? view->GetDocument() : NULL;
+}
+
+wxCommandProcessor *wxDocManager::GetCurrentCommandProcessor() const
+{
+ wxDocument * const doc = GetCurrentDocument();
+ return doc ? doc->GetCommandProcessor() : NULL;
}
// Make a default name for a new document
long WXUNUSED(flags),
bool WXUNUSED(save))
{
- // We can only have multiple filters in Windows and GTK
-#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
+#ifdef wxHAS_MULTIPLE_FILEDLG_FILTERS
wxString descrBuf;
- int i;
- for (i = 0; i < noTemplates; i++)
+ for (int i = 0; i < noTemplates; i++)
{
if (templates[i]->IsVisible())
{
else
msgTitle = wxString(_("File error"));
- (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK | wxICON_EXCLAMATION | wxCENTRE,
- parent);
+ wxMessageBox(_("Sorry, could not open this file."),
+ msgTitle,
+ wxOK | wxICON_EXCLAMATION | wxCENTRE,
+ parent);
path = wxEmptyString;
return NULL;
theTemplate = FindTemplateForPath(path);
if ( !theTemplate )
{
- // Since we do not add files with non-default extensions to the FileHistory this
- // can only happen if the application changes the allowed templates in runtime.
- (void)wxMessageBox(_("Sorry, the format for this file is unknown."),
- _("Open File"),
- wxOK | wxICON_EXCLAMATION | wxCENTRE, wxFindSuitableParent());
+ // Since we do not add files with non-default extensions to the
+ // file history this can only happen if the application changes the
+ // allowed templates in runtime.
+ wxMessageBox(_("Sorry, the format for this file is unknown."),
+ _("Open File"),
+ wxOK | wxICON_EXCLAMATION | wxCENTRE,
+ parent);
}
}
else
{
- path = wxEmptyString;
+ path.clear();
}
return theTemplate;
int noTemplates, bool sort)
{
wxArrayString strings;
- wxDocTemplate **data = new wxDocTemplate *[noTemplates];
+ wxScopedArray<wxDocTemplate *> data(new wxDocTemplate *[noTemplates]);
int i;
int n = 0;
_("Select a document template"),
_("Templates"),
strings,
- (void **)data,
+ (void **)data.get(),
wxFindSuitableParent()
);
}
- delete[] data;
-
return theTemplate;
}
int noTemplates, bool sort)
{
wxArrayString strings;
- wxDocTemplate **data = new wxDocTemplate *[noTemplates];
+ wxScopedArray<wxDocTemplate *> data(new wxDocTemplate *[noTemplates]);
int i;
int n = 0;
_("Select a document view"),
_("Views"),
strings,
- (void **)data,
+ (void **)data.get(),
wxFindSuitableParent()
);
}
- delete[] data;
return theTemplate;
}
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.
+ event.Veto();
+ return;
+ }
- if (ans)
- {
- m_childView->Activate(false);
- delete m_childView;
- m_childView = NULL;
- m_childDocument = NULL;
+ m_childView->Activate(false);
+ delete m_childView;
+ m_childView = NULL;
+ m_childDocument = NULL;
- this->Destroy();
- }
- else
- event.Veto();
- }
- else
- event.Veto();
+ Destroy();
}
// ----------------------------------------------------------------------------
{
if (m_docManager->Clear(!event.CanVeto()))
{
- this->Destroy();
+ Destroy();
}
else
event.Veto();
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;
*maxPage = 1;