home *** CD-ROM | disk | FTP | other *** search
/ com!online 2001 December / COMCD1201.iso / openoffice / f_0020 / Layouter.xba < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-21  |  9.8 KB  |  322 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. ' Todo: Testplan: ImageControl an erster Stelle im Array der Feldnamen
  6. ' Todo: Durchtesten mit allen m├╢glichen Datentypen in allen m├╢glichen Konstellationen
  7. '         Was passiert, wenn Felder jenseits der R├ñnder positioniert werden?
  8. ' Todo: Die ObjektArrays oDBShapeList() und oTCShaplist k├╢nnten 3-Dimensional sein mit dem Model und dem Control 
  9. ' in den anderen beiden Dimensionen
  10.  
  11. Public oProgressbar as Object
  12. Public ProgressValue as Integer
  13. Public oDocument as Object
  14. Public oController as Object
  15. Public oForm as Object
  16. Public oDrawPage as Object
  17. Public oPageStyle as Object
  18.  
  19. Public nMaxColRightX as Long
  20. Public nMaxTCWidth as Long
  21. Public nMaxRowRightX as Long
  22. Public nMaxRowY as Long
  23. Public nSecMaxRowY as Long
  24. Public MaxIndex as Integer
  25. Public Const cVertDistance = 200
  26. Public Const cHoriDistance = 300
  27.  
  28. Public nPageWidth as Long
  29. Public nPageHeight as Long
  30. Public nFormWidth as Long
  31. Public nFormHeight as Long
  32. Public nMaxHoriPos as Long
  33. Public nMaxVertPos as Long
  34.  
  35. Public CONST SBALIGNLEFT = 0
  36. Public CONST SBALIGNRIGHT = 2
  37.  
  38. Public Const SBNOBORDER = 0
  39. Public Const SB3DBORDER = 1
  40. Public Const SBSIMPLEBORDER = 2
  41.  
  42. Public CurArrangement as Integer
  43. Public CurBorderType as Integer
  44. Public CurAlignmode as Integer
  45.  
  46. Public OldAlignMode as Integer
  47. Public OldBorderType as Integer
  48. Public OldArrangement as Integer
  49.  
  50. Public Const cColumnarLeft = 1
  51. Public Const cColumnarTop = 2
  52. Public Const cTabled = 3
  53. Public Const cLeftJustified = 4
  54. Public Const cTopJustified = 5
  55.  
  56. Public Const cXOffset = 1000
  57. Public Const cYOffset = 700
  58. ' This is the viewed space that we lose because of the symbol bars
  59. Public Const cSymbolMargin = 2000
  60. Public Const MaxFieldIndex% = 200
  61.    
  62. Public Const cControlCollectionCount = 9
  63. Public Const cLabel         = 1
  64. Public Const cTextBox         = 2
  65. Public Const cCheckBox         = 3
  66. Public Const cDateBox         = 4
  67. Public Const cTimeBox         = 5
  68. Public Const cNumericBox     = 6
  69. Public Const cCurrencyBox     = 7
  70. Public Const cGridControl    = 8
  71. Public Const cImageControl    = 9
  72.  
  73. Public Styles(8, 50) as String
  74. Public FieldMetaValues(MaxFieldIndex,3)
  75. ' Description of this List:
  76. ' FieldMetaValues(0-MaxFieldIndex,0) (Datafieldtype)
  77. ' FieldMetaValues(0-MaxFieldIndex,1) (Datafieldlength)
  78. ' FieldMetaValues(0-MaxFieldIndex,2) (ControlType eg. cLabel, cTextbox usw.)
  79.  
  80. Public FieldNames(MaxFieldIndex) as string
  81. Public oModelService(cControlCollectionCount) as String
  82. Public oGridModel as Object
  83.  
  84. ' field label postfix (the label ist the data source followed by a postfix)
  85. Public nFieldPostfixes (MaxFieldIndex%) as string
  86.  
  87.  
  88. Function InsertControl (oControlObject as object, aPoint as Object, aSize as Object)
  89. Dim oShape as object
  90.     oShape = oDocument.CreateInstance ("com.sun.star.drawing.ControlShape")
  91.     oShape.Size = aSize
  92.     oShape.Position = aPoint
  93.     oShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
  94.     oShape.control = oControlObject
  95.     oDrawPage.Add (oShape)
  96.     InsertControl = oShape
  97. End Function
  98.  
  99.  
  100. Function ArrangeControls()
  101. Dim oShape as Object
  102. Dim i as Integer
  103. ' Todo: Was haben diese Postfixes zu bedeuten?
  104. '    nFieldPostfixes() = nFldLabelPostfixes$()
  105.     oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
  106.     oProgressbar.Start("", MaxIndex)
  107.     If oDBForm.HasbyName("Grid1") Then
  108.         oGridshape.Dispose
  109.     End If
  110.     ToggleLayoutPage(False)
  111.     Select Case CurArrangement
  112.         Case cTabled
  113.             PositionGridControl(MaxIndex)
  114.         Case Else
  115.             oDocument.LockControllers()
  116.             PositionControls(MaxIndex)
  117.             oDocument.UnlockControllers()
  118.     End Select
  119.     ToggleLayoutPage(True)
  120.     oProgressbar.End
  121.     Exit Function
  122.  
  123. ErrorAndCloseForm:
  124.     ToggleWindow(True)
  125.     MsgBox(sMsgErrMsg, 16, sMsgWizardName)
  126.     oDocument.Dispose()
  127.     Stop
  128.     exit Function
  129. End Function
  130.  
  131.  
  132. Sub OpenFormDocument()
  133. Dim NoArgs() as new com.sun.star.beans.PropertyValue
  134. Dim oViewSettings as Object
  135.     oDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter", "_blank", 0, NoArgs())
  136.     oDocument.ApplyFormDesignMode = False
  137.     oController = oDocument.GetCurrentController
  138.     oViewSettings = oDocument.CurrentController.ViewSettings
  139.     oViewSettings.ShowTableBoundaries = False
  140. ' Todo: Im Auge behalten, ob die Viewsettings auch mit abgespeichert werden
  141.     oViewSettings.ShowTextBoundaries = False
  142.     oViewSettings.ShowOnlineLayout = True
  143.     oViewSettings.ShowHoriRuler = True
  144.     oDrawPage = oDocument.DrawPage
  145.     oPageStyle = oDocument.StyleFamilies.GetByName("PageStyles").GetByName("Standard")
  146. End Sub
  147.  
  148.  
  149. Sub ConfigurePageStyle()
  150. Dim aPageSize As New com.sun.star.awt.Size
  151. Dim aSize As New com.sun.star.awt.Size
  152.     oPageStyle.IsLandscape = True
  153.     aPageSize = oPageStyle.Size
  154.     nPageWidth = aPageSize.Width
  155.     nPageHeight = aPageSize.Height
  156.     aSize.Width = nPageHeight
  157.     aSize.Height = nPageWidth
  158.     oPageStyle.Size = aSize
  159.  
  160.     nPageWidth = nPageHeight
  161.     nPageHeight = oPageStyle.Size.Height
  162.     nFormWidth = nPageWidth - oPageStyle.RightMargin - oPageStyle.LeftMargin - 2 * cXOffset
  163.     nFormHeight = nPageHeight - oPageStyle.TopMargin - oPageStyle.BottomMargin - 2 * cYOffset - cSymbolMargin
  164. End Sub
  165.  
  166.  
  167. ' Modify the Borders of the Controls
  168. Sub ChangeBorderLayouts(oEvent as Object)
  169. Dim oModel as Object
  170. Dim i as Integer
  171. Dim oCurModel as Object
  172.     oModel = oEvent.Source.Model
  173.     SwitchBorderMode(Val(Right(oModel.Name,1)))    
  174.     ToggleLayoutPage(False)
  175.     oDocument.LockControllers
  176.  
  177. ' Todo: Auch unsichtbare Controls m├╝ssen eine neue Border bekommen
  178. ' Am besten wird hierbei das dynamische Array oDBShapeList() abgegriffen
  179.     If CurArrangement = cTabled Then
  180.         oGridModel.Border = CurBorderType
  181.     Else
  182.         If OldBorderType <> CurBorderType Then
  183.             For i = 0 To MaxIndex
  184.                 oCurModel = oDBShapeList(i).GetControl
  185.                 If oCurModel.PropertySetInfo.HasPropertyByName("Border")Then
  186.                     oCurModel.Border = CurBorderType
  187.                 End If
  188.             Next i
  189.         End If
  190.     End If
  191.     oDocument.UnlockControllers
  192.     ToggleLayoutPage(True)
  193. End Sub
  194.  
  195.  
  196. Sub ChangeLabelAlignments(oEvent as Object)
  197. Dim i as Integer
  198. Dim oCurModel as Object
  199. Dim oModel as Object
  200.     oModel = oEvent.Source.Model
  201.     SwitchAlignMode(Val(Right(oModel.Name,1)))
  202.     ToggleLayoutPage(False)
  203.     oDocument.LockControllers()
  204.     If OldAlignMode <> CurAlignMode Then
  205.         For i = 0 To MaxIndex
  206.             oCurModel = oTCShapeList(i).GetControl
  207.             oCurModel.Align = CurAlignmode
  208.         Next i
  209.     End If
  210.     oDocument.UnlockControllers()
  211.     ToggleLayoutPage(True)
  212. End Sub
  213.  
  214.  
  215. Sub ChangeArrangemode(oEvent as Object)
  216. Dim oModel as Object
  217.     oModel = oEvent.Source.Model
  218.     SwitchArrangementButtons(Val(Right(oModel.Name,1)))
  219.     oModel.State = 1
  220.     DlgFormDB.GetControl("cmdArrange" & OldArrangement).Model.State = 0
  221.     If CurArrangement <> OldArrangement Then
  222.         ArrangeControls()
  223.         Select Case CurArrangement
  224.             Case cTabled
  225.                 ToggleBorderGroup(False)
  226.                 ToggleAlignGroup(False)
  227.             Case Else ' cColumnarTop,cLeftJustified, cTopJustified
  228.                 ToggleAlignGroup(CurArrangement = cColumnarLeft)
  229.                 If CurArrangement = cColumnarTop Then
  230.                     If CurAlignMode = com.sun.star.awt.TextAlign.RIGHT Then
  231.                         oDialogModel.optAlign0.State = 1
  232.                         CurAlignMode = com.sun.star.awt.TextAlign.LEFT
  233.                         OldAlignMode = com.sun.star.awt.TextAlign.RIGHT
  234.                     End If
  235.                 End If
  236.                 ControlCaptionstoStandardLayout()
  237.                 oDBForm.Load
  238.         End Select
  239.     End If
  240. End Sub
  241.  
  242.  
  243. Sub    ToggleBorderGroup(bDoEnable as Boolean)
  244.     With oDialogModel
  245.         .hlnBorderLayout.Enabled = bDoEnable
  246.         .optBorder0.Enabled = bDoEnable         ' 0: No border
  247.         .optBorder1.Enabled = bDoEnable        ' 1: 3D border
  248.         .optBorder2.Enabled = bDoEnable        ' 2: simple border
  249.     End With
  250. End Sub
  251.  
  252.  
  253. Sub    ToggleAlignGroup(ByVal bDoEnable as Boolean)
  254.     With oDialogModel
  255.         If bDoEnable Then
  256.             bDoEnable = CurArrangement <> cTabled
  257.         End If
  258.         .hlnAlign.Enabled = bDoEnable
  259.         .optAlign0.Enabled = bDoEnable
  260.         .optAlign2.Enabled = bDoEnable            '
  261.     End With
  262. End Sub
  263.  
  264.  
  265. Sub ToggleLayoutPage(bDoEnable as Boolean)
  266.     With oDialogModel
  267.         .hlnArrangements.Enabled = bDoEnable
  268.         .cmdArrange1.Enabled = bDoEnable
  269.         .cmdArrange2.Enabled = bDoEnable
  270.         .cmdArrange3.Enabled = bDoEnable
  271.         .cmdArrange4.Enabled = bDoEnable
  272.         .cmdArrange5.Enabled = bDoEnable
  273.         .lstStyles.Enabled = bDoEnable
  274.         .lblStyles.Enabled = bDoEnable
  275.         .hlnBackground.Enabled = bDoEnable
  276.         .optTiled.Enabled = bDoEnable
  277.         .optArea.Enabled = bDoEnable
  278.         .cmdHelp.Enabled = bDoEnable
  279.         .cmdBack.Enabled = bDoEnable
  280.         .cmdGoOn.Enabled = bDoEnable
  281. '        If DlgFormDB.GetControl("imgTheme").Visible Then
  282. '            .imgTheme.Enabled = bDoEnable
  283. '        End If
  284.     End With
  285.     ToggleAlignGroup(bDoEnable)
  286.     ToggleBorderGroup(bDoEnable)
  287. End Sub
  288.  
  289.  
  290. Sub DestroyControlShapes(oDrawPage as Object)
  291. Dim i as Integer
  292. Dim oShape as Object
  293.     For i = oDrawPage.Count-1 To 0 Step -1
  294.         oShape = oDrawPage.GetByIndex(i)
  295.         If oShape.ShapeType = "com.sun.star.drawing.ControlShape" Then
  296.             oShape.Dispose
  297.         End If
  298.     Next i
  299. End Sub
  300.  
  301.  
  302. Sub SwitchArrangementButtons(ByVal LocArrangement as Integer)
  303.     OldArrangement = CurArrangement
  304.     CurArrangement = LocArrangement
  305.     If OldArrangement <> 0 Then
  306.         DlgFormDB.GetControl("cmdArrange" & OldArrangement).Model.State = 0
  307.     End If
  308.     DlgFormDB.GetControl("cmdArrange" & CurArrangement).Model.State = 1
  309. End Sub
  310.  
  311.  
  312. Sub SwitchBorderMode(ByVal LocBorderType as Integer)
  313.     OldBorderType = CurBorderType
  314.     CurBorderType = LocBorderType
  315. End Sub
  316.  
  317.  
  318. Sub SwitchAlignMode(ByVal LocAlignMode as Integer)
  319.     OldAlignMode = CurAlignMode
  320.     CurAlignMode = LocAlignMode
  321. End Sub
  322. </script:module>