1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
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 .
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,
"calc
")
<> 0 Then
29 oSheets = oDocument.Sheets
30 oSheet = oDocument.Sheets.GetbyIndex(
0)
31 oAddressRanges = oDocument.createInstance(
"com.sun.star.sheet.SheetCellRanges
")
33 ' Retrieve the indices for the cellformatations
34 oFormats = oDocument.NumberFormats
39 ' If Not DocDisposed Then
40 ' ReprotectSheets()
42 If DialogModel.Step =
3 And (Not bCancelTask) Then
43 If Msgbox(sMsgCancelConversion,
36, sMsgCancelTitle) =
6 Then
45 DialogConvert.EndExecute
50 DialogConvert.EndExecute()
55 Function ConvertDocument()
57 ' DocDisposed = True
58 InitializeProgressbar()
59 If Instr(
1, CurMimeType,
"calc
")
<> 0 Then
60 bDocHasProtectedSheets = CheckSheetProtection(oSheets)
61 If bDocHasProtectedSheets Then
62 bDocHasProtectedSheets = UnprotectSheetsWithPassword(oSheets, bDoUnProtect)
64 If Not bDocHasProtectedSheets Then
65 If Not bRangeListDefined Then
67 CreateRangeEnumeration(True)
69 IncreaseStatusvalue(SBRelGet/
3)
71 RangeIndex = Ubound(RangeList())
72 If RangeIndex
> -
1 Then
73 ConvertThehardWay(RangeList(), True, False)
74 MakeStyleEnumeration(True)
75 oDocument.calculateAll()
78 bRangeListDefined = False
81 DialogModel.ProgressBar.ProgressValue =
10 ' oStatusline.SetValue(
10)
83 DialogModel.ProgressBar.ProgressValue =
80 ' oStatusline.SetValue(
80)
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
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 =
"0 [$EUR]
"
112 aSimpleStr =
"0 [$
" & sEuroSign
& aFormat.CurrencyExtension
& "]
"
115 nSimpleKey = Numberformat(oFormats, aSimpleStr, oLocale)
116 ' set new Currency format with according settings
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)
124 If Err
<> 0 Then
131 Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Object)
135 nRetKey = oFormats.queryKey( aFormatStr, oLocale, True )
139 nRetKey = oFormats.addNew( aFormatStr, oLocale )
140 If nRetKey = -
1 Then nRetKey =
0
142 Numberformat = nRetKey
146 Function CheckFormatType( FormatObject as object)
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 ' 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
162 If FieldinArray(CurrSymbolList(),
2,oFormatofObject.CurrencySymbol) Then
163 ' 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 ' The Currency - extension also fits
168 CheckFormatType = True
170 ' The Currency - symbol is Euro-conforming (like
'DEM
'), so there is no Currency-Extension
171 CheckFormatType = oFormatofObject.CurrencySymbol = CurrsymbolList(
2)
174 ' The Currency Symbol of the object is not the desired one
175 If oFormatofObject.CurrencySymbol =
"" Then
176 ' Format is
"automatic
"
177 CheckFormatType = CheckLocale(oFormatofObject.Locale)
179 CheckFormatType = False
184 If Err
<> 0 Then
185 CheckFormatType = False
192 Sub StartConversion()
194 Select Case DialogModel.Step
196 If DialogModel.chkComplete.State =
1 Then
197 ConvertWholeDocument()
199 ConvertRangesorStylesofDocument()
203 If InitializeThirdStep() Then
208 DialogConvert.EndExecute()
213 Sub IncreaseStatusValue(AddStatusValue as Integer)
214 StatusValue = Int(StatusValue + AddStatusValue)
215 If DialogModel.Step =
3 Then
216 DialogModel.ProgressBar.ProgressValue = StatusValue
218 oStatusline.SetValue(StatusValue)
224 Dim AddtoList as Boolean
226 Dim OldCurrIndex as Integer
227 bRangeListDefined = False
228 OldCurrIndex = CurrIndex
229 CurrIndex = DialogModel.lstCurrencies.SelectedItems(
0)
230 If OldCurrIndex
<> 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()
245 ElseIf DialogModel.optSelRange.State=
1 Then
246 'Preselected Range
248 EnableStep1DialogControls(True, True, True)
249 ElseIf DialogModel.Step =
2 Then
250 EnableStep2DialogControls(True)
256 Sub FillUpCurrencyListbox()
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)
264 DialogModel.lstCurrencies.StringItemList() = LocList()
265 If CurrIndex
> -
1 Then
266 SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
271 Sub InitializeProgressbar()
273 If Not IsNull(oStatusLine) Then
274 oStatusline.Start(sStsPROGRESS,
100)
276 DialogModel.ProgressBar.ProgressValue =
0
283 If Not IsNull(oStatusLine) Then
286 DialogModel.ProgressBar.ProgressValue =
100