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=
"tools" script:
language=
"StarBasic">REM ***** BASIC *****
22 Public Const SBMAXTEXTSIZE =
50
25 Function SetProgressValue(iValue as Integer)
29 ProgressValue = iValue
30 oProgressbar.Value = iValue
34 Function GetPreferredWidth(oModel as Object, bGetMaxWidth as Boolean, Optional LocText)
35 Dim aPeerSize as new com.sun.star.awt.Size
37 Dim oControl as Object
38 If Not IsMissing(LocText) Then
40 aPeerSize = GetPeerSize(oModel, oControl, LocText)
41 ElseIf CurControlType = cImageControl Then
42 GetPreferredWidth() =
2000
45 aPeerSize = GetPeerSize(oModel, oControl)
47 nWidth = aPeerSize.Width
48 ' We increase the preferred Width a bit so that the control does not become too small
49 ' when we change the border from
"3D
" to
"Flat
"
50 GetPreferredWidth = (nWidth +
10) * XPixelFactor
' PixelTo100thmm(nWidth)
54 Function GetPreferredHeight(oModel as Object, Optional LocText)
55 Dim aPeerSize as new com.sun.star.awt.Size
56 Dim nHeight as Integer
57 Dim oControl as Object
58 If Not IsMissing(LocText) Then
60 aPeerSize = GetPeerSize(oModel, oControl, LocText)
61 ElseIf CurControlType = cImageControl Then
62 GetPreferredHeight() =
2000
65 aPeerSize = GetPeerSize(oModel, oControl)
67 nHeight = aPeerSize.Height
68 ' We increase the preferred Height a bit so that the control does not become too small
69 ' when we change the border from
"3D
" to
"Flat
"
70 GetPreferredHeight = (nHeight+
1) * YPixelFactor
' PixelTo100thmm(nHeight)
74 Function GetPeerSize(oModel as Object, oControl as Object, Optional LocText)
76 Dim aPeerSize as new com.sun.star.awt.Size
78 oControl = oController.GetControl(oModel)
79 oPeer = oControl.GetPeer()
80 If oControl.Model.PropertySetInfo.HasPropertybyName(
"EffectiveMax
") Then
81 If oControl.Model.EffectiveMax =
0 Then
82 ' This is relevant for decimal fields
83 oControl.Model.EffectiveValue =
999.9999
85 oControl.Model.EffectiveValue = oControl.Model.EffectiveMax
87 GetPeerSize() = oPeer.PreferredSize()
88 oControl.Model.EffectiveValue = NullValue
89 ElseIf Not IsMissing(LocText) Then
90 oControl.Text = LocText
91 GetPeerSize() = oPeer.PreferredSize()
92 ElseIf CurFieldType = com.sun.star.sdbc.DataType.BIT Then
93 GetPeerSize() = oPeer.PreferredSize()
94 ElseIf CurFieldType = com.sun.star.sdbc.DataType.BOOLEAN Then
95 GetPeerSize() = oPeer.PreferredSize()
96 ElseIf CurFieldType = com.sun.star.sdbc.DataType.DATE Then
97 oControl.Model.Date = Date
98 GetPeerSize() = oPeer.PreferredSize()
99 oControl.Model.Date = NullValue
100 ElseIf CurFieldType = com.sun.star.sdbc.DataType.TIME Then
102 GetPeerSize() = oPeer.PreferredSize()
103 oControl.Time = NullValue
105 If oControl.MaxTextLen
> SBMAXTEXTSIZE Then
106 oControl.Text = Mid(SBSIZETEXT,
1, SBMAXTEXTSIZE)
108 oControl.Text = Mid(SBSIZETEXT,
1, oControl.MaxTextLen)
110 GetPeerSize() = oPeer.PreferredSize()
111 oControl.Text =
""
116 Function TwipToCM(ByVal nValue as long) as String
117 TwipToCM = trim(str(nValue /
567)) +
"cm
"
121 Function TwipTo100telMM(ByVal nValue as long) as long
122 TwipTo100telMM = nValue /
0.567
126 Function TwipToPixel(ByVal nValue as long) as long
' not an exact calculation
127 TwipToPixel = nValue /
15
131 Function PixelTo100thMMX(oControl as Object) as long
132 oPeer = oControl.GetPeer()
133 PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterX/
100000)
135 ' PixelTo100thMM = nValue *
28 ' not an exact calculation
139 Function PixelTo100thMMY(oControl as Object) as long
140 oPeer = oControl.GetPeer()
141 PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterY/
100000)
143 ' PixelTo100thMM = nValue *
28 ' not an exact calculation
147 Function GetPoint(xPos, YPos) as New com.sun.star.awt.Point
148 Dim aPoint as New com.sun.star.awt.Point
155 Function GetSize(iWidth, iHeight) As New com.sun.star.awt.Size
156 Dim aSize As New com.sun.star.awt.Size
158 aSize.Height = iHeight
164 Dim OldIndex as Integer
166 On Local Error GoTo WIZARDERROR
169 CurIndex = GetCurIndex(DialogModel.lstStyles, Styles(),
8)
170 If CurIndex
<> OldIndex Then
171 ToggleLayoutPage(False)
172 Dim sImportPath as String
173 sImportPath = Styles(CurIndex,
8)
174 bWithBackGraphic = LoadNewStyles(oDocument, DialogModel, CurIndex, sImportPath, Styles(), TexturePath)
175 ControlCaptionsToStandardLayout()
176 ToggleLayoutPage(True,
"lstStyles
")
179 If Err
<> 0 Then
180 Msgbox(sMsgErrMsg,
16, GetProductName())
188 Function SetNumerics(ByVal oLocObject as Object, iLocFieldType as Integer) as Object
189 If CurControlType = cNumericBox Then
190 oLocObject.TreatAsNumber = True
191 Select Case iLocFieldType
192 Case com.sun.star.sdbc.DataType.BIGINT
193 oLocObject.EffectiveMax =
2147483647 *
2147483647
194 oLocObject.EffectiveMin = -(-
2147483648 * -
2147483648)
195 ' oLocObject.DecimalAccuracy =
0
196 Case com.sun.star.sdbc.DataType.INTEGER
197 oLocObject.EffectiveMax =
2147483647
198 oLocObject.EffectiveMin = -
2147483648
199 Case com.sun.star.sdbc.DataType.SMALLINT
200 oLocObject.EffectiveMax =
32767
201 oLocObject.EffectiveMin = -
32768
202 Case com.sun.star.sdbc.DataType.TINYINT
203 oLocObject.EffectiveMax =
127
204 oLocObject.EffectiveMin = -
128
205 Case com.sun.star.sdbc.DataType.FLOAT, com.sun.star.sdbc.DataType.REAL, com.sun.star.sdbc.DataType.DOUBLE, com.sun.star.sdbc.DataType.DECIMAL, com.sun.star.sdbc.DataType.NUMERIC
206 'Todo: oLocObject.DecimalAccuracy = ...
207 oLocObject.EffectiveDefault = CurDefaultValue
208 ' Todo: HelpText???
210 If oLocObject.PropertySetinfo.HasPropertyByName(
"Width
")Then
' Note: an Access AutoincrementField does not provide this property Width
211 oLocObject.Width = CurFieldLength + CurScale +
1
213 If CurIsCurrency Then
214 'Todo: How do you set currencies?
216 ElseIf CurControlType = cTextBox Then
'com.sun.star.sdbc.DataType.CHAR, com.sun.star.sdbc.DataType.VARCHAR, com.sun.star.sdbc.DataType.LONGVARCHAR
217 If CurFieldLength =
0 Then
'Or oLocObject.MaxTextLen
> SBMAXTEXTSIZE
218 oLocObject.MaxTextLen = SBMAXTEXTSIZE
219 CurFieldLength = SBMAXTEXTSIZE
221 oLocObject.MaxTextLen = CurFieldLength
223 oLocObject.DefaultText = CurDefaultValue
224 ElseIf CurControlType = cDateBox Then
225 ' Todo Why does this not work?: oLocObject.DefaultDate = CurDefaultValue
226 ElseIf CurControlType = cTimeBox Then
' com.sun.star.sdbc.DataType.DATE, com.sun.star.sdbc.DataType.TIME
227 oLocObject.DefaultTime = CurDefaultValue
228 ' Todo: Property TimeFormat? from where?
229 ElseIf CurControlType = cCheckBox Then
230 ' Todo Why does this not work?: oLocObject.DefaultState = CurDefaultValue
232 If oLocObject.PropertySetInfo.HasPropertybyName(
"FormatKey
") Then
233 On Local Error Resume Next
234 oLocObject.FormatKey = CurFormatKey
239 ' Destroy all Shapes in Nirwana
242 Dim oControl as Object
244 For n = oDrawPage.Count-
1 To
0 Step -
1
245 oShape = oDrawPage(n)
246 If oShape.Position.Y
> -
2000 Then
247 oDrawPage.Remove(oShape)
253 ' Destroy all Shapes in Nirwana
254 Sub RemoveNirwanaShapes()
256 Dim oControl as Object
258 For n = oDrawPage.Count-
1 To
0 Step -
1
259 oShape = oDrawPage(n)
260 If oShape.Position.Y
< -
2000 Then
261 oDrawPage.Remove(oShape)
268 ' Note: as Shapes cannot be removed from the DrawPage without destroying
269 ' the object we have to park them somewhere beyond the visible area of the page
270 Sub ShapesToNirwana()
272 Dim oControl as Object
273 For n =
0 To oDrawPage.Count-
1
274 oDrawPage(n).Position = GetPoint(-
20, -
10000)
279 Function CalcUniqueContentName(ByVal oContainer as Object, sBaseName as String) as String
281 Dim nPostfix as Integer
282 Dim sReturn as String
285 while (oContainer.hasByName(sReturn))
286 sReturn = sBaseName
& nPostfix
287 nPostfix = nPostfix +
1
289 CalcUniqueContentName = sReturn
293 Function CountItemsInArray(BigArray(), SearchItem)
295 Dim MaxIndex as Integer
296 Dim ResCount as Integer
298 MaxIndex = Ubound(BigArray())
299 For i =
0 To MaxIndex
300 If SearchItem = BigArray(i) Then
301 ResCount = ResCount +
1
304 CountItemsInArray() = ResCount
308 Function GetDBHeight(oDBModel as Object)
309 If CurControlType = cImageControl Then
312 If CurFieldType = com.sun.star.sdbc.DataType.LONGVARCHAR Then
313 oDBModel.MultiLine = True
314 nDBHeight = nDBRefHeight *
4
316 nDBHeight = nDBRefHeight
319 GetDBHeight() = nDBHeight
323 Function GetFormWizardPaths() as Boolean
324 FormPath = GetOfficeSubPath(
"Template
",
"../wizard/bitmap
")
325 If FormPath
<> "" Then
326 WizardPath = GetOfficeSubPath(
"Template
",
"wizard/
")
327 If Wizardpath
<> "" Then
328 TexturePath = GetOfficeSubPath(
"Gallery
",
"backgrounds/
")
329 If TexturePath
<> "" Then
330 WorkPath = GetPathSettings(
"Work
")
331 If WorkPath
<> "" Then
332 TempPath = GetPathSettings(
"Temp
")
333 If TempPath
<> "" Then
334 GetFormWizardPaths = True
341 DisposeDocument(oDocument)
342 GetFormWizardPaths() = False
346 Function GetFilterName(sApplicationKey as String) as String
350 Dim Maxindex as Integer
352 oFactory = createUnoService(
"com.sun.star.document.FilterFactory
")
353 oArgs() = oFactory.getByName(sApplicationKey)
354 MaxIndex = Ubound(oArgs())
355 For i =
0 to MaxIndex
356 If (oArgs(i).Name=
"UIName
") Then
357 UIName = oArgs(i).Value
361 GetFilterName() = UIName