tools.xba 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <!--
  4. * This file is part of the LibreOffice project.
  5. *
  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/.
  9. *
  10. * This file incorporates work covered by the following license notice:
  11. *
  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 .
  19. -->
  20. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="tools" script:language="StarBasic">REM ***** BASIC *****
  21. Option Explicit
  22. Public Const SBMAXTEXTSIZE = 50
  23. Function SetProgressValue(iValue as Integer)
  24. If iValue = 0 Then
  25. oProgressbar.End
  26. End If
  27. ProgressValue = iValue
  28. oProgressbar.Value = iValue
  29. End Function
  30. Function GetPreferredWidth(oModel as Object, bGetMaxWidth as Boolean, Optional LocText)
  31. Dim aPeerSize as new com.sun.star.awt.Size
  32. Dim nWidth as Integer
  33. Dim oControl as Object
  34. If Not IsMissing(LocText) Then
  35. &apos; Label
  36. aPeerSize = GetPeerSize(oModel, oControl, LocText)
  37. ElseIf CurControlType = cImageControl Then
  38. GetPreferredWidth() = 2000
  39. Exit Function
  40. Else
  41. aPeerSize = GetPeerSize(oModel, oControl)
  42. End If
  43. nWidth = aPeerSize.Width
  44. &apos; We increase the preferred Width a bit so that the control does not become too small
  45. &apos; when we change the border from &quot;3D&quot; to &quot;Flat&quot;
  46. GetPreferredWidth = (nWidth + 10) * XPixelFactor &apos; PixelTo100thmm(nWidth)
  47. End Function
  48. Function GetPreferredHeight(oModel as Object, Optional LocText)
  49. Dim aPeerSize as new com.sun.star.awt.Size
  50. Dim nHeight as Integer
  51. Dim oControl as Object
  52. If Not IsMissing(LocText) Then
  53. &apos; Label
  54. aPeerSize = GetPeerSize(oModel, oControl, LocText)
  55. ElseIf CurControlType = cImageControl Then
  56. GetPreferredHeight() = 2000
  57. Exit Function
  58. Else
  59. aPeerSize = GetPeerSize(oModel, oControl)
  60. End If
  61. nHeight = aPeerSize.Height
  62. &apos; We increase the preferred Height a bit so that the control does not become too small
  63. &apos; when we change the border from &quot;3D&quot; to &quot;Flat&quot;
  64. GetPreferredHeight = (nHeight+1) * YPixelFactor &apos; PixelTo100thmm(nHeight)
  65. End Function
  66. Function GetPeerSize(oModel as Object, oControl as Object, Optional LocText)
  67. Dim oPeer as Object
  68. Dim aPeerSize as new com.sun.star.awt.Size
  69. Dim NullValue
  70. oControl = oController.GetControl(oModel)
  71. oPeer = oControl.GetPeer()
  72. If oControl.Model.PropertySetInfo.HasPropertybyName(&quot;EffectiveMax&quot;) Then
  73. If oControl.Model.EffectiveMax = 0 Then
  74. &apos; This is relevant for decimal fields
  75. oControl.Model.EffectiveValue = 999.9999
  76. Else
  77. oControl.Model.EffectiveValue = oControl.Model.EffectiveMax
  78. End If
  79. GetPeerSize() = oPeer.PreferredSize()
  80. oControl.Model.EffectiveValue = NullValue
  81. ElseIf Not IsMissing(LocText) Then
  82. oControl.Text = LocText
  83. GetPeerSize() = oPeer.PreferredSize()
  84. ElseIf CurFieldType = com.sun.star.sdbc.DataType.BIT Then
  85. GetPeerSize() = oPeer.PreferredSize()
  86. ElseIf CurFieldType = com.sun.star.sdbc.DataType.BOOLEAN Then
  87. GetPeerSize() = oPeer.PreferredSize()
  88. ElseIf CurFieldType = com.sun.star.sdbc.DataType.DATE Then
  89. oControl.Model.Date = Date
  90. GetPeerSize() = oPeer.PreferredSize()
  91. oControl.Model.Date = NullValue
  92. ElseIf CurFieldType = com.sun.star.sdbc.DataType.TIME Then
  93. oControl.Time = Time
  94. GetPeerSize() = oPeer.PreferredSize()
  95. oControl.Time = NullValue
  96. Else
  97. If oControl.MaxTextLen &gt; SBMAXTEXTSIZE Then
  98. oControl.Text = Mid(SBSIZETEXT,1, SBMAXTEXTSIZE)
  99. Else
  100. oControl.Text = Mid(SBSIZETEXT,1, oControl.MaxTextLen)
  101. End If
  102. GetPeerSize() = oPeer.PreferredSize()
  103. oControl.Text = &quot;&quot;
  104. End If
  105. End Function
  106. Function TwipToCM(ByVal nValue as long) as String
  107. TwipToCM = trim(str(nValue / 567)) + &quot;cm&quot;
  108. End function
  109. Function TwipTo100telMM(ByVal nValue as long) as long
  110. TwipTo100telMM = nValue / 0.567
  111. End function
  112. Function TwipToPixel(ByVal nValue as long) as long &apos; not an exact calculation
  113. TwipToPixel = nValue / 15
  114. End function
  115. Function PixelTo100thMMX(oControl as Object) as long
  116. oPeer = oControl.GetPeer()
  117. PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterX/100000)
  118. &apos; PixelTo100thMM = nValue * 28 &apos; not an exact calculation
  119. End function
  120. Function PixelTo100thMMY(oControl as Object) as long
  121. oPeer = oControl.GetPeer()
  122. PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterY/100000)
  123. &apos; PixelTo100thMM = nValue * 28 &apos; not an exact calculation
  124. End function
  125. Function GetPoint(xPos, YPos) as New com.sun.star.awt.Point
  126. Dim aPoint as New com.sun.star.awt.Point
  127. aPoint.X = xPos
  128. aPoint.Y = yPos
  129. GetPoint() = aPoint
  130. End Function
  131. Function GetSize(iWidth, iHeight) As New com.sun.star.awt.Size
  132. Dim aSize As New com.sun.star.awt.Size
  133. aSize.Width = iWidth
  134. aSize.Height = iHeight
  135. GetSize() = aSize
  136. End Function
  137. Sub ImportStyles()
  138. Dim OldIndex as Integer
  139. If Not bDebug Then
  140. On Local Error GoTo WIZARDERROR
  141. End If
  142. OldIndex = CurIndex
  143. CurIndex = GetCurIndex(DialogModel.lstStyles, Styles(),8)
  144. If CurIndex &lt;&gt; OldIndex Then
  145. ToggleLayoutPage(False)
  146. Dim sImportPath as String
  147. sImportPath = Styles(CurIndex, 8)
  148. bWithBackGraphic = LoadNewStyles(oDocument, DialogModel, CurIndex, sImportPath, Styles(), TexturePath)
  149. ControlCaptionsToStandardLayout()
  150. ToggleLayoutPage(True, &quot;lstStyles&quot;)
  151. End If
  152. WIZARDERROR:
  153. If Err &lt;&gt; 0 Then
  154. Msgbox(sMsgErrMsg, 16, GetProductName())
  155. Resume LOCERROR
  156. LOCERROR:
  157. End If
  158. End Sub
  159. Function SetNumerics(ByVal oLocObject as Object, iLocFieldType as Integer) as Object
  160. If CurControlType = cNumericBox Then
  161. oLocObject.TreatAsNumber = True
  162. Select Case iLocFieldType
  163. Case com.sun.star.sdbc.DataType.BIGINT
  164. oLocObject.EffectiveMax = 2147483647 * 2147483647
  165. oLocObject.EffectiveMin = -(-2147483648 * -2147483648)
  166. &apos; oLocObject.DecimalAccuracy = 0
  167. Case com.sun.star.sdbc.DataType.INTEGER
  168. oLocObject.EffectiveMax = 2147483647
  169. oLocObject.EffectiveMin = -2147483648
  170. Case com.sun.star.sdbc.DataType.SMALLINT
  171. oLocObject.EffectiveMax = 32767
  172. oLocObject.EffectiveMin = -32768
  173. Case com.sun.star.sdbc.DataType.TINYINT
  174. oLocObject.EffectiveMax = 127
  175. oLocObject.EffectiveMin = -128
  176. 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
  177. &apos;Todo: oLocObject.DecimalAccuracy = ...
  178. oLocObject.EffectiveDefault = CurDefaultValue
  179. &apos; Todo: HelpText???
  180. End Select
  181. If oLocObject.PropertySetinfo.HasPropertyByName(&quot;Width&quot;)Then &apos; Note: an Access AutoincrementField does not provide this property Width
  182. oLocObject.Width = CurFieldLength + CurScale + 1
  183. End If
  184. If CurIsCurrency Then
  185. &apos;Todo: How do you set currencies?
  186. End If
  187. ElseIf CurControlType = cTextBox Then &apos;com.sun.star.sdbc.DataType.CHAR, com.sun.star.sdbc.DataType.VARCHAR, com.sun.star.sdbc.DataType.LONGVARCHAR
  188. If CurFieldLength = 0 Then &apos;Or oLocObject.MaxTextLen &gt; SBMAXTEXTSIZE
  189. oLocObject.MaxTextLen = SBMAXTEXTSIZE
  190. CurFieldLength = SBMAXTEXTSIZE
  191. Else
  192. oLocObject.MaxTextLen = CurFieldLength
  193. End If
  194. oLocObject.DefaultText = CurDefaultValue
  195. ElseIf CurControlType = cDateBox Then
  196. &apos; Todo Why does this not work?: oLocObject.DefaultDate = CurDefaultValue
  197. ElseIf CurControlType = cTimeBox Then &apos; com.sun.star.sdbc.DataType.DATE, com.sun.star.sdbc.DataType.TIME
  198. oLocObject.DefaultTime = CurDefaultValue
  199. &apos; Todo: Property TimeFormat? from where?
  200. ElseIf CurControlType = cCheckBox Then
  201. &apos; Todo Why does this not work?: oLocObject.DefaultState = CurDefaultValue
  202. End If
  203. If oLocObject.PropertySetInfo.HasPropertybyName(&quot;FormatKey&quot;) Then
  204. On Local Error Resume Next
  205. oLocObject.FormatKey = CurFormatKey
  206. End If
  207. End Function
  208. &apos; Destroy all Shapes in Nirwana
  209. Sub RemoveShapes()
  210. Dim n as Integer
  211. Dim oControl as Object
  212. Dim oShape as Object
  213. For n = oDrawPage.Count-1 To 0 Step -1
  214. oShape = oDrawPage(n)
  215. If oShape.Position.Y &gt; -2000 Then
  216. oDrawPage.Remove(oShape)
  217. End If
  218. Next n
  219. End Sub
  220. &apos; Destroy all Shapes in Nirwana
  221. Sub RemoveNirwanaShapes()
  222. Dim n as Integer
  223. Dim oControl as Object
  224. Dim oShape as Object
  225. For n = oDrawPage.Count-1 To 0 Step -1
  226. oShape = oDrawPage(n)
  227. If oShape.Position.Y &lt; -2000 Then
  228. oDrawPage.Remove(oShape)
  229. End If
  230. Next n
  231. End Sub
  232. &apos; Note: as Shapes cannot be removed from the DrawPage without destroying
  233. &apos; the object we have to park them somewhere beyond the visible area of the page
  234. Sub ShapesToNirwana()
  235. Dim n as Integer
  236. Dim oControl as Object
  237. For n = 0 To oDrawPage.Count-1
  238. oDrawPage(n).Position = GetPoint(-20, -10000)
  239. Next n
  240. End Sub
  241. Function CalcUniqueContentName(ByVal oContainer as Object, sBaseName as String) as String
  242. Dim nPostfix as Integer
  243. Dim sReturn as String
  244. nPostfix = 2
  245. sReturn = sBaseName
  246. while (oContainer.hasByName(sReturn))
  247. sReturn = sBaseName &amp; nPostfix
  248. nPostfix = nPostfix + 1
  249. Wend
  250. CalcUniqueContentName = sReturn
  251. End Function
  252. Function CountItemsInArray(BigArray(), SearchItem)
  253. Dim i as Integer
  254. Dim MaxIndex as Integer
  255. Dim ResCount as Integer
  256. ResCount = 0
  257. MaxIndex = Ubound(BigArray())
  258. For i = 0 To MaxIndex
  259. If SearchItem = BigArray(i) Then
  260. ResCount = ResCount + 1
  261. End If
  262. Next i
  263. CountItemsInArray() = ResCount
  264. End Function
  265. Function GetDBHeight(oDBModel as Object)
  266. If CurControlType = cImageControl Then
  267. nDBHeight = 2000
  268. Else
  269. If CurFieldType = com.sun.star.sdbc.DataType.LONGVARCHAR Then
  270. oDBModel.MultiLine = True
  271. nDBHeight = nDBRefHeight * 4
  272. Else
  273. nDBHeight = nDBRefHeight
  274. End If
  275. End If
  276. GetDBHeight() = nDBHeight
  277. End Function
  278. Function GetFormWizardPaths() as Boolean
  279. FormPath = GetOfficeSubPath(&quot;Template&quot;,&quot;../wizard/bitmap&quot;)
  280. If FormPath &lt;&gt; &quot;&quot; Then
  281. WizardPath = GetOfficeSubPath(&quot;Template&quot;,&quot;wizard/&quot;)
  282. If Wizardpath &lt;&gt; &quot;&quot; Then
  283. TexturePath = GetOfficeSubPath(&quot;Gallery&quot;, &quot;backgrounds/&quot;)
  284. If TexturePath &lt;&gt; &quot;&quot; Then
  285. WorkPath = GetPathSettings(&quot;Work&quot;)
  286. If WorkPath &lt;&gt; &quot;&quot; Then
  287. TempPath = GetPathSettings(&quot;Temp&quot;)
  288. If TempPath &lt;&gt; &quot;&quot; Then
  289. GetFormWizardPaths = True
  290. Exit Function
  291. End If
  292. End If
  293. End If
  294. End If
  295. End If
  296. DisposeDocument(oDocument)
  297. GetFormWizardPaths() = False
  298. End Function
  299. Function GetFilterName(sApplicationKey as String) as String
  300. Dim oArgs()
  301. Dim oFactory
  302. Dim i as Integer
  303. Dim Maxindex as Integer
  304. Dim UIName as String
  305. oFactory = createUnoService(&quot;com.sun.star.document.FilterFactory&quot;)
  306. oArgs() = oFactory.getByName(sApplicationKey)
  307. MaxIndex = Ubound(oArgs())
  308. For i = 0 to MaxIndex
  309. If (oArgs(i).Name=&quot;UIName&quot;) Then
  310. UIName = oArgs(i).Value
  311. Exit For
  312. End If
  313. next i
  314. GetFilterName() = UIName
  315. End Function
  316. </script:module>