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(Namelist()) Then
71 If Not IsMissing(DriverProperties()) Then
72 RegisterNewDataSource(DSName, PropertyList(), DriverProperties())
74 RegisterNewDataSource(DSName, PropertyList())
76 oDBSource = oDBContext.GetByName(DSName)
77 ConnectToDatabase = oDBSource.GetConnection(UserID, Password)
79 Msgbox(
"DataSource
" & DSName
& " is not registered
" ,
16, GetProductname())
80 ConnectToDatabase() = NULL
84 If Err
<> 0 Then
85 Msgbox(Error$,
16, GetProductName())
92 Function GetStarOfficeLocale() as New com.sun.star.lang.Locale
93 Dim aLocLocale As New com.sun.star.lang.Locale
97 oMasterKey = GetRegistryKeyContent(
"org.openoffice.Setup/L10N/
")
98 sLocale = oMasterKey.getByName(
"ooLocale
")
99 sLocaleList() = ArrayoutofString(sLocale,
"-
")
100 aLocLocale.Language = sLocaleList(
0)
101 If Ubound(sLocaleList())
> 0 Then
102 aLocLocale.Country = sLocaleList(
1)
104 GetStarOfficeLocale() = aLocLocale
108 Function GetRegistryKeyContent(sKeyName as string, Optional bforUpdate as Boolean)
109 Dim oConfigProvider as Object
110 Dim aNodePath(
0) as new com.sun.star.beans.PropertyValue
111 oConfigProvider = createUnoService(
"com.sun.star.configuration.ConfigurationProvider
")
112 aNodePath(
0).Name =
"nodepath
"
113 aNodePath(
0).Value = sKeyName
114 If IsMissing(bForUpdate) Then
115 GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationAccess
", aNodePath())
118 GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationUpdateAccess
", aNodePath())
120 GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationAccess
", aNodePath())
126 Function GetProductname() as String
127 Dim oProdNameAccess as Object
128 Dim sVersion as String
129 Dim sProdName as String
130 oProdNameAccess = GetRegistryKeyContent(
"org.openoffice.Setup/Product
")
131 sProdName = oProdNameAccess.getByName(
"ooName
")
132 sVersion = oProdNameAccess.getByName(
"ooSetupVersion
")
133 GetProductName = sProdName
& sVersion
137 ' Opens a Document, checks beforehand, whether it has to be loaded
138 ' or whether it is already on the desktop.
139 ' If the parameter bDisposable is set to False then then returned document
140 ' should not be disposed afterwards, because it is already opened.
141 Function OpenDocument(DocPath as String, Args(), Optional bDisposable as Boolean)
142 Dim oComponents as Object
143 Dim oComponent as Object
144 ' Search if one of the active Components is the one that you search for
145 oComponents = StarDesktop.Components.CreateEnumeration
146 While oComponents.HasmoreElements
147 oComponent = oComponents.NextElement
148 If hasUnoInterfaces(oComponent,
"com.sun.star.frame.XModel
") then
149 If UCase(oComponent.URL) = UCase(DocPath) then
150 OpenDocument() = oComponent
151 If Not IsMissing(bDisposable) Then
158 If Not IsMissing(bDisposable) Then
161 OpenDocument() = StarDesktop.LoadComponentFromURL(DocPath,
"_default
",
0,Args())
165 Function TaskonDesktop(DocPath as String) as Boolean
166 Dim oComponents as Object
167 Dim oComponent as Object
168 ' Search if one of the active Components is the one that you search for
169 oComponents = StarDesktop.Components.CreateEnumeration
170 While oComponents.HasmoreElements
171 oComponent = oComponents.NextElement
172 If hasUnoInterfaces(oComponent,
"com.sun.star.frame.XModel
") then
173 If UCase(oComponent.URL) = UCase(DocPath) then
179 TaskonDesktop = False
183 ' Retrieves a FileName out of a StarOffice-Document
184 Function RetrieveFileName(LocDoc as Object)
186 Dim LocURLArray() as String
187 Dim MaxArrIndex as integer
190 LocURLArray() = ArrayoutofString(LocURL,
"/
",MaxArrIndex)
191 RetrieveFileName = LocURLArray(MaxArrIndex)
195 ' Gets a special configured PathSetting
196 Function GetPathSettings(sPathType as String, Optional bshowall as Boolean, Optional ListIndex as integer) as String
197 Dim oSettings, oPathSettings as Object
199 Dim PathList() as String
200 Dim MaxIndex as Integer
203 oPS = createUnoService(
"com.sun.star.util.PathSettings
")
205 If Not IsMissing(bShowall) Then
207 ShowPropertyValues(oPS)
211 sPath = oPS.getPropertyValue(sPathType)
212 If Not IsMissing(ListIndex) Then
213 ' Share and User-Directory
214 If Instr(
1,sPath,
";
")
<> 0 Then
215 PathList = ArrayoutofString(sPath,
";
", MaxIndex)
216 If ListIndex
<= MaxIndex Then
217 sPath = PathList(ListIndex)
219 Msgbox(
"String Cannot be analyzed!
" & sPath ,
16, GetProductName())
223 If Instr(
1, sPath,
";
") =
0 Then
224 GetPathSettings = ConvertToUrl(sPath)
226 GetPathSettings = sPath
233 ' Gets the fully qualified path to a subdirectory of the
234 ' Template Directory, e. g. with the parameter
"wizard/bitmap
"
235 ' The parameter must be passed over in Url-scription
236 ' The return-Value is in Urlscription
237 Function GetOfficeSubPath(sOfficePath as String, ByVal sSubDir as String)
238 Dim sOfficeString as String
239 Dim sOfficeList() as String
240 Dim sOfficeDir as String
241 Dim sBigDir as String
243 Dim MaxIndex as Integer
245 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
246 sOfficeString = GetPathSettings(sOfficePath)
247 If Right(sSubDir,
1)
<> "/
" Then
248 sSubDir = sSubDir
& "/
"
250 sOfficeList() = ArrayoutofString(sOfficeString,
";
", MaxIndex)
251 For i =
0 To MaxIndex
252 sOfficeDir = ConvertToUrl(sOfficeList(i))
253 If Right(sOfficeDir,
1)
<> "/
" Then
254 sOfficeDir = sOfficeDir
& "/
"
256 sBigDir = sOfficeDir
& sSubDir
257 If oUcb.Exists(sBigDir) Then
258 GetOfficeSubPath() = sBigDir
262 ShowNoOfficePathError()
263 GetOfficeSubPath =
""
267 Sub ShowNoOfficePathError()
268 Dim ProductName as String
270 Dim bResObjectexists as Boolean
271 Dim oLocResSrv as Object
272 bResObjectexists = not IsNull(oResSrv)
273 If bResObjectexists Then
276 If InitResources(
"Tools
",
"com
") Then
277 ProductName = GetProductName()
278 sError = GetResText(
1006)
279 sError = ReplaceString(sError, ProductName,
"%PRODUCTNAME
")
280 sError = ReplaceString(sError, chr(
13),
"<BR
>")
281 MsgBox(sError,
16, ProductName)
283 If bResObjectexists Then
290 Function InitResources(Description, ShortDescription as String) as boolean
291 Dim xResource as Object
292 Dim aArgs(
0) as String
293 On Error Goto ErrorOcurred
294 aArgs(
0) = ShortDescription
295 oConfigProvider = createUnoService(
"com.sun.star.configuration.ConfigurationProvider
")
296 xResource = getProcessServiceManager().createInstanceWithArguments(
"org.libreoffice.resource.ResourceIndexAccess
", aArgs() )
297 If (IsNull(xResource)) then
298 InitResources = FALSE
299 MsgBox(
"could not initialize ResourceIndexAccess
")
302 oResSrv = xResource.getByName(
"String
" )
307 InitResources = FALSE
308 nSolarVer = GetSolarVersion()
309 MsgBox(
"Resource file missing (
" & ShortDescription
& trim(str(nSolarVer)) +
"*.res)
",
16, GetProductName())
315 Function GetResText( nID as integer ) As string
316 On Error Goto ErrorOcurred
317 If Not IsNull(oResSrv) Then
318 GetResText = oResSrv.getByIndex( nID )
320 GetResText =
""
324 GetResText =
""
325 MsgBox(
"Resource with ID =
" + str( nID ) +
" not found!
",
16, GetProductName())
331 Function CutPathView(sDocUrl as String, Optional PathLen as Integer)
332 Dim sViewPath as String
333 Dim FileName as String
334 Dim iFileLen as Integer
335 sViewPath = ConvertfromURL(sDocURL)
336 iViewPathLen = Len(sViewPath)
337 If iViewPathLen
> 60 Then
338 FileName = FileNameoutofPath(sViewPath,
"/
")
339 iFileLen = Len(FileName)
340 If iFileLen
< 44 Then
341 sViewPath = Left(sViewPath,
57-iFileLen-
10)
& "...
" & Right(sViewPath,iFileLen +
10)
343 sViewPath = Left(sViewPath,
27)
& " ...
" & Right(sViewPath,
28)
346 CutPathView = sViewPath
350 ' Deletes the content of all cells that are softformatted according
351 ' to the
'InputStyleName
'
352 Sub DeleteInputCells(oSheet as Object, InputStyleName as String)
353 Dim oRanges as Object
355 oRanges = oSheet.CellFormatRanges.createEnumeration
356 While oRanges.hasMoreElements
357 oRange = oRanges.NextElement
358 If Instr(
1,oRange.CellStyle, InputStyleName)
<> 0 Then
359 Call ReplaceRangeValues(oRange,
"")
365 ' Inserts a certain String to all cells of a Range that ist passed over
366 ' either as an object or as the RangeName
367 Sub ChangeValueofRange(oSheet as Object, Range, ReplaceValue, Optional StyleName as String)
368 Dim oCellRange as Object
369 If Vartype(Range) =
8 Then
370 ' Get the Range out of the Rangename
371 oCellRange = oSheet.GetCellRangeByName(Range)
373 ' The range is passed over as an object
374 Set oCellRange = Range
376 If IsMissing(StyleName) Then
377 ReplaceRangeValues(oCellRange, ReplaceValue)
379 If Instr(
1,oCellRange.CellStyle,StyleName) Then
380 ReplaceRangeValues(oCellRange, ReplaceValue)
386 Sub ReplaceRangeValues(oRange as Object, ReplaceValue)
387 Dim oRangeAddress as Object
388 Dim ColCount as Integer
389 Dim RowCount as Integer
391 oRangeAddress = oRange.RangeAddress
392 ColCount = oRangeAddress.EndColumn - oRangeAddress.StartColumn
393 RowCount = oRangeAddress.EndRow - oRangeAddress.StartRow
394 Dim FillArray(RowCount) as Variant
395 Dim sLine(ColCount) as Variant
396 For i =
0 To ColCount
397 sLine(i) = ReplaceValue
399 For i =
0 To RowCount
400 FillArray(i) = sLine()
402 oRange.DataArray = FillArray()
406 ' Returns the Value of the first cell of a Range
407 Function GetValueofCellbyName(oSheet as Object, sCellName as String)
409 oCell = GetCellByName(oSheet, sCellName)
410 GetValueofCellbyName = oCell.Value
414 Function DuplicateRow(oSheet as Object, RangeName as String)
417 Dim oCellAddress as New com.sun.star.table.CellAddress
418 Dim oRangeAddress as New com.sun.star.table.CellRangeAddress
419 oRange = oSheet.GetCellRangeByName(RangeName)
420 oRangeAddress = oRange.RangeAddress
421 oCell = oSheet.GetCellByPosition(oRangeAddress.StartColumn,oRangeAddress.StartRow)
422 oCellAddress = oCell.CellAddress
423 oSheet.Rows.InsertByIndex(oCellAddress.Row,
1)
424 oRangeAddress = oRange.RangeAddress
425 oSheet.CopyRange(oCellAddress, oRangeAddress)
426 DuplicateRow = oRangeAddress.StartRow-
1
430 ' Returns the String of the first cell of a Range
431 Function GetStringofCellbyName(oSheet as Object, sCellName as String)
433 oCell = GetCellByName(oSheet, sCellName)
434 GetStringofCellbyName = oCell.String
438 ' Returns a named Cell
439 Function GetCellByName(oSheet as Object, sCellName as String) as Object
440 Dim oCellRange as Object
441 Dim oCellAddress as Object
442 oCellRange = oSheet.GetCellRangeByName(sCellName)
443 oCellAddress = oCellRange.RangeAddress
444 GetCellByName = oSheet.GetCellByPosition(oCellAddress.StartColumn,oCellAddress.StartRow)
448 ' Changes the numeric Value of a cell by transmitting the String of the numeric Value
449 Sub ChangeCellValue(oCell as Object, ValueString as String)
451 oCell.Formula =
"=Value(
" & """" & ValueString
& """" & ")
"
452 CellValue = oCell.Value
453 oCell.Formula =
""
454 oCell.Value = CellValue
458 Function GetDocumentType(oDocument)
459 On Local Error GoTo NODOCUMENTTYPE
460 ' ShowSupportedServiceNames(oDocument)
461 If oDocument.SupportsService(
"com.sun.star.sheet.SpreadsheetDocument
") Then
462 GetDocumentType() =
"scalc
"
463 ElseIf oDocument.SupportsService(
"com.sun.star.text.TextDocument
") Then
464 GetDocumentType() =
"swriter
"
465 ElseIf oDocument.SupportsService(
"com.sun.star.drawing.DrawingDocument
") Then
466 GetDocumentType() =
"sdraw
"
467 ElseIf oDocument.SupportsService(
"com.sun.star.presentation.PresentationDocument
") Then
468 GetDocumentType() =
"simpress
"
469 ElseIf oDocument.SupportsService(
"com.sun.star.formula.FormulaProperties
") Then
470 GetDocumentType() =
"smath
"
473 If Err
<> 0 Then
474 GetDocumentType =
""
481 Function GetNumberFormatType(oDocFormats, oFormatObject as Object) as Integer
482 Dim ThisFormatKey as Long
483 Dim oObjectFormat as Object
484 On Local Error Goto NOFORMAT
485 ThisFormatKey = oFormatObject.NumberFormat
486 oObjectFormat = oDocFormats.GetByKey(ThisFormatKey)
487 GetNumberFormatType = oObjectFormat.Type
489 If Err
<> 0 Then
490 Msgbox(
"Numberformat of Object is not available!
",
16, GetProductName())
491 GetNumberFormatType =
0
495 On Local Error Goto
0
499 Sub ProtectSheets(Optional oSheets as Object)
501 Dim oDocSheets as Object
502 If IsMissing(oSheets) Then
503 oDocSheets = StarDesktop.CurrentFrame.Controller.Model.Sheets
505 Set oDocSheets = oSheets
508 For i =
0 To oDocSheets.Count-
1
509 oDocSheets(i).Protect(
"")
514 Sub UnprotectSheets(Optional oSheets as Object)
516 Dim oDocSheets as Object
517 If IsMissing(oSheets) Then
518 oDocSheets = StarDesktop.CurrentFrame.Controller.Model.Sheets
520 Set oDocSheets = oSheets
523 For i =
0 To oDocSheets.Count-
1
524 oDocSheets(i).Unprotect(
"")
529 Function GetRowIndex(oSheet as Object, RowName as String)
531 oRange = oSheet.GetCellRangeByName(RowName)
532 GetRowIndex = oRange.RangeAddress.StartRow
536 Function GetColumnIndex(oSheet as Object, ColName as String)
538 oRange = oSheet.GetCellRangeByName(ColName)
539 GetColumnIndex = oRange.RangeAddress.StartColumn
543 Function CopySheetbyName(oSheets as Object, OldName as String, NewName as String, DestPos as Integer) as Object
546 Dim BasicSheetName as String
548 BasicSheetName = NewName
549 ' Copy the last table. Assumption: The last table is the template
550 On Local Error Goto RENAMESHEET
551 oSheets.CopybyName(OldName, NewName, DestPos)
554 oSheet = oSheets(DestPos)
555 If Err
<> 0 Then
556 ' Test if renaming failed
558 Do While oSheet.Name
<> NewName
559 NewName = BasicSheetName
& "_
" & Count
560 oSheet.Name = NewName
566 CopySheetbyName = oSheet
570 ' Dis-or enables a Window and adjusts the mousepointer accordingly
571 Sub ToggleWindow(bDoEnable as Boolean)
572 Dim oWindow as Object
573 oWindow = StarDesktop.CurrentFrame.ComponentWindow
574 oWindow.Enable = bDoEnable
578 Function CheckNewSheetname(oSheets as Object, Sheetname as String, Optional oLocale) as String
579 Dim nStartFlags as Long
580 Dim nContFlags as Long
581 Dim oCharService as Object
582 Dim iSheetNameLength as Integer
583 Dim iResultPos as Integer
584 Dim WrongChar as String
585 Dim oResult as Object
586 nStartFlags = com.sun.star.i18n.KParseTokens.ANY_LETTER_OR_NUMBER + com.sun.star.i18n.KParseTokens.ASC_UNDERSCORE
587 nContFlags = nStartFlags
588 oCharService = CreateUnoService(
"com.sun.star.i18n.CharacterClassification
")
589 iSheetNameLength = Len(SheetName)
590 If IsMissing(oLocale) Then
591 oLocale = ThisComponent.CharLocale
594 oResult =oCharService.parsePredefinedToken(com.sun.star.i18n.KParseType.IDENTNAME, SheetName,
0, oLocale, nStartFlags,
"", nContFlags,
" ")
595 iResultPos = oResult.EndPos
596 If iResultPos
< iSheetNameLength Then
597 WrongChar = Mid(SheetName, iResultPos+
1,
1)
598 SheetName = ReplaceString(SheetName,
"_
", WrongChar)
600 Loop Until iResultPos = iSheetNameLength
601 CheckNewSheetname = SheetName
605 Sub AddNewSheetName(oSheets as Object, ByVal SheetName as String)
607 Dim bSheetIsThere as Boolean
608 Dim iSheetNameLength as Integer
609 iSheetNameLength = Len(SheetName)
612 bSheetIsThere = oSheets.HasByName(SheetName)
613 If bSheetIsThere Then
614 SheetName = Right(SheetName,iSheetNameLength)
& "_
" & Count
617 Loop Until Not bSheetIsThere
618 AddNewSheetname = SheetName
622 Function GetSheetIndex(oSheets, sName) as Integer
624 For i =
0 To oSheets.Count-
1
625 If oSheets(i).Name = sName Then
634 Function GetLastUsedRow(oSheet as Object) as Integer
636 Dim oCursor As Object
637 Dim aAddress As Variant
638 oCell = oSheet.GetCellbyPosition(
0,
0)
639 oCursor = oSheet.createCursorByRange(oCell)
640 oCursor.GotoEndOfUsedArea(True)
641 aAddress = oCursor.RangeAddress
642 GetLastUsedRow = aAddress.EndRow
646 ' Note To set a one lined frame you have to set the inner width to
0
647 ' In the API all Units that refer to pt-Heights are
"1/
100mm
"
648 ' The convert factor from
1pt to
1/
100 mm is approximately
35
649 Function ModifyBorderLineWidth(ByVal oStyleBorder, iInnerLineWidth as Integer, iOuterLineWidth as Integer)
650 Dim aBorder as New com.sun.star.table.BorderLine
651 aBorder = oStyleBorder
652 aBorder.InnerLineWidth = iInnerLineWidth
653 aBorder.OuterLineWidth = iOuterLineWidth
654 ModifyBorderLineWidth = aBorder
658 Sub AttachBasicMacroToEvent(oDocument as Object, EventName as String, SubPath as String)
659 Dim PropValue(
1) as new com.sun.star.beans.PropertyValue
660 PropValue(
0).Name =
"EventType
"
661 PropValue(
0).Value =
"StarBasic
"
662 PropValue(
1).Name =
"Script
"
663 PropValue(
1).Value =
"macro:///
" & SubPath
664 oDocument.Events.ReplaceByName(EventName, PropValue())
669 Function ModifyPropertyValue(oContent() as New com.sun.star.beans.PropertyValue, TargetProperties() as New com.sun.star.beans.PropertyValue)
670 Dim MaxIndex as Integer
673 MaxIndex = Ubound(oContent())
675 For i =
0 To MaxIndex
676 a = GetPropertyValueIndex(oContent(i).Name, TargetProperties())
677 If a
<> -
1 Then
678 If Vartype(TargetProperties(a).Value)
<> 9 Then
679 If TargetProperties(a).Value
<> oContent(i).Value Then
680 oContent(i).Value = TargetProperties(a).Value
684 If Not EqualUnoObjects(TargetProperties(a).Value, oContent(i).Value) Then
685 oContent(i).Value = TargetProperties(a).Value
691 ModifyPropertyValue() = bDoReplace
695 Function GetPropertyValueIndex(SearchName as String, TargetProperties() as New com.sun.star.beans.PropertyValue ) as Integer
697 For i =
0 To Ubound(TargetProperties())
698 If Searchname = TargetProperties(i).Name Then
699 GetPropertyValueIndex = i
703 GetPropertyValueIndex() = -
1
707 Sub DispatchSlot(SlotID as Integer)
708 Dim oArg() as new com.sun.star.beans.PropertyValue
709 Dim oUrl as new com.sun.star.util.URL
712 oTrans = createUNOService(
"com.sun.star.util.URLTransformer
")
713 oUrl.Complete =
"slot:
" & CStr(SlotID)
714 oTrans.parsestrict(oUrl)
715 oDisp = StarDesktop.ActiveFrame.queryDispatch(oUrl,
"_self
",
0)
716 oDisp.dispatch(oUrl, oArg())
720 'returns the type of the office application
721 'FatOffice =
0, WebTop =
1
722 'This routine has to be changed if the Product Name is being changed!
723 Function IsFatOffice() As Boolean
724 If sProductname =
"" Then
725 sProductname = GetProductname()
728 'The following line has to include the current productname
729 If Instr(
1,sProductname,
"WebTop
",
1)
<> 0 Then
735 Function GetLocale(sLanguage as String, sCountry as String)
736 Dim oLocale as New com.sun.star.lang.Locale
737 oLocale.Language = sLanguage
738 oLocale.Country = sCountry
743 Sub ToggleDesignMode(oDocument as Object)
744 Dim aSwitchMode as new com.sun.star.util.URL
745 aSwitchMode.Complete =
".uno:SwitchControlDesignMode
"
746 aTransformer = createUnoService(
"com.sun.star.util.URLTransformer
")
747 aTransformer.parseStrict(aSwitchMode)
748 oFrame = oDocument.currentController.Frame
749 oDispatch = oFrame.queryDispatch(aSwitchMode, oFrame.Name,
63)
750 Dim aEmptyArgs() as New com.sun.star.bean.PropertyValue
751 oDispatch.dispatch(aSwitchMode, aEmptyArgs())
756 Function isHighContrast(oPeer as Object)
759 Dim myGreen as Integer
760 Dim myBlue as Integer
761 Dim myLuminance as Double
763 UIColor = oPeer.getProperty(
"DisplayBackgroundColor
" )
764 myRed = Red (UIColor)
765 myGreen = Green (UIColor)
766 myBlue = Blue (UIColor)
767 myLuminance = (( myBlue*
28 + myGreen*
151 + myRed*
77 ) /
256 )
768 isHighContrast = false
769 If myLuminance
<=
25 Then isHighContrast = true
773 Function CreateNewDocument(sType as String, Optional sAddMsg as String) as Object
774 Dim NoArgs() as new com.sun.star.beans.PropertyValue
775 Dim oDocument as Object
778 On Local Error Goto NOMODULEINSTALLED
779 sUrl =
"private:factory/
" & sType
780 oDocument = StarDesktop.LoadComponentFromURL(sUrl,
"_default
",
0, NoArgs())
782 If (Err
<> 0) OR IsNull(oDocument) Then
783 If InitResources(
"",
"com
") Then
785 Case
"swriter
"
786 ErrMsg = GetResText(
1001)
787 Case
"scalc
"
788 ErrMsg = GetResText(
1002)
789 Case
"simpress
"
790 ErrMsg = GetResText(
1003)
791 Case
"sdraw
"
792 ErrMsg = GetResText(
1004)
793 Case
"smath
"
794 ErrMsg = GetResText(
1005)
796 ErrMsg =
"Invalid Document Type!
"
798 ErrMsg = ReplaceString(ErrMsg, chr(
13),
"<BR
>")
799 If Not IsMissing(sAddMsg) Then
800 ErrMsg = ErrMsg
& chr(
13)
& sAddMsg
802 Msgbox(ErrMsg,
48, GetProductName())
804 If Err
<> 0 Then
809 CreateNewDocument = oDocument
813 ' This Sub has been used in order to ensure that after disposing a document
814 ' from the backing window it is returned to the backing window, so the
815 ' office won
't be closed
816 Sub DisposeDocument(oDocument as Object)
817 Dim dispatcher as Object
820 Dim url as new com.sun.star.util.URL
821 Dim NoArgs() as New com.sun.star.beans.PropertyValue
823 If Not IsNull(oDocument) Then
824 oDocument.setModified(false)
825 parser = createUnoService(
"com.sun.star.util.URLTransformer
")
826 url.Complete =
".uno:CloseDoc
"
827 parser.parseStrict(url)
828 oFrame = oDocument.CurrentController.Frame
829 disp = oFrame.queryDispatch(url,
"_self
", com.sun.star.util.SearchFlags.NORM_WORD_ONLY)
830 disp.dispatch(url, NoArgs())
834 'Function to calculate if the year is a leap year
835 Function CalIsLeapYear(ByVal iYear as Integer) as Boolean
836 CalIsLeapYear = ((iYear Mod
4 =
0) And ((iYear Mod
100 <> 0) Or (iYear Mod
400 =
0)))