xref: /trunk/main/wizards/source/depot/Currency.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="Currency" script:language="StarBasic">REM  *****  BASIC  *****
24Option Explicit
25
26Dim bDoUnLoad as Boolean
27
28
29Sub Startup()
30Dim i as Integer
31Dim a as Integer
32Dim ListString as String
33Dim MarketListBoxControl as Object
34	Initialize(False)
35	MarketListBoxControl = DlgStartUp.GetControl(&quot;lstMarkets&quot;)
36	a = 0
37	For i = 0 To Ubound(sMarket(),1)
38		ListString = sMarket(i,0)
39		If sMarket(i,0) &lt;&gt; &quot;&quot; Then
40			If sMarket(i,3) = &quot;&quot; Then
41				ListString = ListString &amp; &quot;    (&quot; &amp; sNoInternetUpdate &amp; &quot;)&quot;
42			Else
43				ListString = ListString &amp; &quot;    (&quot; &amp; sMarketplace &amp; &quot; &quot; &amp; sMarket(i,2) &amp; &quot;)&quot;
44			End If
45			MarketListBoxControl.AddItem(ListString, a)
46			a = a + 1
47		End If
48	Next i
49	MarketListBoxControl.SelectItemPos(GlobListIndex, True)
50	DlgStartUp.Title = sDepotCurrency
51	DlgStartUp.Model.cmdGoOn.DefaultButton = True
52	DlgStartUp.GetControl(&quot;lstMarkets&quot;).SetFocus()
53	DlgStartUp.Execute()
54	DlgStartUp.Dispose()
55End Sub
56
57
58Sub EnableGoOnButton()
59	StartUpModel.cmdGoOn.Enabled = True
60	StartUpModel.cmdGoOn.DefaultButton = True
61End Sub
62
63
64Sub CloseStartUpDialog()
65	DlgStartUp.EndExecute()
66&apos;	oDocument.Dispose()
67End Sub
68
69
70Sub DisposeDocument()
71	If bDoUnload Then
72		oDocument.Dispose()
73	End If
74End Sub
75
76
77Sub ChooseMarket(Optional aEvent)
78Dim Index as Integer
79Dim bIsDocLanguage as Boolean
80Dim bIsDocCountry as Boolean
81	oInternetModel = GetControlModel(oDocument.Sheets(0), &quot;CmdInternet&quot;)
82	If Not IsMissing(aEvent) Then
83		Index = StartupModel.lstMarkets.SelectedItems(0)
84		oInternetModel.Tag = Index
85	Else
86		Index = oInternetModel.Tag
87	End If
88	oMarketModel = GetControlModel(oDocument.Sheets(0), &quot;CmdHistory&quot;)
89	sCurCurrency = sMarket(Index,1)
90	If Index = 0 Then
91		HistoryChartSource = sMarket(Index,4)
92	End If
93	sCurStockIDLabel = sMarket(Index,5)
94	sCurExtension = sMarket(Index,8)
95	iValueCol = Val(sMarket(Index,10)
96	If Instr(sCurExtension,&quot;;&quot;) &lt;&gt; 0 Then
97		&apos; Take the german extension as the stock place is Frankfurt
98		sCurExtension = &quot;407&quot;
99	End If
100	sCurChartSource = sMarket(Index,3)
101	bIsDocLanguage = Instr(1, sMarket(Index,6), sDocLanguage, SBBINARY) &lt;&gt; 0
102	bIsDocCountry = Instr(1, sMarket(Index,7), sDocCountry, SBBINARY) &lt;&gt; 0  OR SDocCountry = &quot;&quot;
103	sCurSeparator = sMarket(Index,9)
104	TransactModel.txtRate.CurrencySymbol = sCurCurrency
105	TransactModel.txtFix.CurrencySymbol = sCurCurrency
106	TransactModel.txtMinimum.CurrencySymbol = sCurCurrency
107	bEnableMarket = Index = 0
108	bEnableInternet = sCurChartSource &lt;&gt; &quot;&quot;
109	oMarketModel.Enabled = bEnableMarket
110	oInternetModel.Enabled = bEnableInternet
111	If Not IsMissing(aEvent) Then
112		ConvertStylesCurrencies()
113		bDoUnload = False
114		DlgStartUp.EndExecute()
115	End If
116End Sub
117
118
119Sub ConvertStylesCurrencies()
120Dim m as integer
121Dim aStyleFormat as Object
122Dim StyleName as String
123Dim bAddToList as Boolean
124Dim oStyle as Object
125Dim oStyles as Object
126 	UnprotectSheets(oSheets)
127	oFirstSheet.GetCellByPosition(SBCOLUMNID1, SBROWHEADER1).SetString(sCurStockIDLabel)
128	oStyles = oDocument.StyleFamilies.GetbyIndex(0)
129	For m = 0 To oStyles.count-1
130		oStyle = oStyles.GetbyIndex(m)
131		StyleName = oStyle.Name
132		bAddToList = CheckFormatType(oStyle)
133		If bAddToList Then
134			SwitchNumberFormat(ostyle, oDocFormats, sCurCurrency, sCurExtension)
135		End If
136	Next m
137	ProtectSheets(oSheets)
138End Sub
139
140
141Sub SwitchNumberFormat(oObject as Object, oFormats as object, sNewSymbol as String, sNewExtension as String)
142Dim nFormatLanguage as Integer
143Dim nFormatDecimals as Integer
144Dim nFormatLeading as Integer
145Dim bFormatLeading as Integer
146Dim bFormatNegRed as Integer
147Dim bFormatThousands as Integer
148Dim aNewStr as String
149Dim iNumberFormat as Long
150Dim sSimpleStr as String
151Dim nSimpleKey as Long
152Dim aFormat()
153Dim oLocale as New com.sun.star.lang.Locale
154	&apos; Numberformat with the new Symbol as Base for new Format
155	sSimpleStr = &quot;0 [$&quot; &amp; sNewSymbol &amp; &quot;-&quot; &amp; sNewExtension &amp; &quot;]&quot;
156	nSimpleKey = Numberformat(oFormats, sSimpleStr, oDocLocale)
157	On Local Error Resume Next
158	iNumberFormat = oObject.NumberFormat
159	If Err &lt;&gt; 0 Then
160		Msgbox &quot;Error Reading the Number Format&quot;
161		Resume CLERROR
162	End If
163
164	On Local Error GoTo NOKEY
165	aFormat() = oFormats.getByKey(iNumberFormat)
166	On Local Error GoTo 0
167	&apos; set new currency format with according settings
168	nFormatDecimals = aFormat.Decimals
169	nFormatLeading = aFormat.LeadingZeros
170	bFormatNegRed = aFormat.NegativeRed
171	bFormatThousands = aFormat.ThousandsSeparator
172	oLocale = aFormat.Locale
173	aNewStr = oFormats.generateFormat(nSimpleKey, oLocale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
174	oObject.NumberFormat = Numberformat(oFormats, aNewStr, oLocale)
175	NOKEY:
176	If Err &lt;&gt; 0 Then
177		Resume CLERROR
178	End If
179	CLERROR:
180End Sub
181
182
183Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Variant )
184Dim nRetkey
185	nRetKey = oFormats.queryKey(aFormatStr, oLocale, True)
186	If nRetKey = -1 Then
187		nRetKey = oFormats.addNew( aFormatStr, oLocale )
188		If nRetKey = -1 Then nRetKey = 0
189	End If
190	Numberformat = nRetKey
191End Function
192
193
194Function CheckFormatType(oStyle as Object)
195Dim oFormatofObject as Object
196	oFormatofObject = oDocFormats.getByKey(oStyle.NumberFormat)
197  	CheckFormatType = INT(oFormatOfObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
198End Function</script:module>
199