xref: /AOO41X/main/wizards/source/formwizard/Layouter.xba (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Layouter" script:language="StarBasic">Option Explicit
24
25Public oProgressbar as Object
26Public ProgressValue as Integer
27Public oDocument as Object
28Public oController as Object
29Public oForm as Object
30Public oDrawPage as Object
31Public oPageStyle as Object
32
33Public nMaxColRightX as Long
34Public nMaxTCWidth as Long
35Public nMaxRowRightX as Long
36Public nMaxRowY as Long
37Public nSecMaxRowY as Long
38Public MaxIndex as Integer
39Public CurIndex as Integer
40
41Public Const cVertDistance = 200
42Public Const cHoriDistance = 300
43
44Public nPageWidth as Long
45Public nPageHeight as Long
46Public nFormWidth as Long
47Public nFormHeight as Long
48Public nMaxHoriPos as Long
49Public nMaxVertPos as Long
50
51Public CONST SBALIGNLEFT = 0
52Public CONST SBALIGNRIGHT = 2
53
54Public Const SBNOBORDER = 0
55Public Const SB3DBORDER = 1
56Public Const SBSIMPLEBORDER = 2
57
58Public CurArrangement as Integer
59Public CurBorderType as Integer
60Public CurAlignmode as Integer
61
62Public OldAlignMode as Integer
63Public OldBorderType as Integer
64Public OldArrangement as Integer
65
66Public Const cColumnarLeft = 1
67Public Const cColumnarTop = 2
68Public Const cTabled = 3
69Public Const cLeftJustified = 4
70Public Const cTopJustified = 5
71
72Public Const cXOffset = 1000
73Public Const cYOffset = 700
74&apos; This is the viewed space that we lose because of the symbol bars
75Public Const cSymbolMargin = 2000
76Public Const MaxFieldIndex = 200
77
78Public Const cControlCollectionCount = 9
79Public Const cLabel         = 1
80Public Const cTextBox       = 2
81Public Const cCheckBox      = 3
82Public Const cDateBox       = 4
83Public Const cTimeBox       = 5
84Public Const cNumericBox    = 6
85Public Const cCurrencyBox   = 7
86Public Const cGridControl   = 8
87Public Const cImageControl  = 9
88
89Public Styles(100, 8) as String
90
91Public CurControlType as Integer
92Public CurFieldlength as Double
93Public CurFieldType as Integer
94Public CurFieldName as String
95Public CurControlName as String
96Public CurFormatKey as Long
97Public CurDefaultValue
98Public CurIsCurrency as Boolean
99Public CurScale as Integer
100Public CurHelpText as String
101
102Public FieldMetaValues(MaxFieldIndex, 8)
103&apos; Description of this List:
104&apos;  CurFieldType = FieldMetaValues(Index,0)
105&apos;  CurFieldLength = FieldMetaValues(Index,1)
106&apos;  CurControlType = FieldMetaValues(Index,2)   (ControlType eg. cLabel, cTextbox usw.)
107&apos;  CurControlName = FieldMetaValues(Index,3)
108&apos;  CurFormatKey = FieldMetaValues(Index,4)
109&apos;  CurDefaultValue = FieldMetaValues(Index,5)
110&apos;  CurIsCurrency = FieldMetaValues(Index,6)
111&apos;  CurScale = FieldMetaValues(Index,7)
112&apos;  CurHelpText = FieldMetaValues(Index,8)
113
114Public FieldNames(MaxFieldIndex) as string
115Public oModelService(cControlCollectionCount) as String
116Public oGridModel as Object
117
118
119Function InsertControl(oContainer as Object, oControlObject as object, aPoint as Object, aSize as Object)
120Dim oShape as object
121    oShape = oDocument.CreateInstance (&quot;com.sun.star.drawing.ControlShape&quot;)
122    oShape.Size = aSize
123    oShape.Position = aPoint
124    oShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
125    oShape.control = oControlObject
126    oContainer.Add(oShape)
127    InsertControl() = oShape
128End Function
129
130
131Function ArrangeControls()
132Dim oShape as Object
133Dim i as Integer
134    oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
135    oProgressbar.Start(&quot;&quot;, MaxIndex)
136    If oDBForm.HasbyName(&quot;Grid1&quot;) Then
137        RemoveShapes()
138    End If
139    ToggleLayoutPage(False)
140    Select Case CurArrangement
141        Case cTabled
142            PositionGridControl(MaxIndex)
143        Case Else
144            PositionControls(MaxIndex)
145    End Select
146    ToggleLayoutPage(True)
147    oProgressbar.End
148End Function
149
150
151Sub OpenFormDocument()
152Dim NoArgs() as new com.sun.star.beans.PropertyValue
153Dim oViewSettings as Object
154    oDocument = CreateNewDocument(&quot;swriter&quot;)
155    oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
156    oProgressbar.Start(&quot;&quot;, 100)
157    oDocument.ApplyFormDesignMode = False
158    oController = oDocument.GetCurrentController
159    oViewSettings = oDocument.CurrentController.ViewSettings
160    oViewSettings.ShowTableBoundaries = False
161    oViewSettings.ShowOnlineLayout = True
162    oDrawPage = oDocument.DrawPage
163    oPageStyle = oDocument.StyleFamilies.GetByName(&quot;PageStyles&quot;).GetByName(&quot;Standard&quot;)
164End Sub
165
166
167Sub InitializeLabelValues()
168Dim oLabelModel as Object
169Dim oTBModel as Object
170Dim oLabelShape as Object
171Dim oTBShape as Object
172Dim aTBSize As New com.sun.star.awt.Size
173Dim aLabelSize As New com.sun.star.awt.Size
174Dim aPoint As New com.sun.star.awt.Point
175Dim aSize As New com.sun.star.awt.Size
176Dim oLocControl as Object
177Dim oLocPeer as Object
178    oLabelModel =  CreateUnoService(&quot;com.sun.star.form.component.FixedText&quot;)
179    oTBModel =  CreateUnoService(&quot;com.sun.star.form.component.TextField&quot;)
180
181    Set oLabelShape = InsertControl(oDrawPage, oLabelModel, aPoint, aLabelSize)
182    Set oTBShape = InsertControl(oDrawPage, oTBModel, aPoint, aSize)
183
184    oLocPeer = oController.GetControl(oLabelModel).Peer
185    XPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterX
186    YPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterY
187    aLabelSize = GetPeerSize(oLabelModel, oLocControl, &quot;The quick brown fox...&quot;)
188    nTCHeight = (aLabelSize.Height+1) * YPixelFactor
189    aTBSize = GetPeerSize(oTBModel, oLocControl, &quot;The quick brown fox...&quot;)
190    nDBRefHeight = (aTBSize.Height+1) * YPixelFactor
191    BasicLabelDiffHeight = Clng((nDBRefHeight - nTCHeight)/2)
192    oDrawPage.Remove(oLabelShape)
193    oDrawPage.Remove(oTBShape)
194End Sub
195
196
197Sub ConfigurePageStyle()
198Dim aPageSize As New com.sun.star.awt.Size
199Dim aSize As New com.sun.star.awt.Size
200    oPageStyle.IsLandscape = True
201    aPageSize = oPageStyle.Size
202    nPageWidth = aPageSize.Width
203    nPageHeight = aPageSize.Height
204    aSize.Width = nPageHeight
205    aSize.Height = nPageWidth
206    oPageStyle.Size = aSize
207    nPageWidth = nPageHeight
208    nPageHeight = oPageStyle.Size.Height
209    nFormWidth = nPageWidth - oPageStyle.RightMargin - oPageStyle.LeftMargin - 2 * cXOffset
210    nFormHeight = nPageHeight - oPageStyle.TopMargin - oPageStyle.BottomMargin - 2 * cYOffset - cSymbolMargin
211End Sub
212
213
214&apos; Modify the Borders of the Controls
215Sub ChangeBorderLayouts(oEvent as Object)
216Dim oModel as Object
217Dim i as Integer
218Dim oCurModel as Object
219Dim sLocText as String
220Dim oGroupShape as Object
221Dim s as Integer
222    If Not bDebug Then
223        On Local Error GoTo WIZARDERROR
224    End If
225    oModel = oEvent.Source.Model
226    SwitchBorderMode(Val(Right(oModel.Name,1)))
227    ToggleLayoutPage(False)
228    If CurArrangement = cTabled Then
229        oGridModel.Border = CurBorderType
230    Else
231        If OldBorderType &lt;&gt; CurBorderType Then
232            For i = 0 To MaxIndex
233                If oDBShapeList(i).SupportsService(&quot;com.sun.star.drawing.GroupShape&quot;) Then
234                    oGroupShape = oDBShapeList(i)
235                    For s = 0 To oGroupShape.Count-1
236                        oGroupShape(s).Control.Border = CurBorderType
237                    Next s
238                Else
239                    If oDBModelList(i).PropertySetInfo.HasPropertyByName(&quot;Border&quot;) Then
240                        oDBModelList(i).Border = CurBorderType
241                    End If
242                End If
243            Next i
244        End If
245    End If
246    ToggleLayoutPage(True)
247WIZARDERROR:
248    If Err &lt;&gt; 0 Then
249        Msgbox(sMsgErrMsg, 16, GetProductName())
250        Resume LOCERROR
251        LOCERROR:
252        DlgFormDB.Dispose()
253    End If
254End Sub
255
256
257Sub ChangeLabelAlignments(oEvent as Object)
258Dim i as Integer
259Dim oSize as New com.sun.star.awt.Size
260Dim oModel as Object
261    If Not bDebug Then
262        On Local Error GoTo WIZARDERROR
263    End If
264    oModel = oEvent.Source.Model
265    SwitchAlignMode(Val(Right(oModel.Name,1)))
266    ToggleLayoutPage(False)
267    If OldAlignMode &lt;&gt; CurAlignMode Then
268        For i = 0 To MaxIndex
269            oTCShapeList(i).GetControl.Align = CurAlignmode
270        Next i
271    End If
272    If CurAlignmode = com.sun.star.awt.TextAlign.RIGHT Then
273        For i = 0 To Ubound(oTCShapeList())
274            oSize = oTCShapeList(i).Size
275            oSize.Width = oDBShapeList(i).Position.X - oTCShapeList(i).Position.X - cHoriDistance
276            oTCShapeList(i).Size = oSize
277        Next i
278    End If
279
280WIZARDERROR:
281    If Err &lt;&gt; 0 Then
282        Msgbox(sMsgErrMsg, 16, GetProductName())
283        Resume LOCERROR
284        LOCERROR:
285    End If
286    ToggleLayoutPage(True)
287End Sub
288
289
290Sub ChangeArrangemode(oEvent as Object)
291Dim oModel as Object
292    If Not bDebug Then
293        On Local Error GoTo WIZARDERROR
294    End If
295    oModel = oEvent.Source.Model
296    SwitchArrangementButtons(Val(Right(oModel.Name,1)))
297    oModel.State = 1
298    DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; OldArrangement).Model.State = 0
299    If CurArrangement &lt;&gt; OldArrangement Then
300        ArrangeControls()
301        Select Case CurArrangement
302            Case cTabled
303                ToggleBorderGroup(False)
304                ToggleAlignGroup(False)
305            Case Else &apos; cColumnarTop,cLeftJustified, cTopJustified
306                ToggleAlignGroup(CurArrangement = cColumnarLeft)
307                If CurArrangement = cColumnarTop Then
308                    If CurAlignMode = com.sun.star.awt.TextAlign.RIGHT Then
309                        DialogModel.optAlign0.State = 1
310                        CurAlignMode = com.sun.star.awt.TextAlign.LEFT
311                        OldAlignMode = com.sun.star.awt.TextAlign.RIGHT
312                    End If
313                End If
314                ControlCaptionstoStandardLayout()
315                oDBForm.Load
316        End Select
317    End If
318WIZARDERROR:
319    If Err &lt;&gt; 0 Then
320        Msgbox(sMsgErrMsg, 16, GetProductName())
321        Resume LOCERROR
322        LOCERROR:
323    End If
324End Sub
325
326
327Sub ToggleBorderGroup(bDoEnable as Boolean)
328    With DialogModel
329        .hlnBorderLayout.Enabled = bDoEnable
330        .optBorder0.Enabled = bDoEnable     &apos; 0: No border
331        .optBorder1.Enabled = bDoEnable     &apos; 1: 3D border
332        .optBorder2.Enabled = bDoEnable     &apos; 2: simple border
333    End With
334End Sub
335
336
337Sub ToggleAlignGroup(ByVal bDoEnable as Boolean)
338    With DialogModel
339        If bDoEnable Then
340            bDoEnable = CurArrangement = cColumnarLeft
341        End If
342        .hlnAlign.Enabled = bDoEnable
343        .optAlign0.Enabled = bDoEnable
344        .optAlign2.Enabled = bDoEnable
345    End With
346End Sub
347
348
349Sub ToggleLayoutPage(bDoEnable as Boolean, Optional FocusControlName as String)
350    DialogModel.Enabled = bDoEnable
351    If bDoEnable Then
352        If Not bDebug Then
353            oDocument.UnlockControllers()
354        End If
355        ToggleOptionButtons(DialogModel,(bWithBackGraphic = True))
356        ToggleAlignGroup(bDoEnable)
357        ToggleBorderGroup(bDoEnable)
358    Else
359        If Not bDebug Then
360            oDocument.LockControllers()
361        End If
362    End If
363    If Not IsMissing(FocusControlName) Then
364        DlgFormDB.GetControl(FocusControlName).SetFocus()
365    End If
366End Sub
367
368
369Sub DestroyControlShapes(oDrawPage as Object)
370Dim i as Integer
371Dim oShape as Object
372    For i = oDrawPage.Count-1 To 0 Step -1
373        oShape = oDrawPage.GetByIndex(i)
374        If oShape.ShapeType = &quot;com.sun.star.drawing.ControlShape&quot; Then
375            oShape.Dispose()
376        End If
377    Next i
378End Sub
379
380
381Sub SwitchArrangementButtons(ByVal LocArrangement as Integer)
382    OldArrangement = CurArrangement
383    CurArrangement = LocArrangement
384    If OldArrangement &lt;&gt; 0 Then
385        DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; OldArrangement).Model.State = 0
386    End If
387    DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; CurArrangement).Model.State = 1
388End Sub
389
390
391Sub SwitchBorderMode(ByVal LocBorderType as Integer)
392    OldBorderType = CurBorderType
393    CurBorderType = LocBorderType
394End Sub
395
396
397Sub SwitchAlignMode(ByVal LocAlignMode as Integer)
398    OldAlignMode = CurAlignMode
399    CurAlignMode = LocAlignMode
400End Sub</script:module>
401