wxArt2D
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
a2dDocument Class Reference

The document class can be used to model an application's file-based data. More...

#include <docviewref.h>

Inheritance diagram for a2dDocument:
Inheritance graph
[legend]
Collaboration diagram for a2dDocument:
Collaboration graph
[legend]

Public Member Functions

 a2dDocument (a2dDocument *parent=(a2dDocument *) NULL)
 Constructor. More...
 
 ~a2dDocument ()
 destructor
 
 a2dDocument (const a2dDocument &other)
 constructor with other document
 
void SetFilename (const wxFileName &filename, bool notifyViews=false)
 Sets the filename for this document. Usually called by the framework. More...
 
wxFileName GetFilename () const
 Get the file name in use for this document.
 
void SetTitle (const wxString &title, bool notifyViews=false)
 Sets the title for this document. More...
 
wxString GetTitle () const
 Returns the title for this document.
 
void SetDocumentTypeName (const wxString &name)
 Sets the document type name for this document. See the comment for documentTypeName.
 
wxString GetDocumentTypeName () const
 Gets the document type name of this document. See the comment for documentTypeName.
 
bool GetDocumentSaved () const
 Returns if the document was saved after a modification.
 
bool IsDocumentSaved () const
 Alias for a2dDocument::GetDocumentSaved.
 
void SetDocumentSaved (bool saved=true)
 Sets the document saved flag. More...
 
bool IsClosed ()
 returns true when document is closed or busy closing. More...
 
bool Close (bool force)
 Closes the document if not vetod. More...
 
bool Save ()
 Saves the document by sending a a2dDocumentEvent ::wxEVT_SAVE_DOCUMENT event. More...
 
bool SaveAs (const wxFileName &fileTosaveTo=wxFileName(wxT("")), a2dDocumentFlagMask flags=a2dREFDOC_NON)
 Tries to save the document by sending a a2dDocumentEvent ::wxEVT_SAVEAS_DOCUMENT event. More...
 
bool Export (a2dDocumentTemplate *doctemplate, const wxFileName &fileTosaveTo=wxFileName(wxT("")), a2dDocumentFlagMask flags=a2dREFDOC_NON)
 Tries to save the document by sending a a2dDocumentEvent ::wxEVT_EXPORT_DOCUMENT event. More...
 
bool Import (a2dDocumentTemplate *doctemplate, const wxFileName &fileToImport=wxFileName(wxT("")), a2dDocumentFlagMask flags=a2dREFDOC_NON)
 Tries to read a file into the document by sending a a2dDocumentEvent ::wxEVT_IMPORT_DOCUMENT event. More...
 
virtual bool Revert ()
 Normally should undo all changes by rereading the file again. More...
 
virtual a2dDocumentInputStreamLoadObject (a2dDocumentInputStream &stream, a2dIOHandlerStrIn *handler)
 handling loading of the document from a stream More...
 
virtual a2dDocumentOutputStreamSaveObject (a2dDocumentOutputStream &stream, a2dIOHandlerStrOut *handler)
 handling saving and exporting of the document to a stream More...
 
void SetLastError (a2dError lastError)
 can be set by a2dIOHandler's by e.g LoadObject(). More...
 
a2dError GetLastError ()
 is set by a2dIOHandler's and is tested by LoadObject(). More...
 
void Load (wxObject *parent, a2dIOHandlerXmlSerIn &parser)
 used by CVG parser More...
 
void Save (wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dObjectList *towrite)
 called from a2dIOHandlerXmlSerOut after a SaveObject. More...
 
void Save (a2dIOHandlerXmlSerOut &out, wxObject *start=NULL)
 called from a2dIOHandlerXmlSerOut after a SaveObject. More...
 
virtual int SaveModifiedDialog (bool canCancel=true)
 dialog when the user needs to confirm saving a document More...
 
virtual void CreateCommandProcessor ()
 create a command processor and set it for the document. More...
 
a2dCommandProcessorGetCommandProcessor () const
 Returns a pointer to the command processor associated with this document.
 
void SetCommandProcessor (a2dCommandProcessor *proc)
 Sets the command processor to be used for this document. More...
 
virtual void DeleteContents ()
 called when there is a need to clear the contents of the document. More...
 
virtual bool Draw (wxDC &context)
 Might be used to draw the contents of a document to a a2dView using a wxDc as the drawing context. More...
 
bool IsModified () const
 Has the document been modified.
 
void Modify (bool mod)
 set the docuent as modified or not More...
 
void AskSaveWhenOwned (bool askSaveWhenOwned)
 Ask to save when document is modified and last view is closed? More...
 
virtual void UpdateAllViews (a2dView *sender=(a2dView *) NULL, unsigned int hint=a2dVIEW_UPDATE_ALL, wxObject *objecthint=(wxObject *) NULL)
 sent Update events to all a2dView which display or use this document. More...
 
