-
Notifications
You must be signed in to change notification settings - Fork 3
/
ZtProgress.cls
188 lines (153 loc) · 5.96 KB
/
ZtProgress.cls
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "ZtProgress"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Class ZtProgress.
' It manages progress bars in ZtStartForm.
'
' Zotero Tools.
' This software is under Revised ('New') BSD license.
' Copyright © 2019, Olaf Ahrens. All rights reserved.
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Private constants.
Private Const PVT_SUBSTEPS_RUNNING_WIDTH_DIVISOR As Integer = 10
Private Const PVT_SUBSTEPS_RUNNING_SHIFT_DIVISOR As Integer = 7
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Private variables.
Private pvtSub0Control As MSForms.Control
Private pvtSub1Control As MSForms.Control
Private pvtControl As MSForms.Control
Private pvtSubMax As Single
Private pvtMax As Single
Private pvtSubProgressWidth As Single
Private pvtProgressWidth As Single
Private pvtSub0CurrentWidth As Single
Private pvtSub1CurrentWidth As Single
Private pvtCurrentWidth As Single
Private pvtSubRunningWidth As Single
Private pvtSubRunningShift As Single
Private pvtSub0Left As Single
Private pvtIsInRunningMode As Boolean
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Friend procedures and properties.
Friend Sub Initialize(ByVal valSubstepsControl0 As MSForms.Control, ByVal valSubstepsControl1 As MSForms.Control, ByVal valStepsControl As MSForms.Control, _
ByVal valSubstepsMaxWidth As Single, ByVal valStepsMaxWidth As Single)
Set pvtSub0Control = valSubstepsControl0
Set pvtSub1Control = valSubstepsControl1
Set pvtControl = valStepsControl
pvtSubMax = valSubstepsMaxWidth
pvtMax = valStepsMaxWidth
pvtSubRunningWidth = pvtSubMax / PVT_SUBSTEPS_RUNNING_WIDTH_DIVISOR
pvtSubRunningShift = pvtSubRunningWidth / PVT_SUBSTEPS_RUNNING_SHIFT_DIVISOR
Me.Reset
End Sub
Friend Sub Reset()
pvtSubProgressWidth = 0
pvtProgressWidth = 0
pvtSub0CurrentWidth = 0
pvtSub1CurrentWidth = 0
pvtCurrentWidth = 0
pvtSub0Left = 0
With pvtSub0Control
.Left = pvtSub0Left
.Width = pvtSub0CurrentWidth
End With
With pvtSub1Control
.Left = 0
.Width = pvtSub1CurrentWidth
End With
With pvtControl
.Left = 0
.Width = pvtCurrentWidth
End With
pvtIsInRunningMode = False
DoEvents
End Sub
Friend Sub SetCompleted()
pvtIsInRunningMode = False
pvtSubProgressWidth = pvtSubMax
pvtSub0Control.Width = pvtSubProgressWidth
pvtSub0Left = 0
pvtSub0Control.Left = pvtSub0Left
pvtSub1CurrentWidth = 0
pvtSub1Control.Width = pvtSub1CurrentWidth
pvtCurrentWidth = pvtMax
pvtControl.Width = pvtCurrentWidth
End Sub
Friend Sub SetStepsCt(ByVal valCt As Integer)
pvtProgressWidth = pvtMax / CSng(valCt + 2) ' For initial step and last step.
Me.SetCompleteStep
End Sub
Friend Sub SetStep(Optional ByVal valSubstepsCt As Integer = 0)
If pvtProgressWidth > 0 Then
If pvtIsInRunningMode Then
If valSubstepsCt > 0 Then
Me.SetToNormalMode
End If
Else
If valSubstepsCt = 0 Then
Me.SetToRunningMode
End If
End If
pvtCurrentWidth = pvtCurrentWidth + pvtProgressWidth
pvtControl.Width = pvtCurrentWidth
If Not pvtIsInRunningMode Then
pvtSubProgressWidth = pvtSubMax / valSubstepsCt
pvtSub0CurrentWidth = 0
pvtSub0Control.Width = pvtSub0CurrentWidth
pvtSub1CurrentWidth = 0
pvtSub1Control.Width = pvtSub1CurrentWidth
End If
DoEvents
End If
End Sub
Friend Sub SetCompleteStep()
Me.SetStep 1
Me.SetSubstep
End Sub
Friend Sub SetSubstep()
If pvtProgressWidth > 0 Then
If pvtIsInRunningMode Then
pvtSub0Left = (pvtSub0Left + pvtSubRunningShift) Mod pvtSubMax
pvtSub0Control.Left = pvtSub0Left
If pvtSub0Left + pvtSubRunningWidth > pvtSubMax Then
pvtSub1Control.Width = pvtSub0Left + pvtSubRunningWidth - pvtSubMax
Else
pvtSub1Control.Width = 0
End If
Else
pvtSub0CurrentWidth = pvtSub0CurrentWidth + pvtSubProgressWidth
pvtSub0Control.Width = pvtSub0CurrentWidth
End If
DoEvents
End If
End Sub
Friend Sub SetToRunningMode()
If Not pvtIsInRunningMode Then
pvtIsInRunningMode = True
pvtSub0Control.Width = pvtSubRunningWidth
DoEvents
End If
End Sub
Friend Sub SetToNormalMode()
If pvtIsInRunningMode Then
pvtIsInRunningMode = False
pvtSub0Left = 0
pvtSub0Control.Left = pvtSub0Left
pvtSub0Control.Width = pvtSub0CurrentWidth
pvtSub1CurrentWidth = 0
pvtSub1Control.Width = pvtSub1CurrentWidth
DoEvents
End If
End Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *