home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2002 November / VPR0211A.ISO / OPENOFFICE / f_0138 / Layouter.xba < prev    next >
Extensible Markup Language  |  2001-12-18  |  12KB  |  383 lines

  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.  
  5. Public oProgressbar as Object
  6. Public ProgressValue as Integer
  7. Public oDocument as Object
  8. Public oController as Object
  9. Public oForm as Object
  10. Public oDrawPage as Object
  11. Public oPageStyle as Object
  12.  
  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
  20.  
  21. Public Const cVertDistance = 200
  22. Public Const cHoriDistance = 300
  23.  
  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
  30.  
  31. Public CONST SBALIGNLEFT = 0
  32. Public CONST SBALIGNRIGHT = 2
  33.  
  34. Public Const SBNOBORDER = 0
  35. Public Const SB3DBORDER = 1
  36. Public Const SBSIMPLEBORDER = 2
  37.  
  38. Public CurArrangement as Integer
  39. Public CurBorderType as Integer
  40. Public CurAlignmode as Integer
  41.  
  42. Public OldAlignMode as Integer
  43. Public OldBorderType as Integer
  44. Public OldArrangement as Integer
  45.  
  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
  51.  
  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
  57.    
  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
  68.  
  69. Public Styles(8, 50) as String
  70.  
  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
  81.  
  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)
  93.  
  94. Public FieldNames(MaxFieldIndex) as string
  95. Public oModelService(cControlCollectionCount) as String
  96. Public oGridModel as Object
  97.  
  98.  
  99. Function InsertControl(oContainer as Object, oControlObject as object, aPoint as Object, aSize as Object)
  100. Dim oShape as object
  101.     oShape = oDocument.CreateInstance ("com.sun.star.drawing.ControlShape")
  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
  108. End Function
  109.  
  110.  
  111. Function ArrangeControls()
  112. Dim oShape as Object
  113. Dim i as Integer
  114.     oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
  115.     oProgressbar.Start("", MaxIndex)
  116.     If oDBForm.HasbyName("Grid1") Then
  117.         RemoveShapes()
  118. '        PrintdbgInfo oDBForm.GetByName("Grid1")
  119. '        oDBForm.GetByName("Grid1").Dispose
  120.     End If
  121.     ToggleLayoutPage(False)
  122.     Select Case CurArrangement
  123.         Case cTabled
  124.             PositionGridControl(MaxIndex)
  125.         Case Else
  126.             PositionControls(MaxIndex)
  127.     End Select
  128.     ToggleLayoutPage(True)
  129.     oProgressbar.End
  130. End Function
  131.  
  132.  
  133. Sub OpenFormDocument()
  134. Dim NoArgs() as new com.sun.star.beans.PropertyValue
  135. Dim oViewSettings as Object
  136.     oDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter", "_blank", 0, NoArgs())
  137.     oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
  138.     oProgressbar.Start("", 100)
  139.     oDocument.ApplyFormDesignMode = False
  140.     oController = oDocument.GetCurrentController
  141.     oViewSettings = oDocument.CurrentController.ViewSettings
  142.     oViewSettings.ShowTableBoundaries = False
  143.     oViewSettings.ShowTextBoundaries = False
  144.     oViewSettings.ShowOnlineLayout = True
  145. '    oViewSettings.ShowHoriRuler = True
  146.     oDrawPage = oDocument.DrawPage
  147.     oPageStyle = oDocument.StyleFamilies.GetByName("PageStyles").GetByName("Standard")
  148. End Sub
  149.  
  150.  
  151. Sub    InitializeLabelValues()
  152. Dim oLabelModel as Object
  153. Dim oTBModel as Object
  154. Dim oLabelShape as Object
  155. Dim oTBShape as Object
  156. Dim aTBSize As New com.sun.star.awt.Size
  157. Dim aLabelSize As New com.sun.star.awt.Size
  158. Dim aPoint As New com.sun.star.awt.Point
  159. Dim oLocControl as Object
  160. Dim oLocPeer as Object
  161.     oLabelModel =  CreateUnoService("com.sun.star.form.component.FixedText")
  162.     oTBModel =  CreateUnoService("com.sun.star.form.component.TextField")
  163.  
  164.     Set oLabelShape = InsertControl(oDrawPage, oLabelModel, aPoint, aSize)
  165.     Set oTBShape = InsertControl(oDrawPage, oTBModel, aPoint, aSize)
  166.  
  167.     oLocPeer = oController.GetControl(oLabelModel).Peer
  168.     XPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterX
  169.     YPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterY
  170.     aLabelSize = GetPeerSize(oLabelModel, oLocControl, "The quick brown fox...")
  171.     nTCHeight = (aLabelSize.Height+1) * YPixelFactor
  172.     aTBSize = GetPeerSize(oTBModel, oLocControl, "The quick brown fox...")
  173.     nDBRefHeight = (aTBSize.Height+1) * YPixelFactor
  174.     BasicLabelDiffHeight = Clng((nDBRefHeight - nTCHeight)/2)
  175.     oDrawPage.Remove(oLabelShape)
  176.     oDrawPage.Remove(oTBShape)
  177. End Sub
  178.  
  179.  
  180. Sub ConfigurePageStyle()
  181. Dim aPageSize As New com.sun.star.awt.Size
  182. Dim aSize As New com.sun.star.awt.Size
  183.     oPageStyle.IsLandscape = True
  184.     aPageSize = oPageStyle.Size
  185.     nPageWidth = aPageSize.Width
  186.     nPageHeight = aPageSize.Height
  187.     aSize.Width = nPageHeight
  188.     aSize.Height = nPageWidth
  189.     oPageStyle.Size = aSize
  190.     nPageWidth = nPageHeight
  191.     nPageHeight = oPageStyle.Size.Height
  192.     nFormWidth = nPageWidth - oPageStyle.RightMargin - oPageStyle.LeftMargin - 2 * cXOffset
  193.     nFormHeight = nPageHeight - oPageStyle.TopMargin - oPageStyle.BottomMargin - 2 * cYOffset - cSymbolMargin
  194. End Sub
  195.  
  196.  
  197. ' Modify the Borders of the Controls
  198. Sub ChangeBorderLayouts(oEvent as Object)
  199. Dim oModel as Object
  200. Dim i as Integer
  201. Dim oCurModel as Object
  202. Dim sLocText as String
  203. Dim oGroupShape as Object
  204. Dim s as Integer
  205.     If Not bDebug Then
  206.         On Local Error GoTo WIZARDERROR
  207.     End If
  208.     oModel = oEvent.Source.Model
  209.     SwitchBorderMode(Val(Right(oModel.Name,1)))
  210.     ToggleLayoutPage(False)
  211.     If CurArrangement = cTabled Then
  212.         oGridModel.Border = CurBorderType
  213.     Else
  214.         If OldBorderType <> CurBorderType Then
  215.             For i = 0 To MaxIndex
  216.                 If oDBShapeList(i).SupportsService("com.sun.star.drawing.GroupShape") Then
  217.                     oGroupShape = oDBShapeList(i)
  218.                     For s = 0 To oGroupShape.Count-1
  219.                         oGroupShape(s).Control.Border = CurBorderType
  220.                     Next s
  221.                 Else
  222.                     If oDBModelList(i).PropertySetInfo.HasPropertyByName("Border") Then
  223.                         oDBModelList(i).Border = CurBorderType
  224.                     End If
  225.                 End If
  226.             Next i
  227.         End If
  228.     End If
  229.     ToggleLayoutPage(True)
  230. WIZARDERROR:
  231.     If Err <> 0 Then    
  232.         Msgbox(sMsgErrMsg, 16, GetProductName())
  233.         Resume LOCERROR
  234.         LOCERROR:
  235.         DlgFormDB.Dispose()    
  236.     End If
  237. End Sub
  238.  
  239.  
  240. Sub ChangeLabelAlignments(oEvent as Object)
  241. Dim i as Integer
  242. Dim oSize as New com.sun.star.awt.Size
  243. Dim oModel as Object
  244.     If Not bDebug Then
  245.         On Local Error GoTo WIZARDERROR
  246.     End If
  247.     oModel = oEvent.Source.Model
  248.     SwitchAlignMode(Val(Right(oModel.Name,1)))
  249.     ToggleLayoutPage(False)
  250.     If OldAlignMode <> CurAlignMode Then
  251.         For i = 0 To MaxIndex
  252.             oTCShapeList(i).GetControl.Align = CurAlignmode
  253.         Next i
  254.     End If
  255.     If CurAlignmode = com.sun.star.awt.TextAlign.RIGHT Then
  256.         For i = 0 To Ubound(oTCShapeList())
  257.             oSize = oTCShapeList(i).Size
  258.             oSize.Width = oDBShapeList(i).Position.X - oTCShapeList(i).Position.X - cHoriDistance
  259.             oTCShapeList(i).Size = oSize
  260.         Next i
  261.     End If
  262.  
  263. WIZARDERROR:
  264.     If Err <> 0 Then    
  265.         Msgbox(sMsgErrMsg, 16, GetProductName())
  266.         Resume LOCERROR
  267.         LOCERROR:        
  268.     End If
  269.     ToggleLayoutPage(True)
  270. End Sub
  271.  
  272.  
  273. Sub ChangeArrangemode(oEvent as Object)
  274. Dim oModel as Object
  275.     If Not bDebug Then
  276.         On Local Error GoTo WIZARDERROR
  277.     End If
  278.     oModel = oEvent.Source.Model
  279.     SwitchArrangementButtons(Val(Right(oModel.Name,1)))
  280.     oModel.State = 1
  281.     DlgFormDB.GetControl("cmdArrange" & OldArrangement).Model.State = 0
  282.     If CurArrangement <> OldArrangement Then
  283.         ArrangeControls()
  284.         Select Case CurArrangement
  285.             Case cTabled
  286.                 ToggleBorderGroup(False)
  287.                 ToggleAlignGroup(False)
  288.             Case Else ' cColumnarTop,cLeftJustified, cTopJustified
  289.                 ToggleAlignGroup(CurArrangement = cColumnarLeft)
  290.                 If CurArrangement = cColumnarTop Then
  291.                     If CurAlignMode = com.sun.star.awt.TextAlign.RIGHT Then
  292.                         oDialogModel.optAlign0.State = 1
  293.                         CurAlignMode = com.sun.star.awt.TextAlign.LEFT
  294.                         OldAlignMode = com.sun.star.awt.TextAlign.RIGHT
  295.                     End If
  296.                 End If
  297.                 ControlCaptionstoStandardLayout()
  298.                 oDBForm.Load
  299.         End Select
  300.     End If
  301. WIZARDERROR:
  302.     If Err <> 0 Then    
  303.         Msgbox(sMsgErrMsg, 16, GetProductName())
  304.         Resume LOCERROR
  305.         LOCERROR:        
  306.     End If
  307. End Sub
  308.  
  309.  
  310. Sub    ToggleBorderGroup(bDoEnable as Boolean)
  311.     With oDialogModel
  312.         .hlnBorderLayout.Enabled = bDoEnable
  313.         .optBorder0.Enabled = bDoEnable         ' 0: No border
  314.         .optBorder1.Enabled = bDoEnable        ' 1: 3D border
  315.         .optBorder2.Enabled = bDoEnable        ' 2: simple border
  316.     End With
  317. End Sub
  318.  
  319.  
  320. Sub    ToggleAlignGroup(ByVal bDoEnable as Boolean)
  321.     With oDialogModel
  322.         If bDoEnable Then
  323.             bDoEnable = CurArrangement = cColumnarLeft
  324.         End If
  325.         .hlnAlign.Enabled = bDoEnable
  326.         .optAlign0.Enabled = bDoEnable
  327.         .optAlign2.Enabled = bDoEnable
  328.     End With
  329. End Sub
  330.  
  331.  
  332. Sub ToggleLayoutPage(bDoEnable as Boolean, Optional FocusControlName as String)
  333.     oDialogModel.Enabled = bDoEnable
  334.     If bDoEnable Then
  335.         If Not bDebug Then
  336.             oDocument.UnlockControllers()
  337.         End If
  338.         ToggleOptionButtons(oDialogModel,(bWithBackGraphic = True))
  339.         ToggleAlignGroup(bDoEnable)
  340.         ToggleBorderGroup(bDoEnable)
  341.     Else
  342.         If Not bDebug Then
  343.             oDocument.LockControllers()    
  344.         End If
  345.     End If
  346.     If Not IsMissing(FocusControlName) Then
  347.         DlgFormDB.GetControl(FocusControlName).SetFocus()
  348.     End If    
  349. End Sub
  350.  
  351.  
  352. Sub DestroyControlShapes(oDrawPage as Object)
  353. Dim i as Integer
  354. Dim oShape as Object
  355.     For i = oDrawPage.Count-1 To 0 Step -1
  356.         oShape = oDrawPage.GetByIndex(i)
  357.         If oShape.ShapeType = "com.sun.star.drawing.ControlShape" Then
  358.             oShape.Dispose()
  359.         End If
  360.     Next i
  361. End Sub
  362.  
  363.  
  364. Sub SwitchArrangementButtons(ByVal LocArrangement as Integer)
  365.     OldArrangement = CurArrangement
  366.     CurArrangement = LocArrangement
  367.     If OldArrangement <> 0 Then
  368.         DlgFormDB.GetControl("cmdArrange" & OldArrangement).Model.State = 0
  369.     End If
  370.     DlgFormDB.GetControl("cmdArrange" & CurArrangement).Model.State = 1
  371. End Sub
  372.  
  373.  
  374. Sub SwitchBorderMode(ByVal LocBorderType as Integer)
  375.     OldBorderType = CurBorderType
  376.     CurBorderType = LocBorderType
  377. End Sub
  378.  
  379.  
  380. Sub SwitchAlignMode(ByVal LocAlignMode as Integer)
  381.     OldAlignMode = CurAlignMode
  382.     CurAlignMode = LocAlignMode
  383. End Sub</script:module>