void ReportViews (a2dViewList *allviews)
 sents a ::wxEVT_REPORT_VIEWS to all views, via the a2dDocumentCommandProcessor. More...
 
void EnableAllViews (bool enable, a2dView *sender=(a2dView *) NULL)
 calls Enable( true/false ) for each view. More...
 
void DisConnectAllViews ()
 Disconnect a2dView's using this document. More...
 
a2dDocumentTemplateGetDocumentTemplate () const
 Gets a2dDocumentTemplate pointer which was used to create the a2dView.
 
void SetDocumentTemplate (a2dDocumentTemplate *temp)
 Set a2dDocumentTemplate pointer.
 
wxString GetPrintableName () const
 Get title, or filename if no title, else [unnamed].
 
virtual wxWindow * GetAssociatedWindow () const
 Returns a window that can be used as a parent for document-related dialogs. Override if necessary.
 
void SetModificationTime (const wxDateTime &datatime)
 Sets a time of last modification. More...
 
wxDateTime & GetModificationTime ()
 Returns the time of last modification when the document was saved. More...
 
- Public Member Functions inherited from a2dObject
virtual bool ProcessEvent (wxEvent &event)
 
bool SearchDynamicEventTable (wxEvent &event)
 
void Connect (int winid, int lastId, int eventType, wxObjectEventFunction func, wxObject *userData=(wxObject *) NULL, wxEvtHandler *eventSink=(wxEvtHandler *) NULL)
 
bool Disconnect (int winid, int lastId, wxEventType eventType, wxObjectEventFunction func=NULL, wxObject *userData=(wxObject *) NULL, wxEvtHandler *eventSink=(wxEvtHandler *) NULL)
 
void ProcessConnectedEvent (wxEvent &event)
 wxCHECK_VERSION(2,9,0) More...
 
void ConnectEvent (wxEventType type, wxEvtHandler *eventSink)
 
bool DisconnectEvent (wxEventType type, wxEvtHandler *eventSink)
 
bool DisconnectEventAll (wxEvtHandler *eventSink)
 Remove all dynamic events in classA, going to classB (eventSink) More...
 
 a2dObject ()
 constructor
 
virtual ~a2dObject ()
 destructor
 
void operator= (const a2dObject &other)
 assignment operator
 
int GetOwnedBy ()
 like it to be protected, but this does not work with wxList macros More...
 
virtual a2dObjectSetNonDynamic ()
 Call to mark this object as non-dynamic (static/local/auto) More...
 
void CheckReferences ()
 Check zero reference count and delete if count is 0. More...
 
a2dObjectClone (CloneOptions options, a2dRefMap *refs=NULL) const
 create an exact copy of this property
 
 a2dObject (const a2dObject &other, CloneOptions options, a2dRefMap *refs)
 
virtual wxString GetName () const
 Returns the name of this object, if no name is given the internal id will be returned. More...
 
virtual void SetName (const wxString &name)
 Creates the a2dStringProperty PROPID_Name. More...
 
virtual bool IsTemporary_DontSave () const
 Check if this is a temporary object, which should not be saved.
 
void SaveAsDocument (a2dIOHandlerXmlSerOut &out)
 Save this object and all below as an XML document. More...
 
void LoadFromDocument (a2dIOHandlerXmlSerIn &parser)
 Load this object and all below from an XML document. More...
 
wxInt64 GetUniqueSerializationId () const
 return a unique id for this object More...
 
virtual bool AlwaysWriteSerializationId () const
 If true, always write an id. More...
 
virtual bool LinkReference (a2dObject *other)
 link a reference in the object to the given value More...
 
virtual void ResolveInform ()
 inform an object that reference resolution was done More...
 
void Walker (wxObject *parent, a2dWalkerIOHandler &handler)
 This is used to recursively walk through an object tree.
 
void SetCheck (bool check)
 general flag use at will. More...
 
bool GetCheck () const
 general flag use at will.
 
void SetRelease (bool value)
 set release flag More...
 
bool GetRelease () const
 get release flag More...
 
a2dAutoZeroPtr< a2dObject > ** GetAutoZeroPtrList ()
 return the list head pointer for autozero pointers to this object More...
 
 DECLARE_PROPERTIES ()
 
a2dNamedPropertyGetProperty (const a2dPropertyId *propertyId, a2dPropertyId::Flags flags=a2dPropertyId::flag_none) const
 get property on this object More...
 
void SetProperty (a2dNamedProperty *propertyHolder, a2dPropertyId::SetFlags flags=a2dPropertyId::set_none)
 Set the property to the this object. More...
 
void SetProperty (const a2dNamedProperty &propertyHolder, a2dPropertyId::SetFlags flags=a2dPropertyId::set_none)
 Set the property to the this object and if enabled, to all childs and object members. More...
 
virtual a2dNamedPropertyFindProperty (const a2dPropertyId *id, a2dPropertyId::Flags flags=a2dPropertyId::flag_none)
 Find a dynamic property with given id in the property list. More...
 
