OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
messageb.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 class TMessageBar.
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/messageb.h>
10#include <owl/textgadg.h>
11#include <owl/uimetric.h>
12
13namespace owl {
14
16
17static TFont* createMsgBarFont()
18{
19 return new TDefaultGuiFont(TDefaultGuiFont::sfiStatus);
20}
21//
22/// Constructs a TMessageBar object with the gadget window font. Sets IDW_STATUSBAR,
23/// HighlightLine to true, and TTextGadget's member WideAsPossible to true, making
24/// the text gadget as wide as the window.
25//
27:
28 TGadgetWindow(parent, Horizontal, font ? font : createMsgBarFont(), module),
29 HighlightLine{false},
30 HintText{},
31 GadgetVisibilityCache{}
32{
33 Attr.Id = IDW_STATUSBAR;
35 textGadget->SetWideAsPossible();
37}
38
39//
40/// Adjusts the message bar and paints a highlight line. Then, PaintGadgets either
41/// paints the hint text if any is set or calls TGadgetWindow::PaintGadgets to
42/// repaint each gadget.
43//
44void
46{
47 if (HighlightLine && rect.top == 0)
49
50 if (!HintText.empty())
51 {
53 int y = (clientRect.bottom - GetFontHeight()) / 2;
54 if (HighlightLine)
58 dc.ExtTextOut(5, y, ETO_OPAQUE, &clientRect, HintText, static_cast<int>(HintText.length()));
59 }
60 else
61 {
63 }
64}
65
66//
67/// GetInnerRect computes the rectangle inside the borders and margins of the
68/// message bar. Adjust for the top highlight line if one is set.
69//
70void
78
79//
80/// Calls TGadgetWindow's GetDesiredSize to get the size of the message bar. Then,
81/// if a highlighting line is drawn, adjusts the size of the message bar.
82//
83void
85{
87
88 if (HighlightLine)
89 size.cy++;
90}
91
92//
93/// Forwards the message in the message bar to the text gadget for formatting.
94//
95void
100
101//
102/// Sets the text for the default text message gadget by specifying the id.
103//
104void
106{
108 if (tg)
109 tg->SetText(text.c_str());
110}
111
112void
114{
115 if (text && *text) // !empty
116 {
117 if (text == HintText) return;
118 HintText = text;
119 }
120 else
121 {
122 if (HintText.empty()) return;
123 HintText.clear();
124 }
125
126 if (HintText.empty())
127 {
128 // Restore the visibility state of the gadgets.
129 //
130 // NOTE: We here ignore any changes in gadget visibility between the time the hint text was set
131 // and the time it was cleared (now). To improve this, a notification mechanism is needed to
132 // detect calls to TGadget::SetVisible while the hint text is shown, and update the visibility
133 // state cache accordingly.
134 //
135 for (auto g = FirstGadget(); g; g = NextGadget(*g))
136 {
137 const auto i = GadgetVisibilityCache.find(g);
138 g->SetVisible(i != GadgetVisibilityCache.cend() ? i->second : true);
139 }
140 GadgetVisibilityCache.clear();
141 }
142 else if (GadgetVisibilityCache.empty())
143 {
144 // Store the visibility state of the gadgets and hide them.
145 //
146 for (auto g = FirstGadget(); g; g = NextGadget(*g))
147 {
148 GadgetVisibilityCache.insert({g, g->IsVisible()});
149 g->SetVisible(false);
150 }
151 }
152
153 if (IsWindow())
154 Invalidate();
155}
156
161
162} // OWL namespace
163/* ========================================================================== */
164
static const TColor Sys3dHilight
The symbolic system color value for highlighted 3-dimensional display elements (for edges facing the ...
Definition color.h:344
static const TColor Sys3dFace
The symbolic system color value for the face color of 3-dimensional display elements.
Definition color.h:339
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
void SelectObject(const TBrush &brush)
Selects the given GDI brush object into this DC.
Definition dc.cpp:113
virtual bool ExtTextOut(int x, int y, uint16 options, const TRect *r, const tstring &str, int count=-1, const int *dx=nullptr)
Draws up to count characters of the given null-terminated string in the current font on this DC.
Definition dc.cpp:603
bool TextRect(int x1, int y1, int x2, int y2)
Fills the given rectangle, clipping any text to the rectangle.
Definition dc.h:1878
virtual TColor SetBkColor(const TColor &color)
Sets the current background color of this DC to the given color value or the nearest available.
Definition dc.cpp:405
@ sfiStatus
Represents NONCLIENTMETRICS::lfStatusFont.
Definition gdiobjec.h:393
TFont derived from TGdiObject provides constructors for creating font objects from explicit informati...
Definition gdiobjec.h:296
@ Recessed
Recessed into the window.
Definition gadget.h:131
TGadget * NextGadget(TGadget &gadget) const
Returns the next gadget in the list relative to a given gadget.
Definition gadgetwi.h:407
TGadget * GadgetWithId(int id) const
Returns the gadget with a given ID, or 0 if none is found.
Definition gadgetli.cpp:56
TGadget * FirstGadget() const
Returns the first gadget of the list.
Definition gadgetwi.h:400
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
virtual void PaintGadgets(TDC &dc, bool erase, TRect &rect)
Called by Paint to repaint all of the gadgets, PaintGadgets iterates through the list of gadgets,...
void Insert(TGadget &, TPlacement=After, TGadget *sibling=nullptr) override
Inserts a gadget before or after a sibling gadget (TPlacement).
virtual void GetDesiredSize(TSize &size)
Get the desired size for this gadget window by performing a trial layout of the gadgets without touch...
Definition gadgetwi.cpp:380
const TFont & GetFont() const
Returns the font being used by this gadget window.
Definition gadgetwi.h:423
virtual void GetInnerRect(TRect &rect)
GetInnerRect computes the rectangle inside of the borders and margins of the gadget.
Definition gadgetwi.cpp:564
TMessageBar(TWindow *parent=nullptr, TFont *font=nullptr, TModule *module=nullptr)
Constructs a TMessageBar object with the gadget window font.
Definition messageb.cpp:26
void SetText(const tstring &text)
Forwards the message in the message bar to the text gadget for formatting.
Definition messageb.cpp:96
void SetMessageText(int id, const tstring &text)
Sets the text for the default text message gadget by specifying the id.
Definition messageb.cpp:105
void GetInnerRect(TRect &rect)
GetInnerRect computes the rectangle inside the borders and margins of the message bar.
Definition messageb.cpp:71
void PaintGadgets(TDC &dc, bool erase, TRect &rect)
Adjusts the message bar and paints a highlight line.
Definition messageb.cpp:45
void GetDesiredSize(TSize &rect)
Calls TGadgetWindow's GetDesiredSize to get the size of the message bar.
Definition messageb.cpp:84
void ClearHintText()
Clears the hint text, thus restoring the underlying content on the messagebar.
Definition messageb.cpp:157
virtual void SetHintText(LPCTSTR text)
Sets the hint text displayed on the messagebar.
Definition messageb.cpp:113
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
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
static const TUIMetric CyBorder
Definition uimetric.h:40
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
bool IsWindow() const
Returns true if an HWND is being used.
Definition window.h:2040
TRect GetClientRect() const
Gets the coordinates of the window's client area (the area in a window you can use for drawing).
Definition window.h:2217
virtual void Invalidate(bool erase=true)
Invalidates (mark for painting) the entire client area of a window.
Definition window.h:2822
#define IDG_MESSAGE
Definition gadget.h:29
Definition of class TMessageBar.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
OWL_DIAGINFO
Definition animctrl.cpp:14
const int IDW_STATUSBAR
Definition messageb.h:25
std::string tstring
Definition defs.h:79
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269
Definition of text gadget class TGadget.
Definition of TUIMetric, a UI metrics provider class.