contents up previous next

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

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)

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.


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

notemplates sort

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

notemplates sort

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.