home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Bureautique / OpenOffice / Apache_OpenOffice_4.1.1_Win_x86_install_fr.exe / openoffice1.cab / Layouter.xba < prev    next >
Extensible Markup Language  |  2014-02-25  |  12KB  |  401 lines

  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.  
  25. Public oProgressbar as Object
  26. Public ProgressValue as Integer
  27. Public oDocument as Object
  28. Public oController as Object
  29. Public oForm as Object
  30. Public oDrawPage as Object
  31. Public oPageStyle as Object
  32.  
  33. Public nMaxColRightX as Long
  34. Public nMaxTCWidth as Long
  35. Public nMaxRowRightX as Long
  36. Public nMaxRowY as Long
  37. Public nSecMaxRowY as Long
  38. Public MaxIndex as Integer
  39. Public CurIndex as Integer
  40.  
  41. Public Const cVertDistance = 200
  42. Public Const cHoriDistance = 300
  43.  
  44. Public nPageWidth as Long
  45. Public nPageHeight as Long
  46. Public nFormWidth as Long
  47. Public nFormHeight as Long
  48. Public nMaxHoriPos as Long
  49. Public nMaxVertPos as Long
  50.  
  51. Public CONST SBALIGNLEFT = 0
  52. Public CONST SBALIGNRIGHT = 2
  53.  
  54. Public Const SBNOBORDER = 0
  55. Public Const SB3DBORDER = 1
  56. Public Const SBSIMPLEBORDER = 2
  57.  
  58. Public CurArrangement as Integer
  59. Public CurBorderType as Integer
  60. Public CurAlignmode as Integer
  61.  
  62. Public OldAlignMode as Integer
  63. Public OldBorderType as Integer
  64. Public OldArrangement as Integer
  65.  
  66. Public Const cColumnarLeft = 1
  67. Public Const cColumnarTop = 2
  68. Public Const cTabled = 3
  69. Public Const cLeftJustified = 4
  70. Public Const cTopJustified = 5
  71.  
  72. Public Const cXOffset = 1000
  73. Public Const cYOffset = 700
  74. ' This is the viewed space that we lose because of the symbol bars
  75. Public Const cSymbolMargin = 2000
  76. Public Const MaxFieldIndex = 200
  77.  
  78. Public Const cControlCollectionCount = 9
  79. Public Const cLabel         = 1
  80. Public Const cTextBox         = 2
  81. Public Const cCheckBox         = 3
  82. Public Const cDateBox         = 4
  83. Public Const cTimeBox         = 5
  84. Public Const cNumericBox     = 6
  85. Public Const cCurrencyBox     = 7
  86. Public Const cGridControl    = 8
  87. Public Const cImageControl    = 9
  88.  
  89. Public Styles(100, 8) as String
  90.  
  91. Public CurControlType as Integer
  92. Public CurFieldlength as Double
  93. Public CurFieldType as Integer
  94. Public CurFieldName as String
  95. Public CurControlName as String
  96. Public CurFormatKey as Long
  97. Public CurDefaultValue
  98. Public CurIsCurrency as Boolean
  99. Public CurScale as Integer
  100. Public CurHelpText as String
  101.  
  102. Public FieldMetaValues(MaxFieldIndex, 8)
  103. ' Description of this List:
  104. '    CurFieldType = FieldMetaValues(Index,0)
  105. '    CurFieldLength = FieldMetaValues(Index,1)
  106. '    CurControlType = FieldMetaValues(Index,2)    (ControlType eg. cLabel, cTextbox usw.)
  107. '    CurControlName = FieldMetaValues(Index,3)
  108. '    CurFormatKey = FieldMetaValues(Index,4)
  109. '    CurDefaultValue = FieldMetaValues(Index,5)
  110. '    CurIsCurrency = FieldMetaValues(Index,6)
  111. '    CurScale = FieldMetaValues(Index,7)
  112. '    CurHelpText = FieldMetaValues(Index,8)
  113.  
  114. Public FieldNames(MaxFieldIndex) as string
  115. Public oModelService(cControlCollectionCount) as String
  116. Public oGridModel as Object
  117.  
  118.  
  119. Function InsertControl(oContainer as Object, oControlObject as object, aPoint as Object, aSize as Object)
  120. Dim oShape as object
  121.     oShape = oDocument.CreateInstance ("com.sun.star.drawing.ControlShape")
  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
  128. End Function
  129.  
  130.  
  131. Function ArrangeControls()
  132. Dim oShape as Object
  133. Dim i as Integer
  134.     oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
  135.     oProgressbar.Start("", MaxIndex)
  136.     If oDBForm.HasbyName("Grid1") 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
  148. End Function
  149.  
  150.  
  151. Sub OpenFormDocument()
  152. Dim NoArgs() as new com.sun.star.beans.PropertyValue
  153. Dim oViewSettings as Object
  154.     oDocument = CreateNewDocument("swriter")
  155.     oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
  156.     oProgressbar.Start("", 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("PageStyles").GetByName("Standard")
  164. End Sub
  165.  
  166.  
  167. Sub    InitializeLabelValues()
  168. Dim oLabelModel as Object
  169. Dim oTBModel as Object
  170. Dim oLabelShape as Object
  171. Dim oTBShape as Object
  172. Dim aTBSize As New com.sun.star.awt.Size
  173. Dim aLabelSize As New com.sun.star.awt.Size
  174. Dim aPoint As New com.sun.star.awt.Point
  175. Dim aSize As New com.sun.star.awt.Size
  176. Dim oLocControl as Object
  177. Dim oLocPeer as Object
  178.     oLabelModel =  CreateUnoService("com.sun.star.form.component.FixedText")
  179.     oTBModel =  CreateUnoService("com.sun.star.form.component.TextField")
  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, "The quick brown fox...")
  188.     nTCHeight = (aLabelSize.Height+1) * YPixelFactor
  189.     aTBSize = GetPeerSize(oTBModel, oLocControl, "The quick brown fox...")
  190.     nDBRefHeight = (aTBSize.Height+1) * YPixelFactor
  191.     BasicLabelDiffHeight = Clng((nDBRefHeight - nTCHeight)/2)
  192.     oDrawPage.Remove(oLabelShape)
  193.     oDrawPage.Remove(oTBShape)
  194. End Sub
  195.  
  196.  
  197. Sub ConfigurePageStyle()
  198. Dim aPageSize As New com.sun.star.awt.Size
  199. Dim 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
  211. End Sub
  212.  
  213.  
  214. ' Modify the Borders of the Controls
  215. Sub ChangeBorderLayouts(oEvent as Object)
  216. Dim oModel as Object
  217. Dim i as Integer
  218. Dim oCurModel as Object
  219. Dim sLocText as String
  220. Dim oGroupShape as Object
  221. Dim 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 <> CurBorderType Then
  232.             For i = 0 To MaxIndex
  233.                 If oDBShapeList(i).SupportsService("com.sun.star.drawing.GroupShape") 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("Border") Then
  240.                         oDBModelList(i).Border = CurBorderType
  241.                     End If
  242.                 End If
  243.             Next i
  244.         End If
  245.     End If
  246.     ToggleLayoutPage(True)
  247. WIZARDERROR:
  248.     If Err <> 0 Then    
  249.         Msgbox(sMsgErrMsg, 16, GetProductName())
  250.         Resume LOCERROR
  251.         LOCERROR:
  252.         DlgFormDB.Dispose()    
  253.     End If
  254. End Sub
  255.  
  256.  
  257. Sub ChangeLabelAlignments(oEvent as Object)
  258. Dim i as Integer
  259. Dim oSize as New com.sun.star.awt.Size
  260. Dim 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 <> 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.  
  280. WIZARDERROR:
  281.     If Err <> 0 Then    
  282.         Msgbox(sMsgErrMsg, 16, GetProductName())
  283.         Resume LOCERROR
  284.         LOCERROR:        
  285.     End If
  286.     ToggleLayoutPage(True)
  287. End Sub
  288.  
  289.  
  290. Sub ChangeArrangemode(oEvent as Object)
  291. Dim 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("cmdArrange" & OldArrangement).Model.State = 0
  299.     If CurArrangement <> OldArrangement Then
  300.         ArrangeControls()
  301.         Select Case CurArrangement
  302.             Case cTabled
  303.                 ToggleBorderGroup(False)
  304.                 ToggleAlignGroup(False)
  305.             Case Else ' 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
  318. WIZARDERROR:
  319.     If Err <> 0 Then    
  320.         Msgbox(sMsgErrMsg, 16, GetProductName())
  321.         Resume LOCERROR
  322.         LOCERROR:        
  323.     End If
  324. End Sub
  325.  
  326.  
  327. Sub    ToggleBorderGroup(bDoEnable as Boolean)
  328.     With DialogModel
  329.         .hlnBorderLayout.Enabled = bDoEnable
  330.         .optBorder0.Enabled = bDoEnable         ' 0: No border
  331.         .optBorder1.Enabled = bDoEnable        ' 1: 3D border
  332.         .optBorder2.Enabled = bDoEnable        ' 2: simple border
  333.     End With
  334. End Sub
  335.  
  336.  
  337. Sub    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
  346. End Sub
  347.  
  348.  
  349. Sub 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    
  366. End Sub
  367.  
  368.  
  369. Sub DestroyControlShapes(oDrawPage as Object)
  370. Dim i as Integer
  371. Dim oShape as Object
  372.     For i = oDrawPage.Count-1 To 0 Step -1
  373.         oShape = oDrawPage.GetByIndex(i)
  374.         If oShape.ShapeType = "com.sun.star.drawing.ControlShape" Then
  375.             oShape.Dispose()
  376.         End If
  377.     Next i
  378. End Sub
  379.  
  380.  
  381. Sub SwitchArrangementButtons(ByVal LocArrangement as Integer)
  382.     OldArrangement = CurArrangement
  383.     CurArrangement = LocArrangement
  384.     If OldArrangement <> 0 Then
  385.         DlgFormDB.GetControl("cmdArrange" & OldArrangement).Model.State = 0
  386.     End If
  387.     DlgFormDB.GetControl("cmdArrange" & CurArrangement).Model.State = 1
  388. End Sub
  389.  
  390.  
  391. Sub SwitchBorderMode(ByVal LocBorderType as Integer)
  392.     OldBorderType = CurBorderType
  393.     CurBorderType = LocBorderType
  394. End Sub
  395.  
  396.  
  397. Sub SwitchAlignMode(ByVal LocAlignMode as Integer)
  398.     OldAlignMode = CurAlignMode
  399.     CurAlignMode = LocAlignMode
  400. End Sub</script:module>
  401.