xref: /trunk/main/wizards/source/euro/ConvertRun.xba (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ConvertRun" script:language="StarBasic">Option Explicit
4
5Public oPreSelRange as Object
6
7Sub Main()
8    BasicLibraries.LoadLibrary(&quot;Tools&quot;)
9    If InitResources(&quot;Euro Converter&quot;, &quot;eur&quot;) Then
10        bDoUnProtect = False
11        bPreSelected = True
12        oDocument = ThisComponent
13        RetrieveDocumentObjects()                                           &apos; Statusline, SheetsCollection etc.
14        InitializeConverter(oDocument.CharLocale, 1)
15        GetPreSelectedRange()
16        If GoOn Then
17            DialogModel.lstCurrencies.TabIndex = 2
18            DialogConvert.GetControl(&quot;chkComplete&quot;).SetFocus()
19            DialogConvert.Execute
20        End If
21        DialogConvert.Dispose
22    End If
23End Sub
24
25
26Sub SelectListItem()
27Dim Listbox as Object
28Dim oListSheet as Object
29Dim CurStyleName as String
30Dim oCursheet as Object
31Dim oTempRanges as Object
32Dim sCurSheetName as String
33Dim RangeName as String
34Dim oSheetRanges as Object
35Dim ListIndex as Integer
36Dim a as Integer
37Dim i as Integer
38Dim n as Integer
39Dim m as Integer
40Dim MaxIndex as Integer
41    Listbox = DialogModel.lstSelection
42    If Ubound(Listbox.SelectedItems()) &gt; -1 Then
43        EnableStep1DialogControls(False, False, False)
44        oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
45
46        &apos; Is the sheet the basis, then the sheetobject has to be created
47        If DialogModel.optDocRanges.State = 1 Then
48            &apos; Document is the basis for the conversion
49            ListIndex = Listbox.SelectedItems(0)
50            oCurSheet = RetrieveSheetoutofRangeName(Listbox.StringItemList(ListIndex))
51            oDocument.CurrentController.SetActiveSheet(oCurSheet)
52        Else
53            oCurSheet = oDocument.CurrentController.ActiveSheet
54        End If
55        sCurSheetName = oCurSheet.Name
56        If DialogModel.optCellTemplates.State = 1 Then
57            Dim CurIndex as Integer
58            For i = 0 To Ubound(Listbox.SelectedItems())
59                CurIndex = Listbox.SelectedItems(i)
60                CurStylename = Listbox.StringItemList(CurIndex)
61                oSheetRanges = oCursheet.CellFormatRanges.createEnumeration
62                While oSheetRanges.hasMoreElements
63                    oRange = oSheetRanges.NextElement
64                    If oRange.getPropertyState(&quot;NumberFormat&quot;) = 1 Then
65                        If oRange.CellStyle = CurStyleName Then
66                            oSelRanges.InsertbyName(&quot;&quot;,oRange)
67                        End If
68                    End If
69                Wend
70            Next i
71        Else
72            &apos; Hard Formatation is selected
73            a = -1
74            For n = 0 To Ubound(Listbox.SelectedItems())
75                m = Listbox.SelectedItems(n)
76                RangeName = Listbox.StringItemList(m)
77                oListSheet = RetrieveSheetoutofRangeName(RangeName)
78                a = a + 1
79                MaxIndex = Ubound(SelRangeList())
80                If a &gt; MaxIndex Then
81                    Redim Preserve SelRangeList(MaxIndex + SBRANGEUBOUND)
82                End If
83                SelRangeList(a) = RangeName
84                If oListSheet.Name = sCurSheetName Then
85                    oRange = RetrieveRangeoutofRangeName(RangeName)
86                    oSelRanges.InsertbyName(&quot;&quot;,oRange)
87                End If
88            Next n
89        End If
90        If a &gt; -1 Then
91            ReDim Preserve SelRangeList(a)
92        Else
93            ReDim SelRangeList()
94        End If
95        oDocument.CurrentController.Select(oSelRanges)
96        EnableStep1DialogControls(True, True, True)
97    End If
98End Sub
99
100
101&apos; Procedure that is called by an event
102Sub RetrieveEnableValue()
103Dim EnableValue as Boolean
104    EnableValue = Not DialogModel.lstSelection.Enabled
105    EnableStep1DialogControls(True, EnableValue, True)
106End Sub
107
108
109Sub EnableStep1DialogControls(bCurrEnabled as Boolean, bFrameEnabled as Boolean, bButtonsEnabled as Boolean)
110Dim bCurrIsSelected as Boolean
111Dim bObjectIsSelected as Boolean
112Dim bConvertWholeDoc as Boolean
113Dim bDoEnableFrame as Boolean
114    bConvertWholeDoc  = DialogModel.chkComplete.State = 1
115    bDoEnableFrame = bFrameEnabled And (NOT bConvertWholeDoc)
116
117    &apos; Controls around the Selection Listbox
118    With DialogModel
119        .lblCurrencies.Enabled = bCurrEnabled
120        .lstCurrencies.Enabled = bCurrEnabled
121        .lstSelection.Enabled = bDoEnableFrame
122        .lblSelection.Enabled = bDoEnableFrame
123        .hlnSelection.Enabled = bDoEnableFrame
124        .optCellTemplates.Enabled = bDoEnableFrame
125        .optSheetRanges.Enabled = bDoEnableFrame
126        .optDocRanges.Enabled = bDoEnableFrame
127        .optSelRange.Enabled = bDoEnableFrame
128    End With
129    &apos; The CheckBox has the Value &apos;1&apos; when the Controls in the Frame are disabled
130    If bButtonsEnabled Then
131        bCurrIsSelected = Ubound(DialogModel.lstCurrencies.SelectedItems()) &lt;&gt; -1
132        &apos; Enable GoOnButton only when Currency is selected
133        DialogModel.cmdGoOn.Enabled =  bCurrIsSelected
134        DialogModel.chkComplete.Enabled = bCurrIsSelected
135        If bDoEnableFrame AND DialogModel.cmdGoOn.Enabled Then
136            &apos; If FrameControls are enabled, check if Listbox is Empty
137            bObjectIsSelected = Ubound(DialogModel.lstSelection.SelectedItems()) &lt;&gt; -1
138            DialogModel.cmdGoOn.Enabled = bObjectIsSelected
139        End If
140    Else
141        DialogModel.cmdGoOn.Enabled = False
142        DialogModel.chkComplete.Enabled = False
143    End If
144End Sub
145
146
147Sub ConvertRangesOrStylesOfDocument()
148Dim i as Integer
149Dim ItemName as String
150Dim SelList() as String
151Dim oSheetRanges as Object
152
153    bDocHasProtectedSheets = CheckSheetProtection(oSheets)
154    If bDocHasProtectedSheets Then
155        bDocHasProtectedSheets = UnprotectSheetsWithPassWord(oSheets, bDoUnProtect)
156        DialogModel.cmdGoOn.Enabled = False
157    End If
158    If Not bDocHasProtectedSheets Then
159        EnableStep1DialogControls(False, False, False)
160        InitializeProgressBar()
161        If DialogModel.optSelRange.State = 1 Then
162            SelectListItem()
163        End If
164        SelList() =  DialogConvert.GetControl(&quot;lstSelection&quot;).SelectedItems()
165        If DialogModel.optCellTemplates.State = 1 Then
166            &apos; Option &apos;Soft&apos; Formatation is selected
167            AssignRangestoStyle(DialogModel.lstSelection.StringItemList(), SelList())
168            ConverttheSoftWay(SelList(), True)
169        ElseIf DialogModel.optSelRange.State = 1 Then
170            oSheetRanges = oPreSelRange.CellFormatRanges.createEnumeration
171            While oSheetRanges.hasMoreElements
172                oRange = oSheetRanges.NextElement
173                If CheckFormatType(oRange) Then
174                    ConvertCellCurrencies(oRange)
175                    SwitchNumberFormat(oRange, oFormats, sEuroSign)
176                End If
177            Wend
178        Else
179            ConverttheHardWay(SelList(), False, True)
180        End If
181        oStatusline.End
182        EnableStep1DialogControls(True, False, True)
183        DialogModel.cmdGoOn.Enabled = True
184        oDocument.CurrentController.Select(oSelRanges)
185    End If
186End Sub
187
188
189Sub ConvertWholeDocument()
190Dim s as Integer
191    DialogModel.cmdGoOn.Enabled = False
192    DialogModel.chkComplete.Enabled = False
193    GoOn = ConvertDocument()
194    EmptyListbox(DialogModel.lstSelection())
195    EnableStep1DialogControls(True, True, True)
196End Sub
197
198
199&apos; Everything previously selected will be deselected
200Sub EmptySelection()
201Dim RangeName as String
202Dim i as Integer
203Dim MaxIndex as Integer
204Dim EmptySelRangeList() as String
205
206    If Not IsNull(oSelRanges) Then
207        If oSelRanges.HasElements Then
208            EmptySelRangeList() = ArrayOutofString(oSelRanges.RangeAddressesasString, &quot;;&quot;, MaxIndex)
209            For i = 0 To MaxIndex
210                oSelRanges.RemovebyName(EmptySelRangeList(i))
211            Next i
212        End If
213        oDocument.CurrentController.Select(oSelRanges)
214    Else
215        oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
216    End If
217End Sub
218
219
220Function AddSelectedRangeToSelRangesEnum() as Object
221Dim oLocRange as Object
222    osheet = oDocument.CurrentController.GetActiveSheet
223    oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
224    &apos; Check if a Currency-Range has been selected
225    oLocRange = oDocument.CurrentController.Selection
226    bPreSelected = oLocRange.SupportsService(&quot;com.sun.star.sheet.SheetCellRange&quot;)
227    If bPreSelected Then
228        oSelRanges.InsertbyName(&quot;&quot;,oLocRange)
229        AddSelectedRangeToSelRangesEnum() = oLocRange
230    End If
231End Function
232
233
234Sub GetPreSelectedRange()
235Dim i as Integer
236Dim OldCurrSymbolList(2) as String
237Dim OldCurrIndex as Integer
238Dim OldCurExtension(2) as String
239    oPreSelRange = AddSelectedRangeToSelRangesEnum()
240
241    DialogModel.chkComplete.State = Abs(Not(bPreSelected))
242    If bPreSelected Then
243        DialogModel.optSelRange.State = 1
244        AddRangeToListbox(oPreSelRange)
245    Else
246        DialogModel.optCellTemplates.State  = 1
247        CreateStyleEnumeration()
248    End If
249    EnableStep1DialogControls(True, bPreSelected, True)
250    DialogModel.optSelRange.Enabled = bPreSelected
251End Sub
252
253
254Sub AddRangeToListbox(oLocRange as Object)
255    EmptyListBox(DialogModel.lstSelection)
256    PreName = RetrieveRangeNamefromAddress(oLocRange)
257    AddSingleItemToListbox(DialogModel.lstSelection, Prename)&apos;, 0)
258    SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
259    TotCellCount = CountRangeCells(oLocRange)
260End Sub
261
262
263Sub CheckRangeSelection(Optional oEvent)
264    EmptySelection()
265    AddRangeToListbox(oPreSelRange)
266    oPreSelRange = AddSelectedRangeToSelRangesEnum()
267End Sub
268
269
270&apos; Checks if a Field (LocField) is already defined in an Array
271&apos; Returns &apos;True&apos; or &apos;False&apos;
272Function FieldinList(LocList(), MaxIndex as integer, ByVal LocField ) As Boolean
273Dim i as integer
274    LocField = Ucase(LocField)
275    For i = Lbound(LocList()) to MaxIndex
276        If Ucase(LocList(i)) = LocField  then
277            FieldInList = True
278            Exit Function
279        End if
280    Next
281    FieldInList = False
282End Function
283
284
285Function CheckLocale(oLocale) as Boolean
286Dim i as Integer
287Dim LocCountry as String
288Dim LocLanguage as String
289    LocCountry = oLocale.Country
290    LocLanguage = oLocale.Language
291    For i = 0 To 1
292        If LocLanguage = LangIDValue(CurrIndex,i,0) AND LocCountry = LangIDValue(CurrIndex,i,1) Then
293            CheckLocale = True
294            Exit Function
295        End If
296    Next i
297    CheckLocale = False
298End Function
299
300
301Sub SetOptionValuestoNull()
302    With DialogModel
303        .optCellTemplates.State = 0
304        .optSheetRanges.State = 0
305        .optDocRanges.State = 0
306        .optSelRange.State = 0
307    End With
308End Sub
309
310
311
312Sub SetStatusLineText(sStsREPROTECT as String)
313    If Not IsNull(oStatusLine) Then
314        oStatusline.SetText(sStsREPROTECT)
315    End If
316End Sub
317</script:module>