home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 May / Gamestar_62_2004-05_dvd.iso / Programy / openoffice / f_0321 / Common.xba < prev    next >
Extensible Markup Language  |  2002-09-17  |  8KB  |  271 lines

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