xref: /aoo42x/main/wizards/source/depot/Currency.xba (revision 3e02b54d)
1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
23cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Currency" script:language="StarBasic">REM  *****  BASIC  *****
24cdf0e10cSrcweirOption Explicit
25cdf0e10cSrcweir
26cdf0e10cSrcweirDim bDoUnLoad as Boolean
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweirSub Startup()
30cdf0e10cSrcweirDim i as Integer
31cdf0e10cSrcweirDim a as Integer
32cdf0e10cSrcweirDim ListString as String
33cdf0e10cSrcweirDim MarketListBoxControl as Object
34cdf0e10cSrcweir	Initialize(False)
35cdf0e10cSrcweir	MarketListBoxControl = DlgStartUp.GetControl(&quot;lstMarkets&quot;)
36cdf0e10cSrcweir	a = 0
37cdf0e10cSrcweir	For i = 0 To Ubound(sMarket(),1)
38cdf0e10cSrcweir		ListString = sMarket(i,0)
39cdf0e10cSrcweir		If sMarket(i,0) &lt;&gt; &quot;&quot; Then
40cdf0e10cSrcweir			If sMarket(i,3) = &quot;&quot; Then
41cdf0e10cSrcweir				ListString = ListString &amp; &quot;    (&quot; &amp; sNoInternetUpdate &amp; &quot;)&quot;
42cdf0e10cSrcweir			Else
43cdf0e10cSrcweir				ListString = ListString &amp; &quot;    (&quot; &amp; sMarketplace &amp; &quot; &quot; &amp; sMarket(i,2) &amp; &quot;)&quot;
44cdf0e10cSrcweir			End If
45cdf0e10cSrcweir			MarketListBoxControl.AddItem(ListString, a)
46cdf0e10cSrcweir			a = a + 1
47cdf0e10cSrcweir		End If
48cdf0e10cSrcweir	Next i
49cdf0e10cSrcweir	MarketListBoxControl.SelectItemPos(GlobListIndex, True)
50cdf0e10cSrcweir	DlgStartUp.Title = sDepotCurrency
51cdf0e10cSrcweir	DlgStartUp.Model.cmdGoOn.DefaultButton = True
52cdf0e10cSrcweir	DlgStartUp.GetControl(&quot;lstMarkets&quot;).SetFocus()
53cdf0e10cSrcweir	DlgStartUp.Execute()
54cdf0e10cSrcweir	DlgStartUp.Dispose()
55cdf0e10cSrcweirEnd Sub
56cdf0e10cSrcweir
57cdf0e10cSrcweir
58cdf0e10cSrcweirSub EnableGoOnButton()
59cdf0e10cSrcweir	StartUpModel.cmdGoOn.Enabled = True
60cdf0e10cSrcweir	StartUpModel.cmdGoOn.DefaultButton = True
61cdf0e10cSrcweirEnd Sub
62cdf0e10cSrcweir
63cdf0e10cSrcweir
64cdf0e10cSrcweirSub CloseStartUpDialog()
65cdf0e10cSrcweir	DlgStartUp.EndExecute()
66cdf0e10cSrcweir&apos;	oDocument.Dispose()
67cdf0e10cSrcweirEnd Sub
68cdf0e10cSrcweir
69cdf0e10cSrcweir
70cdf0e10cSrcweirSub DisposeDocument()
71cdf0e10cSrcweir	If bDoUnload Then
72cdf0e10cSrcweir		oDocument.Dispose()
73cdf0e10cSrcweir	End If
74cdf0e10cSrcweirEnd Sub
75cdf0e10cSrcweir
76cdf0e10cSrcweir
77cdf0e10cSrcweirSub ChooseMarket(Optional aEvent)
78cdf0e10cSrcweirDim Index as Integer
79cdf0e10cSrcweirDim bIsDocLanguage as Boolean
80cdf0e10cSrcweirDim bIsDocCountry as Boolean
81cdf0e10cSrcweir	oInternetModel = GetControlModel(oDocument.Sheets(0), &quot;CmdInternet&quot;)
82cdf0e10cSrcweir	If Not IsMissing(aEvent) Then
83cdf0e10cSrcweir		Index = StartupModel.lstMarkets.SelectedItems(0)
84cdf0e10cSrcweir		oInternetModel.Tag = Index
85cdf0e10cSrcweir	Else
86cdf0e10cSrcweir		Index = oInternetModel.Tag
87cdf0e10cSrcweir	End If
88cdf0e10cSrcweir	oMarketModel = GetControlModel(oDocument.Sheets(0), &quot;CmdHistory&quot;)
89cdf0e10cSrcweir	sCurCurrency = sMarket(Index,1)
90cdf0e10cSrcweir	If Index = 0 Then
91cdf0e10cSrcweir		HistoryChartSource = sMarket(Index,4)
92cdf0e10cSrcweir	End If
93cdf0e10cSrcweir	sCurStockIDLabel = sMarket(Index,5)
94cdf0e10cSrcweir	sCurExtension = sMarket(Index,8)
95cdf0e10cSrcweir	iValueCol = Val(sMarket(Index,10)
96cdf0e10cSrcweir	If Instr(sCurExtension,&quot;;&quot;) &lt;&gt; 0 Then
97cdf0e10cSrcweir		&apos; Take the german extension as the stock place is Frankfurt
98cdf0e10cSrcweir		sCurExtension = &quot;407&quot;
99cdf0e10cSrcweir	End If
100cdf0e10cSrcweir	sCurChartSource = sMarket(Index,3)
101cdf0e10cSrcweir	bIsDocLanguage = Instr(1, sMarket(Index,6), sDocLanguage, SBBINARY) &lt;&gt; 0
102cdf0e10cSrcweir	bIsDocCountry = Instr(1, sMarket(Index,7), sDocCountry, SBBINARY) &lt;&gt; 0  OR SDocCountry = &quot;&quot;
103cdf0e10cSrcweir	sCurSeparator = sMarket(Index,9)
104cdf0e10cSrcweir	TransactModel.txtRate.CurrencySymbol = sCurCurrency
105cdf0e10cSrcweir	TransactModel.txtFix.CurrencySymbol = sCurCurrency
106cdf0e10cSrcweir	TransactModel.txtMinimum.CurrencySymbol = sCurCurrency
107cdf0e10cSrcweir	bEnableMarket = Index = 0
108cdf0e10cSrcweir	bEnableInternet = sCurChartSource &lt;&gt; &quot;&quot;
109cdf0e10cSrcweir	oMarketModel.Enabled = bEnableMarket
110cdf0e10cSrcweir	oInternetModel.Enabled = bEnableInternet
111cdf0e10cSrcweir	If Not IsMissing(aEvent) Then
112cdf0e10cSrcweir		ConvertStylesCurrencies()
113cdf0e10cSrcweir		bDoUnload = False
114cdf0e10cSrcweir		DlgStartUp.EndExecute()
115cdf0e10cSrcweir	End If
116cdf0e10cSrcweirEnd Sub
117cdf0e10cSrcweir
118cdf0e10cSrcweir
119cdf0e10cSrcweirSub ConvertStylesCurrencies()
120cdf0e10cSrcweirDim m as integer
121cdf0e10cSrcweirDim aStyleFormat as Object
122cdf0e10cSrcweirDim StyleName as String
123cdf0e10cSrcweirDim bAddToList as Boolean
124cdf0e10cSrcweirDim oStyle as Object
125cdf0e10cSrcweirDim oStyles as Object
126cdf0e10cSrcweir 	UnprotectSheets(oSheets)
127cdf0e10cSrcweir	oFirstSheet.GetCellByPosition(SBCOLUMNID1, SBROWHEADER1).SetString(sCurStockIDLabel)
128cdf0e10cSrcweir	oStyles = oDocument.StyleFamilies.GetbyIndex(0)
129cdf0e10cSrcweir	For m = 0 To oStyles.count-1
130cdf0e10cSrcweir		oStyle = oStyles.GetbyIndex(m)
131cdf0e10cSrcweir		StyleName = oStyle.Name
132cdf0e10cSrcweir		bAddToList = CheckFormatType(oStyle)
133cdf0e10cSrcweir		If bAddToList Then
134cdf0e10cSrcweir			SwitchNumberFormat(ostyle, oDocFormats, sCurCurrency, sCurExtension)
135cdf0e10cSrcweir		End If
136cdf0e10cSrcweir	Next m
137cdf0e10cSrcweir	ProtectSheets(oSheets)
138cdf0e10cSrcweirEnd Sub
139cdf0e10cSrcweir
140cdf0e10cSrcweir
141cdf0e10cSrcweirSub SwitchNumberFormat(oObject as Object, oFormats as object, sNewSymbol as String, sNewExtension as String)
142cdf0e10cSrcweirDim nFormatLanguage as Integer
143cdf0e10cSrcweirDim nFormatDecimals as Integer
144cdf0e10cSrcweirDim nFormatLeading as Integer
145cdf0e10cSrcweirDim bFormatLeading as Integer
146cdf0e10cSrcweirDim bFormatNegRed as Integer
147cdf0e10cSrcweirDim bFormatThousands as Integer
148cdf0e10cSrcweirDim aNewStr as String
149cdf0e10cSrcweirDim iNumberFormat as Long
150cdf0e10cSrcweirDim sSimpleStr as String
151cdf0e10cSrcweirDim nSimpleKey as Long
152cdf0e10cSrcweirDim aFormat()
153cdf0e10cSrcweirDim oLocale as New com.sun.star.lang.Locale
154cdf0e10cSrcweir	&apos; Numberformat with the new Symbol as Base for new Format
155cdf0e10cSrcweir	sSimpleStr = &quot;0 [$&quot; &amp; sNewSymbol &amp; &quot;-&quot; &amp; sNewExtension &amp; &quot;]&quot;
156cdf0e10cSrcweir	nSimpleKey = Numberformat(oFormats, sSimpleStr, oDocLocale)
157cdf0e10cSrcweir	On Local Error Resume Next
158cdf0e10cSrcweir	iNumberFormat = oObject.NumberFormat
159cdf0e10cSrcweir	If Err &lt;&gt; 0 Then
160cdf0e10cSrcweir		Msgbox &quot;Error Reading the Number Format&quot;
161cdf0e10cSrcweir		Resume CLERROR
162cdf0e10cSrcweir	End If
163cdf0e10cSrcweir
164cdf0e10cSrcweir	On Local Error GoTo NOKEY
165cdf0e10cSrcweir	aFormat() = oFormats.getByKey(iNumberFormat)
166cdf0e10cSrcweir	On Local Error GoTo 0
167cdf0e10cSrcweir	&apos; set new currency format with according settings
168cdf0e10cSrcweir	nFormatDecimals = aFormat.Decimals
169cdf0e10cSrcweir	nFormatLeading = aFormat.LeadingZeros
170cdf0e10cSrcweir	bFormatNegRed = aFormat.NegativeRed
171cdf0e10cSrcweir	bFormatThousands = aFormat.ThousandsSeparator
172cdf0e10cSrcweir	oLocale = aFormat.Locale
173cdf0e10cSrcweir	aNewStr = oFormats.generateFormat(nSimpleKey, oLocale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
174cdf0e10cSrcweir	oObject.NumberFormat = Numberformat(oFormats, aNewStr, oLocale)
175cdf0e10cSrcweir	NOKEY:
176cdf0e10cSrcweir	If Err &lt;&gt; 0 Then
177cdf0e10cSrcweir		Resume CLERROR
178cdf0e10cSrcweir	End If
179cdf0e10cSrcweir	CLERROR:
180cdf0e10cSrcweirEnd Sub
181cdf0e10cSrcweir
182cdf0e10cSrcweir
183cdf0e10cSrcweirFunction Numberformat( oFormats as Object, aFormatStr as String, oLocale as Variant )
184cdf0e10cSrcweirDim nRetkey
185cdf0e10cSrcweir	nRetKey = oFormats.queryKey(aFormatStr, oLocale, True)
186cdf0e10cSrcweir	If nRetKey = -1 Then
187cdf0e10cSrcweir		nRetKey = oFormats.addNew( aFormatStr, oLocale )
188cdf0e10cSrcweir		If nRetKey = -1 Then nRetKey = 0
189cdf0e10cSrcweir	End If
190cdf0e10cSrcweir	Numberformat = nRetKey
191cdf0e10cSrcweirEnd Function
192cdf0e10cSrcweir
193cdf0e10cSrcweir
194cdf0e10cSrcweirFunction CheckFormatType(oStyle as Object)
195cdf0e10cSrcweirDim oFormatofObject as Object
196cdf0e10cSrcweir	oFormatofObject = oDocFormats.getByKey(oStyle.NumberFormat)
197cdf0e10cSrcweir  	CheckFormatType = INT(oFormatOfObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
198*3e02b54dSAndrew RistEnd Function</script:module>
199