#include <wx/docview.h>
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.
A normal document is the one created without parent document and is associated with a disk file. Since version 2.9.2 wxWidgets also supports a special kind of documents called child documents which are virtual in the sense that they do not correspond to a file but rather to a part of their parent document. Because of this, the child documents can't be created directly by user but can only be created by the parent document (usually when it's being created itself). They also can't be independently saved. A child document has its own view with the corresponding window. This view can be closed by user but, importantly, is also automatically closed when its parent document is closed. Thus, child documents may be convenient for creating additional windows which need to be closed when the main document is. The docview sample demonstrates this use of child documents by creating a child document containing the information about the parameters of the image opened in the main document.
Public Member Functions | |
wxDocument (wxDocument *parent=NULL) | |
Constructor. More... | |
virtual | ~wxDocument () |
Destructor. More... | |
virtual bool | AddView (wxView *view) |
If the view is not already in the list of views, adds the view and calls OnChangedViewList(). More... | |
bool | AlreadySaved () const |
Returns true if the document hasn't been modified since the last time it had been saved. More... | |
void | Activate () const |
Activate the first view of the document if any. More... | |
virtual bool | Close () |
Closes the document, by calling OnSaveModified() and then (if this returned true) OnCloseDocument(). More... | |
virtual bool | DeleteAllViews () |
Calls wxView::Close() and deletes each view. More... | |
virtual bool | DeleteContents () |
Virtual method called from OnCloseDocument(). More... | |
virtual wxCommandProcessor * | GetCommandProcessor () const |
Returns a pointer to the command processor associated with this document. More... | |
virtual wxDocManager * | GetDocumentManager () const |
Gets a pointer to the associated document manager. More... | |
wxString | GetDocumentName () const |
Gets the document type name for this document. More... | |
bool | GetDocumentSaved () const |
Return true if this document had been already saved. More... | |
virtual wxDocTemplate * | GetDocumentTemplate () const |
Gets a pointer to the template that created the document. More... | |
virtual wxWindow * | GetDocumentWindow () const |
Intended to return a suitable window for using as a parent for document-related dialog boxes. More... | |
wxString | GetFilename () const |
Gets the filename associated with this document, or "" if none is associated. More... | |
wxView * | GetFirstView () const |
A convenience function to get the first view for a document, because in many cases a document will only have a single view. More... | |
wxString | GetTitle () const |
Gets the title for this document. More... | |
virtual wxString | GetUserReadableName () const |
Return the document name suitable to be shown to the user. More... | |
wxViewVector | GetViewsVector () const |
Returns a vector of wxView pointers. More... | |
bool | IsChildDocument () const |
Returns true if this document is a child document corresponding to a part of the parent document and not a disk file as usual. More... | |
virtual bool | IsModified () const |
Returns true if the document has been modified since the last save, false otherwise. More... | |
virtual void | Modify (bool modify) |
Call with true to mark the document as modified since the last save, false otherwise. More... | |
virtual void | OnChangedViewList () |
Called when a view is added to or deleted from this document. More... | |
virtual bool | OnCloseDocument () |
This virtual function is called when the document is being closed. More... | |
virtual bool | OnCreate (const wxString &path, long flags) |
Called just after the document object is created to give it a chance to initialize itself. More... | |
virtual wxCommandProcessor * | OnCreateCommandProcessor () |
Override this function if you want a different (or no) command processor to be created when the document is created. More... | |
virtual bool | OnNewDocument () |
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. More... | |
virtual bool | OnOpenDocument (const wxString &filename) |
Constructs an input file stream for the given filename (which must not be empty), and calls LoadObject(). More... | |
virtual bool | OnSaveDocument (const wxString &filename) |
Constructs an output file stream for the given filename (which must not be empty), and calls SaveObject(). More... | |
virtual bool | OnSaveModified () |
If the document has been modified, prompts the user to ask if the changes should be saved. More... | |
virtual bool | RemoveView (wxView *view) |
Removes the view from the document's list of views, and calls OnChangedViewList(). More... | |
virtual bool | Save () |
Saves the document by calling OnSaveDocument() if there is an associated filename, or SaveAs() if there is no filename. More... | |
virtual bool | SaveAs () |
Prompts the user for a file to save to, and then calls OnSaveDocument(). More... | |
virtual bool | Revert () |
Discard changes and load last saved version. More... | |
virtual void | SetCommandProcessor (wxCommandProcessor *processor) |
Sets the command processor to be used for this document. More... | |
void | SetDocumentName (const wxString &name) |
Sets the document type name for this document. More... | |
virtual void | SetDocumentTemplate (wxDocTemplate *templ) |
Sets the pointer to the template that created the document. More... | |
void | SetDocumentSaved (bool saved=true) |
Sets if this document has been already saved or not. More... | |
void | SetFilename (const wxString &filename, bool notifyViews=false) |
Sets the filename for this document. More... | |
virtual void | OnChangeFilename (bool notifyViews) |
If notifyViews is true, wxView::OnChangeFilename() is called for all views. More... | |
void | SetTitle (const wxString &title) |
Sets the title for this document. More... | |
virtual void | UpdateAllViews (wxView *sender=NULL, wxObject *hint=NULL) |
Updates all views. More... | |
wxList & | GetViews () |
Returns the list whose elements are the views on the document. More... | |
const wxList & | GetViews () const |
Returns the list whose elements are the views on the document. More... | |
virtual istream & | LoadObject (istream &stream) |
Override this function and call it from your own LoadObject() before streaming your own data. More... | |
virtual wxInputStream & | LoadObject (wxInputStream &stream) |
Override this function and call it from your own LoadObject() before streaming your own data. More... | |
virtual ostream & | SaveObject (ostream &stream) |
Override this function and call it from your own SaveObject() before streaming your own data. More... | |
virtual wxOutputStream & | SaveObject (wxOutputStream &stream) |
Override this function and call it from your own SaveObject() before streaming your own data. 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... | |
virtual bool | SearchEventTable (wxEventTable &table, wxEvent &event) |
Searches the event table, executing an event handler function if an appropriate one is found. 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 bool | DoSaveDocument (const wxString &file) |
This method is called by OnSaveDocument() to really save the document contents to the specified file. More... | |
virtual bool | DoOpenDocument (const wxString &file) |
This method is called by OnOpenDocument() to really load the document contents from the specified file. 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 | |
wxCommandProcessor * | m_commandProcessor |
A pointer to the command processor associated with this document. More... | |
wxString | m_documentFile |
Filename associated with this document ("" if none). More... | |
bool | m_documentModified |
true if the document has been modified, false otherwise. More... | |
wxDocTemplate * | m_documentTemplate |
A pointer to the template from which this document was created. More... | |
wxString | m_documentTitle |
Document title. More... | |
wxString | m_documentTypeName |
The document type name given to the wxDocTemplate constructor, copied to this variable when the document is created. More... | |
wxList | m_documentViews |
List of wxView instances associated with this document. 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... | |
wxDocument::wxDocument | ( | wxDocument * | parent = NULL | ) |
Constructor.
Define your own default constructor to initialize application-specific data.
parent | Specifying a non-NULL parent document here makes this document a special child document, see their description in the class documentation. Notice that this parameter exists but is ignored in wxWidgets versions prior to 2.9.1. |
|
virtual |
Destructor.
Removes itself from the document manager.
void wxDocument::Activate | ( | ) | const |
Activate the first view of the document if any.
This function simply calls the Raise() method of the frame of the first view. You may need to override the Raise() method to get the desired effect if you are not using a standard wxFrame for your view. For instance, if your document is inside its own notebook tab you could implement Raise() like this:
|
virtual |
If the view is not already in the list of views, adds the view and calls OnChangedViewList().
bool wxDocument::AlreadySaved | ( | ) | const |
Returns true if the document hasn't been modified since the last time it had been saved.
Notice that this function returns false if the document had been never saved at all, so it may be also used to test whether it makes sense to save the document: if it returns true, there is nothing to save but if false is returned, it can be saved, even if it might be not modified (this can be used to create an empty document file by the user).
|
virtual |
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 |
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 |
Virtual method called from OnCloseDocument().
This method may be overridden to perform any additional cleanup which might be needed when the document is closed.
The return value of this method is currently ignored.
The default version does nothing and simply returns true.
|
protectedvirtual |
This method is called by OnOpenDocument() to really load the document contents from the specified file.
Base class version creates a file-based stream and calls LoadObject(). Override this if you need to do something else or prefer not to use LoadObject() at all.
|
protectedvirtual |
This method is called by OnSaveDocument() to really save the document contents to the specified file.
Base class version creates a file-based stream and calls SaveObject(). Override this if you need to do something else or prefer not to use SaveObject() at all.
|
virtual |
Returns a pointer to the command processor associated with this document.
|
virtual |
Gets a pointer to the associated document manager.
wxString wxDocument::GetDocumentName | ( | ) | const |
Gets the document type name for this document.
See the comment for m_documentTypeName.
bool wxDocument::GetDocumentSaved | ( | ) | const |
Return true if this document had been already saved.
|
virtual |
Gets a pointer to the template that created the document.
|
virtual |
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.
wxString wxDocument::GetFilename | ( | ) | const |
Gets the filename associated with this document, or "" if none is associated.
wxView* wxDocument::GetFirstView | ( | ) | const |
A convenience function to get the first view for a document, because in many cases a document will only have a single view.
wxString wxDocument::GetTitle | ( | ) | const |
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.
|
virtual |
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 unnamed.
wxList& wxDocument::GetViews | ( | ) |
Returns the list whose elements are the views on the document.
const wxList& wxDocument::GetViews | ( | ) | const |
Returns the list whose elements are the views on the document.
wxViewVector wxDocument::GetViewsVector | ( | ) | const |
Returns a vector of wxView pointers.
bool wxDocument::IsChildDocument | ( | ) | const |
Returns true if this document is a child document corresponding to a part of the parent document and not a disk file as usual.
This method can be used to check whether file-related operations make sense for this document as they only apply to top-level documents and not child ones.
|
virtual |
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.
|
virtual |
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.
|
virtual |
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.
|
virtual |
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.
|
virtual |
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 |
If notifyViews is true, wxView::OnChangeFilename() is called for all views.
|
virtual |
This virtual function is called when the document is being closed.
The default implementation calls DeleteContents() (which may be overridden to perform additional cleanup) and sets the modified flag to false. You can override it to supply additional behaviour when the document is closed with Close().
Notice that previous wxWidgets versions used to call this function also from OnNewDocument(), rather counter-intuitively. This is no longer the case since wxWidgets 2.9.0.
|
virtual |
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.
For compatibility reasons, this method may either delete the document itself if its initialization fails or not do it in which case it is deleted by caller. It is recommended to delete the document explicitly in this function if it can't be initialized.
path | The associated file path. |
flags | Flags passed to CreateDocument(). |
|
virtual |
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.
|
virtual |
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 |
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 |
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 |
If the document has been modified, prompts the user to ask if the changes should be saved.
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 |
Removes the view from the document's list of views, and calls OnChangedViewList().
|
virtual |
Discard changes and load last saved version.
Prompts the user first, and then calls DoOpenDocument() to reload the current file.
|
virtual |
Saves the document by calling OnSaveDocument() if there is an associated filename, or SaveAs() if there is no filename.
|
virtual |
Prompts the user for a file to save to, and then calls OnSaveDocument().
|
virtual |
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.
|
virtual |
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.
|
virtual |
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.
void wxDocument::SetDocumentName | ( | const wxString & | name | ) |
Sets the document type name for this document.
See the comment for m_documentTypeName.
void wxDocument::SetDocumentSaved | ( | bool | saved = true | ) |
Sets if this document has been already saved or not.
Normally there is no need to call this function as the document-view framework does it itself as the documents are loaded from and saved to the files. However it may be useful in some particular cases, for example it may be called with false argument to prevent the user from saving the just opened document into the same file if this shouldn't be done for some reason (e.g. file format version changes and a new extension should be used for saving).
|
virtual |
Sets the pointer to the template that created the document.
Should only be called by the framework.
void wxDocument::SetFilename | ( | const wxString & | filename, |
bool | notifyViews = false |
||
) |
Sets the filename for this document.
Usually called by the framework.
Calls OnChangeFilename() which in turn calls wxView::OnChangeFilename() for all views if notifyViews is true.
void wxDocument::SetTitle | ( | const wxString & | title | ) |
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.
Updates all views.
If sender is non-NULL, does not update this view. hint represents optional information to allow a view to optimize its update.
|
protected |
A pointer to the command processor associated with this document.
|
protected |
Filename associated with this document ("" if none).
|
protected |
true if the document has been modified, false otherwise.
|
protected |
A pointer to the template from which this document was created.
|
protected |
Document title.
The document title is used for an associated frame (if any), and is usually constructed by the framework from the filename.
|
protected |
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.
|
protected |
List of wxView instances associated with this document.