]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/docmanag.tex
added wxMBConv parameter for wxFFile::ReadAll() and documented it (improved patch...
[wxWidgets.git] / docs / latex / wx / docmanag.tex
CommitLineData
a660d684
KB
1\section{\class{wxDocManager}}\label{wxdocmanager}
2
fc2171bd 3The wxDocManager class is part of the document/view framework supported by wxWidgets,
a660d684
KB
4and cooperates with the \helpref{wxView}{wxview}, \helpref{wxDocument}{wxdocument}\rtfsp
5and \helpref{wxDocTemplate}{wxdoctemplate} classes.
6
7\wxheading{Derived from}
8
9\helpref{wxEvtHandler}{wxevthandler}\\
10\helpref{wxObject}{wxobject}
11
954b8ae6
JS
12\wxheading{Include files}
13
14<wx/docview.h>
15
a660d684
KB
16\wxheading{See also}
17
18\helpref{wxDocManager overview}{wxdocmanageroverview}, \helpref{wxDocument}{wxdocument},\rtfsp
7f555861 19\helpref{wxView}{wxview}, \helpref{wxDocTemplate}{wxdoctemplate}, \helpref{wxFileHistory}{wxfilehistory}
a660d684
KB
20
21\latexignore{\rtfignore{\wxheading{Members}}}
22
b236c10f 23\membersection{wxDocManager::m\_currentView}\label{wxdocmanagermcreateview}
a660d684
KB
24
25\member{wxView*}{m\_currentView}
26
27The currently active view.
28
b236c10f 29\membersection{wxDocManager::m\_defaultDocumentNameCounter}\label{wxdocmanagermdefaultdocumentnamecounter}
a660d684
KB
30
31\member{int}{m\_defaultDocumentNameCounter}
32
33Stores the integer to be used for the next default document name.
34
b236c10f 35\membersection{wxDocManager::m\_fileHistory}\label{wxdocmanagermfilehistory}
a660d684
KB
36
37\member{wxFileHistory*}{m\_fileHistory}
38
39A pointer to an instance of \helpref{wxFileHistory}{wxfilehistory},
40which manages the history of recently-visited files on the File menu.
41
b236c10f 42\membersection{wxDocManager::m\_maxDocsOpen}\label{wxdocmanagermmaxdocsopen}
a660d684
KB
43
44\member{int}{m\_maxDocsOpen}
45
46Stores the maximum number of documents that can be opened before
47existing documents are closed. By default, this is 10,000.
48
b236c10f 49\membersection{wxDocManager::m\_docs}\label{wxdocmanagermdocs}
a660d684
KB
50
51\member{wxList}{m\_docs}
52
53A list of all documents.
54
b236c10f 55\membersection{wxDocManager::m\_flags}\label{wxdocmanagermflags}
a660d684
KB
56
57\member{long}{m\_flags}
58
59Stores the flags passed to the constructor.
60
b236c10f 61\membersection{wxDocManager::m\_lastDirectory}\label{wxdocmanagermlastdirectory}
ac0ac824
JS
62
63The directory last selected by the user when opening a file.
64
65\member{wxFileHistory*}{m\_fileHistory}
66
b236c10f 67\membersection{wxDocManager::m\_templates}\label{wxdocmanagermtemplates}
a660d684
KB
68
69\member{wxList}{mnTemplates}
70
71A list of all document templates.
72
b236c10f 73\membersection{wxDocManager::wxDocManager}\label{wxdocmanagerctor}
a660d684 74
cc81d32f 75\func{void}{wxDocManager}{\param{long}{ flags = wxDEFAULT\_DOCMAN\_FLAGS}, \param{bool}{ initialize = true}}
a660d684
KB
76
77Constructor. Create a document manager instance dynamically near the start of your application
78before doing any document or view operations.
79
80{\it flags} is currently unused.
81
cc81d32f 82If {\it initialize} is true, the \helpref{Initialize}{wxdocmanagerinitialize} function will be called
a660d684 83to create a default history list object. If you derive from wxDocManager, you may wish to call the
cc81d32f 84base constructor with false, and then call Initialize in your own constructor, to allow
a660d684
KB
85your own Initialize or OnCreateFileHistory functions to be called.
86
b236c10f 87\membersection{wxDocManager::\destruct{wxDocManager}}\label{wxdocmanagerdtor}
a660d684
KB
88
89\func{void}{\destruct{wxDocManager}}{\void}
90
91Destructor.
92
b236c10f 93\membersection{wxDocManager::ActivateView}\label{wxdocmanageractivateview}
a660d684 94
f6e9a818 95\func{void}{ActivateView}{\param{wxView* }{doc}, \param{bool}{ activate = true}}
a660d684
KB
96
97Sets the current view.
98
b236c10f 99\membersection{wxDocManager::AddDocument}\label{wxdocmanageradddocument}
a660d684
KB
100
101\func{void}{AddDocument}{\param{wxDocument *}{doc}}
102
103Adds the document to the list of documents.
104
b236c10f 105\membersection{wxDocManager::AddFileToHistory}\label{wxdocmanageraddfiletohistory}
a660d684
KB
106
107\func{void}{AddFileToHistory}{\param{const wxString\& }{filename}}
108
109Adds a file to the file history list, if we have a pointer to an appropriate file menu.
110
b236c10f 111\membersection{wxDocManager::AssociateTemplate}\label{wxdocmanagerassociatetemplate}
a660d684
KB
112
113\func{void}{AssociateTemplate}{\param{wxDocTemplate *}{temp}}
114
115Adds the template to the document manager's template list.
116
b236c10f 117\membersection{wxDocManager::CloseDocuments}\label{wxdocmanagerclosedocuments}
33a20136 118
cc81d32f 119\func{bool}{CloseDocuments}{\param{bool }{force = true}}
33a20136 120
2edb0bde 121Closes all currently opened documents.
33a20136 122
b236c10f 123\membersection{wxDocManager::CreateDocument}\label{wxdocmanagercreatedocument}
a660d684
KB
124
125\func{wxDocument*}{CreateDocument}{\param{const wxString\& }{path}, \param{long}{ flags}}
126
127Creates a new document in a manner determined by the {\it flags} parameter, which can be:
128
129\begin{itemize}\itemsep=0pt
130\item wxDOC\_NEW Creates a fresh document.
131\item wxDOC\_SILENT Silently loads the given document file.
132\end{itemize}
133
134If wxDOC\_NEW is present, a new document will be created and returned, possibly after
135asking the user for a template to use if there is more than one document template.
136If wxDOC\_SILENT is present, a new document will be created and the given file loaded
137into it. If neither of these flags is present, the user will be presented with
138a file selector for the file to load, and the template to use will be determined by the
139extension (Windows) or by popping up a template choice list (other platforms).
140
141If the maximum number of documents has been reached, this function
142will delete the oldest currently loaded document before creating a new one.
143
b236c10f 144\membersection{wxDocManager::CreateView}\label{wxdocmanagercreateview}
a660d684
KB
145
146\func{wxView*}{CreateView}{\param{wxDocument*}{doc}, \param{long}{ flags}}
147
148Creates a new view for the given document. If more than one view is allowed for the
149document (by virtue of multiple templates mentioning the same document type), a choice
150of view is presented to the user.
151
b236c10f 152\membersection{wxDocManager::DisassociateTemplate}\label{wxdocmanagerdisassociatetemplate}
a660d684
KB
153
154\func{void}{DisassociateTemplate}{\param{wxDocTemplate *}{temp}}
155
156Removes the template from the list of templates.
157
7f555861 158\membersection{wxDocManager::FileHistoryAddFilesToMenu}\label{wxdocmanagerfilehistoryaddfilestomenu}
a660d684 159
7f555861 160\func{void}{FileHistoryAddFilesToMenu}{\void}
a660d684 161
7f555861
JS
162Appends the files in the history list, to all menus managed by the file history object.
163
164\func{void}{FileHistoryAddFilesToMenu}{\param{wxMenu*}{ menu}}
165
166Appends the files in the history list, to the given menu only.
167
168\membersection{wxDocManager::FileHistoryLoad}\label{wxdocmanagerfilehistoryload}
169
170\func{void}{FileHistoryLoad}{\param{wxConfigBase\& }{config}}
171
172Loads the file history from a config object.
173
174\wxheading{See also}
a660d684 175
7f555861 176\helpref{wxConfig}{wxconfigbase}
a660d684 177
7f555861 178\membersection{wxDocManager::FileHistoryRemoveMenu}\label{wxdocmanagerfilehistoryremovemenu}
a660d684 179
7f555861
JS
180\func{void}{FileHistoryRemoveMenu}{\param{wxMenu*}{ menu}}
181
182Removes the given menu from the list of menus managed by the file history object.
183
184\membersection{wxDocManager::FileHistorySave}\label{wxdocmanagerfilehistorysave}
185
186\func{void}{FileHistorySave}{\param{wxConfigBase\& }{resourceFile}}
187
188Saves the file history into a config object. This must be called
a660d684
KB
189explicitly by the application.
190
7f555861
JS
191\wxheading{See also}
192
193\helpref{wxConfig}{wxconfigbase}
a660d684 194
7f555861
JS
195\membersection{wxDocManager::FileHistoryUseMenu}\label{wxdocmanagerfilehistoryusemenu}
196
197\func{void}{FileHistoryUseMenu}{\param{wxMenu*}{ menu}}
a660d684
KB
198
199Use this menu for appending recently-visited document filenames, for convenient
200access. Calling this function with a valid menu pointer enables the history
201list functionality.
202
7f555861
JS
203Note that you can add multiple menus using this function, to be managed by the
204file history object.
205
b236c10f 206\membersection{wxDocManager::FindTemplateForPath}\label{wxdocmanagerfindtemplateforpath}
a660d684
KB
207
208\func{wxDocTemplate *}{FindTemplateForPath}{\param{const wxString\& }{path}}
209
210Given a path, try to find template that matches the extension. This is only
211an approximate method of finding a template for creating a document.
212
b236c10f 213\membersection{wxDocManager::GetCurrentDocument}\label{wxdocmanagergetcurrentdocument}
a660d684
KB
214
215\func{wxDocument *}{GetCurrentDocument}{\void}
216
217Returns the document associated with the currently active view (if any).
218
b236c10f 219\membersection{wxDocManager::GetCurrentView}\label{wxdocmanagergetcurrentview}
a660d684
KB
220
221\func{wxView *}{GetCurrentView}{\void}
222
223Returns the currently active view
224
b236c10f 225\membersection{wxDocManager::GetDocuments}\label{wxdocmanagergetdocuments}
a660d684
KB
226
227\func{wxList\&}{GetDocuments}{\void}
228
229Returns a reference to the list of documents.
230
b236c10f 231\membersection{wxDocManager::GetFileHistory}\label{wxdocmanagergetfilehistory}
a660d684
KB
232
233\func{wxFileHistory *}{GetFileHistory}{\void}
234
235Returns a pointer to file history.
236
ac0ac824
JS
237\membersection{wxDocManager::GetLastDirectory}\label{wxdocmanagergetlastdirectory}
238
239\constfunc{wxString}{GetLastDirectory}{\void}
240
241Returns the directory last selected by the user when opening a file. Initially empty.
242
b236c10f 243\membersection{wxDocManager::GetMaxDocsOpen}\label{wxdocmanagergetmaxdocsopen}
a660d684
KB
244
245\func{int}{GetMaxDocsOpen}{\void}
246
247Returns the number of documents that can be open simultaneously.
248
b236c10f 249\membersection{wxDocManager::GetHistoryFilesCount}\label{wxdocmanagergethistoryfilescount}
a660d684 250
7af6b69e 251\func{size\_t}{GetHistoryFilesCount}{\void}
a660d684
KB
252
253Returns the number of files currently stored in the file history.
254
255\membersection{wxDocManager::Initialize}\label{wxdocmanagerinitialize}
256
257\func{bool}{Initialize}{\void}
258
259Initializes data; currently just calls OnCreateFileHistory. Some data cannot
260always be initialized in the constructor because the programmer must be given
261the opportunity to override functionality. If OnCreateFileHistory was called
262from the constructor, an overridden virtual OnCreateFileHistory would not be
263called due to C++'s `interesting' constructor semantics. In fact Initialize
264\rtfsp{\it is} called from the wxDocManager constructor, but this can be
cc81d32f 265vetoed by passing false to the second argument, allowing the derived class's
a660d684
KB
266constructor to call Initialize, possibly calling a different OnCreateFileHistory
267from the default.
268
269The bottom line: if you're not deriving from Initialize, forget it and
270construct wxDocManager with no arguments.
271
b236c10f 272\membersection{wxDocManager::MakeDefaultName}\label{wxdocmanagermakedefaultname}
a660d684
KB
273
274\func{bool}{MakeDefaultName}{\param{const wxString\& }{buf}}
275
276Copies a suitable default name into {\it buf}. This is implemented by
277appending an integer counter to the string {\bf unnamed} and incrementing
278the counter.
279
fa7161e0
MB
280\perlnote{In wxPerl this function must return the modified name rather
281than just modifying the argument.}
282
b236c10f 283\membersection{wxDocManager::OnCreateFileHistory}\label{wxdocmanageroncreatefilehistory}
a660d684
KB
284
285\func{wxFileHistory *}{OnCreateFileHistory}{\void}
286
287A hook to allow a derived class to create a different type of file history. Called
288from \helpref{Initialize}{wxdocmanagerinitialize}.
289
b236c10f 290\membersection{wxDocManager::OnFileClose}\label{wxdocmanageronfileclose}
a660d684 291
3980000c 292\func{void}{OnFileClose}{\param{wxCommandEvent\& }{event}}
a660d684
KB
293
294Closes and deletes the currently active document.
295
b236c10f 296\membersection{wxDocManager::OnFileCloseAll}\label{wxdocmanageronfilecloseall}
33a20136 297
3980000c 298\func{void}{OnFileCloseAll}{\param{wxCommandEvent\& }{event}}
33a20136
VZ
299
300Closes and deletes all the currently opened documents.
301
b236c10f 302\membersection{wxDocManager::OnFileNew}\label{wxdocmanageronfilenew}
a660d684 303
3980000c 304\func{void}{OnFileNew}{\param{wxCommandEvent\& }{event}}
a660d684
KB
305
306Creates a document from a list of templates (if more than one template).
307
b236c10f 308\membersection{wxDocManager::OnFileOpen}\label{wxdocmanageronfileopen}
a660d684 309
3980000c 310\func{void}{OnFileOpen}{\param{wxCommandEvent\& }{event}}
a660d684
KB
311
312Creates a new document and reads in the selected file.
313
3980000c
RR
314\membersection{wxDocManager::OnFileRevert}\label{wxdocmanageronfilerevert}
315
316\func{void}{OnFileRevert}{\param{wxCommandEvent\& }{event}}
317
318Reverts the current document by calling wxDocument::Revert for the current document.
319
b236c10f 320\membersection{wxDocManager::OnFileSave}\label{wxdocmanageronfilesave}
a660d684 321
3980000c 322\func{void}{OnFileSave}{\param{wxCommandEvent\& }{event}}
a660d684
KB
323
324Saves the current document by calling wxDocument::Save for the current document.
325
b236c10f 326\membersection{wxDocManager::OnFileSaveAs}\label{wxdocmanageronfilesaveas}
a660d684 327
3980000c 328\func{void}{OnFileSaveAs}{\param{wxCommandEvent\& }{event}}
a660d684
KB
329
330Calls wxDocument::SaveAs for the current document.
331
b236c10f 332\membersection{wxDocManager::RemoveDocument}\label{wxdocmanagerremovedocument}
a660d684
KB
333
334\func{void}{RemoveDocument}{\param{wxDocument *}{doc}}
335
336Removes the document from the list of documents.
337
b236c10f 338\membersection{wxDocManager::SelectDocumentPath}\label{wxdocmanagerselectdocumentpath}
a660d684
KB
339
340\func{wxDocTemplate *}{SelectDocumentPath}{\param{wxDocTemplate **}{templates},
f6e9a818 341 \param{int}{ noTemplates}, \param{wxString\& }{path},
a660d684
KB
342 \param{long}{ flags}, \param{bool}{ save}}
343
344Under Windows, pops up a file selector with a list of filters corresponding to document templates.
345The wxDocTemplate corresponding to the selected file's extension is returned.
346
347On other platforms, if there is more than one document template a choice list is popped up,
348followed by a file selector.
349
350This function is used in wxDocManager::CreateDocument.
351
762e1997
MB
352\perlnote{In wxPerl {\tt templates} is a reference to a list of templates.
353If you override this method in your document manager it must return
354two values, eg:\par
355 (doctemplate, path) = My::DocManager->SelectDocumentPath( ... );
356}
357
b236c10f 358\membersection{wxDocManager::SelectDocumentType}\label{wxdocmanagerselectdocumenttype}
a660d684
KB
359
360\func{wxDocTemplate *}{SelectDocumentType}{\param{wxDocTemplate **}{templates},
cc81d32f 361 \param{int}{ noTemplates}, \param{bool}{ sort=false}}
a660d684
KB
362
363Returns a document template by asking the user (if there is more than one template).
364This function is used in wxDocManager::CreateDocument.
365
52b9ca21
GT
366\wxheading{Parameters}
367
368\docparam{templates}{Pointer to an array of templates from which to choose a desired template.}
369\docparam{noTemplates}{Number of templates being pointed to by the {\it templates} pointer.}
370\docparam{sort}{If more than one template is passed in in {\it templates},
371then this parameter indicates whether the list of templates that the user
372will have to choose from is sorted or not when shown the choice box dialog.
cc81d32f 373Default is false.}
52b9ca21 374
762e1997
MB
375\perlnote{In wxPerl {\tt templates} is a reference to a list of templates.}
376
b236c10f 377\membersection{wxDocManager::SelectViewType}\label{wxdocmanagerselectviewtype}
a660d684
KB
378
379\func{wxDocTemplate *}{SelectViewType}{\param{wxDocTemplate **}{templates},
cc81d32f 380 \param{int}{ noTemplates}, \param{bool}{ sort=false}}
a660d684
KB
381
382Returns a document template by asking the user (if there is more than one template),
383displaying a list of valid views. This function is used in wxDocManager::CreateView.
52b9ca21 384The dialog normally will not appear because the array of templates only contains
a660d684
KB
385those relevant to the document in question, and often there will only be one such.
386
52b9ca21
GT
387\wxheading{Parameters}
388
389\docparam{templates}{Pointer to an array of templates from which to choose a desired template.}
390\docparam{noTemplates}{Number of templates being pointed to by the {\it templates} pointer.}
391\docparam{sort}{If more than one template is passed in in {\it templates},
392then this parameter indicates whether the list of templates that the user
393will have to choose from is sorted or not when shown the choice box dialog.
cc81d32f 394Default is false.}
52b9ca21 395
762e1997
MB
396\perlnote{In wxPerl {\tt templates} is a reference to a list of templates.}
397
ac0ac824
JS
398\membersection{wxDocManager::SetLastDirectory}\label{wxdocmanagersetlastdirectory}
399
400\func{void}{SetLastDirectory}{\param{const wxString\&}{ dir}}
401
402Sets the directory to be displayed to the user when opening a file. Initially this is empty.
403
b236c10f 404\membersection{wxDocManager::SetMaxDocsOpen}\label{wxdocmanagersetmaxdocsopen}
a660d684
KB
405
406\func{void}{SetMaxDocsOpen}{\param{int}{ n}}
407
408Sets the maximum number of documents that can be open at a time. By default, this
409is 10,000. If you set it to 1, existing documents will be saved and deleted
410when the user tries to open or create a new one (similar to the behaviour
411of Windows Write, for example). Allowing multiple documents gives behaviour
412more akin to MS Word and other Multiple Document Interface applications.
413
414
415