OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
progressbar.cpp
Go to the documentation of this file.
1//
2/// \file progressbar.cpp
3/// Encapsulation for Windows ProgressBar common control
4//
5// Part of OWLNext - the next generation Object Windows Library
6// Copyright © 2010-2011 Jogy
7//
8// For more information, including license details, see
9// http://owlnext.sourceforge.net
10//
11
12#include <owl/pch.h>
13#include <owl/progressbar.h>
14#include <owl/commctrl.h>
15#include <owl/uimetric.h>
16#include <stdio.h>
17
18namespace owl {
19
21
22//
23/// Simplified constructor for a TProgressBar object. Creates a horizontal LED progressbar
24///
26 int id,
27 int x, int y, int w, int h,
28 TModule* module)
29:
30 TControl(parent, id, _T(""), x, y, w, h ? h : int(TUIMetric::CyVScroll), module)
31{
33 Min = 0;
34 Max = 100;
35 Step = 10;
36 Value = 0;
37 Margin = TUIMetric::CxBorder;
38 Attr.Style &= ~WS_TABSTOP;
39 Marquee = false;
40 MarqueeUpdateTime = 0;
41}
42
43//
44// Constructor for a resource gauge object.
45//
47 int resId,
48 TModule* module)
49:
50 TControl(parent, resId, module)
51{
53 Min = 0;
54 Max = 100;
55 Step = 10;
56 Value = 0;
57 Margin = TUIMetric::CxBorder;
58 Marquee = false;
59 MarqueeUpdateTime = 0;
60}
61
62//
63/// Returns the class name of the native control
64//
69
70//
71/// Sets the Min and Max data members to minValue and maxValue values returned by the
72/// constructor. If Max is less than or equal to Min, SetRange resets Max to Min + 1.
73/// Note: This function is now implemented in terms of the PBM_SETRANGE32 message, thus
74/// supporting a full 32-bit range. Previous implementations used the 16-bit PBM_SETRANGE.
75//
76void
78{
79 if (maxValue <= minValue)
81
82 if (GetHandle())
84
85 Min = minValue;
86 Max = maxValue;
87}
88
89//
90/// Sets the BarColor data member to the value specified in color.
91//
92void
99
100void
107
108//
109/// Sets the Step amount of the gauge for StepIt operations
110//
111void
113{
114 if (GetHandle())
116 Step = step;
117}
118
119//
120/// Set the value of the gauge
121//
122/// Restricts value to be within the minimum and maximum values established for the
123/// gauge. If the current value has changed, SetValue marks the old position for
124/// repainting. Then, it sets the data member Value to the new value.
125//
126void
128{
129 // Constrain value to be in the range "Min..Max"
130 //
131 if (value > Max)
132 value = Max;
133
134 else if (value < Min)
135 value = Min;
136
137 // Paint to new position, converting value to pixels
138 //
139 if (value != Value) {
140 if (GetHandle()) {
142 }
143 Value = value;
144 }
145}
146
147//
148/// Changes the value of the gauge by the given delta.
149//
150void
152{
153 if (!delta)
154 return;
155
156 // Constrain delta such that Value stays in the range "Min..Max"
157 //
158 if (delta + Value > Max)
159 delta = Max - Value;
160
161 else if (delta + Value < Min)
162 delta = Min - Value;
163
164 if (GetHandle()) {
165 Value = static_cast<int>(SendMessage(PBM_DELTAPOS, delta)) + delta; // Take oportunity to sync
166 return; // Bypass Value update below
167 }
168
169 Value += delta;
170}
171
172//
173/// Adjusts the active gauge value by the Step increment. If the new value exceeds
174/// the Max value of the gauge, StepIt wraps the setting of the gauge to its Min
175/// value.
176//
177void
179{
180 if (GetHandle()) {
182 }
183 else {
184 if (Value + Step < Max)
185 DeltaValue(Step);
186 else
187 SetValue(Min);
188 }
189}
190
191//
192/// Sets the state of the progress bar.
193/// Returns the previous state.
194/// \note Wrapper for PBM_SETSTATE.
195/// \see https://msdn.microsoft.com/en-us/library/windows/desktop/bb760850.aspx
196//
198{
199 return static_cast<uint>(SendMessage(PBM_SETSTATE, state));
200}
201
203{
204 if (enable)
206 else
208
209 if (GetHandle())
210 {
212 }
213 else
214 {
215 Marquee = enable;
216 MarqueeUpdateTime = timeBetweenUpdates;
217 }
218}
219
220
221//
222/// If a system control is being used, updates it to match our member settings.
223//
224void
226{
228 SendMessage(PBM_SETRANGE, 0, MkParam2(Min, Max));
230 SendMessage(PBM_SETPOS, Value);
231 if (Marquee)
232 SendMessage(PBM_SETMARQUEE, Marquee, MarqueeUpdateTime);
233}
234
235
236} // OWL namespace
237/* ========================================================================== */
238
#define PRECONDITION(condition)
Definition checks.h:227
Class wrapper for management of color values.
Definition color.h:245
static const TColor None
not-a-color
Definition color.h:318
TControl unifies its derived control classes, such as TScrollBar, TControlGadget, and TButton.
Definition control.h:38
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
void StepIt()
Adjusts the active gauge value by the Step increment.
void DeltaValue(int delta)
Changes the value of the gauge by the given delta.
void SetStep(int step)
Sets the Step amount of the gauge for StepIt operations.
void SetBkgndColor(const TColor &color)
virtual auto GetWindowClassName() -> TWindowClassName
Returns the class name of the native control.
void SetMarquee(bool enable, uint timeBetweenUpdates=0)
void SetupWindow()
If a system control is being used, updates it to match our member settings.
void SetRange(int minValue, int maxValue)
Sets the Min and Max data members to minValue and maxValue values returned by the constructor.
TProgressBar(TWindow *parent, int id, int x, int y, int w, int h=0, TModule *module=0)
Simplified constructor for a TProgressBar object.
void SetColor(const TColor &color)
Sets the BarColor data member to the value specified in color.
void SetValue(int value)
Set the value of the gauge.
auto SetState(uint) -> uint
Sets the state of the progress bar.
TUIMetric encapsulates the GetSystemMetric() API.
Definition uimetric.h:32
static const TUIMetric CxBorder
Definition uimetric.h:39
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Definition module.h:47
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
bool ModifyStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
Definition window.cpp:3591
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
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
Definition of classes for CommonControl encapsulation.
#define _T(x)
Definition cygwin.h:51
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
void InitializeCommonControls(uint controlFlags)
Wrapper for the Windows API function InitCommmonControlsEx.
Definition commctrl.cpp:19
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
TParam2 MkParam2(const T1 &lo, const T2 &hi)
Definition dispatch.h:65
OWL_DIAGINFO
Definition animctrl.cpp:14
unsigned int uint
Definition number.h:25
Encapsulation for Windows ProgressBar common control.
Definition of TUIMetric, a UI metrics provider class.