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
}
13 \wxheading{Include files
}
19 \helpref{wxDocument overview
}{wxdocumentoverview
},
\helpref{wxView
}{wxview
},
\rtfsp
20 \helpref{wxDocTemplate
}{wxdoctemplate
},
\helpref{wxDocManager
}{wxdocmanager
}
22 \latexignore{\rtfignore{\wxheading{Members
}}}
24 \membersection{wxDocument::m
\_commandProcessor}
26 \member{wxCommandProcessor*
}{m
\_commandProcessor}
28 A pointer to the command processor associated with this
document.
30 \membersection{wxDocument::m
\_documentFile}
32 \member{wxString
}{m
\_documentFile}
34 Filename associated with this
document (``" if none).
36 \membersection{wxDocument::m
\_documentModified}
38 \member{bool
}{m
\_documentModified}
40 TRUE if the
document has been modified, FALSE otherwise.
42 \membersection{wxDocument::m
\_documentTemplate}
44 \member{wxDocTemplate *
}{m
\_documentTemplate}
46 A pointer to the template from which this
document was created.
48 \membersection{wxDocument::m
\_documentTitle}
50 \member{wxString
}{m
\_documentTitle}
52 Document title. The
document title is used for an associated
53 frame (if any), and is usually constructed by the framework from
56 \membersection{wxDocument::m
\_documentTypeName}\label{documenttypename
}
58 \member{wxString
}{m
\_documentTypeName}
60 The
document type name given to the wxDocTemplate constructor, copied to this
61 variable when the
document is created. If several
document templates are
62 created that use the same
document type, this variable is used in wxDocManager::CreateView
63 to collate a list of alternative view types that can be used on this kind of
64 document. Do not change the value of this variable.
66 \membersection{wxDocument::m
\_documentViews}
68 \member{wxList
}{m
\_documentViews}
70 List of wxView instances associated with this
document.
72 \membersection{wxDocument::wxDocument
}
74 \func{}{wxDocument
}{\void}
76 Constructor. Define your own default constructor to initialize application-specific
79 \membersection{wxDocument::
\destruct{wxDocument
}}
81 \func{}{\destruct{wxDocument
}}{\void}
83 Destructor. Removes itself from the
document manager.
85 \membersection{wxDocument::AddView
}
87 \func{virtual bool
}{AddView
}{\param{wxView *
}{view
}}
89 If the view is not already in the list of views, adds the view and calls OnChangedViewList.
91 \membersection{wxDocument::Close
}
93 \func{virtual bool
}{Close
}{\void}
95 Closes the
document, by calling OnSaveModified and then (if this returned TRUE) OnCloseDocument.
96 This does not normally delete the
document object: use DeleteAllViews to do this implicitly.
98 \membersection{wxDocument::DeleteAllViews
}
100 \func{virtual bool
}{DeleteAllViews
}{\void}
102 Calls wxView::Close and deletes each view. Deleting the final view will implicitly
103 delete the
document itself, because the wxView destructor calls RemoveView. This
104 in turns calls wxDocument::OnChangedViewList, whose default implemention is to
105 save and delete the
document if no views exist.
107 \membersection{wxDocument::GetCommandProcessor
}
109 \constfunc{wxCommandProcessor*
}{GetCommandProcessor
}{\void}
111 Returns a pointer to the command processor associated with this
document.
113 See
\helpref{wxCommandProcessor
}{wxcommandprocessor
}.
115 \membersection{wxDocument::GetDocumentTemplate
}
117 \constfunc{wxDocTemplate*
}{GetDocumentTemplate
}{\void}
119 Gets a pointer to the template that created the
document.
121 \membersection{wxDocument::GetDocumentManager
}
123 \constfunc{wxDocManager*
}{GetDocumentManager
}{\void}
125 Gets a pointer to the associated
document manager.
127 \membersection{wxDocument::GetDocumentName
}
129 \constfunc{wxString
}{GetDocumentName
}{\void}
131 Gets the
document type name for this
document. See the comment for
\helpref{documentTypeName
}{documenttypename
}.
133 \membersection{wxDocument::GetDocumentWindow
}
135 \constfunc{wxWindow*
}{GetDocumentWindow
}{\void}
137 Intended to return a suitable window for using as a parent for
document-related
138 dialog boxes. By default, uses the frame associated with the first view.
140 \membersection{wxDocument::GetFilename
}
142 \constfunc{wxString
}{GetFilename
}{\void}
144 Gets the filename associated with this
document, or "" if none is
147 \membersection{wxDocument::GetFirstView
}\label{wxdocumentgetfirstview
}
149 \constfunc{wxView *
}{GetFirstView
}{\void}
151 A convenience function to get the first view for a
document, because
152 in many cases a
document will only have a single view.
154 See also:
\helpref{GetViews
}{wxdocumentgetviews
}
156 \membersection{wxDocument::GetPrintableName
}
158 \constfunc{virtual void
}{GetPrintableName
}{\param{wxString\&
}{name
}}
160 Copies a suitable
document name into the supplied
{\it name
} buffer. The default
161 function uses the title, or if there is no title, uses the filename; or if no
162 filename, the string
{\bf unnamed
}.
164 \membersection{wxDocument::GetTitle
}
166 \constfunc{wxString
}{GetTitle
}{\void}
168 Gets the title for this
document. The
document title is used for an associated
169 frame (if any), and is usually constructed by the framework from
172 \membersection{wxDocument::GetViews
}\label{wxdocumentgetviews
}
174 \constfunc{wxList \&
}{GetViews
}{\void}
176 Returns the list whose elements are the views on the
document.
178 See also:
\helpref{GetFirstView
}{wxdocumentgetfirstview
}
180 \membersection{wxDocument::IsModified
}\label{wxdocumentismodified
}
182 \constfunc{virtual bool
}{IsModified
}{\void}
184 Returns TRUE if the
document has been modified since the last save, FALSE otherwise.
185 You may need to override this if your
document view maintains its own
186 record of being modified (for example if using wxTextWindow to view and edit the
document).
188 See also
\helpref{Modify
}{wxdocumentmodify
}.
190 \membersection{wxDocument::LoadObject
}
192 \func{virtual istream\&
}{LoadObject
}{\param{istream\&
}{stream
}}
194 Override this function and call it from your own LoadObject before
195 streaming your own data. LoadObject is called by the framework
196 automatically when the
document contents need to be loaded.
198 \membersection{wxDocument::Modify
}\label{wxdocumentmodify
}
200 \func{virtual void
}{Modify
}{\param{bool
}{ modify
}}
202 Call with TRUE to mark the
document as modified since the last save, FALSE otherwise.
203 You may need to override this if your
document view maintains its own
204 record of being modified (for example if using wxTextWindow to view and edit the
document).
206 See also
\helpref{IsModified
}{wxdocumentismodified
}.
208 \membersection{wxDocument::OnChangedViewList
}
210 \func{virtual void
}{OnChangedViewList
}{\void}
212 Called when a view is added to or deleted from this
document. The default
213 implementation saves and deletes the
document if no views exist (the last
214 one has just been removed).
216 \membersection{wxDocument::OnCloseDocument
}
218 \func{virtual bool
}{OnCloseDocument
}{\void}
220 The default implementation calls DeleteContents (an empty implementation)
221 sets the modified flag to FALSE. Override this to
222 supply additional behaviour when the
document is closed with Close.
224 \membersection{wxDocument::OnCreate
}
226 \func{virtual bool
}{OnCreate
}{\param{const wxString\&
}{path
},
\param{long
}{ flags
}}
228 Called just after the
document object is created to give it a chance
229 to initialize itself. The default implementation uses the
230 template associated with the
document to create an initial view.
231 If this function returns FALSE, the
document is deleted.
233 \membersection{wxDocument::OnCreateCommandProcessor
}
235 \func{virtual wxCommandProcessor*
}{OnCreateCommandProcessor
}{\void}
237 Override this function if you want a different (or no) command processor
238 to be created when the
document is created. By default, it returns
239 an instance of wxCommandProcessor.
241 See
\helpref{wxCommandProcessor
}{wxcommandprocessor
}.
243 \membersection{wxDocument::OnNewDocument
}
245 \func{virtual bool
}{OnNewDocument
}{\void}
247 The default implementation calls OnSaveModified and DeleteContents, makes a default title for the
248 document, and notifies the views that the filename (in fact, the title) has changed.
250 \membersection{wxDocument::OnOpenDocument
}
252 \func{virtual bool
}{OnOpenDocument
}{\param{const wxString\&
}{filename
}}
254 Constructs an input file stream for the given filename (which must not be empty),
255 and calls LoadObject. If LoadObject returns TRUE, the
document is set to
256 unmodified; otherwise, an error message box is displayed. The
document's
257 views are notified that the filename has changed, to give windows an opportunity
258 to update their titles. All of the
document's views are then updated.
260 \membersection{wxDocument::OnSaveDocument
}
262 \func{virtual bool
}{OnSaveDocument
}{\param{const wxString\&
}{filename
}}
264 Constructs an output file stream for the given filename (which must not be empty),
265 and calls SaveObject. If SaveObject returns TRUE, the
document is set to
266 unmodified; otherwise, an error message box is displayed.
268 \membersection{wxDocument::OnSaveModified
}
270 \func{virtual bool
}{OnSaveModified
}{\void}
272 If the
document has been modified, prompts the user to ask if the changes should
273 be changed. If the user replies Yes, the Save function is called. If No, the
274 document is marked as unmodified and the function succeeds. If Cancel, the
277 \membersection{wxDocument::RemoveView
}
279 \func{virtual bool
}{RemoveView
}{\param{wxView*
}{view
}}
281 Removes the view from the
document's list of views, and calls OnChangedViewList.
283 \membersection{wxDocument::Save
}
285 \func{virtual bool
}{Save
}{\void}
287 Saves the
document by calling OnSaveDocument if there is an associated filename,
288 or SaveAs if there is no filename.
290 \membersection{wxDocument::SaveAs
}
292 \func{virtual bool
}{SaveAs
}{\void}
294 Prompts the user for a file to save to, and then calls OnSaveDocument.
296 \membersection{wxDocument::SaveObject
}
298 \func{virtual ostream\&
}{SaveObject
}{\param{ostream\&
}{stream
}}
300 Override this function and call it from your own SaveObject before
301 streaming your own data. SaveObject is called by the framework
302 automatically when the
document contents need to be saved.
304 \membersection{wxDocument::SetCommandProcessor
}
306 \func{virtual void
}{SetCommandProcessor
}{\param{wxCommandProcessor *
}{processor
}}
308 Sets the command processor to be used for this
document. The
document will then be responsible
309 for its deletion. Normally you should not call this; override OnCreateCommandProcessor
312 See
\helpref{wxCommandProcessor
}{wxcommandprocessor
}.
314 \membersection{wxDocument::SetDocumentName
}
316 \func{void
}{SetDocumentName
}{\param{const wxString\&
}{name
}}
318 Sets the
document type name for this
document. See the comment for
\helpref{documentTypeName
}{documenttypename
}.
320 \membersection{wxDocument::SetDocumentTemplate
}
322 \func{void
}{SetDocumentTemplate
}{\param{wxDocTemplate*
}{templ
}}
324 Sets the pointer to the template that created the
document. Should only be called by the
327 \membersection{wxDocument::SetFilename
}
329 \func{void
}{SetFilename
}{\param{const wxString\&
}{filename
}}
331 Sets the filename for this
document. Usually called by the framework.
333 \membersection{wxDocument::SetTitle
}
335 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
337 Sets the title for this
document. The
document title is used for an associated
338 frame (if any), and is usually constructed by the framework from
341 \membersection{wxDocument::UpdateAllViews
}\label{wxdocumentupdateallviews
}
343 \func{void
}{UpdateAllViews
}{\param{wxView*
}{sender = NULL
}}
345 Updates all views. If
{\it sender
} is non-NULL, does not update this view.