OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
splashwi.cpp
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/// Implementation of TSplashWindow
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/splashwi.h>
10#include <owl/gdiobjec.h>
11#include <owl/layoutwi.h>
12#include <owl/pictwind.h>
13#include <owl/static.h>
14#include <owl/gauge.h>
15#include <owl/uimetric.h>
16
17namespace owl {
18
20
21//
22// ID for creating a timer.
23//
24const int TimerId = 1;
25
26//
27// Threshold value for removing the splash screen.
28//
29const int PercentThreshold = 95;
30
31//
32// Response table for the splash window.
33//
38
39//
40/// Constructor to create a splash screen. The parameters width and height are the
41/// dimensions of the window unless the style ShrinkToFit is used (in which case,
42/// the size of the DIB is used). The timeOut parameter is the number of
43/// milliseconds to wait until the splash screen closes itself. Use 0 to not
44/// automatically close the splash screen. The splash screen does not assume
45/// ownership of the DIB; a private copy is made.
46//
47TSplashWindow::TSplashWindow(const TDib& dib, int width, int height,
48 int style, uint timeOut, LPCTSTR title, TModule* module)
49:
50 TLayoutWindow(nullptr, title, module),
51 Style(style),
52 Static(nullptr),
53 Gauge(0),
54 PictWindow(nullptr),
55 TimeOut(timeOut),
56 CapturedMouse(false)
57{
58 if (HasStyle(ShrinkToFit)) {
59 Attr.W = dib.Width();
60 Attr.H = dib.Height();
61 }
62 else {
63 Attr.W = width;
64 Attr.H = height;
65 }
66
67 Attr.Style = WS_POPUP | WS_VISIBLE | WS_BORDER;
68
69 // If there's a title add the WS_CAPTION style. If ShrinkToFit is set
70 // we also want to adjust the height of the window to account for the
71 // caption.
72 //
73 if( title && ::_tcslen(title)){
74 Attr.Style |= WS_CAPTION;
77 }
78
79 // Ready the layout metrics
80 //
81 int heightPercentDW = 100;
85
86 // Center the dib by default unless ShrinktoFit is set.
87 //
90
91 // Create a a picture window to handle the rendering of the bitmap.
92 // Note that we must make a copy of the DIB since TPictureWindow grabs ownership.
93 //
94 PictWindow = new TPictureWindow(this, new TDib(dib), dispHow, _T(""), module);
95
96 lmPictWindow.X.SameAs(lmParent, lmLeft);
97 lmPictWindow.Y.SameAs(lmParent, lmTop);
98 lmPictWindow.Width.SameAs(lmParent, lmWidth);
99
100 // Create optional static control
101 //
102 if (HasStyle(MakeStatic)) {
103 const int StaticPercent = 10;
104 Static = new TStatic(this, 1, _T(""), 0, 0, 0, 0, 0, module);
105 Static->GetWindowAttr().Style |= SS_CENTER;
107 lmStatic.X.SameAs(lmParent, lmLeft);
108 lmStatic.Width.SameAs(lmParent, lmWidth);
109 lmStatic.Height.PercentOf(lmParent, StaticPercent, lmHeight);
110
111 lmStatic.Y.Below(PictWindow, 1);
113 }
114
115 // Create optional gauge control
116 //
117 if (HasStyle(MakeGauge)) {
118 const int GaugePercent = 10;
119 Gauge = new TGauge(this, _T("%d%%"), 2, 0, 0, 0, 0, true, 0, module);
121 lmGauge.X.SameAs(lmParent, lmLeft);
122 lmGauge.Width.SameAs(lmParent, lmWidth);
123 lmGauge.Height.PercentOf(lmParent, GaugePercent, lmHeight);
124
125 if (HasStyle(MakeStatic))
126 lmGauge.Y.Below(Static, 1);
127 else
128 lmGauge.Y.Below(PictWindow, 1);
129
131 }
132
133 lmPictWindow.Height.PercentOf(lmParent, heightPercentDW, lmHeight);
135}
136
137//
138/// Deletes the child controls.
139//
141{
142 delete Static;
143 delete Gauge;
144 delete PictWindow;
145}
146
147//
148/// After the window has been created, this centers the window and makes it topmost.
149//
150void
152{
154
155 // Center window, make topmost and adjust size to accomidate static
156 // and gauge.
157 //
159
161 int deltaH = Gauge->GetWindowAttr().H;
162 r.Inflate( 0, deltaH );
163 }
164
166
167 int x = (fullRect.Width() - r.Width()) / 2;
168 int y = (fullRect.Height() - r.Height()) / 2;
169 r.Offset(x, y);
171
172 if (HasStyle(MakeGauge)) {
173 // Set the range
174 //
175 GetGauge()->SetRange(0, 100);
176 }
177
178 if (GetTimeOut() != 0) {
179 // Create the timer
180 //
182 }
183
184 // Trap the mouse click
185 //
186 if (HasStyle(CaptureMouse)) {
187 SetCapture();
188 SetCursor(nullptr, IDC_ARROW);
189 CapturedMouse = true;
190 }
191}
192
193//
194/// Before the window closes, and if the mouse has been captured, this releases it now.
195//
196void
198{
199 if (CapturedMouse) {
201 CapturedMouse = false;
202 }
203
204 if (GetTimeOut() != 0)
206}
207
208//
209// Overload Create so that we can force the window to paint asap.
210//
211bool
213{
215 UpdateWindow();
216 return retval;
217}
218
219//
220/// Changes the text within the static control. If the splash screen does not have a
221/// static control, this doesn't do anything.
222//
223void
232
233//
234/// Sets the percentage done for the gauge control. If the splash screen does not
235/// have a gauge control, this doesn't do anything.
236//
237void
239{
240 if (HasStyle(MakeGauge) && IsWindow()) {
241 if (GetGauge())
243
245 // Set up the timer
246 //
247 if (GetTimeOut() != 0)
249 }
250 // and last
251 if (GetGauge())
253 }
254}
255
256//
257/// If the user clicks on the splash screen and the CaptureMouse style is on, this
258/// closes the splash screen.
259//
260void
261TSplashWindow::EvLButtonDown(uint /*modKeys*/, const TPoint& /*point*/)
262{
263 if (HasStyle(CaptureMouse)) {
264 if (HasStyle(MakeGauge))
265 if (GetGauge()->GetValue() < PercentThreshold)
266 return;
267// !BB CloseWindow();
269 }
270}
271
272//
273/// Handler for the timer event. Closes the window.
274//
275void
277{
278 if (HasStyle(MakeGauge)) {
279 if (GetGauge()->GetValue() < PercentThreshold) {
280 // If less than 90% and has a gauge, immediately return
281 //
282 return;
283 }
284 }
285// !BB CloseWindow();
287}
288
289} // OWL namespace
290/* ========================================================================== */
291
Pseudo-GDI object Device Independent Bitmap (DIB) class.
Definition gdiobjec.h:795
A streamable class derived from TControl, TGauge defines the basic behavior of gauge controls.
Definition gauge.h:44
void SetValue(int value)
Set the value of the gauge.
Definition gauge.cpp:176
void SetRange(int minValue, int maxValue)
Sets the Min and Max data members to minValue and maxValue values returned by the constructor.
Definition gauge.cpp:131
When specifying the layout metrics for a window, four layout constraints are needed.
Definition layoutwi.h:54
Derived from TWindow, TLayoutWindow provides functionality for defining the layout metrics for a wind...
Definition layoutwi.h:122
void SetChildLayoutMetrics(TWindow &child, const TLayoutMetrics &metrics)
Sets the metrics for the window and removes any existing ones.
Definition layoutwi.cpp:465
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
bool PumpWaitingMessages()
The inner message loop.
Definition msgthred.cpp:123
This class displays a dib in a window in different ways.
Definition pictwind.h:35
TDisplayHow
How to display the bitmap within the window.
Definition pictwind.h:40
@ Center
Always centered.
Definition pictwind.h:42
@ UpperLeft
Displays the DIB in the upper left corner of the window.
Definition pictwind.h:41
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
This class creates a layout window that contains a TPictureWindow and optionally, a TStatic and a TGa...
Definition splashwi.h:43
uint GetTimeOut() const
Returns the number of milliseconds for the splash window to automatically close.
Definition splashwi.h:148
void SetPercentDone(int percent)
Sets the percentage done for the gauge control.
Definition splashwi.cpp:238
void CleanupWindow() override
Before the window closes, and if the mouse has been captured, this releases it now.
Definition splashwi.cpp:197
void EvTimer(uint timerId)
Handler for the timer event. Closes the window.
Definition splashwi.cpp:276
void SetText(LPCTSTR text)
Changes the text within the static control.
Definition splashwi.cpp:224
void SetupWindow() override
After the window has been created, this centers the window and makes it topmost.
Definition splashwi.cpp:151
bool HasStyle(TStyle) const
Determines if the splash window has a particular style.
Definition splashwi.h:114
TSplashWindow(const TDib &dib, int width, int height, int style=None, uint timeOut=0, LPCTSTR title=0, TModule *module=0)
Constructor to create a splash screen.
Definition splashwi.cpp:47
~TSplashWindow() override
Deletes the child controls.
Definition splashwi.cpp:140
auto Create() -> bool override
Definition splashwi.cpp:212
@ MakeGauge
Display a gauge to indicate progess.
Definition splashwi.h:50
@ MakeStatic
Display a text control.
Definition splashwi.h:51
@ ShrinkToFit
Resizes window to fit bitmap.
Definition splashwi.h:49
@ CaptureMouse
Capture mouse clicks.
Definition splashwi.h:52
TStatic * GetStatic()
Returns the static control used by the splash window.
Definition splashwi.h:131
void EvLButtonDown(uint modKeys, const TPoint &point)
If the user clicks on the splash screen and the CaptureMouse style is on, this closes the splash scre...
Definition splashwi.cpp:261
TGauge * GetGauge()
Returns the gauge used by the splash window.
Definition splashwi.h:140
An interface object that represents a static text interface element.
Definition static.h:36
void SetText(LPCTSTR str)
Sets the static control's text to the string supplied in str.
Definition static.h:226
static const TUIMetric CxScreen
Definition uimetric.h:34
static const TUIMetric CyScreen
Definition uimetric.h:35
bool SetCursor(TModule *module, TResId resId)
Sets the mouse cursor for the window, loading the given resId from the given module.
Definition window.cpp:3766
HWND SetCapture()
Sets the mouse capture to the current window.
Definition window.h:2121
bool KillTimer(UINT_PTR timerId)
Gets rid of the timer and removes any WM_TIMER messages from the message queue.
Definition window.h:3325
TApplication * GetApplication() const
Gets a pointer to the TApplication object associated with this.
Definition window.h:1855
bool SetWindowPos(HWND hWndInsertAfter, const TRect &rect, uint flags)
Changes the size of the window pointed to by rect.
Definition window.h:2809
virtual bool Create()
Creates the window interface element to be associated with this ObjectWindows interface element.
Definition window.cpp:2399
TRect GetWindowRect() const
Gets the screen coordinates of the window's rectangle.
Definition window.h:2257
static void ReleaseCapture()
Releases the mouse capture from this window.
Definition window.h:2130
TWindowAttr & GetWindowAttr()
Returns the TWindowAttr structure, which contains the window's creation attributes.
Definition window.h:1886
bool IsWindow() const
Returns true if an HWND is being used.
Definition window.h:2040
UINT_PTR SetTimer(UINT_PTR timerId, uint timeout, TIMERPROC proc=0)
Creates a timer object associated with this window.
Definition window.h:3339
void UpdateWindow()
Updates the client area of the specified window by immediately sending a WM_PAINT message.
Definition window.h:2901
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition window.cpp:3288
virtual void SetupWindow()
Performs setup following creation of an associated MS-Windows window.
Definition window.cpp:2575
#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
Definition of class TGauge, a gauge control encapsulation & implementation.
Definition of abstract GDI object class and derived classes.
#define lmParent
Use to represent the parent in layout metrics.
Definition layoutco.h:31
@ lmTop
The top edge of the window.
Definition layoutco.h:38
@ lmLeft
The left edge of the window.
Definition layoutco.h:37
@ lmWidth
Definition layoutco.h:48
@ lmHeight
Definition layoutco.h:48
Definition of classes TLayoutMetrics & TLayoutWindow.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
const int PercentThreshold
Definition splashwi.cpp:29
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
EV_WM_TIMER
Definition propsht.cpp:34
unsigned int uint
Definition number.h:25
EV_WM_LBUTTONDOWN
Definition checklst.cpp:195
const int TimerId
Definition splashwi.cpp:24
Definition of class TPictureWindow.
Definition of class TSplashWindow.
Definition of class TStatic, the class for static controls and base for any control that manages simp...
int H
height of the window
Definition window.h:342
uint32 Style
Contains the values that define the style, shape, and size of your window.
Definition window.h:331
Definition of TUIMetric, a UI metrics provider class.