1 \section{\class{wxDocument
}}\label{wxdocument
}
3 The
document class can be used to model an application's file-based
4 data. It is part of the
document/view framework supported by wxWindows,
5 and cooperates with the
\helpref{wxView
}{wxview
},
\helpref{wxDocTemplate
}{wxdoctemplate
}\rtfsp
6 and
\helpref{wxDocManager
}{wxdocmanager
} classes.
8 \wxheading{Derived from
}
10 \helpref{wxEvtHandler
}{wxevthandler
}\\
11 \helpref{wxObject
}{wxobject
}
15 \helpref{wxDocument overview
}{wxdocumentoverview
},
\helpref{wxView
}{wxview
},
\rtfsp
16 \helpref{wxDocTemplate
}{wxdoctemplate
},
\helpref{wxDocManager
}{wxdocmanager
}
18 \latexignore{\rtfignore{\wxheading{Members
}}}
20 \membersection{wxDocument::m
\_commandProcessor}
22 \member{wxCommandProcessor*
}{m
\_commandProcessor}
24 A pointer to the command processor associated with this
document.
26 \membersection{wxDocument::m
\_documentFile}
28 \member{wxString
}{m
\_documentFile}
30 Filename associated with this
document (``" if none).
32 \membersection{wxDocument::m
\_documentModified}
34 \member{bool
}{m
\_documentModified}
36 TRUE if the
document has been modified, FALSE otherwise.
38 \membersection{wxDocument::m
\_documentTemplate}
40 \member{wxDocTemplate *
}{m
\_documentTemplate}
42 A pointer to the template from which this
document was created.
44 \membersection{wxDocument::m
\_documentTitle}
46 \member{wxString
}{m
\_documentTitle}
48 Document title. The
document title is used for an associated
49 frame (if any), and is usually constructed by the framework from
52 \membersection{wxDocument::m
\_documentTypeName}\label{documenttypename
}
54 \member{wxString
}{m
\_documentTypeName}
56 The
document type name given to the wxDocTemplate constructor, copied to this
57 variable when the
document is created. If several
document templates are
58 created that use the same
document type, this variable is used in wxDocManager::CreateView
59 to collate a list of alternative view types that can be used on this kind of
60 document. Do not change the value of this variable.
62 \membersection{wxDocument::m
\_documentViews}
64 \member{wxList
}{m
\_documentViews}
66 List of wxView instances associated with this
document.
68 \membersection{wxDocument::wxDocument
}
70 \func{}{wxDocument
}{\void}
72 Constructor. Define your own default constructor to initialize application-specific
75 \membersection{wxDocument::
\destruct{wxDocument
}}
77 \func{}{\destruct{wxDocument
}}{\void}
79 Destructor. Removes itself from the
document manager.
81 \membersection{wxDocument::AddView
}
83 \func{virtual bool
}{AddView
}{\param{wxView *
}{view
}}
85 If the view is not already in the list of views, adds the view and calls OnChangedViewList.
87 \membersection{wxDocument::Close
}
89 \func{virtual bool
}{Close
}{\void}
91 Closes the
document, by calling OnSaveModified and then (if this returned TRUE) OnCloseDocument.
92 This does not normally delete the
document object: use DeleteAllViews to do this implicitly.
94 \membersection{wxDocument::DeleteAllViews
}
96 \func{virtual bool
}{DeleteAllViews
}{\void}
98 Calls wxView::Close and deletes each view. Deleting the final view will implicitly
99 delete the
document itself, because the wxView destructor calls RemoveView. This
100 in turns calls wxDocument::OnChangedViewList, whose default implemention is to
101 save and delete the
document if no views exist.
103 \membersection{wxDocument::GetCommandProcessor
}
105 \constfunc{wxCommandProcessor*
}{GetCommandProcessor
}{\void}
107 Returns a pointer to the command processor associated with this
document.
109 See
\helpref{wxCommandProcessor
}{wxcommandprocessor
}.
111 \membersection{wxDocument::GetDocumentTemplate
}
113 \constfunc{wxDocTemplate*
}{GetDocumentTemplate
}{\void}
115 Gets a pointer to the template that created the
document.
117 \membersection{wxDocument::GetDocumentManager
}
119 \constfunc{wxDocManager*
}{GetDocumentManager
}{\void}
121 Gets a pointer to the associated
document manager.
123 \membersection{wxDocument::GetDocumentName
}
125 \constfunc{wxString
}{GetDocumentName
}{\void}
127 Gets the
document type name for this
document. See the comment for
\helpref{documentTypeName
}{documenttypename
}.
129 \membersection{wxDocument::GetDocumentWindow
}
131 \constfunc{wxWindow*
}{GetDocumentWindow
}{\void}
133 Intended to return a suitable window for using as a parent for
document-related
134 dialog boxes. By default, uses the frame associated with the first view.
136 \membersection{wxDocument::GetFilename
}
138 \constfunc{wxString
}{GetFilename
}{\void}
140 Gets the filename associated with this
document, or NULL if none is
143 \membersection{wxDocument::GetFirstView
}
145 \constfunc{wxView*
}{GetFirstView
}{\void}
147 A convenience function to get the first view for a
document, because
148 in many cases a
document will only have a single view.
150 \membersection{wxDocument::GetPrintableName
}
152 \constfunc{virtual void
}{GetPrintableName
}{\param{wxString\&
}{name
}}
154 Copies a suitable
document name into the supplied
{\it name
} buffer. The default
155 function uses the title, or if there is no title, uses the filename; or if no
156 filename, the string
{\bf unnamed
}.
158 \membersection{wxDocument::GetTitle
}
160 \constfunc{wxString
}{GetTitle
}{\void}
162 Gets the title for this
document. The
document title is used for an associated
163 frame (if any), and is usually constructed by the framework from
166 \membersection{wxDocument::IsModified
}\label{wxdocumentismodified
}
168 \constfunc{virtual bool
}{IsModified
}{\void}
170 Returns TRUE if the
document has been modified since the last save, FALSE otherwise.
171 You may need to override this if your
document view maintains its own
172 record of being modified (for example if using wxTextWindow to view and edit the
document).
174 See also
\helpref{Modify
}{wxdocumentmodify
}.
176 \membersection{wxDocument::LoadObject
}
178 \func{virtual istream\&
}{LoadObject
}{\param{istream\&
}{stream
}}
180 Override this function and call it from your own LoadObject before
181 streaming your own data. LoadObject is called by the framework
182 automatically when the
document contents need to be loaded.
184 \membersection{wxDocument::Modify
}\label{wxdocumentmodify
}
186 \func{virtual void
}{Modify
}{\param{bool
}{ modify
}}
188 Call with TRUE to mark the
document as modified since the last save, FALSE otherwise.
189 You may need to override this if your
document view maintains its own
190 record of being modified (for example if using wxTextWindow to view and edit the
document).
192 See also
\helpref{IsModified
}{wxdocumentismodified
}.
194 \membersection{wxDocument::OnChangedViewList
}
196 \func{virtual void
}{OnChangedViewList
}{\void}
198 Called when a view is added to or deleted from this
document. The default
199 implementation saves and deletes the
document if no views exist (the last
200 one has just been removed).
202 \membersection{wxDocument::OnCloseDocument
}
204 \func{virtual bool
}{OnCloseDocument
}{\void}
206 The default implementation calls DeleteContents (an empty implementation)
207 sets the modified flag to FALSE. Override this to
208 supply additional behaviour when the
document is closed with Close.
210 \membersection{wxDocument::OnCreate
}
212 \func{virtual bool
}{OnCreate
}{\param{const wxString\&
}{path
},
\param{long
}{ flags
}}
214 Called just after the
document object is created to give it a chance
215 to initialize itself. The default implementation uses the
216 template associated with the
document to create an initial view.
217 If this function returns FALSE, the
document is deleted.
219 \membersection{wxDocument::OnCreateCommandProcessor
}
221 \func{virtual wxCommandProcessor*
}{OnCreateCommandProcessor
}{\void}
223 Override this function if you want a different (or no) command processor
224 to be created when the
document is created. By default, it returns
225 an instance of wxCommandProcessor.
227 See
\helpref{wxCommandProcessor
}{wxcommandprocessor
}.
229 \membersection{wxDocument::OnNewDocument
}
231 \func{virtual bool
}{OnNewDocument
}{\void}
233 The default implementation calls OnSaveModified and DeleteContents, makes a default title for the
234 document, and notifies the views that the filename (in fact, the title) has changed.
236 \membersection{wxDocument::OnOpenDocument
}
238 \func{virtual bool
}{OnOpenDocument
}{\param{const wxString\&
}{filename
}}
240 Constructs an input file stream for the given filename (which must not be NULL),
241 and calls LoadObject. If LoadObject returns TRUE, the
document is set to
242 unmodified; otherwise, an error message box is displayed. The
document's
243 views are notified that the filename has changed, to give windows an opportunity
244 to update their titles. All of the
document's views are then updated.
246 \membersection{wxDocument::OnSaveDocument
}
248 \func{virtual bool
}{OnSaveDocument
}{\param{const wxString\&
}{filename
}}
250 Constructs an output file stream for the given filename (which must not be NULL),
251 and calls SaveObject. If SaveObject returns TRUE, the
document is set to
252 unmodified; otherwise, an error message box is displayed.
254 \membersection{wxDocument::OnSaveModified
}
256 \func{virtual bool
}{OnSaveModified
}{\void}
258 If the
document has been modified, prompts the user to ask if the changes should
259 be changed. If the user replies Yes, the Save function is called. If No, the
260 document is marked as unmodified and the function succeeds. If Cancel, the
263 \membersection{wxDocument::RemoveView
}
265 \func{virtual bool
}{RemoveView
}{\param{wxView*
}{view
}}
267 Removes the view from the
document's list of views, and calls OnChangedViewList.
269 \membersection{wxDocument::Save
}
271 \func{virtual bool
}{Save
}{\void}
273 Saves the
document by calling OnSaveDocument if there is an associated filename,
274 or SaveAs if there is no filename.
276 \membersection{wxDocument::SaveAs
}
278 \func{virtual bool
}{SaveAs
}{\void}
280 Prompts the user for a file to save to, and then calls OnSaveDocument.
282 \membersection{wxDocument::SaveObject
}
284 \func{virtual ostream\&
}{SaveObject
}{\param{ostream\&
}{stream
}}
286 Override this function and call it from your own SaveObject before
287 streaming your own data. SaveObject is called by the framework
288 automatically when the
document contents need to be saved.
290 \membersection{wxDocument::SetCommandProcessor
}
292 \func{virtual void
}{SetCommandProcessor
}{\param{wxCommandProcessor *
}{processor
}}
294 Sets the command processor to be used for this
document. The
document will then be responsible
295 for its deletion. Normally you should not call this; override OnCreateCommandProcessor
298 See
\helpref{wxCommandProcessor
}{wxcommandprocessor
}.
300 \membersection{wxDocument::SetDocumentName
}
302 \func{void
}{SetDocumentName
}{\param{const wxString\&
}{name
}}
304 Sets the
document type name for this
document. See the comment for
\helpref{documentTypeName
}{documenttypename
}.
306 \membersection{wxDocument::SetDocumentTemplate
}
308 \func{void
}{SetDocumentTemplate
}{\param{wxDocTemplate*
}{templ
}}
310 Sets the pointer to the template that created the
document. Should only be called by the
313 \membersection{wxDocument::SetFilename
}
315 \func{void
}{SetFilename
}{\param{const wxString\&
}{filename
}}
317 Sets the filename for this
document. Usually called by the framework.
319 \membersection{wxDocument::SetTitle
}
321 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
323 Sets the title for this
document. The
document title is used for an associated
324 frame (if any), and is usually constructed by the framework from
327 \membersection{wxDocument::UpdateAllViews
}\label{wxdocumentupdateallviews
}
329 \func{void
}{UpdateAllViews
}{\param{wxView*
}{sender = NULL
}}
331 Updates all views. If
{\it sender
} is non-NULL, does not update this view.