OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
buttonga.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Definition of class TButtonGadget.
7//----------------------------------------------------------------------------
8
9#if !defined(OWL_BUTTONGA_H)
10#define OWL_BUTTONGA_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17#include <owl/gadget.h>
18
19namespace owl {
20
21class _OWLCLASS TCelArray;
22
23#include <owl/preclass.h>
24
25/// \addtogroup gadgets
26/// @{
27/// \class TButtonGadget
28// ~~~~~ ~~~~~~~~~~~~~
29/// Derived from TGadget, TButtonGadget represent buttons that you can click on or
30/// off. You can also apply attributes such as color, style, and shape (notched or
31/// unnotched) to your button gadgets.
32///
33/// In general, button gadgets are classified as either command or attribute
34/// buttons. Attribute buttons include radio buttons (which are considered
35/// exclusive), or check boxes (which are nonexclusive). The public data member,
36/// TType, enumerates these button types.
37/// TButtonGadget contains several functions that let you change the style of a
38/// button. Use SetAntialiasEdges to turn antialiasing on and off, SetNotchCorners
39/// to control corner notching, and SetShadowStyle to change the style of the button
40/// shadow.
41///
42/// TButtonGadget objects respond to mouse events in the following manner: when a
43/// mouse button is pressed, the button is pressed; when the mouse button is
44/// released, the button is released. Commands can be entered only when the mouse
45/// button is in the "up" state. When the mouse is pressed, TButtonGadget objects
46/// capture the mouse and reserve all mouse messages for the current window. When
47/// the mouse button is up, button gadgets release the capture for the current
48/// window. The public data member, TState, enumerates the three button states.
49///
50/// Buttons begin highlighting and do a capture when pressed (the mouse down
51/// occurs). they cancel highlighting when the mouse exits, but begin
52/// highlighting again when the mouse re-enters. when the mouse goes up the
53/// capture is released
54//
55/// There are two basic type of buttons: commands and settings (attribute
56/// buttons). Settings can be exclusive (like a radio button) or non-exclusive
57/// (like a check box), or SemiExclusive where they act like both
58//
59/// There are three normal button states: up, down, and indeterminate. in
60/// addition the button can be highlighted (pressed) in all three states
61//
62/// Commands can only be in the "up" state. Settings can be in all three states
63//
64/// \todo Move NotchCorners to OWL5COMPAT, implement repeating commands
66 public:
67/// Enumerates the types of button gadgets. An exclusive button is one that works in
68/// conjunction with other buttons such that one button is activated at a time.
69 enum TType { ///< Basic type of this button
70 Command, ///< Sends a command when pressed.
71 Exclusive, ///< Stays down when pressed and causes other buttons in the group to pop back up.
72 NonExclusive, ///< Toggles its state when pressed and ignores other buttons.
73 SemiExclusive, ///< Same as exclusive, except that it also pops back up if pressed while it is down.
74 RepeatCmd, ///< Auto-repeating command button.
75 };
76
77/// TState enumerates the three button positions during which the button can be
78/// pressed: up (0), down (1), and an indeterminate state (2). A nonzero value
79/// indicates a highlighted button.
80 enum TState { ///< Current state of this button
81 Up, ///< Button is up, i.e. unchecked
82 Down, ///< Button is down, i.e. checked
83 Indeterminate, ///< Button is neither checked nor unchecked
84 };
85
86#if defined(OWL5_COMPAT)
87/// Enumerates button shadow styles--either single (1) or double (2) shadow borders.
88 enum TShadowStyle { ///< Bottom & right side shadow width for old UI style
89 SingleShadow = 1,
90 DoubleShadow = 2,
91 };
92#endif
93
94 TButtonGadget(TResId glyphResIdOrIndex,
95 int id,
96 TType type = Command,
97 bool enabled = false, // initial state before cmd enabling
98 TState state = Up,
99 bool sharedGlyph = false);
100 ~TButtonGadget();
101
102 // Some accessors
103 //
104 void SetButtonState(TState newState);
105 TState GetButtonState() const;
106
107 TType GetButtonType() const;
108
109 // A few button style options. These styles may be ignores on some
110 // UI platforms
111 //
112 bool GetNotchCorners() const;
113 void SetNotchCorners(bool notchCorners=true);
114
115#if defined(OWL5_COMPAT)
118#endif
119
120 bool GetAntialiasEdges() const;
121 void SetAntialiasEdges(bool anti=true);
122
123 // TGadget overrides
124 //
125 virtual void GetDesiredSize(TSize& size);
126 virtual void SetBounds(const TRect& r);
127 virtual void CommandEnable();
128 virtual void SysColorChange();
129
130 protected:
131
132 // TGadget overrides
133 //
134 virtual void Paint(TDC& dc);
135 virtual void PaintBorder(TDC& dc);
136 virtual void MouseEnter(uint modKeys, const TPoint& p);
137 virtual void MouseMove(uint modKeys, const TPoint& p);
138 virtual void MouseLeave(uint modKeys, const TPoint& p);
139 virtual void LButtonDown(uint modKeys, const TPoint& p);
140 virtual void LButtonUp(uint modKeys, const TPoint& p);
141
142 /// Glyph types and construction functions
143 //
144 /// Contains values that allow a glyph button to display different glyphs when its
145 /// state changes. For example, the CelPressed constant could be used to toggle a
146 /// glyph button between a happy face and a sad face when it is pressed.
147 /// \note Unused at the moment.
148 /// \todo Implement the functionality to allow a glyph button to display different glyphs when its
149 /// state changes
150 //
151 enum {
152 //CelMask,
153 CelNormal, ///< Displayed under normal circumstances.
154 CelDisabled, ///< Displayed when the button is disabled (grayed).
155 CelIndeterm, ///< Displayed when an ambiguous or indeterminate state is encountered.
156 CelDown, ///< Displayed when the button is down or checked.
157 CelPressed, ///< Displayed when the button is pressed.
159 };
160
161 // New virtuals
162 //
163 virtual void PaintFace(TDC& dc, const TRect& rect);
164 virtual TDib* GetGlyphDib();
165 virtual void ReleaseGlyphDib(TDib* glyph);
166 virtual void BuildCelArray();
167
168 // Button protocol
169 // ~~~~~~ ~~~~~~~~
170
171 // Invoked by mouse-down & mouse enter events. sets member data "Pressed"
172 // to true and highlights the button
173 //
174 virtual void BeginPressed(const TPoint& p);
175
176 // Invoked by mouse exit events. sets member data "Pressed" to false and
177 // paints the button in its current state.
178 // Sets gadget InMouse member to mstate.
179 //
180 virtual void CancelPressed(const TPoint& p, bool mstate=false);
181
182 // The action method called on a completed 'click', generates WM_COMMAND
183 //
184 virtual void Activate(const TPoint& p);
185
187// !CQ some of these need accessors of some sort...
188 TResId ResId; ///< Holds the resource ID for this button gadget's bitmap.
189 TCelArray* CelArray; ///< CelArray used to cache glyph states
190
191 TPoint BitmapOrigin; ///< Points to the x and y coordinates of the bitmap used for this button gadget.
192 TState State :4; ///< Current state of button
193 TType Type :4; ///< Type of this button
194#if defined(OWL5_COMPAT)
195 TShadowStyle ShadowStyle :4; ///< Shadow style, may be ignored w/ 3dUI
196#endif
197// !CQ bool Repeat :1; // Does this button auto-repeat
198 bool NotchCorners :1; ///< Notch (round) corners? ignored w/ 3dUI
199 bool Pressed :1; ///< Initialized to false, Pressed is true if the button is pushed or false if it is released.
200 bool AntialiasEdges:1; ///< Should border edges be antialiased?
201 bool SharingGlyph; ///< Should the button share glyphs with its gadget window?
202 int GlyphIndex; ///< Base index for our glyph bitmap
203
204 private:
205 int GlyphCount; ///< How many glyphs are we using (1,3,4,5)
206
207 protected:
208 void SetButtonType(TType newType);
209 void SetGlyphIndex(int index);
210 bool IsPressed() const;
211 void CheckExclusively();
212 TResId GetResId() const;
213
214 TCelArray* GetCelArray();
215 const TCelArray* GetCelArray() const;
216
217 TPoint& GetBitmapOrigin();
218 const TPoint& GetBitmapOrigin() const;
219 void SetBitmapOrigin(const TPoint& bitmapOrigin);
220
221 private:
222 friend class TBarDescr;
223};
224/// @}
225
226#include <owl/posclass.h>
227
228//----------------------------------------------------------------------------
229// Inline implementations
230//
231
232//
233/// Returns the state of the button.
234//
236 return State;
237}
238
239//
240/// Return the type of the button.
241//
243 return Type;
244}
245
246//
247/// Returns true if the button has rounded corners. This style may be ignores on
248/// some UI platforms.
249//
251 return NotchCorners;
252}
253
254//
255/// By default, SetNotchCorners implements notched corners for buttons. To repaint
256/// the frame of the button if the window has already been created, call
257/// InvalidateRect with the Bounds rectangle. This style may be ignores on some UI
258/// platforms.
259//
261 NotchCorners = notchCorners;
262}
263
264//
265/// Return the current shadow style of the button.
266//
267#if defined(OWL5_COMPAT)
268inline TButtonGadget::TShadowStyle TButtonGadget::GetShadowStyle() const {
269 return ShadowStyle;
270}
271
272/// Sets the button style to a shadow style which, by default, is DoubleShadow. Sets
273/// the left and top borders to 2 and the right and bottom borders to ShadowStyle +
274/// 1.
275/// \note This is obsolete under modern versions of Windows
276inline void TButtonGadget::SetShadowStyle(TShadowStyle s) {
277 ShadowStyle = s;
278}
279#endif
280
281//
282/// Returns true if the border edges are antialiased.
283//
285 return AntialiasEdges;
286}
287
288//
289/// Turns the antialiasing of the button bevels on or off. By default, antialiasing
290/// is on.
291//
293 AntialiasEdges=anti;
294}
295
296//
297/// Sets the type of the button.
298//
300{
301 Type = newType;
302}
303
304/// Returns the resource ID for this button gadget's bitmap.
306{
307 return ResId;
308}
309
310/// Returns the CelArray used to cache glyph states
312{
313 return CelArray;
314}
315
316/// Returns the CelArray used to cache glyph states
318{
319 return CelArray;
320}
321
322/// Returns the x and y coordinates of the bitmap used for this button gadget.
324{
325 return BitmapOrigin;
326}
327
328/// Returns the x and y coordinates of the bitmap used for this button gadget.
330{
331 return BitmapOrigin;
332}
333
334/// Sets the x and y coordinates of the bitmap used for this button gadget.
336{
337 BitmapOrigin = bitmapOrigin;
338}
339
340/// Returns true if the button is pushed or false if it is released
341inline bool TButtonGadget::IsPressed() const
342{
343 return Pressed;
344}
345
346
347} // OWL namespace
348
349
350#endif // OWL_BUTTONGA_H
Descriptor of Bar Implementation.
Definition bardescr.h:71
Derived from TGadget, TButtonGadget represent buttons that you can click on or off.
Definition buttonga.h:65
TState
TState enumerates the three button positions during which the button can be pressed: up (0),...
Definition buttonga.h:80
@ Down
Button is down, i.e. checked.
Definition buttonga.h:82
@ Up
Current state of this button.
Definition buttonga.h:81
@ Indeterminate
Button is neither checked nor unchecked.
Definition buttonga.h:83
TPoint & GetBitmapOrigin()
Returns the x and y coordinates of the bitmap used for this button gadget.
Definition buttonga.h:323
TResId GetResId() const
Returns the resource ID for this button gadget's bitmap.
Definition buttonga.h:305
bool GetAntialiasEdges() const
Return the current shadow style of the button.
Definition buttonga.h:284
TType
Enumerates the types of button gadgets.
Definition buttonga.h:69
@ NonExclusive
Toggles its state when pressed and ignores other buttons.
Definition buttonga.h:72
@ SemiExclusive
Same as exclusive, except that it also pops back up if pressed while it is down.
Definition buttonga.h:73
@ Exclusive
Stays down when pressed and causes other buttons in the group to pop back up.
Definition buttonga.h:71
@ Command
Basic type of this button.
Definition buttonga.h:70
@ RepeatCmd
Auto-repeating command button.
Definition buttonga.h:74
void SetNotchCorners(bool notchCorners=true)
By default, SetNotchCorners implements notched corners for buttons.
Definition buttonga.h:260
bool IsPressed() const
Returns true if the button is pushed or false if it is released.
Definition buttonga.h:341
TState GetButtonState() const
Returns the state of the button.
Definition buttonga.h:235
void SetBitmapOrigin(const TPoint &bitmapOrigin)
Sets the x and y coordinates of the bitmap used for this button gadget.
Definition buttonga.h:335
@ CelNormal
Displayed under normal circumstances.
Definition buttonga.h:153
@ CelPressed
Displayed when the button is pressed.
Definition buttonga.h:157
@ CelDown
Displayed when the button is down or checked.
Definition buttonga.h:156
@ CelIndeterm
Displayed when an ambiguous or indeterminate state is encountered.
Definition buttonga.h:155
@ CelDisabled
Displayed when the button is disabled (grayed).
Definition buttonga.h:154
bool GetNotchCorners() const
Returns true if the button has rounded corners.
Definition buttonga.h:250
TType GetButtonType() const
Return the type of the button.
Definition buttonga.h:242
void SetButtonType(TType newType)
Sets the type of the button.
Definition buttonga.h:299
void SetAntialiasEdges(bool anti=true)
Turns the antialiasing of the button bevels on or off.
Definition buttonga.h:292
TCelArray * GetCelArray()
Returns the CelArray used to cache glyph states.
Definition buttonga.h:311
TCelArray is a horizontal array of cels (a unit of animation) created by slicing a portion of or an e...
Definition celarray.h:35
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
Pseudo-GDI object Device Independent Bitmap (DIB) class.
Definition gdiobjec.h:795
TGadget is the base class for the following derived gadget classes:
Definition gadget.h:120
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
Base class TGadget and simple derived TSeparatorGadget.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
#define protected_data
Definition defs.h:209
#define _OWLCLASS
Definition defs.h:290