xref: /AOO41X/main/wizards/source/gimmicks/Userfields.xba (revision ff0525f24f03981d56b7579b645949f111420994)
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&apos;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(&quot;Tools&quot;)
41    UserFieldDatatype(0,0) = &quot;COMPANY&quot;
42    UserFieldDatatype(0,1) = &quot;o&quot;
43    UserFieldDatatype(1,0) = &quot;FIRSTNAME&quot;
44    UserFieldDatatype(1,1) = &quot;givenname&quot;
45    UserFieldDatatype(2,0) = &quot;LASTNAME&quot;
46    UserFieldDatatype(2,1) = &quot;sn&quot;
47    UserFieldDatatype(3,0) = &quot;INITIALS&quot;
48    UserFieldDatatype(3,1) = &quot;initials&quot;
49    UserFieldDatatype(4,0) = &quot;STREET&quot;
50    UserFieldDatatype(4,1) = &quot;street&quot;
51    UserFieldDatatype(5,0) = &quot;COUNTRY&quot;
52    UserFieldDatatype(5,1) = &quot;c&quot;
53    UserFieldDatatype(6,0) = &quot;ZIP&quot;
54    UserFieldDatatype(6,1) = &quot;postalcode&quot;
55    UserFieldDatatype(7,0) = &quot;CITY&quot;
56    UserFieldDatatype(7,1) = &quot;l&quot;
57    UserFieldDatatype(8,0) = &quot;TITLE&quot;
58    UserFieldDatatype(8,1) = &quot;title&quot;
59    UserFieldDatatype(9,0) = &quot;POSITION&quot;
60    UserFieldDatatype(9,1) = &quot;position&quot;
61    UserFieldDatatype(10,0) = &quot;PHONE_HOME&quot;
62    UserFieldDatatype(10,1) = &quot;homephone&quot;
63    UserFieldDatatype(11,0) = &quot;PHONE_WORK&quot;
64    UserFieldDatatype(11,1) = &quot;telephonenumber&quot;
65    UserFieldDatatype(12,0) = &quot;FAX&quot;
66    UserFieldDatatype(12,1) = &quot;facsimiletelephonenumber&quot;
67    UserFieldDatatype(13,0) = &quot;E-MAIL&quot;
68    UserFieldDatatype(13,1) = &quot;mail&quot;
69    UserFieldDatatype(14,0) = &quot;STATE&quot;
70    UserFieldDatatype(14,1) = &quot;st&quot;
71    FilePath = GetPathSettings(&quot;Config&quot;, False) &amp; &quot;/&quot; &amp; &quot;UserData.dat&quot;
72    DlgUserFields = LoadDialog(&quot;Gimmicks&quot;,&quot;UserfieldDlg&quot;)
73    SystemPath = ConvertFromUrl(FilePath)
74    DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, &quot;&apos;&quot; &amp; SystemPath &amp; &quot;&apos;&quot;, &quot;&lt;ConfigDir&gt;&quot;)
75    DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, GetProductName(), &quot;&lt;PRODUCTNAME&gt;&quot;)
76    DlgUserFields.Model.cmdSelect.HelpText = ReplaceString(DlgUserFields.Model.cmdSelect.HelpText, GetProductName(), &quot;&lt;PRODUCTNAME&gt;&quot;)
77    ScrollBarValue = 0
78    oUserDataAccess = GetRegistryKeyContent(&quot;org.openoffice.UserProfile/Data&quot;, 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(&quot;Label&quot; &amp; a).Model.Label = UserFieldDataType(a-1,0)
91            .GetControl(&quot;TextField&quot; &amp; 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) &gt;= 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(&quot;TextField&quot; &amp; 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) = &quot;&quot;
135        For m = 0 To SBMAXFIELDINDEX
136            FileStrings(n) = FileStrings(n) &amp; UserFieldFamily(n,m) &amp; &quot;;&quot;
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 &lt;&gt; Ubound(UserFieldFamily(), 1)
147    DlgUserFields.Model.cmdPrevUser.Enabled = CurFieldIndex &lt;&gt; 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(&quot;Config&quot;, False) &amp; &quot;/&quot; &amp; &quot;UserData.dat&quot;, 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), &quot;;&quot;)
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(&quot;TextField&quot; &amp; i).Model.Text = &quot;&quot;
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(&quot;Label&quot; &amp; a).Model.Label = UserFieldDataType(CurIndex,0)
196        DlgUserFields.GetControl(&quot;TextField&quot; &amp; 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 &lt; 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