OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
doctpl.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1993, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Definition of class TDocTemplate, and class template TDocTemplateT<D,V>
7//----------------------------------------------------------------------------
8#if !defined(OWL_DOCTPL_H)
9#define OWL_DOCTPL_H
10
11#include <owl/private/defs.h>
12#if defined(BI_HAS_PRAGMA_ONCE)
13# pragma once
14#endif
15
16#include <owl/defs.h>
17#include <owl/registry.h>
18#include <owl/objstrm.h>
19#include <owl/private/gmodule.h>
20
21# define _DOCVIEWENTRY
22
23
24namespace owl {class _OWLCLASS TDocTemplate;};
25
26
27//
28/// Templates constructed before app get linked onto this head pointer
29//
31
32namespace owl {
33
34/// \addtogroup docview
35/// @{
36
37class _OWLCLASS TDocManager;
38class _OWLCLASS TModule;
39class _OWLCLASS TDocument;
40class _OWLCLASS TView;
41
42#include <owl/preclass.h>
43
44//
45/// \class TDocTemplate
46// ~~~~~ ~~~~~~~~~~~~
47/// TDocTemplate is an abstract base class that contains document template
48/// functionality. This document template class defines several functions that make
49/// it easier for you to use documents and their corresponding views. TDocTemplate
50/// classes create documents and views from resources and handle document naming and
51/// browsing. The document manager maintains a list of the current template objects.
52/// Each document type requires a separate document template.
53//
55 public:
56
57/// A pure virtual function that must be defined in a derived class, ConstructDoc
58/// creates a document specified by the document template class. Use this function
59/// in place of CreateDoc.
60 virtual TDocument* ConstructDoc(TDocument* parent = nullptr) = 0;
61
62/// A pure virtual function that must be defined in a derived class, ConstructView
63/// creates the view specified by the document template class.
65
66/// A pure virtual function that must be defined in a derived class, IsMyKindOfDoc
67/// tests if the template belongs to the same class as the document or to a derived
68/// class.
70
71/// A pure virtual function that must be defined in a derived class, IsMyKindofView
72/// tests if the template belongs to the same class as the view or to a derived
73/// class.
75
76/// A pure virtual function that must be defined in a derived class, GetViewName
77/// gets the name of the view associated with the template.
78 virtual LPCTSTR GetViewName() = 0;
79
80 bool IsVisible(); ///< displayable in file select dialogs
81
82/// Makes a copy of a document template.
83#if !defined (BI_GLOBALNM_BUG)
84 virtual TDocTemplate* Clone(TModule* module,
86#else
87 virtual TDocTemplate* Clone(TModule* module,
89#endif
90
91 TDocManager* GetDocManager() const;
92 void SetDocManager(TDocManager* dm);
93 LPCTSTR GetDirectory() const;
94 void SetDirectory(LPCTSTR);
95 void SetDirectory(LPCTSTR, int len);
96 TDocTemplate* GetNextTemplate() const;
97 bool IsFlagSet(long flag) const;
98 long GetFlags() const;
99 void SetFlag(long flag);
100 void ClearFlag(long flag);
101 bool IsStatic() const;
102 TModule*& GetModule();
103 void SetModule(TModule* module);
104 int GetRefCount() const;
105
106 LPCTSTR GetFileFilter() const;
107 LPCTSTR GetDescription() const;
108 LPCTSTR GetDefaultExt() const;
109
110 protected: // Called only from parameterized derived class
113
114 private:
115 tchar * Directory; ///< Current directory path, 0 until changed
116 long Flags; ///< dtXxx bits for dialogs and creation modes
117 TDocManager* DocManager; ///< Pointer back to document manager
118 LONG RefCnt; ///< Documents attached + 1 if attached to docmgr
119 TModule** ModulePtr; ///< Would be TModule*&, except for streaming
120 TModule* ModuleDeref; ///< Used only when setting a new module
121
122 protected: // Called only from parameterized derived class
124 LPCTSTR dir, LPCTSTR ext, long flags,
125 TModule*& module, TDocTemplate*& phead);
126
127 friend class TDocument; // access to RefCnt
128 friend class TDocManager;
130};
131
133
134#define DECLARE_STREAMABLE_OPSDV( cls ) \
135static ipstream& readRef( ipstream& is, cls& cl ); \
136friend inline ipstream& operator >> ( ipstream& is, cls& cl ) \
137 { return cls::readRef( is, cl ); } \
138static ipstream& readPtr( ipstream& is, cls*& cl ); \
139friend inline ipstream& operator >> ( ipstream& is, cls*& cl ) \
140 { return cls::readPtr( is, cl ); } \
141static opstream& writeRef( opstream& is, const cls& cl ); \
142friend inline opstream& operator << ( opstream& os, const cls& cl ) \
143 { return cls::writeRef( os, cl ); } \
144static opstream& writePtr( opstream& is, const cls* cl ); \
145friend inline opstream& operator << ( opstream& os, const cls* cl ) \
146 { return cls::writePtr( os, cl ); }
147
148//
149// class TDocTemplateT<D,V>
150// ~~~~~ ~~~~~~~~~~~~~~~~~~
151/// To register the associated document and view classes, a parameterized subclass,
152/// TDocTemplateT<D,V>, is used to construct a particular document and view, where D
153/// represents the document class and V represents the view class. The parameterized
154/// template classes are created using a macro, which also generates the associated
155/// streamable support. The document and view classes are provided through the use
156/// of a parameterized subclass. The template class name is used as a typedef for
157/// the parameterized class. For example,
158/// \code
159/// DEFINE_DOC_TEMPLATE_CLASS(TFileDocument, TEditView, MyEditFile)
160/// \endcode
161/// You can instantiate a document template using either a static member or an
162/// explicit construction. For example,
163/// \code
164/// MyEditFile et1(_T("Edit text files"),
165/// T("*.txt"),T("D:\\doc"),_T(".TXT"),dtNoAutoView);
166/// new MyEditFile(.....)
167/// \endcode
168/// When a document template is created, the document manager (TDocManager)
169/// registers the template. When the document template's delete function is called
170/// to delete the template, it is no longer visible to the user. However, it remains
171/// in memory as long as any documents still use it.
172//
173template<class D, class V>
175 public:
179 LPCTSTR dir, LPCTSTR ext, long flags = 0,
180 TModule*& module = owl::Module,
182#if !defined (BI_GLOBALNM_BUG)
183 TDocTemplateT* Clone(TModule* module,
185#else
186 TDocTemplateT* Clone(TModule* module,
188#endif
189
190 D* ConstructDoc(TDocument* parent = nullptr);
192 D* IsMyKindOfDoc(TDocument& doc); ///< Returns 0 if template can't support
193 V* IsMyKindOfView(TView& view); ///< Returns 0 if template incompatible
194
195 virtual LPCTSTR GetViewName();
196
197#if OWL_PERSISTENT_STREAMS
198 // Explicit expansion of DECLARE_STREAMABLE for use with parameterized class
199 // DECLARE_STREAMABLE_FROM_BASE(TDocTemplateT<D,V>);
200 //
206#endif
207};
208
209#include <owl/posclass.h>
210
211//----------------------------------------------------------------------------
212// Template flags used in reg parameter "docflags"
213//
214
215//
216// Definitions of dtXxx document/view flags for templates and CreateDoc()
217//
218const uint dtNewDoc = 0x80000000L; ///< create new document, no path used
219const uint dtAutoDelete = 0x40000000L; ///< delete doc when last view is deleted
220const uint dtNoAutoView = 0x20000000L; ///< no automatic create of default view
221const uint dtSingleView = 0x10000000L; ///< only a single view per document
222const uint dtAutoOpen = 0x08000000L; ///< open document upon creation
223const uint dtUpdateDir = 0x04000000L; ///< syncronize directory with dialog dir
224const uint dtHidden = 0x02000000L; ///< hide template from user selection
225const uint dtSelected = 0x01000000L; ///< indicates template last selected
226const uint dtDynRegInfo = 0x00800000L; ///< reginfo table is dynamic, not static
227const uint dtSingleUse = 0x00400000L; ///< to be registered as single use
228const uint dtRegisterExt= 0x00200000L; ///< register extension with this app
229const uint dtForbidNew = 0x00100000L; ///< forbids creating new document
230
231//
232// Flags defined by Windows in <commdlg.h> - use the low order 17 bits
233//
234const uint dtReadOnly = 0x0001; //OFN_READONLY; ///< initial check readonly box
235const uint dtOverwritePrompt= 0x0002; //OFN_OVERWRITEPROMPT; ///< prompt before overwrite
236const uint dtHideReadOnly = 0x0004; //OFN_HIDEREADONLY; ///< no show readonly box
237const uint dtPathMustExist = 0x0800; //OFN_PATHMUSTEXIST; ///< path must be valid
238const uint dtFileMustExist = 0x1000; //OFN_FILEMUSTEXIST; ///< file must exist
239const uint dtCreatePrompt = 0x2000; //OFN_CREATEPROMPT; ///< prompt before create
240const uint dtNoReadOnly = 0x8000; //OFN_NOREADONLYRETURN; ///< return writable file
241const uint dtNoTestCreate = 0x10000L;//OFN_NOTESTFILECREATE; ///< skip create tests;
242
243/// @}
244
245
246
247//----------------------------------------------------------------------------
248// Inline implementations
249//
250
251//
252/// Points to the document manager.
253//
255{
256 return DocManager;
257}
258
259//
260/// Sets the current document manager to the argument dm.
261//
263{
264 DocManager = dm;
265}
266
267//
268/// Gets the next template in the list of templates.
269//
271{
272 return static_cast<TDocTemplate*>(Next);
273}
274
275//
276/// Returns nonzero if the document template flag is set.
277//
278inline bool TDocTemplate::IsFlagSet(long flag) const
279{
280 return (GetFlags() & flag) != 0;
281}
282
283//
284/// Gets the document template constants, which indicate how the document is created
285/// and opened.
286//
287inline long TDocTemplate::GetFlags() const
288{
289 return Flags;
290}
291
292//
293/// Returns true if the template is statically constructed.
294//
295inline bool TDocTemplate::IsStatic() const
296{
297 return (RefCnt & 0x8000) != 0;
298}
299
300//
301/// Returns a module pointer.
302//
304{
305 return *ModulePtr;
306}
307
308//
309/// Return the number of reference count of the template.
310/// \note The reference count of static templates has the high bit set.
311//
313{
314 return RefCnt;
315}
316
317//
318/// Sets a module pointer.
319//
321{
322 ModuleDeref = module;
323 ModulePtr = &ModuleDeref;
324}
325
326//
327/// Indicates whether the document can be displayed in the file selection dialog
328/// box. A document is visible if dtHidden isn't set and Description isn't 0.
329//
330inline bool
332{
333 return (GetFlags() & dtHidden) == 0;
334}
335
336//
337/// Constructs a TDocTemplateT using the registration table to determine the file
338/// filter pattern, search path for viewing the directory, default file extension,
339/// and flag values. See the entry in this manual for registration macros for more
340/// information about how the registration tables are created. module, which is
341/// instantiated and exported directly from every executable module, can be used to
342/// access the current instance.
343//
344template<class D, class V> inline
351
352//
353/// Constructs a TDocTemplateT with the specified file description (desc), file
354/// filter pattern (filt), search path for viewing the directory (dir), default file
355/// extension (ext), and flags representing the view and creation options (flags).
356/// module, which is instantiated and exported directly from every executable
357/// module, can be used to access the current instance.
358//
359template<class D, class V> inline
361 LPCTSTR dir, LPCTSTR ext, long flags,
362 TModule*& module, TDocTemplate*& phead)
363:
364 TDocTemplate(desc, filt, dir, ext, flags, module, phead)
365{
366}
367
368//
369/// Makes a copy of the TDocTemplateT object.
370//
371template<class D, class V> inline TDocTemplateT<D,V>*
373{
374 TDocTemplateT<D,V>* tpl = new TDocTemplateT<D,V>(GetRegList(),
375 GetModule(), phead);
376 tpl->SetModule(module);
377 return tpl;
378}
379
380//
381/// 'Factory' method to create a new document of type 'D' using the specified
382/// parameter as the parent document.
383//
384template<class D, class V> inline D*
386{
387 return new D(parent);
388}
389
390//
391/// 'Factory' method to create a new view of type 'V' from the specified
392/// document parameter.
393//
394template<class D, class V> inline V*
396{
397 return new V(static_cast<D&>(doc));
398}
399
400//
401/// Gets the name of the view associated with the template.
402//
403template<class D, class V> inline LPCTSTR
405{
406 return V::StaticName();
407}
408
409//----------------------------------------------------------------------------
410
411/// Tests to see if the document (doc) is either the same class as the template's
412/// document class or a derived class. If the template can't use the document,
413/// IsMyKIndOfDoc returns 0.
414//
415template<class D, class V> D*
417{
418 return dynamic_cast<D*>(&doc);
419}
420
421/// Tests to see if the view (view) is either the same class as the template's view
422/// class or a derived class. If the template can't use the view, IsMyKIndOfView
423/// returns 0.
424//
425template<class D, class V> V*
427{
428 return dynamic_cast<V*>(&view);
429}
430
431#define DEFINE_DOC_TEMPLATE_CLASS(docClass, viewClass, cls)\
432 typedef ::owl::TDocTemplateT<docClass, viewClass> cls;\
433 IMPLEMENT_STREAMABLE_CLASS(cls);\
434 IMPLEMENT_STREAMABLE_CTOR1_IMPL(template<>, cls, TDocTemplateT, ::owl::TDocTemplate)\
435 IMPLEMENT_STREAMABLE_POINTER_IMPL(template<>, cls)
436
437} // OWL namespace
438
439#endif // OWL_DOCTPL_H
TDocManager creates a document manager object that manages the list of current documents and register...
Definition docmanag.h:100
TDocTemplate is an abstract base class that contains document template functionality.
Definition doctpl.h:54
void SetDocManager(TDocManager *dm)
Sets the current document manager to the argument dm.
Definition doctpl.h:262
virtual LPCTSTR GetViewName()=0
A pure virtual function that must be defined in a derived class, GetViewName gets the name of the vie...
virtual TDocument * ConstructDoc(TDocument *parent=nullptr)=0
A pure virtual function that must be defined in a derived class, ConstructDoc creates a document spec...
DECLARE_ABSTRACT_STREAMABLE_OWL(TDocTemplate, 1)
bool IsFlagSet(long flag) const
Returns nonzero if the document template flag is set.
Definition doctpl.h:278
virtual TView * ConstructView(TDocument &doc)=0
A pure virtual function that must be defined in a derived class, ConstructView creates the view speci...
bool IsVisible()
displayable in file select dialogs
Definition doctpl.h:331
virtual TDocument * IsMyKindOfDoc(TDocument &doc)=0
A pure virtual function that must be defined in a derived class, IsMyKindOfDoc tests if the template ...
bool IsStatic() const
Returns true if the template is statically constructed.
Definition doctpl.h:295
virtual TDocTemplate * Clone(TModule *module, TDocTemplate *&phead=::DocTemplateStaticHead)=0
Makes a copy of a document template.
int GetRefCount() const
Return the number of reference count of the template.
Definition doctpl.h:312
virtual TView * IsMyKindOfView(TView &view)=0
A pure virtual function that must be defined in a derived class, IsMyKindofView tests if the template...
TDocTemplate * GetNextTemplate() const
Gets the next template in the list of templates.
Definition doctpl.h:270
void SetModule(TModule *module)
Sets a module pointer.
Definition doctpl.h:320
TDocManager * GetDocManager() const
Points to the document manager.
Definition doctpl.h:254
long GetFlags() const
Gets the document template constants, which indicate how the document is created and opened.
Definition doctpl.h:287
TModule *& GetModule()
Returns a module pointer.
Definition doctpl.h:303
To register the associated document and view classes, a parameterized subclass, TDocTemplateT<D,...
Definition doctpl.h:174
D * ConstructDoc(TDocument *parent=nullptr)
'Factory' method to create a new document of type 'D' using the specified parameter as the parent doc...
Definition doctpl.h:385
virtual LPCTSTR GetViewName()
Gets the name of the view associated with the template.
Definition doctpl.h:404
TDocTemplateT * Clone(TModule *module, TDocTemplate *&phead=::DocTemplateStaticHead)
Makes a copy of the TDocTemplateT object.
Definition doctpl.h:372
V * ConstructView(TDocument &doc)
'Factory' method to create a new view of type 'V' from the specified document parameter.
Definition doctpl.h:395
TDocTemplateT(TRegList &regList, TModule *&module=owl::Module, TDocTemplate *&phead=DocTemplateStaticHead)
Constructs a TDocTemplateT using the registration table to determine the file filter pattern,...
Definition doctpl.h:345
D * IsMyKindOfDoc(TDocument &doc)
Returns 0 if template can't support.
Definition doctpl.h:416
V * IsMyKindOfView(TView &view)
Returns 0 if template incompatible.
Definition doctpl.h:426
An abstract base class, TDocument is the base class for all document objects and serves as an interfa...
Definition docview.h:187
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
A registration parameter table, composed of a list of TRegItems.
Definition registry.h:531
Classes that inherit from TStreamableBase are known as streamable classes (their objects can be writt...
Definition objstrm.h:108
Abstract base class for view access from document.
Definition docview.h:397
owl::TDocTemplate * DocTemplateStaticHead
Templates constructed before app get linked onto this head pointer.
Definition global.cpp:66
#define DECLARE_CASTABLE
Definition objstrm.h:1440
#define DECLARE_STREAMER_FROM_BASES(cls, base)
Definition objstrm.h:1300
#define DECLARE_STREAMABLE_CTOR(cls)
Definition objstrm.h:1433
#define DECLARE_STREAMABLE_INLINES(cls)
Definition objstrm.h:1538
const uint dtAutoDelete
delete doc when last view is deleted
Definition doctpl.h:219
#define DECLARE_STREAMABLE_OPSDV(cls)
Definition doctpl.h:134
const uint dtPathMustExist
Definition doctpl.h:237
const uint dtFileMustExist
Definition doctpl.h:238
const uint dtNoTestCreate
Definition doctpl.h:241
const uint dtNewDoc
create new document, no path used
Definition doctpl.h:218
const uint dtNoReadOnly
Definition doctpl.h:240
const uint dtNoAutoView
no automatic create of default view
Definition doctpl.h:220
const uint dtAutoOpen
open document upon creation
Definition doctpl.h:222
const uint dtForbidNew
forbids creating new document
Definition doctpl.h:229
const uint dtSingleUse
to be registered as single use
Definition doctpl.h:227
const uint dtRegisterExt
register extension with this app
Definition doctpl.h:228
const uint dtCreatePrompt
Definition doctpl.h:239
const uint dtHidden
hide template from user selection
Definition doctpl.h:224
const uint dtOverwritePrompt
Definition doctpl.h:235
const uint dtHideReadOnly
Definition doctpl.h:236
const uint dtDynRegInfo
reginfo table is dynamic, not static
Definition doctpl.h:226
const uint dtSelected
indicates template last selected
Definition doctpl.h:225
const uint dtSingleView
only a single view per document
Definition doctpl.h:221
const uint dtUpdateDir
syncronize directory with dialog dir
Definition doctpl.h:223
const uint dtReadOnly
Definition doctpl.h:234
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
char tchar
Definition defs.h:77
TModule * Module
Definition global.cpp:34
unsigned int uint
Definition number.h:25
General definitions used by all ObjectWindows programs.
#define _OWLCLASS
Definition defs.h:338
General Registry access & registration implementation TRegKey, TRegValue, TRegKeyIterator,...