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