diff options
author | Tom Verbeek <tv@openoffice.org> | 2001-04-23 09:46:42 +0000 |
---|---|---|
committer | Tom Verbeek <tv@openoffice.org> | 2001-04-23 09:46:42 +0000 |
commit | 191835bec9bafbe76567363e2e5a1fdd7b232671 (patch) | |
tree | f3b6f68a56b2ba9575fee6f77a5966af45804e47 /wizards/source/euro/ConvertRun.xba | |
parent | a2255c1e77bee1071b372efd33d3b4adfeb0907b (diff) |
initial revision
Diffstat (limited to 'wizards/source/euro/ConvertRun.xba')
-rw-r--r-- | wizards/source/euro/ConvertRun.xba | 408 |
1 files changed, 408 insertions, 0 deletions
diff --git a/wizards/source/euro/ConvertRun.xba b/wizards/source/euro/ConvertRun.xba new file mode 100644 index 000000000000..0df2eed92417 --- /dev/null +++ b/wizards/source/euro/ConvertRun.xba @@ -0,0 +1,408 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ConvertRun" script:language="StarBasic">Option Explicit +' Todo Den Bug mit der Statuszeilengeschichte überprüfen +' Todo Vorselektion der Listbox +' Mauspointer umschalten: + +' Todo: Sinnigkeit von 'DocDisposed' noch einmal überprüfen + +Sub Main() + LoadLibrary("tools") + If InitResources("Euro Converter", "eur") Then + DoUnProtect = 0 + bPreSelected = True + DocDisposed = False + oDocument = StarDesktop.CurrentFrame.Controller.Model + RetrieveDocumentObjects() ' Statusline, SheetsCollection etc. + InitializeConverter(oDocument.CharLocale, 1) + GetPreSelectedRange() + If GoOn Then + DialogConvert.Execute + Else + DialogConvert.Dispose + End If + End If +End Sub + + +Sub SelectListItem() +Dim Listbox as Object +Dim oListSheet as Object +Dim AddRange as Boolean +Dim CurStyleName as String +Dim oCursheet as Object +Dim oTempRanges as Object +Dim sCurSheetName as String +Dim RangeName as String +Dim oSheetRanges as Object +Dim ListIndex as Integer +Dim a as Integer +Dim s as Integer +Dim i as Integer +Dim n as Integer +Dim m as Integer +Dim AddStyle as Boolean + Listbox = DialogModel.lstSelection + If Ubound(Listbox.SelectedItems()) > -1 Then +' ToggleWindow(False) + EnableStep1DialogControls(False, False, False) + oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges") + + ' Is the sheet the basis, then the sheetobject has to be created + If DialogModel.optDocRanges.State= 1 Then + ' Document is the basis for the conversion + ListIndex = Listbox.SelectedItems(0) + oCurSheet = RetrieveSheetoutofRangeName(ListIndex) + oDocument.CurrentController.SetActiveSheet(oCurSheet) + Else + oCurSheet = oDocument.CurrentController.ActiveSheet + End If + sCurSheetName = oCurSheet.Name + AddStyle = True + If DialogModel.optCellTemplates.State = 1 Then + 'Soft formatation is selected + For s = 0 To oSheets.Count-1 + If oSheets.GetbyIndex(s).IsProtected Then + AddStyle = UnprotectSheet(oSheets.GetbyIndex(s)) + If Not AddStyle Then + Exit For + End If + End If + Next s + If AddStyle Then + Dim CurIndex as Integer + For i = 0 To Ubound(Listbox.SelectedItems()) + CurIndex = Listbox.SelectedItems(i) + CurStylename = Listbox.StringItemList(CurIndex) + oSheetRanges = oCursheet.CellFormatRanges.createEnumeration + While oSheetRanges.hasMoreElements + oRange = oSheetRanges.NextElement + If oRange.getPropertyState("NumberFormat") = 1 Then + If oRange.CellStyle = CurStyleName Then + oSelRanges.InsertbyName("",oRange) + End If + End If + Wend + Next i + Else + EmptyListbox(Listbox) + End If + Else + a = 1 + ' Hard Formatation is selected + For n = 0 To Ubound(Listbox.SelectedItems()) + m = Listbox.SelectedItems(n) + RangeName = Listbox.StringItemList(m) + oListSheet = RetrieveSheetoutofRangeName(RangeName) + AddRange = UnprotectSheet(oListSheet) +' Todo: Klären wie das am besten geht! + If Not AddRange Then + DeselectListboxItem(Listbox, n) + Else + SelRangeList(a) = RangeName + SelRangeList(0) = Str(a) + a = a + 1 + If oListSheet.Name = sCurSheetName Then + oRange = RetrieveRangeoutofRangeName(RangeName) + oSelRanges.InsertbyName("",oRange) + End If + End If + Next n + End If + oDocument.CurrentController.Select(oSelRanges) + EnableStep1DialogControls(True, True, True) +' ToggleWindow(True) + End If +End Sub + + +' Prozedur that is called by an event +Sub RetrieveEnableValue() +Dim EnableValue as Boolean + EnableValue = Not DialogModel.lstSelection.Enabled + EnableStep1DialogControls(True, EnableValue, True) +End Sub + + +Sub EnableStep1DialogControls(bCurrEnabled as Boolean, bFrameEnabled as Boolean, bButtonsEnabled as Boolean) +Dim bNoComboSelection as Boolean +Dim bNoLBSelection as Boolean + ' Controls around the Currency-Listbox + DialogModel.lblCurrencies.Enabled = bCurrEnabled + DialogModel.lstCurrencies.Enabled = bCurrEnabled + + DialogModel.lstSelection.Enabled = bFrameEnabled + DialogModel.lblSelection.Enabled = bFrameEnabled + DialogModel.frmSelection.Enabled = bFrameEnabled + DialogModel.optCellTemplates.Enabled = bFrameEnabled + DialogModel.optSheetRanges.Enabled = bFrameEnabled + DialogModel.optDocRanges.Enabled = bFrameEnabled + DialogModel.optSelRange.Enabled = bFrameEnabled + + ' The CheckBox has the Value 'True' when the Controls in the Frame are disabled + If bButtonsEnabled Then + bNoComboSelection = Ubound(DialogModel.lstCurrencies.SelectedItems()) = -1 + ' Enable GoOnButton only when Currency is selected + DialogModel.cmdGoOn.Enabled = Not bNoComboSelection + DialogModel.chkComplete.Enabled = Not bNoComboSelection + If bFrameEnabled AND Not DialogModel.chkComplete.State = 1 AND DialogModel.cmdGoOn.Enabled Then + ' If FrameControls are enabled, check if Listbox is Empty + bNoLBSelection = Ubound(DialogModel.lstSelection.SelectedItems()) = -1 + DialogModel.cmdGoOn.Enabled = NOT bNoLBSelection + End If + Else + DialogModel.cmdGoOn.Enabled = False + DialogModel.chkComplete.Enabled = False + End If +End Sub + + +Sub ConvertRangesOrStylesOfDocument() +Dim i as Integer +Dim Listbox as Object +Dim ItemName as String +Dim ThisList() as String +Dim ThisSel() as Boolean + + ' Variable, in der der aktuelle Stand der Fortschrittsleiste angzeigt wird + CurCellCount = 0 + Listbox = DialogModel.lstSelection + EnableStep1DialogControls(False, False, False) + + oStatusline.Start(sStsPROGRESS,100) ' "Konvertierungsfortschritt:" + StatusValue = 0 + If DialogModel.optSelRange.State = 1 Then + SelectListItem() + End If + ThisSel() = GetSelectedListboxItems(Listbox) + ThisList() = Listbox.StringItemList() + If DialogModel.optCellTemplates.State <> 1 Then + ' Option 'Hard Formatation is selected + SelectRange() + ConverttheHardWay(ThisList(), ThisSel(), False, False) + Else + ' Option 'Soft' Formatation is selected + AssignRangestoStyle(ThisList(), ThisSel()) + ConverttheSoftWay(ThisList(), ThisSel(), False) + End If + oStatusline.End + i = 0 + ' Todo: Dieses Array vorab neu dimensionieren und in For - Schleife abarbeiten + While RemoveList(i) <> "" + ItemName = RemoveList(i) + RemoveItemfromListbox(Listbox, ItemName) + i = i + 1 + Wend + EnableStep1DialogControls(True, False, True) + DialogModel.cmdGoOn.Enabled = True + oDocument.CurrentController.Select(oSelRanges) +End Sub + + +Sub ConvertWholeDocument() +Dim s as Integer + DialogModel.cmdGoOn.Enabled = False + DialogModel.chkComplete.Enabled = False + GoOn = ConvertDocument() + If Ubound(DialogModel.lstSelection.StringItemList()) > -1 AND GoOn Then + EmptyListbox(DialogModel.lstSelection()) + EnableStep1DialogControls(True, True, True) + Else + ' The next time ask for unprotection again + DoUnprotect = 0 + DialogModel.cmdGoOn.Enabled = True + DialogModel.chkComplete.Enabled = True + End If +End Sub + + +Sub SelectCurrency() +Dim AddtoList as Boolean +Dim UpRangeList as Integer +Dim OldCurrIndex as Integer + OldCurrIndex = CurrIndex + CurrIndex = DialogModel.lstCurrencies.SelectedItems(0) + InitializeCurrencyValues(CurrIndex) + CurExtension(0) = LangIDValue(CurrIndex,0,2) + CurExtension(1) = LangIDValue(CurrIndex,1,2) + If DialogModel.Step = 1 Then + If OldCurrIndex = -1 Then + DialogModel.chkComplete.State = 1 + EnableStep1DialogControls(True,False, True) + SetOptionValuestoNull() + Else + EnableStep1DialogControls(False,False, False) + If DialogModel.optCellTemplates.State = 1 Then + EnableStep1DialogControls(False, False, False) + CreateStyleEnumeration() + EnableStep1DialogControls(True, True, True) + ElseIf ((DialogModel.optSheetRanges.State = 1) OR (DialogModel.optDocRanges.State = 1)) AND (DialogModel.Step = 1) Then + UpRangeList = UBound(RangeList()) + ReDim RangeList(UpRangeList) 'as String + CreateRangeEnumeration(False) + ElseIf DialogModel.optSelRange.State= 1 Then + 'Preselected Range + CheckRangeSelection() + End If + EnableStep1DialogControls(True, True, True) + End If + ElseIf DialogModel.Step = 2 Then + EnableStep2DialogControls(True) + End If +End Sub + + + +Sub FillUpCurrencyListbox() +Dim i as Integer +Dim MaxIndex as Integer + MaxIndex = Ubound(CurrValue(),1) + Dim LocList(MaxIndex) as String + For i = 0 To MaxIndex + LocList(i) = CurrValue(i,0) + Next i + DialogModel.lstCurrencies.StringItemList() = LocList() + If CurrIndex > -1 Then + SelectListboxItem(DialogModel.lstCurrencies, CurrIndex) + End If +End Sub + + +' Alles was selektiert wurde wird deselektiert +Sub EmptySelection() +Dim RangeName as String +Dim i, MaxIndex as Integer +Dim EmptySelRangeList(30) as String + + If Not IsNull(oSelRanges) Then + If oSelRanges.HasElements Then + EmptySelRangeList() = ArrayOutofString(oSelRanges.RangeAddressesasString, ";", MaxIndex) + i = 0 + Do + If EmptySelRangeList(i) <> "" Then + oSelRanges.RemovebyName(EmptySelRangeList(i)) + i = i + 1 + End If + Loop Until EmptySelRangeList(i) = "" + End If + oDocument.CurrentController.Select(oSelRanges) + Else + oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges") + End If +End Sub + + +Sub AddSelectedRangeToSelRangesEnum() + osheet = oDocument.CurrentController.GetActiveSheet + oAddressRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges") + oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges") + ' Check if a Currency-Range has been selected + oRange = oDocument.CurrentController.Selection + oSelRanges.InsertbyName("",oRange) +End Sub + + +Sub GetPreSelectedRange() +Dim i as Integer +Dim OldCurrSymbolList(2) as String +Dim OldCurrIndex as Integer +Dim OldCurExtension(1) as String + AddSelectedRangeToSelRangesEnum() + bPreSelected = CheckIfRangeisCurrency(oRange) + If bPreSelected Then +' Todo: Array als ganzes übergeben! + OldCurrSymbolList() = CurrSymbolList() + OldCurExtension() = CurExtension() + OldCurrIndex = CurrIndex + For i = 0 To 10 + CurrIndex = i + CurExtension(0) = LangIDValue(CurrIndex,0,2) + CurExtension(1) = LangIDValue(CurrIndex,1,2) + InitializeCurrencyValues(CurrIndex) + bPreSelected = CheckFormatType(oRange) + If bPreSelected Then + Exit For + End If + Next i + If Not bPreSelected Then + CurrIndex = OldCurrIndex + CurrSymbolList() = OldCurrSymbolList() + CurExtension() = OldCurExtension() + End If + End If + + If CurrIndex > -1 Then + If bPreSelected Then + DialogModel.optSelRange.State = 1 + AddRangeToListbox() + Else + DialogModel.optCellTemplates.State = 1 + CreateStyleEnumeration() + End If + End If + EnableStep1DialogControls(True, bPreSelected, True) +' Todo: auf Integer umstellen + DialogModel.chkComplete.State = Not bPreSelected + DialogModel.optSelRange.Enabled = bPreSelected +End Sub + + +Sub AddRangeToListbox() + EmptyListBox(DialogModel.lstSelection) + ' Den Namen der Range ermitteln und in ein Array packen + PreName = RetrieveRangeNamefromAddress(oRange.RangeAddress, oSheet.Name) + AddSingleItemToListbox(DialogModel.lstSelection, Prename)', 0) + SelectListboxItem(DialogModel.lstCurrencies, CurrIndex) + TotCellCount = CountRangeCells(oRange) +End Sub + + +Sub CheckRangeSelection(Optional oEvent) +' Todo: Beim Startup werden die folgenden zwei Zeilen doppelt ausgeführt + AddSelectedRangeToSelRangesEnum() + bPreSelected = CheckFormatType(oRange) + If bPreSelected Then + AddRangeToListbox() + End If +End Sub + + +' Checks if a Field (LocField) is already defined in an Array +' Returns 'True' or 'False' +Function FieldinList(LocList(), MaxIndex as integer, ByVal LocField ) As Boolean +Dim i as integer + LocField = Ucase(LocField) + For i = Lbound(LocList()) to MaxIndex + If Ucase(LocList(i)) = LocField then + FieldInList = True + Exit Function + End if + Next + FieldInList = False +End Function + + +Function CheckLocale(oLocale) as Boolean +Dim i as Integer +Dim LocCountry as String +Dim LocLanguage as String + LocCountry = oLocale.Country + LocLanguage = oLocale.Language + For i = 0 To 1 + If LocLanguage = LangIDValue(CurrIndex,i,0) AND LocCountry = LangIDValue(CurrIndex,i,1) Then + CheckLocale = True + Exit Function + End If + Next i + CheckLocale = False +End Function + + +Sub SetOptionValuestoNull() + DialogModel.optCellTemplates.State = 0 + DialogModel.optSheetRanges.State = 0 + DialogModel.optDocRanges.State = 0 + DialogModel.optSelRange.State = 0 +End Sub +</script:module>
\ No newline at end of file |