virtual const a2dNamedPropertyFindProperty (const a2dPropertyId *id, a2dPropertyId::Flags flags=a2dPropertyId::flag_none) const
 Find a dynamic property with given id in the property list. More...
 
virtual bool HasProperty (const a2dPropertyId *id, const wxString &stringvalue=wxEmptyString) const
 Check if the object has a property with given id and string representation. More...
 
virtual void OnPropertyChanged (const a2dPropertyId *id)
 This function is called after a property changed. More...
 
virtual bool EditProperties (const a2dPropertyId *id, bool withUndo=true)
 edit properties of the object More...
 
void TakeOverProperties (a2dObject *from, a2dPropertyIdList *listOfIds)
 Properties in the id list are taken from the given object, en set to this. More...
 
wxURI GetURI () const
 quick way to get to PROPID_URI property More...
 
void SetURI (const wxURI &url)
 quickly set a property PROPID_URI More...
 
const a2dNamedPropertyListGetPropertyList () const
 Get the Property List. More...
 
bool HasDynamicProperties () const
 test if there are dynamic properties in the m_propertylist
 
virtual bool RemoveProperty (const a2dPropertyId *id, bool all=true)
 This function is called by a2dPropertyId to remove a property from the list. More...
 
void RemoveTemporaryProperties ()
 remove all temporary properties
 
virtual bool AddProperty (a2dNamedProperty *property)
 This function is called by a2dPropertyId to add a property to the list. More...
 

Protected Member Functions

a2dObjectDoClone (a2dObject::CloneOptions options, a2dRefMap *refs) const
 Clone document.
 
void OnCreateDocument (a2dDocumentEvent &event)
 default handler for ::wxEVT_CREATE_DOCUMENT, Called after creation of document from a template. More...
 
void OnSaveDocument (a2dDocumentEvent &event)
 Called by wxWindows when a file needs to be saved. More...
 
void OnSaveAsDocument (a2dDocumentEvent &event)
 default handler for a2dDocumentEvent of type ::wxEVT_SAVEAS_DOCUMENT More...
 
void OnOpenDocument (a2dDocumentEvent &event)
 load a document from a file into this document More...
 
void OnNewDocument (a2dDocumentEvent &event)
 called after creating a new document from a template , in order to initialize it. More...
 
void OnCloseDocument (a2dCloseDocumentEvent &event)
 called when document is closed More...
 
void OnCloseView (a2dCloseViewEvent &event)
 Intercept to do cleanup/veto closing of a view. More...
 
void OnRemoveView (a2dDocumentEvent &event)
 what to do when a view using this document will stop using it. More...
 
void OnAddView (a2dDocumentEvent &event)
 what to do when a view starts using this document
 
void OnExportDocument (a2dDocumentEvent &event)
 The default handler for ::wxEVT_EXPORT_DOCUMENT. More...
 
void OnImportDocument (a2dDocumentEvent &event)
 The default handler for ::wxEVT_IMPORT_DOCUMENT. More...
 
- Protected Member Functions inherited from a2dObject
virtual bool DoIgnoreIfNotMember (const a2dPropertyId *id) const
 used to decide if a property shall be ignored, if it is not a member More...
 
virtual void DoWalker (wxObject *parent, a2dWalkerIOHandler &handler)
 iterate over this object and its children More...
 
