1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Layouter" script:
language=
"StarBasic">Option Explicit
22 Public oProgressbar as Object
23 Public ProgressValue as Integer
24 Public oDocument as Object
25 Public oController as Object
26 Public oForm as Object
27 Public oDrawPage as Object
28 Public oPageStyle as Object
30 Public nMaxColRightX as Long
31 Public nMaxTCWidth as Long
32 Public nMaxRowRightX as Long
33 Public nMaxRowY as Long
34 Public nSecMaxRowY as Long
35 Public MaxIndex as Integer
36 Public CurIndex as Integer
38 Public Const cVertDistance =
200
39 Public Const cHoriDistance =
300
41 Public nPageWidth as Long
42 Public nPageHeight as Long
43 Public nFormWidth as Long
44 Public nFormHeight as Long
45 Public nMaxHoriPos as Long
46 Public nMaxVertPos as Long
48 Public CONST SBALIGNLEFT =
0
49 Public CONST SBALIGNRIGHT =
2
51 Public Const SBNOBORDER =
0
52 Public Const SB3DBORDER =
1
53 Public Const SBSIMPLEBORDER =
2
55 Public CurArrangement as Integer
56 Public CurBorderType as Integer
57 Public CurAlignmode as Integer
59 Public OldAlignMode as Integer
60 Public OldBorderType as Integer
61 Public OldArrangement as Integer
63 Public Const cColumnarLeft =
1
64 Public Const cColumnarTop =
2
65 Public Const cTabled =
3
66 Public Const cLeftJustified =
4
67 Public Const cTopJustified =
5
69 Public Const cXOffset =
1000
70 Public Const cYOffset =
700
71 ' This is the viewed space that we lose because of the symbol bars
72 Public Const cSymbolMargin =
2000
73 Public Const MaxFieldIndex =
200
75 Public Const cControlCollectionCount =
9
76 Public Const cLabel =
1
77 Public Const cTextBox =
2
78 Public Const cCheckBox =
3
79 Public Const cDateBox =
4
80 Public Const cTimeBox =
5
81 Public Const cNumericBox =
6
82 Public Const cCurrencyBox =
7
83 Public Const cGridControl =
8
84 Public Const cImageControl =
9
86 Public Styles(
100,
8) as String
88 Public CurControlType as Integer
89 Public CurFieldlength as Double
90 Public CurFieldType as Integer
91 Public CurFieldName as String
92 Public CurControlName as String
93 Public CurFormatKey as Long
94 Public CurDefaultValue
95 Public CurIsCurrency as Boolean
96 Public CurScale as Integer
97 Public CurHelpText as String
99 Public FieldMetaValues(MaxFieldIndex,
8)
100 ' Description of this List:
101 ' CurFieldType = FieldMetaValues(Index,
0)
102 ' CurFieldLength = FieldMetaValues(Index,
1)
103 ' CurControlType = FieldMetaValues(Index,
2) (ControlType, e.g., cLabel, cTextbox, etc.)
104 ' CurControlName = FieldMetaValues(Index,
3)
105 ' CurFormatKey = FieldMetaValues(Index,
4)
106 ' CurDefaultValue = FieldMetaValues(Index,
5)
107 ' CurIsCurrency = FieldMetaValues(Index,
6)
108 ' CurScale = FieldMetaValues(Index,
7)
109 ' CurHelpText = FieldMetaValues(Index,
8)
111 Public FieldNames(MaxFieldIndex) as string
112 Public oModelService(cControlCollectionCount) as String
113 Public oGridModel as Object
116 Function InsertControl(oContainer as Object, oControlObject as object, aPoint as Object, aSize as Object)
118 oShape = oDocument.CreateInstance (
"com.sun.star.drawing.ControlShape
")
120 oShape.Position = aPoint
121 oShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
122 oShape.control = oControlObject
123 oContainer.Add(oShape)
124 InsertControl() = oShape
128 Function ArrangeControls()
131 oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
132 oProgressbar.Start(
"", MaxIndex)
133 If oDBForm.HasbyName(
"Grid1
") Then
136 ToggleLayoutPage(False)
137 Select Case CurArrangement
139 PositionGridControl(MaxIndex)
141 PositionControls(MaxIndex)
143 ToggleLayoutPage(True)
148 Sub OpenFormDocument()
149 Dim NoArgs() as new com.sun.star.beans.PropertyValue
150 Dim oViewSettings as Object
151 oDocument = CreateNewDocument(
"swriter
")
152 oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
153 oProgressbar.Start(
"",
100)
154 oDocument.ApplyFormDesignMode = False
155 oController = oDocument.GetCurrentController
156 oViewSettings = oDocument.CurrentController.ViewSettings
157 oViewSettings.ShowTableBoundaries = False
158 oViewSettings.ShowOnlineLayout = True
159 oDrawPage = oDocument.DrawPage
160 oPageStyle = oDocument.StyleFamilies.GetByName(
"PageStyles
").GetByName(
"Standard
")
164 Sub InitializeLabelValues()
165 Dim oLabelModel as Object
166 Dim oTBModel as Object
167 Dim oLabelShape as Object
168 Dim oTBShape as Object
169 Dim aTBSize As New com.sun.star.awt.Size
170 Dim aLabelSize As New com.sun.star.awt.Size
171 Dim aPoint As New com.sun.star.awt.Point
172 Dim aSize As New com.sun.star.awt.Size
173 Dim oLocControl as Object
174 Dim oLocPeer as Object
175 oLabelModel = CreateUnoService(
"com.sun.star.form.component.FixedText
")
176 oTBModel = CreateUnoService(
"com.sun.star.form.component.TextField
")
178 Set oLabelShape = InsertControl(oDrawPage, oLabelModel, aPoint, aLabelSize)
179 Set oTBShape = InsertControl(oDrawPage, oTBModel, aPoint, aSize)
181 oLocPeer = oController.GetControl(oLabelModel).Peer
182 XPixelFactor =
100000/oLocPeer.GetInfo.PixelPerMeterX
183 YPixelFactor =
100000/oLocPeer.GetInfo.PixelPerMeterY
184 aLabelSize = GetPeerSize(oLabelModel, oLocControl,
"The quick brown fox...
")
185 nTCHeight = (aLabelSize.Height+
1) * YPixelFactor
186 aTBSize = GetPeerSize(oTBModel, oLocControl,
"The quick brown fox...
")
187 nDBRefHeight = (aTBSize.Height+
1) * YPixelFactor
188 BasicLabelDiffHeight = Clng((nDBRefHeight - nTCHeight)/
2)
189 oDrawPage.Remove(oLabelShape)
190 oDrawPage.Remove(oTBShape)
194 Sub ConfigurePageStyle()
195 Dim aPageSize As New com.sun.star.awt.Size
196 Dim aSize As New com.sun.star.awt.Size
197 oPageStyle.IsLandscape = True
198 aPageSize = oPageStyle.Size
199 nPageWidth = aPageSize.Width
200 nPageHeight = aPageSize.Height
201 aSize.Width = nPageHeight
202 aSize.Height = nPageWidth
203 oPageStyle.Size = aSize
204 nPageWidth = nPageHeight
205 nPageHeight = oPageStyle.Size.Height
206 nFormWidth = nPageWidth - oPageStyle.RightMargin - oPageStyle.LeftMargin -
2 * cXOffset
207 nFormHeight = nPageHeight - oPageStyle.TopMargin - oPageStyle.BottomMargin -
2 * cYOffset - cSymbolMargin
211 ' Modify the Borders of the Controls
212 Sub ChangeBorderLayouts(oEvent as Object)
215 Dim oCurModel as Object
216 Dim sLocText as String
217 Dim oGroupShape as Object
220 On Local Error GoTo WIZARDERROR
222 oModel = oEvent.Source.Model
223 SwitchBorderMode(Val(Right(oModel.Name,
1)))
224 ToggleLayoutPage(False)
225 If CurArrangement = cTabled Then
226 oGridModel.Border = CurBorderType
228 If OldBorderType
<> CurBorderType Then
229 For i =
0 To MaxIndex
230 If oDBShapeList(i).SupportsService(
"com.sun.star.drawing.GroupShape
") Then
231 oGroupShape = oDBShapeList(i)
232 For s =
0 To oGroupShape.Count-
1
233 oGroupShape(s).Control.Border = CurBorderType
236 If oDBModelList(i).PropertySetInfo.HasPropertyByName(
"Border
") Then
237 oDBModelList(i).Border = CurBorderType
243 ToggleLayoutPage(True)
245 If Err
<> 0 Then
246 Msgbox(sMsgErrMsg,
16, GetProductName())
254 Sub ChangeLabelAlignments(oEvent as Object)
256 Dim oSize as New com.sun.star.awt.Size
259 On Local Error GoTo WIZARDERROR
261 oModel = oEvent.Source.Model
262 SwitchAlignMode(Val(Right(oModel.Name,
1)))
263 ToggleLayoutPage(False)
264 If OldAlignMode
<> CurAlignMode Then
265 For i =
0 To MaxIndex
266 oTCShapeList(i).GetControl.Align = CurAlignmode
269 If CurAlignmode = com.sun.star.awt.TextAlign.RIGHT Then
270 For i =
0 To Ubound(oTCShapeList())
271 oSize = oTCShapeList(i).Size
272 oSize.Width = oDBShapeList(i).Position.X - oTCShapeList(i).Position.X - cHoriDistance
273 oTCShapeList(i).Size = oSize
278 If Err
<> 0 Then
279 Msgbox(sMsgErrMsg,
16, GetProductName())
283 ToggleLayoutPage(True)
287 Sub ChangeArrangemode(oEvent as Object)
290 On Local Error GoTo WIZARDERROR
292 oModel = oEvent.Source.Model
293 SwitchArrangementButtons(Val(Right(oModel.Name,
1)))
295 DlgFormDB.GetControl(
"cmdArrange
" & OldArrangement).Model.State =
0
296 If CurArrangement
<> OldArrangement Then
298 Select Case CurArrangement
300 ToggleBorderGroup(False)
301 ToggleAlignGroup(False)
302 Case Else
' cColumnarTop,cLeftJustified, cTopJustified
303 ToggleAlignGroup(CurArrangement = cColumnarLeft)
304 If CurArrangement = cColumnarTop Then
305 If CurAlignMode = com.sun.star.awt.TextAlign.RIGHT Then
306 DialogModel.optAlign0.State =
1
307 CurAlignMode = com.sun.star.awt.TextAlign.LEFT
308 OldAlignMode = com.sun.star.awt.TextAlign.RIGHT
311 ControlCaptionstoStandardLayout()
316 If Err
<> 0 Then
317 Msgbox(sMsgErrMsg,
16, GetProductName())
324 Sub ToggleBorderGroup(bDoEnable as Boolean)
326 .hlnBorderLayout.Enabled = bDoEnable
327 .optBorder0.Enabled = bDoEnable
' 0: No border
328 .optBorder1.Enabled = bDoEnable
' 1:
3D border
329 .optBorder2.Enabled = bDoEnable
' 2: simple border
334 Sub ToggleAlignGroup(ByVal bDoEnable as Boolean)
337 bDoEnable = CurArrangement = cColumnarLeft
339 .hlnAlign.Enabled = bDoEnable
340 .optAlign0.Enabled = bDoEnable
341 .optAlign2.Enabled = bDoEnable
346 Sub ToggleLayoutPage(bDoEnable as Boolean, Optional FocusControlName as String)
347 DialogModel.Enabled = bDoEnable
350 oDocument.UnlockControllers()
352 ToggleOptionButtons(DialogModel,(bWithBackGraphic = True))
353 ToggleAlignGroup(bDoEnable)
354 ToggleBorderGroup(bDoEnable)
357 oDocument.LockControllers()
360 If Not IsMissing(FocusControlName) Then
361 DlgFormDB.GetControl(FocusControlName).SetFocus()
366 Sub DestroyControlShapes(oDrawPage as Object)
369 For i = oDrawPage.Count-
1 To
0 Step -
1
370 oShape = oDrawPage.GetByIndex(i)
371 If oShape.ShapeType =
"com.sun.star.drawing.ControlShape
" Then
378 Sub SwitchArrangementButtons(ByVal LocArrangement as Integer)
379 OldArrangement = CurArrangement
380 CurArrangement = LocArrangement
381 If OldArrangement
<> 0 Then
382 DlgFormDB.GetControl(
"cmdArrange
" & OldArrangement).Model.State =
0
384 DlgFormDB.GetControl(
"cmdArrange
" & CurArrangement).Model.State =
1
388 Sub SwitchBorderMode(ByVal LocBorderType as Integer)
389 OldBorderType = CurBorderType
390 CurBorderType = LocBorderType
394 Sub SwitchAlignMode(ByVal LocAlignMode as Integer)
395 OldAlignMode = CurAlignMode
396 CurAlignMode = LocAlignMode
397 End Sub
</script:module>