xref: /trunk/main/wizards/source/depot/tools.xba (revision 019b6df1)
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3
4<!--***********************************************************
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements.  See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership.  The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License.  You may obtain a copy of the License at
13 *
14 *   http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied.  See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 *
23 ***********************************************************-->
24
25<script:module xmlns:script="http://openoffice.org/2000/script" script:name="tools" script:language="StarBasic">REM ***** BASIC *****
26
27Option Explicit
28
29Sub RemoveSheet()
30	If oSheets.HasbyName(&quot;Link&quot;) then
31		oSheets.RemovebyName(&quot;Link&quot;)
32	End If
33End Sub
34
35
36Sub InitializeStatusLine(StatusText as String, MaxValue as Integer, FirstValue as Integer)
37	oStatusline = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
38	oStatusLine.Start(StatusText, MaxValue)
39	oStatusline.SetValue(FirstValue)
40End Sub
41
42
43Sub MakeRangeVisible(oSheet as Object, RangeName as String, BIsVisible as Boolean)
44Dim oRangeAddress, oColumns as Object
45Dim i, iStartColumn, iEndColumn as Integer
46	oRangeAddress = oSheet.GetCellRangeByName(RangeName).RangeAddress
47	iStartColumn = oRangeAddress.StartColumn
48	iEndColumn = oRangeAddress.EndColumn
49	oColumns = oSheet.Columns
50	For i = iStartColumn To iEndColumn
51		oSheet.Columns(i).IsVisible = bIsVisible
52	Next i
53End Sub
54
55
56Function GetRowIndex(oSheet as Object, RowName as String)
57Dim oRange as Object
58	oRange = oSheet.GetCellRangeByName(RowName)
59	GetRowIndex = oRange.RangeAddress.StartRow
60End Function
61
62
63Function GetTransactionCount(iStartRow as Integer)
64Dim iEndRow as Integer
65	iStartRow = GetRowIndex(oMovementSheet, &quot;ColumnsToHide&quot;)
66	iEndRow = GetRowIndex(oMovementSheet, &quot;HiddenRow3&quot; )
67	GetTransactionCount = iEndRow -iStartRow - 2
68End Function
69
70
71Function GetStocksCount(iStartRow as Integer)
72Dim iEndRow as Integer
73	iStartRow = GetRowIndex(oFirstSheet, &quot;HiddenRow1&quot;)
74	iEndRow = GetRowIndex(oFirstSheet, &quot;HiddenRow2&quot;)
75	GetStocksCount = iEndRow -iStartRow - 1
76End Function
77
78
79Function FillListbox(ListboxControl as Object, MsgTitle as String, bShowMessage) as Boolean
80Dim i, StocksCount as Integer
81Dim iStartRow as Integer
82Dim oCell as Object
83	&apos; Add stock names to empty list box
84	StocksCount = GetStocksCount(iStartRow)
85	If StocksCount &gt; 0 Then
86		ListboxControl.Model.StringItemList() = NullList()
87		For i = 1 To StocksCount
88			oCell = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1,iStartRow + i)
89			ListboxControl.AddItem(oCell.String, i-1)
90		Next
91		FillListbox() = True
92	Else
93		If bShowMessage Then
94			Msgbox(sInsertStockName, 16, MsgTitle)
95			FillListbox() = False
96		End If
97	End If
98End Function
99
100
101Sub CellValuetoControl(oSheet, oControl as Object, CellName as String)
102Dim oCell as Object
103Dim StringValue
104	oCell = GetCellByName(oSheet, CellName)
105	If oControl.PropertySetInfo.HasPropertyByName(&quot;EffectiveValue&quot;) Then
106		oControl.EffectiveValue = oCell.Value
107	Else
108		oControl.Value = oCell.Value
109	End If
110&apos;	If oCell.FormulaResultType = 1 Then
111&apos;		StringValue = oNumberFormatter.GetInputString(oCell.NumberFormat, oCell.Value)
112&apos;		oControl.Text = DeleteStr(StringValue, &quot;%&quot;)
113&apos;	Else
114&apos;		oControl.Text = oCell.String
115&apos;	End If
116End Sub
117
118
119Sub RemoveStockRows(oSheet as Object, iStartRow, RowCount as Integer)
120	If RowCount &gt; 0 Then
121		oSheet.Rows.RemoveByIndex(iStartRow, RowCount)
122	End If
123End Sub
124
125
126Sub AddValueToCellContent(iCellCol, iCellRow as Integer, AddValue)
127Dim oCell as Object
128Dim OldValue
129	oCell = oMovementSheet.GetCellByPosition(iCellCol, iCellRow)
130	OldValue = oCell.Value
131	oCell.Value = OldValue + AddValue
132End Sub
133
134
135Sub CheckInputDate(aEvent as Object)
136Dim oRefDialog as Object
137Dim oRefModel as Object
138Dim oDateModel as Object
139	oDateModel = aEvent.Source.Model
140	oRefModel = DlgReference.GetControl(&quot;cmdGoOn&quot;).Model
141	oRefModel.Enabled = oDateModel.Date &lt;&gt; 0
142End Sub
143
144
145
146&apos; Updates the cell with the CurrentValue after checking if the
147&apos; Newdate is later than the one that is refered to in the annotation
148&apos; of the cell
149Sub InsertCurrentValue(CurValue as Double, iRow as Integer, Newdate as Date)
150Dim oCell as Object
151Dim OldDate as Date
152	oCell = oFirstSheet.GetCellByPosition(SBCOLUMNRATE1, iRow)
153	OldDate = CDate(oCell.Annotation.Text.String)
154	If NewDate &gt;= OldDate Then
155		oCell.SetValue(CurValue)
156		oCell.Annotation.Text.SetString(CStr(NewDate))
157	End If
158End Sub
159
160
161Sub SplitCellValue(oSheet, FirstNumber, SecondNumber, iCol, iRow, NoteText)
162Dim oCell as Object
163Dim OldValue
164	oCell = oSheet.GetCellByPosition(iCol, iRow)
165	OldValue = oCell.Value
166	oCell.Value = OldValue * FirstNumber / SecondNumber
167	If NoteText &lt;&gt; &quot;&quot; Then
168		oCell.Annotation.SetString(NoteText)
169	End If
170End Sub
171
172
173Function GetStockRowIndex(ByVal Stockname) as Integer
174Dim i, StocksCount as Integer
175Dim iStartRow as Integer
176Dim oCell as Object
177	StocksCount = GetStocksCount(iStartRow)
178	For i = 1 To StocksCount
179		oCell = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1,iStartRow + i)
180		If oCell.String = Stockname Then
181			GetStockRowIndex = iStartRow + i
182			Exit Function
183		End If
184	Next
185	GetStockRowIndex = -1
186End Function
187
188
189Function GetStockID(StockName as String, Optional iFirstRow as Integer) as String
190Dim CellStockName as String
191Dim i as Integer
192Dim iCount as Integer
193Dim iLastRow as Integer
194	If IsMissing(iFirstRow) Then
195		iFirstRow = GetRowIndex(oFirstSheet, &quot;HiddenRow1&quot;)
196	End If
197	iCount = GetStocksCount(iFirstRow)
198	iLastRow = iFirstRow + iCount
199	For i = iFirstRow To iLastRow
200		CellStockName = oFirstSheet.GetCellByPosition(SBCOLUMNNAME1, i).String
201		If CellStockname = StockName Then
202			Exit For
203		End If
204	Next i
205	If i &gt; iLastRow Then
206		GetStockID() = &quot;&quot;
207	Else
208		If Not IsMissing(iFirstRow) Then
209			iFirstRow = i
210		End If
211		GetStockID() = oFirstSheet.GetCellByPosition(SBCOLUMNID1, i).String
212	End If
213End Function
214
215
216Function CheckDocLocale(LocLanguage as String, LocCountry as String)
217Dim bIsDocLanguage as Boolean
218Dim bIsDocCountry as Boolean
219	bIsDocLanguage = Instr(1, LocLanguage, sDocLanguage, SBBINARY) &lt;&gt; 0
220	bIsDocCountry = Instr(1, LocCountry, sDocCountry, SBBINARY) &lt;&gt; 0 OR SDocCountry = &quot;&quot;
221	CheckDocLocale = (bIsDocLanguage And bIsDocCountry)
222End Function
223</script:module>
224