| Version: 3.2.5

Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
wxDocManager Class Reference
Class List by Category » Document/View Framework

`#include <wx/docview.h>`

Inheritance diagram for wxDocManager:
[legend]

## Detailed Description

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

##

Library: wxCore
Category: Document/View Framework

See also
  wxDocManager Overview, wxDocument, wxView, wxDocTemplate, wxFileHistory

## Public Member Functions

| wxDocManager (long flags=0, bool initialize=true)
| Constructor. More...
virtual | ~wxDocManager ()
| Destructor. More...
virtual void | ActivateView (wxView *doc, bool activate=true)
| Sets the current view. More...
void | AddDocument (wxDocument *doc)
| Adds the document to the list of documents. More...
virtual void | AddFileToHistory (const wxString &filename)
| Adds a file to the file history list, if we have a pointer to an appropriate file menu. More...
void | AssociateTemplate (wxDocTemplate *temp)
| Adds the template to the document manager's template list. More...
wxDocTemplate * | FindTemplate (const wxClassInfo *classinfo)
| Search for a particular document template. More...
wxDocument * | FindDocumentByPath (const wxString &path) const
| Search for the document corresponding to the given file. More...
bool | CloseDocument (wxDocument *doc, bool force=false)
| Closes the specified document. More...
bool | CloseDocuments (bool force=true)
| Closes all currently opened documents. More...
virtual wxDocument * | CreateDocument (const wxString &path, long flags=0)
| Creates a new document. More...
wxDocument * | CreateNewDocument ()
| Creates an empty new document. More...
virtual wxView * | CreateView (wxDocument *doc, long flags=0)
| Creates a new view for the given document. More...
void | DisassociateTemplate (wxDocTemplate *temp)
| Removes the template from the list of templates. More...
virtual void | FileHistoryAddFilesToMenu ()
| Appends the files in the history list to all menus managed by the file history object. More...
virtual void | FileHistoryAddFilesToMenu (wxMenu *menu)
| Appends the files in the history list to the given menu only. More...
virtual void | FileHistoryLoad (const wxConfigBase &config)
| Loads the file history from a config object. More...
virtual void | FileHistoryRemoveMenu (wxMenu *menu)
| Removes the given menu from the list of menus managed by the file history object. More...
virtual void | FileHistorySave (wxConfigBase &resourceFile)
| Saves the file history into a config object. More...
virtual void | FileHistoryUseMenu (wxMenu *menu)
| Use this menu for appending recently-visited document filenames, for convenient access. More...
virtual wxDocTemplate * | FindTemplateForPath (const wxString &path)
| Given a path, try to find template that matches the extension. More...
wxView * | GetAnyUsableView () const
| Returns the view to apply a user command to. More...
wxDocument * | GetCurrentDocument () const
| Returns the document associated with the currently active view (if any). More...
virtual wxView * | GetCurrentView () const
| Returns the currently active view. More...
wxDocVector | GetDocumentsVector () const
| Returns a vector of wxDocument pointers. More...
wxDocTemplateVector | GetTemplatesVector () const
| Returns a vector of wxDocTemplate pointers. More...
wxList & | GetDocuments ()
| Returns a reference to the list of documents. More...
virtual wxFileHistory * | GetFileHistory () const
| Returns a pointer to file history. More...
virtual size_t | GetHistoryFilesCount () const
| Returns the number of files currently stored in the file history. More...
wxString | GetLastDirectory () const
| Returns the directory last selected by the user when opening a file. More...
int | GetMaxDocsOpen () const
| Returns the number of documents that can be open simultaneously. More...
wxList & | GetTemplates ()
| Returns a reference to the list of associated templates. More...
virtual bool | Initialize ()
| Initializes data; currently just calls OnCreateFileHistory(). More...
virtual wxString | MakeNewDocumentName ()
| Return a string containing a suitable default name for a new document. More...
virtual wxFileHistory * | OnCreateFileHistory ()
| A hook to allow a derived class to create a different type of file history. More...
void | OnFileClose (wxCommandEvent &event)
| Closes and deletes the currently active document. More...
void | OnFileCloseAll (wxCommandEvent &event)
| Closes and deletes all the currently opened documents. More...
void | OnFileNew (wxCommandEvent &event)
| Creates a document from a list of templates (if more than one template). More...
void | OnFileOpen (wxCommandEvent &event)
| Creates a new document and reads in the selected file. More...
void | OnFileRevert (wxCommandEvent &event)
| Reverts the current document by calling wxDocument::Revert() for the current document. More...
void | OnFileSave (wxCommandEvent &event)
| Saves the current document by calling wxDocument::Save() for the current document. More...
void | OnFileSaveAs (wxCommandEvent &event)
| Calls wxDocument::SaveAs() for the current document. More...
void | RemoveDocument (wxDocument *doc)
| Removes the document from the list of documents. More...
virtual wxDocTemplate * | SelectDocumentPath (wxDocTemplate **templates, int noTemplates, wxString &path, long flags, bool save=false)
| Under Windows, pops up a file selector with a list of filters corresponding to document templates. More...
virtual wxDocTemplate * | SelectDocumentType (wxDocTemplate **templates, int noTemplates, bool sort=false)
| Returns a document template by asking the user (if there is more than one template). More...
virtual 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. More...
void | SetLastDirectory (const wxString &dir)
| Sets the directory to be displayed to the user when opening a file. More...
void | SetMaxDocsOpen (int n)
| Sets the maximum number of documents that can be open at a time. More...
Public Member Functions inherited from wxEvtHandler
| wxEvtHandler ()
| Constructor. More...
virtual | ~wxEvtHandler ()
| Destructor. More...
virtual void | QueueEvent (wxEvent *event)
| Queue event for a later processing. More...
virtual void | AddPendingEvent (const wxEvent &event)
| Post an event to be processed later. More...
template<typename T , typename T1 , ... >
void | CallAfter (void(T::*method)(T1,...), T1 x1,...)
| Asynchronously call the given method. More...
template<typename T >
void | CallAfter (const T &functor)
| Asynchronously call the given functor. More...
virtual bool | ProcessEvent (wxEvent &event)
| Processes an event, searching event tables and calling zero or more suitable event handler function(s). More...
bool | ProcessEventLocally (wxEvent &event)
| Try to process the event in this handler and all those chained to it. More...
bool | SafelyProcessEvent (wxEvent &event)
| Processes an event by calling ProcessEvent() and handles any exceptions that occur in the process. More...
void | ProcessPendingEvents ()
| Processes the pending events previously queued using QueueEvent() or AddPendingEvent(); you must call this function only if you are sure there are pending events for this handler, otherwise a `wxCHECK` will fail. More...
void | DeletePendingEvents ()
| Deletes all events queued on this event handler using QueueEvent() or AddPendingEvent(). More...
void | Connect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| Connects the given function dynamically with the event handler, id and event type. More...
void | Connect (int id, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
void | Connect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
bool | Disconnect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| Disconnects the given function dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed. More...
bool | Disconnect (int id=wxID_ANY, wxEventType eventType=wxEVT_NULL, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
bool | Disconnect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
| See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
template<typename EventTag , typename Functor >
void | Bind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
| Binds the given function, functor or method dynamically with the event. More...
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
void | Bind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
| See the Bind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info. More...
template<typename EventTag , typename Functor >
bool | Unbind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
| Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed. More...
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
bool | Unbind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
| See the Unbind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info. More...
void * | GetClientData () const
| Returns user-supplied client data. More...
wxClientData * | GetClientObject () const
| Returns a pointer to the user-supplied client data object. More...
void | SetClientData (void *data)
| Sets user-supplied client data. More...
void | SetClientObject (wxClientData *data)
| Set the client data object. More...
bool | GetEvtHandlerEnabled () const
| Returns true if the event handler is enabled, false otherwise. More...
wxEvtHandler * | GetNextHandler () const
| Returns the pointer to the next handler in the chain. More...
wxEvtHandler * | GetPreviousHandler () const
| Returns the pointer to the previous handler in the chain. More...
void | SetEvtHandlerEnabled (bool enabled)
| Enables or disables the event handler. More...
virtual void | SetNextHandler (wxEvtHandler *handler)
| Sets the pointer to the next handler. More...
virtual void | SetPreviousHandler (wxEvtHandler *handler)
| Sets the pointer to the previous handler. More...
void | Unlink ()
| Unlinks this event handler from the chain it's part of (if any); then links the "previous" event handler to the "next" one (so that the chain won't be interrupted). More...
bool | IsUnlinked () const
| Returns true if the next and the previous handler pointers of this event handler instance are NULL. More...
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to NULL the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class. More...
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj. More...
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone. More...
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer. More...
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
void | UnShare ()
| This is the same of AllocExclusive() but this method is public. More...
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
| The new operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...

## Protected Member Functions

virtual void | OnMRUFileNotExist (unsigned n, const wxString &filename)
| Called when a file selected from the MRU list doesn't exist any more. More...
virtual wxPreviewFrame * | CreatePreviewFrame (wxPrintPreviewBase *preview, wxWindow *parent, const wxString &title)
| Create the frame used for print preview. More...
Protected Member Functions inherited from wxEvtHandler
virtual bool | TryBefore (wxEvent &event)
| Method called by ProcessEvent() before examining this object event tables. More...
virtual bool | TryAfter (wxEvent &event)
| Method called by ProcessEvent() as last resort. More...
Protected Member Functions inherited from wxObject
void | AllocExclusive ()
| Ensure that this object's data is not shared with any other object. More...
virtual wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...

## Protected Attributes

wxView * | m_currentView
| The currently active view. More...
int | m_defaultDocumentNameCounter
| Stores the integer to be used for the next default document name. More...
wxList | m_docs
| A list of all documents. More...
wxFileHistory * | m_fileHistory
| A pointer to an instance of wxFileHistory, which manages the history of recently-visited files on the File menu. More...
wxString | m_lastDirectory
| The directory last selected by the user when opening a file. More...
int | m_maxDocsOpen
| Stores the maximum number of documents that can be opened before existing documents are closed. More...
Protected Attributes inherited from wxObject
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data. More...

## Additional Inherited Members

Static Public Member Functions inherited from wxEvtHandler
static void | AddFilter (wxEventFilter *filter)
| Add an event filter whose FilterEvent() method will be called for each and every event processed by wxWidgets. More...
static void | RemoveFilter (wxEventFilter *filter)
| Remove a filter previously installed with AddFilter(). More...

## Constructor & Destructor Documentation

## ◆ wxDocManager()

wxDocManager::wxDocManager | ( | long | flags = `0`,
|  | bool | initialize = `true`
| ) |  |

Constructor.

Create a document manager instance dynamically near the start of your application before doing any document or view operations.

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.

Parameters

  flags | Currently unused.
  initialize | Indicates whether Initialize() should be called by this ctor.

## ◆ ~wxDocManager()

virtual wxDocManager::~wxDocManager | ( |  | ) |

virtual

Destructor.

## Member Function Documentation

## ◆ ActivateView()

virtual void wxDocManager::ActivateView | ( | wxView * | doc,
|  | bool | activate = `true`
| ) |  |

virtual

Sets the current view.

## ◆ AddDocument()

void wxDocManager::AddDocument | ( | wxDocument * | doc | ) |

Adds the document to the list of documents.

## ◆ AddFileToHistory()

virtual void wxDocManager::AddFileToHistory | ( | const wxString & | filename | ) |

virtual

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

## ◆ AssociateTemplate()

void wxDocManager::AssociateTemplate | ( | wxDocTemplate * | temp | ) |

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

## ◆ CloseDocument()

bool wxDocManager::CloseDocument | ( | wxDocument * | doc,
|  | bool | force = `false`
| ) |  |

Closes the specified document.

If force is true, the document is closed even if it has unsaved changes.

Parameters

  doc | The document to close, must be non-NULL.
  force | If true, close the document even if wxDocument::Close() returns false.

Returns
  true if the document was closed or false if closing it was cancelled by user (only in force = false case).

## ◆ CloseDocuments()

bool wxDocManager::CloseDocuments | ( | bool | force = `true` | ) |

Closes all currently opened documents.

See also
  CloseDocument()

## ◆ CreateDocument()

virtual wxDocument* wxDocManager::CreateDocument | ( | const wxString & | path,
|  | long | flags = `0`
| ) |  |

virtual

Creates a new document.

This function can either create a document corresponding to a new file or to an already existing one depending on whether `wxDOC_NEW` is specified in the flags.

By default, this function asks the user for the type of document to open and the path to its file if it's not specified, i.e. if path is empty. Specifying `wxDOC_SILENT` flag suppresses any prompts and means that the path must be non-empty and there must be a registered document template handling the extension of this file, otherwise a warning message is logged and the function returns NULL. Notice that `wxDOC_SILENT` can be combined with `wxDOC_NEW`, however in this case the path must still be specified, even if the file with this path typically won't exist.

Finally notice that if this document manager was configured to allow only a limited number of simultaneously opened documents using SetMaxDocsOpen(), this function will try to close the oldest existing document if this number was reached before creating a new document. And if closing the old document fails (e.g. because it was vetoed by user), this function fails as well.

Parameters

  path | Path to a file or an empty string. If the path is empty, the user will be asked to select it (thus, this is incompatible with the use of `wxDOC_SILENT`). The file should exist unless flags includes `wxDOC_NEW`.
  flags | By default, none. May include `wxDOC_NEW` to indicate that the new document corresponds to a new file and not an existing one and `wxDOC_SILENT` to suppress any dialogs asking the user about the file path and type.

Returns
  a new document object or NULL on failure.

## ◆ CreateNewDocument()

wxDocument* wxDocManager::CreateNewDocument | ( |  | ) |

Creates an empty new document.

This is equivalent to calling CreateDocument() with `wxDOC_NEW` flags and without the file name.

## ◆ CreatePreviewFrame()

virtual wxPreviewFrame* wxDocManager::CreatePreviewFrame | ( | wxPrintPreviewBase * | preview,
|  | wxWindow * | parent,
|  | const wxString & | title
| ) |  |

protected virtual

Create the frame used for print preview.

This method can be overridden if you need to change the behaviour or appearance of the preview window. By default, a standard wxPreviewFrame is created.

Since
  2.9.1

Parameters

  preview | The associated preview object.
  parent | The parent window for the frame.
  title | The suggested title for the print preview frame.

Returns
  A new print preview frame, must not return NULL.

## ◆ CreateView()

virtual wxView* wxDocManager::CreateView | ( | wxDocument * | doc,
|  | long | flags = `0`
| ) |  |

virtual

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.

## ◆ DisassociateTemplate()

void wxDocManager::DisassociateTemplate | ( | wxDocTemplate * | temp | ) |

Removes the template from the list of templates.

## ◆ FileHistoryAddFilesToMenu() [1/2]

virtual void wxDocManager::FileHistoryAddFilesToMenu | ( |  | ) |

virtual

Appends the files in the history list to all menus managed by the file history object.

## ◆ FileHistoryAddFilesToMenu() [2/2]

virtual void wxDocManager::FileHistoryAddFilesToMenu | ( | wxMenu * | menu | ) |

virtual

Appends the files in the history list to the given menu only.

## ◆ FileHistoryLoad()

virtual void wxDocManager::FileHistoryLoad | ( | const wxConfigBase & | config | ) |

virtual

Loads the file history from a config object.

See also
  wxConfigBase

## ◆ FileHistoryRemoveMenu()

virtual void wxDocManager::FileHistoryRemoveMenu | ( | wxMenu * | menu | ) |

virtual

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

## ◆ FileHistorySave()

virtual void wxDocManager::FileHistorySave | ( | wxConfigBase & | resourceFile | ) |

virtual

Saves the file history into a config object.

This must be called explicitly by the application.

See also
  wxConfigBase

## ◆ FileHistoryUseMenu()

virtual void wxDocManager::FileHistoryUseMenu | ( | wxMenu * | menu | ) |

virtual

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
  You can add multiple menus using this function, to be managed by the file history object.

## ◆ FindDocumentByPath()

wxDocument* wxDocManager::FindDocumentByPath | ( | const wxString & | path | ) | const

Search for the document corresponding to the given file.

Parameters

  path | Document file path.

Returns
  Pointer to a wxDocument, or NULL if none found.

Since
  2.9.5

## ◆ FindTemplate()

wxDocTemplate* wxDocManager::FindTemplate | ( | const wxClassInfo * | classinfo | ) |

Search for a particular document template.

Example:

// creating a document instance of the specified document type:
m_doc = (MyDoc*)docManager->FindTemplate(CLASSINFO(MyDoc))->
CreateDocument(wxEmptyString, wxDOC_SILENT);
wxDocManager::CreateDocument
virtual wxDocument * CreateDocument(const wxString &path, long flags=0)
Creates a new document.
wxEmptyString
wxString wxEmptyString
The global wxString instance of an empty string.
Definition: string.h:1977

Parameters

  classinfo | Class info of a document class for which a wxDocTemplate had been previously created.

Returns
  Pointer to a wxDocTemplate, or NULL if none found.

Since
  2.9.2

## ◆ FindTemplateForPath()

virtual wxDocTemplate* wxDocManager::FindTemplateForPath | ( | const wxString & | path | ) |

virtual

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.

## ◆ GetAnyUsableView()

wxView* wxDocManager::GetAnyUsableView | ( |  | ) | const

Returns the view to apply a user command to.

This method tries to find the view that the user wants to interact with. It returns the same view as GetCurrentDocument() if there is any currently active view but falls back to the first view of the first document if there is no active view.

Since
  2.9.5

## ◆ GetCurrentDocument()

wxDocument* wxDocManager::GetCurrentDocument | ( |  | ) | const

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

## ◆ GetCurrentView()

virtual wxView* wxDocManager::GetCurrentView | ( |  | ) | const

virtual

Returns the currently active view.

This method can return NULL if no view is currently active.

See also
  GetAnyUsableView()

## ◆ GetDocuments()

wxList& wxDocManager::GetDocuments | ( |  | ) |

Returns a reference to the list of documents.

## ◆ GetDocumentsVector()

wxDocVector wxDocManager::GetDocumentsVector | ( |  | ) | const

Returns a vector of wxDocument pointers.

Since
  2.9.5

## ◆ GetFileHistory()

virtual wxFileHistory* wxDocManager::GetFileHistory | ( |  | ) | const

virtual

Returns a pointer to file history.

## ◆ GetHistoryFilesCount()

virtual size_t wxDocManager::GetHistoryFilesCount | ( |  | ) | const

virtual

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

## ◆ GetLastDirectory()

wxString wxDocManager::GetLastDirectory | ( |  | ) | const

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

Initially empty.

## ◆ GetMaxDocsOpen()

int wxDocManager::GetMaxDocsOpen | ( |  | ) | const

Returns the number of documents that can be open simultaneously.

## ◆ GetTemplates()

wxList& wxDocManager::GetTemplates | ( |  | ) |

Returns a reference to the list of associated templates.

## ◆ GetTemplatesVector()

wxDocTemplateVector wxDocManager::GetTemplatesVector | ( |  | ) | const

Returns a vector of wxDocTemplate pointers.

Since
  2.9.5

## ◆ Initialize()

virtual bool wxDocManager::Initialize | ( |  | ) |

virtual

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.

## ◆ MakeNewDocumentName()

virtual wxString wxDocManager::MakeNewDocumentName | ( |  | ) |

virtual

Return a string containing a suitable default name for a new document.

By default this is implemented by appending an integer counter to the string unnamed but can be overridden in the derived classes to do something more appropriate.

## ◆ OnCreateFileHistory()

virtual wxFileHistory* wxDocManager::OnCreateFileHistory | ( |  | ) |

virtual

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

Called from Initialize().

## ◆ OnFileClose()

void wxDocManager::OnFileClose | ( | wxCommandEvent & | event | ) |

Closes and deletes the currently active document.

## ◆ OnFileCloseAll()

void wxDocManager::OnFileCloseAll | ( | wxCommandEvent & | event | ) |

Closes and deletes all the currently opened documents.

## ◆ OnFileNew()

void wxDocManager::OnFileNew | ( | wxCommandEvent & | event | ) |

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

## ◆ OnFileOpen()

void wxDocManager::OnFileOpen | ( | wxCommandEvent & | event | ) |

Creates a new document and reads in the selected file.

## ◆ OnFileRevert()

void wxDocManager::OnFileRevert | ( | wxCommandEvent & | event | ) |

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

## ◆ OnFileSave()

void wxDocManager::OnFileSave | ( | wxCommandEvent & | event | ) |

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

## ◆ OnFileSaveAs()

void wxDocManager::OnFileSaveAs | ( | wxCommandEvent & | event | ) |

Calls wxDocument::SaveAs() for the current document.

## ◆ OnMRUFileNotExist()

virtual void wxDocManager::OnMRUFileNotExist | ( | unsigned | n,
|  | const wxString & | filename
| ) |  |

protected virtual

Called when a file selected from the MRU list doesn't exist any more.

The default behaviour is to remove the file from the MRU (most recently used) files list and the corresponding menu and notify the user about it but this method can be overridden to customize it.

For example, an application may want to just give an error about the missing file filename but not remove it from the file history. Or it could ask the user whether the file should be kept or removed.

Notice that this method is called only if the file selected by user from the MRU files in the menu doesn't exist, but not if opening it failed for any other reason because in the latter case the default behaviour of removing the file from the MRU list is inappropriate. If you still want to do it, you would need to do it by calling RemoveFileFromHistory() explicitly in the part of the file opening code that may fail.

Since
  2.9.3

Parameters

  n | The index of the file in the MRU list, it can be passed to RemoveFileFromHistory() to remove this file from the list.
  filename | The full name of the file.

## ◆ RemoveDocument()

void wxDocManager::RemoveDocument | ( | wxDocument * | doc | ) |

Removes the document from the list of documents.

## ◆ SelectDocumentPath()

virtual wxDocTemplate* wxDocManager::SelectDocumentPath | ( | wxDocTemplate ** | templates,
|  | int | noTemplates,
|  | wxString & | path,
|  | long | flags,
|  | bool | save = `false`
| ) |  |

virtual

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 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, e.g.:

(doctemplate, path) = My::DocManager->SelectDocumentPath(...);
wxDocManager::SelectDocumentPath
virtual wxDocTemplate * SelectDocumentPath(wxDocTemplate **templates, int noTemplates, wxString &path, long flags, bool save=false)
Under Windows, pops up a file selector with a list of filters corresponding to document templates.

## ◆ SelectDocumentType()

virtual wxDocTemplate* wxDocManager::SelectDocumentType | ( | wxDocTemplate ** | templates,
|  | int | noTemplates,
|  | bool | sort = `false`
| ) |  |

virtual

Returns a document template by asking the user (if there is more than one template).

This function is used in 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 into 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.

## ◆ SelectViewType()

virtual wxDocTemplate* wxDocManager::SelectViewType | ( | wxDocTemplate ** | templates,
|  | int | noTemplates,
|  | bool | sort = `false`
| ) |  |

virtual

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

## ◆ SetLastDirectory()

void wxDocManager::SetLastDirectory | ( | const wxString & | dir | ) |

Sets the directory to be displayed to the user when opening a file.

Initially this is empty.

## ◆ SetMaxDocsOpen()

void wxDocManager::SetMaxDocsOpen | ( | int | n | ) |

Sets the maximum number of documents that can be open at a time.

By default, this is `INT_MAX`, i.e. the number of documents is unlimited. 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.

## Member Data Documentation

## ◆ m_currentView

wxView* wxDocManager::m_currentView

protected

The currently active view.

## ◆ m_defaultDocumentNameCounter

int wxDocManager::m_defaultDocumentNameCounter

protected

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

## ◆ m_docs

wxList wxDocManager::m_docs

protected

A list of all documents.

## ◆ m_fileHistory

wxFileHistory* wxDocManager::m_fileHistory

protected

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

## ◆ m_lastDirectory

wxString wxDocManager::m_lastDirectory

protected

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

## ◆ m_maxDocsOpen

int wxDocManager::m_maxDocsOpen

protected

Stores the maximum number of documents that can be opened before existing documents are closed.

By default, this is `INT_MAX` i.e. practically unlimited.