OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
control.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/// Implementation of class TControl. This defines the basic behavior of all
7/// controls.
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/control.h>
11
12namespace owl {
13
15
16// from window.cpp
17//
19
20
21//
22// General Controls diagnostic group
23//
25
26
34
35
36//
37/// Invokes TWindow's constructor, passing it parent (parent window), title (caption
38/// text), and module. Sets the control attributes using the supplied library ID
39/// (Id), position (x, y) relative to the origin of the parent window's client area,
40/// width (w), and height (h) parameters. It sets the control style to WS_CHILD |
41/// WS_VISIBLE | WS_GROUP | WS_TABSTOP.
42//
44 int id,
46 int x, int y, int w, int h,
47 TModule* module)
48{
49 // Initialize virtual base, in case the derived-most used default ctor
50 //
51 TWindow::Init(parent, title, module);
52
53 Attr.Id = id;
54 Attr.X = x;
55 Attr.Y = y;
56 Attr.W = w;
57 Attr.H = h;
58 Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP;
59
60 TRACEX(OwlControl, OWL_CDLEVEL, "TControl constructed @" << (void*)this);
61}
62
63//
64/// String-aware overload
65//
67 int id,
68 const tstring& title,
69 int x, int y, int w, int h,
70 TModule* module)
71{
72 // Initialize virtual base, in case the derived-most used default ctor
73 //
74 TWindow::Init(parent, title, module);
75
76 Attr.Id = id;
77 Attr.X = x;
78 Attr.Y = y;
79 Attr.W = w;
80 Attr.H = h;
81 Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP;
82
83 TRACEX(OwlControl, OWL_CDLEVEL, "TControl constructed @" << (void*)this);
84}
85
86
87//
88/// Constructs an object to be associated with an interface control of a TDialog
89/// object. Invokes the TWindow constructor, then enables the data transfer
90/// mechanism by calling TWindow::EnableTransfer.
91/// The id parameter must correspond to a control interface resource that you
92/// define.
93//
95 int resourceId,
96 TModule* module)
97{
98 // Initialize virtual base, in case the derived-most used default ctor
99 //
100 TWindow::Init(parent, nullptr, module);
101
103 memset(&Attr, 0x0, sizeof(Attr));
104 Attr.Id = resourceId;
106
107 TRACEX(OwlControl, OWL_CDLEVEL, "TControl constructed from resource @" << (void*)this);
108}
109
110//
111/// Overload for controls loaded from resource
112/// Allows the title specified in the resource data to be overridden.
113//
115{
116 // Initialize virtual base, in case the derived-most used default ctor
117 //
118 TWindow::Init(parent, title, module);
119
121 memset(&Attr, 0x0, sizeof(Attr));
122 Attr.Id = resourceId;
124
125 TRACEX(OwlControl, OWL_CDLEVEL, "TControl constructed from resource @" << (void*)this);
126}
127
128
129//
130/// Constructor to alias a non-OWL control
131//
133{
134 // Initialize virtual base, in case the derived-most used default ctor
135 //
136 TWindow::Init(handle, module);
137
138 TRACEX(OwlControl, OWL_CDLEVEL, "TControl aliased @" << (void*)this <<
139 " to handle" << static_cast<void*>(handle));
140}
141
142
143//
144//
145//
147{
148 TRACEX(OwlControl, OWL_CDLEVEL, "TControl destructed @" << (void*)this);
149}
150
151//
152/// Intercept WM_PAINT to redirect from TWindow to the underlying control if
153/// this Owl object is just a wrapper for a predefined class.
154//
155/// If the control has a predefined class, EvPaint calls TWindow::DefaultProcessing
156/// for painting. Otherwise, it calls TWindow::EvPaint.
157//
158void
160{
162 DefaultProcessing(); // don't call TWindow::EvPaint()
163
164 else
166}
167
168//
169/// Provides special handling for predefined controls.
170/// Predefined Windows controls handle erasure in their WM_PAINT handler, so if the flag
171/// wfPredefinedClass is set, this function will defer to DefaultProcessing. The colors for
172/// controls are set by handling the WM_CTLCOLOR... messages (see TWindow::EvCtlColor).
173//
175{
176 return IsFlagSet(wfPredefinedClass) ?
177 DefaultProcessing() != FALSE :
179}
180
181//
182/// Handles WM_COMPAREITEM message (for owner draw controls) by calling the
183/// corresponding virtual function.
184//
185int
187{
188 COMPAREITEMSTRUCT i(compareInfo); // Create copy to support legacy non-const virtual CompareItem.
189 return CompareItem(i);
190}
191//
192
193//
194/// Function called when a WM_COMPAREITEM is sent to parent on our behalf
195//
196/// Also used with owner-draw buttons and list boxes, CompareItem compares two
197/// items. The derived class supplies the compare logic.
198//
199int
201{
202 TRACEX(OwlControl, 1, "TControl::CompareItem() @" << (void*)this);
203 if (!GetHandle() || compareInfo.itemData1 == compareInfo.itemData2)
204 return 0;
205 if(compareInfo.itemData1){
206 TDrawItem* item = ItemData2DrawItem(compareInfo.itemData1);
207 if(item)
208 return item->Compare(compareInfo);
209 }
210 return 0;
211}
212
213//
214/// Handles WM_DELETEITEM message (for owner draw controls) by calling the
215/// corresponding virtual function.
216//
217void
219{
220 DELETEITEMSTRUCT i(deleteInfo); // Create copy to support legacy non-const virtual DeleteItem.
221 DeleteItem(i);
222}
223
224//
225/// Function called when a WM_DELETEITEM is sent to parent on our behalf
226//
227/// Used with owner-draw buttons and list boxes. In such cases, the derived class
228/// supplies the delete logic.
229//
230void
232{
233 TRACEX(OwlControl, 1, "TControl::DeleteItem() @" << (void*)this);
234}
235
236//
237/// Handles WM_MEASUREITEM message (for owner draw controls) by calling the
238/// corresponding virtual function.
239//
240void
245
246//
247/// Function called when a WM_MEASUREITEM is sent to parent on our behalf
248//
249/// Used by owner-drawn controls to set the dimensions of the specified item. For
250/// list boxes and control boxes, this function applies to specific items; for other
251/// owner-drawn controls, this function is used to set the total size of the
252/// control.
253//
254void
256{
257 TRACEX(OwlControl, 1, "TControl::MeasureItem() @" << (void*)this);
258 if(measureInfo.itemData){
259 TDrawItem* item = ItemData2DrawItem(measureInfo.itemData);
260 if(item)
261 item->Measure(measureInfo);
262 }
263}
264
265//
266/// Handles WM_DRAWITEM message (for owner draw controls) by calling the
267/// corresponding virtual function.
268//
269void
271{
272 DRAWITEMSTRUCT i(drawInfo); // Create copy to support legacy non-const virtual DrawItem.
273 DrawItem(i);
274}
275
276//
277/// Function called when a WM_DRAWITEM is sent to parent on our behalf. This
278/// is in turn broken up into one of three draw events.
279//
280/// Responds to a message forwarded by TWindow to a drawable control when the
281/// control needs to be drawn. DrawItem calls one of the following: ODADrawEntire() if
282/// the entire control needs to be drawn, ODASelect() if the selection state of the
283/// control has changed, or ODAFocus() if the focus has been shifted to or from the
284/// control.
285//
286void
288{
289 switch (drawInfo.itemAction) {
290 case ODA_DRAWENTIRE:
292 break;
293
294 case ODA_FOCUS:
296 break;
297
298 case ODA_SELECT:
300 break;
301 }
302}
303
304//
305/// Responds to a notification message sent to a drawable control when the control
306/// needs to be drawn. ODADrawEntire can be redefined by a drawable control to
307/// specify the manner in which it is to be drawn.
308//
309void
311{
312 TRACEX(OwlControl, 1, "TControl::ODADrawEntire() @" << (void*)this);
313 if(drawInfo.itemData && drawInfo.itemID != (uint16)-1){
314 TDrawItem* item = ItemData2DrawItem(drawInfo.itemData);
315 if(item)
316 item->Draw(drawInfo);
317 }
318}
319
320//
321/// Responds to a notification sent to a drawable control when the focus has shifted
322/// to or from the control. ODAFocus can be redefined by a drawable control to
323/// specify the manner in which it is to be drawn when losing or gaining the focus.
324//
325void
327{
328 TRACEX(OwlControl, 1, "TControl::ODAFocus() @" << (void*)this);
329 if(drawInfo.itemData){
330 TDrawItem* item = ItemData2DrawItem(drawInfo.itemData);
331 if(item)
332 item->Draw(drawInfo);
333 }
334}
335
336//
337/// Responds to a notification sent to a drawable control when the selection state
338/// of the control changes. ODASelect can be redefined by a drawable control to
339/// specify the manner in which it is drawn when its selection state changes.
340//
341void
343{
344 TRACEX(OwlControl, 1, "TControl::ODASelect() @" << (void*)this);
345 if(drawInfo.itemData){
346 TDrawItem* item = ItemData2DrawItem(drawInfo.itemData);
347 if(item)
348 item->Draw(drawInfo);
349 }
350}
351
352
354
355#if OWL_PERSISTENT_STREAMS
356
357//
358//
359//
360void*
361TControl::Streamer::Read(ipstream& is, uint32 version) const
362{
363 TControl* o = GetObject();
365
366 if (version > 1) {
367 int nu;
368 is >> nu; //Old NativeUse flag. Ignored in 6.32 and later versions
369 static_cast<void>(nu); // Eliminate 'never used' warning.
370 }
371
372 return o;
373}
374
375//
376//
377//
378void
379TControl::Streamer::Write(opstream& os) const
380{
381 TControl* o = GetObject();
382 WriteBaseObject((TWindow*)o, os);
383 os << 0; //Old NativeUse flag. Ignored in 6.32 and later versions
384}
385#endif
386
387} // OWL namespace
388
#define TRACEX(group, level, message)
Definition checks.h:263
#define DIAG_DEFINE_GROUP_INIT(f, g, e, l)
Definition checks.h:429
TControl unifies its derived control classes, such as TScrollBar, TControlGadget, and TButton.
Definition control.h:38
auto EvEraseBkgnd(HDC) -> bool
Provides special handling for predefined controls.
Definition control.cpp:174
~TControl() override
Definition control.cpp:146
void EvPaint()
Intercept WM_PAINT to redirect from TWindow to the underlying control if this Owl object is just a wr...
Definition control.cpp:159
virtual void MeasureItem(MEASUREITEMSTRUCT &measureInfo)
Function called when a WM_MEASUREITEM is sent to parent on our behalf.
Definition control.cpp:255
virtual void ODAFocus(DRAWITEMSTRUCT &drawInfo)
Responds to a notification sent to a drawable control when the focus has shifted to or from the contr...
Definition control.cpp:326
virtual void ODASelect(DRAWITEMSTRUCT &drawInfo)
Responds to a notification sent to a drawable control when the selection state of the control changes...
Definition control.cpp:342
virtual void ODADrawEntire(DRAWITEMSTRUCT &drawInfo)
Responds to a notification message sent to a drawable control when the control needs to be drawn.
Definition control.cpp:310
void EvMeasureItem(uint ctrlId, MEASUREITEMSTRUCT &meas)
Handles WM_MEASUREITEM message (for owner draw controls) by calling the corresponding virtual functio...
Definition control.cpp:241
void EvDeleteItem(uint ctrlId, const DELETEITEMSTRUCT &del)
Handles WM_DELETEITEM message (for owner draw controls) by calling the corresponding virtual function...
Definition control.cpp:218
virtual void DrawItem(DRAWITEMSTRUCT &drawInfo)
Function called when a WM_DRAWITEM is sent to parent on our behalf.
Definition control.cpp:287
void EvDrawItem(uint ctrlId, const DRAWITEMSTRUCT &draw)
Handles WM_DRAWITEM message (for owner draw controls) by calling the corresponding virtual function.
Definition control.cpp:270
TControl(TWindow *parent, int id, LPCTSTR title, int x, int y, int w, int h, TModule *module=nullptr)
Invokes TWindow's constructor, passing it parent (parent window), title (caption text),...
Definition control.cpp:43
int EvCompareItem(uint ctrlId, const COMPAREITEMSTRUCT &comp)
Handles WM_COMPAREITEM message (for owner draw controls) by calling the corresponding virtual functio...
Definition control.cpp:186
virtual void DeleteItem(DELETEITEMSTRUCT &deleteInfo)
Function called when a WM_DELETEITEM is sent to parent on our behalf.
Definition control.cpp:231
virtual int CompareItem(COMPAREITEMSTRUCT &compareInfo)
Function called when a WM_COMPAREITEM is sent to parent on our behalf.
Definition control.cpp:200
virtual void Measure(MEASUREITEMSTRUCT &)
Definition window.h:195
virtual void Draw(DRAWITEMSTRUCT &)
Definition window.h:194
virtual int Compare(COMPAREITEMSTRUCT &)
Definition window.h:196
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
bool EvEraseBkgnd(HDC)
Handler for WM_ERASEBKGND.
Definition window.cpp:1924
void EvPaint()
Response method for an incoming WM_PAINT message.
Definition window.cpp:2041
void Init(TWindow *parent, LPCTSTR title, TModule *module)
Normal initialization of a default constructed TWindow.
Definition window.cpp:401
void SetFlag(uint mask)
Sets the specified TWindow wfXxxx constant flags (for example wfAlias, wfTransfer,...
Definition window.h:1783
void EnableTransfer()
Enables the transfer mechanism, which allows state data to be transferred between the window and a tr...
Definition window.h:1828
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
Definition window.cpp:852
bool IsFlagSet(uint mask)
Returns the state of the bit flag in Attr.Flags whose mask is supplied.
Definition window.h:1797
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
Definition of class TControl.
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
void ReadBaseObject(Base *base, ipstream &in)
Definition objstrm.h:1159
#define IMPLEMENT_STREAMABLE1(cls, base1)
Definition objstrm.h:1725
void WriteBaseObject(Base *base, opstream &out)
Definition objstrm.h:1150
@ wfPredefinedClass
Window class used belongs to a predefined Windows class and was not defined by OWL.
Definition window.h:66
@ wfFromResource
Handle comes from HWND created from resource.
Definition window.h:61
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
EV_WM_DELETEITEM
Definition combobex.cpp:26
EV_WM_PAINT
Definition control.cpp:28
unsigned long uint32
Definition number.h:34
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
EV_WM_COMPAREITEM
Definition combobex.cpp:25
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
EV_WM_DRAWITEM
Definition combobex.cpp:27
TDrawItem * ItemData2DrawItem(ULONG_PTR data)
Handles WM_DRAWITEM message (for owner draw controls & menus) by forwarding message to control itself...
Definition window.cpp:4464
EV_WM_MEASUREITEM
Definition combobex.cpp:28
#define OWL_CDLEVEL
Definition defs.h:171
#define OWL_INI
Definition defs.h:170