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.h
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/// Definition of class TButton. This defines the basic behavior of all buttons.
7//----------------------------------------------------------------------------
8
9#if !defined(OWL_BUTTON_H)
10#define OWL_BUTTON_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17#include <owl/control.h>
18
19namespace owl {
20
21#include <owl/preclass.h>
22
23//
24/// \addtogroup ctrl
25/// @{
26
27//
28/// \class TButton
29/// TButton is an interface class derived from TControl that represents a pushbutton
30/// interface element. You must use a TButton to create a button control in a parent
31/// TWindow object. You can also use a TButton to facilitate communication between
32/// your application and the button controls of a TDialog object. This class is
33/// streamable.
34///
35/// There are two types of pushbuttons: regular and default. Regular buttons have a
36/// thin border. Default buttons (which represent the default action of the window)
37/// have a thick border.
38//
40 : public TControl
41{
42 public:
43
44 TButton(TWindow* parent, int id, LPCTSTR text, int X, int Y, int W, int H, bool isDefault = false, TModule* = 0);
45 TButton(TWindow* parent, int id, const tstring& text, int X, int Y, int W, int H, bool isDefault = false, TModule* = 0);
46 TButton(TWindow* parent, int resourceId, TModule* = 0);
48
49 virtual ~TButton();
50
51 bool GetIsDefPB() const;
52 void SetIsDefPB(bool isdefpb);
53
54 bool GetIsCurrentDefPB() const;
55 void SetIsCurrentDefPB(bool is);
56
57 uint GetState() const;
58 void SetState(uint state);
59
60 void SetStyle(uint style, bool redraw);
61
62 void Click();
63
64 /// For use with SetImage method.
65 //
66 enum TImageType {Bitmap=IMAGE_BITMAP, Icon=IMAGE_ICON};
67
68 HANDLE GetImage() const;
69 HANDLE SetImage(HANDLE image, TImageType imageType = Bitmap);
70
71 protected:
72
73 // Message response functions
74 //
75 uint EvGetDlgCode(const MSG*);
76 TResult BMSetStyle(TParam1, TParam2);
77
78 // Override TWindow member functions
79 //
80 auto GetWindowClassName() -> TWindowClassName override;
81 void SetupWindow() override;
82
84
85 /// Indicates whether the button is to be considered the default push button. Used
86 /// for owner-draw buttons, IsDefPB is set by a TButton constructor based on
87 /// BS_DEFPUSHBUTTON style setting.
88 //
89 bool IsDefPB;
90
92
93 /// Indicates whether the current button is the default push button.
94 //
95 bool IsCurrentDefPB;
96
97 private:
98
99 // Hidden to prevent accidental copying or assignment
100 //
101 TButton(const TButton&);
102 TButton& operator=(const TButton&);
103
106};
107
108/// @}
109
111
112#include <owl/posclass.h>
113
114//
115// button notification response table entry macros, methods are: void method()
116//
117// EV_BN_CLICKED(id, method)
118// EV_BN_DISABLE(id, method)
119// EV_BN_DOUBLECLICKED(id, method)
120// EV_BN_HILITE(id, method)
121// EV_BN_PAINT(id, method)
122// EV_BN_UNHILITE(id, method)
123
124//----------------------------------------------------------------------------
125// Inline implementations
126//
127
128//
129/// Return true if this button is the default pushbutton.
130//
131inline bool TButton::GetIsDefPB() const
132{
133 return IsDefPB;
134}
135
136//
137/// Set this button the default pushbutton.
138//
140{
141 IsDefPB = isdefpb;
142}
143
144//
145/// Return true if this button is the current default pushbutton.
146//
147inline bool TButton::GetIsCurrentDefPB() const
148{
149 return IsCurrentDefPB;
150}
151
152//
153/// Set this button the current default push button.
154//
156{
157 IsCurrentDefPB = is;
158}
159
160//
161/// Simulate clicking of this button
162//
163/// Sends a BM_CLICK message to simulate the user clicking a button.
164/// This message causes the button to receive a WM_LBUTTONDOWN and a WM_LBUTTONUP
165/// message, and the button's parent window to receive a BN_CLICKED notification
166/// message.
167//
168inline void TButton::Click()
169{
172}
173
174//
175/// Return the handle (icon or bitmap) of the image associated with the
176/// button; NULL if there is no associated image.
177//
179{
181 return (HANDLE)CONST_CAST(TButton*, this)->SendMessage(BM_GETIMAGE);
182}
183
184//
185/// Associates a new image (icon or bitmap) with the button. newImage is
186/// the handle of the new image. imageType specifies the type of image. The return
187/// value is the handle of the image previously associated with the button, if any;
188/// otherwise, it is NULL.
189//
195
196//
197/// Set the highlight state of a button. The highlight state indicates whether the
198/// button is highlighted as if the user had pushed it. If state is true the button
199/// is highlighted; a value of false removes any highlighting.
200//
201inline void TButton::SetState(uint state)
202{
204 SendMessage(BM_SETSTATE, state);
205}
206
207//
208/// Returns the current state of the button. The following bit masks can be used to
209/// determine the state:
210///
211/// - \c \b BST_CHECKED Indicates the button is checked.
212/// - \c \b BST_FOCUS Specifies the focus state. A nonzero value indicates that the button has the keyboard focus.
213/// - \c \b BST_INDETERMINATE Indicates the button is grayed because the state of the button
214/// is indeterminate. This value applies only if the button has the BS_3STATE or BS_AUTO3STATE style.
215/// - \c \b BST_PUSHED Specifies the highlight state. A nonzero value indicates that the
216/// button is highlighted. A button is automatically highlighted when the user
217/// positions the cursor over it and presses and holds the left mouse button. The
218/// highlighting is removed when the user releases the mouse button.
219/// - \c \b BST_UNCHECKED Indicates the button is unchecked. Same as the Windows NT return
220/// value of zero.
221//
223{
225 return (uint)CONST_CAST(TButton*, this)->SendMessage(BM_GETSTATE);
226}
227
228//
229/// Change the style of a button. If redraw is true the button is redrawn. The
230/// style parameter can be one of the following:
231///
232/// - \c \b BS_3STATE Creates a button that is the same as a check box, except that the box
233/// can be grayed as well as checked or unchecked. Use the grayed state to show that
234/// the state of the check box is not determined.
235/// - \c \b BS_AUTO3STATE Creates a button that is the same as a three-state check box,
236/// except that the box changes its state when the user selects it. The state cycles
237/// through checked, grayed, and unchecked.
238/// - \c \b BS_AUTOCHECKBOX Creates a button that is the same as a check box, except that
239/// the check state automatically toggles between checked and unchecked each time
240/// the user selects the check box.
241/// - \c \b BS_AUTORADIOBUTTON Creates a button that is the same as a radio button, except
242/// that when the user selects it, Windows automatically sets the button's check
243/// state to checked and automatically sets the check state for all other buttons in
244/// the same group to unchecked.
245/// - \c \b BS_CHECKBOX Creates a small, empty check box with text. By default, the text is
246/// displayed to the right of the check box. To display the text to the left of the
247/// check box, combine this flag with the BS_LEFTTEXT style (or with the equivalent
248/// BS_RIGHTBUTTON style).
249/// - \c \b BS_DEFPUSHBUTTON Creates a push button that behaves like a BS_PUSHBUTTON style
250/// button, but also has a heavy black border. If the button is in a dialog box, the
251/// user can select the button by pressing the ENTER key, even when the button does
252/// not have the input focus. This style is useful for enabling the user to quickly
253/// select the most likely (default) option.
254/// - \c \b BS_GROUPBOX Creates a rectangle in which other controls can be grouped. Any text
255/// associated with this style is displayed in the rectangle's upper left corner.
256/// - \c \b BS_LEFTTEXT Places text on the left side of the radio button or check box when
257/// combined with a radio button or check box style. Same as the BS_RIGHTBUTTON
258/// style.
259/// - \c \b BS_OWNERDRAW Creates an owner-drawn button. The owner window receives a
260/// WM_MEASUREITEM message when the button is created and a WM_DRAWITEM message when
261/// a visual aspect of the button has changed. Do not combine the BS_OWNERDRAW style
262/// with any other button styles.
263/// - \c \b BS_PUSHBUTTON Creates a push button that posts a WM_COMMAND message to the owner
264/// window when the user selects the button.
265/// - \c \b BS_RADIOBUTTON Creates a small circle with text. By default, the text is
266/// displayed to the right of the circle. To display the text to the left of the
267/// circle, combine this flag with the BS_LEFTTEXT style (or with the equivalent
268/// BS_RIGHTBUTTON style). Use radio buttons for groups of related, but mutually
269/// exclusive choices.
270/// - \c \b BS_USERBUTTON Obsolete, but provided for compatibility with 16-bit versions of
271/// Windows. Win32-based applications should use BS_OWNERDRAW instead.
272/// - \c \b BS_BITMAP Specifies that the button displays a bitmap.
273/// - \c \b BS_BOTTOM Places text at the bottom of the button rectangle.
274/// - \c \b BS_CENTER Centers text horizontally in the button rectangle.
275/// - \c \b BS_ICON Specifies that the button displays an icon.
276/// - \c \b BS_LEFT Left-justifies the text in the button rectangle. However, if the button
277/// is a check box or radio button that does not have the BS_RIGHTBUTTON style, the
278/// text is left justified on the right side of the check box or radio button.
279/// - \c \b BS_MULTILINE Wraps the button text to multiple lines if the text string is too
280/// long to fit on a single line in the button rectangle.
281/// - \c \b BS_NOTIFY Enables a button to send BN_DBLCLK, BN_KILLFOCUS, and BN_SETFOCUS
282/// notification messages to its parent window. Note that buttons send the
283/// - \c \b BN_CLICKED notification message regardless of whether it has this style.
284/// - \c \b BS_PUSHLIKE Makes a button (such as a check box, three-state check box, or radio
285/// button) look and act like a push button. The button looks raised when it isn't
286/// pushed or checked, and sunken when it is pushed or checked.
287/// - \c \b BS_RIGHT Right-justifies text in the button rectangle. However, if the button
288/// is a check box or radio button that does not have the BS_RIGHTBUTTON style, the
289/// text is right justified on the right side of the check box or radio button.
290/// - \c \b BS_RIGHTBUTTON Positions a radio button's circle or a check box's square on the
291/// right side of the button rectangle. Same as the BS_LEFTTEXT style.
292/// - \c \b BS_TEXT Specifies that the button displays text.
293/// - \c \b BS_TOP Places text at the top of the button rectangle.
294/// - \c \b BS_VCENTER Places text in the middle (vertically) of the button rectangle.
295//
296inline void TButton::SetStyle(uint style, bool redraw)
297{
300}
301
302
303} // OWL namespace
304
305
306#endif // OWL_BUTTON_H
307
#define PRECONDITION(condition)
Definition checks.h:227
TButton is an interface class derived from TControl that represents a pushbutton interface element.
Definition button.h:41
TImageType
For use with SetImage method.
Definition button.h:66
bool GetIsCurrentDefPB() const
Return true if this button is the current default pushbutton.
Definition button.h:147
void SetIsCurrentDefPB(bool is)
Set this button the current default push button.
Definition button.h:155
void SetState(uint state)
Set the highlight state of a button.
Definition button.h:201
HANDLE SetImage(HANDLE image, TImageType imageType=Bitmap)
Associates a new image (icon or bitmap) with the button.
Definition button.h:190
HANDLE GetImage() const
Return the handle (icon or bitmap) of the image associated with the button; NULL if there is no assoc...
Definition button.h:178
void SetIsDefPB(bool isdefpb)
Set this button the default pushbutton.
Definition button.h:139
void SetStyle(uint style, bool redraw)
Change the style of a button.
Definition button.h:296
void Click()
Simulate clicking of this button.
Definition button.h:168
bool GetIsDefPB() const
Return true if this button is the default pushbutton.
Definition button.h:131
uint GetState() const
Returns the current state of the button.
Definition button.h:222
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
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
Definition of class TControl.
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
#define DECLARE_STREAMABLE_OWL(cls, ver)
Definition objstrm.h:1529
#define DECLARE_STREAMABLE_INLINES(cls)
Definition objstrm.h:1538
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
TParam2 MkParam2(const T1 &lo, const T2 &hi)
Definition dispatch.h:65
LRESULT TResult
Result type.
Definition dispatch.h:52
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
#define protected_data
Definition defs.h:208
#define public_data
Definition defs.h:207
#define CONST_CAST(targetType, object)
Definition defs.h:273
#define _OWLCLASS
Definition defs.h:338