1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Currency" script:
language=
"StarBasic">REM ***** BASIC *****
23 Dim bDoUnLoad as Boolean
29 Dim ListString as String
30 Dim MarketListBoxControl as Object
32 MarketListBoxControl = DlgStartUp.GetControl(
"lstMarkets
")
34 For i =
0 To Ubound(sMarket(),
1)
35 ListString = sMarket(i,
0)
36 If sMarket(i,
0)
<> "" Then
37 If sMarket(i,
3) =
"" Then
38 ListString = ListString
& " (
" & sNoInternetUpdate
& ")
"
40 ListString = ListString
& " (
" & sMarketplace
& " " & sMarket(i,
2)
& ")
"
42 MarketListBoxControl.AddItem(ListString, a)
46 MarketListBoxControl.SelectItemPos(GlobListIndex, True)
47 DlgStartUp.Title = sDepotCurrency
48 DlgStartUp.Model.cmdGoOn.DefaultButton = True
49 DlgStartUp.GetControl(
"lstMarkets
").SetFocus()
55 Sub EnableGoOnButton()
56 StartUpModel.cmdGoOn.Enabled = True
57 StartUpModel.cmdGoOn.DefaultButton = True
61 Sub CloseStartUpDialog()
62 DlgStartUp.EndExecute()
63 ' oDocument.Dispose()
74 Sub ChooseMarket(Optional aEvent)
76 Dim bIsDocLanguage as Boolean
77 Dim bIsDocCountry as Boolean
78 oInternetModel = GetControlModel(oDocument.Sheets(
0),
"CmdInternet
")
79 If Not IsMissing(aEvent) Then
80 Index = StartupModel.lstMarkets.SelectedItems(
0)
81 oInternetModel.Tag = Index
83 Index = oInternetModel.Tag
85 oMarketModel = GetControlModel(oDocument.Sheets(
0),
"CmdHistory
")
86 sCurCurrency = sMarket(Index,
1)
88 HistoryChartSource = sMarket(Index,
4)
90 sCurStockIDLabel = sMarket(Index,
5)
91 sCurExtension = sMarket(Index,
8)
92 iValueCol = Val(sMarket(Index,
10))
93 If Instr(sCurExtension,
";
")
<> 0 Then
94 ' Take the german extension as the stock place is Frankfurt
95 sCurExtension =
"407"
97 sCurChartSource = sMarket(Index,
3)
98 bIsDocLanguage = Instr(
1, sMarket(Index,
6), sDocLanguage, SBBINARY)
<> 0
99 bIsDocCountry = Instr(
1, sMarket(Index,
7), sDocCountry, SBBINARY)
<> 0 OR SDocCountry =
""
100 sCurSeparator = sMarket(Index,
9)
101 TransactModel.txtRate.CurrencySymbol = sCurCurrency
102 TransactModel.txtFix.CurrencySymbol = sCurCurrency
103 TransactModel.txtMinimum.CurrencySymbol = sCurCurrency
104 bEnableMarket = Index =
0
105 bEnableInternet = sCurChartSource
<> ""
106 oMarketModel.Enabled = bEnableMarket
107 oInternetModel.Enabled = bEnableInternet
108 If Not IsMissing(aEvent) Then
109 ConvertStylesCurrencies()
111 DlgStartUp.EndExecute()
116 Sub ConvertStylesCurrencies()
118 Dim aStyleFormat as Object
119 Dim StyleName as String
120 Dim bAddToList as Boolean
122 Dim oStyles as Object
123 UnprotectSheets(oSheets)
124 oFirstSheet.GetCellByPosition(SBCOLUMNID1, SBROWHEADER1).SetString(sCurStockIDLabel)
125 oStyles = oDocument.StyleFamilies.GetbyIndex(
0)
126 For m =
0 To oStyles.count-
1
127 oStyle = oStyles.GetbyIndex(m)
128 StyleName = oStyle.Name
129 bAddToList = CheckFormatType(oStyle)
131 SwitchNumberFormat(ostyle, oDocFormats, sCurCurrency, sCurExtension)
134 ProtectSheets(oSheets)
138 Sub SwitchNumberFormat(oObject as Object, oFormats as object, sNewSymbol as String, sNewExtension as String)
139 Dim nFormatLanguage as Integer
140 Dim nFormatDecimals as Integer
141 Dim nFormatLeading as Integer
142 Dim bFormatLeading as Integer
143 Dim bFormatNegRed as Integer
144 Dim bFormatThousands as Integer
145 Dim aNewStr as String
146 Dim iNumberFormat as Long
147 Dim sSimpleStr as String
148 Dim nSimpleKey as Long
150 Dim oLocale as New com.sun.star.lang.Locale
151 ' Numberformat with the new Symbol as Base for new Format
152 sSimpleStr =
"0 [$
" & sNewSymbol
& "-
" & sNewExtension
& "]
"
153 nSimpleKey = Numberformat(oFormats, sSimpleStr, oDocLocale)
154 On Local Error Resume Next
155 iNumberFormat = oObject.NumberFormat
156 If Err
<> 0 Then
157 Msgbox
"Error Reading the Number Format
"
161 On Local Error GoTo NOKEY
162 aFormat() = oFormats.getByKey(iNumberFormat)
163 On Local Error GoTo
0
164 ' set new currency format with according settings
165 nFormatDecimals = aFormat.Decimals
166 nFormatLeading = aFormat.LeadingZeros
167 bFormatNegRed = aFormat.NegativeRed
168 bFormatThousands = aFormat.ThousandsSeparator
169 oLocale = aFormat.Locale
170 aNewStr = oFormats.generateFormat(nSimpleKey, oLocale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
171 oObject.NumberFormat = Numberformat(oFormats, aNewStr, oLocale)
173 If Err
<> 0 Then
180 Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Variant )
182 nRetKey = oFormats.queryKey(aFormatStr, oLocale, True)
184 nRetKey = oFormats.addNew( aFormatStr, oLocale )
185 If nRetKey = -
1 Then nRetKey =
0
187 Numberformat = nRetKey
191 Function CheckFormatType(oStyle as Object)
192 Dim oFormatofObject as Object
193 oFormatofObject = oDocFormats.getByKey(oStyle.NumberFormat)
194 CheckFormatType = INT(oFormatOfObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
195 End Function
</script:module>