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