]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/document.tex
added wxNode::IndexOf and wxList::IndexOf (patch by Frank McIngvale)
[wxWidgets.git] / docs / latex / wx / document.tex
CommitLineData
a660d684
KB
1\section{\class{wxDocument}}\label{wxdocument}
2
3The document class can be used to model an application's file-based
4data. It is part of the document/view framework supported by wxWindows,
5and cooperates with the \helpref{wxView}{wxview}, \helpref{wxDocTemplate}{wxdoctemplate}\rtfsp
6and \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
24A pointer to the command processor associated with this document.
25
26\membersection{wxDocument::m\_documentFile}
27
28\member{wxString}{m\_documentFile}
29
30Filename associated with this document (``" if none).
31
32\membersection{wxDocument::m\_documentModified}
33
34\member{bool}{m\_documentModified}
35
36TRUE if the document has been modified, FALSE otherwise.
37
38\membersection{wxDocument::m\_documentTemplate}
39
40\member{wxDocTemplate *}{m\_documentTemplate}
41
42A pointer to the template from which this document was created.
43
44\membersection{wxDocument::m\_documentTitle}
45
46\member{wxString}{m\_documentTitle}
47
48Document title. The document title is used for an associated
49frame (if any), and is usually constructed by the framework from
50the filename.
51
52\membersection{wxDocument::m\_documentTypeName}\label{documenttypename}
53
54\member{wxString}{m\_documentTypeName}
55
56The document type name given to the wxDocTemplate constructor, copied to this
57variable when the document is created. If several document templates are
58created that use the same document type, this variable is used in wxDocManager::CreateView
59to collate a list of alternative view types that can be used on this kind of
60document. Do not change the value of this variable.
61
62\membersection{wxDocument::m\_documentViews}
63
64\member{wxList}{m\_documentViews}
65
66List of wxView instances associated with this document.
67
68\membersection{wxDocument::wxDocument}
69
70\func{}{wxDocument}{\void}
71
72Constructor. Define your own default constructor to initialize application-specific
73data.
74
75\membersection{wxDocument::\destruct{wxDocument}}
76
77\func{}{\destruct{wxDocument}}{\void}
78
79Destructor. Removes itself from the document manager.
80
81\membersection{wxDocument::AddView}
82
83\func{virtual bool}{AddView}{\param{wxView *}{view}}
84
85If 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
91Closes the document, by calling OnSaveModified and then (if this returned TRUE) OnCloseDocument.
92This 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
98Calls wxView::Close and deletes each view. Deleting the final view will implicitly
99delete the document itself, because the wxView destructor calls RemoveView. This
100in turns calls wxDocument::OnChangedViewList, whose default implemention is to
101save and delete the document if no views exist.
102
103\membersection{wxDocument::GetCommandProcessor}
104
105\constfunc{wxCommandProcessor*}{GetCommandProcessor}{\void}
106
107Returns a pointer to the command processor associated with this document.
108
109See \helpref{wxCommandProcessor}{wxcommandprocessor}.
110
111\membersection{wxDocument::GetDocumentTemplate}
112
113\constfunc{wxDocTemplate*}{GetDocumentTemplate}{\void}
114
115Gets a pointer to the template that created the document.
116
117\membersection{wxDocument::GetDocumentManager}
118
119\constfunc{wxDocManager*}{GetDocumentManager}{\void}
120
121Gets a pointer to the associated document manager.
122
123\membersection{wxDocument::GetDocumentName}
124
125\constfunc{wxString}{GetDocumentName}{\void}
126
127Gets 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
133Intended to return a suitable window for using as a parent for document-related
134dialog boxes. By default, uses the frame associated with the first view.
135
136\membersection{wxDocument::GetFilename}
137
138\constfunc{wxString}{GetFilename}{\void}
139
140Gets the filename associated with this document, or NULL if none is
141associated.
142
143\membersection{wxDocument::GetFirstView}
144
145\constfunc{wxView*}{GetFirstView}{\void}
146
147A convenience function to get the first view for a document, because
148in 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
154Copies a suitable document name into the supplied {\it name} buffer. The default
155function uses the title, or if there is no title, uses the filename; or if no
156filename, the string {\bf unnamed}.
157
158\membersection{wxDocument::GetTitle}
159
160\constfunc{wxString}{GetTitle}{\void}
161
162Gets the title for this document. The document title is used for an associated
163frame (if any), and is usually constructed by the framework from
164the filename.
165
166\membersection{wxDocument::IsModified}\label{wxdocumentismodified}
167
168\constfunc{virtual bool}{IsModified}{\void}
169
170Returns TRUE if the document has been modified since the last save, FALSE otherwise.
171You may need to override this if your document view maintains its own
172record of being modified (for example if using wxTextWindow to view and edit the document).
173
174See also \helpref{Modify}{wxdocumentmodify}.
175
176\membersection{wxDocument::LoadObject}
177
178\func{virtual istream\&}{LoadObject}{\param{istream\& }{stream}}
179
180Override this function and call it from your own LoadObject before
181streaming your own data. LoadObject is called by the framework
182automatically 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
188Call with TRUE to mark the document as modified since the last save, FALSE otherwise.
189You may need to override this if your document view maintains its own
190record of being modified (for example if using wxTextWindow to view and edit the document).
191
192See also \helpref{IsModified}{wxdocumentismodified}.
193
194\membersection{wxDocument::OnChangedViewList}
195
196\func{virtual void}{OnChangedViewList}{\void}
197
198Called when a view is added to or deleted from this document. The default
199implementation saves and deletes the document if no views exist (the last
200one has just been removed).
201
202\membersection{wxDocument::OnCloseDocument}
203
204\func{virtual bool}{OnCloseDocument}{\void}
205
206The default implementation calls DeleteContents (an empty implementation)
207sets the modified flag to FALSE. Override this to
208supply 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
214Called just after the document object is created to give it a chance
215to initialize itself. The default implementation uses the
216template associated with the document to create an initial view.
217If this function returns FALSE, the document is deleted.
218
219\membersection{wxDocument::OnCreateCommandProcessor}
220
221\func{virtual wxCommandProcessor*}{OnCreateCommandProcessor}{\void}
222
223Override this function if you want a different (or no) command processor
224to be created when the document is created. By default, it returns
225an instance of wxCommandProcessor.
226
227See \helpref{wxCommandProcessor}{wxcommandprocessor}.
228
229\membersection{wxDocument::OnNewDocument}
230
231\func{virtual bool}{OnNewDocument}{\void}
232
233The default implementation calls OnSaveModified and DeleteContents, makes a default title for the
234document, 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
240Constructs an input file stream for the given filename (which must not be NULL),
241and calls LoadObject. If LoadObject returns TRUE, the document is set to
242unmodified; otherwise, an error message box is displayed. The document's
243views are notified that the filename has changed, to give windows an opportunity
244to 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
250Constructs an output file stream for the given filename (which must not be NULL),
251and calls SaveObject. If SaveObject returns TRUE, the document is set to
252unmodified; otherwise, an error message box is displayed.
253
254\membersection{wxDocument::OnSaveModified}
255
256\func{virtual bool}{OnSaveModified}{\void}
257
258If the document has been modified, prompts the user to ask if the changes should
259be changed. If the user replies Yes, the Save function is called. If No, the
260document is marked as unmodified and the function succeeds. If Cancel, the
261function fails.
262
263\membersection{wxDocument::RemoveView}
264
265\func{virtual bool}{RemoveView}{\param{wxView* }{view}}
266
267Removes 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
273Saves the document by calling OnSaveDocument if there is an associated filename,
274or SaveAs if there is no filename.
275
276\membersection{wxDocument::SaveAs}
277
278\func{virtual bool}{SaveAs}{\void}
279
280Prompts 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
286Override this function and call it from your own SaveObject before
287streaming your own data. SaveObject is called by the framework
288automatically when the document contents need to be saved.
289
290\membersection{wxDocument::SetCommandProcessor}
291
292\func{virtual void}{SetCommandProcessor}{\param{wxCommandProcessor *}{processor}}
293
294Sets the command processor to be used for this document. The document will then be responsible
295for its deletion. Normally you should not call this; override OnCreateCommandProcessor
296instead.
297
298See \helpref{wxCommandProcessor}{wxcommandprocessor}.
299
300\membersection{wxDocument::SetDocumentName}
301
302\func{void}{SetDocumentName}{\param{const wxString\& }{name}}
303
304Sets 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
310Sets the pointer to the template that created the document. Should only be called by the
311framework.
312
313\membersection{wxDocument::SetFilename}
314
315\func{void}{SetFilename}{\param{const wxString\& }{filename}}
316
317Sets 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
323Sets the title for this document. The document title is used for an associated
324frame (if any), and is usually constructed by the framework from
325the filename.
326
7f555861 327\membersection{wxDocument::UpdateAllViews}\label{wxdocumentupdateallviews}
a660d684 328
7f555861
JS
329\func{void}{UpdateAllViews}{\param{wxView* }{sender = NULL}}
330
331Updates all views. If {\it sender} is non-NULL, does not update this view.