]> git.saurik.com Git - wxWidgets.git/blame - interface/docview.h
add wxShowEvent::IsShown() and wxIconizeEvent::IsIconized() instead of (now deprecate...
[wxWidgets.git] / interface / docview.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: docview.h
0c1fe6e9 3// Purpose: interface of various doc/view framework classes
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxDocTemplate
11 @wxheader{docview.h}
7c913512 12
23324ae1
FM
13 The wxDocTemplate class is used to model the relationship between a
14 document class and a view class.
7c913512 15
23324ae1 16 @library{wxcore}
0c1fe6e9 17 @category{docview}
7c913512 18
0c1fe6e9 19 @see @ref overview_docview_wxdoctemplate, wxDocument, wxView
23324ae1
FM
20*/
21class wxDocTemplate : public wxObject
22{
23public:
24 /**
0c1fe6e9
BP
25 Constructor. Create instances dynamically near the start of your
26 application after creating a wxDocManager instance, and before doing
27 any document or view operations.
28
29 @param manager
30 The document manager object which manages this template.
31 @param descr
32 A short description of what the template is for. This string will
33 be displayed in the file filter list of Windows file selectors.
34 @param filter
35 An appropriate file filter such as "*.txt".
36 @param dir
37 The default directory to use for file selectors.
38 @param ext
39 The default file extension (such as "txt").
40 @param docTypeName
41 A name that should be unique for a given type of document, used for
42 gathering a list of views relevant to a particular document.
43 @param viewTypeName
44 A name that should be unique for a given view.
45 @param docClassInfo
46 A pointer to the run-time document class information as returned by
47 the CLASSINFO() macro, e.g. CLASSINFO(MyDocumentClass). If this is
48 not supplied, you will need to derive a new wxDocTemplate class and
49 override the CreateDocument() member to return a new document
50 instance on demand.
51 @param viewClassInfo
52 A pointer to the run-time view class information as returned by the
53 CLASSINFO() macro, e.g. CLASSINFO(MyViewClass). If this is not
54 supplied, you will need to derive a new wxDocTemplate class and
55 override the CreateView() member to return a new view instance on
56 demand.
57 @param flags
58 A bit list of the following:
59 - wxTEMPLATE_VISIBLE - The template may be displayed to the
60 user in dialogs.
61 - wxTEMPLATE_INVISIBLE - The template may not be displayed to
62 the user in dialogs.
63 - wxDEFAULT_TEMPLATE_FLAGS - Defined as wxTEMPLATE_VISIBLE.
23324ae1
FM
64 */
65 wxDocTemplate(wxDocManager* manager, const wxString& descr,
0c1fe6e9
BP
66 const wxString& filter, const wxString& dir,
67 const wxString& ext, const wxString& docTypeName,
23324ae1 68 const wxString& viewTypeName,
4cc4bfaf
FM
69 wxClassInfo* docClassInfo = NULL,
70 wxClassInfo* viewClassInfo = NULL,
23324ae1
FM
71 long flags = wxDEFAULT_TEMPLATE_FLAGS);
72
73 /**
74 Destructor.
75 */
76 ~wxDocTemplate();
77
78 /**
0c1fe6e9
BP
79 Creates a new instance of the associated document class. If you have
80 not supplied a wxClassInfo parameter to the template constructor, you
81 will need to override this function to return an appropriate document
82 instance.
83
84 This function calls InitDocument() which in turns calls
85 wxDocument::OnCreate().
23324ae1 86 */
4cc4bfaf 87 wxDocument* CreateDocument(const wxString& path, long flags = 0);
23324ae1
FM
88
89 /**
0c1fe6e9
BP
90 Creates a new instance of the associated view class. If you have not
91 supplied a wxClassInfo parameter to the template constructor, you will
92 need to override this function to return an appropriate view instance.
23324ae1 93 */
4cc4bfaf 94 wxView* CreateView(wxDocument* doc, long flags = 0);
23324ae1
FM
95
96 /**
0c1fe6e9
BP
97 Returns the default file extension for the document data, as passed to
98 the document template constructor.
23324ae1
FM
99 */
100 wxString GetDefaultExtension();
101
102 /**
0c1fe6e9
BP
103 Returns the text description of this template, as passed to the
104 document template constructor.
23324ae1
FM
105 */
106 wxString GetDescription();
107
108 /**
0c1fe6e9
BP
109 Returns the default directory, as passed to the document template
110 constructor.
23324ae1
FM
111 */
112 wxString GetDirectory();
113
114 /**
0c1fe6e9
BP
115 Returns a pointer to the document manager instance for which this
116 template was created.
23324ae1 117 */
4cc4bfaf 118 wxDocManager* GetDocumentManager();
23324ae1
FM
119
120 /**
0c1fe6e9
BP
121 Returns the document type name, as passed to the document template
122 constructor.
23324ae1
FM
123 */
124 wxString GetDocumentName();
125
126 /**
0c1fe6e9
BP
127 Returns the file filter, as passed to the document template
128 constructor.
23324ae1
FM
129 */
130 wxString GetFileFilter();
131
132 /**
133 Returns the flags, as passed to the document template constructor.
134 */
135 long GetFlags();
136
137 /**
0c1fe6e9
BP
138 Returns the view type name, as passed to the document template
139 constructor.
23324ae1
FM
140 */
141 wxString GetViewName();
142
143 /**
0c1fe6e9
BP
144 Initialises the document, calling wxDocument::OnCreate(). This is
145 called from CreateDocument().
23324ae1 146 */
0c1fe6e9 147 bool InitDocument(wxDocument* doc, const wxString& path, long flags = 0);
23324ae1
FM
148
149 /**
0c1fe6e9
BP
150 Returns @true if the document template can be shown in user dialogs,
151 @false otherwise.
23324ae1
FM
152 */
153 bool IsVisible();
154
155 /**
156 Sets the default file extension.
157 */
158 void SetDefaultExtension(const wxString& ext);
159
160 /**
161 Sets the template description.
162 */
163 void SetDescription(const wxString& descr);
164
165 /**
166 Sets the default directory.
167 */
168 void SetDirectory(const wxString& dir);
169
170 /**
0c1fe6e9
BP
171 Sets the pointer to the document manager instance for which this
172 template was created. Should not be called by the application.
23324ae1 173 */
4cc4bfaf 174 void SetDocumentManager(wxDocManager* manager);
23324ae1
FM
175
176 /**
177 Sets the file filter.
178 */
179 void SetFileFilter(const wxString& filter);
180
181 /**
0c1fe6e9
BP
182 Sets the internal document template flags (see the constructor
183 description for more details).
23324ae1
FM
184 */
185 void SetFlags(long flags);
186
187 /**
23324ae1
FM
188 The default extension for files of this type.
189 */
0c1fe6e9 190 wxString m_defaultExt;
23324ae1
FM
191
192 /**
23324ae1
FM
193 A short description of this template.
194 */
0c1fe6e9 195 wxString m_description;
23324ae1
FM
196
197 /**
23324ae1
FM
198 The default directory for files of this type.
199 */
0c1fe6e9 200 wxString m_directory;
23324ae1
FM
201
202 /**
0c1fe6e9
BP
203 Run-time class information that allows document instances to be
204 constructed dynamically.
23324ae1 205 */
0c1fe6e9 206 wxClassInfo* m_docClassInfo;
23324ae1
FM
207
208 /**
23324ae1
FM
209 The named type of the document associated with this template.
210 */
0c1fe6e9 211 wxString m_docTypeName;
23324ae1
FM
212
213 /**
23324ae1
FM
214 A pointer to the document manager for which this template was created.
215 */
0c1fe6e9 216 wxDocTemplate* m_documentManager;
23324ae1
FM
217
218 /**
0c1fe6e9 219 The file filter (such as "*.txt") to be used in file selector dialogs.
23324ae1 220 */
0c1fe6e9 221 wxString m_fileFilter;
23324ae1
FM
222
223 /**
23324ae1
FM
224 The flags passed to the constructor.
225 */
0c1fe6e9 226 long m_flags;
23324ae1
FM
227
228 /**
23324ae1
FM
229 Run-time class information that allows view instances to be constructed
230 dynamically.
231 */
0c1fe6e9 232 wxClassInfo* m_viewClassInfo;
23324ae1
FM
233
234 /**
23324ae1
FM
235 The named type of the view associated with this template.
236 */
0c1fe6e9 237 wxString m_viewTypeName;
23324ae1
FM
238};
239
240
e54c96f1 241
23324ae1
FM
242/**
243 @class wxDocManager
244 @wxheader{docview.h}
7c913512 245
23324ae1 246 The wxDocManager class is part of the document/view framework supported by
0c1fe6e9
BP
247 wxWidgets, and cooperates with the wxView, wxDocument and wxDocTemplate
248 classes.
7c913512 249
23324ae1 250 @library{wxcore}
0c1fe6e9 251 @category{docview}
7c913512 252
0c1fe6e9
BP
253 @see @ref overview_docview_wxdocmanager, wxDocument, wxView, wxDocTemplate,
254 wxFileHistory
23324ae1
FM
255*/
256class wxDocManager : public wxEvtHandler
257{
258public:
259 /**
0c1fe6e9
BP
260 Constructor. Create a document manager instance dynamically near the
261 start of your application before doing any document or view operations.
262
4cc4bfaf 263 @a flags is currently unused.
0c1fe6e9
BP
264
265 If @a initialize is @true, the Initialize() function will be called to
266 create a default history list object. If you derive from wxDocManager,
267 you may wish to call the base constructor with @false, and then call
268 Initialize() in your own constructor, to allow your own Initialize() or
269 OnCreateFileHistory functions to be called.
23324ae1
FM
270 */
271 wxDocManager(long flags = wxDEFAULT_DOCMAN_FLAGS,
4cc4bfaf 272 bool initialize = true);
23324ae1
FM
273
274 /**
275 Destructor.
276 */
277 ~wxDocManager();
278
279 /**
280 Sets the current view.
281 */
4cc4bfaf 282 void ActivateView(wxView* doc, bool activate = true);
23324ae1
FM
283
284 /**
285 Adds the document to the list of documents.
286 */
4cc4bfaf 287 void AddDocument(wxDocument* doc);
23324ae1
FM
288
289 /**
0c1fe6e9
BP
290 Adds a file to the file history list, if we have a pointer to an
291 appropriate file menu.
23324ae1
FM
292 */
293 void AddFileToHistory(const wxString& filename);
294
295 /**
296 Adds the template to the document manager's template list.
297 */
4cc4bfaf 298 void AssociateTemplate(wxDocTemplate* temp);
23324ae1
FM
299
300 /**
301 Closes all currently opened documents.
302 */
4cc4bfaf 303 bool CloseDocuments(bool force = true);
23324ae1
FM
304
305 /**
0c1fe6e9
BP
306 Creates a new document in a manner determined by the @a flags
307 parameter, which can be:
308
309 - wxDOC_NEW - Creates a fresh document.
310 - wxDOC_SILENT - Silently loads the given document file.
311
312 If wxDOC_NEW is present, a new document will be created and returned,
313 possibly after asking the user for a template to use if there is more
314 than one document template. If wxDOC_SILENT is present, a new document
315 will be created and the given file loaded into it. If neither of these
316 flags is present, the user will be presented with a file selector for
317 the file to load, and the template to use will be determined by the
318 extension (Windows) or by popping up a template choice list (other
319 platforms).
320
321 If the maximum number of documents has been reached, this function will
322 delete the oldest currently loaded document before creating a new one.
23324ae1
FM
323 */
324 wxDocument* CreateDocument(const wxString& path, long flags);
325
326 /**
0c1fe6e9
BP
327 Creates a new view for the given document. If more than one view is
328 allowed for the document (by virtue of multiple templates mentioning
329 the same document type), a choice of view is presented to the user.
23324ae1
FM
330 */
331 wxView* CreateView(wxDocument* doc, long flags);
332
333 /**
334 Removes the template from the list of templates.
335 */
4cc4bfaf 336 void DisassociateTemplate(wxDocTemplate* temp);
23324ae1 337
23324ae1 338 /**
0c1fe6e9
BP
339 Appends the files in the history list to all menus managed by the file
340 history object.
23324ae1
FM
341 */
342 void FileHistoryAddFilesToMenu();
0c1fe6e9
BP
343 /**
344 Appends the files in the history list to the given @a menu only.
345 */
7c913512 346 void FileHistoryAddFilesToMenu(wxMenu* menu);
23324ae1
FM
347
348 /**
349 Loads the file history from a config object.
3c4f71cc 350
0c1fe6e9 351 @see wxConfigBase
23324ae1 352 */
6656b711 353 void FileHistoryLoad(const wxConfigBase& config);
23324ae1
FM
354
355 /**
0c1fe6e9
BP
356 Removes the given menu from the list of menus managed by the file
357 history object.
23324ae1
FM
358 */
359 void FileHistoryRemoveMenu(wxMenu* menu);
360
361 /**
362 Saves the file history into a config object. This must be called
363 explicitly by the application.
3c4f71cc 364
0c1fe6e9 365 @see wxConfigBase
23324ae1
FM
366 */
367 void FileHistorySave(wxConfigBase& resourceFile);
368
369 /**
0c1fe6e9
BP
370 Use this menu for appending recently-visited document filenames, for
371 convenient access. Calling this function with a valid menu pointer
372 enables the history list functionality.
373
374 @note You can add multiple menus using this function, to be managed by
375 the file history object.
23324ae1
FM
376 */
377 void FileHistoryUseMenu(wxMenu* menu);
378
379 /**
0c1fe6e9
BP
380 Given a path, try to find template that matches the extension. This is
381 only an approximate method of finding a template for creating a
382 document.
23324ae1 383 */
4cc4bfaf 384 wxDocTemplate* FindTemplateForPath(const wxString& path);
23324ae1
FM
385
386 /**
0c1fe6e9
BP
387 Returns the document associated with the currently active view (if
388 any).
23324ae1 389 */
4cc4bfaf 390 wxDocument* GetCurrentDocument();
23324ae1
FM
391
392 /**
393 Returns the currently active view
394 */
4cc4bfaf 395 wxView* GetCurrentView();
23324ae1
FM
396
397 /**
398 Returns a reference to the list of documents.
399 */
400 wxList GetDocuments();
401
402 /**
403 Returns a pointer to file history.
404 */
4cc4bfaf 405 wxFileHistory* GetFileHistory();
23324ae1
FM
406
407 /**
408 Returns the number of files currently stored in the file history.
409 */
410 size_t GetHistoryFilesCount();
411
412 /**
0c1fe6e9
BP
413 Returns the directory last selected by the user when opening a file.
414 Initially empty.
23324ae1 415 */
328f5751 416 wxString GetLastDirectory() const;
23324ae1
FM
417
418 /**
419 Returns the number of documents that can be open simultaneously.
420 */
421 int GetMaxDocsOpen();
422
423 /**
424 Returns a reference to the list of associated templates.
425 */
426 wxList GetTemplates();
427
428 /**
0c1fe6e9
BP
429 Initializes data; currently just calls OnCreateFileHistory().
430
431 Some data cannot always be initialized in the constructor because the
432 programmer must be given the opportunity to override functionality. If
433 OnCreateFileHistory() was called from the constructor, an overridden
434 virtual OnCreateFileHistory() would not be called due to C++'s
435 'interesting' constructor semantics. In fact Initialize() @e is called
436 from the wxDocManager constructor, but this can be vetoed by passing
437 @false to the second argument, allowing the derived class's constructor
438 to call Initialize(), possibly calling a different
439 OnCreateFileHistory() from the default.
440
441 The bottom line: if you're not deriving from Initialize(), forget it
442 and construct wxDocManager with no arguments.
23324ae1
FM
443 */
444 bool Initialize();
445
446 /**
0c1fe6e9
BP
447 Return a string containing a suitable default name for a new document.
448 By default this is implemented by appending an integer counter to the
449 string @b unnamed but can be overridden in the derived classes to do
450 something more appropriate.
23324ae1
FM
451 */
452 wxString MakeNewDocumentName();
453
454 /**
0c1fe6e9
BP
455 A hook to allow a derived class to create a different type of file
456 history. Called from Initialize().
23324ae1 457 */
4cc4bfaf 458 wxFileHistory* OnCreateFileHistory();
23324ae1
FM
459
460 /**
461 Closes and deletes the currently active document.
462 */
463 void OnFileClose(wxCommandEvent& event);
464
465 /**
466 Closes and deletes all the currently opened documents.
467 */
468 void OnFileCloseAll(wxCommandEvent& event);
469
470 /**
0c1fe6e9
BP
471 Creates a document from a list of templates (if more than one
472 template).
23324ae1
FM
473 */
474 void OnFileNew(wxCommandEvent& event);
475
476 /**
477 Creates a new document and reads in the selected file.
478 */
479 void OnFileOpen(wxCommandEvent& event);
480
481 /**
0c1fe6e9
BP
482 Reverts the current document by calling wxDocument::Revert() for the
483 current document.
23324ae1
FM
484 */
485 void OnFileRevert(wxCommandEvent& event);
486
487 /**
0c1fe6e9
BP
488 Saves the current document by calling wxDocument::Save() for the
489 current document.
23324ae1
FM
490 */
491 void OnFileSave(wxCommandEvent& event);
492
493 /**
0c1fe6e9 494 Calls wxDocument::SaveAs() for the current document.
23324ae1
FM
495 */
496 void OnFileSaveAs(wxCommandEvent& event);
497
498 /**
499 Removes the document from the list of documents.
500 */
4cc4bfaf 501 void RemoveDocument(wxDocument* doc);
23324ae1
FM
502
503 /**
0c1fe6e9
BP
504 Under Windows, pops up a file selector with a list of filters
505 corresponding to document templates. The wxDocTemplate corresponding to
506 the selected file's extension is returned.
507
508 On other platforms, if there is more than one document template a
509 choice list is popped up, followed by a file selector.
510
23324ae1 511 This function is used in CreateDocument().
23324ae1 512 */
4cc4bfaf 513 wxDocTemplate* SelectDocumentPath(wxDocTemplate** templates,
0c1fe6e9
BP
514 int noTemplates, wxString& path,
515 long flags, bool save);
23324ae1
FM
516
517 /**
0c1fe6e9
BP
518 Returns a document template by asking the user (if there is more than
519 one template). This function is used in CreateDocument().
3c4f71cc 520
7c913512 521 @param templates
0c1fe6e9
BP
522 Pointer to an array of templates from which to choose a desired
523 template.
7c913512 524 @param noTemplates
4cc4bfaf 525 Number of templates being pointed to by the templates pointer.
7c913512 526 @param sort
0c1fe6e9
BP
527 If more than one template is passed in in templates, then this
528 parameter indicates whether the list of templates that the user
529 will have to choose from is sorted or not when shown the choice box
530 dialog. Default is @false.
23324ae1 531 */
4cc4bfaf 532 wxDocTemplate* SelectDocumentType(wxDocTemplate** templates,
0c1fe6e9 533 int noTemplates, bool sort = false);
23324ae1
FM
534
535 /**
0c1fe6e9
BP
536 Returns a document template by asking the user (if there is more than
537 one template), displaying a list of valid views. This function is used
538 in CreateView(). The dialog normally will not appear because the array
539 of templates only contains those relevant to the document in question,
540 and often there will only be one such.
3c4f71cc 541
7c913512 542 @param templates
0c1fe6e9
BP
543 Pointer to an array of templates from which to choose a desired
544 template.
7c913512 545 @param noTemplates
4cc4bfaf 546 Number of templates being pointed to by the templates pointer.
7c913512 547 @param sort
0c1fe6e9
BP
548 If more than one template is passed in in templates, then this
549 parameter indicates whether the list of templates that the user
550 will have to choose from is sorted or not when shown the choice box
551 dialog. Default is @false.
23324ae1 552 */
4cc4bfaf 553 wxDocTemplate* SelectViewType(wxDocTemplate** templates,
0c1fe6e9 554 int noTemplates, bool sort = false);
23324ae1
FM
555
556 /**
0c1fe6e9
BP
557 Sets the directory to be displayed to the user when opening a file.
558 Initially this is empty.
23324ae1
FM
559 */
560 void SetLastDirectory(const wxString& dir);
561
562 /**
0c1fe6e9
BP
563 Sets the maximum number of documents that can be open at a time. By
564 default, this is 10,000. If you set it to 1, existing documents will be
565 saved and deleted when the user tries to open or create a new one
566 (similar to the behaviour of Windows Write, for example). Allowing
567 multiple documents gives behaviour more akin to MS Word and other
568 Multiple Document Interface applications.
23324ae1
FM
569 */
570 void SetMaxDocsOpen(int n);
571
572 /**
23324ae1
FM
573 The currently active view.
574 */
0c1fe6e9 575 wxView* m_currentView;
23324ae1
FM
576
577 /**
23324ae1
FM
578 Stores the integer to be used for the next default document name.
579 */
0c1fe6e9 580 int m_defaultDocumentNameCounter;
23324ae1
FM
581
582 /**
23324ae1
FM
583 A list of all documents.
584 */
0c1fe6e9 585 wxList m_docs;
23324ae1
FM
586
587 /**
0c1fe6e9
BP
588 A pointer to an instance of wxFileHistory, which manages the history of
589 recently-visited files on the File menu.
23324ae1 590 */
0c1fe6e9 591 wxFileHistory* m_fileHistory;
23324ae1
FM
592
593 /**
23324ae1
FM
594 Stores the flags passed to the constructor.
595 */
0c1fe6e9 596 long m_flags;
23324ae1
FM
597
598 /**
599 The directory last selected by the user when opening a file.
23324ae1 600 */
0c1fe6e9 601 wxFileHistory* m_fileHistory;
23324ae1
FM
602
603 /**
23324ae1
FM
604 Stores the maximum number of documents that can be opened before
605 existing documents are closed. By default, this is 10,000.
606 */
0c1fe6e9 607 int m_maxDocsOpen;
23324ae1
FM
608};
609
610
e54c96f1 611
23324ae1
FM
612/**
613 @class wxView
614 @wxheader{docview.h}
7c913512 615
23324ae1
FM
616 The view class can be used to model the viewing and editing component of
617 an application's file-based data. It is part of the document/view framework
0c1fe6e9 618 supported by wxWidgets, and cooperates with the wxDocument, wxDocTemplate
23324ae1 619 and wxDocManager classes.
7c913512 620
23324ae1 621 @library{wxcore}
0c1fe6e9 622 @category{docview}
7c913512 623
0c1fe6e9 624 @see @ref overview_docview_wxview, wxDocument, wxDocTemplate, wxDocManager
23324ae1
FM
625*/
626class wxView : public wxEvtHandler
627{
628public:
629 /**
630 Constructor. Define your own default constructor to initialize
0c1fe6e9 631 application-specific data.
23324ae1
FM
632 */
633 wxView();
634
635 /**
636 Destructor. Removes itself from the document's list of views.
637 */
638 ~wxView();
639
640 /**
0c1fe6e9
BP
641 Call this from your view frame's wxDocChildFrame::OnActivate() member
642 to tell the framework which view is currently active. If your windowing
643 system doesn't call wxDocChildFrame::OnActivate(), you may need to call
644 this function from any place where you know the view must be active,
645 and the framework will need to get the current view.
646
647 The prepackaged view frame wxDocChildFrame calls Activate() from its
648 wxDocChildFrame::OnActivate() member.
649
23324ae1
FM
650 This function calls OnActivateView().
651 */
652 virtual void Activate(bool activate);
653
654 /**
0c1fe6e9
BP
655 Closes the view by calling OnClose(). If @a deleteWindow is @true, this
656 function should delete the window associated with the view.
23324ae1 657 */
4cc4bfaf 658 virtual bool Close(bool deleteWindow = true);
23324ae1
FM
659
660 /**
661 Gets a pointer to the document associated with the view.
662 */
328f5751 663 wxDocument* GetDocument() const;
23324ae1
FM
664
665 /**
0c1fe6e9
BP
666 Returns a pointer to the document manager instance associated with this
667 view.
23324ae1 668 */
328f5751 669 wxDocManager* GetDocumentManager() const;
23324ae1
FM
670
671 /**
0c1fe6e9
BP
672 Gets the frame associated with the view (if any). Note that this
673 "frame" is not a wxFrame at all in the generic MDI implementation which
674 uses notebook pages instead of frames and this is why this method
675 returns a wxWindow and not a wxFrame.
23324ae1 676 */
4cc4bfaf 677 wxWindow* GetFrame();
23324ae1
FM
678
679 /**
680 Gets the name associated with the view (passed to the wxDocTemplate
0c1fe6e9 681 constructor). Not currently used by the framework.
23324ae1 682 */
328f5751 683 wxString GetViewName() const;
23324ae1
FM
684
685 /**
686 Called when a view is activated by means of Activate(). The default
0c1fe6e9 687 implementation does nothing.
23324ae1 688 */
4cc4bfaf
FM
689 virtual void OnActivateView(bool activate, wxView* activeView,
690 wxView* deactiveView);
23324ae1
FM
691
692 /**
0c1fe6e9
BP
693 Called when the filename has changed. The default implementation
694 constructs a suitable title and sets the title of the view frame (if
695 any).
23324ae1
FM
696 */
697 virtual void OnChangeFilename();
698
699 /**
0c1fe6e9
BP
700 Implements closing behaviour. The default implementation calls
701 wxDocument::Close() to close the associated document. Does not delete
702 the view. The application may wish to do some cleaning up operations in
703 this function, @e if a call to wxDocument::Close() succeeded. For
704 example, if your views all share the same window, you need to
705 disassociate the window from the view and perhaps clear the window. If
706 @a deleteWindow is @true, delete the frame associated with the view.
23324ae1
FM
707 */
708 virtual bool OnClose(bool deleteWindow);
709
710 /**
0c1fe6e9 711 Override this to clean up the view when the document is being closed.
23324ae1
FM
712 */
713 virtual void OnClosingDocument();
714
715 /**
0c1fe6e9
BP
716 wxDocManager or wxDocument creates a wxView via a wxDocTemplate. Just
717 after the wxDocTemplate creates the wxView, it calls OnCreate(). The
718 wxView can create a wxDocChildFrame (or derived class) in its
719 wxView::OnCreate() member function. This wxDocChildFrame provides user
720 interface elements to view and/or edit the contents of the wxDocument.
721
23324ae1
FM
722 By default, simply returns @true. If the function returns @false, the
723 view will be deleted.
724 */
725 virtual bool OnCreate(wxDocument* doc, long flags);
726
727 /**
0c1fe6e9
BP
728 If the printing framework is enabled in the library, this function
729 returns a wxPrintout object for the purposes of printing. It should
730 create a new object every time it is called; the framework will delete
731 objects it creates.
732
733 By default, this function returns an instance of wxDocPrintout, which
734 prints and previews one page by calling OnDraw().
735
23324ae1
FM
736 Override to return an instance of a class other than wxDocPrintout.
737 */
738 virtual wxPrintout* OnCreatePrintout();
739
740 /**
741 Override this function to render the view on the given device context.
742 */
743 virtual void OnDraw(wxDC* dc);
744
745 /**
0c1fe6e9
BP
746 Called when the view should be updated.
747
748 @param sender
749 A pointer to the wxView that sent the update request, or @NULL if
750 no single view requested the update (for instance, when the
751 document is opened).
752 @param hint
753 This is unused currently, but may in future contain
754 application-specific information for making updating more
755 efficient.
23324ae1
FM
756 */
757 virtual void OnUpdate(wxView* sender, wxObject* hint);
758
759 /**
760 Associates the given document with the view. Normally called by the
761 framework.
762 */
763 void SetDocument(wxDocument* doc);
764
765 /**
0c1fe6e9
BP
766 Sets the frame associated with this view. The application should call
767 this if possible, to tell the view about the frame.
768
769 See GetFrame() for the explanation about the mismatch between the
770 "Frame" in the method name and the type of its parameter.
23324ae1
FM
771 */
772 void SetFrame(wxWindow* frame);
773
774 /**
775 Sets the view type name. Should only be called by the framework.
776 */
777 void SetViewName(const wxString& name);
778
779 /**
0c1fe6e9
BP
780 The document associated with this view. There may be more than one view
781 per document, but there can never be more than one document for one
782 view.
23324ae1 783 */
0c1fe6e9 784 wxDocument* m_viewDocument;
23324ae1
FM
785
786 /**
23324ae1
FM
787 Frame associated with the view, if any.
788 */
0c1fe6e9 789 wxFrame* m_viewFrame;
23324ae1
FM
790
791 /**
0c1fe6e9
BP
792 The view type name given to the wxDocTemplate constructor, copied to
793 this variable when the view is created. Not currently used by the
794 framework.
23324ae1 795 */
0c1fe6e9 796 wxString m_viewTypeName;
23324ae1
FM
797};
798
799
e54c96f1 800
23324ae1
FM
801/**
802 @class wxDocChildFrame
803 @wxheader{docview.h}
7c913512 804
23324ae1 805 The wxDocChildFrame class provides a default frame for displaying documents
0c1fe6e9
BP
806 on separate windows. This class can only be used for SDI (not MDI) child
807 frames.
7c913512 808
23324ae1 809 The class is part of the document/view framework supported by wxWidgets,
0c1fe6e9
BP
810 and cooperates with the wxView, wxDocument, wxDocManager and wxDocTemplate
811 classes.
7c913512 812
23324ae1 813 @library{wxcore}
0c1fe6e9 814 @category{docview}
7c913512 815
0c1fe6e9 816 @see @ref overview_docview, @ref page_samples_docview, wxFrame
23324ae1
FM
817*/
818class wxDocChildFrame : public wxFrame
819{
820public:
821 /**
822 Constructor.
823 */
824 wxDocChildFrame(wxDocument* doc, wxView* view, wxFrame* parent,
0c1fe6e9 825 wxWindowID id, const wxString& title,
23324ae1
FM
826 const wxPoint& pos = wxDefaultPosition,
827 const wxSize& size = wxDefaultSize,
828 long style = wxDEFAULT_FRAME_STYLE,
829 const wxString& name = "frame");
830
831 /**
832 Destructor.
833 */
834 ~wxDocChildFrame();
835
836 /**
837 Returns the document associated with this frame.
838 */
328f5751 839 wxDocument* GetDocument() const;
23324ae1
FM
840
841 /**
842 Returns the view associated with this frame.
843 */
328f5751 844 wxView* GetView() const;
23324ae1
FM
845
846 /**
0c1fe6e9
BP
847 Sets the currently active view to be the frame's view. You may need to
848 override (but still call) this function in order to set the keyboard
23324ae1
FM
849 focus for your subwindow.
850 */
851 void OnActivate(wxActivateEvent event);
852
853 /**
854 Closes and deletes the current view and document.
855 */
856 void OnCloseWindow(wxCloseEvent& event);
857
858 /**
859 Sets the document for this frame.
860 */
4cc4bfaf 861 void SetDocument(wxDocument* doc);
23324ae1
FM
862
863 /**
864 Sets the view for this frame.
865 */
4cc4bfaf 866 void SetView(wxView* view);
23324ae1
FM
867
868 /**
23324ae1
FM
869 The document associated with the frame.
870 */
0c1fe6e9 871 wxDocument* m_childDocument;
23324ae1
FM
872
873 /**
23324ae1
FM
874 The view associated with the frame.
875 */
0c1fe6e9 876 wxView* m_childView;
23324ae1
FM
877};
878
879
e54c96f1 880
23324ae1
FM
881/**
882 @class wxDocParentFrame
883 @wxheader{docview.h}
7c913512 884
23324ae1 885 The wxDocParentFrame class provides a default top-level frame for
0c1fe6e9
BP
886 applications using the document/view framework. This class can only be used
887 for SDI (not MDI) parent frames.
7c913512 888
0c1fe6e9
BP
889 It cooperates with the wxView, wxDocument, wxDocManager and wxDocTemplate
890 classes.
7c913512 891
23324ae1 892 @library{wxcore}
0c1fe6e9 893 @category{docview}
7c913512 894
0c1fe6e9 895 @see @ref overview_docview, @ref page_samples_docview, wxFrame
23324ae1
FM
896*/
897class wxDocParentFrame : public wxFrame
898{
899public:
23324ae1 900 /**
0c1fe6e9 901 Default constructor.
23324ae1
FM
902 */
903 wxDocParentFrame();
0c1fe6e9
BP
904 /**
905 Constructor.
906 */
4cc4bfaf 907 wxDocParentFrame(wxDocManager* manager, wxFrame* parent,
0c1fe6e9 908 wxWindowID id, const wxString& title,
7c913512
FM
909 const wxPoint& pos = wxDefaultPosition,
910 const wxSize& size = wxDefaultSize,
911 long style = wxDEFAULT_FRAME_STYLE,
912 const wxString& name = "frame");
23324ae1
FM
913
914 /**
915 Destructor.
916 */
917 ~wxDocParentFrame();
918
919 /**
920 Used in two-step construction.
921 */
4cc4bfaf 922 bool Create(wxDocManager* manager, wxFrame* parent,
23324ae1
FM
923 wxWindowID id, const wxString& title,
924 const wxPoint& pos = wxDefaultPosition,
925 const wxSize& size = wxDefaultSize,
926 long style = wxDEFAULT_FRAME_STYLE,
927 const wxString& name = "frame");
928
929 /**
0c1fe6e9 930 Returns the associated document manager object.
23324ae1 931 */
328f5751 932 wxDocManager* GetDocumentManager() const;
23324ae1
FM
933
934 /**
935 Deletes all views and documents. If no user input cancelled the
936 operation, the frame will be destroyed and the application will exit.
0c1fe6e9
BP
937 Since understanding how document/view clean-up takes place can be
938 difficult, the implementation of this function is shown below:
939
940 @code
941 void wxDocParentFrame::OnCloseWindow(wxCloseEvent& event)
942 {
943 if (m_docManager->Clear(!event.CanVeto()))
944 {
945 this->Destroy();
946 }
947 else
948 event.Veto();
949 }
950 @endcode
23324ae1
FM
951 */
952 void OnCloseWindow(wxCloseEvent& event);
953};
954
955
e54c96f1 956
23324ae1
FM
957/**
958 @class wxDocument
959 @wxheader{docview.h}
7c913512 960
0c1fe6e9
BP
961 The document class can be used to model an application's file-based data.
962 It is part of the document/view framework supported by wxWidgets, and
963 cooperates with the wxView, wxDocTemplate and wxDocManager classes.
7c913512 964
23324ae1 965 @library{wxcore}
0c1fe6e9 966 @category{docview}
7c913512 967
0c1fe6e9 968 @see @ref overview_docview, wxView, wxDocTemplate, wxDocManager
23324ae1
FM
969*/
970class wxDocument : public wxEvtHandler
971{
972public:
973 /**
974 Constructor. Define your own default constructor to initialize
0c1fe6e9 975 application-specific data.
23324ae1
FM
976 */
977 wxDocument();
978
979 /**
980 Destructor. Removes itself from the document manager.
981 */
982 ~wxDocument();
983
984 /**
0c1fe6e9
BP
985 If the view is not already in the list of views, adds the view and
986 calls OnChangedViewList().
23324ae1 987 */
4cc4bfaf 988 virtual bool AddView(wxView* view);
23324ae1
FM
989
990 /**
0c1fe6e9
BP
991 Closes the document, by calling OnSaveModified() and then (if this
992 returned @true) OnCloseDocument(). This does not normally delete the
993 document object, use DeleteAllViews() to do this implicitly.
23324ae1
FM
994 */
995 virtual bool Close();
996
997 /**
0c1fe6e9
BP
998 Calls wxView::Close() and deletes each view. Deleting the final view
999 will implicitly delete the document itself, because the wxView
1000 destructor calls RemoveView(). This in turns calls OnChangedViewList(),
1001 whose default implemention is to save and delete the document if no
1002 views exist.
23324ae1
FM
1003 */
1004 virtual bool DeleteAllViews();
1005
1006 /**
0c1fe6e9
BP
1007 Returns a pointer to the command processor associated with this
1008 document.
1009
1010 @see wxCommandProcessor
23324ae1 1011 */
328f5751 1012 wxCommandProcessor* GetCommandProcessor() const;
23324ae1
FM
1013
1014 /**
1015 Gets a pointer to the associated document manager.
1016 */
328f5751 1017 wxDocManager* GetDocumentManager() const;
23324ae1
FM
1018
1019 /**
1020 Gets the document type name for this document. See the comment for
0c1fe6e9 1021 @ref m_documentTypeName.
23324ae1 1022 */
328f5751 1023 wxString GetDocumentName() const;
23324ae1
FM
1024
1025 /**
1026 Gets a pointer to the template that created the document.
1027 */
328f5751 1028 wxDocTemplate* GetDocumentTemplate() const;
23324ae1
FM
1029
1030 /**
0c1fe6e9
BP
1031 Intended to return a suitable window for using as a parent for
1032 document-related dialog boxes. By default, uses the frame associated
1033 with the first view.
23324ae1 1034 */
328f5751 1035 wxWindow* GetDocumentWindow() const;
23324ae1
FM
1036
1037 /**
1038 Gets the filename associated with this document, or "" if none is
1039 associated.
1040 */
328f5751 1041 wxString GetFilename() const;
23324ae1
FM
1042
1043 /**
0c1fe6e9
BP
1044 A convenience function to get the first view for a document, because in
1045 many cases a document will only have a single view.
1046
1047 @see GetViews()
23324ae1 1048 */
328f5751 1049 wxView* GetFirstView() const;
23324ae1
FM
1050
1051 /**
0c1fe6e9
BP
1052 Gets the title for this document. The document title is used for an
1053 associated frame (if any), and is usually constructed by the framework
1054 from the filename.
23324ae1 1055 */
328f5751 1056 wxString GetTitle() const;
23324ae1
FM
1057
1058 /**
1059 Return the document name suitable to be shown to the user. The default
1060 implementation uses the document title, if any, of the name part of the
1061 document filename if it was set or, otherwise, the string @b unnamed.
1062 */
328f5751 1063 virtual wxString GetUserReadableName() const;
23324ae1
FM
1064
1065 /**
1066 Returns the list whose elements are the views on the document.
0c1fe6e9
BP
1067
1068 @see GetFirstView()
23324ae1 1069 */
328f5751 1070 wxList GetViews() const;
23324ae1
FM
1071
1072 /**
0c1fe6e9
BP
1073 Returns @true if the document has been modified since the last save,
1074 @false otherwise. You may need to override this if your document view
1075 maintains its own record of being modified.
1076
1077 @see Modify()
23324ae1 1078 */
328f5751 1079 virtual bool IsModified() const;
23324ae1
FM
1080
1081 //@{
1082 /**
0c1fe6e9
BP
1083 Override this function and call it from your own LoadObject() before
1084 streaming your own data. LoadObject() is called by the framework
23324ae1 1085 automatically when the document contents need to be loaded.
0c1fe6e9
BP
1086
1087 @note This version of LoadObject() may not exist depending on how
1088 wxWidgets was configured.
23324ae1 1089 */
0c1fe6e9
BP
1090 virtual istream& LoadObject(istream& stream);
1091 virtual wxInputStream& LoadObject(wxInputStream& stream);
23324ae1
FM
1092 //@}
1093
1094 /**
0c1fe6e9
BP
1095 Call with @true to mark the document as modified since the last save,
1096 @false otherwise. You may need to override this if your document view
1097 maintains its own record of being modified.
1098
1099 @see IsModified()
23324ae1
FM
1100 */
1101 virtual void Modify(bool modify);
1102
1103 /**
0c1fe6e9
BP
1104 Called when a view is added to or deleted from this document. The
1105 default implementation saves and deletes the document if no views exist
1106 (the last one has just been removed).
23324ae1
FM
1107 */
1108 virtual void OnChangedViewList();
1109
1110 /**
0c1fe6e9
BP
1111 The default implementation calls DeleteContents() (an empty
1112 implementation) and sets the modified flag to @false. Override this to
1113 supply additional behaviour when the document is closed with Close().
23324ae1
FM
1114 */
1115 virtual bool OnCloseDocument();
1116
1117 /**
0c1fe6e9
BP
1118 Called just after the document object is created to give it a chance to
1119 initialize itself. The default implementation uses the template
1120 associated with the document to create an initial view. If this
1121 function returns @false, the document is deleted.
23324ae1
FM
1122 */
1123 virtual bool OnCreate(const wxString& path, long flags);
1124
1125 /**
0c1fe6e9
BP
1126 Override this function if you want a different (or no) command
1127 processor to be created when the document is created. By default, it
1128 returns an instance of wxCommandProcessor.
1129
1130 @see wxCommandProcessor
23324ae1
FM
1131 */
1132 virtual wxCommandProcessor* OnCreateCommandProcessor();
1133
1134 /**
0c1fe6e9
BP
1135 The default implementation calls OnSaveModified() and DeleteContents(),
1136 makes a default title for the document, and notifies the views that the
1137 filename (in fact, the title) has changed.
23324ae1
FM
1138 */
1139 virtual bool OnNewDocument();
1140
1141 /**
0c1fe6e9
BP
1142 Constructs an input file stream for the given filename (which must not
1143 be empty), and calls LoadObject(). If LoadObject() returns @true, the
1144 document is set to unmodified; otherwise, an error message box is
1145 displayed. The document's views are notified that the filename has
1146 changed, to give windows an opportunity to update their titles. All of
1147 the document's views are then updated.
23324ae1
FM
1148 */
1149 virtual bool OnOpenDocument(const wxString& filename);
1150
1151 /**
0c1fe6e9
BP
1152 Constructs an output file stream for the given filename (which must not
1153 be empty), and calls SaveObject(). If SaveObject() returns @true, the
1154 document is set to unmodified; otherwise, an error message box is
1155 displayed.
23324ae1
FM
1156 */
1157 virtual bool OnSaveDocument(const wxString& filename);
1158
1159 /**
0c1fe6e9
BP
1160 If the document has been modified, prompts the user to ask if the
1161 changes should be changed. If the user replies Yes, the Save() function
1162 is called. If No, the document is marked as unmodified and the function
1163 succeeds. If Cancel, the function fails.
23324ae1
FM
1164 */
1165 virtual bool OnSaveModified();
1166
1167 /**
0c1fe6e9
BP
1168 Removes the view from the document's list of views, and calls
1169 OnChangedViewList().
23324ae1
FM
1170 */
1171 virtual bool RemoveView(wxView* view);
1172
1173 /**
0c1fe6e9
BP
1174 Saves the document by calling OnSaveDocument() if there is an
1175 associated filename, or SaveAs() if there is no filename.
23324ae1
FM
1176 */
1177 virtual bool Save();
1178
1179 /**
0c1fe6e9
BP
1180 Prompts the user for a file to save to, and then calls
1181 OnSaveDocument().
23324ae1
FM
1182 */
1183 virtual bool SaveAs();
1184
1185 //@{
1186 /**
0c1fe6e9
BP
1187 Override this function and call it from your own SaveObject() before
1188 streaming your own data. SaveObject() is called by the framework
23324ae1 1189 automatically when the document contents need to be saved.
0c1fe6e9
BP
1190
1191 @note This version of SaveObject() may not exist depending on how
1192 wxWidgets was configured.
23324ae1 1193 */
0c1fe6e9
BP
1194 virtual ostream& SaveObject(ostream& stream);
1195 virtual wxOutputStream& SaveObject(wxOutputStream& stream);
23324ae1
FM
1196 //@}
1197
1198 /**
0c1fe6e9
BP
1199 Sets the command processor to be used for this document. The document
1200 will then be responsible for its deletion. Normally you should not call
1201 this; override OnCreateCommandProcessor() instead.
1202
1203 @see wxCommandProcessor
23324ae1 1204 */
4cc4bfaf 1205 virtual void SetCommandProcessor(wxCommandProcessor* processor);
23324ae1
FM
1206
1207 /**
1208 Sets the document type name for this document. See the comment for
0c1fe6e9 1209 @ref m_documentTypeName.
23324ae1
FM
1210 */
1211 void SetDocumentName(const wxString& name);
1212
1213 /**
0c1fe6e9
BP
1214 Sets the pointer to the template that created the document. Should only
1215 be called by the framework.
23324ae1
FM
1216 */
1217 void SetDocumentTemplate(wxDocTemplate* templ);
1218
1219 /**
1220 Sets the filename for this document. Usually called by the framework.
0c1fe6e9
BP
1221
1222 If @a notifyViews is @true, wxView::OnChangeFilename() is called for
1223 all views.
23324ae1 1224 */
0c1fe6e9 1225 void SetFilename(const wxString& filename, bool notifyViews = false);
23324ae1
FM
1226
1227 /**
0c1fe6e9
BP
1228 Sets the title for this document. The document title is used for an
1229 associated frame (if any), and is usually constructed by the framework
1230 from the filename.
23324ae1
FM
1231 */
1232 void SetTitle(const wxString& title);
1233
1234 /**
0c1fe6e9
BP
1235 Updates all views. If @a sender is non-@NULL, does not update this
1236 view. @a hint represents optional information to allow a view to
1237 optimize its update.
23324ae1 1238 */
4cc4bfaf 1239 void UpdateAllViews(wxView* sender = NULL, wxObject* hint = NULL);
23324ae1 1240
0bbe61b8
VZ
1241protected:
1242 /**
1243 This method is called by OnSaveDocument() to really save the document
1244 contents to the specified file.
1245
1246 Base class version creates a file-based stream and calls SaveObject().
1247 Override this if you need to do something else or prefer not to use
1248 SaveObject() at all.
1249 */
1250 virtual bool DoSaveDocument(const wxString& file);
1251
1252 /**
1253 This method is called by OnOpenDocument() to really load the document
1254 contents from the specified file.
1255
1256 Base class version creates a file-based stream and calls LoadObject().
1257 Override this if you need to do something else or prefer not to use
1258 LoadObject() at all.
1259 */
1260 virtual bool DoOpenDocument(const wxString& file);
1261
23324ae1 1262 /**
23324ae1
FM
1263 A pointer to the command processor associated with this document.
1264 */
0c1fe6e9 1265 wxCommandProcessor* m_commandProcessor;
23324ae1
FM
1266
1267 /**
23324ae1
FM
1268 Filename associated with this document ("" if none).
1269 */
0c1fe6e9 1270 wxString m_documentFile;
23324ae1
FM
1271
1272 /**
23324ae1
FM
1273 @true if the document has been modified, @false otherwise.
1274 */
0c1fe6e9 1275 bool m_documentModified;
23324ae1
FM
1276
1277 /**
23324ae1
FM
1278 A pointer to the template from which this document was created.
1279 */
0c1fe6e9 1280 wxDocTemplate* m_documentTemplate;
23324ae1
FM
1281
1282 /**
0c1fe6e9
BP
1283 Document title. The document title is used for an associated frame (if
1284 any), and is usually constructed by the framework from the filename.
23324ae1 1285 */
0c1fe6e9 1286 wxString m_documentTitle;
23324ae1
FM
1287
1288 /**
0c1fe6e9
BP
1289 The document type name given to the wxDocTemplate constructor, copied
1290 to this variable when the document is created. If several document
1291 templates are created that use the same document type, this variable is
1292 used in wxDocManager::CreateView() to collate a list of alternative
1293 view types that can be used on this kind of document. Do not change the
1294 value of this variable.
23324ae1 1295 */
0c1fe6e9 1296 wxString m_documentTypeName;
23324ae1
FM
1297
1298 /**
23324ae1
FM
1299 List of wxView instances associated with this document.
1300 */
0c1fe6e9 1301 wxList m_documentViews;
23324ae1
FM
1302};
1303
1304
e54c96f1 1305
23324ae1
FM
1306/**
1307 @class wxFileHistory
1308 @wxheader{docview.h}
7c913512 1309
0c1fe6e9
BP
1310 The wxFileHistory encapsulates a user interface convenience, the list of
1311 most recently visited files as shown on a menu (usually the File menu).
7c913512 1312
23324ae1 1313 wxFileHistory can manage one or more file menus. More than one menu may be
0c1fe6e9
BP
1314 required in an MDI application, where the file history should appear on
1315 each MDI child menu as well as the MDI parent frame.
7c913512 1316
23324ae1 1317 @library{wxcore}
0c1fe6e9 1318 @category{docview}
7c913512 1319
0c1fe6e9 1320 @see @ref overview_docview, wxDocManager
23324ae1
FM
1321*/
1322class wxFileHistory : public wxObject
1323{
1324public:
1325 /**
1326 Constructor. Pass the maximum number of files that should be stored and
1327 displayed.
0c1fe6e9
BP
1328
1329 @a idBase defaults to wxID_FILE1 and represents the id given to the
1330 first history menu item. Since menu items can't share the same ID you
1331 should change @a idBase (to one of your own defined IDs) when using
1332 more than one wxFileHistory in your application.
23324ae1 1333 */
0c1fe6e9 1334 wxFileHistory(size_t maxFiles = 9, wxWindowID idBase = wxID_FILE1);
23324ae1
FM
1335
1336 /**
1337 Destructor.
1338 */
1339 ~wxFileHistory();
1340
1341 /**
1342 Adds a file to the file history list, if the object has a pointer to an
1343 appropriate file menu.
1344 */
1345 void AddFileToHistory(const wxString& filename);
1346
23324ae1 1347 /**
0c1fe6e9
BP
1348 Appends the files in the history list, to all menus managed by the file
1349 history object.
23324ae1
FM
1350 */
1351 void AddFilesToMenu();
0c1fe6e9
BP
1352 /**
1353 Appends the files in the history list, to the given menu only.
1354 */
7c913512 1355 void AddFilesToMenu(wxMenu* menu);
23324ae1
FM
1356
1357 /**
1358 Returns the base identifier for the range used for appending items.
1359 */
328f5751 1360 wxWindowID GetBaseId() const;
23324ae1
FM
1361
1362 /**
1363 Returns the number of files currently stored in the file history.
1364 */
328f5751 1365 size_t GetCount() const;
23324ae1
FM
1366
1367 /**
1368 Returns the file at this index (zero-based).
1369 */
328f5751 1370 wxString GetHistoryFile(size_t index) const;
23324ae1
FM
1371
1372 /**
1373 Returns the maximum number of files that can be stored.
1374 */
328f5751 1375 int GetMaxFiles() const;
23324ae1
FM
1376
1377 /**
1378 Returns the list of menus that are managed by this file history object.
3c4f71cc 1379
4cc4bfaf 1380 @see UseMenu()
23324ae1 1381 */
0c1fe6e9 1382 const wxList& GetMenus() const;
23324ae1
FM
1383
1384 /**
0c1fe6e9
BP
1385 Loads the file history from the given config object. This function
1386 should be called explicitly by the application.
3c4f71cc 1387
0c1fe6e9 1388 @see wxConfigBase
23324ae1 1389 */
6656b711 1390 void Load(const wxConfigBase& config);
23324ae1
FM
1391
1392 /**
1393 Removes the specified file from the history.
1394 */
1395 void RemoveFileFromHistory(size_t i);
1396
1397 /**
1398 Removes this menu from the list of those managed by this object.
1399 */
1400 void RemoveMenu(wxMenu* menu);
1401
1402 /**
0c1fe6e9
BP
1403 Saves the file history into the given config object. This must be
1404 called explicitly by the application.
3c4f71cc 1405
0c1fe6e9 1406 @see wxConfigBase
23324ae1
FM
1407 */
1408 void Save(wxConfigBase& config);
1409
1410 /**
1411 Sets the base identifier for the range used for appending items.
1412 */
1413 void SetBaseId(wxWindowID baseId);
1414
1415 /**
0c1fe6e9
BP
1416 Adds this menu to the list of those menus that are managed by this file
1417 history object. Also see AddFilesToMenu() for initializing the menu
1418 with filenames that are already in the history when this function is
1419 called, as this is not done automatically.
23324ae1
FM
1420 */
1421 void UseMenu(wxMenu* menu);
1422
1423 /**
23324ae1
FM
1424 A character array of strings corresponding to the most recently opened
1425 files.
1426 */
0c1fe6e9 1427 char** m_fileHistory;
23324ae1
FM
1428
1429 /**
23324ae1
FM
1430 The number of files stored in the history array.
1431 */
0c1fe6e9 1432 size_t m_fileHistoryN;
23324ae1
FM
1433
1434 /**
23324ae1
FM
1435 The maximum number of files to be stored and displayed on the menu.
1436 */
0c1fe6e9 1437 size_t m_fileMaxFiles;
23324ae1
FM
1438
1439 /**
23324ae1
FM
1440 The file menu used to display the file history list (if enabled).
1441 */
0c1fe6e9 1442 wxMenu* m_fileMenu;
23324ae1
FM
1443};
1444
1445
e54c96f1 1446
23324ae1
FM
1447// ============================================================================
1448// Global functions/macros
1449// ============================================================================
1450
1ba0de2e
BP
1451/** @ingroup group_funcmacro_file */
1452//@{
1453
23324ae1 1454/**
1ba0de2e
BP
1455 Copies the given file to @a stream. Useful when converting an old
1456 application to use streams (within the document/view framework, for
1457 example).
1458
1459 @header{wx/docview.h}
23324ae1
FM
1460*/
1461bool wxTransferFileToStream(const wxString& filename,
1462 ostream& stream);
1463
1ba0de2e
BP
1464/**
1465 Copies the given stream to the file @a filename. Useful when converting an
1466 old application to use streams (within the document/view framework, for
1467 example).
1468
1469 @header{wx/docview.h}
1470*/
1471bool wxTransferStreamToFile(istream& stream,
1472 const wxString& filename);
1473
1474//@}
1475