Common.xba 8.4 KB

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