-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathZtMessageDisplay.cls
181 lines (141 loc) · 7.5 KB
/
ZtMessageDisplay.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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "ZtMessageDisplay"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Implements ZtIMessageDisplayable
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Class ZtMessageDisplay.
' Shows messages and manages user reactions to these.
'
' Zotero Tools.
' This software is under Revised ('New') BSD license.
' Copyright © 2019, Olaf Ahrens. All rights reserved.
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Private constants.
Private Const PVT_SOUND_CRITICAL As String = "SystemHand"
Private Const PVT_SOUND_EXCLAMATION As String = "SystemExclamation"
Private Const PVT_SOUND_QUESTION As String = "SystemQuestion"
Private Const PVT_SOUND_INFORMATION As String = ".Default"
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Private variables.
Private pvtTextBox As MSForms.TextBox
Private WithEvents pvtProcedeButton As MSForms.CommandButton
Private WithEvents pvtCancelButton As MSForms.CommandButton
Private WithEvents pvtSuppressButton As MSForms.CommandButton
Private pvtResult As ZtFMessageType
Private pvtAppPrepare As ZtIAppPreparable
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Private interface procedures and properties directing to Friend procedures and properties below.
Private Function ZtIMessageDisplayable_Show(ByVal valMessage As String, ByVal valType As ZtFMessageType, Optional ByVal valRePrepare As Boolean = True, _
Optional ByVal valSelectionRange As Word.Range = Nothing) As ZtFMessageType
ZtIMessageDisplayable_Show = Me.Show(valMessage, valType, valRePrepare, valSelectionRange)
End Function
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Friend procedures and properties.
Friend Sub Initialize(ByVal valTextBox As MSForms.TextBox, ByVal valProcedeButton As MSForms.CommandButton, _
Optional ByVal valCancelButton As MSForms.CommandButton = Nothing, Optional ByVal valSuppressButton As MSForms.CommandButton = Nothing, _
Optional ByVal valAppPrepare As ZtIAppPreparable = Nothing)
Set pvtAppPrepare = valAppPrepare
Set pvtTextBox = valTextBox
Set pvtProcedeButton = valProcedeButton
Set pvtCancelButton = valCancelButton
Set pvtSuppressButton = valSuppressButton
End Sub
Friend Function Show(ByVal valMessage As String, ByVal valType As ZtFMessageType, Optional ByVal valRePrepare As Boolean = True, _
Optional ByVal valSelectionRange As Word.Range = Nothing) As ZtFMessageType
Dim locStart As Date
pvtAppPrepare.Unprepare
If Not valSelectionRange Is Nothing Then
valSelectionRange.Select
DoEvents
End If
With pvtTextBox
If (valType And MessageCritical) = MessageCritical Then
ZtApiProcedures.PlaySound PVT_SOUND_CRITICAL, vbNullString, CLng(SndAlias + SndAsync)
.Font.Bold = True
.ForeColor = vbRed
ElseIf (valType And MessageExclamation) = MessageExclamation Then
ZtApiProcedures.PlaySound PVT_SOUND_EXCLAMATION, vbNullString, CLng(SndAlias + SndAsync)
.Font.Bold = False
.ForeColor = vbBlue
ElseIf (valType And MessageQuestion) = MessageQuestion Then
ZtApiProcedures.PlaySound PVT_SOUND_QUESTION, vbNullString, CLng(SndAlias + SndAsync)
.Font.Bold = False
.ForeColor = vbBlack
Else
ZtApiProcedures.PlaySound PVT_SOUND_INFORMATION, vbNullString, CLng(SndAlias + SndAsync)
.Font.Bold = False
.ForeColor = vbBlack
End If
.Text = valMessage
End With
' Enable buttons.
If Not pvtProcedeButton Is Nothing Then
pvtProcedeButton.Enabled = ((valType And MessageOk) = MessageOk) Or ((valType And MessageNo) = MessageNo)
End If
If Not pvtCancelButton Is Nothing Then
pvtCancelButton.Enabled = ((valType And MessageCancel) = MessageCancel)
End If
If Not pvtSuppressButton Is Nothing Then
pvtSuppressButton.Enabled = ((valType And MessageSuppress) = MessageSuppress)
End If
' Wait for user reaction.
pvtResult = MessageNone
locStart = Now
Do While pvtResult = MessageNone
Do
DoEvents
Loop Until Now >= DateAdd("s", 1, locStart)
Loop
' Resume after user reaction.
If valRePrepare And pvtResult <> MessageCancel Then
pvtAppPrepare.Prepare
End If
pvtTextBox.Text = vbNullString
Show = pvtResult
End Function
Friend Sub Clear()
pvtTextBox.Text = vbNullString
pvtEnableProcedureControls False
End Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Event procedures.
Private Sub pvtProcedeButton_Click()
pvtResult = MessageOk
pvtEnableProcedureControls False
End Sub
Private Sub pvtCancelButton_Click()
pvtResult = MessageCancel
pvtEnableProcedureControls False
End Sub
Private Sub pvtSuppressButton_Click()
pvtResult = MessageSuppress
pvtEnableProcedureControls False
End Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Private procedures.
Private Sub pvtEnableProcedureControls(ByVal valEnable As Boolean)
If Not pvtProcedeButton Is Nothing Then
pvtProcedeButton.Enabled = valEnable
End If
If Not pvtCancelButton Is Nothing Then
pvtCancelButton.Enabled = valEnable
End If
If Not pvtSuppressButton Is Nothing Then
pvtSuppressButton.Enabled = valEnable
End If
DoEvents
End Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *