office-gobmx/wizards/source/euro/ConvertRun.xba

317 lines
9.6 KiB
Text
Raw Normal View History

2001-04-23 04:46:42 -05:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ConvertRun" script:language="StarBasic">Option Explicit
2001-09-12 06:30:01 -05:00
Public oPreSelRange as Object
2001-04-23 04:46:42 -05:00
Sub Main()
2001-05-04 09:11:48 -05:00
BasicLibraries.LoadLibrary(&quot;Tools&quot;)
2001-04-23 04:46:42 -05:00
If InitResources(&quot;Euro Converter&quot;, &quot;eur&quot;) Then
2001-06-25 13:03:49 -05:00
bDoUnProtect = False
2001-04-23 04:46:42 -05:00
bPreSelected = True
2001-11-19 09:24:29 -06:00
oDocument = ThisComponent
RetrieveDocumentObjects() &apos; Statusline, SheetsCollection etc.
2001-04-23 04:46:42 -05:00
InitializeConverter(oDocument.CharLocale, 1)
GetPreSelectedRange()
If GoOn Then
DialogConvert.GetControl(&quot;chkComplete&quot;).SetFocus()
2001-04-23 04:46:42 -05:00
DialogConvert.Execute
End If
2001-12-07 04:15:28 -06:00
DialogConvert.Dispose
2001-04-23 04:46:42 -05:00
End If
End Sub
Sub SelectListItem()
Dim Listbox as Object
Dim oListSheet as Object
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 i as Integer
Dim n as Integer
Dim m as Integer
Dim MaxIndex as Integer
2001-04-23 04:46:42 -05:00
Listbox = DialogModel.lstSelection
If Ubound(Listbox.SelectedItems()) &gt; -1 Then
EnableStep1DialogControls(False, False, False)
oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
&apos; Is the sheet the basis, then the sheetobject has to be created
If DialogModel.optDocRanges.State = 1 Then
2001-04-23 04:46:42 -05:00
&apos; Document is the basis for the conversion
ListIndex = Listbox.SelectedItems(0)
2001-06-25 13:03:49 -05:00
oCurSheet = RetrieveSheetoutofRangeName(Listbox.StringItemList(ListIndex))
2001-04-23 04:46:42 -05:00
oDocument.CurrentController.SetActiveSheet(oCurSheet)
Else
oCurSheet = oDocument.CurrentController.ActiveSheet
End If
sCurSheetName = oCurSheet.Name
If DialogModel.optCellTemplates.State = 1 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(&quot;NumberFormat&quot;) = 1 Then
If oRange.CellStyle = CurStyleName Then
oSelRanges.InsertbyName(&quot;&quot;,oRange)
2001-04-23 04:46:42 -05:00
End If
End If
Wend
Next i
2001-04-23 04:46:42 -05:00
Else
&apos; Hard Formatation is selected
2001-09-21 08:45:18 -05:00
a = -1
2001-04-23 04:46:42 -05:00
For n = 0 To Ubound(Listbox.SelectedItems())
m = Listbox.SelectedItems(n)
RangeName = Listbox.StringItemList(m)
oListSheet = RetrieveSheetoutofRangeName(RangeName)
a = a + 1
MaxIndex = Ubound(SelRangeList())
If a &gt; MaxIndex Then
Redim Preserve SelRangeList(MaxIndex + SBRANGEUBOUND)
End If
SelRangeList(a) = RangeName
If oListSheet.Name = sCurSheetName Then
oRange = RetrieveRangeoutofRangeName(RangeName)
oSelRanges.InsertbyName(&quot;&quot;,oRange)
2001-04-23 04:46:42 -05:00
End If
Next n
End If
If a &gt; -1 Then
ReDim Preserve SelRangeList(a)
Else
ReDim SelRangeList()
End If
2001-04-23 04:46:42 -05:00
oDocument.CurrentController.Select(oSelRanges)
EnableStep1DialogControls(True, True, True)
End If
End Sub
&apos; 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)
2001-09-12 06:30:01 -05:00
Dim bCurrIsSelected as Boolean
Dim bObjectIsSelected as Boolean
Dim bConvertWholeDoc as Boolean
Dim bDoEnableFrame as Boolean
bConvertWholeDoc = DialogModel.chkComplete.State = 1
bDoEnableFrame = bFrameEnabled And (NOT bConvertWholeDoc)
&apos; Controls around the Selection Listbox
With DialogModel
.lblCurrencies.Enabled = bCurrEnabled
2001-09-12 06:30:01 -05:00
.lstCurrencies.Enabled = bCurrEnabled
.lstSelection.Enabled = bDoEnableFrame
.lblSelection.Enabled = bDoEnableFrame
.hlnSelection.Enabled = bDoEnableFrame
.optCellTemplates.Enabled = bDoEnableFrame
.optSheetRanges.Enabled = bDoEnableFrame
.optDocRanges.Enabled = bDoEnableFrame
.optSelRange.Enabled = bDoEnableFrame
End With
2001-09-21 08:45:18 -05:00
&apos; The CheckBox has the Value &apos;1&apos; when the Controls in the Frame are disabled
2001-04-23 04:46:42 -05:00
If bButtonsEnabled Then
2001-09-12 06:30:01 -05:00
bCurrIsSelected = Ubound(DialogModel.lstCurrencies.SelectedItems()) &lt;&gt; -1
2001-04-23 04:46:42 -05:00
&apos; Enable GoOnButton only when Currency is selected
2001-09-12 06:30:01 -05:00
DialogModel.cmdGoOn.Enabled = bCurrIsSelected
DialogModel.chkComplete.Enabled = bCurrIsSelected
If bDoEnableFrame AND DialogModel.cmdGoOn.Enabled Then
2001-04-23 04:46:42 -05:00
&apos; If FrameControls are enabled, check if Listbox is Empty
2001-09-12 06:30:01 -05:00
bObjectIsSelected = Ubound(DialogModel.lstSelection.SelectedItems()) &lt;&gt; -1
DialogModel.cmdGoOn.Enabled = bObjectIsSelected
2001-04-23 04:46:42 -05:00
End If
Else
DialogModel.cmdGoOn.Enabled = False
DialogModel.chkComplete.Enabled = False
End If
End Sub
Sub ConvertRangesOrStylesOfDocument()
2001-04-23 04:46:42 -05:00
Dim i as Integer
Dim ItemName as String
Dim SelList() as String
2001-09-12 06:30:01 -05:00
Dim oSheetRanges as Object
2001-04-23 04:46:42 -05:00
bDocHasProtectedSheets = CheckSheetProtection(oSheets)
If bDocHasProtectedSheets Then
2001-06-25 13:03:49 -05:00
bDocHasProtectedSheets = UnprotectSheetsWithPassWord(oSheets, bDoUnProtect)
DialogModel.cmdGoOn.Enabled = False
2001-04-23 04:46:42 -05:00
End If
If Not bDocHasProtectedSheets Then
EnableStep1DialogControls(False, False, False)
InitializeProgressBar()
If DialogModel.optSelRange.State = 1 Then
SelectListItem()
End If
SelList() = DialogConvert.GetControl(&quot;lstSelection&quot;).SelectedItems()
If DialogModel.optCellTemplates.State = 1 Then
&apos; Option &apos;Soft&apos; Formatation is selected
AssignRangestoStyle(DialogModel.lstSelection.StringItemList(), SelList())
ConverttheSoftWay(SelList(), True)
2001-09-12 06:30:01 -05:00
ElseIf DialogModel.optSelRange.State = 1 Then
oSheetRanges = oPreSelRange.CellFormatRanges.createEnumeration
While oSheetRanges.hasMoreElements
oRange = oSheetRanges.NextElement
2001-09-12 09:50:40 -05:00
If CheckFormatType(oRange) Then
ConvertCellCurrencies(oRange)
SwitchNumberFormat(oRange, oFormats, sEuroSign)
End If
2001-09-12 06:30:01 -05:00
Wend
Else
ConverttheHardWay(SelList(), False, True)
End If
oStatusline.End
EnableStep1DialogControls(True, False, True)
DialogModel.cmdGoOn.Enabled = True
oDocument.CurrentController.Select(oSelRanges)
2001-04-23 04:46:42 -05:00
End If
End Sub
Sub ConvertWholeDocument()
Dim s as Integer
DialogModel.cmdGoOn.Enabled = False
DialogModel.chkComplete.Enabled = False
GoOn = ConvertDocument()
2001-06-25 13:03:49 -05:00
EmptyListbox(DialogModel.lstSelection())
EnableStep1DialogControls(True, True, True)
2001-04-23 04:46:42 -05:00
End Sub
&apos; Alles was selektiert wurde wird deselektiert
Sub EmptySelection()
Dim RangeName as String
Dim i as Integer
Dim MaxIndex as Integer
Dim EmptySelRangeList() as String
2001-04-23 04:46:42 -05:00
If Not IsNull(oSelRanges) Then
If oSelRanges.HasElements Then
EmptySelRangeList() = ArrayOutofString(oSelRanges.RangeAddressesasString, &quot;;&quot;, MaxIndex)
For i = 0 To MaxIndex
oSelRanges.RemovebyName(EmptySelRangeList(i))
Next i
2001-04-23 04:46:42 -05:00
End If
oDocument.CurrentController.Select(oSelRanges)
Else
oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
End If
End Sub
2001-09-12 06:30:01 -05:00
Function AddSelectedRangeToSelRangesEnum() as Object
Dim oLocRange as Object
2001-04-23 04:46:42 -05:00
osheet = oDocument.CurrentController.GetActiveSheet
oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
&apos; Check if a Currency-Range has been selected
2001-09-12 06:30:01 -05:00
oLocRange = oDocument.CurrentController.Selection
bPreSelected = oLocRange.SupportsService(&quot;com.sun.star.sheet.SheetCellRange&quot;)
If bPreSelected Then
oSelRanges.InsertbyName(&quot;&quot;,oLocRange)
AddSelectedRangeToSelRangesEnum() = oLocRange
End If
2001-09-12 06:30:01 -05:00
End Function
2001-04-23 04:46:42 -05:00
Sub GetPreSelectedRange()
Dim i as Integer
Dim OldCurrSymbolList(2) as String
Dim OldCurrIndex as Integer
2001-09-12 06:30:01 -05:00
Dim OldCurExtension(2) as String
oPreSelRange = AddSelectedRangeToSelRangesEnum()
2001-11-19 09:24:29 -06:00
DialogModel.chkComplete.State = Abs(Not(bPreSelected))
2001-09-21 08:45:18 -05:00
If bPreSelected Then
DialogModel.optSelRange.State = 1
AddRangeToListbox(oPreSelRange)
Else
DialogModel.optCellTemplates.State = 1
CreateStyleEnumeration()
End If
2001-04-23 04:46:42 -05:00
EnableStep1DialogControls(True, bPreSelected, True)
DialogModel.optSelRange.Enabled = bPreSelected
End Sub
2001-09-12 06:30:01 -05:00
Sub AddRangeToListbox(oLocRange as Object)
2001-04-23 04:46:42 -05:00
EmptyListBox(DialogModel.lstSelection)
2001-09-12 06:30:01 -05:00
PreName = RetrieveRangeNamefromAddress(oLocRange)
2001-04-23 04:46:42 -05:00
AddSingleItemToListbox(DialogModel.lstSelection, Prename)&apos;, 0)
SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
2001-09-12 06:30:01 -05:00
TotCellCount = CountRangeCells(oLocRange)
2001-04-23 04:46:42 -05:00
End Sub
Sub CheckRangeSelection(Optional oEvent)
EmptySelection()
AddRangeToListbox(oPreSelRange)
oPreSelRange = AddSelectedRangeToSelRangesEnum()
2001-04-23 04:46:42 -05:00
End Sub
&apos; Checks if a Field (LocField) is already defined in an Array
&apos; Returns &apos;True&apos; or &apos;False&apos;
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
2001-04-23 04:46:42 -05:00
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()
With DialogModel
.optCellTemplates.State = 0
.optSheetRanges.State = 0
.optDocRanges.State = 0
.optSelRange.State = 0
End With
2001-04-23 04:46:42 -05:00
End Sub
Sub SetStatusLineText(sStsREPROTECT as String)
If Not IsNull(oStatusLine) Then
oStatusline.SetText(sStsREPROTECT)
End If
End Sub
2001-05-04 09:11:48 -05:00
</script:module>