xref: /trunk/main/wizards/source/formwizard/Layouter.xba (revision fc9fd3f14a55d77b35643a64034752a178b2a5b0)
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
4
5Public oProgressbar as Object
6Public ProgressValue as Integer
7Public oDocument as Object
8Public oController as Object
9Public oForm as Object
10Public oDrawPage as Object
11Public oPageStyle as Object
12
13Public nMaxColRightX as Long
14Public nMaxTCWidth as Long
15Public nMaxRowRightX as Long
16Public nMaxRowY as Long
17Public nSecMaxRowY as Long
18Public MaxIndex as Integer
19Public CurIndex as Integer
20
21Public Const cVertDistance = 200
22Public Const cHoriDistance = 300
23
24Public nPageWidth as Long
25Public nPageHeight as Long
26Public nFormWidth as Long
27Public nFormHeight as Long
28Public nMaxHoriPos as Long
29Public nMaxVertPos as Long
30
31Public CONST SBALIGNLEFT = 0
32Public CONST SBALIGNRIGHT = 2
33
34Public Const SBNOBORDER = 0
35Public Const SB3DBORDER = 1
36Public Const SBSIMPLEBORDER = 2
37
38Public CurArrangement as Integer
39Public CurBorderType as Integer
40Public CurAlignmode as Integer
41
42Public OldAlignMode as Integer
43Public OldBorderType as Integer
44Public OldArrangement as Integer
45
46Public Const cColumnarLeft = 1
47Public Const cColumnarTop = 2
48Public Const cTabled = 3
49Public Const cLeftJustified = 4
50Public Const cTopJustified = 5
51
52Public Const cXOffset = 1000
53Public Const cYOffset = 700
54&apos; This is the viewed space that we lose because of the symbol bars
55Public Const cSymbolMargin = 2000
56Public Const MaxFieldIndex = 200
57
58Public Const cControlCollectionCount = 9
59Public Const cLabel         = 1
60Public Const cTextBox       = 2
61Public Const cCheckBox      = 3
62Public Const cDateBox       = 4
63Public Const cTimeBox       = 5
64Public Const cNumericBox    = 6
65Public Const cCurrencyBox   = 7
66Public Const cGridControl   = 8
67Public Const cImageControl  = 9
68
69Public Styles(100, 8) as String
70
71Public CurControlType as Integer
72Public CurFieldlength as Double
73Public CurFieldType as Integer
74Public CurFieldName as String
75Public CurControlName as String
76Public CurFormatKey as Long
77Public CurDefaultValue
78Public CurIsCurrency as Boolean
79Public CurScale as Integer
80Public CurHelpText as String
81
82Public FieldMetaValues(MaxFieldIndex, 8)
83&apos; Description of this List:
84&apos;  CurFieldType = FieldMetaValues(Index,0)
85&apos;  CurFieldLength = FieldMetaValues(Index,1)
86&apos;  CurControlType = FieldMetaValues(Index,2)   (ControlType eg. cLabel, cTextbox usw.)
87&apos;  CurControlName = FieldMetaValues(Index,3)
88&apos;  CurFormatKey = FieldMetaValues(Index,4)
89&apos;  CurDefaultValue = FieldMetaValues(Index,5)
90&apos;  CurIsCurrency = FieldMetaValues(Index,6)
91&apos;  CurScale = FieldMetaValues(Index,7)
92&apos;  CurHelpText = FieldMetaValues(Index,8)
93
94Public FieldNames(MaxFieldIndex) as string
95Public oModelService(cControlCollectionCount) as String
96Public oGridModel as Object
97
98
99Function InsertControl(oContainer as Object, oControlObject as object, aPoint as Object, aSize as Object)
100Dim oShape as object
101    oShape = oDocument.CreateInstance (&quot;com.sun.star.drawing.ControlShape&quot;)
102    oShape.Size = aSize
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
108End Function
109
110
111Function ArrangeControls()
112Dim oShape as Object
113Dim i as Integer
114    oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
115    oProgressbar.Start(&quot;&quot;, MaxIndex)
116    If oDBForm.HasbyName(&quot;Grid1&quot;) Then
117        RemoveShapes()
118    End If
119    ToggleLayoutPage(False)
120    Select Case CurArrangement
121        Case cTabled
122            PositionGridControl(MaxIndex)
123        Case Else
124            PositionControls(MaxIndex)
125    End Select
126    ToggleLayoutPage(True)
127    oProgressbar.End
128End Function
129
130
131Sub OpenFormDocument()
132Dim NoArgs() as new com.sun.star.beans.PropertyValue
133Dim oViewSettings as Object
134    oDocument = CreateNewDocument(&quot;swriter&quot;)
135    oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
136    oProgressbar.Start(&quot;&quot;, 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(&quot;PageStyles&quot;).GetByName(&quot;Standard&quot;)
144End Sub
145
146
147Sub InitializeLabelValues()
148Dim oLabelModel as Object
149Dim oTBModel as Object
150Dim oLabelShape as Object
151Dim oTBShape as Object
152Dim aTBSize As New com.sun.star.awt.Size
153Dim aLabelSize As New com.sun.star.awt.Size
154Dim aPoint As New com.sun.star.awt.Point
155Dim aSize As New com.sun.star.awt.Size
156Dim oLocControl as Object
157Dim oLocPeer as Object
158    oLabelModel =  CreateUnoService(&quot;com.sun.star.form.component.FixedText&quot;)
159    oTBModel =  CreateUnoService(&quot;com.sun.star.form.component.TextField&quot;)
160
161    Set oLabelShape = InsertControl(oDrawPage, oLabelModel, aPoint, aLabelSize)
162    Set oTBShape = InsertControl(oDrawPage, oTBModel, aPoint, aSize)
163
164    oLocPeer = oController.GetControl(oLabelModel).Peer
165    XPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterX
166    YPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterY
167    aLabelSize = GetPeerSize(oLabelModel, oLocControl, &quot;The quick brown fox...&quot;)
168    nTCHeight = (aLabelSize.Height+1) * YPixelFactor
169    aTBSize = GetPeerSize(oTBModel, oLocControl, &quot;The quick brown fox...&quot;)
170    nDBRefHeight = (aTBSize.Height+1) * YPixelFactor
171    BasicLabelDiffHeight = Clng((nDBRefHeight - nTCHeight)/2)
172    oDrawPage.Remove(oLabelShape)
173    oDrawPage.Remove(oTBShape)
174End Sub
175
176
177Sub ConfigurePageStyle()
178Dim aPageSize As New com.sun.star.awt.Size
179Dim 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
191End Sub
192
193
194&apos; Modify the Borders of the Controls
195Sub ChangeBorderLayouts(oEvent as Object)
196Dim oModel as Object
197Dim i as Integer
198Dim oCurModel as Object
199Dim sLocText as String
200Dim oGroupShape as Object
201Dim s as Integer
202    If Not bDebug Then
203        On Local Error GoTo WIZARDERROR
204    End If
205    oModel = oEvent.Source.Model
206    SwitchBorderMode(Val(Right(oModel.Name,1)))
207    ToggleLayoutPage(False)
208    If CurArrangement = cTabled Then
209        oGridModel.Border = CurBorderType
210    Else
211        If OldBorderType &lt;&gt; CurBorderType Then
212            For i = 0 To MaxIndex
213                If oDBShapeList(i).SupportsService(&quot;com.sun.star.drawing.GroupShape&quot;) Then
214                    oGroupShape = oDBShapeList(i)
215                    For s = 0 To oGroupShape.Count-1
216                        oGroupShape(s).Control.Border = CurBorderType
217                    Next s
218                Else
219                    If oDBModelList(i).PropertySetInfo.HasPropertyByName(&quot;Border&quot;) Then
220                        oDBModelList(i).Border = CurBorderType
221                    End If
222                End If
223            Next i
224        End If
225    End If
226    ToggleLayoutPage(True)
227WIZARDERROR:
228    If Err &lt;&gt; 0 Then
229        Msgbox(sMsgErrMsg, 16, GetProductName())
230        Resume LOCERROR
231        LOCERROR:
232        DlgFormDB.Dispose()
233    End If
234End Sub
235
236
237Sub ChangeLabelAlignments(oEvent as Object)
238Dim i as Integer
239Dim oSize as New com.sun.star.awt.Size
240Dim oModel as Object
241    If Not bDebug Then
242        On Local Error GoTo WIZARDERROR
243    End If
244    oModel = oEvent.Source.Model
245    SwitchAlignMode(Val(Right(oModel.Name,1)))
246    ToggleLayoutPage(False)
247    If OldAlignMode &lt;&gt; CurAlignMode Then
248        For i = 0 To MaxIndex
249            oTCShapeList(i).GetControl.Align = CurAlignmode
250        Next i
251    End If
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
257        Next i
258    End If
259
260WIZARDERROR:
261    If Err &lt;&gt; 0 Then
262        Msgbox(sMsgErrMsg, 16, GetProductName())
263        Resume LOCERROR
264        LOCERROR:
265    End If
266    ToggleLayoutPage(True)
267End Sub
268
269
270Sub ChangeArrangemode(oEvent as Object)
271Dim oModel as Object
272    If Not bDebug Then
273        On Local Error GoTo WIZARDERROR
274    End If
275    oModel = oEvent.Source.Model
276    SwitchArrangementButtons(Val(Right(oModel.Name,1)))
277    oModel.State = 1
278    DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; OldArrangement).Model.State = 0
279    If CurArrangement &lt;&gt; OldArrangement Then
280        ArrangeControls()
281        Select Case CurArrangement
282            Case cTabled
283                ToggleBorderGroup(False)
284                ToggleAlignGroup(False)
285            Case Else &apos; 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
292                    End If
293                End If
294                ControlCaptionstoStandardLayout()
295                oDBForm.Load
296        End Select
297    End If
298WIZARDERROR:
299    If Err &lt;&gt; 0 Then
300        Msgbox(sMsgErrMsg, 16, GetProductName())
301        Resume LOCERROR
302        LOCERROR:
303    End If
304End Sub
305
306
307Sub ToggleBorderGroup(bDoEnable as Boolean)
308    With DialogModel
309        .hlnBorderLayout.Enabled = bDoEnable
310        .optBorder0.Enabled = bDoEnable     &apos; 0: No border
311        .optBorder1.Enabled = bDoEnable     &apos; 1: 3D border
312        .optBorder2.Enabled = bDoEnable     &apos; 2: simple border
313    End With
314End Sub
315
316
317Sub ToggleAlignGroup(ByVal bDoEnable as Boolean)
318    With DialogModel
319        If bDoEnable Then
320            bDoEnable = CurArrangement = cColumnarLeft
321        End If
322        .hlnAlign.Enabled = bDoEnable
323        .optAlign0.Enabled = bDoEnable
324        .optAlign2.Enabled = bDoEnable
325    End With
326End Sub
327
328
329Sub ToggleLayoutPage(bDoEnable as Boolean, Optional FocusControlName as String)
330    DialogModel.Enabled = bDoEnable
331    If bDoEnable Then
332        If Not bDebug Then
333            oDocument.UnlockControllers()
334        End If
335        ToggleOptionButtons(DialogModel,(bWithBackGraphic = True))
336        ToggleAlignGroup(bDoEnable)
337        ToggleBorderGroup(bDoEnable)
338    Else
339        If Not bDebug Then
340            oDocument.LockControllers()
341        End If
342    End If
343    If Not IsMissing(FocusControlName) Then
344        DlgFormDB.GetControl(FocusControlName).SetFocus()
345    End If
346End Sub
347
348
349Sub DestroyControlShapes(oDrawPage as Object)
350Dim i as Integer
351Dim oShape as Object
352    For i = oDrawPage.Count-1 To 0 Step -1
353        oShape = oDrawPage.GetByIndex(i)
354        If oShape.ShapeType = &quot;com.sun.star.drawing.ControlShape&quot; Then
355            oShape.Dispose()
356        End If
357    Next i
358End Sub
359
360
361Sub SwitchArrangementButtons(ByVal LocArrangement as Integer)
362    OldArrangement = CurArrangement
363    CurArrangement = LocArrangement
364    If OldArrangement &lt;&gt; 0 Then
365        DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; OldArrangement).Model.State = 0
366    End If
367    DlgFormDB.GetControl(&quot;cmdArrange&quot; &amp; CurArrangement).Model.State = 1
368End Sub
369
370
371Sub SwitchBorderMode(ByVal LocBorderType as Integer)
372    OldBorderType = CurBorderType
373    CurBorderType = LocBorderType
374End Sub
375
376
377Sub SwitchAlignMode(ByVal LocAlignMode as Integer)
378    OldAlignMode = CurAlignMode
379    CurAlignMode = LocAlignMode
380End Sub</script:module>