OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
button.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 TButton. This defines the basic behavior of all
7/// buttons.
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/button.h>
11#include <owl/applicat.h>
12
13#if defined(OWL_SUPPORT_BWCC)
14# include <owl/private/bwcc.h>
15#endif
16
17namespace owl {
18
21
22
25 EV_MESSAGE(BM_SETSTYLE, BMSetStyle),
27
28
29//
30/// Constructs a button object with the supplied parent window (parent), control ID
31/// (Id), associated text (text), position (X,Y) relative to the origin of the
32/// parent window's client area, width (W), and height (H). If IsDefault is true,
33/// the constructor adds BS_DEFPUSHBUTTON to the default styles set for the TButton
34/// (in Attr.Style). Otherwise, it adds BS_PUSHBUTTON.
35//
36TButton::TButton(TWindow* parent, int id, LPCTSTR text, int x, int y, int w, int h, bool isDefault, TModule* module)
37:
38 TControl(parent, id, text, x, y, w, h, module)
39{
40 IsCurrentDefPB = false; // not used for buttons in windows
41 IsDefPB = false; // not used for buttons in windows
42
43 if (isDefault)
44 Attr.Style |= BS_DEFPUSHBUTTON;
45
46 else
47 Attr.Style |= BS_PUSHBUTTON;
48 TRACEX(OwlControl, OWL_CDLEVEL, "TButton constructed @" << (void*)this);
49}
50
51//
52/// String-aware overload
53//
54TButton::TButton(TWindow* parent, int id, const tstring& text, int x, int y, int w, int h, bool isDefault, TModule* module)
55:
56 TControl(parent, id, text, x, y, w, h, module)
57{
58 IsCurrentDefPB = false; // not used for buttons in windows
59 IsDefPB = false; // not used for buttons in windows
60
61 if (isDefault)
62 Attr.Style |= BS_DEFPUSHBUTTON;
63
64 else
65 Attr.Style |= BS_PUSHBUTTON;
66 TRACEX(OwlControl, OWL_CDLEVEL, "TButton constructed @" << (void*)this);
67}
68
69//
70/// Constructs a TButton object to be associated with a button control of a TDialog
71/// object. Calls DisableTransfer to exclude the button from the transfer mechanism
72/// because there is no data to be transferred.
73/// The resId parameter must correspond to a button resource that you define.
74//
76:
77 TControl(parent, resourceId, module)
78{
80 IsDefPB = false; // needed for drawable buttons
81 IsCurrentDefPB = false; // needed for drawable buttons
82 TRACEX(OwlControl, OWL_CDLEVEL, "TButton constructed from resource @" << (void*)this);
83}
84
85//
86/// Constructs a TButton object to encapsulate (alias) an existing control.
87//
89:
90 TControl(hWnd, module)
91{
92 // TODO: Test the effect of these initializations.
93 //
94 IsDefPB = GetStyle() & BS_DEFPUSHBUTTON;
95 IsCurrentDefPB = false;
96 TRACEX(OwlControl, OWL_CDLEVEL, _T("TButton alias constructed @") << (void*)this);
97}
98
99//
100/// Output a debug message if using the diagnostic libraries.
101//
103{
104 TRACEX(OwlControl, OWL_CDLEVEL, "TButton destructed @" << (void*)this);
105}
106
107//
108/// Return name of predefined Windows button class
109//
110/// Overrides TWindow's GetWindowClassName function. Returns the name "BUTTON".
111//
113{
114#if defined(OWL_SUPPORT_BWCC)
115 if (GetApplication()->BWCCEnabled()) {
116 TRACEX(OwlControl, 1, "BWCC button used for classname @" << (void*)this);
118 }
119#endif
120 TRACEX(OwlControl, 1, "Regular button used for classname @" << (void*)this);
121 return TWindowClassName{_T("BUTTON")};
122}
123
124//
125/// Overrides TWindow's SetupWindow function. If the button is the default push
126/// button and an owner-drawn button, SetupWindow sends a DM_SETDEFID message to the
127/// parent window.
128//
129/// \note this only works (and IsDefPB should only be true) if Parent is a dialog
130//
131void
133{
134 TRACEX(OwlControl, 1, "TButton::SetupWindow() @" << (void*)this);
135 if (IsDefPB && ((Attr.Style & BS_OWNERDRAW) == BS_OWNERDRAW))
136 Parent->HandleMessage(DM_SETDEFID, Attr.Id);
137}
138
139//
140/// Responds to WM_GETDLGCODE messages that are sent to a dialog box associated with
141/// a control. EvGetDlgCode allows the dialog manager to intercept a message that
142/// would normally go to a control and then ask the control if it wants to process
143/// this message. If not, the dialog manager processes the message. The msg
144/// parameter indicates the kind of message (for example, a control, command, or
145/// button message) sent to the dialog box manager.
146///
147/// EvGetDlgCode returns a code that indicates how the button is to be treated. If
148/// this is the currently used push button, EvGetDlgCode returns either
149/// DLGC_DEFPUSHBUTTON or DLGC_UNDEFPUSHBUTTON.
150///
151/// if this is a drawable button we tell Windows whether we want to
152/// be treated as the current default push button or not
153//
154uint
156{
157 if ((Attr.Style & BS_OWNERDRAW) != BS_OWNERDRAW)
159
160 else if (IsCurrentDefPB)
162
163 else
165}
166
167//
168/// Because a button can't have both owner-drawn and push button styles, BMSetStyle
169/// keeps track of the style if the button is owner-drawn and the system tries to
170/// set the style to BS_DEFPUSHBUTTON. BMSetStyle sets IsCurrentDefPB to true if the
171/// button style is BS_DEFPUSHBUTTON.
172//
175{
176 if ((Attr.Style & BS_OWNERDRAW) != BS_OWNERDRAW)
178 else if (param1 == BS_DEFPUSHBUTTON) {
179 IsCurrentDefPB = true;
180 Invalidate();
181 }
182 else if (param1 == BS_PUSHBUTTON) {
183 IsCurrentDefPB = false;
184 Invalidate();
185 }
186 else {
188 }
189
190 return 0;
191}
192
194
195#if OWL_PERSISTENT_STREAMS
196
197//
198//
199//
200void*
201TButton::Streamer::Read(ipstream& is, uint32 /*version*/) const
202{
203 ReadBaseObject((TControl*)GetObject(), is);
204 is >> GetObject()->IsDefPB;
205 return GetObject();
206}
207
208//
209//
210//
211void
212TButton::Streamer::Write(opstream& os) const
213{
214 WriteBaseObject((TControl*)GetObject(), os);
215 os << GetObject()->IsDefPB;
216}
217#endif
218
219
220} // OWL namespace
221
Definition of class TApplication.
Definition of class TButton.
Legacy support for Borland Windows Custom Controls (BWCC)
#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
TButton(TWindow *parent, int id, LPCTSTR text, int X, int Y, int W, int H, bool isDefault=false, TModule *=0)
Constructs a button object with the supplied parent window (parent), control ID (Id),...
Definition button.cpp:36
TResult BMSetStyle(TParam1, TParam2)
Because a button can't have both owner-drawn and push button styles, BMSetStyle keeps track of the st...
Definition button.cpp:174
void SetupWindow() override
Overrides TWindow's SetupWindow function.
Definition button.cpp:132
auto GetWindowClassName() -> TWindowClassName override
Return name of predefined Windows button class.
Definition button.cpp:112
virtual ~TButton()
Output a debug message if using the diagnostic libraries.
Definition button.cpp:102
uint EvGetDlgCode(const MSG *)
Responds to WM_GETDLGCODE messages that are sent to a dialog box associated with a control.
Definition button.cpp:155
TControl unifies its derived control classes, such as TScrollBar, TControlGadget, and TButton.
Definition control.h:38
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
uint EvGetDlgCode(const MSG *msg)
The default message handler for WM_GETDLGCODE.
Definition window.h:3698
void DisableTransfer()
Disables (for the interface object) the transfer mechanism, which allows state data to be transferred...
Definition window.h:1835
uint32 GetStyle() const
Gets the style bits of the underlying window or the 'Style' member of the attribute structure associa...
Definition window.cpp:3558
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
Definition window.cpp:852
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
virtual void Invalidate(bool erase=true)
Invalidates (mark for painting) the entire client area of a window.
Definition window.h:2822
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
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned long uint32
Definition number.h:34
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
LRESULT TResult
Result type.
Definition dispatch.h:52
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_MESSAGE(message, method)
Response table entry for raw message handling Uses a dispatcher that just forwards WPARAM and LPARAM.
Definition windowev.h:113