]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/document.tex
added wxLocale::IsAvailable() (extended patch 1547191)
[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
fc2171bd 4data. It is part of the document/view framework supported by wxWidgets,
a660d684
KB
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
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
28A 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
34Filename 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 40true 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
46A 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
52Document title. The document title is used for an associated
53frame (if any), and is usually constructed by the framework from
54the filename.
55
56\membersection{wxDocument::m\_documentTypeName}\label{documenttypename}
57
58\member{wxString}{m\_documentTypeName}
59
60The document type name given to the wxDocTemplate constructor, copied to this
61variable when the document is created. If several document templates are
62created that use the same document type, this variable is used in wxDocManager::CreateView
63to collate a list of alternative view types that can be used on this kind of
64document. 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
70List of wxView instances associated with this document.
71
b236c10f 72\membersection{wxDocument::wxDocument}\label{wxdocumentctor}
a660d684
KB
73
74\func{}{wxDocument}{\void}
75
76Constructor. Define your own default constructor to initialize application-specific
77data.
78
b236c10f 79\membersection{wxDocument::\destruct{wxDocument}}\label{wxdocumentdtor}
a660d684
KB
80
81\func{}{\destruct{wxDocument}}{\void}
82
83Destructor. 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
89If 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 95Closes the document, by calling OnSaveModified and then (if this returned true) OnCloseDocument.
a660d684
KB
96This 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
102Calls wxView::Close and deletes each view. Deleting the final view will implicitly
103delete the document itself, because the wxView destructor calls RemoveView. This
104in turns calls wxDocument::OnChangedViewList, whose default implemention is to
105save 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
111Returns a pointer to the command processor associated with this document.
112
113See \helpref{wxCommandProcessor}{wxcommandprocessor}.
114
b236c10f 115\membersection{wxDocument::GetDocumentTemplate}\label{wxdocumentgetdocumenttemplate}
a660d684
KB
116
117\constfunc{wxDocTemplate*}{GetDocumentTemplate}{\void}
118
119Gets 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
125Gets a pointer to the associated document manager.
126
b236c10f 127\membersection{wxDocument::GetDocumentName}\label{wxdocumentgetdocumentname}
a660d684
KB
128
129\constfunc{wxString}{GetDocumentName}{\void}
130
131Gets 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
137Intended to return a suitable window for using as a parent for document-related
138dialog 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 144Gets the filename associated with this document, or "" if none is
a660d684
KB
145associated.
146
6776a0b2 147\membersection{wxDocument::GetFirstView}\label{wxdocumentgetfirstview}
a660d684 148
4b21397f 149\constfunc{wxView *}{GetFirstView}{\void}
a660d684
KB
150
151A convenience function to get the first view for a document, because
152in many cases a document will only have a single view.
153
4b21397f
VZ
154See also: \helpref{GetViews}{wxdocumentgetviews}
155
b236c10f 156\membersection{wxDocument::GetPrintableName}\label{wxdocumentgetprintablename}
a660d684
KB
157
158\constfunc{virtual void}{GetPrintableName}{\param{wxString\& }{name}}
159
160Copies a suitable document name into the supplied {\it name} buffer. The default
161function uses the title, or if there is no title, uses the filename; or if no
162filename, the string {\bf unnamed}.
163
fa7161e0
MB
164\perlnote{In wxPerl this function must return the modified name rather
165than just modifying the argument.}
166
b236c10f 167\membersection{wxDocument::GetTitle}\label{wxdocumentgettitle}
a660d684
KB
168
169\constfunc{wxString}{GetTitle}{\void}
170
171Gets the title for this document. The document title is used for an associated
172frame (if any), and is usually constructed by the framework from
173the filename.
174
6776a0b2 175\membersection{wxDocument::GetViews}\label{wxdocumentgetviews}
4b21397f
VZ
176
177\constfunc{wxList \&}{GetViews}{\void}
178
179Returns the list whose elements are the views on the document.
180
181See also: \helpref{GetFirstView}{wxdocumentgetfirstview}
182
a660d684
KB
183\membersection{wxDocument::IsModified}\label{wxdocumentismodified}
184
185\constfunc{virtual bool}{IsModified}{\void}
186
cc81d32f 187Returns true if the document has been modified since the last save, false otherwise.
a660d684
KB
188You may need to override this if your document view maintains its own
189record of being modified (for example if using wxTextWindow to view and edit the document).
190
191See also \helpref{Modify}{wxdocumentmodify}.
192
b236c10f 193\membersection{wxDocument::LoadObject}\label{wxdocumentloadobject}
a660d684
KB
194
195\func{virtual istream\&}{LoadObject}{\param{istream\& }{stream}}
196
fa482912
JS
197\func{virtual wxInputStream\&}{LoadObject}{\param{wxInputStream\& }{stream}}
198
a660d684
KB
199Override this function and call it from your own LoadObject before
200streaming your own data. LoadObject is called by the framework
201automatically when the document contents need to be loaded.
202
fc2171bd 203Note that only one of these forms exists, depending on how wxWidgets
fa482912
JS
204was configured.
205
a660d684
KB
206\membersection{wxDocument::Modify}\label{wxdocumentmodify}
207
208\func{virtual void}{Modify}{\param{bool}{ modify}}
209
cc81d32f 210Call with true to mark the document as modified since the last save, false otherwise.
a660d684
KB
211You may need to override this if your document view maintains its own
212record of being modified (for example if using wxTextWindow to view and edit the document).
213
214See also \helpref{IsModified}{wxdocumentismodified}.
215
b236c10f 216\membersection{wxDocument::OnChangedViewList}\label{wxdocumentonchangedviewlist}
a660d684
KB
217
218\func{virtual void}{OnChangedViewList}{\void}
219
220Called when a view is added to or deleted from this document. The default
221implementation saves and deletes the document if no views exist (the last
222one has just been removed).
223
b236c10f 224\membersection{wxDocument::OnCloseDocument}\label{wxdocumentonclosedocument}
a660d684
KB
225
226\func{virtual bool}{OnCloseDocument}{\void}
227
228The default implementation calls DeleteContents (an empty implementation)
cc81d32f 229sets the modified flag to false. Override this to
a660d684
KB
230supply additional behaviour when the document is closed with Close.
231
b236c10f 232\membersection{wxDocument::OnCreate}\label{wxdocumentoncreate}
a660d684
KB
233
234\func{virtual bool}{OnCreate}{\param{const wxString\& }{path}, \param{long}{ flags}}
235
236Called just after the document object is created to give it a chance
237to initialize itself. The default implementation uses the
238template associated with the document to create an initial view.
cc81d32f 239If this function returns false, the document is deleted.
a660d684 240
b236c10f 241\membersection{wxDocument::OnCreateCommandProcessor}\label{wxdocumentoncreatecommandprocessor}
a660d684
KB
242
243\func{virtual wxCommandProcessor*}{OnCreateCommandProcessor}{\void}
244
245Override this function if you want a different (or no) command processor
246to be created when the document is created. By default, it returns
247an instance of wxCommandProcessor.
248
249See \helpref{wxCommandProcessor}{wxcommandprocessor}.
250
b236c10f 251\membersection{wxDocument::OnNewDocument}\label{wxdocumentonnewdocument}
a660d684
KB
252
253\func{virtual bool}{OnNewDocument}{\void}
254
255The default implementation calls OnSaveModified and DeleteContents, makes a default title for the
256document, and notifies the views that the filename (in fact, the title) has changed.
257
b236c10f 258\membersection{wxDocument::OnOpenDocument}\label{wxdocumentonopendocument}
a660d684
KB
259
260\func{virtual bool}{OnOpenDocument}{\param{const wxString\& }{filename}}
261
ad813b00 262Constructs an input file stream for the given filename (which must not be empty),
cc81d32f 263and calls LoadObject. If LoadObject returns true, the document is set to
a660d684
KB
264unmodified; otherwise, an error message box is displayed. The document's
265views are notified that the filename has changed, to give windows an opportunity
266to update their titles. All of the document's views are then updated.
267
b236c10f 268\membersection{wxDocument::OnSaveDocument}\label{wxdocumentonsavedocument}
a660d684
KB
269
270\func{virtual bool}{OnSaveDocument}{\param{const wxString\& }{filename}}
271
ad813b00 272Constructs an output file stream for the given filename (which must not be empty),
cc81d32f 273and calls SaveObject. If SaveObject returns true, the document is set to
a660d684
KB
274unmodified; otherwise, an error message box is displayed.
275
b236c10f 276\membersection{wxDocument::OnSaveModified}\label{wxdocumentonsavemodified}
a660d684
KB
277
278\func{virtual bool}{OnSaveModified}{\void}
279
280If the document has been modified, prompts the user to ask if the changes should
281be changed. If the user replies Yes, the Save function is called. If No, the
282document is marked as unmodified and the function succeeds. If Cancel, the
283function fails.
284
b236c10f 285\membersection{wxDocument::RemoveView}\label{wxdocumentremoveview}
a660d684
KB
286
287\func{virtual bool}{RemoveView}{\param{wxView* }{view}}
288
289Removes the view from the document's list of views, and calls OnChangedViewList.
290
b236c10f 291\membersection{wxDocument::Save}\label{wxdocumentsave}
a660d684
KB
292
293\func{virtual bool}{Save}{\void}
294
295Saves the document by calling OnSaveDocument if there is an associated filename,
296or SaveAs if there is no filename.
297
b236c10f 298\membersection{wxDocument::SaveAs}\label{wxdocumentsaveas}
a660d684
KB
299
300\func{virtual bool}{SaveAs}{\void}
301
302Prompts the user for a file to save to, and then calls OnSaveDocument.
303
b236c10f 304\membersection{wxDocument::SaveObject}\label{wxdocumentsaveobject}
a660d684
KB
305
306\func{virtual ostream\&}{SaveObject}{\param{ostream\& }{stream}}
307
fa482912
JS
308\func{virtual wxOutputStream\&}{SaveObject}{\param{wxOutputStream\& }{stream}}
309
a660d684
KB
310Override this function and call it from your own SaveObject before
311streaming your own data. SaveObject is called by the framework
312automatically when the document contents need to be saved.
313
fc2171bd 314Note that only one of these forms exists, depending on how wxWidgets
fa482912
JS
315was configured.
316
b236c10f 317\membersection{wxDocument::SetCommandProcessor}\label{wxdocumentsetcommandprocessor}
a660d684
KB
318
319\func{virtual void}{SetCommandProcessor}{\param{wxCommandProcessor *}{processor}}
320
321Sets the command processor to be used for this document. The document will then be responsible
322for its deletion. Normally you should not call this; override OnCreateCommandProcessor
323instead.
324
325See \helpref{wxCommandProcessor}{wxcommandprocessor}.
326
b236c10f 327\membersection{wxDocument::SetDocumentName}\label{wxdocumentsetdocumentname}
a660d684
KB
328
329\func{void}{SetDocumentName}{\param{const wxString\& }{name}}
330
331Sets the document type name for this document. See the comment for \helpref{documentTypeName}{documenttypename}.
332
b236c10f 333\membersection{wxDocument::SetDocumentTemplate}\label{wxdocumentsetdocumenttemplate}
a660d684
KB
334
335\func{void}{SetDocumentTemplate}{\param{wxDocTemplate* }{templ}}
336
337Sets the pointer to the template that created the document. Should only be called by the
338framework.
339
b236c10f 340\membersection{wxDocument::SetFilename}\label{wxdocumentsetfilename}
a660d684 341
cc81d32f 342\func{void}{SetFilename}{\param{const wxString\& }{filename}, \param{bool}{ notifyViews = false}}
a660d684
KB
343
344Sets the filename for this document. Usually called by the framework.
345
cc81d32f 346If {\it notifyViews} is true, wxView::OnChangeFilename is called for all views.
f6bcfd97 347
b236c10f 348\membersection{wxDocument::SetTitle}\label{wxdocumentsettitle}
a660d684
KB
349
350\func{void}{SetTitle}{\param{const wxString\& }{title}}
351
352Sets the title for this document. The document title is used for an associated
353frame (if any), and is usually constructed by the framework from
354the filename.
355
7f555861 356\membersection{wxDocument::UpdateAllViews}\label{wxdocumentupdateallviews}
a660d684 357
42bcb12b 358\func{void}{UpdateAllViews}{\param{wxView* }{sender = NULL}, \param{wxObject*}{ hint = NULL}}
7f555861
JS
359
360Updates all views. If {\it sender} is non-NULL, does not update this view.
62448488 361
42bcb12b
JS
362{\it hint} represents optional information to allow a view to optimize its update.
363