home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2002 November / VPR0211A.ISO / OPENOFFICE / f_0138 / tools.xba < prev   
Extensible Markup Language  |  2001-12-18  |  10KB  |  302 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.  
  7. Function SetProgressValue(iValue as Integer)    
  8.     If iValue = 0 Then
  9.         oProgressbar.End
  10.     End If
  11.     ProgressValue = iValue
  12.     oProgressbar.Value = iValue
  13. End Function
  14.  
  15.  
  16. Function GetPreferredWidth(oModel as Object, bGetMaxWidth as Boolean, Optional LocText)
  17. Dim aPeerSize as new com.sun.star.awt.Size
  18. Dim nWidth as Integer
  19. Dim oControl as Object
  20.     If Not IsMissing(LocText) Then
  21.         ' Label
  22.         aPeerSize = GetPeerSize(oModel, oControl, LocText)
  23.     ElseIf CurControlType = cImageControl Then
  24.         GetPreferredWidth() = 2000
  25.         Exit Function
  26.     Else
  27.         aPeerSize = GetPeerSize(oModel, oControl)
  28.     End If
  29.     nWidth = aPeerSize.Width
  30.     ' We increase the preferred Width a bit so that the control does not become too small
  31.     ' when we change the border from "3D" to "Flat"
  32.     GetPreferredWidth = (nWidth + 10) * XPixelFactor    ' PixelTo100thmm(nWidth)
  33. End Function
  34.  
  35.  
  36. Function GetPreferredHeight(oModel as Object, Optional LocText)
  37. Dim aPeerSize as new com.sun.star.awt.Size
  38. Dim nHeight as Integer
  39. Dim oControl as Object
  40.     If Not IsMissing(LocText) Then
  41.         ' Label
  42.         aPeerSize = GetPeerSize(oModel, oControl, LocText)
  43.     ElseIf CurControlType = cImageControl Then
  44.         GetPreferredHeight() = 2000
  45.         Exit Function
  46.     Else
  47.         aPeerSize = GetPeerSize(oModel, oControl)
  48.     End If
  49.     nHeight = aPeerSize.Height
  50.     ' We increase the preferred Height a bit so that the control does not become too small
  51.     ' when we change the border from "3D" to "Flat"
  52.     GetPreferredHeight = (nHeight+1) * YPixelFactor     ' PixelTo100thmm(nHeight)
  53. End Function
  54.  
  55.  
  56. Function GetPeerSize(oModel as Object, oControl as Object, Optional LocText)
  57. Dim oPeer as Object
  58. Dim aPeerSize as new com.sun.star.awt.Size
  59. Dim NullValue
  60.     oControl = oController.GetControl(oModel)
  61.     oPeer = oControl.GetPeer()
  62.     If oControl.Model.PropertySetInfo.HasPropertybyName("EffectiveMax") Then
  63.         If oControl.Model.EffectiveMax = 0 Then
  64.             ' This is relevant for decimal fields
  65.             oControl.Model.EffectiveValue = 999.9999
  66.         Else
  67.             oControl.Model.EffectiveValue = oControl.Model.EffectiveMax
  68.         End If
  69.         GetPeerSize() = oPeer.PreferredSize()    
  70.         oControl.Model.EffectiveValue = NullValue
  71.     ElseIf Not IsMissing(LocText) Then
  72.         oControl.Text = LocText
  73.         GetPeerSize() = oPeer.PreferredSize()
  74.     ElseIf CurFieldType = com.sun.star.sdbc.DataType.BIT Then
  75.         GetPeerSize() = oPeer.PreferredSize()
  76.     ElseIf CurFieldType = com.sun.star.sdbc.DataType.DATE Then
  77.         oControl.Model.Date = Date
  78.         GetPeerSize() = oPeer.PreferredSize()
  79.         oControl.Model.Date = NullValue
  80.     ElseIf CurFieldType = com.sun.star.sdbc.DataType.TIME Then
  81.         oControl.Time = Time
  82.         GetPeerSize() = oPeer.PreferredSize()
  83.         oControl.Time = NullValue
  84.     Else
  85.         oControl.Text = Mid(SBSIZETEXT,1,oControl.MaxTextLen)
  86.         GetPeerSize() = oPeer.PreferredSize()
  87.         oControl.Text = ""
  88.     End If
  89. End Function
  90.  
  91.  
  92. Function TwipToCM(BYVAL nValue as long) as String
  93.     TwipToCM = trim(str(nValue / 567)) + "cm"
  94. End function
  95.  
  96.  
  97. Function TwipTo100telMM(BYVAL nValue as long) as long
  98.      TwipTo100telMM = nValue / 0.567
  99. End function
  100.  
  101.  
  102. Function TwipToPixel(BYVAL nValue as long) as long ' nur ungefaehre Berechnung
  103.     TwipToPixel = nValue / 15
  104. End function
  105.  
  106.  
  107. Function PixelTo100thMMX(oControl as Object) as long
  108.     oPeer = oControl.GetPeer()
  109.     PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterX/100000)
  110.  
  111. '     PixelTo100thMM = nValue * 28                    ' nur ungefテ、hre Berechnung 
  112. End function
  113.  
  114.  
  115. Function PixelTo100thMMY(oControl as Object) as long
  116.     oPeer = oControl.GetPeer()
  117.     PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterY/100000)
  118.  
  119. '     PixelTo100thMM = nValue * 28                    ' nur ungefテ、hre Berechnung 
  120. End function
  121.  
  122.  
  123. Function GetPoint(xPos, YPos) as New com.sun.star.awt.Point
  124. Dim aPoint as New com.sun.star.awt.Point
  125.     aPoint.X = xPos
  126.     aPoint.Y = yPos
  127.     GetPoint() = aPoint
  128. End Function
  129.  
  130.  
  131. Function GetSize(iWidth, iHeight) As New com.sun.star.awt.Size
  132. Dim aSize As New com.sun.star.awt.Size
  133.     aSize.Width = iWidth
  134.     aSize.Height = iHeight
  135.     GetSize() = aSize
  136. End Function
  137.  
  138.  
  139. Sub    ImportStyles()
  140. Dim OldIndex as Integer
  141.     If Not bDebug Then
  142.         On Local Error GoTo WIZARDERROR
  143.     End If
  144.     OldIndex = CurIndex
  145.     CurIndex = GetCurIndex(oDialogModel.lstStyles, Styles(), NumberofStyles,8)
  146.     If CurIndex <> OldIndex Then    
  147.         ToggleLayoutPage(False)
  148.         SetImportStyle()
  149.         ToggleLayoutPage(True, "lstStyles")    
  150.     End If
  151. WIZARDERROR:
  152.     If Err <> 0 Then    
  153.         Msgbox(sMsgErrMsg, 16, GetProductName())
  154.         Resume LOCERROR
  155.         LOCERROR:        
  156.     End If
  157. End Sub
  158.  
  159.  
  160. Sub SetImportStyle()
  161. Dim sImportPath as String
  162.     sImportPath = Styles(8,CurIndex)
  163.     bWithBackGraphic = LoadNewStyles(oDocument, oDialogModel, CurIndex, sImportPath, Styles(), TexturePath)
  164.     ControlCaptionsToStandardLayout()
  165. End Sub
  166.  
  167.  
  168. Function SetNumerics(ByVal oLocObject as Object, iLocFieldType as Integer) as Object    
  169. '    Msgbox CurFieldName & ":" & chr(13) & oLocObject.dbg_Properties
  170.     If CurControlType = cNumericBox Then
  171.         oLocObject.TreatAsNumber = True
  172.         Select Case iLocFieldType
  173.             Case com.sun.star.sdbc.DataType.BIGINT
  174.                 oLocObOject.EffectiveMax = 2147483647 * 2147483647
  175.                 oLocbject.EffectiveMin = -(-2147483648 * -2147483648)
  176. '                oLocObject.DecimalAccuracy = 0
  177.             Case com.sun.star.sdbc.DataType.INTEGER
  178.                 oLocObject.EffectiveMax = 2147483647
  179.                 oLocObject.EffectiveMin = -2147483648
  180.             Case  com.sun.star.sdbc.DataType.SMALLINT
  181.                 oLocObject.EffectiveMax = 32767
  182.                 oLocObject.EffectiveMin = -32768
  183.             Case com.sun.star.sdbc.DataType.TINYINT
  184.                 oLocObject.EffectiveMax = 127
  185.                 oLocObject.EffectiveMin = -128
  186.             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
  187. 'Todo:            oLocObject.DecimalAccuracy = ...
  188.                  oLocObject.EffectiveDefault = CurDefaultValue
  189. ' Todo: HelpText???
  190.         End Select
  191.         If oLocObject.PropertySetinfo.HasPropertyByName("Width")Then ' Note: an Access AutoincrementField does not provide this property Width
  192.             oLocObject.Width = CurFieldLength + CurScale + 1
  193.         End If
  194.         If CurIsCurrency Then
  195. 'Todo: Wie setzt man Wテ、hrungen?            Msgbox "Wテ、hrungsfeld: " & oLocObject.dbg_Properties
  196.         End If
  197.     ElseIf CurControlType = cTextBox Then    'com.sun.star.sdbc.DataType.CHAR, com.sun.star.sdbc.DataType.VARCHAR, com.sun.star.sdbc.DataType.LONGVARCHAR
  198.         If oLocObject.MaxTextLen = 0 Or oLocObject.MaxTextLen > 30 Then
  199.             oLocObject.MaxTextLen = 30
  200.             CurFieldLength = 30
  201.         Else
  202.             oLocObject.MaxTextLen = CurFieldLength
  203.         End If
  204.         oLocObject.DefaultText = CurDefaultValue
  205.     ElseIf CurControlType = cDateBox Then
  206. ''Todo Why does this not work?:        oLocObject.DefaultDate = CurDefaultValue
  207.     ElseIf CurControlType = cTimeBox Then    'com.sun.star.sdbc.DataType.DATE, com.sun.star.sdbc.DataType.TIME
  208.         oLocObject.DefaultTime = CurDefaultValue
  209. ' Todo: Property TimeFormat? frome where?
  210.     ElseIf CurControlType = cCheckBox Then
  211. 'Todo Why does this not work?:        oLocObject.DefautState = CurDefaultValue
  212.     End If
  213.     If oLocObject.PropertySetInfo.HasPropertybyName("FormatKey") Then
  214.         On Local Error Resume Next
  215.         oLocObject.FormatKey = CurFormatKey
  216.     End If
  217. End Function
  218.  
  219.  
  220. ' Destroy all Shapes in Nirwana
  221. Sub RemoveShapes()
  222. Dim n as Integer
  223. Dim oControl as Object
  224. Dim oShape as Object
  225.     For n = oDrawPage.Count-1 To 0 Step -1
  226.         oShape = oDrawPage(n)
  227.         If oShape.Position.Y > -2000 Then
  228.             oDrawPage.Remove(oShape)
  229.         End If
  230.     Next n
  231. End Sub
  232.  
  233.  
  234. ' Destroy all Shapes in Nirwana
  235. Sub RemoveNirwanaShapes()
  236. Dim n as Integer
  237. Dim oControl as Object
  238. Dim oShape as Object
  239.     For n = oDrawPage.Count-1 To 0 Step -1
  240.         oShape = oDrawPage(n)
  241.         If oShape.Position.Y < -2000 Then
  242.             oDrawPage.Remove(oShape)
  243.         End If
  244.     Next n
  245. End Sub
  246.  
  247.  
  248.  
  249. ' Note: as Shapes cannot be removed from the DrawPage without destroying
  250. ' the object we have to park them somewhere beyond the visible area of the page
  251. Sub ShapesToNirwana()
  252. Dim n as Integer
  253. Dim oControl as Object
  254.     For n = 0 To oDrawPage.Count-1
  255.         oDrawPage(n).Position = GetPoint(-20, -10000)
  256.     Next n
  257. End Sub
  258.  
  259.  
  260. Function CalcUniqueContentName(BYVAL oContainer as Object, sBaseName as String) as String
  261.  
  262. Dim nPostfix as Integer
  263. Dim sReturn as String
  264.     nPostfix = 2
  265.     sReturn = sBaseName
  266.     while (oContainer.hasByName(sReturn))
  267.         sReturn = sBaseName & nPostfix
  268.         nPostfix = nPostfix + 1
  269.     Wend
  270.     CalcUniqueContentName = sReturn
  271. End Function
  272.  
  273.  
  274. Function CountItemsInArray(BigArray(), SearchItem)
  275. Dim i as Integer
  276. Dim MaxIndex as Integer
  277. Dim ResCount as Integer
  278.     ResCount = 0
  279.     MaxIndex = Ubound(BigArray())
  280.     For i = 0 To MaxIndex
  281.         If SearchItem = BigArray(i) Then
  282.             ResCount = ResCount + 1
  283.         End If
  284.     Next i
  285.     CountItemsInArray() = ResCount
  286. End Function
  287.  
  288.  
  289. Function GetDBHeight(oDBModel as Object)
  290.     If CurControlType = cImageControl Then
  291.         nDBHeight = 2000
  292.     Else
  293.         If CurFieldType = com.sun.star.sdbc.DataType.LONGVARCHAR Then
  294.             oDBModel.MultiLine = True
  295.             nDBHeight = nDBRefHeight * 4
  296.         Else
  297.             nDBHeight = nDBRefHeight
  298.         End If
  299.     End If
  300.     GetDBHeight() = nDBHeight
  301. End Function
  302. </script:module>