OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
swindow.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1991, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Streamable object implementation for TWindow.
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9
10#include <owl/applicat.h>
11#include <owl/appdict.h>
12#include <owl/window.h>
13#include <owl/scroller.h>
14#include "strmresid.h"
15
16namespace owl {
17
19
20namespace { char dummy[] = "Not empty!"; }
21
22#if OWL_PERSISTENT_STREAMS
23
25
26const int StreamIsTop = 1;
27const int StreamIsTopChild = 2;
28
29//
30// Input
31//
32void *
33TWindow::Streamer::Read(ipstream& is, uint32 version) const
34{
35 TWindow* o = GetObject();
36 int flags;
37 is >> flags;
38 if (flags & StreamIsTop) {
39 o->ChildList = 0; // indicate no children connected yet
40 return o; // we only need to read our child list
41 }
42
43 o->Handle = 0;
44 o->Parent = 0;
45 o->SiblingList = 0;
46 o->ChildList = 0;
47 o->TransferBuffer = 0;
48 o->DefaultProc = 0;
49 o->HAccel = 0;
50 o->ContextPopupMenu = 0;
51 o->SetUniqueId();
52
53 is >> o->Module;
54 TResId TempId;
55 is >> TempId;
56 o->Title = const_cast<LPTSTR>(static_cast<LPCTSTR>(TempId));
57 is >> o->Flags;
58
59 if (o->IsFlagSet(wfFromResource)) {
60 o->DefaultProc = (WNDPROC)::DefWindowProc;
61 memset(&o->Attr, 0, sizeof(o->Attr));
62 }
63 else
64 {
65 UINT_PTR p = reinterpret_cast<UINT_PTR>(o->Attr.Param);
66 is >> o->Attr.Style >> o->Attr.ExStyle
67 >> o->Attr.X >> o->Attr.Y >> o->Attr.W >> o->Attr.H >> p;
68 o->Attr.Param = reinterpret_cast<LPVOID>(p);
69 o->DefaultProc = ::DefWindowProc;
70 }
71
72 TResId accelTable;
73 is >> o->Attr.Id
74 >> o->Attr.Menu // Owned; deallocated by ~TWindow.
75 >> accelTable;
76 o->Attr.AccelTable = InternStreamedResId_(accelTable);
77
78 is >> o->ZOrder;
79
80 is >> o->Parent;
81
82 if (o->Parent) {
83 o->Application = o->Parent->GetApplication();
84
85 // Version 1 and version 3 sibling streaming techniques
86 //
87 if (version == 1) {
88 if (flags & StreamIsTopChild)
89 o->Parent->ChildList = o; // set parent's child pointer to this
90
91 is >> o->ChildList;
92 is >> o->SiblingList;
93 }
94 else {
95 o->Parent->AddChild(o);
96
97 static bool readSiblings = true;
98 bool saveReadSiblings = readSiblings;
99 readSiblings = true;
100 is >> o->ChildList;
101 readSiblings = saveReadSiblings;
102
103 if (readSiblings) {
104 readSiblings = false;
105
106 unsigned numSiblings;
107 is >> numSiblings;
108 for (unsigned i = 0; i < numSiblings; i++) {
109 TWindow* sibling;
110 is >> sibling;
111 }
112 readSiblings = true;
113 }
114 }
115 }
116 else {
117 o->Application = TYPESAFE_DOWNCAST(o->Module,TApplication);
118 if (!o->Application)
119 o->Application = OWLGetAppDictionary().GetApplication(0);
120 }
121
122 is >> o->Scroller;
123 if (o->Scroller)
124 o->Scroller->SetWindow(o);
125
126 // SetCursor does nothing if passed the current settings, so read into temporaries and reset
127 // the current settings first.
128 //
129 o->HCursor = 0;
130 o->CursorModule = nullptr;
131 o->CursorResId = 0;
132 TModule* cursorModule;
133 TResId cursorResId;
134 is >> cursorModule >> cursorResId;
135 o->SetCursor(cursorModule, InternStreamedResId_(cursorResId));
136 is >> o->BkgndColor; // !CQ need streamer for TColor
137
138 o->InstanceProc = o->CreateInstanceProc();
139
140 return o;
141}
142
143//
144// Output
145//
146void
147TWindow::Streamer::Write(opstream& os) const
148{
149 TWindow* o = GetObject();
150
151 o->AssignZOrder();
152 int flags = 0;
153 if (o->IsFlagSet(wfStreamTop) || o->IsFlagSet(wfMainWindow))
154 flags |= StreamIsTop;
155 else if (o->Parent) {
156 if ((o->Parent->IsFlagSet(wfStreamTop) || o->Parent->IsFlagSet(wfMainWindow))
157 && o->Parent->ChildList == o)
158 flags |= StreamIsTopChild;
159 }
160 os << flags;
161
162 if (flags & StreamIsTop)
163 return;
164
165 os << o->Module;
166 os << TResId(o->Title);
167
168 uint32 saveFlags = o->Flags;
169 if (o->GetHandle())
170 saveFlags |= wfAutoCreate;
171 os << saveFlags;
172
173 if (!o->IsFlagSet(wfFromResource)) {
174 uint32 saveStyle = o->Attr.Style &
175 ~(WS_MINIMIZE | WS_MAXIMIZE | WS_DISABLED | WS_VISIBLE);
176
177 if (o->GetHandle())
178 saveStyle |= o->GetWindowLong(GWL_STYLE) &
179 (WS_MINIMIZE | WS_MAXIMIZE | WS_DISABLED | WS_VISIBLE);
180
181 const UINT_PTR p = reinterpret_cast<UINT_PTR>(o->Attr.Param);
182 os << saveStyle << o->Attr.ExStyle
183 << o->Attr.X << o->Attr.Y << o->Attr.W << o->Attr.H << p;
184 }
185
186 os << o->Attr.Id
187 << o->Attr.Menu
188 << o->Attr.AccelTable;
189
190 os << o->ZOrder;
191
192 os << o->Parent;
193
194#if 0 // (TWindow::Streamer::ClassVersion() == 1)
195 os << o->ChildList;
196 os << o->SiblingList;
197
198#else // version >= 3
199 if (o->Parent) {
200 static bool writeSiblings = true;
201 bool saveWriteSiblings = writeSiblings;
202 writeSiblings = true;
203 os << o->ChildList;
204 writeSiblings = saveWriteSiblings;
205
206 if (writeSiblings) {
207 writeSiblings = false;
208
209 os << (o->Parent->NumChildren()-1);
210 for (TWindow* sibling = o->SiblingList; sibling != o; sibling = sibling->Next())
211 os << sibling;
212 writeSiblings = true;
213 }
214 }
215
216#endif
217
218 os << o->Scroller;
219
220 os << o->CursorModule << o->CursorResId;
221 os << o->BkgndColor;
222}
223
224#endif
225
226} // OWL namespace
227/* ========================================================================== */
228
Definition of class TAppDictionary.
Definition of class TApplication.
TApplication * GetApplication(uint pid=0)
Looks up and returns the application associated with a given process ID.
Definition appdict.cpp:192
Derived from TModule and TMsgThread and virtually derived from TEventHandler, TApplication acts as an...
Definition applicat.h:141
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:78
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
TWindow * Next()
Returns a pointer to the next sibling window in the window's sibling list.
Definition window.h:1755
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
Base class for writing streamable objects.
Definition objstrm.h:480
@ wfFromResource
Handle comes from HWND created from resource.
Definition window.h:61
@ wfMainWindow
This frame window is the main window.
Definition window.h:63
@ wfStreamTop
This window is the topmost one to stream.
Definition window.h:65
@ wfAutoCreate
Create the HWND when our parent is created.
Definition window.h:60
Object Windows Library (OWLNext Core).
Definition animctrl.h:22
unsigned long uint32
Definition number.h:34
TAppDictionary & OWLGetAppDictionary()
Global exported TAppDictionary in Owl.
Definition appdict.cpp:35
OWL_DIAGINFO
Definition animctrl.cpp:14
IMPLEMENT_STREAMABLE(TDocManager)
auto InternStreamedResId_(TResId id) -> TResId
Definition strmresid.h:37
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269
Definition of class TScroller.
Private helper for reading resource identifiers from persistent streams.
Base window class TWindow definition, including HWND encapsulation.