11#include <owl/docview.rh>
15#if defined(__BORLANDC__)
49 DocManager = parent->DocManager;
54 if (parent->ParentDoc == parent) {
57 DocManager->DocList.Insert(
this);
60 parent->ChildDoc.
Insert(
this);
68 DocManager->DocList.Insert(
this);
84 if (ParentDoc ==
this)
99 TRACEX(OwlDocView, 0,
_T(
"~TDocument(): StreamList not 0!"));
106 ParentDoc->ChildDoc.Remove(
this);
109 const auto ok = DocManager !=
nullptr;
110 WARN(!ok,
_T(
"TDocument::~TDocument: Terminating due to failed precondition."));
111 if (!ok) std::terminate();
113 DocManager->PostEvent(
dnClose, *
this);
114 DocManager->DocList.Remove(
this);
124static const LPCTSTR PropNames[] = {
125 _T(
"Document Class"),
129 _T(
"Document Title"),
135static int PropFlags[] = {
150 TRACEX(OwlDocView, 0,
_T(
"PropertyName(): index <= PrevProperty!"));
156 TRACEX(OwlDocView, 0,
_T(
"PropertyName(): index >= PrevProperty!"));
169 TRACEX(OwlDocView, 0,
_T(
"PropertyFlags(): index <= PrevProperty!"));
175 TRACEX(OwlDocView, 0,
_T(
"PropertyFlags(): index >= PrevProperty!"));
191 if (
_tcscmp(PropNames[i], name) == 0)
194 TRACEX(OwlDocView, 0,
_T(
"FindProperty: Index of [") << name <<
_T(
"] not found") );
236 src = Template ? Template->GetDescription() :
nullptr;
242 for (view=ViewList, cnt=0; view !=
nullptr; view=view->NextView, cnt++)
248 wsprintf(numBuf,
_T(
"%d"), cnt);
262 TRACEX(OwlDocView, 0,
_T(
"GetProperty(): invalid property [")
263 << index <<
_T(
"] specified!") );
268 TRACEX(OwlDocView, 0,
_T(
"GetProperty(): 0-Length buffer specified!"));
271 int srclen = src ?
static_cast<int>(
::_tcslen(src)) : 0;
272 if (textlen > srclen)
275 memcpy(dest, src, textlen*
sizeof(
tchar));
276 *(
reinterpret_cast<LPTSTR
>(dest) + textlen) = 0;
290 SetTitle(
reinterpret_cast<LPCTSTR
>(src));
294 return SetDocPath(
reinterpret_cast<LPCTSTR
>(src));
297 TRACEX(OwlDocView, 0,
_T(
"SetProperty(): invalid prop [") << prop <<\
334 while (pdoc->ParentDoc)
335 pdoc = pdoc->ParentDoc;
347 DocManager->DocList.Remove(
this);
360 DocPath = (path && *path) ?
strnewdup(path) :
nullptr;
363 if (!DocPath || GetFileTitle(DocPath, title,
COUNTOF(title)) != 0) {
365 CHECK(DocManager->GetApplication());
367 int len = DocManager->GetApplication()->LoadString(IDS_UNTITLED,
369 if (DocManager->IsFlagSet(
dmMDI))
370 wsprintf(title+len,
_T(
"%d"), ++(DocManager->GetUntitledIndex()));
382 if (!Title || title!=Title)
385 Title = title ?
strnewdup(title) :
nullptr;
400 DocManager->UnRefTemplate(*Template);
404 DocManager->RefTemplate(*tpl);
414TDocument::ReindexFrames()
419 for (seq = -1, view = ViewList; view !=
nullptr; view = view->NextView) {
426 seq = (seq == -2 ? 0 : 1);
427 for (view = ViewList; view !=
nullptr; view = view->NextView)
455 for ( ; *plist; plist = &(*plist)->
NextStream) {
456 if (*plist == &strm) {
478 return view ? view->NextView : ViewList;
485TDocument::AttachView(
TView& view)
489 for (ppview = &ViewList; *ppview; ppview = &(*ppview)->NextView)
492 view.NextView =
nullptr;
505 TRACEX(OwlDocView, 0,
_T(
"InitView(): 0 view specified!"));
509 TRACEX(OwlDocView, 0,
_T(
"InitView(): Invalid view object specified!"));
515 DocManager->PostEvent(
dnCreate, *view);
518 TRACEX(OwlDocView, 0,
_T(
"InitView(): Invalid view object post dnCreate!"));
535TDocument::DetachView(
TView& view)
537 TView** plist = &ViewList;
538 for (; *plist; plist = &(*plist)->NextView) {
539 if (*plist == &view) {
544 *plist = view.NextView;
587 while ((pdoc = ChildDoc.Next(pdoc)) !=
nullptr) {
592 WARNX(OwlDocView, !DocPath, 0,
_T(
"Commit(): 0 DocPath!"));
607 while ((pdoc = ChildDoc.Next(pdoc)) !=
nullptr) {
633 for (
auto d = ChildDoc.Next(
nullptr); d; d = ChildDoc.Next(d))
635 bool r = d->NotifyViews(eventId, param, exclude);
636 answer = answer && r;
640 for (
TView* view = ViewList; view !=
nullptr; view = view->NextView)
642 if (view == exclude)
continue;
644 if (view->
Find(eventInfo))
646 bool r = view->
Dispatch(eventInfo, 0, param) != 0;
647 answer = answer && r;
673 for (
TView* view = ViewList; view !=
nullptr; view = view->NextView)
675 if (view == exclude)
continue;
677 if (view->
Find(eventInfo))
679 bool r = view->
Dispatch(eventInfo, 0, param) != 0;
680 answer = answer && r;
703 while ((pdoc = ChildDoc.Next(pdoc)) !=
nullptr)
704 if ((view = pdoc->
QueryViews(eventId, param, exclude)) !=
nullptr)
708 for (view = ViewList; view !=
nullptr; view = view->NextView)
710 if (view == exclude)
continue;
712 if (view->
Find(eventInfo))
713 if (view->
Dispatch(eventInfo, 0, param))
730 while ((pdoc = ChildDoc.Next(pdoc)) !=
nullptr)
758 while ((pdoc = ChildDoc.Next(pdoc)) !=
nullptr)
778 while ((pdoc = ChildDoc.Next(pdoc)) !=
nullptr)
782 return DocManager->FlushDoc(*
this);
796 while ((pdoc = ChildDoc.Next(pdoc)) !=
nullptr)
810 return DocManager->PostDocError(*
this, sid, choice);
821 return doc ? doc->NextDoc : DocList;
831 for (pdoc = DocList; pdoc; pdoc = pdoc->NextDoc)
834 doc->NextDoc = DocList;
846 for (ppdoc = &DocList; *ppdoc; ppdoc = &(*ppdoc)->NextDoc) {
848 *ppdoc = doc->NextDoc;
860 for (
TDocument* pDoc = DocList; pDoc; pDoc = pDoc->NextDoc)
879#if OWL_PERSISTENT_STREAMS
892 o->DirtyFlag =
false;
900 o->DocPath =
_A2W(docPath);
901 o->Title =
_A2W(title);
914 is >> TView::NextViewId;
923TDocument::Streamer::Write(opstream& os)
const
927 while (!o->CanClose())
931 os.fwriteString(
_W2A(o->DocPath));
932 os.fwriteString(
_W2A(o->Title));
936 os << TView::NextViewId;
Definition of class TAppDictionary.
#define WARNX(group, condition, level, message)
#define WARN(condition, message)
#define PRECONDITION(condition)
#define TRACEX(group, level, message)
TApplication * GetApplication(uint pid=0)
Looks up and returns the application associated with a given process ID.
Derived from TModule and TMsgThread and virtually derived from TEventHandler, TApplication acts as an...
TDocManager * GetDocManager()
Return the current document manager.
virtual void PostEvent(int id, TDocument &doc)
changed doc status
bool Contains(TDocument *doc)
Checks if doc is contained in the list.
bool Remove(TDocument *doc)
Removes a document from the document list, fails if not there.
void Destroy()
Deletes all documents.
TDocument * Next(const TDocument *doc)
If the doc parameter is 0, Next returns the first document in the list of documents.
bool Insert(TDocument *doc)
Inserts a new document into the document list. Fails if the document already exists.
An abstract base class, TDocument is the base class for all document objects and serves as an interfa...
friend class TView
access to Attach/DetatchView()
TDocument(TDocument *parent=nullptr)
Although you do not create a TDocument object directly, you must call the constructor when you create...
TStream * NextStream(const TStream *strm)
Gets the next entry in the stream. Holds 0 if none exists.
void DestroyViews()
Destroys the views attached to this document.
virtual int GetProperty(int index, void *dest, int textlen=0)
Retrieves the property identified by the given index.
virtual int FindProperty(LPCTSTR name)
return property index
TView * NextView(const TView *view)
Gets the next view in the list of views. Holds 0 if none exists.
void SetDocManager(TDocManager &dm)
Sets the current document manager to the argument dm.
virtual void DetachStream(TStream &strm)
called from TStream destructor
bool NotifyOwnViews(int eventId, TParam2=0, TView *exclude=nullptr)
Notifies the views of this document of a change.
virtual TDocument & RootDocument()
Returns the this pointer as the root document.
friend class TDocTemplate
access to InitView()
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.
virtual bool SetProperty(int index, const void *src)
native type
friend class TStream
access to Attach/DetachStream()
virtual bool HasFocus(HWND hwnd)
Document (or child doc) has Focus.
virtual bool CanClose()
Returns false if unable to close.
bool SetTemplate(TDocTemplate *tpl)
Sets the document template.
virtual LPCTSTR PropertyName(int index)
locale invariant name
virtual bool Close()
close document, does not delete or detach
virtual int PropertyFlags(int index)
pfXxxxx bit array
void DestroyChildren()
Destroy children first if we have any.
TView * InitView(TView *view)
called from template InitView
virtual ~TDocument()
Deletes a TDocument object.
virtual void AttachStream(TStream &strm)
called from TStream constructor
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 ev...
virtual void SetTitle(LPCTSTR title)
Sets the title of the document.
virtual TDocument * DocWithFocus(HWND hwnd)
Return pointer to this document or one of its child documents if the spcecified window parameter is a...
virtual bool SetDocPath(LPCTSTR path)
Sets the document path for Open and Save operations.
virtual bool IsDirty()
Also queries doc and view hierarchy.
@ TemplateName
text property: Name of template attached to document
@ PrevProperty
Index of last property in base class (none in this case).
@ StoragePath
text property: Identifies object holding data of this document
@ NextProperty
Next index to be used by derived class.
@ ViewCount
int property: Number of views displaying this document
@ DocumentClass
text Property: Name of C++ class encapsulating document
@ DocTitle
text property: Caption of this document
virtual bool IsOpen()
Checks to see if the document has any streams in its stream list.
virtual bool Commit(bool force=false)
save current data, force write
virtual uint PostError(uint sid, uint choice=MB_OK)
Posts the error message passed as a string resource ID in sid.
virtual bool Revert(bool clear=false)
abort changes, no reload if true
A nested class, TEventInfo provides specific information about the type of message sent,...
virtual bool Find(TEventInfo &info, TEqualOperator op=0)
Searches the list of response table entries looking for a match.
TResult Dispatch(TEventInfo &info, TParam1, TParam2=0)
Takes the message data from TEventInfo's Msg data member and dispatches it to the correct event-handl...
An abstract base class, TStream provides links between streams and documents, views,...
TStream * NextStream
Points to the next stream in the list of active streams.
Abstract base class for view access from document.
bool IsOK()
true if successfully created
virtual bool SetDocTitle(LPCTSTR docname, int index)
Stores the document title.
virtual TWindow * GetWindow()
Returns the TWindow instance associated with the view, or 0 if no view exists.
static void BumpNextViewId()
Increments an internal count used by the Doc/View subsystem to identify each view.
HWND GetHandle() const
Returns the handle of the window.
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
char * freadString()
Reads a string from the stream.
Definition of class TDocManager.
#define _OBJ_FULLTYPENAME(obj)
const uint dtAutoDelete
delete doc when last view is deleted
const uint pfGetText
property accessible as text format
const uint vnViewOpened
a new view has just been constructed
const uint vnViewClosed
another view is about to be destructed
const uint pfConstant
property is invariant for object instance
const uint vnCommit
document is committing, flush cached changes
const uint dtAutoOpen
open document upon creation
const uint pfSettable
property settable as native format
const uint vnRevert
document has reverted, reload data from doc
const uint vnIsWindow
respond true if passed HWND is that of view
const uint vnIsDirty
respond true if uncommitted changes present
const uint pfGetBinary
property accessible as native non-text format
const uint dmMDI
Supports multiple open documents.
@ dnCreate
New document or view has been created.
@ dnClose
Document or view has been closed.
static void Raise(const tstring &msg, uint resId=0)
char * strnewdup(const char *s, size_t minAllocSize=0)
Object Windows Library (OWLNext Core).
LPARAM TParam2
Second parameter type.
TAppDictionary & OWLGetAppDictionary()
Global exported TAppDictionary in Owl.
IMPLEMENT_ABSTRACT_STREAMABLE(TDocTemplate)
DIAG_DECLARE_GROUP(OwlThread)
#define COUNTOF(s)
Array element count Important: Only use this with an argument of array type.
Definition of class TString, a flexible universal string envelope class.