Layouter.xba 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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="Layouter" script:language="StarBasic">Option Explicit
  21. Public oProgressbar as Object
  22. Public ProgressValue as Integer
  23. Public oDocument as Object
  24. Public oController as Object
  25. Public oForm as Object
  26. Public oDrawPage as Object
  27. Public oPageStyle as Object
  28. Public nMaxColRightX as Long
  29. Public nMaxTCWidth as Long
  30. Public nMaxRowRightX as Long
  31. Public nMaxRowY as Long
  32. Public nSecMaxRowY as Long
  33. Public MaxIndex as Integer
  34. Public CurIndex as Integer
  35. Public Const cVertDistance = 200
  36. Public Const cHoriDistance = 300
  37. Public nPageWidth as Long
  38. Public nPageHeight as Long
  39. Public nFormWidth as Long
  40. Public nFormHeight as Long
  41. Public nMaxHoriPos as Long
  42. Public nMaxVertPos as Long
  43. Public CONST SBALIGNLEFT = 0
  44. Public CONST SBALIGNRIGHT = 2
  45. Public Const SBNOBORDER = 0
  46. Public Const SB3DBORDER = 1
  47. Public Const SBSIMPLEBORDER = 2
  48. Public CurArrangement as Integer
  49. Public CurBorderType as Integer
  50. Public CurAlignmode as Integer
  51. Public OldAlignMode as Integer
  52. Public OldBorderType as Integer
  53. Public OldArrangement as Integer
  54. Public Const cColumnarLeft = 1
  55. Public Const cColumnarTop = 2
  56. Public Const cTabled = 3
  57. Public Const cLeftJustified = 4
  58. Public Const cTopJustified = 5
  59. Public Const cXOffset = 1000
  60. Public Const cYOffset = 700
  61. &apos; This is the viewed space that we lose because of the symbol bars
  62. Public Const cSymbolMargin = 2000
  63. Public Const MaxFieldIndex = 200
  64. Public Const cControlCollectionCount = 9
  65. Public Const cLabel = 1
  66. Public Const cTextBox = 2
  67. Public Const cCheckBox = 3
  68. Public Const cDateBox = 4
  69. Public Const cTimeBox = 5
  70. Public Const cNumericBox = 6
  71. Public Const cCurrencyBox = 7
  72. Public Const cGridControl = 8
  73. Public Const cImageControl = 9
  74. Public Styles(100, 8) as String
  75. Public CurControlType as Integer
  76. Public CurFieldlength as Double
  77. Public CurFieldType as Integer
  78. Public CurFieldName as String
  79. Public CurControlName as String
  80. Public CurFormatKey as Long
  81. Public CurDefaultValue
  82. Public CurIsCurrency as Boolean
  83. Public CurScale as Integer
  84. Public CurHelpText as String
  85. Public FieldMetaValues(MaxFieldIndex, 8)
  86. &apos; Description of this List:
  87. &apos; CurFieldType = FieldMetaValues(Index,0)
  88. &apos; CurFieldLength = FieldMetaValues(Index,1)
  89. &apos; CurControlType = FieldMetaValues(Index,2) (ControlType, e.g., cLabel, cTextbox, etc.)
  90. &apos; CurControlName = FieldMetaValues(Index,3)
  91. &apos; CurFormatKey = FieldMetaValues(Index,4)
  92. &apos; CurDefaultValue = FieldMetaValues(Index,5)
  93. &apos; CurIsCurrency = FieldMetaValues(Index,6)
  94. &apos; CurScale = FieldMetaValues(Index,7)
  95. &apos; CurHelpText = FieldMetaValues(Index,8)
  96. Public FieldNames(MaxFieldIndex) as string
  97. Public oModelService(cControlCollectionCount) as String
  98. Public oGridModel as Object
  99. Function InsertControl(oContainer as Object, oControlObject as object, aPoint as Object, aSize as Object)
  100. Dim oShape as object
  101. oShape = oDocument.CreateInstance (&quot;com.sun.star.drawing.ControlShape&quot;)
  102. oShape.Size = aSize
  103. oShape.Position = aPoint
  104. oShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
  105. oShape.control = oControlObject
  106. oContainer.Add(oShape)
  107. InsertControl() = oShape
  108. End Function
  109. Function ArrangeControls()
  110. Dim oShape as Object
  111. Dim i as Integer
  112. oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
  113. oProgressbar.Start(&quot;&quot;, MaxIndex)
  114. If oDBForm.HasbyName(&quot;Grid1&quot;) Then
  115. RemoveShapes()
  116. End If
  117. ToggleLayoutPage(False)
  118. Select Case CurArrangement
  119. Case cTabled
  120. PositionGridControl(MaxIndex)
  121. Case Else
  122. PositionControls(MaxIndex)
  123. End Select
  124. ToggleLayoutPage(True)
  125. oProgressbar.End
  126. End Function
  127. Sub OpenFormDocument()
  128. Dim NoArgs() as new com.sun.star.beans.PropertyValue
  129. Dim oViewSettings as Object
  130. oDocument = CreateNewDocument(&quot;swriter&quot;)
  131. oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
  132. oProgressbar.Start(&quot;&quot;, 100)
  133. oDocument.ApplyFormDesignMode = False
  134. oController = oDocument.GetCurrentController
  135. oViewSettings = oDocument.CurrentController.ViewSettings
  136. oViewSettings.ShowTableBoundaries = False
  137. oViewSettings.ShowOnlineLayout = True
  138. oDrawPage = oDocument.DrawPage
  139. oPageStyle = oDocument.StyleFamilies.GetByName(&quot;PageStyles&quot;).GetByName(&quot;Standard&quot;)
  140. End Sub
  141. Sub InitializeLabelValues()
  142. Dim oLabelModel as Object
  143. Dim oTBModel as Object
  144. Dim oLabelShape as Object
  145. Dim oTBShape as Object
  146. Dim aTBSize As New com.sun.star.awt.Size
  147. Dim aLabelSize As New com.sun.star.awt.Size
  148. Dim aPoint As New com.sun.star.awt.Point
  149. Dim aSize As New com.sun.star.awt.Size
  150. Dim oLocControl as Object
  151. Dim oLocPeer as Object
  152. oLabelModel = CreateUnoService(&quot;com.sun.star.form.component.FixedText&quot;)
  153. oTBModel = CreateUnoService(&quot;com.sun.star.form.component.TextField&quot;)
  154. Set oLabelShape = InsertControl(oDrawPage, oLabelModel, aPoint, aLabelSize)
  155. Set oTBShape = InsertControl(oDrawPage, oTBModel, aPoint, aSize)
  156. oLocPeer = oController.GetControl(oLabelModel).Peer
  157. XPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterX
  158. YPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterY
  159. aLabelSize = GetPeerSize(oLabelModel, oLocControl, &quot;The quick brown fox...&quot;)
  160. nTCHeight = (aLabelSize.Height+1) * YPixelFactor
  161. aTBSize = GetPeerSize(oTBModel, oLocControl, &quot;The quick brown fox...&quot;)
  162. nDBRefHeight = (aTBSize.Height+1) * YPixelFactor
  163. BasicLabelDiffHeight = Clng((nDBRefHeight - nTCHeight)/2)
  164. oDrawPage.Remove(oLabelShape)
  165. oDrawPage.Remove(oTBShape)
  166. End Sub
  167. Sub ConfigurePageStyle()
  168. Dim aPageSize As New com.sun.star.awt.Size
  169. Dim aSize As New com.sun.star.awt.Size
  170. oPageStyle.IsLandscape = True
  171. aPageSize = oPageStyle.Size
  172. nPageWidth = aPageSize.Width
  173. nPageHeight = aPageSize.Height
  174. aSize.Width = nPageHeight
  175. aSize.Height = nPageWidth
  176. oPageStyle.Size = aSize
  177. nPageWidth = nPageHeight
  178. nPageHeight = oPageStyle.Size.Height
  179. nFormWidth = nPageWidth - oPageStyle.RightMargin - oPageStyle.LeftMargin - 2 * cXOffset
  180. nFormHeight = nPageHeight - oPageStyle.TopMargin - oPageStyle.BottomMargin - 2 * cYOffset - cSymbolMargin
  181. End Sub
  182. &apos; Modify the Borders of the Controls
  183. Sub ChangeBorderLayouts(oEvent as Object)
  184. Dim oModel as Object
  185. Dim i as Integer
  186. Dim oCurModel as Object
  187. Dim sLocText as String
  188. Dim oGroupShape as Object
  189. Dim s as Integer
  190. If Not bDebug Then
  191. On Local Error GoTo WIZARDERROR
  192. End If
  193. oModel = oEvent.Source.Model
  194. SwitchBorderMode(Val(Right(oModel.Name,1)))
  195. ToggleLayoutPage(False)
  196. If CurArrangement = cTabled Then
  197. oGridModel.Border = CurBorderType
  198. Else
  199. If OldBorderType &lt;&gt; CurBorderType Then
  200. For i = 0 To MaxIndex
  201. If oDBShapeList(i).SupportsService(&quot;com.sun.star.drawing.GroupShape&quot;) Then
  202. oGroupShape = oDBShapeList(i)
  203. For s = 0 To oGroupShape.Count-1
  204. oGroupShape(s).Control.Border = CurBorderType
  205. Next s
  206. Else
  207. If oDBModelList(i).PropertySetInfo.HasPropertyByName(&quot;Border&quot;) Then
  208. oDBModelList(i).Border = CurBorderType
  209. End If
  210. End If
  211. Next i
  212. End If
  213. End If
  214. ToggleLayoutPage(True)
  215. WIZARDERROR:
  216. If Err &lt;&gt; 0 Then
  217. Msgbox(sMsgErrMsg, 16, GetProductName())
  218. Resume LOCERROR
  219. LOCERROR:
  220. DlgFormDB.Dispose()
  221. End If
  222. End Sub
  223. Sub ChangeLabelAlignments(oEvent as Object)
  224. Dim i as Integer
  225. Dim oSize as New com.sun.star.awt.Size
  226. Dim oModel as Object
  227. If Not bDebug Then
  228. On Local Error GoTo WIZARDERROR
  229. End If
  230. oModel = oEvent.Source.Model
  231. SwitchAlignMode(Val(Right(oModel.Name,1)))
  232. ToggleLayoutPage(False)
  233. If OldAlignMode &lt;&gt; CurAlignMode Then
  234. For i = 0 To MaxIndex
  235. oTCShapeList(i).GetControl.Align = CurAlignmode
  236. Next i
  237. End If
  238. If CurAlignmode = com.sun.star.awt.TextAlign.RIGHT Then
  239. For i = 0 To Ubound(oTCShapeList())
  240. oSize = oTCShapeList(i).Size
  241. oSize.Width = oDBShapeList(i).Position.X - oTCShapeList(i).Position.X - cHoriDistance
  242. oTCShapeList(i).Size = oSize
  243. Next i
  244. End If
  245. WIZARDERROR:
  246. If Err &lt;&gt; 0 Then
  247. Msgbox(sMsgErrMsg, 16, GetProductName())
  248. Resume LOCERROR
  249. LOCERROR:
  250. End If
  251. ToggleLayoutPage(True)
  252. End Sub
  253. Sub ChangeArrangemode(oEvent as Object)
  254. Dim oModel as Object
  255. If Not bDebug Then
  256. On Local Error GoTo WIZARDERROR
  257. End If
  258. oModel = oEvent.Source.Model
  259. SwitchArrangementButtons(Val(Right(oModel.Name,1)))
  260. oModel.State = 1
  261. DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; OldArrangement).Model.State = 0
  262. If CurArrangement &lt;&gt; OldArrangement Then
  263. ArrangeControls()
  264. Select Case CurArrangement
  265. Case cTabled
  266. ToggleBorderGroup(False)
  267. ToggleAlignGroup(False)
  268. Case Else &apos; cColumnarTop,cLeftJustified, cTopJustified
  269. ToggleAlignGroup(CurArrangement = cColumnarLeft)
  270. If CurArrangement = cColumnarTop Then
  271. If CurAlignMode = com.sun.star.awt.TextAlign.RIGHT Then
  272. DialogModel.optAlign0.State = 1
  273. CurAlignMode = com.sun.star.awt.TextAlign.LEFT
  274. OldAlignMode = com.sun.star.awt.TextAlign.RIGHT
  275. End If
  276. End If
  277. ControlCaptionstoStandardLayout()
  278. oDBForm.Load
  279. End Select
  280. End If
  281. WIZARDERROR:
  282. If Err &lt;&gt; 0 Then
  283. Msgbox(sMsgErrMsg, 16, GetProductName())
  284. Resume LOCERROR
  285. LOCERROR:
  286. End If
  287. End Sub
  288. Sub ToggleBorderGroup(bDoEnable as Boolean)
  289. With DialogModel
  290. .hlnBorderLayout.Enabled = bDoEnable
  291. .optBorder0.Enabled = bDoEnable &apos; 0: No border
  292. .optBorder1.Enabled = bDoEnable &apos; 1: 3D border
  293. .optBorder2.Enabled = bDoEnable &apos; 2: simple border
  294. End With
  295. End Sub
  296. Sub ToggleAlignGroup(ByVal bDoEnable as Boolean)
  297. With DialogModel
  298. If bDoEnable Then
  299. bDoEnable = CurArrangement = cColumnarLeft
  300. End If
  301. .hlnAlign.Enabled = bDoEnable
  302. .optAlign0.Enabled = bDoEnable
  303. .optAlign2.Enabled = bDoEnable
  304. End With
  305. End Sub
  306. Sub ToggleLayoutPage(bDoEnable as Boolean, Optional FocusControlName as String)
  307. DialogModel.Enabled = bDoEnable
  308. If bDoEnable Then
  309. If Not bDebug Then
  310. oDocument.UnlockControllers()
  311. End If
  312. ToggleOptionButtons(DialogModel,(bWithBackGraphic = True))
  313. ToggleAlignGroup(bDoEnable)
  314. ToggleBorderGroup(bDoEnable)
  315. Else
  316. If Not bDebug Then
  317. oDocument.LockControllers()
  318. End If
  319. End If
  320. If Not IsMissing(FocusControlName) Then
  321. DlgFormDB.GetControl(FocusControlName).SetFocus()
  322. End If
  323. End Sub
  324. Sub DestroyControlShapes(oDrawPage as Object)
  325. Dim i as Integer
  326. Dim oShape as Object
  327. For i = oDrawPage.Count-1 To 0 Step -1
  328. oShape = oDrawPage.GetByIndex(i)
  329. If oShape.ShapeType = &quot;com.sun.star.drawing.ControlShape&quot; Then
  330. oShape.Dispose()
  331. End If
  332. Next i
  333. End Sub
  334. Sub SwitchArrangementButtons(ByVal LocArrangement as Integer)
  335. OldArrangement = CurArrangement
  336. CurArrangement = LocArrangement
  337. If OldArrangement &lt;&gt; 0 Then
  338. DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; OldArrangement).Model.State = 0
  339. End If
  340. DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; CurArrangement).Model.State = 1
  341. End Sub
  342. Sub SwitchBorderMode(ByVal LocBorderType as Integer)
  343. OldBorderType = CurBorderType
  344. CurBorderType = LocBorderType
  345. End Sub
  346. Sub SwitchAlignMode(ByVal LocAlignMode as Integer)
  347. OldAlignMode = CurAlignMode
  348. CurAlignMode = LocAlignMode
  349. End Sub</script:module>