Bump version to 4.1-6
[LibreOffice.git] / wizards / source / euro / Common.xba
blob8de005ba25f6fd71522bcbe596c9329a48a86cb0
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="Common" script:language="StarBasic"> REM ***** BASIC *****
21 Public DialogModel as Object
22 Public DialogConvert as Object
23 Public DialogPassword as Object
24 Public PasswordModel as Object
26 Sub RetrieveDocumentObjects()
27 CurMimeType = Tools.GetDocumentType(oDocument)
28 If Instr(1, CurMimeType, &quot;calc&quot;) &lt;&gt; 0 Then
29 oSheets = oDocument.Sheets
30 oSheet = oDocument.Sheets.GetbyIndex(0)
31 oAddressRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
32 End If
33 &apos; Retrieve the indices for the cellformatations
34 oFormats = oDocument.NumberFormats
35 End Sub
38 Sub CancelTask()
39 &apos; If Not DocDisposed Then
40 &apos; ReprotectSheets()
41 &apos; End If
42 If DialogModel.Step = 3 And (Not bCancelTask) Then
43 If Msgbox(sMsgCancelConversion, 36, sMsgCancelTitle) = 6 Then
44 bCancelTask = True
45 DialogConvert.EndExecute
46 Else
47 bCancelTask = False
48 End If
49 Else
50 DialogConvert.EndExecute()
51 End If
52 End Sub
55 Function ConvertDocument()
56 GoOn = True
57 &apos; DocDisposed = True
58 InitializeProgressbar()
59 If Instr(1, CurMimeType, &quot;calc&quot;) &lt;&gt; 0 Then
60 bDocHasProtectedSheets = CheckSheetProtection(oSheets)
61 If bDocHasProtectedSheets Then
62 bDocHasProtectedSheets = UnprotectSheetsWithPassword(oSheets, bDoUnProtect)
63 End If
64 If Not bDocHasProtectedSheets Then
65 If Not bRangeListDefined Then
66 TotCellCount = 0
67 CreateRangeEnumeration(True)
68 Else
69 IncreaseStatusvalue(SBRelGet/3)
70 End If
71 RangeIndex = Ubound(RangeList())
72 If RangeIndex &gt; -1 Then
73 ConvertThehardWay(RangeList(), True, False)
74 MakeStyleEnumeration(True)
75 oDocument.calculateAll()
76 End If
77 ReprotectSheets()
78 bRangeListDefined = False
79 End If
80 Else
81 DialogModel.ProgressBar.ProgressValue = 10 &apos; oStatusline.SetValue(10)
82 ConvertTextFields()
83 DialogModel.ProgressBar.ProgressValue = 80 &apos; oStatusline.SetValue(80)
84 ConvertWriterTables()
85 End If
86 EndStatusLine()
87 On Local Error Goto 0
88 End Function
91 Sub SwitchNumberFormat(oObject as Object, oFormats as object)
92 Dim nFormatLanguage as Integer
93 Dim nFormatDecimals as Integer
94 Dim nFormatLeading as Integer
95 Dim bFormatLeading as Integer
96 Dim bFormatNegRed as Integer
97 Dim bFormatThousands as Integer
98 Dim i as Integer
99 Dim aNewStr as String
100 Dim iNumberFormat as Long
101 Dim AddToList as Boolean
102 Dim sOldCurrSymbol as String
103 On Local Error Resume Next
104 iNumberFormat = oObject.NumberFormat
105 On Local Error GoTo NOKEY
106 aFormat() = oFormats.getByKey(iNumberFormat)
107 On Local Error GoTo 0
108 sOldCurrSymbol = aFormat.CurrencySymbol
109 If sOldCurrSymbol = CurrValue(CurrIndex,5) Then
110 aSimpleStr = &quot;0 [$EUR]&quot;
111 Else
112 aSimpleStr = &quot;0 [$&quot; &amp; sEuroSign &amp; aFormat.CurrencyExtension &amp; &quot;]&quot;
113 End If
115 nSimpleKey = Numberformat(oFormats, aSimpleStr, oLocale)
116 &apos; set new Currency format with according settings
117 nFormatDecimals = 2
118 nFormatLeading = aFormat.LeadingZeros
119 bFormatNegRed = aFormat.NegativeRed
120 bFormatThousands = aFormat.ThousandsSeparator
121 aNewStr = oFormats.generateFormat( nSimpleKey, aFormat.Locale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
122 oObject.NumberFormat = Numberformat(oFormats, aNewStr, aFormat.Locale)
123 NOKEY:
124 If Err &lt;&gt; 0 Then
125 Resume CLERROR
126 End If
127 CLERROR:
128 End Sub
131 Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Object)
132 Dim nRetkey
133 Dim l as String
134 Dim c as String
135 nRetKey = oFormats.queryKey( aFormatStr, oLocale, True )
136 If nRetKey = -1 Then
137 l = oLocale.Language
138 c = oLocale.Country
139 nRetKey = oFormats.addNew( aFormatStr, oLocale )
140 If nRetKey = -1 Then nRetKey = 0
141 End If
142 Numberformat = nRetKey
143 End Function
146 Function CheckFormatType( FormatObject as object)
147 Dim i as Integer
148 Dim LocCurrIndex as Integer
149 Dim nFormatFormatString as String
150 Dim FormatLangID as Integer
151 Dim sFormatCurrExt as String
152 Dim oFormatofObject() as Object
154 &apos; Retrieve the Format of the Object
155 On Local Error GoTo NOKEY
156 oFormatofObject = oFormats.getByKey(FormatObject.NumberFormat)
157 On Local Error GoTo 0
158 If NOT INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY Then
159 CheckFormatType = False
160 Exit Function
161 End If
162 If FieldinArray(CurrSymbolList(),2,oFormatofObject.CurrencySymbol) Then
163 &apos; If the Currencysymbol of the object ist the one needed, then check the Currency extension
164 sFormatCurrExt = oFormatofObject.CurrencyExtension
166 If FieldInList(CurExtension(),2,sFormatCurrExt) Then
167 &apos; The Currency - extension also fits
168 CheckFormatType = True
169 Else
170 &apos; The Currency - symbol is Euro-conforming (like &apos;DEM&apos;), so there is no Currency-Extension
171 CheckFormatType = oFormatofObject.CurrencySymbol = CurrsymbolList(2)
172 End If
173 Else
174 &apos; The Currency Symbol of the object is not the desired one
175 If oFormatofObject.CurrencySymbol = &quot;&quot; Then
176 &apos; Format is &quot;automatic&quot;
177 CheckFormatType = CheckLocale(oFormatofObject.Locale)
178 Else
179 CheckFormatType = False
180 End If
181 End If
183 NOKEY:
184 If Err &lt;&gt; 0 Then
185 CheckFormatType = False
186 Resume CLERROR
187 End If
188 CLERROR:
189 End Function
192 Sub StartConversion()
193 GoOn = True
194 Select Case DialogModel.Step
195 Case 1
196 If DialogModel.chkComplete.State = 1 Then
197 ConvertWholeDocument()
198 Else
199 ConvertRangesorStylesofDocument()
200 End If
201 Case 2
202 bCancelTask = False
203 If InitializeThirdStep() Then
204 ConvertDocuments()
205 bCancelTask = True
206 End If
207 Case 3
208 DialogConvert.EndExecute()
209 End Select
210 End Sub
213 Sub IncreaseStatusValue(AddStatusValue as Integer)
214 StatusValue = Int(StatusValue + AddStatusValue)
215 If DialogModel.Step = 3 Then
216 DialogModel.ProgressBar.ProgressValue = StatusValue
217 Else
218 oStatusline.SetValue(StatusValue)
219 End If
220 End Sub
223 Sub SelectCurrency()
224 Dim AddtoList as Boolean
225 Dim NullList()
226 Dim OldCurrIndex as Integer
227 bRangeListDefined = False
228 OldCurrIndex = CurrIndex
229 CurrIndex = DialogModel.lstCurrencies.SelectedItems(0)
230 If OldCurrIndex &lt;&gt; CurrIndex Then
231 InitializeCurrencyValues(CurrIndex)
232 CurExtension(0) = LangIDValue(CurrIndex,0,2)
233 CurExtension(1) = LangIDValue(CurrIndex,1,2)
234 CurExtension(2) = LangIDValue(CurrIndex,2,2)
235 If DialogModel.Step = 1 Then
236 EnableStep1DialogControls(False,False, False)
237 If DialogModel.optCellTemplates.State = 1 Then
238 EnableStep1DialogControls(False, False, False)
239 CreateStyleEnumeration()
240 ElseIf ((DialogModel.optSheetRanges.State = 1) OR (DialogModel.optDocRanges.State = 1)) AND (DialogModel.Step = 1) Then
241 CreateRangeEnumeration(False)
242 If Ubound(RangeList()) = -1 Then
243 DialogModel.lstSelection.StringItemList() = NullList()
244 End If
245 ElseIf DialogModel.optSelRange.State= 1 Then
246 &apos;Preselected Range
247 End If
248 EnableStep1DialogControls(True, True, True)
249 ElseIf DialogModel.Step = 2 Then
250 EnableStep2DialogControls(True)
251 End If
252 End If
253 End Sub
256 Sub FillUpCurrencyListbox()
257 Dim i as Integer
258 Dim MaxIndex as Integer
259 MaxIndex = Ubound(CurrValue(),1)
260 Dim LocList(MaxIndex) as String
261 For i = 0 To MaxIndex
262 LocList(i) = CurrValue(i,0)
263 Next i
264 DialogModel.lstCurrencies.StringItemList() = LocList()
265 If CurrIndex &gt; -1 Then
266 SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
267 End If
268 End Sub
271 Sub InitializeProgressbar()
272 CurCellCount = 0
273 If Not IsNull(oStatusLine) Then
274 oStatusline.Start(sStsPROGRESS, 100)
275 Else
276 DialogModel.ProgressBar.ProgressValue = 0
277 End If
278 StatusValue = 0
279 End Sub
282 Sub EndStatusLine()
283 If Not IsNull(oStatusLine) Then
284 oStatusline.End
285 Else
286 DialogModel.ProgressBar.ProgressValue = 100
287 End If
288 End Sub
289 </script:module>