OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
gadget.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/// Base class TGadget and simple derived TSeparatorGadget.
7//----------------------------------------------------------------------------
8
9#if !defined(OWL_GADGET_H)
10#define OWL_GADGET_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17#include <owl/window.h>
18#include <owl/dc.h>
19
20namespace owl {
21
22class _OWLCLASS TGadgetWindow;
23
24//
25/// \name Ids of some OWL predefined gadgets
26/// @{
27#define IDG_FIRST 30000 ///< first predefined gadget ID
28#define IDG_LAST 31000 ///< last predefined gadget ID
29#define IDG_MESSAGE IDG_FIRST + 0 ///< + 0 is for backwards compatability
30#define IDG_STATUS_EXT IDG_FIRST + 1 ///< The ID for an extended selection gadget
31#define IDG_STATUS_CAPS IDG_FIRST + 2 ///< The ID for a capslock gadget
32#define IDG_STATUS_NUM IDG_FIRST + 3 ///< The ID for a numlock gadget
33#define IDG_STATUS_SCRL IDG_FIRST + 4 ///< The ID for a scroll lock gadget
34#define IDG_STATUS_OVR IDG_FIRST + 5 ///< The ID for an overwrite gadget
35#define IDG_STATUS_REC IDG_FIRST + 6 ///< The ID for a record gadget
36#define IDG_SIZEGRIP IDG_FIRST + 7 ///< The ID for a size grip gadget
37#define IDG_FLATHANDLE IDG_FIRST + 8 ///< The ID for a flat bar handle
38/// @}
39
40#include <owl/preclass.h>
41
42/// \addtogroup gadgets
43/// @{
44
45
46//
47/// \struct TMargins
48// ~~~~~~ ~~~~~~~~
49/// Used by the TGadgetWindow and TGadget classes, TMargins contains the
50/// measurements of the margins for the gadget. The constructor initializes Units to
51/// LayoutUnits and sets Left, Right, Top, and Bottom equal to 0.
52//
54{
55 enum TUnits {Pixels, LayoutUnits, BorderUnits};
56
58
59 int Left : 8;
60 int Right : 8;
61 int Top : 8;
62 int Bottom : 8;
63
64 TMargins() {Units = LayoutUnits; Left = Right = Top = Bottom = 0;}
65
66 TMargins(TUnits u, int l, int r, int t, int b)
67 {Units = u; Left = l; Right = r; Top = t; Bottom = b;}
68
69 void GetPixels(int& left, int& right, int& top, int& bottom, int fontHeight) const;
70};
71
72//
73/// \class TGadget
74// ~~~~~ ~~~~~~~
75/// TGadget is the base class for the following derived gadget classes:
76/// - \c \b TBitmapGadget Displays a bitmap
77/// - \c \b TButtonGadget Uses a bitmap to simulate a button gadget
78/// - \c \b TButtonTextGadget Derived from TButtonGadget and adds displays optionally text
79/// or bitmap or both.
80/// - \c \b TControlGadget Encapsulates inserting a control such as an edit control or a
81/// combobox, into a gadget window.
82/// - \c \b TFlatHandleGadget Uses by TControlBar/TDockableControlBar to simulate FlatGrip
83/// when FlatState enabled.
84/// - \c \b TMenuGadget Displays ppopup menu
85/// - \c \b TPopupButtonGadget Derived from TButtonTextGadget and adds button for popup
86/// actions
87/// - \c \b TPopupMenuGadget Derived from TPopupButtonGadget and show popup menu
88/// - \c \b TTextGadget Displays text
89/// - \c \b TSeparatorGadget Separates logical groups of gadgets.
90/// - \c \b TSizeGripGadget Used on the far right of a status bar to provide re-sizing
91/// grip for the host window.
92///
93/// TGadget interface objects belong to a gadget window, have borders and margins,
94/// and have their own coordinate system. The margins are the same as those for
95/// TGadgetWindow and borders are always measured in border units.
96///
97/// To set the attributes for the gadget, you can either choose a border style
98/// (which automatically sets the individual border edges) or set the borders and
99/// then override the member function PaintBorder to create a custom look for your
100/// gadget. If you change the borders, margins, or border style, the gadget window's
101/// GadgetChangedSize member function is invoked.
102///
103/// Although, by default, gadgets shrink-wrap to fit around their contents, you can
104/// control this attribute by setting your own values for ShrinkWrapWidth and
105/// ShrinkWrapHeight.
106///
107/// A gadget window, being an actual window, receives messages from the mouse. After
108/// the gadget window receives the message, it decides which gadget should receive
109/// the message by calling the member function directly instead of sending or
110/// posting a message.
111///
112/// Typically you would either choose a border style (which automatically
113/// sets the individual border edges) or set the borders and then override
114/// member function PaintBorder() to create a custom look
115///
116/// \note changing the borders, margins, or border style all end up invoking
117/// the gadget window's GadgetChangedSize() member function
118//
120{
121 public:
122 /// Gadget border styles. These match TIUBorder's TStyles exactly.
123 /// For an example of border styles,
124 /// see the sample ObjectWindows program, MDIFILE.CPP, on BC5.x distribution disk.
125 /// Border Style Constants
127 {
128 None, ///< No border painted at all
129 Plain, ///< Plain window frame
130 Raised, ///< Raised above the gadget window
131 Recessed, ///< Recessed into the window
132 Embossed, ///< Painted with an embossed border
133 Grooved, ///< Grouping groove
134 ButtonUp, ///< Button in up position
135 ButtonDn, ///< Button in down position
136 WndRaised, ///< Inner and outer edge of the window are raised
137 WndRecessed, ///< Input field and other window are recessed
138 WellSet, ///< Well option set (auto grows + 1)
139 };
140
141 TGadget(int id = 0, TBorderStyle borderStyle = None);
142 virtual ~TGadget();
143
144 /// Border dimensions
145 ///
146 /// Holds the values for the left, right, top, and bottom measurements of the
147 /// gadget.
149 {
154
155 TBorders() {Left = Right = Top = Bottom = 0;}
156 };
157
158 int GetId() const;
159
160 /// @{
161 void SetBorders(const TBorders& borders);
162 TBorders& GetBorders();
163
164 void SetMargins(const TMargins& margins);
165 TMargins& GetMargins();
166
167 void SetBorderStyle(TBorderStyle bs);
168 TBorderStyle GetBorderStyle() const;
169 /// @}
170
171 TRect& GetBounds();
172 const TRect& GetBounds() const;
173
174 virtual void SetEnabled(bool enabled);
175 bool GetEnabled() const;
176
177 virtual void SetVisible(bool visible);
178 bool IsVisible() const;
179
180 bool IsWindowVisible() const; ///< check to see if the button's created
181
182 void SetEndOfRow(bool eor);
183 bool IsEndOfRow() const;
184
185 bool IsWideAsPossible() const;
186 void SetWideAsPossible(bool wide = true);
187
188
189 // Simply sets the corresponding member data.
190 //
191 void SetShrinkWrap(bool shrinkWrapWidth, bool shrinkWrapHeight);
192
193 // Directly alters the size of the gadget.
194 //
195 void SetSize(const TSize& size);
196
197 // Get the size that this gadget would like to be
198 //
199 virtual void GetDesiredSize(TSize& size);
200
201 // Returns the amount of space in pixels taken up by the borders and
202 // margins
203 //
204 void GetOuterSizes(int& left, int& right, int& top, int& bottom);
205
206 // Returns the area excluding the borders and margins
207 //
208 void GetInnerRect(TRect& rect);
209
210 // Set the bounding rectangle for this gadget
211 //
212 virtual void SetBounds(const TRect& rect);
213
214 virtual bool IdleAction(long idleCount);
215 virtual void CommandEnable();
216 virtual void SysColorChange();
217
218 TGadget* NextGadget();
219
220 protected:
221
222 TGadgetWindow* GetGadgetWindow();
223 const TGadgetWindow* GetGadgetWindow() const;
224
225 // The following virtual methods are called to allow the gadget
226 // to initialize, cleanup or update any internal information
227 // when its inserted into a window, moved or removed.
228 //
229 virtual void Created();
230 virtual void Inserted();
231 virtual void Moved();
232 virtual void Removed();
233
234 bool IsHaveMouse() const;
235 void SetInMouse(bool state);
236
237 bool GetTrackMouse() const;
238 void SetTrackMouse(bool track);
239
240 void Invalidate(bool erase = true);
241 void InvalidateRect(const TRect& rect, // receiver's coord system
242 bool erase = true);
243 void Update(); ///< Paint now if possible
244
245 /// Default behavior returns true if the point is within the receiver's
246 /// bounding rect. "point" is in the receiver's coordinate system
247 //
248 virtual bool PtIn(const TPoint& point);
249
250 virtual void Paint(TDC& dc);
251
252 /// Self sent by method Paint(). Override this is if you want to
253 /// implement a border style that isn't supported
254 //
255 virtual void PaintBorder(TDC& dc);
256
257 // Mouse virtuals forwarded from TGadgetWindows message handlers.
258 // "point" is in the receiver's coordinate system.
259
260 // MouseMove is only called if the mouse is captured. Enter & leave when
261 // mouse enters & leaves a gadget & is not captured.
262 //
263 virtual void MouseEnter(uint modKeys, const TPoint& point);
264 virtual void MouseMove(uint modKeys, const TPoint& point);
265 virtual void MouseLeave(uint modKeys, const TPoint& point);
266
267 // Captures the mouse if "TrackMouse" is set.
268 //
269 virtual void LButtonDown(uint modKeys, const TPoint& point);
270 virtual void RButtonDown(uint modKeys, const TPoint& point);
271
272 // Releases the mouse capture if "TrackMouse" is set.
273 //
274 virtual void LButtonUp(uint modKeys, const TPoint& point);
275 virtual void RButtonUp(uint modKeys, const TPoint& point);
276
277 void ChangeBorderStyle(TBorderStyle bs);
278
279 // Data members -- will become private
280 //
282/// If Clip is false, clipping borders have not been established. If Clip is true,
283/// the drawing for each gadget is restrained by the gadget's border.
284 bool Clip;
285
286/// Initially set to false, WideAsPossible indicates whether the gadget width will
287/// be adjusted by the gadget window to be as wide as possible in the remaining
288/// space.
289 bool WideAsPossible;
290
292/// References the owning or parent window for the gadget.
293 TGadgetWindow* Window;
294
295/// Contains the bounding rectangle for the gadget in gadget window coordinates.
296 TRect Bounds;
297
298/// Contains the border style for the gadget.
299 TBorderStyle BorderStyle;
300
301/// Contains the border measurements of TGadget::GetInnerRect().
302 TBorders Borders;
303
304/// Contains the margin measurements of the rectangle or the gadget.
305 TMargins Margins;
306
307 bool ShrinkWrapWidth; ///< Shrink the width to fit contents?
308 bool ShrinkWrapHeight;///< Shrink the height to fit contents?
309
310/// Initialized to false. When TrackMouse is true, the gadget captures the mouse on
311/// LButtonDown by calling TGadgetWindow's GadgetSetCapture and releases the mouse
312/// on LButtonUp by calling GadgetReleaseCapture.
313 bool TrackMouse;
314
315/// True if mouse in gadget.
316 bool MouseInGadget;
317
318/// Contains the gadget's ID.
319 int Id;
320
321 private:
322 TGadget* Next;
323 enum
324 {
325 Enabled = 0x01,
326 Visible = 0x02,
327 EndOfRow = 0x04,
328 };
329 uint16 Flags; ///< Enabled, EndOfRow flags
330
331 // Hidden to prevent accidental copying or assignment
332 //
333 TGadget(const TGadget&);
334 TGadget& operator =(const TGadget&);
335
336 friend class _OWLCLASS TGadgetList; // Access to Next for containment
337 friend class _OWLCLASS TGadgetWindow; // Access to Next for containment
339};
340
341//
342/// \class TSeparatorGadget
343// ~~~~~ ~~~~~~~~~~~~~~~~
344/// TSeparatorGadget is a simple class you can use to create a separator between
345/// gadgets. To do so, you must specify the size of the separator in units of
346/// SM_CXBORDER (width of the window frame) and SM_CYBORDER (height of the window
347/// frame). Determines the width and height of the gadget and sets the right and
348/// bottom boundaries of the separator. By default, the separator disables itself
349/// and turns off shrink-wrapping. Note that the default border style is none.
350///
351/// "size" is used for both the width and the height
352//
354{
355 public: // only for Flat mode
356 TSeparatorGadget(int size = 0, int id = 0, bool showseparator=true);
357
358 void Inserted();
359 void Paint(TDC& dc);
360
361 void SetShowSep(bool show = true) {ShowSeparator = show; }
362 bool GetShowSep() {return ShowSeparator; }
363
364 protected:
366};
367
368//
369/// \class TFlatHandleGadget
370// ~~~~~ ~~~~~~~~~~~~~~~
371/// A gadget that is used on the far right of a status bar to provide re-sizing
372/// grip for the host window.
373//
375{
376 public:
378 virtual void Paint(TDC& dc);
379 virtual void GetDesiredSize(TSize& size);
380};
381
382//
383/// \class TSizeGripGadget
384// ~~~~~ ~~~~~~~~~~~~~~~
385/// TSizeGripGadget is a gadget that is used on the far right of a status bar to
386/// provide re-sizing grip for the host window.
387//
389{
390 public:
392 void Paint(TDC& dc);
393};
394
395/// @}
396
397#include <owl/posclass.h>
398
399//----------------------------------------------------------------------------
400// Inline implementations
401//
402
403//
404/// Gets the ID for the gadget.
405//
406inline int TGadget::GetId () const
407{
408 return Id;
409}
410
411//
412/// Gets the gadget's borders measured in border units that are based on SM_CXBORDER
413/// and SM_CYBORDER.
414//
416{
417 return Borders;
418}
419
420
421//
422/// Gets the margin dimensions.
423//
425{
426 return Margins;
427}
428
429//
430/// Gets the style for the gadget's borders.
431//
433{
434 return BorderStyle;
435}
436
437//
438/// Returns the boundary rectangle for the gadget.
439//
441{
442 return Bounds;
443}
444
445//
446/// Returns the boundary rectangle for the gadget.
447//
448inline const TRect& TGadget::GetBounds() const
449{
450 return Bounds;
451}
452
453//
454/// Determines whether keyboard and mouse input have been enabled for the specified
455/// gadget. If the gadget is enabled, GetEnabled returns true; otherwise, it returns
456/// false. By default, keyboard and mouse input are enabled.
457//
458inline bool TGadget::GetEnabled() const
459{
460 return Flags & Enabled;
461}
462
463//
464/// Changes the visibility of the gadget.
465//
467{
468 if (visible)
469 Flags |= Visible;
470 else
471 Flags &= ~Visible;
472}
473
474//
475/// Returns true if the gadget is visible.
476//
477inline bool TGadget::IsVisible() const
478{
479 return Flags & Visible;
480}
481
482//
483/// Return true if mouse inside gadget.
484//
485inline bool TGadget::IsHaveMouse() const
486{
487 return MouseInGadget;
488}
489
490/// Sets if mouse inside gadget or not.
491inline void TGadget::SetInMouse(bool state)
492{
493 MouseInGadget = state;
494}
495
496inline bool TGadget::GetTrackMouse() const
497{
498 return TrackMouse;
499}
500
502{
503 TrackMouse = track;
504}
505
506
507//
508/// Sets the end of row property for the gadget. The end of row property is used to
509/// tile gadgets.
510//
511inline void TGadget::SetEndOfRow(bool eor)
512{
513 if (eor)
514 Flags |= EndOfRow;
515 else
516 Flags &= ~EndOfRow;
517}
518
519//
520/// Returns true if this gadget is at the end of a row.
521//
522inline bool TGadget::IsEndOfRow() const
523{
524 return Flags & EndOfRow;
525}
526
527//
528/// Returns the next gadget in the list of gadgets.
529//
531{
532 return Next;
533}
534
535/// Return a pointer to the owning or parent window for the gadget.
537{
538 return Window;
539}
540
541/// Return a pointer to the owning or parent window for the gadget.
543{
544 return Window;
545}
546
547/// Indicates whether the gadget width will be adjusted by the gadget window
548/// to be as wide as possible in the remaining space.
549inline bool TGadget::IsWideAsPossible() const
550{
551 return WideAsPossible;
552}
553
554/// Sets the flag that indicates whether the gadget width will be adjusted by the gadget window
555/// to be as wide as possible in the remaining space.
557{
558 WideAsPossible = wide;
559}
560
561/// Simply changes the border style without recalculating the gadget size
563{
564 BorderStyle = bs;
565}
566
567
568
569} // OWL namespace
570
571
572#endif // OWL_GADGET_H
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
A gadget that is used on the far right of a status bar to provide re-sizing grip for the host window.
Definition gadget.h:375
TGadget is the base class for the following derived gadget classes:
Definition gadget.h:120
bool IsHaveMouse() const
Return true if mouse inside gadget.
Definition gadget.h:485
TRect & GetBounds()
Returns the boundary rectangle for the gadget.
Definition gadget.h:440
bool IsWideAsPossible() const
Indicates whether the gadget width will be adjusted by the gadget window to be as wide as possible in...
Definition gadget.h:549
void SetWideAsPossible(bool wide=true)
Sets the flag that indicates whether the gadget width will be adjusted by the gadget window to be as ...
Definition gadget.h:556
void SetEndOfRow(bool eor)
Sets the end of row property for the gadget.
Definition gadget.h:511
TBorders & GetBorders()
Gets the gadget's borders measured in border units that are based on SM_CXBORDER and SM_CYBORDER.
Definition gadget.h:415
bool GetTrackMouse() const
Definition gadget.h:496
void SetInMouse(bool state)
Sets if mouse inside gadget or not.
Definition gadget.h:491
bool IsVisible() const
Returns true if the gadget is visible.
Definition gadget.h:477
void ChangeBorderStyle(TBorderStyle bs)
Simply changes the border style without recalculating the gadget size.
Definition gadget.h:562
TGadgetWindow * GetGadgetWindow()
Return a pointer to the owning or parent window for the gadget.
Definition gadget.h:536
bool GetEnabled() const
Determines whether keyboard and mouse input have been enabled for the specified gadget.
Definition gadget.h:458
bool IsEndOfRow() const
Returns true if this gadget is at the end of a row.
Definition gadget.h:522
TBorderStyle GetBorderStyle() const
Gets the style for the gadget's borders.
Definition gadget.h:432
void SetTrackMouse(bool track)
Definition gadget.h:501
TBorderStyle
Gadget border styles.
Definition gadget.h:127
@ Embossed
Painted with an embossed border.
Definition gadget.h:132
@ WndRecessed
Input field and other window are recessed.
Definition gadget.h:137
@ Recessed
Recessed into the window.
Definition gadget.h:131
@ None
No border painted at all.
Definition gadget.h:128
@ WndRaised
Inner and outer edge of the window are raised.
Definition gadget.h:136
@ ButtonUp
Button in up position.
Definition gadget.h:134
@ Plain
Plain window frame.
Definition gadget.h:129
@ Grooved
Grouping groove.
Definition gadget.h:133
@ Raised
Raised above the gadget window.
Definition gadget.h:130
@ WellSet
Well option set (auto grows + 1)
Definition gadget.h:138
@ ButtonDn
Button in down position.
Definition gadget.h:135
virtual void SetVisible(bool visible)
Changes the visibility of the gadget.
Definition gadget.h:466
TGadget * NextGadget()
Returns the next gadget in the list of gadgets.
Definition gadget.h:530
TMargins & GetMargins()
Gets the margin dimensions.
Definition gadget.h:424
int GetId() const
Gets the ID for the gadget.
Definition gadget.h:406
TGadgetList is a list of gadgets with management functions.
Definition gadgetwi.h:35
Derived from TWindow, TGadgetWindow maintains a list of tiled gadgets for a window and lets you dynam...
Definition gadgetwi.h:122
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
TSeparatorGadget is a simple class you can use to create a separator between gadgets.
Definition gadget.h:354
void SetShowSep(bool show=true)
Definition gadget.h:361
TSizeGripGadget is a gadget that is used on the far right of a status bar to provide re-sizing grip f...
Definition gadget.h:389
The tagSIZE struct is defined as.
Definition geometry.h:234
Definition of GDI DC encapsulation classes: TDC, TWindowDC, TScreenDC, TDesktopDC,...
#define IDG_SIZEGRIP
The ID for a size grip gadget.
Definition gadget.h:36
#define IDG_FLATHANDLE
The ID for a flat bar handle.
Definition gadget.h:37
#define DECLARE_CASTABLE
Definition objstrm.h:1440
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned int uint
Definition number.h:25
#define protected_data
Definition defs.h:208
#define public_data
Definition defs.h:207
#define _OWLCLASS
Definition defs.h:338
Border dimensions.
Definition gadget.h:149
Used by the TGadgetWindow and TGadget classes, TMargins contains the measurements of the margins for ...
Definition gadget.h:54
TUnits Units
Definition gadget.h:57
TMargins(TUnits u, int l, int r, int t, int b)
Definition gadget.h:66
Base window class TWindow definition, including HWND encapsulation.