The wxDocManager class is part of the document/view framework supported by wxWidgets, and cooperates with the wxView, wxDocument and wxDocTemplate classes.
Derived from
Include files
<wx/docview.h>
See also
wxDocManager overview, wxDocument, wxView, wxDocTemplate, wxFileHistory
Members
wxDocManager::m_currentView
wxDocManager::m_defaultDocumentNameCounter
wxDocManager::m_fileHistory
wxDocManager::m_maxDocsOpen
wxDocManager::m_docs
wxDocManager::m_flags
wxDocManager::m_lastDirectory
wxDocManager::m_templates
wxDocManager::wxDocManager
wxDocManager::~wxDocManager
wxDocManager::ActivateView
wxDocManager::AddDocument
wxDocManager::AddFileToHistory
wxDocManager::AssociateTemplate
wxDocManager::CloseDocuments
wxDocManager::CreateDocument
wxDocManager::CreateView
wxDocManager::DisassociateTemplate
wxDocManager::FileHistoryAddFilesToMenu
wxDocManager::FileHistoryLoad
wxDocManager::FileHistoryRemoveMenu
wxDocManager::FileHistorySave
wxDocManager::FileHistoryUseMenu
wxDocManager::FindTemplateForPath
wxDocManager::GetCurrentDocument
wxDocManager::GetCurrentView
wxDocManager::GetDocuments
wxDocManager::GetFileHistory
wxDocManager::GetLastDirectory
wxDocManager::GetMaxDocsOpen
wxDocManager::GetHistoryFilesCount
wxDocManager::GetTemplates
wxDocManager::Initialize
wxDocManager::MakeDefaultName
wxDocManager::OnCreateFileHistory
wxDocManager::OnFileClose
wxDocManager::OnFileCloseAll
wxDocManager::OnFileNew
wxDocManager::OnFileOpen
wxDocManager::OnFileRevert
wxDocManager::OnFileSave
wxDocManager::OnFileSaveAs
wxDocManager::RemoveDocument
wxDocManager::SelectDocumentPath
wxDocManager::SelectDocumentType
wxDocManager::SelectViewType
wxDocManager::SetLastDirectory
wxDocManager::SetMaxDocsOpen
wxView* m_currentView
The currently active view.
int m_defaultDocumentNameCounter
Stores the integer to be used for the next default document name.
wxFileHistory* m_fileHistory
A pointer to an instance of wxFileHistory, which manages the history of recently-visited files on the File menu.
int m_maxDocsOpen
Stores the maximum number of documents that can be opened before existing documents are closed. By default, this is 10,000.
wxList m_docs
A list of all documents.
long m_flags
Stores the flags passed to the constructor.
The directory last selected by the user when opening a file.
wxFileHistory* m_fileHistory
wxList m_templates
A list of all document templates.
wxDocManager(long flags = wxDEFAULT_DOCMAN_FLAGS, bool initialize = true)
Constructor. Create a document manager instance dynamically near the start of your application before doing any document or view operations.
flags is currently unused.
If initialize is true, the Initialize function will be called to create a default history list object. If you derive from wxDocManager, you may wish to call the base constructor with false, and then call Initialize in your own constructor, to allow your own Initialize or OnCreateFileHistory functions to be called.
void ~wxDocManager()
Destructor.
void ActivateView(wxView* doc, bool activate = true)
Sets the current view.
void AddDocument(wxDocument *doc)
Adds the document to the list of documents.
void AddFileToHistory(const wxString& filename)
Adds a file to the file history list, if we have a pointer to an appropriate file menu.
void AssociateTemplate(wxDocTemplate *temp)
Adds the template to the document manager's template list.
bool CloseDocuments(bool force = true)
Closes all currently opened documents.
wxDocument* CreateDocument(const wxString& path, long flags)
Creates a new document in a manner determined by the flags parameter, which can be:
If wxDOC_NEW is present, a new document will be created and returned, possibly after asking the user for a template to use if there is more than one document template. If wxDOC_SILENT is present, a new document will be created and the given file loaded into it. If neither of these flags is present, the user will be presented with a file selector for the file to load, and the template to use will be determined by the extension (Windows) or by popping up a template choice list (other platforms).
If the maximum number of documents has been reached, this function will delete the oldest currently loaded document before creating a new one.
wxView* CreateView(wxDocument*doc, long flags)
Creates a new view for the given document. If more than one view is allowed for the document (by virtue of multiple templates mentioning the same document type), a choice of view is presented to the user.
void DisassociateTemplate(wxDocTemplate *temp)
Removes the template from the list of templates.
void FileHistoryAddFilesToMenu()
Appends the files in the history list, to all menus managed by the file history object.
void FileHistoryAddFilesToMenu(wxMenu* menu)
Appends the files in the history list, to the given menu only.
void FileHistoryLoad(wxConfigBase& config)
Loads the file history from a config object.
See also
void FileHistoryRemoveMenu(wxMenu* menu)
Removes the given menu from the list of menus managed by the file history object.
void FileHistorySave(wxConfigBase& resourceFile)
Saves the file history into a config object. This must be called explicitly by the application.
See also
void FileHistoryUseMenu(wxMenu* menu)
Use this menu for appending recently-visited document filenames, for convenient access. Calling this function with a valid menu pointer enables the history list functionality.
Note that you can add multiple menus using this function, to be managed by the file history object.
wxDocTemplate * FindTemplateForPath(const wxString& path)
Given a path, try to find template that matches the extension. This is only an approximate method of finding a template for creating a document.
wxDocument * GetCurrentDocument()
Returns the document associated with the currently active view (if any).
wxView * GetCurrentView()
Returns the currently active view
wxList& GetDocuments()
Returns a reference to the list of documents.
wxFileHistory * GetFileHistory()
Returns a pointer to file history.
wxString GetLastDirectory() const
Returns the directory last selected by the user when opening a file. Initially empty.
int GetMaxDocsOpen()
Returns the number of documents that can be open simultaneously.
size_t GetHistoryFilesCount()
Returns the number of files currently stored in the file history.
wxList& GetTemplates()
Returns a reference to the list of associated templates.
bool Initialize()
Initializes data; currently just calls OnCreateFileHistory. Some data cannot always be initialized in the constructor because the programmer must be given the opportunity to override functionality. If OnCreateFileHistory was called from the constructor, an overridden virtual OnCreateFileHistory would not be called due to C++'s 'interesting' constructor semantics. In fact Initialize is called from the wxDocManager constructor, but this can be vetoed by passing false to the second argument, allowing the derived class's constructor to call Initialize, possibly calling a different OnCreateFileHistory from the default.
The bottom line: if you're not deriving from Initialize, forget it and construct wxDocManager with no arguments.
bool MakeDefaultName(const wxString& buf)
Copies a suitable default name into buf. This is implemented by appending an integer counter to the string unnamed and incrementing the counter.
wxPerl note: In wxPerl this function must return the modified name rather than just modifying the argument.
wxFileHistory * OnCreateFileHistory()
A hook to allow a derived class to create a different type of file history. Called from Initialize.
void OnFileClose(wxCommandEvent& event)
Closes and deletes the currently active document.
void OnFileCloseAll(wxCommandEvent& event)
Closes and deletes all the currently opened documents.
void OnFileNew(wxCommandEvent& event)
Creates a document from a list of templates (if more than one template).
void OnFileOpen(wxCommandEvent& event)
Creates a new document and reads in the selected file.
void OnFileRevert(wxCommandEvent& event)
Reverts the current document by calling wxDocument::Revert for the current document.
void OnFileSave(wxCommandEvent& event)
Saves the current document by calling wxDocument::Save for the current document.
void OnFileSaveAs(wxCommandEvent& event)
Calls wxDocument::SaveAs for the current document.
void RemoveDocument(wxDocument *doc)
Removes the document from the list of documents.
wxDocTemplate * SelectDocumentPath(wxDocTemplate **templates, int noTemplates, wxString& path, long flags, bool save)
Under Windows, pops up a file selector with a list of filters corresponding to document templates. The wxDocTemplate corresponding to the selected file's extension is returned.
On other platforms, if there is more than one document template a choice list is popped up, followed by a file selector.
This function is used in wxDocManager::CreateDocument.
wxPerl note: In wxPerl templates is a reference to a list of templates. If you override this method in your document manager it must return two values, eg:
(doctemplate, path) = My::DocManager->SelectDocumentPath( ... );
wxDocTemplate * SelectDocumentType(wxDocTemplate **templates, int noTemplates, bool sort=false)
Returns a document template by asking the user (if there is more than one template). This function is used in wxDocManager::CreateDocument.
Parameters
templates
wxPerl note: In wxPerl templates is a reference to a list of templates.
wxDocTemplate * SelectViewType(wxDocTemplate **templates, int noTemplates, bool sort=false)
Returns a document template by asking the user (if there is more than one template), displaying a list of valid views. This function is used in wxDocManager::CreateView. The dialog normally will not appear because the array of templates only contains those relevant to the document in question, and often there will only be one such.
Parameters
templates
wxPerl note: In wxPerl templates is a reference to a list of templates.
void SetLastDirectory(const wxString& dir)
Sets the directory to be displayed to the user when opening a file. Initially this is empty.
void SetMaxDocsOpen(int n)
Sets the maximum number of documents that can be open at a time. By default, this is 10,000. If you set it to 1, existing documents will be saved and deleted when the user tries to open or create a new one (similar to the behaviour of Windows Write, for example). Allowing multiple documents gives behaviour more akin to MS Word and other Multiple Document Interface applications.