Bump version to 4.1-6
[LibreOffice.git] / wizards / source / euro / ConvertRun.xba
blob61c50fc39bf0e6a2e823740905488067480126a2
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <!--
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 -->
20 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="ConvertRun" script:language="StarBasic">Option Explicit
22 Public oPreSelRange as Object
24 Sub Main()
25 BasicLibraries.LoadLibrary(&quot;Tools&quot;)
26 If InitResources(&quot;Euro Converter&quot;, &quot;eur&quot;) Then
27 bDoUnProtect = False
28 bPreSelected = True
29 oDocument = ThisComponent
30 RetrieveDocumentObjects() &apos; Statusline, SheetsCollection etc.
31 InitializeConverter(oDocument.CharLocale, 1)
32 GetPreSelectedRange()
33 If GoOn Then
34 DialogModel.lstCurrencies.TabIndex = 2
35 DialogConvert.GetControl(&quot;chkComplete&quot;).SetFocus()
36 DialogConvert.Execute
37 End If
38 DialogConvert.Dispose
39 End If
40 End Sub
43 Sub SelectListItem()
44 Dim Listbox as Object
45 Dim oListSheet as Object
46 Dim CurStyleName as String
47 Dim oCursheet as Object
48 Dim oTempRanges as Object
49 Dim sCurSheetName as String
50 Dim RangeName as String
51 Dim oSheetRanges as Object
52 Dim ListIndex as Integer
53 Dim a as Integer
54 Dim i as Integer
55 Dim n as Integer
56 Dim m as Integer
57 Dim MaxIndex as Integer
58 Listbox = DialogModel.lstSelection
59 If Ubound(Listbox.SelectedItems()) &gt; -1 Then
60 EnableStep1DialogControls(False, False, False)
61 oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
63 &apos; Is the sheet the basis, then the sheetobject has to be created
64 If DialogModel.optDocRanges.State = 1 Then
65 &apos; Document is the basis for the conversion
66 ListIndex = Listbox.SelectedItems(0)
67 oCurSheet = RetrieveSheetoutofRangeName(Listbox.StringItemList(ListIndex))
68 oDocument.CurrentController.SetActiveSheet(oCurSheet)
69 Else
70 oCurSheet = oDocument.CurrentController.ActiveSheet
71 End If
72 sCurSheetName = oCurSheet.Name
73 If DialogModel.optCellTemplates.State = 1 Then
74 Dim CurIndex as Integer
75 For i = 0 To Ubound(Listbox.SelectedItems())
76 CurIndex = Listbox.SelectedItems(i)
77 CurStylename = Listbox.StringItemList(CurIndex)
78 oSheetRanges = oCursheet.CellFormatRanges.createEnumeration
79 While oSheetRanges.hasMoreElements
80 oRange = oSheetRanges.NextElement
81 If oRange.getPropertyState(&quot;NumberFormat&quot;) = 1 Then
82 If oRange.CellStyle = CurStyleName Then
83 oSelRanges.InsertbyName(&quot;&quot;,oRange)
84 End If
85 End If
86 Wend
87 Next i
88 Else
89 &apos; Hard Formatation is selected
90 a = -1
91 For n = 0 To Ubound(Listbox.SelectedItems())
92 m = Listbox.SelectedItems(n)
93 RangeName = Listbox.StringItemList(m)
94 oListSheet = RetrieveSheetoutofRangeName(RangeName)
95 a = a + 1
96 MaxIndex = Ubound(SelRangeList())
97 If a &gt; MaxIndex Then
98 Redim Preserve SelRangeList(MaxIndex + SBRANGEUBOUND)
99 End If
100 SelRangeList(a) = RangeName
101 If oListSheet.Name = sCurSheetName Then
102 oRange = RetrieveRangeoutofRangeName(RangeName)
103 oSelRanges.InsertbyName(&quot;&quot;,oRange)
104 End If
105 Next n
106 End If
107 If a &gt; -1 Then
108 ReDim Preserve SelRangeList(a)
109 Else
110 ReDim SelRangeList()
111 End If
112 oDocument.CurrentController.Select(oSelRanges)
113 EnableStep1DialogControls(True, True, True)
114 End If
115 End Sub
118 &apos; Procedure that is called by an event
119 Sub RetrieveEnableValue()
120 Dim EnableValue as Boolean
121 EnableValue = Not DialogModel.lstSelection.Enabled
122 EnableStep1DialogControls(True, EnableValue, True)
123 End Sub
126 Sub EnableStep1DialogControls(bCurrEnabled as Boolean, bFrameEnabled as Boolean, bButtonsEnabled as Boolean)
127 Dim bCurrIsSelected as Boolean
128 Dim bObjectIsSelected as Boolean
129 Dim bConvertWholeDoc as Boolean
130 Dim bDoEnableFrame as Boolean
131 bConvertWholeDoc = DialogModel.chkComplete.State = 1
132 bDoEnableFrame = bFrameEnabled And (NOT bConvertWholeDoc)
134 &apos; Controls around the Selection Listbox
135 With DialogModel
136 .lblCurrencies.Enabled = bCurrEnabled
137 .lstCurrencies.Enabled = bCurrEnabled
138 .lstSelection.Enabled = bDoEnableFrame
139 .lblSelection.Enabled = bDoEnableFrame
140 .hlnSelection.Enabled = bDoEnableFrame
141 .optCellTemplates.Enabled = bDoEnableFrame
142 .optSheetRanges.Enabled = bDoEnableFrame
143 .optDocRanges.Enabled = bDoEnableFrame
144 .optSelRange.Enabled = bDoEnableFrame
145 End With
146 &apos; The CheckBox has the Value &apos;1&apos; when the Controls in the Frame are disabled
147 If bButtonsEnabled Then
148 bCurrIsSelected = Ubound(DialogModel.lstCurrencies.SelectedItems()) &lt;&gt; -1
149 &apos; Enable GoOnButton only when Currency is selected
150 DialogModel.cmdGoOn.Enabled = bCurrIsSelected
151 DialogModel.chkComplete.Enabled = bCurrIsSelected
152 If bDoEnableFrame AND DialogModel.cmdGoOn.Enabled Then
153 &apos; If FrameControls are enabled, check if Listbox is Empty
154 bObjectIsSelected = Ubound(DialogModel.lstSelection.SelectedItems()) &lt;&gt; -1
155 DialogModel.cmdGoOn.Enabled = bObjectIsSelected
156 End If
157 Else
158 DialogModel.cmdGoOn.Enabled = False
159 DialogModel.chkComplete.Enabled = False
160 End If
161 End Sub
164 Sub ConvertRangesOrStylesOfDocument()
165 Dim i as Integer
166 Dim ItemName as String
167 Dim SelList() as String
168 Dim oSheetRanges as Object
170 bDocHasProtectedSheets = CheckSheetProtection(oSheets)
171 If bDocHasProtectedSheets Then
172 bDocHasProtectedSheets = UnprotectSheetsWithPassWord(oSheets, bDoUnProtect)
173 DialogModel.cmdGoOn.Enabled = False
174 End If
175 If Not bDocHasProtectedSheets Then
176 EnableStep1DialogControls(False, False, False)
177 InitializeProgressBar()
178 If DialogModel.optSelRange.State = 1 Then
179 SelectListItem()
180 End If
181 SelList() = DialogConvert.GetControl(&quot;lstSelection&quot;).SelectedItems()
182 If DialogModel.optCellTemplates.State = 1 Then
183 &apos; Option &apos;Soft&apos; Formatation is selected
184 AssignRangestoStyle(DialogModel.lstSelection.StringItemList(), SelList())
185 ConverttheSoftWay(SelList(), True)
186 ElseIf DialogModel.optSelRange.State = 1 Then
187 oSheetRanges = oPreSelRange.CellFormatRanges.createEnumeration
188 While oSheetRanges.hasMoreElements
189 oRange = oSheetRanges.NextElement
190 If CheckFormatType(oRange) Then
191 ConvertCellCurrencies(oRange)
192 SwitchNumberFormat(oRange, oFormats, sEuroSign)
193 End If
194 Wend
195 Else
196 ConverttheHardWay(SelList(), False, True)
197 End If
198 oStatusline.End
199 EnableStep1DialogControls(True, False, True)
200 DialogModel.cmdGoOn.Enabled = True
201 oDocument.CurrentController.Select(oSelRanges)
202 End If
203 End Sub
206 Sub ConvertWholeDocument()
207 Dim s as Integer
208 DialogModel.cmdGoOn.Enabled = False
209 DialogModel.chkComplete.Enabled = False
210 GoOn = ConvertDocument()
211 EmptyListbox(DialogModel.lstSelection())
212 EnableStep1DialogControls(True, True, True)
213 End Sub
216 &apos; Everything previously selected will be deselected
217 Sub EmptySelection()
218 Dim RangeName as String
219 Dim i as Integer
220 Dim MaxIndex as Integer
221 Dim EmptySelRangeList() as String
223 If Not IsNull(oSelRanges) Then
224 If oSelRanges.HasElements Then
225 EmptySelRangeList() = ArrayOutofString(oSelRanges.RangeAddressesasString, &quot;;&quot;, MaxIndex)
226 For i = 0 To MaxIndex
227 oSelRanges.RemovebyName(EmptySelRangeList(i))
228 Next i
229 End If
230 oDocument.CurrentController.Select(oSelRanges)
231 Else
232 oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
233 End If
234 End Sub
237 Function AddSelectedRangeToSelRangesEnum() as Object
238 Dim oLocRange as Object
239 osheet = oDocument.CurrentController.GetActiveSheet
240 oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
241 &apos; Check if a Currency-Range has been selected
242 oLocRange = oDocument.CurrentController.Selection
243 bPreSelected = oLocRange.SupportsService(&quot;com.sun.star.sheet.SheetCellRange&quot;)
244 If bPreSelected Then
245 oSelRanges.InsertbyName(&quot;&quot;,oLocRange)
246 AddSelectedRangeToSelRangesEnum() = oLocRange
247 End If
248 End Function
251 Sub GetPreSelectedRange()
252 Dim i as Integer
253 Dim OldCurrSymbolList(2) as String
254 Dim OldCurrIndex as Integer
255 Dim OldCurExtension(2) as String
256 oPreSelRange = AddSelectedRangeToSelRangesEnum()
258 DialogModel.chkComplete.State = Abs(Not(bPreSelected))
259 If bPreSelected Then
260 DialogModel.optSelRange.State = 1
261 AddRangeToListbox(oPreSelRange)
262 Else
263 DialogModel.optCellTemplates.State = 1
264 CreateStyleEnumeration()
265 End If
266 EnableStep1DialogControls(True, bPreSelected, True)
267 DialogModel.optSelRange.Enabled = bPreSelected
268 End Sub
271 Sub AddRangeToListbox(oLocRange as Object)
272 EmptyListBox(DialogModel.lstSelection)
273 PreName = RetrieveRangeNamefromAddress(oLocRange)
274 AddSingleItemToListbox(DialogModel.lstSelection, Prename)&apos;, 0)
275 SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
276 TotCellCount = CountRangeCells(oLocRange)
277 End Sub
280 Sub CheckRangeSelection(Optional oEvent)
281 EmptySelection()
282 AddRangeToListbox(oPreSelRange)
283 oPreSelRange = AddSelectedRangeToSelRangesEnum()
284 End Sub
287 &apos; Checks if a Field (LocField) is already defined in an Array
288 &apos; Returns &apos;True&apos; or &apos;False&apos;
289 Function FieldinList(LocList(), MaxIndex as integer, ByVal LocField ) As Boolean
290 Dim i as integer
291 LocField = Ucase(LocField)
292 For i = Lbound(LocList()) to MaxIndex
293 If Ucase(LocList(i)) = LocField then
294 FieldInList = True
295 Exit Function
296 End if
297 Next
298 FieldInList = False
299 End Function
302 Function CheckLocale(oLocale) as Boolean
303 Dim i as Integer
304 Dim LocCountry as String
305 Dim LocLanguage as String
306 LocCountry = oLocale.Country
307 LocLanguage = oLocale.Language
308 For i = 0 To 1
309 If LocLanguage = LangIDValue(CurrIndex,i,0) AND LocCountry = LangIDValue(CurrIndex,i,1) Then
310 CheckLocale = True
311 Exit Function
312 End If
313 Next i
314 CheckLocale = False
315 End Function
318 Sub SetOptionValuestoNull()
319 With DialogModel
320 .optCellTemplates.State = 0
321 .optSheetRanges.State = 0
322 .optDocRanges.State = 0
323 .optSelRange.State = 0
324 End With
325 End Sub
329 Sub SetStatusLineText(sStsREPROTECT as String)
330 If Not IsNull(oStatusLine) Then
331 oStatusline.SetText(sStsREPROTECT)
332 End If
333 End Sub
334 </script:module>