1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="tools" script:language="StarBasic">REM ***** BASIC ***** 4*cdf0e10cSrcweirOption Explicit 5*cdf0e10cSrcweirPublic Const SBMAXTEXTSIZE = 50 6*cdf0e10cSrcweir 7*cdf0e10cSrcweir 8*cdf0e10cSrcweirFunction SetProgressValue(iValue as Integer) 9*cdf0e10cSrcweir If iValue = 0 Then 10*cdf0e10cSrcweir oProgressbar.End 11*cdf0e10cSrcweir End If 12*cdf0e10cSrcweir ProgressValue = iValue 13*cdf0e10cSrcweir oProgressbar.Value = iValue 14*cdf0e10cSrcweirEnd Function 15*cdf0e10cSrcweir 16*cdf0e10cSrcweir 17*cdf0e10cSrcweirFunction GetPreferredWidth(oModel as Object, bGetMaxWidth as Boolean, Optional LocText) 18*cdf0e10cSrcweirDim aPeerSize as new com.sun.star.awt.Size 19*cdf0e10cSrcweirDim nWidth as Integer 20*cdf0e10cSrcweirDim oControl as Object 21*cdf0e10cSrcweir If Not IsMissing(LocText) Then 22*cdf0e10cSrcweir ' Label 23*cdf0e10cSrcweir aPeerSize = GetPeerSize(oModel, oControl, LocText) 24*cdf0e10cSrcweir ElseIf CurControlType = cImageControl Then 25*cdf0e10cSrcweir GetPreferredWidth() = 2000 26*cdf0e10cSrcweir Exit Function 27*cdf0e10cSrcweir Else 28*cdf0e10cSrcweir aPeerSize = GetPeerSize(oModel, oControl) 29*cdf0e10cSrcweir End If 30*cdf0e10cSrcweir nWidth = aPeerSize.Width 31*cdf0e10cSrcweir ' We increase the preferred Width a bit so that the control does not become too small 32*cdf0e10cSrcweir ' when we change the border from "3D" to "Flat" 33*cdf0e10cSrcweir GetPreferredWidth = (nWidth + 10) * XPixelFactor ' PixelTo100thmm(nWidth) 34*cdf0e10cSrcweirEnd Function 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir 37*cdf0e10cSrcweirFunction GetPreferredHeight(oModel as Object, Optional LocText) 38*cdf0e10cSrcweirDim aPeerSize as new com.sun.star.awt.Size 39*cdf0e10cSrcweirDim nHeight as Integer 40*cdf0e10cSrcweirDim oControl as Object 41*cdf0e10cSrcweir If Not IsMissing(LocText) Then 42*cdf0e10cSrcweir ' Label 43*cdf0e10cSrcweir aPeerSize = GetPeerSize(oModel, oControl, LocText) 44*cdf0e10cSrcweir ElseIf CurControlType = cImageControl Then 45*cdf0e10cSrcweir GetPreferredHeight() = 2000 46*cdf0e10cSrcweir Exit Function 47*cdf0e10cSrcweir Else 48*cdf0e10cSrcweir aPeerSize = GetPeerSize(oModel, oControl) 49*cdf0e10cSrcweir End If 50*cdf0e10cSrcweir nHeight = aPeerSize.Height 51*cdf0e10cSrcweir ' We increase the preferred Height a bit so that the control does not become too small 52*cdf0e10cSrcweir ' when we change the border from "3D" to "Flat" 53*cdf0e10cSrcweir GetPreferredHeight = (nHeight+1) * YPixelFactor ' PixelTo100thmm(nHeight) 54*cdf0e10cSrcweirEnd Function 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir 57*cdf0e10cSrcweirFunction GetPeerSize(oModel as Object, oControl as Object, Optional LocText) 58*cdf0e10cSrcweirDim oPeer as Object 59*cdf0e10cSrcweirDim aPeerSize as new com.sun.star.awt.Size 60*cdf0e10cSrcweirDim NullValue 61*cdf0e10cSrcweir oControl = oController.GetControl(oModel) 62*cdf0e10cSrcweir oPeer = oControl.GetPeer() 63*cdf0e10cSrcweir If oControl.Model.PropertySetInfo.HasPropertybyName("EffectiveMax") Then 64*cdf0e10cSrcweir If oControl.Model.EffectiveMax = 0 Then 65*cdf0e10cSrcweir ' This is relevant for decimal fields 66*cdf0e10cSrcweir oControl.Model.EffectiveValue = 999.9999 67*cdf0e10cSrcweir Else 68*cdf0e10cSrcweir oControl.Model.EffectiveValue = oControl.Model.EffectiveMax 69*cdf0e10cSrcweir End If 70*cdf0e10cSrcweir GetPeerSize() = oPeer.PreferredSize() 71*cdf0e10cSrcweir oControl.Model.EffectiveValue = NullValue 72*cdf0e10cSrcweir ElseIf Not IsMissing(LocText) Then 73*cdf0e10cSrcweir oControl.Text = LocText 74*cdf0e10cSrcweir GetPeerSize() = oPeer.PreferredSize() 75*cdf0e10cSrcweir ElseIf CurFieldType = com.sun.star.sdbc.DataType.BIT Then 76*cdf0e10cSrcweir GetPeerSize() = oPeer.PreferredSize() 77*cdf0e10cSrcweir ElseIf CurFieldType = com.sun.star.sdbc.DataType.BOOLEAN Then 78*cdf0e10cSrcweir GetPeerSize() = oPeer.PreferredSize() 79*cdf0e10cSrcweir ElseIf CurFieldType = com.sun.star.sdbc.DataType.DATE Then 80*cdf0e10cSrcweir oControl.Model.Date = Date 81*cdf0e10cSrcweir GetPeerSize() = oPeer.PreferredSize() 82*cdf0e10cSrcweir oControl.Model.Date = NullValue 83*cdf0e10cSrcweir ElseIf CurFieldType = com.sun.star.sdbc.DataType.TIME Then 84*cdf0e10cSrcweir oControl.Time = Time 85*cdf0e10cSrcweir GetPeerSize() = oPeer.PreferredSize() 86*cdf0e10cSrcweir oControl.Time = NullValue 87*cdf0e10cSrcweir Else 88*cdf0e10cSrcweir If oControl.MaxTextLen > SBMAXTEXTSIZE Then 89*cdf0e10cSrcweir oControl.Text = Mid(SBSIZETEXT,1, SBMAXTEXTSIZE) 90*cdf0e10cSrcweir Else 91*cdf0e10cSrcweir oControl.Text = Mid(SBSIZETEXT,1, oControl.MaxTextLen) 92*cdf0e10cSrcweir End If 93*cdf0e10cSrcweir GetPeerSize() = oPeer.PreferredSize() 94*cdf0e10cSrcweir oControl.Text = "" 95*cdf0e10cSrcweir End If 96*cdf0e10cSrcweirEnd Function 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir 99*cdf0e10cSrcweirFunction TwipToCM(BYVAL nValue as long) as String 100*cdf0e10cSrcweir TwipToCM = trim(str(nValue / 567)) + "cm" 101*cdf0e10cSrcweirEnd function 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir 104*cdf0e10cSrcweirFunction TwipTo100telMM(BYVAL nValue as long) as long 105*cdf0e10cSrcweir TwipTo100telMM = nValue / 0.567 106*cdf0e10cSrcweirEnd function 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir 109*cdf0e10cSrcweirFunction TwipToPixel(BYVAL nValue as long) as long ' not an exact calculation 110*cdf0e10cSrcweir TwipToPixel = nValue / 15 111*cdf0e10cSrcweirEnd function 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir 114*cdf0e10cSrcweirFunction PixelTo100thMMX(oControl as Object) as long 115*cdf0e10cSrcweir oPeer = oControl.GetPeer() 116*cdf0e10cSrcweir PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterX/100000) 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir' PixelTo100thMM = nValue * 28 ' not an exact calculation 119*cdf0e10cSrcweirEnd function 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir 122*cdf0e10cSrcweirFunction PixelTo100thMMY(oControl as Object) as long 123*cdf0e10cSrcweir oPeer = oControl.GetPeer() 124*cdf0e10cSrcweir PixelTo100mmX = Clng(Peer.GetInfo.PixelPerMeterY/100000) 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir' PixelTo100thMM = nValue * 28 ' not an exact calculation 127*cdf0e10cSrcweirEnd function 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir 130*cdf0e10cSrcweirFunction GetPoint(xPos, YPos) as New com.sun.star.awt.Point 131*cdf0e10cSrcweirDim aPoint as New com.sun.star.awt.Point 132*cdf0e10cSrcweir aPoint.X = xPos 133*cdf0e10cSrcweir aPoint.Y = yPos 134*cdf0e10cSrcweir GetPoint() = aPoint 135*cdf0e10cSrcweirEnd Function 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir 138*cdf0e10cSrcweirFunction GetSize(iWidth, iHeight) As New com.sun.star.awt.Size 139*cdf0e10cSrcweirDim aSize As New com.sun.star.awt.Size 140*cdf0e10cSrcweir aSize.Width = iWidth 141*cdf0e10cSrcweir aSize.Height = iHeight 142*cdf0e10cSrcweir GetSize() = aSize 143*cdf0e10cSrcweirEnd Function 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir 146*cdf0e10cSrcweirSub ImportStyles() 147*cdf0e10cSrcweirDim OldIndex as Integer 148*cdf0e10cSrcweir If Not bDebug Then 149*cdf0e10cSrcweir On Local Error GoTo WIZARDERROR 150*cdf0e10cSrcweir End If 151*cdf0e10cSrcweir OldIndex = CurIndex 152*cdf0e10cSrcweir CurIndex = GetCurIndex(DialogModel.lstStyles, Styles(),8) 153*cdf0e10cSrcweir If CurIndex <> OldIndex Then 154*cdf0e10cSrcweir ToggleLayoutPage(False) 155*cdf0e10cSrcweir Dim sImportPath as String 156*cdf0e10cSrcweir sImportPath = Styles(CurIndex, 8) 157*cdf0e10cSrcweir bWithBackGraphic = LoadNewStyles(oDocument, DialogModel, CurIndex, sImportPath, Styles(), TexturePath) 158*cdf0e10cSrcweir ControlCaptionsToStandardLayout() 159*cdf0e10cSrcweir ToggleLayoutPage(True, "lstStyles") 160*cdf0e10cSrcweir End If 161*cdf0e10cSrcweirWIZARDERROR: 162*cdf0e10cSrcweir If Err <> 0 Then 163*cdf0e10cSrcweir Msgbox(sMsgErrMsg, 16, GetProductName()) 164*cdf0e10cSrcweir Resume LOCERROR 165*cdf0e10cSrcweir LOCERROR: 166*cdf0e10cSrcweir End If 167*cdf0e10cSrcweirEnd Sub 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir 171*cdf0e10cSrcweirFunction SetNumerics(ByVal oLocObject as Object, iLocFieldType as Integer) as Object 172*cdf0e10cSrcweir If CurControlType = cNumericBox Then 173*cdf0e10cSrcweir oLocObject.TreatAsNumber = True 174*cdf0e10cSrcweir Select Case iLocFieldType 175*cdf0e10cSrcweir Case com.sun.star.sdbc.DataType.BIGINT 176*cdf0e10cSrcweir oLocObject.EffectiveMax = 2147483647 * 2147483647 177*cdf0e10cSrcweir oLocObject.EffectiveMin = -(-2147483648 * -2147483648) 178*cdf0e10cSrcweir' oLocObject.DecimalAccuracy = 0 179*cdf0e10cSrcweir Case com.sun.star.sdbc.DataType.INTEGER 180*cdf0e10cSrcweir oLocObject.EffectiveMax = 2147483647 181*cdf0e10cSrcweir oLocObject.EffectiveMin = -2147483648 182*cdf0e10cSrcweir Case com.sun.star.sdbc.DataType.SMALLINT 183*cdf0e10cSrcweir oLocObject.EffectiveMax = 32767 184*cdf0e10cSrcweir oLocObject.EffectiveMin = -32768 185*cdf0e10cSrcweir Case com.sun.star.sdbc.DataType.TINYINT 186*cdf0e10cSrcweir oLocObject.EffectiveMax = 127 187*cdf0e10cSrcweir oLocObject.EffectiveMin = -128 188*cdf0e10cSrcweir 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 189*cdf0e10cSrcweir'Todo: oLocObject.DecimalAccuracy = ... 190*cdf0e10cSrcweir oLocObject.EffectiveDefault = CurDefaultValue 191*cdf0e10cSrcweir' Todo: HelpText??? 192*cdf0e10cSrcweir End Select 193*cdf0e10cSrcweir If oLocObject.PropertySetinfo.HasPropertyByName("Width")Then ' Note: an Access AutoincrementField does not provide this property Width 194*cdf0e10cSrcweir oLocObject.Width = CurFieldLength + CurScale + 1 195*cdf0e10cSrcweir End If 196*cdf0e10cSrcweir If CurIsCurrency Then 197*cdf0e10cSrcweir'Todo: How do you set currencies? 198*cdf0e10cSrcweir End If 199*cdf0e10cSrcweir ElseIf CurControlType = cTextBox Then 'com.sun.star.sdbc.DataType.CHAR, com.sun.star.sdbc.DataType.VARCHAR, com.sun.star.sdbc.DataType.LONGVARCHAR 200*cdf0e10cSrcweir If CurFieldLength = 0 Then 'Or oLocObject.MaxTextLen > SBMAXTEXTSIZE 201*cdf0e10cSrcweir oLocObject.MaxTextLen = SBMAXTEXTSIZE 202*cdf0e10cSrcweir CurFieldLength = SBMAXTEXTSIZE 203*cdf0e10cSrcweir Else 204*cdf0e10cSrcweir oLocObject.MaxTextLen = CurFieldLength 205*cdf0e10cSrcweir End If 206*cdf0e10cSrcweir oLocObject.DefaultText = CurDefaultValue 207*cdf0e10cSrcweir ElseIf CurControlType = cDateBox Then 208*cdf0e10cSrcweir' Todo Why does this not work?: oLocObject.DefaultDate = CurDefaultValue 209*cdf0e10cSrcweir ElseIf CurControlType = cTimeBox Then ' com.sun.star.sdbc.DataType.DATE, com.sun.star.sdbc.DataType.TIME 210*cdf0e10cSrcweir oLocObject.DefaultTime = CurDefaultValue 211*cdf0e10cSrcweir' Todo: Property TimeFormat? frome where? 212*cdf0e10cSrcweir ElseIf CurControlType = cCheckBox Then 213*cdf0e10cSrcweir' Todo Why does this not work?: oLocObject.DefautState = CurDefaultValue 214*cdf0e10cSrcweir End If 215*cdf0e10cSrcweir If oLocObject.PropertySetInfo.HasPropertybyName("FormatKey") Then 216*cdf0e10cSrcweir On Local Error Resume Next 217*cdf0e10cSrcweir oLocObject.FormatKey = CurFormatKey 218*cdf0e10cSrcweir End If 219*cdf0e10cSrcweirEnd Function 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir' Destroy all Shapes in Nirwana 223*cdf0e10cSrcweirSub RemoveShapes() 224*cdf0e10cSrcweirDim n as Integer 225*cdf0e10cSrcweirDim oControl as Object 226*cdf0e10cSrcweirDim oShape as Object 227*cdf0e10cSrcweir For n = oDrawPage.Count-1 To 0 Step -1 228*cdf0e10cSrcweir oShape = oDrawPage(n) 229*cdf0e10cSrcweir If oShape.Position.Y > -2000 Then 230*cdf0e10cSrcweir oDrawPage.Remove(oShape) 231*cdf0e10cSrcweir End If 232*cdf0e10cSrcweir Next n 233*cdf0e10cSrcweirEnd Sub 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir' Destroy all Shapes in Nirwana 237*cdf0e10cSrcweirSub RemoveNirwanaShapes() 238*cdf0e10cSrcweirDim n as Integer 239*cdf0e10cSrcweirDim oControl as Object 240*cdf0e10cSrcweirDim oShape as Object 241*cdf0e10cSrcweir For n = oDrawPage.Count-1 To 0 Step -1 242*cdf0e10cSrcweir oShape = oDrawPage(n) 243*cdf0e10cSrcweir If oShape.Position.Y < -2000 Then 244*cdf0e10cSrcweir oDrawPage.Remove(oShape) 245*cdf0e10cSrcweir End If 246*cdf0e10cSrcweir Next n 247*cdf0e10cSrcweirEnd Sub 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir' Note: as Shapes cannot be removed from the DrawPage without destroying 252*cdf0e10cSrcweir' the object we have to park them somewhere beyond the visible area of the page 253*cdf0e10cSrcweirSub ShapesToNirwana() 254*cdf0e10cSrcweirDim n as Integer 255*cdf0e10cSrcweirDim oControl as Object 256*cdf0e10cSrcweir For n = 0 To oDrawPage.Count-1 257*cdf0e10cSrcweir oDrawPage(n).Position = GetPoint(-20, -10000) 258*cdf0e10cSrcweir Next n 259*cdf0e10cSrcweirEnd Sub 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir 262*cdf0e10cSrcweirFunction CalcUniqueContentName(BYVAL oContainer as Object, sBaseName as String) as String 263*cdf0e10cSrcweir 264*cdf0e10cSrcweirDim nPostfix as Integer 265*cdf0e10cSrcweirDim sReturn as String 266*cdf0e10cSrcweir nPostfix = 2 267*cdf0e10cSrcweir sReturn = sBaseName 268*cdf0e10cSrcweir while (oContainer.hasByName(sReturn)) 269*cdf0e10cSrcweir sReturn = sBaseName & nPostfix 270*cdf0e10cSrcweir nPostfix = nPostfix + 1 271*cdf0e10cSrcweir Wend 272*cdf0e10cSrcweir CalcUniqueContentName = sReturn 273*cdf0e10cSrcweirEnd Function 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir 276*cdf0e10cSrcweirFunction CountItemsInArray(BigArray(), SearchItem) 277*cdf0e10cSrcweirDim i as Integer 278*cdf0e10cSrcweirDim MaxIndex as Integer 279*cdf0e10cSrcweirDim ResCount as Integer 280*cdf0e10cSrcweir ResCount = 0 281*cdf0e10cSrcweir MaxIndex = Ubound(BigArray()) 282*cdf0e10cSrcweir For i = 0 To MaxIndex 283*cdf0e10cSrcweir If SearchItem = BigArray(i) Then 284*cdf0e10cSrcweir ResCount = ResCount + 1 285*cdf0e10cSrcweir End If 286*cdf0e10cSrcweir Next i 287*cdf0e10cSrcweir CountItemsInArray() = ResCount 288*cdf0e10cSrcweirEnd Function 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir 291*cdf0e10cSrcweirFunction GetDBHeight(oDBModel as Object) 292*cdf0e10cSrcweir If CurControlType = cImageControl Then 293*cdf0e10cSrcweir nDBHeight = 2000 294*cdf0e10cSrcweir Else 295*cdf0e10cSrcweir If CurFieldType = com.sun.star.sdbc.DataType.LONGVARCHAR Then 296*cdf0e10cSrcweir oDBModel.MultiLine = True 297*cdf0e10cSrcweir nDBHeight = nDBRefHeight * 4 298*cdf0e10cSrcweir Else 299*cdf0e10cSrcweir nDBHeight = nDBRefHeight 300*cdf0e10cSrcweir End If 301*cdf0e10cSrcweir End If 302*cdf0e10cSrcweir GetDBHeight() = nDBHeight 303*cdf0e10cSrcweirEnd Function 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir 306*cdf0e10cSrcweirFunction GetFormWizardPaths() as Boolean 307*cdf0e10cSrcweir FormPath = GetOfficeSubPath("Template","../wizard/bitmap") 308*cdf0e10cSrcweir If FormPath <> "" Then 309*cdf0e10cSrcweir WebWizardPath = GetOfficeSubPath("Template","wizard/web") 310*cdf0e10cSrcweir If WebWizardPath <> "" Then 311*cdf0e10cSrcweir WizardPath = GetOfficeSubPath("Template","wizard/") 312*cdf0e10cSrcweir If Wizardpath <> "" Then 313*cdf0e10cSrcweir TexturePath = GetOfficeSubPath("Gallery", "www-back/") 314*cdf0e10cSrcweir If TexturePath <> "" Then 315*cdf0e10cSrcweir WorkPath = GetPathSettings("Work") 316*cdf0e10cSrcweir If WorkPath <> "" Then 317*cdf0e10cSrcweir TempPath = GetPathSettings("Temp") 318*cdf0e10cSrcweir If TempPath <> "" Then 319*cdf0e10cSrcweir GetFormWizardPaths = True 320*cdf0e10cSrcweir Exit Function 321*cdf0e10cSrcweir End If 322*cdf0e10cSrcweir End If 323*cdf0e10cSrcweir End If 324*cdf0e10cSrcweir End If 325*cdf0e10cSrcweir End If 326*cdf0e10cSrcweir End If 327*cdf0e10cSrcweir DisposeDocument(oDocument) 328*cdf0e10cSrcweir GetFormWizardPaths() = False 329*cdf0e10cSrcweirEnd Function 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir 332*cdf0e10cSrcweirFunction GetFilterName(sApplicationKey as String) as String 333*cdf0e10cSrcweirDim oArgs() 334*cdf0e10cSrcweirDim oFactory 335*cdf0e10cSrcweirDim i as Integer 336*cdf0e10cSrcweirDim Maxindex as Integer 337*cdf0e10cSrcweirDim UIName as String 338*cdf0e10cSrcweir oFactory = createUnoService("com.sun.star.document.FilterFactory") 339*cdf0e10cSrcweir oArgs() = oFactory.getByName(sApplicationKey) 340*cdf0e10cSrcweir MaxIndex = Ubound(oArgs()) 341*cdf0e10cSrcweir For i = 0 to MaxIndex 342*cdf0e10cSrcweir If (oArgs(i).Name="UIName") Then 343*cdf0e10cSrcweir UIName = oArgs(i).Value 344*cdf0e10cSrcweir Exit For 345*cdf0e10cSrcweir End If 346*cdf0e10cSrcweir next i 347*cdf0e10cSrcweir GetFilterName() = UIName 348*cdf0e10cSrcweirEnd Function 349*cdf0e10cSrcweir</script:module> 350