home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri Kaikille K-CD 2002 #3 / K-CD_2002-03.iso / OpenOffice / f_0259 / Common.xba < prev    next >
Extensible Markup Language  |  2001-10-10  |  8KB  |  264 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.  
  11.     CurMimeType = GetDocumentType(oDocument)
  12.     If Instr(1, CurMimeType, "calc") <> 0 Then
  13.         oSheets = oDocument.Sheets
  14.         oSheet = oDocument.Sheets.GetbyIndex(0)
  15.         oAddressRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
  16.     End If
  17.     oStatusline = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
  18.     ' Retrieve the indices for the cellformatations
  19.     oFormats = oDocument.NumberFormats
  20. End Sub
  21.  
  22.  
  23. Sub CancelTask()
  24. '    If Not DocDisposed Then
  25. '        ReprotectSheets()
  26. '    End If
  27.     If DialogModel.Step = 3 And (Not bCancelTask) Then
  28.         If Msgbox(sMsgCancelConversion, 36, sMsgCancelTitle) = 6 Then
  29.             bCancelTask = True
  30.             DialogConvert.EndExecute
  31.         Else
  32.             bCancelTask = False
  33.         End If
  34.     Else
  35.         DialogConvert.EndExecute()
  36.     End If
  37. End Sub
  38.  
  39.  
  40. Function ConvertDocument()
  41.     GoOn = True
  42. '    DocDisposed = True
  43.     InitializeProgressbar()
  44.     If Instr(1, CurMimeType, "calc") <> 0 Then
  45.         bDocHasProtectedSheets = CheckSheetProtection(oSheets)
  46.         If bDocHasProtectedSheets Then
  47.             bDocHasProtectedSheets = UnprotectSheetsWithPassword(oSheets, bDoUnProtect)
  48.         End If
  49.         If Not bDocHasProtectedSheets Then
  50.             If Not bRangeListDefined Then
  51.                 TotCellCount = 0
  52.                 CreateRangeEnumeration(True)
  53.             Else
  54.                 IncreaseStatusvalue(SBRelGet/3)
  55.             End If
  56.             RangeIndex = Ubound(RangeList(), 1)
  57.             If RangeIndex > -1 Then
  58.                 ConvertThehardWay(RangeList(), True, False)
  59.                 MakeStyleEnumeration(True)
  60.                 oDocument.calculateAll()
  61.             End If
  62.             ReprotectSheets()
  63.             bRangeListDefined = False
  64.         End If
  65.     Else
  66.         oStatusline.SetValue(10)
  67.         ConvertTextFields()
  68.         oStatusline.SetValue(80)
  69.         ConvertWriterTables()
  70.     End If    
  71.     oStatusline.End
  72.     On Local Error Goto 0 
  73. End Function
  74.  
  75.  
  76. Sub SwitchNumberFormat(oObject as Object, oFormats as object)
  77. Dim nFormatLanguage as Integer
  78. Dim nFormatDecimals as Integer
  79. Dim nFormatLeading as Integer
  80. Dim bFormatLeading as Integer
  81. Dim bFormatNegRed as Integer
  82. Dim bFormatThousands as Integer
  83. Dim aLocLocale As New com.sun.star.lang.Locale
  84. Dim i as Integer
  85. Dim aNewStr as String
  86. Dim iNumberFormat as Long
  87. Dim AddToList as Boolean
  88. Dim sOldCurrSymbol as String
  89.     On Local Error Resume Next
  90.     iNumberFormat = oObject.NumberFormat
  91.     On Local Error GoTo NOKEY
  92.     aFormat() = oFormats.getByKey(iNumberFormat)
  93.     On Local Error GoTo 0
  94.     sOldCurrSymbol = aFormat.CurrencySymbol
  95.     If sOldCurrSymbol = CurrValue(CurrIndex,5) Then
  96.         aSimpleStr = "0 [$EUR]"
  97.     Else
  98.         aSimpleStr = "0 [$" & sEuroSign & aFormat.CurrencyExtension & "]"
  99.     End If
  100.  
  101.     ' Numberformat mit dem neuen Symbol als Basis f├╝r generateFormat
  102.     nSimpleKey = Numberformat(oFormats, aSimpleStr, oLocale)
  103.     ' Typ und W├ñhrungssymbol des Numberformats heraussuchen
  104.     ' neues W├ñhrungsformat mit passenden Einstellungen setzen
  105.     nFormatDecimals = 2
  106.     nFormatLeading = aFormat.LeadingZeros
  107.     bFormatNegRed = aFormat.NegativeRed
  108.     bFormatThousands = aFormat.ThousandsSeparator
  109.     aLocLocale = aFormat.Locale
  110.     aNewStr = oFormats.generateFormat( nSimpleKey, oLocale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
  111.     oObject.NumberFormat = Numberformat(oFormats, aNewStr, aLocLocale)
  112.     NOKEY:
  113.     If Err <> 0 Then
  114.         Resume CLERROR
  115.     End If
  116.     CLERROR:
  117. End Sub
  118.  
  119.  
  120. Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Object)
  121. Dim nRetkey 
  122.     nRetKey = oFormats.queryKey( aFormatStr, oLocale, True )
  123.     If nRetKey = -1 Then
  124.         nRetKey = oFormats.addNew( aFormatStr, oLocale )
  125.         If nRetKey = -1 Then nRetKey = 0
  126.     End If
  127.     Numberformat = nRetKey
  128. End Function
  129.  
  130.  
  131. ' Funktion findet den Formattyp einer Vorlage, Zelle oder eines Bereiches heraus und schreibt das Ergebnis
  132. ' in die globale Variable nFormatType; Ist ein W├â┬ñhrungssymbol gesetzt, wird dieses in den globalen String
  133. ' sFormatCurrency geschrieben.
  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.  
  142.     ' Retrieve the Format of the Object
  143.     On Local Error GoTo NOKEY
  144.     oFormatofObject = oFormats.getByKey(FormatObject.NumberFormat)
  145.     On Local Error GoTo 0            
  146.     ' Typ und W├ñhrungssymbol des Numberformats heraussuchen
  147.       If NOT INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY Then
  148.         CheckFormatType = False
  149.         Exit Function
  150.     End If
  151.     If FieldinArray(CurrSymbolList(),2,oFormatofObject.CurrencySymbol) Then
  152.         ' If the Currencysymbol of the object ist the one needed, then check the Currency extension
  153.         sFormatCurrExt = oFormatofObject.CurrencyExtension
  154.  
  155.         If FieldInList(CurExtension(),2,sFormatCurrExt) Then
  156.             ' The Currency - extension also fits
  157.             CheckFormatType = True
  158.         Else
  159.             ' The Currency - symbol is Euro-conforming (like 'DEM'), so there is no Currency-Extension
  160.             CheckFormatType = oFormatofObject.CurrencySymbol = CurrsymbolList(2)
  161.         End If
  162.     Else
  163.         ' The Currency Symbol of the object is not the desired one
  164.         If oFormatofObject.CurrencySymbol = "" Then
  165.             ' Format is "automatic"
  166.             CheckFormatType = CheckLocale(oFormatofObject.Locale)
  167.         Else
  168.             CheckFormatType = False
  169.         End If
  170.     End If
  171.  
  172.     NOKEY:
  173.     If Err <> 0 Then
  174.         CheckFormatType = False
  175.         Resume CLERROR
  176.     End If
  177.     CLERROR:
  178. End Function
  179.  
  180.  
  181. Sub StartConversion()
  182.     GoOn = True
  183. '    ToggleWindow(False)
  184.     Select Case DialogModel.Step
  185.         Case 1
  186.             If DialogModel.chkComplete.State = 1 Then
  187.                 ConvertWholeDocument()
  188.             Else
  189.                 ConvertRangesorStylesofDocument()
  190.             End If
  191.         Case 2
  192.             bCancelTask = False
  193.             InitializeThirdStep()
  194.             ConvertDocuments()
  195.             bCancelTask = True
  196.         Case 3
  197.             DialogConvert.EndExecute()
  198.     End Select
  199. End Sub
  200.  
  201.  
  202. Sub IncreaseStatusValue(AddStatusValue as Integer)
  203.     StatusValue = Int(StatusValue + AddStatusValue)
  204.     oStatusline.SetValue(StatusValue)
  205. End Sub
  206.  
  207.  
  208. Sub SelectCurrency()
  209. Dim AddtoList as Boolean
  210. Dim UpRangeList as Integer
  211. Dim OldCurrIndex as Integer
  212.     bRangeListDefined = False
  213.     OldCurrIndex = CurrIndex
  214.     CurrIndex = DialogModel.lstCurrencies.SelectedItems(0)
  215.     InitializeCurrencyValues(CurrIndex)
  216.     CurExtension(0) = LangIDValue(CurrIndex,0,2)
  217.     CurExtension(1) = LangIDValue(CurrIndex,1,2)
  218.     CurExtension(2) = LangIDValue(CurrIndex,2,2)
  219.     If DialogModel.Step = 1 Then
  220.         If OldCurrIndex = -1 Then
  221.             DialogModel.chkComplete.State = 1
  222.             EnableStep1DialogControls(True,False, True)
  223.             SetOptionValuestoNull()
  224.         Else
  225.             EnableStep1DialogControls(False,False, False)
  226.             If DialogModel.optCellTemplates.State = 1 Then
  227.                 EnableStep1DialogControls(False, False, False)
  228.                 CreateStyleEnumeration()
  229.             ElseIf ((DialogModel.optSheetRanges.State = 1) OR (DialogModel.optDocRanges.State = 1)) AND (DialogModel.Step = 1) Then
  230.                 UpRangeList = UBound(RangeList())
  231.                 ReDim RangeList(UpRangeList) 'as String
  232.                 CreateRangeEnumeration(False)
  233.             ElseIf DialogModel.optSelRange.State= 1 Then
  234.                 'Preselected Range
  235.                 CheckRangeSelection()
  236.             End If
  237.             EnableStep1DialogControls(True, True, True)
  238.         End If
  239.     ElseIf DialogModel.Step = 2 Then
  240.         EnableStep2DialogControls(True)
  241.     End If
  242. End Sub
  243.  
  244.  
  245. Sub FillUpCurrencyListbox()
  246. Dim i as Integer
  247. Dim MaxIndex as Integer
  248.     MaxIndex = Ubound(CurrValue(),1)
  249.     Dim LocList(MaxIndex) as String
  250.     For i = 0 To MaxIndex
  251.         LocList(i) = CurrValue(i,0)
  252.     Next i
  253.     DialogModel.lstCurrencies.StringItemList() = LocList()
  254.     If CurrIndex > -1 Then
  255.         SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
  256.     End If
  257. End Sub
  258.  
  259.  
  260. Sub InitializeProgressbar()
  261.     CurCellCount = 0
  262.     oStatusline.Start(sStsPROGRESS,100)             '"Konvertierungsfortschritt:"
  263.     StatusValue = 0
  264. End Sub</script:module>