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