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