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