]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/document.tex
eb2c774a2db051d55c65b8efee29a50bb2ee15f0
[wxWidgets.git] / docs / latex / wx / document.tex
1 \section{\class{wxDocument}}\label{wxdocument}
2
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.
7
8 \wxheading{Derived from}
9
10 \helpref{wxEvtHandler}{wxevthandler}\\
11 \helpref{wxObject}{wxobject}
12
13 \wxheading{Include files}
14
15 <wx/docview.h>
16
17 \wxheading{See also}
18
19 \helpref{wxDocument overview}{wxdocumentoverview}, \helpref{wxView}{wxview},\rtfsp
20 \helpref{wxDocTemplate}{wxdoctemplate}, \helpref{wxDocManager}{wxdocmanager}
21
22 \latexignore{\rtfignore{\wxheading{Members}}}
23
24 \membersection{wxDocument::m\_commandProcessor}
25
26 \member{wxCommandProcessor*}{m\_commandProcessor}
27
28 A pointer to the command processor associated with this document.
29
30 \membersection{wxDocument::m\_documentFile}
31
32 \member{wxString}{m\_documentFile}
33
34 Filename associated with this document (``" if none).
35
36 \membersection{wxDocument::m\_documentModified}
37
38 \member{bool}{m\_documentModified}
39
40 true if the document has been modified, false otherwise.
41
42 \membersection{wxDocument::m\_documentTemplate}
43
44 \member{wxDocTemplate *}{m\_documentTemplate}
45
46 A pointer to the template from which this document was created.
47
48 \membersection{wxDocument::m\_documentTitle}
49
50 \member{wxString}{m\_documentTitle}
51
52 Document title. The document title is used for an associated
53 frame (if any), and is usually constructed by the framework from
54 the filename.
55
56 \membersection{wxDocument::m\_documentTypeName}\label{documenttypename}
57
58 \member{wxString}{m\_documentTypeName}
59
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.
65
66 \membersection{wxDocument::m\_documentViews}
67
68 \member{wxList}{m\_documentViews}
69
70 List of wxView instances associated with this document.
71
72 \membersection{wxDocument::wxDocument}
73
74 \func{}{wxDocument}{\void}
75
76 Constructor. Define your own default constructor to initialize application-specific
77 data.
78
79 \membersection{wxDocument::\destruct{wxDocument}}
80
81 \func{}{\destruct{wxDocument}}{\void}
82
83 Destructor. Removes itself from the document manager.
84
85 \membersection{wxDocument::AddView}
86
87 \func{virtual bool}{AddView}{\param{wxView *}{view}}
88
89 If the view is not already in the list of views, adds the view and calls OnChangedViewList.
90
91 \membersection{wxDocument::Close}
92
93 \func{virtual bool}{Close}{\void}
94
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.
97
98 \membersection{wxDocument::DeleteAllViews}
99
100 \func{virtual bool}{DeleteAllViews}{\void}
101
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.
106
107 \membersection{wxDocument::GetCommandProcessor}
108
109 \constfunc{wxCommandProcessor*}{GetCommandProcessor}{\void}
110
111 Returns a pointer to the command processor associated with this document.
112
113 See \helpref{wxCommandProcessor}{wxcommandprocessor}.
114
115 \membersection{wxDocument::GetDocumentTemplate}
116
117 \constfunc{wxDocTemplate*}{GetDocumentTemplate}{\void}
118
119 Gets a pointer to the template that created the document.
120
121 \membersection{wxDocument::GetDocumentManager}
122
123 \constfunc{wxDocManager*}{GetDocumentManager}{\void}
124
125 Gets a pointer to the associated document manager.
126
127 \membersection{wxDocument::GetDocumentName}
128
129 \constfunc{wxString}{GetDocumentName}{\void}
130
131 Gets the document type name for this document. See the comment for \helpref{documentTypeName}{documenttypename}.
132
133 \membersection{wxDocument::GetDocumentWindow}
134
135 \constfunc{wxWindow*}{GetDocumentWindow}{\void}
136
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.
139
140 \membersection{wxDocument::GetFilename}
141
142 \constfunc{wxString}{GetFilename}{\void}
143
144 Gets the filename associated with this document, or "" if none is
145 associated.
146
147 \membersection{wxDocument::GetFirstView}\label{wxdocumentgetfirstview}
148
149 \constfunc{wxView *}{GetFirstView}{\void}
150
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.
153
154 See also: \helpref{GetViews}{wxdocumentgetviews}
155
156 \membersection{wxDocument::GetPrintableName}
157
158 \constfunc{virtual void}{GetPrintableName}{\param{wxString\& }{name}}
159
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}.
163
164 \perlnote{In wxPerl this function must return the modified name rather
165 than just modifying the argument.}
166
167 \membersection{wxDocument::GetTitle}
168
169 \constfunc{wxString}{GetTitle}{\void}
170
171 Gets the title for this document. The document title is used for an associated
172 frame (if any), and is usually constructed by the framework from
173 the filename.
174
175 \membersection{wxDocument::GetViews}\label{wxdocumentgetviews}
176
177 \constfunc{wxList \&}{GetViews}{\void}
178
179 Returns the list whose elements are the views on the document.
180
181 See also: \helpref{GetFirstView}{wxdocumentgetfirstview}
182
183 \membersection{wxDocument::IsModified}\label{wxdocumentismodified}
184
185 \constfunc{virtual bool}{IsModified}{\void}
186
187 Returns true if the document has been modified since the last save, false otherwise.
188 You may need to override this if your document view maintains its own
189 record of being modified (for example if using wxTextWindow to view and edit the document).
190
191 See also \helpref{Modify}{wxdocumentmodify}.
192
193 \membersection{wxDocument::LoadObject}
194
195 \func{virtual istream\&}{LoadObject}{\param{istream\& }{stream}}
196
197 \func{virtual wxInputStream\&}{LoadObject}{\param{wxInputStream\& }{stream}}
198
199 Override this function and call it from your own LoadObject before
200 streaming your own data. LoadObject is called by the framework
201 automatically when the document contents need to be loaded.
202
203 Note that only one of these forms exists, depending on how wxWindows
204 was configured.
205
206 \membersection{wxDocument::Modify}\label{wxdocumentmodify}
207
208 \func{virtual void}{Modify}{\param{bool}{ modify}}
209
210 Call with true to mark the document as modified since the last save, false otherwise.
211 You may need to override this if your document view maintains its own
212 record of being modified (for example if using wxTextWindow to view and edit the document).
213
214 See also \helpref{IsModified}{wxdocumentismodified}.
215
216 \membersection{wxDocument::OnChangedViewList}
217
218 \func{virtual void}{OnChangedViewList}{\void}
219
220 Called when a view is added to or deleted from this document. The default
221 implementation saves and deletes the document if no views exist (the last
222 one has just been removed).
223
224 \membersection{wxDocument::OnCloseDocument}
225
226 \func{virtual bool}{OnCloseDocument}{\void}
227
228 The default implementation calls DeleteContents (an empty implementation)
229 sets the modified flag to false. Override this to
230 supply additional behaviour when the document is closed with Close.
231
232 \membersection{wxDocument::OnCreate}
233
234 \func{virtual bool}{OnCreate}{\param{const wxString\& }{path}, \param{long}{ flags}}
235
236 Called just after the document object is created to give it a chance
237 to initialize itself. The default implementation uses the
238 template associated with the document to create an initial view.
239 If this function returns false, the document is deleted.
240
241 \membersection{wxDocument::OnCreateCommandProcessor}
242
243 \func{virtual wxCommandProcessor*}{OnCreateCommandProcessor}{\void}
244
245 Override this function if you want a different (or no) command processor
246 to be created when the document is created. By default, it returns
247 an instance of wxCommandProcessor.
248
249 See \helpref{wxCommandProcessor}{wxcommandprocessor}.
250
251 \membersection{wxDocument::OnNewDocument}
252
253 \func{virtual bool}{OnNewDocument}{\void}
254
255 The default implementation calls OnSaveModified and DeleteContents, makes a default title for the
256 document, and notifies the views that the filename (in fact, the title) has changed.
257
258 \membersection{wxDocument::OnOpenDocument}
259
260 \func{virtual bool}{OnOpenDocument}{\param{const wxString\& }{filename}}
261
262 Constructs an input file stream for the given filename (which must not be empty),
263 and calls LoadObject. If LoadObject returns true, the document is set to
264 unmodified; otherwise, an error message box is displayed. The document's
265 views are notified that the filename has changed, to give windows an opportunity
266 to update their titles. All of the document's views are then updated.
267
268 \membersection{wxDocument::OnSaveDocument}
269
270 \func{virtual bool}{OnSaveDocument}{\param{const wxString\& }{filename}}
271
272 Constructs an output file stream for the given filename (which must not be empty),
273 and calls SaveObject. If SaveObject returns true, the document is set to
274 unmodified; otherwise, an error message box is displayed.
275
276 \membersection{wxDocument::OnSaveModified}
277
278 \func{virtual bool}{OnSaveModified}{\void}
279
280 If the document has been modified, prompts the user to ask if the changes should
281 be changed. If the user replies Yes, the Save function is called. If No, the
282 document is marked as unmodified and the function succeeds. If Cancel, the
283 function fails.
284
285 \membersection{wxDocument::RemoveView}
286
287 \func{virtual bool}{RemoveView}{\param{wxView* }{view}}
288
289 Removes the view from the document's list of views, and calls OnChangedViewList.
290
291 \membersection{wxDocument::Save}
292
293 \func{virtual bool}{Save}{\void}
294
295 Saves the document by calling OnSaveDocument if there is an associated filename,
296 or SaveAs if there is no filename.
297
298 \membersection{wxDocument::SaveAs}
299
300 \func{virtual bool}{SaveAs}{\void}
301
302 Prompts the user for a file to save to, and then calls OnSaveDocument.
303
304 \membersection{wxDocument::SaveObject}
305
306 \func{virtual ostream\&}{SaveObject}{\param{ostream\& }{stream}}
307
308 \func{virtual wxOutputStream\&}{SaveObject}{\param{wxOutputStream\& }{stream}}
309
310 Override this function and call it from your own SaveObject before
311 streaming your own data. SaveObject is called by the framework
312 automatically when the document contents need to be saved.
313
314 Note that only one of these forms exists, depending on how wxWindows
315 was configured.
316
317 \membersection{wxDocument::SetCommandProcessor}
318
319 \func{virtual void}{SetCommandProcessor}{\param{wxCommandProcessor *}{processor}}
320
321 Sets the command processor to be used for this document. The document will then be responsible
322 for its deletion. Normally you should not call this; override OnCreateCommandProcessor
323 instead.
324
325 See \helpref{wxCommandProcessor}{wxcommandprocessor}.
326
327 \membersection{wxDocument::SetDocumentName}
328
329 \func{void}{SetDocumentName}{\param{const wxString\& }{name}}
330
331 Sets the document type name for this document. See the comment for \helpref{documentTypeName}{documenttypename}.
332
333 \membersection{wxDocument::SetDocumentTemplate}
334
335 \func{void}{SetDocumentTemplate}{\param{wxDocTemplate* }{templ}}
336
337 Sets the pointer to the template that created the document. Should only be called by the
338 framework.
339
340 \membersection{wxDocument::SetFilename}
341
342 \func{void}{SetFilename}{\param{const wxString\& }{filename}, \param{bool}{ notifyViews = false}}
343
344 Sets the filename for this document. Usually called by the framework.
345
346 If {\it notifyViews} is true, wxView::OnChangeFilename is called for all views.
347
348 \membersection{wxDocument::SetTitle}
349
350 \func{void}{SetTitle}{\param{const wxString\& }{title}}
351
352 Sets the title for this document. The document title is used for an associated
353 frame (if any), and is usually constructed by the framework from
354 the filename.
355
356 \membersection{wxDocument::UpdateAllViews}\label{wxdocumentupdateallviews}
357
358 \func{void}{UpdateAllViews}{\param{wxView* }{sender = NULL}, \param{wxObject*}{ hint = NULL}}
359
360 Updates all views. If {\it sender} is non-NULL, does not update this view.
361
362 {\it hint} represents optional information to allow a view to optimize its update.
363