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="Userfields" script:language="StarBasic">Option Explicit 4'Todo: Controlling Scrollbar via Keyboard 5 6Public Const SBMAXFIELDINDEX = 14 7 8Public DlgUserFields as Object 9Public oDocument as Object 10Public UserFieldDataType(SBMAXFIELDINDEX,1) as String 11Public ScrollBarValue as Integer 12Public UserFieldFamily(0, SBMAXfIELDINDEX) as String 13Public Const SBTBCOUNT = 9 14Public oUserDataAccess as Object 15Public CurFieldIndex as Integer 16Public FilePath as String 17 18Sub StartChangesUserfields 19Dim SystemPath as String 20 BasicLibraries.LoadLibrary("Tools") 21 UserFieldDatatype(0,0) = "COMPANY" 22 UserFieldDatatype(0,1) = "o" 23 UserFieldDatatype(1,0) = "FIRSTNAME" 24 UserFieldDatatype(1,1) = "givenname" 25 UserFieldDatatype(2,0) = "LASTNAME" 26 UserFieldDatatype(2,1) = "sn" 27 UserFieldDatatype(3,0) = "INITIALS" 28 UserFieldDatatype(3,1) = "initials" 29 UserFieldDatatype(4,0) = "STREET" 30 UserFieldDatatype(4,1) = "street" 31 UserFieldDatatype(5,0) = "COUNTRY" 32 UserFieldDatatype(5,1) = "c" 33 UserFieldDatatype(6,0) = "ZIP" 34 UserFieldDatatype(6,1) = "postalcode" 35 UserFieldDatatype(7,0) = "CITY" 36 UserFieldDatatype(7,1) = "l" 37 UserFieldDatatype(8,0) = "TITLE" 38 UserFieldDatatype(8,1) = "title" 39 UserFieldDatatype(9,0) = "POSITION" 40 UserFieldDatatype(9,1) = "position" 41 UserFieldDatatype(10,0) = "PHONE_HOME" 42 UserFieldDatatype(10,1) = "homephone" 43 UserFieldDatatype(11,0) = "PHONE_WORK" 44 UserFieldDatatype(11,1) = "telephonenumber" 45 UserFieldDatatype(12,0) = "FAX" 46 UserFieldDatatype(12,1) = "facsimiletelephonenumber" 47 UserFieldDatatype(13,0) = "E-MAIL" 48 UserFieldDatatype(13,1) = "mail" 49 UserFieldDatatype(14,0) = "STATE" 50 UserFieldDatatype(14,1) = "st" 51 FilePath = GetPathSettings("Config", False) & "/" & "UserData.dat" 52 DlgUserFields = LoadDialog("Gimmicks","UserfieldDlg") 53 SystemPath = ConvertFromUrl(FilePath) 54 DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, "'" & SystemPath & "'", "<ConfigDir>") 55 DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, GetProductName(), "<PRODUCTNAME>") 56 DlgUserFields.Model.cmdSelect.HelpText = ReplaceString(DlgUserFields.Model.cmdSelect.HelpText, GetProductName(), "<PRODUCTNAME>") 57 ScrollBarValue = 0 58 oUserDataAccess = GetRegistryKeyContent("org.openoffice.UserProfile/Data", True) 59 InitializeUserFamily() 60 FillDialog() 61 DlgUserFields.Execute 62 DlgUserFields.Dispose() 63End Sub 64 65 66Sub FillDialog() 67Dim a as Integer 68 With DlgUserFields 69 For a = 1 To SBTBCount 70 .GetControl("Label" & a).Model.Label = UserFieldDataType(a-1,0) 71 .GetControl("TextField" & a).Model.Text = UserFieldFamily(CurFieldIndex, a-1) 72 Next a 73 .Model.ScrollBar1.ScrollValueMax = (SBMAXFIELDINDEX+1) - SBTBCOUNT 74 .Model.ScrollBar1.BlockIncrement = SBTBCOUNT 75 .Model.ScrollBar1.LineIncrement = 1 76 .Model.ScrollBar1.ScrollValue = ScrollBarValue 77 End With 78End Sub 79 80 81Sub ScrollControls() 82 ScrollTextFieldInfo(ScrollBarValue) 83 ScrollBarValue = DlgUserFields.Model.ScrollBar1.ScrollValue 84 If (ScrollBarValue + SBTBCOUNT) >= SBMAXFIELDINDEX + 1 Then 85 ScrollBarValue = (SBMAXFIELDINDEX + 1) - SBTBCOUNT 86 End If 87 FillupTextFields() 88End Sub 89 90 91Sub ScrollTextFieldInfo(ByVal iScrollValue as Integer) 92Dim a as Integer 93Dim CurIndex as Integer 94 For a = 1 To SBTBCOUNT 95 CurIndex = (a-1) + iScrollValue 96 UserFieldFamily(CurFieldIndex,CurIndex) = DlgUserFields.GetControl("TextField" & a).Model.Text 97 Next a 98End Sub 99 100 101Sub StopMacro() 102 DlgUserFields.EndExecute 103End Sub 104 105 106Sub SaveSettings() 107Dim n as Integer 108Dim m as Integer 109Dim MaxIndex as Integer 110 ScrollTextFieldInfo(DlgUserFields.Model.ScrollBar1.ScrollValue) 111 MaxIndex = Ubound(UserFieldFamily(), 1) 112 Dim FileStrings(MaxIndex) as String 113 For n = 0 To MaxIndex 114 FileStrings(n) = "" 115 For m = 0 To SBMAXFIELDINDEX 116 FileStrings(n) = FileStrings(n) & UserFieldFamily(n,m) & ";" 117 Next m 118 Next n 119 SaveDataToFile(FilePath, FileStrings(), True) 120End Sub 121 122 123Sub ToggleButtons(ByVal Index as Integer) 124Dim i as Integer 125 CurFieldIndex = Index 126 DlgUserFields.Model.cmdNextUser.Enabled = CurFieldIndex <> Ubound(UserFieldFamily(), 1) 127 DlgUserFields.Model.cmdPrevUser.Enabled = CurFieldIndex <> 0 128End Sub 129 130 131Sub InitializeUserFamily() 132Dim FirstIndex as Integer 133Dim UserFieldstrings() as String 134Dim LocStrings() as String 135Dim bFileExists as Boolean 136Dim n as Integer 137Dim m as Integer 138 bFileExists = LoadDataFromFile(GetPathSettings("Config", False) & "/" & "UserData.dat", UserFieldStrings()) 139 If bFileExists Then 140 FirstIndex = Ubound(UserFieldStrings()) 141 ReDim Preserve UserFieldFamily(FirstIndex, SBMAXFIELDINDEX) as String 142 For n = 0 To FirstIndex 143 LocStrings() = ArrayOutofString(UserFieldStrings(n), ";") 144 For m = 0 To SBMAXFIELDINDEX 145 UserFieldFamily(n,m) = LocStrings(m) 146 Next m 147 Next n 148 Else 149 ReDim Preserve UserFieldFamily(0,SBMAXFIELDINDEX) as String 150 For m = 0 To SBMAXFIELDINDEX 151 UserFieldFamily(0,m) = oUserDataAccess.GetByName(UserFieldDataType(m,1)) 152 Next m 153 End If 154 ToggleButtons(0) 155End Sub 156 157 158Sub AddRecord() 159Dim i as Integer 160Dim MaxIndex as Integer 161 For i = 1 To SBTBCount 162 DlgUserFields.GetControl("TextField" & i).Model.Text = "" 163 Next i 164 MaxIndex = Ubound(UserFieldFamily(),1) 165 ReDim Preserve UserFieldFamily(MaxIndex + 1, SBMAXFIELDINDEX) as String 166 ToggleButtons(MaxIndex + 1, 1) 167End Sub 168 169 170Sub FillupTextFields() 171Dim a as Integer 172Dim CurIndex as Integer 173 For a = 1 To SBTBCOUNT 174 CurIndex = (a-1) + ScrollBarValue 175 DlgUserFields.GetControl("Label" & a).Model.Label = UserFieldDataType(CurIndex,0) 176 DlgUserFields.GetControl("TextField" & a).Model.Text = UserFieldFamily(CurFieldIndex, CurIndex) 177 Next a 178End Sub 179 180 181Sub StepToRecord(aEvent as Object) 182Dim iStep as Integer 183 iStep = CInt(aEvent.Source.Model.Tag) 184 ScrollTextFieldInfo(ScrollBarValue) 185 ToggleButtons(CurFieldIndex + iStep) 186 FillUpTextFields() 187End Sub 188 189 190Sub SelectCurrentFields() 191Dim MaxIndex as Integer 192Dim i as Integer 193 ScrollTextFieldInfo(ScrollBarValue) 194 MaxIndex = Ubound(UserFieldFamily(),2) 195 For i = 0 To MaxIndex 196 oUserDataAccess.ReplaceByName(UserFieldDataType(i,1), UserFieldFamily(CurFieldIndex, i)) 197 Next i 198 oUserDataAccess.commitChanges() 199End Sub 200 201 202Sub DeleteCurrentSettings() 203Dim n as Integer 204Dim m as Integer 205Dim MaxIndex as Integer 206 MaxIndex = Ubound(UserFieldFamily(),1) 207 If CurFieldIndex < MaxIndex Then 208 For n = CurFieldIndex To MaxIndex - 1 209 For m = 0 To SBMAXFIELDINDEX 210 UserFieldFamily(n,m) = UserFieldFamily(n + 1,m) 211 Next m 212 Next n 213 Else 214 CurFieldIndex = MaxIndex - 1 215 End If 216 ReDim Preserve UserFieldFamily(MaxIndex-1, SBMAXfIELDINDEX) as String 217 FillupTextFields() 218 ToggleButtons(CurFieldIndex) 219End Sub</script:module>