home *** CD-ROM | disk | FTP | other *** search
/ com!online 2001 December / COMCD1201.iso / openoffice / f_0020 / tools.xba < prev   
Encoding:
Extensible Markup Language  |  2001-08-24  |  6.5 KB  |  216 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="tools" script:language="StarBasic">REM  *****  BASIC  *****
  4. Option Explicit
  5.  
  6. Function SetProgressValue(iValue as Integer)    
  7.     If iValue = 0 Then
  8.         oProgressbar.End
  9.     End If
  10.     ProgressValue = iValue
  11.     oProgressbar.Value = iValue
  12. End Function
  13.  
  14.  
  15. Function GetPreferredWidth(oModel as Object, bGetMaxWidth as Boolean, Optional LocText)
  16. Dim aPeerSize as new com.sun.star.awt.Size
  17. Dim nWidth as Integer
  18. Dim oControl as Object
  19. ' Todo: Wie geht das mit ImageControls
  20. ' kann nur fest verdrahtet werden
  21.     If Not IsMissing(LocText) Then
  22.         aPeerSize = GetPeerSize(oModel, oControl, LocText)
  23.     Else
  24.         aPeerSize = GetPeerSize(oModel, oControl)
  25.     End If
  26.     nWidth = aPeerSize.Width
  27.     GetPreferredWidth = nWidth * XPixelFactor    ' PixelTo100thmm(nWidth)
  28. End Function
  29.  
  30.  
  31. Function GetPreferredHeight(oModel as Object, Optional LocText)
  32. Dim aPeerSize as new com.sun.star.awt.Size
  33. Dim nHeight as Integer
  34. Dim oControl as Object
  35. ' Todo: Wie geht das mit ImageControls
  36.     If Not IsMissing(LocText) Then
  37.         aPeerSize = GetPeerSize(oModel, oControl, LocText)
  38.     Else
  39.         aPeerSize = GetPeerSize(oModel, oControl)
  40.     End If
  41.     nHeight = aPeerSize.Height
  42.     GetPreferredHeight = nHeight * YPixelFactor     ' PixelTo100thmm(nHeight)
  43. End Function
  44.  
  45.  
  46.  
  47. Function GetPeerSize(oModel as Object, oControl as Object, Optional LocText)    
  48. Dim oPeer as Object
  49. Dim aPeerSize as new com.sun.star.awt.Size
  50.     oControl = oController.GetControl(oModel)
  51.     oPeer = oControl.GetPeer()
  52. ' Todo: Wie geht es bei Image Controls?    
  53.     If oControl.Model.PropertySetInfo.HasPropertybyName("EffectiveMax") Then
  54.         If oControl.Model.EffectiveMax = 0 Then
  55.             oControl.Model.EffectiveValue = 999.9999            
  56.         Else
  57.             oControl.Model.EffectiveValue = oControl.Model.EffectiveMax
  58.         End If
  59.         aPeerSize = oPeer.PreferredSize()
  60.  
  61.     ElseIf Not IsMissing(LocText) Then
  62.         oControl.Text = LocText
  63.         aPeerSize = oPeer.PreferredSize()
  64.     ElseIf CurFieldType = com.sun.star.sdbc.DataType.BIT Then
  65.         oPeer.PreferredSize
  66.         aPeerSize = oPeer.PreferredSize
  67.     Else
  68.         oControl.Text = "2222222222"
  69.         aPeerSize = oPeer.PreferredSize()
  70.         oControl.Text = ""
  71.     End If
  72.     GetPeerSize = aPeerSize
  73. End Function
  74.  
  75.  
  76. Function TwipToCM(BYVAL nValue as long) as String
  77.     TwipToCM = trim(str(nValue / 567)) + "cm"
  78. End function
  79.  
  80.  
  81. Function TwipTo100telMM(BYVAL nValue as long) as long
  82.      TwipTo100telMM = nValue / 0.567
  83. End function
  84.  
  85.  
  86. Function TwipToPixel(BYVAL nValue as long) as long ' nur ungefaehre Berechnung
  87.     TwipToPixel = nValue / 15
  88. End function
  89.  
  90.  
  91. Function PixelTo100thMMX(oControl as Object) as long
  92.     oPeer = oControl.GetPeer()
  93.     PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterX/100000)
  94.  
  95. '     PixelTo100thMM = nValue * 28        ' nur ungef├ñhre Berechnung 
  96. End function
  97.  
  98.  
  99. Function PixelTo100thMMY(oControl as Object) as long
  100.     oPeer = oControl.GetPeer()
  101.     PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterY/100000)
  102.  
  103. '     PixelTo100thMM = nValue * 28        ' nur ungef├ñhre Berechnung 
  104. End function
  105.  
  106.  
  107. Function GetPoint(xPos, YPos) as New com.sun.star.awt.Point
  108. Dim aPoint as New com.sun.star.awt.Point
  109.     aPoint.X = xPos
  110.     aPoint.Y = yPos
  111.     GetPoint() = aPoint
  112. End Function
  113.  
  114.  
  115. Function GetSize(iWidth, iHeight) As New com.sun.star.awt.Size
  116. Dim aSize As New com.sun.star.awt.Size
  117.     aSize.Width = iWidth
  118.     aSize.Height = iHeight
  119.     GetSize() = aSize
  120. End Function
  121.  
  122.  
  123. Sub    ImportStyles()
  124. Dim CurIndex as Integer
  125. Dim sImportPath as String
  126. Dim bWithBackGraphic as Boolean
  127.     ToggleLayoutPage(False)
  128.     oDocument.LockControllers
  129.     CurIndex = GetCurIndex(oDialogModel.lstStyles, Styles(), NumberofStyles,8)
  130.     sImportPath = Styles(8,CurIndex)
  131.     bWithBackGraphic = LoadNewStyles(oDocument, oDialogModel, CurIndex, sImportPath, Styles(), TexturePath)
  132.     ControlCaptionsToStandardLayout()
  133.     ToggleOptionButtons(oDialogModel, bWithBackGraphic)    
  134.     ConfigurePageStyle()    
  135.     oDocument.UnlockControllers
  136.     ToggleLayoutPage(True)    
  137. End Sub
  138.  
  139.  
  140. Function SetNumerics(ByVal oLocObject as Object) as Object    
  141.     ' Todo: FS fragen, ob dies alles richtig ist
  142.     ' Todo: Es sollte in der Hilfe darauf hingewiesen werden, dass der untere Wertbereich negativ ist.
  143.     Select Case CurFieldType
  144.         Case com.sun.star.sdbc.DataType.BIGINT
  145.             oLocObOject.EffectiveMax = 2147483647 * 2147483647 
  146.             oLocbject.EffectiveMin = -(-2147483648 * -2147483648)
  147.         Case com.sun.star.sdbc.DataType.INTEGER 
  148.             oLocObject.EffectiveMax = 2147483647 
  149.             oLocObject.EffectiveMin = -2147483648
  150.         Case  com.sun.star.sdbc.DataType.SMALLINT
  151.             oLocObject.EffectiveMax = 32767 
  152.             oLocObject.EffectiveMin = -32768
  153.         Case com.sun.star.sdbc.DataType.TINYINT
  154.             oLocObject.EffectiveMax = 127
  155.             oLocObject.EffectiveMin = -128
  156.         Case com.sun.star.sdbc.DataType.FLOAT, com.sun.star.sdbc.DataType.REAL, com.sun.star.sdbc.DataType.DOUBLE, com.sun.star.sdbc.DataType.DECIMAL, com.sun.star.sdbc.DataType.NUMERIC
  157.         ' Todo: Hier sollte der Numberformatter angeworfen werden um die Nachkommastellen
  158.         ' festzulegen, da ein EffectiveMax/EffectiveMin hier keinen Sinn macht
  159. '            oLocObject.DecimalAccuracy = FieldDecimalAccuracy%(n%) ' Nachkommastellen
  160.     End Select
  161. End Function
  162.  
  163.  
  164. ' Destroy all Shapes in Nirwana
  165. Sub RemoveShapes()
  166. Dim n as Integer
  167. Dim oControl as Object
  168. Dim oShape as Object
  169.     For n = oDrawPage.Count-1 To 0 Step -1
  170.         oShape = oDrawPage(n)
  171.         If oShape.Position.Y > -2000 Then
  172.             oDrawPage.Remove(oShape)
  173.         End If
  174.     Next n
  175. End Sub
  176.  
  177. ' Note as Shapes cannot be removed from the DrawPage without destroying
  178. ' the object we have to park them somewhere in Nirwana
  179. Sub ShapesToNirwana()
  180. Dim n as Integer
  181. Dim oControl as Object
  182.     For n = 0 To oDrawPage.Count-1
  183.         oDrawPage(n).Position = GetPoint(-20, -10000)
  184.     Next n
  185. End Sub
  186.  
  187.  
  188. Function CalcUniqueContentName(BYVAL oContainer as Object, sBaseName as String) as String
  189. Dim nPostfix as Integer
  190. Dim sReturn as String
  191.     nPostfix = 2
  192.     sReturn = sBaseName
  193.  
  194.     while (oContainer.hasByName(sReturn))
  195.         sReturn = sBaseName & nPostfix
  196.         nPostfix = nPostfix + 1
  197.     Wend
  198.     CalcUniqueContentName = sReturn
  199. End Function
  200.  
  201.  
  202.  
  203.  
  204. Function CountItemsInArray(BigArray(), SearchItem)
  205. Dim i as Integer
  206. Dim MaxIndex as Integer
  207. Dim ResCount as Integer
  208.     ResCount = 0
  209.     MaxIndex = Ubound(BigArray())
  210.     For i = 0 To MaxIndex
  211.         If SearchItem = BigArray(i) Then
  212.             ResCount = ResCount + 1
  213.         End If
  214.     Next i
  215.     CountItemsInArray() = ResCount
  216. End Function                    </script:module>