OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
view.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 classes TView & TWindowView
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/defs.h>
10#include <owl/docmanag.h>
11#include <owl/appdict.h>
12#include <owl/bardescr.h>
13#include <owl/docview.rh>
14
15#if defined(__BORLANDC__)
16# pragma option -w-ccc // Disable "Condition is always true/false"
17#endif
18
19namespace owl {
20
22DIAG_DECLARE_GROUP(OwlDocView); // General Doc/View diagnostic group
23
24
25
26const uint MinUniqueViewId = 0x8000;
27uint TView::NextViewId = MinUniqueViewId;
28
29//
30/// Constructs a TView object of the document associated with the view. Sets the
31/// private data member ViewId to NextViewId. Calls TDocument's private member
32/// function AttachView to attach the view to the associated document.
33//
35:
36 Tag(nullptr),
37 ViewMenu(nullptr),
38 ViewBar(0)
39{
40 ViewId = NextViewId;
41 doc.AttachView(*this);
42}
43
44//
45/// Frees a TView object and calls TDocument's private member function DetachView to
46/// detach the view from the associated document.
47//
49{
50 delete ViewMenu;
51 delete ViewBar;
52
53 const auto ok = Doc != nullptr;
54 WARN(!ok, _T("TView::~TView: Terminating due to failed precondition."));
55 if (!ok) std::terminate();
56
57 if (Doc->DetachView(*this)) {
58 delete Doc;
59 }
60}
61
62//
63// Detach the view from the current document and attach it to another.
64// (Added by Vidar Hasfjord, 2007-08-27.)
65//
66void
68{
69 if (&new_doc == Doc) return; // Guard against reassignment.
70
71 // Detach and register whether the document should be deleted.
72 // The actual deletion is postponed to later to avoid any side-effects
73 // from the deletion that may affect the validity of the new document.
74
76 if (Doc && Doc->DetachView(*this))
77 delete_doc = Doc;
78
79 // Update the new document and existing views as if this was a new view.
80
81 new_doc.AttachView(*this);
82 CHECK(Doc == &new_doc);
83 Doc->ReindexFrames();
84
85 // Deletion of the old doc should be safe now.
86
87 if (delete_doc)
88 delete delete_doc;
89}
90
91//
92//
93//
94void
96{
97 delete ViewMenu;
98 ViewMenu = menu;
100
101 //if (tpl && ViewMenu && *ViewMenu->GetModule() == *tpl->GetModule())
102 // must check also if template is static becouse as module = 0;
103 if (tpl && ViewMenu && !tpl->IsStatic() && *ViewMenu->GetModule() == *tpl->GetModule())
104 ViewMenu->SetModule(tpl->GetModule());// force same module alias as template
105}
106//
107/// Sets the menu descriptor for this view. This can be any existing TMenuDescr
108/// object. If no descriptor exists, ViewMenu is 0.
109//
110void
112{
113 delete ViewBar;
114 ViewBar = bar;
115}
116
117static const tchar* const TView_PropertyNames[] = {
118 _T("View Class"), // ViewClass
119 _T("View Name"), // ViewName
120};
121
122static const int TView_PropertyFlags[] = {
123 pfGetText|pfConstant, // ViewClass
124 pfGetText|pfConstant, // ViewName
125};
126
127//
128/// Returns the text name of the property given the index value.
129//
130const tchar*
132{
133 if (index <= PrevProperty) {
134 TRACEX(OwlDocView, 0, _T("PropertyName(): index <= PrevProperty!"));
135 return nullptr;
136 }
137 else if (index < NextProperty)
138 return TView_PropertyNames[index-PrevProperty-1];
139 else {
140 TRACEX(OwlDocView, 0, _T("PropertyName(): index >= NextProperty!"));
141 return nullptr;
142 }
143}
144
145//
146/// Returns the attributes of a specified property given the index of the property
147/// whose attributes you want to retrieve.
148//
149int
151{
152 if (index <= PrevProperty) {
153 TRACEX(OwlDocView, 0, _T("PropertyFlags(): index <= PrevProperty!"));
154 return 0;
155 }
156 else if (index < NextProperty)
157 return TView_PropertyFlags[index-PrevProperty-1];
158 else {
159 TRACEX(OwlDocView, 0, _T("PropertyFlags(): index >= NextProperty!"));
160 return 0;
161 }
162}
163
164//
165/// Gets the property index, given the property name (name). Returns 0 if the name
166/// is not found.
167//
168int
170{
171 PRECONDITION(name != nullptr);
172 int i;
173 for (i=0; i < NextProperty-PrevProperty-1; i++)
174 if (_tcscmp(TView_PropertyNames[i], name) == 0)
175 return i+PrevProperty+1;
176
177 TRACEX(OwlDocView, 0, _T("FindProperty: Index of [") << name << _T("] not found") );
178 return 0;
179}
180
181//
182/// Retrieves the property identified by the given index.
183/// If the requested property is text, then `dest` should point to a text buffer, and `textlen`
184/// should specify the maximum number of characters the buffer can hold, excluding the terminating
185/// null-character, i.e. the buffer must have room for (`textlen` + 1) characters.
186///
187/// If the requested property is numerical, then it may be requested either as text or in its
188/// binary form. To request the property as text, pass a text buffer as described above. To request
189/// the property in binary form, `dest` should point to storage of sufficent size, and `textlen`
190/// should be zero.
191///
192/// Non-text properties without textual representation, e.g. file handles, may only be requested
193/// in binary form, i.e. `dest` must point to sufficient storage, and `textlen` must be zero.
194///
195/// \return If the parameter `textlen` is non-zero, which means that the property is requested in
196/// string form, the function returns the length of the string, i.e. the character count excluding
197/// the terminating null-character. If the parameter `textlen` is zero, which means that property
198/// is requested in binary form, the return value is the size of the data in bytes.
199///
200/// If the property is text, and `textlen` is zero, the function fails and returns 0. The function
201/// also fails and returns 0 if `textlen` is non-zero and the property requested can not be
202/// expressed as text. It also returns 0 if the property is not defined.
203///
204/// \sa TView::TViewProp
205//
206int
207TView::GetProperty(int index, void * dest, int textlen)
208{
209 LPCTSTR src;
210 switch (index) {
211
212 case ViewClass:{
214 src = _A2W(_OBJ_FULLTYPENAME(this));
215 }
216 break;
217
218 case ViewName:
219 src = GetViewName();
220 break;
221
222 default:
223 TRACEX(OwlDocView, 0, _T("GetProperty(): ") \
224 _T("invalid property [") << index << _T("] specified!") );
225 return 0;
226 }
227
228 if (!textlen) {
229 TRACEX(OwlDocView, 0, _T("GetProperty(): 0-Length buffer specified!"));
230 return 0;
231 }
232
233 int srclen = src ? static_cast<int>(::_tcslen(src)) : 0;
234 if (textlen > srclen)
235 textlen = srclen;
236 if (textlen)
237 memcpy(dest, src, textlen*sizeof(tchar));
238 *((tchar *)dest + textlen) = 0;
239 return srclen;
240}
241
242//
243/// Increments an internal count used by the Doc/View subsystem to identify each
244/// view.
245//
246void
248{
249 if (++NextViewId < MinUniqueViewId)
250 NextViewId = MinUniqueViewId;
251}
252
254
255#if OWL_PERSISTENT_STREAMS
256
257//
258//
259//
260void*
261TView::Streamer::Read(ipstream& is, uint32 /*version*/) const
262{
263 TView* o = GetObject();
264 bool hasViewMenu = is.readByte();
265 if (hasViewMenu) {
266 o->ViewMenu = new TMenuDescr;
267 is >> *o->ViewMenu;
268 }
269 else
270 o->ViewMenu = 0;
271 o->ViewBar = 0;
272 is >> o->ViewId;
273 is >> o->Doc;
274 is >> o->NextView;
275 return o;
276}
277
278//
279//
280//
281void
282TView::Streamer::Write(opstream& os) const
283{
284 TView* o = GetObject();
285 os.writeByte(uint8(o->ViewMenu ? 1 : 0));
286 if (o->ViewMenu)
287 os << *o->ViewMenu;
288 os << o->ViewId;
289 os << o->Doc;
290 os << o->NextView;
291}
292#endif
293//----------------------------------------------------------------------------
294// TWindowView Implementation
295//
296
297DEFINE_RESPONSE_TABLE1(TWindowView, TWindow)
300
301//
302/// Constructs a TWindowView interface object associated with the window view. Sets
303/// ViewId to NextViewId. Calls the associated document's AttachView() function (a
304/// private TDocument function) to attach the view to the document.
305//
307:
308 TWindow(parent, nullptr, doc.GetDocManager().GetApplication()),
309 TView(doc)
310{
311}
312
314
315#if OWL_PERSISTENT_STREAMS
316//
317//
318//
319void*
320TWindowView::Streamer::Read(ipstream& is, uint32 /*version*/) const
321{
322 ReadBaseObject((TWindow*)GetObject(), is);
323 ReadBaseObject((TView*)GetObject(), is);
324 return GetObject();
325}
326
327//
328//
329//
330void
331TWindowView::Streamer::Write(opstream& os) const
332{
333 WriteBaseObject((TWindow*)GetObject(), os);
334 WriteBaseObject((TView*)GetObject(), os);
335}
336#endif
337//----------------------------------------------------------------------------
338// TDialogView Implementation
339//
340
341DEFINE_RESPONSE_TABLE1(TDialogView, TDialog)
344
345//
346//
347//
349:
350 TDialog(parent, resId, module),
351 TView(doc)
352{
353}
354//
356 TAutoDelete del, TModule* module)
357:
358 TDialog(parent, dlgTemplate, del, module),
359 TView(doc)
360{
361}
362//
365:
366 TDialog(hTemplate, parent, del, module),
367 TView(doc)
368{
369}
370
372
373#if OWL_PERSISTENT_STREAMS
374//
375//
376//
377void*
378TDialogView::Streamer::Read(ipstream& is, uint32 /*version*/) const
379{
380 ReadBaseObject((TDialog*)GetObject(), is);
381 ReadBaseObject((TView*)GetObject(), is);
382 return GetObject();
383}
384
385//
386//
387//
388void
389TDialogView::Streamer::Write(opstream& os) const
390{
391 WriteBaseObject((TDialog*)GetObject(), os);
392 WriteBaseObject((TView*)GetObject(), os);
393}
394
395#endif
396
397//----------------------------------------------------------------------------
398
399} // OWL namespace
400/* ========================================================================== */
401
Definition of class TAppDictionary.
Class definition for TBarDescr.
#define CHECK(condition)
Definition checks.h:239
#define WARN(condition, message)
Definition checks.h:273
#define PRECONDITION(condition)
Definition checks.h:227
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
#define TRACEX(group, level, message)
Definition checks.h:263
Descriptor of Bar Implementation.
Definition bardescr.h:71
Typically used to obtain information from a user, a dialog box is a window inside of which other cont...
Definition dialog.h:85
Derived from TDialog and TView.
Definition docview.h:530
TDialogView(TDocument &doc, TWindow *parent, TResId resId, TModule *module=&GetGlobalModule())
Definition view.cpp:348
TDocTemplate is an abstract base class that contains document template functionality.
Definition doctpl.h:54
An abstract base class, TDocument is the base class for all document objects and serves as an interfa...
Definition docview.h:187
TDocTemplate * GetTemplate()
Gets the template used for document creation.
Definition docview.h:866
Menu with information used to allow merging.
Definition menu.h:206
TModule * GetModule() const
Returns a pointer to the module object.
Definition menu.h:279
void SetModule(TModule *module)
Sets the default module object for this menu descriptor.
Definition menu.h:286
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
Abstract base class for view access from document.
Definition docview.h:397
@ ViewClass
Name of the C++ class encapsulating the view. (text)
Definition docview.h:405
@ ViewName
Name of the view. (text)
Definition docview.h:406
@ PrevProperty
Index of last property in base class.
Definition docview.h:404
@ NextProperty
Next index to be used by derived class.
Definition docview.h:407
virtual int PropertyFlags(int index)
pfXxxxx bit array
Definition view.cpp:150
virtual ~TView()
Frees a TView object and calls TDocument's private member function DetachView to detach the view from...
Definition view.cpp:48
virtual LPCTSTR PropertyName(int index)
locale invariant name
Definition view.cpp:131
virtual int FindProperty(LPCTSTR name)
return property index
Definition view.cpp:169
void SetViewBar(TBarDescr *bar)
Sets the menu descriptor for this view.
Definition view.cpp:111
TView(TDocument &doc)
Constructs a TView object of the document associated with the view.
Definition view.cpp:34
void SetDocument(TDocument &)
Definition view.cpp:67
virtual LPCTSTR GetViewName()=0
Pure virtual function that returns 0.
void SetViewMenu(TMenuDescr *menu)
Definition view.cpp:95
virtual int GetProperty(int index, void *dest, int textlen=0)
Retrieves the property identified by the given index.
Definition view.cpp:207
static void BumpNextViewId()
Increments an internal count used by the Doc/View subsystem to identify each view.
Definition view.cpp:247
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
Derived from both TWindow and TView, TWindowView is a streamable base class that can be used for deri...
Definition docview.h:494
TWindowView(TDocument &doc, TWindow *parent=nullptr)
Constructs a TWindowView interface object associated with the window view.
Definition view.cpp:306
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define _tcscmp
Definition cygwin.h:75
#define _tcslen
Definition cygwin.h:74
#define _T(x)
Definition cygwin.h:51
Definition of class TDocManager.
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
#define IMPLEMENT_ABSTRACT_STREAMABLE(cls)
Definition objstrm.h:1718
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
void ReadBaseObject(Base *base, ipstream &in)
Definition objstrm.h:1159
#define _OBJ_FULLTYPENAME(obj)
Definition objstrm.h:78
#define IMPLEMENT_STREAMABLE2(cls, base1, base2)
Definition objstrm.h:1726
void WriteBaseObject(Base *base, opstream &out)
Definition objstrm.h:1150
const uint pfGetText
property accessible as text format
Definition docview.h:122
const uint pfConstant
property is invariant for object instance
Definition docview.h:124
#define _A2W(lpw)
Definition memory.h:220
#define _USES_CONVERSION
Definition memory.h:217
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
EV_VN_ISWINDOW
Definition commview.cpp:26
unsigned char uint8
Definition number.h:32
unsigned long uint32
Definition number.h:34
char tchar
Definition defs.h:77
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
unsigned int uint
Definition number.h:25
const uint MinUniqueViewId
Definition view.cpp:26
General definitions used by all ObjectWindows programs.