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=
"ConvertRun" script:
language=
"StarBasic">Option Explicit
22 Public oPreSelRange as Object
25 BasicLibraries.LoadLibrary(
"Tools
")
26 If InitResources(
"Euro Converter
",
"eur
") Then
29 oDocument = ThisComponent
30 RetrieveDocumentObjects()
' Statusline, SheetsCollection etc.
31 InitializeConverter(oDocument.CharLocale,
1)
34 DialogModel.lstCurrencies.TabIndex =
2
35 DialogConvert.GetControl(
"chkComplete
").SetFocus()
45 Dim oListSheet as Object
46 Dim CurStyleName as String
47 Dim oCursheet as Object
48 Dim oTempRanges as Object
49 Dim sCurSheetName as String
50 Dim RangeName as String
51 Dim oSheetRanges as Object
52 Dim ListIndex as Integer
57 Dim MaxIndex as Integer
58 Listbox = DialogModel.lstSelection
59 If Ubound(Listbox.SelectedItems())
> -
1 Then
60 EnableStep1DialogControls(False, False, False)
61 oSelRanges = oDocument.createInstance(
"com.sun.star.sheet.SheetCellRanges
")
63 ' Is the sheet the basis, then the sheetobject has to be created
64 If DialogModel.optDocRanges.State =
1 Then
65 ' Document is the basis for the conversion
66 ListIndex = Listbox.SelectedItems(
0)
67 oCurSheet = RetrieveSheetoutofRangeName(Listbox.StringItemList(ListIndex))
68 oDocument.CurrentController.SetActiveSheet(oCurSheet)
70 oCurSheet = oDocument.CurrentController.ActiveSheet
72 sCurSheetName = oCurSheet.Name
73 If DialogModel.optCellTemplates.State =
1 Then
74 Dim CurIndex as Integer
75 For i =
0 To Ubound(Listbox.SelectedItems())
76 CurIndex = Listbox.SelectedItems(i)
77 CurStylename = Listbox.StringItemList(CurIndex)
78 oSheetRanges = oCursheet.CellFormatRanges.createEnumeration
79 While oSheetRanges.hasMoreElements
80 oRange = oSheetRanges.NextElement
81 If oRange.getPropertyState(
"NumberFormat
") =
1 Then
82 If oRange.CellStyle = CurStyleName Then
83 oSelRanges.InsertbyName(
"",oRange)
89 ' Hard Formatation is selected
91 For n =
0 To Ubound(Listbox.SelectedItems())
92 m = Listbox.SelectedItems(n)
93 RangeName = Listbox.StringItemList(m)
94 oListSheet = RetrieveSheetoutofRangeName(RangeName)
96 MaxIndex = Ubound(SelRangeList())
97 If a
> MaxIndex Then
98 Redim Preserve SelRangeList(MaxIndex + SBRANGEUBOUND)
100 SelRangeList(a) = RangeName
101 If oListSheet.Name = sCurSheetName Then
102 oRange = RetrieveRangeoutofRangeName(RangeName)
103 oSelRanges.InsertbyName(
"",oRange)
108 ReDim Preserve SelRangeList(a)
112 oDocument.CurrentController.Select(oSelRanges)
113 EnableStep1DialogControls(True, True, True)
118 ' Procedure that is called by an event
119 Sub RetrieveEnableValue()
120 Dim EnableValue as Boolean
121 EnableValue = Not DialogModel.lstSelection.Enabled
122 EnableStep1DialogControls(True, EnableValue, True)
126 Sub EnableStep1DialogControls(bCurrEnabled as Boolean, bFrameEnabled as Boolean, bButtonsEnabled as Boolean)
127 Dim bCurrIsSelected as Boolean
128 Dim bObjectIsSelected as Boolean
129 Dim bConvertWholeDoc as Boolean
130 Dim bDoEnableFrame as Boolean
131 bConvertWholeDoc = DialogModel.chkComplete.State =
1
132 bDoEnableFrame = bFrameEnabled And (NOT bConvertWholeDoc)
134 ' Controls around the Selection Listbox
136 .lblCurrencies.Enabled = bCurrEnabled
137 .lstCurrencies.Enabled = bCurrEnabled
138 .lstSelection.Enabled = bDoEnableFrame
139 .lblSelection.Enabled = bDoEnableFrame
140 .hlnSelection.Enabled = bDoEnableFrame
141 .optCellTemplates.Enabled = bDoEnableFrame
142 .optSheetRanges.Enabled = bDoEnableFrame
143 .optDocRanges.Enabled = bDoEnableFrame
144 .optSelRange.Enabled = bDoEnableFrame
146 ' The CheckBox has the Value
'1' when the Controls in the Frame are disabled
147 If bButtonsEnabled Then
148 bCurrIsSelected = Ubound(DialogModel.lstCurrencies.SelectedItems())
<> -
1
149 ' Enable GoOnButton only when Currency is selected
150 DialogModel.cmdGoOn.Enabled = bCurrIsSelected
151 DialogModel.chkComplete.Enabled = bCurrIsSelected
152 If bDoEnableFrame AND DialogModel.cmdGoOn.Enabled Then
153 ' If FrameControls are enabled, check if Listbox is Empty
154 bObjectIsSelected = Ubound(DialogModel.lstSelection.SelectedItems())
<> -
1
155 DialogModel.cmdGoOn.Enabled = bObjectIsSelected
158 DialogModel.cmdGoOn.Enabled = False
159 DialogModel.chkComplete.Enabled = False
164 Sub ConvertRangesOrStylesOfDocument()
166 Dim ItemName as String
167 Dim SelList() as String
168 Dim oSheetRanges as Object
170 bDocHasProtectedSheets = CheckSheetProtection(oSheets)
171 If bDocHasProtectedSheets Then
172 bDocHasProtectedSheets = UnprotectSheetsWithPassWord(oSheets, bDoUnProtect)
173 DialogModel.cmdGoOn.Enabled = False
175 If Not bDocHasProtectedSheets Then
176 EnableStep1DialogControls(False, False, False)
177 InitializeProgressBar()
178 If DialogModel.optSelRange.State =
1 Then
181 SelList() = DialogConvert.GetControl(
"lstSelection
").SelectedItems()
182 If DialogModel.optCellTemplates.State =
1 Then
183 ' Option
'Soft
' Formatation is selected
184 AssignRangestoStyle(DialogModel.lstSelection.StringItemList(), SelList())
185 ConverttheSoftWay(SelList(), True)
186 ElseIf DialogModel.optSelRange.State =
1 Then
187 oSheetRanges = oPreSelRange.CellFormatRanges.createEnumeration
188 While oSheetRanges.hasMoreElements
189 oRange = oSheetRanges.NextElement
190 If CheckFormatType(oRange) Then
191 ConvertCellCurrencies(oRange)
192 SwitchNumberFormat(oRange, oFormats, sEuroSign)
196 ConverttheHardWay(SelList(), False, True)
199 EnableStep1DialogControls(True, False, True)
200 DialogModel.cmdGoOn.Enabled = True
201 oDocument.CurrentController.Select(oSelRanges)
206 Sub ConvertWholeDocument()
208 DialogModel.cmdGoOn.Enabled = False
209 DialogModel.chkComplete.Enabled = False
210 GoOn = ConvertDocument()
211 EmptyListbox(DialogModel.lstSelection())
212 EnableStep1DialogControls(True, True, True)
216 ' Everything previously selected will be deselected
218 Dim RangeName as String
220 Dim MaxIndex as Integer
221 Dim EmptySelRangeList() as String
223 If Not IsNull(oSelRanges) Then
224 If oSelRanges.HasElements Then
225 EmptySelRangeList() = ArrayOutofString(oSelRanges.RangeAddressesasString,
";
", MaxIndex)
226 For i =
0 To MaxIndex
227 oSelRanges.RemovebyName(EmptySelRangeList(i))
230 oDocument.CurrentController.Select(oSelRanges)
232 oSelRanges = oDocument.createInstance(
"com.sun.star.sheet.SheetCellRanges
")
237 Function AddSelectedRangeToSelRangesEnum() as Object
238 Dim oLocRange as Object
239 osheet = oDocument.CurrentController.GetActiveSheet
240 oSelRanges = oDocument.createInstance(
"com.sun.star.sheet.SheetCellRanges
")
241 ' Check if a Currency-Range has been selected
242 oLocRange = oDocument.CurrentController.Selection
243 bPreSelected = oLocRange.SupportsService(
"com.sun.star.sheet.SheetCellRange
")
245 oSelRanges.InsertbyName(
"",oLocRange)
246 AddSelectedRangeToSelRangesEnum() = oLocRange
251 Sub GetPreSelectedRange()
253 Dim OldCurrSymbolList(
2) as String
254 Dim OldCurrIndex as Integer
255 Dim OldCurExtension(
2) as String
256 oPreSelRange = AddSelectedRangeToSelRangesEnum()
258 DialogModel.chkComplete.State = Abs(Not(bPreSelected))
260 DialogModel.optSelRange.State =
1
261 AddRangeToListbox(oPreSelRange)
263 DialogModel.optCellTemplates.State =
1
264 CreateStyleEnumeration()
266 EnableStep1DialogControls(True, bPreSelected, True)
267 DialogModel.optSelRange.Enabled = bPreSelected
271 Sub AddRangeToListbox(oLocRange as Object)
272 EmptyListBox(DialogModel.lstSelection)
273 PreName = RetrieveRangeNamefromAddress(oLocRange)
274 AddSingleItemToListbox(DialogModel.lstSelection, Prename)
',
0)
275 SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
276 TotCellCount = CountRangeCells(oLocRange)
280 Sub CheckRangeSelection(Optional oEvent)
282 AddRangeToListbox(oPreSelRange)
283 oPreSelRange = AddSelectedRangeToSelRangesEnum()
287 ' Checks if a Field (LocField) is already defined in an Array
288 ' Returns
'True
' or
'False
'
289 Function FieldinList(LocList(), MaxIndex as integer, ByVal LocField ) As Boolean
291 LocField = Ucase(LocField)
292 For i = Lbound(LocList()) to MaxIndex
293 If Ucase(LocList(i)) = LocField then
302 Function CheckLocale(oLocale) as Boolean
304 Dim LocCountry as String
305 Dim LocLanguage as String
306 LocCountry = oLocale.Country
307 LocLanguage = oLocale.Language
309 If LocLanguage = LangIDValue(CurrIndex,i,
0) AND LocCountry = LangIDValue(CurrIndex,i,
1) Then
318 Sub SetOptionValuestoNull()
320 .optCellTemplates.State =
0
321 .optSheetRanges.State =
0
322 .optDocRanges.State =
0
323 .optSelRange.State =
0
329 Sub SetStatusLineText(sStsREPROTECT as String)
330 If Not IsNull(oStatusLine) Then
331 oStatusline.SetText(sStsREPROTECT)