Userfields.xba 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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.
  5. *
  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/.
  9. *
  10. * This file incorporates work covered by the following license notice:
  11. *
  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
  22. Public Const SBMAXFIELDINDEX = 14
  23. Public DlgUserFields as Object
  24. Public oDocument as Object
  25. Public UserFieldDataType(SBMAXFIELDINDEX,1) as String
  26. Public ScrollBarValue as Integer
  27. Public UserFieldFamily(0, SBMAXfIELDINDEX) as String
  28. Public Const SBTBCOUNT = 9
  29. Public oUserDataAccess as Object
  30. Public CurFieldIndex as Integer
  31. Public FilePath as String
  32. Sub StartChangesUserfields
  33. Dim SystemPath as String
  34. BasicLibraries.LoadLibrary(&quot;Tools&quot;)
  35. UserFieldDatatype(0,0) = &quot;COMPANY&quot;
  36. UserFieldDatatype(0,1) = &quot;o&quot;
  37. UserFieldDatatype(1,0) = &quot;FIRSTNAME&quot;
  38. UserFieldDatatype(1,1) = &quot;givenname&quot;
  39. UserFieldDatatype(2,0) = &quot;LASTNAME&quot;
  40. UserFieldDatatype(2,1) = &quot;sn&quot;
  41. UserFieldDatatype(3,0) = &quot;INITIALS&quot;
  42. UserFieldDatatype(3,1) = &quot;initials&quot;
  43. UserFieldDatatype(4,0) = &quot;STREET&quot;
  44. UserFieldDatatype(4,1) = &quot;street&quot;
  45. UserFieldDatatype(5,0) = &quot;COUNTRY&quot;
  46. UserFieldDatatype(5,1) = &quot;c&quot;
  47. UserFieldDatatype(6,0) = &quot;ZIP&quot;
  48. UserFieldDatatype(6,1) = &quot;postalcode&quot;
  49. UserFieldDatatype(7,0) = &quot;CITY&quot;
  50. UserFieldDatatype(7,1) = &quot;l&quot;
  51. UserFieldDatatype(8,0) = &quot;TITLE&quot;
  52. UserFieldDatatype(8,1) = &quot;title&quot;
  53. UserFieldDatatype(9,0) = &quot;POSITION&quot;
  54. UserFieldDatatype(9,1) = &quot;position&quot;
  55. UserFieldDatatype(10,0) = &quot;PHONE_HOME&quot;
  56. UserFieldDatatype(10,1) = &quot;homephone&quot;
  57. UserFieldDatatype(11,0) = &quot;PHONE_WORK&quot;
  58. UserFieldDatatype(11,1) = &quot;telephonenumber&quot;
  59. UserFieldDatatype(12,0) = &quot;FAX&quot;
  60. UserFieldDatatype(12,1) = &quot;facsimiletelephonenumber&quot;
  61. UserFieldDatatype(13,0) = &quot;E-MAIL&quot;
  62. UserFieldDatatype(13,1) = &quot;mail&quot;
  63. UserFieldDatatype(14,0) = &quot;STATE&quot;
  64. UserFieldDatatype(14,1) = &quot;st&quot;
  65. FilePath = GetPathSettings(&quot;Config&quot;, False) &amp; &quot;/&quot; &amp; &quot;UserData.dat&quot;
  66. DlgUserFields = LoadDialog(&quot;Gimmicks&quot;,&quot;UserfieldDlg&quot;)
  67. SystemPath = ConvertFromUrl(FilePath)
  68. DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, &quot;&apos;&quot; &amp; SystemPath &amp; &quot;&apos;&quot;, &quot;&lt;ConfigDir&gt;&quot;)
  69. DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, GetProductName(), &quot;&lt;PRODUCTNAME&gt;&quot;)
  70. DlgUserFields.Model.cmdSelect.HelpText = ReplaceString(DlgUserFields.Model.cmdSelect.HelpText, GetProductName(), &quot;&lt;PRODUCTNAME&gt;&quot;)
  71. ScrollBarValue = 0
  72. oUserDataAccess = GetRegistryKeyContent(&quot;org.openoffice.UserProfile/Data&quot;, True)
  73. InitializeUserFamily()
  74. FillDialog()
  75. DlgUserFields.Execute
  76. DlgUserFields.Dispose()
  77. End Sub
  78. Sub FillDialog()
  79. Dim a as Integer
  80. With DlgUserFields
  81. For a = 1 To SBTBCount
  82. .GetControl(&quot;Label&quot; &amp; a).Model.Label = UserFieldDataType(a-1,0)
  83. .GetControl(&quot;TextField&quot; &amp; a).Model.Text = UserFieldFamily(CurFieldIndex, a-1)
  84. Next a
  85. .Model.ScrollBar1.ScrollValueMax = (SBMAXFIELDINDEX+1) - SBTBCOUNT
  86. .Model.ScrollBar1.BlockIncrement = SBTBCOUNT
  87. .Model.ScrollBar1.LineIncrement = 1
  88. .Model.ScrollBar1.ScrollValue = ScrollBarValue
  89. End With
  90. End Sub
  91. Sub ScrollControls()
  92. ScrollTextFieldInfo(ScrollBarValue)
  93. ScrollBarValue = DlgUserFields.Model.ScrollBar1.ScrollValue
  94. If (ScrollBarValue + SBTBCOUNT) &gt;= SBMAXFIELDINDEX + 1 Then
  95. ScrollBarValue = (SBMAXFIELDINDEX + 1) - SBTBCOUNT
  96. End If
  97. FillupTextFields()
  98. End Sub
  99. Sub ScrollTextFieldInfo(ByVal iScrollValue as Integer)
  100. Dim a as Integer
  101. Dim CurIndex as Integer
  102. For a = 1 To SBTBCOUNT
  103. CurIndex = (a-1) + iScrollValue
  104. UserFieldFamily(CurFieldIndex,CurIndex) = DlgUserFields.GetControl(&quot;TextField&quot; &amp; a).Model.Text
  105. Next a
  106. End Sub
  107. Sub StopMacro()
  108. DlgUserFields.EndExecute
  109. End Sub
  110. Sub SaveSettings()
  111. Dim n as Integer
  112. Dim m as Integer
  113. Dim MaxIndex as Integer
  114. ScrollTextFieldInfo(DlgUserFields.Model.ScrollBar1.ScrollValue)
  115. MaxIndex = Ubound(UserFieldFamily(), 1)
  116. Dim FileStrings(MaxIndex) as String
  117. For n = 0 To MaxIndex
  118. FileStrings(n) = &quot;&quot;
  119. For m = 0 To SBMAXFIELDINDEX
  120. FileStrings(n) = FileStrings(n) &amp; UserFieldFamily(n,m) &amp; &quot;;&quot;
  121. Next m
  122. Next n
  123. SaveDataToFile(FilePath, FileStrings(), True)
  124. End Sub
  125. Sub ToggleButtons(ByVal Index as Integer)
  126. Dim i as Integer
  127. CurFieldIndex = Index
  128. DlgUserFields.Model.cmdNextUser.Enabled = CurFieldIndex &lt;&gt; Ubound(UserFieldFamily(), 1)
  129. DlgUserFields.Model.cmdPrevUser.Enabled = CurFieldIndex &lt;&gt; 0
  130. 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
  156. Sub AddRecord()
  157. Dim i as Integer
  158. Dim MaxIndex as Integer
  159. For i = 1 To SBTBCount
  160. DlgUserFields.GetControl(&quot;TextField&quot; &amp; i).Model.Text = &quot;&quot;
  161. Next i
  162. MaxIndex = Ubound(UserFieldFamily(),1)
  163. ReDim Preserve UserFieldFamily(MaxIndex + 1, SBMAXFIELDINDEX) as String
  164. ToggleButtons(MaxIndex + 1, 1)
  165. End Sub
  166. Sub FillupTextFields()
  167. Dim a as Integer
  168. Dim CurIndex as Integer
  169. For a = 1 To SBTBCOUNT
  170. CurIndex = (a-1) + ScrollBarValue
  171. DlgUserFields.GetControl(&quot;Label&quot; &amp; a).Model.Label = UserFieldDataType(CurIndex,0)
  172. DlgUserFields.GetControl(&quot;TextField&quot; &amp; a).Model.Text = UserFieldFamily(CurFieldIndex, CurIndex)
  173. Next a
  174. End Sub
  175. Sub StepToRecord(aEvent as Object)
  176. Dim iStep as Integer
  177. iStep = CInt(aEvent.Source.Model.Tag)
  178. ScrollTextFieldInfo(ScrollBarValue)
  179. ToggleButtons(CurFieldIndex + iStep)
  180. FillUpTextFields()
  181. End Sub
  182. Sub SelectCurrentFields()
  183. Dim MaxIndex as Integer
  184. Dim i as Integer
  185. ScrollTextFieldInfo(ScrollBarValue)
  186. MaxIndex = Ubound(UserFieldFamily(),2)
  187. For i = 0 To MaxIndex
  188. oUserDataAccess.ReplaceByName(UserFieldDataType(i,1), UserFieldFamily(CurFieldIndex, i))
  189. Next i
  190. oUserDataAccess.commitChanges()
  191. End Sub
  192. Sub DeleteCurrentSettings()
  193. Dim n as Integer
  194. Dim m as Integer
  195. Dim MaxIndex as Integer
  196. MaxIndex = Ubound(UserFieldFamily(),1)
  197. If CurFieldIndex &lt; MaxIndex Then
  198. For n = CurFieldIndex To MaxIndex - 1
  199. For m = 0 To SBMAXFIELDINDEX
  200. UserFieldFamily(n,m) = UserFieldFamily(n + 1,m)
  201. Next m
  202. Next n
  203. Else
  204. CurFieldIndex = MaxIndex - 1
  205. End If
  206. ReDim Preserve UserFieldFamily(MaxIndex-1, SBMAXfIELDINDEX) as String
  207. FillupTextFields()
  208. ToggleButtons(CurFieldIndex)
  209. End Sub</script:module>