1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<!--*********************************************************** 4 * 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 * 22 ***********************************************************--> 23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Userfields" script:language="StarBasic">Option Explicit 24'Todo: Controlling Scrollbar via Keyboard 25 26Public Const SBMAXFIELDINDEX = 14 27 28Public DlgUserFields as Object 29Public oDocument as Object 30Public UserFieldDataType(SBMAXFIELDINDEX,1) as String 31Public ScrollBarValue as Integer 32Public UserFieldFamily(0, SBMAXfIELDINDEX) as String 33Public Const SBTBCOUNT = 9 34Public oUserDataAccess as Object 35Public CurFieldIndex as Integer 36Public FilePath as String 37 38Sub StartChangesUserfields 39Dim SystemPath as String 40 BasicLibraries.LoadLibrary("Tools") 41 UserFieldDatatype(0,0) = "COMPANY" 42 UserFieldDatatype(0,1) = "o" 43 UserFieldDatatype(1,0) = "FIRSTNAME" 44 UserFieldDatatype(1,1) = "givenname" 45 UserFieldDatatype(2,0) = "LASTNAME" 46 UserFieldDatatype(2,1) = "sn" 47 UserFieldDatatype(3,0) = "INITIALS" 48 UserFieldDatatype(3,1) = "initials" 49 UserFieldDatatype(4,0) = "STREET" 50 UserFieldDatatype(4,1) = "street" 51 UserFieldDatatype(5,0) = "COUNTRY" 52 UserFieldDatatype(5,1) = "c" 53 UserFieldDatatype(6,0) = "ZIP" 54 UserFieldDatatype(6,1) = "postalcode" 55 UserFieldDatatype(7,0) = "CITY" 56 UserFieldDatatype(7,1) = "l" 57 UserFieldDatatype(8,0) = "TITLE" 58 UserFieldDatatype(8,1) = "title" 59 UserFieldDatatype(9,0) = "POSITION" 60 UserFieldDatatype(9,1) = "position" 61 UserFieldDatatype(10,0) = "PHONE_HOME" 62 UserFieldDatatype(10,1) = "homephone" 63 UserFieldDatatype(11,0) = "PHONE_WORK" 64 UserFieldDatatype(11,1) = "telephonenumber" 65 UserFieldDatatype(12,0) = "FAX" 66 UserFieldDatatype(12,1) = "facsimiletelephonenumber" 67 UserFieldDatatype(13,0) = "E-MAIL" 68 UserFieldDatatype(13,1) = "mail" 69 UserFieldDatatype(14,0) = "STATE" 70 UserFieldDatatype(14,1) = "st" 71 FilePath = GetPathSettings("Config", False) & "/" & "UserData.dat" 72 DlgUserFields = LoadDialog("Gimmicks","UserfieldDlg") 73 SystemPath = ConvertFromUrl(FilePath) 74 DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, "'" & SystemPath & "'", "<ConfigDir>") 75 DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, GetProductName(), "<PRODUCTNAME>") 76 DlgUserFields.Model.cmdSelect.HelpText = ReplaceString(DlgUserFields.Model.cmdSelect.HelpText, GetProductName(), "<PRODUCTNAME>") 77 ScrollBarValue = 0 78 oUserDataAccess = GetRegistryKeyContent("org.openoffice.UserProfile/Data", True) 79 InitializeUserFamily() 80 FillDialog() 81 DlgUserFields.Execute 82 DlgUserFields.Dispose() 83End Sub 84 85 86Sub FillDialog() 87Dim a as Integer 88 With DlgUserFields 89 For a = 1 To SBTBCount 90 .GetControl("Label" & a).Model.Label = UserFieldDataType(a-1,0) 91 .GetControl("TextField" & a).Model.Text = UserFieldFamily(CurFieldIndex, a-1) 92 Next a 93 .Model.ScrollBar1.ScrollValueMax = (SBMAXFIELDINDEX+1) - SBTBCOUNT 94 .Model.ScrollBar1.BlockIncrement = SBTBCOUNT 95 .Model.ScrollBar1.LineIncrement = 1 96 .Model.ScrollBar1.ScrollValue = ScrollBarValue 97 End With 98End Sub 99 100 101Sub ScrollControls() 102 ScrollTextFieldInfo(ScrollBarValue) 103 ScrollBarValue = DlgUserFields.Model.ScrollBar1.ScrollValue 104 If (ScrollBarValue + SBTBCOUNT) >= SBMAXFIELDINDEX + 1 Then 105 ScrollBarValue = (SBMAXFIELDINDEX + 1) - SBTBCOUNT 106 End If 107 FillupTextFields() 108End Sub 109 110 111Sub ScrollTextFieldInfo(ByVal iScrollValue as Integer) 112Dim a as Integer 113Dim CurIndex as Integer 114 For a = 1 To SBTBCOUNT 115 CurIndex = (a-1) + iScrollValue 116 UserFieldFamily(CurFieldIndex,CurIndex) = DlgUserFields.GetControl("TextField" & a).Model.Text 117 Next a 118End Sub 119 120 121Sub StopMacro() 122 DlgUserFields.EndExecute 123End Sub 124 125 126Sub SaveSettings() 127Dim n as Integer 128Dim m as Integer 129Dim MaxIndex as Integer 130 ScrollTextFieldInfo(DlgUserFields.Model.ScrollBar1.ScrollValue) 131 MaxIndex = Ubound(UserFieldFamily(), 1) 132 Dim FileStrings(MaxIndex) as String 133 For n = 0 To MaxIndex 134 FileStrings(n) = "" 135 For m = 0 To SBMAXFIELDINDEX 136 FileStrings(n) = FileStrings(n) & UserFieldFamily(n,m) & ";" 137 Next m 138 Next n 139 SaveDataToFile(FilePath, FileStrings(), True) 140End Sub 141 142 143Sub ToggleButtons(ByVal Index as Integer) 144Dim i as Integer 145 CurFieldIndex = Index 146 DlgUserFields.Model.cmdNextUser.Enabled = CurFieldIndex <> Ubound(UserFieldFamily(), 1) 147 DlgUserFields.Model.cmdPrevUser.Enabled = CurFieldIndex <> 0 148End Sub 149 150 151Sub InitializeUserFamily() 152Dim FirstIndex as Integer 153Dim UserFieldstrings() as String 154Dim LocStrings() as String 155Dim bFileExists as Boolean 156Dim n as Integer 157Dim m as Integer 158 bFileExists = LoadDataFromFile(GetPathSettings("Config", False) & "/" & "UserData.dat", UserFieldStrings()) 159 If bFileExists Then 160 FirstIndex = Ubound(UserFieldStrings()) 161 ReDim Preserve UserFieldFamily(FirstIndex, SBMAXFIELDINDEX) as String 162 For n = 0 To FirstIndex 163 LocStrings() = ArrayOutofString(UserFieldStrings(n), ";") 164 For m = 0 To SBMAXFIELDINDEX 165 UserFieldFamily(n,m) = LocStrings(m) 166 Next m 167 Next n 168 Else 169 ReDim Preserve UserFieldFamily(0,SBMAXFIELDINDEX) as String 170 For m = 0 To SBMAXFIELDINDEX 171 UserFieldFamily(0,m) = oUserDataAccess.GetByName(UserFieldDataType(m,1)) 172 Next m 173 End If 174 ToggleButtons(0) 175End Sub 176 177 178Sub AddRecord() 179Dim i as Integer 180Dim MaxIndex as Integer 181 For i = 1 To SBTBCount 182 DlgUserFields.GetControl("TextField" & i).Model.Text = "" 183 Next i 184 MaxIndex = Ubound(UserFieldFamily(),1) 185 ReDim Preserve UserFieldFamily(MaxIndex + 1, SBMAXFIELDINDEX) as String 186 ToggleButtons(MaxIndex + 1, 1) 187End Sub 188 189 190Sub FillupTextFields() 191Dim a as Integer 192Dim CurIndex as Integer 193 For a = 1 To SBTBCOUNT 194 CurIndex = (a-1) + ScrollBarValue 195 DlgUserFields.GetControl("Label" & a).Model.Label = UserFieldDataType(CurIndex,0) 196 DlgUserFields.GetControl("TextField" & a).Model.Text = UserFieldFamily(CurFieldIndex, CurIndex) 197 Next a 198End Sub 199 200 201Sub StepToRecord(aEvent as Object) 202Dim iStep as Integer 203 iStep = CInt(aEvent.Source.Model.Tag) 204 ScrollTextFieldInfo(ScrollBarValue) 205 ToggleButtons(CurFieldIndex + iStep) 206 FillUpTextFields() 207End Sub 208 209 210Sub SelectCurrentFields() 211Dim MaxIndex as Integer 212Dim i as Integer 213 ScrollTextFieldInfo(ScrollBarValue) 214 MaxIndex = Ubound(UserFieldFamily(),2) 215 For i = 0 To MaxIndex 216 oUserDataAccess.ReplaceByName(UserFieldDataType(i,1), UserFieldFamily(CurFieldIndex, i)) 217 Next i 218 oUserDataAccess.commitChanges() 219End Sub 220 221 222Sub DeleteCurrentSettings() 223Dim n as Integer 224Dim m as Integer 225Dim MaxIndex as Integer 226 MaxIndex = Ubound(UserFieldFamily(),1) 227 If CurFieldIndex < MaxIndex Then 228 For n = CurFieldIndex To MaxIndex - 1 229 For m = 0 To SBMAXFIELDINDEX 230 UserFieldFamily(n,m) = UserFieldFamily(n + 1,m) 231 Next m 232 Next n 233 Else 234 CurFieldIndex = MaxIndex - 1 235 End If 236 ReDim Preserve UserFieldFamily(MaxIndex-1, SBMAXfIELDINDEX) as String 237 FillupTextFields() 238 ToggleButtons(CurFieldIndex) 239End Sub</script:module> 240