summaryrefslogtreecommitdiff
path: root/wizards/source/formwizard/Layouter.xba
blob: ae10314bbda34eed0712099107748aa8f0b5ffe8 (plain)
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Layouter" script:language="StarBasic">Option Explicit

Public oProgressbar as Object
Public ProgressValue as Integer
Public oDocument as Object
Public oController as Object
Public oForm as Object
Public oDrawPage as Object
Public oPageStyle as Object

Public nMaxColRightX as Long
Public nMaxTCWidth as Long
Public nMaxRowRightX as Long
Public nMaxRowY as Long
Public nSecMaxRowY as Long
Public MaxIndex as Integer
Public CurIndex as Integer

Public Const cVertDistance = 200
Public Const cHoriDistance = 300

Public nPageWidth as Long
Public nPageHeight as Long
Public nFormWidth as Long
Public nFormHeight as Long
Public nMaxHoriPos as Long
Public nMaxVertPos as Long

Public CONST SBALIGNLEFT = 0
Public CONST SBALIGNRIGHT = 2

Public Const SBNOBORDER = 0
Public Const SB3DBORDER = 1
Public Const SBSIMPLEBORDER = 2

Public CurArrangement as Integer
Public CurBorderType as Integer
Public CurAlignmode as Integer

Public OldAlignMode as Integer
Public OldBorderType as Integer
Public OldArrangement as Integer

Public Const cColumnarLeft = 1
Public Const cColumnarTop = 2
Public Const cTabled = 3
Public Const cLeftJustified = 4
Public Const cTopJustified = 5

Public Const cXOffset = 1000
Public Const cYOffset = 700
&apos; This is the viewed space that we lose because of the symbol bars
Public Const cSymbolMargin = 2000
Public Const MaxFieldIndex = 200

Public Const cControlCollectionCount = 9
Public Const cLabel 		= 1
Public Const cTextBox 		= 2
Public Const cCheckBox	 	= 3
Public Const cDateBox 		= 4
Public Const cTimeBox 		= 5
Public Const cNumericBox 	= 6
Public Const cCurrencyBox 	= 7
Public Const cGridControl	= 8
Public Const cImageControl	= 9

Public Styles(100, 8) as String

Public CurControlType as Integer
Public CurFieldlength as Double
Public CurFieldType as Integer
Public CurFieldName as String
Public CurControlName as String
Public CurFormatKey as Long
Public CurDefaultValue
Public CurIsCurrency as Boolean
Public CurScale as Integer
Public CurHelpText as String

Public FieldMetaValues(MaxFieldIndex, 8)
&apos; Description of this List:
&apos;	CurFieldType = FieldMetaValues(Index,0)
&apos;	CurFieldLength = FieldMetaValues(Index,1)
&apos;	CurControlType = FieldMetaValues(Index,2)	(ControlType eg. cLabel, cTextbox usw.)
&apos;	CurControlName = FieldMetaValues(Index,3)
&apos;	CurFormatKey = FieldMetaValues(Index,4)
&apos;	CurDefaultValue = FieldMetaValues(Index,5)
&apos;	CurIsCurrency = FieldMetaValues(Index,6)
&apos;	CurScale = FieldMetaValues(Index,7)
&apos;	CurHelpText = FieldMetaValues(Index,8)

Public FieldNames(MaxFieldIndex) as string
Public oModelService(cControlCollectionCount) as String
Public oGridModel as Object


Function InsertControl(oContainer as Object, oControlObject as object, aPoint as Object, aSize as Object)
Dim oShape as object
	oShape = oDocument.CreateInstance (&quot;com.sun.star.drawing.ControlShape&quot;)
	oShape.Size = aSize
	oShape.Position = aPoint
	oShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
	oShape.control = oControlObject
	oContainer.Add(oShape)
	InsertControl() = oShape
End Function


Function ArrangeControls()
Dim oShape as Object
Dim i as Integer
	oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
	oProgressbar.Start(&quot;&quot;, MaxIndex)
	If oDBForm.HasbyName(&quot;Grid1&quot;) Then
		RemoveShapes()
	End If
	ToggleLayoutPage(False)
	Select Case CurArrangement
		Case cTabled
			PositionGridControl(MaxIndex)
		Case Else
			PositionControls(MaxIndex)
	End Select
	ToggleLayoutPage(True)
	oProgressbar.End
End Function


