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
glyphbtn.h
Go to the documentation of this file.
1//-------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Definition of class TGlyphButton
7//-------------------------------------------------------------------------
8
9#if !defined(OWL_GLYPHBTN_H)
10#define OWL_GLYPHBTN_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17// Macro defining class name (usable in resource definition)
18//
19#if !defined(OWL_GLYPHBTN)
20#if defined(UNICODE)
21# define OWL_GLYPHBTN L"OWL_GlyphBtn"
22#else
23# define OWL_GLYPHBTN "OWL_GlyphBtn"
24#endif
25#endif
26
27#if !defined(RC_INVOKED)
28
29#include <owl/button.h>
30#include <owl/uihelper.h>
31#include <owl/bitset.h>
32#include <owl/color.h>
33
34
35namespace owl {
36
37#include <owl/preclass.h>
38
39class _OWLCLASS TFont;
40class _OWLCLASS TCelArray;
41
42/// \addtogroup ctrl
43/// @{
44/// \class TBtnBitmap
45// ~~~~~ ~~~~~~~~~~
46/// TBtnBitmap is an enhanced version of TBitmap with the ability to update the face
47/// color of a bitmap to match the system setting (COLOR_BTNFACE).
48//
50 public:
52 const TColor& faceColor = TColor::LtGray);
54 const TColor& faceColor = TColor::LtGray,
56
57 void UpdateFaceColor();
58 static void MapColor(TDC& dc, TDC& srcDC, const TColor& toColor,
59 const TColor& fromColor, int width, int height);
60
61 protected:
62 TColor FaceColor; ///< Current face color of bitmap
63};
64
65//
66/// \class TGlyphButton
67// ~~~~~ ~~~~~~~~~~~~
68/// TGlyphButton encapsulates a control which is capable of displaying a bitmap (or
69/// glyph) and/or text.
70/// There is a number of predefined images, plus the ability to display a user-provided one. For examples see the picture below:
71/// \image html glyphbuttons.bmp
72//
74 public:
75 enum TBtnType {
76 btOk, ///< 'Ok' button
77 btCancel, ///< 'Cancel' button
78 btYes, ///< 'Yes' button
79 btNo, ///< 'No' button
80 btClose, ///< 'Close' button
81 btAbort, ///< 'Abort' button
82 btIgnore, ///< 'Ignore' button
83 btHelp, ///< 'Help' button
84 btApply, ///< 'Apply' button
85 btBrowse, ///< 'Browse' button
86 btRevert, ///< 'Revert' button
87 btAdd, ///< 'Add' button
88 btDelete, ///< 'Delete' button
89 btEdit, ///< 'Edit' button
90 btKey, ///< 'Key' button
91 btSetup, ///< 'Setup' button
92 btCustom, ///< Custom button
93 };
94 public:
95 TGlyphButton(TWindow* parent,
96 int id,
98 int X, int Y, int W, int H,
99 TBtnType type = btCustom,
100 bool isDefault = false,
101 TModule* module = 0);
102
104 TWindow* parent,
105 int id,
106 const tstring& text,
107 int X, int Y, int W, int H,
108 TBtnType type = btCustom,
109 bool isDefault = false,
110 TModule* module = 0);
111
112 TGlyphButton(TWindow* parent, int resourceId= 0, TBtnType type = btCustom, TModule* module = 0);
114
115 /// Enumeration describing the state when a particular bitmap should
116 /// be displayed. Used with the 'SetGlyph' method.
117 /// \note If only a single 'up' bitmap is specified, TGlyphBtn will
118 /// automatically generate the bitmaps for the other states.
119 //
121 gtUp = TUIFace::Normal, ///< Bitmap for when button is up
122 gtDisabled = TUIFace::Disabled, ///< Bitmap for when button is disabled
123 gtDown, ///< Bitmap for when button is depressed
125 };
126
127 /// \name Methods for specifying the glyphs that should be used
128 /// @{
129
130 void SetGlyph(TBitmap* bitmap, TGlyphType = gtUp, TAutoDelete autoDelete = AutoDelete);
131 void SetGlyph(const TIcon&, TGlyphType = gtUp);
132 void SetGlyph(TResId resId, TModule* module = 0, TGlyphType = gtUp);
133 void SetGlyph(HBITMAP hBitmap, TGlyphType = gtUp, TAutoDelete autoDelete = NoAutoDelete);
134
135 /// @}
136
137 /// Enumeration describing how to position the text and glyph
138 /// of the button.
139 //
141 lsNone, ///< Use specified coordinates
142
143 // Horizontal layouts [center vertically]
144 //
145 lsH_SGST, ///< Space Glyph Space Text (Horizontal)
146 lsH_GST, ///< Glyph Space Text (Horizontal)
147 lsH_STSG, ///< Space Text Space Glyph (Horizontal)
148 lsH_TSGS, ///< Text Space Glyph Space (Horizontal)
149
150 // Vertical layouts [center horizontally]
151 lsV_SGST, ///< Space Glyph Space Text (Vertical)
152 lsV_GST, ///< Glyph Space Text (Vertical)
153 lsV_STSG, ///< Space Text Space Glyph (Vertical)
154 lsV_TSGS, ///< Text Space Glyph Space (Vertical)
155 };
156
157 // Methods to specify how the glyph and/or text should be laid out
158 //
159 void SetLayoutStyle(TLayoutStyle style);
160 void SetTextOrigin(int x, int y);
161 void SetGlyphOrigin(int x, int y);
162
163 protected:
164 // Overriden TWindow virtuals
165 //
166 void SetupWindow() override;
167 void Paint(TDC&, bool erase, TRect&) override;
168 void GetWindowClass(WNDCLASS&) override;
169 auto GetWindowClassName() -> TWindowClassName override;
170
171 // Routine which determines location of text and glyph
172 //
173 virtual void LayoutTextGlyph(const TRect& faceRect, TRect& textRect,
175 // Initialization routine
176 //
177 void InitVars();
178
179 /// Init glip
180 //
181 void InitGlyp(TBtnType type);
182
183 /// Enumeration describing the current state of the button.
184 //
186 biPushed = 0x0001, ///< Button is currently depressed
187 biFocus = 0x0002, ///< Button has focus
188 biDefault = 0x0004, ///< Button is a 'DefaultPushButton'
189 biDisabled = 0x0008, ///< Button is disabled
190 biShowText = 0x0010, ///< Button should display its caption
191 biShowGlyph = 0x0020, ///< Button should draw its glyph
192 biFlatStyle = 0x0040, ///< Button draws border in flat style
193 biGtUp = 0x0080, ///< Was Set Up Glyph
194 biGtDown = 0x0100, ///< Was Set Down Glyph
195 biGtDisabled= 0x0200, ///< Was Set Disabled Glyph
196 biHot = 0x0400, // Mouse over the button
197 };
198
199 // Set, clear, query flags about the state of the control
200 //
201 int Clear(int t);
202 int Set(int t);
203 bool IsSet(int t) const;
204
205 // Event handlers
206 //
207 void EvPaint();
208 bool EvEraseBkgnd(HDC);
209 void EvSetFocus(THandle hWndLostFocus);
210 void EvKillFocus(THandle hWndGetFocus);
211 HFONT EvGetFont();
212 void EvSetFont(HFONT hFont, bool redraw);
213 uint EvGetDlgCode(const MSG* msg);
214 void EvLButtonDown(uint modKeys, const TPoint& point);
215 void EvLButtonDblClk(uint modKeys, const TPoint& point);
216 void EvLButtonUp(uint modKeys, const TPoint& point);
217 void EvMouseMove(uint modKeys, const TPoint& point);
218 void EvKeyDown(uint key, uint repeatCount, uint flags);
219 void EvKeyUp(uint key, uint repeatCount, uint flags);
220 void EvEnable(bool enabled);
221 void EvCancelMode();
222 void EvSysColorChange();
223 void EvMouseLeave();
224 TResult BmGetState(TParam1, TParam2);
225 TResult BmSetState(TParam1, TParam2);
226 TResult BmSetStyle(TParam1, TParam2);
227
228 // Helper functions
229 //
230 void PaintNow();
231 void PaintButton(TDC& dc);
232 virtual void PaintFrame(TDC& dc, TRect& rect);
233 virtual void PaintDefaultRect(TDC& dc, TRect& rect);
234 virtual void PaintFace(TDC& dc, const TRect& rect);
235 virtual void PaintFocusRect(TDC& dc, const TRect& faceRect);
236 void ClearCapture();
237 virtual void BuildCelArray(const TBitmap* cell);
238
239 private:
240 // Hidden to prevent accidental copying or assignment
241 //
244
245 TCelArray* CelArray; ///< CelArray used to cache glyph states
246 TFont* BtnFont; ///< Pointer to font used by button
247 int xGlyph; ///< x (left) coordinate of glyph
248 int yGlyph; ///< y (top ) coordinate of glyph
249 int xText; ///< x (left) coordinate of text
250 int yText; ///< y (top ) coordinate of text
251 TLayoutStyle LayStyle; ///< How text & glyph should be laid out
252 TBtnType BtnType; ///< Button type
253 TBitFlags<uint> Flags; ///< Status flags
254
256};
257/// @}
258#include <owl/posclass.h>
259
260
261//----------------------------------------------------------------------------
262// Inline implementations
263//
264
265//
266/// Clear flags about the state of the control
267//
268inline int
270{
271 return Flags.Clear(t);
272}
273
274//
275/// Set flags about the state of the control
276//
277inline int
279{
280 return Flags.Set(t);
281}
282
283//
284/// Query flags about the state of the control
285//
286inline bool
288{
289 return Flags.IsSet(t);
290}
291
292} // OWL namespace
293
294#endif // !RC_INVOKED
295
296
297#endif // OWL_GLYPHBTN_H
Definition of a bit set and a character set.
Definition of class TButton.
T Clear(T t)
Clear the bits that are enabled in the specified parameter.
Definition bitset.h:188
bool IsSet(T t) const
Return true of the ON bits of the parameter are currently enabled.
Definition bitset.h:198
T Set(T t)
Activate the bits that are enabled in the specified parameter.
Definition bitset.h:179
TBitmap is the GDI bitmap class derived from TGdiObject.
Definition gdiobjec.h:510
TBtnBitmap is an enhanced version of TBitmap with the ability to update the face color of a bitmap to...
Definition glyphbtn.h:49
TColor FaceColor
Current face color of bitmap.
Definition glyphbtn.h:62
TButton is an interface class derived from TControl that represents a pushbutton interface element.
Definition button.h:41
TCelArray is a horizontal array of cels (a unit of animation) created by slicing a portion of or an e...
Definition celarray.h:35
Class wrapper for management of color values.
Definition color.h:245
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
TFont derived from TGdiObject provides constructors for creating font objects from explicit informati...
Definition gdiobjec.h:296
TGlyphButton encapsulates a control which is capable of displaying a bitmap (or glyph) and/or text.
Definition glyphbtn.h:73
int Clear(int t)
Clear flags about the state of the control.
Definition glyphbtn.h:269
TButtonInfo
Enumeration describing the current state of the button.
Definition glyphbtn.h:185
TGlyphType
Enumeration describing the state when a particular bitmap should be displayed.
Definition glyphbtn.h:120
@ gtDown
Bitmap for when button is depressed.
Definition glyphbtn.h:123
TLayoutStyle
Enumeration describing how to position the text and glyph of the button.
Definition glyphbtn.h:140
@ lsH_TSGS
Text Space Glyph Space (Horizontal)
Definition glyphbtn.h:148
@ lsH_GST
Glyph Space Text (Horizontal)
Definition glyphbtn.h:146
@ lsV_STSG
Space Text Space Glyph (Vertical)
Definition glyphbtn.h:153
@ lsV_GST
Glyph Space Text (Vertical)
Definition glyphbtn.h:152
@ lsV_TSGS
Text Space Glyph Space (Vertical)
Definition glyphbtn.h:154
@ lsH_SGST
Space Glyph Space Text (Horizontal)
Definition glyphbtn.h:145
@ lsNone
Use specified coordinates.
Definition glyphbtn.h:141
@ lsV_SGST
Space Glyph Space Text (Vertical)
Definition glyphbtn.h:151
@ lsH_STSG
Space Text Space Glyph (Horizontal)
Definition glyphbtn.h:147
int Set(int t)
Set flags about the state of the control.
Definition glyphbtn.h:278
bool IsSet(int t) const
Query flags about the state of the control.
Definition glyphbtn.h:287
@ btAdd
'Add' button
Definition glyphbtn.h:87
@ btClose
'Close' button
Definition glyphbtn.h:80
@ btYes
'Yes' button
Definition glyphbtn.h:78
@ btApply
'Apply' button
Definition glyphbtn.h:84
@ btOk
'Ok' button
Definition glyphbtn.h:76
@ btHelp
'Help' button
Definition glyphbtn.h:83
@ btSetup
'Setup' button
Definition glyphbtn.h:91
@ btNo
'No' button
Definition glyphbtn.h:79
@ btDelete
'Delete' button
Definition glyphbtn.h:88
@ btCustom
Custom button.
Definition glyphbtn.h:92
@ btAbort
'Abort' button
Definition glyphbtn.h:81
@ btRevert
'Revert' button
Definition glyphbtn.h:86
@ btBrowse
'Browse' button
Definition glyphbtn.h:85
@ btCancel
'Cancel' button
Definition glyphbtn.h:77
@ btEdit
'Edit' button
Definition glyphbtn.h:89
@ btKey
'Key' button
Definition glyphbtn.h:90
@ btIgnore
'Ignore' button
Definition glyphbtn.h:82
TIcon, derived from TGdiObject, represents the GDI object icon class.
Definition gdiobjec.h:670
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
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
Definition of windowing system color classes.
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
@ NoAutoDelete
Definition gdibase.h:70
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
LRESULT TResult
Result type.
Definition dispatch.h:52
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
#define _OWLCLASS
Definition defs.h:338
Definition of the UI Helper Classes: TUIHandle, TUIBorder, TUIFace, TUIPart.