OWLNext 7.0
Borland's Object Windows Library for the modern age
|
An abstract base class, TDocument is the base class for all document objects and serves as an interface between the document, its views, and the document manager (TDocManager class). More...
#include <owl/docview.h>
Classes | |
class | TList |
Document list class. More... | |
Public Types | |
enum | TDocProp { PrevProperty = 0 , DocumentClass , TemplateName , ViewCount , StoragePath , DocTitle , NextProperty } |
These property values, which describe the basic properties of a document, are available in classes derived from TDocument. More... | |
typedef TList | List |
Public Member Functions | |
TDocument (TDocument *parent=nullptr) | |
Although you do not create a TDocument object directly, you must call the constructor when you create a derived class. | |
virtual | ~TDocument () |
Deletes a TDocument object. | |
virtual TInStream * | InStream (int mode, LPCTSTR strmId=nullptr) |
Generic input for the particular storage medium, InStream returns a pointer to a TInStream. | |
TInStream * | InStream (int mode, const tstring &streamId) |
virtual TOutStream * | OutStream (int mode, LPCTSTR strmId=nullptr) |
Generic output for the particular storage medium, OutStream returns a pointer to a TOutStream. | |
TOutStream * | OutStream (int mode, const tstring &streamId) |
virtual bool | Open (int mode, LPCTSTR path=nullptr) |
Opens the document using the path specified by DocPath. | |
bool | Open (int mode, const tstring &path) |
virtual bool | Close () |
close document, does not delete or detach | |
virtual bool | Commit (bool force=false) |
save current data, force write | |
virtual bool | Revert (bool clear=false) |
abort changes, no reload if true | |
virtual TDocument & | RootDocument () |
Returns the this pointer as the root document. | |
TDocManager & | GetDocManager () |
Returns a pointer to the current document manager. | |
void | SetDocManager (TDocManager &dm) |
Sets the current document manager to the argument dm. | |
TDocument * | GetParentDoc () |
Returns either the parent document of the current document or 0 if there is no parent document. | |
TDocTemplate * | GetTemplate () |
Gets the template used for document creation. | |
bool | SetTemplate (TDocTemplate *tpl) |
Sets the document template. | |
LPCTSTR | GetDocPath () const |
Returns the directory path for the document. | |
virtual bool | SetDocPath (LPCTSTR path) |
Sets the document path for Open and Save operations. | |
bool | SetDocPath (const tstring &path) |
LPCTSTR | GetTitle () const |
Returns the title of the document. | |
virtual void | SetTitle (LPCTSTR title) |
Sets the title of the document. | |
void | SetTitle (const tstring &title) |
virtual bool | IsDirty () |
Also queries doc and view hierarchy. | |
void | SetDirty (bool dirty=true) |
Updates the document's dirty flag using the specified parameter. | |
virtual bool | IsOpen () |
Checks to see if the document has any streams in its stream list. | |
virtual bool | CanClose () |
Returns false if unable to close. | |
virtual bool | HasFocus (HWND hwnd) |
Document (or child doc) has Focus. | |
virtual TDocument * | DocWithFocus (HWND hwnd) |
Return pointer to this document or one of its child documents if the spcecified window parameter is a view associated with the document. | |
bool | NotifyViews (int eventId, TParam2=0, TView *exclude=nullptr) |
Notifies the views of this document, and the views of any child documents, of a change. | |
bool | NotifyOwnViews (int eventId, TParam2=0, TView *exclude=nullptr) |
Notifies the views of this document of a change. | |
TView * | QueryViews (int eventId, TParam2=0, TView *exclude=nullptr) |
Queries the views of the current document, and the views of any child documents, about a specified event. | |
virtual uint | PostError (uint sid, uint choice=MB_OK) |
Posts the error message passed as a string resource ID in sid. | |
virtual int | PropertyCount () |
Gets the total number of properties for the TDocument object. | |
virtual int | FindProperty (LPCTSTR name) |
return property index | |
int | FindProperty (const tstring &name) |
virtual int | PropertyFlags (int index) |
pfXxxxx bit array | |
virtual LPCTSTR | PropertyName (int index) |
locale invariant name | |
virtual int | GetProperty (int index, void *dest, int textlen=0) |
Retrieves the property identified by the given index. | |
virtual bool | SetProperty (int index, const void *src) |
native type | |
TList & | GetChildren () |
Return reference to the children document list. | |
TView * | GetViewList () const |
Return pointer to the head of the link list of views associated with this document. | |
TView * | NextView (const TView *view) |
Gets the next view in the list of views. Holds 0 if none exists. | |
TStream * | GetStreamList () const |
Returns head of the link list of streams associated with this document. | |
TStream * | NextStream (const TStream *strm) |
Gets the next entry in the stream. Holds 0 if none exists. | |
void * | GetTag () const |
Returns pointer to user-defined data [i.e. tag] attached to this document. | |
void | SetTag (void **tag) |
Attach an arbitrary (user-defined) pointer with this document. | |
int | GetOpenMode () const |
Gets the mode and protection flag values for the current document. | |
void | SetOpenMode (int mode) |
Sets the mode and protection flag values for the current document. | |
TView * | InitView (TView *view) |
called from template InitView | |
bool | IsEmbedded () const |
Returns true if the document is embedded in an OLE 2 container. | |
void | SetEmbedded (bool embed) |
Marks the document as being embedded in an OLE 2 container. | |
virtual bool | InitDoc () |
A virtual method that is overridden by TOleDocument::InitDoc. | |
TDocument (TDocManager *docMan) | |
create a dummy document to hold docmgr | |
Public Member Functions inherited from owl::TStreamableBase | |
virtual | ~TStreamableBase () |
Protected Member Functions | |
virtual void | AttachStream (TStream &strm) |
called from TStream constructor | |
virtual void | DetachStream (TStream &strm) |
called from TStream destructor | |
void | DestroyViews () |
Destroys the views attached to this document. | |
void | DestroyChildren () |
Destroy children first if we have any. | |
Friends | |
class | TDocTemplate |
access to InitView() | |
class | TView |
access to Attach/DetatchView() | |
class | TStream |
access to Attach/DetachStream() | |
class | TDocManager |
class | TList |
access to NextDoc | |
An abstract base class, TDocument is the base class for all document objects and serves as an interface between the document, its views, and the document manager (TDocManager class).
TDocument creates, destroys, and sends messages about the view. For example, if the user changes a document, TDocument tells the view that the document has been updated. The DEFINE_DOC_TEMPLATE_CLASS macro associates a document with its views.
In order to send messages to its associated views, the document maintains a list of all the views existing for that document and communicates with the views using ObjectWindows event-handling mechanism. Rather than using the function SendMessage(), the document accesses the view's event table. The views can update the document's data by calling the member functions of the particular document. Views can also request streams, which are constructed by the document.
Both documents and views have lists of properties for their applications to use. When documents and views are created or destroyed, messages are sent to the application, which can then query the properties to determine how to process the document or view. It is the document manager's responsibility to determine if a particular view is appropriate for the given document.
Because the property attribute functions are virtual, a derived class (which is called first) might override the properties defined in a base class. Each derived class must implement its own property attribute types of either string or binary data. If the derived class duplicates the property names of the parent class, it should provide the same behavior and data type as the parent.
In order to add persistence to documents, TDocument contains several virtual functions (for example, InStream and OutStream) that support streaming. Your derived classes need to override these functions in order to read and write data.
Although documents are usually associated with files, they do not necessarily have to be files; they can also consist of database tables, mail systems, fax or modem transmissions, disk directories, and so on.
These property values, which describe the basic properties of a document, are available in classes derived from TDocument.
They can be used to update and query the attributes of a document. PrevProperty and NextProperty are delimiters for every document's property list. See GetProperty() and SetProperty() for more information.
Although you do not create a TDocument object directly, you must call the constructor when you create a derived class.
parent points to the parent of the new document. If no parent exists, parent is 0.
Definition at line 34 of file document.cpp.
References CHECK, owl::TAppDictionary::GetApplication(), owl::TDocument::TList::Insert(), owl::OWLGetAppDictionary(), and owl::TXOwl::Raise().
|
virtual |
Deletes a TDocument object.
Normally, Close is called first. TDocument's destructor destroys all children and closes all open streams. If this is the last document that used the template, it closes the object's template and any associated views, deletes the object's stream, and removes itself from the parent's list of children if a parent exists. If there is no parent, it removes itself from the document manager's document list.
Definition at line 80 of file document.cpp.
References _T, DestroyChildren(), DestroyViews(), owl::dnClose, owl::TDocManager::PostEvent(), owl::TDocument::TList::Remove(), SetTemplate(), TRACEX, and WARN.
|
inline |
called from TStream constructor
Called from TStream's constructor, AttachStream attaches a stream to the current document.
Definition at line 441 of file document.cpp.
References owl::TStream::NextStream.
|
virtual |
Returns false if unable to close.
Checks to see if all child documents can be closed before closing the current document.
If any child returns false, CanClose returns false and aborts the process. If all children return true, calls TDocManager::FlushDoc. If FlushDoc finds that the document has been changed but not saved, it displays a message asking the user to either save the document, discard any changes, or cancel the operation. If the document has not been changed and all children's CanClose functions return true, this CanClose function returns true.
Reimplemented in ocf::TOleDocument.
Definition at line 775 of file document.cpp.
References owl::TDocManager::FlushDoc(), and owl::TDocument::TList::Next().
|
virtual |
close document, does not delete or detach
Closes the document but does not delete or detach the document.
Before closing the document, Close checks any child documents and tries to close them before closing the parent document. Even if you write your own Close function, call TDocument's version to ensure that all child documents are checked before the parent document is closed.
Reimplemented in ocf::TOleDocument, ocf::TStorageDocument, and owl::TFileDocument.
Definition at line 793 of file document.cpp.
References owl::TDocument::TList::Next().
save current data, force write
Saves the current data to storage.
When a file is closed, the document manager calls either Commit or Revert. If force is true, all data is written to storage. Commit checks any child documents and commits their changes to storage also. Before the current data is saved, all child documents must return true. If all child documents return true, Commit flushes the views for operations that occurred since the last time the view was checked. After all data for the document is updated and saved, Commit returns true.
Reimplemented in ocf::TOleDocument, ocf::TStorageDocument, and owl::TFileDocument.
Definition at line 584 of file document.cpp.
References _T, owl::TDocument::TList::Next(), NotifyViews(), owl::vnCommit, and WARNX.
|
protected |
Destroy children first if we have any.
Then force close here as a last resort if derived classes have not done so. Since we have destructed down to a TDocument by now, derived closes will not be called.
Definition at line 309 of file document.cpp.
References Close(), and owl::TDocument::TList::Destroy().
|
protected |
Destroys the views attached to this document.
Definition at line 318 of file document.cpp.
called from TStream destructor
Called from TStream's destructor, DetachStream detaches the stream from the current document.
Definition at line 452 of file document.cpp.
References owl::TStream::NextStream.
Return pointer to this document or one of its child documents if the spcecified window parameter is a view associated with the document.
Definition at line 755 of file document.cpp.
References owl::TDocument::TList::Next(), QueryViews(), and owl::vnIsWindow.
Definition at line 278 of file docview.h.
References FindProperty().
return property index
Gets the property index, given the property name (name).
Returns either the integer index number that corresponds to the name or 0 if the name isn't found in the list of properties.
Reimplemented in ocf::TStorageDocument, owl::TFileDocument, and owl::TFileDocument.
Definition at line 186 of file document.cpp.
References _T, _tcscmp, NextProperty, PRECONDITION, PrevProperty, and TRACEX.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Retrieves the property identified by the given index.
If the requested property is text, then dest
should point to a text buffer, and textlen
should specify the maximum number of characters the buffer can hold, excluding the terminating null-character, i.e. the buffer must have room for (textlen
+ 1) characters.
If the requested property is numerical, then it may be requested either as text or in its binary form. To request the property as text, pass a text buffer as described above. To request the property in binary form, dest
should point to storage of sufficent size, and textlen
should be zero.
Non-text properties without textual representation, e.g. file handles, may only be requested in binary form, i.e. dest
must point to sufficient storage, and textlen
must be zero.
textlen
is non-zero, which means that the property is requested in string form, the function returns the length of the string, i.e. the character count excluding the terminating null-character. If the parameter textlen
is zero, which means that property is requested in binary form, the return value is the size of the data in bytes.If the property is text, and textlen
is zero, the function fails and returns 0. The function also fails and returns 0 if textlen
is non-zero and the property requested can not be expressed as text. It also returns 0 if the property is not defined.
Reimplemented in ocf::TStorageDocument, and owl::TFileDocument.
Definition at line 224 of file document.cpp.
References _A2W, _OBJ_FULLTYPENAME, _T, _tcslen, _USES_CONVERSION, DocTitle, DocumentClass, owl::TDocTemplate::GetDescription(), StoragePath, TemplateName, TRACEX, and ViewCount.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Document (or child doc) has Focus.
Used by the document manager, HasFocus returns true if this document's view has focus.
hwnd is a handle to the document. to determine if the document contains a view with a focus.
Definition at line 743 of file document.cpp.
References DocWithFocus().
|
inlinevirtual |
A virtual method that is overridden by TOleDocument::InitDoc.
You can use this function to prepare the document before the view is constructed and before the dnCreate event, which indicates that the document has been created and is posted.
Reimplemented in ocf::TOleDocument.
called from template InitView
Initializes the view.
Notifies others a view is created by posting the dnCreate event.
Definition at line 502 of file document.cpp.
References _T, owl::TView::BumpNextViewId(), CHECK, owl::dnCreate, owl::TDocManager::PostEvent(), and TRACEX.
Definition at line 234 of file docview.h.
References InStream().
Generic input for the particular storage medium, InStream returns a pointer to a TInStream.
mode is a combination of the ios bits defined in iostream.h. See the document open mode constants for a list of the open modes. Used for documents that support named streams, strmId is a pointer to the name of a stream. Override this function to provide streaming for your document class.
Reimplemented in owl::TFileDocument, owl::TFileDocument, and ocf::TStorageDocument.
|
virtual |
Also queries doc and view hierarchy.
Returns true if the document or one of its views has changed but has not been saved.
Definition at line 724 of file document.cpp.
References owl::TDocument::TList::Next(), QueryViews(), and owl::vnIsDirty.
|
inline |
|
inlinevirtual |
Checks to see if the document has any streams in its stream list.
Returns false if no streams are open; otherwise, returns true.
Reimplemented in ocf::TStorageDocument, and owl::TFileDocument.
Gets the next entry in the stream. Holds 0 if none exists.
Definition at line 467 of file document.cpp.
References owl::TStream::NextStream.
Gets the next view in the list of views. Holds 0 if none exists.
Definition at line 476 of file document.cpp.
Notifies the views of this document of a change.
Does not notify views of child documents.
The notification message, WM_OWLNOTIFY, is sent with the given eventId, which is private to the particular document class, and a single generic argument, which will be cast to the actual type of the parameter of the response function. If the optional parameter exclude
is set, the appointed view will not be notified.
In contrast to QueryViews, NotifyOwnViews sends the notification message to all views, regardless of the return values. NotifyOwnViews returns true
, if and only if all views return true
. If a view does not handle the notification, then a true
return value is assumed. In other words, NotifyOwnViews will return false
only if a view handles the notification and explicitly returns false
. In any case, all views are notified.
Definition at line 668 of file document.cpp.
References WM_OWLNOTIFY.
Notifies the views of this document, and the views of any child documents, of a change.
The notification message, WM_OWLNOTIFY, is sent with the given eventId, which is private to the particular document class, and a single generic argument, which will be cast to the actual type of the parameter of the response function. If the optional parameter exclude
is set, the appointed view will not be notified.
In contrast to QueryViews, NotifyViews sends the notification message to all views, regardless of the return values. NotifyViews returns true
, if and only if all views return true
. If a view does not handle the notification, then a true
return value is assumed. In other words, NotifyViews will return false
only if a view handles the notification and explicitly returns false
. In any case, all views are notified.
Definition at line 629 of file document.cpp.
References owl::TDocument::TList::Next(), and WM_OWLNOTIFY.
Opens the document using the path specified by DocPath.
Sets OpenMode to mode. TDocument::Open always returns true and actually performs no actions. Other classes override this function to open specified file documents and views.
Reimplemented in ocf::TOleDocument, owl::TFileDocument, owl::TFileDocument, and ocf::TStorageDocument.
|
inline |
Definition at line 236 of file docview.h.
References OutStream().
|
inlinevirtual |
Generic output for the particular storage medium, OutStream returns a pointer to a TOutStream.
mode is a combination of the ios bits defined in iostream.h. Used for documents that support named streams, strmId points to the name of the stream. TDocument::OutStream version always returns 0. Override this function to provide streaming for your document class.
Reimplemented in owl::TFileDocument, owl::TFileDocument, and ocf::TStorageDocument.
Posts the error message passed as a string resource ID in sid.
choice is one or more of the MB_Xxxx style constants.
Definition at line 808 of file document.cpp.
References owl::TDocManager::PostDocError().
|
inlinevirtual |
Gets the total number of properties for the TDocument object.
Returns NextProperty -1.
Reimplemented in ocf::TStorageDocument, and owl::TFileDocument.
Definition at line 904 of file docview.h.
References NextProperty.
pfXxxxx bit array
Returns the attributes of a specified property given the index (index) of the property whose attributes you want to retrieve.
Reimplemented in ocf::TStorageDocument, and owl::TFileDocument.
Definition at line 166 of file document.cpp.
References _T, NextProperty, PrevProperty, and TRACEX.
locale invariant name
Returns the name of the property given the index value (index).
Reimplemented in ocf::TStorageDocument, and owl::TFileDocument.
Definition at line 147 of file document.cpp.
References _T, NextProperty, PrevProperty, and TRACEX.
Queries the views of the current document, and the views of any child documents, about a specified event.
The notification message, WM_OWLNOTIFY, is sent with the given eventId, which is private to the particular document class, and a single generic argument, which will be cast to the actual type of the parameter of the response function. If the optional parameter exclude
is set, the appointed view will not be queried.
In contrast to NotifyViews, the query stops at the first view that returns true
, and the pointer to the view is returned. If no view returns true
, nullptr
is returned.
Definition at line 699 of file document.cpp.
References owl::TDocument::TList::Next(), and WM_OWLNOTIFY.
abort changes, no reload if true
Performs the reverse of Commit() and cancels any changes made to the document since the last commit.
If clear is true, data is not reloaded for views. Revert also checks all child documents and cancels any changes if all children return true. When a file is closed, the document manager calls either Commit() or Revert. Returns true if the operation is successful.
Reimplemented in ocf::TOleDocument, ocf::TStorageDocument, and owl::TFileDocument.
Definition at line 604 of file document.cpp.
References owl::TDocument::TList::Next(), NotifyViews(), and owl::vnRevert.
|
virtual |
Returns the this pointer as the root document.
Definition at line 331 of file document.cpp.
void owl::TDocument::SetDocManager | ( | TDocManager & | dm | ) |
Sets the current document manager to the argument dm.
Definition at line 343 of file document.cpp.
References owl::TDocument::TList::Remove().
Definition at line 255 of file docview.h.
References SetDocPath().
Sets the document path for Open and Save operations.
Reimplemented in ocf::TStorageDocument.
Definition at line 357 of file document.cpp.
References _MAX_PATH, _T, CHECK, COUNTOF, owl::dmMDI, owl::TDocManager::GetApplication(), owl::TDocManager::GetUntitledIndex(), owl::TDocManager::IsFlagSet(), owl::TModule::LoadString(), SetTitle(), and strnewdup().
native type
Sets the value of the property, given index, the index value of the property, and src, the data type (either binary or text) to which the property must be set.
Reimplemented in ocf::TStorageDocument, and owl::TFileDocument.
Definition at line 286 of file document.cpp.
References _T, DocTitle, SetDocPath(), SetTitle(), StoragePath, and TRACEX.
bool owl::TDocument::SetTemplate | ( | TDocTemplate * | tpl | ) |
Sets the document template.
However, if the template type is incompatible with the file, the document manager will refuse to save the file as this template type.
Definition at line 396 of file document.cpp.
References CHECK, owl::TDocManager::RefTemplate(), and owl::TDocManager::UnRefTemplate().
Definition at line 259 of file docview.h.
References SetTitle().
Sets the title of the document.
Definition at line 380 of file document.cpp.
References strnewdup().
|
friend |
|
friend |
access to InitView()