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=
"develop" script:
language=
"StarBasic">REM ***** BASIC *****
6 Public oDBShapeList() as Object
7 Public oTCShapeList() as Object
8 Public oDBModelList() as Object
9 Public oGroupShapeList() as Object
11 Public oGridShape as Object
13 Public StartA as Integer
14 Public bIsFirstRun as Boolean
15 Public bIsVeryFirstRun as Boolean
16 Public bControlsareCreated as Boolean
17 Public nDBRefHeight as Long
18 Public nXTCPos
&, nYTCPos
&, nXDBPos
&, nYDBPos
&, nTCHeight
&, nTCWidth
&, nDBHeight
&, nDBWidth
&
20 Dim iReduceWidth as Integer
22 Function PositionControls(Maxindex as Integer)
23 Dim oTCModel as Object
24 Dim oDBModel as Object
28 bIsVeryFirstRun = True
33 If CurArrangement = cLeftJustified Or cTopJustified Then
34 DialogModel.optAlign0.State =
1
37 GetCurrentMetaValues(i)
38 oTCModel = InsertTextControl(i)
39 If CurFieldType = com.sun.star.sdbc.DataType.TIMESTAMP Then
40 InsertTimeStampShape(i)
43 bIsVeryFirstRun = False
44 oDBModelList(i).LabelControl = oTCModel
46 GetLabelDiffHeight(i+
1)
48 oProgressbar.Value = i
50 ControlCaptionstoStandardLayout()
51 bControlsareCreated = True
55 Sub ResetPosSizes(LastIndex as Integer)
56 Select Case CurArrangement
58 nYDBPos = nYDBPos + nDBHeight + cVertDistance
59 If (nYDBPos
> cYOffset + nFormHeight) Or (LastIndex = MaxIndex) Then
60 RepositionColumnarLeftControls(LastIndex)
61 nXTCPos = nMaxColRightX +
2 * cHoriDistance
62 nXDBPos = nXTCPos + cHoriDistance + nMaxTCWidth
65 StartA = LastIndex +
1
70 nYTCPos = nYDBPos + LABELDIFFHEIGHT
72 nYTCPos = nYDBPos + nDBHeight + cVertDistance
73 If nYTCPos
> cYOffset + nFormHeight Then
74 nXDBPos = nMaxColRightX + cHoriDistance
76 nYDBPos = cYOffset + nTCHeight + cVertDistance
79 StartA = LastIndex +
1
84 Case cLeftJustified,cTopJustified
85 If nMaxColRightX
> cXOffset + nFormWidth Then
86 Dim nOldYTCPos as Long
88 CheckJustifiedPosition()
90 nXTCPos = nMaxColRightX + CHoriDistance
91 If CurArrangement = cLeftJustified Then
92 nYTCPos = nYDBPos + LabelDiffHeight
100 Sub RepositionColumnarLeftControls(LastIndex as Integer)
101 Dim aSize As New com.sun.star.awt.Size
102 Dim aPoint As New com.sun.star.awt.Point
104 aSize = GetSize(nMaxTCWidth, nTCHeight)
106 For i = StartA To LastIndex
108 nXTCPos = oTCShapeList(i).Position.X
109 nXDBPos = nXTCPos + nMaxTCWidth + cHoriDistance
111 ResetDBShape(oDBShapeList(i), nXDBPos)
112 CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
117 Sub ResetDBShape(oLocDBShape as Object, iXPos as Long)
118 Dim aSize As New com.sun.star.awt.Size
119 Dim aPoint As New com.sun.star.awt.Point
120 nYDBPos = oLocDBShape.Position.Y
121 nDBWidth = oLocDBShape.Size.Width
122 nDBHeight = oLocDBShape.Size.Height
123 aPoint = GetPoint(iXPos,nYDBPos)
124 oLocDBShape.SetPosition(aPoint)
128 Sub InitializePosSizes()
132 nDBHeight = nDBRefHeight
134 Select Case CurArrangement
135 Case cColumnarLeft, cLeftJustified
136 GetLabelDiffHeight(
0)
137 nYTCPos = cYOffset + LABELDIFFHEIGHT
138 nXDBPos = cXOffset +
3050
140 Case cColumnarTop, cTopJustified
147 Function InsertTextControl(i as Integer) as Object
150 Dim aPoint as New com.sun.star.awt.Point
151 Dim aSize As New com.sun.star.awt.Size
152 If bControlsareCreated Then
153 Set oShape = oTCShapeList(i)
154 Set oModel = oShape.GetControl
155 If CurArrangement = cLeftJustified Then
156 nTCWidth = GetPreferredWidth(oModel, True, CurFieldname)
158 nTCWidth = oShape.Size.Width
160 oShape.Position = GetPoint(nXTCPos, nYTCPos)
161 If CurArrangement = cColumnarTop Then
162 oModel.Align = com.sun.star.awt.TextAlign.LEFT
165 oModel = CreateUnoService(oModelService(cLabel))
166 aPoint = GetPoint(nXTCPos, nYTCPos)
167 aSize = GetSize(nTCWidth,nTCHeight)
168 Set oShape = InsertControl(oDrawPage, oModel, aPoint, aSize)
169 Set oTCShapeList(i)= oShape
170 If bIsVeryFirstRun Then
171 If CurArrangement = cColumnarTop Then
172 nYDBPos = nYTCPos + nTCHeight
175 nTCWidth = GetPreferredWidth(oModel, True, CurFieldName)
177 If CurArrangement = cColumnarLeft Then
178 ' Note This If Sequence must be called before retrieving the outer Points
180 nMaxTCWidth = nTCWidth
182 ElseIf nTCWidth
> nMaxTCWidth Then
183 nMaxTCWidth = nTCWidth
186 CheckOuterPoints(oShape.Position.X, nTCWidth, nYTCPos, nTCHeight, False)
187 Select Case CurArrangement
189 nXDBPos = nMaxColRightX
190 Case cColumnarTop,cTopJustified
191 oModel.Align = com.sun.star.awt.TextAlign.LEFT
193 nYDBPos = nYTCPos + nTCHeight
194 If CurFieldLength =
20 And nDBWidth
> 2 * nTCWidth Then
195 iReduceWidth = iReduceWidth +
1
198 oShape.SetSize(GetSize(nTCWidth,nTCHeight))
199 If CurHelpText
<> "" Then
200 oModel.HelpText = CurHelptext
202 InsertTextControl = oModel
206 Sub InsertDBControl(i as Integer)
207 Dim aPoint as New com.sun.star.awt.Point
208 Dim aSize As New com.sun.star.awt.Size
209 Dim oControl as Object
210 Dim iColRightX as Long
212 aPoint = GetPoint(nXDBPos, nYDBPos)
213 If bControlsAreCreated Then
214 oDBShapeList(i).Position = aPoint
216 oDBModelList(i) = CreateUnoService(oModelService(CurControlType))
217 oDBShapeList(i) = InsertControl(oDrawPage, oDBModelList(i), aPoint, aSize)
218 SetNumerics(oDBModelList(i), CurFieldType)
219 If CurControlType = cCheckBox Then
220 oDBModelList(i).Label =
""
222 oDBModelList(i).DataField = CurFieldName
224 nDBHeight = GetDBHeight(oDBModelList(i))
225 nDBWidth = GetPreferredWidth(oDBModelList(i),True)
226 aSize = GetSize(nDBWidth,nDBHeight)
227 oDBShapeList(i).SetSize(aSize)
228 CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
232 Function InsertTimeStampShape(i as Integer) as Object
233 Dim oDateModel as Object
234 Dim oTimeModel as Object
235 Dim oDateShape as Object
236 Dim oTimeShape as Object
237 Dim oDateTimeShape as Object
238 Dim aPoint as New com.sun.star.awt.Point
239 Dim aSize as New com.sun.star.awt.Size
240 Dim nDateWidth as Long
241 Dim nTimeWidth as Long
242 Dim oGroupShape as Object
243 aPoint = GetPoint(nXDBPos, nYDBPos)
244 If bControlsAreCreated Then
245 oDBShapeList(i).Position = aPoint
246 nDBWidth = oDBShapeList(i).Size.Width
247 nDBHeight = oDBShapeList(i).Size.Height
249 oGroupShape = oDocument.CreateInstance(
"com.sun.star.drawing.GroupShape
")
250 oGroupShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
251 oDrawPage.Add(oGroupShape)
252 CurFieldType = com.sun.star.sdbc.DataType.DATE
253 oDateModel = CreateUnoService(
"com.sun.star.form.component.DateField
")
254 oDateModel.DataField = CurFieldName
255 oDateShape = InsertControl(oGroupShape, oDateModel, aPoint, aSize)
256 SetNumerics(oDateModel, CurFieldType)
257 nDBHeight = GetDBHeight(oDateModel)
258 nDateWidth = GetPreferredWidth(oDateModel,True)
259 aSize = GetSize(nDateWidth,nDBHeight)
260 oDateShape.SetSize(aSize)
262 CurFieldType = com.sun.star.sdbc.DataType.TIME
263 oTimeModel = CreateUnoService(
"com.sun.star.form.component.TimeField
")
264 oTimeModel.DataField = CurFieldName
265 oTimeShape = InsertControl(oGroupShape, oTimeModel, aPoint, aSize)
266 oTimeShape.Position = GetPoint(nXDBPos +
10 + nDateWidth,nYDBPos)
267 nTimeWidth = GetPreferredWidth(oTimeModel)
268 aSize = GetSize(nTimeWidth,nDBHeight)
269 oTimeShape.SetSize(aSize)
270 nDBWidth = nDateWidth + nTimeWidth +
10
271 oGroupShape.Position = aPoint
272 oGroupShape.Size = GetSize(nDBWidth, nDBHeight)
273 Set oDBShapeList(i)= oGroupShape
275 CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
276 InsertTimeStampShape() = oDBShapeList(i)
280 ' Note: on all Controls except for the checkbox the Label has to be set
281 ' a bit under the DBControl because its Height is also smaller
282 Sub GetLabelDiffHeight(Index as Integer)
283 If (CurArrangement = cLeftJustified) Or (CurArrangement = cColumnarLeft) Then
284 If Index
<= Ubound(FieldMetaValues()) Then
285 If FieldMetaValues(Index,
2) = cCheckBox Then
288 LabelDiffHeight = BasicLabelDiffHeight
295 Sub CheckJustifiedPosition()
296 Dim nLeftDist as Long
297 Dim nRightDist as Long
298 Dim oLocDBShape as Object
299 Dim oLocTextShape as Object
300 Dim nBaseWidth as Long
301 nBaseWidth = nFormWidth + cXOffset
302 nLeftDist = nMaxColRightX - nBaseWidth
303 nRightDist = nBaseWidth - nXTCPos + cHoriDistance
304 If nLeftDist
< 0.5 * nRightDist and iReduceWidth
> 2 Then
305 ' Fieldwidths in the line can be made smaller
306 AdjustLineWidth(StartA, a, nLeftDist, -
1)
307 If CurArrangement = cLeftjustified Then
308 nYDBPos = nMaxRowY + cVertDistance
309 nYTCPos = nYDBPos + LABELDIFFHEIGHT
312 nYTCPos = nMaxRowY + cVertDistance
313 nYDBPos = nYTCPos + nTCHeight
320 Set oLocDBShape = oDBShapeList(a)
321 Set oLocTextShape = oTCShapeList(a)
322 If CurArrangement = cLeftJustified Then
323 If nYDBPos + nDBHeight = nMaxRowY Then
324 ' The last Control was the highes in the row
325 nYDBPos = nSecMaxRowY + cVertDistance
327 nYDBPos = nMaxRowY + cVertDistance
329 nYTCPos = nYDBPos + LABELDIFFHEIGHT
330 nXDBPos = cXOffset + nTCWidth
331 oLocTextShape.Position = GetPoint(cXOffset, nYTCPos)
332 oLocDBShape.Position = GetPoint(nXDBPos, nYDBPos)
333 ' PosSizes for the next two Controls
334 nXTCPos = oLocDBShape.Position.X + oLocDBShape.Size.Width + cHoriDistance
336 CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
337 nXDBPos = nMaxColRightX + cHoriDistance
338 Else
' cTopJustified
339 If nYDBPos + nDBHeight = nMaxRowY Then
340 ' The last Control was the highest in the row
341 nYTCPos = nSecMaxRowY + cVertDistance
343 nYTCPos = nMaxRowY + cVertDistance
345 nYDBPos = nYTCPOS + nTCHeight
348 oLocTextShape.Position = GetPoint(cXOffset, nYTCPos)
349 oLocDBShape.Position = GetPoint(cXOffset, nYDBPos)
351 If nDBWidth
> nTCWidth Then
352 CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
354 CheckOuterPoints(nXDBPos, nTCWidth, nYDBPos, nDBHeight, True)
356 nXTCPos = nMaxColRightX + cHoriDistance
359 AdjustLineWidth(StartA, a-
1, nRightDist,
1)
367 Function GetCorrWidth(StartIndex as Integer, EndIndex as Integer, nDist as Long, Widthfactor as Integer) as Integer
368 Dim ShapeCount as Integer
369 If WidthFactor
> 0 Then
370 ShapeCount = EndIndex-StartIndex +
1
372 ShapeCount = iReduceWidth
374 GetCorrWidth() = (nDist)/ShapeCount
378 Sub AdjustLineWidth(StartIndex as Integer, EndIndex as Integer, nDist as Long, Widthfactor as Integer)
380 Dim oLocDBShape as Object
381 Dim oLocTCShape as Object
382 Dim CorrWidth as Integer
383 Dim bAdjustPos as Boolean
384 Dim iLocTCPosX as Long
385 Dim iLocDBPosX as Long
386 CorrWidth = GetCorrWidth(StartIndex, EndIndex, nDist, Widthfactor)
388 iLocTCPosX = cXOffset
389 For i = StartIndex To EndIndex
390 Set oLocDBShape = oDBShapeList(i)
391 Set oLocTCShape = oTCShapeList(i)
393 oLocTCShape.Position = GetPoint(iLocTCPosX, oLocTCShape.Position.Y)
394 If CurArrangement = cLeftJustified Then
395 iLocDBPosX = oLocTCShape.Position.X + oLocTCShape.Size.Width
396 oLocDBShape.Position = GetPoint(iLocDBPosX, oLocDBShape.Position.Y)
398 oLocDBShape.Position = GetPoint(iLocTCPosX, oLocTCShape.Position.Y + nTCHeight)
403 If CDbl(FieldMetaValues(i,
1))
> 20 or WidthFactor
> 0 Then
404 If (CurArrangement = cTopJustified) And (oLocTCShape.Size.Width
> oLocDBShape.Size.Width) Then
405 oLocDBShape.Size = GetSize(oLocTCShape.Size.Width + WidthFactor * CorrWidth, oLocDBShape.Size.Height)
407 oLocDBShape.Size = GetSize(oLocDBShape.Size.Width + WidthFactor * CorrWidth, oLocDBShape.Size.Height)
410 iLocTCPosX = oLocDBShape.Position.X + oLocDBShape.Size.Width + cHoriDistance
411 If CurArrangement = cTopJustified Then
412 If oLocTCShape.Size.Width
> oLocDBShape.Size.Width Then
413 iLocTCPosX = oLocDBShape.Position.X + oLocTCShape.Size.Width + cHoriDistance
420 Sub CheckOuterPoints(nXPos, nWidth, nYPos, nHeight, bIsDBField as Boolean)
421 Dim nColRightX as Long
423 Dim nOldMaxRowY as Long
424 If CurArrangement = cLeftJustified Or CurArrangement = cTopJustified Then
426 ' Only at DBControls you can measure the Value of nMaxRowY
428 nMaxRowY = nYPos + nHeight
429 nSecMaxRowY = nMaxRowY
431 nRowY = nYPos + nHeight
432 If nRowY
>= nMaxRowY Then
433 nOldMaxRowY = nMaxRowY
434 nSecMaxRowY = nOldMaxRowY
440 ' Find the outer right point
442 nMaxColRightX = nXPos + nWidth
445 nColRightX = nXPos + nWidth
446 If nColRightX
> nMaxColRightX Then
447 nMaxColRightX = nColRightX
453 Function PositionGridControl(MaxIndex as Integer)
454 Dim oControl as Object
456 Dim oColumn as Object
457 Dim aPoint as New com.sun.star.awt.Point
458 Dim aSize as New com.sun.star.awt.Size
459 If bControlsareCreated Then
462 oGridModel = CreateUnoService(oModelService(cGridControl))
463 oGridModel.Name =
"Grid1
"
464 aPoint = GetPoint(cXOffset, cYOffset)
465 aSize = GetSize(nFormWidth, nFormHeight)
466 oDBForm.InsertByName (oGridModel.Name, oGridModel)
467 oGridShape = InsertControl(oDrawPage, oGridModel, aPoint, aSize)
468 For n =
0 to MaxIndex
469 GetCurrentMetaValues(n)
470 If CurFieldType = com.sun.star.sdbc.DataType.TIMESTAMP Then
471 oColumn = SetupGridColumn(oGridModel,
"DateField
", False, com.sun.star.sdbc.DataType.DATE, CurFieldName
& " " & sDateAppendix)
472 oColumn = SetupGridColumn(oGridModel,
"TimeField
", False, com.sun.star.sdbc.DataType.TIME, CurFieldName
& " " & sTimeAppendix)
474 If CurControlType = cImageControl Then
475 oColumn = SetupGridColumn(oGridModel,
"TextField
", True, CurFieldType, CurFieldName)
477 oColumn = SetupGridColumn(oGridModel, CurControlName, False, CurFieldType, CurFieldName)
480 oProgressbar.Value = n
485 Function SetupGridColumn(oGridModel as Object, ControlName as String, bHidden as Boolean, iLocFieldType as Integer, ColName as String) as Object
486 Dim oColumn as Object
487 CurControlName = ControlName
488 oColumn = oGridModel.CreateColumn(CurControlName)
489 oColumn.Name = CalcUniqueContentName(oGridModel, CurControlName)
490 oColumn.Hidden = bHidden
491 SetNumerics(oColumn, iLocFieldType)
492 oColumn.DataField = CurFieldName
493 oColumn.Label = ColName
494 oColumn.Width =
0 ' Width of column is adjusted to Columname
495 oGridModel.insertByName(oColumn.Name, oColumn)
499 Sub ControlCaptionstoStandardLayout()
501 Dim iBorderType as Integer
502 Dim oCurModel as Object
504 Dim iStandardColor as Long
505 If CurArrangement
<> cTabled Then
506 oStyle = oDocument.StyleFamilies.GetByName(
"ParagraphStyles
").GetByName(
"Standard
")
507 iStandardColor = oStyle.CharColor
508 For i =
0 To MaxIndex
509 oCurModel = oTCShapeList(i).GetControl
511 If oCurModel.TextColor = iStandardColor Then
515 oCurModel.TextColor = iStandardColor
521 Sub GroupShapesTogether()
523 If CurArrangement
<> cTabled Then
524 For i =
0 To MaxIndex
525 oGroupShapeList(i) = CreateUnoService(
"com.sun.star.drawing.ShapeCollection
")
526 oGroupShapeList(i).Add(oTCShapeList(i))
527 oGroupShapeList(i).Add(oDBShapeList(i))
528 oDrawPage.Group(oGroupShapeList(i))
531 RemoveNirwanaShapes()
533 End Sub
</script:module>