virtual void DoSave (wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
 Save settings.
 
virtual void DoLoad (wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
 Load settings.
 

Protected Attributes

bool m_askSaveWhenOwned
 Set when Owners become zero and document will be deleted. May also be overruled by user.
 
wxFileName m_documentFile
 Filename associated with this document ("" if none).
 
wxDateTime m_modificationtime
 last modification time when this document was stored.
 
wxString m_documentTitle
 Document title. More...
 
wxString m_documentTypeName
 The document type name given to the a2dDocumentTemplate constructor,. More...
 
a2dDocumentTemplatePtr m_documentTemplate
 A pointer to the template from which this document was created.
 
long m_documentModified
 modified flag
 
a2dDocumentm_documentParent
 parant document if set.
 
a2dSmrtPtr< a2dCommandProcessorm_commandProcessor
 A pointer to the command processor associated with this document.
 
bool m_savedYet
 saved flag
 
bool m_isClosed
 set true when document is closed or when busy closing document.
 
wxUint32 m_id
 This identifies the document in event processing. More...
 
a2dError m_lastError
 error code used when LoadObject is returning.
 
- Protected Attributes inherited from a2dObject
a2dNamedPropertyList m_propertylist
 properties
 
int m_refcount
 how many references to this object do exist
 
bool m_check: 1
 used for linking multiple referenced objects when serializing
 
bool m_release: 1
 when set object is treated as being deleted, and wil be deleted in idle time.
 
bool m_recursion_active: 1
 this is used as a recursion stopper
 
bool m_pendingDisconnects: 1
 
unsigned int m_iteratorCount
 
a2dAutoZeroPtr< a2dObject > * m_autozeroptrlist
 this is a list of all a2dAutoZeroPtr object pointing to this object
 

Friends

class a2dSmrtPtrBase
 

Additional Inherited Members

- Public Types inherited from a2dObject
enum  CloneOptions {
  clone_members = 0x00000001, clone_properties = 0x00000002, clone_childs = 0x00000004, clone_unused = 0x00000008,
  clone_setoriginal = 0x00000010, clone_seteditcopy = 0x00000020, clone_noReference = 0x00000040, clone_noCameleonRef = 0x00000080,
  clone_toDrag = 0x00000100, clone_flat = 0x00000000, clone_deep = clone_members | clone_properties | clone_childs
}
 options for cloning More...
 
typedef a2dAutoZeroPtr< a2dObjectTAutoZeroPtrListClass
 this is needed inside the smart pointer template code
 
- Static Public Attributes inherited from a2dObject
static a2dPropertyIdBoolPROPID_Check = NULL
 used for linking multiple referenced objects when serializing
 
static a2dPropertyIdUriPROPID_URI = NULL
 attach an URL to the object
 
static a2dPropertyIdStringPROPID_Name = NULL
 Name property, to return name of this object.
 
static a2dPropertyIdVoidPtrPROPID_autozeroptrlist = NULL
 
static const a2dSignal sm_Edit_properties = wxNewId()
 edit properties event, see EditProperties()
 
- Protected Types inherited from a2dObject
enum  { refcount_nondynamic = 0x76543210 }
 special refcount value for non-dynamic objects
 

Detailed Description

The document class can be used to model an application's file-based data.

It is part of the document/view framework, and cooperates with the a2dView, a2dDocumentTemplate, a2dViewTemplate and a2dDocumentCommandProcessor classes.

a2dDocument can also be used in a setting with just a2dView's and/or templates, so without a a2dDocumentCommandProcessor controlling most tasks. Most events coming from the document meant for the a2dView (e.g. Update events) will be received, since it is always registered to the document. For others register your wxEvtHandler to recieve events. Therefore if you just want to display the fixed data in the a2dDocument, a a2dDocumentCommandProcessor is not really needed. In the general case with several view and documents, it is best to use a a2dDocumentCommandProcessor.

Events types which can be/are intercepted:

- ::wxEVT_CLOSE_VIEW sent when a view wants to be closed ( may veto )
- ::wxEVT_DISCONNECT_ALLVIEWS sent to document and document manager within DisconnectAllViews().
- ::wxEVT_CLOSE_DOCUMENT sent to document just after calling Close()
- ::wxEVT_ADD_VIEW sent to document just after a view was added to the document
- ::wxEVT_REMOVE_VIEW sent to document just before a view is removed from the document
- ::wxEVT_OPEN_DOCUMENT sent by docmanager when a document was created and opened from a file.
    Default handler loads the file.
- ::wxEVT_NEW_DOCUMENT sent by docmanager when a document was created as new.
    See default handler.
- ::wxEVT_CREATE_DOCUMENT sent after creation of document from a template.
- ::wxEVT_SAVE_DOCUMENT sent to save document ( e.g from Save() )
- ::wxEVT_SAVEAS_DOCUMENT sent to save document under a different name ( e.g from SaveAs() )
- ::wxEVT_EXPORT_DOCUMENT sent to export a document ( e.g from Export())
- ::wxEVT_IMPORT_DOCUMENT sent to export a document ( e.g from Import())
- ::wxEVT_POST_LOAD_DOCUMENT sent just after a document was loaded from a file in LoadObject()
- ::wxEVT_CHANGEDMODIFY_DOCUMENT sent just after a document its modify flag has changed in Modify()
- ::wxEVT_REPORT_VIEWS sent to the event views, to assemble all a2dView using the document.
- ::wxEVT_UPDATE_VIEWS sent when all view need to update them selfs ( e.g. after a change in the document )
    \see UpdateAllViews()
- ::wxEVT_ENABLE_VIEWS sent from EnableAllViews(), to disable or enable all views on the document.
- ::wxEVT_CHANGEDFILENAME_DOCUMENT sent from SetFilename(), when the document its fileinfo has changed.
- ::wxEVT_CHANGEDTITLE_DOCUMENT sent from SetTitle(), when the document its title has changed.

Definition at line 1066 of file docviewref.h.

Constructor & Destructor Documentation

a2dDocument::a2dDocument ( a2dDocument parent = a2dDocument* ) NULL)

Constructor.

The document may have a parent, so a hierachically structure of documents is possible.

Remarks
Current implementation doesn't support a nice access to parent/child docs.
Parameters
parentThe document's parent

Definition at line 335 of file docviewref.cpp.

Member Function Documentation

void a2dDocument::AskSaveWhenOwned ( bool  askSaveWhenOwned)
inline

Ask to save when document is modified and last view is closed?

When there are still owners of the document, and the last view is closed it can either be saved or delayed until the application closes. Setting AskSaveWhenOwned delayes the saving of the data until later.

Definition at line 1338 of file docviewref.h.

bool a2dDocument::Close ( bool  force)

Closes the document if not vetod.

Closing a document means that the application does not want the the document in memory anymore in order to view or modify it. This function prepares the document for deletion.

Sents a ::wxEVT_CLOSE_DOCUMENT event. The default handler is OnCloseDocument( a2dCloseDocumentEvent& event ).

Default calls SaveModifiedDialog(), to give the user a change to save his changes.

This does not normally delete the document object, which only happens if the reference count reaches zero, indicating no more Owners do exist.

See Also
OnCloseDocument
SaveModifiedDialog

Definition at line 457 of file docviewref.cpp.

void a2dDocument::CreateCommandProcessor ( )
virtual

create a command processor and set it for the document.

If available the existing commandprocessor will be deleted. A new CommandProcessor will be created and set for the document.

Override if you need a more application specific commandhandler.

Reimplemented in a2dCanvasDocument.

Definition at line 1107 of file docviewref.cpp.

void a2dDocument::DeleteContents ( )
virtual

called when there is a need to clear the contents of the document.

Override this function to define the way to do this.

Reimplemented in a2dCanvasDocument.

Definition at line 373 of file docviewref.cpp.

void a2dDocument::DisConnectAllViews ( )

Disconnect a2dView's using this document.

It depends on the application if a disconnected view will be closed or not. In case the views will be resused for another document after disconnecting them, obviously they should not be closed. Typically thsi will be the case in a one frame application, where the frame has one or more fixed views, which will be used for the currently open document.

Before starting to disconnect the views, a a2dDocumentEvent type ::wxEVT_DISCONNECT_ALLVIEWS is sent to this a2dDocument, which can be intercepted to do some general cleanup on the document.

In case the a2dView::Close() is called on disconnection, . this generates a a2dCloseViewEvent (type ::wxEVT_CLOSE_VIEW ) sent to the document and the view. The event can not be vetod for this action.

Definition at line 449 of file docviewref.cpp.

bool a2dDocument::Draw ( wxDC &  context)
virtual

Might be used to draw the contents of a document to a a2dView using a wxDc as the drawing context.

You need to override this method in derived class to do something usefull.

Returns
default only returns true

Definition at line 1159 of file docviewref.cpp.

void a2dDocument::EnableAllViews ( bool  enable,
a2dView sender = a2dView* ) NULL 
)

