xref: /aoo41x/main/wizards/source/euro/Hard.xba (revision cdf0e10c)
1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Hard" script:language="StarBasic">REM  *****  BASIC  *****
4*cdf0e10cSrcweirOption Explicit
5*cdf0e10cSrcweir
6*cdf0e10cSrcweir
7*cdf0e10cSrcweirSub CreateRangeList()
8*cdf0e10cSrcweirDim MaxIndex as Integer
9*cdf0e10cSrcweir	MaxIndex = -1
10*cdf0e10cSrcweir	EnableStep1DialogControls(False, False, False)
11*cdf0e10cSrcweir	EmptySelection()
12*cdf0e10cSrcweir	DialogModel.lblSelection.Label = sCURRRANGES
13*cdf0e10cSrcweir	EmptyListbox(DialogModel.lstSelection)
14*cdf0e10cSrcweir	oDocument.CurrentController.Select(oSelRanges)
15*cdf0e10cSrcweir	If (DialogModel.optSheetRanges.State = 1) AND (DialogModel.chkComplete.State &lt;&gt; 1) Then
16*cdf0e10cSrcweir		&apos; Conversion on a sheet?
17*cdf0e10cSrcweir		SetStatusLineText(sStsRELRANGES)
18*cdf0e10cSrcweir		osheet = oDocument.CurrentController.GetActiveSheet
19*cdf0e10cSrcweir		oRanges = osheet.CellFormatRanges.createEnumeration()
20*cdf0e10cSrcweir		MaxIndex = AddSheetRanges(oRanges, MaxIndex, oSheet, False)
21*cdf0e10cSrcweir		If MaxIndex &gt; -1 Then
22*cdf0e10cSrcweir			ReDim Preserve RangeList(MaxIndex)
23*cdf0e10cSrcweir		End If
24*cdf0e10cSrcweir	Else
25*cdf0e10cSrcweir		CreateRangeEnumeration(False)
26*cdf0e10cSrcweir		bRangeListDefined = True
27*cdf0e10cSrcweir	End If
28*cdf0e10cSrcweir	EnableStep1DialogControls(True, True, True)
29*cdf0e10cSrcweir	SetStatusLineText(&quot;&quot;)
30*cdf0e10cSrcweirEnd Sub
31*cdf0e10cSrcweir
32*cdf0e10cSrcweir
33*cdf0e10cSrcweirSub CreateRangeEnumeration(bAutopilot as Boolean)
34*cdf0e10cSrcweirDim i as Integer
35*cdf0e10cSrcweirDim MaxIndex as integer
36*cdf0e10cSrcweirDim sStatustext as String
37*cdf0e10cSrcweir	MaxIndex = -1
38*cdf0e10cSrcweir	If Not bRangeListDefined Then
39*cdf0e10cSrcweir		&apos; Cellranges are not yet defined
40*cdf0e10cSrcweir		oSheets = oDocument.Sheets
41*cdf0e10cSrcweir		For i = 0 To oSheets.Count-1
42*cdf0e10cSrcweir			oSheet = oSheets.GetbyIndex(i)
43*cdf0e10cSrcweir			If bAutopilot Then
44*cdf0e10cSrcweir				IncreaseStatusValue(SBRELGET/osheets.Count)
45*cdf0e10cSrcweir			Else
46*cdf0e10cSrcweir				sStatustext = ReplaceString(sStsRELSHEETRANGES,Str(i+1),&quot;%1Number%1&quot;)
47*cdf0e10cSrcweir				sStatustext = ReplaceString(sStatusText,oSheets.Count,&quot;%2TotPageCount%2&quot;)
48*cdf0e10cSrcweir				SetStatusLineText(sStatusText)
49*cdf0e10cSrcweir			End If
50*cdf0e10cSrcweir			oRanges = osheet.CellFormatRanges.createEnumeration
51*cdf0e10cSrcweir			MaxIndex = AddSheetRanges(oRanges, MaxIndex, oSheet, bAutopilot)
52*cdf0e10cSrcweir		Next i
53*cdf0e10cSrcweir	Else
54*cdf0e10cSrcweir		If Not bAutoPilot Then
55*cdf0e10cSrcweir			SetStatusLineText(sStsRELRANGES)
56*cdf0e10cSrcweir			&apos; cellranges already defined
57*cdf0e10cSrcweir			For i = 0 To Ubound(RangeList())
58*cdf0e10cSrcweir				If RangeList(i) &lt;&gt; &quot;&quot; Then
59*cdf0e10cSrcweir					AddSingleItemToListBox(DialogModel.lstSelection, RangeList(i))
60*cdf0e10cSrcweir				End If
61*cdf0e10cSrcweir			Next
62*cdf0e10cSrcweir		End If
63*cdf0e10cSrcweir	End If
64*cdf0e10cSrcweir	If MaxIndex &gt; -1 Then
65*cdf0e10cSrcweir		ReDim Preserve RangeList(MaxIndex)
66*cdf0e10cSrcweir	Else
67*cdf0e10cSrcweir		ReDim RangeList()
68*cdf0e10cSrcweir	End If
69*cdf0e10cSrcweir	Rangeindex = MaxIndex
70*cdf0e10cSrcweirEnd Sub
71*cdf0e10cSrcweir
72*cdf0e10cSrcweir
73*cdf0e10cSrcweirFunction AddSheetRanges(oRanges as Object, r as Integer, oSheet as Object, bAutopilot)
74*cdf0e10cSrcweirDim RangeName as String
75*cdf0e10cSrcweirDim AddtoList as Boolean
76*cdf0e10cSrcweirDim iCurStep as Integer
77*cdf0e10cSrcweirDim MaxIndex as Integer
78*cdf0e10cSrcweir	iCurStep = DialogModel.Step
79*cdf0e10cSrcweir	While oRanges.hasMoreElements
80*cdf0e10cSrcweir		oRange = oRanges.NextElement
81*cdf0e10cSrcweir		AddToList = CheckFormatType(oRange)
82*cdf0e10cSrcweir		If AddToList Then
83*cdf0e10cSrcweir			RangeName = RetrieveRangeNamefromAddress(oRange)
84*cdf0e10cSrcweir			TotCellCount = TotCellCount + CountRangeCells(oRange)
85*cdf0e10cSrcweir			If Not bAutoPilot Then
86*cdf0e10cSrcweir				AddSingleItemToListbox(DialogModel.lstSelection, RangeName)
87*cdf0e10cSrcweir			End If
88*cdf0e10cSrcweir			&apos; The Ranges are only passed to an Array when the whole Document is the basis
89*cdf0e10cSrcweir			&apos; Redimension the RangeList Array if necessary
90*cdf0e10cSrcweir			MaxIndex = Ubound(RangeList())
91*cdf0e10cSrcweir			r = r + 1
92*cdf0e10cSrcweir			If r &gt; MaxIndex Then
93*cdf0e10cSrcweir				MaxIndex = MaxIndex + SBRANGEUBOUND
94*cdf0e10cSrcweir				ReDim Preserve RangeList(MaxIndex)
95*cdf0e10cSrcweir			End If
96*cdf0e10cSrcweir			RangeList(r) = RangeName
97*cdf0e10cSrcweir		End If
98*cdf0e10cSrcweir	Wend
99*cdf0e10cSrcweir	AddSheetRanges = r
100*cdf0e10cSrcweirEnd Function
101*cdf0e10cSrcweir
102*cdf0e10cSrcweir
103*cdf0e10cSrcweir&apos; adds a section to the collection
104*cdf0e10cSrcweirSub SelectRange()
105*cdf0e10cSrcweirDim i as Integer
106*cdf0e10cSrcweirDim RangeName as String
107*cdf0e10cSrcweirDim SelItem as String
108*cdf0e10cSrcweirDim CurRange as String
109*cdf0e10cSrcweirDim SheetRangeName as String
110*cdf0e10cSrcweirDim DescriptionList() as String
111*cdf0e10cSrcweirDim MaxRangeIndex as Integer
112*cdf0e10cSrcweirDim StatusValue as Integer
113*cdf0e10cSrcweir	StatusValue = 0
114*cdf0e10cSrcweir	MaxRangeIndex = Ubound(SelRangeList())
115*cdf0e10cSrcweir	CurSheetName = oSheet.Name
116*cdf0e10cSrcweir	For i = 0 To MaxRangeIndex
117*cdf0e10cSrcweir		SelItem = SelRangeList(i)
118*cdf0e10cSrcweir		&apos; Is the Range already included in the collection?
119*cdf0e10cSrcweir		oRange = RetrieveRangeoutOfRangename(SelItem)
120*cdf0e10cSrcweir		TotCellCount = TotCellCount + CountRangeCells(oRange)
121*cdf0e10cSrcweir		DescriptionList() = ArrayOutofString(SelItem,&quot;.&quot;,1)
122*cdf0e10cSrcweir		SheetRangeName = DeleteStr(DescriptionList(0),&quot;&apos;&quot;)
123*cdf0e10cSrcweir		If SheetRangeName = CurSheetName Then
124*cdf0e10cSrcweir			oSelRanges.InsertbyName(&quot;&quot;,oRange)
125*cdf0e10cSrcweir		End If
126*cdf0e10cSrcweir		IncreaseStatusValue(SBRELGET/MaxRangeIndex)
127*cdf0e10cSrcweir	Next i
128*cdf0e10cSrcweirEnd Sub
129*cdf0e10cSrcweir
130*cdf0e10cSrcweir
131*cdf0e10cSrcweirSub ConvertThehardWay(ListboxList(), SwitchFormat as Boolean, bRemove as Boolean)
132*cdf0e10cSrcweirDim i as Integer
133*cdf0e10cSrcweirDim AddCells as Long
134*cdf0e10cSrcweirDim OldStatusValue as Single
135*cdf0e10cSrcweirDim RangeName as String
136*cdf0e10cSrcweirDim LastIndex as Integer
137*cdf0e10cSrcweirDim oSelListbox as Object
138*cdf0e10cSrcweir
139*cdf0e10cSrcweir	oSelListbox = DialogConvert.GetControl(&quot;lstSelection&quot;)
140*cdf0e10cSrcweir	Lastindex = Ubound(ListboxList())
141*cdf0e10cSrcweir	If TotCellCount &gt; 0 Then
142*cdf0e10cSrcweir		OldStatusValue = StatusValue
143*cdf0e10cSrcweir		&apos; hard format
144*cdf0e10cSrcweir		For i = 0 To LastIndex
145*cdf0e10cSrcweir			RangeName = ListboxList(i)
146*cdf0e10cSrcweir			oRange = RetrieveRangeoutofRangeName(RangeName)
147*cdf0e10cSrcweir			ConvertCellCurrencies(oRange)
148*cdf0e10cSrcweir			If bRemove Then
149*cdf0e10cSrcweir				If oSelRanges.HasbyName(RangeName) Then
150*cdf0e10cSrcweir					oSelRanges.RemovebyName(RangeName)
151*cdf0e10cSrcweir					oDocument.CurrentController.Select(oSelRanges)
152*cdf0e10cSrcweir				End If
153*cdf0e10cSrcweir			End If
154*cdf0e10cSrcweir			If SwitchFormat Then
155*cdf0e10cSrcweir				If oRange.getPropertyState(&quot;NumberFormat&quot;) &lt;&gt; 1 Then
156*cdf0e10cSrcweir					&apos; Range is hard formatted
157*cdf0e10cSrcweir					SwitchNumberFormat(oRange, oFormats, sEuroSign)
158*cdf0e10cSrcweir				End If
159*cdf0e10cSrcweir			Else
160*cdf0e10cSrcweir				SwitchNumberFormat(oRange, oFormats, sEuroSign)
161*cdf0e10cSrcweir			End If
162*cdf0e10cSrcweir			AddCells = CountRangeCells(oRange)
163*cdf0e10cSrcweir			CurCellCount = AddCells
164*cdf0e10cSrcweir			IncreaseStatusValue((CurCellCount/TotCellCount)*(100-OldStatusValue))
165*cdf0e10cSrcweir			If bRemove Then
166*cdf0e10cSrcweir				RemoveListBoxItemByName(oSelListbox.Model,Rangename)
167*cdf0e10cSrcweir			End If
168*cdf0e10cSrcweir		Next
169*cdf0e10cSrcweir	End If
170*cdf0e10cSrcweirEnd Sub
171*cdf0e10cSrcweir
172*cdf0e10cSrcweir
173*cdf0e10cSrcweirSub ConvertCellCurrencies(oRange as Object)
174*cdf0e10cSrcweirDim oValues as Object
175*cdf0e10cSrcweirDim oCells as Object
176*cdf0e10cSrcweirDim oCell as Object
177*cdf0e10cSrcweir  	oValues = oRange.queryContentCells(com.sun.star.sheet.CellFlags.VALUE)
178*cdf0e10cSrcweir	If (oValues.Count &gt; 0) Then
179*cdf0e10cSrcweir		oCells = oValues.Cells.createEnumeration
180*cdf0e10cSrcweir		While oCells.hasMoreElements
181*cdf0e10cSrcweir			oCell = oCells.nextElement
182*cdf0e10cSrcweir			ModifyObjectValuewithCurrFactor(oCell)
183*cdf0e10cSrcweir		Wend
184*cdf0e10cSrcweir	End If
185*cdf0e10cSrcweirEnd Sub
186*cdf0e10cSrcweir
187*cdf0e10cSrcweir
188*cdf0e10cSrcweirSub ModifyObjectValuewithCurrFactor(oDocObject as Object)
189*cdf0e10cSrcweirDim oDocObjectValue as double
190*cdf0e10cSrcweir	oDocObjectValue = oDocObject.Value
191*cdf0e10cSrcweir	oDocObject.Value = Round(oDocObjectValue/CurrFactor, 2)
192*cdf0e10cSrcweirEnd Sub
193*cdf0e10cSrcweir
194*cdf0e10cSrcweir
195*cdf0e10cSrcweirFunction CheckIfRangeisCurrency(FormatObject as Object)
196*cdf0e10cSrcweirDim oFormatofObject() as Object
197*cdf0e10cSrcweir	&apos; Retrieve the Format of the Object
198*cdf0e10cSrcweir	On Local Error GoTo NOKEY
199*cdf0e10cSrcweir	oFormatofObject() = oFormats.getByKey(FormatObject.NumberFormat)
200*cdf0e10cSrcweir	On Local Error GoTo 0
201*cdf0e10cSrcweir	CheckIfRangeIsCurrency = INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
202*cdf0e10cSrcweir	Exit Function
203*cdf0e10cSrcweirNOKEY:
204*cdf0e10cSrcweir	CheckIfRangeisCurrency = False
205*cdf0e10cSrcweir	Resume CLERROR
206*cdf0e10cSrcweir	CLERROR:
207*cdf0e10cSrcweirEnd Function
208*cdf0e10cSrcweir
209*cdf0e10cSrcweir
210*cdf0e10cSrcweirFunction CountColumnsForRow(IndexArray() as String, Row as Integer)
211*cdf0e10cSrcweirDim i as Integer
212*cdf0e10cSrcweirDim NoNulls as Boolean
213*cdf0e10cSrcweir	For i = 1 To Ubound(IndexArray,2)
214*cdf0e10cSrcweir		If IndexArray(Row,i)= &quot;&quot; Then
215*cdf0e10cSrcweir			NoNulls = False
216*cdf0e10cSrcweir			Exit For
217*cdf0e10cSrcweir		End If
218*cdf0e10cSrcweir	Next
219*cdf0e10cSrcweir	CountColumnsForRow = i
220*cdf0e10cSrcweirEnd Function
221*cdf0e10cSrcweir
222*cdf0e10cSrcweir
223*cdf0e10cSrcweirFunction CountRangeCells(oRange as Object) As Long
224*cdf0e10cSrcweirDim oRangeAddress as Object
225*cdf0e10cSrcweirDim LocCellCount as Long
226*cdf0e10cSrcweir	oRangeAddress = oRange.RangeAddress
227*cdf0e10cSrcweir	LocCellCount = (oRangeAddress.EndColumn - oRangeAddress.StartColumn + 1) * (oRangeAddress.EndRow - oRangeAddress.StartRow + 1)
228*cdf0e10cSrcweir	CountRangeCells = LocCellCount
229*cdf0e10cSrcweirEnd Function</script:module>