## wxDocManager

The wxDocManager class is part of the document/view framework supported by wxWindows, 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::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::GetNoHistoryFiles
wxDocManager::Initialize
wxDocManager::MakeDefaultName
wxDocManager::OnCreateFileHistory
wxDocManager::OnFileClose
wxDocManager::OnFileNew
wxDocManager::OnFileOpen
wxDocManager::OnFileSave
wxDocManager::OnFileSaveAs
wxDocManager::OnMenuCommand
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 mnTemplates

A list of all document templates.

### wxDocManager::wxDocManager

void 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, bool deleting)

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

int GetNoHistoryFiles()

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

### 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)

Copies a suitable default name into buf. This is implemented by appending an integer counter to the string unnamed and incrementing the counter.

### 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()

Closes and deletes the currently active document.

### wxDocManager::OnFileNew

void OnFileNew()

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

### wxDocManager::OnFileOpen

void OnFileOpen()

Creates a new document and reads in the selected file.

### wxDocManager::OnFileSave

void OnFileSave()

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

### wxDocManager::OnFileSaveAs

void OnFileSaveAs()

Calls wxDocument::SaveAs for the current document.

### wxDocManager::OnMenuCommand

void OnMenuCommand(int cmd)

Processes menu commands routed from child or parent frames. This deals with the following predefined menu item identifiers:

- wxID_OPEN Creates a new document and opens a file into it.
- wxID_CLOSE Closes the current document.
- wxID_NEW Creates a new document.
- wxID_SAVE Saves the document.
- wxID_SAVE_AS Saves the document into a specified filename.

Unrecognized commands are routed to the currently active wxView's OnMenuCommand.

### wxDocManager::RemoveDocument

void RemoveDocument(wxDocument *doc)

Removes the document from the list of documents.

### wxDocManager::SelectDocumentPath

wxDocTemplate * SelectDocumentPath(wxDocTemplate **templates, int noTemplates, const wxString& path, const wxString& bufSize, 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.

### wxDocManager::SelectDocumentType

wxDocTemplate * SelectDocumentType(wxDocTemplate **templates, int noTemplates)

Returns a document template by asking the user (if there is more than one template). This function is used in wxDocManager::CreateDocument.

### wxDocManager::SelectViewType

wxDocTemplate * SelectViewType(wxDocTemplate **templates, int noTemplates)

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 won't appear because the array of templates only contains those relevant to the document in question, and often there will only be one such.

### 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.