calls Enable( true/false ) for each view.

Enables or disables all views. If sender is non-NULL, does NOT call it for this view. The disabling a a2dView means that it will not process any events, until enabled again.

Definition at line 1195 of file docviewref.cpp.

bool a2dDocument::Export ( a2dDocumentTemplate doctemplate,
const wxFileName &  fileTosaveTo = wxFileName( wxT( "" ) ),
a2dDocumentFlagMask  flags = a2dREFDOC_NON 
)

Tries to save the document by sending a a2dDocumentEvent ::wxEVT_EXPORT_DOCUMENT event.

See Also
OnExportDocument
Returns
true if the document could be saved

Definition at line 700 of file docviewref.cpp.

a2dError a2dDocument::GetLastError ( )
inline

is set by a2dIOHandler's and is tested by LoadObject().

If parsing a document from the stream is incorrect due to formating errors, the handler or LoadObject itself can set this error code.

Definition at line 1248 of file docviewref.h.

wxDateTime& a2dDocument::GetModificationTime ( )
inline

Returns the time of last modification when the document was saved.

Returns
time of last modification

Definition at line 1410 of file docviewref.h.

bool a2dDocument::Import ( a2dDocumentTemplate doctemplate,
const wxFileName &  fileToImport = wxFileName( wxT( "" ) ),
a2dDocumentFlagMask  flags = a2dREFDOC_NON 
)

Tries to read a file into the document by sending a a2dDocumentEvent ::wxEVT_IMPORT_DOCUMENT event.

See Also
OnImportDocument
Returns
true if the document could be read

Definition at line 786 of file docviewref.cpp.

bool a2dDocument::IsClosed ( )
inline

returns true when document is closed or busy closing.

Closing a document in general includes closing its views too. When busy closing a document, this function here can be used to prevent recursive calls elsewhere. You can savely call Close() anyway, but if other actions depends on the document being closed or not, you can check it with this here. A typical example is a closing a document and also releasing it from some higher order class.

See Also
Close() for more.

Definition at line 1147 of file docviewref.h.

void a2dDocument::Load ( wxObject *  parent,
a2dIOHandlerXmlSerIn parser 
)
virtual

used by CVG parser

Remarks
do not use directly

Reimplemented from a2dObject.

Reimplemented in a2dCanvasDocument.

Definition at line 992 of file docviewref.cpp.

a2dDocumentInputStream & a2dDocument::LoadObject ( a2dDocumentInputStream stream,
a2dIOHandlerStrIn handler 
)
virtual

