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