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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
<?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="develop" script:language="StarBasic">REM ***** BASIC *****
Option Explicit
Public oDBShapeList() as Object
Public oTCShapeList() as Object
Public oDBModelList() as Object
Public oGroupShapeList() as Object
Public oGridShape as Object
Public a as Integer
Public StartA as Integer
Public bIsFirstRun as Boolean
Public bIsVeryFirstRun as Boolean
Public bControlsareCreated as Boolean
Public nDBRefHeight as Long
Public nXTCPos&, nYTCPos&, nXDBPos&, nYDBPos&, nTCHeight&, nTCWidth&, nDBHeight&, nDBWidth&
Dim iReduceWidth as Integer
Function PositionControls(Maxindex as Integer)
Dim oTCModel as Object
Dim oDBModel as Object
Dim i as Integer
InitializePosSizes()
bIsFirstRun = True
bIsVeryFirstRun = True
a = 0
StartA = 0
nMaxRowY = 0
nSecMaxRowY = 0
If CurArrangement = cLeftJustified Or cTopJustified Then
DialogModel.optAlign0.State = 1
End If
For i = 0 To MaxIndex
GetCurrentMetaValues(i)
oTCModel = InsertTextControl(i)
If CurFieldType = com.sun.star.sdbc.DataType.TIMESTAMP Then
InsertTimeStampShape(i)
Else
InsertDBControl(i)
bIsVeryFirstRun = False
oDBModelList(i).LabelControl = oTCModel
End If
GetLabelDiffHeight(i+1)
ResetPosSizes(i)
oProgressbar.Value = i
Next i
ControlCaptionstoStandardLayout()
bControlsareCreated = True
End Function
Sub ResetPosSizes(LastIndex as Integer)
Select Case CurArrangement
Case cColumnarLeft
nYDBPos = nYDBPos + nDBHeight + cVertDistance
If (nYDBPos > cYOffset + nFormHeight) Or (LastIndex = MaxIndex) Then
RepositionColumnarLeftControls(LastIndex)
nXTCPos = nMaxColRightX + 2 * cHoriDistance
nXDBPos = nXTCPos + cHoriDistance + nMaxTCWidth
nYDBPos = cYOffset
bIsFirstRun = True
StartA = LastIndex + 1
a = 0
Else
a = a + 1
End If
nYTCPos = nYDBPos + LABELDIFFHEIGHT
Case cColumnarTop
nYTCPos = nYDBPos + nDBHeight + cVertDistance
If nYTCPos > cYOffset + nFormHeight Then
nXDBPos = nMaxColRightX + cHoriDistance
nXTCPos = nXDBPos
nYDBPos = cYOffset + nTCHeight + cVertDistance
nYTCPos = cYOffset
bIsFirstRun = True
StartA = LastIndex + 1
a = 0
Else
a = a + 1
End If
Case cLeftJustified,cTopJustified
If nMaxColRightX > cXOffset + nFormWidth Then
Dim nOldYTCPos as Long
nOldYTCPos = nYTCPos
CheckJustifiedPosition()
Else
nXTCPos = nMaxColRightX + CHoriDistance
If CurArrangement = cLeftJustified Then
nYTCPos = nYDBPos + LabelDiffHeight
End If
End If
a = a + 1
End Select
End Sub
Sub RepositionColumnarLeftControls(LastIndex as Integer)
Dim aSize As New com.sun.star.awt.Size
Dim aPoint As New com.sun.star.awt.Point
Dim i as Integer
aSize = GetSize(nMaxTCWidth, nTCHeight)
bIsFirstRun = True
For i = StartA To LastIndex
If i = StartA Then
nXTCPos = oTCShapeList(i).Position.X
nXDBPos = nXTCPos + nMaxTCWidth + cHoriDistance
End If
ResetDBShape(oDBShapeList(i), nXDBPos)
CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
Next i
End Sub
Sub ResetDBShape(oLocDBShape as Object, iXPos as Long)
Dim aSize As New com.sun.star.awt.Size
Dim aPoint As New com.sun.star.awt.Point
nYDBPos = oLocDBShape.Position.Y
nDBWidth = oLocDBShape.Size.Width
nDBHeight = oLocDBShape.Size.Height
aPoint = GetPoint(iXPos,nYDBPos)
oLocDBShape.SetPosition(aPoint)
End Sub
Sub InitializePosSizes()
nXTCPos = cXOffset
nTCWidth = 2000
nDBWidth = 2000
nDBHeight = nDBRefHeight
iReduceWidth = 0
Select Case CurArrangement
Case cColumnarLeft, cLeftJustified
GetLabelDiffHeight(0)
nYTCPos = cYOffset + LABELDIFFHEIGHT
nXDBPos = cXOffset + 3050
nYDBPos = cYOffset
Case cColumnarTop, cTopJustified
nXDBPos = cXOffset
nYTCPos = cYOffset
End Select
End Sub
Function InsertTextControl(i as Integer) as Object
Dim oShape as Object
Dim oModel as Object
Dim aPoint as New com.sun.star.awt.Point
Dim aSize As New com.sun.star.awt.Size
If bControlsareCreated Then
Set oShape = oTCShapeList(i)
Set oModel = oShape.GetControl
If CurArrangement = cLeftJustified Then
nTCWidth = GetPreferredWidth(oModel, True, CurFieldname)
Else
nTCWidth = oShape.Size.Width
End If
oShape.Position = GetPoint(nXTCPos, nYTCPos)
If CurArrangement = cColumnarTop Then
oModel.Align = com.sun.star.awt.TextAlign.LEFT
End If
Else
oModel = CreateUnoService(oModelService(cLabel))
aPoint = GetPoint(nXTCPos, nYTCPos)
aSize = GetSize(nTCWidth,nTCHeight)
Set oShape = InsertControl(oDrawPage, oModel, aPoint, aSize)
Set oTCShapeList(i)= oShape
If bIsVeryFirstRun Then
If CurArrangement = cColumnarTop Then
nYDBPos = nYTCPos + nTCHeight
End If
End If
nTCWidth = GetPreferredWidth(oModel, True, CurFieldName)
End If
If CurArrangement = cColumnarLeft Then
' Note This If Sequence must be called before retrieving the outer Points
If bIsFirstRun Then
nMaxTCWidth = nTCWidth
bIsFirstRun = False
ElseIf nTCWidth > nMaxTCWidth Then
nMaxTCWidth = nTCWidth
End If
End If
CheckOuterPoints(oShape.Position.X, nTCWidth, nYTCPos, nTCHeight, False)
Select Case CurArrangement
Case cLeftJustified
nXDBPos = nMaxColRightX
Case cColumnarTop,cTopJustified
oModel.Align = com.sun.star.awt.TextAlign.LEFT
nXDBPos = nXTCPos
nYDBPos = nYTCPos + nTCHeight
If CurFieldLength = 20 And nDBWidth > 2 * nTCWidth Then
iReduceWidth = iReduceWidth + 1
End If
End Select
oShape.SetSize(GetSize(nTCWidth,nTCHeight))
If CurHelpText <> "" Then
oModel.HelpText = CurHelptext
End If
InsertTextControl = oModel
End Function
Sub InsertDBControl(i as Integer)
Dim aPoint as New com.sun.star.awt.Point
Dim aSize As New com.sun.star.awt.Size
Dim oControl as Object
Dim iColRightX as Long
aPoint = GetPoint(nXDBPos, nYDBPos)
If bControlsAreCreated Then
oDBShapeList(i).Position = aPoint
Else
oDBModelList(i) = CreateUnoService(oModelService(CurControlType))
oDBShapeList(i) = InsertControl(oDrawPage, oDBModelList(i), aPoint, aSize)
SetNumerics(oDBModelList(i), CurFieldType)
If CurControlType = cCheckBox Then
oDBModelList(i).Label = ""
End If
oDBModelList(i).DataField = CurFieldName
End If
nDBHeight = GetDBHeight(oDBModelList(i))
nDBWidth = GetPreferredWidth(oDBModelList(i),True)
aSize = GetSize(nDBWidth,nDBHeight)
oDBShapeList(i).SetSize(aSize)
CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
End Sub
Function InsertTimeStampShape(i as Integer) as Object
Dim oDateModel as Object
Dim oTimeModel as Object
Dim oDateShape as Object
Dim oTimeShape as Object
Dim oDateTimeShape as Object
Dim aPoint as New com.sun.star.awt.Point
Dim aSize as New com.sun.star.awt.Size
Dim nDateWidth as Long
Dim nTimeWidth as Long
Dim oGroupShape as Object
aPoint = GetPoint(nXDBPos, nYDBPos)
If bControlsAreCreated Then
oDBShapeList(i).Position = aPoint
nDBWidth = oDBShapeList(i).Size.Width
nDBHeight = oDBShapeList(i).Size.Height
Else
oGroupShape = oDocument.CreateInstance("com.sun.star.drawing.GroupShape")
oGroupShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
oDrawPage.Add(oGroupShape)
CurFieldType = com.sun.star.sdbc.DataType.DATE
oDateModel = CreateUnoService("com.sun.star.form.component.DateField")
oDateModel.DataField = CurFieldName
oDateShape = InsertControl(oGroupShape, oDateModel, aPoint, aSize)
SetNumerics(oDateModel, CurFieldType)
nDBHeight = GetDBHeight(oDateModel)
nDateWidth = GetPreferredWidth(oDateModel,True)
aSize = GetSize(nDateWidth,nDBHeight)
oDateShape.SetSize(aSize)
CurFieldType = com.sun.star.sdbc.DataType.TIME
oTimeModel = CreateUnoService("com.sun.star.form.component.TimeField")
oTimeModel.DataField = CurFieldName
oTimeShape = InsertControl(oGroupShape, oTimeModel, aPoint, aSize)
oTimeShape.Position = GetPoint(nXDBPos + 10 + nDateWidth,nYDBPos)
nTimeWidth = GetPreferredWidth(oTimeModel)
aSize = GetSize(nTimeWidth,nDBHeight)
oTimeShape.SetSize(aSize)
nDBWidth = nDateWidth + nTimeWidth + 10
oGroupShape.Position = aPoint
oGroupShape.Size = GetSize(nDBWidth, nDBHeight)
Set oDBShapeList(i)= oGroupShape
End If
CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
InsertTimeStampShape() = oDBShapeList(i)
End Function
' Note: on all Controls except for the checkbox the Label has to be set
' a bit under the DBControl because its Height is also smaller
Sub GetLabelDiffHeight(Index as Integer)
If (CurArrangement = cLeftJustified) Or (CurArrangement = cColumnarLeft) Then
If Index <= Ubound(FieldMetaValues()) Then
If FieldMetaValues(Index,2) = cCheckBox Then
LabelDiffHeight = 0
Else
LabelDiffHeight = BasicLabelDiffHeight
End If
End If
End If
End Sub
Sub CheckJustifiedPosition()
Dim nLeftDist as Long
Dim nRightDist as Long
Dim oLocDBShape as Object
Dim oLocTextShape as Object
Dim nBaseWidth as Long
nBaseWidth = nFormWidth + cXOffset
nLeftDist = nMaxColRightX - nBaseWidth
nRightDist = nBaseWidth - nXTCPos + cHoriDistance
If nLeftDist < 0.5 * nRightDist and iReduceWidth > 2 Then
' Fieldwidths in the line can be made smaller
AdjustLineWidth(StartA, a, nLeftDist, - 1)
If CurArrangement = cLeftjustified Then
nYDBPos = nMaxRowY + cVertDistance
nYTCPos = nYDBPos + LABELDIFFHEIGHT
nXTCPos = cXOffset
Else
nYTCPos = nMaxRowY + cVertDistance
nYDBPos = nYTCPos + nTCHeight
nXTCPos = cXOffset
nXDBPos = cXOffset
End If
bIsFirstRun = True
StartA = a + 1
Else
Set oLocDBShape = oDBShapeList(a)
Set oLocTextShape = oTCShapeList(a)
If CurArrangement = cLeftJustified Then
If nYDBPos + nDBHeight = nMaxRowY Then
' The last Control was the highest in the row
nYDBPos = nSecMaxRowY + cVertDistance
Else
nYDBPos = nMaxRowY + cVertDistance
End If
nYTCPos = nYDBPos + LABELDIFFHEIGHT
nXDBPos = cXOffset + nTCWidth
oLocTextShape.Position = GetPoint(cXOffset, nYTCPos)
oLocDBShape.Position = GetPoint(nXDBPos, nYDBPos)
' PosSizes for the next two Controls
nXTCPos = oLocDBShape.Position.X + oLocDBShape.Size.Width + cHoriDistance
bIsFirstRun = True
CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
nXDBPos = nMaxColRightX + cHoriDistance
Else ' cTopJustified
If nYDBPos + nDBHeight = nMaxRowY Then
' The last Control was the highest in the row
nYTCPos = nSecMaxRowY + cVertDistance
Else
nYTCPos = nMaxRowY + cVertDistance
End If
nYDBPos = nYTCPOS + nTCHeight
nXDBPos = cXOffset
nXTCPos = cXOffset
oLocTextShape.Position = GetPoint(cXOffset, nYTCPos)
oLocDBShape.Position = GetPoint(cXOffset, nYDBPos)
bIsFirstRun = True
If nDBWidth > nTCWidth Then
CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
Else
CheckOuterPoints(nXDBPos, nTCWidth, nYDBPos, nDBHeight, True)
End If
nXTCPos = nMaxColRightX + cHoriDistance
nXDBPos = nXTCPos
End If
AdjustLineWidth(StartA, a-1, nRightDist, 1)
StartA = a
End If
iReduceWidth = 0
End Sub
Function GetCorrWidth(StartIndex as Integer, EndIndex as Integer, nDist as Long, Widthfactor as Integer) as Integer
Dim ShapeCount as Integer
If WidthFactor > 0 Then
ShapeCount = EndIndex-StartIndex + 1
Else
ShapeCount = iReduceWidth
End If
GetCorrWidth() = (nDist)/ShapeCount
End Function
Sub AdjustLineWidth(StartIndex as Integer, EndIndex as Integer, nDist as Long, Widthfactor as Integer)
Dim i as Integer
Dim oLocDBShape as Object
Dim oLocTCShape as Object
Dim CorrWidth as Integer
Dim bAdjustPos as Boolean
Dim iLocTCPosX as Long
Dim iLocDBPosX as Long
CorrWidth = GetCorrWidth(StartIndex, EndIndex, nDist, Widthfactor)
bAdjustPos = False
iLocTCPosX = cXOffset
For i = StartIndex To EndIndex
Set oLocDBShape = oDBShapeList(i)
Set oLocTCShape = oTCShapeList(i)
If bAdjustPos Then
oLocTCShape.Position = GetPoint(iLocTCPosX, oLocTCShape.Position.Y)
If CurArrangement = cLeftJustified Then
iLocDBPosX = oLocTCShape.Position.X + oLocTCShape.Size.Width
oLocDBShape.Position = GetPoint(iLocDBPosX, oLocDBShape.Position.Y)
Else
oLocDBShape.Position = GetPoint(iLocTCPosX, oLocTCShape.Position.Y + nTCHeight)
End If
Else
bAdjustPos = True
End If
If CDbl(FieldMetaValues(i,1)) > 20 or WidthFactor > 0 Then
If (CurArrangement = cTopJustified) And (oLocTCShape.Size.Width > oLocDBShape.Size.Width) Then
oLocDBShape.Size = GetSize(oLocTCShape.Size.Width + WidthFactor * CorrWidth, oLocDBShape.Size.Height)
Else
oLocDBShape.Size = GetSize(oLocDBShape.Size.Width + WidthFactor * CorrWidth, oLocDBShape.Size.Height)
End If
End If
iLocTCPosX = oLocDBShape.Position.X + oLocDBShape.Size.Width + cHoriDistance
If CurArrangement = cTopJustified Then
If oLocTCShape.Size.Width > oLocDBShape.Size.Width Then
iLocTCPosX = oLocDBShape.Position.X + oLocTCShape.Size.Width + cHoriDistance
End If
End If
Next i
End Sub
Sub CheckOuterPoints(nXPos, nWidth, nYPos, nHeight, bIsDBField as Boolean)
Dim nColRightX as Long
Dim nRowY as Long
Dim nOldMaxRowY as Long
If CurArrangement = cLeftJustified Or CurArrangement = cTopJustified Then
If bIsDBField Then
' Only at DBControls you can measure the Value of nMaxRowY
If bIsFirstRun Then
nMaxRowY = nYPos + nHeight
nSecMaxRowY = nMaxRowY
Else
nRowY = nYPos + nHeight
If nRowY >= nMaxRowY Then
nOldMaxRowY = nMaxRowY
nSecMaxRowY = nOldMaxRowY
nMaxRowY = nRowY
End If
End If
End If
End If
' Find the outer right point
If bIsFirstRun Then
nMaxColRightX = nXPos + nWidth
bIsFirstRun = False
Else
nColRightX = nXPos + nWidth
If nColRightX > nMaxColRightX Then
nMaxColRightX = nColRightX
End If
End If
End Sub
Function PositionGridControl(MaxIndex as Integer)
Dim oControl as Object
Dim n as Integer
Dim oColumn as Object
Dim aPoint as New com.sun.star.awt.Point
Dim aSize as New com.sun.star.awt.Size
If bControlsareCreated Then
ShapesToNirwana()
End If
oGridModel = CreateUnoService(oModelService(cGridControl))
oGridModel.Name = "Grid1"
aPoint = GetPoint(cXOffset, cYOffset)
aSize = GetSize(nFormWidth, nFormHeight)
oDBForm.InsertByName (oGridModel.Name, oGridModel)
oGridShape = InsertControl(oDrawPage, oGridModel, aPoint, aSize)
For n = 0 to MaxIndex
GetCurrentMetaValues(n)
If CurFieldType = com.sun.star.sdbc.DataType.TIMESTAMP Then
oColumn = SetupGridColumn(oGridModel,"DateField", False, com.sun.star.sdbc.DataType.DATE, CurFieldName & " " & sDateAppendix)
oColumn = SetupGridColumn(oGridModel,"TimeField", False, com.sun.star.sdbc.DataType.TIME, CurFieldName & " " & sTimeAppendix)
Else
If CurControlType = cImageControl Then
oColumn = SetupGridColumn(oGridModel,"TextField", True, CurFieldType, CurFieldName)
Else
oColumn = SetupGridColumn(oGridModel, CurControlName, False, CurFieldType, CurFieldName)
End If
End If
oProgressbar.Value = n
next n
End Function
Function SetupGridColumn(oGridModel as Object, ControlName as String, bHidden as Boolean, iLocFieldType as Integer, ColName as String) as Object
Dim oColumn as Object
CurControlName = ControlName
oColumn = oGridModel.CreateColumn(CurControlName)
oColumn.Name = CalcUniqueContentName(oGridModel, CurControlName)
oColumn.Hidden = bHidden
SetNumerics(oColumn, iLocFieldType)
oColumn.DataField = CurFieldName
oColumn.Label = ColName
oColumn.Width = 0 ' Width of column is adjusted to Columname
oGridModel.insertByName(oColumn.Name, oColumn)
End Function
Sub ControlCaptionstoStandardLayout()
Dim i as Integer
Dim iBorderType as Integer
Dim oCurModel as Object
Dim oStyle as Object
Dim iStandardColor as Long
If CurArrangement <> cTabled Then
oStyle = oDocument.StyleFamilies.GetByName("ParagraphStyles").GetByName("Standard")
iStandardColor = oStyle.CharColor
For i = 0 To MaxIndex
oCurModel = oTCShapeList(i).GetControl
If i = 0 Then
If oCurModel.TextColor = iStandardColor Then
Exit Sub
End If
End If
oCurModel.TextColor = iStandardColor
Next i
End If
End Sub
Sub GroupShapesTogether()
Dim i as Integer
If CurArrangement <> cTabled Then
For i = 0 To MaxIndex
oGroupShapeList(i) = CreateUnoService("com.sun.star.drawing.ShapeCollection")
oGroupShapeList(i).Add(oTCShapeList(i))
oGroupShapeList(i).Add(oDBShapeList(i))
oDrawPage.Group(oGroupShapeList(i))
Next i
Else
RemoveNirwanaShapes()
End If
End Sub</script:module>
|