OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
doctpl.cpp
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/// Implementation of class TDocTemplate
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/defs.h>
10#include <owl/doctpl.h>
11#include <stdio.h>
12
13namespace owl {
14
16
17//
18// Construct a Doc/View template from the specified parameters.
19//
20/// Uses the information in the registration table (regList) to construct a
21/// TDocTemplate with the specified file description, file filter pattern, search
22/// path for viewing the directory, default file extension, and flags representing
23/// the view and creation options from the registration list. Then, adds this
24/// template to the document manager's template list. If the document manager is not
25/// yet constructed, adds the template to a static list, which the document manager
26/// will later add to its template list.
27/// The argument, module, specifies the TModule of the caller. phead specifies the
28/// template head for the caller's module. See the Registration macros entry in this
29/// manual for information about the registration macros that generate a TRegList,
30/// which contains the attributes used to create a TDocTemplate object.
31//
34:
36 Directory(nullptr),
37 ModulePtr(&module)
38{
39 RefCnt = module ? 1 : 0x8001; // static if constructed before Module
40 Flags = _ttol((*RegList)["docflags"]);
41}
42
43//
44/// Sets the document template constants, which indicate how the document is created
45/// and opened.
46//
48{
49 Flags = GetFlags() | flag;
50}
51
52//
53/// Clears a document template constant.
54//
56{
57 Flags = GetFlags() & ~flag;
58}
59
60//
61/// Gets the directory path to use when searching for matching files. This will get
62/// updated if a file is selected and the dtUpdateDir flag is set.
63//
65{
66 if (Directory)
67 return Directory;
68 return (*RegList)["directory"];
69}
70
71//
72/// Sets the directory path to use when searching for matching files. This will get
73/// updated if a file is selected and the dtUpdateDir flag is set.
74//
76{
77 delete[] Directory;
78 Directory = nullptr;
79 if (txt)
80 Directory = strnewdup(txt);
81}
82
83//
84/// Sets the directory path to use when searching for matching files. This will get
85/// updated if a file is selected and the dtUpdateDir flag is set.
86//
88{
89 delete[] Directory;
90 Directory = nullptr;
91 if (txt && len > 0) {
92 Directory = strnewdup(txt, len);
93 Directory[len] = 0;
94 }
95}
96
97//
98// Called only when RefCnt goes to 0
99//
100/// Destroys a TDocTemplate object and frees the data members (FileFilter,
101/// Description, Directory, and DefaultExt). The Destructor is called only when no
102/// views or documents are associated with the template. Instead of calling this
103/// Destructor directly, use the Delete member function.
104//
106{
107 if (GetFlags() & dtDynRegInfo) {
108 delete RegList;
109 RegList = nullptr;
110 }
111 delete[] Directory;
112}
113
114//
115/// Gets any valid document matching pattern to use when searching for files.
116//
118{
119 return (*RegList)["docfilter"];
120}
121
122//
123/// Gets the template description to put in the file-selection list box or the
124/// File|New menu-selection list box.
125//
127{
128 return (*RegList)["description"];
129}
130
131//
132/// Gets the default extension to use if the user has entered the name of a file
133/// without any extension. If there is no default extension, GetDefaultExt contains
134/// 0.
135//
137{
138 return (*RegList)["extension"];
139}
140
141//
142//
143//
144class TRegListOldDocTemplate : public TRegList {
145 public:
146 TRegListOldDocTemplate(LPCTSTR desc, LPCTSTR filt,
147 LPCTSTR dir, LPCTSTR ext, long flags);
148 TRegItem List[6]; // 4 strings, flags, terminator
149 tchar FlagBuf[12]; // for string representation of doc template flags
150};
151
152//
153//
154//
155TRegListOldDocTemplate::TRegListOldDocTemplate(LPCTSTR desc,
157 LPCTSTR dir,
158 LPCTSTR ext,
159 long flags)
160:
161 TRegList(List)
162{
163 _stprintf(FlagBuf,_T("0x%lX"),flags);
164 List[0].Key = "description";
165 List[0].Value = desc;
166 List[1].Key = "docfilter";
167 List[1].Value = filt;
168 List[2].Key = "directory";
169 List[2].Value = dir;
170 List[3].Key = "extension";
171 List[3].Value = ext;
172 List[4].Key = "docflags";
173 List[4].Value = FlagBuf;
174 List[5].Key = nullptr;
175}
176
177//
178/// Constructs a Doc/View template from the description, filter, directory, file
179/// extension, 'dt' flags, module and template head parameters. This constructor is
180/// primarily for backward compatibility with earlier implementation of
181/// ObjectWindows' Doc/View subsystem.
182//
185 long flags, TModule*& module,
187:
188 TRegLink(),
189 Directory(nullptr),
190 Flags(flags | dtDynRegInfo),
191 ModulePtr(&module)
192{
193//JJH this is nasty...but works.
194#if defined(__GNUC__) && (__GNUC__ >= 3)
195 AddLink((TRegLink**)&rphead, reinterpret_cast<TRegLink*>(this));
196#else
197 AddLink((TRegLink**)&rphead, static_cast<TRegLink*>(this));
198#endif
199 RefCnt = module ? 1 : 0x8001; // static if contructed before Module
200// NextTemplate = 0;
201 RegList = new TRegListOldDocTemplate(desc, filt, dir, ext, flags);
202}
203
204
206
207#if OWL_PERSISTENT_STREAMS
208
209//
210//
211//
212void*
213TDocTemplate::Streamer::Read(ipstream& is, uint32 /*version*/) const
214{
215 TDocTemplate* o = GetObject();
216 bool wasStatic = o->IsStatic(); // test in case dummy template passed
217 {int tplRefCnt; is >> tplRefCnt; o->RefCnt = tplRefCnt; }// need to set back to 1 if doc attach increments!!?
218 is >> o->Flags;
219 if (o->IsStatic()) {
220 delete[] o->Directory;
221 }
222#if defined(UNICODE)
224 char * dir = is.freadString();
225 o->Directory = strnewdup(_A2W(dir));
226 delete[] dir;
227#else
228 o->Directory = is.freadString();
229#endif
230 if (o->IsStatic() && !wasStatic) { // dummy template passed as sink
231 delete[] o->Directory;
232 }
233 return o;
234 ///JD need to link up reg info table!!
235}
236
237//
238//
239//
240void
241TDocTemplate::Streamer::Write(opstream& os) const
242{
243 TDocTemplate* o = GetObject();
244 os << (int)o->RefCnt;
245 os << o->GetFlags();
247 os.fwriteString(_W2A(o->Directory));
248}
249
250#endif
251
252} // OWL namespace
253
TDocTemplate is an abstract base class that contains document template functionality.
Definition doctpl.h:54
void SetFlag(long flag)
Sets the document template constants, which indicate how the document is created and opened.
Definition doctpl.cpp:47
LPCTSTR GetDescription() const
Gets the template description to put in the file-selection list box or the File|New menu-selection li...
Definition doctpl.cpp:126
LPCTSTR GetDefaultExt() const
Gets the default extension to use if the user has entered the name of a file without any extension.
Definition doctpl.cpp:136
LPCTSTR GetDirectory() const
Gets the directory path to use when searching for matching files.
Definition doctpl.cpp:64
void SetDirectory(LPCTSTR)
Sets the directory path to use when searching for matching files.
Definition doctpl.cpp:75
~TDocTemplate()
Destroys a TDocTemplate object and frees the data members (FileFilter, Description,...
Definition doctpl.cpp:105
TDocTemplate(TRegList &regList, TModule *&module, TDocTemplate *&phead)
Uses the information in the registration table (regList) to construct a TDocTemplate with the specifi...
Definition doctpl.cpp:32
LPCTSTR GetFileFilter() const
Gets any valid document matching pattern to use when searching for files.
Definition doctpl.cpp:117
void ClearFlag(long flag)
Clears a document template constant.
Definition doctpl.cpp:55
long GetFlags() const
Gets the document template constants, which indicate how the document is created and opened.
Definition doctpl.h:287
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
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define _stprintf
Definition cygwin.h:88
#define _ttol
Definition cygwin.h:65
#define _T(x)
Definition cygwin.h:51
Definition of class TDocTemplate, and class template TDocTemplateT<D,V>
#define IMPLEMENT_ABSTRACT_STREAMABLE(cls)
Definition objstrm.h:1718
const uint dtDynRegInfo
reginfo table is dynamic, not static
Definition doctpl.h:226
#define _W2A(lpw)
Definition memory.h:219
char * strnewdup(const char *s, size_t minAllocSize=0)
Definition memory.cpp:25
#define _A2W(lpw)
Definition memory.h:220
#define _USES_CONVERSION
Definition memory.h:217
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned long uint32
Definition number.h:34
char tchar
Definition defs.h:77
OWL_DIAGINFO
Definition animctrl.cpp:14
General definitions used by all ObjectWindows programs.
A single registration list entry.
Definition registry.h:508