OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
checkbox.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/// Implemenation of class TCheckBox. This defines the basic behavior for all
7/// check boxes.
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/checkbox.h>
11#include <owl/groupbox.h>
12#include <owl/applicat.h>
13
14#if defined(OWL_SUPPORT_BWCC)
15# include <owl/private/bwcc.h>
16#endif
17
18namespace owl {
19
22
23
24DEFINE_RESPONSE_TABLE1(TCheckBox, TButton)
28
29//
30/// constructor for a TCheckBox object
31//
32/// Constructs a check box object with the specified parent window (parent), control
33/// ID (Id), associated text (title), position relative to the origin of the parent
34/// window's client area (x, y), width (w), height (h), associated group box
35/// (group), and owning module (module). Invokes the TButton constructor with
36/// similar parameters. Sets the check box's style to WS_CHILD | WS_VISIBLE |
37/// WS_TABSTOP | BS_AUTOCHECKBOX.
38//
39TCheckBox::TCheckBox(TWindow* parent, int id, LPCTSTR title, int x, int y, int w, int h, TGroupBox* group, TModule* module)
40:
41 TButton(parent, id, title, x, y, w, h, false, module)
42{
43 Group = group;
44 //
45 // Don't use TButton's inherited style - it conflicts with BS_AUTOCHECKBOX
46 //
48
49 TRACEX(OwlControl, OWL_CDLEVEL, _T("TCheckBox constructed @") << (void*)this);
50}
51
52//
53/// String-aware overload
54//
55TCheckBox::TCheckBox(TWindow* parent, int id, const tstring& title, int x, int y, int w, int h, TGroupBox* group,
56 TModule* module)
57:
58 TButton(parent, id, title, x, y, w, h, false, module)
59{
60 Group = group;
61 //
62 // Don't use TButton's inherited style - it conflicts with BS_AUTOCHECKBOX
63 //
65
66 TRACEX(OwlControl, OWL_CDLEVEL, _T("TCheckBox constructed @") << (void*)this);
67}
68
69//
70/// Constructs a TCheckButton object to encapsulate (alias) an existing control.
71//
73:
74 TButton(hWnd, module),
75 Group(nullptr)
76{
77 TRACEX(OwlControl, OWL_CDLEVEL, _T("TCheckBox alias constructed @") << (void*)this);
78}
79
80
81//
82/// Constructs an associated TCheckBox object for the check box control with a
83/// resource ID of resourceId in the parent dialog box. Sets Group to group then
84/// enables the data transfer mechanism by calling TWindow::EnableTransfer.
85//
87 int resourceId,
89 TModule* module)
90:
91 TButton(parent, resourceId, module)
92{
93 Group = group;
95
96 TRACEX(OwlControl, OWL_CDLEVEL, _T("TCheckBox constructed from resource @") << (void*)this);
97}
98
99//
100/// Output a trace message if using the diagnostic libraries.
101//
103{
104 TRACEX(OwlControl, OWL_CDLEVEL, _T("TCheckBox destructed @") << (void*)this);
105}
106
107//
108/// Return name of Windows check box class
109//
110/// returns "BUTTON."
111//
113{
114#if defined(OWL_SUPPORT_BWCC)
115 if (GetApplication()->BWCCEnabled()) {
116 TRACEX(OwlControl, 1, _T("BWCC checkbox used for classname @") << (void*)this);
117 // !CQ to be consistent, we should do this trace for ALL bwcc-able controls,
118 // !CQ or none.
120 }
121#endif
122 TRACEX(OwlControl, 1, _T("Regular checkbox used for classname @") << (void*)this);
123 return TWindowClassName{_T("BUTTON")};
124}
125
126//
127/// transfers state information for the TCheckBox
128//
129/// Overrides TWindow::Transfer. Transfers the check state of the check box to or
130/// from buffer, using the values specified in the table in GetCheck(). If direction
131/// is tdGetDate, the check box state is transferred into the buffer. If direction
132/// is tdSetData, the check box state is changed to the settings in the transfer
133/// buffer.
134/// Transfer() returns the size of the transfer data in bytes. To get the size without
135/// actually transferring the check box, use tdSizeData as the direction argument.
136//
137uint
139{
140 if (!buffer && direction != tdSizeData) return 0;
141 if (direction == tdGetData)
142 *reinterpret_cast<uint16*>(buffer) = static_cast<uint16>(GetCheck());
143
144 else if (direction == tdSetData)
146
147 return sizeof(uint16);
148}
149
150//
151/// Forces the check box into the state specified by check.
152//
153/// unchecks, checks, or grays the checkbox (if 3-state) according to the
154/// CheckFlag passed (pass BF_UNCHECKED(0), BF_CHECKED(1), or BF_GRAYED(2))
155//
156/// if a Group has been specified for the TCheckBox, notifies the Group that
157/// the state of the check box has changed
158//
159void
161{
163 SendMessage(BM_SETCHECK, check);
164
165 if (Group)
166 Group->SelectionChanged(Attr.Id);
167}
168
169//
170/// Toggles the check state of the check box
171//
172/// Toggles the check box between checked and unchecked if it is a two-state check
173/// box; toggles it between checked, unchecked, and gray if it is a three-state
174/// check box.
175//
176void
178{
180 SetCheck((GetCheck() + 1) % 3);
181
182 else
183 SetCheck((GetCheck() + 1) % 2);
184}
185
186//
187/// Responds to an incoming BN_CLICKED message
188//
189/// Responds to notification message BN_CLICKED, indicating that the user clicked
190/// the check box. If Group isn't 0, BNClicked() calls the group box's
191/// SelectionChanged() member function to notify the group box that the state has
192/// changed.
193//
194void
196{
197 if (Group)
198 Group->SelectionChanged(Attr.Id);
199
200 DefaultProcessing(); // give parent an opportunity to handle...
201}
202
204
205#if OWL_PERSISTENT_STREAMS
206
207//
208/// reads an instance of TCheckBox from the passed ipstream
209//
210void*
211TCheckBox::Streamer::Read(ipstream& is, uint32 /*version*/) const
212{
213 ReadBaseObject((TButton*)GetObject(), is);
214 is >> GetObject()->Group;
215 return GetObject();
216}
217
218//
219/// writes the TCheckBox to the passed opstream
220//
221void
222TCheckBox::Streamer::Write(opstream& os) const
223{
224 WriteBaseObject((TButton*)GetObject(), os);
225 os << GetObject()->Group;
226}
227#endif
228
229
230} // OWL namespace
231///////////////////////////////////////
232
Definition of class TApplication.
Legacy support for Borland Windows Custom Controls (BWCC)
Definition of class TCheckBox.
#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
TButton is an interface class derived from TControl that represents a pushbutton interface element.
Definition button.h:41
TCheckBox is a streamable interface class that represents a check box control.
Definition checkbox.h:53
void Toggle()
Toggles the check state of the check box.
Definition checkbox.cpp:177
~TCheckBox() override
Output a trace message if using the diagnostic libraries.
Definition checkbox.cpp:102
uint GetCheck() const
Returns the state of the check box.
Definition checkbox.h:168
TCheckBox(TWindow *parent, int id, LPCTSTR title, int x, int y, int w, int h, TGroupBox *=0, TModule *=0)
constructor for a TCheckBox object
Definition checkbox.cpp:39
auto GetWindowClassName() -> TWindowClassName override
Return name of Windows check box class.
Definition checkbox.cpp:112
void BNClicked()
Responds to an incoming BN_CLICKED message.
Definition checkbox.cpp:195
void Transfer(WORD &state, TTransferDirection direction)
Safe overload.
Definition checkbox.h:79
void SetCheck(uint check)
Forces the check box into the state specified by check.
Definition checkbox.cpp:160
An instance of a TGroupBox is an interface object that represents a corresponding group box element.
Definition groupbox.h:50
virtual void SelectionChanged(int controlId)
If NotifyParent is true, SelectionChanged notifies the parent window of the group box that one of its...
Definition groupbox.cpp:104
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Definition module.h:47
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
long GetWindowLong(int index) const
Retrieves information about the window depending on the value stored in index.
Definition window.h:2388
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
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition window.cpp:3288
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
#define _T(x)
Definition cygwin.h:51
#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
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
Definition window.h:92
@ tdSizeData
Return the size of data transferred by the class.
Definition window.h:95
@ tdSetData
Set data from the buffer into the window.
Definition window.h:94
@ tdGetData
Get data from the window into the buffer.
Definition window.h:93
Definition of class TGroupBox.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned long uint32
Definition number.h:34
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
unsigned short uint16
Definition number.h:33
std::string tstring
Definition defs.h:79
EV_WM_GETDLGCODE
Definition button.cpp:24
unsigned int uint
Definition number.h:25
#define OWL_CDLEVEL
Definition defs.h:171
#define EV_NOTIFY_AT_CHILD(notifyCode, method)
Response table entry for a child ID notification handled at the child.
Definition windowev.h:162