## wxDocument

The document class can be used to model an application's file-based data. It is part of the document/view framework supported by wxWindows, and cooperates with the wxView, wxDocTemplate and wxDocManager classes.

Derived from

wxEvtHandler
wxObject

Include files

<wx/docview.h>

See also

wxDocument overview, wxView, wxDocTemplate, wxDocManager

Members

wxDocument::m_commandProcessor
wxDocument::m_documentFile
wxDocument::m_documentModified
wxDocument::m_documentTemplate
wxDocument::m_documentTitle
wxDocument::m_documentTypeName
wxDocument::m_documentViews
wxDocument::wxDocument
wxDocument::~wxDocument
wxDocument::AddView
wxDocument::Close
wxDocument::DeleteAllViews
wxDocument::GetCommandProcessor
wxDocument::GetDocumentTemplate
wxDocument::GetDocumentManager
wxDocument::GetDocumentName
wxDocument::GetDocumentWindow
wxDocument::GetFilename
wxDocument::GetFirstView
wxDocument::GetPrintableName
wxDocument::GetTitle
wxDocument::GetViews
wxDocument::IsModified
wxDocument::LoadObject
wxDocument::Modify
wxDocument::OnChangedViewList
wxDocument::OnCloseDocument
wxDocument::OnCreate
wxDocument::OnCreateCommandProcessor
wxDocument::OnNewDocument
wxDocument::OnOpenDocument
wxDocument::OnSaveDocument
wxDocument::OnSaveModified
wxDocument::RemoveView
wxDocument::Save
wxDocument::SaveAs
wxDocument::SaveObject
wxDocument::SetCommandProcessor
wxDocument::SetDocumentName
wxDocument::SetDocumentTemplate
wxDocument::SetFilename
wxDocument::SetTitle
wxDocument::UpdateAllViews

### wxDocument::m_commandProcessor

wxCommandProcessor* m_commandProcessor

A pointer to the command processor associated with this document.

### wxDocument::m_documentFile

wxString m_documentFile

Filename associated with this document ("" if none).

### wxDocument::m_documentModified

bool m_documentModified

TRUE if the document has been modified, FALSE otherwise.

### wxDocument::m_documentTemplate

wxDocTemplate * m_documentTemplate

A pointer to the template from which this document was created.

### wxDocument::m_documentTitle

wxString m_documentTitle

Document title. The document title is used for an associated frame (if any), and is usually constructed by the framework from the filename.

### wxDocument::m_documentTypeName

wxString m_documentTypeName

The document type name given to the wxDocTemplate constructor, copied to this variable when the document is created. If several document templates are created that use the same document type, this variable is used in wxDocManager::CreateView to collate a list of alternative view types that can be used on this kind of document. Do not change the value of this variable.

### wxDocument::m_documentViews

wxList m_documentViews

List of wxView instances associated with this document.

### wxDocument::wxDocument

wxDocument()

Constructor. Define your own default constructor to initialize application-specific data.

### wxDocument::~wxDocument

~wxDocument()

Destructor. Removes itself from the document manager.

### wxDocument::AddView

virtual bool AddView(wxView *view)

If the view is not already in the list of views, adds the view and calls OnChangedViewList.

### wxDocument::Close

virtual bool Close()

Closes the document, by calling OnSaveModified and then (if this returned TRUE) OnCloseDocument. This does not normally delete the document object: use DeleteAllViews to do this implicitly.

### wxDocument::DeleteAllViews

virtual bool DeleteAllViews()

Calls wxView::Close and deletes each view. Deleting the final view will implicitly delete the document itself, because the wxView destructor calls RemoveView. This in turns calls wxDocument::OnChangedViewList, whose default implemention is to save and delete the document if no views exist.

### wxDocument::GetCommandProcessor

wxCommandProcessor* GetCommandProcessor() const

Returns a pointer to the command processor associated with this document.

See wxCommandProcessor.

### wxDocument::GetDocumentTemplate

wxDocTemplate* GetDocumentTemplate() const

Gets a pointer to the template that created the document.

### wxDocument::GetDocumentManager

wxDocManager* GetDocumentManager() const

Gets a pointer to the associated document manager.

### wxDocument::GetDocumentName

wxString GetDocumentName() const

Gets the document type name for this document. See the comment for documentTypeName.

### wxDocument::GetDocumentWindow

wxWindow* GetDocumentWindow() const

Intended to return a suitable window for using as a parent for document-related dialog boxes. By default, uses the frame associated with the first view.

### wxDocument::GetFilename

wxString GetFilename() const

Gets the filename associated with this document, or "" if none is associated.

### wxDocument::GetFirstView

wxView * GetFirstView() const

A convenience function to get the first view for a document, because in many cases a document will only have a single view.

See also: GetViews

### wxDocument::GetPrintableName

virtual void GetPrintableName(wxString& name) const

Copies a suitable document name into the supplied name buffer. The default function uses the title, or if there is no title, uses the filename; or if no filename, the string unnamed.

### wxDocument::GetTitle

wxString GetTitle() const

