## wxDocManager

The wxDocManager class is part of the document/view framework supported by wxWidgets, and cooperates with the wxView, wxDocument and wxDocTemplate classes.

Derived from

wxEvtHandler
wxObject

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::MakeNewDocumentName
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

### wxDocManager::m_currentView

wxView* m_currentView

The currently active view.

### wxDocManager::m_defaultDocumentNameCounter

int m_defaultDocumentNameCounter

Stores the integer to be used for the next default document name.

### wxDocManager::m_fileHistory

wxFileHistory* m_fileHistory

A pointer to an instance of wxFileHistory, which manages the history of recently-visited files on the File menu.

### wxDocManager::m_maxDocsOpen

int m_maxDocsOpen

Stores the maximum number of documents that can be opened before existing documents are closed. By default, this is 10,000.

### wxDocManager::m_docs

wxList m_docs

A list of all documents.

### wxDocManager::m_flags

long m_flags

Stores the flags passed to the constructor.

### wxDocManager::m_lastDirectory

The directory last selected by the user when opening a file.

wxFileHistory* m_fileHistory

### wxDocManager::m_templates

wxList m_templates

A list of all document templates.

### wxDocManager::wxDocManager

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.

### wxDocManager::~wxDocManager

void ~wxDocManager()

Destructor.

### wxDocManager::ActivateView

void ActivateView(wxView* doc, bool activate = true)

Sets the current view.

### wxDocManager::AddDocument

void AddDocument(wxDocument *doc)

Adds the document to the list of documents.

### wxDocManager::AddFileToHistory

void AddFileToHistory(const wxString& filename)

Adds a file to the file history list, if we have a pointer to an appropriate file menu.

### wxDocManager::AssociateTemplate

void AssociateTemplate(wxDocTemplate *temp)

Adds the template to the document manager's template list.

### wxDocManager::CloseDocuments

bool CloseDocuments(bool force = true)

Closes all currently opened documents.

### wxDocManager::CreateDocument

wxDocument* CreateDocument(const wxString& path, long flags)

Creates a new document in a manner determined by the flags parameter, which can be:

- wxDOC_NEW Creates a fresh document.
- wxDOC_SILENT Silently loads the given document file.

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.

### wxDocManager::CreateView

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.

### wxDocManager::DisassociateTemplate

void DisassociateTemplate(wxDocTemplate *temp)

Removes the template from the list of templates.

### wxDocManager::FileHistoryAddFilesToMenu

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.

### wxDocManager::FileHistoryLoad

void FileHistoryLoad(wxConfigBase& config)

Loads the file history from a config object.

See also

wxConfig

### wxDocManager::FileHistoryRemoveMenu

void FileHistoryRemoveMenu(wxMenu* menu)

Removes the given menu from the list of menus managed by the file history object.

### wxDocManager::FileHistorySave

void FileHistorySave(wxConfigBase& resourceFile)

Saves the file history into a config object. This must be called explicitly by the application.

See also

wxConfig

### wxDocManager::FileHistoryUseMenu

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.

### wxDocManager::FindTemplateForPath

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.

### wxDocManager::GetCurrentDocument

wxDocument * GetCurrentDocument()

Returns the document associated with the currently active view (if any).

### wxDocManager::GetCurrentView

wxView * GetCurrentView()

Returns the currently active view

### wxDocManager::GetDocuments

wxList& GetDocuments()

Returns a reference to the list of documents.

### wxDocManager::GetFileHistory

wxFileHistory * GetFileHistory()

Returns a pointer to file history.

### wxDocManager::GetLastDirectory

wxString GetLastDirectory() const

Returns the directory last selected by the user when opening a file. Initially empty.

### wxDocManager::GetMaxDocsOpen

int GetMaxDocsOpen()

Returns the number of documents that can be open simultaneously.

### wxDocManager::GetHistoryFilesCount

size_t GetHistoryFilesCount()

Returns the number of files currently stored in the file history.

### wxDocManager::GetTemplates

wxList& GetTemplates()

Returns a reference to the list of associated templates.

### wxDocManager::Initialize

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.

### wxDocManager::MakeDefaultName

bool MakeDefaultName(const wxString& buf)

This method is preserved for backwards compatibility in wxWidgets 2.8 but is renamed to MakeNewDocumentName in wxWidgets 3.0, please see its description for the details.

This function simply copies the value returned by MakeNewDocumentName() into the provided buf and returns `true`.

wxPerl note: In wxPerl this function must return the modified name rather than just modifying the argument.

### wxDocManager::MakeNewDocumentName

wxString MakeNewDocumentName()

Returns the name to be used for a new document. The default implementation appends an integer counter to the string unnamed and increments the counter. To customize this behaviour, you need to override the virtual MakeNewDocumentName method but if you only need to call this method, an not to override it, please use this method which is forward-compatible with wxWidgets 3.0.

This function is new since wxWidgets version 2.8.8

### wxDocManager::OnCreateFileHistory

wxFileHistory * OnCreateFileHistory()

A hook to allow a derived class to create a different type of file history. Called from Initialize.

### wxDocManager::OnFileClose

void OnFileClose(wxCommandEvent& event)

Closes and deletes the currently active document.

### wxDocManager::OnFileCloseAll

void OnFileCloseAll(wxCommandEvent& event)

Closes and deletes all the currently opened documents.

### wxDocManager::OnFileNew

void OnFileNew(wxCommandEvent& event)

Creates a document from a list of templates (if more than one template).

### wxDocManager::OnFileOpen

void OnFileOpen(wxCommandEvent& event)

Creates a new document and reads in the selected file.

### wxDocManager::OnFileRevert

void OnFileRevert(wxCommandEvent& event)

Reverts the current document by calling wxDocument::Revert for the current document.

### wxDocManager::OnFileSave

void OnFileSave(wxCommandEvent& event)

Saves the current document by calling wxDocument::Save for the current document.

### wxDocManager::OnFileSaveAs

void OnFileSaveAs(wxCommandEvent& event)

Calls wxDocument::SaveAs for the current document.

### wxDocManager::RemoveDocument

void RemoveDocument(wxDocument *doc)

Removes the document from the list of documents.

### wxDocManager::SelectDocumentPath

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( ... );

### wxDocManager::SelectDocumentType

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

Pointer to an array of templates from which to choose a desired template.

noTemplates

Number of templates being pointed to by the templates pointer.

sort

If more than one template is passed in in templates, then this parameter indicates whether the list of templates that the user will have to choose from is sorted or not when shown the choice box dialog. Default is false.

wxPerl note: In wxPerl `templates` is a reference to a list of templates.

### wxDocManager::SelectViewType

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

Pointer to an array of templates from which to choose a desired template.

noTemplates

Number of templates being pointed to by the templates pointer.

sort

If more than one template is passed in in templates, then this parameter indicates whether the list of templates that the user will have to choose from is sorted or not when shown the choice box dialog. Default is false.

wxPerl note: In wxPerl `templates` is a reference to a list of templates.

### wxDocManager::SetLastDirectory

void SetLastDirectory(const wxString& dir)

Sets the directory to be displayed to the user when opening a file. Initially this is empty.

### wxDocManager::SetMaxDocsOpen

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.