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