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=
"Layouter" script:
language=
"StarBasic">Option Explicit
5 Public oProgressbar as Object
6 Public ProgressValue as Integer
7 Public oDocument as Object
8 Public oController as Object
10 Public oDrawPage as Object
11 Public oPageStyle as Object
13 Public nMaxColRightX as Long
14 Public nMaxTCWidth as Long
15 Public nMaxRowRightX as Long
16 Public nMaxRowY as Long
17 Public nSecMaxRowY as Long
18 Public MaxIndex as Integer
19 Public CurIndex as Integer
21 Public Const cVertDistance =
200
22 Public Const cHoriDistance =
300
24 Public nPageWidth as Long
25 Public nPageHeight as Long
26 Public nFormWidth as Long
27 Public nFormHeight as Long
28 Public nMaxHoriPos as Long
29 Public nMaxVertPos as Long
31 Public CONST SBALIGNLEFT =
0
32 Public CONST SBALIGNRIGHT =
2
34 Public Const SBNOBORDER =
0
35 Public Const SB3DBORDER =
1
36 Public Const SBSIMPLEBORDER =
2
38 Public CurArrangement as Integer
39 Public CurBorderType as Integer
40 Public CurAlignmode as Integer
42 Public OldAlignMode as Integer
43 Public OldBorderType as Integer
44 Public OldArrangement as Integer
46 Public Const cColumnarLeft =
1
47 Public Const cColumnarTop =
2
48 Public Const cTabled =
3
49 Public Const cLeftJustified =
4
50 Public Const cTopJustified =
5
52 Public Const cXOffset =
1000
53 Public Const cYOffset =
700
54 ' This is the viewed space that we lose because of the symbol bars
55 Public Const cSymbolMargin =
2000
56 Public Const MaxFieldIndex =
200
58 Public Const cControlCollectionCount =
9
59 Public Const cLabel =
1
60 Public Const cTextBox =
2
61 Public Const cCheckBox =
3
62 Public Const cDateBox =
4
63 Public Const cTimeBox =
5
64 Public Const cNumericBox =
6
65 Public Const cCurrencyBox =
7
66 Public Const cGridControl =
8
67 Public Const cImageControl =
9
69 Public Styles(
100,
8) as String
71 Public CurControlType as Integer
72 Public CurFieldlength as Double
73 Public CurFieldType as Integer
74 Public CurFieldName as String
75 Public CurControlName as String
76 Public CurFormatKey as Long
77 Public CurDefaultValue
78 Public CurIsCurrency as Boolean
79 Public CurScale as Integer
80 Public CurHelpText as String
82 Public FieldMetaValues(MaxFieldIndex,
8)
83 ' Description of this List:
84 ' CurFieldType = FieldMetaValues(Index,
0)
85 ' CurFieldLength = FieldMetaValues(Index,
1)
86 ' CurControlType = FieldMetaValues(Index,
2) (ControlType eg. cLabel, cTextbox usw.)
87 ' CurControlName = FieldMetaValues(Index,
3)
88 ' CurFormatKey = FieldMetaValues(Index,
4)
89 ' CurDefaultValue = FieldMetaValues(Index,
5)
90 ' CurIsCurrency = FieldMetaValues(Index,
6)
91 ' CurScale = FieldMetaValues(Index,
7)
92 ' CurHelpText = FieldMetaValues(Index,
8)
94 Public FieldNames(MaxFieldIndex) as string
95 Public oModelService(cControlCollectionCount) as String
96 Public oGridModel as Object
99 Function InsertControl(oContainer as Object, oControlObject as object, aPoint as Object, aSize as Object)
101 oShape = oDocument.CreateInstance (
"com.sun.star.drawing.ControlShape
")
103 oShape.Position = aPoint
104 oShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
105 oShape.control = oControlObject
106 oContainer.Add(oShape)
107 InsertControl() = oShape
111 Function ArrangeControls()
114 oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
115 oProgressbar.Start(
"", MaxIndex)
116 If oDBForm.HasbyName(
"Grid1
") Then
119 ToggleLayoutPage(False)
120 Select Case CurArrangement
122 PositionGridControl(MaxIndex)
124 PositionControls(MaxIndex)
126 ToggleLayoutPage(True)
131 Sub OpenFormDocument()
132 Dim NoArgs() as new com.sun.star.beans.PropertyValue
133 Dim oViewSettings as Object
134 oDocument = CreateNewDocument(
"swriter
")
135 oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
136 oProgressbar.Start(
"",
100)
137 oDocument.ApplyFormDesignMode = False
138 oController = oDocument.GetCurrentController
139 oViewSettings = oDocument.CurrentController.ViewSettings
140 oViewSettings.ShowTableBoundaries = False
141 oViewSettings.ShowOnlineLayout = True
142 oDrawPage = oDocument.DrawPage
143 oPageStyle = oDocument.StyleFamilies.GetByName(
"PageStyles
").GetByName(
"Standard
")
147 Sub InitializeLabelValues()
148 Dim oLabelModel as Object
149 Dim oTBModel as Object
150 Dim oLabelShape as Object
151 Dim oTBShape as Object
152 Dim aTBSize As New com.sun.star.awt.Size
153 Dim aLabelSize As New com.sun.star.awt.Size
154 Dim aPoint As New com.sun.star.awt.Point
155 Dim aSize As New com.sun.star.awt.Size
156 Dim oLocControl as Object
157 Dim oLocPeer as Object
158 oLabelModel = CreateUnoService(
"com.sun.star.form.component.FixedText
")
159 oTBModel = CreateUnoService(
"com.sun.star.form.component.TextField
")
161 Set oLabelShape = InsertControl(oDrawPage, oLabelModel, aPoint, aLabelSize)
162 Set oTBShape = InsertControl(oDrawPage, oTBModel, aPoint, aSize)
164 oLocPeer = oController.GetControl(oLabelModel).Peer
165 XPixelFactor =
100000/oLocPeer.GetInfo.PixelPerMeterX
166 YPixelFactor =
100000/oLocPeer.GetInfo.PixelPerMeterY
167 aLabelSize = GetPeerSize(oLabelModel, oLocControl,
"The quick brown fox...
")
168 nTCHeight = (aLabelSize.Height+
1) * YPixelFactor
169 aTBSize = GetPeerSize(oTBModel, oLocControl,
"The quick brown fox...
")
170 nDBRefHeight = (aTBSize.Height+
1) * YPixelFactor
171 BasicLabelDiffHeight = Clng((nDBRefHeight - nTCHeight)/
2)
172 oDrawPage.Remove(oLabelShape)
173 oDrawPage.Remove(oTBShape)
177 Sub ConfigurePageStyle()
178 Dim aPageSize As New com.sun.star.awt.Size
179 Dim aSize As New com.sun.star.awt.Size
180 oPageStyle.IsLandscape = True
181 aPageSize = oPageStyle.Size
182 nPageWidth = aPageSize.Width
183 nPageHeight = aPageSize.Height
184 aSize.Width = nPageHeight
185 aSize.Height = nPageWidth
186 oPageStyle.Size = aSize
187 nPageWidth = nPageHeight
188 nPageHeight = oPageStyle.Size.Height
189 nFormWidth = nPageWidth - oPageStyle.RightMargin - oPageStyle.LeftMargin -
2 * cXOffset
190 nFormHeight = nPageHeight - oPageStyle.TopMargin - oPageStyle.BottomMargin -
2 * cYOffset - cSymbolMargin
194 ' Modify the Borders of the Controls
195 Sub ChangeBorderLayouts(oEvent as Object)
198 Dim oCurModel as Object
199 Dim sLocText as String
200 Dim oGroupShape as Object
203 On Local Error GoTo WIZARDERROR
205 oModel = oEvent.Source.Model
206 SwitchBorderMode(Val(Right(oModel.Name,
1)))
207 ToggleLayoutPage(False)
208 If CurArrangement = cTabled Then
209 oGridModel.Border = CurBorderType
211 If OldBorderType
<> CurBorderType Then
212 For i =
0 To MaxIndex
213 If oDBShapeList(i).SupportsService(
"com.sun.star.drawing.GroupShape
") Then
214 oGroupShape = oDBShapeList(i)
215 For s =
0 To oGroupShape.Count-
1
216 oGroupShape(s).Control.Border = CurBorderType
219 If oDBModelList(i).PropertySetInfo.HasPropertyByName(
"Border
") Then
220 oDBModelList(i).Border = CurBorderType
226 ToggleLayoutPage(True)
228 If Err
<> 0 Then
229 Msgbox(sMsgErrMsg,
16, GetProductName())
237 Sub ChangeLabelAlignments(oEvent as Object)
239 Dim oSize as New com.sun.star.awt.Size
242 On Local Error GoTo WIZARDERROR
244 oModel = oEvent.Source.Model
245 SwitchAlignMode(Val(Right(oModel.Name,
1)))
246 ToggleLayoutPage(False)
247 If OldAlignMode
<> CurAlignMode Then
248 For i =
0 To MaxIndex
249 oTCShapeList(i).GetControl.Align = CurAlignmode
252 If CurAlignmode = com.sun.star.awt.TextAlign.RIGHT Then
253 For i =
0 To Ubound(oTCShapeList())
254 oSize = oTCShapeList(i).Size
255 oSize.Width = oDBShapeList(i).Position.X - oTCShapeList(i).Position.X - cHoriDistance
256 oTCShapeList(i).Size = oSize
261 If Err
<> 0 Then
262 Msgbox(sMsgErrMsg,
16, GetProductName())
266 ToggleLayoutPage(True)
270 Sub ChangeArrangemode(oEvent as Object)
273 On Local Error GoTo WIZARDERROR
275 oModel = oEvent.Source.Model
276 SwitchArrangementButtons(Val(Right(oModel.Name,
1)))
278 DlgFormDB.GetControl(
"cmdArrange
" & OldArrangement).Model.State =
0
279 If CurArrangement
<> OldArrangement Then
281 Select Case CurArrangement
283 ToggleBorderGroup(False)
284 ToggleAlignGroup(False)
285 Case Else
' cColumnarTop,cLeftJustified, cTopJustified
286 ToggleAlignGroup(CurArrangement = cColumnarLeft)
287 If CurArrangement = cColumnarTop Then
288 If CurAlignMode = com.sun.star.awt.TextAlign.RIGHT Then
289 DialogModel.optAlign0.State =
1
290 CurAlignMode = com.sun.star.awt.TextAlign.LEFT
291 OldAlignMode = com.sun.star.awt.TextAlign.RIGHT
294 ControlCaptionstoStandardLayout()
299 If Err
<> 0 Then
300 Msgbox(sMsgErrMsg,
16, GetProductName())
307 Sub ToggleBorderGroup(bDoEnable as Boolean)
309 .hlnBorderLayout.Enabled = bDoEnable
310 .optBorder0.Enabled = bDoEnable
' 0: No border
311 .optBorder1.Enabled = bDoEnable
' 1:
3D border
312 .optBorder2.Enabled = bDoEnable
' 2: simple border
317 Sub ToggleAlignGroup(ByVal bDoEnable as Boolean)
320 bDoEnable = CurArrangement = cColumnarLeft
322 .hlnAlign.Enabled = bDoEnable
323 .optAlign0.Enabled = bDoEnable
324 .optAlign2.Enabled = bDoEnable
329 Sub ToggleLayoutPage(bDoEnable as Boolean, Optional FocusControlName as String)
330 DialogModel.Enabled = bDoEnable
333 oDocument.UnlockControllers()
335 ToggleOptionButtons(DialogModel,(bWithBackGraphic = True))
336 ToggleAlignGroup(bDoEnable)
337 ToggleBorderGroup(bDoEnable)
340 oDocument.LockControllers()
343 If Not IsMissing(FocusControlName) Then
344 DlgFormDB.GetControl(FocusControlName).SetFocus()
349 Sub DestroyControlShapes(oDrawPage as Object)
352 For i = oDrawPage.Count-
1 To
0 Step -
1
353 oShape = oDrawPage.GetByIndex(i)
354 If oShape.ShapeType =
"com.sun.star.drawing.ControlShape
" Then
361 Sub SwitchArrangementButtons(ByVal LocArrangement as Integer)
362 OldArrangement = CurArrangement
363 CurArrangement = LocArrangement
364 If OldArrangement
<> 0 Then
365 DlgFormDB.GetControl(
"cmdArrange
" & OldArrangement).Model.State =
0
367 DlgFormDB.GetControl(
"cmdArrange
" & CurArrangement).Model.State =
1
371 Sub SwitchBorderMode(ByVal LocBorderType as Integer)
372 OldBorderType = CurBorderType
373 CurBorderType = LocBorderType
377 Sub SwitchAlignMode(ByVal LocAlignMode as Integer)
378 OldAlignMode = CurAlignMode
379 CurAlignMode = LocAlignMode
380 End Sub
</script:module>