home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 December / CHIP_CD_2004-12.iso / bonus / oo / OOo_1.1.3_ru_RU_infra_WinIntel_install.exe / $PLUGINSDIR / f_0218 / Misc.xba < prev    next >
Extensible Markup Language  |  2003-03-27  |  26KB  |  810 lines

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