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
statusba.cpp
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/// Implementation of TStatusBar
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/defs.h>
10#include <owl/statusba.h>
11#include <owl/modegad.h>
12#include <owl/uimetric.h>
13#include <owl/statusba.rh>
14#include <owl/layoutwi.h>
15
16namespace owl {
17
19
20//
21// Local class to manage the mode indicator strings
22//
23class TModeStrings {
24 public:
25 // Constructor
26 //
27 TModeStrings() : NumModes(0), ModeBuff(nullptr), ModeStrings(nullptr) {}
28 ~TModeStrings()
29 {
30 delete[] ModeBuff;
31 delete[] ModeStrings;
32 }
33
34 void Init(TModule* module, uint16 resId, LPCTSTR defaultModes);
35
36 // Accessors
37 int Count() const { return NumModes; }
38 LPCTSTR operator [](int i) const { return ModeStrings[i]; }
39
40 private:
41 int NumModes;
42 tchar* ModeBuff;
43 tchar** ModeStrings;
44};
45
46//
47// Gets the mode string array from a single resource string, like:
48// "EXT|CAPS|NUM|SCRL|OVR|REC"
49// using the provided default string if resource not found.
50//
51void
52TModeStrings::Init(TModule* module, uint16 resId, LPCTSTR defaultModes)
53{
54 if (!ModeStrings) {
55 tstring modeResString(module->LoadString(resId));
56 ModeBuff = strnewdup(modeResString.length() > 0 ?
57 modeResString.c_str() :
59 NumModes = 1;
60 for (TCharIterator<tchar> i(ModeBuff); ; i++) {
61 if (!*i.Current())
62 break;
63 if (*i.Current() == _T('|')) {
64 *i.Current() = 0;
65 NumModes++;
66 }
67 }
68
69 typedef tchar* pchar;
70 ModeStrings = new pchar[NumModes];
71 tchar* p = ModeBuff;
72 for (int j = 0; j < NumModes; j++) {
73 ModeStrings[j] = p;
74 p += ::_tcslen(p) + 1;
75 }
76 }
77}
78
79//
80// Static mode string object, & default mode indicator strings
81//
82static tchar DefOnModes[] = _T("EXT|CAPS|NUM|SCRL|OVR|REC");
83static TModeStrings&
84GetModeOnStrings()
85{
86 static TModeStrings ModeOnStrings;
87 return ModeOnStrings;
88}
89
90static int VkKeys[] = {
91 0,
96 0
97};
98
99static int GadgetIds[] = {
106};
107
108//----------------------------------------------------------------------------
109
110DEFINE_RESPONSE_TABLE1(TStatusBar, TMessageBar)
114
115//
116/// Constructs a TStatusBar object in the parent window and creates any new gadgets
117/// and mode indicator gadgets. Sets BorderStyle to borderStyle, ModeIndicators to
118/// modeIndicators, and NumModeIndicators to 0. borderStyle can be any one of the
119/// values of the BorderStyle enum (for example, Plain, Raised, Recessed, or
120/// Embossed). The parameter mode indicators can be one of the values of the
121/// TModeIndicator enum, such as CapsLock, NumLock, ScrollLock, or Overtype. The
122/// parameter font points to a font object that contains the type of fonts used for
123/// the gadget window. The parameter, module, which defaults to 0, is passed to the
124/// base TWindow's constructor in the module parameter. Sets the values of the
125/// margins and borders depending on whether the gadget is raised, recessed, or
126/// plain.
127//
131 TFont* font,
132 TModule* module)
133:
134 TMessageBar(parent, font, module)
135{
136 BorderStyle = borderStyle;
137 ModeIndicators = modeIndicators;
138 ModeIndicatorState = 0;
139 NumModeIndicators = 0;
140 WideHintText = true;
141 GetModeOnStrings().Init(GetModule(), IDS_MODES, DefOnModes);
142
143 // Statusbars should always stay flush to the decorated frame's border
144 //
146
147 if (BorderStyle == TGadget::Plain || BorderStyle == TGadget::Embossed)
148 HighlightLine = false;
149 else
150 Spacing.Value = 2; // Hilight line + 1/4-em margin on raised & recessed
151
152 switch (BorderStyle) {
153 case TGadget::None:
155 case TGadget::Grooved:
160 case TGadget::WellSet:
161 break;
162
163 case TGadget::Raised:
165 // We want one border height along the top and bottom and 1/2 an em quad
166 // along the left and right so we will set pixels and compute the lengths
167 // ourselves
168 //
169 Margins.Units = TMargins::Pixels;
170 Margins.Left = LayoutUnitsToPixels(4);
171 Margins.Right = LayoutUnitsToPixels(4);
172
173
174 // The UI for a sizegrip isn't available in 16-bit Windows
175 //
176 if (ModeIndicators & SizeGrip)
177 Margins.Right = LayoutUnitsToPixels(1);
178 Margins.Top = Margins.Bottom = TUIMetric::CyBorder;
179 break;
180
181 case TGadget::Plain:
182 Margins.Units = TMargins::BorderUnits;
183 Margins.Left = Margins.Top = Margins.Right = Margins.Bottom = -1;
184 break;
185 default: //JJH added empty default construct
186 break;
187 }
188
189 Gadgets->SetBorderStyle(BorderStyle); // Set border style for first gadget
190
191 // Create text gadgets for any mode indicators the user requested,
192 // using provided border style.
193 //
194 TScreenDC dc;
195 dc.SelectObject(*Font);
196
197 for (int i = 0; i < GetModeOnStrings().Count(); i++)
198 if (ModeIndicators & (1 << i)) {
200 if (owl::VkKeys[i] == 0) {
201 gadget = new TTextGadget(GadgetIds[i], BorderStyle, TTextGadget::Left,
202 lstrlen(GetModeOnStrings()[i]),
203 GetModeOnStrings()[i], 0);
204 gadget->SetEnabled(false);
205 }
206 else
207 gadget = new TModeGadget(VkKeys[i], GetModeOnStrings()[i],
208 GadgetIds[i],
209 BorderStyle, TModeGadget::Center, 0);
210
211 TMargins margins = gadget->GetMargins();
212
213 // Use small left and right margins
214 //
215 margins.Left = margins.Right = 2;
216 gadget->SetMargins(margins);
217
219 NumModeIndicators++;
220 }
221
222 if (ModeIndicators & SizeGrip) {
223 InsertSizeGrip();
224 }
225
226}
227
228//
229/// Create a size grip and place it on the status bar.
230/// (Size grips are not available on 16-bit Windows.)
231//
232void
233TStatusBar::InsertSizeGrip()
234{
237
240 TRect bounds = gadget->GetBounds();
241 bounds.Inflate(1, 1);
242 gadget->SetBounds(bounds);
243 NumModeIndicators++;
244}
245
246//
247/// Determines if a given gadget is being used as a mode indicator
248//
249bool
250TStatusBar::IsModeIndicator(TGadget* gadget)
251{
252 int nonModeIndicators = NumGadgets - NumModeIndicators;
253 TGadget* g = Gadgets;
254
255 for (int i = 0; i < nonModeIndicators; i++) {
256 if (gadget == g)
257 return false;
258
259 g = g->NextGadget();
260 }
261
262 return true;
263}
264
265//
266/// Determines the position of the new gadget in relation to any previously existing
267/// gadgets and uses the Pixels, LayoutUnits, and BorderUnits fields of TMargins to
268/// determine the amount of spacing to leave between the mode indicators.
269//
270void
272{
274
275 if (BorderStyle == TGadget::Plain)
276 origin.x -= cxBorder; // overlap the borders
277
279 if (gadget)
280 return;
281
282 // Leave extra spacing between the mode indicators
283 //
284 if (IsModeIndicator(next))
285 switch (Spacing.Units) {
286 case TMargins::Pixels:
287 origin.x += Spacing.Value;
288 break;
289
291 origin.x += LayoutUnitsToPixels(Spacing.Value);
292 break;
293
295 origin.x += Spacing.Value * cxBorder;
296 break;
297 }
298}
299
300//
301/// Inserts the gadget (objects derived from class TGadget) in the status bar. By
302/// default, the new gadget is placed just after any existing gadgets and to the
303/// left of the status mode indicators. For example, you can insert a painting tool
304/// or a happy face that activates a recorded macro.
305//
306void
308{
309 gadget.SetBorderStyle(BorderStyle);
310 if (!sibling)
311 sibling = operator[](NumGadgets - NumModeIndicators - 1);
313}
314
315//
316/// Overriden to allow hint text to be displayed in the text gadget.
317/// If WideHintText is requested then the hint covers the whole gadget window.
318/// Otherwise it is displayed within the text gadget.
319//
320void
322{
323 if (WideHintText)
325 else
326 {
327 tstring s = text ? tstring(text) : tstring();
328 SetText(s);
329 }
330}
331
332//
333/// Get the text gadget & the mode string associated with a mode indicator
334//
335bool
336TStatusBar::GetGadgetAndStrings(TModeIndicator mode, TTextGadget*& gadget,
337 LPCTSTR& strOn)
338{
339 if ((ModeIndicators & mode) == 0) {
340 return false; // tracing
341 }
342 else {
343 uint slot = NumGadgets - 1;
344 int index;
345
346 for (index = GetModeOnStrings().Count() - 1; (1 << index) > mode; index--)
347 if (ModeIndicators & (1 << index))
348 slot--;
349
350 strOn = GetModeOnStrings()[index];
351
352 for (gadget = (TTextGadget*)Gadgets; slot > 0; slot--)
353 gadget = (TTextGadget*)gadget->NextGadget();
354
355 return true;
356 }
357}
358
359//
360/// Toggles the ModeIndicator.
361//
362void
367
368//
369/// Sets TModeIndicator to a given text gadget and set the status (on, by default)
370/// of the mode indicator. For the mode indicator to appear on the status bar, you
371/// must specify the mode when the window is constructed.
372//
373void
375{
377 const tchar* strOn;
378
379 if (GetGadgetAndStrings(mode, gadget, strOn)) {
380 gadget->SetEnabled(on);
381 }
382
383 if (on)
384 ModeIndicatorState |= mode;
385 else
386 ModeIndicatorState &= ~mode;
387}
388
389
390//
391/// If the status bar has a size grip gadget and the mouse is over the gadget,
392/// simulates resizing of the frame.
393//
394uint
396{
398
400 if (grip && grip->GetEnabled()) {
401 TRect rect = grip->GetBounds();
402 rect.right += 1;
403 rect.bottom += 1;
405 if (rect.Contains(p)) ///BGM use TGadget::PtIn here (so IsVisible() will be checked)
407 }
408
409 return retVal;
410}
411
412//
413/// If the frame window that owns the status bar maximizes,
414/// then remove the size grip. (Otherwise, the size grip
415/// remains uselessly and confusingly active in a maximized window.)
416//
417void
419{
422
423 // If the window was maximized and has a grip, then remove the grip.
424 //
425 bool callresize = false;
427 if (grip) {
428 Remove(*grip);
429 delete grip;
430 NumModeIndicators--;
432 callresize = true;
433 }
434 }
435 // If the window was restored and if it is supposed to have a size grip
436 // but the grip isn't there, then provide a new grip.
437 //
438 else if (sizeType == SIZE_RESTORED) {
439 if (!grip && (GetModeIndicators() & SizeGrip)) {
440 InsertSizeGrip();
442 callresize = true;
443 }
444 }
445 if(callresize){
447 if(window)
448 window->Layout();
449 }
450}
451
452
453} // OWL namespace
454/* ========================================================================== */
455
#define PRECONDITION(condition)
Definition checks.h:227
void SelectObject(const TBrush &brush)
Selects the given GDI brush object into this DC.
Definition dc.cpp:113
TFont derived from TGdiObject provides constructors for creating font objects from explicit informati...
Definition gdiobjec.h:296
TGadget is the base class for the following derived gadget classes:
Definition gadget.h:120
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
TGadget * operator[](uint index)
Returns gadget at a given index.
Definition gadgetli.cpp:68
TPlacement
Enumerates the placement of a gadget.
Definition gadgetwi.h:47
TGadget * GadgetWithId(int id) const
Returns the gadget with a given ID, or 0 if none is found.
Definition gadgetli.cpp:56
virtual void Insert(TGadget &gadget, TPlacement=After, TGadget *sibling=nullptr)
Inserts a Gadget.
Definition gadgetli.cpp:89
int LayoutUnitsToPixels(int units)
Converts layout units to pixels.
Definition gadgetwi.cpp:343
friend class TGadget
Definition gadgetwi.h:361
auto Remove(TGadget &) -> TGadget *override
Removes a gadget from the gadget window.
virtual void LayoutSession()
LayoutSession is typically called when a change occurs in the size of the margins or gadgets,...
Definition gadgetwi.cpp:357
Derived from TWindow, TLayoutWindow provides functionality for defining the layout metrics for a wind...
Definition layoutwi.h:122
virtual void Layout()
Causes the window to resize and position its children according to the specified metrics.
Definition layoutwi.cpp:351
Derived from TGadgetWindow, TMessageBar implements a message bar with one text gadget as wide as the ...
Definition messageb.h:36
void SetText(const tstring &text)
Forwards the message in the message bar to the text gadget for formatting.
Definition messageb.cpp:96
virtual void SetHintText(LPCTSTR text)
Sets the hint text displayed on the messagebar.
Definition messageb.cpp:113
TModeGadget is a mode-tracking text gadget class.
Definition modegad.h:29
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
Derived from TWindowDC, TScreenDC is a DC class that provides direct access to the screen bitmap.
Definition dc.h:610
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
TModeIndicator
Enumerates the keyboard modes.
Definition statusba.h:39
uint GetModeIndicators() const
Returns the bit flags for which indicator is on.
Definition statusba.h:204
void EvOwlFrameSize(uint sizeType, const TSize &)
BGM SetModeIndicators is nearly useless; after construction, TStatusBar BGM pays almost no attention ...
Definition statusba.cpp:418
void ToggleModeIndicator(TModeIndicator)
Toggles the ModeIndicator.
Definition statusba.cpp:363
void Insert(TGadget &, TPlacement=After, TGadget *sibling=nullptr) override
By default, adds "gadget" after the existing text gadgets and before the mode indicator gadgets.
Definition statusba.cpp:307
void PositionGadget(TGadget *previous, TGadget *next, TPoint &) override
Determines the position of the new gadget in relation to any previously existing gadgets and uses the...
Definition statusba.cpp:271
TStatusBar(TWindow *parent=0, TGadget::TBorderStyle borderStyle=TGadget::Recessed, uint modeIndicators=0, TFont *font=0, TModule *module=0)
Constructs a TStatusBar object in the parent window and creates any new gadgets and mode indicator ga...
Definition statusba.cpp:128
uint EvNCHitTest(const TPoint &point)
If the status bar has a size grip gadget and the mouse is over the gadget, simulates resizing of the ...
Definition statusba.cpp:395
void SetModeIndicator(TModeIndicator, bool state)
Sets TModeIndicator to a given text gadget and set the status (on, by default) of the mode indicator.
Definition statusba.cpp:374
void SetHintText(LPCTSTR text) override
Overriden method of TMessageBar to use our own text gadget Set (or clear if 0) menu/command item hint...
Definition statusba.cpp:321
bool GetModeIndicator(TModeIndicator i) const
Returns the current status bar mode indicator.
Definition statusba.h:158
Derived from TGadget, TTextGadget is a text gadget object.
Definition textgadg.h:37
@ Left
Aligns the text at the left edge of the bounding rectangle.
Definition textgadg.h:43
@ Center
Aligns the text horizontally at the center of the bounding rectangle.
Definition textgadg.h:44
static const TUIMetric CyBorder
Definition uimetric.h:40
static const TUIMetric CxBorder
Definition uimetric.h:39
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
void SetFlag(uint mask)
Sets the specified TWindow wfXxxx constant flags (for example wfAlias, wfTransfer,...
Definition window.h:1783
TWindow * GetParentO() const
Return the OWL's parent for this window.
Definition window.h:2006
TModule * GetModule() const
Returns a pointer to the module object.
Definition window.h:1841
TPoint MapScreenToClient(const TPoint &p) const
Functional-style version of ScreenToClient.
Definition window.h:870
uint EvNCHitTest(const TPoint &)
The default message handler for WM_NCHITTEST.
Definition window.h:3869
#define _tcslen
Definition cygwin.h:74
#define _T(x)
Definition cygwin.h:51
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
#define IDG_STATUS_SCRL
The ID for a scroll lock gadget.
Definition gadget.h:33
#define IDG_SIZEGRIP
The ID for a size grip gadget.
Definition gadget.h:36
#define IDG_STATUS_OVR
The ID for an overwrite gadget.
Definition gadget.h:34
#define IDG_STATUS_CAPS
The ID for a capslock gadget.
Definition gadget.h:31
#define IDG_STATUS_EXT
The ID for an extended selection gadget.
Definition gadget.h:30
#define IDG_STATUS_NUM
The ID for a numlock gadget.
Definition gadget.h:32
#define IDG_STATUS_REC
The ID for a record gadget.
Definition gadget.h:35
@ wfInsertAtEdge
(Decoration) Window to be inserted against frame's edge
Definition window.h:83
Definition of classes TLayoutMetrics & TLayoutWindow.
char * strnewdup(const char *s, size_t minAllocSize=0)
Definition memory.cpp:25
Definition of mode-tracking text gadget class TModeGadget.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
EV_WM_NCHITTEST
Definition floatfra.cpp:29
EV_OWLFRAMESIZE
Definition statusba.cpp:112
char tchar
Definition defs.h:77
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
unsigned short uint16
Definition number.h:33
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
General definitions used by all ObjectWindows programs.
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269
Definition of class TStatusBar.
Used by the TGadgetWindow and TGadget classes, TMargins contains the measurements of the margins for ...
Definition gadget.h:54
TMargins::TUnits Units
Definition statusba.h:78
Definition of TUIMetric, a UI metrics provider class.