]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/document.tex
a bit more docs
[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{See also}
14
15 \helpref{wxDocument overview}{wxdocumentoverview}, \helpref{wxView}{wxview},\rtfsp
16 \helpref{wxDocTemplate}{wxdoctemplate}, \helpref{wxDocManager}{wxdocmanager}
17
18 \latexignore{\rtfignore{\wxheading{Members}}}
19
20 \membersection{wxDocument::m\_commandProcessor}
21
22 \member{wxCommandProcessor*}{m\_commandProcessor}
23
24 A pointer to the command processor associated with this document.
25
26 \membersection{wxDocument::m\_documentFile}
27
28 \member{wxString}{m\_documentFile}
29
30 Filename associated with this document (``" if none).
31
32 \membersection{wxDocument::m\_documentModified}
33
34 \member{bool}{m\_documentModified}
35
36 TRUE if the document has been modified, FALSE otherwise.
37
38 \membersection{wxDocument::m\_documentTemplate}
39
40 \member{wxDocTemplate *}{m\_documentTemplate}
41
42 A pointer to the template from which this document was created.
43
44 \membersection{wxDocument::m\_documentTitle}
45
46 \member{wxString}{m\_documentTitle}
47
48 Document title. The document title is used for an associated
49 frame (if any), and is usually constructed by the framework from
50 the filename.
51
52 \membersection{wxDocument::m\_documentTypeName}\label{documenttypename}
53
54 \member{wxString}{m\_documentTypeName}
55
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.
61
62 \membersection{wxDocument::m\_documentViews}
63
64 \member{wxList}{m\_documentViews}
65
66 List of wxView instances associated with this document.
67
68 \membersection{wxDocument::wxDocument}
69
70 \func{}{wxDocument}{\void}
71
72 Constructor. Define your own default constructor to initialize application-specific
73 data.
74
75 \membersection{wxDocument::\destruct{wxDocument}}
76
77 \func{}{\destruct{wxDocument}}{\void}
78
79 Destructor. Removes itself from the document manager.
80
81 \membersection{wxDocument::AddView}
82
83 \func{virtual bool}{AddView}{\param{wxView *}{view}}
84
85 If the view is not already in the list of views, adds the view and calls OnChangedViewList.
86
87 \membersection{wxDocument::Close}
88
89 \func{virtual bool}{Close}{\void}
90
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.
93
94 \membersection{wxDocument::DeleteAllViews}
95
96 \func{virtual bool}{DeleteAllViews}{\void}
97
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.
102
103 \membersection{wxDocument::GetCommandProcessor}
104
105 \constfunc{wxCommandProcessor*}{GetCommandProcessor}{\void}
106
107 Returns a pointer to the command processor associated with this document.
108
109 See \helpref{wxCommandProcessor}{wxcommandprocessor}.
110
111 \membersection{wxDocument::GetDocumentTemplate}
112
113 \constfunc{wxDocTemplate*}{GetDocumentTemplate}{\void}
114
115 Gets a pointer to the template that created the document.
116
117 \membersection{wxDocument::GetDocumentManager}
118
119 \constfunc{wxDocManager*}{GetDocumentManager}{\void}
120
121 Gets a pointer to the associated document manager.
122
123 \membersection{wxDocument::GetDocumentName}
124
125 \constfunc{wxString}{GetDocumentName}{\void}
126
127 Gets the document type name for this document. See the comment for \helpref{documentTypeName}{documenttypename}.
128
129 \membersection{wxDocument::GetDocumentWindow}
130
131 \constfunc{wxWindow*}{GetDocumentWindow}{\void}
132
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.
135
136 \membersection{wxDocument::GetFilename}
137
138 \constfunc{wxString}{GetFilename}{\void}
139
140 Gets the filename associated with this document, or NULL if none is
141 associated.
142
143 \membersection{wxDocument::GetFirstView}
144
145 \constfunc{wxView*}{GetFirstView}{\void}
146
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.
149
150 \membersection{wxDocument::GetPrintableName}
151
152 \constfunc{virtual void}{GetPrintableName}{\param{wxString\& }{name}}
153
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}.
157
158 \membersection{wxDocument::GetTitle}
159
160 \constfunc{wxString}{GetTitle}{\void}
161
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
164 the filename.
165
166 \membersection{wxDocument::IsModified}\label{wxdocumentismodified}
167
168 \constfunc{virtual bool}{IsModified}{\void}
169
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).
173
174 See also \helpref{Modify}{wxdocumentmodify}.
175
176 \membersection{wxDocument::LoadObject}
177
178 \func{virtual istream\&}{LoadObject}{\param{istream\& }{stream}}
179
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.
183
184 \membersection{wxDocument::Modify}\label{wxdocumentmodify}
185
186 \func{virtual void}{Modify}{\param{bool}{ modify}}
187
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).
191
192 See also \helpref{IsModified}{wxdocumentismodified}.
193
194 \membersection{wxDocument::OnChangedViewList}
195
196 \func{virtual void}{OnChangedViewList}{\void}
197
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).
201
202 \membersection{wxDocument::OnCloseDocument}
203
204 \func{virtual bool}{OnCloseDocument}{\void}
205
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.
209
210 \membersection{wxDocument::OnCreate}
211
212 \func{virtual bool}{OnCreate}{\param{const wxString\& }{path}, \param{long}{ flags}}
213
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.
218
219 \membersection{wxDocument::OnCreateCommandProcessor}
220
221 \func{virtual wxCommandProcessor*}{OnCreateCommandProcessor}{\void}
222
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.
226
227 See \helpref{wxCommandProcessor}{wxcommandprocessor}.
228
229 \membersection{wxDocument::OnNewDocument}
230
231 \func{virtual bool}{OnNewDocument}{\void}
232
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.
235
236 \membersection{wxDocument::OnOpenDocument}
237
238 \func{virtual bool}{OnOpenDocument}{\param{const wxString\& }{filename}}
239
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.
245
246 \membersection{wxDocument::OnSaveDocument}
247
248 \func{virtual bool}{OnSaveDocument}{\param{const wxString\& }{filename}}
249
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.
253
254 \membersection{wxDocument::OnSaveModified}
255
256 \func{virtual bool}{OnSaveModified}{\void}
257
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
261 function fails.
262
263 \membersection{wxDocument::RemoveView}
264
265 \func{virtual bool}{RemoveView}{\param{wxView* }{view}}
266
267 Removes the view from the document's list of views, and calls OnChangedViewList.
268
269 \membersection{wxDocument::Save}
270
271 \func{virtual bool}{Save}{\void}
272
273 Saves the document by calling OnSaveDocument if there is an associated filename,
274 or SaveAs if there is no filename.
275
276 \membersection{wxDocument::SaveAs}
277
278 \func{virtual bool}{SaveAs}{\void}
279
280 Prompts the user for a file to save to, and then calls OnSaveDocument.
281
282 \membersection{wxDocument::SaveObject}
283
284 \func{virtual ostream\&}{SaveObject}{\param{ostream\& }{stream}}
285
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.
289
290 \membersection{wxDocument::SetCommandProcessor}
291
292 \func{virtual void}{SetCommandProcessor}{\param{wxCommandProcessor *}{processor}}
293
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
296 instead.
297
298 See \helpref{wxCommandProcessor}{wxcommandprocessor}.
299
300 \membersection{wxDocument::SetDocumentName}
301
302 \func{void}{SetDocumentName}{\param{const wxString\& }{name}}
303
304 Sets the document type name for this document. See the comment for \helpref{documentTypeName}{documenttypename}.
305
306 \membersection{wxDocument::SetDocumentTemplate}
307
308 \func{void}{SetDocumentTemplate}{\param{wxDocTemplate* }{templ}}
309
310 Sets the pointer to the template that created the document. Should only be called by the
311 framework.
312
313 \membersection{wxDocument::SetFilename}
314
315 \func{void}{SetFilename}{\param{const wxString\& }{filename}}
316
317 Sets the filename for this document. Usually called by the framework.
318
319 \membersection{wxDocument::SetTitle}
320
321 \func{void}{SetTitle}{\param{const wxString\& }{title}}
322
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
325 the filename.
326
327 \membersection{wxDocument::UpdateAllViews}\label{wxdocumentupdateallviews}
328
329 \func{void}{UpdateAllViews}{\param{wxView* }{sender = NULL}}
330
331 Updates all views. If {\it sender} is non-NULL, does not update this view.
332