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