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
306
307
308
309
310
311
312
313
314
315
316
317
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ConvertRun" script:language="StarBasic">Option Explicit
Public oPreSelRange as Object
Sub Main()
BasicLibraries.LoadLibrary("Tools")
If InitResources("Euro Converter", "eur") Then
bDoUnProtect = False
bPreSelected = True
oDocument = ThisComponent
RetrieveDocumentObjects() ' Statusline, SheetsCollection etc.
InitializeConverter(oDocument.CharLocale, 1)
GetPreSelectedRange()
If GoOn Then
DialogModel.lstCurrencies.TabIndex = 2
DialogConvert.GetControl("chkComplete").SetFocus()
DialogConvert.Execute
End If
DialogConvert.Dispose
End If
End Sub
Sub SelectListItem()
Dim Listbox as Object
Dim oListSheet as Object
Dim CurStyleName as String
Dim oCursheet as Object
Dim oTempRanges as Object
Dim sCurSheetName as String
Dim RangeName as String
Dim oSheetRanges as Object
Dim ListIndex as Integer
Dim a as Integer
Dim i as Integer
Dim n as Integer
Dim m as Integer
Dim MaxIndex as Integer
Listbox = DialogModel.lstSelection
If Ubound(Listbox.SelectedItems()) > -1 Then
EnableStep1DialogControls(False, False, False)
oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
' Is the sheet the basis, then the sheetobject has to be created
If DialogModel.optDocRanges.State = 1 Then
' Document is the basis for the conversion
ListIndex = Listbox.SelectedItems(0)
oCurSheet = RetrieveSheetoutofRangeName(Listbox.StringItemList(ListIndex))
oDocument.CurrentController.SetActiveSheet(oCurSheet)
Else
oCurSheet = oDocument.CurrentController.ActiveSheet
End If
sCurSheetName = oCurSheet.Name
If DialogModel.optCellTemplates.State = 1 Then
Dim CurIndex as Integer
For i = 0 To Ubound(Listbox.SelectedItems())
CurIndex = Listbox.SelectedItems(i)
CurStylename = Listbox.StringItemList(CurIndex)
oSheetRanges = oCursheet.CellFormatRanges.createEnumeration
While oSheetRanges.hasMoreElements
oRange = oSheetRanges.NextElement
If oRange.getPropertyState("NumberFormat") = 1 Then
If oRange.CellStyle = CurStyleName Then
oSelRanges.InsertbyName("",oRange)
End If
End If
Wend
Next i
Else
' Hard Formatation is selected
a = -1
For n = 0 To Ubound(Listbox.SelectedItems())
m = Listbox.SelectedItems(n)
RangeName = Listbox.StringItemList(m)
oListSheet = RetrieveSheetoutofRangeName(RangeName)
a = a + 1
MaxIndex = Ubound(SelRangeList())
If a > MaxIndex Then
Redim Preserve SelRangeList(MaxIndex + SBRANGEUBOUND)
End If
SelRangeList(a) = RangeName
If oListSheet.Name = sCurSheetName Then
oRange = RetrieveRangeoutofRangeName(RangeName)
oSelRanges.InsertbyName("",oRange)
End If
Next n
End If
If a > -1 Then
ReDim Preserve SelRangeList(a)
Else
ReDim SelRangeList()
End If
oDocument.CurrentController.Select(oSelRanges)
EnableStep1DialogControls(True, True, True)
End If
End Sub
' Procedure that is called by an event
Sub RetrieveEnableValue()
Dim EnableValue as Boolean
EnableValue = Not DialogModel.lstSelection.Enabled
EnableStep1DialogControls(True, EnableValue, True)
End Sub
Sub EnableStep1DialogControls(bCurrEnabled as Boolean, bFrameEnabled as Boolean, bButtonsEnabled as Boolean)
Dim bCurrIsSelected as Boolean
Dim bObjectIsSelected as Boolean
Dim bConvertWholeDoc as Boolean
Dim bDoEnableFrame as Boolean
bConvertWholeDoc = DialogModel.chkComplete.State = 1
bDoEnableFrame = bFrameEnabled And (NOT bConvertWholeDoc)
' Controls around the Selection Listbox
With DialogModel
.lblCurrencies.Enabled = bCurrEnabled
.lstCurrencies.Enabled = bCurrEnabled
.lstSelection.Enabled = bDoEnableFrame
.lblSelection.Enabled = bDoEnableFrame
.hlnSelection.Enabled = bDoEnableFrame
.optCellTemplates.Enabled = bDoEnableFrame
.optSheetRanges.Enabled = bDoEnableFrame
.optDocRanges.Enabled = bDoEnableFrame
.optSelRange.Enabled = bDoEnableFrame
End With
' The CheckBox has the Value '1' when the Controls in the Frame are disabled
If bButtonsEnabled Then
bCurrIsSelected = Ubound(DialogModel.lstCurrencies.SelectedItems()) <> -1
' Enable GoOnButton only when Currency is selected
DialogModel.cmdGoOn.Enabled = bCurrIsSelected
DialogModel.chkComplete.Enabled = bCurrIsSelected
If bDoEnableFrame AND DialogModel.cmdGoOn.Enabled Then
' If FrameControls are enabled, check if Listbox is Empty
bObjectIsSelected = Ubound(DialogModel.lstSelection.SelectedItems()) <> -1
DialogModel.cmdGoOn.Enabled = bObjectIsSelected
End If
Else
DialogModel.cmdGoOn.Enabled = False
DialogModel.chkComplete.Enabled = False
End If
End Sub
Sub ConvertRangesOrStylesOfDocument()
Dim i as Integer
Dim ItemName as String
Dim SelList() as String
Dim oSheetRanges as Object
bDocHasProtectedSheets = CheckSheetProtection(oSheets)
If bDocHasProtectedSheets Then
bDocHasProtectedSheets = UnprotectSheetsWithPassWord(oSheets, bDoUnProtect)
DialogModel.cmdGoOn.Enabled = False
End If
If Not bDocHasProtectedSheets Then
EnableStep1DialogControls(False, False, False)
InitializeProgressBar()
If DialogModel.optSelRange.State = 1 Then
SelectListItem()
End If
SelList() = DialogConvert.GetControl("lstSelection").SelectedItems()
If DialogModel.optCellTemplates.State = 1 Then
' Option 'Soft' Formatation is selected
AssignRangestoStyle(DialogModel.lstSelection.StringItemList(), SelList())
ConverttheSoftWay(SelList(), True)
ElseIf DialogModel.optSelRange.State = 1 Then
oSheetRanges = oPreSelRange.CellFormatRanges.createEnumeration
While oSheetRanges.hasMoreElements
oRange = oSheetRanges.NextElement
If CheckFormatType(oRange) Then
ConvertCellCurrencies(oRange)
SwitchNumberFormat(oRange, oFormats, sEuroSign)
End If
Wend
Else
ConverttheHardWay(SelList(), False, True)
End If
oStatusline.End
EnableStep1DialogControls(True, False, True)
DialogModel.cmdGoOn.Enabled = True
oDocument.CurrentController.Select(oSelRanges)
End If
End Sub
Sub ConvertWholeDocument()
Dim s as Integer
DialogModel.cmdGoOn.Enabled = False
DialogModel.chkComplete.Enabled = False
GoOn = ConvertDocument()
EmptyListbox(DialogModel.lstSelection())
EnableStep1DialogControls(True, True, True)
End Sub
' Everything previously selected will be deselected
Sub EmptySelection()
Dim RangeName as String
Dim i as Integer
Dim MaxIndex as Integer
Dim EmptySelRangeList() as String
If Not IsNull(oSelRanges) Then
If oSelRanges.HasElements Then
EmptySelRangeList() = ArrayOutofString(oSelRanges.RangeAddressesasString, ";", MaxIndex)
For i = 0 To MaxIndex
oSelRanges.RemovebyName(EmptySelRangeList(i))
Next i
End If
oDocument.CurrentController.Select(oSelRanges)
Else
oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
End If
End Sub
Function AddSelectedRangeToSelRangesEnum() as Object
Dim oLocRange as Object
osheet = oDocument.CurrentController.GetActiveSheet
oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
' Check if a Currency-Range has been selected
oLocRange = oDocument.CurrentController.Selection
bPreSelected = oLocRange.SupportsService("com.sun.star.sheet.SheetCellRange")
If bPreSelected Then
oSelRanges.InsertbyName("",oLocRange)
AddSelectedRangeToSelRangesEnum() = oLocRange
End If
End Function
Sub GetPreSelectedRange()
Dim i as Integer
Dim OldCurrSymbolList(2) as String
Dim OldCurrIndex as Integer
Dim OldCurExtension(2) as String
oPreSelRange = AddSelectedRangeToSelRangesEnum()
DialogModel.chkComplete.State = Abs(Not(bPreSelected))
If bPreSelected Then
DialogModel.optSelRange.State = 1
AddRangeToListbox(oPreSelRange)
Else
DialogModel.optCellTemplates.State = 1
CreateStyleEnumeration()
End If
EnableStep1DialogControls(True, bPreSelected, True)
DialogModel.optSelRange.Enabled = bPreSelected
End Sub
Sub AddRangeToListbox(oLocRange as Object)
EmptyListBox(DialogModel.lstSelection)
PreName = RetrieveRangeNamefromAddress(oLocRange)
AddSingleItemToListbox(DialogModel.lstSelection, Prename)', 0)
SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
TotCellCount = CountRangeCells(oLocRange)
End Sub
Sub CheckRangeSelection(Optional oEvent)
EmptySelection()
AddRangeToListbox(oPreSelRange)
oPreSelRange = AddSelectedRangeToSelRangesEnum()
End Sub
' Checks if a Field (LocField) is already defined in an Array
' Returns 'True' or 'False'
Function FieldinList(LocList(), MaxIndex as integer, ByVal LocField ) As Boolean
Dim i as integer
LocField = Ucase(LocField)
For i = Lbound(LocList()) to MaxIndex
If Ucase(LocList(i)) = LocField then
FieldInList = True
Exit Function
End if
Next
FieldInList = False
End Function
Function CheckLocale(oLocale) as Boolean
Dim i as Integer
Dim LocCountry as String
Dim LocLanguage as String
LocCountry = oLocale.Country
LocLanguage = oLocale.Language
For i = 0 To 1
If LocLanguage = LangIDValue(CurrIndex,i,0) AND LocCountry = LangIDValue(CurrIndex,i,1) Then
CheckLocale = True
Exit Function
End If
Next i
CheckLocale = False
End Function
Sub SetOptionValuestoNull()
With DialogModel
.optCellTemplates.State = 0
.optSheetRanges.State = 0
.optDocRanges.State = 0
.optSelRange.State = 0
End With
End Sub
Sub SetStatusLineText(sStsREPROTECT as String)
If Not IsNull(oStatusLine) Then
oStatusline.SetText(sStsREPROTECT)
End If
End Sub
</script:module>
|