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="Misc" script:language="StarBasic">REM ***** BASIC ***** 4*cdf0e10cSrcweir 5*cdf0e10cSrcweirConst SBSHARE = 0 6*cdf0e10cSrcweirConst SBUSER = 1 7*cdf0e10cSrcweirDim Taskindex as Integer 8*cdf0e10cSrcweirDim oResSrv as Object 9*cdf0e10cSrcweir 10*cdf0e10cSrcweirSub Main() 11*cdf0e10cSrcweirDim PropList(3,1)' as String 12*cdf0e10cSrcweir PropList(0,0) = "URL" 13*cdf0e10cSrcweir PropList(0,1) = "sdbc:odbc:Erica_Test_Unicode" 14*cdf0e10cSrcweir PropList(1,0) = "User" 15*cdf0e10cSrcweir PropList(1,1) = "extra" 16*cdf0e10cSrcweir PropList(2,0) = "Password" 17*cdf0e10cSrcweir PropList(2,1) = "extra" 18*cdf0e10cSrcweir PropList(3,0) = "IsPasswordRequired" 19*cdf0e10cSrcweir PropList(3,1) = True 20*cdf0e10cSrcweirEnd Sub 21*cdf0e10cSrcweir 22*cdf0e10cSrcweir 23*cdf0e10cSrcweirFunction RegisterNewDataSource(DSName as String, PropertyList(), Optional DriverProperties() as New com.sun.star.beans.PropertyValue) 24*cdf0e10cSrcweirDim oDataSource as Object 25*cdf0e10cSrcweirDim oDBContext as Object 26*cdf0e10cSrcweirDim oPropInfo as Object 27*cdf0e10cSrcweirDim i as Integer 28*cdf0e10cSrcweir oDBContext = createUnoService("com.sun.star.sdb.DatabaseContext") 29*cdf0e10cSrcweir oDataSource = createUnoService("com.sun.star.sdb.DataSource") 30*cdf0e10cSrcweir For i = 0 To Ubound(PropertyList(), 1) 31*cdf0e10cSrcweir sPropName = PropertyList(i,0) 32*cdf0e10cSrcweir sPropValue = PropertyList(i,1) 33*cdf0e10cSrcweir oDataSource.SetPropertyValue(sPropName,sPropValue) 34*cdf0e10cSrcweir Next i 35*cdf0e10cSrcweir If Not IsMissing(DriverProperties()) Then 36*cdf0e10cSrcweir oDataSource.Info() = DriverProperties() 37*cdf0e10cSrcweir End If 38*cdf0e10cSrcweir oDBContext.RegisterObject(DSName, oDataSource) 39*cdf0e10cSrcweir RegisterNewDataSource () = oDataSource 40*cdf0e10cSrcweirEnd Function 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir' Connects to a registered Database 44*cdf0e10cSrcweirFunction ConnecttoDatabase(DSName as String, UserID as String, Password as String, Optional Propertylist(), Optional DriverProperties() as New com.sun.star.beans.PropertyValue) 45*cdf0e10cSrcweirDim oDBContext as Object 46*cdf0e10cSrcweirDim oDBSource as Object 47*cdf0e10cSrcweir' On Local Error Goto NOCONNECTION 48*cdf0e10cSrcweir oDBContext = CreateUnoService("com.sun.star.sdb.DatabaseContext") 49*cdf0e10cSrcweir If oDBContext.HasbyName(DSName) Then 50*cdf0e10cSrcweir oDBSource = oDBContext.GetByName(DSName) 51*cdf0e10cSrcweir ConnectToDatabase = oDBSource.GetConnection(UserID, Password) 52*cdf0e10cSrcweir Else 53*cdf0e10cSrcweir If Not IsMissing(Namelist()) Then 54*cdf0e10cSrcweir If Not IsMissing(DriverProperties()) Then 55*cdf0e10cSrcweir RegisterNewDataSource(DSName, PropertyList(), DriverProperties()) 56*cdf0e10cSrcweir Else 57*cdf0e10cSrcweir RegisterNewDataSource(DSName, PropertyList()) 58*cdf0e10cSrcweir End If 59*cdf0e10cSrcweir oDBSource = oDBContext.GetByName(DSName) 60*cdf0e10cSrcweir ConnectToDatabase = oDBSource.GetConnection(UserID, Password) 61*cdf0e10cSrcweir Else 62*cdf0e10cSrcweir Msgbox("DataSource " & DSName & " is not registered" , 16, GetProductname()) 63*cdf0e10cSrcweir ConnectToDatabase() = NULL 64*cdf0e10cSrcweir End If 65*cdf0e10cSrcweir End If 66*cdf0e10cSrcweirNOCONNECTION: 67*cdf0e10cSrcweir If Err <> 0 Then 68*cdf0e10cSrcweir Msgbox(Error$, 16, GetProductName()) 69*cdf0e10cSrcweir Resume LEAVESUB 70*cdf0e10cSrcweir LEAVESUB: 71*cdf0e10cSrcweir End If 72*cdf0e10cSrcweirEnd Function 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir 75*cdf0e10cSrcweirFunction GetStarOfficeLocale() as New com.sun.star.lang.Locale 76*cdf0e10cSrcweirDim aLocLocale As New com.sun.star.lang.Locale 77*cdf0e10cSrcweirDim sLocale as String 78*cdf0e10cSrcweirDim sLocaleList(1) 79*cdf0e10cSrcweirDim oMasterKey 80*cdf0e10cSrcweir oMasterKey = GetRegistryKeyContent("org.openoffice.Setup/L10N/") 81*cdf0e10cSrcweir sLocale = oMasterKey.getByName("ooLocale") 82*cdf0e10cSrcweir sLocaleList() = ArrayoutofString(sLocale, "-") 83*cdf0e10cSrcweir aLocLocale.Language = sLocaleList(0) 84*cdf0e10cSrcweir If Ubound(sLocaleList()) > 0 Then 85*cdf0e10cSrcweir aLocLocale.Country = sLocaleList(1) 86*cdf0e10cSrcweir End If 87*cdf0e10cSrcweir GetStarOfficeLocale() = aLocLocale 88*cdf0e10cSrcweirEnd Function 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir 91*cdf0e10cSrcweirFunction GetRegistryKeyContent(sKeyName as string, Optional bforUpdate as Boolean) 92*cdf0e10cSrcweirDim oConfigProvider as Object 93*cdf0e10cSrcweirDim aNodePath(0) as new com.sun.star.beans.PropertyValue 94*cdf0e10cSrcweir oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider") 95*cdf0e10cSrcweir aNodePath(0).Name = "nodepath" 96*cdf0e10cSrcweir aNodePath(0).Value = sKeyName 97*cdf0e10cSrcweir If IsMissing(bForUpdate) Then 98*cdf0e10cSrcweir GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath()) 99*cdf0e10cSrcweir Else 100*cdf0e10cSrcweir If bForUpdate Then 101*cdf0e10cSrcweir GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", aNodePath()) 102*cdf0e10cSrcweir Else 103*cdf0e10cSrcweir GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath()) 104*cdf0e10cSrcweir End If 105*cdf0e10cSrcweir End If 106*cdf0e10cSrcweirEnd Function 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir 109*cdf0e10cSrcweirFunction GetProductname() as String 110*cdf0e10cSrcweirDim oProdNameAccess as Object 111*cdf0e10cSrcweirDim sVersion as String 112*cdf0e10cSrcweirDim sProdName as String 113*cdf0e10cSrcweir oProdNameAccess = GetRegistryKeyContent("org.openoffice.Setup/Product") 114*cdf0e10cSrcweir sProdName = oProdNameAccess.getByName("ooName") 115*cdf0e10cSrcweir sVersion = oProdNameAccess.getByName("ooSetupVersion") 116*cdf0e10cSrcweir GetProductName = sProdName & sVersion 117*cdf0e10cSrcweirEnd Function 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir' Opens a Document, checks beforehand, wether it has to be loaded 121*cdf0e10cSrcweir' or wether it is already on the desktop. 122*cdf0e10cSrcweir' If the parameter bDisposable is set to False then then returned document 123*cdf0e10cSrcweir' should not be disposed afterwards, because it is already opened. 124*cdf0e10cSrcweirFunction OpenDocument(DocPath as String, Args(), Optional bDisposable as Boolean) 125*cdf0e10cSrcweirDim oComponents as Object 126*cdf0e10cSrcweirDim oComponent as Object 127*cdf0e10cSrcweir ' Search if one of the active Components ist the one that you search for 128*cdf0e10cSrcweir oComponents = StarDesktop.Components.CreateEnumeration 129*cdf0e10cSrcweir While oComponents.HasmoreElements 130*cdf0e10cSrcweir oComponent = oComponents.NextElement 131*cdf0e10cSrcweir If hasUnoInterfaces(oComponent,"com.sun.star.frame.XModel") then 132*cdf0e10cSrcweir If UCase(oComponent.URL) = UCase(DocPath) then 133*cdf0e10cSrcweir OpenDocument() = oComponent 134*cdf0e10cSrcweir If Not IsMissing(bDisposable) Then 135*cdf0e10cSrcweir bDisposable = False 136*cdf0e10cSrcweir End If 137*cdf0e10cSrcweir Exit Function 138*cdf0e10cSrcweir End If 139*cdf0e10cSrcweir End If 140*cdf0e10cSrcweir Wend 141*cdf0e10cSrcweir If Not IsMissing(bDisposable) Then 142*cdf0e10cSrcweir bDisposable = True 143*cdf0e10cSrcweir End If 144*cdf0e10cSrcweir OpenDocument() = StarDesktop.LoadComponentFromURL(DocPath,"_default",0,Args()) 145*cdf0e10cSrcweirEnd Function 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir 148*cdf0e10cSrcweirFunction TaskonDesktop(DocPath as String) as Boolean 149*cdf0e10cSrcweirDim oComponents as Object 150*cdf0e10cSrcweirDim oComponent as Object 151*cdf0e10cSrcweir ' Search if one of the active Components ist the one that you search for 152*cdf0e10cSrcweir oComponents = StarDesktop.Components.CreateEnumeration 153*cdf0e10cSrcweir While oComponents.HasmoreElements 154*cdf0e10cSrcweir oComponent = oComponents.NextElement 155*cdf0e10cSrcweir If hasUnoInterfaces(oComponent,"com.sun.star.frame.XModel") then 156*cdf0e10cSrcweir If UCase(oComponent.URL) = UCase(DocPath) then 157*cdf0e10cSrcweir TaskonDesktop = True 158*cdf0e10cSrcweir Exit Function 159*cdf0e10cSrcweir End If 160*cdf0e10cSrcweir End If 161*cdf0e10cSrcweir Wend 162*cdf0e10cSrcweir TaskonDesktop = False 163*cdf0e10cSrcweirEnd Function 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir' Retrieves a FileName out of a StarOffice-Document 167*cdf0e10cSrcweirFunction RetrieveFileName(LocDoc as Object) 168*cdf0e10cSrcweirDim LocURL as String 169*cdf0e10cSrcweirDim LocURLArray() as String 170*cdf0e10cSrcweirDim MaxArrIndex as integer 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir LocURL = LocDoc.Url 173*cdf0e10cSrcweir LocURLArray() = ArrayoutofString(LocURL,"/",MaxArrIndex) 174*cdf0e10cSrcweir RetrieveFileName = LocURLArray(MaxArrIndex) 175*cdf0e10cSrcweirEnd Function 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir' Gets a special configured PathSetting 179*cdf0e10cSrcweirFunction GetPathSettings(sPathType as String, Optional bshowall as Boolean, Optional ListIndex as integer) as String 180*cdf0e10cSrcweirDim oSettings, oPathSettings as Object 181*cdf0e10cSrcweirDim sPath as String 182*cdf0e10cSrcweirDim PathList() as String 183*cdf0e10cSrcweirDim MaxIndex as Integer 184*cdf0e10cSrcweirDim oPS as Object 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir oPS = createUnoService("com.sun.star.util.PathSettings") 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir If Not IsMissing(bShowall) Then 189*cdf0e10cSrcweir If bShowAll Then 190*cdf0e10cSrcweir ShowPropertyValues(oPS) 191*cdf0e10cSrcweir Exit Function 192*cdf0e10cSrcweir End If 193*cdf0e10cSrcweir End If 194*cdf0e10cSrcweir sPath = oPS.getPropertyValue(sPathType) 195*cdf0e10cSrcweir If Not IsMissing(ListIndex) Then 196*cdf0e10cSrcweir ' Share and User-Directory 197*cdf0e10cSrcweir If Instr(1,sPath,";") <> 0 Then 198*cdf0e10cSrcweir PathList = ArrayoutofString(sPath,";", MaxIndex) 199*cdf0e10cSrcweir If ListIndex <= MaxIndex Then 200*cdf0e10cSrcweir sPath = PathList(ListIndex) 201*cdf0e10cSrcweir Else 202*cdf0e10cSrcweir Msgbox("String Cannot be analyzed!" & sPath , 16, GetProductName()) 203*cdf0e10cSrcweir End If 204*cdf0e10cSrcweir End If 205*cdf0e10cSrcweir End If 206*cdf0e10cSrcweir If Instr(1, sPath, ";") = 0 Then 207*cdf0e10cSrcweir GetPathSettings = ConvertToUrl(sPath) 208*cdf0e10cSrcweir Else 209*cdf0e10cSrcweir GetPathSettings = sPath 210*cdf0e10cSrcweir End If 211*cdf0e10cSrcweir 212*cdf0e10cSrcweirEnd Function 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir' Gets the fully qualified path to a subdirectory of the 217*cdf0e10cSrcweir' Template Directory, e. g. with the parameter "wizard/bitmap" 218*cdf0e10cSrcweir' The parameter must be passed over in Url-scription 219*cdf0e10cSrcweir' The return-Value is in Urlscription 220*cdf0e10cSrcweirFunction GetOfficeSubPath(sOfficePath as String, ByVal sSubDir as String) 221*cdf0e10cSrcweirDim sOfficeString as String 222*cdf0e10cSrcweirDim sOfficeList() as String 223*cdf0e10cSrcweirDim sOfficeDir as String 224*cdf0e10cSrcweirDim sBigDir as String 225*cdf0e10cSrcweirDim i as Integer 226*cdf0e10cSrcweirDim MaxIndex as Integer 227*cdf0e10cSrcweirDim oUcb as Object 228*cdf0e10cSrcweir oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess") 229*cdf0e10cSrcweir sOfficeString = GetPathSettings(sOfficePath) 230*cdf0e10cSrcweir If Right(sSubDir,1) <> "/" Then 231*cdf0e10cSrcweir sSubDir = sSubDir & "/" 232*cdf0e10cSrcweir End If 233*cdf0e10cSrcweir sOfficeList() = ArrayoutofString(sOfficeString,";", MaxIndex) 234*cdf0e10cSrcweir For i = 0 To MaxIndex 235*cdf0e10cSrcweir sOfficeDir = ConvertToUrl(sOfficeList(i)) 236*cdf0e10cSrcweir If Right(sOfficeDir,1) <> "/" Then 237*cdf0e10cSrcweir sOfficeDir = sOfficeDir & "/" 238*cdf0e10cSrcweir End If 239*cdf0e10cSrcweir sBigDir = sOfficeDir & sSubDir 240*cdf0e10cSrcweir If oUcb.Exists(sBigDir) Then 241*cdf0e10cSrcweir GetOfficeSubPath() = sBigDir 242*cdf0e10cSrcweir Exit Function 243*cdf0e10cSrcweir End If 244*cdf0e10cSrcweir Next i 245*cdf0e10cSrcweir ShowNoOfficePathError() 246*cdf0e10cSrcweir GetOfficeSubPath = "" 247*cdf0e10cSrcweirEnd Function 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir 250*cdf0e10cSrcweirSub ShowNoOfficePathError() 251*cdf0e10cSrcweirDim ProductName as String 252*cdf0e10cSrcweirDim sError as String 253*cdf0e10cSrcweirDim bResObjectexists as Boolean 254*cdf0e10cSrcweirDim oLocResSrv as Object 255*cdf0e10cSrcweir bResObjectexists = not IsNull(oResSrv) 256*cdf0e10cSrcweir If bResObjectexists Then 257*cdf0e10cSrcweir oLocResSrv = oResSrv 258*cdf0e10cSrcweir End If 259*cdf0e10cSrcweir If InitResources("Tools", "com") Then 260*cdf0e10cSrcweir ProductName = GetProductName() 261*cdf0e10cSrcweir sError = GetResText(1006) 262*cdf0e10cSrcweir sError = ReplaceString(sError, ProductName, "%PRODUCTNAME") 263*cdf0e10cSrcweir sError = ReplaceString(sError, chr(13), "<BR>") 264*cdf0e10cSrcweir MsgBox(sError, 16, ProductName) 265*cdf0e10cSrcweir End If 266*cdf0e10cSrcweir If bResObjectexists Then 267*cdf0e10cSrcweir oResSrv = oLocResSrv 268*cdf0e10cSrcweir End If 269*cdf0e10cSrcweir 270*cdf0e10cSrcweirEnd Sub 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir 273*cdf0e10cSrcweirFunction InitResources(Description, ShortDescription as String) as boolean 274*cdf0e10cSrcweir On Error Goto ErrorOcurred 275*cdf0e10cSrcweir oResSrv = createUnoService( "com.sun.star.resource.VclStringResourceLoader" ) 276*cdf0e10cSrcweir If (IsNull(oResSrv)) then 277*cdf0e10cSrcweir InitResources = FALSE 278*cdf0e10cSrcweir MsgBox( Description & ": No resource loader found", 16, GetProductName()) 279*cdf0e10cSrcweir Else 280*cdf0e10cSrcweir InitResources = TRUE 281*cdf0e10cSrcweir oResSrv.FileName = ShortDescription 282*cdf0e10cSrcweir End If 283*cdf0e10cSrcweir Exit Function 284*cdf0e10cSrcweirErrorOcurred: 285*cdf0e10cSrcweir Dim nSolarVer 286*cdf0e10cSrcweir InitResources = FALSE 287*cdf0e10cSrcweir nSolarVer = GetSolarVersion() 288*cdf0e10cSrcweir MsgBox("Resource file missing (" & ShortDescription & trim(str(nSolarVer)) + "*.res)", 16, GetProductName()) 289*cdf0e10cSrcweir Resume CLERROR 290*cdf0e10cSrcweir CLERROR: 291*cdf0e10cSrcweirEnd Function 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir 294*cdf0e10cSrcweirFunction GetResText( nID as integer ) As string 295*cdf0e10cSrcweir On Error Goto ErrorOcurred 296*cdf0e10cSrcweir If Not IsNull(oResSrv) Then 297*cdf0e10cSrcweir GetResText = oResSrv.getString( nID ) 298*cdf0e10cSrcweir Else 299*cdf0e10cSrcweir GetResText = "" 300*cdf0e10cSrcweir End If 301*cdf0e10cSrcweir Exit Function 302*cdf0e10cSrcweirErrorOcurred: 303*cdf0e10cSrcweir GetResText = "" 304*cdf0e10cSrcweir MsgBox("Resource with ID =" + str( nID ) + " not found!", 16, GetProductName()) 305*cdf0e10cSrcweir Resume CLERROR 306*cdf0e10cSrcweir CLERROR: 307*cdf0e10cSrcweirEnd Function 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir 310*cdf0e10cSrcweirFunction CutPathView(sDocUrl as String, Optional PathLen as Integer) 311*cdf0e10cSrcweirDim sViewPath as String 312*cdf0e10cSrcweirDim FileName as String 313*cdf0e10cSrcweirDim iFileLen as Integer 314*cdf0e10cSrcweir sViewPath = ConvertfromURL(sDocURL) 315*cdf0e10cSrcweir iViewPathLen = Len(sViewPath) 316*cdf0e10cSrcweir If iViewPathLen > 60 Then 317*cdf0e10cSrcweir FileName = FileNameoutofPath(sViewPath, "/") 318*cdf0e10cSrcweir iFileLen = Len(FileName) 319*cdf0e10cSrcweir If iFileLen < 44 Then 320*cdf0e10cSrcweir sViewPath = Left(sViewPath,57-iFileLen-10) & "..." & Right(sViewPath,iFileLen + 10) 321*cdf0e10cSrcweir Else 322*cdf0e10cSrcweir sViewPath = Left(sViewPath,27) & " ... " & Right(sViewPath,28) 323*cdf0e10cSrcweir End If 324*cdf0e10cSrcweir End If 325*cdf0e10cSrcweir CutPathView = sViewPath 326*cdf0e10cSrcweirEnd Function 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir' Deletes the content of all cells that are softformatted according 330*cdf0e10cSrcweir' to the 'InputStyleName' 331*cdf0e10cSrcweirSub DeleteInputCells(oSheet as Object, InputStyleName as String) 332*cdf0e10cSrcweirDim oRanges as Object 333*cdf0e10cSrcweirDim oRange as Object 334*cdf0e10cSrcweir oRanges = oSheet.CellFormatRanges.createEnumeration 335*cdf0e10cSrcweir While oRanges.hasMoreElements 336*cdf0e10cSrcweir oRange = oRanges.NextElement 337*cdf0e10cSrcweir If Instr(1,oRange.CellStyle, InputStyleName) <> 0 Then 338*cdf0e10cSrcweir Call ReplaceRangeValues(oRange, "") 339*cdf0e10cSrcweir End If 340*cdf0e10cSrcweir Wend 341*cdf0e10cSrcweirEnd Sub 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir' Inserts a certain String to all cells of a Range that ist passed over 345*cdf0e10cSrcweir' either as an object or as the RangeName 346*cdf0e10cSrcweirSub ChangeValueofRange(oSheet as Object, Range, ReplaceValue, Optional StyleName as String) 347*cdf0e10cSrcweirDim oCellRange as Object 348*cdf0e10cSrcweir If Vartype(Range) = 8 Then 349*cdf0e10cSrcweir ' Get the Range out of the Rangename 350*cdf0e10cSrcweir oCellRange = oSheet.GetCellRangeByName(Range) 351*cdf0e10cSrcweir Else 352*cdf0e10cSrcweir ' The range is passed over as an object 353*cdf0e10cSrcweir Set oCellRange = Range 354*cdf0e10cSrcweir End If 355*cdf0e10cSrcweir If IsMissing(StyleName) Then 356*cdf0e10cSrcweir ReplaceRangeValues(oCellRange, ReplaceValue) 357*cdf0e10cSrcweir Else 358*cdf0e10cSrcweir If Instr(1,oCellRange.CellStyle,StyleName) Then 359*cdf0e10cSrcweir ReplaceRangeValues(oCellRange, ReplaceValue) 360*cdf0e10cSrcweir End If 361*cdf0e10cSrcweir End If 362*cdf0e10cSrcweirEnd Sub 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir 365*cdf0e10cSrcweirSub ReplaceRangeValues(oRange as Object, ReplaceValue) 366*cdf0e10cSrcweirDim oRangeAddress as Object 367*cdf0e10cSrcweirDim ColCount as Integer 368*cdf0e10cSrcweirDim RowCount as Integer 369*cdf0e10cSrcweirDim i as Integer 370*cdf0e10cSrcweir oRangeAddress = oRange.RangeAddress 371*cdf0e10cSrcweir ColCount = oRangeAddress.EndColumn - oRangeAddress.StartColumn 372*cdf0e10cSrcweir RowCount = oRangeAddress.EndRow - oRangeAddress.StartRow 373*cdf0e10cSrcweir Dim FillArray(RowCount) as Variant 374*cdf0e10cSrcweir Dim sLine(ColCount) as Variant 375*cdf0e10cSrcweir For i = 0 To ColCount 376*cdf0e10cSrcweir sLine(i) = ReplaceValue 377*cdf0e10cSrcweir Next i 378*cdf0e10cSrcweir For i = 0 To RowCount 379*cdf0e10cSrcweir FillArray(i) = sLine() 380*cdf0e10cSrcweir Next i 381*cdf0e10cSrcweir oRange.DataArray = FillArray() 382*cdf0e10cSrcweirEnd Sub 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir' Returns the Value of the first cell of a Range 386*cdf0e10cSrcweirFunction GetValueofCellbyName(oSheet as Object, sCellName as String) 387*cdf0e10cSrcweirDim oCell as Object 388*cdf0e10cSrcweir oCell = GetCellByName(oSheet, sCellName) 389*cdf0e10cSrcweir GetValueofCellbyName = oCell.Value 390*cdf0e10cSrcweirEnd Function 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir 393*cdf0e10cSrcweirFunction DuplicateRow(oSheet as Object, RangeName as String) 394*cdf0e10cSrcweirDim oRange as Object 395*cdf0e10cSrcweirDim oCell as Object 396*cdf0e10cSrcweirDim oCellAddress as New com.sun.star.table.CellAddress 397*cdf0e10cSrcweirDim oRangeAddress as New com.sun.star.table.CellRangeAddress 398*cdf0e10cSrcweir oRange = oSheet.GetCellRangeByName(RangeName) 399*cdf0e10cSrcweir oRangeAddress = oRange.RangeAddress 400*cdf0e10cSrcweir oCell = oSheet.GetCellByPosition(oRangeAddress.StartColumn,oRangeAddress.StartRow) 401*cdf0e10cSrcweir oCellAddress = oCell.CellAddress 402*cdf0e10cSrcweir oSheet.Rows.InsertByIndex(oCellAddress.Row,1) 403*cdf0e10cSrcweir oRangeAddress = oRange.RangeAddress 404*cdf0e10cSrcweir oSheet.CopyRange(oCellAddress, oRangeAddress) 405*cdf0e10cSrcweir DuplicateRow = oRangeAddress.StartRow-1 406*cdf0e10cSrcweirEnd Function 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir' Returns the String of the first cell of a Range 410*cdf0e10cSrcweirFunction GetStringofCellbyName(oSheet as Object, sCellName as String) 411*cdf0e10cSrcweirDim oCell as Object 412*cdf0e10cSrcweir oCell = GetCellByName(oSheet, sCellName) 413*cdf0e10cSrcweir GetStringofCellbyName = oCell.String 414*cdf0e10cSrcweirEnd Function 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir' Returns a named Cell 418*cdf0e10cSrcweirFunction GetCellByName(oSheet as Object, sCellName as String) as Object 419*cdf0e10cSrcweirDim oCellRange as Object 420*cdf0e10cSrcweirDim oCellAddress as Object 421*cdf0e10cSrcweir oCellRange = oSheet.GetCellRangeByName(sCellName) 422*cdf0e10cSrcweir oCellAddress = oCellRange.RangeAddress 423*cdf0e10cSrcweir GetCellByName = oSheet.GetCellByPosition(oCellAddress.StartColumn,oCellAddress.StartRow) 424*cdf0e10cSrcweirEnd Function 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir' Changes the numeric Value of a cell by transmitting the String of the numeric Value 428*cdf0e10cSrcweirSub ChangeCellValue(oCell as Object, ValueString as String) 429*cdf0e10cSrcweirDim CellValue 430*cdf0e10cSrcweir oCell.Formula = "=Value(" & """" & ValueString & """" & ")" 431*cdf0e10cSrcweir CellValue = oCell.Value 432*cdf0e10cSrcweir oCell.Formula = "" 433*cdf0e10cSrcweir oCell.Value = CellValue 434*cdf0e10cSrcweirEnd Sub 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir 437*cdf0e10cSrcweirFunction GetDocumentType(oDocument) 438*cdf0e10cSrcweir On Local Error GoTo NODOCUMENTTYPE 439*cdf0e10cSrcweir' ShowSupportedServiceNames(oDocument) 440*cdf0e10cSrcweir If oDocument.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then 441*cdf0e10cSrcweir GetDocumentType() = "scalc" 442*cdf0e10cSrcweir ElseIf oDocument.SupportsService("com.sun.star.text.TextDocument") Then 443*cdf0e10cSrcweir GetDocumentType() = "swriter" 444*cdf0e10cSrcweir ElseIf oDocument.SupportsService("com.sun.star.drawing.DrawingDocument") Then 445*cdf0e10cSrcweir GetDocumentType() = "sdraw" 446*cdf0e10cSrcweir ElseIf oDocument.SupportsService("com.sun.star.presentation.PresentationDocument") Then 447*cdf0e10cSrcweir GetDocumentType() = "simpress" 448*cdf0e10cSrcweir ElseIf oDocument.SupportsService("com.sun.star.formula.FormulaProperties") Then 449*cdf0e10cSrcweir GetDocumentType() = "smath" 450*cdf0e10cSrcweir End If 451*cdf0e10cSrcweir NODOCUMENTTYPE: 452*cdf0e10cSrcweir If Err <> 0 Then 453*cdf0e10cSrcweir GetDocumentType = "" 454*cdf0e10cSrcweir Resume GOON 455*cdf0e10cSrcweir GOON: 456*cdf0e10cSrcweir End If 457*cdf0e10cSrcweirEnd Function 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir 460*cdf0e10cSrcweirFunction GetNumberFormatType(oDocFormats, oFormatObject as Object) as Integer 461*cdf0e10cSrcweirDim ThisFormatKey as Long 462*cdf0e10cSrcweirDim oObjectFormat as Object 463*cdf0e10cSrcweir On Local Error Goto NOFORMAT 464*cdf0e10cSrcweir ThisFormatKey = oFormatObject.NumberFormat 465*cdf0e10cSrcweir oObjectFormat = oDocFormats.GetByKey(ThisFormatKey) 466*cdf0e10cSrcweir GetNumberFormatType = oObjectFormat.Type 467*cdf0e10cSrcweir NOFORMAT: 468*cdf0e10cSrcweir If Err <> 0 Then 469*cdf0e10cSrcweir Msgbox("Numberformat of Object is not available!", 16, GetProductName()) 470*cdf0e10cSrcweir GetNumberFormatType = 0 471*cdf0e10cSrcweir GOTO NOERROR 472*cdf0e10cSrcweir End If 473*cdf0e10cSrcweir NOERROR: 474*cdf0e10cSrcweir On Local Error Goto 0 475*cdf0e10cSrcweirEnd Function 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir 478*cdf0e10cSrcweirSub ProtectSheets(Optional oSheets as Object) 479*cdf0e10cSrcweirDim i as Integer 480*cdf0e10cSrcweirDim oDocSheets as Object 481*cdf0e10cSrcweir If IsMissing(oSheets) Then 482*cdf0e10cSrcweir oDocSheets = StarDesktop.CurrentFrame.Controller.Model.Sheets 483*cdf0e10cSrcweir Else 484*cdf0e10cSrcweir Set oDocSheets = oSheets 485*cdf0e10cSrcweir End If 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir For i = 0 To oDocSheets.Count-1 488*cdf0e10cSrcweir oDocSheets(i).Protect("") 489*cdf0e10cSrcweir Next i 490*cdf0e10cSrcweirEnd Sub 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir 493*cdf0e10cSrcweirSub UnprotectSheets(Optional oSheets as Object) 494*cdf0e10cSrcweirDim i as Integer 495*cdf0e10cSrcweirDim oDocSheets as Object 496*cdf0e10cSrcweir If IsMissing(oSheets) Then 497*cdf0e10cSrcweir oDocSheets = StarDesktop.CurrentFrame.Controller.Model.Sheets 498*cdf0e10cSrcweir Else 499*cdf0e10cSrcweir Set oDocSheets = oSheets 500*cdf0e10cSrcweir End If 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir For i = 0 To oDocSheets.Count-1 503*cdf0e10cSrcweir oDocSheets(i).Unprotect("") 504*cdf0e10cSrcweir Next i 505*cdf0e10cSrcweirEnd Sub 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir 508*cdf0e10cSrcweirFunction GetRowIndex(oSheet as Object, RowName as String) 509*cdf0e10cSrcweirDim oRange as Object 510*cdf0e10cSrcweir oRange = oSheet.GetCellRangeByName(RowName) 511*cdf0e10cSrcweir GetRowIndex = oRange.RangeAddress.StartRow 512*cdf0e10cSrcweirEnd Function 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir 515*cdf0e10cSrcweirFunction GetColumnIndex(oSheet as Object, ColName as String) 516*cdf0e10cSrcweirDim oRange as Object 517*cdf0e10cSrcweir oRange = oSheet.GetCellRangeByName(ColName) 518*cdf0e10cSrcweir GetColumnIndex = oRange.RangeAddress.StartColumn 519*cdf0e10cSrcweirEnd Function 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir 522*cdf0e10cSrcweirFunction CopySheetbyName(oSheets as Object, OldName as String, NewName as String, DestPos as Integer) as Object 523*cdf0e10cSrcweirDim oSheet as Object 524*cdf0e10cSrcweirDim Count as Integer 525*cdf0e10cSrcweirDim BasicSheetName as String 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir BasicSheetName = NewName 528*cdf0e10cSrcweir ' Copy the last table. Assumption: The last table is the template 529*cdf0e10cSrcweir On Local Error Goto RENAMESHEET 530*cdf0e10cSrcweir oSheets.CopybyName(OldName, NewName, DestPos) 531*cdf0e10cSrcweir 532*cdf0e10cSrcweirRENAMESHEET: 533*cdf0e10cSrcweir oSheet = oSheets(DestPos) 534*cdf0e10cSrcweir If Err <> 0 Then 535*cdf0e10cSrcweir ' Test if renaming failed 536*cdf0e10cSrcweir Count = 2 537*cdf0e10cSrcweir Do While oSheet.Name <> NewName 538*cdf0e10cSrcweir NewName = BasicSheetName & "_" & Count 539*cdf0e10cSrcweir oSheet.Name = NewName 540*cdf0e10cSrcweir Count = Count + 1 541*cdf0e10cSrcweir Loop 542*cdf0e10cSrcweir Resume CL_ERROR 543*cdf0e10cSrcweirCL_ERROR: 544*cdf0e10cSrcweir End If 545*cdf0e10cSrcweir CopySheetbyName = oSheet 546*cdf0e10cSrcweirEnd Function 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir' Dis-or enables a Window and adjusts the mousepointer accordingly 550*cdf0e10cSrcweirSub ToggleWindow(bDoEnable as Boolean) 551*cdf0e10cSrcweirDim oWindow as Object 552*cdf0e10cSrcweir oWindow = StarDesktop.CurrentFrame.ComponentWindow 553*cdf0e10cSrcweir oWindow.Enable = bDoEnable 554*cdf0e10cSrcweirEnd Sub 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir 557*cdf0e10cSrcweirFunction CheckNewSheetname(oSheets as Object, Sheetname as String, Optional oLocale) as String 558*cdf0e10cSrcweirDim nStartFlags as Long 559*cdf0e10cSrcweirDim nContFlags as Long 560*cdf0e10cSrcweirDim oCharService as Object 561*cdf0e10cSrcweirDim iSheetNameLength as Integer 562*cdf0e10cSrcweirDim iResultPos as Integer 563*cdf0e10cSrcweirDim WrongChar as String 564*cdf0e10cSrcweirDim oResult as Object 565*cdf0e10cSrcweir nStartFlags = com.sun.star.i18n.KParseTokens.ANY_LETTER_OR_NUMBER + com.sun.star.i18n.KParseTokens.ASC_UNDERSCORE 566*cdf0e10cSrcweir nContFlags = nStartFlags 567*cdf0e10cSrcweir oCharService = CreateUnoService("com.sun.star.i18n.CharacterClassification") 568*cdf0e10cSrcweir iSheetNameLength = Len(SheetName) 569*cdf0e10cSrcweir If IsMissing(oLocale) Then 570*cdf0e10cSrcweir oLocale = ThisComponent.CharLocale 571*cdf0e10cSrcweir End If 572*cdf0e10cSrcweir Do 573*cdf0e10cSrcweir oResult =oCharService.parsePredefinedToken(com.sun.star.i18n.KParseType.IDENTNAME, SheetName, 0, oLocale, nStartFlags, "", nContFlags, " ") 574*cdf0e10cSrcweir iResultPos = oResult.EndPos 575*cdf0e10cSrcweir If iResultPos < iSheetNameLength Then 576*cdf0e10cSrcweir WrongChar = Mid(SheetName, iResultPos+1,1) 577*cdf0e10cSrcweir SheetName = ReplaceString(SheetName,"_", WrongChar) 578*cdf0e10cSrcweir End If 579*cdf0e10cSrcweir Loop Until iResultPos = iSheetNameLength 580*cdf0e10cSrcweir CheckNewSheetname = SheetName 581*cdf0e10cSrcweirEnd Function 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir 584*cdf0e10cSrcweirSub AddNewSheetName(oSheets as Object, ByVal SheetName as String) 585*cdf0e10cSrcweirDim Count as Integer 586*cdf0e10cSrcweirDim bSheetIsThere as Boolean 587*cdf0e10cSrcweirDim iSheetNameLength as Integer 588*cdf0e10cSrcweir iSheetNameLength = Len(SheetName) 589*cdf0e10cSrcweir Count = 2 590*cdf0e10cSrcweir Do 591*cdf0e10cSrcweir bSheetIsThere = oSheets.HasByName(SheetName) 592*cdf0e10cSrcweir If bSheetIsThere Then 593*cdf0e10cSrcweir SheetName = Right(SheetName,iSheetNameLength) & "_" & Count 594*cdf0e10cSrcweir Count = Count + 1 595*cdf0e10cSrcweir End If 596*cdf0e10cSrcweir Loop Until Not bSheetIsThere 597*cdf0e10cSrcweir AddNewSheetname = SheetName 598*cdf0e10cSrcweirEnd Sub 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir 601*cdf0e10cSrcweirFunction GetSheetIndex(oSheets, sName) as Integer 602*cdf0e10cSrcweirDim i as Integer 603*cdf0e10cSrcweir For i = 0 To oSheets.Count-1 604*cdf0e10cSrcweir If oSheets(i).Name = sName Then 605*cdf0e10cSrcweir GetSheetIndex = i 606*cdf0e10cSrcweir exit Function 607*cdf0e10cSrcweir End If 608*cdf0e10cSrcweir Next i 609*cdf0e10cSrcweir GetSheetIndex = -1 610*cdf0e10cSrcweirEnd Function 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir 613*cdf0e10cSrcweirFunction GetLastUsedRow(oSheet as Object) as Integer 614*cdf0e10cSrcweirDim oCell As Object 615*cdf0e10cSrcweirDim oCursor As Object 616*cdf0e10cSrcweirDim aAddress As Variant 617*cdf0e10cSrcweir oCell = oSheet.GetCellbyPosition(0, 0) 618*cdf0e10cSrcweir oCursor = oSheet.createCursorByRange(oCell) 619*cdf0e10cSrcweir oCursor.GotoEndOfUsedArea(True) 620*cdf0e10cSrcweir aAddress = oCursor.RangeAddress 621*cdf0e10cSrcweir GetLastUsedRow = aAddress.EndRow 622*cdf0e10cSrcweirEnd Function 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir' Note To set a one lined frame you have to set the inner width to 0 626*cdf0e10cSrcweir' In the API all Units that refer to pt-Heights are "1/100mm" 627*cdf0e10cSrcweir' The convert factor from 1pt to 1/100 mm is approximately 35 628*cdf0e10cSrcweirFunction ModifyBorderLineWidth(ByVal oStyleBorder, iInnerLineWidth as Integer, iOuterLineWidth as Integer) 629*cdf0e10cSrcweirDim aBorder as New com.sun.star.table.BorderLine 630*cdf0e10cSrcweir aBorder = oStyleBorder 631*cdf0e10cSrcweir aBorder.InnerLineWidth = iInnerLineWidth 632*cdf0e10cSrcweir aBorder.OuterLineWidth = iOuterLineWidth 633*cdf0e10cSrcweir ModifyBorderLineWidth = aBorder 634*cdf0e10cSrcweirEnd Function 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir 637*cdf0e10cSrcweirSub AttachBasicMacroToEvent(oDocument as Object, EventName as String, SubPath as String) 638*cdf0e10cSrcweirDim PropValue(1) as new com.sun.star.beans.PropertyValue 639*cdf0e10cSrcweir PropValue(0).Name = "EventType" 640*cdf0e10cSrcweir PropValue(0).Value = "StarBasic" 641*cdf0e10cSrcweir PropValue(1).Name = "Script" 642*cdf0e10cSrcweir PropValue(1).Value = "macro:///" & SubPath 643*cdf0e10cSrcweir oDocument.Events.ReplaceByName(EventName, PropValue()) 644*cdf0e10cSrcweirEnd Sub 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir 647*cdf0e10cSrcweir 648*cdf0e10cSrcweirFunction ModifyPropertyValue(oContent() as New com.sun.star.beans.PropertyValue, TargetProperties() as New com.sun.star.beans.PropertyValue) 649*cdf0e10cSrcweirDim MaxIndex as Integer 650*cdf0e10cSrcweirDim i as Integer 651*cdf0e10cSrcweirDim a as Integer 652*cdf0e10cSrcweir MaxIndex = Ubound(oContent()) 653*cdf0e10cSrcweir bDoReplace = False 654*cdf0e10cSrcweir For i = 0 To MaxIndex 655*cdf0e10cSrcweir a = GetPropertyValueIndex(oContent(i).Name, TargetProperties()) 656*cdf0e10cSrcweir If a <> -1 Then 657*cdf0e10cSrcweir If Vartype(TargetProperties(a).Value) <> 9 Then 658*cdf0e10cSrcweir If TargetProperties(a).Value <> oContent(i).Value Then 659*cdf0e10cSrcweir oContent(i).Value = TargetProperties(a).Value 660*cdf0e10cSrcweir bDoReplace = True 661*cdf0e10cSrcweir End If 662*cdf0e10cSrcweir Else 663*cdf0e10cSrcweir If Not EqualUnoObjects(TargetProperties(a).Value, oContent(i).Value) Then 664*cdf0e10cSrcweir oContent(i).Value = TargetProperties(a).Value 665*cdf0e10cSrcweir bDoReplace = True 666*cdf0e10cSrcweir End If 667*cdf0e10cSrcweir End If 668*cdf0e10cSrcweir End If 669*cdf0e10cSrcweir Next i 670*cdf0e10cSrcweir ModifyPropertyValue() = bDoReplace 671*cdf0e10cSrcweirEnd Function 672*cdf0e10cSrcweir 673*cdf0e10cSrcweir 674*cdf0e10cSrcweirFunction GetPropertyValueIndex(SearchName as String, TargetProperties() as New com.sun.star.beans.PropertyValue ) as Integer 675*cdf0e10cSrcweirDim i as Integer 676*cdf0e10cSrcweir For i = 0 To Ubound(TargetProperties()) 677*cdf0e10cSrcweir If Searchname = TargetProperties(i).Name Then 678*cdf0e10cSrcweir GetPropertyValueIndex = i 679*cdf0e10cSrcweir Exit Function 680*cdf0e10cSrcweir End If 681*cdf0e10cSrcweir Next i 682*cdf0e10cSrcweir GetPropertyValueIndex() = -1 683*cdf0e10cSrcweirEnd Function 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir 686*cdf0e10cSrcweirSub DispatchSlot(SlotID as Integer) 687*cdf0e10cSrcweirDim oArg() as new com.sun.star.beans.PropertyValue 688*cdf0e10cSrcweirDim oUrl as new com.sun.star.util.URL 689*cdf0e10cSrcweirDim oTrans as Object 690*cdf0e10cSrcweirDim oDisp as Object 691*cdf0e10cSrcweir oTrans = createUNOService("com.sun.star.util.URLTransformer") 692*cdf0e10cSrcweir oUrl.Complete = "slot:" & CStr(SlotID) 693*cdf0e10cSrcweir oTrans.parsestrict(oUrl) 694*cdf0e10cSrcweir oDisp = StarDesktop.ActiveFrame.queryDispatch(oUrl, "_self", 0) 695*cdf0e10cSrcweir oDisp.dispatch(oUrl, oArg()) 696*cdf0e10cSrcweirEnd Sub 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir 699*cdf0e10cSrcweir'returns the type of the office application 700*cdf0e10cSrcweir'FatOffice = 0, WebTop = 1 701*cdf0e10cSrcweir'This routine has to be changed if the Product Name is being changed! 702*cdf0e10cSrcweirFunction IsFatOffice() As Boolean 703*cdf0e10cSrcweir If sProductname = "" Then 704*cdf0e10cSrcweir sProductname = GetProductname() 705*cdf0e10cSrcweir End If 706*cdf0e10cSrcweir IsFatOffice = TRUE 707*cdf0e10cSrcweir 'The following line has to include the current productname 708*cdf0e10cSrcweir If Instr(1,sProductname,"WebTop",1) <> 0 Then 709*cdf0e10cSrcweir IsFatOffice = FALSE 710*cdf0e10cSrcweir End If 711*cdf0e10cSrcweirEnd Function 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir 714*cdf0e10cSrcweirFunction GetLocale(sLanguage as String, sCountry as String) 715*cdf0e10cSrcweirDim oLocale as New com.sun.star.lang.Locale 716*cdf0e10cSrcweir oLocale.Language = sLanguage 717*cdf0e10cSrcweir oLocale.Country = sCountry 718*cdf0e10cSrcweir GetLocale = oLocale 719*cdf0e10cSrcweirEnd Function 720*cdf0e10cSrcweir 721*cdf0e10cSrcweir 722*cdf0e10cSrcweirSub ToggleDesignMode(oDocument as Object) 723*cdf0e10cSrcweirDim aSwitchMode as new com.sun.star.util.URL 724*cdf0e10cSrcweir aSwitchMode.Complete = ".uno:SwitchControlDesignMode" 725*cdf0e10cSrcweir aTransformer = createUnoService("com.sun.star.util.URLTransformer") 726*cdf0e10cSrcweir aTransformer.parseStrict(aSwitchMode) 727*cdf0e10cSrcweir oFrame = oDocument.currentController.Frame 728*cdf0e10cSrcweir oDispatch = oFrame.queryDispatch(aSwitchMode, oFrame.Name, 63) 729*cdf0e10cSrcweir Dim aEmptyArgs() as New com.sun.star.bean.PropertyValue 730*cdf0e10cSrcweir oDispatch.dispatch(aSwitchMode, aEmptyArgs()) 731*cdf0e10cSrcweir Erase aSwitchMode 732*cdf0e10cSrcweirEnd Sub 733*cdf0e10cSrcweir 734*cdf0e10cSrcweir 735*cdf0e10cSrcweirFunction isHighContrast(oPeer as Object) 736*cdf0e10cSrcweir Dim UIColor as Long 737*cdf0e10cSrcweir Dim myRed as Integer 738*cdf0e10cSrcweir Dim myGreen as Integer 739*cdf0e10cSrcweir Dim myBlue as Integer 740*cdf0e10cSrcweir Dim myLuminance as Double 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir UIColor = oPeer.getProperty( "DisplayBackgroundColor" ) 743*cdf0e10cSrcweir myRed = Red (UIColor) 744*cdf0e10cSrcweir myGreen = Green (UIColor) 745*cdf0e10cSrcweir myBlue = Blue (UIColor) 746*cdf0e10cSrcweir myLuminance = (( myBlue*28 + myGreen*151 + myRed*77 ) / 256 ) 747*cdf0e10cSrcweir isHighContrast = false 748*cdf0e10cSrcweir If myLuminance <= 25 Then isHighContrast = true 749*cdf0e10cSrcweirEnd Function 750*cdf0e10cSrcweir 751*cdf0e10cSrcweir 752*cdf0e10cSrcweirFunction CreateNewDocument(sType as String, Optional sAddMsg as String) as Object 753*cdf0e10cSrcweirDim NoArgs() as new com.sun.star.beans.PropertyValue 754*cdf0e10cSrcweirDim oDocument as Object 755*cdf0e10cSrcweirDim sUrl as String 756*cdf0e10cSrcweirDim ErrMsg as String 757*cdf0e10cSrcweir On Local Error Goto NOMODULEINSTALLED 758*cdf0e10cSrcweir sUrl = "private:factory/" & sType 759*cdf0e10cSrcweir oDocument = StarDesktop.LoadComponentFromURL(sUrl,"_default",0, NoArgs()) 760*cdf0e10cSrcweirNOMODULEINSTALLED: 761*cdf0e10cSrcweir If (Err <> 0) OR IsNull(oDocument) Then 762*cdf0e10cSrcweir If InitResources("", "com") Then 763*cdf0e10cSrcweir Select Case sType 764*cdf0e10cSrcweir Case "swriter" 765*cdf0e10cSrcweir ErrMsg = GetResText(1001) 766*cdf0e10cSrcweir Case "scalc" 767*cdf0e10cSrcweir ErrMsg = GetResText(1002) 768*cdf0e10cSrcweir Case "simpress" 769*cdf0e10cSrcweir ErrMsg = GetResText(1003) 770*cdf0e10cSrcweir Case "sdraw" 771*cdf0e10cSrcweir ErrMsg = GetResText(1004) 772*cdf0e10cSrcweir Case "smath" 773*cdf0e10cSrcweir ErrMsg = GetResText(1005) 774*cdf0e10cSrcweir Case Else 775*cdf0e10cSrcweir ErrMsg = "Invalid Document Type!" 776*cdf0e10cSrcweir End Select 777*cdf0e10cSrcweir ErrMsg = ReplaceString(ErrMsg, chr(13), "<BR>") 778*cdf0e10cSrcweir If Not IsMissing(sAddMsg) Then 779*cdf0e10cSrcweir ErrMsg = ErrMsg & chr(13) & sAddMsg 780*cdf0e10cSrcweir End If 781*cdf0e10cSrcweir Msgbox(ErrMsg, 48, GetProductName()) 782*cdf0e10cSrcweir End If 783*cdf0e10cSrcweir If Err <> 0 Then 784*cdf0e10cSrcweir Resume GOON 785*cdf0e10cSrcweir End If 786*cdf0e10cSrcweir End If 787*cdf0e10cSrcweirGOON: 788*cdf0e10cSrcweir CreateNewDocument = oDocument 789*cdf0e10cSrcweirEnd Function 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir 792*cdf0e10cSrcweir' This Sub has been used in order to ensure that after disposing a document 793*cdf0e10cSrcweir' from the backing window it is returned to the backing window, so the 794*cdf0e10cSrcweir' office won't be closed 795*cdf0e10cSrcweirSub DisposeDocument(oDocument as Object) 796*cdf0e10cSrcweirDim dispatcher as Object 797*cdf0e10cSrcweirDim parser as Object 798*cdf0e10cSrcweirDim disp as Object 799*cdf0e10cSrcweirDim url as new com.sun.star.util.URL 800*cdf0e10cSrcweirDim NoArgs() as New com.sun.star.beans.PropertyValue 801*cdf0e10cSrcweirDim oFrame as Object 802*cdf0e10cSrcweir If Not IsNull(oDocument) Then 803*cdf0e10cSrcweir oDocument.setModified(false) 804*cdf0e10cSrcweir parser = createUnoService("com.sun.star.util.URLTransformer") 805*cdf0e10cSrcweir url.Complete = ".uno:CloseDoc" 806*cdf0e10cSrcweir parser.parseStrict(url) 807*cdf0e10cSrcweir oFrame = oDocument.CurrentController.Frame 808*cdf0e10cSrcweir disp = oFrame.queryDispatch(url,"_self", com.sun.star.util.SearchFlags.NORM_WORD_ONLY) 809*cdf0e10cSrcweir disp.dispatch(url, NoArgs()) 810*cdf0e10cSrcweir End If 811*cdf0e10cSrcweirEnd Sub 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir'Function to calculate if the year is a leap year 814*cdf0e10cSrcweirFunction CalIsLeapYear(ByVal iYear as Integer) as Boolean 815*cdf0e10cSrcweir CalIsLeapYear = ((iYear Mod 4 = 0) And ((iYear Mod 100 <> 0) Or (iYear Mod 400 = 0))) 816*cdf0e10cSrcweirEnd Function 817*cdf0e10cSrcweir</script:module>