handling loading of the document from a stream

The given handler is used to load the document from the stream.

Override this function to implement your own version. LoadObject is called by the framework automatically when the document contents needs to be loaded.

Note
only one of these forms exists, depending on how wxWindows was configured.

Reimplemented in a2dCanvasDocument.

Definition at line 942 of file docviewref.cpp.

void a2dDocument::Modify ( bool  mod)

set the docuent as modified or not

If the modified status changes an ::wxEVT_CHANGEDMODIFY_DOCUMENT event will be send.

Parameters
modtrue to set document modified, else false

Definition at line 1168 of file docviewref.cpp.

void a2dDocument::OnCloseDocument ( a2dCloseDocumentEvent event)
protected

called when document is closed

Default handler for a2dDocumentEvent of type ::wxEVT_CLOSE_DOCUMENT.

The default implementation, calls SaveModifiedDialog(), and if not canceled, disconnects and/or closes all views using DisconnectAllViews(). This leads to sending ::wxEVT_DISCONNECT_ALLVIEWS to the document and ::wxEVT_CLOSE_VIEW to each view. This enables the program to delete or detach views etc. Next empties the document by calling DeleteContents setting modified flag to false.

Override this to supply additional behaviour when the document is closed with Close.

e.g. In a single document and view approach, you very likely want to call DeleteContents and set the modified flag to false.

Emptying a document while views are using it, is dangerous. Views may refer to or use objects in the document. Therefore the default:

  • closes all views ( holding and display parts of the document, else maybe dangling pointers )
  • clears the undo stack ( which may hold references to objects within the document )
  • empty the document
Remarks
Remember a view also Owns a reference to a document, so certainly all views need to be gone to really get a document deleted.

Definition at line 479 of file docviewref.cpp.

void a2dDocument::OnCloseView ( a2dCloseViewEvent event)
protected

Intercept to do cleanup/veto closing of a view.

The handler function for EVT_CLOSE_VIEW, it is called when the program tries to close a View.

The frame or window containing the view sent a EVT_CLOSE_WINDOW, this results in a EVT_CLOSE_VIEW being sent to the document and to the view. OR The a2dDocumentCommandProcessor is closing all documents plus views.

The a2dCloseViewEvent is generated via the a2dView::Close function, so that the application can also invoke the handler programmatically.

See Also
a2dCloseViewEvent for the way the event is propegated to the several classes in the Objects in docview frame work. framework. If OnCloseView does not veto the close event, the a2dView will futher propegate the event.

The Default implementation: Checks if the view is the last reference for the document; if so, asks user to confirm save data. If AskSaveWhenOwned() == true it will always ask to save the data.

Definition at line 413 of file docviewref.cpp.

void a2dDocument::OnCreateDocument ( a2dDocumentEvent event)
protected

default handler for ::wxEVT_CREATE_DOCUMENT, Called after creation of document from a template.

Called by framework if the documemt is created automatically by the default document manager (via a document template). This gives the document a chance to initialise.

This Default handler does Nothing Yet.

Definition at line 1164 of file docviewref.cpp.

void a2dDocument::OnExportDocument ( a2dDocumentEvent event)
protected

The default handler for ::wxEVT_EXPORT_DOCUMENT.

This method asks for a file, to export/save the document into, using the handler of the event its a2dDocumentTemplate. If a a2dDocumentTemplate was not given as part of the event, the document template of this document is used to search for possible templates to be used for exporting this document. The selection is based on GetDocumentTemplate()->GetDocumentTypeName(). Next a file dialog is presented to select a file to export.

If a filename is part of the event, this is used as initial file to export to in the save dialog. If a2dDocumentFlagMask contains a2dREFDOC_SILENT, no dialog will be presented.

Definition at line 713 of file docviewref.cpp.

void a2dDocument::OnImportDocument ( a2dDocumentEvent event)
protected

The default handler for ::wxEVT_IMPORT_DOCUMENT.

This method asks for a file, to read the document from, using the handler of the event its a2dDocumentTemplate. If a a2dDocumentTemplate was not given as part of the event, the document template of this document is used to search for possible templates to be used for importing into this document. The selection is based on GetDocumentTemplate()->GetDocumentTypeName(). Next a file dialog is presented to select a file to import.

If as part of the event a path+path was already provided, that will be used. If a2dREFDOC_SILENT was set as flag in the event, no dialogs will appear, when a file+path is available.

Definition at line 799 of file docviewref.cpp.

void a2dDocument::OnNewDocument ( a2dDocumentEvent event)
protected

called after creating a new document from a template , in order to initialize it.

called by: a2dDocumentCommandProcessor::CreateDocument() a2dDocumentCommandProcessor::AddCreatedDocument()

Default handler for a2dDocumentEvent of type ::wxEVT_NEW_DOCUMENT.

The default makes a default title for the document, and notifies the views that the filename (in fact, the title) has changed.

