summaryrefslogtreecommitdiffstats
path: root/wizards/source/gimmicks/Userfields.xba
blob: 17426cb49b08d19f9b66debfb047bb31c6447b52 (plain)
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
&apos;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(&quot;Tools&quot;)
	UserFieldDatatype(0,0) = &quot;COMPANY&quot;
	UserFieldDatatype(0,1) = &quot;o&quot;
	UserFieldDatatype(1,0) = &quot;FIRSTNAME&quot;
	UserFieldDatatype(1,1) = &quot;givenname&quot;
	UserFieldDatatype(2,0) = &quot;LASTNAME&quot;
	UserFieldDatatype(2,1) = &quot;sn&quot;
	UserFieldDatatype(3,0) = &quot;INITIALS&quot;
	UserFieldDatatype(3,1) = &quot;initials&quot;
	UserFieldDatatype(4,0) = &quot;STREET&quot;
	UserFieldDatatype(4,1) = &quot;street&quot;
	UserFieldDatatype(5,0) = &quot;COUNTRY&quot;
	UserFieldDatatype(5,1) = &quot;c&quot;
	UserFieldDatatype(6,0) = &quot;ZIP&quot;
	UserFieldDatatype(6,1) = &quot;postalcode&quot;
	UserFieldDatatype(7,0) = &quot;CITY&quot;
	UserFieldDatatype(7,1) = &quot;l&quot;
	UserFieldDatatype(8,0) = &quot;TITLE&quot;
	UserFieldDatatype(8,1) = &quot;title&quot;
	UserFieldDatatype(9,0) = &quot;POSITION&quot;
	UserFieldDatatype(9,1) = &quot;position&quot;
	UserFieldDatatype(10,0) = &quot;PHONE_HOME&quot;
	UserFieldDatatype(10,1) = &quot;homephone&quot;
	UserFieldDatatype(11,0) = &quot;PHONE_WORK&quot;
	UserFieldDatatype(11,1) = &quot;telephonenumber&quot;
	UserFieldDatatype(12,0) = &quot;FAX&quot;
	UserFieldDatatype(12,1) = &quot;facsimiletelephonenumber&quot;
	UserFieldDatatype(13,0) = &quot;E-MAIL&quot;
	UserFieldDatatype(13,1) = &quot;mail&quot;
	UserFieldDatatype(14,0) = &quot;STATE&quot;
	UserFieldDatatype(14,1) = &quot;st&quot;
	FilePath = GetPathSettings(&quot;Config&quot;, False) &amp; &quot;/&quot; &amp; &quot;UserData.dat&quot;
	DlgUserFields = LoadDialog(&quot;Gimmicks&quot;,&quot;UserfieldDlg&quot;)
	SystemPath = ConvertFromUrl(FilePath)
	DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, &quot;&apos;&quot; &amp; SystemPath &amp; &quot;&apos;&quot;, &quot;&lt;ConfigDir&gt;&quot;)
	DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, GetProductName(), &quot;&lt;PRODUCTNAME&gt;&quot;)
	DlgUserFields.Model.cmdSelect.HelpText = ReplaceString(DlgUserFields.Model.cmdSelect.HelpText, GetProductName(), &quot;&lt;PRODUCTNAME&gt;&quot;)
	ScrollBarValue = 0
	oUserDataAccess = GetRegistryKeyContent(&quot;org.openoffice.UserProfile/Data&quot;, True)
	InitializeUserFamily()
	FillDialog()
	DlgUserFields.Execute
	DlgUserFields.Dispose()
End Sub


Sub FillDialog()
Dim a as Integer
	With DlgUserFields
		For a = 1 To SBTBCount
			.GetControl(&quot;Label&quot; &amp; a).Model.Label = UserFieldDataType(a-1,0)
			.GetControl(&quot;TextField&quot; &amp; 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) &gt;= 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(&quot;TextField&quot; &amp; 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) = &quot;&quot;
		For m = 0 To SBMAXFIELDINDEX
			FileStrings(n) = FileStrings(n) &amp; UserFieldFamily(n,m) &amp; &quot;;&quot;
		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 &lt;&gt; Ubound(UserFieldFamily(), 1)
	DlgUserFields.Model.cmdPrevUser.Enabled = CurFieldIndex &lt;&gt; 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(&quot;Config&quot;, False) &amp; &quot;/&quot; &amp; &quot;UserData.dat&quot;, UserFieldStrings())
	If bFileExists Then
		FirstIndex = Ubound(UserFieldStrings())
		ReDim Preserve UserFieldFamily(FirstIndex, SBMAXFIELDINDEX) as String
		For n = 0 To FirstIndex
			LocStrings() = ArrayOutofString(UserFieldStrings(n), &quot;;&quot;)
			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(&quot;TextField&quot; &amp; i).Model.Text = &quot;&quot;
	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(&quot;Label&quot; &amp; a).Model.Label = UserFieldDataType(CurIndex,0)
		DlgUserFields.GetControl(&quot;TextField&quot; &amp; 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 &lt; 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>