Sub OpenFormDocument()
Dim NoArgs() as new com.sun.star.beans.PropertyValue
Dim oViewSettings as Object
	oDocument = CreateNewDocument(&quot;swriter&quot;)
	oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
	oProgressbar.Start(&quot;&quot;, 100)
	oDocument.ApplyFormDesignMode = False
	oController = oDocument.GetCurrentController
	oViewSettings = oDocument.CurrentController.ViewSettings
	oViewSettings.ShowTableBoundaries = False
	oViewSettings.ShowOnlineLayout = True
	oDrawPage = oDocument.DrawPage
	oPageStyle = oDocument.StyleFamilies.GetByName(&quot;PageStyles&quot;).GetByName(&quot;Standard&quot;)
End Sub


Sub	InitializeLabelValues()
Dim oLabelModel as Object
Dim oTBModel as Object
Dim oLabelShape as Object
Dim oTBShape as Object
Dim aTBSize As New com.sun.star.awt.Size
Dim aLabelSize As New com.sun.star.awt.Size
Dim aPoint As New com.sun.star.awt.Point
Dim aSize As New com.sun.star.awt.Size
Dim oLocControl as Object
Dim oLocPeer as Object
	oLabelModel =  CreateUnoService(&quot;com.sun.star.form.component.FixedText&quot;)
	oTBModel =  CreateUnoService(&quot;com.sun.star.form.component.TextField&quot;)

	Set oLabelShape = InsertControl(oDrawPage, oLabelModel, aPoint, aLabelSize)
	Set oTBShape = InsertControl(oDrawPage, oTBModel, aPoint, aSize)

	oLocPeer = oController.GetControl(oLabelModel).Peer
	XPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterX
	YPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterY
	aLabelSize = GetPeerSize(oLabelModel, oLocControl, &quot;The quick brown fox...&quot;)
	nTCHeight = (aLabelSize.Height+1) * YPixelFactor
	aTBSize = GetPeerSize(oTBModel, oLocControl, &quot;The quick brown fox...&quot;)
	nDBRefHeight = (aTBSize.Height+1) * YPixelFactor
	BasicLabelDiffHeight = Clng((nDBRefHeight - nTCHeight)/2)
	oDrawPage.Remove(oLabelShape)
	oDrawPage.Remove(oTBShape)
End Sub


Sub ConfigurePageStyle()
Dim aPageSize As New com.sun.star.awt.Size
Dim aSize As New com.sun.star.awt.Size
	oPageStyle.IsLandscape = True
	aPageSize = oPageStyle.Size
	nPageWidth = aPageSize.Width
	nPageHeight = aPageSize.Height
	aSize.Width = nPageHeight
	aSize.Height = nPageWidth
	oPageStyle.Size = aSize
	nPageWidth = nPageHeight
	nPageHeight = oPageStyle.Size.Height
	nFormWidth = nPageWidth - oPageStyle.RightMargin - oPageStyle.LeftMargin - 2 * cXOffset
	nFormHeight = nPageHeight - oPageStyle.TopMargin - oPageStyle.BottomMargin - 2 * cYOffset - cSymbolMargin
End Sub


&apos; Modify the Borders of the Controls
Sub ChangeBorderLayouts(oEvent as Object)
Dim oModel as Object
Dim i as Integer
Dim oCurModel as Object
Dim sLocText as String
Dim oGroupShape as Object
Dim s as Integer
	If Not bDebug Then
		On Local Error GoTo WIZARDERROR
	End If
	oModel = oEvent.Source.Model
	SwitchBorderMode(Val(Right(oModel.Name,1)))
	ToggleLayoutPage(False)
	If CurArrangement = cTabled Then
		oGridModel.Border = CurBorderType
	Else
		If OldBorderType &lt;&gt; CurBorderType Then
			For i = 0 To MaxIndex
				If oDBShapeList(i).SupportsService(&quot;com.sun.star.drawing.GroupShape&quot;) Then
					oGroupShape = oDBShapeList(i)
					For s = 0 To oGroupShape.Count-1
						oGroupShape(s).Control.Border = CurBorderType
					Next s
				Else
					If oDBModelList(i).PropertySetInfo.HasPropertyByName(&quot;Border&quot;) Then
						oDBModelList(i).Border = CurBorderType
					End If
				End If
			Next i
		End If
	End If
	ToggleLayoutPage(True)
WIZARDERROR:
	If Err &lt;&gt; 0 Then	
		Msgbox(sMsgErrMsg, 16, GetProductName())
		Resume LOCERROR
		LOCERROR:
		DlgFormDB.Dispose()	
	End If
End Sub


