forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgressBar.cpp
More file actions
138 lines (92 loc) · 2.78 KB
/
ProgressBar.cpp
File metadata and controls
138 lines (92 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//
// ProgressBar.cpp
//
#include "ProgressBar.h"
namespace CppUnit {
// Paint the progress bar in response to a paint message
void ProgressBar::paint(CDC& dc)
{
paintBackground (dc);
paintStatus (dc);
}
// Paint the background of the progress bar region
void ProgressBar::paintBackground (CDC& dc)
{
CBrush brshBackground;
CPen penGray (PS_SOLID, 1, RGB (128, 128, 128));
CPen penWhite (PS_SOLID, 1, RGB (255, 255, 255));
VERIFY (brshBackground.CreateSolidBrush (::GetSysColor (COLOR_BTNFACE)));
dc.FillRect (_bounds, &brshBackground);
CPen *pOldPen;
pOldPen = dc.SelectObject (&penGray);
{
dc.MoveTo (_bounds.left, _bounds.top);
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top);
dc.MoveTo (_bounds.left, _bounds.top);
dc.LineTo (_bounds.left, _bounds.top + _bounds.Height () -1);
}
dc.SelectObject (&penWhite);
{
dc.MoveTo (_bounds.left + _bounds.Width () -1, _bounds.top);
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top + _bounds.Height () -1);
dc.MoveTo (_bounds.left, _bounds.top + _bounds.Height () -1);
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top + _bounds.Height () -1);
}
dc.SelectObject (pOldPen);
}
// Paint the actual status of the progress bar
void ProgressBar::paintStatus (CDC& dc)
{
if (_progress <= 0)
return;
CBrush brshStatus;
CRect rect (_bounds.left, _bounds.top,
_bounds.left + _progressX, _bounds.bottom);
COLORREF statusColor = getStatusColor ();
VERIFY (brshStatus.CreateSolidBrush (statusColor));
rect.DeflateRect (1, 1);
dc.FillRect (rect, &brshStatus);
}
// Paint the current step
void ProgressBar::paintStep (int startX, int endX)
{
// kludge: painting the whole region on each step
_baseWindow->RedrawWindow (_bounds);
_baseWindow->UpdateWindow ();
}
// Setup the progress bar for execution over a total number of steps
void ProgressBar::start (int total)
{
_total = total;
reset ();
}
// Take one step, indicating whether it was a successful step
void ProgressBar::step (bool successful)
{
_progress++;
int x = _progressX;
_progressX = scale (_progress);
if (!_error && !successful)
{
_error = true;
x = 1;
}
paintStep (x, _progressX);
}
// Map from steps to display units
int ProgressBar::scale (int value)
{
if (_total > 0)
return max (1, value * (_bounds.Width () - 1) / _total);
return value;
}
// Reset the progress bar
void ProgressBar::reset ()
{
_progressX = 1;
_progress = 0;
_error = false;
_baseWindow->RedrawWindow (_bounds);
_baseWindow->UpdateWindow ();
}
} // namespace CppUnit