1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"tools" script:
language=
"StarBasic">REM ***** BASIC *****
5 Public Const SBMAXTEXTSIZE =
50
8 Function SetProgressValue(iValue as Integer)
12 ProgressValue = iValue
13 oProgressbar.Value = iValue
17 Function GetPreferredWidth(oModel as Object, bGetMaxWidth as Boolean, Optional LocText)
18 Dim aPeerSize as new com.sun.star.awt.Size
20 Dim oControl as Object
21 If Not IsMissing(LocText) Then
23 aPeerSize = GetPeerSize(oModel, oControl, LocText)
24 ElseIf CurControlType = cImageControl Then
25 GetPreferredWidth() =
2000
28 aPeerSize = GetPeerSize(oModel, oControl)
30 nWidth = aPeerSize.Width
31 ' We increase the preferred Width a bit so that the control does not become too small
32 ' when we change the border from
"3D
" to
"Flat
"
33 GetPreferredWidth = (nWidth +
10) * XPixelFactor
' PixelTo100thmm(nWidth)
37 Function GetPreferredHeight(oModel as Object, Optional LocText)
38 Dim aPeerSize as new com.sun.star.awt.Size
39 Dim nHeight as Integer
40 Dim oControl as Object
41 If Not IsMissing(LocText) Then
43 aPeerSize = GetPeerSize(oModel, oControl, LocText)
44 ElseIf CurControlType = cImageControl Then
45 GetPreferredHeight() =
2000
48 aPeerSize = GetPeerSize(oModel, oControl)
50 nHeight = aPeerSize.Height
51 ' We increase the preferred Height a bit so that the control does not become too small
52 ' when we change the border from
"3D
" to
"Flat
"
53 GetPreferredHeight = (nHeight+
1) * YPixelFactor
' PixelTo100thmm(nHeight)
57 Function GetPeerSize(oModel as Object, oControl as Object, Optional LocText)
59 Dim aPeerSize as new com.sun.star.awt.Size
61 oControl = oController.GetControl(oModel)
62 oPeer = oControl.GetPeer()
63 If oControl.Model.PropertySetInfo.HasPropertybyName(
"EffectiveMax
") Then
64 If oControl.Model.EffectiveMax =
0 Then
65 ' This is relevant for decimal fields
66 oControl.Model.EffectiveValue =
999.9999
68 oControl.Model.EffectiveValue = oControl.Model.EffectiveMax
70 GetPeerSize() = oPeer.PreferredSize()
71 oControl.Model.EffectiveValue = NullValue
72 ElseIf Not IsMissing(LocText) Then
73 oControl.Text = LocText
74 GetPeerSize() = oPeer.PreferredSize()
75 ElseIf CurFieldType = com.sun.star.sdbc.DataType.BIT Then
76 GetPeerSize() = oPeer.PreferredSize()
77 ElseIf CurFieldType = com.sun.star.sdbc.DataType.BOOLEAN Then
78 GetPeerSize() = oPeer.PreferredSize()
79 ElseIf CurFieldType = com.sun.star.sdbc.DataType.DATE Then
80 oControl.Model.Date = Date
81 GetPeerSize() = oPeer.PreferredSize()
82 oControl.Model.Date = NullValue
83 ElseIf CurFieldType = com.sun.star.sdbc.DataType.TIME Then
85 GetPeerSize() = oPeer.PreferredSize()
86 oControl.Time = NullValue
88 If oControl.MaxTextLen
> SBMAXTEXTSIZE Then
89 oControl.Text = Mid(SBSIZETEXT,
1, SBMAXTEXTSIZE)
91 oControl.Text = Mid(SBSIZETEXT,
1, oControl.MaxTextLen)
93 GetPeerSize() = oPeer.PreferredSize()
94 oControl.Text =
""
99 Function TwipToCM(BYVAL nValue as long) as String
100 TwipToCM = trim(str(nValue /
567)) +
"cm
"
104 Function TwipTo100telMM(BYVAL nValue as long) as long
105 TwipTo100telMM = nValue /
0.567
109 Function TwipToPixel(BYVAL nValue as long) as long
' not an exact calculation
110 TwipToPixel = nValue /
15
114 Function PixelTo100thMMX(oControl as Object) as long
115 oPeer = oControl.GetPeer()
116 PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterX/
100000)
118 ' PixelTo100thMM = nValue *
28 ' not an exact calculation
122 Function PixelTo100thMMY(oControl as Object) as long
123 oPeer = oControl.GetPeer()
124 PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterY/
100000)
126 ' PixelTo100thMM = nValue *
28 ' not an exact calculation
130 Function GetPoint(xPos, YPos) as New com.sun.star.awt.Point
131 Dim aPoint as New com.sun.star.awt.Point
138 Function GetSize(iWidth, iHeight) As New com.sun.star.awt.Size
139 Dim aSize As New com.sun.star.awt.Size
141 aSize.Height = iHeight
147 Dim OldIndex as Integer
149 On Local Error GoTo WIZARDERROR
152 CurIndex = GetCurIndex(DialogModel.lstStyles, Styles(),
8)
153 If CurIndex
<> OldIndex Then
154 ToggleLayoutPage(False)
155 Dim sImportPath as String
156 sImportPath = Styles(CurIndex,
8)
157 bWithBackGraphic = LoadNewStyles(oDocument, DialogModel, CurIndex, sImportPath, Styles(), TexturePath)
158 ControlCaptionsToStandardLayout()
159 ToggleLayoutPage(True,
"lstStyles
")
162 If Err
<> 0 Then
163 Msgbox(sMsgErrMsg,
16, GetProductName())
171 Function SetNumerics(ByVal oLocObject as Object, iLocFieldType as Integer) as Object
172 If CurControlType = cNumericBox Then
173 oLocObject.TreatAsNumber = True
174 Select Case iLocFieldType
175 Case com.sun.star.sdbc.DataType.BIGINT
176 oLocObject.EffectiveMax =
2147483647 *
2147483647
177 oLocObject.EffectiveMin = -(-
2147483648 * -
2147483648)
178 ' oLocObject.DecimalAccuracy =
0
179 Case com.sun.star.sdbc.DataType.INTEGER
180 oLocObject.EffectiveMax =
2147483647
181 oLocObject.EffectiveMin = -
2147483648
182 Case com.sun.star.sdbc.DataType.SMALLINT
183 oLocObject.EffectiveMax =
32767
184 oLocObject.EffectiveMin = -
32768
185 Case com.sun.star.sdbc.DataType.TINYINT
186 oLocObject.EffectiveMax =
127
187 oLocObject.EffectiveMin = -
128
188 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
189 'Todo: oLocObject.DecimalAccuracy = ...
190 oLocObject.EffectiveDefault = CurDefaultValue
191 ' Todo: HelpText???
193 If oLocObject.PropertySetinfo.HasPropertyByName(
"Width
")Then
' Note: an Access AutoincrementField does not provide this property Width
194 oLocObject.Width = CurFieldLength + CurScale +
1
196 If CurIsCurrency Then
197 'Todo: How do you set currencies?
199 ElseIf CurControlType = cTextBox Then
'com.sun.star.sdbc.DataType.CHAR, com.sun.star.sdbc.DataType.VARCHAR, com.sun.star.sdbc.DataType.LONGVARCHAR
200 If CurFieldLength =
0 Then
'Or oLocObject.MaxTextLen
> SBMAXTEXTSIZE
201 oLocObject.MaxTextLen = SBMAXTEXTSIZE
202 CurFieldLength = SBMAXTEXTSIZE
204 oLocObject.MaxTextLen = CurFieldLength
206 oLocObject.DefaultText = CurDefaultValue
207 ElseIf CurControlType = cDateBox Then
208 ' Todo Why does this not work?: oLocObject.DefaultDate = CurDefaultValue
209 ElseIf CurControlType = cTimeBox Then
' com.sun.star.sdbc.DataType.DATE, com.sun.star.sdbc.DataType.TIME
210 oLocObject.DefaultTime = CurDefaultValue
211 ' Todo: Property TimeFormat? frome where?
212 ElseIf CurControlType = cCheckBox Then
213 ' Todo Why does this not work?: oLocObject.DefautState = CurDefaultValue
215 If oLocObject.PropertySetInfo.HasPropertybyName(
"FormatKey
") Then
216 On Local Error Resume Next
217 oLocObject.FormatKey = CurFormatKey
222 ' Destroy all Shapes in Nirwana
225 Dim oControl as Object
227 For n = oDrawPage.Count-
1 To
0 Step -
1
228 oShape = oDrawPage(n)
229 If oShape.Position.Y
> -
2000 Then
230 oDrawPage.Remove(oShape)
236 ' Destroy all Shapes in Nirwana
237 Sub RemoveNirwanaShapes()
239 Dim oControl as Object
241 For n = oDrawPage.Count-
1 To
0 Step -
1
242 oShape = oDrawPage(n)
243 If oShape.Position.Y
< -
2000 Then
244 oDrawPage.Remove(oShape)
251 ' Note: as Shapes cannot be removed from the DrawPage without destroying
252 ' the object we have to park them somewhere beyond the visible area of the page
253 Sub ShapesToNirwana()
255 Dim oControl as Object
256 For n =
0 To oDrawPage.Count-
1
257 oDrawPage(n).Position = GetPoint(-
20, -
10000)
262 Function CalcUniqueContentName(BYVAL oContainer as Object, sBaseName as String) as String
264 Dim nPostfix as Integer
265 Dim sReturn as String
268 while (oContainer.hasByName(sReturn))
269 sReturn = sBaseName
& nPostfix
270 nPostfix = nPostfix +
1
272 CalcUniqueContentName = sReturn
276 Function CountItemsInArray(BigArray(), SearchItem)
278 Dim MaxIndex as Integer
279 Dim ResCount as Integer
281 MaxIndex = Ubound(BigArray())
282 For i =
0 To MaxIndex
283 If SearchItem = BigArray(i) Then
284 ResCount = ResCount +
1
287 CountItemsInArray() = ResCount
291 Function GetDBHeight(oDBModel as Object)
292 If CurControlType = cImageControl Then
295 If CurFieldType = com.sun.star.sdbc.DataType.LONGVARCHAR Then
296 oDBModel.MultiLine = True
297 nDBHeight = nDBRefHeight *
4
299 nDBHeight = nDBRefHeight
302 GetDBHeight() = nDBHeight
306 Function GetFormWizardPaths() as Boolean
307 FormPath = GetOfficeSubPath(
"Template
",
"wizard/bitmap
")
308 If FormPath
<> "" Then
309 WebWizardPath = GetOfficeSubPath(
"Template
",
"wizard/web
")
310 If WebWizardPath
<> "" Then
311 WizardPath = GetOfficeSubPath(
"Template
",
"wizard/
")
312 If Wizardpath
<> "" Then
313 TexturePath = GetOfficeSubPath(
"Gallery
",
"www-back/
")
314 If TexturePath
<> "" Then
315 WorkPath = GetPathSettings(
"Work
")
316 If WorkPath
<> "" Then
317 TempPath = GetPathSettings(
"Temp
")
318 If TempPath
<> "" Then
319 GetFormWizardPaths = True
327 DisposeDocument(oDocument)
328 GetFormWizardPaths() = False
332 Function GetFilterName(sApplicationKey as String) as String
336 Dim Maxindex as Integer
338 oFactory = createUnoService(
"com.sun.star.document.FilterFactory
")
339 oArgs() = oFactory.getByName(sApplicationKey)
340 MaxIndex = Ubound(oArgs())
341 For i =
0 to MaxIndex
342 If (oArgs(i).Name=
"UIName
") Then
343 UIName = oArgs(i).Value
347 GetFilterName() = UIName