Sub ChangeLabelAlignments(oEvent as Object)
Dim i as Integer
Dim oSize as New com.sun.star.awt.Size
Dim oModel as Object
	If Not bDebug Then
		On Local Error GoTo WIZARDERROR
	End If
	oModel = oEvent.Source.Model
	SwitchAlignMode(Val(Right(oModel.Name,1)))
	ToggleLayoutPage(False)
	If OldAlignMode &lt;&gt; CurAlignMode Then
		For i = 0 To MaxIndex
			oTCShapeList(i).GetControl.Align = CurAlignmode
		Next i
	End If
	If CurAlignmode = com.sun.star.awt.TextAlign.RIGHT Then
		For i = 0 To Ubound(oTCShapeList())
			oSize = oTCShapeList(i).Size
			oSize.Width = oDBShapeList(i).Position.X - oTCShapeList(i).Position.X - cHoriDistance
			oTCShapeList(i).Size = oSize
		Next i
	End If

WIZARDERROR:
	If Err &lt;&gt; 0 Then	
		Msgbox(sMsgErrMsg, 16, GetProductName())
		Resume LOCERROR
		LOCERROR:		
	End If
	ToggleLayoutPage(True)
End Sub


Sub ChangeArrangemode(oEvent as Object)
Dim oModel as Object
	If Not bDebug Then
		On Local Error GoTo WIZARDERROR
	End If
	oModel = oEvent.Source.Model
	SwitchArrangementButtons(Val(Right(oModel.Name,1)))
	oModel.State = 1
	DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; OldArrangement).Model.State = 0
	If CurArrangement &lt;&gt; OldArrangement Then
		ArrangeControls()
		Select Case CurArrangement
			Case cTabled
				ToggleBorderGroup(False)
				ToggleAlignGroup(False)
			Case Else &apos; cColumnarTop,cLeftJustified, cTopJustified
				ToggleAlignGroup(CurArrangement = cColumnarLeft)
				If CurArrangement = cColumnarTop Then
					If CurAlignMode = com.sun.star.awt.TextAlign.RIGHT Then
						DialogModel.optAlign0.State = 1
						CurAlignMode = com.sun.star.awt.TextAlign.LEFT
						OldAlignMode = com.sun.star.awt.TextAlign.RIGHT
					End If
				End If
				ControlCaptionstoStandardLayout()
				oDBForm.Load
		End Select
	End If
WIZARDERROR:
	If Err &lt;&gt; 0 Then	
		Msgbox(sMsgErrMsg, 16, GetProductName())
		Resume LOCERROR
		LOCERROR:		
	End If
End Sub


Sub	ToggleBorderGroup(bDoEnable as Boolean)
	With DialogModel
		.hlnBorderLayout.Enabled = bDoEnable
		.optBorder0.Enabled = bDoEnable	 	&apos; 0: No border
		.optBorder1.Enabled = bDoEnable		&apos; 1: 3D border
		.optBorder2.Enabled = bDoEnable		&apos; 2: simple border
	End With
End Sub


Sub	ToggleAlignGroup(ByVal bDoEnable as Boolean)
	With DialogModel
		If bDoEnable Then
			bDoEnable = CurArrangement = cColumnarLeft
		End If
		.hlnAlign.Enabled = bDoEnable
		.optAlign0.Enabled = bDoEnable
		.optAlign2.Enabled = bDoEnable
	End With
End Sub


Sub ToggleLayoutPage(bDoEnable as Boolean, Optional FocusControlName as String)
	DialogModel.Enabled = bDoEnable
	If bDoEnable Then
		If Not bDebug Then
			oDocument.UnlockControllers()
		End If
		ToggleOptionButtons(DialogModel,(bWithBackGraphic = True))
		ToggleAlignGroup(bDoEnable)
		ToggleBorderGroup(bDoEnable)
	Else
		If Not bDebug Then
			oDocument.LockControllers()	
		End If
	End If
	If Not IsMissing(FocusControlName) Then
		DlgFormDB.GetControl(FocusControlName).SetFocus()
	End If	
End Sub


Sub DestroyControlShapes(oDrawPage as Object)
Dim i as Integer
Dim oShape as Object
	For i = oDrawPage.Count-1 To 0 Step -1
		oShape = oDrawPage.GetByIndex(i)
		If oShape.ShapeType = &quot;com.sun.star.drawing.ControlShape&quot; Then
			oShape.Dispose()
		End If
	Next i
End Sub


Sub SwitchArrangementButtons(ByVal LocArrangement as Integer)
	OldArrangement = CurArrangement
	CurArrangement = LocArrangement
	If OldArrangement &lt;&gt; 0 Then
		DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; OldArrangement).Model.State = 0
	End If
	DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; CurArrangement).Model.State = 1
End Sub


Sub SwitchBorderMode(ByVal LocBorderType as Integer)
	OldBorderType = CurBorderType
	CurBorderType = LocBorderType
End Sub


Sub SwitchAlignMode(ByVal LocAlignMode as Integer)
	OldAlignMode = CurAlignMode
	CurAlignMode = LocAlignMode
End Sub</script:module>