1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Misc" script:
language=
"StarBasic">REM ***** BASIC *****
24 Dim Taskindex as Integer
28 Dim PropList(
3,
1)
' as String
29 PropList(
0,
0) =
"URL
"
30 PropList(
0,
1) =
"sdbc:odbc:Erica_Test_Unicode
"
31 PropList(
1,
0) =
"User
"
32 PropList(
1,
1) =
"extra
"
33 PropList(
2,
0) =
"Password
"
34 PropList(
2,
1) =
"extra
"
35 PropList(
3,
0) =
"IsPasswordRequired
"
40 Function RegisterNewDataSource(DSName as String, PropertyList(), Optional DriverProperties() as New com.sun.star.beans.PropertyValue)
41 Dim oDataSource as Object
42 Dim oDBContext as Object
43 Dim oPropInfo as Object
45 oDBContext = createUnoService(
"com.sun.star.sdb.DatabaseContext
")
46 oDataSource = createUnoService(
"com.sun.star.sdb.DataSource
")
47 For i =
0 To Ubound(PropertyList(),
1)
48 sPropName = PropertyList(i,
0)
49 sPropValue = PropertyList(i,
1)
50 oDataSource.SetPropertyValue(sPropName,sPropValue)
52 If Not IsMissing(DriverProperties()) Then
53 oDataSource.Info() = DriverProperties()
55 oDBContext.RegisterObject(DSName, oDataSource)
56 RegisterNewDataSource () = oDataSource
60 ' Connects to a registered Database
61 Function ConnectToDatabase(DSName as String, UserID as String, Password as String, Optional Propertylist(), Optional DriverProperties() as New com.sun.star.beans.PropertyValue)
62 Dim oDBContext as Object
63 Dim oDBSource as Object
64 ' On Local Error Goto NOCONNECTION
65 oDBContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
66 If oDBContext.HasbyName(DSName) Then
67 oDBSource = oDBContext.GetByName(DSName)
68 ConnectToDatabase = oDBSource.GetConnection(UserID, Password)
70 If Not IsMissing(Propertylist()) Then
71 RegisterNewDataSource(DSName, PropertyList(), DriverProperties())
72 oDBSource = oDBContext.GetByName(DSName)
73 ConnectToDatabase = oDBSource.GetConnection(UserID, Password)
75 Msgbox(
"DataSource
" & DSName
& " is not registered
" ,
16, GetProductname())
76 ConnectToDatabase() = NULL
80 If Err
<> 0 Then
81 Msgbox(Error$,
16, GetProductName())
88 Function GetStarOfficeLocale() as New com.sun.star.lang.Locale
89 Dim aLocLocale As New com.sun.star.lang.Locale
93 oMasterKey = GetRegistryKeyContent(
"org.openoffice.Setup/L10N/
")
94 sLocale = oMasterKey.getByName(
"ooLocale
")
95 sLocaleList() = ArrayoutofString(sLocale,
"-
")
96 aLocLocale.Language = sLocaleList(
0)
97 If Ubound(sLocaleList())
> 0 Then
98 aLocLocale.Country = sLocaleList(
1)
100 If Ubound(sLocaleList())
> 1 Then
101 aLocLocale.Variant = sLocaleList(
2)
103 GetStarOfficeLocale() = aLocLocale
107 Function GetRegistryKeyContent(sKeyName as string, Optional bforUpdate as Boolean)
108 Dim oConfigProvider as Object
109 Dim aNodePath(
0) as new com.sun.star.beans.PropertyValue
110 oConfigProvider = createUnoService(
"com.sun.star.configuration.ConfigurationProvider
")
111 aNodePath(
0).Name =
"nodepath
"
112 aNodePath(
0).Value = sKeyName
113 If IsMissing(bForUpdate) Then bForUpdate = False
115 GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationUpdateAccess
", aNodePath())
117 GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationAccess
", aNodePath())
122 Function GetProductname() as String
123 Dim oProdNameAccess as Object
124 Dim sVersion as String
125 Dim sProdName as String
126 oProdNameAccess = GetRegistryKeyContent(
"org.openoffice.Setup/Product
")
127 sProdName = oProdNameAccess.getByName(
"ooName
")
128 sVersion = oProdNameAccess.getByName(
"ooSetupVersion
")
129 GetProductName = sProdName
& sVersion
133 ' Opens a Document, checks beforehand, whether it has to be loaded
134 ' or whether it is already on the desktop.
135 ' If the parameter bDisposable is set to False then the returned document
136 ' should not be disposed afterwards, because it is already opened.
137 Function OpenDocument(DocPath as String, Args(), Optional bDisposable as Boolean)
138 Dim oComponents as Object
139 Dim oComponent as Object
140 ' Search if one of the active Components is the one that you search for
141 oComponents = StarDesktop.Components.CreateEnumeration
142 While oComponents.HasmoreElements
143 oComponent = oComponents.NextElement
144 If hasUnoInterfaces(oComponent,
"com.sun.star.frame.XModel
") then
145 If UCase(oComponent.URL) = UCase(DocPath) then
146 OpenDocument() = oComponent
147 If Not IsMissing(bDisposable) Then
154 If Not IsMissing(bDisposable) Then
157 OpenDocument() = StarDesktop.LoadComponentFromURL(DocPath,
"_default
",
0,Args())
161 Function TaskonDesktop(DocPath as String) as Boolean
162 Dim oComponents as Object
163 Dim oComponent as Object
164 ' Search if one of the active Components is the one that you search for
165 oComponents = StarDesktop.Components.CreateEnumeration
166 While oComponents.HasmoreElements
167 oComponent = oComponents.NextElement
168 If hasUnoInterfaces(oComponent,
"com.sun.star.frame.XModel
") then
169 If UCase(oComponent.URL) = UCase(DocPath) then
175 TaskonDesktop = False
179 ' Retrieves a FileName out of a StarOffice-Document
180 Function RetrieveFileName(LocDoc as Object)
182 Dim LocURLArray() as String
183 Dim MaxArrIndex as integer
186 LocURLArray() = ArrayoutofString(LocURL,
"/
",MaxArrIndex)
187 RetrieveFileName = LocURLArray(MaxArrIndex)
191 ' Gets a special configured PathSetting
192 Function GetPathSettings(sPathType as String, Optional bshowall as Boolean, Optional ListIndex as integer) as String
193 Dim oSettings, oPathSettings as Object
195 Dim PathList() as String
196 Dim MaxIndex as Integer
199 oPS = createUnoService(
"com.sun.star.util.PathSettings
")
201 If Not IsMissing(bShowall) Then
203 ShowPropertyValues(oPS)
207 sPath = oPS.getPropertyValue(sPathType)
208 If Not IsMissing(ListIndex) Then
209 ' Share and User-Directory
210 If Instr(
1,sPath,
";
")
<> 0 Then
211 PathList = ArrayoutofString(sPath,
";
", MaxIndex)
212 If ListIndex
<= MaxIndex Then
213 sPath = PathList(ListIndex)
215 Msgbox(
"String Cannot be analyzed!
" & sPath ,
16, GetProductName())
219 If Instr(
1, sPath,
";
") =
0 Then
220 GetPathSettings = ConvertToUrl(sPath)
222 GetPathSettings = sPath
229 ' Gets the fully qualified path to a subdirectory of the
230 ' Template Directory, e. g. with the parameter
"wizard/bitmap
"
231 ' The parameter must be passed in Url notation
232 ' The return-Value is in Url notation
233 Function GetOfficeSubPath(sOfficePath as String, ByVal sSubDir as String)
234 Dim sOfficeString as String
235 Dim sOfficeList() as String
236 Dim sOfficeDir as String
237 Dim sBigDir as String
239 Dim MaxIndex as Integer
241 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
242 sOfficeString = GetPathSettings(sOfficePath)
243 If Right(sSubDir,
1)
<> "/
" Then
244 sSubDir = sSubDir
& "/
"
246 sOfficeList() = ArrayoutofString(sOfficeString,
";
", MaxIndex)
247 For i =
0 To MaxIndex
248 sOfficeDir = ConvertToUrl(sOfficeList(i))
249 If Right(sOfficeDir,
1)
<> "/
" Then
250 sOfficeDir = sOfficeDir
& "/
"
252 sBigDir = sOfficeDir
& sSubDir
253 If oUcb.Exists(sBigDir) Then
254 GetOfficeSubPath() = sBigDir
258 ShowNoOfficePathError()
259 GetOfficeSubPath =
""
263 Sub ShowNoOfficePathError()
264 Dim ProductName as String
266 Dim bResObjectexists as Boolean
267 Dim oLocResSrv as Object
268 bResObjectexists = not IsNull(oResSrv)
269 If bResObjectexists Then
272 If InitResources(
"Tools
") Then
273 ProductName = GetProductName()
274 sError = GetResText(
"RID_COMMON_6
")
275 sError = ReplaceString(sError, ProductName,
"%PRODUCTNAME
")
276 sError = ReplaceString(sError, chr(
13),
"<BR
>")
277 MsgBox(sError,
16, ProductName)
279 If bResObjectexists Then
286 Function InitResources(Description) as boolean
287 Dim xResource as Object
288 Dim sOfficeDir as String
290 On Error Goto ErrorOccurred
291 sOfficeDir =
"$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/wizards/
"
292 sOfficeDir = GetDefaultContext.getByName(
"/singletons/com.sun.star.util.theMacroExpander
").ExpandMacros(sOfficeDir)
293 aArgs(
0) = sOfficeDir
295 aArgs(
2) = GetStarOfficeLocale()
296 aArgs(
3) =
"resources
"
297 aArgs(
4) =
""
299 oResSrv = getProcessServiceManager().createInstanceWithArguments(
"com.sun.star.resource.StringResourceWithLocation
", aArgs() )
300 If (IsNull(oResSrv)) then
301 InitResources = FALSE
302 MsgBox(
"could not initialize StringResourceWithLocation
")
309 InitResources = FALSE
310 nSolarVer = GetSolarVersion()
311 MsgBox(
"Resource file missing
",
16, GetProductName())
317 Function GetResText( sID as String ) As string
318 Dim sString as String
319 On Error Goto ErrorOccurred
320 If Not IsNull(oResSrv) Then
321 sString = oResSrv.resolveString(sID)
322 GetResText = ReplaceString(sString, GetProductname(),
"%PRODUCTNAME
")
324 GetResText =
""
328 GetResText =
""
329 MsgBox(
"Resource with ID =
" + sID +
" not found!
",
16, GetProductName())
335 Function CutPathView(sDocUrl as String, Optional PathLen as Integer)
336 Dim sViewPath as String
337 Dim FileName as String
338 Dim iFileLen as Integer
339 sViewPath = ConvertfromURL(sDocURL)
340 iViewPathLen = Len(sViewPath)
341 If iViewPathLen
> 60 Then
342 FileName = FileNameoutofPath(sViewPath,
"/
")
343 iFileLen = Len(FileName)
344 If iFileLen
< 44 Then
345 sViewPath = Left(sViewPath,
57-iFileLen-
10)
& "...
" & Right(sViewPath,iFileLen +
10)
347 sViewPath = Left(sViewPath,
27)
& " ...
" & Right(sViewPath,
28)
350 CutPathView = sViewPath
354 ' Deletes the content of all cells that are softformatted according
355 ' to the
'InputStyleName
'
356 Sub DeleteInputCells(oSheet as Object, InputStyleName as String)
357 Dim oRanges as Object
359 oRanges = oSheet.CellFormatRanges.createEnumeration
360 While oRanges.hasMoreElements
361 oRange = oRanges.NextElement
362 If Instr(
1,oRange.CellStyle, InputStyleName)
<> 0 Then
363 Call ReplaceRangeValues(oRange,
"")
369 ' Inserts a certain string to all cells of a range that is passed
370 ' either as an object or as the RangeName
371 Sub ChangeValueofRange(oSheet as Object, Range, ReplaceValue, Optional StyleName as String)
372 Dim oCellRange as Object
373 If Vartype(Range) =
8 Then
374 ' Get the Range out of the Rangename
375 oCellRange = oSheet.GetCellRangeByName(Range)
377 ' The range is passed as an object
378 Set oCellRange = Range
380 If IsMissing(StyleName) Then
381 ReplaceRangeValues(oCellRange, ReplaceValue)
383 If Instr(
1,oCellRange.CellStyle,StyleName) Then
384 ReplaceRangeValues(oCellRange, ReplaceValue)
390 Sub ReplaceRangeValues(oRange as Object, ReplaceValue)
391 Dim oRangeAddress as Object
392 Dim ColCount as Integer
393 Dim RowCount as Integer
395 oRangeAddress = oRange.RangeAddress
396 ColCount = oRangeAddress.EndColumn - oRangeAddress.StartColumn
397 RowCount = oRangeAddress.EndRow - oRangeAddress.StartRow
398 Dim FillArray(RowCount) as Variant
399 Dim sLine(ColCount) as Variant
400 For i =
0 To ColCount
401 sLine(i) = ReplaceValue
403 For i =
0 To RowCount
404 FillArray(i) = sLine()
406 oRange.DataArray = FillArray()
410 ' Returns the Value of the first cell of a Range
411 Function GetValueofCellbyName(oSheet as Object, sCellName as String)
413 oCell = GetCellByName(oSheet, sCellName)
414 GetValueofCellbyName = oCell.Value
418 Function DuplicateRow(oSheet as Object, RangeName as String)
421 Dim oCellAddress as New com.sun.star.table.CellAddress
422 Dim oRangeAddress as New com.sun.star.table.CellRangeAddress
423 oRange = oSheet.GetCellRangeByName(RangeName)
424 oRangeAddress = oRange.RangeAddress
425 oCell = oSheet.GetCellByPosition(oRangeAddress.StartColumn,oRangeAddress.StartRow)
426 oCellAddress = oCell.CellAddress
427 oSheet.Rows.InsertByIndex(oCellAddress.Row,
1)
428 oRangeAddress = oRange.RangeAddress
429 oSheet.CopyRange(oCellAddress, oRangeAddress)
430 DuplicateRow = oRangeAddress.StartRow-
1
434 ' Returns the String of the first cell of a Range
435 Function GetStringofCellbyName(oSheet as Object, sCellName as String)
437 oCell = GetCellByName(oSheet, sCellName)
438 GetStringofCellbyName = oCell.String
442 ' Returns a named Cell
443 Function GetCellByName(oSheet as Object, sCellName as String) as Object
444 Dim oCellRange as Object
445 Dim oCellAddress as Object
446 oCellRange = oSheet.GetCellRangeByName(sCellName)
447 oCellAddress = oCellRange.RangeAddress
448 GetCellByName = oSheet.GetCellByPosition(oCellAddress.StartColumn,oCellAddress.StartRow)
452 ' Changes the numeric Value of a cell by transmitting the String of the numeric Value
453 Sub ChangeCellValue(oCell as Object, ValueString as String)
455 oCell.Formula =
"=Value(
" & """" & ValueString
& """" & ")
"
456 CellValue = oCell.Value
457 oCell.Formula =
""
458 oCell.Value = CellValue
462 Function GetDocumentType(oDocument)
463 On Local Error GoTo NODOCUMENTTYPE
464 ' ShowSupportedServiceNames(oDocument)
465 If oDocument.SupportsService(
"com.sun.star.sheet.SpreadsheetDocument
") Then
466 GetDocumentType() =
"scalc
"
467 ElseIf oDocument.SupportsService(
"com.sun.star.text.TextDocument
") Then
468 GetDocumentType() =
"swriter
"
469 ElseIf oDocument.SupportsService(
"com.sun.star.drawing.DrawingDocument
") Then
470 GetDocumentType() =
"sdraw
"
471 ElseIf oDocument.SupportsService(
"com.sun.star.presentation.PresentationDocument
") Then
472 GetDocumentType() =
"simpress
"
473 ElseIf oDocument.SupportsService(
"com.sun.star.formula.FormulaProperties
") Then
474 GetDocumentType() =
"smath
"
477 If Err
<> 0 Then
478 GetDocumentType =
""
485 Function GetNumberFormatType(oDocFormats, oFormatObject as Object) as Integer
486 Dim ThisFormatKey as Long
487 Dim oObjectFormat as Object
488 On Local Error Goto NOFORMAT
489 ThisFormatKey = oFormatObject.NumberFormat
490 oObjectFormat = oDocFormats.GetByKey(ThisFormatKey)
491 GetNumberFormatType = oObjectFormat.Type
493 If Err
<> 0 Then
494 Msgbox(
"Numberformat of Object is not available!
",
16, GetProductName())
495 GetNumberFormatType =
0
499 On Local Error Goto
0
503 Sub ProtectSheets(Optional oSheets as Object)
505 Dim oDocSheets as Object
506 If IsMissing(oSheets) Then
507 oDocSheets = StarDesktop.CurrentFrame.Controller.Model.Sheets
509 Set oDocSheets = oSheets
512 For i =
0 To oDocSheets.Count-
1
513 oDocSheets(i).Protect(
"")
518 Sub UnprotectSheets(Optional oSheets as Object)
520 Dim oDocSheets as Object
521 If IsMissing(oSheets) Then
522 oDocSheets = StarDesktop.CurrentFrame.Controller.Model.Sheets
524 Set oDocSheets = oSheets
527 For i =
0 To oDocSheets.Count-
1
528 oDocSheets(i).Unprotect(
"")
533 Function GetRowIndex(oSheet as Object, RowName as String)
535 oRange = oSheet.GetCellRangeByName(RowName)
536 GetRowIndex = oRange.RangeAddress.StartRow
540 Function GetColumnIndex(oSheet as Object, ColName as String)
542 oRange = oSheet.GetCellRangeByName(ColName)
543 GetColumnIndex = oRange.RangeAddress.StartColumn
547 Function CopySheetbyName(oSheets as Object, OldName as String, NewName as String, DestPos as Integer) as Object
550 Dim BasicSheetName as String
552 BasicSheetName = NewName
553 ' Copy the last table. Assumption: The last table is the template
554 On Local Error Goto RENAMESHEET
555 oSheets.CopybyName(OldName, NewName, DestPos)
558 oSheet = oSheets(DestPos)
559 If Err
<> 0 Then
560 ' Test if renaming failed
562 Do While oSheet.Name
<> NewName
563 NewName = BasicSheetName
& "_
" & Count
564 oSheet.Name = NewName
570 CopySheetbyName = oSheet
574 ' Dis-or enables a Window and adjusts the mousepointer accordingly
575 Sub ToggleWindow(bDoEnable as Boolean)
576 Dim oWindow as Object
577 oWindow = StarDesktop.CurrentFrame.ComponentWindow
578 oWindow.Enable = bDoEnable
582 Function CheckNewSheetname(oSheets as Object, Sheetname as String, Optional oLocale) as String
583 Dim nStartFlags as Long
584 Dim nContFlags as Long
585 Dim oCharService as Object
586 Dim iSheetNameLength as Integer
587 Dim iResultPos as Integer
588 Dim WrongChar as String
589 Dim oResult as Object
590 nStartFlags = com.sun.star.i18n.KParseTokens.ANY_LETTER_OR_NUMBER + com.sun.star.i18n.KParseTokens.ASC_UNDERSCORE
591 nContFlags = nStartFlags
592 oCharService = CreateUnoService(
"com.sun.star.i18n.CharacterClassification
")
593 iSheetNameLength = Len(SheetName)
594 If IsMissing(oLocale) Then
595 oLocale = ThisComponent.CharLocale
598 oResult =oCharService.parsePredefinedToken(com.sun.star.i18n.KParseType.IDENTNAME, SheetName,
0, oLocale, nStartFlags,
"", nContFlags,
" ")
599 iResultPos = oResult.EndPos
600 If iResultPos
< iSheetNameLength Then
601 WrongChar = Mid(SheetName, iResultPos+
1,
1)
602 SheetName = ReplaceString(SheetName,
"_
", WrongChar)
604 Loop Until iResultPos = iSheetNameLength
605 CheckNewSheetname = SheetName
609 Sub AddNewSheetName(oSheets as Object, ByVal SheetName as String)
611 Dim bSheetIsThere as Boolean
612 Dim iSheetNameLength as Integer
613 iSheetNameLength = Len(SheetName)
616 bSheetIsThere = oSheets.HasByName(SheetName)
617 If bSheetIsThere Then
618 SheetName = Right(SheetName,iSheetNameLength)
& "_
" & Count
621 Loop Until Not bSheetIsThere
622 AddNewSheetname = SheetName
626 Function GetSheetIndex(oSheets, sName) as Integer
628 For i =
0 To oSheets.Count-
1
629 If oSheets(i).Name = sName Then
638 Function GetLastUsedRow(oSheet as Object) as Long
640 Dim oCursor As Object
641 Dim aAddress As Variant
642 oCell = oSheet.GetCellbyPosition(
0,
0)
643 oCursor = oSheet.createCursorByRange(oCell)
644 oCursor.GotoEndOfUsedArea(True)
645 aAddress = oCursor.RangeAddress
646 GetLastUsedRow = aAddress.EndRow
650 ' Note To set a one lined frame you have to set the inner width to
0
651 ' In the API all Units that refer to pt-Heights are
"1/
100mm
"
652 ' The convert factor from
1pt to
1/
100 mm is approximately
35
653 Function ModifyBorderLineWidth(ByVal oStyleBorder, iInnerLineWidth as Integer, iOuterLineWidth as Integer)
654 Dim aBorder as New com.sun.star.table.BorderLine
655 aBorder = oStyleBorder
656 aBorder.InnerLineWidth = iInnerLineWidth
657 aBorder.OuterLineWidth = iOuterLineWidth
658 ModifyBorderLineWidth = aBorder
662 Sub AttachBasicMacroToEvent(oDocument as Object, EventName as String, SubPath as String)
663 Dim PropValue(
1) as new com.sun.star.beans.PropertyValue
664 PropValue(
0).Name =
"EventType
"
665 PropValue(
0).Value =
"StarBasic
"
666 PropValue(
1).Name =
"Script
"
667 PropValue(
1).Value =
"macro:///
" & SubPath
668 oDocument.Events.ReplaceByName(EventName, PropValue())
673 Function ModifyPropertyValue(oContent() as New com.sun.star.beans.PropertyValue, TargetProperties() as New com.sun.star.beans.PropertyValue)
674 Dim MaxIndex as Integer
677 MaxIndex = Ubound(oContent())
679 For i =
0 To MaxIndex
680 a = GetPropertyValueIndex(oContent(i).Name, TargetProperties())
681 If a
<> -
1 Then
682 If Vartype(TargetProperties(a).Value)
<> 9 Then
683 If TargetProperties(a).Value
<> oContent(i).Value Then
684 oContent(i).Value = TargetProperties(a).Value
688 If Not EqualUnoObjects(TargetProperties(a).Value, oContent(i).Value) Then
689 oContent(i).Value = TargetProperties(a).Value
695 ModifyPropertyValue() = bDoReplace
699 Function GetPropertyValueIndex(SearchName as String, TargetProperties() as New com.sun.star.beans.PropertyValue ) as Integer
701 For i =
0 To Ubound(TargetProperties())
702 If Searchname = TargetProperties(i).Name Then
703 GetPropertyValueIndex = i
707 GetPropertyValueIndex() = -
1
711 Sub DispatchSlot(SlotID as Integer)
712 Dim oArg() as new com.sun.star.beans.PropertyValue
713 Dim oUrl as new com.sun.star.util.URL
716 oTrans = createUNOService(
"com.sun.star.util.URLTransformer
")
717 oUrl.Complete =
"slot:
" & CStr(SlotID)
718 oTrans.parsestrict(oUrl)
719 oDisp = StarDesktop.ActiveFrame.queryDispatch(oUrl,
"_self
",
0)
720 oDisp.dispatch(oUrl, oArg())
724 'returns the type of the office application
725 'FatOffice =
0, WebTop =
1
726 'This routine has to be changed if the Product Name is being changed!
727 Function IsFatOffice() As Boolean
728 If sProductname =
"" Then
729 sProductname = GetProductname()
732 'The following line has to include the current productname
733 If Instr(
1,sProductname,
"WebTop
",
1)
<> 0 Then
739 Sub ToggleDesignMode(oDocument as Object)
740 Dim aSwitchMode as new com.sun.star.util.URL
741 aSwitchMode.Complete =
".uno:SwitchControlDesignMode
"
742 aTransformer = createUnoService(
"com.sun.star.util.URLTransformer
")
743 aTransformer.parseStrict(aSwitchMode)
744 oFrame = oDocument.currentController.Frame
745 oDispatch = oFrame.queryDispatch(aSwitchMode, oFrame.Name,
63)
746 Dim aEmptyArgs() as New com.sun.star.bean.PropertyValue
747 oDispatch.dispatch(aSwitchMode, aEmptyArgs())
752 Function isHighContrast(oPeer as Object)
755 Dim myGreen as Integer
756 Dim myBlue as Integer
757 Dim myLuminance as Double
759 UIColor = oPeer.getProperty(
"DisplayBackgroundColor
" )
760 myRed = Red (UIColor)
761 myGreen = Green (UIColor)
762 myBlue = Blue (UIColor)
763 myLuminance = (( myBlue*
28 + myGreen*
151 + myRed*
77 ) /
256 )
764 isHighContrast = false
765 If myLuminance
<=
25 Then isHighContrast = true
769 Function CreateNewDocument(sType as String, Optional sAddMsg as String) as Object
770 Dim NoArgs() as new com.sun.star.beans.PropertyValue
771 Dim oDocument as Object
774 On Local Error Goto NOMODULEINSTALLED
775 sUrl =
"private:factory/
" & sType
776 oDocument = StarDesktop.LoadComponentFromURL(sUrl,
"_default
",
0, NoArgs())
778 If (Err
<> 0) OR IsNull(oDocument) Then
779 If InitResources(
"") Then
781 Case
"swriter
"
782 ErrMsg = GetResText(
"RID_COMMON_1
")
783 Case
"scalc
"
784 ErrMsg = GetResText(
"RID_COMMON_2
")
785 Case
"simpress
"
786 ErrMsg = GetResText(
"RID_COMMON_3
")
787 Case
"sdraw
"
788 ErrMsg = GetResText(
"RID_COMMON_4
")
789 Case
"smath
"
790 ErrMsg = GetResText(
"RID_COMMON_5
")
792 ErrMsg =
"Invalid Document Type!
"
794 ErrMsg = ReplaceString(ErrMsg, chr(
13),
"<BR
>")
795 If Not IsMissing(sAddMsg) Then
796 ErrMsg = ErrMsg
& chr(
13)
& sAddMsg
798 Msgbox(ErrMsg,
48, GetProductName())
800 If Err
<> 0 Then
805 CreateNewDocument = oDocument
809 ' This Sub has been used in order to ensure that after disposing a document
810 ' from the backing window it is returned to the backing window, so the
811 ' office won
't be closed
812 Sub DisposeDocument(oDocument as Object)
813 Dim dispatcher as Object
816 Dim url as new com.sun.star.util.URL
817 Dim NoArgs() as New com.sun.star.beans.PropertyValue
819 If Not IsNull(oDocument) Then
820 oDocument.setModified(false)
821 parser = createUnoService(
"com.sun.star.util.URLTransformer
")
822 url.Complete =
".uno:CloseDoc
"
823 parser.parseStrict(url)
824 oFrame = oDocument.CurrentController.Frame
825 disp = oFrame.queryDispatch(url,
"_self
", com.sun.star.util.SearchFlags.NORM_WORD_ONLY)
826 disp.dispatch(url, NoArgs())
830 'Function to calculate if the year is a leap year
831 Function CalIsLeapYear(ByVal iYear as Integer) as Boolean
832 CalIsLeapYear = ((iYear Mod
4 =
0) And ((iYear Mod
100 <> 0) Or (iYear Mod
400 =
0)))