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