home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri Kaikille K-CD 2002 #3 / K-CD_2002-03.iso / OpenOffice / f_0018 / Layouter.xba < prev    next >
Extensible Markup Language  |  2001-10-12  |  10KB  |  314 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(oContainer as Object, 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.     oContainer.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.     nPageWidth = nPageHeight
  160.     nPageHeight = oPageStyle.Size.Height
  161.     nFormWidth = nPageWidth - oPageStyle.RightMargin - oPageStyle.LeftMargin - 2 * cXOffset
  162.     nFormHeight = nPageHeight - oPageStyle.TopMargin - oPageStyle.BottomMargin - 2 * cYOffset - cSymbolMargin
  163. End Sub
  164.  
  165.  
  166. ' Modify the Borders of the Controls
  167. Sub ChangeBorderLayouts(oEvent as Object)
  168. Dim oModel as Object
  169. Dim i as Integer
  170. Dim oCurModel as Object
  171. Dim sLocText as String
  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.                 oDBModelList(i).Border = CurBorderType
  185.             Next i
  186.         End If
  187.     End If
  188.     oDocument.UnlockControllers
  189.     ToggleLayoutPage(True)
  190. End Sub
  191.  
  192.  
  193. Sub ChangeLabelAlignments(oEvent as Object)
  194. Dim i as Integer
  195. Dim oModel as Object
  196.     oModel = oEvent.Source.Model
  197.     SwitchAlignMode(Val(Right(oModel.Name,1)))
  198.     ToggleLayoutPage(False)
  199.     oDocument.LockControllers()
  200.     If OldAlignMode <> CurAlignMode Then
  201.         For i = 0 To MaxIndex
  202.             oTCShapeList(i).GetControl.Align = CurAlignmode
  203.         Next i
  204.     End If
  205.     oDocument.UnlockControllers()
  206.     ToggleLayoutPage(True)
  207. End Sub
  208.  
  209.  
  210. Sub ChangeArrangemode(oEvent as Object)
  211. Dim oModel as Object
  212.     oModel = oEvent.Source.Model
  213.     SwitchArrangementButtons(Val(Right(oModel.Name,1)))
  214.     oModel.State = 1
  215.     DlgFormDB.GetControl("cmdArrange" & OldArrangement).Model.State = 0
  216.     If CurArrangement <> OldArrangement Then
  217.         ArrangeControls()
  218.         Select Case CurArrangement
  219.             Case cTabled
  220.                 ToggleBorderGroup(False)
  221.                 ToggleAlignGroup(False)
  222.             Case Else ' cColumnarTop,cLeftJustified, cTopJustified
  223.                 ToggleAlignGroup(CurArrangement = cColumnarLeft)
  224.                 If CurArrangement = cColumnarTop Then
  225.                     If CurAlignMode = com.sun.star.awt.TextAlign.RIGHT Then
  226.                         oDialogModel.optAlign0.State = 1
  227.                         CurAlignMode = com.sun.star.awt.TextAlign.LEFT
  228.                         OldAlignMode = com.sun.star.awt.TextAlign.RIGHT
  229.                     End If
  230.                 End If
  231.                 ControlCaptionstoStandardLayout()
  232.                 oDBForm.Load
  233.         End Select
  234.     End If
  235. End Sub
  236.  
  237.  
  238. Sub    ToggleBorderGroup(bDoEnable as Boolean)
  239.     With oDialogModel
  240.         .hlnBorderLayout.Enabled = bDoEnable
  241.         .optBorder0.Enabled = bDoEnable         ' 0: No border
  242.         .optBorder1.Enabled = bDoEnable        ' 1: 3D border
  243.         .optBorder2.Enabled = bDoEnable        ' 2: simple border
  244.     End With
  245. End Sub
  246.  
  247.  
  248. Sub    ToggleAlignGroup(ByVal bDoEnable as Boolean)
  249.     With oDialogModel
  250.         If bDoEnable Then
  251.             bDoEnable = CurArrangement = cColumnarLeft
  252.         End If
  253.         .hlnAlign.Enabled = bDoEnable
  254.         .optAlign0.Enabled = bDoEnable
  255.         .optAlign2.Enabled = bDoEnable
  256.     End With
  257. End Sub
  258.  
  259.  
  260. Sub ToggleLayoutPage(bDoEnable as Boolean, Optional FocusControlName as String)
  261.     With oDialogModel
  262.         .hlnArrangements.Enabled = bDoEnable
  263.         .cmdArrange1.Enabled = bDoEnable
  264.         .cmdArrange2.Enabled = bDoEnable
  265.         .cmdArrange3.Enabled = bDoEnable
  266.         .cmdArrange4.Enabled = bDoEnable
  267.         .cmdArrange5.Enabled = bDoEnable
  268.         .lstStyles.Enabled = bDoEnable
  269.         .lblStyles.Enabled = bDoEnable
  270.         .cmdHelp.Enabled = bDoEnable
  271.         .cmdBack.Enabled = bDoEnable
  272.         .cmdGoOn.Enabled = bDoEnable
  273.         If Not IsMissing(FocusControlName) Then
  274.             DlgFormDB.GetControl(FocusControlName).SetFocus()
  275.         End If
  276.     End With
  277.     ToggleOptionButtons(oDialogModel,((bWithBackGraphic = True) AND (bDoEnable = True)))
  278.     ToggleAlignGroup(bDoEnable)
  279.     ToggleBorderGroup(bDoEnable)
  280. End Sub
  281.  
  282.  
  283. Sub DestroyControlShapes(oDrawPage as Object)
  284. Dim i as Integer
  285. Dim oShape as Object
  286.     For i = oDrawPage.Count-1 To 0 Step -1
  287.         oShape = oDrawPage.GetByIndex(i)
  288.         If oShape.ShapeType = "com.sun.star.drawing.ControlShape" Then
  289.             oShape.Dispose
  290.         End If
  291.     Next i
  292. End Sub
  293.  
  294.  
  295. Sub SwitchArrangementButtons(ByVal LocArrangement as Integer)
  296.     OldArrangement = CurArrangement
  297.     CurArrangement = LocArrangement
  298.     If OldArrangement <> 0 Then
  299.         DlgFormDB.GetControl("cmdArrange" & OldArrangement).Model.State = 0
  300.     End If
  301.     DlgFormDB.GetControl("cmdArrange" & CurArrangement).Model.State = 1
  302. End Sub
  303.  
  304.  
  305. Sub SwitchBorderMode(ByVal LocBorderType as Integer)
  306.     OldBorderType = CurBorderType
  307.     CurBorderType = LocBorderType
  308. End Sub
  309.  
  310.  
  311. Sub SwitchAlignMode(ByVal LocAlignMode as Integer)
  312.     OldAlignMode = CurAlignMode
  313.     CurAlignMode = LocAlignMode
  314. End Sub</script:module>