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