OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
gadgetwi.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 TGadgetList, TGadgetWindow & TGadgetWindowFont
7/// A list holding gadgets, & a window class owning & managing tiled gadgets.
8//----------------------------------------------------------------------------
9
10#if !defined(OWL_GADGETWI_H)
11#define OWL_GADGETWI_H
12
13#include <owl/private/defs.h>
14#if defined(BI_HAS_PRAGMA_ONCE)
15# pragma once
16#endif
17
18#include <owl/window.h>
19#include <owl/gadget.h>
20#include <owl/gdiobjec.h>
21
22namespace owl {
23
24class _OWLCLASS TCelArray;
25class _OWLCLASS TTooltip;
26
27#include <owl/preclass.h>
28
29/// \addtogroup gadgets
30/// @{
31/// \class TGadgetList
32// ~~~~~ ~~~~~~~~~~~
33/// TGadgetList is a list of gadgets with management functions.
34//
36 public:
38 virtual ~TGadgetList();
39
40 /// Enumerates the placement of a gadget. The new gadget is inserted either before
41 /// or after another gadget.
42 /// You can control the placement of the new gadget by specifying a sibling gadget
43 /// that the new gadget is inserted before or after. If the sibling argument in
44 /// TGadgetWindow::Insert is 0 then the new gadget is inserted at the beginning or
45 /// the end of the existing gadgets. By default, the new gadget is inserted at the
46 /// end of the existing gadgets.
47 enum TPlacement {Before, After};
48
49 /// \name
50 /// @{
51 // Insert a Gadget or a list of gadgets. Gadgets are removed from
52 // the source list
53 //
54 virtual void Insert(TGadget& gadget, TPlacement = After,
55 TGadget* sibling = nullptr);
56 virtual void InsertFrom(TGadgetList& list, TPlacement = After,
57 TGadget* sibling = nullptr);
58 /// @}
59
60 /// Removes (unlinks) a gadget.
61 //
62 virtual TGadget* Remove(TGadget& gadget);
63
64 // Callbacks invoked when a gadget is removed or inserted
65 //
66 virtual void Inserted(TGadget& gadget);
67 virtual void Removed(TGadget& gadget);
68
69 // Insert/remove methods that take a source/dest TGadgetList&
70
71 // Locate and iterate over gadgets
72 //
73 uint GadgetCount() const;
74 TGadget* FirstGadget() const;
75 TGadget* NextGadget(TGadget& gadget) const;
76 TGadget* GadgetFromPoint(const TPoint& point) const;
77 TGadget* GadgetWithId(int id) const;
78 TGadget* operator [](uint index);
79
81 TGadget* Gadgets; ///< Linked list of gadgets
82 uint NumGadgets; ///< Total number of gadgets
83};
84
85//
86/// \class TGadgetWindowFont
87// ~~~~~ ~~~~~~~~~~~~~~~~~
88/// Derived from TFont, TGadgetWindowFont is the default font used by TGadgetWindow.
89/// The font is based on TDefaultGuiFont, but you can specify the point size, boldness and italics
90/// style in the constructor.
91//
93 public:
95 explicit TGadgetWindowFont(int pointSize, bool bold = false, bool italic = false);
96};
97
98//
99/// \class TGadgetWindow
100// ~~~~~ ~~~~~~~~~~~~~
101/// Derived from TWindow, TGadgetWindow maintains a list of tiled gadgets for a
102/// window and lets you dynamically arrange tool bars. You can specify the following
103/// attributes of these gadgets:
104/// - \c \b Horizontal or vertical tiling. Positions the gadgets horizontally
105/// or vertically within the inner rectangle (the area excluding borders and
106/// margins).
107/// - \c \b Gadget font. Default font to use for gadgets and for calculating
108/// layout units. For font information, see the description of TGadgetWindowFont.
109/// - \c \b Left, right, top, and bottom margins. Specified in pixels, layout
110/// units (based on the window font), or border units (the width or height of a thin
111/// window border).
112/// - \c \b Measurement units. Specified in pixels, layout units, or border
113/// units.
114/// - \c \b Gadget window size. A gadget window can shrink-wrap its width,
115/// height, or both to fit around its gadgets. By default, horizontally tiled
116/// gadgets shrink-wrap to fit the height of the window and vertically tiled gadgets
117/// shrink-wrap to fit the width of the window.
118///
119/// TGadgetWindow is the base class for the following derived classes: TControlBar,
120/// TMessageBar, TToolBox, and TStatusBar.
121//
122class _OWLCLASS TGadgetWindow : virtual public TWindow, public TGadgetList {
123 public:
124
125 /// Enumeration describing how gadgets should be laid out within the
126 /// gadget window.
127 /// TGadgetWindow::TileGadgets actually tiles the gadgets in the direction
128 /// requested.
129 //
131 Horizontal, ///< Arrange gadgets in a row
132 Vertical, ///< Arrange gadgets in a column
133 Rectangular ///< Arrange gadgets in rows and columns (2-D grid)
134 };
135
136 TGadgetWindow(TWindow* parent = nullptr,
137 TTileDirection direction = Horizontal,
138 TFont* font = nullptr,
139 TModule* module = nullptr);
140 ~TGadgetWindow() override;
141
142 // Override TWindow member function and choose initial size if shrink
143 // wrapping was requested
144 //
145 auto Create() -> bool override;
146
147 // Changes the margins and initiates a layout session
148 //
149 void SetMargins(const TMargins& margins);
150
151 TMargins& GetMargins();
152 const TMargins& GetMargins() const;
153
154 // Get or set the direction. Setting the direction swaps dimentional
155 // members & initiates a layout session
156 //
157 TTileDirection GetDirection() const;
158 virtual void SetDirection(TTileDirection direction);
159
160 void SetRectangularDimensions(int width, int height, int rowMargin= -1);
161
162 const TFont& GetFont() const;
163 uint GetFontHeight() const;
164
165 // Retrieves/assigns tooltip of/to window
166 //
167 auto GetTooltip() const -> TTooltip* override;
168 void EnableTooltip(bool enable=true) override;
169 void SetTooltip(TTooltip* tooltip);
170
171 bool GetWantTooltip() const;
172 void SetWantTooltip(bool wantTooltip);
173
174 // Getting & releasing of the mouse by gadgets.
175 //
176 bool GadgetSetCapture(TGadget& gadget);
177 void GadgetReleaseCapture(TGadget& gadget);
178 TGadget* GadgetGetCaptured();
179
180 /// Hint mode settings & action used by contained gadgets
181 //
183 NoHints, ///< No hints.
184 PressHints, ///< Hints when a button is pressed.
185 EnterHints ///< Hints when the mouse passes over a gadget.
186 };
187 void SetHintMode(THintMode hintMode);
188 THintMode GetHintMode();
189 void SetHintCommand(int id); ///< (id <= 0) to clear
190
191/// Enumerates the flat styles settings of the gadget.
193 NonFlatNormal = 0x0000L, ///< No Flat style - default.
194 FlatStandard = 0x0001L, ///< Flat style IE 3.0 - base style.
195 FlatGrayButtons = 0x0002L, ///< Adds Gray buttons effect to FlatStandard.
196 FlatHotText = 0x0004L, ///< Adds hot text effect like
197 FlatSingleDiv = 0x0008L, ///< Adds single divider ala IE 4.01
198 FlatXPTheme = 0x0010L, ///< Windows XP theme styles
199 FlatDefault = 0xFFFFL, ///< System automatically select apropriated style.
200 };
201
202 static void EnableFlatStyle(uint style = FlatDefault);
203 /*virtual*/ static uint GetFlatStyle();
204
205 // Windows XP theme styles
206 //
207 bool IsThemed() const;
208 void EnableThemeBackground(bool enable = true);
209 bool IsThemeBackgroundEnabled() const;
210 bool IsBackgroundThemed() const;
211
212 // TGadgetList list management overrides
213 // Insert & remove a Gadget, update their Window ptr to this window
214 //
215 void Insert(TGadget&, TPlacement = After, TGadget* sibling = nullptr) override;
216 void InsertFrom(TGadgetList&, TPlacement = After, TGadget* sibling = nullptr) override;
217 auto Remove(TGadget&) -> TGadget* override;
218
219 // Override callbacks invoked when a gadget is removed or inserted
220 // Locate and iterate over gadgets
221 //
222 void Inserted(TGadget&) override;
223 void Removed(TGadget&) override;
224
225 // Shared CelArray management
226 //
227 virtual void SetCelArray(TCelArray* sharedCels);
228 virtual TCelArray& GetCelArray(int minX = 0, int minY = 0);
229
230 // During idle time, iterates over the Gadgets invoking their
231 // CommandEnable() member function
232 //
233 auto IdleAction(long idleCount) -> bool override;
234
235 // Set timer - useful for gadgets that need regular update [Time/Date]
236 //
237 bool EnableTimer();
238
239 // Sent by a Gadget when its size has changed. Initiates a layout session
240 //
241 void GadgetChangedSize(TGadget& gadget);
242
243 // Begins a layout session which tiles the Gadgets & repaints
244 //
245 virtual void LayoutSession();
246
247 // Simply sets the corresponding member data
248 //
249 void SetShrinkWrap(bool shrinkWrapWidth, bool shrinkWrapHeight);
250
251 // Get the desired size for this gadget window.
252 //
253 virtual void GetDesiredSize(TSize& size);
254
255 protected:
256 // Called by Paint(). Iterates over the Gadgets and asks each one to draw
257 //
258 virtual void PaintGadgets(TDC& dc, bool erase, TRect& rect);
259
260 // Computes the area inside of the borders and margins
261 //
262 virtual void GetInnerRect(TRect& rect);
263
264 int LayoutUnitsToPixels(int units);
265
266 void GetMargins(const TMargins& margins,
267 int& left, int& right, int& top, int& bottom);
268 void UseDesiredSize();
269
270 /// Gadget layout information used during the layout process
271 //
273 public:
275 : DesiredSize(0,0), GadgetBounds(new TRect[gadgetCount]) {}
278 };
279
280 // Calculates the layout of the Gadgets in the specified direction
281 // Returns the TLayoutInfo to describe the result but does not move the
282 // gadgets.
283 //
284 virtual void LayoutGadgets(TTileDirection dir, TLayoutInfo& layout);
285
286 /// Tiles the Gadgets in the current direction
287 //
288 virtual TRect TileGadgets();
289
290 // Selects the font into the DC and calls PaintGadgets()
291 //
292 void Paint(TDC&, bool erase, TRect&) override;
293
294 virtual void PositionGadget(TGadget* previous, TGadget* next,
295 TPoint& point);
296
297 // Overrides of TWindow virtuals
298 //
299 void SetupWindow() override;
300 void CleanupWindow() override;
301 bool PreProcessMsg(MSG& msg) override;
302
303 // Message response functions
304 //
305 void EvLButtonDown(uint modKeys, const TPoint& point);
306 void EvLButtonUp(uint modKeys, const TPoint& point);
307 void EvLButtonDblClk(uint modKeys, const TPoint& point);
308 void EvRButtonDown(uint modKeys, const TPoint& point);
309 void EvRButtonUp(uint modKeys, const TPoint& point);
310 void EvMouseMove(uint modKeys, const TPoint& point);
311 bool EvWindowPosChanging(WINDOWPOS & windowPos);
312 void EvSysColorChange();
313 bool EvEraseBkgnd(HDC);
314 void EvCreateTooltips();
315
316 // The overridden event handler functions are virtual, and not dispatched
317 // thru response tables
318 //
319 auto EvCommand(uint id, HWND hWndCtl, uint notifyCode) -> TResult override;
320 void EvCommandEnable(TCommandEnabler&) override;
321
322 // Protected data members
323 //
325 TFont* Font; ///< Font used for size calculations
326// TBrush* BkgndBrush; // OBSOLETE: background brush
327 TGadget* Capture; ///< Gadget that has captured the mouse
328 TGadget* AtMouse; ///< Last Gadget at mouse position
329 TMargins Margins;
330 uint FontHeight : 8;
331 bool ShrinkWrapWidth : 8;
332 bool ShrinkWrapHeight : 8;
333 uint WideAsPossible : 8; ///< # of "WideAsPossible" gadgets
334 bool DirtyLayout : 8;
335 TTileDirection Direction : 8;
336 THintMode HintMode : 8;
337 TCelArray* SharedCels; ///< CelArray that can be shared by gadgets
338 TTooltip* Tooltip; ///< Tooltip
339 bool WantTooltip; ///< Flags whether to create a tooltip
340 int RowWidth; ///< Requested max width of each row
341 int RowMargin; ///< Settable inter-row margin
342 bool WantTimer; ///< Flags whether to start a timer
343 UINT_PTR TimerID; ///< Timer identifier
344 static uint FlatStyle; ///< FlatStyle
345 bool ThemeBackgroundMode; ///< Indicate enablement of themed backgrounds
346
347 private:
348 // Calculate layouts metrics for window and all gadgets for a given
349 // direction
350 //
351 void LayoutHorizontally(TLayoutInfo&);
352 void LayoutVertically(TLayoutInfo&);
353 void LayoutRectangularly(TLayoutInfo&);
354 void FinishRow(int, TGadget*, TGadget*, int, TLayoutInfo&, int&);
355
356 // Hidden to prevent accidental copying or assignment
357 //
360
361 friend class TGadget;
362
365};
366
367#define EV_WM_CREATETOOLTIP OWL_EV_(WM_OWLCREATETTIP, EvCreateTooltips)
368
369//
370/// \class TGadgetControl
371// ~~~~~ ~~~~~~~~~~~~~~
372/// TGadgetControl is a specialized, easily constructed gadget window that holds one
373/// gadget for use as a control in a window.
374//
376 public:
377 TGadgetControl(TWindow* parent = nullptr,
378 TGadget* soleGadget = nullptr,
379 TFont* font = nullptr,
380 TModule* module = nullptr);
381};
382
383/// @}
384
385#include <owl/posclass.h>
386
387//----------------------------------------------------------------------------
388// Inline implementations
389
390//
391/// Returns the number of gadgets in the list.
392//
394 return NumGadgets;
395}
396
397//
398/// Returns the first gadget of the list.
399//
401 return Gadgets;
402}
403
404//
405/// Returns the next gadget in the list relative to a given gadget
406//
408 return gadget.NextGadget();
409}
410
411//----------------------------------------------------------------------------
412
413//
414/// Returns the direction of tiling for this gadget window.
415//
417 return Direction;
418}
419
420//
421/// Returns the font being used by this gadget window.
422//
423inline const TFont& TGadgetWindow::GetFont() const {
424 return *Font;
425}
426
427//
428/// Returns Tooltip
429//
431 return Tooltip;
432}
433
434//
435/// Returns the height of the font being used by this gadget window.
436//
438 return FontHeight;
439}
440
441//
442/// Sets the mode of the hint text. Defaults to PressHints (displays hint text when
443/// a button is pressed).
444//
446 HintMode = hintMode;
447}
448
449//
450/// Returns the current hint mode of this gadget window.
451//
453 return HintMode;
454}
455
456//
457/// Returns the flat style
458//
460 return FlatStyle;
461}
462
463//
464/// Retrieve the sizes of the 4 margins in pixels for this gadget window given a
465/// margin object
466//
468 int& left, int& right, int& top, int& bottom)
469{
470 margins.GetPixels(left, right, top, bottom, FontHeight);
471}
472
473//
474/// Retrieves gadget with capture
475//
477{
478 return Capture;
479}
480
482{
483 return Margins;
484}
485
487{
488 return Margins;
489}
490
492{
493 return WantTooltip;
494}
495
497{
498 WantTooltip = wantTooltip;
499}
500
501
502} // OWL namespace
503
504
505#endif // OWL_GADGETWI_H
TCelArray is a horizontal array of cels (a unit of animation) created by slicing a portion of or an e...
Definition celarray.h:35
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209
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
TGadgetControl is a specialized, easily constructed gadget window that holds one gadget for use as a ...
Definition gadgetwi.h:375
TGadget is the base class for the following derived gadget classes:
Definition gadget.h:120
TGadgetList is a list of gadgets with management functions.
Definition gadgetwi.h:35
uint GadgetCount() const
Returns the number of gadgets in the list.
Definition gadgetwi.h:393
TGadget * NextGadget(TGadget &gadget) const
Returns the next gadget in the list relative to a given gadget.
Definition gadgetwi.h:407
TPlacement
Enumerates the placement of a gadget.
Definition gadgetwi.h:47
TGadget * FirstGadget() const
Returns the first gadget of the list.
Definition gadgetwi.h:400
Gadget layout information used during the layout process.
Definition gadgetwi.h:272
TAPointer< TRect > GadgetBounds
Definition gadgetwi.h:277
TLayoutInfo(int gadgetCount)
Definition gadgetwi.h:274
Derived from TFont, TGadgetWindowFont is the default font used by TGadgetWindow.
Definition gadgetwi.h:92
Derived from TWindow, TGadgetWindow maintains a list of tiled gadgets for a window and lets you dynam...
Definition gadgetwi.h:122
uint GetFontHeight() const
Returns the height of the font being used by this gadget window.
Definition gadgetwi.h:437
TGadget * GadgetGetCaptured()
Retrieves gadget with capture.
Definition gadgetwi.h:476
static uint GetFlatStyle()
Returns the flat style.
Definition gadgetwi.h:459
THintMode GetHintMode()
Returns the current hint mode of this gadget window.
Definition gadgetwi.h:452
TFlatStyle
Enumerates the flat styles settings of the gadget.
Definition gadgetwi.h:192
TMargins & GetMargins()
Definition gadgetwi.h:481
void SetHintMode(THintMode hintMode)
Sets the mode of the hint text.
Definition gadgetwi.h:445
const TFont & GetFont() const
Returns the font being used by this gadget window.
Definition gadgetwi.h:423
auto GetTooltip() const -> TTooltip *override
Returns Tooltip.
Definition gadgetwi.h:430
bool GetWantTooltip() const
Definition gadgetwi.h:491
void SetWantTooltip(bool wantTooltip)
Definition gadgetwi.h:496
TTileDirection
Enumeration describing how gadgets should be laid out within the gadget window.
Definition gadgetwi.h:130
@ Vertical
Arrange gadgets in a column.
Definition gadgetwi.h:132
@ Horizontal
Arrange gadgets in a row.
Definition gadgetwi.h:131
TTileDirection GetDirection() const
Returns the direction of tiling for this gadget window.
Definition gadgetwi.h:416
THintMode
Hint mode settings & action used by contained gadgets.
Definition gadgetwi.h:182
@ NoHints
No hints.
Definition gadgetwi.h:183
@ PressHints
Hints when a button is pressed.
Definition gadgetwi.h:184
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
The tagSIZE struct is defined as.
Definition geometry.h:234
TTooltip encapsulates a tooltip window - i.e.
Definition tooltip.h:175
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
Base class TGadget and simple derived TSeparatorGadget.
Definition of abstract GDI object class and derived classes.
#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 _OWLCLASS
Definition defs.h:338
Used by the TGadgetWindow and TGadget classes, TMargins contains the measurements of the margins for ...
Definition gadget.h:54
Base window class TWindow definition, including HWND encapsulation.