1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of various doc/view framework classes
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 The wxDocTemplate class is used to model the relationship between a
14 document class and a view class.
19 @see @ref overview_docview_wxdoctemplate, wxDocument, wxView
21 class wxDocTemplate
: public wxObject
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.
30 The document manager object which manages this template.
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.
35 An appropriate file filter such as "*.txt".
37 The default directory to use for file selectors.
39 The default file extension (such as "txt").
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.
44 A name that should be unique for a given view.
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
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
58 A bit list of the following:
59 - wxTEMPLATE_VISIBLE - The template may be displayed to the
61 - wxTEMPLATE_INVISIBLE - The template may not be displayed to
63 - wxDEFAULT_TEMPLATE_FLAGS - Defined as wxTEMPLATE_VISIBLE.
65 wxDocTemplate(wxDocManager
* manager
, const wxString
& descr
,
66 const wxString
& filter
, const wxString
& dir
,
67 const wxString
& ext
, const wxString
& docTypeName
,
68 const wxString
& viewTypeName
,
69 wxClassInfo
* docClassInfo
= NULL
,
70 wxClassInfo
* viewClassInfo
= NULL
,
71 long flags
= wxDEFAULT_TEMPLATE_FLAGS
);
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
84 This function calls InitDocument() which in turns calls
85 wxDocument::OnCreate().
87 wxDocument
* CreateDocument(const wxString
& path
, long flags
= 0);
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.
94 wxView
* CreateView(wxDocument
* doc
, long flags
= 0);
97 Returns the default file extension for the document data, as passed to
98 the document template constructor.
100 wxString
GetDefaultExtension();
103 Returns the text description of this template, as passed to the
104 document template constructor.
106 wxString
GetDescription();
109 Returns the default directory, as passed to the document template
112 wxString
GetDirectory();
115 Returns a pointer to the document manager instance for which this
116 template was created.
118 wxDocManager
* GetDocumentManager();
121 Returns the document type name, as passed to the document template
124 wxString
GetDocumentName();
127 Returns the file filter, as passed to the document template
130 wxString
GetFileFilter();
133 Returns the flags, as passed to the document template constructor.
138 Returns the view type name, as passed to the document template
141 wxString
GetViewName();
144 Initialises the document, calling wxDocument::OnCreate(). This is
145 called from CreateDocument().
147 bool InitDocument(wxDocument
* doc
, const wxString
& path
, long flags
= 0);
150 Returns @true if the document template can be shown in user dialogs,
156 Sets the default file extension.
158 void SetDefaultExtension(const wxString
& ext
);
161 Sets the template description.
163 void SetDescription(const wxString
& descr
);
166 Sets the default directory.
168 void SetDirectory(const wxString
& dir
);
171 Sets the pointer to the document manager instance for which this
172 template was created. Should not be called by the application.
174 void SetDocumentManager(wxDocManager
* manager
);
177 Sets the file filter.
179 void SetFileFilter(const wxString
& filter
);
182 Sets the internal document template flags (see the constructor
183 description for more details).
185 void SetFlags(long flags
);
188 The default extension for files of this type.
190 wxString m_defaultExt
;
193 A short description of this template.
195 wxString m_description
;
198 The default directory for files of this type.
200 wxString m_directory
;
203 Run-time class information that allows document instances to be
204 constructed dynamically.
206 wxClassInfo
* m_docClassInfo
;
209 The named type of the document associated with this template.
211 wxString m_docTypeName
;
214 A pointer to the document manager for which this template was created.
216 wxDocTemplate
* m_documentManager
;
219 The file filter (such as "*.txt") to be used in file selector dialogs.
221 wxString m_fileFilter
;
224 The flags passed to the constructor.
229 Run-time class information that allows view instances to be constructed
232 wxClassInfo
* m_viewClassInfo
;
235 The named type of the view associated with this template.
237 wxString m_viewTypeName
;
246 The wxDocManager class is part of the document/view framework supported by
247 wxWidgets, and cooperates with the wxView, wxDocument and wxDocTemplate
253 @see @ref overview_docview_wxdocmanager, wxDocument, wxView, wxDocTemplate,
256 class wxDocManager
: public wxEvtHandler
260 Constructor. Create a document manager instance dynamically near the
261 start of your application before doing any document or view operations.
263 @a flags is currently unused.
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.
271 wxDocManager(long flags
= wxDEFAULT_DOCMAN_FLAGS
,
272 bool initialize
= true);
280 Sets the current view.
282 void ActivateView(wxView
* doc
, bool activate
= true);
285 Adds the document to the list of documents.
287 void AddDocument(wxDocument
* doc
);
290 Adds a file to the file history list, if we have a pointer to an
291 appropriate file menu.
293 void AddFileToHistory(const wxString
& filename
);
296 Adds the template to the document manager's template list.
298 void AssociateTemplate(wxDocTemplate
* temp
);
301 Closes all currently opened documents.
303 bool CloseDocuments(bool force
= true);
306 Creates a new document in a manner determined by the @a flags
307 parameter, which can be:
309 - wxDOC_NEW - Creates a fresh document.
310 - wxDOC_SILENT - Silently loads the given document file.
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
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.
324 wxDocument
* CreateDocument(const wxString
& path
, long flags
);
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.
331 wxView
* CreateView(wxDocument
* doc
, long flags
);
334 Removes the template from the list of templates.
336 void DisassociateTemplate(wxDocTemplate
* temp
);
339 Appends the files in the history list to all menus managed by the file
342 void FileHistoryAddFilesToMenu();
344 Appends the files in the history list to the given @a menu only.
346 void FileHistoryAddFilesToMenu(wxMenu
* menu
);
349 Loads the file history from a config object.
353 void FileHistoryLoad(wxConfigBase
& config
);
356 Removes the given menu from the list of menus managed by the file
359 void FileHistoryRemoveMenu(wxMenu
* menu
);
362 Saves the file history into a config object. This must be called
363 explicitly by the application.
367 void FileHistorySave(wxConfigBase
& resourceFile
);
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.
374 @note You can add multiple menus using this function, to be managed by
375 the file history object.
377 void FileHistoryUseMenu(wxMenu
* menu
);
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
384 wxDocTemplate
* FindTemplateForPath(const wxString
& path
);
387 Returns the document associated with the currently active view (if
390 wxDocument
* GetCurrentDocument();
393 Returns the currently active view
395 wxView
* GetCurrentView();
398 Returns a reference to the list of documents.
400 wxList
GetDocuments();
403 Returns a pointer to file history.
405 wxFileHistory
* GetFileHistory();
408 Returns the number of files currently stored in the file history.
410 size_t GetHistoryFilesCount();
413 Returns the directory last selected by the user when opening a file.
416 wxString
GetLastDirectory() const;
419 Returns the number of documents that can be open simultaneously.
421 int GetMaxDocsOpen();
424 Returns a reference to the list of associated templates.
426 wxList
GetTemplates();
429 Initializes data; currently just calls OnCreateFileHistory().
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.
441 The bottom line: if you're not deriving from Initialize(), forget it
442 and construct wxDocManager with no arguments.
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.
452 wxString
MakeNewDocumentName();
455 A hook to allow a derived class to create a different type of file
456 history. Called from Initialize().
458 wxFileHistory
* OnCreateFileHistory();
461 Closes and deletes the currently active document.
463 void OnFileClose(wxCommandEvent
& event
);
466 Closes and deletes all the currently opened documents.
468 void OnFileCloseAll(wxCommandEvent
& event
);
471 Creates a document from a list of templates (if more than one
474 void OnFileNew(wxCommandEvent
& event
);
477 Creates a new document and reads in the selected file.
479 void OnFileOpen(wxCommandEvent
& event
);
482 Reverts the current document by calling wxDocument::Revert() for the
485 void OnFileRevert(wxCommandEvent
& event
);
488 Saves the current document by calling wxDocument::Save() for the
491 void OnFileSave(wxCommandEvent
& event
);
494 Calls wxDocument::SaveAs() for the current document.
496 void OnFileSaveAs(wxCommandEvent
& event
);
499 Removes the document from the list of documents.
501 void RemoveDocument(wxDocument
* doc
);
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.
508 On other platforms, if there is more than one document template a
509 choice list is popped up, followed by a file selector.
511 This function is used in CreateDocument().
513 wxDocTemplate
* SelectDocumentPath(wxDocTemplate
** templates
,
514 int noTemplates
, wxString
& path
,
515 long flags
, bool save
);
518 Returns a document template by asking the user (if there is more than
519 one template). This function is used in CreateDocument().
522 Pointer to an array of templates from which to choose a desired
525 Number of templates being pointed to by the templates pointer.
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.
532 wxDocTemplate
* SelectDocumentType(wxDocTemplate
** templates
,
533 int noTemplates
, bool sort
= false);
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.
543 Pointer to an array of templates from which to choose a desired
546 Number of templates being pointed to by the templates pointer.
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.
553 wxDocTemplate
* SelectViewType(wxDocTemplate
** templates
,
554 int noTemplates
, bool sort
= false);
557 Sets the directory to be displayed to the user when opening a file.
558 Initially this is empty.
560 void SetLastDirectory(const wxString
& dir
);
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.
570 void SetMaxDocsOpen(int n
);
573 The currently active view.
575 wxView
* m_currentView
;
578 Stores the integer to be used for the next default document name.
580 int m_defaultDocumentNameCounter
;
583 A list of all documents.
588 A pointer to an instance of wxFileHistory, which manages the history of
589 recently-visited files on the File menu.
591 wxFileHistory
* m_fileHistory
;
594 Stores the flags passed to the constructor.
599 The directory last selected by the user when opening a file.
601 wxFileHistory
* m_fileHistory
;
604 Stores the maximum number of documents that can be opened before
605 existing documents are closed. By default, this is 10,000.
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
618 supported by wxWidgets, and cooperates with the wxDocument, wxDocTemplate
619 and wxDocManager classes.
624 @see @ref overview_docview_wxview, wxDocument, wxDocTemplate, wxDocManager
626 class wxView
: public wxEvtHandler
630 Constructor. Define your own default constructor to initialize
631 application-specific data.
636 Destructor. Removes itself from the document's list of views.
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.
647 The prepackaged view frame wxDocChildFrame calls Activate() from its
648 wxDocChildFrame::OnActivate() member.
650 This function calls OnActivateView().
652 virtual void Activate(bool activate
);
655 Closes the view by calling OnClose(). If @a deleteWindow is @true, this
656 function should delete the window associated with the view.
658 virtual bool Close(bool deleteWindow
= true);
661 Gets a pointer to the document associated with the view.
663 wxDocument
* GetDocument() const;
666 Returns a pointer to the document manager instance associated with this
669 wxDocManager
* GetDocumentManager() const;
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.
677 wxWindow
* GetFrame();
680 Gets the name associated with the view (passed to the wxDocTemplate
681 constructor). Not currently used by the framework.
683 wxString
GetViewName() const;
686 Called when a view is activated by means of Activate(). The default
687 implementation does nothing.
689 virtual void OnActivateView(bool activate
, wxView
* activeView
,
690 wxView
* deactiveView
);
693 Called when the filename has changed. The default implementation
694 constructs a suitable title and sets the title of the view frame (if
697 virtual void OnChangeFilename();
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.
708 virtual bool OnClose(bool deleteWindow
);
711 Override this to clean up the view when the document is being closed.
713 virtual void OnClosingDocument();
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.
722 By default, simply returns @true. If the function returns @false, the
723 view will be deleted.
725 virtual bool OnCreate(wxDocument
* doc
, long flags
);
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
733 By default, this function returns an instance of wxDocPrintout, which
734 prints and previews one page by calling OnDraw().
736 Override to return an instance of a class other than wxDocPrintout.
738 virtual wxPrintout
* OnCreatePrintout();
741 Override this function to render the view on the given device context.
743 virtual void OnDraw(wxDC
* dc
);
746 Called when the view should be updated.
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
753 This is unused currently, but may in future contain
754 application-specific information for making updating more
757 virtual void OnUpdate(wxView
* sender
, wxObject
* hint
);
760 Associates the given document with the view. Normally called by the
763 void SetDocument(wxDocument
* doc
);
766 Sets the frame associated with this view. The application should call
767 this if possible, to tell the view about the frame.
769 See GetFrame() for the explanation about the mismatch between the
770 "Frame" in the method name and the type of its parameter.
772 void SetFrame(wxWindow
* frame
);
775 Sets the view type name. Should only be called by the framework.
777 void SetViewName(const wxString
& name
);
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
784 wxDocument
* m_viewDocument
;
787 Frame associated with the view, if any.
789 wxFrame
* m_viewFrame
;
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
796 wxString m_viewTypeName
;
802 @class wxDocChildFrame
805 The wxDocChildFrame class provides a default frame for displaying documents
806 on separate windows. This class can only be used for SDI (not MDI) child
809 The class is part of the document/view framework supported by wxWidgets,
810 and cooperates with the wxView, wxDocument, wxDocManager and wxDocTemplate
816 @see @ref overview_docview, @ref page_samples_docview, wxFrame
818 class wxDocChildFrame
: public wxFrame
824 wxDocChildFrame(wxDocument
* doc
, wxView
* view
, wxFrame
* parent
,
825 wxWindowID id
, const wxString
& title
,
826 const wxPoint
& pos
= wxDefaultPosition
,
827 const wxSize
& size
= wxDefaultSize
,
828 long style
= wxDEFAULT_FRAME_STYLE
,
829 const wxString
& name
= "frame");
837 Returns the document associated with this frame.
839 wxDocument
* GetDocument() const;
842 Returns the view associated with this frame.
844 wxView
* GetView() const;
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
849 focus for your subwindow.
851 void OnActivate(wxActivateEvent event
);
854 Closes and deletes the current view and document.
856 void OnCloseWindow(wxCloseEvent
& event
);
859 Sets the document for this frame.
861 void SetDocument(wxDocument
* doc
);
864 Sets the view for this frame.
866 void SetView(wxView
* view
);
869 The document associated with the frame.
871 wxDocument
* m_childDocument
;
874 The view associated with the frame.
882 @class wxDocParentFrame
885 The wxDocParentFrame class provides a default top-level frame for
886 applications using the document/view framework. This class can only be used
887 for SDI (not MDI) parent frames.
889 It cooperates with the wxView, wxDocument, wxDocManager and wxDocTemplate
895 @see @ref overview_docview, @ref page_samples_docview, wxFrame
897 class wxDocParentFrame
: public wxFrame
907 wxDocParentFrame(wxDocManager
* manager
, wxFrame
* parent
,
908 wxWindowID id
, const wxString
& title
,
909 const wxPoint
& pos
= wxDefaultPosition
,
910 const wxSize
& size
= wxDefaultSize
,
911 long style
= wxDEFAULT_FRAME_STYLE
,
912 const wxString
& name
= "frame");
920 Used in two-step construction.
922 bool Create(wxDocManager
* manager
, wxFrame
* parent
,
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");
930 Returns the associated document manager object.
932 wxDocManager
* GetDocumentManager() const;
935 Deletes all views and documents. If no user input cancelled the
936 operation, the frame will be destroyed and the application will exit.
937 Since understanding how document/view clean-up takes place can be
938 difficult, the implementation of this function is shown below:
941 void wxDocParentFrame::OnCloseWindow(wxCloseEvent& event)
943 if (m_docManager->Clear(!event.CanVeto()))
952 void OnCloseWindow(wxCloseEvent
& event
);
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.
968 @see @ref overview_docview, wxView, wxDocTemplate, wxDocManager
970 class wxDocument
: public wxEvtHandler
974 Constructor. Define your own default constructor to initialize
975 application-specific data.
980 Destructor. Removes itself from the document manager.
985 If the view is not already in the list of views, adds the view and
986 calls OnChangedViewList().
988 virtual bool AddView(wxView
* view
);
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.
995 virtual bool Close();
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
1004 virtual bool DeleteAllViews();
1007 Returns a pointer to the command processor associated with this
1010 @see wxCommandProcessor
1012 wxCommandProcessor
* GetCommandProcessor() const;
1015 Gets a pointer to the associated document manager.
1017 wxDocManager
* GetDocumentManager() const;
1020 Gets the document type name for this document. See the comment for
1021 @ref m_documentTypeName.
1023 wxString
GetDocumentName() const;
1026 Gets a pointer to the template that created the document.
1028 wxDocTemplate
* GetDocumentTemplate() const;
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.
1035 wxWindow
* GetDocumentWindow() const;
1038 Gets the filename associated with this document, or "" if none is
1041 wxString
GetFilename() const;
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.
1049 wxView
* GetFirstView() const;
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
1056 wxString
GetTitle() const;
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.
1063 virtual wxString
GetUserReadableName() const;
1066 Returns the list whose elements are the views on the document.
1070 wxList
GetViews() const;
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.
1079 virtual bool IsModified() const;
1083 Override this function and call it from your own LoadObject() before
1084 streaming your own data. LoadObject() is called by the framework
1085 automatically when the document contents need to be loaded.
1087 @note This version of LoadObject() may not exist depending on how
1088 wxWidgets was configured.
1090 virtual istream
& LoadObject(istream
& stream
);
1091 virtual wxInputStream
& LoadObject(wxInputStream
& stream
);
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.
1101 virtual void Modify(bool modify
);
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).
1108 virtual void OnChangedViewList();
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().
1115 virtual bool OnCloseDocument();
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.
1123 virtual bool OnCreate(const wxString
& path
, long flags
);
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.
1130 @see wxCommandProcessor
1132 virtual wxCommandProcessor
* OnCreateCommandProcessor();
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.
1139 virtual bool OnNewDocument();
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.
1149 virtual bool OnOpenDocument(const wxString
& filename
);
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
1157 virtual bool OnSaveDocument(const wxString
& filename
);
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.
1165 virtual bool OnSaveModified();
1168 Removes the view from the document's list of views, and calls
1169 OnChangedViewList().
1171 virtual bool RemoveView(wxView
* view
);
1174 Saves the document by calling OnSaveDocument() if there is an
1175 associated filename, or SaveAs() if there is no filename.
1177 virtual bool Save();
1180 Prompts the user for a file to save to, and then calls
1183 virtual bool SaveAs();
1187 Override this function and call it from your own SaveObject() before
1188 streaming your own data. SaveObject() is called by the framework
1189 automatically when the document contents need to be saved.
1191 @note This version of SaveObject() may not exist depending on how
1192 wxWidgets was configured.
1194 virtual ostream
& SaveObject(ostream
& stream
);
1195 virtual wxOutputStream
& SaveObject(wxOutputStream
& stream
);
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.
1203 @see wxCommandProcessor
1205 virtual void SetCommandProcessor(wxCommandProcessor
* processor
);
1208 Sets the document type name for this document. See the comment for
1209 @ref m_documentTypeName.
1211 void SetDocumentName(const wxString
& name
);
1214 Sets the pointer to the template that created the document. Should only
1215 be called by the framework.
1217 void SetDocumentTemplate(wxDocTemplate
* templ
);
1220 Sets the filename for this document. Usually called by the framework.
1222 If @a notifyViews is @true, wxView::OnChangeFilename() is called for
1225 void SetFilename(const wxString
& filename
, bool notifyViews
= false);
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
1232 void SetTitle(const wxString
& title
);
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.
1239 void UpdateAllViews(wxView
* sender
= NULL
, wxObject
* hint
= NULL
);
1243 This method is called by OnSaveDocument() to really save the document
1244 contents to the specified file.
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.
1250 virtual bool DoSaveDocument(const wxString
& file
);
1253 This method is called by OnOpenDocument() to really load the document
1254 contents from the specified file.
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.
1260 virtual bool DoOpenDocument(const wxString
& file
);
1263 A pointer to the command processor associated with this document.
1265 wxCommandProcessor
* m_commandProcessor
;
1268 Filename associated with this document ("" if none).
1270 wxString m_documentFile
;
1273 @true if the document has been modified, @false otherwise.
1275 bool m_documentModified
;
1278 A pointer to the template from which this document was created.
1280 wxDocTemplate
* m_documentTemplate
;
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.
1286 wxString m_documentTitle
;
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.
1296 wxString m_documentTypeName
;
1299 List of wxView instances associated with this document.
1301 wxList m_documentViews
;
1307 @class wxFileHistory
1308 @wxheader{docview.h}
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).
1313 wxFileHistory can manage one or more file menus. More than one menu may be
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.
1320 @see @ref overview_docview, wxDocManager
1322 class wxFileHistory
: public wxObject
1326 Constructor. Pass the maximum number of files that should be stored and
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.
1334 wxFileHistory(size_t maxFiles
= 9, wxWindowID idBase
= wxID_FILE1
);
1342 Adds a file to the file history list, if the object has a pointer to an
1343 appropriate file menu.
1345 void AddFileToHistory(const wxString
& filename
);
1348 Appends the files in the history list, to all menus managed by the file
1351 void AddFilesToMenu();
1353 Appends the files in the history list, to the given menu only.
1355 void AddFilesToMenu(wxMenu
* menu
);
1358 Returns the base identifier for the range used for appending items.
1360 wxWindowID
GetBaseId() const;
1363 Returns the number of files currently stored in the file history.
1365 size_t GetCount() const;
1368 Returns the file at this index (zero-based).
1370 wxString
GetHistoryFile(size_t index
) const;
1373 Returns the maximum number of files that can be stored.
1375 int GetMaxFiles() const;
1378 Returns the list of menus that are managed by this file history object.
1382 const wxList
& GetMenus() const;
1385 Loads the file history from the given config object. This function
1386 should be called explicitly by the application.
1390 void Load(wxConfigBase
& config
);
1393 Removes the specified file from the history.
1395 void RemoveFileFromHistory(size_t i
);
1398 Removes this menu from the list of those managed by this object.
1400 void RemoveMenu(wxMenu
* menu
);
1403 Saves the file history into the given config object. This must be
1404 called explicitly by the application.
1408 void Save(wxConfigBase
& config
);
1411 Sets the base identifier for the range used for appending items.
1413 void SetBaseId(wxWindowID baseId
);
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.
1421 void UseMenu(wxMenu
* menu
);
1424 A character array of strings corresponding to the most recently opened
1427 char** m_fileHistory
;
1430 The number of files stored in the history array.
1432 size_t m_fileHistoryN
;
1435 The maximum number of files to be stored and displayed on the menu.
1437 size_t m_fileMaxFiles
;
1440 The file menu used to display the file history list (if enabled).
1447 // ============================================================================
1448 // Global functions/macros
1449 // ============================================================================
1451 /** @ingroup group_funcmacro_file */
1455 Copies the given file to @a stream. Useful when converting an old
1456 application to use streams (within the document/view framework, for
1459 @header{wx/docview.h}
1461 bool wxTransferFileToStream(const wxString
& filename
,
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
1469 @header{wx/docview.h}
1471 bool wxTransferStreamToFile(istream
& stream
,
1472 const wxString
& filename
);