xref: /aoo42x/main/wizards/source/tools/Misc.xba (revision cdf0e10c)
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)&apos; as String
12*cdf0e10cSrcweir	PropList(0,0) = &quot;URL&quot;
13*cdf0e10cSrcweir	PropList(0,1) = &quot;sdbc:odbc:Erica_Test_Unicode&quot;
14*cdf0e10cSrcweir	PropList(1,0) = &quot;User&quot;
15*cdf0e10cSrcweir	PropList(1,1) = &quot;extra&quot;
16*cdf0e10cSrcweir	PropList(2,0) = &quot;Password&quot;
17*cdf0e10cSrcweir	PropList(2,1) = &quot;extra&quot;
18*cdf0e10cSrcweir	PropList(3,0) = &quot;IsPasswordRequired&quot;
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(&quot;com.sun.star.sdb.DatabaseContext&quot;)
29*cdf0e10cSrcweir    oDataSource = createUnoService(&quot;com.sun.star.sdb.DataSource&quot;)
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&apos; 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&apos;	On Local Error Goto NOCONNECTION
48*cdf0e10cSrcweir	oDBContext = CreateUnoService(&quot;com.sun.star.sdb.DatabaseContext&quot;)
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(&quot;DataSource &quot; &amp; DSName &amp; &quot; is not registered&quot; , 16, GetProductname())
63*cdf0e10cSrcweir			ConnectToDatabase() = NULL
64*cdf0e10cSrcweir		End If
65*cdf0e10cSrcweir	End If
66*cdf0e10cSrcweirNOCONNECTION:
67*cdf0e10cSrcweir	If Err &lt;&gt; 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(&quot;org.openoffice.Setup/L10N/&quot;)
81*cdf0e10cSrcweir	sLocale = oMasterKey.getByName(&quot;ooLocale&quot;)
82*cdf0e10cSrcweir	sLocaleList() = ArrayoutofString(sLocale, &quot;-&quot;)
83*cdf0e10cSrcweir	aLocLocale.Language = sLocaleList(0)
84*cdf0e10cSrcweir	If Ubound(sLocaleList()) &gt; 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(&quot;com.sun.star.configuration.ConfigurationProvider&quot;)
95*cdf0e10cSrcweir	aNodePath(0).Name = &quot;nodepath&quot;
96*cdf0e10cSrcweir	aNodePath(0).Value = sKeyName
97*cdf0e10cSrcweir	If IsMissing(bForUpdate) Then
98*cdf0e10cSrcweir		GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationAccess&quot;, aNodePath())
99*cdf0e10cSrcweir	Else
100*cdf0e10cSrcweir		If bForUpdate Then
101*cdf0e10cSrcweir			GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationUpdateAccess&quot;, aNodePath())
102*cdf0e10cSrcweir		Else
103*cdf0e10cSrcweir			GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationAccess&quot;, 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(&quot;org.openoffice.Setup/Product&quot;)
114*cdf0e10cSrcweir	sProdName = oProdNameAccess.getByName(&quot;ooName&quot;)
115*cdf0e10cSrcweir	sVersion = oProdNameAccess.getByName(&quot;ooSetupVersion&quot;)
116*cdf0e10cSrcweir	GetProductName = sProdName &amp; sVersion
117*cdf0e10cSrcweirEnd Function
118*cdf0e10cSrcweir
119*cdf0e10cSrcweir
120*cdf0e10cSrcweir&apos; Opens a Document, checks beforehand, wether it has to be loaded
121*cdf0e10cSrcweir&apos; or wether it is already on the desktop.
122*cdf0e10cSrcweir&apos; If the parameter bDisposable is set to False then then returned document
123*cdf0e10cSrcweir&apos; 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	&apos; 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,&quot;com.sun.star.frame.XModel&quot;) 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,&quot;_default&quot;,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	&apos; 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,&quot;com.sun.star.frame.XModel&quot;) 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&apos; 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,&quot;/&quot;,MaxArrIndex)
174*cdf0e10cSrcweir	RetrieveFileName = LocURLArray(MaxArrIndex)
175*cdf0e10cSrcweirEnd Function
176*cdf0e10cSrcweir
177*cdf0e10cSrcweir
178*cdf0e10cSrcweir&apos; 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(&quot;com.sun.star.util.PathSettings&quot;)
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		&apos; Share and User-Directory
197*cdf0e10cSrcweir		If Instr(1,sPath,&quot;;&quot;) &lt;&gt; 0 Then
198*cdf0e10cSrcweir			PathList = ArrayoutofString(sPath,&quot;;&quot;, MaxIndex)
199*cdf0e10cSrcweir			If ListIndex &lt;= MaxIndex Then
200*cdf0e10cSrcweir				sPath = PathList(ListIndex)
201*cdf0e10cSrcweir			Else
202*cdf0e10cSrcweir				Msgbox(&quot;String Cannot be analyzed!&quot; &amp; sPath , 16, GetProductName())
203*cdf0e10cSrcweir			End If
204*cdf0e10cSrcweir		End If
205*cdf0e10cSrcweir	End If
206*cdf0e10cSrcweir	If Instr(1, sPath, &quot;;&quot;) = 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&apos; Gets the fully qualified path to a subdirectory of the
217*cdf0e10cSrcweir&apos; Template Directory, e. g. with the parameter &quot;wizard/bitmap&quot;
218*cdf0e10cSrcweir&apos; The parameter must be passed over in Url-scription
219*cdf0e10cSrcweir&apos; 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(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
229*cdf0e10cSrcweir	sOfficeString = GetPathSettings(sOfficePath)
230*cdf0e10cSrcweir	If Right(sSubDir,1) &lt;&gt; &quot;/&quot; Then
231*cdf0e10cSrcweir		sSubDir = sSubDir &amp; &quot;/&quot;
232*cdf0e10cSrcweir	End If
233*cdf0e10cSrcweir	sOfficeList() = ArrayoutofString(sOfficeString,&quot;;&quot;, MaxIndex)
234*cdf0e10cSrcweir	For i = 0 To MaxIndex
235*cdf0e10cSrcweir		sOfficeDir = ConvertToUrl(sOfficeList(i))
236*cdf0e10cSrcweir		If Right(sOfficeDir,1) &lt;&gt; &quot;/&quot; Then
237*cdf0e10cSrcweir			sOfficeDir = sOfficeDir &amp; &quot;/&quot;
238*cdf0e10cSrcweir		End If
239*cdf0e10cSrcweir		sBigDir = sOfficeDir &amp; 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 = &quot;&quot;
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(&quot;Tools&quot;, &quot;com&quot;) Then
260*cdf0e10cSrcweir		ProductName = GetProductName()
261*cdf0e10cSrcweir		sError = GetResText(1006)
262*cdf0e10cSrcweir		sError = ReplaceString(sError, ProductName, &quot;%PRODUCTNAME&quot;)
263*cdf0e10cSrcweir		sError = ReplaceString(sError, chr(13), &quot;&lt;BR&gt;&quot;)
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( &quot;com.sun.star.resource.VclStringResourceLoader&quot; )
276*cdf0e10cSrcweir	If (IsNull(oResSrv)) then
277*cdf0e10cSrcweir		InitResources = FALSE
278*cdf0e10cSrcweir		MsgBox( Description &amp; &quot;: No resource loader found&quot;, 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(&quot;Resource file missing (&quot; &amp; ShortDescription  &amp; trim(str(nSolarVer)) + &quot;*.res)&quot;, 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 = &quot;&quot;
300*cdf0e10cSrcweir	End If
301*cdf0e10cSrcweir	Exit Function
302*cdf0e10cSrcweirErrorOcurred:
303*cdf0e10cSrcweir	GetResText = &quot;&quot;
304*cdf0e10cSrcweir	MsgBox(&quot;Resource with ID =&quot; + str( nID ) + &quot; not found!&quot;, 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 &gt; 60 Then
317*cdf0e10cSrcweir		FileName = FileNameoutofPath(sViewPath, &quot;/&quot;)
318*cdf0e10cSrcweir		iFileLen = Len(FileName)
319*cdf0e10cSrcweir		If iFileLen &lt; 44 Then
320*cdf0e10cSrcweir			sViewPath = Left(sViewPath,57-iFileLen-10) &amp; &quot;...&quot; &amp; Right(sViewPath,iFileLen + 10)
321*cdf0e10cSrcweir		Else
322*cdf0e10cSrcweir			sViewPath = Left(sViewPath,27) &amp; &quot; ... &quot; &amp; Right(sViewPath,28)
323*cdf0e10cSrcweir		End If
324*cdf0e10cSrcweir	End If
325*cdf0e10cSrcweir	CutPathView = sViewPath
326*cdf0e10cSrcweirEnd Function
327*cdf0e10cSrcweir
328*cdf0e10cSrcweir
329*cdf0e10cSrcweir&apos; Deletes the content of all cells that are softformatted according
330*cdf0e10cSrcweir&apos; to the &apos;InputStyleName&apos;
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) &lt;&gt; 0 Then
338*cdf0e10cSrcweir			Call ReplaceRangeValues(oRange, &quot;&quot;)
339*cdf0e10cSrcweir		End If
340*cdf0e10cSrcweir	Wend
341*cdf0e10cSrcweirEnd Sub
342*cdf0e10cSrcweir
343*cdf0e10cSrcweir
344*cdf0e10cSrcweir&apos; Inserts a certain String to all cells of a Range that ist passed over
345*cdf0e10cSrcweir&apos; 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		&apos; Get the Range out of the Rangename
350*cdf0e10cSrcweir		oCellRange = oSheet.GetCellRangeByName(Range)
351*cdf0e10cSrcweir	Else
352*cdf0e10cSrcweir		&apos; 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&apos; 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&apos; 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&apos; 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&apos; 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 = &quot;=Value(&quot; &amp; &quot;&quot;&quot;&quot; &amp; ValueString &amp; &quot;&quot;&quot;&quot; &amp; &quot;)&quot;
431*cdf0e10cSrcweir	CellValue = oCell.Value
432*cdf0e10cSrcweir	oCell.Formula = &quot;&quot;
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&apos;	ShowSupportedServiceNames(oDocument)
440*cdf0e10cSrcweir	If oDocument.SupportsService(&quot;com.sun.star.sheet.SpreadsheetDocument&quot;) Then
441*cdf0e10cSrcweir		GetDocumentType() = &quot;scalc&quot;
442*cdf0e10cSrcweir	ElseIf oDocument.SupportsService(&quot;com.sun.star.text.TextDocument&quot;) Then
443*cdf0e10cSrcweir		GetDocumentType() = &quot;swriter&quot;
444*cdf0e10cSrcweir	ElseIf oDocument.SupportsService(&quot;com.sun.star.drawing.DrawingDocument&quot;) Then
445*cdf0e10cSrcweir		GetDocumentType() = &quot;sdraw&quot;
446*cdf0e10cSrcweir	ElseIf oDocument.SupportsService(&quot;com.sun.star.presentation.PresentationDocument&quot;) Then
447*cdf0e10cSrcweir		GetDocumentType() = &quot;simpress&quot;
448*cdf0e10cSrcweir	ElseIf oDocument.SupportsService(&quot;com.sun.star.formula.FormulaProperties&quot;) Then
449*cdf0e10cSrcweir		GetDocumentType() = &quot;smath&quot;
450*cdf0e10cSrcweir	End If
451*cdf0e10cSrcweir	NODOCUMENTTYPE:
452*cdf0e10cSrcweir	If Err &lt;&gt; 0 Then
453*cdf0e10cSrcweir		GetDocumentType = &quot;&quot;
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 &lt;&gt; 0 Then
469*cdf0e10cSrcweir		Msgbox(&quot;Numberformat of Object is not available!&quot;, 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(&quot;&quot;)
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(&quot;&quot;)
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	&apos; 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 &lt;&gt; 0 Then
535*cdf0e10cSrcweir		&apos; Test if renaming failed
536*cdf0e10cSrcweir		Count = 2
537*cdf0e10cSrcweir		Do While oSheet.Name &lt;&gt; NewName
538*cdf0e10cSrcweir			NewName = BasicSheetName &amp; &quot;_&quot; &amp; 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&apos; 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(&quot;com.sun.star.i18n.CharacterClassification&quot;)
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, &quot;&quot;, nContFlags, &quot; &quot;)
574*cdf0e10cSrcweir		iResultPos = oResult.EndPos
575*cdf0e10cSrcweir		If iResultPos &lt; iSheetNameLength Then
576*cdf0e10cSrcweir			WrongChar = Mid(SheetName, iResultPos+1,1)
577*cdf0e10cSrcweir			SheetName = ReplaceString(SheetName,&quot;_&quot;, 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) &amp; &quot;_&quot; &amp; 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&apos; Note To set a one lined frame you have to set the inner width to 0
626*cdf0e10cSrcweir&apos; In the API all Units that refer to pt-Heights are &quot;1/100mm&quot;
627*cdf0e10cSrcweir&apos; 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 = &quot;EventType&quot;
640*cdf0e10cSrcweir	PropValue(0).Value = &quot;StarBasic&quot;
641*cdf0e10cSrcweir	PropValue(1).Name = &quot;Script&quot;
642*cdf0e10cSrcweir	PropValue(1).Value = &quot;macro:///&quot; &amp; 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 &lt;&gt; -1 Then
657*cdf0e10cSrcweir			If Vartype(TargetProperties(a).Value) &lt;&gt; 9 Then
658*cdf0e10cSrcweir				If TargetProperties(a).Value &lt;&gt; 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(&quot;com.sun.star.util.URLTransformer&quot;)
692*cdf0e10cSrcweir	oUrl.Complete = &quot;slot:&quot; &amp; CStr(SlotID)
693*cdf0e10cSrcweir	oTrans.parsestrict(oUrl)
694*cdf0e10cSrcweir	oDisp = StarDesktop.ActiveFrame.queryDispatch(oUrl, &quot;_self&quot;, 0)
695*cdf0e10cSrcweir	oDisp.dispatch(oUrl, oArg())
696*cdf0e10cSrcweirEnd Sub
697*cdf0e10cSrcweir
698*cdf0e10cSrcweir
699*cdf0e10cSrcweir&apos;returns the type of the office application
700*cdf0e10cSrcweir&apos;FatOffice = 0, WebTop = 1
701*cdf0e10cSrcweir&apos;This routine has to be changed if the Product Name is being changed!
702*cdf0e10cSrcweirFunction IsFatOffice() As Boolean
703*cdf0e10cSrcweir  If sProductname = &quot;&quot; Then
704*cdf0e10cSrcweir    sProductname = GetProductname()
705*cdf0e10cSrcweir  End If
706*cdf0e10cSrcweir  IsFatOffice = TRUE
707*cdf0e10cSrcweir  &apos;The following line has to include the current productname
708*cdf0e10cSrcweir  If Instr(1,sProductname,&quot;WebTop&quot;,1) &lt;&gt; 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 = &quot;.uno:SwitchControlDesignMode&quot;
725*cdf0e10cSrcweir	aTransformer = createUnoService(&quot;com.sun.star.util.URLTransformer&quot;)
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( &quot;DisplayBackgroundColor&quot; )
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 &lt;= 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 = &quot;private:factory/&quot; &amp; sType
759*cdf0e10cSrcweir	oDocument = StarDesktop.LoadComponentFromURL(sUrl,&quot;_default&quot;,0, NoArgs())
760*cdf0e10cSrcweirNOMODULEINSTALLED:
761*cdf0e10cSrcweir	If (Err &lt;&gt; 0) OR IsNull(oDocument) Then
762*cdf0e10cSrcweir		If InitResources(&quot;&quot;, &quot;com&quot;) Then
763*cdf0e10cSrcweir			Select Case sType
764*cdf0e10cSrcweir				Case &quot;swriter&quot;
765*cdf0e10cSrcweir					ErrMsg = GetResText(1001)
766*cdf0e10cSrcweir				Case &quot;scalc&quot;
767*cdf0e10cSrcweir					ErrMsg = GetResText(1002)
768*cdf0e10cSrcweir				Case &quot;simpress&quot;
769*cdf0e10cSrcweir					ErrMsg = GetResText(1003)
770*cdf0e10cSrcweir				Case &quot;sdraw&quot;
771*cdf0e10cSrcweir					ErrMsg = GetResText(1004)
772*cdf0e10cSrcweir				Case &quot;smath&quot;
773*cdf0e10cSrcweir					ErrMsg = GetResText(1005)
774*cdf0e10cSrcweir				Case Else
775*cdf0e10cSrcweir					ErrMsg = &quot;Invalid Document Type!&quot;
776*cdf0e10cSrcweir			End Select
777*cdf0e10cSrcweir			ErrMsg = ReplaceString(ErrMsg, chr(13), &quot;&lt;BR&gt;&quot;)
778*cdf0e10cSrcweir			If Not IsMissing(sAddMsg) Then
779*cdf0e10cSrcweir				ErrMsg = ErrMsg &amp; chr(13) &amp; sAddMsg
780*cdf0e10cSrcweir			End If
781*cdf0e10cSrcweir			Msgbox(ErrMsg, 48, GetProductName())
782*cdf0e10cSrcweir		End If
783*cdf0e10cSrcweir		If Err &lt;&gt; 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&apos; This Sub has been used in order to ensure that after disposing a document
793*cdf0e10cSrcweir&apos; from the backing window it is returned to the backing window, so the
794*cdf0e10cSrcweir&apos; office won&apos;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(&quot;com.sun.star.util.URLTransformer&quot;)
805*cdf0e10cSrcweir		url.Complete = &quot;.uno:CloseDoc&quot;
806*cdf0e10cSrcweir		parser.parseStrict(url)
807*cdf0e10cSrcweir		oFrame = oDocument.CurrentController.Frame
808*cdf0e10cSrcweir		disp = oFrame.queryDispatch(url,&quot;_self&quot;, 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&apos;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 &lt;&gt; 0) Or (iYear Mod 400 = 0)))
816*cdf0e10cSrcweirEnd Function
817*cdf0e10cSrcweir</script:module>