update dev300-m58
[ooovba.git] / wizards / source / euro / ConvertRun.xba
bloba15c884122287133c918af1b8c3f290f6a372fd0
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
5 Public oPreSelRange as Object
7 Sub Main()
8 BasicLibraries.LoadLibrary(&quot;Tools&quot;)
9 If InitResources(&quot;Euro Converter&quot;, &quot;eur&quot;) Then
10 bDoUnProtect = False
11 bPreSelected = True
12 oDocument = ThisComponent
13 RetrieveDocumentObjects() &apos; Statusline, SheetsCollection etc.
14 InitializeConverter(oDocument.CharLocale, 1)
15 GetPreSelectedRange()
16 If GoOn Then
17 DialogModel.lstCurrencies.TabIndex = 2
18 DialogConvert.GetControl(&quot;chkComplete&quot;).SetFocus()
19 DialogConvert.Execute
20 End If
21 DialogConvert.Dispose
22 End If
23 End Sub
26 Sub SelectListItem()
27 Dim Listbox as Object
28 Dim oListSheet as Object
29 Dim CurStyleName as String
30 Dim oCursheet as Object
31 Dim oTempRanges as Object
32 Dim sCurSheetName as String
33 Dim RangeName as String
34 Dim oSheetRanges as Object
35 Dim ListIndex as Integer
36 Dim a as Integer
37 Dim i as Integer
38 Dim n as Integer
39 Dim m as Integer
40 Dim MaxIndex as Integer
41 Listbox = DialogModel.lstSelection
42 If Ubound(Listbox.SelectedItems()) &gt; -1 Then
43 EnableStep1DialogControls(False, False, False)
44 oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
46 &apos; Is the sheet the basis, then the sheetobject has to be created
47 If DialogModel.optDocRanges.State = 1 Then
48 &apos; Document is the basis for the conversion
49 ListIndex = Listbox.SelectedItems(0)
50 oCurSheet = RetrieveSheetoutofRangeName(Listbox.StringItemList(ListIndex))
51 oDocument.CurrentController.SetActiveSheet(oCurSheet)
52 Else
53 oCurSheet = oDocument.CurrentController.ActiveSheet
54 End If
55 sCurSheetName = oCurSheet.Name
56 If DialogModel.optCellTemplates.State = 1 Then
57 Dim CurIndex as Integer
58 For i = 0 To Ubound(Listbox.SelectedItems())
59 CurIndex = Listbox.SelectedItems(i)
60 CurStylename = Listbox.StringItemList(CurIndex)
61 oSheetRanges = oCursheet.CellFormatRanges.createEnumeration
62 While oSheetRanges.hasMoreElements
63 oRange = oSheetRanges.NextElement
64 If oRange.getPropertyState(&quot;NumberFormat&quot;) = 1 Then
65 If oRange.CellStyle = CurStyleName Then
66 oSelRanges.InsertbyName(&quot;&quot;,oRange)
67 End If
68 End If
69 Wend
70 Next i
71 Else
72 &apos; Hard Formatation is selected
73 a = -1
74 For n = 0 To Ubound(Listbox.SelectedItems())
75 m = Listbox.SelectedItems(n)
76 RangeName = Listbox.StringItemList(m)
77 oListSheet = RetrieveSheetoutofRangeName(RangeName)
78 a = a + 1
79 MaxIndex = Ubound(SelRangeList())
80 If a &gt; MaxIndex Then
81 Redim Preserve SelRangeList(MaxIndex + SBRANGEUBOUND)
82 End If
83 SelRangeList(a) = RangeName
84 If oListSheet.Name = sCurSheetName Then
85 oRange = RetrieveRangeoutofRangeName(RangeName)
86 oSelRanges.InsertbyName(&quot;&quot;,oRange)
87 End If
88 Next n
89 End If
90 If a &gt; -1 Then
91 ReDim Preserve SelRangeList(a)
92 Else
93 ReDim SelRangeList()
94 End If
95 oDocument.CurrentController.Select(oSelRanges)
96 EnableStep1DialogControls(True, True, True)
97 End If
98 End Sub
101 &apos; Procedure that is called by an event
102 Sub RetrieveEnableValue()
103 Dim EnableValue as Boolean
104 EnableValue = Not DialogModel.lstSelection.Enabled
105 EnableStep1DialogControls(True, EnableValue, True)
106 End Sub
109 Sub EnableStep1DialogControls(bCurrEnabled as Boolean, bFrameEnabled as Boolean, bButtonsEnabled as Boolean)
110 Dim bCurrIsSelected as Boolean
111 Dim bObjectIsSelected as Boolean
112 Dim bConvertWholeDoc as Boolean
113 Dim bDoEnableFrame as Boolean
114 bConvertWholeDoc = DialogModel.chkComplete.State = 1
115 bDoEnableFrame = bFrameEnabled And (NOT bConvertWholeDoc)
117 &apos; Controls around the Selection Listbox
118 With DialogModel
119 .lblCurrencies.Enabled = bCurrEnabled
120 .lstCurrencies.Enabled = bCurrEnabled
121 .lstSelection.Enabled = bDoEnableFrame
122 .lblSelection.Enabled = bDoEnableFrame
123 .hlnSelection.Enabled = bDoEnableFrame
124 .optCellTemplates.Enabled = bDoEnableFrame
125 .optSheetRanges.Enabled = bDoEnableFrame
126 .optDocRanges.Enabled = bDoEnableFrame
127 .optSelRange.Enabled = bDoEnableFrame
128 End With
129 &apos; The CheckBox has the Value &apos;1&apos; when the Controls in the Frame are disabled
130 If bButtonsEnabled Then
131 bCurrIsSelected = Ubound(DialogModel.lstCurrencies.SelectedItems()) &lt;&gt; -1
132 &apos; Enable GoOnButton only when Currency is selected
133 DialogModel.cmdGoOn.Enabled = bCurrIsSelected
134 DialogModel.chkComplete.Enabled = bCurrIsSelected
135 If bDoEnableFrame AND DialogModel.cmdGoOn.Enabled Then
136 &apos; If FrameControls are enabled, check if Listbox is Empty
137 bObjectIsSelected = Ubound(DialogModel.lstSelection.SelectedItems()) &lt;&gt; -1
138 DialogModel.cmdGoOn.Enabled = bObjectIsSelected
139 End If
140 Else
141 DialogModel.cmdGoOn.Enabled = False
142 DialogModel.chkComplete.Enabled = False
143 End If
144 End Sub
147 Sub ConvertRangesOrStylesOfDocument()
148 Dim i as Integer
149 Dim ItemName as String
150 Dim SelList() as String
151 Dim oSheetRanges as Object
153 bDocHasProtectedSheets = CheckSheetProtection(oSheets)
154 If bDocHasProtectedSheets Then
155 bDocHasProtectedSheets = UnprotectSheetsWithPassWord(oSheets, bDoUnProtect)
156 DialogModel.cmdGoOn.Enabled = False
157 End If
158 If Not bDocHasProtectedSheets Then
159 EnableStep1DialogControls(False, False, False)
160 InitializeProgressBar()
161 If DialogModel.optSelRange.State = 1 Then
162 SelectListItem()
163 End If
164 SelList() = DialogConvert.GetControl(&quot;lstSelection&quot;).SelectedItems()
165 If DialogModel.optCellTemplates.State = 1 Then
166 &apos; Option &apos;Soft&apos; Formatation is selected
167 AssignRangestoStyle(DialogModel.lstSelection.StringItemList(), SelList())
168 ConverttheSoftWay(SelList(), True)
169 ElseIf DialogModel.optSelRange.State = 1 Then
170 oSheetRanges = oPreSelRange.CellFormatRanges.createEnumeration
171 While oSheetRanges.hasMoreElements
172 oRange = oSheetRanges.NextElement
173 If CheckFormatType(oRange) Then
174 ConvertCellCurrencies(oRange)
175 SwitchNumberFormat(oRange, oFormats, sEuroSign)
176 End If
177 Wend
178 Else
179 ConverttheHardWay(SelList(), False, True)
180 End If
181 oStatusline.End
182 EnableStep1DialogControls(True, False, True)
183 DialogModel.cmdGoOn.Enabled = True
184 oDocument.CurrentController.Select(oSelRanges)
185 End If
186 End Sub
189 Sub ConvertWholeDocument()
190 Dim s as Integer
191 DialogModel.cmdGoOn.Enabled = False
192 DialogModel.chkComplete.Enabled = False
193 GoOn = ConvertDocument()
194 EmptyListbox(DialogModel.lstSelection())
195 EnableStep1DialogControls(True, True, True)
196 End Sub
199 &apos; Everything previously selected will be deselected
200 Sub EmptySelection()
201 Dim RangeName as String
202 Dim i as Integer
203 Dim MaxIndex as Integer
204 Dim EmptySelRangeList() as String
206 If Not IsNull(oSelRanges) Then
207 If oSelRanges.HasElements Then
208 EmptySelRangeList() = ArrayOutofString(oSelRanges.RangeAddressesasString, &quot;;&quot;, MaxIndex)
209 For i = 0 To MaxIndex
210 oSelRanges.RemovebyName(EmptySelRangeList(i))
211 Next i
212 End If
213 oDocument.CurrentController.Select(oSelRanges)
214 Else
215 oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
216 End If
217 End Sub
220 Function AddSelectedRangeToSelRangesEnum() as Object
221 Dim oLocRange as Object
222 osheet = oDocument.CurrentController.GetActiveSheet
223 oSelRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
224 &apos; Check if a Currency-Range has been selected
225 oLocRange = oDocument.CurrentController.Selection
226 bPreSelected = oLocRange.SupportsService(&quot;com.sun.star.sheet.SheetCellRange&quot;)
227 If bPreSelected Then
228 oSelRanges.InsertbyName(&quot;&quot;,oLocRange)
229 AddSelectedRangeToSelRangesEnum() = oLocRange
230 End If
231 End Function
234 Sub GetPreSelectedRange()
235 Dim i as Integer
236 Dim OldCurrSymbolList(2) as String
237 Dim OldCurrIndex as Integer
238 Dim OldCurExtension(2) as String
239 oPreSelRange = AddSelectedRangeToSelRangesEnum()
241 DialogModel.chkComplete.State = Abs(Not(bPreSelected))
242 If bPreSelected Then
243 DialogModel.optSelRange.State = 1
244 AddRangeToListbox(oPreSelRange)
245 Else
246 DialogModel.optCellTemplates.State = 1
247 CreateStyleEnumeration()
248 End If
249 EnableStep1DialogControls(True, bPreSelected, True)
250 DialogModel.optSelRange.Enabled = bPreSelected
251 End Sub
254 Sub AddRangeToListbox(oLocRange as Object)
255 EmptyListBox(DialogModel.lstSelection)
256 PreName = RetrieveRangeNamefromAddress(oLocRange)
257 AddSingleItemToListbox(DialogModel.lstSelection, Prename)&apos;, 0)
258 SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
259 TotCellCount = CountRangeCells(oLocRange)
260 End Sub
263 Sub CheckRangeSelection(Optional oEvent)
264 EmptySelection()
265 AddRangeToListbox(oPreSelRange)
266 oPreSelRange = AddSelectedRangeToSelRangesEnum()
267 End Sub
270 &apos; Checks if a Field (LocField) is already defined in an Array
271 &apos; Returns &apos;True&apos; or &apos;False&apos;
272 Function FieldinList(LocList(), MaxIndex as integer, ByVal LocField ) As Boolean
273 Dim i as integer
274 LocField = Ucase(LocField)
275 For i = Lbound(LocList()) to MaxIndex
276 If Ucase(LocList(i)) = LocField then
277 FieldInList = True
278 Exit Function
279 End if
280 Next
281 FieldInList = False
282 End Function
285 Function CheckLocale(oLocale) as Boolean
286 Dim i as Integer
287 Dim LocCountry as String
288 Dim LocLanguage as String
289 LocCountry = oLocale.Country
290 LocLanguage = oLocale.Language
291 For i = 0 To 1
292 If LocLanguage = LangIDValue(CurrIndex,i,0) AND LocCountry = LangIDValue(CurrIndex,i,1) Then
293 CheckLocale = True
294 Exit Function
295 End If
296 Next i
297 CheckLocale = False
298 End Function
301 Sub SetOptionValuestoNull()
302 With DialogModel
303 .optCellTemplates.State = 0
304 .optSheetRanges.State = 0
305 .optDocRanges.State = 0
306 .optSelRange.State = 0
307 End With
308 End Sub
312 Sub SetStatusLineText(sStsREPROTECT as String)
313 If Not IsNull(oStatusLine) Then
314 oStatusline.SetText(sStsREPROTECT)
315 End If
316 End Sub
317 </script:module>