]>
git.saurik.com Git - wxWidgets.git/blob - interface/docview.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxDocTemplate class
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.
20 @ref overview_wxdoctemplateoverview "wxDocTemplate overview", wxDocument, wxView
22 class wxDocTemplate
: public wxObject
26 Constructor. Create instances dynamically near the start of your application
28 a wxDocManager instance, and before doing any document or view operations.
30 @e manager is the document manager object which manages this template.
32 @e descr is a short description of what the template is for. This string will
34 file filter list of Windows file selectors.
36 @e filter is an appropriate file filter such as @c *.txt.
38 @e dir is the default directory to use for file selectors.
40 @e ext is the default file extension (such as txt).
42 @e docTypeName is a name that should be unique for a given type of document,
44 gathering a list of views relevant to a particular document.
46 @e viewTypeName is a name that should be unique for a given view.
48 @e docClassInfo is a pointer to the run-time document class information as
50 by the CLASSINFO macro, e.g. CLASSINFO(MyDocumentClass). If this is not
52 you will need to derive a new wxDocTemplate class and override the
54 member to return a new document instance on demand.
56 @e viewClassInfo is a pointer to the run-time view class information as returned
57 by the CLASSINFO macro, e.g. CLASSINFO(MyViewClass). If this is not supplied,
58 you will need to derive a new wxDocTemplate class and override the CreateView
59 member to return a new view instance on demand.
61 @e flags is a bit list of the following:
63 wxTEMPLATE_VISIBLE The template may be displayed to the user in dialogs.
64 wxTEMPLATE_INVISIBLE The template may not be displayed to the user in dialogs.
65 wxDEFAULT_TEMPLATE_FLAGS Defined as wxTEMPLATE_VISIBLE.
69 @b Wx::DocTemplate-new( docmgr, descr, filter, dir,
70 ext, docTypeName, viewTypeName, docClassInfo, viewClassInfo, flags
74 will construct document and view objects from the class information
76 @b Wx::DocTemplate-new( docmgr, descr, filter, dir,
77 ext, docTypeName, viewTypeName, docClassName, viewClassName, flags
81 will construct document and view objects from perl packages
83 @b Wx::DocTemplate-new( docmgr, descr, filter, dir,
84 ext, docTypeName, viewTypeName )
87 @c Wx::DocTemplate::CreateDocument() and
88 @c Wx::DocTemplate::CreateView() must be overridden
90 wxDocTemplate(wxDocManager
* manager
, const wxString
& descr
,
91 const wxString
& filter
,
94 const wxString
& docTypeName
,
95 const wxString
& viewTypeName
,
96 wxClassInfo
* docClassInfo
= @NULL
,
97 wxClassInfo
* viewClassInfo
= @NULL
,
98 long flags
= wxDEFAULT_TEMPLATE_FLAGS
);
106 Creates a new instance of the associated document class. If you have not
108 a wxClassInfo parameter to the template constructor, you will need to override
110 function to return an appropriate document instance.
112 This function calls InitDocument() which in turns
113 calls wxDocument::OnCreate.
115 wxDocument
* CreateDocument(const wxString
& path
, long flags
= 0);
118 Creates a new instance of the associated view class. If you have not supplied
119 a wxClassInfo parameter to the template constructor, you will need to override
121 function to return an appropriate view instance.
123 wxView
* CreateView(wxDocument
* doc
, long flags
= 0);
126 Returns the default file extension for the document data, as passed to the
127 document template constructor.
129 wxString
GetDefaultExtension();
132 Returns the text description of this template, as passed to the document
133 template constructor.
135 wxString
GetDescription();
138 Returns the default directory, as passed to the document template constructor.
140 wxString
GetDirectory();
143 Returns a pointer to the document manager instance for which this template was
146 wxDocManager
* GetDocumentManager();
149 Returns the document type name, as passed to the document template constructor.
151 wxString
GetDocumentName();
154 Returns the file filter, as passed to the document template constructor.
156 wxString
GetFileFilter();
159 Returns the flags, as passed to the document template constructor.
164 Returns the view type name, as passed to the document template constructor.
166 wxString
GetViewName();
169 Initialises the document, calling wxDocument::OnCreate. This is called from
172 bool InitDocument(wxDocument
* doc
, const wxString
& path
,
176 Returns @true if the document template can be shown in user dialogs, @false
182 Sets the default file extension.
184 void SetDefaultExtension(const wxString
& ext
);
187 Sets the template description.
189 void SetDescription(const wxString
& descr
);
192 Sets the default directory.
194 void SetDirectory(const wxString
& dir
);
197 Sets the pointer to the document manager instance for which this template was
199 Should not be called by the application.
201 void SetDocumentManager(wxDocManager
* manager
);
204 Sets the file filter.
206 void SetFileFilter(const wxString
& filter
);
209 Sets the internal document template flags (see the constructor description for
212 void SetFlags(long flags
);
215 wxString m_defaultExt
217 The default extension for files of this type.
222 wxString m_description
224 A short description of this template.
231 The default directory for files of this type.
236 wxClassInfo* m_docClassInfo
238 Run-time class information that allows document instances to be constructed
244 wxString m_docTypeName
246 The named type of the document associated with this template.
251 wxDocTemplate* m_documentManager
253 A pointer to the document manager for which this template was created.
258 wxString m_fileFilter
260 The file filter (such as @c *.txt) to be used in file selector dialogs.
267 The flags passed to the constructor.
272 wxClassInfo* m_viewClassInfo
274 Run-time class information that allows view instances to be constructed
280 wxString m_viewTypeName
282 The named type of the view associated with this template.
291 The wxDocManager class is part of the document/view framework supported by
293 and cooperates with the wxView, wxDocument
294 and wxDocTemplate classes.
300 @ref overview_wxdocmanageroverview "wxDocManager overview", wxDocument, wxView,
301 wxDocTemplate, wxFileHistory
303 class wxDocManager
: public wxEvtHandler
307 Constructor. Create a document manager instance dynamically near the start of
309 before doing any document or view operations.
311 @e flags is currently unused.
313 If @e initialize is @true, the Initialize() function will be called
314 to create a default history list object. If you derive from wxDocManager, you
316 base constructor with @false, and then call Initialize in your own constructor,
318 your own Initialize or OnCreateFileHistory functions to be called.
320 wxDocManager(long flags
= wxDEFAULT_DOCMAN_FLAGS
,
321 bool initialize
= @
true);
329 Sets the current view.
331 void ActivateView(wxView
* doc
, bool activate
= @
true);
334 Adds the document to the list of documents.
336 void AddDocument(wxDocument
* doc
);
339 Adds a file to the file history list, if we have a pointer to an appropriate
342 void AddFileToHistory(const wxString
& filename
);
345 Adds the template to the document manager's template list.
347 void AssociateTemplate(wxDocTemplate
* temp
);
350 Closes all currently opened documents.
352 bool CloseDocuments(bool force
= @
true);
355 Creates a new document in a manner determined by the @e flags parameter, which
358 wxDOC_NEW Creates a fresh document.
359 wxDOC_SILENT Silently loads the given document file.
361 If wxDOC_NEW is present, a new document will be created and returned, possibly
363 asking the user for a template to use if there is more than one document
365 If wxDOC_SILENT is present, a new document will be created and the given file
367 into it. If neither of these flags is present, the user will be presented with
368 a file selector for the file to load, and the template to use will be
370 extension (Windows) or by popping up a template choice list (other platforms).
372 If the maximum number of documents has been reached, this function
373 will delete the oldest currently loaded document before creating a new one.
375 wxDocument
* CreateDocument(const wxString
& path
, long flags
);
378 Creates a new view for the given document. If more than one view is allowed for
380 document (by virtue of multiple templates mentioning the same document type), a
382 of view is presented to the user.
384 wxView
* CreateView(wxDocument
* doc
, long flags
);
387 Removes the template from the list of templates.
389 void DisassociateTemplate(wxDocTemplate
* temp
);
393 Appends the files in the history list, to the given menu only.
395 void FileHistoryAddFilesToMenu();
396 void FileHistoryAddFilesToMenu(wxMenu
* menu
);
400 Loads the file history from a config object.
404 void FileHistoryLoad(wxConfigBase
& config
);
407 Removes the given menu from the list of menus managed by the file history
410 void FileHistoryRemoveMenu(wxMenu
* menu
);
413 Saves the file history into a config object. This must be called
414 explicitly by the application.
418 void FileHistorySave(wxConfigBase
& resourceFile
);
421 Use this menu for appending recently-visited document filenames, for convenient
422 access. Calling this function with a valid menu pointer enables the history
425 Note that you can add multiple menus using this function, to be managed by the
428 void FileHistoryUseMenu(wxMenu
* menu
);
431 Given a path, try to find template that matches the extension. This is only
432 an approximate method of finding a template for creating a document.
434 wxDocTemplate
* FindTemplateForPath(const wxString
& path
);
437 Returns the document associated with the currently active view (if any).
439 wxDocument
* GetCurrentDocument();
442 Returns the currently active view
444 wxView
* GetCurrentView();
447 Returns a reference to the list of documents.
449 wxList
GetDocuments();
452 Returns a pointer to file history.
454 wxFileHistory
* GetFileHistory();
457 Returns the number of files currently stored in the file history.
459 size_t GetHistoryFilesCount();
462 Returns the directory last selected by the user when opening a file. Initially
465 wxString
GetLastDirectory();
468 Returns the number of documents that can be open simultaneously.
470 int GetMaxDocsOpen();
473 Returns a reference to the list of associated templates.
475 wxList
GetTemplates();
478 Initializes data; currently just calls OnCreateFileHistory. Some data cannot
479 always be initialized in the constructor because the programmer must be given
480 the opportunity to override functionality. If OnCreateFileHistory was called
481 from the constructor, an overridden virtual OnCreateFileHistory would not be
482 called due to C++'s 'interesting' constructor semantics. In fact Initialize
483 @e is called from the wxDocManager constructor, but this can be
484 vetoed by passing @false to the second argument, allowing the derived class's
485 constructor to call Initialize, possibly calling a different OnCreateFileHistory
488 The bottom line: if you're not deriving from Initialize, forget it and
489 construct wxDocManager with no arguments.
494 Return a string containing a suitable default name for a new document. By
495 default this is implemented by appending an integer counter to the string
496 @b unnamed but can be overridden in the derived classes to do something more
499 wxString
MakeNewDocumentName();
502 A hook to allow a derived class to create a different type of file history.
506 wxFileHistory
* OnCreateFileHistory();
509 Closes and deletes the currently active document.
511 void OnFileClose(wxCommandEvent
& event
);
514 Closes and deletes all the currently opened documents.
516 void OnFileCloseAll(wxCommandEvent
& event
);
519 Creates a document from a list of templates (if more than one template).
521 void OnFileNew(wxCommandEvent
& event
);
524 Creates a new document and reads in the selected file.
526 void OnFileOpen(wxCommandEvent
& event
);
529 Reverts the current document by calling wxDocument::Revert for the current
532 void OnFileRevert(wxCommandEvent
& event
);
535 Saves the current document by calling wxDocument::Save for the current document.
537 void OnFileSave(wxCommandEvent
& event
);
540 Calls wxDocument::SaveAs for the current document.
542 void OnFileSaveAs(wxCommandEvent
& event
);
545 Removes the document from the list of documents.
547 void RemoveDocument(wxDocument
* doc
);
550 Under Windows, pops up a file selector with a list of filters corresponding to
552 The wxDocTemplate corresponding to the selected file's extension is returned.
554 On other platforms, if there is more than one document template a choice list
556 followed by a file selector.
558 This function is used in CreateDocument().
560 (doctemplate, path) = My::DocManager-SelectDocumentPath( ... );
562 wxDocTemplate
* SelectDocumentPath(wxDocTemplate
** templates
,
569 Returns a document template by asking the user (if there is more than one
571 This function is used in CreateDocument().
574 Pointer to an array of templates from which to choose a desired template.
577 Number of templates being pointed to by the templates pointer.
580 If more than one template is passed in in templates,
581 then this parameter indicates whether the list of templates that the user
582 will have to choose from is sorted or not when shown the choice box dialog.
585 wxDocTemplate
* SelectDocumentType(wxDocTemplate
** templates
,
590 Returns a document template by asking the user (if there is more than one
592 displaying a list of valid views. This function is used in CreateView().
593 The dialog normally will not appear because the array of templates only contains
594 those relevant to the document in question, and often there will only be one
598 Pointer to an array of templates from which to choose a desired template.
601 Number of templates being pointed to by the templates pointer.
604 If more than one template is passed in in templates,
605 then this parameter indicates whether the list of templates that the user
606 will have to choose from is sorted or not when shown the choice box dialog.
609 wxDocTemplate
* SelectViewType(wxDocTemplate
** templates
,
614 Sets the directory to be displayed to the user when opening a file. Initially
617 void SetLastDirectory(const wxString
& dir
);
620 Sets the maximum number of documents that can be open at a time. By default,
622 is 10,000. If you set it to 1, existing documents will be saved and deleted
623 when the user tries to open or create a new one (similar to the behaviour
624 of Windows Write, for example). Allowing multiple documents gives behaviour
625 more akin to MS Word and other Multiple Document Interface applications.
627 void SetMaxDocsOpen(int n
);
630 wxView* m_currentView
632 The currently active view.
637 int m_defaultDocumentNameCounter
639 Stores the integer to be used for the next default document name.
646 A list of all documents.
651 wxFileHistory* m_fileHistory
653 A pointer to an instance of wxFileHistory,
654 which manages the history of recently-visited files on the File menu.
661 Stores the flags passed to the constructor.
666 The directory last selected by the user when opening a file.
668 wxFileHistory* m_fileHistory
675 Stores the maximum number of documents that can be opened before
676 existing documents are closed. By default, this is 10,000.
685 The view class can be used to model the viewing and editing component of
686 an application's file-based data. It is part of the document/view framework
687 supported by wxWidgets,
688 and cooperates with the wxDocument, wxDocTemplate
689 and wxDocManager classes.
695 @ref overview_wxviewoverview "wxView overview", wxDocument, wxDocTemplate,
698 class wxView
: public wxEvtHandler
702 Constructor. Define your own default constructor to initialize
709 Destructor. Removes itself from the document's list of views.
714 Call this from your view frame's OnActivate member to tell the framework which
716 currently active. If your windowing system doesn't call OnActivate, you may
718 call this function from any place where you know the view must
719 be active, and the framework will need to get the current view.
721 The prepackaged view frame wxDocChildFrame calls Activate() from its OnActivate
724 This function calls OnActivateView().
726 virtual void Activate(bool activate
);
729 Closes the view by calling OnClose. If @e deleteWindow is @true, this function
731 delete the window associated with the view.
733 virtual bool Close(bool deleteWindow
= @
true);
736 Gets a pointer to the document associated with the view.
738 wxDocument
* GetDocument();
741 Returns a pointer to the document manager instance associated with this view.
743 wxDocManager
* GetDocumentManager();
746 Gets the frame associated with the view (if any). Note that this "frame'' is
747 not a wxFrame at all in the generic MDI implementation which uses the notebook
748 pages instead of the frames and this is why this method returns a wxWindow and
751 wxWindow
* GetFrame();
754 Gets the name associated with the view (passed to the wxDocTemplate
756 Not currently used by the framework.
758 wxString
GetViewName();
761 Called when a view is activated by means of Activate(). The default
765 virtual void OnActivateView(bool activate
, wxView
* activeView
,
766 wxView
* deactiveView
);
769 Called when the filename has changed. The default implementation constructs a
770 suitable title and sets the title of the view frame (if any).
772 virtual void OnChangeFilename();
775 Implements closing behaviour. The default implementation calls wxDocument::Close
776 to close the associated document. Does not delete the view. The application
777 may wish to do some cleaning up operations in this function, @e if a
778 call to wxDocument::Close succeeded. For example, if your views
779 all share the same window, you need to disassociate the window from the view
780 and perhaps clear the window. If @e deleteWindow is @true, delete the
781 frame associated with the view.
783 virtual bool OnClose(bool deleteWindow
);
786 Override this to clean up the view when the document is being
789 virtual void OnClosingDocument();
792 wxDocManager or wxDocument creates a wxView via a wxDocTemplate.
793 Just after the wxDocTemplate creates the wxView, it calls
794 OnCreate(). In its OnCreate member function, the wxView can create a
796 or a derived class. This wxDocChildFrame provides user interface
797 elements to view and/or edit the contents of the wxDocument.
799 By default, simply returns @true. If the function returns @false, the
800 view will be deleted.
802 virtual bool OnCreate(wxDocument
* doc
, long flags
);
805 If the printing framework is enabled in the library, this function returns a
806 wxPrintout object for the purposes of printing. It should create a new object
807 every time it is called; the framework will delete objects it creates.
809 By default, this function returns an instance of wxDocPrintout, which prints
810 and previews one page by calling OnDraw().
812 Override to return an instance of a class other than wxDocPrintout.
814 virtual wxPrintout
* OnCreatePrintout();
817 Override this function to render the view on the given device context.
819 virtual void OnDraw(wxDC
* dc
);
822 Called when the view should be updated. @e sender is a pointer to the view
823 that sent the update request, or @NULL if no single view requested the update
825 when the document is opened). @e hint is as yet unused but may in future contain
826 application-specific information for making updating more efficient.
828 virtual void OnUpdate(wxView
* sender
, wxObject
* hint
);
831 Associates the given document with the view. Normally called by the
834 void SetDocument(wxDocument
* doc
);
837 Sets the frame associated with this view. The application should call this
838 if possible, to tell the view about the frame.
840 See GetFrame() for the explanation about the mismatch
841 between the "Frame'' in the method name and the type of its parameter.
843 void SetFrame(wxWindow
* frame
);
846 Sets the view type name. Should only be called by the framework.
848 void SetViewName(const wxString
& name
);
851 wxDocument* m_viewDocument
853 The document associated with this view. There may be more than one view per
854 document, but there can never be more than one document for one view.
861 Frame associated with the view, if any.
866 wxString m_viewTypeName
868 The view type name given to the wxDocTemplate constructor, copied to this
869 variable when the view is created. Not currently used by the framework.
875 @class wxDocChildFrame
878 The wxDocChildFrame class provides a default frame for displaying documents
879 on separate windows. This class can only be used for SDI (not MDI) child frames.
881 The class is part of the document/view framework supported by wxWidgets,
882 and cooperates with the wxView, wxDocument,
883 wxDocManager and wxDocTemplate classes.
885 See the example application in @c samples/docview.
891 @ref overview_docviewoverview "Document/view overview", wxFrame
893 class wxDocChildFrame
: public wxFrame
899 wxDocChildFrame(wxDocument
* doc
, wxView
* view
, wxFrame
* parent
,
901 const wxString
& title
,
902 const wxPoint
& pos
= wxDefaultPosition
,
903 const wxSize
& size
= wxDefaultSize
,
904 long style
= wxDEFAULT_FRAME_STYLE
,
905 const wxString
& name
= "frame");
913 Returns the document associated with this frame.
915 wxDocument
* GetDocument();
918 Returns the view associated with this frame.
923 Sets the currently active view to be the frame's view. You may need
924 to override (but still call) this function in order to set the keyboard
925 focus for your subwindow.
927 void OnActivate(wxActivateEvent event
);
930 Closes and deletes the current view and document.
932 void OnCloseWindow(wxCloseEvent
& event
);
935 Sets the document for this frame.
937 void SetDocument(wxDocument
* doc
);
940 Sets the view for this frame.
942 void SetView(wxView
* view
);
945 wxDocument* m_childDocument
947 The document associated with the frame.
954 The view associated with the frame.
960 @class wxDocParentFrame
963 The wxDocParentFrame class provides a default top-level frame for
964 applications using the document/view framework. This class can only be used for
965 SDI (not MDI) parent frames.
967 It cooperates with the wxView, wxDocument,
968 wxDocManager and wxDocTemplates classes.
970 See the example application in @c samples/docview.
976 @ref overview_docviewoverview "Document/view overview", wxFrame
978 class wxDocParentFrame
: public wxFrame
986 wxDocParentFrame(wxDocManager
* manager
, wxFrame
* parent
,
988 const wxString
& title
,
989 const wxPoint
& pos
= wxDefaultPosition
,
990 const wxSize
& size
= wxDefaultSize
,
991 long style
= wxDEFAULT_FRAME_STYLE
,
992 const wxString
& name
= "frame");
1001 Used in two-step construction.
1003 bool Create(wxDocManager
* manager
, wxFrame
* parent
,
1004 wxWindowID id
, const wxString
& title
,
1005 const wxPoint
& pos
= wxDefaultPosition
,
1006 const wxSize
& size
= wxDefaultSize
,
1007 long style
= wxDEFAULT_FRAME_STYLE
,
1008 const wxString
& name
= "frame");
1011 Returns the associated @ref overview_wxdocmanager "document manager object".
1013 wxDocManager
* GetDocumentManager();
1016 Deletes all views and documents. If no user input cancelled the
1017 operation, the frame will be destroyed and the application will exit.
1019 Since understanding how document/view clean-up takes place can be difficult,
1020 the implementation of this function is shown below.
1022 void OnCloseWindow(wxCloseEvent
& event
);
1028 @wxheader{docview.h}
1030 The document class can be used to model an application's file-based
1031 data. It is part of the document/view framework supported by wxWidgets,
1032 and cooperates with the wxView, wxDocTemplate
1033 and wxDocManager classes.
1039 @ref overview_wxdocumentoverview "wxDocument overview", wxView, wxDocTemplate,
1042 class wxDocument
: public wxEvtHandler
1046 Constructor. Define your own default constructor to initialize
1047 application-specific
1053 Destructor. Removes itself from the document manager.
1058 If the view is not already in the list of views, adds the view and calls
1061 virtual bool AddView(wxView
* view
);
1064 Closes the document, by calling OnSaveModified and then (if this returned @true)
1066 This does not normally delete the document object: use DeleteAllViews to do
1069 virtual bool Close();
1072 Calls wxView::Close and deletes each view. Deleting the final view will
1074 delete the document itself, because the wxView destructor calls RemoveView. This
1075 in turns calls OnChangedViewList(), whose default implemention is to
1076 save and delete the document if no views exist.
1078 virtual bool DeleteAllViews();
1081 Returns a pointer to the command processor associated with this document.
1083 See wxCommandProcessor.
1085 wxCommandProcessor
* GetCommandProcessor();
1088 Gets a pointer to the associated document manager.
1090 wxDocManager
* GetDocumentManager();
1093 Gets the document type name for this document. See the comment for
1096 wxString
GetDocumentName();
1099 Gets a pointer to the template that created the document.
1101 wxDocTemplate
* GetDocumentTemplate();
1104 Intended to return a suitable window for using as a parent for document-related
1105 dialog boxes. By default, uses the frame associated with the first view.
1107 wxWindow
* GetDocumentWindow();
1110 Gets the filename associated with this document, or "" if none is
1113 wxString
GetFilename();
1116 A convenience function to get the first view for a document, because
1117 in many cases a document will only have a single view.
1119 See also: GetViews()
1121 wxView
* GetFirstView();
1124 Gets the title for this document. The document title is used for an associated
1125 frame (if any), and is usually constructed by the framework from
1128 wxString
GetTitle();
1131 Return the document name suitable to be shown to the user. The default
1132 implementation uses the document title, if any, of the name part of the
1133 document filename if it was set or, otherwise, the string @b unnamed.
1135 virtual wxString
GetUserReadableName();
1138 Returns the list whose elements are the views on the document.
1140 See also: GetFirstView()
1145 Returns @true if the document has been modified since the last save, @false
1147 You may need to override this if your document view maintains its own
1148 record of being modified (for example if using wxTextWindow to view and edit
1153 virtual bool IsModified();
1157 Override this function and call it from your own LoadObject before
1158 streaming your own data. LoadObject is called by the framework
1159 automatically when the document contents need to be loaded.
1161 Note that only one of these forms exists, depending on how wxWidgets
1164 virtual istream
LoadObject(istream
& stream
);
1165 virtual wxInputStream
LoadObject(wxInputStream
& stream
);
1169 Call with @true to mark the document as modified since the last save, @false
1171 You may need to override this if your document view maintains its own
1172 record of being modified (for example if using wxTextWindow to view and edit
1175 See also IsModified().
1177 virtual void Modify(bool modify
);
1180 Called when a view is added to or deleted from this document. The default
1181 implementation saves and deletes the document if no views exist (the last
1182 one has just been removed).
1184 virtual void OnChangedViewList();
1187 The default implementation calls DeleteContents (an empty implementation)
1188 sets the modified flag to @false. Override this to
1189 supply additional behaviour when the document is closed with Close.
1191 virtual bool OnCloseDocument();
1194 Called just after the document object is created to give it a chance
1195 to initialize itself. The default implementation uses the
1196 template associated with the document to create an initial view.
1197 If this function returns @false, the document is deleted.
1199 virtual bool OnCreate(const wxString
& path
, long flags
);
1202 Override this function if you want a different (or no) command processor
1203 to be created when the document is created. By default, it returns
1204 an instance of wxCommandProcessor.
1206 See wxCommandProcessor.
1208 virtual wxCommandProcessor
* OnCreateCommandProcessor();
1211 The default implementation calls OnSaveModified and DeleteContents, makes a
1212 default title for the
1213 document, and notifies the views that the filename (in fact, the title) has
1216 virtual bool OnNewDocument();
1219 Constructs an input file stream for the given filename (which must not be
1221 and calls LoadObject. If LoadObject returns @true, the document is set to
1222 unmodified; otherwise, an error message box is displayed. The document's
1223 views are notified that the filename has changed, to give windows an opportunity
1224 to update their titles. All of the document's views are then updated.
1226 virtual bool OnOpenDocument(const wxString
& filename
);
1229 Constructs an output file stream for the given filename (which must not be
1231 and calls SaveObject. If SaveObject returns @true, the document is set to
1232 unmodified; otherwise, an error message box is displayed.
1234 virtual bool OnSaveDocument(const wxString
& filename
);
1237 If the document has been modified, prompts the user to ask if the changes should
1238 be changed. If the user replies Yes, the Save function is called. If No, the
1239 document is marked as unmodified and the function succeeds. If Cancel, the
1242 virtual bool OnSaveModified();
1245 Removes the view from the document's list of views, and calls OnChangedViewList.
1247 virtual bool RemoveView(wxView
* view
);
1250 Saves the document by calling OnSaveDocument if there is an associated filename,
1251 or SaveAs if there is no filename.
1253 virtual bool Save();
1256 Prompts the user for a file to save to, and then calls OnSaveDocument.
1258 virtual bool SaveAs();
1262 Override this function and call it from your own SaveObject before
1263 streaming your own data. SaveObject is called by the framework
1264 automatically when the document contents need to be saved.
1266 Note that only one of these forms exists, depending on how wxWidgets
1269 virtual ostream
SaveObject(ostream
& stream
);
1270 virtual wxOutputStream
SaveObject(wxOutputStream
& stream
);
1274 Sets the command processor to be used for this document. The document will then
1276 for its deletion. Normally you should not call this; override
1277 OnCreateCommandProcessor
1280 See wxCommandProcessor.
1282 virtual void SetCommandProcessor(wxCommandProcessor
* processor
);
1285 Sets the document type name for this document. See the comment for
1288 void SetDocumentName(const wxString
& name
);
1291 Sets the pointer to the template that created the document. Should only be
1295 void SetDocumentTemplate(wxDocTemplate
* templ
);
1298 Sets the filename for this document. Usually called by the framework.
1300 If @e notifyViews is @true, wxView::OnChangeFilename is called for all views.
1302 void SetFilename(const wxString
& filename
,
1303 bool notifyViews
= @
false);
1306 Sets the title for this document. The document title is used for an associated
1307 frame (if any), and is usually constructed by the framework from
1310 void SetTitle(const wxString
& title
);
1313 Updates all views. If @e sender is non-@NULL, does not update this view.
1315 @e hint represents optional information to allow a view to optimize its update.
1317 void UpdateAllViews(wxView
* sender
= @NULL
, wxObject
* hint
= @NULL
);
1320 wxCommandProcessor* m_commandProcessor
1322 A pointer to the command processor associated with this document.
1327 wxString m_documentFile
1329 Filename associated with this document ("" if none).
1334 bool m_documentModified
1336 @true if the document has been modified, @false otherwise.
1341 wxDocTemplate * m_documentTemplate
1343 A pointer to the template from which this document was created.
1348 wxString m_documentTitle
1350 Document title. The document title is used for an associated
1351 frame (if any), and is usually constructed by the framework from
1357 wxString m_documentTypeName
1359 The document type name given to the wxDocTemplate constructor, copied to this
1360 variable when the document is created. If several document templates are
1361 created that use the same document type, this variable is used in
1362 wxDocManager::CreateView
1363 to collate a list of alternative view types that can be used on this kind of
1364 document. Do not change the value of this variable.
1369 wxList m_documentViews
1371 List of wxView instances associated with this document.
1377 @class wxFileHistory
1378 @wxheader{docview.h}
1380 The wxFileHistory encapsulates a user interface convenience, the
1381 list of most recently visited files as shown on a menu (usually the File menu).
1383 wxFileHistory can manage one or more file menus. More than one menu may be
1385 in an MDI application, where the file history should appear on each MDI child
1387 as well as the MDI parent frame.
1393 @ref overview_wxfilehistoryoverview "wxFileHistory overview", wxDocManager
1395 class wxFileHistory
: public wxObject
1399 Constructor. Pass the maximum number of files that should be stored and
1402 @e idBase defaults to wxID_FILE1 and represents the id given to the first
1403 history menu item. Since menu items can't share the same ID you should change
1404 idBase (To one of your own defined IDs) when using more than one wxFileHistory
1405 in your application.
1407 wxFileHistory(size_t maxFiles
= 9,
1408 wxWindowID idBase
= wxID_FILE1
);
1416 Adds a file to the file history list, if the object has a pointer to an
1417 appropriate file menu.
1419 void AddFileToHistory(const wxString
& filename
);
1423 Appends the files in the history list, to the given menu only.
1425 void AddFilesToMenu();
1426 void AddFilesToMenu(wxMenu
* menu
);
1430 Returns the base identifier for the range used for appending items.
1432 wxWindowID
GetBaseId();
1435 Returns the number of files currently stored in the file history.
1440 Returns the file at this index (zero-based).
1442 wxString
GetHistoryFile(size_t index
);
1445 Returns the maximum number of files that can be stored.
1450 Returns the list of menus that are managed by this file history object.
1454 const wxList
GetMenus();
1457 Loads the file history from the given config object. This function should be
1458 called explicitly by the application.
1462 void Load(wxConfigBase
& config
);
1465 Removes the specified file from the history.
1467 void RemoveFileFromHistory(size_t i
);
1470 Removes this menu from the list of those managed by this object.
1472 void RemoveMenu(wxMenu
* menu
);
1475 Saves the file history into the given config object. This must be called
1476 explicitly by the application.
1480 void Save(wxConfigBase
& config
);
1483 Sets the base identifier for the range used for appending items.
1485 void SetBaseId(wxWindowID baseId
);
1488 Adds this menu to the list of those menus that are managed by this file history
1490 Also see AddFilesToMenu() for
1491 initializing the menu with filenames that are already in the history when this
1492 function is called, as this is not done automatically.
1494 void UseMenu(wxMenu
* menu
);
1497 char** m_fileHistory
1499 A character array of strings corresponding to the most recently opened
1505 size_t m_fileHistoryN
1507 The number of files stored in the history array.
1512 size_t m_fileMaxFiles
1514 The maximum number of files to be stored and displayed on the menu.
1521 The file menu used to display the file history list (if enabled).
1526 // ============================================================================
1527 // Global functions/macros
1528 // ============================================================================
1531 Copies the given file to @e stream. Useful when converting an old application to
1532 use streams (within the document/view framework, for example).
1534 bool wxTransferFileToStream(const wxString
& filename
,