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