]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
1 | \section{\class{wxDocument}}\label{wxdocument} |
2 | ||
3 | The document class can be used to model an application's file-based | |
fc2171bd | 4 | data. It is part of the document/view framework supported by wxWidgets, |
a660d684 KB |
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 | ||
954b8ae6 JS |
13 | \wxheading{Include files} |
14 | ||
15 | <wx/docview.h> | |
16 | ||
a660d684 KB |
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 | ||
b236c10f | 24 | \membersection{wxDocument::m\_commandProcessor}\label{wxdocumentmcommandprocessor} |
a660d684 KB |
25 | |
26 | \member{wxCommandProcessor*}{m\_commandProcessor} | |
27 | ||
28 | A pointer to the command processor associated with this document. | |
29 | ||
b236c10f | 30 | \membersection{wxDocument::m\_documentFile}\label{wxdocumentmdocumentfile} |
a660d684 KB |
31 | |
32 | \member{wxString}{m\_documentFile} | |
33 | ||
34 | Filename associated with this document (``" if none). | |
35 | ||
b236c10f | 36 | \membersection{wxDocument::m\_documentModified}\label{wxdocumentmdocumentmodified} |
a660d684 KB |
37 | |
38 | \member{bool}{m\_documentModified} | |
39 | ||
cc81d32f | 40 | true if the document has been modified, false otherwise. |
a660d684 | 41 | |
b236c10f | 42 | \membersection{wxDocument::m\_documentTemplate}\label{wxdocumentmdocumenttemplate} |
a660d684 KB |
43 | |
44 | \member{wxDocTemplate *}{m\_documentTemplate} | |
45 | ||
46 | A pointer to the template from which this document was created. | |
47 | ||
b236c10f | 48 | \membersection{wxDocument::m\_documentTitle}\label{wxdocumentmdocumenttitle} |
a660d684 KB |
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 | ||
b236c10f | 66 | \membersection{wxDocument::m\_documentViews}\label{wxdocumentmdocumentviews} |
a660d684 KB |
67 | |
68 | \member{wxList}{m\_documentViews} | |
69 | ||
70 | List of wxView instances associated with this document. | |
71 | ||
b236c10f | 72 | \membersection{wxDocument::wxDocument}\label{wxdocumentctor} |
a660d684 KB |
73 | |
74 | \func{}{wxDocument}{\void} | |
75 | ||
76 | Constructor. Define your own default constructor to initialize application-specific | |
77 | data. | |
78 | ||
b236c10f | 79 | \membersection{wxDocument::\destruct{wxDocument}}\label{wxdocumentdtor} |
a660d684 KB |
80 | |
81 | \func{}{\destruct{wxDocument}}{\void} | |
82 | ||
83 | Destructor. Removes itself from the document manager. | |
84 | ||
b236c10f | 85 | \membersection{wxDocument::AddView}\label{wxdocumentaddview} |
a660d684 KB |
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 | ||
b236c10f | 91 | \membersection{wxDocument::Close}\label{wxdocumentclose} |
a660d684 KB |
92 | |
93 | \func{virtual bool}{Close}{\void} | |
94 | ||
cc81d32f | 95 | Closes the document, by calling OnSaveModified and then (if this returned true) OnCloseDocument. |
a660d684 KB |
96 | This does not normally delete the document object: use DeleteAllViews to do this implicitly. |
97 | ||
b236c10f | 98 | \membersection{wxDocument::DeleteAllViews}\label{wxdocumentdeleteviews} |
a660d684 KB |
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 | ||
b236c10f | 107 | \membersection{wxDocument::GetCommandProcessor}\label{wxdocumentgetcommandprocessor} |
a660d684 KB |
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 | ||
b236c10f | 115 | \membersection{wxDocument::GetDocumentTemplate}\label{wxdocumentgetdocumenttemplate} |
a660d684 KB |
116 | |
117 | \constfunc{wxDocTemplate*}{GetDocumentTemplate}{\void} | |
118 | ||
119 | Gets a pointer to the template that created the document. | |
120 | ||
b236c10f | 121 | \membersection{wxDocument::GetDocumentManager}\label{wxdocumentgetdocumentmanager} |
a660d684 KB |
122 | |
123 | \constfunc{wxDocManager*}{GetDocumentManager}{\void} | |
124 | ||
125 | Gets a pointer to the associated document manager. | |
126 | ||
b236c10f | 127 | \membersection{wxDocument::GetDocumentName}\label{wxdocumentgetdocumentname} |
a660d684 KB |
128 | |
129 | \constfunc{wxString}{GetDocumentName}{\void} | |
130 | ||
131 | Gets the document type name for this document. See the comment for \helpref{documentTypeName}{documenttypename}. | |
132 | ||
b236c10f | 133 | \membersection{wxDocument::GetDocumentWindow}\label{wxdocumentgetdocumentwindow} |
a660d684 KB |
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 | ||
b236c10f | 140 | \membersection{wxDocument::GetFilename}\label{wxdocumentgetfilename} |
a660d684 KB |
141 | |
142 | \constfunc{wxString}{GetFilename}{\void} | |
143 | ||
ad813b00 | 144 | Gets the filename associated with this document, or "" if none is |
a660d684 KB |
145 | associated. |
146 | ||
6776a0b2 | 147 | \membersection{wxDocument::GetFirstView}\label{wxdocumentgetfirstview} |
a660d684 | 148 | |
4b21397f | 149 | \constfunc{wxView *}{GetFirstView}{\void} |
a660d684 KB |
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 | ||
4b21397f VZ |
154 | See also: \helpref{GetViews}{wxdocumentgetviews} |
155 | ||
724b119a | 156 | \membersection{wxDocument::GetUserReadableName}\label{wxdocumentgetuserreadablentablename} |
a660d684 | 157 | |
724b119a | 158 | \constfunc{virtual wxString}{GetUserReadableName}{\void} |
a660d684 | 159 | |
724b119a VZ |
160 | Return the document name suitable to be shown to the user. The default |
161 | implementation uses the document title, if any, of the name part of the | |
162 | document filename if it was set or, otherwise, the string {\bf unnamed}. | |
fa7161e0 | 163 | |
b236c10f | 164 | \membersection{wxDocument::GetTitle}\label{wxdocumentgettitle} |
a660d684 KB |
165 | |
166 | \constfunc{wxString}{GetTitle}{\void} | |
167 | ||
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 | |
170 | the filename. | |
171 | ||
6776a0b2 | 172 | \membersection{wxDocument::GetViews}\label{wxdocumentgetviews} |
4b21397f VZ |
173 | |
174 | \constfunc{wxList \&}{GetViews}{\void} | |
175 | ||
176 | Returns the list whose elements are the views on the document. | |
177 | ||
178 | See also: \helpref{GetFirstView}{wxdocumentgetfirstview} | |
179 | ||
a660d684 KB |
180 | \membersection{wxDocument::IsModified}\label{wxdocumentismodified} |
181 | ||
182 | \constfunc{virtual bool}{IsModified}{\void} | |
183 | ||
cc81d32f | 184 | Returns true if the document has been modified since the last save, false otherwise. |
a660d684 KB |
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). | |
187 | ||
188 | See also \helpref{Modify}{wxdocumentmodify}. | |
189 | ||
b236c10f | 190 | \membersection{wxDocument::LoadObject}\label{wxdocumentloadobject} |
a660d684 KB |
191 | |
192 | \func{virtual istream\&}{LoadObject}{\param{istream\& }{stream}} | |
193 | ||
fa482912 JS |
194 | \func{virtual wxInputStream\&}{LoadObject}{\param{wxInputStream\& }{stream}} |
195 | ||
a660d684 KB |
196 | Override this function and call it from your own LoadObject before |
197 | streaming your own data. LoadObject is called by the framework | |
198 | automatically when the document contents need to be loaded. | |
199 | ||
fc2171bd | 200 | Note that only one of these forms exists, depending on how wxWidgets |
fa482912 JS |
201 | was configured. |
202 | ||
a660d684 KB |
203 | \membersection{wxDocument::Modify}\label{wxdocumentmodify} |
204 | ||
205 | \func{virtual void}{Modify}{\param{bool}{ modify}} | |
206 | ||
cc81d32f | 207 | Call with true to mark the document as modified since the last save, false otherwise. |
a660d684 KB |
208 | You may need to override this if your document view maintains its own |
209 | record of being modified (for example if using wxTextWindow to view and edit the document). | |
210 | ||
211 | See also \helpref{IsModified}{wxdocumentismodified}. | |
212 | ||
b236c10f | 213 | \membersection{wxDocument::OnChangedViewList}\label{wxdocumentonchangedviewlist} |
a660d684 KB |
214 | |
215 | \func{virtual void}{OnChangedViewList}{\void} | |
216 | ||
217 | Called when a view is added to or deleted from this document. The default | |
218 | implementation saves and deletes the document if no views exist (the last | |
219 | one has just been removed). | |
220 | ||
b236c10f | 221 | \membersection{wxDocument::OnCloseDocument}\label{wxdocumentonclosedocument} |
a660d684 KB |
222 | |
223 | \func{virtual bool}{OnCloseDocument}{\void} | |
224 | ||
225 | The default implementation calls DeleteContents (an empty implementation) | |
cc81d32f | 226 | sets the modified flag to false. Override this to |
a660d684 KB |
227 | supply additional behaviour when the document is closed with Close. |
228 | ||
b236c10f | 229 | \membersection{wxDocument::OnCreate}\label{wxdocumentoncreate} |
a660d684 KB |
230 | |
231 | \func{virtual bool}{OnCreate}{\param{const wxString\& }{path}, \param{long}{ flags}} | |
232 | ||
233 | Called just after the document object is created to give it a chance | |
234 | to initialize itself. The default implementation uses the | |
235 | template associated with the document to create an initial view. | |
cc81d32f | 236 | If this function returns false, the document is deleted. |
a660d684 | 237 | |
b236c10f | 238 | \membersection{wxDocument::OnCreateCommandProcessor}\label{wxdocumentoncreatecommandprocessor} |
a660d684 KB |
239 | |
240 | \func{virtual wxCommandProcessor*}{OnCreateCommandProcessor}{\void} | |
241 | ||
242 | Override this function if you want a different (or no) command processor | |
243 | to be created when the document is created. By default, it returns | |
244 | an instance of wxCommandProcessor. | |
245 | ||
246 | See \helpref{wxCommandProcessor}{wxcommandprocessor}. | |
247 | ||
b236c10f | 248 | \membersection{wxDocument::OnNewDocument}\label{wxdocumentonnewdocument} |
a660d684 KB |
249 | |
250 | \func{virtual bool}{OnNewDocument}{\void} | |
251 | ||
252 | The default implementation calls OnSaveModified and DeleteContents, makes a default title for the | |
253 | document, and notifies the views that the filename (in fact, the title) has changed. | |
254 | ||
b236c10f | 255 | \membersection{wxDocument::OnOpenDocument}\label{wxdocumentonopendocument} |
a660d684 KB |
256 | |
257 | \func{virtual bool}{OnOpenDocument}{\param{const wxString\& }{filename}} | |
258 | ||
ad813b00 | 259 | Constructs an input file stream for the given filename (which must not be empty), |
cc81d32f | 260 | and calls LoadObject. If LoadObject returns true, the document is set to |
a660d684 KB |
261 | unmodified; otherwise, an error message box is displayed. The document's |
262 | views are notified that the filename has changed, to give windows an opportunity | |
263 | to update their titles. All of the document's views are then updated. | |
264 | ||
b236c10f | 265 | \membersection{wxDocument::OnSaveDocument}\label{wxdocumentonsavedocument} |
a660d684 KB |
266 | |
267 | \func{virtual bool}{OnSaveDocument}{\param{const wxString\& }{filename}} | |
268 | ||
ad813b00 | 269 | Constructs an output file stream for the given filename (which must not be empty), |
cc81d32f | 270 | and calls SaveObject. If SaveObject returns true, the document is set to |
a660d684 KB |
271 | unmodified; otherwise, an error message box is displayed. |
272 | ||
b236c10f | 273 | \membersection{wxDocument::OnSaveModified}\label{wxdocumentonsavemodified} |
a660d684 KB |
274 | |
275 | \func{virtual bool}{OnSaveModified}{\void} | |
276 | ||
277 | If the document has been modified, prompts the user to ask if the changes should | |
278 | be changed. If the user replies Yes, the Save function is called. If No, the | |
279 | document is marked as unmodified and the function succeeds. If Cancel, the | |
280 | function fails. | |
281 | ||
b236c10f | 282 | \membersection{wxDocument::RemoveView}\label{wxdocumentremoveview} |
a660d684 KB |
283 | |
284 | \func{virtual bool}{RemoveView}{\param{wxView* }{view}} | |
285 | ||
286 | Removes the view from the document's list of views, and calls OnChangedViewList. | |
287 | ||
b236c10f | 288 | \membersection{wxDocument::Save}\label{wxdocumentsave} |
a660d684 KB |
289 | |
290 | \func{virtual bool}{Save}{\void} | |
291 | ||
292 | Saves the document by calling OnSaveDocument if there is an associated filename, | |
293 | or SaveAs if there is no filename. | |
294 | ||
b236c10f | 295 | \membersection{wxDocument::SaveAs}\label{wxdocumentsaveas} |
a660d684 KB |
296 | |
297 | \func{virtual bool}{SaveAs}{\void} | |
298 | ||
299 | Prompts the user for a file to save to, and then calls OnSaveDocument. | |
300 | ||
b236c10f | 301 | \membersection{wxDocument::SaveObject}\label{wxdocumentsaveobject} |
a660d684 KB |
302 | |
303 | \func{virtual ostream\&}{SaveObject}{\param{ostream\& }{stream}} | |
304 | ||
fa482912 JS |
305 | \func{virtual wxOutputStream\&}{SaveObject}{\param{wxOutputStream\& }{stream}} |
306 | ||
a660d684 KB |
307 | Override this function and call it from your own SaveObject before |
308 | streaming your own data. SaveObject is called by the framework | |
309 | automatically when the document contents need to be saved. | |
310 | ||
fc2171bd | 311 | Note that only one of these forms exists, depending on how wxWidgets |
fa482912 JS |
312 | was configured. |
313 | ||
b236c10f | 314 | \membersection{wxDocument::SetCommandProcessor}\label{wxdocumentsetcommandprocessor} |
a660d684 KB |
315 | |
316 | \func{virtual void}{SetCommandProcessor}{\param{wxCommandProcessor *}{processor}} | |
317 | ||
318 | Sets the command processor to be used for this document. The document will then be responsible | |
319 | for its deletion. Normally you should not call this; override OnCreateCommandProcessor | |
320 | instead. | |
321 | ||
322 | See \helpref{wxCommandProcessor}{wxcommandprocessor}. | |
323 | ||
b236c10f | 324 | \membersection{wxDocument::SetDocumentName}\label{wxdocumentsetdocumentname} |
a660d684 KB |
325 | |
326 | \func{void}{SetDocumentName}{\param{const wxString\& }{name}} | |
327 | ||
328 | Sets the document type name for this document. See the comment for \helpref{documentTypeName}{documenttypename}. | |
329 | ||
b236c10f | 330 | \membersection{wxDocument::SetDocumentTemplate}\label{wxdocumentsetdocumenttemplate} |
a660d684 KB |
331 | |
332 | \func{void}{SetDocumentTemplate}{\param{wxDocTemplate* }{templ}} | |
333 | ||
334 | Sets the pointer to the template that created the document. Should only be called by the | |
335 | framework. | |
336 | ||
b236c10f | 337 | \membersection{wxDocument::SetFilename}\label{wxdocumentsetfilename} |
a660d684 | 338 | |
cc81d32f | 339 | \func{void}{SetFilename}{\param{const wxString\& }{filename}, \param{bool}{ notifyViews = false}} |
a660d684 KB |
340 | |
341 | Sets the filename for this document. Usually called by the framework. | |
342 | ||
cc81d32f | 343 | If {\it notifyViews} is true, wxView::OnChangeFilename is called for all views. |
f6bcfd97 | 344 | |
b236c10f | 345 | \membersection{wxDocument::SetTitle}\label{wxdocumentsettitle} |
a660d684 KB |
346 | |
347 | \func{void}{SetTitle}{\param{const wxString\& }{title}} | |
348 | ||
349 | Sets the title for this document. The document title is used for an associated | |
350 | frame (if any), and is usually constructed by the framework from | |
351 | the filename. | |
352 | ||
7f555861 | 353 | \membersection{wxDocument::UpdateAllViews}\label{wxdocumentupdateallviews} |
a660d684 | 354 | |
42bcb12b | 355 | \func{void}{UpdateAllViews}{\param{wxView* }{sender = NULL}, \param{wxObject*}{ hint = NULL}} |
7f555861 JS |
356 | |
357 | Updates all views. If {\it sender} is non-NULL, does not update this view. | |
62448488 | 358 | |
42bcb12b JS |
359 | {\it hint} represents optional information to allow a view to optimize its update. |
360 |