1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?>
2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*b1cdbd2cSJim Jagielski<!--***********************************************************
4*b1cdbd2cSJim Jagielski *
5*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
6*b1cdbd2cSJim Jagielski * or more contributor license agreements.  See the NOTICE file
7*b1cdbd2cSJim Jagielski * distributed with this work for additional information
8*b1cdbd2cSJim Jagielski * regarding copyright ownership.  The ASF licenses this file
9*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
10*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
11*b1cdbd2cSJim Jagielski * with the License.  You may obtain a copy of the License at
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski *   http://www.apache.org/licenses/LICENSE-2.0
14*b1cdbd2cSJim Jagielski *
15*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
16*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
17*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*b1cdbd2cSJim Jagielski * KIND, either express or implied.  See the License for the
19*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
20*b1cdbd2cSJim Jagielski * under the License.
21*b1cdbd2cSJim Jagielski *
22*b1cdbd2cSJim Jagielski ***********************************************************-->
23*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="develop" script:language="StarBasic">REM  *****  BASIC  *****
24*b1cdbd2cSJim JagielskiOption Explicit
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim JagielskiPublic oDBShapeList() as Object
27*b1cdbd2cSJim JagielskiPublic oTCShapeList() as Object
28*b1cdbd2cSJim JagielskiPublic oDBModelList() as Object
29*b1cdbd2cSJim JagielskiPublic oGroupShapeList() as Object
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim JagielskiPublic oGridShape as Object
32*b1cdbd2cSJim JagielskiPublic a as Integer
33*b1cdbd2cSJim JagielskiPublic StartA as Integer
34*b1cdbd2cSJim JagielskiPublic bIsFirstRun as Boolean
35*b1cdbd2cSJim JagielskiPublic bIsVeryFirstRun as Boolean
36*b1cdbd2cSJim JagielskiPublic bControlsareCreated as Boolean
37*b1cdbd2cSJim JagielskiPublic nDBRefHeight as Long
38*b1cdbd2cSJim JagielskiPublic nXTCPos&amp;, nYTCPos&amp;, nXDBPos&amp;, nYDBPos&amp;, nTCHeight&amp;, nTCWidth&amp;, nDBHeight&amp;, nDBWidth&amp;
39*b1cdbd2cSJim Jagielski
40*b1cdbd2cSJim JagielskiDim iReduceWidth as Integer
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim JagielskiFunction PositionControls(Maxindex as Integer)
43*b1cdbd2cSJim JagielskiDim oTCModel as Object
44*b1cdbd2cSJim JagielskiDim oDBModel as Object
45*b1cdbd2cSJim JagielskiDim i as Integer
46*b1cdbd2cSJim Jagielski	InitializePosSizes()
47*b1cdbd2cSJim Jagielski	bIsFirstRun = True
48*b1cdbd2cSJim Jagielski	bIsVeryFirstRun = True
49*b1cdbd2cSJim Jagielski	a = 0
50*b1cdbd2cSJim Jagielski	StartA = 0
51*b1cdbd2cSJim Jagielski	nMaxRowY = 0
52*b1cdbd2cSJim Jagielski	nSecMaxRowY = 0
53*b1cdbd2cSJim Jagielski	If CurArrangement = cLeftJustified Or cTopJustified Then
54*b1cdbd2cSJim Jagielski		DialogModel.optAlign0.State = 1
55*b1cdbd2cSJim Jagielski	End If
56*b1cdbd2cSJim Jagielski	For i = 0 To MaxIndex
57*b1cdbd2cSJim Jagielski		GetCurrentMetaValues(i)
58*b1cdbd2cSJim Jagielski		oTCModel = InsertTextControl(i)
59*b1cdbd2cSJim Jagielski		If CurFieldType = com.sun.star.sdbc.DataType.TIMESTAMP Then
60*b1cdbd2cSJim Jagielski			InsertTimeStampShape(i)
61*b1cdbd2cSJim Jagielski		Else
62*b1cdbd2cSJim Jagielski			InsertDBControl(i)
63*b1cdbd2cSJim Jagielski			bIsVeryFirstRun = False
64*b1cdbd2cSJim Jagielski			oDBModelList(i).LabelControl = oTCModel
65*b1cdbd2cSJim Jagielski		End If
66*b1cdbd2cSJim Jagielski		GetLabelDiffHeight(i+1)
67*b1cdbd2cSJim Jagielski		ResetPosSizes(i)
68*b1cdbd2cSJim Jagielski		oProgressbar.Value = i
69*b1cdbd2cSJim Jagielski	Next i
70*b1cdbd2cSJim Jagielski	ControlCaptionstoStandardLayout()
71*b1cdbd2cSJim Jagielski	bControlsareCreated = True
72*b1cdbd2cSJim JagielskiEnd Function
73*b1cdbd2cSJim Jagielski
74*b1cdbd2cSJim Jagielski
75*b1cdbd2cSJim JagielskiSub ResetPosSizes(LastIndex as Integer)
76*b1cdbd2cSJim Jagielski	Select Case CurArrangement
77*b1cdbd2cSJim Jagielski		Case cColumnarLeft
78*b1cdbd2cSJim Jagielski			nYDBPos = nYDBPos  + nDBHeight + cVertDistance
79*b1cdbd2cSJim Jagielski			If (nYDBPos &gt; cYOffset + nFormHeight) Or (LastIndex = MaxIndex) Then
80*b1cdbd2cSJim Jagielski				RepositionColumnarLeftControls(LastIndex)
81*b1cdbd2cSJim Jagielski				nXTCPos = nMaxColRightX + 2 * cHoriDistance
82*b1cdbd2cSJim Jagielski				nXDBPos = nXTCPos + cHoriDistance + nMaxTCWidth
83*b1cdbd2cSJim Jagielski				nYDBPos = cYOffset
84*b1cdbd2cSJim Jagielski				bIsFirstRun = True
85*b1cdbd2cSJim Jagielski				StartA = LastIndex + 1
86*b1cdbd2cSJim Jagielski				a = 0
87*b1cdbd2cSJim Jagielski			Else
88*b1cdbd2cSJim Jagielski				a = a + 1
89*b1cdbd2cSJim Jagielski			End If
90*b1cdbd2cSJim Jagielski			nYTCPos = nYDBPos + LABELDIFFHEIGHT
91*b1cdbd2cSJim Jagielski		Case cColumnarTop
92*b1cdbd2cSJim Jagielski			nYTCPos = nYDBPos + nDBHeight + cVertDistance
93*b1cdbd2cSJim Jagielski			If nYTCPos &gt; cYOffset + nFormHeight Then
94*b1cdbd2cSJim Jagielski				nXDBPos = nMaxColRightX + cHoriDistance
95*b1cdbd2cSJim Jagielski				nXTCPos = nXDBPos
96*b1cdbd2cSJim Jagielski				nYDBPos = cYOffset + nTCHeight + cVertDistance
97*b1cdbd2cSJim Jagielski				nYTCPos = cYOffset
98*b1cdbd2cSJim Jagielski				bIsFirstRun = True
99*b1cdbd2cSJim Jagielski				StartA = LastIndex + 1
100*b1cdbd2cSJim Jagielski				a = 0
101*b1cdbd2cSJim Jagielski			Else
102*b1cdbd2cSJim Jagielski				a = a + 1
103*b1cdbd2cSJim Jagielski			End If
104*b1cdbd2cSJim Jagielski		Case cLeftJustified,cTopJustified
105*b1cdbd2cSJim Jagielski			If nMaxColRightX &gt; cXOffset + nFormWidth Then
106*b1cdbd2cSJim Jagielski				Dim nOldYTCPos as Long
107*b1cdbd2cSJim Jagielski				nOldYTCPos = nYTCPos
108*b1cdbd2cSJim Jagielski				CheckJustifiedPosition()
109*b1cdbd2cSJim Jagielski			Else
110*b1cdbd2cSJim Jagielski				nXTCPos = nMaxColRightX + CHoriDistance
111*b1cdbd2cSJim Jagielski				If CurArrangement = cLeftJustified Then
112*b1cdbd2cSJim Jagielski					nYTCPos = nYDBPos + LabelDiffHeight
113*b1cdbd2cSJim Jagielski				End If
114*b1cdbd2cSJim Jagielski			End If
115*b1cdbd2cSJim Jagielski			a = a + 1
116*b1cdbd2cSJim Jagielski	End Select
117*b1cdbd2cSJim JagielskiEnd Sub
118*b1cdbd2cSJim Jagielski
119*b1cdbd2cSJim Jagielski
120*b1cdbd2cSJim JagielskiSub	RepositionColumnarLeftControls(LastIndex as Integer)
121*b1cdbd2cSJim JagielskiDim aSize As New com.sun.star.awt.Size
122*b1cdbd2cSJim JagielskiDim aPoint As New com.sun.star.awt.Point
123*b1cdbd2cSJim JagielskiDim i as Integer
124*b1cdbd2cSJim Jagielski	aSize = GetSize(nMaxTCWidth, nTCHeight)
125*b1cdbd2cSJim Jagielski	bIsFirstRun = True
126*b1cdbd2cSJim Jagielski	For i = StartA To LastIndex
127*b1cdbd2cSJim Jagielski		If i = StartA Then
128*b1cdbd2cSJim Jagielski			nXTCPos = oTCShapeList(i).Position.X
129*b1cdbd2cSJim Jagielski			nXDBPos = nXTCPos + nMaxTCWidth  + cHoriDistance
130*b1cdbd2cSJim Jagielski		End If
131*b1cdbd2cSJim Jagielski		ResetDBShape(oDBShapeList(i), nXDBPos)
132*b1cdbd2cSJim Jagielski		CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
133*b1cdbd2cSJim Jagielski	Next i
134*b1cdbd2cSJim JagielskiEnd Sub
135*b1cdbd2cSJim Jagielski
136*b1cdbd2cSJim Jagielski
137*b1cdbd2cSJim JagielskiSub ResetDBShape(oLocDBShape as Object, iXPos as Long)
138*b1cdbd2cSJim JagielskiDim aSize As New com.sun.star.awt.Size
139*b1cdbd2cSJim JagielskiDim aPoint As New com.sun.star.awt.Point
140*b1cdbd2cSJim Jagielski	nYDBPos = oLocDBShape.Position.Y
141*b1cdbd2cSJim Jagielski	nDBWidth = oLocDBShape.Size.Width
142*b1cdbd2cSJim Jagielski	nDBHeight = oLocDBShape.Size.Height
143*b1cdbd2cSJim Jagielski	aPoint = GetPoint(iXPos,nYDBPos)
144*b1cdbd2cSJim Jagielski	oLocDBShape.SetPosition(aPoint)
145*b1cdbd2cSJim JagielskiEnd Sub
146*b1cdbd2cSJim Jagielski
147*b1cdbd2cSJim Jagielski
148*b1cdbd2cSJim JagielskiSub InitializePosSizes()
149*b1cdbd2cSJim Jagielski	nXTCPos = cXOffset
150*b1cdbd2cSJim Jagielski	nTCWidth = 2000
151*b1cdbd2cSJim Jagielski	nDBWidth = 2000
152*b1cdbd2cSJim Jagielski	nDBHeight = nDBRefHeight
153*b1cdbd2cSJim Jagielski	iReduceWidth = 0
154*b1cdbd2cSJim Jagielski	Select Case CurArrangement
155*b1cdbd2cSJim Jagielski		Case cColumnarLeft, cLeftJustified
156*b1cdbd2cSJim Jagielski			GetLabelDiffHeight(0)
157*b1cdbd2cSJim Jagielski			nYTCPos = cYOffset + LABELDIFFHEIGHT
158*b1cdbd2cSJim Jagielski			nXDBPos = cXOffset + 3050
159*b1cdbd2cSJim Jagielski			nYDBPos = cYOffset
160*b1cdbd2cSJim Jagielski		Case cColumnarTop, cTopJustified
161*b1cdbd2cSJim Jagielski			nXDBPos = cXOffset
162*b1cdbd2cSJim Jagielski			nYTCPos = cYOffset
163*b1cdbd2cSJim Jagielski	End Select
164*b1cdbd2cSJim JagielskiEnd Sub
165*b1cdbd2cSJim Jagielski
166*b1cdbd2cSJim Jagielski
167*b1cdbd2cSJim JagielskiFunction InsertTextControl(i as Integer) as Object
168*b1cdbd2cSJim JagielskiDim oShape as Object
169*b1cdbd2cSJim JagielskiDim oModel as Object
170*b1cdbd2cSJim JagielskiDim aPoint as New com.sun.star.awt.Point
171*b1cdbd2cSJim JagielskiDim aSize As New com.sun.star.awt.Size
172*b1cdbd2cSJim Jagielski	If bControlsareCreated Then
173*b1cdbd2cSJim Jagielski		Set oShape = oTCShapeList(i)
174*b1cdbd2cSJim Jagielski		Set oModel = oShape.GetControl
175*b1cdbd2cSJim Jagielski		If CurArrangement = cLeftJustified Then
176*b1cdbd2cSJim Jagielski			nTCWidth = GetPreferredWidth(oModel, True, CurFieldname)
177*b1cdbd2cSJim Jagielski		Else
178*b1cdbd2cSJim Jagielski			nTCWidth = oShape.Size.Width
179*b1cdbd2cSJim Jagielski		End If
180*b1cdbd2cSJim Jagielski		oShape.Position = GetPoint(nXTCPos, nYTCPos)
181*b1cdbd2cSJim Jagielski		If CurArrangement = cColumnarTop Then
182*b1cdbd2cSJim Jagielski			oModel.Align = com.sun.star.awt.TextAlign.LEFT
183*b1cdbd2cSJim Jagielski		End If
184*b1cdbd2cSJim Jagielski	Else
185*b1cdbd2cSJim Jagielski		oModel = CreateUnoService(oModelService(cLabel))
186*b1cdbd2cSJim Jagielski		aPoint = GetPoint(nXTCPos, nYTCPos)
187*b1cdbd2cSJim Jagielski		aSize = GetSize(nTCWidth,nTCHeight)
188*b1cdbd2cSJim Jagielski		Set oShape = InsertControl(oDrawPage, oModel, aPoint, aSize)
189*b1cdbd2cSJim Jagielski		Set oTCShapeList(i)= oShape
190*b1cdbd2cSJim Jagielski		If bIsVeryFirstRun Then
191*b1cdbd2cSJim Jagielski			If CurArrangement = cColumnarTop Then
192*b1cdbd2cSJim Jagielski				nYDBPos = nYTCPos + nTCHeight
193*b1cdbd2cSJim Jagielski			End If
194*b1cdbd2cSJim Jagielski		End If
195*b1cdbd2cSJim Jagielski		nTCWidth = GetPreferredWidth(oModel, True, CurFieldName)
196*b1cdbd2cSJim Jagielski	End If
197*b1cdbd2cSJim Jagielski	If CurArrangement = cColumnarLeft Then
198*b1cdbd2cSJim Jagielski		&apos; Note This If Sequence must be called before retrieving the outer Points
199*b1cdbd2cSJim Jagielski		If bIsFirstRun Then
200*b1cdbd2cSJim Jagielski			nMaxTCWidth = nTCWidth
201*b1cdbd2cSJim Jagielski			bIsFirstRun = False
202*b1cdbd2cSJim Jagielski		ElseIf nTCWidth &gt; nMaxTCWidth Then
203*b1cdbd2cSJim Jagielski			nMaxTCWidth = nTCWidth
204*b1cdbd2cSJim Jagielski		End If
205*b1cdbd2cSJim Jagielski	End If
206*b1cdbd2cSJim Jagielski	CheckOuterPoints(oShape.Position.X, nTCWidth, nYTCPos, nTCHeight, False)
207*b1cdbd2cSJim Jagielski	Select Case CurArrangement
208*b1cdbd2cSJim Jagielski		Case cLeftJustified
209*b1cdbd2cSJim Jagielski			nXDBPos = nMaxColRightX
210*b1cdbd2cSJim Jagielski		Case cColumnarTop,cTopJustified
211*b1cdbd2cSJim Jagielski			oModel.Align = com.sun.star.awt.TextAlign.LEFT
212*b1cdbd2cSJim Jagielski			nXDBPos = nXTCPos
213*b1cdbd2cSJim Jagielski			nYDBPos = nYTCPos + nTCHeight
214*b1cdbd2cSJim Jagielski			If CurFieldLength = 20 And nDBWidth &gt; 2 * nTCWidth Then
215*b1cdbd2cSJim Jagielski				iReduceWidth = iReduceWidth + 1
216*b1cdbd2cSJim Jagielski			End If
217*b1cdbd2cSJim Jagielski	End Select
218*b1cdbd2cSJim Jagielski	oShape.SetSize(GetSize(nTCWidth,nTCHeight))
219*b1cdbd2cSJim Jagielski	If CurHelpText &lt;&gt; &quot;&quot; Then
220*b1cdbd2cSJim Jagielski		oModel.HelpText = CurHelptext
221*b1cdbd2cSJim Jagielski	End If
222*b1cdbd2cSJim Jagielski	InsertTextControl = oModel
223*b1cdbd2cSJim JagielskiEnd Function
224*b1cdbd2cSJim Jagielski
225*b1cdbd2cSJim Jagielski
226*b1cdbd2cSJim JagielskiSub InsertDBControl(i as Integer)
227*b1cdbd2cSJim JagielskiDim aPoint as New com.sun.star.awt.Point
228*b1cdbd2cSJim JagielskiDim aSize As New com.sun.star.awt.Size
229*b1cdbd2cSJim JagielskiDim oControl as Object
230*b1cdbd2cSJim JagielskiDim iColRightX as Long
231*b1cdbd2cSJim Jagielski
232*b1cdbd2cSJim Jagielski	aPoint = GetPoint(nXDBPos, nYDBPos)
233*b1cdbd2cSJim Jagielski	If bControlsAreCreated Then
234*b1cdbd2cSJim Jagielski		oDBShapeList(i).Position = aPoint
235*b1cdbd2cSJim Jagielski	Else
236*b1cdbd2cSJim Jagielski		oDBModelList(i) = CreateUnoService(oModelService(CurControlType))
237*b1cdbd2cSJim Jagielski		oDBShapeList(i) = InsertControl(oDrawPage, oDBModelList(i), aPoint, aSize)
238*b1cdbd2cSJim Jagielski		SetNumerics(oDBModelList(i), CurFieldType)
239*b1cdbd2cSJim Jagielski		If CurControlType = cCheckBox Then
240*b1cdbd2cSJim Jagielski			oDBModelList(i).Label = &quot;&quot;
241*b1cdbd2cSJim Jagielski		End If
242*b1cdbd2cSJim Jagielski		oDBModelList(i).DataField = CurFieldName
243*b1cdbd2cSJim Jagielski	End If
244*b1cdbd2cSJim Jagielski	nDBHeight = GetDBHeight(oDBModelList(i))
245*b1cdbd2cSJim Jagielski	nDBWidth = GetPreferredWidth(oDBModelList(i),True)
246*b1cdbd2cSJim Jagielski	aSize = GetSize(nDBWidth,nDBHeight)
247*b1cdbd2cSJim Jagielski	oDBShapeList(i).SetSize(aSize)
248*b1cdbd2cSJim Jagielski	CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
249*b1cdbd2cSJim JagielskiEnd Sub
250*b1cdbd2cSJim Jagielski
251*b1cdbd2cSJim Jagielski
252*b1cdbd2cSJim JagielskiFunction InsertTimeStampShape(i as Integer) as Object
253*b1cdbd2cSJim JagielskiDim oDateModel as Object
254*b1cdbd2cSJim JagielskiDim oTimeModel as Object
255*b1cdbd2cSJim JagielskiDim oDateShape as Object
256*b1cdbd2cSJim JagielskiDim oTimeShape as Object
257*b1cdbd2cSJim JagielskiDim oDateTimeShape as Object
258*b1cdbd2cSJim JagielskiDim aPoint as New com.sun.star.awt.Point
259*b1cdbd2cSJim JagielskiDim aSize as New com.sun.star.awt.Size
260*b1cdbd2cSJim JagielskiDim nDateWidth as Long
261*b1cdbd2cSJim JagielskiDim nTimeWidth as Long
262*b1cdbd2cSJim JagielskiDim oGroupShape as Object
263*b1cdbd2cSJim Jagielski	aPoint = GetPoint(nXDBPos, nYDBPos)
264*b1cdbd2cSJim Jagielski	If bControlsAreCreated Then
265*b1cdbd2cSJim Jagielski		oDBShapeList(i).Position = aPoint
266*b1cdbd2cSJim Jagielski		nDBWidth = oDBShapeList(i).Size.Width
267*b1cdbd2cSJim Jagielski		nDBHeight = oDBShapeList(i).Size.Height
268*b1cdbd2cSJim Jagielski	Else
269*b1cdbd2cSJim Jagielski		oGroupShape = oDocument.CreateInstance(&quot;com.sun.star.drawing.GroupShape&quot;)
270*b1cdbd2cSJim Jagielski		oGroupShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
271*b1cdbd2cSJim Jagielski		oDrawPage.Add(oGroupShape)
272*b1cdbd2cSJim Jagielski		CurFieldType = com.sun.star.sdbc.DataType.DATE
273*b1cdbd2cSJim Jagielski		oDateModel = CreateUnoService(&quot;com.sun.star.form.component.DateField&quot;)
274*b1cdbd2cSJim Jagielski		oDateModel.DataField = CurFieldName
275*b1cdbd2cSJim Jagielski		oDateShape = InsertControl(oGroupShape, oDateModel, aPoint, aSize)
276*b1cdbd2cSJim Jagielski		SetNumerics(oDateModel, CurFieldType)
277*b1cdbd2cSJim Jagielski		nDBHeight = GetDBHeight(oDateModel)
278*b1cdbd2cSJim Jagielski		nDateWidth = GetPreferredWidth(oDateModel,True)
279*b1cdbd2cSJim Jagielski		aSize = GetSize(nDateWidth,nDBHeight)
280*b1cdbd2cSJim Jagielski		oDateShape.SetSize(aSize)
281*b1cdbd2cSJim Jagielski
282*b1cdbd2cSJim Jagielski		CurFieldType = com.sun.star.sdbc.DataType.TIME
283*b1cdbd2cSJim Jagielski		oTimeModel = CreateUnoService(&quot;com.sun.star.form.component.TimeField&quot;)
284*b1cdbd2cSJim Jagielski		oTimeModel.DataField = CurFieldName
285*b1cdbd2cSJim Jagielski		oTimeShape = InsertControl(oGroupShape, oTimeModel, aPoint, aSize)
286*b1cdbd2cSJim Jagielski		oTimeShape.Position = GetPoint(nXDBPos + 10 + nDateWidth,nYDBPos)
287*b1cdbd2cSJim Jagielski		nTimeWidth = GetPreferredWidth(oTimeModel)
288*b1cdbd2cSJim Jagielski		aSize = GetSize(nTimeWidth,nDBHeight)
289*b1cdbd2cSJim Jagielski		oTimeShape.SetSize(aSize)
290*b1cdbd2cSJim Jagielski		nDBWidth = nDateWidth + nTimeWidth + 10
291*b1cdbd2cSJim Jagielski		oGroupShape.Position = aPoint
292*b1cdbd2cSJim Jagielski		oGroupShape.Size = GetSize(nDBWidth, nDBHeight)
293*b1cdbd2cSJim Jagielski		Set oDBShapeList(i)= oGroupShape
294*b1cdbd2cSJim Jagielski	End If
295*b1cdbd2cSJim Jagielski	CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
296*b1cdbd2cSJim Jagielski	InsertTimeStampShape() = oDBShapeList(i)
297*b1cdbd2cSJim JagielskiEnd Function
298*b1cdbd2cSJim Jagielski
299*b1cdbd2cSJim Jagielski
300*b1cdbd2cSJim Jagielski&apos; Note: on all Controls except for the checkbox the Label has to be set
301*b1cdbd2cSJim Jagielski&apos; a bit under the DBControl because its Height is also smaller
302*b1cdbd2cSJim JagielskiSub GetLabelDiffHeight(Index as Integer)
303*b1cdbd2cSJim Jagielski	If (CurArrangement = cLeftJustified) Or (CurArrangement = cColumnarLeft) Then
304*b1cdbd2cSJim Jagielski		If Index &lt;= Ubound(FieldMetaValues()) Then
305*b1cdbd2cSJim Jagielski			If FieldMetaValues(Index,2) = cCheckBox Then
306*b1cdbd2cSJim Jagielski				LabelDiffHeight = 0
307*b1cdbd2cSJim Jagielski			Else
308*b1cdbd2cSJim Jagielski				LabelDiffHeight = BasicLabelDiffHeight
309*b1cdbd2cSJim Jagielski			End If
310*b1cdbd2cSJim Jagielski		End If
311*b1cdbd2cSJim Jagielski	End If
312*b1cdbd2cSJim JagielskiEnd Sub
313*b1cdbd2cSJim Jagielski
314*b1cdbd2cSJim Jagielski
315*b1cdbd2cSJim JagielskiSub CheckJustifiedPosition()
316*b1cdbd2cSJim JagielskiDim nLeftDist as Long
317*b1cdbd2cSJim JagielskiDim nRightDist as Long
318*b1cdbd2cSJim JagielskiDim oLocDBShape as Object
319*b1cdbd2cSJim JagielskiDim oLocTextShape as Object
320*b1cdbd2cSJim JagielskiDim nBaseWidth as Long
321*b1cdbd2cSJim Jagielski	nBaseWidth = nFormWidth + cXOffset
322*b1cdbd2cSJim Jagielski	nLeftDist = nMaxColRightX - nBaseWidth
323*b1cdbd2cSJim Jagielski	nRightDist = nBaseWidth - nXTCPos + cHoriDistance
324*b1cdbd2cSJim Jagielski	If nLeftDist &lt; 0.5 * nRightDist and iReduceWidth &gt; 2 Then
325*b1cdbd2cSJim Jagielski		&apos; Fieldwidths in the line can be made smaller
326*b1cdbd2cSJim Jagielski		AdjustLineWidth(StartA, a, nLeftDist, - 1)
327*b1cdbd2cSJim Jagielski		If CurArrangement = cLeftjustified Then
328*b1cdbd2cSJim Jagielski			nYDBPos = nMaxRowY + cVertDistance
329*b1cdbd2cSJim Jagielski			nYTCPos = nYDBPos + LABELDIFFHEIGHT
330*b1cdbd2cSJim Jagielski			nXTCPos = cXOffset
331*b1cdbd2cSJim Jagielski		Else
332*b1cdbd2cSJim Jagielski			nYTCPos = nMaxRowY + cVertDistance
333*b1cdbd2cSJim Jagielski			nYDBPos = nYTCPos + nTCHeight
334*b1cdbd2cSJim Jagielski			nXTCPos = cXOffset
335*b1cdbd2cSJim Jagielski			nXDBPos = cXOffset
336*b1cdbd2cSJim Jagielski		End If
337*b1cdbd2cSJim Jagielski		bIsFirstRun = True
338*b1cdbd2cSJim Jagielski		StartA = a + 1
339*b1cdbd2cSJim Jagielski	Else
340*b1cdbd2cSJim Jagielski		Set oLocDBShape = oDBShapeList(a)
341*b1cdbd2cSJim Jagielski		Set oLocTextShape = oTCShapeList(a)
342*b1cdbd2cSJim Jagielski		If CurArrangement = cLeftJustified Then
343*b1cdbd2cSJim Jagielski			If nYDBPos + nDBHeight = nMaxRowY Then
344*b1cdbd2cSJim Jagielski				&apos; The last Control was the highes in the row
345*b1cdbd2cSJim Jagielski				nYDBPos = nSecMaxRowY + cVertDistance
346*b1cdbd2cSJim Jagielski			Else
347*b1cdbd2cSJim Jagielski				nYDBPos = nMaxRowY + cVertDistance
348*b1cdbd2cSJim Jagielski			End If
349*b1cdbd2cSJim Jagielski			nYTCPos = nYDBPos + LABELDIFFHEIGHT
350*b1cdbd2cSJim Jagielski			nXDBPos = cXOffset + nTCWidth
351*b1cdbd2cSJim Jagielski			oLocTextShape.Position = GetPoint(cXOffset, nYTCPos)
352*b1cdbd2cSJim Jagielski			oLocDBShape.Position = GetPoint(nXDBPos, nYDBPos)
353*b1cdbd2cSJim Jagielski			&apos; PosSizes for the next two Controls
354*b1cdbd2cSJim Jagielski			nXTCPos = oLocDBShape.Position.X + oLocDBShape.Size.Width + cHoriDistance
355*b1cdbd2cSJim Jagielski			bIsFirstRun = True
356*b1cdbd2cSJim Jagielski			CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
357*b1cdbd2cSJim Jagielski			nXDBPos = nMaxColRightX + cHoriDistance
358*b1cdbd2cSJim Jagielski		Else		&apos; cTopJustified
359*b1cdbd2cSJim Jagielski			If nYDBPos + nDBHeight = nMaxRowY Then
360*b1cdbd2cSJim Jagielski				&apos; The last Control was the highest in the row
361*b1cdbd2cSJim Jagielski				nYTCPos = nSecMaxRowY + cVertDistance
362*b1cdbd2cSJim Jagielski			Else
363*b1cdbd2cSJim Jagielski				nYTCPos = nMaxRowY + cVertDistance
364*b1cdbd2cSJim Jagielski			End If
365*b1cdbd2cSJim Jagielski			nYDBPos = nYTCPOS + nTCHeight
366*b1cdbd2cSJim Jagielski			nXDBPos = cXOffset
367*b1cdbd2cSJim Jagielski			nXTCPos = cXOffset
368*b1cdbd2cSJim Jagielski			oLocTextShape.Position = GetPoint(cXOffset, nYTCPos)
369*b1cdbd2cSJim Jagielski			oLocDBShape.Position = GetPoint(cXOffset, nYDBPos)
370*b1cdbd2cSJim Jagielski			bIsFirstRun = True
371*b1cdbd2cSJim Jagielski			If nDBWidth &gt; nTCWidth Then
372*b1cdbd2cSJim Jagielski				CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
373*b1cdbd2cSJim Jagielski			Else
374*b1cdbd2cSJim Jagielski				CheckOuterPoints(nXDBPos, nTCWidth, nYDBPos, nDBHeight, True)
375*b1cdbd2cSJim Jagielski			End If
376*b1cdbd2cSJim Jagielski			nXTCPos = nMaxColRightX + cHoriDistance
377*b1cdbd2cSJim Jagielski			nXDBPos = nXTCPos
378*b1cdbd2cSJim Jagielski		End If
379*b1cdbd2cSJim Jagielski		AdjustLineWidth(StartA, a-1, nRightDist, 1)
380*b1cdbd2cSJim Jagielski		StartA = a
381*b1cdbd2cSJim Jagielski 	End If
382*b1cdbd2cSJim Jagielski 	iReduceWidth = 0
383*b1cdbd2cSJim JagielskiEnd Sub
384*b1cdbd2cSJim Jagielski
385*b1cdbd2cSJim Jagielski
386*b1cdbd2cSJim Jagielski
387*b1cdbd2cSJim JagielskiFunction GetCorrWidth(StartIndex as Integer, EndIndex as Integer, nDist as Long, Widthfactor as Integer) as Integer
388*b1cdbd2cSJim JagielskiDim ShapeCount as Integer
389*b1cdbd2cSJim Jagielski	If WidthFactor &gt; 0 Then
390*b1cdbd2cSJim Jagielski		ShapeCount = EndIndex-StartIndex + 1
391*b1cdbd2cSJim Jagielski	Else
392*b1cdbd2cSJim Jagielski		ShapeCount = iReduceWidth
393*b1cdbd2cSJim Jagielski	End If
394*b1cdbd2cSJim Jagielski	GetCorrWidth() = (nDist)/ShapeCount
395*b1cdbd2cSJim JagielskiEnd Function
396*b1cdbd2cSJim Jagielski
397*b1cdbd2cSJim Jagielski
398*b1cdbd2cSJim JagielskiSub AdjustLineWidth(StartIndex as Integer, EndIndex as Integer, nDist as Long, Widthfactor as Integer)
399*b1cdbd2cSJim JagielskiDim i as Integer
400*b1cdbd2cSJim JagielskiDim oLocDBShape as Object
401*b1cdbd2cSJim JagielskiDim oLocTCShape as Object
402*b1cdbd2cSJim JagielskiDim CorrWidth as Integer
403*b1cdbd2cSJim JagielskiDim bAdjustPos as Boolean
404*b1cdbd2cSJim JagielskiDim iLocTCPosX as Long
405*b1cdbd2cSJim JagielskiDim iLocDBPosX as Long
406*b1cdbd2cSJim Jagielski	CorrWidth =	GetCorrWidth(StartIndex, EndIndex, nDist, Widthfactor)
407*b1cdbd2cSJim Jagielski	bAdjustPos = False
408*b1cdbd2cSJim Jagielski	iLocTCPosX = cXOffset
409*b1cdbd2cSJim Jagielski	For i = StartIndex To EndIndex
410*b1cdbd2cSJim Jagielski		Set oLocDBShape = oDBShapeList(i)
411*b1cdbd2cSJim Jagielski		Set oLocTCShape = oTCShapeList(i)
412*b1cdbd2cSJim Jagielski		If bAdjustPos Then
413*b1cdbd2cSJim Jagielski			oLocTCShape.Position = GetPoint(iLocTCPosX, oLocTCShape.Position.Y)
414*b1cdbd2cSJim Jagielski			If CurArrangement = cLeftJustified Then
415*b1cdbd2cSJim Jagielski				iLocDBPosX = oLocTCShape.Position.X + oLocTCShape.Size.Width
416*b1cdbd2cSJim Jagielski				oLocDBShape.Position = GetPoint(iLocDBPosX, oLocDBShape.Position.Y)
417*b1cdbd2cSJim Jagielski			Else
418*b1cdbd2cSJim Jagielski				oLocDBShape.Position = GetPoint(iLocTCPosX, oLocTCShape.Position.Y + nTCHeight)
419*b1cdbd2cSJim Jagielski			End If
420*b1cdbd2cSJim Jagielski		Else
421*b1cdbd2cSJim Jagielski			bAdjustPos = True
422*b1cdbd2cSJim Jagielski		End If
423*b1cdbd2cSJim Jagielski		If CDbl(FieldMetaValues(i,1)) &gt; 20 or WidthFactor &gt; 0 Then
424*b1cdbd2cSJim Jagielski			If (CurArrangement = cTopJustified) And (oLocTCShape.Size.Width &gt; oLocDBShape.Size.Width) Then
425*b1cdbd2cSJim Jagielski				oLocDBShape.Size = GetSize(oLocTCShape.Size.Width + WidthFactor * CorrWidth, oLocDBShape.Size.Height)
426*b1cdbd2cSJim Jagielski			Else
427*b1cdbd2cSJim Jagielski				oLocDBShape.Size = GetSize(oLocDBShape.Size.Width + WidthFactor * CorrWidth, oLocDBShape.Size.Height)
428*b1cdbd2cSJim Jagielski			End If
429*b1cdbd2cSJim Jagielski		End If
430*b1cdbd2cSJim Jagielski		iLocTCPosX = oLocDBShape.Position.X + oLocDBShape.Size.Width + cHoriDistance
431*b1cdbd2cSJim Jagielski		If CurArrangement = cTopJustified Then
432*b1cdbd2cSJim Jagielski			If oLocTCShape.Size.Width &gt; oLocDBShape.Size.Width Then
433*b1cdbd2cSJim Jagielski				iLocTCPosX = oLocDBShape.Position.X + oLocTCShape.Size.Width + cHoriDistance
434*b1cdbd2cSJim Jagielski			End If
435*b1cdbd2cSJim Jagielski		End If
436*b1cdbd2cSJim Jagielski	Next i
437*b1cdbd2cSJim JagielskiEnd Sub
438*b1cdbd2cSJim Jagielski
439*b1cdbd2cSJim Jagielski
440*b1cdbd2cSJim JagielskiSub CheckOuterPoints(nXPos, nWidth, nYPos, nHeight, bIsDBField as Boolean)
441*b1cdbd2cSJim JagielskiDim nColRightX as Long
442*b1cdbd2cSJim JagielskiDim nRowY as Long
443*b1cdbd2cSJim JagielskiDim nOldMaxRowY as Long
444*b1cdbd2cSJim Jagielski	If CurArrangement = cLeftJustified Or CurArrangement = cTopJustified Then
445*b1cdbd2cSJim Jagielski		If bIsDBField Then
446*b1cdbd2cSJim Jagielski			&apos; Only at DBControls you can measure the Value of nMaxRowY
447*b1cdbd2cSJim Jagielski			If bIsFirstRun Then
448*b1cdbd2cSJim Jagielski				nMaxRowY = nYPos + nHeight
449*b1cdbd2cSJim Jagielski				nSecMaxRowY = nMaxRowY
450*b1cdbd2cSJim Jagielski			Else
451*b1cdbd2cSJim Jagielski				nRowY = nYPos + nHeight
452*b1cdbd2cSJim Jagielski				If nRowY &gt;= nMaxRowY Then
453*b1cdbd2cSJim Jagielski					nOldMaxRowY = nMaxRowY
454*b1cdbd2cSJim Jagielski					nSecMaxRowY = nOldMaxRowY
455*b1cdbd2cSJim Jagielski					nMaxRowY = nRowY
456*b1cdbd2cSJim Jagielski				End If
457*b1cdbd2cSJim Jagielski			End If
458*b1cdbd2cSJim Jagielski		End If
459*b1cdbd2cSJim Jagielski	End If
460*b1cdbd2cSJim Jagielski	&apos; Find the outer right point
461*b1cdbd2cSJim Jagielski	If bIsFirstRun Then
462*b1cdbd2cSJim Jagielski		nMaxColRightX = nXPos + nWidth
463*b1cdbd2cSJim Jagielski		bIsFirstRun = False
464*b1cdbd2cSJim Jagielski	Else
465*b1cdbd2cSJim Jagielski		nColRightX = nXPos + nWidth
466*b1cdbd2cSJim Jagielski		If nColRightX &gt; nMaxColRightX Then
467*b1cdbd2cSJim Jagielski			nMaxColRightX = nColRightX
468*b1cdbd2cSJim Jagielski		End If
469*b1cdbd2cSJim Jagielski	End If
470*b1cdbd2cSJim JagielskiEnd Sub
471*b1cdbd2cSJim Jagielski
472*b1cdbd2cSJim Jagielski
473*b1cdbd2cSJim JagielskiFunction PositionGridControl(MaxIndex as Integer)
474*b1cdbd2cSJim JagielskiDim oControl as Object
475*b1cdbd2cSJim JagielskiDim n as Integer
476*b1cdbd2cSJim JagielskiDim oColumn as Object
477*b1cdbd2cSJim JagielskiDim aPoint as New com.sun.star.awt.Point
478*b1cdbd2cSJim JagielskiDim aSize as New com.sun.star.awt.Size
479*b1cdbd2cSJim Jagielski	If bControlsareCreated Then
480*b1cdbd2cSJim Jagielski		ShapesToNirwana()
481*b1cdbd2cSJim Jagielski	End If
482*b1cdbd2cSJim Jagielski	oGridModel = CreateUnoService(oModelService(cGridControl))
483*b1cdbd2cSJim Jagielski	oGridModel.Name = &quot;Grid1&quot;
484*b1cdbd2cSJim Jagielski	aPoint = GetPoint(cXOffset, cYOffset)
485*b1cdbd2cSJim Jagielski	aSize = GetSize(nFormWidth, nFormHeight)
486*b1cdbd2cSJim Jagielski	oDBForm.InsertByName (oGridModel.Name, oGridModel)
487*b1cdbd2cSJim Jagielski	oGridShape = InsertControl(oDrawPage, oGridModel, aPoint, aSize)
488*b1cdbd2cSJim Jagielski	For n = 0 to MaxIndex
489*b1cdbd2cSJim Jagielski		GetCurrentMetaValues(n)
490*b1cdbd2cSJim Jagielski	    If CurFieldType = com.sun.star.sdbc.DataType.TIMESTAMP Then
491*b1cdbd2cSJim Jagielski			oColumn = SetupGridColumn(oGridModel,&quot;DateField&quot;, False, com.sun.star.sdbc.DataType.DATE, CurFieldName &amp; &quot; &quot; &amp; sDateAppendix)
492*b1cdbd2cSJim Jagielski			oColumn = SetupGridColumn(oGridModel,&quot;TimeField&quot;, False, com.sun.star.sdbc.DataType.TIME, CurFieldName &amp; &quot; &quot; &amp; sTimeAppendix)
493*b1cdbd2cSJim Jagielski	    Else
494*b1cdbd2cSJim Jagielski			If CurControlType = cImageControl Then
495*b1cdbd2cSJim Jagielski				oColumn = SetupGridColumn(oGridModel,&quot;TextField&quot;, True, CurFieldType, CurFieldName)
496*b1cdbd2cSJim Jagielski			Else
497*b1cdbd2cSJim Jagielski				oColumn = SetupGridColumn(oGridModel, CurControlName, False, CurFieldType, CurFieldName)
498*b1cdbd2cSJim Jagielski			End If
499*b1cdbd2cSJim Jagielski		End If
500*b1cdbd2cSJim Jagielski		oProgressbar.Value = n
501*b1cdbd2cSJim Jagielski	next n
502*b1cdbd2cSJim JagielskiEnd Function
503*b1cdbd2cSJim Jagielski
504*b1cdbd2cSJim Jagielski
505*b1cdbd2cSJim JagielskiFunction SetupGridColumn(oGridModel as Object, ControlName as String, bHidden as Boolean, iLocFieldType as Integer, ColName as String) as Object
506*b1cdbd2cSJim JagielskiDim oColumn as Object
507*b1cdbd2cSJim Jagielski	CurControlName = ControlName
508*b1cdbd2cSJim Jagielski	oColumn = oGridModel.CreateColumn(CurControlName)
509*b1cdbd2cSJim Jagielski	oColumn.Name = CalcUniqueContentName(oGridModel, CurControlName)
510*b1cdbd2cSJim Jagielski	oColumn.Hidden = bHidden
511*b1cdbd2cSJim Jagielski	SetNumerics(oColumn, iLocFieldType)
512*b1cdbd2cSJim Jagielski	oColumn.DataField = CurFieldName
513*b1cdbd2cSJim Jagielski	oColumn.Label = ColName
514*b1cdbd2cSJim Jagielski	oColumn.Width = 0 	&apos; Width of column is adjusted to Columname
515*b1cdbd2cSJim Jagielski	oGridModel.insertByName(oColumn.Name, oColumn)
516*b1cdbd2cSJim JagielskiEnd Function
517*b1cdbd2cSJim Jagielski
518*b1cdbd2cSJim Jagielski
519*b1cdbd2cSJim JagielskiSub ControlCaptionstoStandardLayout()
520*b1cdbd2cSJim JagielskiDim i as Integer
521*b1cdbd2cSJim JagielskiDim iBorderType as Integer
522*b1cdbd2cSJim JagielskiDim oCurModel as Object
523*b1cdbd2cSJim JagielskiDim oStyle as Object
524*b1cdbd2cSJim JagielskiDim iStandardColor as Long
525*b1cdbd2cSJim Jagielski	If CurArrangement &lt;&gt; cTabled Then
526*b1cdbd2cSJim Jagielski		oStyle = oDocument.StyleFamilies.GetByName(&quot;ParagraphStyles&quot;).GetByName(&quot;Standard&quot;)
527*b1cdbd2cSJim Jagielski		iStandardColor = oStyle.CharColor
528*b1cdbd2cSJim Jagielski		For i = 0 To MaxIndex
529*b1cdbd2cSJim Jagielski			oCurModel = oTCShapeList(i).GetControl
530*b1cdbd2cSJim Jagielski			If i = 0 Then
531*b1cdbd2cSJim Jagielski				If oCurModel.TextColor = iStandardColor Then
532*b1cdbd2cSJim Jagielski					Exit Sub
533*b1cdbd2cSJim Jagielski				End If
534*b1cdbd2cSJim Jagielski			End If
535*b1cdbd2cSJim Jagielski			oCurModel.TextColor = iStandardColor
536*b1cdbd2cSJim Jagielski		Next i
537*b1cdbd2cSJim Jagielski	End If
538*b1cdbd2cSJim JagielskiEnd Sub
539*b1cdbd2cSJim Jagielski
540*b1cdbd2cSJim Jagielski
541*b1cdbd2cSJim JagielskiSub GroupShapesTogether()
542*b1cdbd2cSJim JagielskiDim i as Integer
543*b1cdbd2cSJim Jagielski	If CurArrangement &lt;&gt; cTabled Then
544*b1cdbd2cSJim Jagielski		For i = 0 To MaxIndex
545*b1cdbd2cSJim Jagielski			oGroupShapeList(i) = CreateUnoService(&quot;com.sun.star.drawing.ShapeCollection&quot;)
546*b1cdbd2cSJim Jagielski			oGroupShapeList(i).Add(oTCShapeList(i))
547*b1cdbd2cSJim Jagielski			oGroupShapeList(i).Add(oDBShapeList(i))
548*b1cdbd2cSJim Jagielski			oDrawPage.Group(oGroupShapeList(i))
549*b1cdbd2cSJim Jagielski		Next i
550*b1cdbd2cSJim Jagielski	Else
551*b1cdbd2cSJim Jagielski		RemoveNirwanaShapes()
552*b1cdbd2cSJim Jagielski	End If
553*b1cdbd2cSJim JagielskiEnd Sub</script:module>
554