Common.xba 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <!--***********************************************************
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. ***********************************************************-->
  23. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Common" script:language="StarBasic"> REM ***** BASIC *****
  24. Public DialogModel as Object
  25. Public DialogConvert as Object
  26. Public DialogPassword as Object
  27. Public PasswordModel as Object
  28. Sub RetrieveDocumentObjects()
  29. CurMimeType = Tools.GetDocumentType(oDocument)
  30. If Instr(1, CurMimeType, &quot;calc&quot;) &lt;&gt; 0 Then
  31. oSheets = oDocument.Sheets
  32. oSheet = oDocument.Sheets.GetbyIndex(0)
  33. oAddressRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
  34. End If
  35. &apos; Retrieve the indices for the cellformatations
  36. oFormats = oDocument.NumberFormats
  37. End Sub
  38. Sub CancelTask()
  39. &apos; If Not DocDisposed Then
  40. &apos; ReprotectSheets()
  41. &apos; End If
  42. If DialogModel.Step = 3 And (Not bCancelTask) Then
  43. If Msgbox(sMsgCancelConversion, 36, sMsgCancelTitle) = 6 Then
  44. bCancelTask = True
  45. DialogConvert.EndExecute
  46. Else
  47. bCancelTask = False
  48. End If
  49. Else
  50. DialogConvert.EndExecute()
  51. End If
  52. End Sub
  53. Function ConvertDocument()
  54. GoOn = True
  55. &apos; DocDisposed = True
  56. InitializeProgressbar()
  57. If Instr(1, CurMimeType, &quot;calc&quot;) &lt;&gt; 0 Then
  58. bDocHasProtectedSheets = CheckSheetProtection(oSheets)
  59. If bDocHasProtectedSheets Then
  60. bDocHasProtectedSheets = UnprotectSheetsWithPassword(oSheets, bDoUnProtect)
  61. End If
  62. If Not bDocHasProtectedSheets Then
  63. If Not bRangeListDefined Then
  64. TotCellCount = 0
  65. CreateRangeEnumeration(True)
  66. Else
  67. IncreaseStatusvalue(SBRelGet/3)
  68. End If
  69. RangeIndex = Ubound(RangeList())
  70. If RangeIndex &gt; -1 Then
  71. ConvertThehardWay(RangeList(), True, False)
  72. MakeStyleEnumeration(True)
  73. oDocument.calculateAll()
  74. End If
  75. ReprotectSheets()
  76. bRangeListDefined = False
  77. End If
  78. Else
  79. DialogModel.ProgressBar.ProgressValue = 10 &apos; oStatusline.SetValue(10)
  80. ConvertTextFields()
  81. DialogModel.ProgressBar.ProgressValue = 80 &apos; oStatusline.SetValue(80)
  82. ConvertWriterTables()
  83. End If
  84. EndStatusLine()
  85. On Local Error Goto 0
  86. End Function
  87. Sub SwitchNumberFormat(oObject as Object, oFormats as object)
  88. Dim nFormatLanguage as Integer
  89. Dim nFormatDecimals as Integer
  90. Dim nFormatLeading as Integer
  91. Dim bFormatLeading as Integer
  92. Dim bFormatNegRed as Integer
  93. Dim bFormatThousands as Integer
  94. Dim i as Integer
  95. Dim aNewStr as String
  96. Dim iNumberFormat as Long
  97. Dim AddToList as Boolean
  98. Dim sOldCurrSymbol as String
  99. On Local Error Resume Next
  100. iNumberFormat = oObject.NumberFormat
  101. On Local Error GoTo NOKEY
  102. aFormat() = oFormats.getByKey(iNumberFormat)
  103. On Local Error GoTo 0
  104. sOldCurrSymbol = aFormat.CurrencySymbol
  105. If sOldCurrSymbol = CurrValue(CurrIndex,5) Then
  106. aSimpleStr = &quot;0 [$EUR]&quot;
  107. Else
  108. aSimpleStr = &quot;0 [$&quot; &amp; sEuroSign &amp; aFormat.CurrencyExtension &amp; &quot;]&quot;
  109. End If
  110. nSimpleKey = Numberformat(oFormats, aSimpleStr, oLocale)
  111. &apos; set new Currency format with according settings
  112. nFormatDecimals = 2
  113. nFormatLeading = aFormat.LeadingZeros
  114. bFormatNegRed = aFormat.NegativeRed
  115. bFormatThousands = aFormat.ThousandsSeparator
  116. aNewStr = oFormats.generateFormat( nSimpleKey, aFormat.Locale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
  117. oObject.NumberFormat = Numberformat(oFormats, aNewStr, aFormat.Locale)
  118. NOKEY:
  119. If Err &lt;&gt; 0 Then
  120. Resume CLERROR
  121. End If
  122. CLERROR:
  123. End Sub
  124. Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Object)
  125. Dim nRetkey
  126. Dim l as String
  127. Dim c as String
  128. nRetKey = oFormats.queryKey( aFormatStr, oLocale, True )
  129. If nRetKey = -1 Then
  130. l = oLocale.Language
  131. c = oLocale.Country
  132. nRetKey = oFormats.addNew( aFormatStr, oLocale )
  133. If nRetKey = -1 Then nRetKey = 0
  134. End If
  135. Numberformat = nRetKey
  136. End Function
  137. Function CheckFormatType( FormatObject as object)
  138. Dim i as Integer
  139. Dim LocCurrIndex as Integer
  140. Dim nFormatFormatString as String
  141. Dim FormatLangID as Integer
  142. Dim sFormatCurrExt as String
  143. Dim oFormatofObject() as Object
  144. &apos; Retrieve the Format of the Object
  145. On Local Error GoTo NOKEY
  146. oFormatofObject = oFormats.getByKey(FormatObject.NumberFormat)
  147. On Local Error GoTo 0
  148. If NOT INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY Then
  149. CheckFormatType = False
  150. Exit Function
  151. End If
  152. If FieldinArray(CurrSymbolList(),2,oFormatofObject.CurrencySymbol) Then
  153. &apos; If the Currencysymbol of the object ist the one needed, then check the Currency extension
  154. sFormatCurrExt = oFormatofObject.CurrencyExtension
  155. If FieldInList(CurExtension(),2,sFormatCurrExt) Then
  156. &apos; The Currency - extension also fits
  157. CheckFormatType = True
  158. Else
  159. &apos; The Currency - symbol is Euro-conforming (like &apos;DEM&apos;), so there is no Currency-Extension
  160. CheckFormatType = oFormatofObject.CurrencySymbol = CurrsymbolList(2)
  161. End If
  162. Else
  163. &apos; The Currency Symbol of the object is not the desired one
  164. If oFormatofObject.CurrencySymbol = &quot;&quot; Then
  165. &apos; Format is &quot;automatic&quot;
  166. CheckFormatType = CheckLocale(oFormatofObject.Locale)
  167. Else
  168. CheckFormatType = False
  169. End If
  170. End If
  171. NOKEY:
  172. If Err &lt;&gt; 0 Then
  173. CheckFormatType = False
  174. Resume CLERROR
  175. End If
  176. CLERROR:
  177. End Function
  178. Sub StartConversion()
  179. GoOn = True
  180. Select Case DialogModel.Step
  181. Case 1
  182. If DialogModel.chkComplete.State = 1 Then
  183. ConvertWholeDocument()
  184. Else
  185. ConvertRangesorStylesofDocument()
  186. End If
  187. Case 2
  188. bCancelTask = False
  189. If InitializeThirdStep() Then
  190. ConvertDocuments()
  191. bCancelTask = True
  192. End If
  193. Case 3
  194. DialogConvert.EndExecute()
  195. End Select
  196. End Sub
  197. Sub IncreaseStatusValue(AddStatusValue as Integer)
  198. StatusValue = Int(StatusValue + AddStatusValue)
  199. If DialogModel.Step = 3 Then
  200. DialogModel.ProgressBar.ProgressValue = StatusValue
  201. Else
  202. oStatusline.SetValue(StatusValue)
  203. End If
  204. End Sub
  205. Sub SelectCurrency()
  206. Dim AddtoList as Boolean
  207. Dim NullList()
  208. Dim OldCurrIndex as Integer
  209. bRangeListDefined = False
  210. OldCurrIndex = CurrIndex
  211. CurrIndex = DialogModel.lstCurrencies.SelectedItems(0)
  212. If OldCurrIndex &lt;&gt; CurrIndex Then
  213. InitializeCurrencyValues(CurrIndex)
  214. CurExtension(0) = LangIDValue(CurrIndex,0,2)
  215. CurExtension(1) = LangIDValue(CurrIndex,1,2)
  216. CurExtension(2) = LangIDValue(CurrIndex,2,2)
  217. If DialogModel.Step = 1 Then
  218. EnableStep1DialogControls(False,False, False)
  219. If DialogModel.optCellTemplates.State = 1 Then
  220. EnableStep1DialogControls(False, False, False)
  221. CreateStyleEnumeration()
  222. ElseIf ((DialogModel.optSheetRanges.State = 1) OR (DialogModel.optDocRanges.State = 1)) AND (DialogModel.Step = 1) Then
  223. CreateRangeEnumeration(False)
  224. If Ubound(RangeList()) = -1 Then
  225. DialogModel.lstSelection.StringItemList() = NullList()
  226. End If
  227. ElseIf DialogModel.optSelRange.State= 1 Then
  228. &apos;Preselected Range
  229. End If
  230. EnableStep1DialogControls(True, True, True)
  231. ElseIf DialogModel.Step = 2 Then
  232. EnableStep2DialogControls(True)
  233. End If
  234. End If
  235. End Sub
  236. Sub FillUpCurrencyListbox()
  237. Dim i as Integer
  238. Dim MaxIndex as Integer
  239. MaxIndex = Ubound(CurrValue(),1)
  240. Dim LocList(MaxIndex) as String
  241. For i = 0 To MaxIndex
  242. LocList(i) = CurrValue(i,0)
  243. Next i
  244. DialogModel.lstCurrencies.StringItemList() = LocList()
  245. If CurrIndex &gt; -1 Then
  246. SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
  247. End If
  248. End Sub
  249. Sub InitializeProgressbar()
  250. CurCellCount = 0
  251. If Not IsNull(oStatusLine) Then
  252. oStatusline.Start(sStsPROGRESS, 100)
  253. Else
  254. DialogModel.ProgressBar.ProgressValue = 0
  255. End If
  256. StatusValue = 0
  257. End Sub
  258. Sub EndStatusLine()
  259. If Not IsNull(oStatusLine) Then
  260. oStatusline.End
  261. Else
  262. DialogModel.ProgressBar.ProgressValue = 100
  263. End If
  264. End Sub
  265. </script:module>