Bump for 3.6-28
[LibreOffice.git] / wizards / source / gimmicks / Userfields.xba
blob391337c6a357de4943d6db2032f1e07d7c0fddf1
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 &apos;Todo: Controlling Scrollbar via Keyboard
6 Public Const SBMAXFIELDINDEX = 14
8 Public DlgUserFields as Object
9 Public oDocument as Object
10 Public UserFieldDataType(SBMAXFIELDINDEX,1) as String
11 Public ScrollBarValue as Integer
12 Public UserFieldFamily(0, SBMAXfIELDINDEX) as String
13 Public Const SBTBCOUNT = 9
14 Public oUserDataAccess as Object
15 Public CurFieldIndex as Integer
16 Public FilePath as String
18 Sub StartChangesUserfields
19 Dim SystemPath as String
20 BasicLibraries.LoadLibrary(&quot;Tools&quot;)
21 UserFieldDatatype(0,0) = &quot;COMPANY&quot;
22 UserFieldDatatype(0,1) = &quot;o&quot;
23 UserFieldDatatype(1,0) = &quot;FIRSTNAME&quot;
24 UserFieldDatatype(1,1) = &quot;givenname&quot;
25 UserFieldDatatype(2,0) = &quot;LASTNAME&quot;
26 UserFieldDatatype(2,1) = &quot;sn&quot;
27 UserFieldDatatype(3,0) = &quot;INITIALS&quot;
28 UserFieldDatatype(3,1) = &quot;initials&quot;
29 UserFieldDatatype(4,0) = &quot;STREET&quot;
30 UserFieldDatatype(4,1) = &quot;street&quot;
31 UserFieldDatatype(5,0) = &quot;COUNTRY&quot;
32 UserFieldDatatype(5,1) = &quot;c&quot;
33 UserFieldDatatype(6,0) = &quot;ZIP&quot;
34 UserFieldDatatype(6,1) = &quot;postalcode&quot;
35 UserFieldDatatype(7,0) = &quot;CITY&quot;
36 UserFieldDatatype(7,1) = &quot;l&quot;
37 UserFieldDatatype(8,0) = &quot;TITLE&quot;
38 UserFieldDatatype(8,1) = &quot;title&quot;
39 UserFieldDatatype(9,0) = &quot;POSITION&quot;
40 UserFieldDatatype(9,1) = &quot;position&quot;
41 UserFieldDatatype(10,0) = &quot;PHONE_HOME&quot;
42 UserFieldDatatype(10,1) = &quot;homephone&quot;
43 UserFieldDatatype(11,0) = &quot;PHONE_WORK&quot;
44 UserFieldDatatype(11,1) = &quot;telephonenumber&quot;
45 UserFieldDatatype(12,0) = &quot;FAX&quot;
46 UserFieldDatatype(12,1) = &quot;facsimiletelephonenumber&quot;
47 UserFieldDatatype(13,0) = &quot;E-MAIL&quot;
48 UserFieldDatatype(13,1) = &quot;mail&quot;
49 UserFieldDatatype(14,0) = &quot;STATE&quot;
50 UserFieldDatatype(14,1) = &quot;st&quot;
51 FilePath = GetPathSettings(&quot;Config&quot;, False) &amp; &quot;/&quot; &amp; &quot;UserData.dat&quot;
52 DlgUserFields = LoadDialog(&quot;Gimmicks&quot;,&quot;UserfieldDlg&quot;)
53 SystemPath = ConvertFromUrl(FilePath)
54 DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, &quot;&apos;&quot; &amp; SystemPath &amp; &quot;&apos;&quot;, &quot;&lt;ConfigDir&gt;&quot;)
55 DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, GetProductName(), &quot;&lt;PRODUCTNAME&gt;&quot;)
56 DlgUserFields.Model.cmdSelect.HelpText = ReplaceString(DlgUserFields.Model.cmdSelect.HelpText, GetProductName(), &quot;&lt;PRODUCTNAME&gt;&quot;)
57 ScrollBarValue = 0
58 oUserDataAccess = GetRegistryKeyContent(&quot;org.openoffice.UserProfile/Data&quot;, True)
59 InitializeUserFamily()
60 FillDialog()
61 DlgUserFields.Execute
62 DlgUserFields.Dispose()
63 End Sub
66 Sub FillDialog()
67 Dim a as Integer
68 With DlgUserFields
69 For a = 1 To SBTBCount
70 .GetControl(&quot;Label&quot; &amp; a).Model.Label = UserFieldDataType(a-1,0)
71 .GetControl(&quot;TextField&quot; &amp; 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
78 End Sub
81 Sub ScrollControls()
82 ScrollTextFieldInfo(ScrollBarValue)
83 ScrollBarValue = DlgUserFields.Model.ScrollBar1.ScrollValue
84 If (ScrollBarValue + SBTBCOUNT) &gt;= SBMAXFIELDINDEX + 1 Then
85 ScrollBarValue = (SBMAXFIELDINDEX + 1) - SBTBCOUNT
86 End If
87 FillupTextFields()
88 End Sub
91 Sub ScrollTextFieldInfo(ByVal iScrollValue as Integer)
92 Dim a as Integer
93 Dim CurIndex as Integer
94 For a = 1 To SBTBCOUNT
95 CurIndex = (a-1) + iScrollValue
96 UserFieldFamily(CurFieldIndex,CurIndex) = DlgUserFields.GetControl(&quot;TextField&quot; &amp; a).Model.Text
97 Next a
98 End Sub
101 Sub StopMacro()
102 DlgUserFields.EndExecute
103 End Sub
106 Sub SaveSettings()
107 Dim n as Integer
108 Dim m as Integer
109 Dim 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) = &quot;&quot;
115 For m = 0 To SBMAXFIELDINDEX
116 FileStrings(n) = FileStrings(n) &amp; UserFieldFamily(n,m) &amp; &quot;;&quot;
117 Next m
118 Next n
119 SaveDataToFile(FilePath, FileStrings(), True)
120 End Sub
123 Sub ToggleButtons(ByVal Index as Integer)
124 Dim i as Integer
125 CurFieldIndex = Index
126 DlgUserFields.Model.cmdNextUser.Enabled = CurFieldIndex &lt;&gt; Ubound(UserFieldFamily(), 1)
127 DlgUserFields.Model.cmdPrevUser.Enabled = CurFieldIndex &lt;&gt; 0
128 End Sub
131 Sub InitializeUserFamily()
132 Dim FirstIndex as Integer
133 Dim UserFieldstrings() as String
134 Dim LocStrings() as String
135 Dim bFileExists as Boolean
136 Dim n as Integer
137 Dim m as Integer
138 bFileExists = LoadDataFromFile(GetPathSettings(&quot;Config&quot;, False) &amp; &quot;/&quot; &amp; &quot;UserData.dat&quot;, 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), &quot;;&quot;)
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)
155 End Sub
158 Sub AddRecord()
159 Dim i as Integer
160 Dim MaxIndex as Integer
161 For i = 1 To SBTBCount
162 DlgUserFields.GetControl(&quot;TextField&quot; &amp; i).Model.Text = &quot;&quot;
163 Next i
164 MaxIndex = Ubound(UserFieldFamily(),1)
165 ReDim Preserve UserFieldFamily(MaxIndex + 1, SBMAXFIELDINDEX) as String
166 ToggleButtons(MaxIndex + 1, 1)
167 End Sub
170 Sub FillupTextFields()
171 Dim a as Integer
172 Dim CurIndex as Integer
173 For a = 1 To SBTBCOUNT
174 CurIndex = (a-1) + ScrollBarValue
175 DlgUserFields.GetControl(&quot;Label&quot; &amp; a).Model.Label = UserFieldDataType(CurIndex,0)
176 DlgUserFields.GetControl(&quot;TextField&quot; &amp; a).Model.Text = UserFieldFamily(CurFieldIndex, CurIndex)
177 Next a
178 End Sub
181 Sub StepToRecord(aEvent as Object)
182 Dim iStep as Integer
183 iStep = CInt(aEvent.Source.Model.Tag)
184 ScrollTextFieldInfo(ScrollBarValue)
185 ToggleButtons(CurFieldIndex + iStep)
186 FillUpTextFields()
187 End Sub
190 Sub SelectCurrentFields()
191 Dim MaxIndex as Integer
192 Dim 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()
199 End Sub
202 Sub DeleteCurrentSettings()
203 Dim n as Integer
204 Dim m as Integer
205 Dim MaxIndex as Integer
206 MaxIndex = Ubound(UserFieldFamily(),1)
207 If CurFieldIndex &lt; 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)
219 End Sub</script:module>