home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri Kaikille K-CD 2002 #3 / K-CD_2002-03.iso / OpenOffice / f_0259 / ConvertRun.xba < prev    next >
Extensible Markup Language  |  2001-09-21  |  11KB  |  320 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="ConvertRun" script:language="StarBasic">Option Explicit
  4.  
  5. Public oPreSelRange as Object
  6.  
  7. ' Todo Den Bug mit der Statuszeilengeschichte ├╝berpr├╝fen
  8. ' Todo Vorselektion der Listbox
  9. ' Mauspointer umschalten:
  10.  
  11. ' Todo: Sinnigkeit von 'DocDisposed' noch einmal ├╝berpr├╝fen
  12. ' Todo: In der Hilfe sollte ein Hinweis erscheinen, dass immer zwei Nachkommastellen angezeigt werden
  13. ' und die resultierende Betrag ebenfalls bis auf zwei Stellen nach dem Komma gerundet wird
  14.  
  15. Sub Main()
  16.     BasicLibraries.LoadLibrary("Tools")
  17.     If InitResources("Euro Converter", "eur") Then
  18.         bDoUnProtect = False
  19.         bPreSelected = True
  20. '        DocDisposed = False
  21.         oDocument = StarDesktop.CurrentFrame.Controller.Model
  22.         RetrieveDocumentObjects()                                            ' Statusline, SheetsCollection etc.
  23.         InitializeConverter(oDocument.CharLocale, 1)
  24.         GetPreSelectedRange()
  25.         If GoOn Then
  26.             DialogConvert.Execute
  27.         Else
  28.             DialogConvert.Dispose
  29.         End If
  30.     End If
  31. End Sub
  32.  
  33.  
  34. Sub SelectListItem()
  35. Dim Listbox as Object
  36. Dim oListSheet as Object
  37. Dim CurStyleName as String
  38. Dim oCursheet as Object
  39. Dim oTempRanges as Object
  40. Dim sCurSheetName as String
  41. Dim RangeName as String
  42. Dim oSheetRanges as Object
  43. Dim ListIndex as Integer
  44. Dim a as Integer
  45. Dim i as Integer
  46. Dim n as Integer
  47. Dim m as Integer
  48. Dim MaxIndex as Integer
  49.     Listbox = DialogModel.lstSelection
  50.     If Ubound(Listbox.SelectedItems()) > -1 Then
  51.         EnableStep1DialogControls(False, False, False)
  52.         oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
  53.  
  54.         ' Is the sheet the basis, then the sheetobject has to be created
  55.         If DialogModel.optDocRanges.State = 1 Then
  56.             ' Document is the basis for the conversion
  57.             ListIndex = Listbox.SelectedItems(0)
  58.             oCurSheet = RetrieveSheetoutofRangeName(Listbox.StringItemList(ListIndex))
  59.             oDocument.CurrentController.SetActiveSheet(oCurSheet)
  60.         Else
  61.             oCurSheet = oDocument.CurrentController.ActiveSheet
  62.         End If
  63.         sCurSheetName = oCurSheet.Name
  64.         If DialogModel.optCellTemplates.State = 1 Then
  65.             Dim CurIndex as Integer
  66.             For i = 0 To Ubound(Listbox.SelectedItems())
  67.                 CurIndex = Listbox.SelectedItems(i)
  68.                 CurStylename = Listbox.StringItemList(CurIndex)
  69.                 oSheetRanges = oCursheet.CellFormatRanges.createEnumeration
  70.                 While oSheetRanges.hasMoreElements
  71.                     oRange = oSheetRanges.NextElement
  72.                     If oRange.getPropertyState("NumberFormat") = 1 Then
  73.                         If oRange.CellStyle = CurStyleName Then
  74.                             oSelRanges.InsertbyName("",oRange)
  75.                         End If
  76.                     End If
  77.                 Wend
  78.             Next i
  79.         Else
  80.             ' Hard Formatation is selected
  81.             a = -1
  82.             For n = 0 To Ubound(Listbox.SelectedItems())
  83.                 m = Listbox.SelectedItems(n)
  84.                 RangeName = Listbox.StringItemList(m)
  85.                 oListSheet = RetrieveSheetoutofRangeName(RangeName)
  86.                 a = a + 1
  87.                 MaxIndex = Ubound(SelRangeList())
  88.                 If a > MaxIndex Then
  89.                     Redim Preserve SelRangeList(MaxIndex + SBRANGEUBOUND)
  90.                 End If
  91.                 SelRangeList(a) = RangeName
  92.                 If oListSheet.Name = sCurSheetName Then
  93.                     oRange = RetrieveRangeoutofRangeName(RangeName)
  94.                     oSelRanges.InsertbyName("",oRange)
  95.                 End If
  96.             Next n
  97.         End If
  98.         If a > -1 Then
  99.             ReDim Preserve SelRangeList(a)
  100.         Else
  101.             ReDim SelRangeList()
  102.         End If
  103.         oDocument.CurrentController.Select(oSelRanges)
  104.         EnableStep1DialogControls(True, True, True)
  105.     End If
  106. End Sub
  107.  
  108.  
  109. ' Prozedur that is called by an event
  110. Sub RetrieveEnableValue()
  111. Dim EnableValue as Boolean
  112.     EnableValue = Not DialogModel.lstSelection.Enabled
  113.     EnableStep1DialogControls(True, EnableValue, True)
  114. End Sub
  115.  
  116.  
  117. Sub EnableStep1DialogControls(bCurrEnabled as Boolean, bFrameEnabled as Boolean, bButtonsEnabled as Boolean)
  118. Dim bCurrIsSelected as Boolean
  119. Dim bObjectIsSelected as Boolean
  120. Dim bConvertWholeDoc as Boolean
  121. Dim bDoEnableFrame as Boolean
  122.     bConvertWholeDoc  = DialogModel.chkComplete.State = 1
  123.     bDoEnableFrame = bFrameEnabled And (NOT bConvertWholeDoc)
  124.  
  125.     ' Controls around the Selection Listbox
  126.     With DialogModel
  127.         .lblCurrencies.Enabled = bCurrEnabled
  128.         .lstCurrencies.Enabled = bCurrEnabled
  129.         .lstSelection.Enabled = bDoEnableFrame
  130.         .lblSelection.Enabled = bDoEnableFrame
  131.         .hlnSelection.Enabled = bDoEnableFrame
  132.         .optCellTemplates.Enabled = bDoEnableFrame
  133.         .optSheetRanges.Enabled = bDoEnableFrame
  134.         .optDocRanges.Enabled = bDoEnableFrame
  135.         .optSelRange.Enabled = bDoEnableFrame
  136.     End With
  137.     ' The CheckBox has the Value '1' when the Controls in the Frame are disabled
  138.     If bButtonsEnabled Then
  139.         bCurrIsSelected = Ubound(DialogModel.lstCurrencies.SelectedItems()) <> -1
  140.         ' Enable GoOnButton only when Currency is selected
  141.         DialogModel.cmdGoOn.Enabled =  bCurrIsSelected
  142.         DialogModel.chkComplete.Enabled = bCurrIsSelected
  143.         If bDoEnableFrame AND DialogModel.cmdGoOn.Enabled Then
  144.             ' If FrameControls are enabled, check if Listbox is Empty
  145.             bObjectIsSelected = Ubound(DialogModel.lstSelection.SelectedItems()) <> -1
  146.             DialogModel.cmdGoOn.Enabled = bObjectIsSelected
  147.         End If
  148.     Else
  149.         DialogModel.cmdGoOn.Enabled = False
  150.         DialogModel.chkComplete.Enabled = False
  151.     End If
  152. End Sub
  153.  
  154.  
  155. Sub ConvertRangesOrStylesOfDocument()
  156. Dim i as Integer
  157. Dim ItemName as String
  158. Dim SelList() as String
  159. Dim oSheetRanges as Object
  160.  
  161.     bDocHasProtectedSheets = CheckSheetProtection(oSheets)
  162.     If bDocHasProtectedSheets Then
  163.         bDocHasProtectedSheets = UnprotectSheetsWithPassWord(oSheets, bDoUnProtect)
  164.         DialogModel.cmdGoOn.Enabled = False
  165.     End If
  166.     If Not bDocHasProtectedSheets Then
  167.         EnableStep1DialogControls(False, False, False)
  168.         InitializeProgressBar()
  169.         If DialogModel.optSelRange.State = 1 Then
  170.             SelectListItem()
  171.         End If
  172.         SelList() =  DialogConvert.GetControl("lstSelection").SelectedItems()
  173.         If DialogModel.optCellTemplates.State = 1 Then
  174.             ' Option 'Soft' Formatation is selected
  175.             AssignRangestoStyle(DialogModel.lstSelection.StringItemList(), SelList())
  176.             ConverttheSoftWay(SelList(), True)
  177.         ElseIf DialogModel.optSelRange.State = 1 Then
  178.             oSheetRanges = oPreSelRange.CellFormatRanges.createEnumeration
  179.             While oSheetRanges.hasMoreElements
  180.                 oRange = oSheetRanges.NextElement
  181.                 If CheckFormatType(oRange) Then
  182.                     ConvertCellCurrencies(oRange)
  183.                     SwitchNumberFormat(oRange, oFormats, sEuroSign)
  184.                 End If
  185.             Wend
  186.         Else
  187.             ConverttheHardWay(SelList(), False, True)
  188.         End If
  189.         oStatusline.End
  190.         EnableStep1DialogControls(True, False, True)
  191.         DialogModel.cmdGoOn.Enabled = True
  192.         oDocument.CurrentController.Select(oSelRanges)
  193.     End If
  194. End Sub
  195.  
  196.  
  197. Sub ConvertWholeDocument()
  198. Dim s as Integer
  199.     DialogModel.cmdGoOn.Enabled = False
  200.     DialogModel.chkComplete.Enabled = False
  201.     GoOn = ConvertDocument()
  202.     EmptyListbox(DialogModel.lstSelection())
  203.     EnableStep1DialogControls(True, True, True)
  204. End Sub
  205.  
  206.  
  207. ' Alles was selektiert wurde wird deselektiert
  208. Sub EmptySelection()
  209. Dim RangeName as String
  210. Dim i as Integer
  211. Dim MaxIndex as Integer
  212. Dim EmptySelRangeList() as String
  213.  
  214.     If Not IsNull(oSelRanges) Then
  215.         If oSelRanges.HasElements Then
  216.             EmptySelRangeList() = ArrayOutofString(oSelRanges.RangeAddressesasString, ";", MaxIndex)
  217.             For i = 0 To MaxIndex
  218.                 oSelRanges.RemovebyName(EmptySelRangeList(i))
  219.             Next i
  220.         End If
  221.         oDocument.CurrentController.Select(oSelRanges)
  222.     Else
  223.         oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
  224.     End If
  225. End Sub
  226.  
  227.  
  228. Function AddSelectedRangeToSelRangesEnum() as Object
  229. Dim oLocRange as Object
  230.     osheet = oDocument.CurrentController.GetActiveSheet
  231.     oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
  232.     ' Check if a Currency-Range has been selected
  233.     oLocRange = oDocument.CurrentController.Selection
  234.     oSelRanges.InsertbyName("",oLocRange)
  235.     AddSelectedRangeToSelRangesEnum() = oLocRange
  236. End Function
  237.  
  238.  
  239. Sub GetPreSelectedRange()
  240. Dim i as Integer
  241. Dim OldCurrSymbolList(2) as String
  242. Dim OldCurrIndex as Integer
  243. Dim OldCurExtension(2) as String
  244.     oPreSelRange = AddSelectedRangeToSelRangesEnum()
  245.     bPreSelected = True
  246.     If bPreSelected Then
  247.         DialogModel.optSelRange.State = 1
  248.         AddRangeToListbox(oPreSelRange)
  249.     Else
  250.         DialogModel.optCellTemplates.State  = 1
  251.         CreateStyleEnumeration()
  252.     End If
  253.     EnableStep1DialogControls(True, bPreSelected, True)
  254. ' Todo: auf Integer umstellen
  255.     DialogModel.chkComplete.State = Not(Abs(bPreSelected))
  256.     DialogModel.optSelRange.Enabled = bPreSelected
  257. End Sub
  258.  
  259.  
  260. Sub AddRangeToListbox(oLocRange as Object)
  261.     EmptyListBox(DialogModel.lstSelection)
  262.     ' Den Namen der Range ermitteln und in ein Array packen
  263.     PreName = RetrieveRangeNamefromAddress(oLocRange)
  264.     AddSingleItemToListbox(DialogModel.lstSelection, Prename)', 0)
  265.     SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
  266.     TotCellCount = CountRangeCells(oLocRange)
  267. End Sub
  268.  
  269.  
  270. Sub CheckRangeSelection(Optional oEvent)
  271. ' Todo: Beim Startup werden die folgenden zwei Zeilen doppelt ausgef├╝hrt
  272. '    oPreSelRange = AddSelectedRangeToSelRangesEnum()
  273. '    bPreSelected = CheckFormatType(oRange)
  274.  '    If bPreSelected Then
  275.         EmptySelection()
  276.         AddRangeToListbox(oPreSelRange)
  277. '    End If
  278. End Sub
  279.  
  280.  
  281. ' Checks if a Field (LocField) is already defined in an Array
  282. ' Returns 'True' or 'False'
  283. Function FieldinList(LocList(), MaxIndex as integer, ByVal LocField ) As Boolean
  284. Dim i as integer
  285.     LocField = Ucase(LocField)
  286.     For i = Lbound(LocList()) to MaxIndex
  287.         If Ucase(LocList(i)) = LocField  then
  288.             FieldInList = True
  289.             Exit Function
  290.         End if
  291.     Next
  292.     FieldInList = False
  293. End Function
  294.  
  295.  
  296. Function CheckLocale(oLocale) as Boolean
  297. Dim i as Integer
  298. Dim LocCountry as String
  299. Dim LocLanguage as String
  300.     LocCountry = oLocale.Country
  301.     LocLanguage = oLocale.Language
  302.     For i = 0 To 1
  303.         If LocLanguage = LangIDValue(CurrIndex,i,0) AND LocCountry = LangIDValue(CurrIndex,i,1) Then
  304.             CheckLocale = True
  305.             Exit Function
  306.         End If
  307.     Next i
  308.     CheckLocale = False
  309. End Function
  310.  
  311.  
  312. Sub    SetOptionValuestoNull()
  313.     With DialogModel
  314.         .optCellTemplates.State = 0
  315.         .optSheetRanges.State = 0
  316.         .optDocRanges.State = 0
  317.         .optSelRange.State = 0
  318.     End With
  319. End Sub
  320. </script:module>