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