2001-04-23 04:46:42 -05:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
2001-06-25 02:58:41 -05:00
|
|
|
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
2002-01-11 06:30:59 -06:00
|
|
|
<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("Tools")
|
2001-04-23 04:46:42 -05:00
|
|
|
If InitResources("Euro Converter", "eur") 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
|
2001-06-25 02:58:41 -05:00
|
|
|
RetrieveDocumentObjects() ' Statusline, SheetsCollection etc.
|
2001-04-23 04:46:42 -05:00
|
|
|
InitializeConverter(oDocument.CharLocale, 1)
|
|
|
|
GetPreSelectedRange()
|
|
|
|
If GoOn Then
|
2001-10-31 09:24:41 -06:00
|
|
|
DialogConvert.GetControl("chkComplete").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
|
2001-06-25 02:58:41 -05:00
|
|
|
Dim MaxIndex as Integer
|
2001-04-23 04:46:42 -05:00
|
|
|
Listbox = DialogModel.lstSelection
|
|
|
|
If Ubound(Listbox.SelectedItems()) > -1 Then
|
|
|
|
EnableStep1DialogControls(False, False, False)
|
|
|
|
oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
|
|
|
|
|
|
|
|
' Is the sheet the basis, then the sheetobject has to be created
|
2001-06-25 02:58:41 -05:00
|
|
|
If DialogModel.optDocRanges.State = 1 Then
|
2001-04-23 04:46:42 -05:00
|
|
|
' 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
|
2001-06-25 02:58:41 -05:00
|
|
|
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)
|
2001-04-23 04:46:42 -05:00
|
|
|
End If
|
2001-06-25 02:58:41 -05:00
|
|
|
End If
|
|
|
|
Wend
|
|
|
|
Next i
|
2001-04-23 04:46:42 -05:00
|
|
|
Else
|
|
|
|
' 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)
|
2001-04-25 04:10:51 -05:00
|
|
|
oListSheet = RetrieveSheetoutofRangeName(RangeName)
|
2001-06-25 02:58:41 -05:00
|
|
|
a = a + 1
|
|
|
|
MaxIndex = Ubound(SelRangeList())
|
|
|
|
If a > MaxIndex Then
|
|
|
|
Redim Preserve SelRangeList(MaxIndex + SBRANGEUBOUND)
|
|
|
|
End If
|
|
|
|
SelRangeList(a) = RangeName
|
|
|
|
If oListSheet.Name = sCurSheetName Then
|
|
|
|
oRange = RetrieveRangeoutofRangeName(RangeName)
|
|
|
|
oSelRanges.InsertbyName("",oRange)
|
2001-04-23 04:46:42 -05:00
|
|
|
End If
|
|
|
|
Next n
|
|
|
|
End If
|
2001-06-25 02:58:41 -05:00
|
|
|
If a > -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
|
|
|
|
|
|
|
|
|
|
|
|
' 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)
|
|
|
|
|
|
|
|
' Controls around the Selection Listbox
|
2001-06-25 02:58:41 -05:00
|
|
|
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
|
2001-06-25 02:58:41 -05:00
|
|
|
End With
|
2001-09-21 08:45:18 -05:00
|
|
|
' The CheckBox has the Value '1' 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()) <> -1
|
2001-04-23 04:46:42 -05:00
|
|
|
' 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
|
|
|
' If FrameControls are enabled, check if Listbox is Empty
|
2001-09-12 06:30:01 -05:00
|
|
|
bObjectIsSelected = Ubound(DialogModel.lstSelection.SelectedItems()) <> -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
|
|
|
|
|
|
|
|
|
2001-04-25 04:10:51 -05:00
|
|
|
Sub ConvertRangesOrStylesOfDocument()
|
2001-04-23 04:46:42 -05:00
|
|
|
Dim i as Integer
|
|
|
|
Dim ItemName as String
|
2001-06-25 02:58:41 -05:00
|
|
|
Dim SelList() as String
|
2001-09-12 06:30:01 -05:00
|
|
|
Dim oSheetRanges as Object
|
2001-04-23 04:46:42 -05:00
|
|
|
|
2001-06-25 02:58:41 -05:00
|
|
|
bDocHasProtectedSheets = CheckSheetProtection(oSheets)
|
|
|
|
If bDocHasProtectedSheets Then
|
2001-06-25 13:03:49 -05:00
|
|
|
bDocHasProtectedSheets = UnprotectSheetsWithPassWord(oSheets, bDoUnProtect)
|
2001-06-25 02:58:41 -05:00
|
|
|
DialogModel.cmdGoOn.Enabled = False
|
2001-04-23 04:46:42 -05:00
|
|
|
End If
|
2001-06-25 02:58:41 -05:00
|
|
|
If Not bDocHasProtectedSheets Then
|
|
|
|
EnableStep1DialogControls(False, False, False)
|
|
|
|
InitializeProgressBar()
|
|
|
|
If DialogModel.optSelRange.State = 1 Then
|
|
|
|
SelectListItem()
|
|
|
|
End If
|
|
|
|
SelList() = DialogConvert.GetControl("lstSelection").SelectedItems()
|
|
|
|
If DialogModel.optCellTemplates.State = 1 Then
|
|
|
|
' Option 'Soft' 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
|
2001-06-25 02:58:41 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
' Alles was selektiert wurde wird deselektiert
|
|
|
|
Sub EmptySelection()
|
|
|
|
Dim RangeName as String
|
2001-06-25 02:58:41 -05:00
|
|
|
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, ";", MaxIndex)
|
2001-06-25 02:58:41 -05:00
|
|
|
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("com.sun.star.sheet.SheetCellRanges")
|
|
|
|
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("com.sun.star.sheet.SheetCellRanges")
|
|
|
|
' Check if a Currency-Range has been selected
|
2001-09-12 06:30:01 -05:00
|
|
|
oLocRange = oDocument.CurrentController.Selection
|
2001-11-06 10:19:36 -06:00
|
|
|
bPreSelected = oLocRange.SupportsService("com.sun.star.sheet.SheetCellRange")
|
|
|
|
If bPreSelected Then
|
|
|
|
oSelRanges.InsertbyName("",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
|
|
|
|
2001-11-06 10:19:36 -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)', 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)
|
2001-11-02 09:49:43 -06:00
|
|
|
EmptySelection()
|
|
|
|
AddRangeToListbox(oPreSelRange)
|
|
|
|
oPreSelRange = AddSelectedRangeToSelRangesEnum()
|
2001-04-23 04:46:42 -05:00
|
|
|
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
|
2001-04-25 04:10:51 -05:00
|
|
|
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()
|
2001-06-25 02:58:41 -05:00
|
|
|
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
|
2002-07-11 09:36:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>
|