-
Notifications
You must be signed in to change notification settings - Fork 138
/
clsScrollbar.cls
265 lines (228 loc) · 9.12 KB
/
clsScrollbar.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsScrollbar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
'滚动条类,用于设置和保持相应的属性和值,并生成对应PYTHON的TKinter代码
Private m_dicTotal As Dictionary '保存全部的属性,包括默认值
Private m_Base As clsBaseControl '基础控件类
Private m_CanbeOutByMainForm As Boolean
'输出PYTHON代码,
'sOut: 输出参数,界面代码
'sCmd: 输出参数,事件处理回调代码
'sI18n: 输出参数,控件文本翻译代码
'rel:是否使用相对坐标,
'usettk:是否使用TTK主题扩展
Public Sub toString(ByRef sOut As cStrBuilder, ByRef sCmd As cStrBuilder, ByRef sI18n As cStrBuilder, ByVal rel As Boolean, ByVal usettk As Boolean)
Dim cmdTxt As String
'滚动条的命令绑定额外处理
cmdTxt = m_Base("command")
If Len(cmdTxt) Then
sCmd.Append m_Base.CreateFuncDefOOP(cmdTxt, "method, dir, jump=None")
End If
m_Base("command") = ""
m_Base.toString sOut, sCmd, sI18n, rel, usettk
m_Base("command") = cmdTxt
End Sub
'创建对象后要马上调用这个函数初始化各参数
Public Sub InitConfig(o As Object, parentWidth As Long, parentHeight As Long, dMethods As Dictionary)
Dim s As String, sa() As String, I As Long, idx As Long
m_Base.SetVbWidgetInstance o
m_Base.Name = o.Properties("Name")
m_Base.StyleName = IIf(o.ClassName = "HScrollBar", "Horizontal", "Vertical") & ".TScrollbar"
m_dicTotal("x") = m_Base.toPixelX(o.Properties("Left"))
m_dicTotal("y") = m_Base.toPixelY(o.Properties("Top"))
m_dicTotal("width") = m_Base.toPixelX(o.Properties("Width"))
m_dicTotal("height") = m_Base.toPixelY(o.Properties("Height"))
m_dicTotal("relx") = Format(o.Properties("Left") / parentWidth, "0.###")
m_dicTotal("rely") = Format(o.Properties("Top") / parentHeight, "0.###")
m_dicTotal("relwidth") = Format(o.Properties("Width") / parentWidth, "0.###")
m_dicTotal("relheight") = Format(o.Properties("Height") / parentHeight, "0.###")
m_dicTotal("orient") = IIf(o.ClassName = "HScrollBar", "'horizontal'", "'vertical'")
m_dicTotal("bg") = ""
m_dicTotal("bd") = ""
m_dicTotal("jump") = 0
m_dicTotal("relief") = "SUNKEN"
m_dicTotal("activerelief") = "SUNKEN"
m_dicTotal("takefocus") = IIf(o.Properties("TabStop"), 1, 0)
m_dicTotal("cursor") = m_Base.GetCursorName(o.Properties("MousePointer"))
m_dicTotal("command") = "" 'o.Properties("Name") & "_Cmd"
m_dicTotal("bindcommand") = m_Base.GetBindCommandStr(dMethods)
'这些是默认选择的
m_Base("x") = m_dicTotal("x")
m_Base("y") = m_dicTotal("y")
m_Base("width") = m_dicTotal("width")
m_Base("height") = m_dicTotal("height")
m_Base("relx") = m_dicTotal("relx")
m_Base("rely") = m_dicTotal("rely")
m_Base("relwidth") = m_dicTotal("relwidth")
m_Base("relheight") = m_dicTotal("relheight")
'm_Base("command") = m_dicTotal("command")
m_Base("orient") = m_dicTotal("orient")
If m_dicTotal("takefocus") = 0 Then m_Base("takefocus") = m_dicTotal("takefocus")
If m_dicTotal("cursor") <> "" Then m_Base("cursor") = m_dicTotal("cursor")
If m_dicTotal("bindcommand") <> "" Then m_Base("bindcommand") = m_dicTotal("bindcommand")
'使用控件的tag属性保存一些额外默认要保存的属性,
'开始字符为:p@,后接属性名,每个属性使用@隔开,属性值可选,如果有值,则使用k=v格式
s = Trim(o.Properties("Tag"))
If Len(s) Then
sa = Split(s, "@")
If sa(0) = "p" Or sa(0) = "P" Then
For I = 1 To UBound(sa)
s = sa(I)
idx = InStr(2, s, "=")
If idx > 0 Then '有值
m_dicTotal(Left$(s, idx - 1)) = Mid$(s, idx + 1)
m_Base(Left$(s, idx - 1)) = m_dicTotal(Left$(s, idx - 1))
ElseIf Len(s) > 0 And Len(m_dicTotal(s)) > 0 Then '仅有属性,则判断属性是否合法
m_Base(s) = m_dicTotal(s)
End If
Next
End If
End If
End Sub
'设置属性值的可能值列表
'返回值:0-没有可选值,1-有一个严格限制的可选值列表,2-除提供的可选值列表外,还可以手动输入其他值
'输出:sa()可选值列表数组
Public Function GetAttrValueList(sAttr As String, ByRef sa() As String) As Long
GetAttrValueList = 1
If sAttr = "jump" Then
sa = Split("1,0", ",")
ElseIf sAttr = "activerelief" Then
sa = Split("FLAT,GROOVE,RAISED,RIDGE,SOLID,SUNKEN", ",")
Else
GetAttrValueList = m_Base.GetAttrValueList(sAttr, sa)
End If
End Function
'判断此控件是否存在对应的属性
Public Function hasAttribute(sAttr As String) As Boolean
hasAttribute = m_Base.hasAttribute(sAttr)
End Function
'获取此控件对应的当前设定的属性值,没有则返回空串
Public Function GetAttrCurrentValue(sAttr As String) As String
GetAttrCurrentValue = m_Base.GetAttrCurrentValue(sAttr)
End Function
Public Function Tips(sAttr As String) As String
Tips = sAttr & vbCrLf
Select Case sAttr:
Case "jump"
Tips = Tips & L("l_TipJump", "Set to 1, the callback isn't called until the user releases the mouse button.")
Case "activerelief"
Tips = Tips & L("l_TipActiveRelief", "To display the slider with a different relief style when the mouse is over the slider.")
Case Else:
Tips = m_Base.Tips(sAttr)
End Select
End Function
Private Sub Class_Initialize()
Set m_dicTotal = New Dictionary
Set m_Base = New clsBaseControl
m_Base.ctlType = "Scrollbar"
m_Base.StyleName = "TScrollbar"
m_CanbeOutByMainForm = True
End Sub
'返回一个集合,每个项目三元对"属性名|值|是否默认选择"
'这个函数用于主界面填充属性参数列表框
Public Function Allitems() As Collection
Dim re As Collection, k As Variant, ks As Collection
Set re = New Collection
'标准参数
Set ks = m_dicTotal.Keys
For Each k In ks
If Len(m_Base(k)) Then
re.Add k & "|" & m_Base(k) & "|1"
Else
re.Add k & "|" & m_dicTotal(k) & "|0"
End If
Next
'用户增加的自定义参数(如果有的话)
Set ks = m_Base.Keys
For Each k In ks
If Not m_dicTotal.Exists(k) Then
re.Add k & "|" & m_Base(k) & "|1"
End If
Next
Set Allitems = re
End Function
Public Sub SetConfig(sAttrs As String)
m_Base.SetConfig sAttrs
End Sub
Public Sub SetSingleConfig(sAttr As String)
m_Base.SetSingleConfig sAttr
End Sub
Private Sub Class_Terminate()
Set m_dicTotal = Nothing
Set m_Base = Nothing
End Sub
Public Property Let Parent(s As String)
m_Base.Parent = s
End Property
Public Property Get Parent() As String
Parent = m_Base.Parent
End Property
Public Property Get Name() As String
Name = m_Base.Name
End Property
'用于改变其默认对应的widget类型,修改widget类型后注意属性列表的合法性
Public Function SetWidgetType(sType As String, sStyleName As String)
m_Base.ctlType = sType
m_Base.StyleName = sStyleName
End Function
'确定主处理函数能否调用其toString()来产生代码,默认为True,设置为False说明由其他对象来调用处理
Public Property Get EnableOutByMainForm() As Boolean
EnableOutByMainForm = m_CanbeOutByMainForm
End Property
Public Property Let EnableOutByMainForm(bEnable As Boolean)
m_CanbeOutByMainForm = bEnable
End Property
'对象序列化函数
Public Function Serializer(vSer As clsSerialization)
vSer.Serializer m_Base
End Function
Public Function Deserializer(vSer As clsSerialization)
vSer.Deserializer m_Base
End Function
Public Property Get Description() As String
Description = L("l_DescScrollbar", "Scrollbar widget.")
End Property
Public Property Let ScaleMode(nV As Long)
m_Base.ScaleMode = nV
End Property
'用于模拟比较排序的函数,实际上是判断两个对象的依赖关系
'用本对象和另一个对象比较,逻辑结果为'本对象-另一个对象'
'返回值含义:
'<0:表示本对象需要在另一个对象前输出代码
'=0:表示两者将没有依赖关系,代码前后顺序无影响
'>0:另一个对象要先输出代码。
'整体的逻辑结果类似是重的沉底
Public Function Compare(ByRef Obj As Object) As Long
Dim tObj As String
tObj = TypeName(Obj)
'如果是可滚动控件和滚动条相比较,则交给可滚动对象来比较
If tObj = "clsListbox" Or tObj = "clsText" Or tObj = "clsCanvas" Or tObj = "clsTreeview" Then
Compare = Obj.Compare(Me)
Compare = Switch(Compare > 0, -1, Compare < 0, 1, Compare = 0, 0) '比较结果要反个个
Exit Function
End If
If Parent = Obj.Name Then '父控件先输出代码
Compare = 1
ElseIf Obj.Parent = Name Then
Compare = -1
ElseIf Parent = WTOP And Obj.Parent <> WTOP Then '顶层控件先输出
Compare = -1
ElseIf Parent <> WTOP And Obj.Parent = WTOP Then
Compare = 1
Else
Compare = 0
End If
End Function