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
15namespace owl {
16
18
19namespace { char dummy[] = "Not empty!"; }
20
21#if OWL_PERSISTENT_STREAMS
22
24
25const int StreamIsTop = 1;
26const int StreamIsTopChild = 2;
27
28//
29// Input
30//
31void *
32TWindow::Streamer::Read(ipstream& is, uint32 version) const
33{
34 TWindow* o = GetObject();
35 int flags;
36 is >> flags;
37 if (flags & StreamIsTop) {
38 o->ChildList = 0; // indicate no children connected yet
39 return o; // we only need to read our child list
40 }
41
42 o->Handle = 0;
43 o->Parent = 0;
44 o->SiblingList = 0;
45 o->ChildList = 0;
46 o->TransferBuffer = 0;
47 o->DefaultProc = 0;
48 o->HAccel = 0;
49 o->ContextPopupMenu = 0;
50 o->SetUniqueId();
51
52 is >> o->Module;
53 TResId TempId;
54 is >> TempId;
55 o->Title = const_cast<LPTSTR>(static_cast<LPCTSTR>(TempId));
56 is >> o->Flags;
57
58 if (o->IsFlagSet(wfFromResource)) {
59 o->DefaultProc = (WNDPROC)::DefWindowProc;
60 memset(&o->Attr, 0, sizeof(o->Attr));
61 }
62 else
63 {
64 UINT_PTR p = reinterpret_cast<UINT_PTR>(o->Attr.Param);
65 is >> o->Attr.Style >> o->Attr.ExStyle
66 >> o->Attr.X >> o->Attr.Y >> o->Attr.W >> o->Attr.H >> p;
67 o->Attr.Param = reinterpret_cast<LPVOID>(p);
68 o->DefaultProc = ::DefWindowProc;
69 }
70
71 is >> o->Attr.Id
72 >> o->Attr.Menu
73 >> o->Attr.AccelTable;
74
75 is >> o->ZOrder;
76
77 is >> o->Parent;
78
79 if (o->Parent) {
80 o->Application = o->Parent->GetApplication();
81
82 // Version 1 and version 3 sibling streaming techniques
83 //
84 if (version == 1) {
85 if (flags & StreamIsTopChild)
86 o->Parent->ChildList = o; // set parent's child pointer to this
87
88 is >> o->ChildList;
89 is >> o->SiblingList;
90 }
91 else {
92 o->Parent->AddChild(o);
93
94 static bool readSiblings = true;
96 readSiblings = true;
97 is >> o->ChildList;
99
100 if (readSiblings) {
101 readSiblings = false;
102
103 unsigned numSiblings;
104 is >> numSiblings;
105 for (unsigned i = 0; i < numSiblings; i++) {
106 TWindow* sibling;
107 is >> sibling;
108 }
109 readSiblings = true;
110 }
111 }
112 }
113 else {
114 o->Application = TYPESAFE_DOWNCAST(o->Module,TApplication);
115 if (!o->Application)
116 o->Application = OWLGetAppDictionary().GetApplication(0);
117 }
118
119 is >> o->Scroller;
120 if (o->Scroller)
121 o->Scroller->SetWindow(o);
122
123 o->HCursor = 0;
124 is >> o->CursorModule >> o->CursorResId;
125 o->SetCursor(o->CursorModule, o->CursorResId);
126 is >> o->BkgndColor; // !CQ need streamer for TColor
127
128 o->InstanceProc = o->CreateInstanceProc();
129
130 return o;
131}
132
133//
134// Output
135//
136void
137TWindow::Streamer::Write(opstream& os) const
138{
139 TWindow* o = GetObject();
140
141 o->AssignZOrder();
142 int flags = 0;
143 if (o->IsFlagSet(wfStreamTop) || o->IsFlagSet(wfMainWindow))
144 flags |= StreamIsTop;
145 else if (o->Parent) {
146 if ((o->Parent->IsFlagSet(wfStreamTop) || o->Parent->IsFlagSet(wfMainWindow))
147 && o->Parent->ChildList == o)
148 flags |= StreamIsTopChild;
149 }
150 os << flags;
151
152 if (flags & StreamIsTop)
153 return;
154
155 os << o->Module;
156 os << TResId(o->Title);
157
158 uint32 saveFlags = o->Flags;
159 if (o->GetHandle())
161 os << saveFlags;
162
163 if (!o->IsFlagSet(wfFromResource)) {
164 uint32 saveStyle = o->Attr.Style &
166
167 if (o->GetHandle())
168 saveStyle |= o->GetWindowLong(GWL_STYLE) &
170
171 const UINT_PTR p = reinterpret_cast<UINT_PTR>(o->Attr.Param);
172 os << saveStyle << o->Attr.ExStyle
173 << o->Attr.X << o->Attr.Y << o->Attr.W << o->Attr.H << p;
174 }
175
176 os << o->Attr.Id
177 << o->Attr.Menu
178 << o->Attr.AccelTable;
179
180 os << o->ZOrder;
181
182 os << o->Parent;
183
184#if 0 // (TWindow::Streamer::ClassVersion() == 1)
185 os << o->ChildList;
186 os << o->SiblingList;
187
188#else // version >= 3
189 if (o->Parent) {
190 static bool writeSiblings = true;
192 writeSiblings = true;
193 os << o->ChildList;
195
196 if (writeSiblings) {
197 writeSiblings = false;
198
199 os << (o->Parent->NumChildren()-1);
200 for (TWindow* sibling = o->SiblingList; sibling != o; sibling = sibling->Next())
201 os << sibling;
202 writeSiblings = true;
203 }
204 }
205
206#endif
207
208 os << o->Scroller;
209
210 os << o->CursorModule << o->CursorResId;
211 os << o->BkgndColor;
212}
213
214#endif
215
216} // OWL namespace
217/* ========================================================================== */
218
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
#define IMPLEMENT_STREAMABLE(cls)
Definition objstrm.h:1724
@ 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
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269
Definition of class TScroller.
Base window class TWindow definition, including HWND encapsulation.