home *** CD-ROM | disk | FTP | other *** search
/ com!online 2001 December / COMCD1201.iso / openoffice / f_0020 / develop.xba < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-24  |  15.8 KB  |  494 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="develop" script:language="StarBasic">REM  *****  BASIC  *****
  4. Option Explicit
  5.  
  6. Public oDBShapeList() as Object
  7. Public oTCShapeList() as Object
  8. Public oGridShape as Object
  9. Public a as Integer
  10. Public StartA as Integer
  11. Public bIsFirstRun as Boolean
  12. Public bIsVeryFirstRun as Boolean
  13.  
  14. Public bIsVeryFirstValueField as Boolean
  15. ' This boolean variable refers to the following Controltypes: cTextBox, cCheckBox, cDateBox, cTimeBox, cNumericBox, cCurrencyBox
  16.  
  17. Public bControlsareCreated as Boolean
  18. Public nDBRefWidth as Long
  19. Public nDBRefHeight as Long
  20. Public nXTCPos&, nYTCPos&, nXDBPos&, nYDBPos&, nTCHeight&, nTCWidth&, nDBHeight&, nDBWidth&
  21. Public CurControlType as Integer
  22. Public CurFieldlength as Double
  23. Public CurFieldType as Integer
  24. Public CurFieldName as String
  25. Public CurControlName as String
  26. Dim iReduceWidth as Integer
  27.  
  28. Function PositionControls(Maxindex as Integer)
  29. Dim oTCModel as Object
  30. Dim oDBModel as Object
  31. Dim i as Integer
  32.     InitializePosSizes()
  33.     bIsFirstRun = True
  34.     bIsVeryFirstRun = True
  35.     bIsVeryFirstValueField = True
  36.     a = 0
  37.     StartA = 0
  38.     nMaxRowY = 0
  39.     nSecMaxRowY = 0
  40.     For i = 0 To MaxIndex
  41.         CurFieldType = FieldMetaValues(i,0)
  42.         CurFieldLength = CDbl(FieldMetaValues(i,1))
  43.         CurControlType = FieldMetaValues(i,2)
  44.         CurControlName = FieldMetaValues(i,3)
  45.         CurFieldName = FieldNames(i)
  46.         oTCModel = InsertTextControl(i)
  47.         InsertDBControl(oDBModel, i)
  48.         bIsVeryFirstRun = False
  49.         oDBModel.LabelControl = oTCModel
  50.         ResetPosSizes(i)
  51.         oProgressbar.Value = i
  52.     Next i
  53.     ControlCaptionstoStandardLayout()
  54.     bControlsareCreated = True
  55. End Function
  56.  
  57.  
  58. Sub ResetPosSizes(LastIndex as Integer)
  59.     Select Case CurArrangement
  60.         Case cColumnarLeft
  61.             nYDBPos = nYDBPos  + nDBHeight + cVertDistance
  62.             If (nYDBPos > cYOffset + nFormHeight) Or (LastIndex = MaxIndex) Then
  63.                 RepositionColumnarLeftControls(LastIndex)
  64.                 nXTCPos = nMaxColRightX + 2 * cHoriDistance
  65.                 nXDBPos = nXTCPos + cHoriDistance + nMaxTCWidth
  66.                 nYDBPos = cYOffset
  67.                 nYTCPos = cYOffset
  68.                 bIsFirstRun = True
  69.                 StartA = LastIndex + 1
  70.                 a = 0
  71.             Else
  72.                 a = a + 1
  73.             End If
  74.             nYTCPos = nYDBPos
  75.         Case cColumnarTop
  76.             nYTCPos = nYDBPos + nDBHeight + cVertDistance
  77.             If nYTCPos > cYOffset + nFormHeight Then
  78.                 nXDBPos = nMaxColRightX + cHoriDistance
  79.                 nXTCPos = nMaxColRightX + cHoriDistance
  80.                 nYDBPos = cYOffset + nTCHeight + cVertDistance
  81.                 nYTCPos = cYOffset
  82.                 bIsFirstRun = True
  83.                 StartA = LastIndex + 1
  84.                 a = 0
  85.             Else
  86.                 a = a + 1
  87.             End If
  88.         Case cLeftJustified,cTopJustified
  89. ' Todo: Ber├╝cksichtigen, wenn das Label eines Controls l├ñnger als das DB-Control ist
  90.             If nMaxColRightX > cXOffset + nFormWidth Then
  91.                 Dim nOldYTCPos as Long
  92.                 nOldYTCPos = nYTCPos
  93.                 CheckJustifiedPosition()
  94.             Else
  95.                 nXTCPos = nMaxColRightX + CHoriDistance
  96.             End If
  97.             a = a + 1                
  98.     End Select
  99. End Sub
  100.  
  101.  
  102. Sub    RepositionColumnarLeftControls(LastIndex as Integer)
  103. Dim aSize As New com.sun.star.awt.Size
  104. Dim aPoint As New com.sun.star.awt.Point
  105. Dim i as Integer
  106. Dim oLocTextShape as Object
  107. Dim oLocDBShape as Object
  108.     aSize = GetSize(nMaxTCWidth, nTCHeight)
  109.     bIsFirstRun = True
  110.     For i = StartA To LastIndex
  111.         Set oLocTextShape = oTCShapeList(i)
  112.         Set oLocDBShape = oDBShapeList(i)
  113.         oLocTextShape.Size = aSize
  114.         If i = StartA Then
  115.             nXTCPos = oLocTextShape.Position.X
  116.             nXDBPos = nXTCPos + nMaxTCWidth  + cHoriDistance
  117.         End If
  118.         nYDBPos = oLocDBShape.Position.Y
  119.         nDBWidth = oLocDBShape.Size.Width
  120.         nDBHeight = oLocDBShape.Size.Height
  121.         aPoint = GetPoint(nXDBPos,nYDBPos)
  122.         oLocDBShape.SetPosition(aPoint)
  123.         CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
  124. '        GroupShapes(oDrawPage, oLocTextShape, oLocDBShape)
  125.     Next i
  126. End Sub
  127.  
  128.  
  129. Sub InitializePosSizes()
  130.     nXTCPos = cXOffset
  131.     nYTCPos = cYOffset
  132.     nTCWidth = 2000
  133.     nTCHeight = 560
  134.     nDBWidth = 2000
  135.     nDBHeight = 560
  136.     iReduceWidth = 0
  137.     Select Case CurArrangement
  138.         Case cColumnarLeft, cLeftJustified
  139.             nXDBPos = cXOffset + 3050
  140.             nYDBPos = cYOffset
  141.         Case cColumnarTop, cTopJustified
  142.             nXDBPos = cXOffset
  143.     End Select
  144. End Sub
  145.  
  146.  
  147. Function InsertTextControl(i as Integer) as Object
  148. Dim oShape as Object
  149. Dim oModel as Object
  150. Dim aPoint as New com.sun.star.awt.Point
  151. Dim aSize As New com.sun.star.awt.Size
  152.  
  153.     If bControlsareCreated Then
  154.         Set oShape = oTCShapeList(i)
  155.         Set oModel = oShape.GetControl
  156.         nTCWidth = oShape.Size.Width
  157.         nTCHeight = oShape.Size.Height
  158.         oShape.Position = GetPoint(nXTCPos, nYTCPos)
  159.         If CurArrangement = cColumnarTop Then
  160.             oModel.Align = com.sun.star.awt.TextAlign.LEFT
  161.         End If
  162.     Else
  163.         oModel = CreateUnoService(oModelService(cLabel))
  164.  
  165. '        oModel.Label = CurFieldName ' + nFieldPostfixes(i) (Todo: Was ist ein fieldPostfix?)
  166. ' Todo: According to FS this handling should be verified. I should not rely on the shape to create a model on its
  167. ' own. therefor the model should be inserted before the shape
  168. '        oDBForm.InsertByName(oModel.Name, oModel)
  169.         aPoint = GetPoint(nXTCPos, nYTCPos)
  170.         aSize = GetSize(nTCWidth,nTCHeight)
  171.         Set oShape = InsertControl(oModel, aPoint, aSize)
  172.         Set oTCShapeList(i)= oShape
  173.         If bIsVeryFirstRun Then
  174.             nTCHeight = GetPreferredHeight(oModel, CurFieldname)
  175.             If CurArrangement = cColumnarTop Then
  176.                 nYDBPos = nYTCPos + nTCHeight
  177.             End If
  178.         End If
  179.         nTCWidth = GetPreferredWidth(oModel, True, CurFieldname)
  180.     End If
  181.     If CurArrangement = cColumnarLeft Then
  182.         ' Note This If Sequence must be called before retrieving the outer Points
  183.         If bIsFirstRun Then
  184.             nMaxTCWidth = nTCWidth
  185.             bIsFirstRun = False
  186.         ElseIf nTCWidth > nMaxTCWidth Then
  187.             nMaxTCWidth = nTCWidth
  188.         End If
  189.     End If
  190.     CheckOuterPoints(oShape.Position.X, nTCWidth, nYTCPos, nTCHeight, False)
  191.     Select Case CurArrangement
  192.         Case cLeftJustified
  193.             nXDBPos = nMaxColRightX
  194.         Case cColumnarTop,cTopJustified
  195.             nXDBPos = nXTCPos
  196.             nYDBPos = nYTCPos + nTCHeight
  197.             If CurFieldLength = 20 And nDBWidth > 2 * nTCWidth Then
  198.                 iReduceWidth = iReduceWidth + 1
  199.             End If 
  200.     End Select    
  201.     oShape.SetSize(GetSize(nTCWidth,nTCHeight))
  202.     InsertTextControl = oModel
  203. End Function
  204.  
  205.  
  206. Sub InsertDBControl(oDBModel as Object, i as Integer)
  207. Dim aPoint as New com.sun.star.awt.Point
  208. Dim aSize As New com.sun.star.awt.Size
  209. Dim oShape as Object
  210. Dim oControl as Object
  211. Dim iColRightX as Long
  212.  
  213.     If Not bIsVeryFirstValueField Then
  214.         nDBWidth = Clng(CurFieldLength/2 * nDBRefWidth)
  215.     Else
  216.         nDBWidth = 1
  217.     End If
  218.     aPoint = GetPoint(nXDBPos, nYDBPos)
  219.     If bControlsAreCreated Then
  220.         Set oShape = oDBShapeList(i)
  221.         Set oDBModel = oShape.GetControl
  222.         oShape.Position = aPoint
  223.     Else
  224.         aSize = GetSize(nDBWidth,nDBHeight)
  225.         oDBModel = CreateUnoService(oModelService(CurControlType))
  226. '        oDBModel.Name = CurControlName
  227.         SetNumerics(oDBModel)
  228.         oShape = InsertControl(oDBModel, aPoint, aSize)
  229.         Set oDBShapeList(i)= oShape
  230. ' Todo: According to FS this handling should be verified. I should not rely on the shape to create a model on its
  231. ' own. therefor the model should be inserted before the shape        
  232. '        oDBForm.InsertByName(oDBModel.Name, oDBModel)
  233.         If CurControlType = cCheckBox Then
  234.             oDBModel.Label = ""
  235.         End If
  236.  
  237.     End If
  238.     If CurControlType = cImageControl Then
  239.         ' Todo: Dies ist nur eine vorsichtige Sch├ñtzung
  240.         nDBWidth = 2000
  241.         nDBHeight = 2000
  242.     Else
  243.         If bIsVeryFirstValueField Then
  244.             nDBRefWidth = GetPreferredWidth(oDBModel,True)
  245.             ' Todo: Hier wird vereinfachend davon ausgegangen, dass es sich bei DB-Feldern immer um Textfelder handelt!
  246.             nDBRefHeight = GetPreferredHeight(oDBModel)
  247.             bIsVeryFirstValueField = False
  248.         End If
  249.         'Todo: Vielleicht k├╢nnte man dieses Feld auch noch tiefer machen
  250.         If CurFieldType = com.sun.star.sdbc.DataType.LONGVARCHAR Then
  251.             oDBModel.MultiLine = True
  252.             nDBHeight = nDBRefHeight * 2
  253.         Else
  254.             nDBHeight = nDBRefHeight
  255.         End If
  256.         nDBWidth = CInt(CurFieldLength/10 * nDBRefWidth)
  257.     End If
  258.     aSize = GetSize(nDBWidth,nDBHeight)
  259.     oShape.SetSize(aSize)
  260.     CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
  261.     oDBModel.DataField = CurFieldName
  262. End Sub
  263.  
  264.  
  265. Sub CheckJustifiedPosition()
  266. Dim nLeftDist as Long
  267. Dim nRightDist as Long
  268. Dim oLocDBShape as Object
  269. Dim oLocTextShape as Object
  270. Dim nBaseWidth as Long
  271.     nBaseWidth = nFormWidth + cXOffset
  272.     nLeftDist = nMaxColRightX - nBaseWidth
  273.     nRightDist = nBaseWidth - nXTCPos + cHoriDistance
  274.     If nLeftDist < 0.5 * nRightDist and iReduceWidth > 2 Then
  275.         ' Fieldwidths in the line can be made smaller
  276.         AdjustLineWidth(StartA, a, nLeftDist, - 1)
  277.         If CurArrangement = cLeftjustified Then
  278.             nYDBPos = nMaxRowY + cVertDistance
  279.             nYTCPos = nYDBPos + 5
  280.             nXTCPos = cXOffset
  281.         Else
  282.             nYTCPos = nMaxRowY + cVertDistance
  283.             nYDBPos = nYTCPos + nTCHeight
  284.             nXTCPos = cXOffset
  285.             nXDBPos = cXOffset
  286.         End If
  287.         bIsFirstRun = True
  288.         StartA = a + 1
  289.     Else
  290.         Set oLocDBShape = oDBShapeList(a)
  291.         Set oLocTextShape = oTCShapeList(a)
  292.         If CurArrangement = cLeftJustified Then
  293.             If nYDBPos + nDBHeight = nMaxRowY Then
  294.                 ' The last Control was the highes in the row
  295.                 nYTCPos = nSecMaxRowY + cVertDistance
  296.             Else
  297.                 nYTCPos = nMaxRowY + cVertDistance
  298.             End If
  299.             nYDBPos = nYTCPos
  300.             nXDBPos = cXOffset + nTCWidth
  301.             oLocTextShape.Position = GetPoint(cXOffset, nYTCPos)
  302.             oLocDBShape.Position = GetPoint(nXDBPos, nYDBPos)
  303.             ' PosSizes for the next two Controls
  304.             nXTCPos = oLocDBShape.Position.X + oLocDBShape.Size.Width + cHoriDistance
  305.             bIsFirstRun = True
  306.             CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
  307.             nXDBPos = nMaxColRightX + cHoriDistance
  308.         Else        ' cTopJustified
  309.             If nYDBPos + nDBHeight = nMaxRowY Then
  310.                 ' The last Control was the highest in the row
  311.                 nYTCPos = nSecMaxRowY + cVertDistance
  312.             Else
  313.                 nYTCPos = nMaxRowY + cVertDistance
  314.             End If
  315.             nYDBPos = nYTCPOS + nTCHeight
  316.             nXDBPos = cXOffset
  317.             nXTCPos = cXOffset
  318.             oLocTextShape.Position = GetPoint(cXOffset, nYTCPos)
  319.             oLocDBShape.Position = GetPoint(cXOffset, nYDBPos)
  320.             bIsFirstRun = True
  321.             If nDBWidth > nTCWidth Then
  322.                 CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
  323.             Else
  324.                 CheckOuterPoints(nXDBPos, nTCWidth, nYDBPos, nDBHeight, True)
  325.             End If
  326.             nXTCPos = nMaxColRightX + cHoriDistance
  327.             nXDBPos = nXTCPos
  328.         End If
  329.         AdjustLineWidth(StartA, a-1, nRightDist, 1)
  330.         StartA = a
  331.      End If
  332.      iReduceWidth = 0
  333. End Sub
  334.  
  335.  
  336. Sub AdjustLineWidth(StartIndex as Integer, EndIndex as Integer, nDist as Long, Widthfactor as Integer)
  337. Dim i as Integer
  338. Dim oLocDBShape as Object
  339. Dim oLocTCShape as Object
  340. Dim CorrWidth as Integer
  341. Dim bAdjustPos as Boolean
  342. Dim iLocTCPosX as Long
  343. Dim iLocDBPosX as Long
  344. Dim ShapeCount as Integer
  345. ' Todo: Hier muss ber├╝cksichtigt werden, dass gewisse Widths z.B f├╝r numerische Controls nicht pl├╢tzlich zu klein werden
  346. ' Am besten werden nur TextControls gestaucht, so dass vorher geschaut werden muss, ob ├╝berhaupt TextControls vorhanden
  347. ' sind
  348.     If WidthFactor > 0 Then
  349.         ShapeCount = EndIndex-StartIndex + 1
  350.     Else
  351.         ShapeCount = iReduceWidth
  352.     End If
  353.     CorrWidth = (nDist)/ShapeCount  
  354.     bAdjustPos = False
  355.     iLocTCPosX = cXOffset
  356.     For i = StartIndex To EndIndex
  357.         Set oLocDBShape = oDBShapeList(i)
  358.         Set oLocTCShape = oTCShapeList(i)
  359.         If bAdjustPos Then
  360.             oLocTCShape.Position = GetPoint(iLocTCPosX, oLocTCShape.Position.Y)
  361.             If CurArrangement = cLeftJustified Then
  362.                 iLocDBPosX = oLocTCShape.Position.X + oLocTCShape.Size.Width
  363.                 oLocDBShape.Position = GetPoint(iLocDBPosX, oLocDBShape.Position.Y)
  364.             Else
  365.                 oLocDBShape.Position = GetPoint(iLocTCPosX, oLocTCShape.Position.Y + nTCHeight)
  366.             End If
  367.         Else
  368.             bAdjustPos = True
  369.         End If
  370.         If CDbl(FieldMetaValues(i,1)) > 20 or WidthFactor > 0 Then
  371.             oLocDBShape.Size = GetSize(oLocDBShape.Size.Width + WidthFactor * CorrWidth, oLocDBShape.Size.Height)
  372.         End If
  373.         iLocTCPosX = oLocDBShape.Position.X + oLocDBShape.Size.Width + cHoriDistance
  374.         If CurArrangement = cTopJustified Then
  375.             If oLocTCShape.Size.Width > oLocDBShape.Size.Width Then
  376.                 iLocTCPosX = oLocDBShape.Position.X + oLocTCShape.Size.Width + cHoriDistance
  377.             End If
  378.         End If
  379.     Next i
  380. End Sub
  381.  
  382.  
  383. Sub CheckOuterPoints(nXPos, nWidth, nYPos, nHeight, bIsDBField as Boolean)
  384. Dim nColRightX as Long
  385. Dim nRowY as Long
  386. Dim nOldMaxRowY as Long
  387.  
  388.     If CurArrangement = cLeftJustified Or CurArrangement = cTopJustified Then
  389.         If bIsDBField Then
  390.             ' Only at DBControls you can measure the Value of nMaxRowY
  391.             If bIsFirstRun Then
  392.                 nMaxRowY = nYPos + nHeight
  393.                 nSecMaxRowY = nMaxRowY
  394.             Else
  395.                 nRowY = nYPos + nHeight
  396.                 If nRowY >= nMaxRowY Then
  397.                     nOldMaxRowY = nMaxRowY
  398.                     nSecMaxRowY = nOldMaxRowY
  399.                     nMaxRowY = nRowY
  400.                 End If
  401.             End If
  402.         End If 
  403.     End If
  404.     ' Find the outer right point
  405.     If bIsFirstRun Then
  406.         nMaxColRightX = nXPos + nWidth
  407.         bIsFirstRun = False
  408.     Else
  409.         nColRightX = nXPos + nWidth
  410.         If nColRightX > nMaxColRightX Then
  411.             nMaxColRightX = nColRightX
  412.         End If
  413.     End If
  414. End Sub
  415.  
  416.  
  417. Function PositionGridControl(MaxIndex as Integer)
  418. Dim oControl as Object
  419. Dim n as Integer
  420. Dim oColumn as Object
  421. Dim aPoint as New com.sun.star.awt.Point
  422. Dim aSize as New com.sun.star.awt.Size
  423. Dim nWidth as Long
  424.     If bControlsareCreated Then
  425.         oDocument.LockControllers()
  426.         ShapesToNirwana()
  427.         oDocument.UnlockControllers()
  428.     End If
  429.     oGridModel = CreateUnoService(oModelService(cGridControl))
  430.     oGridModel.Name = "Grid1"
  431.     nWidth = 0
  432.     For n = 0 to MaxIndex
  433.         CurFieldType = FieldMetaValues(n,0)
  434.         CurControlType = FieldMetaValues(n,2)
  435.         CurFieldName = FieldNames(n)
  436.         If CurControlType = cImageControl Then
  437. 'Todo: Hier muss in der Hilfe vermittelt werden, dass Image Controls nicht dargestellt werden k├╢nnen
  438.             CurControlName = "TextField"            
  439.             oColumn = oGridModel.CreateColumn(CurControlName)
  440.             oColumn.Name = CalcUniqueContentName(oGridModel, CurControlName)
  441.             oColumn.Hidden = True
  442.         Else
  443.             CurControlName = FieldMetaValues(n,3)
  444.         oColumn = oGridModel.CreateColumn(CurControlName)
  445.         oColumn.Name = CalcUniqueContentName(oGridModel, CurControlName)
  446.         End If
  447.         SetNumerics(oColumn)
  448.         oColumn.DataField = CurFieldName
  449.         oColumn.Label = CurFieldName  '+ nFieldPostfixes(n); Todo: Was hat das nFieldPostfix hier zu suchen?
  450.         oColumn.Width = 0     'Spaltenbreite richtet sich nach dem Feldnamen
  451.         oGridModel.insertByName(oColumn.Name, oColumn)
  452.         oProgressbar.Value = n
  453.         nWidth = nWidth + oColumn.Width
  454.     next n
  455.     aPoint = GetPoint(cXOffset, cYOffset)
  456.     ' Todo: Man m├╝sste die Gr├╢├ƒe und die Position der Controls von der Anzahl der 
  457.     ' Datenbankfelder abh├ñngig machen
  458.     aSize = GetSize(nFormWidth, nFormHeight)
  459.     oDBForm.InsertByName (oGridModel.Name, oGridModel)
  460.     oGridShape = InsertControl (oGridModel, aPoint, aSize)
  461. End function
  462.  
  463.  
  464. Sub ControlCaptionstoStandardLayout()
  465. Dim i as Integer
  466. Dim iBorderType as Integer
  467. Dim oCurModel as Object
  468. Dim oStyle as Object
  469. Dim iStandardColor as Long
  470.     If CurArrangement <> cTabled Then
  471.         oStyle = oDocument.StyleFamilies.GetByName("ParagraphStyles").GetByName("Standard")
  472.         iStandardColor = oStyle.CharColor
  473.         For i = 0 To MaxIndex
  474.             oCurModel = oTCShapeList(i).GetControl
  475.             If i = 0 Then
  476.                 If oCurModel.TextColor = iStandardColor Then
  477.                     Exit Sub
  478.                 End If
  479.             End If
  480.             oCurModel.TextColor = iStandardColor
  481.         Next i
  482.     End If 
  483. End Sub
  484.  
  485.  
  486. Sub GroupShapes(oDrawPage as Object, oLocTextShape as Object, oLocDBShape as Object)
  487. Dim oShapes as Object
  488.     oShapes = createUnoService("com.sun.star.drawing.ShapeCollection")
  489.     oShapes.Add(oLocTextShape)
  490.     oShapes.Add(oLocDBShape)
  491.     oDrawPage.Group(oShapes)
  492. End Sub
  493.  
  494. </script:module>