The user can intercept the event to fill new documents if empty, but do Skip() the event for the base implementation to be called.

Understand that views might already by open on the document.

Definition at line 502 of file docviewref.cpp.

void a2dDocument::OnOpenDocument ( a2dDocumentEvent event)
protected

load a document from a file into this document

Default handler for a2dDocumentEvent of type ::wxEVT_OPEN_DOCUMENT.

In the default handler SaveModifiedDialog() is called first, and if the document is modified the user is asked to save the changes. Cancel will not open the file into the document.

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.

Remarks
m_documentTemplate must be set for the default handler to work.
Note
only one of these forms exists, depending on how wxWindows was configured.

Definition at line 874 of file docviewref.cpp.

void a2dDocument::OnRemoveView ( a2dDocumentEvent event)
protected

what to do when a view using this document will stop using it.

When a view is switching its document to another document, or when a view is closed, this event is sent to the document just before a2dView releases the document. The default implementation asks to save the document if it was modified, but only if m_askSaveWhenOwned is true or m_refcount has reached 1, which is when only the view itself Own the document. In an application where this document is also controlled by a a2dDocumentCommandProcessor, the refcount would by two. When an application has a fixed set of views (per Frame) used by any document that is shown, it of course makes no sence to automatically close a document when the refcount reaches 1. In a standard "multi child frame+view + document", one can automatically close the document when a refcount of < 2 is reached. Which means when a document its last view is closed, and the document is only owned by the controlling a2dDocumentCommandProcessor. To make this happen intercept the ::wxEVT_REMOVE_VIEW, and implement whatever you need. In this case you should call a2dDocviewGlobals->GetDocviewCommandProcessor()->FileClose() in order to Close the document, which leads to the a2dDocumentCommandProcessor releasing the document. The very last release and therefore deletion will be done in a2dView after returning from the ::wxEVT_REMOVE_VIEW event.

Definition at line 429 of file docviewref.cpp.

void a2dDocument::OnSaveAsDocument ( a2dDocumentEvent event)
protected

default handler for a2dDocumentEvent of type ::wxEVT_SAVEAS_DOCUMENT

Prompts the user for a file to save to.

Notifies the views that the filename has changes by sending ::wxEVT_CHANGEDFILENAME_DOCUMENT. Register your wxEvtHandler to receive it.

Remarks
the document its a2dDocumentTemplate is used to find the right a2dIOHandlerStrOut via a2dDocumentTemplate::GetDocumentIOHandlerForSave().

Definition at line 544 of file docviewref.cpp.

void a2dDocument::OnSaveDocument ( a2dDocumentEvent event)
protected

Called by wxWindows when a file needs to be saved.

Default handler for a2dDocumentEvent of type ::wxEVT_SAVE_DOCUMENT.

Save in the file filename of the document, or call SaveAs if the filename is not set.

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.

event is set Allowed if the file could be opened and the document was saved.

Remarks
the document its a2dDocumentTemplate is used to find the right a2dIOHandlerStrOut via a2dDocumentTemplate::GetDocumentIOHandlerForSave().

Definition at line 632 of file docviewref.cpp.

void a2dDocument::ReportViews ( a2dViewList allviews)

sents a ::wxEVT_REPORT_VIEWS to all views, via the a2dDocumentCommandProcessor.

The a2dView's using this document will report themself by adding itself to the allviews list.

Definition at line 1179 of file docviewref.cpp.

bool a2dDocument::Revert ( )
virtual

Normally should undo all changes by rereading the file again.

Todo:
make a default implementation which does do it ( unless already saved the changes sofar )

Definition at line 1078 of file docviewref.cpp.

bool a2dDocument::Save ( )

Saves the document by sending a a2dDocumentEvent ::wxEVT_SAVE_DOCUMENT event.

The method first tests if the document is modified and not saved yet. If it is modified and not saved, the event is sent.

See Also
OnSaveDocument
Returns
true if the document could be saved

Definition at line 517 of file docviewref.cpp.

void a2dDocument::Save ( wxObject *  parent,
a2dIOHandlerXmlSerOut out,
a2dObjectList towrite 
)
virtual

called from a2dIOHandlerXmlSerOut after a SaveObject.

Parameters
parentparent object from which Save was called
outCVG io handler
towriteobject to write later

Reimplemented from a2dObject.

Reimplemented in a2dCanvasDocument.

Definition at line 1008 of file docviewref.cpp.

void a2dDocument::Save ( a2dIOHandlerXmlSerOut out,
wxObject *  start = NULL 
)

called from a2dIOHandlerXmlSerOut after a SaveObject.

Parameters
outCVG io handler
startstart wrting from this object

Definition at line 1022 of file docviewref.cpp.

bool a2dDocument::SaveAs ( const wxFileName &  fileTosaveTo = wxFileName( wxT( "" ) ),
a2dDocumentFlagMask  flags = a2dREFDOC_NON 
)

