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