$szTitle = "wxdocmanager"; include "./_header.inc"; ?>
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.
include "./_footer.inc"; ?>