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
5 Public oPreSelRange as Object
8 BasicLibraries.LoadLibrary(
"Tools
")
9 If InitResources(
"Euro Converter
",
"eur
") Then
12 oDocument = ThisComponent
13 RetrieveDocumentObjects()
' Statusline, SheetsCollection etc.
14 InitializeConverter(oDocument.CharLocale,
1)
17 DialogModel.lstCurrencies.TabIndex =
2
18 DialogConvert.GetControl(
"chkComplete
").SetFocus()
28 Dim oListSheet as Object
29 Dim CurStyleName as String
30 Dim oCursheet as Object
31 Dim oTempRanges as Object
32 Dim sCurSheetName as String
33 Dim RangeName as String
34 Dim oSheetRanges as Object
35 Dim ListIndex as Integer
40 Dim MaxIndex as Integer
41 Listbox = DialogModel.lstSelection
42 If Ubound(Listbox.SelectedItems())
> -
1 Then
43 EnableStep1DialogControls(False, False, False)
44 oSelRanges = oDocument.createInstance(
"com.sun.star.sheet.SheetCellRanges
")
46 ' Is the sheet the basis, then the sheetobject has to be created
47 If DialogModel.optDocRanges.State =
1 Then
48 ' Document is the basis for the conversion
49 ListIndex = Listbox.SelectedItems(
0)
50 oCurSheet = RetrieveSheetoutofRangeName(Listbox.StringItemList(ListIndex))
51 oDocument.CurrentController.SetActiveSheet(oCurSheet)
53 oCurSheet = oDocument.CurrentController.ActiveSheet
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(
"NumberFormat
") =
1 Then
65 If oRange.CellStyle = CurStyleName Then
66 oSelRanges.InsertbyName(
"",oRange)
72 ' Hard Formatation is selected
74 For n =
0 To Ubound(Listbox.SelectedItems())
75 m = Listbox.SelectedItems(n)
76 RangeName = Listbox.StringItemList(m)
77 oListSheet = RetrieveSheetoutofRangeName(RangeName)
79 MaxIndex = Ubound(SelRangeList())
80 If a
> MaxIndex Then
81 Redim Preserve SelRangeList(MaxIndex + SBRANGEUBOUND)
83 SelRangeList(a) = RangeName
84 If oListSheet.Name = sCurSheetName Then
85 oRange = RetrieveRangeoutofRangeName(RangeName)
86 oSelRanges.InsertbyName(
"",oRange)
91 ReDim Preserve SelRangeList(a)
95 oDocument.CurrentController.Select(oSelRanges)
96 EnableStep1DialogControls(True, True, True)
101 ' Procedure that is called by an event
102 Sub RetrieveEnableValue()
103 Dim EnableValue as Boolean
104 EnableValue = Not DialogModel.lstSelection.Enabled
105 EnableStep1DialogControls(True, EnableValue, True)
109 Sub EnableStep1DialogControls(bCurrEnabled as Boolean, bFrameEnabled as Boolean, bButtonsEnabled as Boolean)
110 Dim bCurrIsSelected as Boolean
111 Dim bObjectIsSelected as Boolean
112 Dim bConvertWholeDoc as Boolean
113 Dim bDoEnableFrame as Boolean
114 bConvertWholeDoc = DialogModel.chkComplete.State =
1
115 bDoEnableFrame = bFrameEnabled And (NOT bConvertWholeDoc)
117 ' Controls around the Selection Listbox
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
129 ' The CheckBox has the Value
'1' when the Controls in the Frame are disabled
130 If bButtonsEnabled Then
131 bCurrIsSelected = Ubound(DialogModel.lstCurrencies.SelectedItems())
<> -
1
132 ' 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 ' If FrameControls are enabled, check if Listbox is Empty
137 bObjectIsSelected = Ubound(DialogModel.lstSelection.SelectedItems())
<> -
1
138 DialogModel.cmdGoOn.Enabled = bObjectIsSelected
141 DialogModel.cmdGoOn.Enabled = False
142 DialogModel.chkComplete.Enabled = False
147 Sub ConvertRangesOrStylesOfDocument()
149 Dim ItemName as String
150 Dim SelList() as String
151 Dim oSheetRanges as Object
153 bDocHasProtectedSheets = CheckSheetProtection(oSheets)
154 If bDocHasProtectedSheets Then
155 bDocHasProtectedSheets = UnprotectSheetsWithPassWord(oSheets, bDoUnProtect)
156 DialogModel.cmdGoOn.Enabled = False
158 If Not bDocHasProtectedSheets Then
159 EnableStep1DialogControls(False, False, False)
160 InitializeProgressBar()
161 If DialogModel.optSelRange.State =
1 Then
164 SelList() = DialogConvert.GetControl(
"lstSelection
").SelectedItems()
165 If DialogModel.optCellTemplates.State =
1 Then
166 ' Option
'Soft
' 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)
179 ConverttheHardWay(SelList(), False, True)
182 EnableStep1DialogControls(True, False, True)
183 DialogModel.cmdGoOn.Enabled = True
184 oDocument.CurrentController.Select(oSelRanges)
189 Sub ConvertWholeDocument()
191 DialogModel.cmdGoOn.Enabled = False
192 DialogModel.chkComplete.Enabled = False
193 GoOn = ConvertDocument()
194 EmptyListbox(DialogModel.lstSelection())
195 EnableStep1DialogControls(True, True, True)
199 ' Everything previously selected will be deselected
201 Dim RangeName as String
203 Dim MaxIndex as Integer
204 Dim EmptySelRangeList() as String
206 If Not IsNull(oSelRanges) Then
207 If oSelRanges.HasElements Then
208 EmptySelRangeList() = ArrayOutofString(oSelRanges.RangeAddressesasString,
";
", MaxIndex)
209 For i =
0 To MaxIndex
210 oSelRanges.RemovebyName(EmptySelRangeList(i))
213 oDocument.CurrentController.Select(oSelRanges)
215 oSelRanges = oDocument.createInstance(
"com.sun.star.sheet.SheetCellRanges
")
220 Function AddSelectedRangeToSelRangesEnum() as Object
221 Dim oLocRange as Object
222 osheet = oDocument.CurrentController.GetActiveSheet
223 oSelRanges = oDocument.createInstance(
"com.sun.star.sheet.SheetCellRanges
")
224 ' Check if a Currency-Range has been selected
225 oLocRange = oDocument.CurrentController.Selection
226 bPreSelected = oLocRange.SupportsService(
"com.sun.star.sheet.SheetCellRange
")
228 oSelRanges.InsertbyName(
"",oLocRange)
229 AddSelectedRangeToSelRangesEnum() = oLocRange
234 Sub GetPreSelectedRange()
236 Dim OldCurrSymbolList(
2) as String
237 Dim OldCurrIndex as Integer
238 Dim OldCurExtension(
2) as String
239 oPreSelRange = AddSelectedRangeToSelRangesEnum()
241 DialogModel.chkComplete.State = Abs(Not(bPreSelected))
243 DialogModel.optSelRange.State =
1
244 AddRangeToListbox(oPreSelRange)
246 DialogModel.optCellTemplates.State =
1
247 CreateStyleEnumeration()
249 EnableStep1DialogControls(True, bPreSelected, True)
250 DialogModel.optSelRange.Enabled = bPreSelected
254 Sub AddRangeToListbox(oLocRange as Object)
255 EmptyListBox(DialogModel.lstSelection)
256 PreName = RetrieveRangeNamefromAddress(oLocRange)
257 AddSingleItemToListbox(DialogModel.lstSelection, Prename)
',
0)
258 SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
259 TotCellCount = CountRangeCells(oLocRange)
263 Sub CheckRangeSelection(Optional oEvent)
265 AddRangeToListbox(oPreSelRange)
266 oPreSelRange = AddSelectedRangeToSelRangesEnum()
270 ' Checks if a Field (LocField) is already defined in an Array
271 ' Returns
'True
' or
'False
'
272 Function FieldinList(LocList(), MaxIndex as integer, ByVal LocField ) As Boolean
274 LocField = Ucase(LocField)
275 For i = Lbound(LocList()) to MaxIndex
276 If Ucase(LocList(i)) = LocField then
285 Function CheckLocale(oLocale) as Boolean
287 Dim LocCountry as String
288 Dim LocLanguage as String
289 LocCountry = oLocale.Country
290 LocLanguage = oLocale.Language
292 If LocLanguage = LangIDValue(CurrIndex,i,
0) AND LocCountry = LangIDValue(CurrIndex,i,
1) Then
301 Sub SetOptionValuestoNull()
303 .optCellTemplates.State =
0
304 .optSheetRanges.State =
0
305 .optDocRanges.State =
0
306 .optSelRange.State =
0
312 Sub SetStatusLineText(sStsREPROTECT as String)
313 If Not IsNull(oStatusLine) Then
314 oStatusline.SetText(sStsREPROTECT)