Tries to save the document by sending a a2dDocumentEvent ::wxEVT_SAVEAS_DOCUMENT event.

The default handler asks for a file, to save the document into.

See Also
OnSaveAsDocument
Returns
true if the document could be saved

Definition at line 530 of file docviewref.cpp.

int a2dDocument::SaveModifiedDialog ( bool  canCancel = true)
virtual

dialog when the user needs to confirm saving a document

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 and return is wxYES. If No, the document is marked as unmodified and return is wxNO If Cancel return is wxCANCEL. If document was not modified, also wxYES is returned.

Definition at line 1118 of file docviewref.cpp.

a2dDocumentOutputStream & a2dDocument::SaveObject ( a2dDocumentOutputStream stream,
a2dIOHandlerStrOut handler 
)
virtual

handling saving and exporting of the document to a stream

The a2dIOHandler given is used to save the document to the stream.

Override this function to implement your own version. SaveObject is called by the framework automatically when the document contents need to be saved.

Note
only one of these forms exists, depending on how wxWindows was configured.

Reimplemented in a2dCanvasDocument.

Definition at line 1037 of file docviewref.cpp.

void a2dDocument::SetCommandProcessor ( a2dCommandProcessor proc)
inline

Sets the command processor to be used for this document.

Use in case you need one a2dCommandProcessor to be used for several a2dDocument's, Make sure you set it to NULL before deleting the document itself, else the a2dDocument destructor will delete it ( leaving the others with dangling pointers ).

Definition at line 1304 of file docviewref.h.

void a2dDocument::SetDocumentSaved ( bool  saved = true)
inline

Sets the document saved flag.

The document saved flag is normally set by the framework,

Definition at line 1136 of file docviewref.h.

void a2dDocument::SetFilename ( const wxFileName &  filename,
bool  notifyViews = false 
)

Sets the filename for this document. Usually called by the framework.

If notifyViews is true, a a2dDocumentEvent of type ::wxEVT_CHANGEDFILENAME_DOCUMENT. Register your wxEvtHandler to recieve it.

Definition at line 1202 of file docviewref.cpp.

void a2dDocument::SetLastError ( a2dError  lastError)
inline

can be set by a2dIOHandler's by e.g LoadObject().

If parsing a document from the stream is incorrect due to formating errors, the handler or LoadObject itself can set this error code, which result in veto-ing the event.

Definition at line 1241 of file docviewref.h.

void a2dDocument::SetModificationTime ( const wxDateTime &  datatime)
inline

Sets a time of last modification.

Parameters
datatimenew modification time

Definition at line 1404 of file docviewref.h.

void a2dDocument::SetTitle ( const wxString &  title,
bool  notifyViews = false 
)

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. The title may be changed by the programmer or set by an IOHandler

Parameters
titleThe title of the document.
notifyViewsIf true a a2dDocumentEvent of type ::wxEVT_CHANGEDTITLE_DOCUMENT Register your wxEvtHandler to recieve it.

Definition at line 1216 of file docviewref.cpp.

void a2dDocument::UpdateAllViews ( a2dView sender = a2dView* ) NULL,
unsigned int  hint = a2dVIEW_UPDATE_ALL,
wxObject *  objecthint = ( wxObject* ) NULL 
)
virtual

sent Update events to all a2dView which display or use this document.

This function is typicaly called when the document its contents has changed, this in general will result in the a2dView displaying this new information. Understand that this only informs the views to update themselfs, how and what the view needs to update can be indicated by the hints, or in more complex situations the views will read the document contents to see what did change, and only update what changed in its view.

Parameters
senderwhich view did calls this function ( Non = NULL ).
hintupdate will differ on the hint given and the implementation
objecthintmore complex way to deliver hints

Definition at line 1186 of file docviewref.cpp.

Member Data Documentation

wxString a2dDocument::m_documentTitle
protected

Document title.

The document title is used for an associated frame (if any), and is usually constructed by the framework from the filename.

Definition at line 1614 of file docviewref.h.

wxString a2dDocument::m_documentTypeName
protected

The document type name given to the a2dDocumentTemplate constructor,.

is copied to this variable when the document is created.

In a2dDocumentCommandProcessor::AddCreatedDocument() first set this, to search an appropriate template.

It is used later on to select Views from the a2dViewTemplate's. a2dViewTemplate uses the same documentTypeName as a2dDocumentTemplate's.

The same a2dDocument derived class instances, can have a different m_documentTypeName.

If several view templates are created that use the same document type, this variable is used in a2dDocumentCommandProcessor::CreateView to collate a list of alternative view types that can be used on this kind of document.

Definition at line 1631 of file docviewref.h.

wxUint32 a2dDocument::m_id
protected

This identifies the document in event processing.

Not sure, if this is really used for something

Definition at line 1653 of file docviewref.h.


The documentation for this class was generated from the following files:
a2dDocument Class Reference -- Sun Oct 12 2014 17:04:35 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation