xref: /aoo42x/main/wizards/source/euro/Common.xba (revision 3e02b54d)
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Common" script:language="StarBasic"> REM  *****  BASIC  *****
24Public DialogModel as Object
25Public DialogConvert as Object
26Public DialogPassword as Object
27Public PasswordModel as Object
28
29Sub	RetrieveDocumentObjects()
30	CurMimeType = Tools.GetDocumentType(oDocument)
31	If Instr(1, CurMimeType, &quot;calc&quot;) &lt;&gt; 0 Then
32	    oSheets = oDocument.Sheets
33		oSheet = oDocument.Sheets.GetbyIndex(0)
34		oAddressRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
35	End If
36    &apos; Retrieve the indices for the cellformatations
37    oFormats = oDocument.NumberFormats
38End Sub
39
40
41Sub CancelTask()
42&apos;	If Not DocDisposed Then
43&apos;		ReprotectSheets()
44&apos;	End If
45	If DialogModel.Step = 3 And (Not bCancelTask) Then
46		If Msgbox(sMsgCancelConversion, 36, sMsgCancelTitle) = 6 Then
47			bCancelTask = True
48			DialogConvert.EndExecute
49		Else
50			bCancelTask = False
51		End If
52	Else
53		DialogConvert.EndExecute()
54	End If
55End Sub
56
57
58Function ConvertDocument()
59	GoOn = True
60&apos;	DocDisposed = True
61	InitializeProgressbar()
62	If Instr(1, CurMimeType, &quot;calc&quot;) &lt;&gt; 0 Then
63		bDocHasProtectedSheets = CheckSheetProtection(oSheets)
64		If bDocHasProtectedSheets Then
65			bDocHasProtectedSheets = UnprotectSheetsWithPassword(oSheets, bDoUnProtect)
66		End If
67		If Not bDocHasProtectedSheets Then
68			If Not bRangeListDefined Then
69				TotCellCount = 0
70				CreateRangeEnumeration(True)
71			Else
72				IncreaseStatusvalue(SBRelGet/3)
73			End If
74			RangeIndex = Ubound(RangeList())
75			If RangeIndex &gt; -1 Then
76				ConvertThehardWay(RangeList(), True, False)
77				MakeStyleEnumeration(True)
78				oDocument.calculateAll()
79			End If
80			ReprotectSheets()
81			bRangeListDefined = False
82		End If
83	Else
84		DialogModel.ProgressBar.ProgressValue = 10  &apos; oStatusline.SetValue(10)
85		ConvertTextFields()
86		DialogModel.ProgressBar.ProgressValue = 80  &apos; oStatusline.SetValue(80)
87		ConvertWriterTables()
88	End If
89	EndStatusLine()
90	On Local Error Goto 0
91End Function
92
93
94Sub SwitchNumberFormat(oObject as Object, oFormats as object)
95Dim nFormatLanguage as Integer
96Dim nFormatDecimals as Integer
97Dim nFormatLeading as Integer
98Dim bFormatLeading as Integer
99Dim bFormatNegRed as Integer
100Dim bFormatThousands as Integer
101Dim i as Integer
102Dim aNewStr as String
103Dim iNumberFormat as Long
104Dim AddToList as Boolean
105Dim sOldCurrSymbol as String
106	On Local Error Resume Next
107	iNumberFormat = oObject.NumberFormat
108	On Local Error GoTo NOKEY
109	aFormat() = oFormats.getByKey(iNumberFormat)
110	On Local Error GoTo 0
111	sOldCurrSymbol = aFormat.CurrencySymbol
112	If sOldCurrSymbol = CurrValue(CurrIndex,5) Then
113		aSimpleStr = &quot;0 [$EUR]&quot;
114	Else
115		aSimpleStr = &quot;0 [$&quot; &amp; sEuroSign &amp; aFormat.CurrencyExtension &amp; &quot;]&quot;
116	End If
117
118	nSimpleKey = Numberformat(oFormats, aSimpleStr, oLocale)
119	&apos; set new Currency format with according settings
120	nFormatDecimals = 2
121	nFormatLeading = aFormat.LeadingZeros
122	bFormatNegRed = aFormat.NegativeRed
123	bFormatThousands = aFormat.ThousandsSeparator
124	aNewStr = oFormats.generateFormat( nSimpleKey, aFormat.Locale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
125	oObject.NumberFormat = Numberformat(oFormats, aNewStr, aFormat.Locale)
126	NOKEY:
127	If Err &lt;&gt; 0 Then
128		Resume CLERROR
129	End If
130	CLERROR:
131End Sub
132
133
134Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Object)
135Dim nRetkey
136Dim l as String
137Dim c as String
138	nRetKey = oFormats.queryKey( aFormatStr, oLocale, True )
139	If nRetKey = -1 Then
140		l = oLocale.Language
141		c = oLocale.Country
142		nRetKey = oFormats.addNew( aFormatStr, oLocale )
143		If nRetKey = -1 Then nRetKey = 0
144	End If
145	Numberformat = nRetKey
146End Function
147
148
149Function CheckFormatType( FormatObject as object)
150Dim i as Integer
151Dim LocCurrIndex as Integer
152Dim nFormatFormatString as String
153Dim FormatLangID as Integer
154Dim sFormatCurrExt as String
155Dim oFormatofObject() as Object
156
157	&apos; Retrieve the Format of the Object
158	On Local Error GoTo NOKEY
159	oFormatofObject = oFormats.getByKey(FormatObject.NumberFormat)
160	On Local Error GoTo 0
161  	If NOT INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY Then
162		CheckFormatType = False
163		Exit Function
164	End If
165	If FieldinArray(CurrSymbolList(),2,oFormatofObject.CurrencySymbol) Then
166		&apos; If the Currencysymbol of the object ist the one needed, then check the Currency extension
167		sFormatCurrExt = oFormatofObject.CurrencyExtension
168
169		If FieldInList(CurExtension(),2,sFormatCurrExt) Then
170			&apos; The Currency - extension also fits
171			CheckFormatType = True
172		Else
173			&apos; The Currency - symbol is Euro-conforming (like &apos;DEM&apos;), so there is no Currency-Extension
174			CheckFormatType = oFormatofObject.CurrencySymbol = CurrsymbolList(2)
175		End If
176	Else
177		&apos; The Currency Symbol of the object is not the desired one
178		If oFormatofObject.CurrencySymbol = &quot;&quot; Then
179			&apos; Format is &quot;automatic&quot;
180			CheckFormatType = CheckLocale(oFormatofObject.Locale)
181		Else
182			CheckFormatType = False
183		End If
184	End If
185
186	NOKEY:
187	If Err &lt;&gt; 0 Then
188		CheckFormatType = False
189		Resume CLERROR
190	End If
191	CLERROR:
192End Function
193
194
195Sub StartConversion()
196	GoOn = True
197	Select Case DialogModel.Step
198		Case 1
199			If DialogModel.chkComplete.State = 1 Then
200				ConvertWholeDocument()
201			Else
202				ConvertRangesorStylesofDocument()
203			End If
204		Case 2
205			bCancelTask = False
206			If InitializeThirdStep() Then
207				ConvertDocuments()
208				bCancelTask = True
209			End If
210		Case 3
211			DialogConvert.EndExecute()
212	End Select
213End Sub
214
215
216Sub IncreaseStatusValue(AddStatusValue as Integer)
217	StatusValue = Int(StatusValue + AddStatusValue)
218	If DialogModel.Step = 3 Then
219		DialogModel.ProgressBar.ProgressValue = StatusValue
220	Else
221		oStatusline.SetValue(StatusValue)
222	End If
223End Sub
224
225
226Sub SelectCurrency()
227Dim AddtoList as Boolean
228Dim NullList()
229Dim OldCurrIndex as Integer
230	bRangeListDefined = False
231	OldCurrIndex = CurrIndex
232	CurrIndex = DialogModel.lstCurrencies.SelectedItems(0)
233	If OldCurrIndex &lt;&gt; CurrIndex Then
234		InitializeCurrencyValues(CurrIndex)
235		CurExtension(0) = LangIDValue(CurrIndex,0,2)
236		CurExtension(1) = LangIDValue(CurrIndex,1,2)
237		CurExtension(2) = LangIDValue(CurrIndex,2,2)
238		If DialogModel.Step = 1 Then
239			EnableStep1DialogControls(False,False, False)
240			If DialogModel.optCellTemplates.State = 1 Then
241				EnableStep1DialogControls(False, False, False)
242				CreateStyleEnumeration()
243			ElseIf ((DialogModel.optSheetRanges.State = 1) OR (DialogModel.optDocRanges.State = 1)) AND (DialogModel.Step = 1) Then
244				CreateRangeEnumeration(False)
245				If Ubound(RangeList()) = -1 Then
246					DialogModel.lstSelection.StringItemList() = NullList()
247				End If
248			ElseIf DialogModel.optSelRange.State= 1 Then
249				&apos;Preselected Range
250			End If
251			EnableStep1DialogControls(True, True, True)
252		ElseIf DialogModel.Step = 2 Then
253			EnableStep2DialogControls(True)
254		End If
255	End If
256End Sub
257
258
259Sub FillUpCurrencyListbox()
260Dim i as Integer
261Dim MaxIndex as Integer
262	MaxIndex = Ubound(CurrValue(),1)
263	Dim LocList(MaxIndex) as String
264	For i = 0 To MaxIndex
265		LocList(i) = CurrValue(i,0)
266	Next i
267	DialogModel.lstCurrencies.StringItemList() = LocList()
268	If CurrIndex &gt; -1 Then
269		SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
270	End If
271End Sub
272
273
274Sub InitializeProgressbar()
275	CurCellCount = 0
276	If Not IsNull(oStatusLine) Then
277		oStatusline.Start(sStsPROGRESS, 100)
278	Else
279		DialogModel.ProgressBar.ProgressValue = 0
280	End If
281	StatusValue = 0
282End Sub
283
284
285Sub	EndStatusLine()
286	If Not IsNull(oStatusLine) Then
287		oStatusline.End
288	Else
289		DialogModel.ProgressBar.ProgressValue = 100
290	End If
291End Sub
292</script:module>
293