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