Gets the title for this document. The document title is used for an associated frame (if any), and is usually constructed by the framework from the filename.

### wxDocument::GetViews

wxList & GetViews() const

Returns the list whose elements are the views on the document.

See also: GetFirstView

### wxDocument::IsModified

virtual bool IsModified() const

Returns TRUE if the document has been modified since the last save, FALSE otherwise. You may need to override this if your document view maintains its own record of being modified (for example if using wxTextWindow to view and edit the document).

See also Modify.

### wxDocument::LoadObject

virtual istream& LoadObject(istream& stream)

virtual wxInputStream& LoadObject(wxInputStream& stream)

Override this function and call it from your own LoadObject before streaming your own data. LoadObject is called by the framework automatically when the document contents need to be loaded.

Note that only one of these forms exists, depending on how wxWindows was configured.

### wxDocument::Modify

virtual void Modify(bool modify)

Call with TRUE to mark the document as modified since the last save, FALSE otherwise. You may need to override this if your document view maintains its own record of being modified (for example if using wxTextWindow to view and edit the document).

See also IsModified.

### wxDocument::OnChangedViewList

virtual void OnChangedViewList()

Called when a view is added to or deleted from this document. The default implementation saves and deletes the document if no views exist (the last one has just been removed).

### wxDocument::OnCloseDocument

virtual bool OnCloseDocument()

The default implementation calls DeleteContents (an empty implementation) sets the modified flag to FALSE. Override this to supply additional behaviour when the document is closed with Close.

### wxDocument::OnCreate

virtual bool OnCreate(const wxString& path, long flags)

Called just after the document object is created to give it a chance to initialize itself. The default implementation uses the template associated with the document to create an initial view. If this function returns FALSE, the document is deleted.

### wxDocument::OnCreateCommandProcessor

virtual wxCommandProcessor* OnCreateCommandProcessor()

Override this function if you want a different (or no) command processor to be created when the document is created. By default, it returns an instance of wxCommandProcessor.

See wxCommandProcessor.

### wxDocument::OnNewDocument

virtual bool OnNewDocument()

The default implementation calls OnSaveModified and DeleteContents, makes a default title for the document, and notifies the views that the filename (in fact, the title) has changed.

### wxDocument::OnOpenDocument

virtual bool OnOpenDocument(const wxString& filename)

Constructs an input file stream for the given filename (which must not be empty), and calls LoadObject. If LoadObject returns TRUE, the document is set to unmodified; otherwise, an error message box is displayed. The document's views are notified that the filename has changed, to give windows an opportunity to update their titles. All of the document's views are then updated.

### wxDocument::OnSaveDocument

virtual bool OnSaveDocument(const wxString& filename)

Constructs an output file stream for the given filename (which must not be empty), and calls SaveObject. If SaveObject returns TRUE, the document is set to unmodified; otherwise, an error message box is displayed.

### wxDocument::OnSaveModified

virtual bool OnSaveModified()

If the document has been modified, prompts the user to ask if the changes should be changed. If the user replies Yes, the Save function is called. If No, the document is marked as unmodified and the function succeeds. If Cancel, the function fails.

### wxDocument::RemoveView

virtual bool RemoveView(wxView* view)

Removes the view from the document's list of views, and calls OnChangedViewList.

### wxDocument::Save

virtual bool Save()

Saves the document by calling OnSaveDocument if there is an associated filename, or SaveAs if there is no filename.

### wxDocument::SaveAs

virtual bool SaveAs()

Prompts the user for a file to save to, and then calls OnSaveDocument.

### wxDocument::SaveObject

virtual ostream& SaveObject(ostream& stream)

virtual wxOutputStream& SaveObject(wxOutputStream& stream)

Override this function and call it from your own SaveObject before streaming your own data. SaveObject is called by the framework automatically when the document contents need to be saved.

Note that only one of these forms exists, depending on how wxWindows was configured.

### wxDocument::SetCommandProcessor

virtual void SetCommandProcessor(wxCommandProcessor *processor)

Sets the command processor to be used for this document. The document will then be responsible for its deletion. Normally you should not call this; override OnCreateCommandProcessor instead.

See wxCommandProcessor.

### wxDocument::SetDocumentName

void SetDocumentName(const wxString& name)

Sets the document type name for this document. See the comment for documentTypeName.

### wxDocument::SetDocumentTemplate

void SetDocumentTemplate(wxDocTemplate* templ)

Sets the pointer to the template that created the document. Should only be called by the framework.

### wxDocument::SetFilename

void SetFilename(const wxString& filename, bool notifyViews = FALSE)

Sets the filename for this document. Usually called by the framework.

If notifyViews is TRUE, wxView::OnChangeFilename is called for all views.

### wxDocument::SetTitle

void SetTitle(const wxString& title)

Sets the title for this document. The document title is used for an associated frame (if any), and is usually constructed by the framework from the filename.

### wxDocument::UpdateAllViews

void UpdateAllViews(wxView* sender = NULL)

Updates all views. If sender is non-NULL, does not update this view.