2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: docview.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxDocTemplate
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxDocTemplate
|
|
|
|
@wxheader{docview.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The wxDocTemplate class is used to model the relationship between a
|
|
|
|
document class and a view class.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dvf}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see @ref overview_wxdoctemplateoverview "wxDocTemplate overview", wxDocument,
|
|
|
|
wxView
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxDocTemplate : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor. Create instances dynamically near the start of your application
|
|
|
|
after creating
|
|
|
|
a wxDocManager instance, and before doing any document or view operations.
|
2008-03-09 12:33:59 +00:00
|
|
|
@a manager is the document manager object which manages this template.
|
|
|
|
@a descr is a short description of what the template is for. This string will
|
2008-03-08 13:52:38 +00:00
|
|
|
be displayed in the
|
|
|
|
file filter list of Windows file selectors.
|
2008-03-09 12:33:59 +00:00
|
|
|
@a filter is an appropriate file filter such as @c *.txt.
|
|
|
|
@a dir is the default directory to use for file selectors.
|
|
|
|
@a ext is the default file extension (such as txt).
|
|
|
|
@a docTypeName is a name that should be unique for a given type of document,
|
2008-03-08 13:52:38 +00:00
|
|
|
used for
|
|
|
|
gathering a list of views relevant to a particular document.
|
2008-03-09 12:33:59 +00:00
|
|
|
@a viewTypeName is a name that should be unique for a given view.
|
|
|
|
@a docClassInfo is a pointer to the run-time document class information as
|
2008-03-08 13:52:38 +00:00
|
|
|
returned
|
|
|
|
by the CLASSINFO macro, e.g. CLASSINFO(MyDocumentClass). If this is not
|
|
|
|
supplied,
|
|
|
|
you will need to derive a new wxDocTemplate class and override the
|
|
|
|
CreateDocument
|
|
|
|
member to return a new document instance on demand.
|
2008-03-09 12:33:59 +00:00
|
|
|
@a viewClassInfo is a pointer to the run-time view class information as returned
|
2008-03-08 13:52:38 +00:00
|
|
|
by the CLASSINFO macro, e.g. CLASSINFO(MyViewClass). If this is not supplied,
|
|
|
|
you will need to derive a new wxDocTemplate class and override the CreateView
|
|
|
|
member to return a new view instance on demand.
|
2008-03-09 12:33:59 +00:00
|
|
|
@a flags is a bit list of the following:
|
2008-03-08 13:52:38 +00:00
|
|
|
wxTEMPLATE_VISIBLE The template may be displayed to the user in dialogs.
|
|
|
|
wxTEMPLATE_INVISIBLE The template may not be displayed to the user in dialogs.
|
|
|
|
wxDEFAULT_TEMPLATE_FLAGS Defined as wxTEMPLATE_VISIBLE.
|
|
|
|
|
|
|
|
|
|
|
|
@b Wx::DocTemplate-new( docmgr, descr, filter, dir,
|
|
|
|
ext, docTypeName, viewTypeName, docClassInfo, viewClassInfo, flags
|
|
|
|
)
|
|
|
|
|
|
|
|
will construct document and view objects from the class information
|
|
|
|
|
|
|
|
@b Wx::DocTemplate-new( docmgr, descr, filter, dir,
|
|
|
|
ext, docTypeName, viewTypeName, docClassName, viewClassName, flags
|
|
|
|
)
|
|
|
|
|
|
|
|
will construct document and view objects from perl packages
|
|
|
|
|
|
|
|
@b Wx::DocTemplate-new( docmgr, descr, filter, dir,
|
|
|
|
ext, docTypeName, viewTypeName )
|
|
|
|
|
|
|
|
@c Wx::DocTemplate::CreateDocument() and
|
|
|
|
@c Wx::DocTemplate::CreateView() must be overridden
|
|
|
|
*/
|
|
|
|
wxDocTemplate(wxDocManager* manager, const wxString& descr,
|
|
|
|
const wxString& filter,
|
|
|
|
const wxString& dir,
|
|
|
|
const wxString& ext,
|
|
|
|
const wxString& docTypeName,
|
|
|
|
const wxString& viewTypeName,
|
2008-03-09 12:33:59 +00:00
|
|
|
wxClassInfo* docClassInfo = NULL,
|
|
|
|
wxClassInfo* viewClassInfo = NULL,
|
2008-03-08 13:52:38 +00:00
|
|
|
long flags = wxDEFAULT_TEMPLATE_FLAGS);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
~wxDocTemplate();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Creates a new instance of the associated document class. If you have not
|
|
|
|
supplied
|
|
|
|
a wxClassInfo parameter to the template constructor, you will need to override
|
|
|
|
this
|
|
|
|
function to return an appropriate document instance.
|
|
|
|
This function calls InitDocument() which in turns
|
|
|
|
calls wxDocument::OnCreate.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxDocument* CreateDocument(const wxString& path, long flags = 0);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Creates a new instance of the associated view class. If you have not supplied
|
|
|
|
a wxClassInfo parameter to the template constructor, you will need to override
|
|
|
|
this
|
|
|
|
function to return an appropriate view instance.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxView* CreateView(wxDocument* doc, long flags = 0);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the default file extension for the document data, as passed to the
|
|
|
|
document template constructor.
|
|
|
|
*/
|
|
|
|
wxString GetDefaultExtension();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the text description of this template, as passed to the document
|
|
|
|
template constructor.
|
|
|
|
*/
|
|
|
|
wxString GetDescription();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the default directory, as passed to the document template constructor.
|
|
|
|
*/
|
|
|
|
wxString GetDirectory();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer to the document manager instance for which this template was
|
|
|
|
created.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxDocManager* GetDocumentManager();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the document type name, as passed to the document template constructor.
|
|
|
|
*/
|
|
|
|
wxString GetDocumentName();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the file filter, as passed to the document template constructor.
|
|
|
|
*/
|
|
|
|
wxString GetFileFilter();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the flags, as passed to the document template constructor.
|
|
|
|
*/
|
|
|
|
long GetFlags();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the view type name, as passed to the document template constructor.
|
|
|
|
*/
|
|
|
|
wxString GetViewName();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialises the document, calling wxDocument::OnCreate. This is called from
|
|
|
|
CreateDocument().
|
|
|
|
*/
|
|
|
|
bool InitDocument(wxDocument* doc, const wxString& path,
|
|
|
|
long flags = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the document template can be shown in user dialogs, @false
|
|
|
|
otherwise.
|
|
|
|
*/
|
|
|
|
bool IsVisible();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the default file extension.
|
|
|
|
*/
|
|
|
|
void SetDefaultExtension(const wxString& ext);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the template description.
|
|
|
|
*/
|
|
|
|
void SetDescription(const wxString& descr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the default directory.
|
|
|
|
*/
|
|
|
|
void SetDirectory(const wxString& dir);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the pointer to the document manager instance for which this template was
|
|
|
|
created.
|
|
|
|
Should not be called by the application.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void SetDocumentManager(wxDocManager* manager);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the file filter.
|
|
|
|
*/
|
|
|
|
void SetFileFilter(const wxString& filter);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the internal document template flags (see the constructor description for
|
|
|
|
more details).
|
|
|
|
*/
|
|
|
|
void SetFlags(long flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxString m_defaultExt
|
|
|
|
The default extension for files of this type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxString m_description
|
|
|
|
A short description of this template.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxString m_directory
|
|
|
|
The default directory for files of this type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxClassInfo* m_docClassInfo
|
|
|
|
Run-time class information that allows document instances to be constructed
|
|
|
|
dynamically.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxString m_docTypeName
|
|
|
|
The named type of the document associated with this template.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxDocTemplate* m_documentManager
|
|
|
|
A pointer to the document manager for which this template was created.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxString m_fileFilter
|
|
|
|
The file filter (such as @c *.txt) to be used in file selector dialogs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
long m_flags
|
|
|
|
The flags passed to the constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxClassInfo* m_viewClassInfo
|
|
|
|
Run-time class information that allows view instances to be constructed
|
|
|
|
dynamically.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxString m_viewTypeName
|
|
|
|
The named type of the view associated with this template.
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxDocManager
|
|
|
|
@wxheader{docview.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The wxDocManager class is part of the document/view framework supported by
|
|
|
|
wxWidgets,
|
|
|
|
and cooperates with the wxView, wxDocument
|
|
|
|
and wxDocTemplate classes.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dvf}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see @ref overview_wxdocmanageroverview "wxDocManager overview", wxDocument,
|
|
|
|
wxView, wxDocTemplate, wxFileHistory
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxDocManager : public wxEvtHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor. Create a document manager instance dynamically near the start of
|
|
|
|
your application
|
|
|
|
before doing any document or view operations.
|
2008-03-09 12:33:59 +00:00
|
|
|
@a flags is currently unused.
|
|
|
|
If @a initialize is @true, the Initialize() function will be called
|
2008-03-08 13:52:38 +00:00
|
|
|
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(long flags = wxDEFAULT_DOCMAN_FLAGS,
|
2008-03-09 12:33:59 +00:00
|
|
|
bool initialize = true);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
~wxDocManager();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the current view.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void ActivateView(wxView* doc, bool activate = true);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Adds the document to the list of documents.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void AddDocument(wxDocument* doc);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Adds a file to the file history list, if we have a pointer to an appropriate
|
|
|
|
file menu.
|
|
|
|
*/
|
|
|
|
void AddFileToHistory(const wxString& filename);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Adds the template to the document manager's template list.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void AssociateTemplate(wxDocTemplate* temp);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Closes all currently opened documents.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
bool CloseDocuments(bool force = true);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-09 12:33:59 +00:00
|
|
|
Creates a new document in a manner determined by the @a flags parameter, which
|
2008-03-08 13:52:38 +00:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
wxDocument* CreateDocument(const wxString& path, 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.
|
|
|
|
*/
|
|
|
|
wxView* CreateView(wxDocument* doc, long flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes the template from the list of templates.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void DisassociateTemplate(wxDocTemplate* temp);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Appends the files in the history list, to the given menu only.
|
|
|
|
*/
|
|
|
|
void FileHistoryAddFilesToMenu();
|
2008-03-08 14:43:31 +00:00
|
|
|
void FileHistoryAddFilesToMenu(wxMenu* menu);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Loads the file history from a config object.
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxConfig()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void FileHistoryLoad(wxConfigBase& config);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes the given menu from the list of menus managed by the file history
|
|
|
|
object.
|
|
|
|
*/
|
|
|
|
void FileHistoryRemoveMenu(wxMenu* menu);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Saves the file history into a config object. This must be called
|
|
|
|
explicitly by the application.
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxConfig()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void FileHistorySave(wxConfigBase& resourceFile);
|
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void FileHistoryUseMenu(wxMenu* menu);
|
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxDocTemplate* FindTemplateForPath(const wxString& path);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the document associated with the currently active view (if any).
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxDocument* GetCurrentDocument();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the currently active view
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxView* GetCurrentView();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a reference to the list of documents.
|
|
|
|
*/
|
|
|
|
wxList GetDocuments();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer to file history.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxFileHistory* GetFileHistory();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the number of files currently stored in the file history.
|
|
|
|
*/
|
|
|
|
size_t GetHistoryFilesCount();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the directory last selected by the user when opening a file. Initially
|
|
|
|
empty.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString GetLastDirectory() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the number of documents that can be open simultaneously.
|
|
|
|
*/
|
|
|
|
int GetMaxDocsOpen();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a reference to the list of associated templates.
|
|
|
|
*/
|
|
|
|
wxList GetTemplates();
|
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
|
|
|
@e 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 Initialize();
|
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
|
|
|
@b unnamed but can be overridden in the derived classes to do something more
|
|
|
|
appropriate.
|
|
|
|
*/
|
|
|
|
wxString MakeNewDocumentName();
|
|
|
|
|
|
|
|
/**
|
|
|
|
A hook to allow a derived class to create a different type of file history.
|
|
|
|
Called
|
|
|
|
from Initialize().
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxFileHistory* OnCreateFileHistory();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Closes and deletes the currently active document.
|
|
|
|
*/
|
|
|
|
void OnFileClose(wxCommandEvent& event);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Closes and deletes all the currently opened documents.
|
|
|
|
*/
|
|
|
|
void OnFileCloseAll(wxCommandEvent& event);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Creates a document from a list of templates (if more than one template).
|
|
|
|
*/
|
|
|
|
void OnFileNew(wxCommandEvent& event);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Creates a new document and reads in the selected file.
|
|
|
|
*/
|
|
|
|
void OnFileOpen(wxCommandEvent& event);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reverts the current document by calling wxDocument::Revert for the current
|
|
|
|
document.
|
|
|
|
*/
|
|
|
|
void OnFileRevert(wxCommandEvent& event);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Saves the current document by calling wxDocument::Save for the current document.
|
|
|
|
*/
|
|
|
|
void OnFileSave(wxCommandEvent& event);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Calls wxDocument::SaveAs for the current document.
|
|
|
|
*/
|
|
|
|
void OnFileSaveAs(wxCommandEvent& event);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes the document from the list of documents.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void RemoveDocument(wxDocument* doc);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
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().
|
|
|
|
(doctemplate, path) = My::DocManager-SelectDocumentPath( ... );
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxDocTemplate* SelectDocumentPath(wxDocTemplate** templates,
|
|
|
|
int noTemplates,
|
|
|
|
wxString& path,
|
|
|
|
long flags,
|
|
|
|
bool save);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a document template by asking the user (if there is more than one
|
|
|
|
template).
|
|
|
|
This function is used in CreateDocument().
|
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param templates
|
2008-03-09 12:33:59 +00:00
|
|
|
Pointer to an array of templates from which to choose a desired template.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param noTemplates
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of templates being pointed to by the templates pointer.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param sort
|
2008-03-09 12:33:59 +00:00
|
|
|
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.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxDocTemplate* SelectDocumentType(wxDocTemplate** templates,
|
|
|
|
int noTemplates,
|
|
|
|
bool sort = false);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param templates
|
2008-03-09 12:33:59 +00:00
|
|
|
Pointer to an array of templates from which to choose a desired template.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param noTemplates
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of templates being pointed to by the templates pointer.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param sort
|
2008-03-09 12:33:59 +00:00
|
|
|
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.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxDocTemplate* SelectViewType(wxDocTemplate** templates,
|
|
|
|
int noTemplates,
|
|
|
|
bool sort = false);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the directory to be displayed to the user when opening a file. Initially
|
|
|
|
this is empty.
|
|
|
|
*/
|
|
|
|
void SetLastDirectory(const wxString& dir);
|
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void SetMaxDocsOpen(int n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxView* m_currentView
|
|
|
|
The currently active view.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
int m_defaultDocumentNameCounter
|
|
|
|
Stores the integer to be used for the next default document name.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxList m_docs
|
|
|
|
A list of all documents.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxFileHistory* m_fileHistory
|
|
|
|
A pointer to an instance of wxFileHistory,
|
|
|
|
which manages the history of recently-visited files on the File menu.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
long m_flags
|
|
|
|
Stores the flags passed to the constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
The directory last selected by the user when opening a file.
|
|
|
|
wxFileHistory* m_fileHistory
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
int m_maxDocsOpen
|
|
|
|
Stores the maximum number of documents that can be opened before
|
|
|
|
existing documents are closed. By default, this is 10,000.
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxView
|
|
|
|
@wxheader{docview.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The view class can be used to model the viewing and editing component of
|
|
|
|
an application's file-based data. It is part of the document/view framework
|
|
|
|
supported by wxWidgets,
|
|
|
|
and cooperates with the wxDocument, wxDocTemplate
|
|
|
|
and wxDocManager classes.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dvf}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see @ref overview_wxviewoverview "wxView overview", wxDocument, wxDocTemplate,
|
2008-03-08 13:52:38 +00:00
|
|
|
wxDocManager
|
|
|
|
*/
|
|
|
|
class wxView : public wxEvtHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor. Define your own default constructor to initialize
|
|
|
|
application-specific
|
|
|
|
data.
|
|
|
|
*/
|
|
|
|
wxView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor. Removes itself from the document's list of views.
|
|
|
|
*/
|
|
|
|
~wxView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Call this from your view frame's OnActivate member to tell the framework which
|
|
|
|
view is
|
|
|
|
currently active. If your windowing system doesn't call OnActivate, you may
|
|
|
|
need to
|
|
|
|
call this function from any place where you know the view must
|
|
|
|
be active, and the framework will need to get the current view.
|
|
|
|
The prepackaged view frame wxDocChildFrame calls Activate() from its OnActivate
|
|
|
|
member.
|
|
|
|
This function calls OnActivateView().
|
|
|
|
*/
|
|
|
|
virtual void Activate(bool activate);
|
|
|
|
|
|
|
|
/**
|
2008-03-09 12:33:59 +00:00
|
|
|
Closes the view by calling OnClose. If @a deleteWindow is @true, this function
|
2008-03-08 13:52:38 +00:00
|
|
|
should
|
|
|
|
delete the window associated with the view.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
virtual bool Close(bool deleteWindow = true);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets a pointer to the document associated with the view.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxDocument* GetDocument() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer to the document manager instance associated with this view.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxDocManager* GetDocumentManager() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the frame associated with the view (if any). Note that this "frame'' is
|
|
|
|
not a wxFrame at all in the generic MDI implementation which uses the notebook
|
|
|
|
pages instead of the frames and this is why this method returns a wxWindow and
|
|
|
|
not a wxFrame.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxWindow* GetFrame();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the name associated with the view (passed to the wxDocTemplate
|
|
|
|
constructor).
|
|
|
|
Not currently used by the framework.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString GetViewName() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Called when a view is activated by means of Activate(). The default
|
|
|
|
implementation does
|
|
|
|
nothing.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
virtual void OnActivateView(bool activate, wxView* activeView,
|
|
|
|
wxView* deactiveView);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Called when the filename has changed. The default implementation constructs a
|
|
|
|
suitable title and sets the title of the view frame (if any).
|
|
|
|
*/
|
|
|
|
virtual void OnChangeFilename();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Implements closing behaviour. The default implementation calls wxDocument::Close
|
|
|
|
to close the associated document. Does not delete the view. The application
|
|
|
|
may wish to do some cleaning up operations in this function, @e if a
|
|
|
|
call to wxDocument::Close succeeded. For example, if your views
|
|
|
|
all share the same window, you need to disassociate the window from the view
|
2008-03-09 12:33:59 +00:00
|
|
|
and perhaps clear the window. If @a deleteWindow is @true, delete the
|
2008-03-08 13:52:38 +00:00
|
|
|
frame associated with the view.
|
|
|
|
*/
|
|
|
|
virtual bool OnClose(bool deleteWindow);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Override this to clean up the view when the document is being
|
|
|
|
closed.
|
|
|
|
*/
|
|
|
|
virtual void OnClosingDocument();
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxDocManager or wxDocument creates a wxView via a wxDocTemplate.
|
|
|
|
Just after the wxDocTemplate creates the wxView, it calls
|
|
|
|
OnCreate(). In its OnCreate member function, the wxView can create a
|
|
|
|
wxDocChildFrame
|
|
|
|
or a derived class. This wxDocChildFrame provides user interface
|
|
|
|
elements to view and/or edit the contents of the wxDocument.
|
|
|
|
By default, simply returns @true. If the function returns @false, the
|
|
|
|
view will be deleted.
|
|
|
|
*/
|
|
|
|
virtual bool OnCreate(wxDocument* doc, long flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
If the printing framework is enabled in the library, this function returns a
|
|
|
|
wxPrintout object for the purposes of printing. It should create a new object
|
|
|
|
every time it is called; the framework will delete objects it creates.
|
|
|
|
By default, this function returns an instance of wxDocPrintout, which prints
|
|
|
|
and previews one page by calling OnDraw().
|
|
|
|
Override to return an instance of a class other than wxDocPrintout.
|
|
|
|
*/
|
|
|
|
virtual wxPrintout* OnCreatePrintout();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Override this function to render the view on the given device context.
|
|
|
|
*/
|
|
|
|
virtual void OnDraw(wxDC* dc);
|
|
|
|
|
|
|
|
/**
|
2008-03-09 12:33:59 +00:00
|
|
|
Called when the view should be updated. @a sender is a pointer to the view
|
2008-03-08 13:52:38 +00:00
|
|
|
that sent the update request, or @NULL if no single view requested the update
|
|
|
|
(for instance,
|
2008-03-09 12:33:59 +00:00
|
|
|
when the document is opened). @a hint is as yet unused but may in future contain
|
2008-03-08 13:52:38 +00:00
|
|
|
application-specific information for making updating more efficient.
|
|
|
|
*/
|
|
|
|
virtual void OnUpdate(wxView* sender, wxObject* hint);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Associates the given document with the view. Normally called by the
|
|
|
|
framework.
|
|
|
|
*/
|
|
|
|
void SetDocument(wxDocument* doc);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the frame associated with this view. The application should call this
|
|
|
|
if possible, to tell the view about the frame.
|
|
|
|
See GetFrame() for the explanation about the mismatch
|
|
|
|
between the "Frame'' in the method name and the type of its parameter.
|
|
|
|
*/
|
|
|
|
void SetFrame(wxWindow* frame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the view type name. Should only be called by the framework.
|
|
|
|
*/
|
|
|
|
void SetViewName(const wxString& name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxDocument* m_viewDocument
|
|
|
|
The document associated with this view. There may be more than one view per
|
|
|
|
document, but there can never be more than one document for one view.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxFrame* m_viewFrame
|
|
|
|
Frame associated with the view, if any.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxString m_viewTypeName
|
|
|
|
The view type name given to the wxDocTemplate constructor, copied to this
|
|
|
|
variable when the view is created. Not currently used by the framework.
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxDocChildFrame
|
|
|
|
@wxheader{docview.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The wxDocChildFrame class provides a default frame for displaying documents
|
|
|
|
on separate windows. This class can only be used for SDI (not MDI) child frames.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The class is part of the document/view framework supported by wxWidgets,
|
|
|
|
and cooperates with the wxView, wxDocument,
|
|
|
|
wxDocManager and wxDocTemplate classes.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
See the example application in @c samples/docview.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dvf}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see @ref overview_docviewoverview, wxFrame
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxDocChildFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
|
|
|
wxDocChildFrame(wxDocument* doc, wxView* view, wxFrame* parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& title,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxDEFAULT_FRAME_STYLE,
|
|
|
|
const wxString& name = "frame");
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
~wxDocChildFrame();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the document associated with this frame.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxDocument* GetDocument() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the view associated with this frame.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxView* GetView() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the currently active view to be the frame's view. You may need
|
|
|
|
to override (but still call) this function in order to set the keyboard
|
|
|
|
focus for your subwindow.
|
|
|
|
*/
|
|
|
|
void OnActivate(wxActivateEvent event);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Closes and deletes the current view and document.
|
|
|
|
*/
|
|
|
|
void OnCloseWindow(wxCloseEvent& event);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the document for this frame.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void SetDocument(wxDocument* doc);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the view for this frame.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void SetView(wxView* view);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
wxDocument* m_childDocument
|
|
|
|
The document associated with the frame.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxView* m_childView
|
|
|
|
The view associated with the frame.
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxDocParentFrame
|
|
|
|
@wxheader{docview.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The wxDocParentFrame class provides a default top-level frame for
|
|
|
|
applications using the document/view framework. This class can only be used for
|
|
|
|
SDI (not MDI) parent frames.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
It cooperates with the wxView, wxDocument,
|
2008-03-10 15:24:38 +00:00
|
|
|
wxDocManager and wxDocTemplates() classes.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
See the example application in @c samples/docview.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dvf}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see @ref overview_docviewoverview, wxFrame
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxDocParentFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
|
|
|
wxDocParentFrame();
|
2008-03-09 12:33:59 +00:00
|
|
|
wxDocParentFrame(wxDocManager* manager, wxFrame* parent,
|
2008-03-08 14:43:31 +00:00
|
|
|
wxWindowID id,
|
|
|
|
const wxString& title,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxDEFAULT_FRAME_STYLE,
|
|
|
|
const wxString& name = "frame");
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
~wxDocParentFrame();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Used in two-step construction.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
bool Create(wxDocManager* manager, wxFrame* parent,
|
2008-03-08 13:52:38 +00:00
|
|
|
wxWindowID id, const wxString& title,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxDEFAULT_FRAME_STYLE,
|
|
|
|
const wxString& name = "frame");
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the associated @ref overview_wxdocmanager "document manager object".
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxDocManager* GetDocumentManager() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Deletes all views and documents. If no user input cancelled the
|
|
|
|
operation, the frame will be destroyed and the application will exit.
|
|
|
|
Since understanding how document/view clean-up takes place can be difficult,
|
|
|
|
the implementation of this function is shown below.
|
|
|
|
*/
|
|
|
|
void OnCloseWindow(wxCloseEvent& event);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxDocument
|
|
|
|
@wxheader{docview.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The document class can be used to model an application's file-based
|
|
|
|
data. It is part of the document/view framework supported by wxWidgets,
|
|
|
|
and cooperates with the wxView, wxDocTemplate
|
|
|
|
and wxDocManager classes.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dvf}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see @ref overview_wxdocumentoverview "wxDocument overview", wxView,
|
|
|
|
wxDocTemplate, wxDocManager
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxDocument : public wxEvtHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor. Define your own default constructor to initialize
|
|
|
|
application-specific
|
|
|
|
data.
|
|
|
|
*/
|
|
|
|
wxDocument();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor. Removes itself from the document manager.
|
|
|
|
*/
|
|
|
|
~wxDocument();
|
|
|
|
|
|
|
|
/**
|
|
|
|
If the view is not already in the list of views, adds the view and calls
|
|
|
|
OnChangedViewList.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
virtual bool AddView(wxView* view);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Closes the document, by calling OnSaveModified and then (if this returned @true)
|
|
|
|
OnCloseDocument.
|
|
|
|
This does not normally delete the document object: use DeleteAllViews to do
|
|
|
|
this implicitly.
|
|
|
|
*/
|
|
|
|
virtual bool Close();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Calls wxView::Close and deletes each view. Deleting the final view will
|
|
|
|
implicitly
|
|
|
|
delete the document itself, because the wxView destructor calls RemoveView. This
|
|
|
|
in turns calls OnChangedViewList(), whose default implemention is to
|
|
|
|
save and delete the document if no views exist.
|
|
|
|
*/
|
|
|
|
virtual bool DeleteAllViews();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer to the command processor associated with this document.
|
|
|
|
See wxCommandProcessor.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxCommandProcessor* GetCommandProcessor() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets a pointer to the associated document manager.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxDocManager* GetDocumentManager() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the document type name for this document. See the comment for
|
2008-03-10 15:24:38 +00:00
|
|
|
documentTypeName().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString GetDocumentName() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets a pointer to the template that created the document.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxDocTemplate* GetDocumentTemplate() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Intended to return a suitable window for using as a parent for document-related
|
|
|
|
dialog boxes. By default, uses the frame associated with the first view.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxWindow* GetDocumentWindow() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the filename associated with this document, or "" if none is
|
|
|
|
associated.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString GetFilename() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
A convenience function to get the first view for a document, because
|
|
|
|
in many cases a document will only have a single view.
|
|
|
|
See also: GetViews()
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxView* GetFirstView() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the title for this document. The document title is used for an associated
|
|
|
|
frame (if any), and is usually constructed by the framework from
|
|
|
|
the filename.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString GetTitle() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return the document name suitable to be shown to the user. The default
|
|
|
|
implementation uses the document title, if any, of the name part of the
|
|
|
|
document filename if it was set or, otherwise, the string @b unnamed.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
virtual wxString GetUserReadableName() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the list whose elements are the views on the document.
|
|
|
|
See also: GetFirstView()
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxList GetViews() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the document has been modified since the last save, @false
|
|
|
|
otherwise.
|
|
|
|
You may need to override this if your document view maintains its own
|
|
|
|
record of being modified (for example if using wxTextWindow to view and edit
|
|
|
|
the document).
|
|
|
|
See also Modify().
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
virtual bool IsModified() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Override this function and call it from your own LoadObject before
|
|
|
|
streaming your own data. LoadObject is called by the framework
|
|
|
|
automatically when the document contents need to be loaded.
|
|
|
|
Note that only one of these forms exists, depending on how wxWidgets
|
|
|
|
was configured.
|
|
|
|
*/
|
|
|
|
virtual istream LoadObject(istream& stream);
|
2008-03-08 14:43:31 +00:00
|
|
|
virtual wxInputStream LoadObject(wxInputStream& stream);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Call with @true to mark the document as modified since the last save, @false
|
|
|
|
otherwise.
|
|
|
|
You may need to override this if your document view maintains its own
|
|
|
|
record of being modified (for example if using wxTextWindow to view and edit
|
|
|
|
the document).
|
|
|
|
See also IsModified().
|
|
|
|
*/
|
|
|
|
virtual void Modify(bool modify);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Called when a view is added to or deleted from this document. The default
|
|
|
|
implementation saves and deletes the document if no views exist (the last
|
|
|
|
one has just been removed).
|
|
|
|
*/
|
|
|
|
virtual void OnChangedViewList();
|
|
|
|
|
|
|
|
/**
|
|
|
|
The default implementation calls DeleteContents (an empty implementation)
|
|
|
|
sets the modified flag to @false. Override this to
|
|
|
|
supply additional behaviour when the document is closed with Close.
|
|
|
|
*/
|
|
|
|
virtual bool OnCloseDocument();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Called just after the document object is created to give it a chance
|
|
|
|
to initialize itself. The default implementation uses the
|
|
|
|
template associated with the document to create an initial view.
|
|
|
|
If this function returns @false, the document is deleted.
|
|
|
|
*/
|
|
|
|
virtual bool OnCreate(const wxString& path, long flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Override this function if you want a different (or no) command processor
|
|
|
|
to be created when the document is created. By default, it returns
|
|
|
|
an instance of wxCommandProcessor.
|
|
|
|
See wxCommandProcessor.
|
|
|
|
*/
|
|
|
|
virtual wxCommandProcessor* OnCreateCommandProcessor();
|
|
|
|
|
|
|
|
/**
|
|
|
|
The default implementation calls OnSaveModified and DeleteContents, makes a
|
|
|
|
default title for the
|
|
|
|
document, and notifies the views that the filename (in fact, the title) has
|
|
|
|
changed.
|
|
|
|
*/
|
|
|
|
virtual bool OnNewDocument();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructs an input file stream for the given filename (which must not be
|
|
|
|
empty),
|
|
|
|
and calls LoadObject. If LoadObject returns @true, the document is set to
|
|
|
|
unmodified; otherwise, an error message box is displayed. The document's
|
|
|
|
views are notified that the filename has changed, to give windows an opportunity
|
|
|
|
to update their titles. All of the document's views are then updated.
|
|
|
|
*/
|
|
|
|
virtual bool OnOpenDocument(const wxString& filename);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructs an output file stream for the given filename (which must not be
|
|
|
|
empty),
|
|
|
|
and calls SaveObject. If SaveObject returns @true, the document is set to
|
|
|
|
unmodified; otherwise, an error message box is displayed.
|
|
|
|
*/
|
|
|
|
virtual bool OnSaveDocument(const wxString& filename);
|
|
|
|
|
|
|
|
/**
|
|
|
|
If the document has been modified, prompts the user to ask if the changes should
|
|
|
|
be changed. If the user replies Yes, the Save function is called. If No, the
|
|
|
|
document is marked as unmodified and the function succeeds. If Cancel, the
|
|
|
|
function fails.
|
|
|
|
*/
|
|
|
|
virtual bool OnSaveModified();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes the view from the document's list of views, and calls OnChangedViewList.
|
|
|
|
*/
|
|
|
|
virtual bool RemoveView(wxView* view);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Saves the document by calling OnSaveDocument if there is an associated filename,
|
|
|
|
or SaveAs if there is no filename.
|
|
|
|
*/
|
|
|
|
virtual bool Save();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Prompts the user for a file to save to, and then calls OnSaveDocument.
|
|
|
|
*/
|
|
|
|
virtual bool SaveAs();
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Override this function and call it from your own SaveObject before
|
|
|
|
streaming your own data. SaveObject is called by the framework
|
|
|
|
automatically when the document contents need to be saved.
|
|
|
|
Note that only one of these forms exists, depending on how wxWidgets
|
|
|
|
was configured.
|
|
|
|
*/
|
|
|
|
virtual ostream SaveObject(ostream& stream);
|
2008-03-08 14:43:31 +00:00
|
|
|
virtual wxOutputStream SaveObject(wxOutputStream& stream);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the command processor to be used for this document. The document will then
|
|
|
|
be responsible
|
|
|
|
for its deletion. Normally you should not call this; override
|
|
|
|
OnCreateCommandProcessor
|
|
|
|
instead.
|
|
|
|
See wxCommandProcessor.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
virtual void SetCommandProcessor(wxCommandProcessor* processor);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the document type name for this document. See the comment for
|
2008-03-10 15:24:38 +00:00
|
|
|
documentTypeName().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void SetDocumentName(const wxString& name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the pointer to the template that created the document. Should only be
|
|
|
|
called by the
|
|
|
|
framework.
|
|
|
|
*/
|
|
|
|
void SetDocumentTemplate(wxDocTemplate* templ);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the filename for this document. Usually called by the framework.
|
2008-03-09 12:33:59 +00:00
|
|
|
If @a notifyViews is @true, wxView::OnChangeFilename is called for all views.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void SetFilename(const wxString& filename,
|
2008-03-09 12:33:59 +00:00
|
|
|
bool notifyViews = false);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the title for this document. The document title is used for an associated
|
|
|
|
frame (if any), and is usually constructed by the framework from
|
|
|
|
the filename.
|
|
|
|
*/
|
|
|
|
void SetTitle(const wxString& title);
|
|
|
|
|
|
|
|
/**
|
2008-03-09 12:33:59 +00:00
|
|
|
Updates all views. If @a sender is non-@NULL, does not update this view.
|
|
|
|
@a hint represents optional information to allow a view to optimize its update.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void UpdateAllViews(wxView* sender = NULL, wxObject* hint = NULL);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
wxCommandProcessor* m_commandProcessor
|
|
|
|
A pointer to the command processor associated with this document.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxString m_documentFile
|
|
|
|
Filename associated with this document ("" if none).
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
bool m_documentModified
|
|
|
|
@true if the document has been modified, @false otherwise.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxDocTemplate * m_documentTemplate
|
|
|
|
A pointer to the template from which this document was created.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxString m_documentTitle
|
|
|
|
Document title. The document title is used for an associated
|
|
|
|
frame (if any), and is usually constructed by the framework from
|
|
|
|
the filename.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxString m_documentTypeName
|
|
|
|
The document type name given to the wxDocTemplate constructor, copied to this
|
|
|
|
variable when the document is created. If several document templates are
|
|
|
|
created that use the same document type, this variable is used in
|
|
|
|
wxDocManager::CreateView
|
|
|
|
to collate a list of alternative view types that can be used on this kind of
|
|
|
|
document. Do not change the value of this variable.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxList m_documentViews
|
|
|
|
List of wxView instances associated with this document.
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxFileHistory
|
|
|
|
@wxheader{docview.h}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The wxFileHistory encapsulates a user interface convenience, the
|
|
|
|
list of most recently visited files as shown on a menu (usually the File menu).
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
wxFileHistory can manage one or more file menus. More than one menu may be
|
|
|
|
required
|
|
|
|
in an MDI application, where the file history should appear on each MDI child
|
|
|
|
menu
|
|
|
|
as well as the MDI parent frame.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
|
|
|
@category{FIXME}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see @ref overview_wxfilehistoryoverview "wxFileHistory overview", wxDocManager
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxFileHistory : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor. Pass the maximum number of files that should be stored and
|
|
|
|
displayed.
|
2008-03-09 12:33:59 +00:00
|
|
|
@a idBase defaults to wxID_FILE1 and represents the id given to the first
|
2008-03-08 13:52:38 +00:00
|
|
|
history menu item. Since menu items can't share the same ID you should change
|
|
|
|
idBase (To one of your own defined IDs) when using more than one wxFileHistory
|
|
|
|
in your application.
|
|
|
|
*/
|
|
|
|
wxFileHistory(size_t maxFiles = 9,
|
|
|
|
wxWindowID idBase = wxID_FILE1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
~wxFileHistory();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Adds a file to the file history list, if the object has a pointer to an
|
|
|
|
appropriate file menu.
|
|
|
|
*/
|
|
|
|
void AddFileToHistory(const wxString& filename);
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Appends the files in the history list, to the given menu only.
|
|
|
|
*/
|
|
|
|
void AddFilesToMenu();
|
2008-03-08 14:43:31 +00:00
|
|
|
void AddFilesToMenu(wxMenu* menu);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the base identifier for the range used for appending items.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxWindowID GetBaseId() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the number of files currently stored in the file history.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
size_t GetCount() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the file at this index (zero-based).
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString GetHistoryFile(size_t index) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the maximum number of files that can be stored.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
int GetMaxFiles() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the list of menus that are managed by this file history object.
|
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see UseMenu()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
const wxList GetMenus() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Loads the file history from the given config object. This function should be
|
|
|
|
called explicitly by the application.
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxConfig()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void Load(wxConfigBase& config);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes the specified file from the history.
|
|
|
|
*/
|
|
|
|
void RemoveFileFromHistory(size_t i);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes this menu from the list of those managed by this object.
|
|
|
|
*/
|
|
|
|
void RemoveMenu(wxMenu* menu);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Saves the file history into the given config object. This must be called
|
|
|
|
explicitly by the application.
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxConfig()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void Save(wxConfigBase& config);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the base identifier for the range used for appending items.
|
|
|
|
*/
|
|
|
|
void SetBaseId(wxWindowID baseId);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Adds this menu to the list of those menus that are managed by this file history
|
|
|
|
object.
|
|
|
|
Also see AddFilesToMenu() for
|
|
|
|
initializing the menu with filenames that are already in the history when this
|
|
|
|
function is called, as this is not done automatically.
|
|
|
|
*/
|
|
|
|
void UseMenu(wxMenu* menu);
|
|
|
|
|
|
|
|
/**
|
|
|
|
char** m_fileHistory
|
|
|
|
A character array of strings corresponding to the most recently opened
|
|
|
|
files.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
size_t m_fileHistoryN
|
|
|
|
The number of files stored in the history array.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
size_t m_fileMaxFiles
|
|
|
|
The maximum number of files to be stored and displayed on the menu.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
wxMenu* m_fileMenu
|
|
|
|
The file menu used to display the file history list (if enabled).
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
// ============================================================================
|
|
|
|
// Global functions/macros
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
Copies the given file to @e stream. Useful when converting an old application to
|
|
|
|
use streams (within the document/view framework, for example).
|
|
|
|
*/
|
|
|
|
bool wxTransferFileToStream(const wxString& filename,
|
|
|
|
ostream& stream);
|
|
|
|
|