-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathThemeHelper.bas
More file actions
306 lines (190 loc) · 9.03 KB
/
ThemeHelper.bas
File metadata and controls
306 lines (190 loc) · 9.03 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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
Attribute VB_Name = "ThemeHelper"
'--------------------------------------------------------------------------------
' Component : ThemeHelper
' Project : ViDock
'
' Description: Parses the theme XML files
'
'--------------------------------------------------------------------------------
Option Explicit
Private m_themeDoc As DOMDocument
Public ListWindowClipped As Collection
Public ListWindowClippedImage As GDIPImage
Public ListWindow As Collection
Public ListWindowImage As GDIPImage
Public ListWindowTextMargin As MARGIN
Public ListWindowTextClippedMargin As MARGIN
Public Buttons As Collection
Public SliceDefinitions As Collection
Public Margins As Collection
Public Colour1 As Colour
Public Colour2 As Colour
Public Seperator As GDIPImage
Public FontSize As Single
Public Font As GDIPFont
Public FontBold As GDIPFont
Function Initialize() As Boolean
'On Error GoTo Handler
Set Buttons = New Collection
Set SliceDefinitions = New Collection
Set Margins = New Collection
Set m_themeDoc = New DOMDocument
If m_themeDoc.Load(App.Path & "\resources\theme.xml") = False Then Exit Function
Set Seperator = New GDIPImage: Seperator.FromFile App.Path & "\resources\separator.png"
ProcessXMLElements m_themeDoc.firstChild
GenerateFonts
Set ListWindowClippedImage = New GDIPImage
Set ListWindowImage = New GDIPImage
Set ListWindowClipped = SliceHelper.CreateSlicesFromXML("list_window_clipped", ListWindowClippedImage)
Set ListWindow = SliceHelper.CreateSlicesFromXML("list_window", ListWindowImage)
Set ListWindowTextMargin = ThemeHelper.GetMargin("list_window_text")
Set ListWindowTextClippedMargin = ThemeHelper.GetMargin("list_window_text_clipped")
Initialize = True
Exit Function
Handler:
LogError 0, "Initialize", "ThemeHelper", Err.Description
End Function
Public Function GetMargin(ByVal marginId As String) As MARGIN
If Not ExistInCol(Margins, marginId) Then Exit Function
Set GetMargin = Margins(marginId)
End Function
Public Function GetButton(ByVal buttonId As String) As IXMLDOMElement
If Not ExistInCol(Buttons, buttonId) Then Exit Function
Set GetButton = Buttons(buttonId)
End Function
Public Function GetSliceDefinition(ByVal sliceId As String) As IXMLDOMElement
If Not ExistInCol(SliceDefinitions, sliceId) Then Exit Function
Set GetSliceDefinition = SliceDefinitions(sliceId)
End Function
Private Sub ProcessFontXMLElement(ByRef xmlRoot As IXMLDOMElement)
Dim fontFace As String
If Not xmlRoot.tagName = "font" Then Exit Sub
If Not IsNull(xmlRoot.getAttribute("size")) Then
FontSize = xmlRoot.getAttribute("size")
Else
FontSize = 15
End If
If Font Is Nothing Then
If Not IsNull(xmlRoot.getAttribute("face")) Then
fontFace = xmlRoot.getAttribute("face")
End If
If Not IsNull(xmlRoot.getAttribute("colour1")) Then
Set Colour1 = New Colour
Colour1.SetColourByHex xmlRoot.getAttribute("colour1")
End If
If Not IsNull(xmlRoot.getAttribute("colour2")) Then
Set Colour2 = New Colour
Colour2.SetColourByHex xmlRoot.getAttribute("colour2")
End If
Dim thisFamily As GDIPFontFamily
Set thisFamily = CreateFontFamily(fontFace)
Set Font = New GDIPFont
Font.Constructor thisFamily, FontSize, FontStyleRegular
Set FontBold = New GDIPFont
FontBold.Constructor thisFamily, FontSize, FontStyleBold
End If
End Sub
Private Sub ProcessMarginXMLElements(ByRef xmlRoot As IXMLDOMElement)
Dim thisMargin As MARGIN
Dim thisMarginId As String
Dim thisChild As IXMLDOMElement
For Each thisChild In xmlRoot.childNodes
If LCase(thisChild.tagName) = "margin" Then
If Not IsNull(thisChild.getAttribute("id")) Then
thisMarginId = thisChild.getAttribute("id")
End If
If Not thisMarginId = vbNullString Then
Set thisMargin = New MARGIN
Margins.Add thisMargin, thisMarginId
With thisMargin
If Not IsNull(thisChild.getAttribute("height")) Then .Height = thisChild.getAttribute("height")
If Not IsNull(thisChild.getAttribute("width")) Then .Width = thisChild.getAttribute("width")
If Not IsNull(thisChild.getAttribute("x-overflow")) Then .X_Overflow = thisChild.getAttribute("x-overflow")
If Not IsNull(thisChild.getAttribute("y-overflow")) Then .Y_Overflow = thisChild.getAttribute("y-overflow")
If Not IsNull(thisChild.getAttribute("x")) Then .X = thisChild.getAttribute("x")
If Not IsNull(thisChild.getAttribute("y")) Then .Y = thisChild.getAttribute("y")
End With
End If
End If
Next
End Sub
Private Sub GenerateFonts()
Dim fontFamilies() As GDIPFontFamily
Dim numberReturned As Long
Dim privateFontCollection As GDIPPrivateFC
Dim privateFontFamily As GDIPFontFamily
'Get Regular Font
Set privateFontCollection = New GDIPPrivateFC
Set privateFontFamily = New GDIPFontFamily
privateFontCollection.AddFontFile (App.Path & "\resources\font.ttf")
privateFontCollection.FontCollection.GetFamilies 1, fontFamilies, numberReturned
If numberReturned > 0 Then
Set privateFontFamily = fontFamilies(0)
Set Font = New GDIPFont
Font.Constructor privateFontFamily, FontSize, FontStyleRegular
Set FontBold = New GDIPFont
FontBold.Constructor privateFontFamily, FontSize, FontStyleBold
End If
'Get Bold Font
Set privateFontCollection = New GDIPPrivateFC
Set privateFontFamily = New GDIPFontFamily
privateFontCollection.AddFontFile (App.Path & "\resources\font-bold.ttf")
privateFontCollection.FontCollection.GetFamilies 1, fontFamilies, numberReturned
If numberReturned > 0 Then
Set privateFontFamily = fontFamilies(0)
Set FontBold = New GDIPFont
FontBold.Constructor privateFontFamily, FontSize, FontStyleRegular
End If
'SetStatusHelper m_privateFontCollection.AddFontFile(App.Path & "\resources\font-bold.ttf")
'If Not IsNull(xmlRoot.getAttribute("face")) Then
' DefaultFace = xmlRoot.getAttribute("face")
'End If
'If Not IsNull(xmlRoot.getAttribute("colour1")) Then
' Set Colour1 = New Colour
' Colour1.SetColourByHex xmlRoot.getAttribute("colour1")
'End If
'If Not IsNull(xmlRoot.getAttribute("colour2")) Then
' Set Colour2 = New Colour
' Colour2.SetColourByHex xmlRoot.getAttribute("colour2")
'End If
'If Not IsNull(xmlRoot.getAttribute("size")) Then
' FontSize = xmlRoot.getAttribute("size")
'Else
' FontSize = 17
'End If
End Sub
Private Sub ProcessXMLElements(ByRef xmlRoot As IXMLDOMElement)
Dim thisIncludedDoc As DOMDocument
Dim thisChild As IXMLDOMElement
Dim thisElementID As String
If Not IsNull(xmlRoot.getAttribute("id")) Then
thisElementID = xmlRoot.getAttribute("id")
End If
Debug.Print "Processing:: " & thisElementID
Select Case LCase(xmlRoot.tagName)
Case "button"
If Not thisElementID = vbNullString Then Buttons.Add xmlRoot, thisElementID
Case "slice_index"
Debug.Print "Adding slice_index: " & thisElementID
If Not thisElementID = vbNullString Then SliceDefinitions.Add xmlRoot, thisElementID
Case "margins"
ProcessMarginXMLElements xmlRoot
End Select
If LCase(xmlRoot.tagName) = "theme" Then
For Each thisChild In xmlRoot.childNodes
Select Case thisChild.tagName
Case "xi:include"
Set thisIncludedDoc = New DOMDocument
If thisIncludedDoc.Load(App.Path & "\resources\" & thisChild.getAttribute("href")) Then
'For Each selectedChild In thisIncludedDoc.childNodes
ProcessXMLElements thisIncludedDoc.firstChild
'Next
Else
LogError 0, "ProcessXMLElements", "ThemeHelper", "Failure processing:: " & thisChild.getAttribute("href")
End If
Case "font"
ProcessFontXMLElement thisChild
End Select
Next
End If
End Sub